@namzu/sdk 46.0.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 +325 -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 +8 -0
- package/dist/authorization/gate.d.ts.map +1 -1
- package/dist/authorization/gate.js +12 -1
- 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 +8 -1
- package/dist/authorization/rules.js.map +1 -1
- package/dist/authorization/shell-lexer.d.ts +19 -4
- package/dist/authorization/shell-lexer.d.ts.map +1 -1
- package/dist/authorization/shell-lexer.js +91 -65
- 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/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 +24 -11
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +45 -9
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +6 -4
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +8 -3
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +13 -2
- 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 +7 -7
- package/dist/registry/tool/callable.d.ts.map +1 -1
- package/dist/registry/tool/callable.js +6 -7
- package/dist/registry/tool/callable.js.map +1 -1
- 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 -727
- 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 +45 -2
- package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.js +189 -5
- package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +33 -3
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +86 -10
- 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 +22 -3
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +84 -6
- 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 +12 -0
- package/dist/skills/registry.d.ts.map +1 -1
- package/dist/skills/registry.js +19 -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.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js +19 -11
- 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/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/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 +10 -0
- package/dist/tools/defineTool.d.ts.map +1 -1
- package/dist/tools/defineTool.js +17 -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/schedule-tool.d.ts.map +1 -1
- package/dist/tools/schedules/schedule-tool.js +94 -14
- package/dist/tools/schedules/schedule-tool.js.map +1 -1
- package/dist/tools/schedules/types.d.ts +52 -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 +49 -12
- package/dist/types/authorization/index.d.ts.map +1 -1
- package/dist/types/authorization/index.js +6 -0
- package/dist/types/authorization/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 +152 -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 +1 -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 +21 -1
- package/src/authorization/program.ts +773 -0
- package/src/authorization/reexec-wrapper.ts +589 -0
- package/src/authorization/rules.ts +18 -1
- package/src/authorization/shell-lexer.ts +104 -59
- 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/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 +136 -7
- package/src/public-tools.ts +24 -4
- package/src/public-types.ts +60 -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 +8 -9
- package/src/registry/tool/execute.ts +16 -846
- 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 +228 -6
- package/src/runtime/query/executor.ts +110 -12
- 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 +87 -9
- 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 +25 -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.ts +21 -11
- package/src/tools/builtins/edit.ts +12 -2
- package/src/tools/builtins/json-string-hint.ts +16 -0
- package/src/tools/builtins/search-tools.ts +7 -20
- 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 +28 -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/schedule-tool.ts +107 -14
- package/src/tools/schedules/types.ts +52 -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 +12 -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 +154 -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
package/src/probe/errors.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { RegistryCollisionError } from '../registry/collision.js'
|
|
1
2
|
import type { VetoableEventKind } from '../types/probe/index.js'
|
|
2
3
|
|
|
3
|
-
export class ProbeNameCollisionError extends
|
|
4
|
+
export class ProbeNameCollisionError extends RegistryCollisionError {
|
|
4
5
|
readonly probeName: string
|
|
5
6
|
|
|
6
7
|
constructor(probeName: string) {
|
|
7
8
|
super(
|
|
9
|
+
'ProbeRegistry',
|
|
10
|
+
probeName,
|
|
8
11
|
`Probe name "${probeName}" is already registered. Pass { override: true } to replace, or pick a different name.`,
|
|
9
12
|
)
|
|
10
13
|
this.name = 'ProbeNameCollisionError'
|
|
@@ -97,14 +97,20 @@ When you have understood the task, reply with the plan: what you would change, i
|
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
99
|
* Appended after {@link CODING_AGENT_DELEGATION_DOCTRINE} only for a host
|
|
100
|
-
* session that has
|
|
101
|
-
* {@link CodingAgentDoctrineOptions.
|
|
100
|
+
* session that has hypermode (its multi-agent mode) turned on. See
|
|
101
|
+
* {@link CodingAgentDoctrineOptions.hypermode}: this text is a stronger
|
|
102
102
|
* restatement of the existing delegation rule, not a new capability — it
|
|
103
103
|
* creates no roster, starts no work by itself, and names no tool the base
|
|
104
104
|
* doctrine did not already name.
|
|
105
105
|
*/
|
|
106
|
-
export const
|
|
107
|
-
This session has
|
|
106
|
+
export const CODING_AGENT_HYPERMODE_DOCTRINE = `### Hypermode
|
|
107
|
+
This session has hypermode on: treat delegation through \`Agent\` as the default for substantive work, not the exception. Before doing multi-step work yourself, ask whether an independent piece of it — a lookup, a draft, a check — could run as its own delegation, and prefer delegating it when the answer is yes. This changes only how eagerly you reach for \`Agent\` on work you would otherwise do inline; it does not mount a roster or start any delegation by itself. Agents in the same phase are launched in the same response, each with \`run_in_background: true\` when you mean to wait for them together; a phase is never started one agent at a time.`
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @deprecated Renamed {@link CODING_AGENT_HYPERMODE_DOCTRINE}; the mode it
|
|
111
|
+
* describes is now called hypermode. Same value. Removed in the next major.
|
|
112
|
+
*/
|
|
113
|
+
export const CODING_AGENT_ORCHESTRATE_DOCTRINE = CODING_AGENT_HYPERMODE_DOCTRINE
|
|
108
114
|
|
|
109
115
|
export const CODING_AGENT_DOCTRINE_CONTRIBUTION_ID = 'namzu.coding-agent-doctrine'
|
|
110
116
|
|
|
@@ -116,15 +122,21 @@ export interface CodingAgentDoctrineOptions {
|
|
|
116
122
|
*/
|
|
117
123
|
delegation?: boolean
|
|
118
124
|
/**
|
|
119
|
-
* Append {@link
|
|
120
|
-
* rules, for a host session whose operator turned on
|
|
121
|
-
*
|
|
122
|
-
*
|
|
125
|
+
* Append {@link CODING_AGENT_HYPERMODE_DOCTRINE} after the delegation
|
|
126
|
+
* rules, for a host session whose operator turned hypermode on. Default
|
|
127
|
+
* `false`, and ignored when `delegation` is `false` — a sub-agent prompt
|
|
128
|
+
* never carries delegation guidance of any strength.
|
|
123
129
|
* Display/prompt-only: it creates no scheduling, no roster and no kernel
|
|
124
130
|
* behaviour change, the same guarantee the `workflow`/`phase` labels on
|
|
125
131
|
* `agent_pending` make. With this left at its default the rendered text
|
|
126
132
|
* is byte-identical to before this option existed.
|
|
127
133
|
*/
|
|
134
|
+
hypermode?: boolean
|
|
135
|
+
/**
|
|
136
|
+
* @deprecated Renamed {@link CodingAgentDoctrineOptions.hypermode}. Still
|
|
137
|
+
* honoured: either flag set to `true` appends the text. Removed in the
|
|
138
|
+
* next major.
|
|
139
|
+
*/
|
|
128
140
|
orchestrate?: boolean
|
|
129
141
|
}
|
|
130
142
|
|
|
@@ -140,8 +152,8 @@ export function codingAgentDoctrineContribution(
|
|
|
140
152
|
const text = [
|
|
141
153
|
CODING_AGENT_WORKING_DOCTRINE,
|
|
142
154
|
options.delegation === false ? undefined : CODING_AGENT_DELEGATION_DOCTRINE,
|
|
143
|
-
options.delegation !== false && options.orchestrate
|
|
144
|
-
?
|
|
155
|
+
options.delegation !== false && (options.hypermode || options.orchestrate)
|
|
156
|
+
? CODING_AGENT_HYPERMODE_DOCTRINE
|
|
145
157
|
: undefined,
|
|
146
158
|
]
|
|
147
159
|
.filter((part): part is string => Boolean(part))
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { renderSkillsSection } from '../persona/assembler.js'
|
|
2
|
+
import { RegistryCollisionError } from '../registry/collision.js'
|
|
2
3
|
import type { AgentRuntimeContext } from '../types/agent/base.js'
|
|
3
4
|
import type { Skill } from '../types/skills/index.js'
|
|
4
5
|
|
|
@@ -112,11 +113,15 @@ export interface PromptContribution {
|
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
/** Two contributions claiming one id. */
|
|
115
|
-
export class PromptContributionCollisionError extends
|
|
116
|
+
export class PromptContributionCollisionError extends RegistryCollisionError {
|
|
116
117
|
readonly details: { id: string }
|
|
117
118
|
|
|
118
119
|
constructor(details: { id: string }) {
|
|
119
|
-
super(
|
|
120
|
+
super(
|
|
121
|
+
'PromptContributionRegistry',
|
|
122
|
+
details.id,
|
|
123
|
+
`A prompt contribution with id "${details.id}" is already registered.`,
|
|
124
|
+
)
|
|
120
125
|
this.name = 'PromptContributionCollisionError'
|
|
121
126
|
this.details = details
|
|
122
127
|
}
|
|
@@ -145,6 +150,11 @@ export class PromptContributionRegistry {
|
|
|
145
150
|
this.byId.set(contribution.id, contribution)
|
|
146
151
|
}
|
|
147
152
|
|
|
153
|
+
/** Revoke one contribution when its owner is disabled or uninstalled. */
|
|
154
|
+
unregister(id: string): boolean {
|
|
155
|
+
return this.byId.delete(id)
|
|
156
|
+
}
|
|
157
|
+
|
|
148
158
|
has(id: string): boolean {
|
|
149
159
|
return this.byId.has(id)
|
|
150
160
|
}
|
package/src/prompt/index.ts
CHANGED
|
@@ -1,8 +1,33 @@
|
|
|
1
1
|
import { mergeTokenUsage } from '../types/common/index.js'
|
|
2
|
-
import type { ReasoningBlock } from '../types/message/index.js'
|
|
2
|
+
import type { ReasoningBlock, ToolInputError } from '../types/message/index.js'
|
|
3
3
|
import type { ChatCompletionResponse } from '../types/provider/chat.js'
|
|
4
4
|
import type { StreamChunk } from '../types/provider/stream.js'
|
|
5
5
|
import { StreamTextAccumulator } from './stream-text.js'
|
|
6
|
+
import {
|
|
7
|
+
INTERLEAVED_TOOL_INPUT_PARSE_ERROR,
|
|
8
|
+
ToolCallIndexer,
|
|
9
|
+
describeToolCallFramingViolation,
|
|
10
|
+
isUnindexedFragment,
|
|
11
|
+
toolCallFramingViolation,
|
|
12
|
+
} from './tool-call-framing.js'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Whether a streamed argument buffer could still be receiving more of a
|
|
16
|
+
* call's arguments right now: empty, or not yet a complete JSON value. Used
|
|
17
|
+
* only by `ToolCallIndexer.placeUnindexedFragment` to tell which open calls
|
|
18
|
+
* could still be an id-less fragment's target — not to validate a finished
|
|
19
|
+
* call, so it does not need the offset-finding `parseToolArguments` the turn
|
|
20
|
+
* loop uses for the message a model is shown.
|
|
21
|
+
*/
|
|
22
|
+
function canAcceptMoreText(buffer: string): boolean {
|
|
23
|
+
if (!buffer) return true
|
|
24
|
+
try {
|
|
25
|
+
JSON.parse(buffer)
|
|
26
|
+
return false
|
|
27
|
+
} catch {
|
|
28
|
+
return true
|
|
29
|
+
}
|
|
30
|
+
}
|
|
6
31
|
|
|
7
32
|
/**
|
|
8
33
|
* Drains a {@link StreamChunk} async iterable into the equivalent
|
|
@@ -18,7 +43,12 @@ import { StreamTextAccumulator } from './stream-text.js'
|
|
|
18
43
|
* - ordinary text is concatenated in delta order; identified public text
|
|
19
44
|
* items are preserved and explicit final-answer items select the settled text;
|
|
20
45
|
* - tool calls are bucketed by `index` into the existing
|
|
21
|
-
* `Array<{ id, function: { name, arguments } }>` shape
|
|
46
|
+
* `Array<{ id, function: { name, arguments } }>` shape. Arguments that
|
|
47
|
+
* arrive before the call's id belong to the call at their index and are
|
|
48
|
+
* kept; the id is filled in when it arrives. A stream that puts a second
|
|
49
|
+
* call id on an index is refused with an error naming the violation, as
|
|
50
|
+
* the turn loop refuses it: the second call's arguments used to be
|
|
51
|
+
* appended to the first's, which left one call no tool could run;
|
|
22
52
|
* - reasoning blocks are bucketed by `index` the same way, because the
|
|
23
53
|
* assembled message is the thing a caller replays and
|
|
24
54
|
* {@link ReasoningBlock} is documented as replayed verbatim. This was
|
|
@@ -41,6 +71,7 @@ export async function collectChatCompletion(
|
|
|
41
71
|
const text = new StreamTextAccumulator()
|
|
42
72
|
let replayState: unknown
|
|
43
73
|
let finishReason: ChatCompletionResponse['finishReason'] = 'stop'
|
|
74
|
+
let finishDetail: ChatCompletionResponse['finishDetail']
|
|
44
75
|
let usage: ChatCompletionResponse['usage'] = {
|
|
45
76
|
promptTokens: 0,
|
|
46
77
|
completionTokens: 0,
|
|
@@ -49,7 +80,12 @@ export async function collectChatCompletion(
|
|
|
49
80
|
cacheWriteTokens: 0,
|
|
50
81
|
}
|
|
51
82
|
|
|
52
|
-
const toolBuckets = new Map<
|
|
83
|
+
const toolBuckets = new Map<
|
|
84
|
+
number,
|
|
85
|
+
{ id: string; name: string; argsBuf: string; unreadable?: boolean }
|
|
86
|
+
>()
|
|
87
|
+
// Places a fragment that came without an index; see `ToolCallIndexer`.
|
|
88
|
+
const toolIndexer = new ToolCallIndexer()
|
|
53
89
|
// Same bucketing rule the turn loop uses (`runtime/query/iteration/
|
|
54
90
|
// stream-turn.ts`), so a message assembled here and a message assembled
|
|
55
91
|
// there carry the same blocks in the same order.
|
|
@@ -81,18 +117,47 @@ export async function collectChatCompletion(
|
|
|
81
117
|
}
|
|
82
118
|
|
|
83
119
|
for (const tc of chunk.delta.toolCalls ?? []) {
|
|
84
|
-
|
|
85
|
-
id:
|
|
86
|
-
|
|
87
|
-
|
|
120
|
+
if (isUnindexedFragment(tc)) {
|
|
121
|
+
// Neither an id nor an index: never a guess. Evaluated fresh for
|
|
122
|
+
// THIS fragment, not decided once when some call opened.
|
|
123
|
+
const placement = toolIndexer.placeUnindexedFragment((i) =>
|
|
124
|
+
canAcceptMoreText(toolBuckets.get(i)?.argsBuf ?? ''),
|
|
125
|
+
)
|
|
126
|
+
if (typeof placement === 'number') {
|
|
127
|
+
const bucket = toolBuckets.get(placement) ?? { id: '', name: '', argsBuf: '' }
|
|
128
|
+
if (tc.function?.name) bucket.name = tc.function.name
|
|
129
|
+
if (tc.function?.arguments) bucket.argsBuf += tc.function.arguments
|
|
130
|
+
toolBuckets.set(placement, bucket)
|
|
131
|
+
} else {
|
|
132
|
+
// More than one open call could still have taken this
|
|
133
|
+
// fragment, or none could: every candidate is unreadable, and
|
|
134
|
+
// the fragment itself is attributed to none of them —
|
|
135
|
+
// appending it to a guess is exactly the splice this exists
|
|
136
|
+
// to refuse.
|
|
137
|
+
for (const candidate of placement.candidates) {
|
|
138
|
+
const bucket = toolBuckets.get(candidate.index)
|
|
139
|
+
if (bucket) bucket.unreadable = true
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
continue
|
|
88
143
|
}
|
|
89
|
-
|
|
144
|
+
const index = toolIndexer.indexOf(tc)
|
|
145
|
+
const open = toolBuckets.get(index)
|
|
146
|
+
const violation = toolCallFramingViolation(open, tc, index)
|
|
147
|
+
if (violation) {
|
|
148
|
+
throw new Error(`Provider stream error: ${describeToolCallFramingViolation(violation)}`)
|
|
149
|
+
}
|
|
150
|
+
const bucket = open ?? { id: '', name: '', argsBuf: '' }
|
|
151
|
+
if (tc.id && !bucket.id) bucket.id = tc.id
|
|
90
152
|
if (tc.function?.name) bucket.name = tc.function.name
|
|
91
153
|
if (tc.function?.arguments) bucket.argsBuf += tc.function.arguments
|
|
92
|
-
toolBuckets.set(
|
|
154
|
+
toolBuckets.set(index, bucket)
|
|
93
155
|
}
|
|
94
156
|
|
|
95
|
-
if (chunk.finishReason)
|
|
157
|
+
if (chunk.finishReason) {
|
|
158
|
+
finishReason = chunk.finishReason
|
|
159
|
+
finishDetail = chunk.finishReason === 'length' ? chunk.finishDetail : undefined
|
|
160
|
+
}
|
|
96
161
|
// Merge (per-field max), not last-write-wins: a late frame that omits
|
|
97
162
|
// input/cache tokens must not zero the counts captured earlier in the stream.
|
|
98
163
|
if (chunk.usage) usage = mergeTokenUsage(usage, chunk.usage)
|
|
@@ -103,7 +168,26 @@ export async function collectChatCompletion(
|
|
|
103
168
|
.map(([, b]) => ({
|
|
104
169
|
id: b.id,
|
|
105
170
|
type: 'function' as const,
|
|
106
|
-
|
|
171
|
+
// An interleaved call is never returned with the buffer it
|
|
172
|
+
// accumulated: that buffer may hold another call's spliced-in
|
|
173
|
+
// fragments, or may simply be missing whatever an id-less
|
|
174
|
+
// fragment carried elsewhere instead. Normalized to `{}`, exactly
|
|
175
|
+
// as the turn loop normalizes any other unreadable call.
|
|
176
|
+
function: { name: b.name, arguments: b.unreadable ? '{}' : b.argsBuf },
|
|
177
|
+
...(b.unreadable
|
|
178
|
+
? {
|
|
179
|
+
metadata: {
|
|
180
|
+
inputTruncated: true,
|
|
181
|
+
partialArguments: b.argsBuf,
|
|
182
|
+
inputError: {
|
|
183
|
+
reason: 'malformed',
|
|
184
|
+
parseError: INTERLEAVED_TOOL_INPUT_PARSE_ERROR,
|
|
185
|
+
length: b.argsBuf.length,
|
|
186
|
+
precedingLength: 0,
|
|
187
|
+
} satisfies ToolInputError,
|
|
188
|
+
},
|
|
189
|
+
}
|
|
190
|
+
: {}),
|
|
107
191
|
}))
|
|
108
192
|
|
|
109
193
|
const reasoningBlocks: ReasoningBlock[] = [...reasoningBuckets.entries()]
|
|
@@ -122,6 +206,7 @@ export async function collectChatCompletion(
|
|
|
122
206
|
...(replayState !== undefined ? { replayState } : {}),
|
|
123
207
|
},
|
|
124
208
|
finishReason,
|
|
209
|
+
...(finishDetail ? { finishDetail } : {}),
|
|
125
210
|
usage,
|
|
126
211
|
}
|
|
127
212
|
}
|
package/src/provider/mock.ts
CHANGED
|
@@ -129,8 +129,15 @@ export class MockLLMProvider implements LLMProvider {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
// Arguments arrive as JSON fragments, which is what forces the
|
|
132
|
-
// consumer's partial-JSON buffering to be exercised.
|
|
133
|
-
|
|
132
|
+
// consumer's partial-JSON buffering to be exercised. A truncated
|
|
133
|
+
// call stops halfway, as the output limit stops a real one: it
|
|
134
|
+
// used to send every fragment and only withhold the block close,
|
|
135
|
+
// so the arguments parsed and nothing was truncated at all.
|
|
136
|
+
const fullArgs = call.rawArguments ?? JSON.stringify(call.args ?? {})
|
|
137
|
+
const args =
|
|
138
|
+
call.truncateArguments === true
|
|
139
|
+
? fullArgs.slice(0, Math.max(1, Math.floor(fullArgs.length / 2)))
|
|
140
|
+
: fullArgs
|
|
134
141
|
const step = call.argChunkSize ?? Math.max(1, Math.ceil(args.length / 3))
|
|
135
142
|
for (let i = 0; i < args.length; i += step) {
|
|
136
143
|
yield {
|
|
@@ -143,15 +150,26 @@ export class MockLLMProvider implements LLMProvider {
|
|
|
143
150
|
throw new Error(call.throwAfterArguments)
|
|
144
151
|
}
|
|
145
152
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
153
|
+
// An output limit stops the response where it is, so nothing the
|
|
154
|
+
// script puts after a truncated call is streamed. It used to go on
|
|
155
|
+
// to the next call, which made the cut call one the model had
|
|
156
|
+
// moved on from: malformed, not truncated.
|
|
157
|
+
if (call.truncateArguments === true) break
|
|
158
|
+
yield { id, delta: { toolCallEnd: { index, id: callId } } }
|
|
149
159
|
}
|
|
150
160
|
|
|
151
161
|
yield {
|
|
152
162
|
id,
|
|
153
163
|
delta: {},
|
|
154
|
-
finishReason:
|
|
164
|
+
finishReason:
|
|
165
|
+
turn.finishReason ??
|
|
166
|
+
// A call cut off mid-JSON is what the output limit does, and the
|
|
167
|
+
// finish reason is how a consumer tells that from malformed JSON.
|
|
168
|
+
(toolCalls.some((call) => call.truncateArguments === true)
|
|
169
|
+
? 'length'
|
|
170
|
+
: toolCalls.length > 0
|
|
171
|
+
? 'tool_calls'
|
|
172
|
+
: 'stop'),
|
|
155
173
|
usage: { ...EMPTY_USAGE, ...turn.usage },
|
|
156
174
|
}
|
|
157
175
|
}
|
package/src/provider/registry.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RegistryCollisionError } from '../registry/collision.js'
|
|
1
2
|
import type {
|
|
2
3
|
LLMProvider,
|
|
3
4
|
LLMProviderConstructor,
|
|
@@ -23,11 +24,13 @@ export class UnknownProviderError extends Error {
|
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
export class DuplicateProviderError extends
|
|
27
|
+
export class DuplicateProviderError extends RegistryCollisionError {
|
|
27
28
|
readonly providerType: string
|
|
28
29
|
|
|
29
30
|
constructor(providerType: string) {
|
|
30
31
|
super(
|
|
32
|
+
'ProviderRegistry',
|
|
33
|
+
providerType,
|
|
31
34
|
`Provider type "${providerType}" is already registered. Pass { replace: true } to override an existing registration.`,
|
|
32
35
|
)
|
|
33
36
|
this.name = 'DuplicateProviderError'
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import type { StreamChunk } from '../types/provider/stream.js'
|
|
2
|
+
|
|
3
|
+
type ToolCallDelta = NonNullable<StreamChunk['delta']['toolCalls']>[number]
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A stream that broke tool-call framing: a second call id on an `index`
|
|
7
|
+
* another call holds.
|
|
8
|
+
*
|
|
9
|
+
* The index is what groups a call's fragments, so after this no buffer can be
|
|
10
|
+
* trusted to hold one call's arguments. The second call's arguments used to be
|
|
11
|
+
* appended to the first's; the buffer that reached `JSON.parse` was then not
|
|
12
|
+
* what the model sent, and the model was told its call had been cut off.
|
|
13
|
+
*
|
|
14
|
+
* Nothing else about a call's framing is a violation. Arguments that arrive
|
|
15
|
+
* before the call's id belong to the call at their index and are kept, and a
|
|
16
|
+
* call whose id never arrives is still one call.
|
|
17
|
+
*/
|
|
18
|
+
export interface ToolCallFramingViolation {
|
|
19
|
+
readonly kind: 'index_reused'
|
|
20
|
+
readonly index: number
|
|
21
|
+
readonly openId: string
|
|
22
|
+
readonly newId: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Whether this tool-call delta puts a new call on an index another call
|
|
27
|
+
* holds, or `undefined` when it does not.
|
|
28
|
+
*
|
|
29
|
+
* The same id repeated on every fragment is fine: some wires send it each
|
|
30
|
+
* time. Only a different one is a second call.
|
|
31
|
+
*/
|
|
32
|
+
export function toolCallFramingViolation(
|
|
33
|
+
open: { readonly id: string } | undefined,
|
|
34
|
+
delta: ToolCallDelta,
|
|
35
|
+
/** The index the fragment was placed on, when it came without one. */
|
|
36
|
+
index: number = delta.index,
|
|
37
|
+
): ToolCallFramingViolation | undefined {
|
|
38
|
+
if (open?.id && delta.id && delta.id !== open.id) {
|
|
39
|
+
return { kind: 'index_reused', index, openId: open.id, newId: delta.id }
|
|
40
|
+
}
|
|
41
|
+
return undefined
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function hasIndex(index: number | undefined): index is number {
|
|
45
|
+
return typeof index === 'number' && Number.isInteger(index) && index >= 0
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Whether a fragment carries neither an index nor an id — the one shape
|
|
50
|
+
* `ToolCallIndexer.indexOf` cannot place by itself, and the only shape
|
|
51
|
+
* {@link ToolCallIndexer.placeUnindexedFragment} is for. A fragment with
|
|
52
|
+
* either goes through `indexOf` instead, unaffected by anything below.
|
|
53
|
+
*/
|
|
54
|
+
export function isUnindexedFragment(delta: {
|
|
55
|
+
readonly index?: number
|
|
56
|
+
readonly id?: string
|
|
57
|
+
}): boolean {
|
|
58
|
+
return !hasIndex(delta.index) && !delta.id
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The index each tool-call fragment of one stream belongs to.
|
|
63
|
+
*
|
|
64
|
+
* A driver sets `index`, and the index is what groups a call's fragments.
|
|
65
|
+
* Some servers leave it out of their `tool_calls` fragments, and a driver
|
|
66
|
+
* that passes the wire value through then sends none. Every such fragment used
|
|
67
|
+
* to land on one `undefined` index: two parallel calls were refused as a
|
|
68
|
+
* reused index, and the turn paused on a stream that had nothing wrong with
|
|
69
|
+
* it but the missing field.
|
|
70
|
+
*
|
|
71
|
+
* A fragment that carries an id, with or without an index, is placed by
|
|
72
|
+
* {@link indexOf}: an id seen before continues its call; a new id names the
|
|
73
|
+
* call the latest fragment went to when that call has no id yet, and starts a
|
|
74
|
+
* call on the next free index otherwise. A fragment that carries an index
|
|
75
|
+
* keeps it, so a well-formed stream is read exactly as before and a real
|
|
76
|
+
* reuse of an index is still refused.
|
|
77
|
+
*
|
|
78
|
+
* A fragment with NEITHER an id nor an index — see
|
|
79
|
+
* {@link isUnindexedFragment} — goes through {@link placeUnindexedFragment}
|
|
80
|
+
* instead, which is never a guess: nothing in such a fragment says which call
|
|
81
|
+
* it continues, so the caller is asked, for every call opened so far,
|
|
82
|
+
* whether it could still be receiving more of its arguments right now, and
|
|
83
|
+
* the fragment is placed only when the answer says exactly one call.
|
|
84
|
+
*/
|
|
85
|
+
export class ToolCallIndexer {
|
|
86
|
+
private readonly byId = new Map<string, number>()
|
|
87
|
+
private readonly idOf = new Map<number, string>()
|
|
88
|
+
private readonly named = new Set<number>()
|
|
89
|
+
private readonly opened = new Set<number>()
|
|
90
|
+
private latest: number | undefined
|
|
91
|
+
private next = 0
|
|
92
|
+
|
|
93
|
+
/** The index this id- or index-bearing fragment belongs to. */
|
|
94
|
+
indexOf(delta: { readonly index?: number; readonly id?: string }): number {
|
|
95
|
+
const index = hasIndex(delta.index) ? delta.index : this.placed(delta.id)
|
|
96
|
+
if (delta.id && !this.byId.has(delta.id)) this.byId.set(delta.id, index)
|
|
97
|
+
if (delta.id) {
|
|
98
|
+
this.named.add(index)
|
|
99
|
+
this.idOf.set(index, delta.id)
|
|
100
|
+
}
|
|
101
|
+
this.opened.add(index)
|
|
102
|
+
if (index >= this.next) this.next = index + 1
|
|
103
|
+
this.latest = index
|
|
104
|
+
return index
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private placed(id: string | undefined): number {
|
|
108
|
+
if (!id) return this.latest ?? this.next
|
|
109
|
+
const known = this.byId.get(id)
|
|
110
|
+
if (known !== undefined) return known
|
|
111
|
+
return this.latest !== undefined && !this.named.has(this.latest) ? this.latest : this.next
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Where a fragment with neither an id nor an index belongs — see
|
|
116
|
+
* {@link isUnindexedFragment}.
|
|
117
|
+
*
|
|
118
|
+
* Evaluated fresh for every such fragment, never decided once and
|
|
119
|
+
* remembered from when a call opened: a call's buffer can go from
|
|
120
|
+
* accepting more text to not (once it completes) and stay that way, so
|
|
121
|
+
* only the state right now, at each fragment, says which calls could
|
|
122
|
+
* still be its target. `canAccept(index)` is asked for every call opened
|
|
123
|
+
* so far and answers exactly that: true while its buffer is empty or is
|
|
124
|
+
* not yet a complete JSON value (it could still be receiving more), false
|
|
125
|
+
* once the buffer already parses as one complete value (nothing more is
|
|
126
|
+
* missing from it).
|
|
127
|
+
*
|
|
128
|
+
* - No call has opened yet: this fragment starts the first one. An id
|
|
129
|
+
* for it, if the stream sends one, arrives on a later fragment and
|
|
130
|
+
* attaches to it — the ordinary "arguments before the id" case,
|
|
131
|
+
* unchanged.
|
|
132
|
+
* - Exactly one open call can still accept: it is unambiguously that
|
|
133
|
+
* one.
|
|
134
|
+
* - Zero, or more than one, open call can: there is no way to tell which
|
|
135
|
+
* one this fragment was for, or none could take it at all. Every call
|
|
136
|
+
* that could have is returned in `candidates` (empty when none could),
|
|
137
|
+
* and the fragment belongs to none of them — appending it to a guess
|
|
138
|
+
* is exactly the splice this method exists to refuse.
|
|
139
|
+
*/
|
|
140
|
+
placeUnindexedFragment(
|
|
141
|
+
canAccept: (index: number) => boolean,
|
|
142
|
+
):
|
|
143
|
+
| number
|
|
144
|
+
| { readonly candidates: ReadonlyArray<{ readonly index: number; readonly id?: string }> } {
|
|
145
|
+
if (this.opened.size === 0) {
|
|
146
|
+
const index = this.next
|
|
147
|
+
this.opened.add(index)
|
|
148
|
+
this.next = index + 1
|
|
149
|
+
this.latest = index
|
|
150
|
+
return index
|
|
151
|
+
}
|
|
152
|
+
const candidates = [...this.opened].filter(canAccept)
|
|
153
|
+
if (candidates.length === 1) {
|
|
154
|
+
const [index] = candidates as [number]
|
|
155
|
+
this.latest = index
|
|
156
|
+
return index
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
candidates: candidates
|
|
160
|
+
.sort((a, b) => a - b)
|
|
161
|
+
.map((index) => ({ index, id: this.idOf.get(index) })),
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* The index a block close belongs to: its own, or, when it has none, the
|
|
167
|
+
* call its id names, or the call the latest fragment went to.
|
|
168
|
+
*/
|
|
169
|
+
closedIndex(end: { readonly index?: number; readonly id?: string }): number | undefined {
|
|
170
|
+
if (hasIndex(end.index)) return end.index
|
|
171
|
+
return (end.id ? this.byId.get(end.id) : undefined) ?? this.latest
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** One sentence naming the violation, for an error's detail. */
|
|
176
|
+
export function describeToolCallFramingViolation(violation: ToolCallFramingViolation): string {
|
|
177
|
+
return `the stream reused tool-call index ${violation.index} for call "${violation.newId}" while call "${violation.openId}" held it`
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* A stream sent a fragment with neither an id nor an index while more than
|
|
182
|
+
* one open call could still have been its target, or while none could.
|
|
183
|
+
*
|
|
184
|
+
* {@link ToolCallIndexer.placeUnindexedFragment} places such a fragment only
|
|
185
|
+
* when exactly one open call can still accept more text right now (its
|
|
186
|
+
* buffer empty, or not yet a complete JSON value). Once two calls are both
|
|
187
|
+
* in that state — the ordinary shape of a chat-completions "open" fragment,
|
|
188
|
+
* name and id with empty arguments, sent for one call right after another,
|
|
189
|
+
* before either has streamed any argument text — a later fragment naming
|
|
190
|
+
* neither could belong to either, and there is no field in it that says
|
|
191
|
+
* which. Guessing (placing it on whichever call was merely most recently
|
|
192
|
+
* active) can splice one call's JSON into the other's, and the splice can
|
|
193
|
+
* still happen to parse, so the wrong call runs with no error at all.
|
|
194
|
+
*
|
|
195
|
+
* `candidates` names every call that could have accepted the fragment: more
|
|
196
|
+
* than one when ambiguous, empty when the fragment matched no open call
|
|
197
|
+
* (nothing to route it to, and nothing to blame for it either).
|
|
198
|
+
*/
|
|
199
|
+
export interface ToolCallInterleaving {
|
|
200
|
+
readonly kind: 'interleaved_without_index'
|
|
201
|
+
readonly candidates: ReadonlyArray<{ readonly index: number; readonly id?: string }>
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** One sentence naming the interleaving, for an error's detail or log line. */
|
|
205
|
+
export function describeToolCallInterleaving(interleaving: ToolCallInterleaving): string {
|
|
206
|
+
if (interleaving.candidates.length === 0) {
|
|
207
|
+
return 'the stream sent a tool-call fragment with neither an index nor an id, and no open call could still have accepted it'
|
|
208
|
+
}
|
|
209
|
+
const names = interleaving.candidates
|
|
210
|
+
.map((c) => (c.id ? `"${c.id}"` : `index ${c.index} (not yet named)`))
|
|
211
|
+
.join(' and ')
|
|
212
|
+
return `the stream sent a tool-call fragment with neither an index nor an id while ${names} could each still have accepted it, with nothing to tell them apart`
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* The `ToolInputError.parseError` given to every call an interleaving names.
|
|
217
|
+
* Reported `reason: 'malformed'`, never `'truncated'`: nothing here says the
|
|
218
|
+
* response was cut off, and "the model moved on to more text, reasoning or
|
|
219
|
+
* another call" — the only other case {@link ToolInputError} models — is
|
|
220
|
+
* exactly what opening a second call means. A call this leaves open may
|
|
221
|
+
* genuinely have gone on to carry valid JSON, if by chance no ambiguous
|
|
222
|
+
* fragment ever decided its fate; it is still reported unreadable rather
|
|
223
|
+
* than risk having guessed right by luck on some other stream.
|
|
224
|
+
*/
|
|
225
|
+
export const INTERLEAVED_TOOL_INPUT_PARSE_ERROR =
|
|
226
|
+
"its fragments arrived interleaved with another call's, with neither carrying an index to tell them apart"
|