@namzu/sdk 30.2.0 → 31.1.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 +562 -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 +79 -13
- 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/index.d.ts +1 -1
- package/dist/types/provider/index.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/model.d.ts +12 -0
- package/dist/types/provider/model.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 +147 -12
- package/src/types/plugin/index.ts +7 -5
- package/src/types/provider/chat.ts +35 -4
- package/src/types/provider/index.ts +1 -1
- package/src/types/provider/interface.ts +22 -7
- package/src/types/provider/model.ts +13 -0
- 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
|
@@ -2,7 +2,7 @@ import { join } from 'node:path';
|
|
|
2
2
|
import { AdvisorRegistry, AdvisoryContext, AdvisoryExecutor, TriggerEvaluator, assertBudgetEnforceable, } from '../../advisory/index.js';
|
|
3
3
|
import { drainQueuedMessages } from '../../agents/handle.js';
|
|
4
4
|
import { AuthorizationGate } from '../../authorization/gate.js';
|
|
5
|
-
import {
|
|
5
|
+
import { repairToolMessageHistory, toolHistoryRepairChanged, } from '../../compaction/dangling.js';
|
|
6
6
|
import { extractFromUserMessage } from '../../compaction/extractor.js';
|
|
7
7
|
import { WorkingStateManager } from '../../compaction/manager.js';
|
|
8
8
|
import { serializeState as serializeWorkingState } from '../../compaction/serializer.js';
|
|
@@ -13,6 +13,7 @@ import { EmergencySaveManager } from '../../manager/run/emergency.js';
|
|
|
13
13
|
import { resolveModelPricing } from '../../pricing/index.js';
|
|
14
14
|
import { resolveProviderCapabilities } from '../../provider/capabilities.js';
|
|
15
15
|
import { withProviderFallback, } from '../../provider/fallback.js';
|
|
16
|
+
import { resolveStreamIdleTimeoutMs, withStreamIdleTimeout } from '../../provider/idle-timeout.js';
|
|
16
17
|
import { withProviderRetry } from '../../provider/retry.js';
|
|
17
18
|
import { DefaultFilesystemMigrator, loggingMigrationSink } from '../../session/migration/index.js';
|
|
18
19
|
import { resolveAttachments } from '../../store/attachment/index.js';
|
|
@@ -25,7 +26,7 @@ import { STRUCTURED_OUTPUT_TOOL_NAME, createStructuredOutputTool, } from '../../
|
|
|
25
26
|
import { buildTaskTools } from '../../tools/task/index.js';
|
|
26
27
|
import { NamzuError } from '../../types/errors/index.js';
|
|
27
28
|
import { autoApproveHandler, } from '../../types/hitl/index.js';
|
|
28
|
-
import { createSystemMessage } from '../../types/message/index.js';
|
|
29
|
+
import { createSystemMessage, } from '../../types/message/index.js';
|
|
29
30
|
import { resolveRunEventReplay } from '../../types/run/event-cursor.js';
|
|
30
31
|
import { memoryCandidateFor } from '../../types/run/memory-promotion.js';
|
|
31
32
|
import { toErrorMessage } from '../../utils/error.js';
|
|
@@ -42,14 +43,18 @@ import { IterationOrchestrator } from './iteration/index.js';
|
|
|
42
43
|
import { isCompactionMessage } from './iteration/phases/compaction.js';
|
|
43
44
|
import { isWorkingMemoryMessage } from './iteration/phases/working-memory.js';
|
|
44
45
|
import { applyLifecycleHookResults } from './plugin-hooks.js';
|
|
46
|
+
import { awaitProjectInstructionCallback, collapseProjectInstructionSnapshots, replaceProjectInstructionSnapshot, } from './project-instructions.js';
|
|
45
47
|
import { PromptBuilder } from './prompt.js';
|
|
46
48
|
import { PendingAnswers, QuestionParkBinding } from './question-park.js';
|
|
47
49
|
import { RepeatCallTracker } from './repeat-call.js';
|
|
50
|
+
import { resolveMaxRequestRichContentBytes } from './request-rich-content.js';
|
|
48
51
|
import { ResultAssembler } from './result.js';
|
|
49
52
|
import { applyPendingResume, planCrashResume, planPendingResume, recoverCompletedCalls, unansweredToolCalls, } from './resume-pending.js';
|
|
53
|
+
import { acquireSandbox, resolveSandboxTeardownTimeoutMs, teardownSandbox, } from './sandbox-lifecycle.js';
|
|
50
54
|
import { ToolGrantSet } from './tool-grants.js';
|
|
51
55
|
import { createToolPause } from './tool-pause.js';
|
|
52
56
|
import { ToolingBootstrap } from './tooling.js';
|
|
57
|
+
const selectedResumeStates = new WeakMap();
|
|
53
58
|
/**
|
|
54
59
|
* Refuse to price a run whose tokens two differently-priced members may produce.
|
|
55
60
|
*
|
|
@@ -137,11 +142,47 @@ function assertBudgetIsMeasurable(params) {
|
|
|
137
142
|
* have worked on the table must not fail because a listing endpoint was
|
|
138
143
|
* down.
|
|
139
144
|
*/
|
|
140
|
-
async function resolveProviderContextWindow(provider, model, signal, log) {
|
|
145
|
+
async function resolveProviderContextWindow(provider, model, signal, timeoutMs, log) {
|
|
141
146
|
if (!provider.resolveContextWindow || !model)
|
|
142
147
|
return undefined;
|
|
148
|
+
if (signal?.aborted)
|
|
149
|
+
return undefined;
|
|
150
|
+
// The resolver is an optional optimisation that runs before RunContext
|
|
151
|
+
// owns its child controller. Give it a private deadline signal and fuse
|
|
152
|
+
// caller cancellation into that transport in the safe direction: neither
|
|
153
|
+
// outcome aborts the caller's controller. Passing a signal is necessary
|
|
154
|
+
// but not sufficient, because a third-party driver can accept it and still
|
|
155
|
+
// leave its promise pending; the race below makes fallback independent of
|
|
156
|
+
// driver cooperation. Promise.race keeps the losing provider promise
|
|
157
|
+
// observed, so a later rejection cannot become unhandled.
|
|
158
|
+
const deadline = new AbortController();
|
|
159
|
+
const resolverSignal = signal ? AbortSignal.any([signal, deadline.signal]) : deadline.signal;
|
|
160
|
+
const interrupted = Symbol('provider-context-window-interrupted');
|
|
161
|
+
let onAbort;
|
|
162
|
+
const interruption = new Promise((resolve) => {
|
|
163
|
+
onAbort = () => resolve(interrupted);
|
|
164
|
+
resolverSignal.addEventListener('abort', onAbort, { once: true });
|
|
165
|
+
});
|
|
166
|
+
// Wire and directory config validation already limit this field to one
|
|
167
|
+
// hour. The clamp also keeps a direct QueryParams caller from triggering
|
|
168
|
+
// Node's >2^31-1 one-millisecond timer coercion and turning a huge run
|
|
169
|
+
// budget into an immediate metadata fallback.
|
|
170
|
+
const deadlineMs = Math.min(Math.max(0, timeoutMs), 2_147_483_647);
|
|
171
|
+
const timer = setTimeout(() => {
|
|
172
|
+
deadline.abort(new Error(`Provider context-window lookup exceeded ${deadlineMs}ms`));
|
|
173
|
+
}, deadlineMs);
|
|
143
174
|
try {
|
|
144
|
-
const
|
|
175
|
+
const resolution = provider.resolveContextWindow(model, resolverSignal);
|
|
176
|
+
const reported = await Promise.race([resolution, interruption]);
|
|
177
|
+
if (reported === interrupted) {
|
|
178
|
+
if (deadline.signal.aborted) {
|
|
179
|
+
log.debug('Provider context-window lookup timed out; using the table', {
|
|
180
|
+
'namzu.model.id': model,
|
|
181
|
+
'namzu.runtime.timeout_ms': deadlineMs,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
145
186
|
return typeof reported === 'number' && reported > 0 ? reported : undefined;
|
|
146
187
|
}
|
|
147
188
|
catch (err) {
|
|
@@ -151,8 +192,61 @@ async function resolveProviderContextWindow(provider, model, signal, log) {
|
|
|
151
192
|
});
|
|
152
193
|
return undefined;
|
|
153
194
|
}
|
|
195
|
+
finally {
|
|
196
|
+
clearTimeout(timer);
|
|
197
|
+
if (onAbort)
|
|
198
|
+
resolverSignal.removeEventListener('abort', onAbort);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Project historical system messages exactly as a new run will persist them.
|
|
203
|
+
*
|
|
204
|
+
* Arbitrary historical prompt floors are rebuilt for this run and therefore
|
|
205
|
+
* never reach its provider-bound conversation. Repair must happen AFTER that
|
|
206
|
+
* removal: treating a soon-to-be-dropped system message as a tool-result
|
|
207
|
+
* boundary can replace an exact real result with an invented unknown outcome.
|
|
208
|
+
* The two state-bearing system forms survive; fresh inherited compaction is
|
|
209
|
+
* pinned until this run can prove it reconstructed equivalent state.
|
|
210
|
+
*/
|
|
211
|
+
function projectStateBearingHistory(messages, options) {
|
|
212
|
+
const projected = [];
|
|
213
|
+
for (const message of messages) {
|
|
214
|
+
if (message.role !== 'system') {
|
|
215
|
+
projected.push(message);
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (isCompactionMessage(message.content)) {
|
|
219
|
+
projected.push(options.pinCompaction ? { ...message, retain: true } : message);
|
|
220
|
+
}
|
|
221
|
+
else if (isWorkingMemoryMessage(message.content)) {
|
|
222
|
+
projected.push(message);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return collapseProjectInstructionSnapshots(projected);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Remove the incomplete turn still owned by a durable resume plan.
|
|
229
|
+
*
|
|
230
|
+
* The plan re-appends the exact assistant with real/denied/recovered results.
|
|
231
|
+
* Generic history repair must not synthesize a competing result first. Any
|
|
232
|
+
* partial results for that turn are removed too; the executor reconstructs
|
|
233
|
+
* them from the durable run transcript through `recoveredResults`.
|
|
234
|
+
*/
|
|
235
|
+
function withoutOwnedResumeTurn(messages, assistant) {
|
|
236
|
+
const ownerIndex = messages.lastIndexOf(assistant);
|
|
237
|
+
if (ownerIndex < 0) {
|
|
238
|
+
throw new NamzuError({
|
|
239
|
+
code: 'invalid_config',
|
|
240
|
+
message: 'A pending checkpoint resume plan does not own a message in its checkpoint.',
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
const ownedIds = new Set((assistant.toolCalls ?? []).map((call) => call.id));
|
|
244
|
+
return messages.filter((message, index) => index !== ownerIndex &&
|
|
245
|
+
!(index > ownerIndex && message.role === 'tool' && ownedIds.has(message.toolCallId)));
|
|
154
246
|
}
|
|
155
247
|
export async function* query(params) {
|
|
248
|
+
const selectedResumeState = selectedResumeStates.get(params);
|
|
249
|
+
selectedResumeStates.delete(params);
|
|
156
250
|
// Resolved at the DOOR, before a run id exists or a logger is built.
|
|
157
251
|
// A caller who set both spellings of a renamed field has a config bug,
|
|
158
252
|
// and refusing it here costs them nothing; refusing it at the read site
|
|
@@ -160,6 +254,18 @@ export async function* query(params) {
|
|
|
160
254
|
// provider call has been paid for and a partial transcript written.
|
|
161
255
|
const promptCache = params.promptCache;
|
|
162
256
|
const taskScheduler = params.taskScheduler;
|
|
257
|
+
const streamIdleTimeoutMs = resolveStreamIdleTimeoutMs(params.runConfig.streamIdleTimeoutMs);
|
|
258
|
+
const maxRequestRichContentBytes = resolveMaxRequestRichContentBytes(params.runConfig.maxRequestRichContentBytes);
|
|
259
|
+
const sandboxTeardownTimeoutMs = resolveSandboxTeardownTimeoutMs(params.sandboxTeardownTimeoutMs);
|
|
260
|
+
// Persist the EFFECTIVE value, not only an override. A run replayed after a
|
|
261
|
+
// later release must be able to explain which liveness policy settled it;
|
|
262
|
+
// an absent field whose meaning follows the currently-installed default
|
|
263
|
+
// would rewrite that evidence at read time.
|
|
264
|
+
const runConfig = {
|
|
265
|
+
...params.runConfig,
|
|
266
|
+
streamIdleTimeoutMs,
|
|
267
|
+
maxRequestRichContentBytes,
|
|
268
|
+
};
|
|
163
269
|
// The run's one correlated logger, built before anything below needs
|
|
164
270
|
// one — the migration check, the retry/fallback wrappers and `ctx`
|
|
165
271
|
// itself all read this SAME object, so a retry warning and the run
|
|
@@ -172,7 +278,7 @@ export async function* query(params) {
|
|
|
172
278
|
const runId = params.runId ?? generateRunId();
|
|
173
279
|
const log = RunContextFactory.buildLogger({
|
|
174
280
|
agentName: params.agentName,
|
|
175
|
-
runConfig
|
|
281
|
+
runConfig,
|
|
176
282
|
runId,
|
|
177
283
|
parentRunId: params.parentRunId,
|
|
178
284
|
sessionId: params.sessionId,
|
|
@@ -222,9 +328,11 @@ export async function* query(params) {
|
|
|
222
328
|
// call site — so without it the "failed, retrying" and "failed, giving
|
|
223
329
|
// up" lines were dead code and a backoff left no trace anywhere.
|
|
224
330
|
//
|
|
225
|
-
// With a chain declared, the same sentence holds
|
|
226
|
-
// applied
|
|
227
|
-
//
|
|
331
|
+
// With a chain declared, the same sentence holds two levels out. The idle
|
|
332
|
+
// watchdog is applied to each raw member, retry wraps that, and fallback
|
|
333
|
+
// wraps the members: `fallback(retry(idle(m0)), retry(idle(m1)), …)`. The
|
|
334
|
+
// idle layer cannot sit outside retry, because its timer would then count a
|
|
335
|
+
// legitimate backoff as provider silence. This order is not a
|
|
228
336
|
// preference. Assembled the other way round — which is what a host gets if
|
|
229
337
|
// it wraps its own chain and hands the result in, because this function
|
|
230
338
|
// would then wrap THAT in retry — an exhausted chain gets restarted from
|
|
@@ -237,7 +345,15 @@ export async function* query(params) {
|
|
|
237
345
|
];
|
|
238
346
|
assertCostIsAttributable(chain, params.pricing);
|
|
239
347
|
assertBudgetIsMeasurable(params);
|
|
240
|
-
const
|
|
348
|
+
const withRecovery = (provider) => {
|
|
349
|
+
const withIdleBound = withStreamIdleTimeout(provider, {
|
|
350
|
+
idleTimeoutMs: streamIdleTimeoutMs,
|
|
351
|
+
log,
|
|
352
|
+
});
|
|
353
|
+
return params.retry === false
|
|
354
|
+
? withIdleBound
|
|
355
|
+
: withProviderRetry(withIdleBound, { config: params.retry, log });
|
|
356
|
+
};
|
|
241
357
|
// Who is serving right now, for the run RECORD rather than for the request.
|
|
242
358
|
//
|
|
243
359
|
// It starts at the head and moves only when the chain does, which is the
|
|
@@ -248,7 +364,10 @@ export async function* query(params) {
|
|
|
248
364
|
const serving = {
|
|
249
365
|
current: { index: 0, providerId: params.provider.id },
|
|
250
366
|
};
|
|
251
|
-
const resilientProvider = withProviderFallback(chain.map((member) => ({
|
|
367
|
+
const resilientProvider = withProviderFallback(chain.map((member) => ({
|
|
368
|
+
...member,
|
|
369
|
+
provider: withRecovery(member.provider),
|
|
370
|
+
})), {
|
|
252
371
|
log,
|
|
253
372
|
onSwap: (to) => {
|
|
254
373
|
serving.current = to;
|
|
@@ -264,7 +383,7 @@ export async function* query(params) {
|
|
|
264
383
|
// take down a run the table could have served perfectly well. That is
|
|
265
384
|
// why the failure path is a swallow with a log rather than a throw: the
|
|
266
385
|
// window is an optimisation over a working default, not a prerequisite.
|
|
267
|
-
const providerContextWindow = await resolveProviderContextWindow(resilientProvider,
|
|
386
|
+
const providerContextWindow = await resolveProviderContextWindow(resilientProvider, runConfig.model, params.signal, runConfig.timeoutMs, log);
|
|
268
387
|
// The mode this conversation was left in, when the run config names none.
|
|
269
388
|
// Read once, before the loop exists, for the same reason the context
|
|
270
389
|
// window is: the executor's resolver is synchronous and hot.
|
|
@@ -310,13 +429,83 @@ export async function* query(params) {
|
|
|
310
429
|
// the bytes. Every failure refuses: a message that silently lost its
|
|
311
430
|
// image is a model answering about a picture it never saw.
|
|
312
431
|
const seeded = queuedForThisRun.length > 0 ? [...queuedForThisRun, ...params.messages] : params.messages;
|
|
313
|
-
|
|
432
|
+
let resolvedInitialMessages;
|
|
433
|
+
let attachmentResolutionCancelled = false;
|
|
434
|
+
try {
|
|
435
|
+
resolvedInitialMessages = [
|
|
436
|
+
...(await resolveAttachments(seeded, params.attachmentStore, {
|
|
437
|
+
signal: params.signal,
|
|
438
|
+
})),
|
|
439
|
+
];
|
|
440
|
+
params.signal?.throwIfAborted();
|
|
441
|
+
}
|
|
442
|
+
catch (error) {
|
|
443
|
+
// Attachment materialization precedes RunContext construction so stored
|
|
444
|
+
// bytes never enter a live run's checkpoints. Cancellation still belongs
|
|
445
|
+
// to that run: preserve the exact input refs, build the context below, and
|
|
446
|
+
// let its normal terminal path classify/persist a cancelled Run. Every
|
|
447
|
+
// other store failure remains a pre-run refusal.
|
|
448
|
+
if (!params.signal?.aborted || error !== params.signal.reason)
|
|
449
|
+
throw error;
|
|
450
|
+
resolvedInitialMessages = [...seeded];
|
|
451
|
+
attachmentResolutionCancelled = true;
|
|
452
|
+
}
|
|
453
|
+
if (!attachmentResolutionCancelled && params.projectInstructionContext?.prepareInitialSnapshot) {
|
|
454
|
+
const preparationSignal = params.signal ?? new AbortController().signal;
|
|
455
|
+
let snapshot;
|
|
456
|
+
try {
|
|
457
|
+
const prepared = await awaitProjectInstructionCallback(preparationSignal, () => params.projectInstructionContext?.prepareInitialSnapshot?.({
|
|
458
|
+
messages: [...resolvedInitialMessages],
|
|
459
|
+
signal: preparationSignal,
|
|
460
|
+
}));
|
|
461
|
+
// The callback promise can settle, remove its listener, and queue this
|
|
462
|
+
// continuation immediately before a queued abort. Publication is a
|
|
463
|
+
// separate authority boundary, so fence it too.
|
|
464
|
+
preparationSignal.throwIfAborted();
|
|
465
|
+
snapshot = prepared;
|
|
466
|
+
}
|
|
467
|
+
catch (error) {
|
|
468
|
+
// This callback runs before RunContext owns its child controller. A
|
|
469
|
+
// caller cancellation here still belongs to the run: publish no late
|
|
470
|
+
// snapshot and let the context below settle the normal cancelled Run.
|
|
471
|
+
// Compare the exact reason: a callback failure that won first must not
|
|
472
|
+
// be erased merely because cancellation arrived before this catch ran.
|
|
473
|
+
if (!preparationSignal.aborted || error !== preparationSignal.reason)
|
|
474
|
+
throw error;
|
|
475
|
+
}
|
|
476
|
+
if (snapshot !== undefined) {
|
|
477
|
+
resolvedInitialMessages = replaceProjectInstructionSnapshot(resolvedInitialMessages, snapshot, 'before-latest-user');
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
const pendingHistoryRepairs = [];
|
|
481
|
+
const projectedInitialMessages = collapseProjectInstructionSnapshots(params.resumeFromCheckpoint || params.continuationMode
|
|
482
|
+
? resolvedInitialMessages
|
|
483
|
+
: projectStateBearingHistory(resolvedInitialMessages, {
|
|
484
|
+
pinCompaction: true,
|
|
485
|
+
}));
|
|
486
|
+
const initialRepair = params.resumeFromCheckpoint
|
|
487
|
+
? { messages: projectedInitialMessages, report: undefined }
|
|
488
|
+
: repairToolMessageHistory(projectedInitialMessages);
|
|
489
|
+
const initialMessages = initialRepair.messages;
|
|
490
|
+
if (initialRepair.report && toolHistoryRepairChanged(initialRepair.report)) {
|
|
491
|
+
pendingHistoryRepairs.push({
|
|
492
|
+
source: 'fresh-history',
|
|
493
|
+
report: initialRepair.report,
|
|
494
|
+
});
|
|
495
|
+
log.warn('Repaired provider-invalid tool history before starting the run', {
|
|
496
|
+
[NAMZU.RUN_ID]: runId,
|
|
497
|
+
'namzu.history.source': 'fresh-history',
|
|
498
|
+
'namzu.history.duplicate_tool_results_removed': initialRepair.report.duplicateToolResultsRemoved,
|
|
499
|
+
'namzu.history.orphaned_tool_results_removed': initialRepair.report.orphanedToolResultsRemoved,
|
|
500
|
+
'namzu.history.synthetic_tool_results_inserted': initialRepair.report.syntheticToolResultsInserted,
|
|
501
|
+
});
|
|
502
|
+
}
|
|
314
503
|
const ctx = RunContextFactory.build({
|
|
315
504
|
...(topicState ? { topicPermissionMode: topicState.permissionMode } : {}),
|
|
316
505
|
...(params.permissionModeRef ? { permissionModeRef: params.permissionModeRef } : {}),
|
|
317
506
|
agentId: params.agentId,
|
|
318
507
|
agentName: params.agentName,
|
|
319
|
-
runConfig
|
|
508
|
+
runConfig,
|
|
320
509
|
provider: resilientProvider,
|
|
321
510
|
workingDirectory: params.workingDirectory,
|
|
322
511
|
pricing: params.pricing,
|
|
@@ -400,6 +589,97 @@ export async function* query(params) {
|
|
|
400
589
|
const eventTranslator = new EventTranslator(ctx.runMgr, undefined, ctx.log);
|
|
401
590
|
eventTranslator.wireActivityStore(ctx.activityStore, ctx.runId);
|
|
402
591
|
eventTranslator.wirePlanManager(ctx.planManager, ctx.runId);
|
|
592
|
+
eventTranslator.setGeneration(params.claimFence);
|
|
593
|
+
if (attachmentResolutionCancelled) {
|
|
594
|
+
// Attachment materialization happens before RunContext exists. Once it
|
|
595
|
+
// observes cancellation, do only the work required to leave an honest
|
|
596
|
+
// durable run: initialize the record, retain the unresolved references,
|
|
597
|
+
// and settle through the ordinary cancellation classifier. Prompt
|
|
598
|
+
// contributions/cache, host callbacks, tools, plugins, sandbox, guardrails,
|
|
599
|
+
// advisors, and providers are all authority-bearing work and stay out.
|
|
600
|
+
if (params.resumeFromCheckpoint && !selectedResumeState) {
|
|
601
|
+
// The canonical resume surface hands query the checkpoint state it
|
|
602
|
+
// already selected. A raw resume query has no such snapshot; after
|
|
603
|
+
// cancellation, reading the store again could hang without a signal,
|
|
604
|
+
// while persisting without it would erase the existing transcript.
|
|
605
|
+
// Refuse before binding/persisting rather than choose either failure.
|
|
606
|
+
ctx.abortController.signal.throwIfAborted();
|
|
607
|
+
}
|
|
608
|
+
const cancelledPrompt = params.systemPrompt ?? '';
|
|
609
|
+
const cancelledAssembler = new ResultAssembler({
|
|
610
|
+
runMgr: ctx.runMgr,
|
|
611
|
+
planManager: ctx.planManager,
|
|
612
|
+
activityStore: ctx.activityStore,
|
|
613
|
+
log: ctx.log,
|
|
614
|
+
emitEvent: eventTranslator.emitEvent,
|
|
615
|
+
drainPending: () => eventTranslator.drainPending(),
|
|
616
|
+
signal: ctx.abortController.signal,
|
|
617
|
+
});
|
|
618
|
+
const rootSpan = getTracer().startSpan(agentRunSpanName(params.agentName), {}, parentContext(params.parentSpan ?? selectedResumeState?.traceContext));
|
|
619
|
+
rootSpan.setAttributes({
|
|
620
|
+
[NAMZU.RUN_ID]: ctx.runMgr.id,
|
|
621
|
+
[GENAI.AGENT_NAME]: params.agentName,
|
|
622
|
+
[GENAI.AGENT_ID]: params.agentId,
|
|
623
|
+
[GENAI.REQUEST_MODEL]: runConfig.model,
|
|
624
|
+
[GENAI.SYSTEM]: params.provider.id,
|
|
625
|
+
});
|
|
626
|
+
try {
|
|
627
|
+
await ctx.runMgr.init();
|
|
628
|
+
if (selectedResumeState) {
|
|
629
|
+
ctx.runMgr.restoreUsage(selectedResumeState.tokenUsage, selectedResumeState.costInfo, selectedResumeState.currentIteration);
|
|
630
|
+
for (const message of selectedResumeState.messages)
|
|
631
|
+
ctx.runMgr.pushMessage(message);
|
|
632
|
+
for (const queued of queuedForThisRun)
|
|
633
|
+
ctx.runMgr.pushMessage(queued);
|
|
634
|
+
}
|
|
635
|
+
else if (params.continuationMode) {
|
|
636
|
+
for (const message of initialMessages)
|
|
637
|
+
ctx.runMgr.pushMessage(message);
|
|
638
|
+
}
|
|
639
|
+
else {
|
|
640
|
+
ctx.runMgr.pushMessage(createSystemMessage(cancelledPrompt, 'cache'));
|
|
641
|
+
for (const message of initialMessages)
|
|
642
|
+
ctx.runMgr.pushMessage(message);
|
|
643
|
+
}
|
|
644
|
+
if (params.eventCursor) {
|
|
645
|
+
yield* catchUpFromCursor(ctx.runMgr, params.eventCursor, params.onEventReplay, params.claimFence, (error) => {
|
|
646
|
+
ctx.log.warn('Replay observer failed after attachment cancellation', {
|
|
647
|
+
'exception.message': toErrorMessage(error),
|
|
648
|
+
});
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
if (selectedResumeState) {
|
|
652
|
+
await eventTranslator.emitEvent({
|
|
653
|
+
type: 'run_resuming',
|
|
654
|
+
runId: ctx.runId,
|
|
655
|
+
fromCheckpointId: selectedResumeState.checkpointId,
|
|
656
|
+
});
|
|
657
|
+
yield* eventTranslator.drainPending();
|
|
658
|
+
}
|
|
659
|
+
ctx.runMgr.markRunning();
|
|
660
|
+
await eventTranslator.emitEvent({
|
|
661
|
+
type: 'run_started',
|
|
662
|
+
runId: ctx.runId,
|
|
663
|
+
systemPrompt: cancelledPrompt,
|
|
664
|
+
});
|
|
665
|
+
yield* eventTranslator.drainPending();
|
|
666
|
+
ctx.abortController.signal.throwIfAborted();
|
|
667
|
+
}
|
|
668
|
+
catch (error) {
|
|
669
|
+
// Attachment resolution has already observed the caller's abort. A
|
|
670
|
+
// reconnect callback can still throw while replay is being reported,
|
|
671
|
+
// but it cannot replace that terminal cause or turn a cancelled run
|
|
672
|
+
// into an unpersisted rejection.
|
|
673
|
+
const terminalError = ctx.abortController.signal.aborted
|
|
674
|
+
? ctx.abortController.signal.reason
|
|
675
|
+
: error;
|
|
676
|
+
yield* cancelledAssembler.handleError(terminalError, rootSpan);
|
|
677
|
+
}
|
|
678
|
+
finally {
|
|
679
|
+
rootSpan.end();
|
|
680
|
+
}
|
|
681
|
+
return await cancelledAssembler.finalize();
|
|
682
|
+
}
|
|
403
683
|
const unsubscribeTaskStore = params.taskStore
|
|
404
684
|
? eventTranslator.wireTaskStore(params.taskStore, ctx.runId)
|
|
405
685
|
: undefined;
|
|
@@ -453,7 +733,11 @@ export async function* query(params) {
|
|
|
453
733
|
throw new NamzuError({
|
|
454
734
|
code: 'capability_unavailable',
|
|
455
735
|
message,
|
|
456
|
-
details: {
|
|
736
|
+
details: {
|
|
737
|
+
providerId: params.provider.id,
|
|
738
|
+
capability: 'tools',
|
|
739
|
+
registeredToolCount,
|
|
740
|
+
},
|
|
457
741
|
});
|
|
458
742
|
}
|
|
459
743
|
ctx.log.warn('Capability mismatch: the provider declares no tool support', {
|
|
@@ -468,7 +752,11 @@ export async function* query(params) {
|
|
|
468
752
|
throw new NamzuError({
|
|
469
753
|
code: 'capability_unavailable',
|
|
470
754
|
message,
|
|
471
|
-
details: {
|
|
755
|
+
details: {
|
|
756
|
+
providerId: params.provider.id,
|
|
757
|
+
capability: 'vision',
|
|
758
|
+
attachmentMessageCount,
|
|
759
|
+
},
|
|
472
760
|
});
|
|
473
761
|
}
|
|
474
762
|
ctx.log.warn('Capability mismatch: the provider declares no vision support', {
|
|
@@ -483,7 +771,11 @@ export async function* query(params) {
|
|
|
483
771
|
throw new NamzuError({
|
|
484
772
|
code: 'capability_unavailable',
|
|
485
773
|
message,
|
|
486
|
-
details: {
|
|
774
|
+
details: {
|
|
775
|
+
providerId: params.provider.id,
|
|
776
|
+
capability: 'documents',
|
|
777
|
+
documentMessageCount,
|
|
778
|
+
},
|
|
487
779
|
});
|
|
488
780
|
}
|
|
489
781
|
ctx.log.warn('Capability mismatch: the provider declares no document support', {
|
|
@@ -537,7 +829,7 @@ export async function* query(params) {
|
|
|
537
829
|
runId: ctx.runId,
|
|
538
830
|
workingDirectory: ctx.cwd,
|
|
539
831
|
permissionMode: () => ctx.permissionMode.current,
|
|
540
|
-
env:
|
|
832
|
+
env: runConfig.env ?? {},
|
|
541
833
|
abortSignal: ctx.abortController.signal,
|
|
542
834
|
allowedTools: effectiveAllowedTools,
|
|
543
835
|
invocationState: params.invocationState,
|
|
@@ -595,10 +887,10 @@ export async function* query(params) {
|
|
|
595
887
|
...(params.promptContributions ? { contributions: params.promptContributions } : {}),
|
|
596
888
|
});
|
|
597
889
|
const guard = new GuardCoordinator({
|
|
598
|
-
tokenBudget:
|
|
599
|
-
timeoutMs:
|
|
600
|
-
costLimitUsd:
|
|
601
|
-
maxIterations:
|
|
890
|
+
tokenBudget: runConfig.tokenBudget,
|
|
891
|
+
timeoutMs: runConfig.timeoutMs,
|
|
892
|
+
costLimitUsd: runConfig.costLimitUsd,
|
|
893
|
+
maxIterations: runConfig.maxIterations,
|
|
602
894
|
});
|
|
603
895
|
const checkpointMgr = new CheckpointManager(ctx.runMgr.getCheckpointStore(), ctx.runMgr.getRunScope());
|
|
604
896
|
// Every checkpoint carries compaction's accumulated state, so a run that
|
|
@@ -627,11 +919,25 @@ export async function* query(params) {
|
|
|
627
919
|
});
|
|
628
920
|
let advisoryCtx;
|
|
629
921
|
if (params.advisory && params.advisory.advisors.length > 0) {
|
|
630
|
-
|
|
922
|
+
// Advisors are model calls owned by this run even when they use a
|
|
923
|
+
// different provider. Sending the raw definitions into the registry
|
|
924
|
+
// lets a triggered or model-requested consultation bypass both the
|
|
925
|
+
// finite stream-silence bound and Stop. Bind every advisor provider at
|
|
926
|
+
// the query boundary, where the effective timeout and run signal are
|
|
927
|
+
// already known; standalone AdvisoryExecutor callers retain their
|
|
928
|
+
// explicitly chosen provider/cancellation policy.
|
|
929
|
+
const boundedAdvisors = params.advisory.advisors.map((advisor) => ({
|
|
930
|
+
...advisor,
|
|
931
|
+
provider: withStreamIdleTimeout(advisor.provider, {
|
|
932
|
+
idleTimeoutMs: streamIdleTimeoutMs,
|
|
933
|
+
log: ctx.log,
|
|
934
|
+
}),
|
|
935
|
+
}));
|
|
936
|
+
const advisorRegistry = new AdvisorRegistry(boundedAdvisors, params.advisory.defaultAdvisorId);
|
|
631
937
|
// A budget the runtime cannot measure is refused here rather than
|
|
632
938
|
// silently ignored for the length of the run.
|
|
633
939
|
assertBudgetEnforceable(params.advisory);
|
|
634
|
-
const advisoryExecutor = new AdvisoryExecutor(ctx.log, params.advisory.budget);
|
|
940
|
+
const advisoryExecutor = new AdvisoryExecutor(ctx.log, params.advisory.budget, ctx.abortController.signal);
|
|
635
941
|
const triggerEvaluator = new TriggerEvaluator(params.advisory.triggers ?? [], params.advisory.budget);
|
|
636
942
|
advisoryCtx = new AdvisoryContext(advisorRegistry, advisoryExecutor, triggerEvaluator, params.advisory.budget);
|
|
637
943
|
// What the run looks like when the MODEL consults an advisor, as
|
|
@@ -675,7 +981,7 @@ export async function* query(params) {
|
|
|
675
981
|
const iterationOrchestrator = new IterationOrchestrator({
|
|
676
982
|
provider: resilientProvider,
|
|
677
983
|
servingMember: () => serving.current,
|
|
678
|
-
runConfig
|
|
984
|
+
runConfig,
|
|
679
985
|
...(params.stopWhen ? { stopWhen: params.stopWhen } : {}),
|
|
680
986
|
...(params.prepareStep ? { prepareStep: params.prepareStep } : {}),
|
|
681
987
|
...(params.beforeStep ? { beforeStep: params.beforeStep } : {}),
|
|
@@ -716,6 +1022,9 @@ export async function* query(params) {
|
|
|
716
1022
|
...(params.repeatCallAdvisory === false ? {} : { repeatCalls: new RepeatCallTracker() }),
|
|
717
1023
|
compactionConfig: params.compactionConfig,
|
|
718
1024
|
...(params.inboundMessages ? { inboundMessages: params.inboundMessages } : {}),
|
|
1025
|
+
...(params.projectInstructionContext
|
|
1026
|
+
? { projectInstructionContext: params.projectInstructionContext }
|
|
1027
|
+
: {}),
|
|
719
1028
|
...(providerContextWindow !== undefined ? { providerContextWindow } : {}),
|
|
720
1029
|
workingStateManager,
|
|
721
1030
|
taskRouter: params.taskRouter,
|
|
@@ -744,9 +1053,11 @@ export async function* query(params) {
|
|
|
744
1053
|
// waterfall, and for a replay fork (which mints a new run id) not
|
|
745
1054
|
// even that. An explicit caller-supplied parent still wins: it is
|
|
746
1055
|
// the more specific statement about where this run belongs.
|
|
747
|
-
const resumedTrace =
|
|
748
|
-
?
|
|
749
|
-
:
|
|
1056
|
+
const resumedTrace = selectedResumeState
|
|
1057
|
+
? selectedResumeState.traceContext
|
|
1058
|
+
: params.resumeFromCheckpoint
|
|
1059
|
+
? await checkpointMgr.readTraceContext(params.resumeFromCheckpoint)
|
|
1060
|
+
: undefined;
|
|
750
1061
|
const rootSpan = tracer.startSpan(agentRunSpanName(params.agentName), {}, parentContext(params.parentSpan ?? resumedTrace));
|
|
751
1062
|
// Hand the run span to the loop so every iteration parents to it.
|
|
752
1063
|
iterationOrchestrator.setRootSpan(rootSpan);
|
|
@@ -755,15 +1066,11 @@ export async function* query(params) {
|
|
|
755
1066
|
checkpointMgr.setTraceSource(() => serializeSpan(rootSpan));
|
|
756
1067
|
// And every park it records carries an absolute deadline, so an
|
|
757
1068
|
// unanswered approval cannot outlive the worker that asked for it.
|
|
758
|
-
checkpointMgr.setParkTtl(
|
|
1069
|
+
checkpointMgr.setParkTtl(runConfig.hitlParkTtlMs);
|
|
759
1070
|
// The claim this worker holds, if it took one. Without this hop the
|
|
760
1071
|
// fence exists, the refusal exists, and no checkpoint a RUN writes ever
|
|
761
1072
|
// carries a number — so a stalled worker is refused nowhere.
|
|
762
1073
|
checkpointMgr.setClaimFence(params.claimFence);
|
|
763
|
-
// And every EVENT it records carries the same fence as its generation,
|
|
764
|
-
// so a consumer whose cursor was minted under an older holding is told
|
|
765
|
-
// the sequence space changed rather than handed a splice from it.
|
|
766
|
-
eventTranslator.setGeneration(params.claimFence);
|
|
767
1074
|
// A question raised from inside a tool becomes a real checkpoint
|
|
768
1075
|
// here. It used to park under a synthetic id nothing ever wrote, so
|
|
769
1076
|
// the checkpoint did not exist: nothing on disk said a human owed
|
|
@@ -826,7 +1133,7 @@ export async function* query(params) {
|
|
|
826
1133
|
[NAMZU.RUN_ID]: ctx.runMgr.id,
|
|
827
1134
|
[GENAI.AGENT_NAME]: params.agentName,
|
|
828
1135
|
[GENAI.AGENT_ID]: params.agentId,
|
|
829
|
-
[GENAI.REQUEST_MODEL]:
|
|
1136
|
+
[GENAI.REQUEST_MODEL]: runConfig.model,
|
|
830
1137
|
[GENAI.SYSTEM]: params.provider.id,
|
|
831
1138
|
});
|
|
832
1139
|
let sandbox;
|
|
@@ -844,27 +1151,17 @@ export async function* query(params) {
|
|
|
844
1151
|
// binds the store and reads the log's head — and precede every
|
|
845
1152
|
// emit below.
|
|
846
1153
|
if (params.eventCursor) {
|
|
847
|
-
yield* catchUpFromCursor(ctx.runMgr, params.eventCursor, params.onEventReplay, params.claimFence)
|
|
1154
|
+
yield* catchUpFromCursor(ctx.runMgr, params.eventCursor, params.onEventReplay, params.claimFence, (error) => {
|
|
1155
|
+
ctx.log.warn('Replay observer failed', {
|
|
1156
|
+
'exception.message': toErrorMessage(error),
|
|
1157
|
+
});
|
|
1158
|
+
});
|
|
848
1159
|
}
|
|
849
|
-
// Handed over here, and the position is load-bearing in BOTH
|
|
850
|
-
// directions. It has to follow `wirePlanManager`, or a host that
|
|
851
|
-
// builds its plan in this callback — which is what the callback is
|
|
852
|
-
// for — does it into silence: `plan_ready`, `plan_approved` and
|
|
853
|
-
// every `plan_step_updated` are emitted with nothing subscribed,
|
|
854
|
-
// and the host then watches a stream that never mentions the plan
|
|
855
|
-
// it just created. It also has to follow `runMgr.init()`, because
|
|
856
|
-
// emitting appends to the run store and an uninitialised store
|
|
857
|
-
// throws — moving it up to the wiring alone traded a silent drop
|
|
858
|
-
// for 25 unhandled rejections.
|
|
859
|
-
//
|
|
860
|
-
// Still before the iteration loop, which is the guarantee the
|
|
861
|
-
// callback actually makes.
|
|
862
|
-
params.onContextCreated?.({ planManager: ctx.planManager });
|
|
863
1160
|
ctx.log.info('Starting query', {
|
|
864
1161
|
[NAMZU.RUN_ID]: ctx.runMgr.id,
|
|
865
1162
|
'namzu.runtime.agent': params.agentName,
|
|
866
|
-
[GENAI.REQUEST_MODEL]:
|
|
867
|
-
'namzu.runtime.token_budget':
|
|
1163
|
+
[GENAI.REQUEST_MODEL]: runConfig.model,
|
|
1164
|
+
'namzu.runtime.token_budget': runConfig.tokenBudget,
|
|
868
1165
|
'namzu.runtime.activity_tracking': ctx.activityStore.enabled,
|
|
869
1166
|
'namzu.runtime.permission_mode': ctx.permissionMode.current,
|
|
870
1167
|
'namzu.runtime.resume_from_checkpoint': params.resumeFromCheckpoint ?? null,
|
|
@@ -895,6 +1192,12 @@ export async function* query(params) {
|
|
|
895
1192
|
};
|
|
896
1193
|
if (params.resumeFromCheckpoint) {
|
|
897
1194
|
const checkpoint = await checkpointMgr.restore(params.resumeFromCheckpoint);
|
|
1195
|
+
const projectedCheckpoint = {
|
|
1196
|
+
...checkpoint,
|
|
1197
|
+
messages: projectStateBearingHistory(checkpoint.messages, {
|
|
1198
|
+
pinCompaction: false,
|
|
1199
|
+
}),
|
|
1200
|
+
};
|
|
898
1201
|
await eventTranslator.emitEvent({
|
|
899
1202
|
type: 'run_resuming',
|
|
900
1203
|
runId: ctx.runMgr.id,
|
|
@@ -940,8 +1243,8 @@ export async function* query(params) {
|
|
|
940
1243
|
// re-decides, so "yes, delete that row" degrades into "ask
|
|
941
1244
|
// again and hope it asks for the same thing".
|
|
942
1245
|
pendingResume =
|
|
943
|
-
params.pendingDecision &&
|
|
944
|
-
? planPendingResume(
|
|
1246
|
+
params.pendingDecision && projectedCheckpoint.pending
|
|
1247
|
+
? planPendingResume(projectedCheckpoint, params.pendingDecision, ctx.log)
|
|
945
1248
|
: null;
|
|
946
1249
|
// Results of tools that finished before the process died. The
|
|
947
1250
|
// executor already emits one `tool_completed` per tool inline
|
|
@@ -949,7 +1252,7 @@ export async function* query(params) {
|
|
|
949
1252
|
// durable all along — it was simply never read back, and the
|
|
950
1253
|
// resumed run re-ran calls that had already charged a card or
|
|
951
1254
|
// sent an email.
|
|
952
|
-
const unanswered = unansweredToolCalls(
|
|
1255
|
+
const unanswered = unansweredToolCalls(projectedCheckpoint.messages);
|
|
953
1256
|
recoveredResults =
|
|
954
1257
|
unanswered.length > 0
|
|
955
1258
|
? await recoverCompletedCalls(ctx.runMgr, unanswered, ctx.log)
|
|
@@ -960,30 +1263,31 @@ export async function* query(params) {
|
|
|
960
1263
|
// the transcript proves execution had begun — a tool-review
|
|
961
1264
|
// park has no completions and keeps the cheap repair below.
|
|
962
1265
|
if (!pendingResume && recoveredResults.size > 0) {
|
|
963
|
-
pendingResume = planCrashResume(
|
|
1266
|
+
pendingResume = planCrashResume(projectedCheckpoint, recoveredResults, ctx.log);
|
|
964
1267
|
}
|
|
965
|
-
//
|
|
966
|
-
//
|
|
967
|
-
//
|
|
968
|
-
//
|
|
969
|
-
//
|
|
970
|
-
//
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
ctx.log.warn('
|
|
1268
|
+
// An incomplete turn with a durable owner is NOT abandoned. A
|
|
1269
|
+
// pending decision or crash-resume plan re-appends that exact
|
|
1270
|
+
// assistant with real/denied/recovered results below. Remove it
|
|
1271
|
+
// from the generic pass so no synthetic result competes with the
|
|
1272
|
+
// authority that still owns the call. Everything else is abandoned
|
|
1273
|
+
// history and is repaired conservatively rather than deleted.
|
|
1274
|
+
const abandonedCheckpointMessages = pendingResume
|
|
1275
|
+
? withoutOwnedResumeTurn(projectedCheckpoint.messages, pendingResume.assistant)
|
|
1276
|
+
: projectedCheckpoint.messages;
|
|
1277
|
+
const checkpointRepair = repairToolMessageHistory(abandonedCheckpointMessages);
|
|
1278
|
+
const restoredMessages = checkpointRepair.messages;
|
|
1279
|
+
if (toolHistoryRepairChanged(checkpointRepair.report)) {
|
|
1280
|
+
pendingHistoryRepairs.push({
|
|
1281
|
+
source: 'abandoned-checkpoint',
|
|
1282
|
+
report: checkpointRepair.report,
|
|
1283
|
+
});
|
|
1284
|
+
ctx.log.warn('Repaired abandoned tool history while restoring a checkpoint', {
|
|
982
1285
|
[NAMZU.RUN_ID]: ctx.runMgr.id,
|
|
983
1286
|
'namzu.checkpoint.id': checkpoint.id,
|
|
984
|
-
'namzu.
|
|
985
|
-
'namzu.
|
|
986
|
-
'namzu.
|
|
1287
|
+
'namzu.history.source': 'abandoned-checkpoint',
|
|
1288
|
+
'namzu.history.duplicate_tool_results_removed': checkpointRepair.report.duplicateToolResultsRemoved,
|
|
1289
|
+
'namzu.history.orphaned_tool_results_removed': checkpointRepair.report.orphanedToolResultsRemoved,
|
|
1290
|
+
'namzu.history.synthetic_tool_results_inserted': checkpointRepair.report.syntheticToolResultsInserted,
|
|
987
1291
|
});
|
|
988
1292
|
}
|
|
989
1293
|
for (const msg of restoredMessages) {
|
|
@@ -1021,8 +1325,22 @@ export async function* query(params) {
|
|
|
1021
1325
|
pushSystemMessages();
|
|
1022
1326
|
let isFirstUserMessage = true;
|
|
1023
1327
|
for (const msg of initialMessages) {
|
|
1024
|
-
if (msg.role === 'system')
|
|
1328
|
+
if (msg.role === 'system') {
|
|
1329
|
+
// A fresh run rebuilds its current static/dynamic prompt above,
|
|
1330
|
+
// so arbitrary historical system messages stay out. These two
|
|
1331
|
+
// are different: they are conversation STATE, and dropping them
|
|
1332
|
+
// deletes the only surviving record of compacted history or the
|
|
1333
|
+
// produced-artifact ledger. A compaction summary arriving from a
|
|
1334
|
+
// prior run is pinned because this new WorkingStateManager cannot
|
|
1335
|
+
// prove it has reconstructed equivalent state yet.
|
|
1336
|
+
if (isCompactionMessage(msg.content)) {
|
|
1337
|
+
ctx.runMgr.pushMessage({ ...msg, retain: true });
|
|
1338
|
+
}
|
|
1339
|
+
else if (isWorkingMemoryMessage(msg.content)) {
|
|
1340
|
+
ctx.runMgr.pushMessage(msg);
|
|
1341
|
+
}
|
|
1025
1342
|
continue;
|
|
1343
|
+
}
|
|
1026
1344
|
ctx.runMgr.pushMessage(msg);
|
|
1027
1345
|
if (workingStateManager && msg.role === 'user' && msg.content) {
|
|
1028
1346
|
extractFromUserMessage(workingStateManager, msg.content, isFirstUserMessage);
|
|
@@ -1040,6 +1358,23 @@ export async function* query(params) {
|
|
|
1040
1358
|
systemPrompt: assembledPrompt,
|
|
1041
1359
|
});
|
|
1042
1360
|
yield* eventTranslator.drainPending();
|
|
1361
|
+
// Pre-run materialization can observe cancellation before RunContext
|
|
1362
|
+
// exists. The exact input has now been seeded and the run is writable;
|
|
1363
|
+
// hand the cancellation to the normal terminal path before invoking
|
|
1364
|
+
// any host callback, guardrail, plugin, sandbox, or provider. Those
|
|
1365
|
+
// boundaries are not all cooperative and must not regain withdrawn
|
|
1366
|
+
// authority merely because the run record still had to be created.
|
|
1367
|
+
ctx.abortController.signal.throwIfAborted();
|
|
1368
|
+
// Handed over here, and the position is load-bearing in three
|
|
1369
|
+
// directions. It has to follow `wirePlanManager`, or a host that
|
|
1370
|
+
// builds its plan in this callback does it into silence. It has to
|
|
1371
|
+
// follow `runMgr.init()` and `run_started`, because plan events append
|
|
1372
|
+
// to that durable run. It also has to follow the pre-model abort fence:
|
|
1373
|
+
// a callback invoked after attachment resolution observed cancellation
|
|
1374
|
+
// would regain withdrawn authority and could replace the cancellation
|
|
1375
|
+
// with its own failure. This is still before the iteration loop, which
|
|
1376
|
+
// is the guarantee the callback makes.
|
|
1377
|
+
params.onContextCreated?.({ planManager: ctx.planManager });
|
|
1043
1378
|
// The box is handed out HERE, after `run_started`, and the position
|
|
1044
1379
|
// is load-bearing rather than tidy. It moved twice:
|
|
1045
1380
|
//
|
|
@@ -1056,6 +1391,20 @@ export async function* query(params) {
|
|
|
1056
1391
|
// before it takes effect, so the handout cannot precede the run
|
|
1057
1392
|
// being writable.
|
|
1058
1393
|
params.onApprovalPolicy?.(approvalPolicy);
|
|
1394
|
+
// History repair happens before the run manager sees the first model
|
|
1395
|
+
// request, but its durable event cannot precede run_started: there is no
|
|
1396
|
+
// writable run log until that event initializes it. Emit the measured
|
|
1397
|
+
// counts here, still before any provider call, so hosts can tell that the
|
|
1398
|
+
// model received a repaired projection rather than the raw history.
|
|
1399
|
+
for (const repair of pendingHistoryRepairs) {
|
|
1400
|
+
await eventTranslator.emitEvent({
|
|
1401
|
+
type: 'message_history_repaired',
|
|
1402
|
+
runId: ctx.runMgr.id,
|
|
1403
|
+
source: repair.source,
|
|
1404
|
+
...repair.report,
|
|
1405
|
+
});
|
|
1406
|
+
yield* eventTranslator.drainPending();
|
|
1407
|
+
}
|
|
1059
1408
|
// Surface capability degradation to the host as run events —
|
|
1060
1409
|
// explicit, not silent (the log.warn above fires at setup time;
|
|
1061
1410
|
// this is the machine-readable channel).
|
|
@@ -1079,14 +1428,24 @@ export async function* query(params) {
|
|
|
1079
1428
|
});
|
|
1080
1429
|
yield* eventTranslator.drainPending();
|
|
1081
1430
|
}
|
|
1431
|
+
if (documentMessageCount > 0) {
|
|
1432
|
+
await eventTranslator.emitEvent({
|
|
1433
|
+
type: 'capability_warning',
|
|
1434
|
+
runId: ctx.runMgr.id,
|
|
1435
|
+
capability: 'documents',
|
|
1436
|
+
providerId: params.provider.id,
|
|
1437
|
+
message: `Provider '${params.provider.id}' does not support documents — document attachments on ${documentMessageCount} user message(s) will not reach the model.`,
|
|
1438
|
+
});
|
|
1439
|
+
yield* eventTranslator.drainPending();
|
|
1440
|
+
}
|
|
1082
1441
|
if (params.pluginManager) {
|
|
1083
|
-
const hookResults = await params.pluginManager.executeHooks('run_start', { runId: ctx.runId }, eventTranslator.emitEvent);
|
|
1442
|
+
const hookResults = await params.pluginManager.executeHooks('run_start', { runId: ctx.runId, signal: ctx.abortController.signal }, eventTranslator.emitEvent);
|
|
1084
1443
|
applyLifecycleHookResults('run_start', hookResults);
|
|
1085
1444
|
yield* eventTranslator.drainPending();
|
|
1086
1445
|
}
|
|
1087
1446
|
// --- Sandbox lifecycle: create before iteration loop ---
|
|
1088
1447
|
if (params.sandboxProvider) {
|
|
1089
|
-
const rootAtCwd =
|
|
1448
|
+
const rootAtCwd = runConfig.sandbox?.workspace === 'working-directory';
|
|
1090
1449
|
// Checked against what the CALLER passed, not against `ctx.cwd`.
|
|
1091
1450
|
// `ctx.cwd` falls back to `process.cwd()`, so reading it here
|
|
1092
1451
|
// would silently root the sandbox at whatever directory the
|
|
@@ -1104,12 +1463,52 @@ export async function* query(params) {
|
|
|
1104
1463
|
details: { workspace: 'working-directory' },
|
|
1105
1464
|
});
|
|
1106
1465
|
}
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1466
|
+
const acquisition = await acquireSandbox({
|
|
1467
|
+
provider: params.sandboxProvider,
|
|
1468
|
+
config: {
|
|
1469
|
+
...(rootAtCwd ? { workingDirectory: ctx.cwd } : {}),
|
|
1470
|
+
timeoutMs: runConfig.sandbox?.timeoutMs,
|
|
1471
|
+
memoryLimitMb: runConfig.sandbox?.memoryLimitMb,
|
|
1472
|
+
maxProcesses: runConfig.sandbox?.maxProcesses,
|
|
1473
|
+
},
|
|
1474
|
+
signal: ctx.abortController.signal,
|
|
1475
|
+
timeoutMs: guard.remainingUntilTimeoutMs(),
|
|
1476
|
+
teardownTimeoutMs: sandboxTeardownTimeoutMs,
|
|
1477
|
+
onLateTeardown: (result) => {
|
|
1478
|
+
if (result.kind === 'destroyed') {
|
|
1479
|
+
ctx.log.info('Late sandbox allocation was destroyed after the run stopped', {
|
|
1480
|
+
[NAMZU.RUN_ID]: ctx.runId,
|
|
1481
|
+
});
|
|
1482
|
+
return;
|
|
1483
|
+
}
|
|
1484
|
+
ctx.log.error('Late sandbox allocation did not stop cleanly', {
|
|
1485
|
+
[NAMZU.RUN_ID]: ctx.runId,
|
|
1486
|
+
...errorAttributes(result.error),
|
|
1487
|
+
});
|
|
1488
|
+
},
|
|
1112
1489
|
});
|
|
1490
|
+
if (acquisition.kind !== 'created') {
|
|
1491
|
+
if (acquisition.createPending) {
|
|
1492
|
+
ctx.log.warn('Sandbox creation was unsettled when the run stopped; any returned handle will be released, but a remote allocation hidden behind a lost response requires provider-side reconciliation or a fleet reaper', {
|
|
1493
|
+
[NAMZU.RUN_ID]: ctx.runId,
|
|
1494
|
+
'namzu.sandbox.provider_id': params.sandboxProvider.id,
|
|
1495
|
+
});
|
|
1496
|
+
}
|
|
1497
|
+
if (acquisition.kind === 'cancelled') {
|
|
1498
|
+
ctx.runMgr.markCancelled();
|
|
1499
|
+
}
|
|
1500
|
+
else {
|
|
1501
|
+
ctx.runMgr.setStopReason('timeout');
|
|
1502
|
+
ctx.log.warn('Sandbox creation exhausted the run timeout', {
|
|
1503
|
+
[NAMZU.RUN_ID]: ctx.runId,
|
|
1504
|
+
'namzu.sandbox.provider_id': params.sandboxProvider.id,
|
|
1505
|
+
...errorAttributes(acquisition.error),
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1508
|
+
yield* resultAssembler.completeRun(rootSpan);
|
|
1509
|
+
return await resultAssembler.finalize();
|
|
1510
|
+
}
|
|
1511
|
+
sandbox = acquisition.sandbox;
|
|
1113
1512
|
toolExecutor.setSandbox(sandbox);
|
|
1114
1513
|
await eventTranslator.emitEvent({
|
|
1115
1514
|
type: 'sandbox_created',
|
|
@@ -1210,7 +1609,7 @@ export async function* query(params) {
|
|
|
1210
1609
|
}
|
|
1211
1610
|
yield* iterationOrchestrator.runLoop();
|
|
1212
1611
|
if (params.pluginManager) {
|
|
1213
|
-
const hookResults = await params.pluginManager.executeHooks('run_end', { runId: ctx.runId }, eventTranslator.emitEvent);
|
|
1612
|
+
const hookResults = await params.pluginManager.executeHooks('run_end', { runId: ctx.runId, signal: ctx.abortController.signal }, eventTranslator.emitEvent);
|
|
1214
1613
|
applyLifecycleHookResults('run_end', hookResults);
|
|
1215
1614
|
yield* eventTranslator.drainPending();
|
|
1216
1615
|
}
|
|
@@ -1326,19 +1725,20 @@ export async function* query(params) {
|
|
|
1326
1725
|
// --- Sandbox lifecycle: destroy after run ---
|
|
1327
1726
|
if (sandbox) {
|
|
1328
1727
|
const sandboxId = sandbox.id;
|
|
1329
|
-
|
|
1330
|
-
|
|
1728
|
+
const teardown = await teardownSandbox(sandbox, sandboxTeardownTimeoutMs);
|
|
1729
|
+
if (teardown.kind === 'destroyed') {
|
|
1331
1730
|
await eventTranslator.emitEvent({
|
|
1332
1731
|
type: 'sandbox_destroyed',
|
|
1333
1732
|
runId: ctx.runId,
|
|
1334
1733
|
sandboxId,
|
|
1335
1734
|
});
|
|
1735
|
+
yield* eventTranslator.drainPending();
|
|
1336
1736
|
ctx.log.info('Sandbox destroyed', { 'namzu.sandbox.id': sandboxId });
|
|
1337
1737
|
}
|
|
1338
|
-
|
|
1738
|
+
else {
|
|
1339
1739
|
ctx.log.error('Sandbox destroy failed', {
|
|
1340
1740
|
'namzu.sandbox.id': sandboxId,
|
|
1341
|
-
|
|
1741
|
+
...errorAttributes(teardown.error),
|
|
1342
1742
|
});
|
|
1343
1743
|
}
|
|
1344
1744
|
}
|
|
@@ -1363,20 +1763,31 @@ export async function* query(params) {
|
|
|
1363
1763
|
* either way — a stale cursor belongs to the client, and must not be able to
|
|
1364
1764
|
* stop the work.
|
|
1365
1765
|
*/
|
|
1366
|
-
async function* catchUpFromCursor(runMgr, cursor, onEventReplay, generation) {
|
|
1766
|
+
async function* catchUpFromCursor(runMgr, cursor, onEventReplay, generation, onReplayObserverError) {
|
|
1367
1767
|
const missed = await runMgr.getRunStore().readEvents({ sinceSeq: cursor.sinceSeq });
|
|
1368
|
-
const replay = resolveRunEventReplay(cursor, {
|
|
1369
|
-
|
|
1768
|
+
const replay = resolveRunEventReplay(cursor, {
|
|
1769
|
+
lastSeq: runMgr.lastEventSeq,
|
|
1770
|
+
...(generation !== undefined ? { generation } : {}),
|
|
1771
|
+
}, missed);
|
|
1772
|
+
if (onEventReplay) {
|
|
1773
|
+
try {
|
|
1774
|
+
// A callback typed `void` may still be implemented with `async` in
|
|
1775
|
+
// TypeScript. Observe that runtime Promise so a late rejection cannot
|
|
1776
|
+
// become process-wide, but never await host code here: replay delivery
|
|
1777
|
+
// and an already-cancelled run must not inherit observer liveness.
|
|
1778
|
+
const settlement = onEventReplay(replay);
|
|
1779
|
+
void Promise.resolve(settlement).catch(onReplayObserverError);
|
|
1780
|
+
}
|
|
1781
|
+
catch (error) {
|
|
1782
|
+
onReplayObserverError(error);
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1370
1785
|
if (replay.status !== 'replayed')
|
|
1371
1786
|
return;
|
|
1372
1787
|
for (const event of replay.events)
|
|
1373
1788
|
yield event;
|
|
1374
1789
|
}
|
|
1375
|
-
|
|
1376
|
-
const fullParams = {
|
|
1377
|
-
...params,
|
|
1378
|
-
resumeHandler: params.resumeHandler ?? autoApproveHandler,
|
|
1379
|
-
};
|
|
1790
|
+
async function drainPreparedQuery(fullParams, listener) {
|
|
1380
1791
|
const gen = query(fullParams);
|
|
1381
1792
|
let result = await gen.next();
|
|
1382
1793
|
while (!result.done) {
|
|
@@ -1387,6 +1798,48 @@ export async function drainQuery(params, listener) {
|
|
|
1387
1798
|
}
|
|
1388
1799
|
return result.value;
|
|
1389
1800
|
}
|
|
1801
|
+
export async function drainQuery(params, listener) {
|
|
1802
|
+
const fullParams = {
|
|
1803
|
+
...params,
|
|
1804
|
+
resumeHandler: params.resumeHandler ?? autoApproveHandler,
|
|
1805
|
+
};
|
|
1806
|
+
return await drainPreparedQuery(fullParams, listener);
|
|
1807
|
+
}
|
|
1808
|
+
/** @internal Canonical resume state already selected by `resumeRun`. */
|
|
1809
|
+
export async function drainQueryWithSelectedResumeState(params, state, listener) {
|
|
1810
|
+
const fullParams = {
|
|
1811
|
+
...params,
|
|
1812
|
+
resumeHandler: params.resumeHandler ?? autoApproveHandler,
|
|
1813
|
+
};
|
|
1814
|
+
if (fullParams.resumeFromCheckpoint !== state.checkpointId) {
|
|
1815
|
+
throw new Error('The selected resume state does not match the requested checkpoint.');
|
|
1816
|
+
}
|
|
1817
|
+
assertSelectedResumeAttribution(fullParams, state);
|
|
1818
|
+
selectedResumeStates.set(fullParams, state);
|
|
1819
|
+
return await drainPreparedQuery(fullParams, listener);
|
|
1820
|
+
}
|
|
1821
|
+
function assertSelectedResumeAttribution(params, state) {
|
|
1822
|
+
const mismatchedFields = [];
|
|
1823
|
+
if (params.runId !== state.runId)
|
|
1824
|
+
mismatchedFields.push('runId');
|
|
1825
|
+
if (params.sessionId !== state.sessionId)
|
|
1826
|
+
mismatchedFields.push('sessionId');
|
|
1827
|
+
if (params.topicId !== state.topicId)
|
|
1828
|
+
mismatchedFields.push('topicId');
|
|
1829
|
+
if (params.projectId !== state.projectId)
|
|
1830
|
+
mismatchedFields.push('projectId');
|
|
1831
|
+
if (params.tenantId !== state.tenantId)
|
|
1832
|
+
mismatchedFields.push('tenantId');
|
|
1833
|
+
if (params.parentRunId !== state.parentRunId)
|
|
1834
|
+
mismatchedFields.push('parentRunId');
|
|
1835
|
+
if (mismatchedFields.length === 0)
|
|
1836
|
+
return;
|
|
1837
|
+
throw new NamzuError({
|
|
1838
|
+
code: 'invalid_config',
|
|
1839
|
+
message: 'The selected resume state does not match the run attribution supplied to the query.',
|
|
1840
|
+
details: { fields: mismatchedFields },
|
|
1841
|
+
});
|
|
1842
|
+
}
|
|
1390
1843
|
function withDeferredDiscoveryTool(tools, allowedTools) {
|
|
1391
1844
|
if (!allowedTools)
|
|
1392
1845
|
return undefined;
|