@namzu/sdk 45.1.0 → 48.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 +436 -8
- package/README.md +7 -8
- package/dist/advisory/history.d.ts.map +1 -1
- package/dist/advisory/history.js +21 -1
- package/dist/advisory/history.js.map +1 -1
- package/dist/advisory/index.d.ts +1 -1
- package/dist/advisory/index.d.ts.map +1 -1
- package/dist/advisory/index.js +1 -1
- package/dist/advisory/index.js.map +1 -1
- package/dist/advisory/registry.d.ts +17 -0
- package/dist/advisory/registry.d.ts.map +1 -1
- package/dist/advisory/registry.js +26 -0
- package/dist/advisory/registry.js.map +1 -1
- package/dist/agents/PipelineAgent.d.ts +2 -46
- package/dist/agents/PipelineAgent.d.ts.map +1 -1
- package/dist/agents/PipelineAgent.js +2 -242
- package/dist/agents/PipelineAgent.js.map +1 -1
- package/dist/agents/QueryAgent.d.ts +21 -0
- package/dist/agents/QueryAgent.d.ts.map +1 -0
- package/dist/agents/QueryAgent.js +214 -0
- package/dist/agents/QueryAgent.js.map +1 -0
- package/dist/agents/ReactiveAgent.d.ts +4 -16
- package/dist/agents/ReactiveAgent.d.ts.map +1 -1
- package/dist/agents/ReactiveAgent.js +4 -183
- package/dist/agents/ReactiveAgent.js.map +1 -1
- package/dist/agents/RouterAgent.d.ts +2 -20
- package/dist/agents/RouterAgent.d.ts.map +1 -1
- package/dist/agents/RouterAgent.js +2 -266
- package/dist/agents/RouterAgent.js.map +1 -1
- package/dist/agents/SupervisorAgent.d.ts +3 -43
- package/dist/agents/SupervisorAgent.d.ts.map +1 -1
- package/dist/agents/SupervisorAgent.js +3 -418
- package/dist/agents/SupervisorAgent.js.map +1 -1
- package/dist/agents/defineAgent.d.ts +2 -1
- package/dist/agents/defineAgent.d.ts.map +1 -1
- package/dist/agents/defineAgent.js +6 -1
- package/dist/agents/defineAgent.js.map +1 -1
- package/dist/agents/examples/PipelineAgent.d.ts +46 -0
- package/dist/agents/examples/PipelineAgent.d.ts.map +1 -0
- package/dist/agents/examples/PipelineAgent.js +242 -0
- package/dist/agents/examples/PipelineAgent.js.map +1 -0
- package/dist/agents/examples/RouterAgent.d.ts +22 -0
- package/dist/agents/examples/RouterAgent.d.ts.map +1 -0
- package/dist/agents/examples/RouterAgent.js +268 -0
- package/dist/agents/examples/RouterAgent.js.map +1 -0
- package/dist/agents/examples/SupervisorAgent.d.ts +45 -0
- package/dist/agents/examples/SupervisorAgent.d.ts.map +1 -0
- package/dist/agents/examples/SupervisorAgent.js +406 -0
- package/dist/agents/examples/SupervisorAgent.js.map +1 -0
- package/dist/agents/explore.d.ts +6 -3
- package/dist/agents/explore.d.ts.map +1 -1
- package/dist/agents/explore.js +6 -3
- package/dist/agents/explore.js.map +1 -1
- package/dist/agents/forward-options.d.ts +11 -0
- package/dist/agents/forward-options.d.ts.map +1 -0
- package/dist/agents/forward-options.js +15 -0
- package/dist/agents/forward-options.js.map +1 -0
- package/dist/agents/index.d.ts +1 -0
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +2 -0
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/runAgent.d.ts +19 -8
- package/dist/agents/runAgent.d.ts.map +1 -1
- package/dist/agents/runAgent.js +99 -29
- package/dist/agents/runAgent.js.map +1 -1
- package/dist/authorization/command-line.d.ts +2 -0
- package/dist/authorization/command-line.d.ts.map +1 -1
- package/dist/authorization/command-line.js +2 -2
- package/dist/authorization/command-line.js.map +1 -1
- package/dist/authorization/gate.d.ts +13 -2
- package/dist/authorization/gate.d.ts.map +1 -1
- package/dist/authorization/gate.js +37 -5
- package/dist/authorization/gate.js.map +1 -1
- package/dist/authorization/program.d.ts +151 -0
- package/dist/authorization/program.d.ts.map +1 -0
- package/dist/authorization/program.js +713 -0
- package/dist/authorization/program.js.map +1 -0
- package/dist/authorization/reexec-wrapper.d.ts +106 -0
- package/dist/authorization/reexec-wrapper.d.ts.map +1 -0
- package/dist/authorization/reexec-wrapper.js +532 -0
- package/dist/authorization/reexec-wrapper.js.map +1 -0
- package/dist/authorization/rules.d.ts +9 -0
- package/dist/authorization/rules.d.ts.map +1 -1
- package/dist/authorization/rules.js +27 -1
- package/dist/authorization/rules.js.map +1 -1
- package/dist/authorization/shell-lexer.d.ts +39 -0
- package/dist/authorization/shell-lexer.d.ts.map +1 -1
- package/dist/authorization/shell-lexer.js +113 -69
- package/dist/authorization/shell-lexer.js.map +1 -1
- package/dist/bridge/sse/mapper.d.ts.map +1 -1
- package/dist/bridge/sse/mapper.js +6 -0
- package/dist/bridge/sse/mapper.js.map +1 -1
- package/dist/capabilities/index.d.ts +54 -0
- package/dist/capabilities/index.d.ts.map +1 -0
- package/dist/capabilities/index.js +92 -0
- package/dist/capabilities/index.js.map +1 -0
- package/dist/config/registry.d.ts +2 -1
- package/dist/config/registry.d.ts.map +1 -1
- package/dist/config/registry.js +3 -2
- package/dist/config/registry.js.map +1 -1
- package/dist/connector/index.d.ts +4 -4
- package/dist/connector/index.d.ts.map +1 -1
- package/dist/connector/index.js +3 -3
- package/dist/connector/index.js.map +1 -1
- package/dist/connector/mcp/adapter.d.ts +16 -1
- package/dist/connector/mcp/adapter.d.ts.map +1 -1
- package/dist/connector/mcp/adapter.js +60 -4
- package/dist/connector/mcp/adapter.js.map +1 -1
- package/dist/connector/mcp/client.d.ts +13 -4
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +20 -3
- package/dist/connector/mcp/client.js.map +1 -1
- package/dist/connector/mcp/discovery.d.ts +24 -1
- package/dist/connector/mcp/discovery.d.ts.map +1 -1
- package/dist/connector/mcp/discovery.js +44 -0
- package/dist/connector/mcp/discovery.js.map +1 -1
- package/dist/connector/mcp/index.d.ts +2 -0
- package/dist/connector/mcp/index.d.ts.map +1 -1
- package/dist/connector/mcp/index.js +11 -0
- package/dist/connector/mcp/index.js.map +1 -1
- package/dist/connector/mcp/mcp-toolset.d.ts +133 -0
- package/dist/connector/mcp/mcp-toolset.d.ts.map +1 -0
- package/dist/connector/mcp/mcp-toolset.js +399 -0
- package/dist/connector/mcp/mcp-toolset.js.map +1 -0
- package/dist/connector/tools/index.d.ts +2 -2
- package/dist/connector/tools/index.d.ts.map +1 -1
- package/dist/connector/tools/index.js +1 -1
- package/dist/connector/tools/index.js.map +1 -1
- package/dist/connector/tools/router.d.ts +15 -13
- package/dist/connector/tools/router.d.ts.map +1 -1
- package/dist/connector/tools/router.js +30 -51
- package/dist/connector/tools/router.js.map +1 -1
- package/dist/contracts/a2a.d.ts +2 -2
- package/dist/directory/derive-supervisor.d.ts +2 -2
- package/dist/directory/derive-supervisor.d.ts.map +1 -1
- package/dist/directory/derive-supervisor.js +6 -7
- package/dist/directory/derive-supervisor.js.map +1 -1
- package/dist/directory/derive.d.ts.map +1 -1
- package/dist/directory/derive.js +5 -5
- package/dist/directory/derive.js.map +1 -1
- package/dist/execution/code-runtime/types.d.ts +2 -2
- package/dist/execution/code-runtime/types.js +1 -1
- package/dist/invariants/index.d.ts +2 -1
- package/dist/invariants/index.d.ts.map +1 -1
- package/dist/invariants/index.js +3 -2
- package/dist/invariants/index.js.map +1 -1
- package/dist/manager/agent/lifecycle.d.ts.map +1 -1
- package/dist/manager/agent/lifecycle.js +9 -0
- package/dist/manager/agent/lifecycle.js.map +1 -1
- package/dist/manager/connector/environment.d.ts +6 -0
- package/dist/manager/connector/environment.d.ts.map +1 -1
- package/dist/manager/connector/environment.js +11 -4
- package/dist/manager/connector/environment.js.map +1 -1
- package/dist/manager/connector/index.d.ts +2 -2
- package/dist/manager/connector/index.d.ts.map +1 -1
- package/dist/manager/connector/index.js +2 -2
- package/dist/manager/connector/index.js.map +1 -1
- package/dist/manager/connector/tenant.d.ts +6 -0
- package/dist/manager/connector/tenant.d.ts.map +1 -1
- package/dist/manager/connector/tenant.js +11 -4
- package/dist/manager/connector/tenant.js.map +1 -1
- package/dist/manager/index.d.ts +2 -2
- package/dist/manager/index.d.ts.map +1 -1
- package/dist/manager/index.js +2 -2
- package/dist/manager/index.js.map +1 -1
- package/dist/manager/resident/learning-observation.d.ts +4 -4
- package/dist/manager/resident/learning.d.ts +36 -36
- package/dist/manager/session/attribution.d.ts +22 -0
- package/dist/manager/session/attribution.d.ts.map +1 -0
- package/dist/manager/session/attribution.js +64 -0
- package/dist/manager/session/attribution.js.map +1 -0
- package/dist/manager/session/turn-recorder.d.ts +14 -0
- package/dist/manager/session/turn-recorder.d.ts.map +1 -1
- package/dist/manager/session/turn-recorder.js +208 -55
- package/dist/manager/session/turn-recorder.js.map +1 -1
- package/dist/peers/address.d.ts +36 -0
- package/dist/peers/address.d.ts.map +1 -0
- package/dist/peers/address.js +52 -0
- package/dist/peers/address.js.map +1 -0
- package/dist/peers/client.d.ts +47 -0
- package/dist/peers/client.d.ts.map +1 -0
- package/dist/peers/client.js +132 -0
- package/dist/peers/client.js.map +1 -0
- package/dist/peers/dir.d.ts +88 -0
- package/dist/peers/dir.d.ts.map +1 -0
- package/dist/peers/dir.js +139 -0
- package/dist/peers/dir.js.map +1 -0
- package/dist/peers/endpoint.d.ts +144 -0
- package/dist/peers/endpoint.d.ts.map +1 -0
- package/dist/peers/endpoint.js +420 -0
- package/dist/peers/endpoint.js.map +1 -0
- package/dist/peers/envelope.d.ts +42 -0
- package/dist/peers/envelope.d.ts.map +1 -0
- package/dist/peers/envelope.js +110 -0
- package/dist/peers/envelope.js.map +1 -0
- package/dist/peers/index.d.ts +30 -0
- package/dist/peers/index.d.ts.map +1 -0
- package/dist/peers/index.js +22 -0
- package/dist/peers/index.js.map +1 -0
- package/dist/peers/protocol.d.ts +645 -0
- package/dist/peers/protocol.d.ts.map +1 -0
- package/dist/peers/protocol.js +151 -0
- package/dist/peers/protocol.js.map +1 -0
- package/dist/peers/record.d.ts +71 -0
- package/dist/peers/record.d.ts.map +1 -0
- package/dist/peers/record.js +45 -0
- package/dist/peers/record.js.map +1 -0
- package/dist/peers/registry.d.ts +54 -0
- package/dist/peers/registry.d.ts.map +1 -0
- package/dist/peers/registry.js +213 -0
- package/dist/peers/registry.js.map +1 -0
- package/dist/plugin/define.d.ts +24 -0
- package/dist/plugin/define.d.ts.map +1 -0
- package/dist/plugin/define.js +42 -0
- package/dist/plugin/define.js.map +1 -0
- package/dist/plugin/index.d.ts +2 -0
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +1 -0
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/lifecycle.d.ts +27 -3
- package/dist/plugin/lifecycle.d.ts.map +1 -1
- package/dist/plugin/lifecycle.js +242 -92
- package/dist/plugin/lifecycle.js.map +1 -1
- package/dist/plugin/resolver.d.ts +2 -2
- package/dist/plugin/resolver.d.ts.map +1 -1
- package/dist/plugin/resolver.js.map +1 -1
- package/dist/plugin/shell-hook.d.ts.map +1 -1
- package/dist/plugin/shell-hook.js +17 -3
- package/dist/plugin/shell-hook.js.map +1 -1
- package/dist/pricing/catalogue.generated.d.ts.map +1 -1
- package/dist/pricing/catalogue.generated.js +28 -4
- package/dist/pricing/catalogue.generated.js.map +1 -1
- package/dist/probe/errors.d.ts +2 -1
- package/dist/probe/errors.d.ts.map +1 -1
- package/dist/probe/errors.js +3 -2
- package/dist/probe/errors.js.map +1 -1
- package/dist/prompt/coding-agent-doctrine.d.ts +18 -7
- package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
- package/dist/prompt/coding-agent-doctrine.js +11 -6
- package/dist/prompt/coding-agent-doctrine.js.map +1 -1
- package/dist/prompt/contributions.d.ts +4 -1
- package/dist/prompt/contributions.d.ts.map +1 -1
- package/dist/prompt/contributions.js +7 -2
- package/dist/prompt/contributions.js.map +1 -1
- package/dist/prompt/index.d.ts +1 -1
- package/dist/prompt/index.d.ts.map +1 -1
- package/dist/prompt/index.js +1 -1
- package/dist/prompt/index.js.map +1 -1
- package/dist/provider/collect-chat-completion.d.ts +6 -1
- package/dist/provider/collect-chat-completion.d.ts.map +1 -1
- package/dist/provider/collect-chat-completion.js +88 -10
- package/dist/provider/collect-chat-completion.js.map +1 -1
- package/dist/provider/mock.d.ts.map +1 -1
- package/dist/provider/mock.js +23 -6
- package/dist/provider/mock.js.map +1 -1
- package/dist/provider/registry.d.ts +2 -1
- package/dist/provider/registry.d.ts.map +1 -1
- package/dist/provider/registry.js +3 -2
- package/dist/provider/registry.js.map +1 -1
- package/dist/provider/tool-call-framing.d.ts +164 -0
- package/dist/provider/tool-call-framing.d.ts.map +1 -0
- package/dist/provider/tool-call-framing.js +163 -0
- package/dist/provider/tool-call-framing.js.map +1 -0
- package/dist/public-runtime.d.ts +27 -14
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +49 -11
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +9 -6
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +13 -5
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +16 -5
- package/dist/public-types.d.ts.map +1 -1
- package/dist/read-model/registry.d.ts +2 -1
- package/dist/read-model/registry.d.ts.map +1 -1
- package/dist/read-model/registry.js +3 -2
- package/dist/read-model/registry.js.map +1 -1
- package/dist/registry/ManagedRegistry.d.ts +30 -0
- package/dist/registry/ManagedRegistry.d.ts.map +1 -1
- package/dist/registry/ManagedRegistry.js +45 -6
- package/dist/registry/ManagedRegistry.js.map +1 -1
- package/dist/registry/collision.d.ts +57 -0
- package/dist/registry/collision.d.ts.map +1 -0
- package/dist/registry/collision.js +41 -0
- package/dist/registry/collision.js.map +1 -0
- package/dist/registry/command/index.d.ts +5 -3
- package/dist/registry/command/index.d.ts.map +1 -1
- package/dist/registry/command/index.js +6 -4
- package/dist/registry/command/index.js.map +1 -1
- package/dist/registry/index.d.ts +3 -4
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/index.js +2 -2
- package/dist/registry/index.js.map +1 -1
- package/dist/registry/plugin/index.d.ts.map +1 -1
- package/dist/registry/plugin/index.js +14 -1
- package/dist/registry/plugin/index.js.map +1 -1
- package/dist/registry/tool/callable.d.ts +22 -0
- package/dist/registry/tool/callable.d.ts.map +1 -0
- package/dist/registry/tool/callable.js +28 -0
- package/dist/registry/tool/callable.js.map +1 -0
- package/dist/registry/tool/execute.d.ts +14 -77
- package/dist/registry/tool/execute.d.ts.map +1 -1
- package/dist/registry/tool/execute.js +15 -720
- package/dist/registry/tool/execute.js.map +1 -1
- package/dist/registry/tool/portable.d.ts +25 -0
- package/dist/registry/tool/portable.d.ts.map +1 -1
- package/dist/registry/tool/portable.js +50 -0
- package/dist/registry/tool/portable.js.map +1 -1
- package/dist/registry/tool/presentation.d.ts +6 -5
- package/dist/registry/tool/presentation.d.ts.map +1 -1
- package/dist/registry/tool/presentation.js +3 -3
- package/dist/registry/tool/presentation.js.map +1 -1
- package/dist/runtime/bidi/session.d.ts +5 -4
- package/dist/runtime/bidi/session.d.ts.map +1 -1
- package/dist/runtime/bidi/session.js +18 -1
- package/dist/runtime/bidi/session.js.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.d.ts +82 -13
- package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.js +227 -17
- package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +37 -5
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +103 -14
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/file-evidence-replay.d.ts +1 -1
- package/dist/runtime/query/file-evidence-replay.d.ts.map +1 -1
- package/dist/runtime/query/file-evidence-replay.js +8 -7
- package/dist/runtime/query/file-evidence-replay.js.map +1 -1
- package/dist/runtime/query/fork/prepare.d.ts +4 -1
- package/dist/runtime/query/fork/prepare.d.ts.map +1 -1
- package/dist/runtime/query/fork/prepare.js +4 -0
- package/dist/runtime/query/fork/prepare.js.map +1 -1
- package/dist/runtime/query/guardrail-presets.d.ts +4 -3
- package/dist/runtime/query/guardrail-presets.d.ts.map +1 -1
- package/dist/runtime/query/guardrail-presets.js +4 -3
- package/dist/runtime/query/guardrail-presets.js.map +1 -1
- package/dist/runtime/query/index.d.ts +23 -10
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +149 -70
- 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 +8 -1
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.js +1 -1
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +2 -2
- package/dist/runtime/query/iteration/phases/context.d.ts.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 +55 -2
- 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 +342 -116
- package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
- package/dist/runtime/query/iteration/tool-input.d.ts +79 -0
- package/dist/runtime/query/iteration/tool-input.d.ts.map +1 -0
- package/dist/runtime/query/iteration/tool-input.js +291 -0
- package/dist/runtime/query/iteration/tool-input.js.map +1 -0
- package/dist/runtime/query/observation-context.d.ts +2 -2
- package/dist/runtime/query/observation-context.d.ts.map +1 -1
- package/dist/runtime/query/observation-context.js.map +1 -1
- package/dist/runtime/query/prelude-lease.d.ts +18 -0
- package/dist/runtime/query/prelude-lease.d.ts.map +1 -0
- package/dist/runtime/query/prelude-lease.js +121 -0
- package/dist/runtime/query/prelude-lease.js.map +1 -0
- package/dist/runtime/query/prepare-turn.d.ts.map +1 -1
- package/dist/runtime/query/prepare-turn.js +386 -187
- package/dist/runtime/query/prepare-turn.js.map +1 -1
- package/dist/runtime/query/prompt-cache.d.ts +2 -2
- package/dist/runtime/query/prompt-cache.d.ts.map +1 -1
- package/dist/runtime/query/prompt.d.ts +2 -2
- package/dist/runtime/query/prompt.d.ts.map +1 -1
- package/dist/runtime/query/prompt.js +1 -1
- package/dist/runtime/query/prompt.js.map +1 -1
- package/dist/runtime/query/resume-session.d.ts.map +1 -1
- package/dist/runtime/query/resume-session.js +37 -2
- package/dist/runtime/query/resume-session.js.map +1 -1
- package/dist/runtime/query/review-policy.d.ts +65 -3
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +143 -22
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/runtime/query/tooling.d.ts +3 -2
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/runtime/query/turn-state.d.ts.map +1 -1
- package/dist/runtime/query/turn-state.js +5 -0
- package/dist/runtime/query/turn-state.js.map +1 -1
- package/dist/runtime/system-events.d.ts +112 -0
- package/dist/runtime/system-events.d.ts.map +1 -0
- package/dist/runtime/system-events.js +183 -0
- package/dist/runtime/system-events.js.map +1 -0
- package/dist/scheduler/delegating.d.ts +2 -1
- package/dist/scheduler/delegating.d.ts.map +1 -1
- package/dist/scheduler/delegating.js +3 -2
- package/dist/scheduler/delegating.js.map +1 -1
- package/dist/skills/index.d.ts +1 -1
- package/dist/skills/index.d.ts.map +1 -1
- package/dist/skills/index.js +1 -1
- package/dist/skills/index.js.map +1 -1
- package/dist/skills/registry.d.ts +18 -0
- package/dist/skills/registry.d.ts.map +1 -1
- package/dist/skills/registry.js +20 -0
- package/dist/skills/registry.js.map +1 -1
- package/dist/store/evidence/index-page.d.ts +2 -2
- package/dist/store/session-log/conformance.d.ts +1 -1
- package/dist/store/session-log/conformance.d.ts.map +1 -1
- package/dist/store/session-log/conformance.js +49 -8
- package/dist/store/session-log/conformance.js.map +1 -1
- package/dist/store/session-log/core.d.ts +8 -3
- package/dist/store/session-log/core.d.ts.map +1 -1
- package/dist/store/session-log/core.js +2 -1
- package/dist/store/session-log/core.js.map +1 -1
- package/dist/store/session-log/fold.d.ts +12 -0
- package/dist/store/session-log/fold.d.ts.map +1 -1
- package/dist/store/session-log/fold.js +57 -7
- package/dist/store/session-log/fold.js.map +1 -1
- package/dist/store/session-log/index.d.ts +2 -2
- package/dist/store/session-log/index.d.ts.map +1 -1
- package/dist/store/session-log/index.js +1 -1
- package/dist/store/session-log/index.js.map +1 -1
- package/dist/test-support/toolset.d.ts +19 -0
- package/dist/test-support/toolset.d.ts.map +1 -0
- package/dist/test-support/toolset.js +20 -0
- package/dist/test-support/toolset.js.map +1 -0
- package/dist/tools/builtins/bash.d.ts +29 -0
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +19 -9
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/browser-url.d.ts +1 -1
- package/dist/tools/builtins/browser-url.js +1 -1
- package/dist/tools/builtins/browser.d.ts +6 -6
- package/dist/tools/builtins/computer-use-coordinates.d.ts +65 -0
- package/dist/tools/builtins/computer-use-coordinates.d.ts.map +1 -0
- package/dist/tools/builtins/computer-use-coordinates.js +123 -0
- package/dist/tools/builtins/computer-use-coordinates.js.map +1 -0
- package/dist/tools/builtins/computer-use-image.d.ts +77 -0
- package/dist/tools/builtins/computer-use-image.d.ts.map +1 -0
- package/dist/tools/builtins/computer-use-image.js +223 -0
- package/dist/tools/builtins/computer-use-image.js.map +1 -0
- package/dist/tools/builtins/computer-use.d.ts +519 -14
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js +1196 -183
- package/dist/tools/builtins/computer-use.js.map +1 -1
- package/dist/tools/builtins/edit.d.ts.map +1 -1
- package/dist/tools/builtins/edit.js +9 -1
- package/dist/tools/builtins/edit.js.map +1 -1
- package/dist/tools/builtins/index.d.ts +2 -1
- package/dist/tools/builtins/index.d.ts.map +1 -1
- package/dist/tools/builtins/index.js +1 -1
- package/dist/tools/builtins/index.js.map +1 -1
- package/dist/tools/builtins/json-string-hint.d.ts +15 -0
- package/dist/tools/builtins/json-string-hint.d.ts.map +1 -0
- package/dist/tools/builtins/json-string-hint.js +17 -0
- package/dist/tools/builtins/json-string-hint.js.map +1 -0
- package/dist/tools/builtins/search-tools.d.ts.map +1 -1
- package/dist/tools/builtins/search-tools.js +7 -15
- package/dist/tools/builtins/search-tools.js.map +1 -1
- package/dist/tools/builtins/skill.d.ts +74 -0
- package/dist/tools/builtins/skill.d.ts.map +1 -1
- package/dist/tools/builtins/skill.js +214 -174
- package/dist/tools/builtins/skill.js.map +1 -1
- package/dist/tools/builtins/write-file.d.ts.map +1 -1
- package/dist/tools/builtins/write-file.js +11 -0
- package/dist/tools/builtins/write-file.js.map +1 -1
- package/dist/tools/command-shell.d.ts +10 -0
- package/dist/tools/command-shell.d.ts.map +1 -1
- package/dist/tools/command-shell.js +45 -1
- package/dist/tools/command-shell.js.map +1 -1
- package/dist/tools/coordinator/agent.d.ts.map +1 -1
- package/dist/tools/coordinator/agent.js +5 -0
- package/dist/tools/coordinator/agent.js.map +1 -1
- package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -1
- package/dist/tools/coordinator/ask-user-question.js +26 -13
- package/dist/tools/coordinator/ask-user-question.js.map +1 -1
- package/dist/tools/coordinator/index.d.ts.map +1 -1
- package/dist/tools/coordinator/index.js +5 -0
- package/dist/tools/coordinator/index.js.map +1 -1
- package/dist/tools/coordinator/question-options.d.ts +78 -0
- package/dist/tools/coordinator/question-options.d.ts.map +1 -0
- package/dist/tools/coordinator/question-options.js +153 -0
- package/dist/tools/coordinator/question-options.js.map +1 -0
- package/dist/tools/defineTool.d.ts +12 -0
- package/dist/tools/defineTool.d.ts.map +1 -1
- package/dist/tools/defineTool.js +24 -0
- package/dist/tools/defineTool.js.map +1 -1
- package/dist/tools/memory/search.d.ts.map +1 -1
- package/dist/tools/memory/search.js +4 -1
- package/dist/tools/memory/search.js.map +1 -1
- package/dist/tools/memory/update.d.ts.map +1 -1
- package/dist/tools/memory/update.js +8 -5
- package/dist/tools/memory/update.js.map +1 -1
- package/dist/tools/render-nonce.d.ts +47 -0
- package/dist/tools/render-nonce.d.ts.map +1 -0
- package/dist/tools/render-nonce.js +63 -0
- package/dist/tools/render-nonce.js.map +1 -0
- package/dist/tools/roster.d.ts +46 -19
- package/dist/tools/roster.d.ts.map +1 -1
- package/dist/tools/roster.js +63 -33
- package/dist/tools/roster.js.map +1 -1
- package/dist/tools/schedules/present.d.ts.map +1 -1
- package/dist/tools/schedules/present.js +2 -0
- package/dist/tools/schedules/present.js.map +1 -1
- package/dist/tools/schedules/schedule-tool.d.ts +6 -5
- package/dist/tools/schedules/schedule-tool.d.ts.map +1 -1
- package/dist/tools/schedules/schedule-tool.js +208 -37
- package/dist/tools/schedules/schedule-tool.js.map +1 -1
- package/dist/tools/schedules/types.d.ts +120 -6
- package/dist/tools/schedules/types.d.ts.map +1 -1
- package/dist/tools/trusted-read-only.d.ts +9 -5
- package/dist/tools/trusted-read-only.d.ts.map +1 -1
- package/dist/tools/trusted-read-only.js +14 -10
- package/dist/tools/trusted-read-only.js.map +1 -1
- package/dist/tools/untrusted-envelope.d.ts +67 -28
- package/dist/tools/untrusted-envelope.d.ts.map +1 -1
- package/dist/tools/untrusted-envelope.js +108 -59
- package/dist/tools/untrusted-envelope.js.map +1 -1
- package/dist/toolsets/combine.d.ts +44 -0
- package/dist/toolsets/combine.d.ts.map +1 -0
- package/dist/toolsets/combine.js +153 -0
- package/dist/toolsets/combine.js.map +1 -0
- package/dist/toolsets/manager.d.ts +201 -0
- package/dist/toolsets/manager.d.ts.map +1 -0
- package/dist/toolsets/manager.js +837 -0
- package/dist/toolsets/manager.js.map +1 -0
- package/dist/toolsets/source-glob.d.ts +15 -0
- package/dist/toolsets/source-glob.d.ts.map +1 -0
- package/dist/toolsets/source-glob.js +23 -0
- package/dist/toolsets/source-glob.js.map +1 -0
- package/dist/toolsets/toolset.d.ts +20 -0
- package/dist/toolsets/toolset.d.ts.map +1 -0
- package/dist/toolsets/toolset.js +28 -0
- package/dist/toolsets/toolset.js.map +1 -0
- package/dist/toolsets/types.d.ts +128 -0
- package/dist/toolsets/types.d.ts.map +1 -0
- package/dist/toolsets/types.js +33 -0
- package/dist/toolsets/types.js.map +1 -0
- package/dist/toolsets/wrappers.d.ts +59 -0
- package/dist/toolsets/wrappers.d.ts.map +1 -0
- package/dist/toolsets/wrappers.js +165 -0
- package/dist/toolsets/wrappers.js.map +1 -0
- package/dist/types/agent/base.d.ts +27 -16
- package/dist/types/agent/base.d.ts.map +1 -1
- package/dist/types/agent/index.d.ts +1 -0
- package/dist/types/agent/index.d.ts.map +1 -1
- package/dist/types/agent/index.js +1 -0
- package/dist/types/agent/index.js.map +1 -1
- package/dist/types/agent/pipeline.d.ts +2 -0
- package/dist/types/agent/pipeline.d.ts.map +1 -1
- package/dist/types/agent/query.d.ts +117 -0
- package/dist/types/agent/query.d.ts.map +1 -0
- package/dist/types/agent/query.js +2 -0
- package/dist/types/agent/query.js.map +1 -0
- package/dist/types/agent/reactive.d.ts +2 -129
- package/dist/types/agent/reactive.d.ts.map +1 -1
- package/dist/types/agent/router.d.ts +2 -0
- package/dist/types/agent/router.d.ts.map +1 -1
- package/dist/types/agent/supervisor.d.ts +5 -2
- package/dist/types/agent/supervisor.d.ts.map +1 -1
- package/dist/types/authorization/index.d.ts +70 -12
- package/dist/types/authorization/index.d.ts.map +1 -1
- package/dist/types/authorization/index.js +11 -0
- package/dist/types/authorization/index.js.map +1 -1
- package/dist/types/computer-use/index.d.ts +176 -0
- package/dist/types/computer-use/index.d.ts.map +1 -1
- package/dist/types/computer-use/index.js.map +1 -1
- package/dist/types/connector/mcp.d.ts +32 -0
- package/dist/types/connector/mcp.d.ts.map +1 -1
- package/dist/types/errors/index.d.ts +15 -0
- package/dist/types/errors/index.d.ts.map +1 -1
- package/dist/types/errors/index.js.map +1 -1
- package/dist/types/hitl/index.d.ts +57 -0
- package/dist/types/hitl/index.d.ts.map +1 -1
- package/dist/types/hitl/index.js.map +1 -1
- package/dist/types/message/index.d.ts +130 -9
- package/dist/types/message/index.d.ts.map +1 -1
- package/dist/types/message/index.js +4 -1
- package/dist/types/message/index.js.map +1 -1
- package/dist/types/plugin/index.d.ts +22 -4
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/plugin/index.js +1 -0
- package/dist/types/plugin/index.js.map +1 -1
- package/dist/types/provider/chat.d.ts +5 -0
- package/dist/types/provider/chat.d.ts.map +1 -1
- package/dist/types/provider/config.d.ts +8 -3
- package/dist/types/provider/config.d.ts.map +1 -1
- package/dist/types/provider/stream.d.ts +39 -0
- package/dist/types/provider/stream.d.ts.map +1 -1
- package/dist/types/sandbox/index.d.ts +1 -1
- package/dist/types/session/events.d.ts +14 -3
- package/dist/types/session/events.d.ts.map +1 -1
- package/dist/types/session/events.js.map +1 -1
- package/dist/types/tool/index.d.ts +171 -91
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/types/toolset/index.d.ts +10 -40
- package/dist/types/toolset/index.d.ts.map +1 -1
- package/package.json +3 -1
- package/src/advisory/history.ts +27 -2
- package/src/advisory/index.ts +1 -1
- package/src/advisory/registry.ts +33 -0
- package/src/agents/AGENTS.md +14 -7
- package/src/agents/PipelineAgent.ts +2 -303
- package/src/agents/QueryAgent.ts +269 -0
- package/src/agents/ReactiveAgent.ts +6 -216
- package/src/agents/RouterAgent.ts +2 -337
- package/src/agents/SupervisorAgent.ts +3 -476
- package/src/agents/defineAgent.ts +13 -2
- package/src/agents/examples/PipelineAgent.ts +302 -0
- package/src/agents/examples/RouterAgent.ts +338 -0
- package/src/agents/examples/SupervisorAgent.ts +472 -0
- package/src/agents/explore.ts +6 -3
- package/src/agents/forward-options.ts +37 -0
- package/src/agents/index.ts +2 -0
- package/src/agents/runAgent.ts +144 -37
- package/src/authorization/command-line.ts +2 -2
- package/src/authorization/gate.ts +46 -5
- package/src/authorization/program.ts +773 -0
- package/src/authorization/reexec-wrapper.ts +589 -0
- package/src/authorization/rules.ts +36 -1
- package/src/authorization/shell-lexer.ts +136 -63
- package/src/bridge/sse/mapper.ts +6 -0
- package/src/capabilities/index.ts +157 -0
- package/src/config/registry.ts +4 -1
- package/src/connector/index.ts +9 -2
- package/src/connector/mcp/adapter.ts +58 -3
- package/src/connector/mcp/client.ts +20 -4
- package/src/connector/mcp/discovery.ts +60 -0
- package/src/connector/mcp/index.ts +13 -0
- package/src/connector/mcp/mcp-toolset.ts +515 -0
- package/src/connector/tools/index.ts +2 -2
- package/src/connector/tools/router.ts +35 -58
- package/src/directory/derive-supervisor.ts +12 -8
- package/src/directory/derive.ts +8 -5
- package/src/execution/code-runtime/types.ts +2 -2
- package/src/invariants/index.ts +4 -1
- package/src/manager/agent/lifecycle.ts +9 -0
- package/src/manager/connector/environment.ts +17 -4
- package/src/manager/connector/index.ts +2 -2
- package/src/manager/connector/tenant.ts +17 -4
- package/src/manager/index.ts +2 -2
- package/src/manager/session/attribution.ts +79 -0
- package/src/manager/session/turn-recorder.ts +211 -55
- package/src/peers/address.ts +58 -0
- package/src/peers/client.ts +202 -0
- package/src/peers/dir.ts +176 -0
- package/src/peers/endpoint.ts +564 -0
- package/src/peers/envelope.ts +121 -0
- package/src/peers/index.ts +96 -0
- package/src/peers/protocol.ts +196 -0
- package/src/peers/record.ts +56 -0
- package/src/peers/registry.ts +241 -0
- package/src/plugin/define.ts +68 -0
- package/src/plugin/index.ts +2 -0
- package/src/plugin/lifecycle.ts +286 -106
- package/src/plugin/resolver.ts +6 -3
- package/src/plugin/shell-hook.ts +21 -5
- package/src/pricing/catalogue.generated.ts +28 -4
- package/src/pricing/rates.source.json +27 -6
- package/src/probe/errors.ts +4 -1
- package/src/prompt/coding-agent-doctrine.ts +22 -10
- package/src/prompt/contributions.ts +12 -2
- package/src/prompt/index.ts +1 -0
- package/src/provider/collect-chat-completion.ts +96 -11
- package/src/provider/mock.ts +24 -6
- package/src/provider/registry.ts +4 -1
- package/src/provider/tool-call-framing.ts +226 -0
- package/src/public-runtime.ts +152 -9
- package/src/public-tools.ts +43 -5
- package/src/public-types.ts +65 -6
- package/src/read-model/registry.ts +7 -2
- package/src/registry/ManagedRegistry.ts +57 -6
- package/src/registry/collision.ts +64 -0
- package/src/registry/command/index.ts +7 -3
- package/src/registry/index.ts +3 -9
- package/src/registry/plugin/index.ts +14 -1
- package/src/registry/tool/callable.ts +36 -0
- package/src/registry/tool/execute.ts +16 -839
- package/src/registry/tool/portable.ts +59 -0
- package/src/registry/tool/presentation.ts +6 -5
- package/src/runtime/bidi/session.ts +24 -5
- package/src/runtime/query/executor/tool-call-admission.ts +288 -22
- package/src/runtime/query/executor.ts +129 -16
- package/src/runtime/query/file-evidence-replay.ts +8 -7
- package/src/runtime/query/fork/prepare.ts +6 -1
- package/src/runtime/query/guardrail-presets.ts +4 -3
- package/src/runtime/query/index.ts +199 -101
- package/src/runtime/query/iteration/index.ts +13 -3
- package/src/runtime/query/iteration/phases/compaction.ts +1 -1
- package/src/runtime/query/iteration/phases/context.ts +2 -2
- package/src/runtime/query/iteration/phases/tool-review.ts +59 -2
- package/src/runtime/query/iteration/stream-turn.ts +390 -136
- package/src/runtime/query/iteration/tool-input.ts +284 -0
- package/src/runtime/query/observation-context.ts +2 -2
- package/src/runtime/query/prelude-lease.ts +132 -0
- package/src/runtime/query/prepare-turn.ts +477 -198
- package/src/runtime/query/prompt-cache.ts +2 -2
- package/src/runtime/query/prompt.ts +4 -4
- package/src/runtime/query/resume-session.ts +42 -3
- package/src/runtime/query/review-policy.ts +190 -24
- package/src/runtime/query/tooling.ts +3 -6
- package/src/runtime/query/turn-state.ts +4 -0
- package/src/runtime/system-events.ts +246 -0
- package/src/scheduler/delegating.ts +7 -2
- package/src/skills/index.ts +1 -1
- package/src/skills/registry.ts +33 -0
- package/src/store/session-log/conformance.ts +51 -8
- package/src/store/session-log/core.ts +10 -4
- package/src/store/session-log/fold.ts +33 -7
- package/src/store/session-log/index.ts +2 -0
- package/src/test-support/toolset.ts +23 -0
- package/src/tools/builtins/bash.ts +27 -10
- package/src/tools/builtins/browser-url.ts +1 -1
- package/src/tools/builtins/computer-use-coordinates.ts +144 -0
- package/src/tools/builtins/computer-use-image.ts +278 -0
- package/src/tools/builtins/computer-use.ts +1495 -191
- package/src/tools/builtins/edit.ts +12 -2
- package/src/tools/builtins/index.ts +7 -1
- package/src/tools/builtins/json-string-hint.ts +16 -0
- package/src/tools/builtins/search-tools.ts +7 -20
- package/src/tools/builtins/skill.ts +304 -174
- package/src/tools/builtins/write-file.ts +12 -0
- package/src/tools/command-shell.ts +46 -1
- package/src/tools/coordinator/agent.ts +6 -0
- package/src/tools/coordinator/ask-user-question.ts +29 -15
- package/src/tools/coordinator/index.ts +6 -0
- package/src/tools/coordinator/question-options.ts +195 -0
- package/src/tools/defineTool.ts +38 -0
- package/src/tools/memory/search.ts +4 -1
- package/src/tools/memory/update.ts +8 -5
- package/src/tools/render-nonce.ts +69 -0
- package/src/tools/roster.ts +84 -33
- package/src/tools/schedules/present.ts +2 -0
- package/src/tools/schedules/schedule-tool.ts +238 -39
- package/src/tools/schedules/types.ts +120 -6
- package/src/tools/trusted-read-only.ts +19 -10
- package/src/tools/untrusted-envelope.ts +121 -57
- package/src/toolsets/combine.ts +181 -0
- package/src/toolsets/manager.ts +996 -0
- package/src/toolsets/source-glob.ts +22 -0
- package/src/toolsets/toolset.ts +31 -0
- package/src/toolsets/types.ts +154 -0
- package/src/toolsets/wrappers.ts +191 -0
- package/src/types/agent/base.ts +29 -16
- package/src/types/agent/index.ts +1 -0
- package/src/types/agent/pipeline.ts +2 -0
- package/src/types/agent/query.ts +129 -0
- package/src/types/agent/reactive.ts +5 -142
- package/src/types/agent/router.ts +2 -0
- package/src/types/agent/supervisor.ts +5 -2
- package/src/types/authorization/index.ts +33 -0
- package/src/types/computer-use/index.ts +202 -0
- package/src/types/connector/mcp.ts +32 -0
- package/src/types/errors/index.ts +15 -0
- package/src/types/hitl/index.ts +57 -0
- package/src/types/message/index.ts +135 -7
- package/src/types/plugin/index.ts +44 -21
- package/src/types/provider/chat.ts +5 -0
- package/src/types/provider/config.ts +8 -3
- package/src/types/provider/stream.ts +39 -0
- package/src/types/sandbox/index.ts +1 -1
- package/src/types/session/events.ts +14 -3
- package/src/types/tool/index.ts +173 -105
- package/src/types/toolset/index.ts +10 -47
- package/dist/registry/toolset/catalog.d.ts +0 -42
- package/dist/registry/toolset/catalog.d.ts.map +0 -1
- package/dist/registry/toolset/catalog.js +0 -234
- package/dist/registry/toolset/catalog.js.map +0 -1
- package/src/registry/toolset/catalog.ts +0 -308
|
@@ -3,8 +3,16 @@ import {
|
|
|
3
3
|
assertHostedWebSearchSupported,
|
|
4
4
|
assertNativeStructuredOutputSupported,
|
|
5
5
|
} from '../../../provider/capabilities.js'
|
|
6
|
-
import { isProviderRequestError } from '../../../provider/errors.js'
|
|
6
|
+
import { ProviderRequestError, isProviderRequestError } from '../../../provider/errors.js'
|
|
7
7
|
import { StreamTextAccumulator } from '../../../provider/stream-text.js'
|
|
8
|
+
import {
|
|
9
|
+
INTERLEAVED_TOOL_INPUT_PARSE_ERROR,
|
|
10
|
+
ToolCallIndexer,
|
|
11
|
+
describeToolCallFramingViolation,
|
|
12
|
+
describeToolCallInterleaving,
|
|
13
|
+
isUnindexedFragment,
|
|
14
|
+
toolCallFramingViolation,
|
|
15
|
+
} from '../../../provider/tool-call-framing.js'
|
|
8
16
|
import { GENAI, NAMZU, chatSpanName, parentContext } from '../../../telemetry/attributes.js'
|
|
9
17
|
import {
|
|
10
18
|
recordModelDuration,
|
|
@@ -20,6 +28,7 @@ import type {
|
|
|
20
28
|
Citation,
|
|
21
29
|
Message,
|
|
22
30
|
ReasoningBlock,
|
|
31
|
+
ToolInputError,
|
|
23
32
|
} from '../../../types/message/index.js'
|
|
24
33
|
import { ProviderError } from '../../../types/provider/errors.js'
|
|
25
34
|
import type {
|
|
@@ -29,11 +38,56 @@ import type {
|
|
|
29
38
|
} from '../../../types/provider/index.js'
|
|
30
39
|
import type { SessionEvent } from '../../../types/session/index.js'
|
|
31
40
|
import type { MessageStopReason } from '../../../types/session/stop-reason.js'
|
|
32
|
-
import { generateMessageId } from '../../../utils/id.js'
|
|
41
|
+
import { generateMessageId, generateToolCallId } from '../../../utils/id.js'
|
|
33
42
|
import type { Logger } from '../../../utils/logger.js'
|
|
34
43
|
import type { EmitEvent } from '../events.js'
|
|
35
44
|
import type { RequestImageIdentity } from '../request-rich-content.js'
|
|
36
45
|
import { streamWithProviderRejectedImageRecovery } from './provider-rejected-image.js'
|
|
46
|
+
import {
|
|
47
|
+
type ParsedToolArguments,
|
|
48
|
+
capPartialArguments,
|
|
49
|
+
classifyUnreadableToolInput,
|
|
50
|
+
parseToolArguments,
|
|
51
|
+
} from './tool-input.js'
|
|
52
|
+
|
|
53
|
+
/** One streamed tool call, gathered by its `index`. */
|
|
54
|
+
interface ToolCallBucket {
|
|
55
|
+
id: string
|
|
56
|
+
name: string
|
|
57
|
+
argsBuf: string
|
|
58
|
+
/** `tool_input_started` was emitted: the id and name are both known. */
|
|
59
|
+
started: boolean
|
|
60
|
+
completed: boolean
|
|
61
|
+
/**
|
|
62
|
+
* Parsed input. `null` while the bucket is still streaming.
|
|
63
|
+
* The synthesized
|
|
64
|
+
* `ChatCompletionResponse.toolCalls[].function.arguments` is
|
|
65
|
+
* derived from this — never from the raw buffer — so the
|
|
66
|
+
* downstream executor (`runtime/query/executor.ts`) never has
|
|
67
|
+
* to re-parse an unreadable string. An unreadable tool call is
|
|
68
|
+
* surfaced as `arguments: "{}"` plus `metadata.inputTruncated`
|
|
69
|
+
* and `metadata.inputError` so tool args remain clean while the
|
|
70
|
+
* executor can still return a specific retry hint.
|
|
71
|
+
*/
|
|
72
|
+
parsed: unknown | null
|
|
73
|
+
/**
|
|
74
|
+
* A parse that failed at `toolCallEnd`, waiting for the end of the
|
|
75
|
+
* stream, which classifies it. Cleared once classified.
|
|
76
|
+
*/
|
|
77
|
+
pendingFailure?: Extract<ParsedToolArguments, { ok: false }>
|
|
78
|
+
inputError?: ToolInputError
|
|
79
|
+
/** Characters the response streamed before this call began. */
|
|
80
|
+
precedingLength: number
|
|
81
|
+
/**
|
|
82
|
+
* A later id-less fragment could not have been told apart between this
|
|
83
|
+
* call and another (see `ToolCallIndexer.interleaving`). Reported
|
|
84
|
+
* `malformed` regardless of what its buffer parses to: it may hold
|
|
85
|
+
* another call's spliced-in fragments, or simply be missing whatever an
|
|
86
|
+
* id-less fragment carried elsewhere instead, and either way it is not
|
|
87
|
+
* what the model sent for this call alone.
|
|
88
|
+
*/
|
|
89
|
+
interleaved?: boolean
|
|
90
|
+
}
|
|
37
91
|
|
|
38
92
|
/**
|
|
39
93
|
* Map a provider's coarse `finishReason` plus the orchestrator's
|
|
@@ -81,8 +135,26 @@ export interface StreamingTurnResult {
|
|
|
81
135
|
* - Stream ends without `finishReason` (a known vendor-SDK failure mode
|
|
82
136
|
* dropped message_stop): we still emit `message_completed` from a
|
|
83
137
|
* finally-style fall-through path with `stopReason: 'refusal'`.
|
|
84
|
-
* -
|
|
85
|
-
*
|
|
138
|
+
* - A tool-call fragment before its call's id or name: kept in the call's
|
|
139
|
+
* buffer, keyed by index, and announced in one `tool_input_delta` right
|
|
140
|
+
* after `tool_input_started`, once both are known. It used to be dropped
|
|
141
|
+
* with a warning, and the call then failed to parse and was reported as
|
|
142
|
+
* cut off.
|
|
143
|
+
* - A call whose id never arrives, on a fragment or on `toolCallEnd`: given
|
|
144
|
+
* one when the stream ends, and announced then. It used to reach the
|
|
145
|
+
* executor with an empty id and none of its arguments. Every call's
|
|
146
|
+
* `tool_input_completed` follows its `tool_input_started`, under the same
|
|
147
|
+
* id, whatever id `toolCallEnd` carries.
|
|
148
|
+
* - A new id on an index another call holds: the stream is refused with a
|
|
149
|
+
* classified `ProviderRequestError` naming the violation. The second
|
|
150
|
+
* call's arguments used to be appended to the first's, and the model was
|
|
151
|
+
* told its call had been cut off.
|
|
152
|
+
* - Arguments that do not parse: classified once the stream has ended, as
|
|
153
|
+
* `truncated` or `malformed` (`ToolInputError`). Only the call the model's
|
|
154
|
+
* last output went to can be `truncated`, and only when the stream reported
|
|
155
|
+
* an output limit, a content filter or nothing at all. A failed parse at
|
|
156
|
+
* `toolCallEnd` defers its `tool_input_completed` to then, because what
|
|
157
|
+
* follows the call and the finish reason arrive after the block closes.
|
|
86
158
|
* - `chunk.error`: when no tool input is recoverable, we surface as
|
|
87
159
|
* a thrown error after emitting the message_completed terminator so
|
|
88
160
|
* consumer cards still close. If a tool-use block was already open,
|
|
@@ -198,6 +270,12 @@ export async function* streamProviderTurn(
|
|
|
198
270
|
const model = ''
|
|
199
271
|
const text = new StreamTextAccumulator()
|
|
200
272
|
let finishReason: ChatCompletionResponse['finishReason'] = 'stop'
|
|
273
|
+
// What the stream itself reported, if anything. `finishReason` above
|
|
274
|
+
// defaults to 'stop' for the response; classifying unreadable tool input
|
|
275
|
+
// needs to know a stream that reported nothing from one that finished.
|
|
276
|
+
let reportedFinishReason: ChatCompletionResponse['finishReason'] | undefined
|
|
277
|
+
// Which limit a 'length' finish reached, when it was the context window.
|
|
278
|
+
let finishDetail: ChatCompletionResponse['finishDetail']
|
|
201
279
|
let usage: ChatCompletionResponse['usage'] = {
|
|
202
280
|
promptTokens: 0,
|
|
203
281
|
completionTokens: 0,
|
|
@@ -205,29 +283,44 @@ export async function* streamProviderTurn(
|
|
|
205
283
|
cachedTokens: 0,
|
|
206
284
|
cacheWriteTokens: 0,
|
|
207
285
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
286
|
+
// Characters the model streamed so far: text, reasoning and every tool
|
|
287
|
+
// call's arguments. Each call records it as it begins, so a cut-off call's
|
|
288
|
+
// share of the response says whether the call itself or what came before
|
|
289
|
+
// it filled the response.
|
|
290
|
+
let streamedLength = 0
|
|
291
|
+
const toolBuckets = new Map<number, ToolCallBucket>()
|
|
292
|
+
// Places a fragment that came without an index; see `ToolCallIndexer`.
|
|
293
|
+
const toolIndexer = new ToolCallIndexer()
|
|
294
|
+
// The call the model's latest output went to, or `undefined` once text,
|
|
295
|
+
// reasoning or a hosted tool followed it. An output limit, a content
|
|
296
|
+
// filter or a dropped stream stops the response wherever it is, so this
|
|
297
|
+
// is the only call one of them can have cut off. Every other call was
|
|
298
|
+
// complete when the model moved on from it.
|
|
299
|
+
let lastOutputCall: ToolCallBucket | undefined
|
|
300
|
+
// Announce a call once its id and name are both known: `tool_input_started`,
|
|
301
|
+
// then, as one delta, whatever arguments arrived before that.
|
|
302
|
+
async function* announceToolCall(bucket: ToolCallBucket): AsyncGenerator<SessionEvent, void> {
|
|
303
|
+
if (bucket.started || !bucket.id || !bucket.name) return
|
|
304
|
+
bucket.started = true
|
|
305
|
+
await emitEvent({
|
|
306
|
+
type: 'tool_input_started',
|
|
307
|
+
turnId,
|
|
308
|
+
iteration,
|
|
309
|
+
messageId,
|
|
310
|
+
toolUseId: bucket.id as ToolUseId,
|
|
311
|
+
toolName: bucket.name,
|
|
312
|
+
})
|
|
313
|
+
yield* drainPending()
|
|
314
|
+
if (bucket.argsBuf) {
|
|
315
|
+
await emitEvent({
|
|
316
|
+
type: 'tool_input_delta',
|
|
317
|
+
turnId,
|
|
318
|
+
toolUseId: bucket.id as ToolUseId,
|
|
319
|
+
partialJson: bucket.argsBuf,
|
|
320
|
+
})
|
|
321
|
+
yield* drainPending()
|
|
229
322
|
}
|
|
230
|
-
|
|
323
|
+
}
|
|
231
324
|
// Reasoning blocks, bucketed by stream index exactly like tool calls.
|
|
232
325
|
// Order matters on replay — a provider wants the assistant turn echoed
|
|
233
326
|
// verbatim — so the map is drained in index order at the end.
|
|
@@ -249,6 +342,8 @@ export async function* streamProviderTurn(
|
|
|
249
342
|
|
|
250
343
|
let streamError: string | undefined
|
|
251
344
|
let streamCause: unknown
|
|
345
|
+
/** The stream broke tool-call framing; nothing it sent becomes a tool call. */
|
|
346
|
+
let framingViolated = false
|
|
252
347
|
|
|
253
348
|
const streamParams = {
|
|
254
349
|
...params,
|
|
@@ -373,6 +468,10 @@ export async function* streamProviderTurn(
|
|
|
373
468
|
}
|
|
374
469
|
|
|
375
470
|
if (chunk.delta.hostedTool) {
|
|
471
|
+
// A hosted tool starting is the model moving on. Its later status
|
|
472
|
+
// changes are not new output: a driver may report the completion
|
|
473
|
+
// only once the response is over.
|
|
474
|
+
if (chunk.delta.hostedTool.status === 'running') lastOutputCall = undefined
|
|
376
475
|
await emitEvent({
|
|
377
476
|
type: 'hosted_tool',
|
|
378
477
|
turnId,
|
|
@@ -386,6 +485,9 @@ export async function* streamProviderTurn(
|
|
|
386
485
|
const reasoning = chunk.delta.reasoning
|
|
387
486
|
if (reasoning) {
|
|
388
487
|
let bucket = reasoningBuckets.get(reasoning.index)
|
|
488
|
+
// A new reasoning block, or more of its text, is the model moving
|
|
489
|
+
// on. A signature or a close is not: it ends a block already begun.
|
|
490
|
+
if (!bucket || reasoning.text) lastOutputCall = undefined
|
|
389
491
|
if (!bucket) {
|
|
390
492
|
bucket = { type: reasoning.type ?? 'thinking', text: '' }
|
|
391
493
|
reasoningBuckets.set(reasoning.index, bucket)
|
|
@@ -404,6 +506,7 @@ export async function* streamProviderTurn(
|
|
|
404
506
|
if (reasoning.encrypted) bucket.encrypted = reasoning.encrypted
|
|
405
507
|
if (reasoning.text) {
|
|
406
508
|
bucket.text += reasoning.text
|
|
509
|
+
streamedLength += reasoning.text.length
|
|
407
510
|
await emitEvent({
|
|
408
511
|
type: 'reasoning_delta',
|
|
409
512
|
turnId,
|
|
@@ -429,6 +532,13 @@ export async function* streamProviderTurn(
|
|
|
429
532
|
}
|
|
430
533
|
|
|
431
534
|
if (chunk.delta.content) {
|
|
535
|
+
// Text a driver adds of its own, such as a list of sources, comes
|
|
536
|
+
// after the model stopped. It is not the model moving on from a
|
|
537
|
+
// call, and not part of what came before one.
|
|
538
|
+
if (chunk.delta.contentOrigin !== 'driver') {
|
|
539
|
+
streamedLength += chunk.delta.content.length
|
|
540
|
+
lastOutputCall = undefined
|
|
541
|
+
}
|
|
432
542
|
await emitEvent({
|
|
433
543
|
type: 'text_delta',
|
|
434
544
|
turnId,
|
|
@@ -441,7 +551,87 @@ export async function* streamProviderTurn(
|
|
|
441
551
|
}
|
|
442
552
|
|
|
443
553
|
for (const tc of chunk.delta.toolCalls ?? []) {
|
|
444
|
-
|
|
554
|
+
if (isUnindexedFragment(tc)) {
|
|
555
|
+
// Neither an id nor an index: never a guess. Evaluated fresh
|
|
556
|
+
// for THIS fragment, not decided once when some call opened —
|
|
557
|
+
// a call's buffer stops accepting text the moment it becomes
|
|
558
|
+
// one complete JSON value, and only the state right now says
|
|
559
|
+
// which open calls still could be this fragment's target.
|
|
560
|
+
const placement = toolIndexer.placeUnindexedFragment((i) => {
|
|
561
|
+
const b = toolBuckets.get(i)
|
|
562
|
+
if (!b || b.completed) return false
|
|
563
|
+
return b.argsBuf === '' || !parseToolArguments(b.argsBuf).ok
|
|
564
|
+
})
|
|
565
|
+
if (typeof placement === 'number') {
|
|
566
|
+
let bucket = toolBuckets.get(placement)
|
|
567
|
+
if (!bucket) {
|
|
568
|
+
bucket = {
|
|
569
|
+
id: '',
|
|
570
|
+
name: '',
|
|
571
|
+
argsBuf: '',
|
|
572
|
+
started: false,
|
|
573
|
+
completed: false,
|
|
574
|
+
parsed: null,
|
|
575
|
+
precedingLength: streamedLength,
|
|
576
|
+
}
|
|
577
|
+
toolBuckets.set(placement, bucket)
|
|
578
|
+
lastOutputCall = bucket
|
|
579
|
+
}
|
|
580
|
+
if (tc.function?.name && !bucket.name) bucket.name = tc.function.name
|
|
581
|
+
const fragment = tc.function?.arguments
|
|
582
|
+
if (fragment) {
|
|
583
|
+
bucket.argsBuf += fragment
|
|
584
|
+
streamedLength += fragment.length
|
|
585
|
+
lastOutputCall = bucket
|
|
586
|
+
}
|
|
587
|
+
if (!bucket.started) {
|
|
588
|
+
yield* announceToolCall(bucket)
|
|
589
|
+
} else if (fragment) {
|
|
590
|
+
await emitEvent({
|
|
591
|
+
type: 'tool_input_delta',
|
|
592
|
+
turnId,
|
|
593
|
+
toolUseId: bucket.id as ToolUseId,
|
|
594
|
+
partialJson: fragment,
|
|
595
|
+
})
|
|
596
|
+
yield* drainPending()
|
|
597
|
+
}
|
|
598
|
+
} else {
|
|
599
|
+
// More than one open call could still have taken this
|
|
600
|
+
// fragment, or none could: every candidate is
|
|
601
|
+
// unreadable, and the fragment itself is attributed to
|
|
602
|
+
// none of them — appending it to a guess is exactly the
|
|
603
|
+
// splice this exists to refuse.
|
|
604
|
+
for (const candidate of placement.candidates) {
|
|
605
|
+
const stuck = toolBuckets.get(candidate.index)
|
|
606
|
+
if (stuck) stuck.interleaved = true
|
|
607
|
+
}
|
|
608
|
+
log.warn('tool-call fragments arrived interleaved with no index', {
|
|
609
|
+
[NAMZU.TURN_ID]: turnId,
|
|
610
|
+
[NAMZU.ITERATION]: iteration,
|
|
611
|
+
'exception.message': describeToolCallInterleaving({
|
|
612
|
+
kind: 'interleaved_without_index',
|
|
613
|
+
candidates: placement.candidates,
|
|
614
|
+
}),
|
|
615
|
+
})
|
|
616
|
+
}
|
|
617
|
+
continue
|
|
618
|
+
}
|
|
619
|
+
const index = toolIndexer.indexOf(tc)
|
|
620
|
+
let bucket = toolBuckets.get(index)
|
|
621
|
+
const violation = toolCallFramingViolation(bucket, tc, index)
|
|
622
|
+
if (violation) {
|
|
623
|
+
// Refused, not repaired: after either violation no buffer can be
|
|
624
|
+
// trusted to hold one call's arguments, and guessing is what
|
|
625
|
+
// told a model its intact call had been cut off. Thrown so the
|
|
626
|
+
// stream is torn down like any other stream failure; the flag
|
|
627
|
+
// keeps the recovery below from turning it into tool calls.
|
|
628
|
+
framingViolated = true
|
|
629
|
+
throw new ProviderRequestError({
|
|
630
|
+
kind: 'server',
|
|
631
|
+
providerId: provider.id,
|
|
632
|
+
detail: describeToolCallFramingViolation(violation),
|
|
633
|
+
})
|
|
634
|
+
}
|
|
445
635
|
if (!bucket) {
|
|
446
636
|
bucket = {
|
|
447
637
|
id: tc.id ?? '',
|
|
@@ -450,76 +640,88 @@ export async function* streamProviderTurn(
|
|
|
450
640
|
started: false,
|
|
451
641
|
completed: false,
|
|
452
642
|
parsed: null,
|
|
453
|
-
|
|
643
|
+
precedingLength: streamedLength,
|
|
454
644
|
}
|
|
455
|
-
toolBuckets.set(
|
|
645
|
+
toolBuckets.set(index, bucket)
|
|
646
|
+
lastOutputCall = bucket
|
|
456
647
|
}
|
|
457
648
|
if (tc.id && !bucket.id) bucket.id = tc.id
|
|
458
649
|
if (tc.function?.name && !bucket.name) bucket.name = tc.function.name
|
|
459
650
|
|
|
460
|
-
|
|
461
|
-
|
|
651
|
+
// Arguments belong to the call at their index whether or not its
|
|
652
|
+
// id has arrived yet: the index is what groups a call's fragments.
|
|
653
|
+
// Until the call can be announced they are only buffered, and the
|
|
654
|
+
// announcement carries them.
|
|
655
|
+
const fragment = tc.function?.arguments
|
|
656
|
+
if (fragment) {
|
|
657
|
+
bucket.argsBuf += fragment
|
|
658
|
+
streamedLength += fragment.length
|
|
659
|
+
lastOutputCall = bucket
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
if (!bucket.started) {
|
|
663
|
+
yield* announceToolCall(bucket)
|
|
664
|
+
} else if (fragment) {
|
|
462
665
|
await emitEvent({
|
|
463
|
-
type: '
|
|
666
|
+
type: 'tool_input_delta',
|
|
464
667
|
turnId,
|
|
465
|
-
iteration,
|
|
466
|
-
messageId,
|
|
467
668
|
toolUseId: bucket.id as ToolUseId,
|
|
468
|
-
|
|
669
|
+
partialJson: fragment,
|
|
469
670
|
})
|
|
470
671
|
yield* drainPending()
|
|
471
672
|
}
|
|
673
|
+
}
|
|
472
674
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
675
|
+
if (chunk.delta.toolCallEnd) {
|
|
676
|
+
const { id: endId } = chunk.delta.toolCallEnd
|
|
677
|
+
const index = toolIndexer.closedIndex(chunk.delta.toolCallEnd)
|
|
678
|
+
const bucket = index === undefined ? undefined : toolBuckets.get(index)
|
|
679
|
+
if (bucket && !bucket.completed) {
|
|
680
|
+
// The block close names the call too; a call whose id no
|
|
681
|
+
// fragment carried is announced by it.
|
|
682
|
+
if (!bucket.id && endId) bucket.id = endId
|
|
683
|
+
yield* announceToolCall(bucket)
|
|
684
|
+
}
|
|
685
|
+
// Settled here only once announced, and always under the id it
|
|
686
|
+
// was announced with, which is the id it runs under. A close
|
|
687
|
+
// with an empty id, or for a call whose name never came, leaves
|
|
688
|
+
// the call to the loop after the stream, which gives it an id
|
|
689
|
+
// and announces it first. The close's own id was used here
|
|
690
|
+
// before: an empty one completed a call that was not yet
|
|
691
|
+
// announced, under an id no other event of the call carried.
|
|
692
|
+
if (bucket?.started && !bucket.completed) {
|
|
693
|
+
bucket.completed = true
|
|
694
|
+
// An interleaved call is never taken at its buffer's word: it
|
|
695
|
+
// may hold another call's spliced-in fragments, or be missing
|
|
696
|
+
// whatever an id-less fragment carried elsewhere instead.
|
|
697
|
+
const parsed = bucket.interleaved
|
|
698
|
+
? { ok: false as const, parseError: INTERLEAVED_TOOL_INPUT_PARSE_ERROR }
|
|
699
|
+
: parseToolArguments(bucket.argsBuf)
|
|
700
|
+
if (parsed.ok) {
|
|
701
|
+
bucket.parsed = parsed.value
|
|
483
702
|
await emitEvent({
|
|
484
|
-
type: '
|
|
703
|
+
type: 'tool_input_completed',
|
|
485
704
|
turnId,
|
|
486
705
|
toolUseId: bucket.id as ToolUseId,
|
|
487
|
-
|
|
706
|
+
input: parsed.value,
|
|
488
707
|
})
|
|
489
708
|
yield* drainPending()
|
|
709
|
+
} else {
|
|
710
|
+
// Whether this call was cut off or malformed is decided by
|
|
711
|
+
// what follows it and how the response ends, and both
|
|
712
|
+
// arrive after the block closes. Its completion is emitted
|
|
713
|
+
// once the stream is over.
|
|
714
|
+
bucket.parsed = {}
|
|
715
|
+
bucket.pendingFailure = parsed
|
|
490
716
|
}
|
|
491
717
|
}
|
|
492
718
|
}
|
|
493
719
|
|
|
494
|
-
if (chunk.
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
bucket.completed = true
|
|
499
|
-
let parsed: unknown = {}
|
|
500
|
-
try {
|
|
501
|
-
parsed = bucket.argsBuf ? JSON.parse(bucket.argsBuf) : {}
|
|
502
|
-
} catch (err) {
|
|
503
|
-
bucket.inputTruncated = true
|
|
504
|
-
log.warn('tool input JSON parse failed at content_block_stop', {
|
|
505
|
-
[NAMZU.TURN_ID]: turnId,
|
|
506
|
-
'namzu.runtime.tool_use_id': endId,
|
|
507
|
-
'exception.message': err instanceof Error ? err.message : String(err),
|
|
508
|
-
})
|
|
509
|
-
}
|
|
510
|
-
bucket.parsed = parsed
|
|
511
|
-
await emitEvent({
|
|
512
|
-
type: 'tool_input_completed',
|
|
513
|
-
turnId,
|
|
514
|
-
toolUseId: endId as ToolUseId,
|
|
515
|
-
input: parsed,
|
|
516
|
-
...(bucket.inputTruncated ? { inputTruncated: true } : {}),
|
|
517
|
-
})
|
|
518
|
-
yield* drainPending()
|
|
519
|
-
}
|
|
720
|
+
if (chunk.finishReason) {
|
|
721
|
+
finishReason = chunk.finishReason
|
|
722
|
+
reportedFinishReason = chunk.finishReason
|
|
723
|
+
finishDetail = chunk.finishReason === 'length' ? chunk.finishDetail : undefined
|
|
520
724
|
}
|
|
521
|
-
|
|
522
|
-
if (chunk.finishReason) finishReason = chunk.finishReason
|
|
523
725
|
// Merge (per-field max), not last-write-wins: a late usage frame that
|
|
524
726
|
// omits input/cache tokens must not zero the counts seen earlier in the
|
|
525
727
|
// stream, which would under-report this turn's accumulated usage.
|
|
@@ -573,76 +775,117 @@ export async function* streamProviderTurn(
|
|
|
573
775
|
}
|
|
574
776
|
}
|
|
575
777
|
|
|
576
|
-
//
|
|
577
|
-
//
|
|
578
|
-
//
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
778
|
+
// A call whose id never arrived is still one call: its index grouped its
|
|
779
|
+
// fragments. Only the name its result is filed under is missing, so it is
|
|
780
|
+
// given one, as a driver does for a wire that sends none, and announced.
|
|
781
|
+
for (const bucket of toolBuckets.values()) {
|
|
782
|
+
if (bucket.id || !bucket.name) continue
|
|
783
|
+
bucket.id = generateToolCallId()
|
|
784
|
+
log.warn('tool call arrived without an id; one was assigned', {
|
|
785
|
+
[NAMZU.TURN_ID]: turnId,
|
|
786
|
+
'namzu.runtime.tool_use_id': bucket.id,
|
|
787
|
+
[GENAI.TOOL_NAME]: bucket.name,
|
|
788
|
+
})
|
|
789
|
+
yield* announceToolCall(bucket)
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
// Settle every tool call the stream left open or unreadable. Two paths
|
|
793
|
+
// arrive here:
|
|
794
|
+
//
|
|
795
|
+
// 1. No `toolCallEnd` came for the call — a driver that never emits one
|
|
796
|
+
// (every call then settles here), or a stream that stopped before
|
|
797
|
+
// the block closed. A buffer that parses is kept.
|
|
798
|
+
// 2. `toolCallEnd` came and the buffer did not parse. Its completion was
|
|
799
|
+
// held back until now, because what it is depends on how the
|
|
800
|
+
// response ended.
|
|
585
801
|
//
|
|
586
|
-
//
|
|
587
|
-
//
|
|
588
|
-
//
|
|
589
|
-
//
|
|
590
|
-
//
|
|
591
|
-
//
|
|
592
|
-
//
|
|
593
|
-
//
|
|
594
|
-
//
|
|
595
|
-
//
|
|
596
|
-
//
|
|
597
|
-
//
|
|
598
|
-
//
|
|
599
|
-
// shorter input or split into smaller calls" message that the
|
|
600
|
-
// model can act on.
|
|
802
|
+
// An unreadable buffer becomes `parsed = {}` — the safe fallback, so the
|
|
803
|
+
// executor's `JSON.parse(arguments)` succeeds and nothing downstream
|
|
804
|
+
// crashes — plus `inputError`. It is `truncated` only for the call the
|
|
805
|
+
// model's last output went to, when the output limit or a content filter
|
|
806
|
+
// stopped the response or it reported nothing at all: whatever stopped
|
|
807
|
+
// the response could cut no other call. Every other unreadable call is
|
|
808
|
+
// `malformed`: the response finished normally, or the model moved on to
|
|
809
|
+
// more output, so it had finished writing the call. The executor turns
|
|
810
|
+
// that into a message the model can act on. Without it the model got a
|
|
811
|
+
// generic "<field> is required" error for a call it did not know was
|
|
812
|
+
// broken, and a cut-off call came back with the same long input, into
|
|
813
|
+
// the same cutoff, in a loop. Calling a malformed call cut off tells the
|
|
814
|
+
// model to send less, which does not fix its JSON.
|
|
601
815
|
for (const bucket of toolBuckets.values()) {
|
|
602
|
-
|
|
816
|
+
let failure = bucket.pendingFailure
|
|
817
|
+
if (!failure) {
|
|
818
|
+
if (!bucket.started || bucket.completed) continue
|
|
603
819
|
bucket.completed = true
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
truncated = true
|
|
615
|
-
parsed = {}
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
bucket.parsed = parsed
|
|
619
|
-
bucket.inputTruncated = truncated
|
|
620
|
-
if (truncated) {
|
|
621
|
-
log.warn('tool input truncated by upstream cutoff (no toolCallEnd, argsBuf unparsable)', {
|
|
622
|
-
[NAMZU.TURN_ID]: turnId,
|
|
623
|
-
'namzu.runtime.tool_use_id': bucket.id,
|
|
624
|
-
[GENAI.TOOL_NAME]: bucket.name,
|
|
625
|
-
'namzu.runtime.buffer_length': bucket.argsBuf.length,
|
|
820
|
+
const parsed = bucket.interleaved
|
|
821
|
+
? { ok: false as const, parseError: INTERLEAVED_TOOL_INPUT_PARSE_ERROR }
|
|
822
|
+
: parseToolArguments(bucket.argsBuf)
|
|
823
|
+
if (parsed.ok) {
|
|
824
|
+
bucket.parsed = parsed.value
|
|
825
|
+
await emitEvent({
|
|
826
|
+
type: 'tool_input_completed',
|
|
827
|
+
turnId,
|
|
828
|
+
toolUseId: bucket.id as ToolUseId,
|
|
829
|
+
input: parsed.value,
|
|
626
830
|
})
|
|
831
|
+
yield* drainPending()
|
|
832
|
+
continue
|
|
627
833
|
}
|
|
628
|
-
|
|
629
|
-
type: 'tool_input_completed',
|
|
630
|
-
turnId,
|
|
631
|
-
toolUseId: bucket.id as ToolUseId,
|
|
632
|
-
input: parsed,
|
|
633
|
-
...(truncated ? { inputTruncated: true } : {}),
|
|
634
|
-
})
|
|
635
|
-
yield* drainPending()
|
|
834
|
+
failure = parsed
|
|
636
835
|
}
|
|
836
|
+
bucket.pendingFailure = undefined
|
|
837
|
+
bucket.parsed = {}
|
|
838
|
+
// An interleaved call is always `malformed`, never `classifyUnreadableToolInput`'s
|
|
839
|
+
// call: whether it happens to be this response's last output and
|
|
840
|
+
// whether the response was cut off are both beside the point here —
|
|
841
|
+
// the buffer it would be judged by cannot be trusted either way.
|
|
842
|
+
const inputError: ToolInputError = bucket.interleaved
|
|
843
|
+
? {
|
|
844
|
+
reason: 'malformed',
|
|
845
|
+
parseError: INTERLEAVED_TOOL_INPUT_PARSE_ERROR,
|
|
846
|
+
length: bucket.argsBuf.length,
|
|
847
|
+
precedingLength: bucket.precedingLength,
|
|
848
|
+
}
|
|
849
|
+
: classifyUnreadableToolInput(
|
|
850
|
+
failure,
|
|
851
|
+
{
|
|
852
|
+
length: bucket.argsBuf.length,
|
|
853
|
+
precedingLength: bucket.precedingLength,
|
|
854
|
+
last: bucket === lastOutputCall,
|
|
855
|
+
},
|
|
856
|
+
reportedFinishReason,
|
|
857
|
+
usage,
|
|
858
|
+
finishDetail,
|
|
859
|
+
)
|
|
860
|
+
bucket.inputError = inputError
|
|
861
|
+
log.warn('tool input could not be read', {
|
|
862
|
+
[NAMZU.TURN_ID]: turnId,
|
|
863
|
+
'namzu.runtime.tool_use_id': bucket.id,
|
|
864
|
+
[GENAI.TOOL_NAME]: bucket.name,
|
|
865
|
+
'namzu.runtime.reason': inputError.reason,
|
|
866
|
+
'namzu.runtime.finish_reason': reportedFinishReason ?? 'none',
|
|
867
|
+
'namzu.runtime.buffer_length': bucket.argsBuf.length,
|
|
868
|
+
'exception.message': inputError.parseError,
|
|
869
|
+
})
|
|
870
|
+
await emitEvent({
|
|
871
|
+
type: 'tool_input_completed',
|
|
872
|
+
turnId,
|
|
873
|
+
toolUseId: bucket.id as ToolUseId,
|
|
874
|
+
input: {},
|
|
875
|
+
inputTruncated: true,
|
|
876
|
+
inputError,
|
|
877
|
+
partialArguments: capPartialArguments(bucket.argsBuf),
|
|
878
|
+
})
|
|
879
|
+
yield* drainPending()
|
|
637
880
|
}
|
|
638
881
|
|
|
639
882
|
// `arguments` MUST be valid JSON for the executor's `JSON.parse`
|
|
640
883
|
// (`runtime/query/executor.ts:executeSingle`) to succeed. We
|
|
641
884
|
// always serialise from the bucket's `parsed` object (filled by
|
|
642
885
|
// either the `toolCallEnd` branch above or the post-stream flush
|
|
643
|
-
// loop) instead of re-emitting `argsBuf`. When the
|
|
644
|
-
//
|
|
645
|
-
// state; the executor parses cleanly and returns a specific
|
|
886
|
+
// loop) instead of re-emitting `argsBuf`. When the arguments could not
|
|
887
|
+
// be read, `metadata.inputTruncated` and `metadata.inputError` carry
|
|
888
|
+
// that state; the executor parses cleanly and returns a specific
|
|
646
889
|
// model-readable retry hint instead of the generic "Invalid JSON in
|
|
647
890
|
// tool arguments" intercept.
|
|
648
891
|
const toolCalls = [...toolBuckets.entries()]
|
|
@@ -658,13 +901,23 @@ export async function* streamProviderTurn(
|
|
|
658
901
|
// normalized to `{}` above, so without this the only record of
|
|
659
902
|
// what the model was actually saying is gone — and a
|
|
660
903
|
// `repairToolCall` hook has nothing to repair.
|
|
661
|
-
...(b.
|
|
662
|
-
? {
|
|
904
|
+
...(b.inputError
|
|
905
|
+
? {
|
|
906
|
+
metadata: {
|
|
907
|
+
inputTruncated: true,
|
|
908
|
+
partialArguments: b.argsBuf,
|
|
909
|
+
inputError: b.inputError,
|
|
910
|
+
},
|
|
911
|
+
}
|
|
663
912
|
: {}),
|
|
664
913
|
}))
|
|
665
914
|
|
|
915
|
+
// Not after a framing violation: the calls it would recover are the ones
|
|
916
|
+
// the stream was just refused for garbling.
|
|
666
917
|
const recoveredToolInputFromStreamError =
|
|
667
|
-
streamError !== undefined &&
|
|
918
|
+
streamError !== undefined &&
|
|
919
|
+
!framingViolated &&
|
|
920
|
+
toolCalls.some((tc) => tc.id && tc.function.name)
|
|
668
921
|
const effectiveFinishReason: ChatCompletionResponse['finishReason'] =
|
|
669
922
|
recoveredToolInputFromStreamError ? 'tool_calls' : finishReason
|
|
670
923
|
|
|
@@ -752,6 +1005,7 @@ export async function* streamProviderTurn(
|
|
|
752
1005
|
...(citations.length > 0 ? { citations } : {}),
|
|
753
1006
|
},
|
|
754
1007
|
finishReason: effectiveFinishReason,
|
|
1008
|
+
...(effectiveFinishReason === 'length' && finishDetail ? { finishDetail } : {}),
|
|
755
1009
|
usage,
|
|
756
1010
|
}
|
|
757
1011
|
|