@namzu/sdk 30.2.0 → 31.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +556 -0
- package/README.md +43 -2
- package/dist/advisory/executor.d.ts +2 -1
- package/dist/advisory/executor.d.ts.map +1 -1
- package/dist/advisory/executor.js +4 -1
- package/dist/advisory/executor.js.map +1 -1
- package/dist/agents/ReactiveAgent.d.ts.map +1 -1
- package/dist/agents/ReactiveAgent.js +12 -0
- package/dist/agents/ReactiveAgent.js.map +1 -1
- package/dist/agents/RouterAgent.d.ts.map +1 -1
- package/dist/agents/RouterAgent.js +21 -3
- package/dist/agents/RouterAgent.js.map +1 -1
- package/dist/agents/SupervisorAgent.d.ts.map +1 -1
- package/dist/agents/SupervisorAgent.js +34 -11
- package/dist/agents/SupervisorAgent.js.map +1 -1
- package/dist/agents/runAgent.d.ts +12 -0
- package/dist/agents/runAgent.d.ts.map +1 -1
- package/dist/agents/runAgent.js +26 -2
- package/dist/agents/runAgent.js.map +1 -1
- package/dist/authorization/command-line.d.ts +81 -0
- package/dist/authorization/command-line.d.ts.map +1 -0
- package/dist/authorization/command-line.js +347 -0
- package/dist/authorization/command-line.js.map +1 -0
- package/dist/authorization/rules.d.ts.map +1 -1
- package/dist/authorization/rules.js +22 -1
- package/dist/authorization/rules.js.map +1 -1
- package/dist/bridge/a2a/client.d.ts +23 -5
- package/dist/bridge/a2a/client.d.ts.map +1 -1
- package/dist/bridge/a2a/client.js +320 -73
- package/dist/bridge/a2a/client.js.map +1 -1
- package/dist/bridge/a2a/mapper.d.ts.map +1 -1
- package/dist/bridge/a2a/mapper.js +4 -0
- package/dist/bridge/a2a/mapper.js.map +1 -1
- package/dist/bridge/acp/server.d.ts +13 -1
- package/dist/bridge/acp/server.d.ts.map +1 -1
- package/dist/bridge/acp/server.js +150 -44
- package/dist/bridge/acp/server.js.map +1 -1
- package/dist/bridge/mcp/connector/adapter.d.ts +3 -2
- package/dist/bridge/mcp/connector/adapter.d.ts.map +1 -1
- package/dist/bridge/mcp/connector/adapter.js +17 -21
- package/dist/bridge/mcp/connector/adapter.js.map +1 -1
- package/dist/bridge/sse/mapper.d.ts.map +1 -1
- package/dist/bridge/sse/mapper.js +3 -0
- package/dist/bridge/sse/mapper.js.map +1 -1
- package/dist/compaction/dangling.d.ts +29 -2
- package/dist/compaction/dangling.d.ts.map +1 -1
- package/dist/compaction/dangling.js +172 -35
- package/dist/compaction/dangling.js.map +1 -1
- package/dist/compaction/index.d.ts +3 -2
- package/dist/compaction/index.d.ts.map +1 -1
- package/dist/compaction/index.js +1 -1
- package/dist/compaction/index.js.map +1 -1
- package/dist/compaction/manual.d.ts +11 -1
- package/dist/compaction/manual.d.ts.map +1 -1
- package/dist/compaction/manual.js +89 -14
- package/dist/compaction/manual.js.map +1 -1
- package/dist/compaction/plan.d.ts +19 -6
- package/dist/compaction/plan.d.ts.map +1 -1
- package/dist/compaction/plan.js +18 -4
- package/dist/compaction/plan.js.map +1 -1
- package/dist/compaction/retention.d.ts +10 -7
- package/dist/compaction/retention.d.ts.map +1 -1
- package/dist/compaction/retention.js +26 -8
- package/dist/compaction/retention.js.map +1 -1
- package/dist/compaction/summary.d.ts +4 -4
- package/dist/compaction/summary.js +4 -4
- package/dist/compaction/verifier.d.ts +19 -1
- package/dist/compaction/verifier.d.ts.map +1 -1
- package/dist/compaction/verifier.js +20 -1
- package/dist/compaction/verifier.js.map +1 -1
- package/dist/config/runtime.d.ts +6 -6
- package/dist/connector/BaseConnector.d.ts +6 -4
- package/dist/connector/BaseConnector.d.ts.map +1 -1
- package/dist/connector/BaseConnector.js +8 -2
- package/dist/connector/BaseConnector.js.map +1 -1
- package/dist/connector/builtins/http.d.ts +16 -4
- package/dist/connector/builtins/http.d.ts.map +1 -1
- package/dist/connector/builtins/http.js +177 -44
- package/dist/connector/builtins/http.js.map +1 -1
- package/dist/connector/builtins/webhook.d.ts +15 -4
- package/dist/connector/builtins/webhook.d.ts.map +1 -1
- package/dist/connector/builtins/webhook.js +165 -45
- package/dist/connector/builtins/webhook.js.map +1 -1
- package/dist/connector/execution-contract.d.ts +11 -0
- package/dist/connector/execution-contract.d.ts.map +1 -0
- package/dist/connector/execution-contract.js +14 -0
- package/dist/connector/execution-contract.js.map +1 -0
- package/dist/connector/http-operation.d.ts +48 -0
- package/dist/connector/http-operation.d.ts.map +1 -0
- package/dist/connector/http-operation.js +205 -0
- package/dist/connector/http-operation.js.map +1 -0
- package/dist/connector/mcp/adapter.d.ts.map +1 -1
- package/dist/connector/mcp/adapter.js +8 -3
- package/dist/connector/mcp/adapter.js.map +1 -1
- package/dist/connector/mcp/client.d.ts +14 -8
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +160 -44
- package/dist/connector/mcp/client.js.map +1 -1
- package/dist/connector/mcp/http-sse.d.ts +8 -2
- package/dist/connector/mcp/http-sse.d.ts.map +1 -1
- package/dist/connector/mcp/http-sse.js +70 -17
- package/dist/connector/mcp/http-sse.js.map +1 -1
- package/dist/connector/mcp/prompt-adapter.d.ts.map +1 -1
- package/dist/connector/mcp/prompt-adapter.js +9 -2
- package/dist/connector/mcp/prompt-adapter.js.map +1 -1
- package/dist/connector/mcp/stdio.d.ts +2 -2
- package/dist/connector/mcp/stdio.d.ts.map +1 -1
- package/dist/connector/mcp/stdio.js +14 -50
- package/dist/connector/mcp/stdio.js.map +1 -1
- package/dist/connector/mcp/streamable-http.d.ts +7 -2
- package/dist/connector/mcp/streamable-http.d.ts.map +1 -1
- package/dist/connector/mcp/streamable-http.js +66 -18
- package/dist/connector/mcp/streamable-http.js.map +1 -1
- package/dist/connector/tools/adapter.d.ts +2 -2
- package/dist/connector/tools/adapter.d.ts.map +1 -1
- package/dist/connector/tools/adapter.js +23 -14
- package/dist/connector/tools/adapter.js.map +1 -1
- package/dist/connector/tools/definitions.d.ts.map +1 -1
- package/dist/connector/tools/definitions.js +5 -2
- package/dist/connector/tools/definitions.js.map +1 -1
- package/dist/connector/tools/result.d.ts +4 -0
- package/dist/connector/tools/result.d.ts.map +1 -0
- package/dist/connector/tools/result.js +20 -0
- package/dist/connector/tools/result.js.map +1 -0
- package/dist/connector/web/guarded-fetch.d.ts +4 -2
- package/dist/connector/web/guarded-fetch.d.ts.map +1 -1
- package/dist/connector/web/guarded-fetch.js +157 -43
- package/dist/connector/web/guarded-fetch.js.map +1 -1
- package/dist/constants/sandbox/index.d.ts +3 -2
- package/dist/constants/sandbox/index.d.ts.map +1 -1
- package/dist/constants/sandbox/index.js +3 -2
- package/dist/constants/sandbox/index.js.map +1 -1
- package/dist/contracts/api.d.ts +2 -0
- package/dist/contracts/api.d.ts.map +1 -1
- package/dist/contracts/schemas.d.ts +38 -12
- package/dist/contracts/schemas.d.ts.map +1 -1
- package/dist/contracts/schemas.js +7 -0
- package/dist/contracts/schemas.js.map +1 -1
- package/dist/directory/derive-supervisor.d.ts.map +1 -1
- package/dist/directory/derive-supervisor.js +8 -0
- package/dist/directory/derive-supervisor.js.map +1 -1
- package/dist/directory/derive.d.ts.map +1 -1
- package/dist/directory/derive.js +8 -0
- package/dist/directory/derive.js.map +1 -1
- package/dist/directory/load.d.ts.map +1 -1
- package/dist/directory/load.js +2 -0
- package/dist/directory/load.js.map +1 -1
- package/dist/directory/types.d.ts +4 -0
- package/dist/directory/types.d.ts.map +1 -1
- package/dist/eval/experiment.d.ts +10 -10
- package/dist/eval/experiment.d.ts.map +1 -1
- package/dist/eval/experiment.js +121 -91
- package/dist/eval/experiment.js.map +1 -1
- package/dist/eval/judge.d.ts +6 -0
- package/dist/eval/judge.d.ts.map +1 -1
- package/dist/eval/judge.js +7 -2
- package/dist/eval/judge.js.map +1 -1
- package/dist/eval/types.d.ts +7 -1
- package/dist/eval/types.d.ts.map +1 -1
- package/dist/manager/agent/lifecycle.d.ts +12 -10
- package/dist/manager/agent/lifecycle.d.ts.map +1 -1
- package/dist/manager/agent/lifecycle.js +16 -3
- package/dist/manager/agent/lifecycle.js.map +1 -1
- package/dist/manager/connector/environment.d.ts +2 -2
- package/dist/manager/connector/environment.d.ts.map +1 -1
- package/dist/manager/connector/environment.js +2 -2
- package/dist/manager/connector/environment.js.map +1 -1
- package/dist/manager/connector/lifecycle.d.ts +10 -2
- package/dist/manager/connector/lifecycle.d.ts.map +1 -1
- package/dist/manager/connector/lifecycle.js +273 -24
- package/dist/manager/connector/lifecycle.js.map +1 -1
- package/dist/manager/connector/tenant.d.ts +5 -4
- package/dist/manager/connector/tenant.d.ts.map +1 -1
- package/dist/manager/connector/tenant.js +47 -22
- package/dist/manager/connector/tenant.js.map +1 -1
- package/dist/manager/goal/activation.d.ts +23 -0
- package/dist/manager/goal/activation.d.ts.map +1 -0
- package/dist/manager/goal/activation.js +41 -0
- package/dist/manager/goal/activation.js.map +1 -0
- package/dist/manager/index.d.ts +3 -2
- package/dist/manager/index.d.ts.map +1 -1
- package/dist/manager/index.js.map +1 -1
- package/dist/manager/run/persistence.d.ts +2 -0
- package/dist/manager/run/persistence.d.ts.map +1 -1
- package/dist/manager/run/persistence.js +5 -1
- package/dist/manager/run/persistence.js.map +1 -1
- package/dist/manager/topic/dependency.d.ts +24 -0
- package/dist/manager/topic/dependency.d.ts.map +1 -0
- package/dist/manager/topic/dependency.js +13 -0
- package/dist/manager/topic/dependency.js.map +1 -0
- package/dist/manager/topic/lifecycle.d.ts +9 -21
- package/dist/manager/topic/lifecycle.d.ts.map +1 -1
- package/dist/manager/topic/lifecycle.js +17 -29
- package/dist/manager/topic/lifecycle.js.map +1 -1
- package/dist/plugin/index.d.ts +1 -0
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/lifecycle.d.ts +15 -0
- package/dist/plugin/lifecycle.d.ts.map +1 -1
- package/dist/plugin/lifecycle.js +144 -38
- package/dist/plugin/lifecycle.js.map +1 -1
- package/dist/plugin/loader.d.ts +3 -3
- package/dist/plugin/loader.d.ts.map +1 -1
- package/dist/plugin/loader.js +58 -12
- package/dist/plugin/loader.js.map +1 -1
- package/dist/provider/collect-chat-completion.d.ts.map +1 -1
- package/dist/provider/collect-chat-completion.js +4 -0
- package/dist/provider/collect-chat-completion.js.map +1 -1
- package/dist/provider/fallback.d.ts +3 -1
- package/dist/provider/fallback.d.ts.map +1 -1
- package/dist/provider/fallback.js +62 -10
- package/dist/provider/fallback.js.map +1 -1
- package/dist/provider/idle-timeout.d.ts +4 -0
- package/dist/provider/idle-timeout.d.ts.map +1 -1
- package/dist/provider/idle-timeout.js +131 -15
- package/dist/provider/idle-timeout.js.map +1 -1
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +1 -0
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/instrumentation.d.ts.map +1 -1
- package/dist/provider/instrumentation.js +1 -0
- package/dist/provider/instrumentation.js.map +1 -1
- package/dist/provider/retry.d.ts.map +1 -1
- package/dist/provider/retry.js +13 -1
- package/dist/provider/retry.js.map +1 -1
- package/dist/public-runtime.d.ts +57 -24
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +42 -35
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +1 -0
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +5 -0
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +33 -12
- package/dist/public-types.d.ts.map +1 -1
- package/dist/rag/embedding.d.ts +8 -3
- package/dist/rag/embedding.d.ts.map +1 -1
- package/dist/rag/embedding.js +120 -9
- package/dist/rag/embedding.js.map +1 -1
- package/dist/rag/index.d.ts +1 -1
- package/dist/rag/index.d.ts.map +1 -1
- package/dist/rag/index.js +1 -1
- package/dist/rag/index.js.map +1 -1
- package/dist/rag/ingestion.d.ts +2 -2
- package/dist/rag/ingestion.d.ts.map +1 -1
- package/dist/rag/ingestion.js +15 -3
- package/dist/rag/ingestion.js.map +1 -1
- package/dist/rag/knowledge-base.d.ts +3 -3
- package/dist/rag/knowledge-base.d.ts.map +1 -1
- package/dist/rag/knowledge-base.js +8 -4
- package/dist/rag/knowledge-base.js.map +1 -1
- package/dist/rag/operation.d.ts +10 -0
- package/dist/rag/operation.d.ts.map +1 -0
- package/dist/rag/operation.js +26 -0
- package/dist/rag/operation.js.map +1 -0
- package/dist/rag/rag-tool.d.ts.map +1 -1
- package/dist/rag/rag-tool.js +6 -3
- package/dist/rag/rag-tool.js.map +1 -1
- package/dist/rag/retriever.d.ts +2 -2
- package/dist/rag/retriever.d.ts.map +1 -1
- package/dist/rag/retriever.js +31 -15
- package/dist/rag/retriever.js.map +1 -1
- package/dist/rag/vector-store.d.ts +3 -3
- package/dist/rag/vector-store.d.ts.map +1 -1
- package/dist/rag/vector-store.js +4 -2
- package/dist/rag/vector-store.js.map +1 -1
- package/dist/registry/command/kernel-commands.d.ts +16 -4
- package/dist/registry/command/kernel-commands.d.ts.map +1 -1
- package/dist/registry/command/kernel-commands.js +171 -0
- package/dist/registry/command/kernel-commands.js.map +1 -1
- package/dist/run/reporter.d.ts.map +1 -1
- package/dist/run/reporter.js +9 -0
- package/dist/run/reporter.js.map +1 -1
- package/dist/run-query/index.d.ts +15 -1
- package/dist/run-query/index.d.ts.map +1 -1
- package/dist/run-query/index.js +69 -15
- package/dist/run-query/index.js.map +1 -1
- package/dist/runtime/query/context.d.ts.map +1 -1
- package/dist/runtime/query/context.js +10 -3
- package/dist/runtime/query/context.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +3 -0
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +80 -18
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/guard.d.ts +9 -0
- package/dist/runtime/query/guard.d.ts.map +1 -1
- package/dist/runtime/query/guard.js +11 -0
- package/dist/runtime/query/guard.js.map +1 -1
- package/dist/runtime/query/index.d.ts +30 -1
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +548 -95
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +74 -14
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.js +94 -53
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +3 -0
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.js +21 -0
- package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
- package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
- package/dist/runtime/query/iteration/stream-turn.js +4 -0
- package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
- package/dist/runtime/query/project-instructions.d.ts +69 -0
- package/dist/runtime/query/project-instructions.d.ts.map +1 -0
- package/dist/runtime/query/project-instructions.js +137 -0
- package/dist/runtime/query/project-instructions.js.map +1 -0
- package/dist/runtime/query/request-rich-content.d.ts +22 -0
- package/dist/runtime/query/request-rich-content.d.ts.map +1 -0
- package/dist/runtime/query/request-rich-content.js +122 -0
- package/dist/runtime/query/request-rich-content.js.map +1 -0
- package/dist/runtime/query/result.d.ts.map +1 -1
- package/dist/runtime/query/result.js +12 -1
- package/dist/runtime/query/result.js.map +1 -1
- package/dist/runtime/query/resume-pending.d.ts.map +1 -1
- package/dist/runtime/query/resume-pending.js +19 -20
- package/dist/runtime/query/resume-pending.js.map +1 -1
- package/dist/runtime/query/resume-run.d.ts.map +1 -1
- package/dist/runtime/query/resume-run.js +54 -8
- package/dist/runtime/query/resume-run.js.map +1 -1
- package/dist/runtime/query/run-state.d.ts +5 -0
- package/dist/runtime/query/run-state.d.ts.map +1 -1
- package/dist/runtime/query/run-state.js +6 -1
- package/dist/runtime/query/run-state.js.map +1 -1
- package/dist/runtime/query/sandbox-lifecycle.d.ts +54 -0
- package/dist/runtime/query/sandbox-lifecycle.d.ts.map +1 -0
- package/dist/runtime/query/sandbox-lifecycle.js +167 -0
- package/dist/runtime/query/sandbox-lifecycle.js.map +1 -0
- package/dist/sandbox/isolation.d.ts.map +1 -1
- package/dist/sandbox/isolation.js +9 -0
- package/dist/sandbox/isolation.js.map +1 -1
- package/dist/sandbox/provider/local.d.ts +56 -6
- package/dist/sandbox/provider/local.d.ts.map +1 -1
- package/dist/sandbox/provider/local.js +181 -76
- package/dist/sandbox/provider/local.js.map +1 -1
- package/dist/sandbox/terminal.d.ts +13 -5
- package/dist/sandbox/terminal.d.ts.map +1 -1
- package/dist/sandbox/terminal.js +11 -3
- package/dist/sandbox/terminal.js.map +1 -1
- package/dist/session/errors.d.ts +28 -29
- package/dist/session/errors.d.ts.map +1 -1
- package/dist/session/errors.js +28 -29
- package/dist/session/errors.js.map +1 -1
- package/dist/session/handoff/broadcast.d.ts +5 -8
- package/dist/session/handoff/broadcast.d.ts.map +1 -1
- package/dist/session/handoff/broadcast.js +16 -6
- package/dist/session/handoff/broadcast.js.map +1 -1
- package/dist/session/handoff/single.d.ts +5 -8
- package/dist/session/handoff/single.d.ts.map +1 -1
- package/dist/session/handoff/single.js +7 -4
- package/dist/session/handoff/single.js.map +1 -1
- package/dist/store/attachment/index.d.ts +11 -3
- package/dist/store/attachment/index.d.ts.map +1 -1
- package/dist/store/attachment/index.js +49 -4
- package/dist/store/attachment/index.js.map +1 -1
- package/dist/store/feedback/conformance.d.ts.map +1 -1
- package/dist/store/feedback/conformance.js +32 -0
- package/dist/store/feedback/conformance.js.map +1 -1
- package/dist/store/feedback/disk.d.ts +8 -6
- package/dist/store/feedback/disk.d.ts.map +1 -1
- package/dist/store/feedback/disk.js +111 -76
- package/dist/store/feedback/disk.js.map +1 -1
- package/dist/store/goal/index.d.ts +111 -0
- package/dist/store/goal/index.d.ts.map +1 -0
- package/dist/store/goal/index.js +436 -0
- package/dist/store/goal/index.js.map +1 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +1 -1
- package/dist/store/index.js.map +1 -1
- package/dist/store/kv/revision-record-store.d.ts +70 -0
- package/dist/store/kv/revision-record-store.d.ts.map +1 -0
- package/dist/store/kv/revision-record-store.js +290 -0
- package/dist/store/kv/revision-record-store.js.map +1 -0
- package/dist/store/memory/disk.d.ts +9 -7
- package/dist/store/memory/disk.d.ts.map +1 -1
- package/dist/store/memory/disk.js +256 -98
- package/dist/store/memory/disk.js.map +1 -1
- package/dist/store/run/disk.d.ts +10 -2
- package/dist/store/run/disk.d.ts.map +1 -1
- package/dist/store/run/disk.js +70 -4
- package/dist/store/run/disk.js.map +1 -1
- package/dist/store/run/memory.d.ts +4 -2
- package/dist/store/run/memory.d.ts.map +1 -1
- package/dist/store/run/memory.js +15 -1
- package/dist/store/run/memory.js.map +1 -1
- package/dist/store/session/disk.d.ts +9 -0
- package/dist/store/session/disk.d.ts.map +1 -1
- package/dist/store/session/disk.js +57 -5
- package/dist/store/session/disk.js.map +1 -1
- package/dist/store/session/memory.d.ts +1 -0
- package/dist/store/session/memory.d.ts.map +1 -1
- package/dist/store/session/memory.js +14 -0
- package/dist/store/session/memory.js.map +1 -1
- package/dist/store/topic/memory.d.ts +1 -2
- package/dist/store/topic/memory.d.ts.map +1 -1
- package/dist/store/topic/memory.js +4 -5
- package/dist/store/topic/memory.js.map +1 -1
- package/dist/store/topic/objective.d.ts +8 -4
- package/dist/store/topic/objective.d.ts.map +1 -1
- package/dist/store/topic/objective.js +185 -100
- package/dist/store/topic/objective.js.map +1 -1
- package/dist/store/topic/state.d.ts +1 -2
- package/dist/store/topic/state.d.ts.map +1 -1
- package/dist/store/topic/state.js +50 -62
- package/dist/store/topic/state.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +20 -0
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/computer-use.d.ts +9 -1
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js.map +1 -1
- package/dist/tools/builtins/content-fingerprint.d.ts +8 -7
- package/dist/tools/builtins/content-fingerprint.d.ts.map +1 -1
- package/dist/tools/builtins/content-fingerprint.js +9 -10
- package/dist/tools/builtins/content-fingerprint.js.map +1 -1
- package/dist/tools/builtins/edit.d.ts +6 -1
- package/dist/tools/builtins/edit.d.ts.map +1 -1
- package/dist/tools/builtins/edit.js +166 -27
- package/dist/tools/builtins/edit.js.map +1 -1
- package/dist/tools/builtins/write-file.d.ts.map +1 -1
- package/dist/tools/builtins/write-file.js +45 -19
- package/dist/tools/builtins/write-file.js.map +1 -1
- package/dist/tools/command-arguments.d.ts +43 -0
- package/dist/tools/command-arguments.d.ts.map +1 -0
- package/dist/tools/command-arguments.js +52 -0
- package/dist/tools/command-arguments.js.map +1 -0
- package/dist/tools/coordinator/index.d.ts +2 -0
- package/dist/tools/coordinator/index.d.ts.map +1 -1
- package/dist/tools/coordinator/index.js +3 -1
- package/dist/tools/coordinator/index.js.map +1 -1
- package/dist/tools/defineTool.d.ts +10 -0
- package/dist/tools/defineTool.d.ts.map +1 -1
- package/dist/tools/defineTool.js +1 -0
- package/dist/tools/defineTool.js.map +1 -1
- package/dist/tools/env-scrub.d.ts +7 -5
- package/dist/tools/env-scrub.d.ts.map +1 -1
- package/dist/tools/env-scrub.js +7 -5
- package/dist/tools/env-scrub.js.map +1 -1
- package/dist/tools/goal/index.d.ts +20 -0
- package/dist/tools/goal/index.d.ts.map +1 -0
- package/dist/tools/goal/index.js +104 -0
- package/dist/tools/goal/index.js.map +1 -0
- package/dist/tools/memory/index.d.ts +16 -0
- package/dist/tools/memory/index.d.ts.map +1 -1
- package/dist/tools/memory/index.js +6 -2
- package/dist/tools/memory/index.js.map +1 -1
- package/dist/tools/memory/search.d.ts +4 -1
- package/dist/tools/memory/search.d.ts.map +1 -1
- package/dist/tools/memory/search.js +10 -2
- package/dist/tools/memory/search.js.map +1 -1
- package/dist/types/agent/base.d.ts +11 -3
- package/dist/types/agent/base.d.ts.map +1 -1
- package/dist/types/agent/factory.d.ts +2 -0
- package/dist/types/agent/factory.d.ts.map +1 -1
- package/dist/types/agent/reactive.d.ts +2 -0
- package/dist/types/agent/reactive.d.ts.map +1 -1
- package/dist/types/agent/supervisor.d.ts +6 -0
- package/dist/types/agent/supervisor.d.ts.map +1 -1
- package/dist/types/agent/task.d.ts +6 -2
- package/dist/types/agent/task.d.ts.map +1 -1
- package/dist/types/connector/core.d.ts +13 -8
- package/dist/types/connector/core.d.ts.map +1 -1
- package/dist/types/connector/definition.d.ts +37 -18
- package/dist/types/connector/definition.d.ts.map +1 -1
- package/dist/types/connector/http.d.ts +6 -0
- package/dist/types/connector/http.d.ts.map +1 -1
- package/dist/types/connector/mcp.d.ts +24 -6
- package/dist/types/connector/mcp.d.ts.map +1 -1
- package/dist/types/connector/tenant.d.ts +17 -7
- package/dist/types/connector/tenant.d.ts.map +1 -1
- package/dist/types/connector/webhook.d.ts +6 -0
- package/dist/types/connector/webhook.d.ts.map +1 -1
- package/dist/types/goal/index.d.ts +46 -0
- package/dist/types/goal/index.d.ts.map +1 -0
- package/dist/types/goal/index.js +2 -0
- package/dist/types/goal/index.js.map +1 -0
- package/dist/types/ids/index.d.ts +2 -0
- package/dist/types/ids/index.d.ts.map +1 -1
- package/dist/types/ids/index.js.map +1 -1
- package/dist/types/message/index.d.ts +75 -10
- package/dist/types/message/index.d.ts.map +1 -1
- package/dist/types/message/index.js +49 -3
- package/dist/types/message/index.js.map +1 -1
- package/dist/types/plugin/index.d.ts +7 -5
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/plugin/index.js.map +1 -1
- package/dist/types/provider/chat.d.ts +27 -4
- package/dist/types/provider/chat.d.ts.map +1 -1
- package/dist/types/provider/interface.d.ts +18 -7
- package/dist/types/provider/interface.d.ts.map +1 -1
- package/dist/types/provider/stream.d.ts +6 -0
- package/dist/types/provider/stream.d.ts.map +1 -1
- package/dist/types/rag/embedding.d.ts +15 -2
- package/dist/types/rag/embedding.d.ts.map +1 -1
- package/dist/types/rag/ingestion.d.ts +2 -2
- package/dist/types/rag/ingestion.d.ts.map +1 -1
- package/dist/types/rag/knowledge-base.d.ts +3 -3
- package/dist/types/rag/knowledge-base.d.ts.map +1 -1
- package/dist/types/rag/retrieval.d.ts +2 -2
- package/dist/types/rag/retrieval.d.ts.map +1 -1
- package/dist/types/rag/scope.d.ts +4 -0
- package/dist/types/rag/scope.d.ts.map +1 -1
- package/dist/types/rag/vector.d.ts +5 -2
- package/dist/types/rag/vector.d.ts.map +1 -1
- package/dist/types/run/config.d.ts +20 -0
- package/dist/types/run/config.d.ts.map +1 -1
- package/dist/types/run/events.d.ts +25 -1
- package/dist/types/run/events.d.ts.map +1 -1
- package/dist/types/run/events.js.map +1 -1
- package/dist/types/run/metadata.d.ts +2 -0
- package/dist/types/run/metadata.d.ts.map +1 -1
- package/dist/types/run/step.d.ts +2 -6
- package/dist/types/run/step.d.ts.map +1 -1
- package/dist/types/run/step.js.map +1 -1
- package/dist/types/run/store.d.ts +55 -2
- package/dist/types/run/store.d.ts.map +1 -1
- package/dist/types/sandbox/index.d.ts +47 -6
- package/dist/types/sandbox/index.d.ts.map +1 -1
- package/dist/types/sandbox/index.js +23 -10
- package/dist/types/sandbox/index.js.map +1 -1
- package/dist/types/session/store.d.ts +13 -0
- package/dist/types/session/store.d.ts.map +1 -1
- package/dist/types/tool/index.d.ts +33 -11
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/types/topic/entity.d.ts +3 -4
- package/dist/types/topic/entity.d.ts.map +1 -1
- package/dist/types/topic/store.d.ts +3 -3
- package/dist/utils/id.d.ts +3 -1
- package/dist/utils/id.d.ts.map +1 -1
- package/dist/utils/id.js +4 -0
- package/dist/utils/id.js.map +1 -1
- package/dist/utils/process-environment.d.ts +26 -0
- package/dist/utils/process-environment.d.ts.map +1 -0
- package/dist/utils/process-environment.js +78 -0
- package/dist/utils/process-environment.js.map +1 -0
- package/dist/vault/InMemoryCredentialVault.d.ts +2 -0
- package/dist/vault/InMemoryCredentialVault.d.ts.map +1 -1
- package/dist/vault/InMemoryCredentialVault.js +24 -4
- package/dist/vault/InMemoryCredentialVault.js.map +1 -1
- package/dist/vault/instrumentation.d.ts.map +1 -1
- package/dist/vault/instrumentation.js +15 -0
- package/dist/vault/instrumentation.js.map +1 -1
- package/package.json +1 -1
- package/src/advisory/executor.ts +4 -1
- package/src/agents/ReactiveAgent.ts +12 -0
- package/src/agents/RouterAgent.ts +25 -3
- package/src/agents/SupervisorAgent.ts +33 -11
- package/src/agents/runAgent.ts +38 -2
- package/src/authorization/command-line.ts +390 -0
- package/src/authorization/rules.ts +22 -1
- package/src/bridge/a2a/client.ts +384 -97
- package/src/bridge/a2a/mapper.ts +5 -0
- package/src/bridge/acp/server.ts +184 -42
- package/src/bridge/mcp/connector/adapter.ts +28 -20
- package/src/bridge/sse/mapper.ts +3 -0
- package/src/compaction/dangling.ts +203 -38
- package/src/compaction/index.ts +9 -2
- package/src/compaction/manual.ts +125 -18
- package/src/compaction/plan.ts +42 -11
- package/src/compaction/retention.ts +23 -8
- package/src/compaction/summary.ts +4 -4
- package/src/compaction/verifier.ts +66 -0
- package/src/connector/BaseConnector.ts +19 -4
- package/src/connector/builtins/http.ts +236 -46
- package/src/connector/builtins/webhook.ts +207 -47
- package/src/connector/execution-contract.ts +27 -0
- package/src/connector/http-operation.ts +238 -0
- package/src/connector/mcp/adapter.ts +8 -3
- package/src/connector/mcp/client.ts +207 -58
- package/src/connector/mcp/http-sse.ts +91 -23
- package/src/connector/mcp/prompt-adapter.ts +8 -2
- package/src/connector/mcp/stdio.ts +21 -46
- package/src/connector/mcp/streamable-http.ts +86 -22
- package/src/connector/tools/adapter.ts +23 -14
- package/src/connector/tools/definitions.ts +5 -2
- package/src/connector/tools/result.ts +21 -0
- package/src/connector/web/guarded-fetch.ts +188 -48
- package/src/constants/sandbox/index.ts +3 -2
- package/src/contracts/api.ts +2 -0
- package/src/contracts/schemas.ts +7 -0
- package/src/directory/derive-supervisor.ts +8 -0
- package/src/directory/derive.ts +8 -0
- package/src/directory/load.ts +2 -0
- package/src/directory/types.ts +4 -0
- package/src/eval/experiment.ts +160 -111
- package/src/eval/judge.ts +13 -2
- package/src/eval/types.ts +7 -1
- package/src/manager/agent/lifecycle.ts +28 -12
- package/src/manager/connector/environment.ts +3 -1
- package/src/manager/connector/lifecycle.ts +364 -24
- package/src/manager/connector/tenant.ts +56 -23
- package/src/manager/goal/activation.ts +52 -0
- package/src/manager/index.ts +10 -2
- package/src/manager/run/persistence.ts +6 -1
- package/src/manager/topic/dependency.ts +39 -0
- package/src/manager/topic/lifecycle.ts +19 -31
- package/src/plugin/index.ts +1 -0
- package/src/plugin/lifecycle.ts +180 -39
- package/src/plugin/loader.ts +70 -13
- package/src/provider/collect-chat-completion.ts +3 -0
- package/src/provider/fallback.ts +79 -11
- package/src/provider/idle-timeout.ts +143 -17
- package/src/provider/index.ts +2 -0
- package/src/provider/instrumentation.ts +1 -0
- package/src/provider/retry.ts +16 -1
- package/src/public-runtime.ts +190 -32
- package/src/public-tools.ts +5 -0
- package/src/public-types.ts +85 -11
- package/src/rag/embedding.ts +147 -19
- package/src/rag/index.ts +1 -1
- package/src/rag/ingestion.ts +16 -2
- package/src/rag/knowledge-base.ts +13 -4
- package/src/rag/operation.ts +28 -0
- package/src/rag/rag-tool.ts +6 -3
- package/src/rag/retriever.ts +62 -11
- package/src/rag/vector-store.ts +8 -2
- package/src/registry/command/kernel-commands.ts +223 -4
- package/src/run/reporter.ts +10 -0
- package/src/run-query/index.ts +84 -15
- package/src/runtime/query/context.ts +13 -3
- package/src/runtime/query/executor.ts +90 -17
- package/src/runtime/query/guard.ts +12 -0
- package/src/runtime/query/index.ts +652 -103
- package/src/runtime/query/iteration/index.ts +89 -13
- package/src/runtime/query/iteration/phases/compaction.ts +120 -55
- package/src/runtime/query/iteration/phases/context.ts +4 -0
- package/src/runtime/query/iteration/phases/tool-review.ts +28 -0
- package/src/runtime/query/iteration/stream-turn.ts +3 -0
- package/src/runtime/query/project-instructions.ts +212 -0
- package/src/runtime/query/request-rich-content.ts +153 -0
- package/src/runtime/query/result.ts +12 -1
- package/src/runtime/query/resume-pending.ts +20 -18
- package/src/runtime/query/resume-run.ts +52 -8
- package/src/runtime/query/run-state.ts +11 -1
- package/src/runtime/query/sandbox-lifecycle.ts +210 -0
- package/src/sandbox/isolation.ts +9 -0
- package/src/sandbox/provider/local.ts +255 -90
- package/src/sandbox/terminal.ts +13 -5
- package/src/session/errors.ts +68 -42
- package/src/session/handoff/broadcast.ts +20 -14
- package/src/session/handoff/single.ts +14 -13
- package/src/store/attachment/index.ts +65 -3
- package/src/store/feedback/conformance.ts +39 -0
- package/src/store/feedback/disk.ts +128 -82
- package/src/store/goal/index.ts +594 -0
- package/src/store/index.ts +1 -1
- package/src/store/kv/revision-record-store.ts +346 -0
- package/src/store/memory/disk.ts +288 -113
- package/src/store/run/disk.ts +96 -5
- package/src/store/run/memory.ts +22 -2
- package/src/store/session/disk.ts +93 -6
- package/src/store/session/memory.ts +22 -0
- package/src/store/topic/memory.ts +4 -5
- package/src/store/topic/objective.ts +215 -100
- package/src/store/topic/state.ts +100 -63
- package/src/tools/builtins/bash.ts +21 -0
- package/src/tools/builtins/computer-use.ts +9 -1
- package/src/tools/builtins/content-fingerprint.ts +9 -12
- package/src/tools/builtins/edit.ts +190 -27
- package/src/tools/builtins/write-file.ts +55 -19
- package/src/tools/command-arguments.ts +54 -0
- package/src/tools/coordinator/index.ts +4 -1
- package/src/tools/defineTool.ts +11 -0
- package/src/tools/env-scrub.ts +7 -5
- package/src/tools/goal/index.ts +129 -0
- package/src/tools/memory/index.ts +26 -3
- package/src/tools/memory/search.ts +20 -3
- package/src/types/agent/base.ts +12 -3
- package/src/types/agent/factory.ts +2 -0
- package/src/types/agent/reactive.ts +2 -0
- package/src/types/agent/supervisor.ts +6 -0
- package/src/types/agent/task.ts +6 -2
- package/src/types/connector/core.ts +13 -8
- package/src/types/connector/definition.ts +54 -20
- package/src/types/connector/http.ts +7 -0
- package/src/types/connector/mcp.ts +27 -6
- package/src/types/connector/tenant.ts +21 -7
- package/src/types/connector/webhook.ts +7 -0
- package/src/types/goal/index.ts +50 -0
- package/src/types/ids/index.ts +2 -0
- package/src/types/message/index.ts +143 -9
- package/src/types/plugin/index.ts +7 -5
- package/src/types/provider/chat.ts +35 -4
- package/src/types/provider/interface.ts +22 -7
- package/src/types/provider/stream.ts +6 -0
- package/src/types/rag/embedding.ts +16 -2
- package/src/types/rag/ingestion.ts +2 -1
- package/src/types/rag/knowledge-base.ts +7 -3
- package/src/types/rag/retrieval.ts +2 -1
- package/src/types/rag/scope.ts +5 -0
- package/src/types/rag/vector.ts +5 -2
- package/src/types/run/config.ts +20 -0
- package/src/types/run/events.ts +28 -3
- package/src/types/run/metadata.ts +2 -0
- package/src/types/run/step.ts +2 -7
- package/src/types/run/store.ts +60 -2
- package/src/types/sandbox/index.ts +57 -14
- package/src/types/session/store.ts +18 -0
- package/src/types/tool/index.ts +33 -11
- package/src/types/topic/entity.ts +3 -4
- package/src/types/topic/store.ts +3 -3
- package/src/utils/id.ts +6 -0
- package/src/utils/process-environment.ts +101 -0
- package/src/vault/InMemoryCredentialVault.ts +29 -4
- package/src/vault/instrumentation.ts +24 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util'
|
|
2
|
+
|
|
3
|
+
import { NamzuError } from '../../types/errors/index.js'
|
|
4
|
+
import type { RunId } from '../../types/ids/index.js'
|
|
5
|
+
import {
|
|
6
|
+
type Message,
|
|
7
|
+
type UserMessage,
|
|
8
|
+
isProjectInstructionMessageSource,
|
|
9
|
+
} from '../../types/message/index.js'
|
|
10
|
+
import type { ToolResult } from '../../types/tool/index.js'
|
|
11
|
+
|
|
12
|
+
/** One real registry execution, after retries and its terminal event. */
|
|
13
|
+
export interface ToolResultObservation {
|
|
14
|
+
readonly runId: RunId
|
|
15
|
+
readonly toolUseId: string
|
|
16
|
+
readonly toolName: string
|
|
17
|
+
readonly input: unknown
|
|
18
|
+
readonly result: ToolResult
|
|
19
|
+
/** Present when another tool dispatched this call. */
|
|
20
|
+
readonly parentToolUseId?: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Authority and durable conversation visible to one host policy callback. */
|
|
24
|
+
export interface ProjectInstructionCallbackContext {
|
|
25
|
+
/** A snapshot of the messages accepted before this callback starts. */
|
|
26
|
+
readonly messages: readonly Message[]
|
|
27
|
+
/** The run-owned cancellation signal for any host I/O the callback starts. */
|
|
28
|
+
readonly signal: AbortSignal
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type ProjectInstructionSnapshotUpdate = UserMessage | null | undefined
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Host-owned live project policy for one run.
|
|
35
|
+
*
|
|
36
|
+
* Tool results are observed only after the registry has produced its final
|
|
37
|
+
* result and the complete tool-result batch is in `context.messages`. Each
|
|
38
|
+
* accepted observation returns its desired complete snapshot and the loop
|
|
39
|
+
* persists it before entering the next observation. `undefined` means no
|
|
40
|
+
* change; `null` explicitly removes the old snapshot.
|
|
41
|
+
*
|
|
42
|
+
* Callbacks must derive publication decisions from `context.messages`, not
|
|
43
|
+
* advance a private "published" cursor before returning: cancellation may win
|
|
44
|
+
* after host work finishes but before the returned value is accepted.
|
|
45
|
+
*/
|
|
46
|
+
export interface ProjectInstructionContext {
|
|
47
|
+
/**
|
|
48
|
+
* Rebuild the first-request snapshot from host authority. Persisted source
|
|
49
|
+
* paths may guide discovery; persisted policy text must not be trusted.
|
|
50
|
+
* `undefined` leaves history unchanged, while `null` removes stale state.
|
|
51
|
+
*/
|
|
52
|
+
prepareInitialSnapshot?(
|
|
53
|
+
context: ProjectInstructionCallbackContext,
|
|
54
|
+
): ProjectInstructionSnapshotUpdate | Promise<ProjectInstructionSnapshotUpdate>
|
|
55
|
+
observeToolResult(
|
|
56
|
+
observation: ToolResultObservation,
|
|
57
|
+
context: ProjectInstructionCallbackContext,
|
|
58
|
+
): ProjectInstructionSnapshotUpdate | Promise<ProjectInstructionSnapshotUpdate>
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Await opaque host work without giving it ownership of run cancellation.
|
|
63
|
+
*
|
|
64
|
+
* The callback receives the signal for cooperative cleanup. The independent
|
|
65
|
+
* settlement boundary is still required: a host implementation that ignores
|
|
66
|
+
* the signal may continue its own work, but it cannot keep Namzu pending or
|
|
67
|
+
* publish a value after authority was withdrawn.
|
|
68
|
+
*/
|
|
69
|
+
export async function awaitProjectInstructionCallback<T>(
|
|
70
|
+
signal: AbortSignal,
|
|
71
|
+
start: () => T | Promise<T>,
|
|
72
|
+
): Promise<T> {
|
|
73
|
+
signal.throwIfAborted()
|
|
74
|
+
|
|
75
|
+
return new Promise<T>((resolve, reject) => {
|
|
76
|
+
let settled = false
|
|
77
|
+
const cleanup = (): void => signal.removeEventListener('abort', onAbort)
|
|
78
|
+
const rejectOnce = (reason: unknown): void => {
|
|
79
|
+
if (settled) return
|
|
80
|
+
settled = true
|
|
81
|
+
cleanup()
|
|
82
|
+
reject(reason)
|
|
83
|
+
}
|
|
84
|
+
const resolveOnce = (value: T): void => {
|
|
85
|
+
if (settled) return
|
|
86
|
+
settled = true
|
|
87
|
+
cleanup()
|
|
88
|
+
resolve(value)
|
|
89
|
+
}
|
|
90
|
+
// Abort delivery is synchronous. This first-cause latch decides whether
|
|
91
|
+
// host completion or authority withdrawal owns publication, even when
|
|
92
|
+
// both happen in the same event-loop turn.
|
|
93
|
+
const onAbort = (): void => rejectOnce(signal.reason)
|
|
94
|
+
|
|
95
|
+
signal.addEventListener('abort', onAbort, { once: true })
|
|
96
|
+
try {
|
|
97
|
+
Promise.resolve(start()).then(resolveOnce, rejectOnce)
|
|
98
|
+
} catch (error) {
|
|
99
|
+
rejectOnce(error)
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function isProjectInstructionMessage(message: Message): message is UserMessage {
|
|
105
|
+
return (
|
|
106
|
+
message.role === 'user' &&
|
|
107
|
+
message.source?.type === 'project-instructions' &&
|
|
108
|
+
isProjectInstructionMessageSource(message.source)
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function assertsProjectInstructionMessage(message: UserMessage): asserts message is UserMessage & {
|
|
113
|
+
readonly source: {
|
|
114
|
+
readonly type: 'project-instructions'
|
|
115
|
+
readonly files: readonly string[]
|
|
116
|
+
}
|
|
117
|
+
} {
|
|
118
|
+
if (!isProjectInstructionMessage(message)) {
|
|
119
|
+
throw new NamzuError({
|
|
120
|
+
code: 'invalid_config',
|
|
121
|
+
message:
|
|
122
|
+
'A project-instruction snapshot must be a user message with valid project-relative provenance.',
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Keep only the latest structurally valid project snapshot, at its own
|
|
129
|
+
* chronological position. Invalid tagged provenance refuses before a provider
|
|
130
|
+
* can be called; an untrusted persisted object cannot acquire policy status by
|
|
131
|
+
* spelling one discriminator.
|
|
132
|
+
*/
|
|
133
|
+
export function collapseProjectInstructionSnapshots(messages: readonly Message[]): Message[] {
|
|
134
|
+
let latest = -1
|
|
135
|
+
for (let index = 0; index < messages.length; index += 1) {
|
|
136
|
+
const message = messages[index]
|
|
137
|
+
if (message?.role !== 'user' || message.source?.type !== 'project-instructions') continue
|
|
138
|
+
assertsProjectInstructionMessage(message)
|
|
139
|
+
latest = index
|
|
140
|
+
}
|
|
141
|
+
if (latest < 0) return [...messages]
|
|
142
|
+
return messages.flatMap((message, index) => {
|
|
143
|
+
if (message.role === 'user' && message.source?.type === 'project-instructions') {
|
|
144
|
+
return index === latest
|
|
145
|
+
? [message.retain === true ? message : { ...message, retain: true }]
|
|
146
|
+
: []
|
|
147
|
+
}
|
|
148
|
+
return [message]
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Replace project policy without mutating the caller's history.
|
|
154
|
+
*
|
|
155
|
+
* Runtime updates append after the finalized tool batch. A host seeding a new
|
|
156
|
+
* human turn uses `before-latest-user`, so the policy is context for that
|
|
157
|
+
* request rather than a reply after it.
|
|
158
|
+
*/
|
|
159
|
+
export function replaceProjectInstructionSnapshot(
|
|
160
|
+
messages: readonly Message[],
|
|
161
|
+
snapshot: UserMessage | null,
|
|
162
|
+
placement: 'append' | 'before-latest-user' = 'append',
|
|
163
|
+
): Message[] {
|
|
164
|
+
if (snapshot) assertsProjectInstructionMessage(snapshot)
|
|
165
|
+
// Validate every tagged predecessor before removing it. A host-authoritative
|
|
166
|
+
// replacement must not turn malformed persisted provenance into a silent
|
|
167
|
+
// success merely because the bad record happens to be superseded.
|
|
168
|
+
const validated = collapseProjectInstructionSnapshots(messages)
|
|
169
|
+
let current: UserMessage | undefined
|
|
170
|
+
for (let index = validated.length - 1; index >= 0; index -= 1) {
|
|
171
|
+
const message = validated[index]
|
|
172
|
+
if (message && isProjectInstructionMessage(message)) {
|
|
173
|
+
current = message
|
|
174
|
+
break
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (
|
|
178
|
+
snapshot !== null &&
|
|
179
|
+
current !== undefined &&
|
|
180
|
+
isDeepStrictEqual(
|
|
181
|
+
{
|
|
182
|
+
content: current.content,
|
|
183
|
+
attachments: current.attachments,
|
|
184
|
+
source: current.source,
|
|
185
|
+
cacheHint: current.cacheHint,
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
content: snapshot.content,
|
|
189
|
+
attachments: snapshot.attachments,
|
|
190
|
+
source: snapshot.source,
|
|
191
|
+
cacheHint: snapshot.cacheHint,
|
|
192
|
+
},
|
|
193
|
+
)
|
|
194
|
+
) {
|
|
195
|
+
return validated
|
|
196
|
+
}
|
|
197
|
+
if (snapshot === null && current === undefined) return validated
|
|
198
|
+
const without = validated.filter(
|
|
199
|
+
(message) => !(message.role === 'user' && message.source?.type === 'project-instructions'),
|
|
200
|
+
)
|
|
201
|
+
if (!snapshot) return without
|
|
202
|
+
const retained = snapshot.retain === true ? snapshot : { ...snapshot, retain: true }
|
|
203
|
+
if (placement === 'append') return [...without, retained]
|
|
204
|
+
let insertion = without.length
|
|
205
|
+
for (let index = without.length - 1; index >= 0; index -= 1) {
|
|
206
|
+
if (without[index]?.role === 'user') {
|
|
207
|
+
insertion = index
|
|
208
|
+
break
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return [...without.slice(0, insertion), retained, ...without.slice(insertion)]
|
|
212
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { Message, MessageAttachment, ToolResultBlock } from '../../types/message/index.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Maximum accumulated inline rich-content payload sent on one model request.
|
|
5
|
+
*
|
|
6
|
+
* Base64 is ASCII, so its JavaScript string length is also its encoded wire
|
|
7
|
+
* payload length before the surrounding JSON. The bound deliberately counts
|
|
8
|
+
* the encoded value rather than estimating decoded bytes: request gateways
|
|
9
|
+
* reject the body they receive, not the file the body represents.
|
|
10
|
+
*/
|
|
11
|
+
export const DEFAULT_MAX_REQUEST_RICH_CONTENT_BYTES = 24 * 1024 * 1024
|
|
12
|
+
|
|
13
|
+
const MAX_REQUEST_RICH_CONTENT_BYTES = Number.MAX_SAFE_INTEGER
|
|
14
|
+
|
|
15
|
+
export function resolveMaxRequestRichContentBytes(value: number | undefined): number {
|
|
16
|
+
const resolved = value ?? DEFAULT_MAX_REQUEST_RICH_CONTENT_BYTES
|
|
17
|
+
if (
|
|
18
|
+
!Number.isSafeInteger(resolved) ||
|
|
19
|
+
resolved < 0 ||
|
|
20
|
+
resolved > MAX_REQUEST_RICH_CONTENT_BYTES
|
|
21
|
+
) {
|
|
22
|
+
throw new RangeError(
|
|
23
|
+
`maxRequestRichContentBytes must be a safe integer from 0 to ${MAX_REQUEST_RICH_CONTENT_BYTES}; received ${String(resolved)}`,
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
return resolved
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type RichKind = 'image' | 'document'
|
|
30
|
+
|
|
31
|
+
interface RichOccurrence {
|
|
32
|
+
readonly messageIndex: number
|
|
33
|
+
readonly itemIndex: number
|
|
34
|
+
readonly source: 'user' | 'tool'
|
|
35
|
+
readonly kind: RichKind
|
|
36
|
+
readonly bytes: number
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const userMarker = (kind: RichKind): string =>
|
|
40
|
+
`[${kind} omitted from this model request to keep the accumulated rich-content payload within its configured size limit; attach it again in a new message if it is still needed.]`
|
|
41
|
+
|
|
42
|
+
const toolMarker = (kind: RichKind): string =>
|
|
43
|
+
`[${kind} omitted from this model request to keep the accumulated rich-content payload within its configured size limit; call the producing tool again if it is still needed.]`
|
|
44
|
+
|
|
45
|
+
function assertInlineAttachment(
|
|
46
|
+
attachment: MessageAttachment,
|
|
47
|
+
): asserts attachment is Exclude<MessageAttachment, { readonly type: 'stored' }> {
|
|
48
|
+
if (attachment.type === 'stored') {
|
|
49
|
+
throw new TypeError(
|
|
50
|
+
'Cannot budget an unresolved stored attachment; resolve attachment bytes before building a model request',
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function collectRichOccurrences(messages: readonly Message[]): RichOccurrence[] {
|
|
56
|
+
const occurrences: RichOccurrence[] = []
|
|
57
|
+
|
|
58
|
+
for (const [messageIndex, message] of messages.entries()) {
|
|
59
|
+
if (message.role === 'user') {
|
|
60
|
+
for (const [itemIndex, attachment] of (message.attachments ?? []).entries()) {
|
|
61
|
+
assertInlineAttachment(attachment)
|
|
62
|
+
occurrences.push({
|
|
63
|
+
messageIndex,
|
|
64
|
+
itemIndex,
|
|
65
|
+
source: 'user',
|
|
66
|
+
kind: attachment.type === 'document' ? 'document' : 'image',
|
|
67
|
+
bytes: attachment.data.length,
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
continue
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (message.role !== 'tool' || !Array.isArray(message.content)) continue
|
|
74
|
+
for (const [itemIndex, block] of message.content.entries()) {
|
|
75
|
+
if (block.type !== 'image' && block.type !== 'document') continue
|
|
76
|
+
occurrences.push({
|
|
77
|
+
messageIndex,
|
|
78
|
+
itemIndex,
|
|
79
|
+
source: 'tool',
|
|
80
|
+
kind: block.type,
|
|
81
|
+
bytes: block.data.length,
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return occurrences
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function appendMarkers(content: string, kinds: readonly RichKind[]): string {
|
|
90
|
+
if (kinds.length === 0) return content
|
|
91
|
+
const markers = kinds.map(userMarker).join('\n\n')
|
|
92
|
+
return content.length > 0 ? `${content}\n\n${markers}` : markers
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Build the provider-bound view of a conversation without editing history.
|
|
97
|
+
*
|
|
98
|
+
* User attachments and rich tool-result blocks share one oldest-first budget.
|
|
99
|
+
* Tool messages and their `toolCallId` are never removed, so the projected
|
|
100
|
+
* transcript retains its provider-valid call/result structure. Returning the
|
|
101
|
+
* original array when nothing is omitted makes the no-op and exact-boundary
|
|
102
|
+
* cases observable and keeps the common path allocation-free.
|
|
103
|
+
*/
|
|
104
|
+
export function projectRequestRichContent(messages: Message[], maxBytes: number): Message[] {
|
|
105
|
+
const occurrences = collectRichOccurrences(messages)
|
|
106
|
+
if (maxBytes === 0 || occurrences.length === 0) return messages
|
|
107
|
+
|
|
108
|
+
let total = occurrences.reduce((sum, occurrence) => sum + occurrence.bytes, 0)
|
|
109
|
+
if (total <= maxBytes) return messages
|
|
110
|
+
|
|
111
|
+
const omitted = new Map<number, Map<number, RichOccurrence>>()
|
|
112
|
+
for (const occurrence of occurrences) {
|
|
113
|
+
if (total <= maxBytes) break
|
|
114
|
+
total -= occurrence.bytes
|
|
115
|
+
let byItem = omitted.get(occurrence.messageIndex)
|
|
116
|
+
if (!byItem) {
|
|
117
|
+
byItem = new Map()
|
|
118
|
+
omitted.set(occurrence.messageIndex, byItem)
|
|
119
|
+
}
|
|
120
|
+
byItem.set(occurrence.itemIndex, occurrence)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return messages.map((message, messageIndex) => {
|
|
124
|
+
const byItem = omitted.get(messageIndex)
|
|
125
|
+
if (!byItem) return message
|
|
126
|
+
|
|
127
|
+
if (message.role === 'user') {
|
|
128
|
+
const { attachments = [], ...withoutAttachments } = message
|
|
129
|
+
const kept = attachments.filter((_attachment, itemIndex) => !byItem.has(itemIndex))
|
|
130
|
+
const omittedKinds = [...byItem.values()]
|
|
131
|
+
.filter((occurrence) => occurrence.source === 'user')
|
|
132
|
+
.sort((a, b) => a.itemIndex - b.itemIndex)
|
|
133
|
+
.map((occurrence) => occurrence.kind)
|
|
134
|
+
return {
|
|
135
|
+
...withoutAttachments,
|
|
136
|
+
content: appendMarkers(message.content, omittedKinds),
|
|
137
|
+
...(kept.length > 0 ? { attachments: kept } : {}),
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (message.role === 'tool' && Array.isArray(message.content)) {
|
|
142
|
+
const content: ToolResultBlock[] = message.content.map((block, itemIndex) => {
|
|
143
|
+
const occurrence = byItem.get(itemIndex)
|
|
144
|
+
return occurrence?.source === 'tool'
|
|
145
|
+
? { type: 'text', text: toolMarker(occurrence.kind) }
|
|
146
|
+
: block
|
|
147
|
+
})
|
|
148
|
+
return { ...message, content }
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return message
|
|
152
|
+
})
|
|
153
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Span, SpanStatusCode } from '@opentelemetry/api'
|
|
2
2
|
import type { PlanManager } from '../../manager/plan/lifecycle.js'
|
|
3
3
|
import type { RunPersistence } from '../../manager/run/persistence.js'
|
|
4
|
-
import { isProviderRequestError } from '../../provider/errors.js'
|
|
4
|
+
import { isCallerAbortError, isProviderRequestError } from '../../provider/errors.js'
|
|
5
5
|
import type { ActivityStore } from '../../store/activity/memory.js'
|
|
6
6
|
import { GENAI, NAMZU } from '../../telemetry/attributes.js'
|
|
7
7
|
import { explainError } from '../../types/errors/catalog.js'
|
|
@@ -122,6 +122,17 @@ export class ResultAssembler {
|
|
|
122
122
|
|
|
123
123
|
async *handleError(err: unknown, rootSpan: Span): AsyncGenerator<RunEvent> {
|
|
124
124
|
const { runMgr, planManager, log, emitEvent, drainPending } = this.config
|
|
125
|
+
if (isCallerAbortError(err, this.config.signal)) {
|
|
126
|
+
// Cancellation may happen before the iteration loop owns control —
|
|
127
|
+
// project preparation, a run-start hook and a pre-model hook all sit
|
|
128
|
+
// outside its catch. The loop already settles its own aborts, but an
|
|
129
|
+
// abort escaping one of these boundaries reached the outer catch and
|
|
130
|
+
// was historically rewritten as a run failure. Preserve the caller's
|
|
131
|
+
// control-flow verdict and let the normal terminal-event path report it.
|
|
132
|
+
runMgr.markCancelled()
|
|
133
|
+
yield* this.completeRun(rootSpan)
|
|
134
|
+
return
|
|
135
|
+
}
|
|
125
136
|
const errorMessage = toErrorMessage(err)
|
|
126
137
|
// The classifier at the provider boundary already walked the cause
|
|
127
138
|
// chain over status, errno and `Retry-After`, so a fully-populated
|
|
@@ -86,7 +86,7 @@ export function planPendingResume(
|
|
|
86
86
|
return null
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
const assistant =
|
|
89
|
+
const assistant = lastUnansweredBatch(checkpoint.messages)?.assistant
|
|
90
90
|
if (!assistant?.toolCalls || assistant.toolCalls.length === 0) {
|
|
91
91
|
log.warn('Checkpoint records a tool_review park but has no unanswered tool calls', {
|
|
92
92
|
'namzu.checkpoint.id': checkpoint.id,
|
|
@@ -142,7 +142,7 @@ function planQuestionResume(
|
|
|
142
142
|
questionId: string,
|
|
143
143
|
log: Logger,
|
|
144
144
|
): PendingResumePlan | null {
|
|
145
|
-
const assistant =
|
|
145
|
+
const assistant = lastUnansweredBatch(checkpoint.messages)?.assistant
|
|
146
146
|
if (!assistant?.toolCalls || assistant.toolCalls.length === 0) {
|
|
147
147
|
log.warn('Checkpoint records a question park but has no unanswered tool calls', {
|
|
148
148
|
'namzu.checkpoint.id': checkpoint.id,
|
|
@@ -207,7 +207,7 @@ export function planCrashResume(
|
|
|
207
207
|
completed: ReadonlyMap<string, unknown>,
|
|
208
208
|
log: Logger,
|
|
209
209
|
): PendingResumePlan | null {
|
|
210
|
-
const assistant =
|
|
210
|
+
const assistant = lastUnansweredBatch(checkpoint.messages)?.assistant
|
|
211
211
|
const calls = assistant?.toolCalls
|
|
212
212
|
if (!assistant || !calls || calls.length === 0) return null
|
|
213
213
|
|
|
@@ -376,29 +376,31 @@ function synthesizeResponse(assistant: AssistantMessage): ChatCompletionResponse
|
|
|
376
376
|
* result is in the history and needs no recovery.
|
|
377
377
|
*/
|
|
378
378
|
export function unansweredToolCalls(messages: readonly Message[]): ToolCall[] {
|
|
379
|
-
|
|
380
|
-
if (!assistant?.toolCalls) return []
|
|
381
|
-
|
|
382
|
-
const answered = new Set<string>()
|
|
383
|
-
for (const msg of messages) {
|
|
384
|
-
if (msg.role === 'tool' && msg.toolCallId) answered.add(msg.toolCallId)
|
|
385
|
-
}
|
|
386
|
-
return assistant.toolCalls.filter((tc) => !answered.has(tc.id))
|
|
379
|
+
return lastUnansweredBatch(messages)?.unanswered ?? []
|
|
387
380
|
}
|
|
388
381
|
|
|
389
|
-
function
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
if (msg.role === 'tool' && msg.toolCallId) answered.add(msg.toolCallId)
|
|
393
|
-
}
|
|
394
|
-
|
|
382
|
+
function lastUnansweredBatch(
|
|
383
|
+
messages: readonly Message[],
|
|
384
|
+
): { readonly assistant: AssistantMessage; readonly unanswered: ToolCall[] } | null {
|
|
395
385
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
396
386
|
const msg = messages[i]
|
|
397
387
|
if (msg?.role !== 'assistant') continue
|
|
398
388
|
const assistant = msg as AssistantMessage
|
|
399
389
|
const calls = assistant.toolCalls
|
|
400
390
|
if (!calls || calls.length === 0) continue
|
|
401
|
-
|
|
391
|
+
|
|
392
|
+
// Only the contiguous result run immediately after this assistant owns
|
|
393
|
+
// its calls. A future/displaced result cannot prove the call completed;
|
|
394
|
+
// treating it as one would skip both crash recovery and the conservative
|
|
395
|
+
// synthetic outcome that prevents a blind side-effect retry.
|
|
396
|
+
const answered = new Set<string>()
|
|
397
|
+
for (let resultIndex = i + 1; resultIndex < messages.length; resultIndex++) {
|
|
398
|
+
const result = messages[resultIndex]
|
|
399
|
+
if (result?.role !== 'tool') break
|
|
400
|
+
answered.add(result.toolCallId)
|
|
401
|
+
}
|
|
402
|
+
const unanswered = calls.filter((call) => !answered.has(call.id))
|
|
403
|
+
if (unanswered.length > 0) return { assistant, unanswered }
|
|
402
404
|
return null
|
|
403
405
|
}
|
|
404
406
|
return null
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { NamzuError } from '../../types/errors/index.js'
|
|
1
2
|
import type { PendingDecision } from '../../types/hitl/index.js'
|
|
2
3
|
import type { CheckpointStore, FencingToken } from '../../types/run/checkpoint-store.js'
|
|
3
4
|
import type { Run } from '../../types/run/entity.js'
|
|
4
5
|
import type { RunEventReplay } from '../../types/run/event-cursor.js'
|
|
5
6
|
import type { RunEventListener } from '../../types/run/events.js'
|
|
6
7
|
import type { RunState } from '../../types/run/state.js'
|
|
7
|
-
import { type QueryParams,
|
|
8
|
-
import { type RunStateScope,
|
|
8
|
+
import { type QueryParams, drainQueryWithSelectedResumeState } from './index.js'
|
|
9
|
+
import { type RunStateScope, loadSelectedRunState } from './run-state.js'
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* What a resume attempt found.
|
|
@@ -117,24 +118,35 @@ export async function resumeRun(params: ResumeRunParams): Promise<ResumeOutcome>
|
|
|
117
118
|
...rest
|
|
118
119
|
} = params
|
|
119
120
|
|
|
120
|
-
const
|
|
121
|
-
|
|
121
|
+
const selected = await loadSelectedRunState(checkpointStore, scope, checkpointId)
|
|
122
|
+
const state = selected?.state
|
|
123
|
+
if (!state?.checkpointId || !selected) return { resumed: false, reason: 'no-checkpoint' }
|
|
124
|
+
assertResumeRequestAttribution(params, state)
|
|
122
125
|
|
|
123
126
|
// A park is outstanding until it is answered. `resolvedAt` is what marks
|
|
124
127
|
// an answered one, so a checkpoint that carries a resolved decision is an
|
|
125
128
|
// ordinary resume, not a question waiting on anybody.
|
|
126
129
|
const outstanding = state.pending && !state.pending.resolvedAt ? state.pending : undefined
|
|
127
130
|
if (outstanding && !pendingDecision) {
|
|
128
|
-
return {
|
|
131
|
+
return {
|
|
132
|
+
resumed: false,
|
|
133
|
+
reason: 'awaiting-decision',
|
|
134
|
+
pending: outstanding,
|
|
135
|
+
state,
|
|
136
|
+
}
|
|
129
137
|
}
|
|
130
138
|
|
|
131
139
|
let replay: RunEventReplay | undefined
|
|
132
140
|
|
|
133
|
-
const run = await
|
|
141
|
+
const run = await drainQueryWithSelectedResumeState(
|
|
134
142
|
{
|
|
135
143
|
...rest,
|
|
136
144
|
messages: [],
|
|
137
145
|
runId: state.runId,
|
|
146
|
+
sessionId: state.sessionId,
|
|
147
|
+
topicId: state.topicId,
|
|
148
|
+
projectId: state.projectId,
|
|
149
|
+
tenantId: state.tenantId,
|
|
138
150
|
// Forwarded, and it is not cosmetic: the run store nests a sub-run's
|
|
139
151
|
// evidence under `<parent>/children/<run>`, so resuming a sub-run
|
|
140
152
|
// without this binds `<base>/<run>` instead — a second, empty
|
|
@@ -148,11 +160,43 @@ export async function resumeRun(params: ResumeRunParams): Promise<ResumeOutcome>
|
|
|
148
160
|
...(pendingDecision ? { pendingDecision } : {}),
|
|
149
161
|
onEventReplay: (verdict: RunEventReplay) => {
|
|
150
162
|
replay = verdict
|
|
151
|
-
onEventReplay?.(verdict)
|
|
163
|
+
return onEventReplay?.(verdict)
|
|
152
164
|
},
|
|
153
165
|
} as QueryParams,
|
|
166
|
+
{
|
|
167
|
+
...state,
|
|
168
|
+
checkpointId: state.checkpointId,
|
|
169
|
+
...(selected.checkpoint.traceContext
|
|
170
|
+
? { traceContext: selected.checkpoint.traceContext }
|
|
171
|
+
: {}),
|
|
172
|
+
},
|
|
154
173
|
listener,
|
|
155
174
|
)
|
|
156
175
|
|
|
157
|
-
return {
|
|
176
|
+
return {
|
|
177
|
+
resumed: true,
|
|
178
|
+
run,
|
|
179
|
+
state,
|
|
180
|
+
...(replay !== undefined ? { replay } : {}),
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function assertResumeRequestAttribution(params: ResumeRunParams, state: RunState): void {
|
|
185
|
+
const mismatchedFields: string[] = []
|
|
186
|
+
if (params.scope.runId !== state.runId) mismatchedFields.push('runId')
|
|
187
|
+
if (params.sessionId !== state.sessionId) mismatchedFields.push('sessionId')
|
|
188
|
+
if (params.topicId !== state.topicId) mismatchedFields.push('topicId')
|
|
189
|
+
if (params.projectId !== state.projectId) mismatchedFields.push('projectId')
|
|
190
|
+
if (params.tenantId !== state.tenantId) mismatchedFields.push('tenantId')
|
|
191
|
+
if (params.parentRunId !== undefined && params.parentRunId !== state.parentRunId) {
|
|
192
|
+
mismatchedFields.push('parentRunId')
|
|
193
|
+
}
|
|
194
|
+
if (mismatchedFields.length === 0) return
|
|
195
|
+
|
|
196
|
+
throw new NamzuError({
|
|
197
|
+
code: 'invalid_config',
|
|
198
|
+
message:
|
|
199
|
+
'The resume request attribution does not match the checkpoint scope selected for this run.',
|
|
200
|
+
details: { fields: mismatchedFields },
|
|
201
|
+
})
|
|
158
202
|
}
|
|
@@ -88,13 +88,22 @@ export async function loadRunState(
|
|
|
88
88
|
scope: RunStateScope,
|
|
89
89
|
checkpointId?: CheckpointId,
|
|
90
90
|
): Promise<RunState | null> {
|
|
91
|
+
return (await loadSelectedRunState(store, scope, checkpointId))?.state ?? null
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** @internal The exact checkpoint selected together with its public run-state projection. */
|
|
95
|
+
export async function loadSelectedRunState(
|
|
96
|
+
store: CheckpointStore,
|
|
97
|
+
scope: RunStateScope,
|
|
98
|
+
checkpointId?: CheckpointId,
|
|
99
|
+
): Promise<{ readonly state: RunState; readonly checkpoint: IterationCheckpoint } | null> {
|
|
91
100
|
const checkpoint = checkpointId
|
|
92
101
|
? await store.readCheckpoint(scope, checkpointId)
|
|
93
102
|
: ((await findPendingCheckpoint(store, scope)) ?? (await newest(store, scope)))
|
|
94
103
|
|
|
95
104
|
if (!checkpoint) return null
|
|
96
105
|
|
|
97
|
-
|
|
106
|
+
const state: RunState = {
|
|
98
107
|
version: RUN_STATE_VERSION,
|
|
99
108
|
runId: checkpoint.runId,
|
|
100
109
|
sessionId: scope.sessionId,
|
|
@@ -113,6 +122,7 @@ export async function loadRunState(
|
|
|
113
122
|
...(checkpoint.pending ? { pending: checkpoint.pending } : {}),
|
|
114
123
|
capturedAt: Date.now(),
|
|
115
124
|
}
|
|
125
|
+
return { state, checkpoint }
|
|
116
126
|
}
|
|
117
127
|
|
|
118
128
|
async function newest(
|