@namzu/sdk 46.0.0 → 48.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +351 -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 +71 -4
- package/dist/connector/mcp/adapter.js.map +1 -1
- package/dist/connector/mcp/client.d.ts +32 -4
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +383 -5
- 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/era.d.ts.map +1 -1
- package/dist/connector/mcp/era.js +7 -0
- package/dist/connector/mcp/era.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/mcp/streamable-http.d.ts +15 -0
- package/dist/connector/mcp/streamable-http.d.ts.map +1 -1
- package/dist/connector/mcp/streamable-http.js +281 -6
- package/dist/connector/mcp/streamable-http.js.map +1 -1
- 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 +1 -0
- package/dist/manager/agent/lifecycle.d.ts.map +1 -1
- package/dist/manager/agent/lifecycle.js +146 -18
- 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/initiative.d.ts +6 -6
- package/dist/manager/resident/learning-observation.d.ts +4 -4
- package/dist/manager/resident/learning.d.ts +36 -36
- package/dist/manager/resident/outbox.d.ts +4 -4
- 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/scheduler/local.d.ts.map +1 -1
- package/dist/scheduler/local.js +2 -0
- package/dist/scheduler/local.js.map +1 -1
- package/dist/session/retention/archive.js +1 -1
- package/dist/session/retention/archive.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/disk.d.ts.map +1 -1
- package/dist/store/session/disk.js +2 -0
- package/dist/store/session/disk.js.map +1 -1
- 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/browser.js +2 -2
- package/dist/tools/builtins/browser.js.map +1 -1
- 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/scheduler.d.ts +6 -1
- package/dist/types/agent/scheduler.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/agent/task.d.ts +19 -1
- package/dist/types/agent/task.d.ts.map +1 -1
- package/dist/types/agent/task.js.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 +45 -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/session/sub-session.d.ts +2 -0
- package/dist/types/session/sub-session.d.ts.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 +73 -3
- package/src/connector/mcp/client.ts +425 -6
- package/src/connector/mcp/discovery.ts +60 -0
- package/src/connector/mcp/era.ts +7 -0
- package/src/connector/mcp/index.ts +13 -0
- package/src/connector/mcp/mcp-toolset.ts +515 -0
- package/src/connector/mcp/streamable-http.ts +302 -5
- 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 +167 -19
- 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/scheduler/local.ts +2 -0
- package/src/session/retention/archive.ts +1 -1
- package/src/skills/index.ts +1 -1
- package/src/skills/registry.ts +25 -0
- package/src/store/session/disk.ts +3 -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/browser.ts +2 -2
- 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/scheduler.ts +6 -1
- package/src/types/agent/supervisor.ts +5 -2
- package/src/types/agent/task.ts +21 -1
- package/src/types/authorization/index.ts +12 -0
- package/src/types/connector/mcp.ts +46 -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/session/sub-session.ts +2 -0
- 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
|
@@ -1,47 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// Tokens too generic to identify a tool by name — ignored when matching a
|
|
15
|
-
// batched `search_tools` query so they can't activate the whole catalog
|
|
16
|
-
// (every bridged tool name shares the `clawtool` prefix, for instance).
|
|
17
|
-
// Generic CRUD verbs are stopped too: a query like "list deals" must rank
|
|
18
|
-
// by "deals", not token-match every `list_*` tool in the deferred catalog.
|
|
19
|
-
const SEARCH_STOP_TOKENS = new Set([
|
|
20
|
-
'clawtool',
|
|
21
|
-
'tool',
|
|
22
|
-
'tools',
|
|
23
|
-
'mcp',
|
|
24
|
-
'the',
|
|
25
|
-
'and',
|
|
26
|
-
'for',
|
|
27
|
-
'use',
|
|
28
|
-
'list',
|
|
29
|
-
'read',
|
|
30
|
-
'create',
|
|
31
|
-
'update',
|
|
32
|
-
'get',
|
|
33
|
-
'find',
|
|
34
|
-
'delete',
|
|
35
|
-
'search',
|
|
36
|
-
]);
|
|
37
|
-
// Weighted-scoring weights mirroring ToolCatalog.searchTools (the richer,
|
|
38
|
-
// otherwise-unused catalog scorer): exact name 12, name substring 8,
|
|
39
|
-
// description 5 — extended here with argument-name indexing (3), following
|
|
40
|
-
// argument names are searched too, not only the tool's own name.
|
|
41
|
-
const SEARCH_WEIGHT_NAME_EXACT = 12;
|
|
42
|
-
const SEARCH_WEIGHT_NAME_PARTIAL = 8;
|
|
43
|
-
const SEARCH_WEIGHT_DESCRIPTION = 5;
|
|
44
|
-
const SEARCH_WEIGHT_ARGUMENT = 3;
|
|
1
|
+
import { RegistryCollisionError } from '../collision.js';
|
|
2
|
+
/**
|
|
3
|
+
* Tool naming and a handful of small, stateless rendering helpers this file
|
|
4
|
+
* used to share with `ToolRegistry`.
|
|
5
|
+
*
|
|
6
|
+
* `ToolRegistry` itself — registration, availability, the execution
|
|
7
|
+
* pipeline — is gone (plan.md v3 §2): a runtime-owned `ToolManager`
|
|
8
|
+
* (`toolsets/manager.ts`) resolves toolsets instead, and carries its own
|
|
9
|
+
* copy of the pipeline this file used to define. What's left here is what
|
|
10
|
+
* had no toolset/manager analogue to move to: a tool name has to be valid
|
|
11
|
+
* regardless of which mechanism resolves it, and `describeWithOutput`/
|
|
12
|
+
* `toolDiscoveryHint` are pure string formatting `ToolManager` still calls.
|
|
13
|
+
*/
|
|
45
14
|
/**
|
|
46
15
|
* What a tool name may be, everywhere it comes from.
|
|
47
16
|
*
|
|
@@ -82,10 +51,10 @@ export function assertToolName(name) {
|
|
|
82
51
|
* shadowing-by-name the only way to say "I do not want this tool", which is
|
|
83
52
|
* precisely what now throws.
|
|
84
53
|
*/
|
|
85
|
-
export class ToolNameCollisionError extends
|
|
54
|
+
export class ToolNameCollisionError extends RegistryCollisionError {
|
|
86
55
|
toolName;
|
|
87
56
|
constructor(toolName, context) {
|
|
88
|
-
super(`Tool name "${toolName}" is already registered by this host, and ${context} will not replace it. Rename the host tool, or decline the one being mounted with runtimeToolOverrides: { "${toolName}": "disabled" }.`);
|
|
57
|
+
super('ToolRegistry', toolName, `Tool name "${toolName}" is already registered by this host, and ${context} will not replace it. Rename the host tool, or decline the one being mounted with runtimeToolOverrides: { "${toolName}": "disabled" }.`);
|
|
89
58
|
this.name = 'ToolNameCollisionError';
|
|
90
59
|
this.toolName = toolName;
|
|
91
60
|
}
|
|
@@ -109,598 +78,6 @@ export function describeWithOutput(description, outputSchema) {
|
|
|
109
78
|
return description;
|
|
110
79
|
return `${description}\n\nReturns (JSON Schema): ${JSON.stringify(outputSchema)}`;
|
|
111
80
|
}
|
|
112
|
-
export class ToolRegistry extends ManagedRegistry {
|
|
113
|
-
availability = new Map();
|
|
114
|
-
tierConfig;
|
|
115
|
-
resultGuardrails;
|
|
116
|
-
preparations = new WeakMap();
|
|
117
|
-
constructor(config) {
|
|
118
|
-
super({
|
|
119
|
-
componentName: 'ToolRegistry',
|
|
120
|
-
idField: 'name',
|
|
121
|
-
logger: config?.logger,
|
|
122
|
-
});
|
|
123
|
-
this.tierConfig = config?.tierConfig;
|
|
124
|
-
this.resultGuardrails = config?.resultGuardrails;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Snapshot membership and availability for another turn without changing this
|
|
128
|
-
* registry. Discovery, registration and suspension then affect only the fork.
|
|
129
|
-
* Definitions, handlers and configuration remain shared; this is not a deep
|
|
130
|
-
* clone or an authorization boundary. Prepared executions belong only to the
|
|
131
|
-
* registry that prepared them and do not transfer to the fork.
|
|
132
|
-
*/
|
|
133
|
-
fork(options = {}) {
|
|
134
|
-
let retained;
|
|
135
|
-
if (options.deferExcept !== undefined) {
|
|
136
|
-
if (!Array.isArray(options.deferExcept))
|
|
137
|
-
throw new TypeError('ToolRegistry.fork deferExcept must be an array of tool names.');
|
|
138
|
-
retained = new Set();
|
|
139
|
-
for (const name of options.deferExcept) {
|
|
140
|
-
if (typeof name !== 'string' || !TOOL_NAME_PATTERN.test(name))
|
|
141
|
-
throw new TypeError('ToolRegistry.fork deferExcept must contain valid tool names.');
|
|
142
|
-
if (retained.has(name))
|
|
143
|
-
throw new TypeError(`ToolRegistry.fork deferExcept contains duplicate tool "${name}".`);
|
|
144
|
-
this.getOrThrow(name);
|
|
145
|
-
retained.add(name);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
const fork = new ToolRegistry({
|
|
149
|
-
logger: this.log,
|
|
150
|
-
tierConfig: this.tierConfig,
|
|
151
|
-
resultGuardrails: this.resultGuardrails,
|
|
152
|
-
});
|
|
153
|
-
fork.items = new Map(this.items);
|
|
154
|
-
fork.availability = new Map(this.availability);
|
|
155
|
-
if (retained) {
|
|
156
|
-
for (const name of fork.listNames()) {
|
|
157
|
-
if (fork.getAvailability(name) === 'active' && !retained.has(name))
|
|
158
|
-
fork.availability.set(name, 'deferred');
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return fork;
|
|
162
|
-
}
|
|
163
|
-
register(idOrToolOrTools, maybeTool) {
|
|
164
|
-
if (Array.isArray(idOrToolOrTools)) {
|
|
165
|
-
const state = (typeof maybeTool === 'string' ? maybeTool : 'active');
|
|
166
|
-
for (const tool of idOrToolOrTools) {
|
|
167
|
-
this.registerOne(tool.name, tool, state);
|
|
168
|
-
}
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
if (typeof idOrToolOrTools === 'string') {
|
|
172
|
-
if (!maybeTool || typeof maybeTool === 'string') {
|
|
173
|
-
throw new Error('register(id, tool) requires a ToolDefinition argument');
|
|
174
|
-
}
|
|
175
|
-
this.registerOne(idOrToolOrTools, maybeTool, 'active');
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
const tool = idOrToolOrTools;
|
|
179
|
-
const state = typeof maybeTool === 'string' ? maybeTool : 'active';
|
|
180
|
-
this.registerOne(tool.name, tool, state);
|
|
181
|
-
}
|
|
182
|
-
registerOne(id, tool, state) {
|
|
183
|
-
assertToolName(id);
|
|
184
|
-
// A model-facing schema is what the constraint is applied TO, so
|
|
185
|
-
// asking for enforcement without one is a request that cannot be
|
|
186
|
-
// honoured. Refusing at registration puts the error where the author
|
|
187
|
-
// can fix it rather than at the first request.
|
|
188
|
-
if (tool.enforceModelInput && !tool.modelInputSchema) {
|
|
189
|
-
throw new Error(`Tool "${id}" enables enforceModelInput but does not define modelInputSchema. Constrained input generation requires an explicit provider-safe model schema.`);
|
|
190
|
-
}
|
|
191
|
-
// …and the schema has to be one a constrained decoder can actually be
|
|
192
|
-
// given. The check above asks whether a model schema EXISTS; this asks
|
|
193
|
-
// whether it can carry the guarantee the tool just requested.
|
|
194
|
-
//
|
|
195
|
-
// Both belong here for the reason the comment above already states.
|
|
196
|
-
// Strict validation runs against a SUBSET of JSON Schema, and a keyword
|
|
197
|
-
// outside it is not degraded — the request is rejected whole, so one
|
|
198
|
-
// unexpressible field takes down every other tool in the call. The
|
|
199
|
-
// first version of this check lived in a provider driver, which meant
|
|
200
|
-
// it fired per request, in one driver, long after the author had moved
|
|
201
|
-
// on. A tool that asks for a guarantee its own schema cannot carry is
|
|
202
|
-
// wrong at the moment it is declared, whichever model it later meets.
|
|
203
|
-
if (tool.enforceModelInput) {
|
|
204
|
-
assertStrictSchema(id, tool.modelInputSchema);
|
|
205
|
-
}
|
|
206
|
-
if (tool.tier && this.tierConfig) {
|
|
207
|
-
const validIds = this.tierConfig.tiers.map((t) => t.id);
|
|
208
|
-
if (!validIds.includes(tool.tier)) {
|
|
209
|
-
throw new Error(`Tool "${id}" has tier "${tool.tier}" which is not defined. Valid tiers: ${validIds.join(', ')}`);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
super.register(id, tool);
|
|
213
|
-
this.availability.set(id, state);
|
|
214
|
-
}
|
|
215
|
-
unregister(id) {
|
|
216
|
-
this.availability.delete(id);
|
|
217
|
-
return super.unregister(id);
|
|
218
|
-
}
|
|
219
|
-
clear() {
|
|
220
|
-
this.availability.clear();
|
|
221
|
-
super.clear();
|
|
222
|
-
}
|
|
223
|
-
activate(names) {
|
|
224
|
-
for (const name of names) {
|
|
225
|
-
this.getOrThrow(name);
|
|
226
|
-
this.availability.set(name, 'active');
|
|
227
|
-
this.log.debug('Tool activated', { 'namzu.tool.name': name });
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
defer(names) {
|
|
231
|
-
for (const name of names) {
|
|
232
|
-
this.getOrThrow(name);
|
|
233
|
-
this.availability.set(name, 'deferred');
|
|
234
|
-
this.log.debug('Tool deferred', { 'namzu.tool.name': name });
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
suspendAll() {
|
|
238
|
-
for (const name of this.listIds()) {
|
|
239
|
-
if (this.getAvailability(name) === 'active') {
|
|
240
|
-
this.availability.set(name, 'suspended');
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
this.log.info('All active tools suspended');
|
|
244
|
-
}
|
|
245
|
-
hasSuspended() {
|
|
246
|
-
for (const state of this.availability.values()) {
|
|
247
|
-
if (state === 'suspended')
|
|
248
|
-
return true;
|
|
249
|
-
}
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
getAvailability(name) {
|
|
253
|
-
return this.availability.get(name) ?? 'active';
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Ranked lexical search over DEFERRED tools, score-descending (ties broken
|
|
257
|
-
* by name) so callers can cap activation at a top-k. Each meaningful query
|
|
258
|
-
* term (≥3 chars, not a stop token) is scored against the tool name
|
|
259
|
-
* (exact/substring), description, and argument names; only tools with a
|
|
260
|
-
* positive score are returned. Description matching is safe here precisely
|
|
261
|
-
* because the result is RANKED — the `search_tools` builtin activates only
|
|
262
|
-
* the top slice, so a shared word can no longer drag in the whole catalog.
|
|
263
|
-
*
|
|
264
|
-
* PARKED (phase 5 of the tool-loading plan): an embedding-backed semantic
|
|
265
|
-
* upgrade was evaluated and deliberately NOT built — at ≤~35 deferred
|
|
266
|
-
* in-house tools with distinct names, weighted lexical scoring sits inside
|
|
267
|
-
* the literature's safe zone, and a weak retriever underperforms no
|
|
268
|
-
* retriever at all. Revisit only when (a) the deferred catalog grows past
|
|
269
|
-
* ~75-100 tools (realistic driver: connector-MCP growth), or (b) telemetry
|
|
270
|
-
* shows a search_tools miss-rate above ~10%. Sticky activation is also
|
|
271
|
-
* deliberate: activating inserts the schema into the tools array at its
|
|
272
|
-
* registry position (a one-time prompt-cache prefix bust); re-defer/TTL
|
|
273
|
-
* would churn that prefix repeatedly and is rejected.
|
|
274
|
-
*/
|
|
275
|
-
searchDeferred(query) {
|
|
276
|
-
return this.searchByAvailability(query, ['deferred']);
|
|
277
|
-
}
|
|
278
|
-
/** Active matches use the same ranking, also recognizing exact short or generic names. */
|
|
279
|
-
searchActive(query) {
|
|
280
|
-
return this.searchByAvailability(query, ['active']);
|
|
281
|
-
}
|
|
282
|
-
searchByAvailability(query, states) {
|
|
283
|
-
const q = query.toLowerCase().trim();
|
|
284
|
-
if (q.length === 0)
|
|
285
|
-
return [];
|
|
286
|
-
const terms = q.split(/\s+/).filter((tok) => tok.length >= 3 && !SEARCH_STOP_TOKENS.has(tok));
|
|
287
|
-
const scored = [];
|
|
288
|
-
for (const tool of this.getByAvailability(states)) {
|
|
289
|
-
const name = tool.name.toLowerCase();
|
|
290
|
-
const description = tool.description.toLowerCase();
|
|
291
|
-
const argumentNames = listArgumentNames(tool);
|
|
292
|
-
let score = terms.length === 0 && name === q ? SEARCH_WEIGHT_NAME_EXACT : 0;
|
|
293
|
-
for (const term of terms) {
|
|
294
|
-
if (name === term) {
|
|
295
|
-
score += SEARCH_WEIGHT_NAME_EXACT;
|
|
296
|
-
}
|
|
297
|
-
else if (name.includes(term)) {
|
|
298
|
-
score += SEARCH_WEIGHT_NAME_PARTIAL;
|
|
299
|
-
}
|
|
300
|
-
if (description.includes(term)) {
|
|
301
|
-
score += SEARCH_WEIGHT_DESCRIPTION;
|
|
302
|
-
}
|
|
303
|
-
if (argumentNames.some((arg) => arg.includes(term))) {
|
|
304
|
-
score += SEARCH_WEIGHT_ARGUMENT;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
if (score > 0) {
|
|
308
|
-
scored.push({ tool, score });
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
scored.sort((a, b) => b.score - a.score || a.tool.name.localeCompare(b.tool.name));
|
|
312
|
-
return scored.map((entry) => entry.tool);
|
|
313
|
-
}
|
|
314
|
-
assignTiers(mapping) {
|
|
315
|
-
for (const [toolName, tierId] of Object.entries(mapping)) {
|
|
316
|
-
const tool = this.getOrThrow(toolName);
|
|
317
|
-
if (this.tierConfig) {
|
|
318
|
-
const validIds = this.tierConfig.tiers.map((t) => t.id);
|
|
319
|
-
if (!validIds.includes(tierId)) {
|
|
320
|
-
throw new Error(`Tier "${tierId}" for tool "${toolName}" is not defined. Valid tiers: ${validIds.join(', ')}`);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
tool.tier = tierId;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
toTierGuidance() {
|
|
327
|
-
if (!this.tierConfig?.guidanceTemplate)
|
|
328
|
-
return null;
|
|
329
|
-
return this.tierConfig.guidanceTemplate(this.tierConfig.tiers);
|
|
330
|
-
}
|
|
331
|
-
listNames() {
|
|
332
|
-
return this.listIds();
|
|
333
|
-
}
|
|
334
|
-
toPromptSection(toolNames) {
|
|
335
|
-
const active = this.getByAvailability(['active'], toolNames);
|
|
336
|
-
const deferred = this.getByAvailability(['deferred'], toolNames);
|
|
337
|
-
const parts = [];
|
|
338
|
-
const contractNote = `<tool_runtime_contract>
|
|
339
|
-
Executable tool names, descriptions, and JSON input schemas are attached through the runtime tools parameter. Treat that runtime schema as authoritative; this prompt section is a discoverability summary only.
|
|
340
|
-
</tool_runtime_contract>`;
|
|
341
|
-
if (active.length > 0) {
|
|
342
|
-
// Name-only: every active tool's full description + JSON schema
|
|
343
|
-
// already rides the runtime tools parameter on each request —
|
|
344
|
-
// repeating descriptions here double-bills the same tokens.
|
|
345
|
-
const entries = active.map((t) => `- ${t.name}`).join('\n');
|
|
346
|
-
parts.push(`<available_tools>\n${entries}\n</available_tools>`);
|
|
347
|
-
}
|
|
348
|
-
if (deferred.length > 0) {
|
|
349
|
-
// Name + one-line hint: deferred schemas stay off the wire, so the
|
|
350
|
-
// hint is the model's only signal of what a deferred tool does. A
|
|
351
|
-
// bare name list caused a real discovery failure in production
|
|
352
|
-
// (the agent never found read_document behind search_tools).
|
|
353
|
-
const entries = deferred
|
|
354
|
-
.map((t) => {
|
|
355
|
-
const hint = toolDiscoveryHint(t.description);
|
|
356
|
-
return hint.length > 0 ? `- ${t.name}: ${hint}` : `- ${t.name}`;
|
|
357
|
-
})
|
|
358
|
-
.join('\n');
|
|
359
|
-
const deferredIntro = this.has('search_tools') &&
|
|
360
|
-
this.getAvailability('search_tools') === 'active' &&
|
|
361
|
-
(!toolNames || toolNames.includes('search_tools'))
|
|
362
|
-
? 'Use search_tools to load these before use:'
|
|
363
|
-
: 'Deferred tools are discoverable but not executable until the runtime activates them:';
|
|
364
|
-
parts.push(`<deferred_tools>\n${deferredIntro}\n${entries}\n</deferred_tools>`);
|
|
365
|
-
}
|
|
366
|
-
if (parts.length === 0)
|
|
367
|
-
return '';
|
|
368
|
-
return [contractNote, ...parts].join('\n\n');
|
|
369
|
-
}
|
|
370
|
-
toLLMTools(toolNames) {
|
|
371
|
-
const toolsToConvert = this.getByAvailability(['active', 'suspended'], toolNames);
|
|
372
|
-
return toolsToConvert.map((tool) => {
|
|
373
|
-
let description = tool.description;
|
|
374
|
-
if (this.tierConfig?.labelInDescription && tool.tier) {
|
|
375
|
-
const tierDef = this.tierConfig.tiers.find((t) => t.id === tool.tier);
|
|
376
|
-
if (tierDef) {
|
|
377
|
-
description = `[${tierDef.label}] ${description}`;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
return {
|
|
381
|
-
type: 'function',
|
|
382
|
-
function: {
|
|
383
|
-
name: tool.name,
|
|
384
|
-
description: describeWithOutput(description, tool.outputSchema),
|
|
385
|
-
parameters: toolWireSchema(tool),
|
|
386
|
-
},
|
|
387
|
-
};
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
getCallableTools(toolNames) {
|
|
391
|
-
return this.getByAvailability(['active'], toolNames);
|
|
392
|
-
}
|
|
393
|
-
prepareExecution(toolName, rawInput) {
|
|
394
|
-
const tool = this.getOrThrow(toolName);
|
|
395
|
-
const parseResult = tool.inputSchema.safeParse(rawInput);
|
|
396
|
-
if (!parseResult.success) {
|
|
397
|
-
return {
|
|
398
|
-
success: false,
|
|
399
|
-
result: this.validationFailure(tool, rawInput, parseResult.error),
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
let retainedInput;
|
|
403
|
-
let reviewInput;
|
|
404
|
-
try {
|
|
405
|
-
retainedInput = clonePreparedInput(parseResult.data, false);
|
|
406
|
-
reviewInput = clonePreparedInput(retainedInput, true);
|
|
407
|
-
}
|
|
408
|
-
catch (err) {
|
|
409
|
-
const message = `Tool "${toolName}" produced an input that cannot be safely prepared for review and execution: ${toErrorMessage(err)}`;
|
|
410
|
-
this.log.error('Prepared tool input could not be detached for review and execution', {
|
|
411
|
-
'namzu.tool.name': toolName,
|
|
412
|
-
'exception.message': toErrorMessage(err),
|
|
413
|
-
});
|
|
414
|
-
return {
|
|
415
|
-
success: false,
|
|
416
|
-
result: { success: false, output: '', error: message },
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
const prepared = Object.freeze({ toolName, input: reviewInput });
|
|
420
|
-
this.preparations.set(prepared, { tool, input: retainedInput });
|
|
421
|
-
return { success: true, prepared };
|
|
422
|
-
}
|
|
423
|
-
async executePrepared(prepared, context) {
|
|
424
|
-
const retained = this.preparations.get(prepared);
|
|
425
|
-
if (!retained) {
|
|
426
|
-
return {
|
|
427
|
-
success: false,
|
|
428
|
-
output: '',
|
|
429
|
-
error: `Tool "${prepared.toolName}" preparation is not owned by this registry or is no longer valid.`,
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
if (this.get(prepared.toolName) !== retained.tool) {
|
|
433
|
-
return {
|
|
434
|
-
success: false,
|
|
435
|
-
output: '',
|
|
436
|
-
error: `Tool "${prepared.toolName}" changed after its input was reviewed; prepare the call again.`,
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
return this.executeRetained(prepared.toolName, retained.tool, retained.input, context);
|
|
440
|
-
}
|
|
441
|
-
async execute(toolName, rawInput, context) {
|
|
442
|
-
let preparation;
|
|
443
|
-
try {
|
|
444
|
-
preparation = this.prepareExecution(toolName, rawInput);
|
|
445
|
-
}
|
|
446
|
-
catch (err) {
|
|
447
|
-
return this.rejectPreparationWithClosedSpan(toolName, context, err);
|
|
448
|
-
}
|
|
449
|
-
if (!preparation.success)
|
|
450
|
-
return preparation.result;
|
|
451
|
-
return this.executePrepared(preparation.prepared, context);
|
|
452
|
-
}
|
|
453
|
-
rejectPreparationWithClosedSpan(toolName, context, err) {
|
|
454
|
-
const tracer = getTracer();
|
|
455
|
-
const parentCtx = context.parentSpan
|
|
456
|
-
? trace.setSpan(otelContext.active(), context.parentSpan)
|
|
457
|
-
: otelContext.active();
|
|
458
|
-
return tracer.startActiveSpan(toolSpanName(toolName), {}, parentCtx, async (span) => {
|
|
459
|
-
try {
|
|
460
|
-
span.setAttributes({
|
|
461
|
-
[GENAI.TOOL_NAME]: toolName,
|
|
462
|
-
[GENAI.TOOL_TYPE]: 'function',
|
|
463
|
-
...(context.toolUseId !== undefined ? { [GENAI.TOOL_CALL_ID]: context.toolUseId } : {}),
|
|
464
|
-
...toolSpanIdentity(context),
|
|
465
|
-
[NAMZU.TOOL_SUCCESS]: false,
|
|
466
|
-
[NAMZU.TOOL_ERROR]: toErrorMessage(err),
|
|
467
|
-
});
|
|
468
|
-
span.setStatus({ code: SpanStatusCode.ERROR, message: toErrorMessage(err) });
|
|
469
|
-
throw err;
|
|
470
|
-
}
|
|
471
|
-
finally {
|
|
472
|
-
span.end();
|
|
473
|
-
}
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
async executeRetained(toolName, tool, finalInput, context) {
|
|
477
|
-
const tracer = getTracer();
|
|
478
|
-
// Explicit parent, not the ambient context. Every span-owning body
|
|
479
|
-
// upstream is an async generator, and a generator resumes on its
|
|
480
|
-
// consumer's async context — so by the time a tool executes, whatever
|
|
481
|
-
// `startActiveSpan` established upstream is long gone and this span
|
|
482
|
-
// would emit as a root. `context.parentSpan` is threaded through
|
|
483
|
-
// `ToolContext`, which already reaches here.
|
|
484
|
-
const parentCtx = context.parentSpan
|
|
485
|
-
? trace.setSpan(otelContext.active(), context.parentSpan)
|
|
486
|
-
: otelContext.active();
|
|
487
|
-
return tracer.startActiveSpan(toolSpanName(toolName), {}, parentCtx, async (span) => {
|
|
488
|
-
try {
|
|
489
|
-
// The call id joins this span to the assistant block that asked
|
|
490
|
-
// for it. Without it a trace shows that `Bash` ran four times
|
|
491
|
-
// this turn and cannot say which span answers which
|
|
492
|
-
// `tool_use` — and the id was already in hand here, threaded
|
|
493
|
-
// through `ToolContext` for the tools that reply
|
|
494
|
-
// asynchronously.
|
|
495
|
-
//
|
|
496
|
-
// Conditional because `toolUseId` is optional: a host calling
|
|
497
|
-
// a tool directly, outside a turn, has no call to correlate to,
|
|
498
|
-
// and an attribute set to `undefined` is worse than an absent
|
|
499
|
-
// one — it reaches the exporter as a key with no value.
|
|
500
|
-
span.setAttributes({
|
|
501
|
-
[GENAI.TOOL_NAME]: toolName,
|
|
502
|
-
[GENAI.TOOL_TYPE]: 'function',
|
|
503
|
-
...(context.toolUseId !== undefined ? { [GENAI.TOOL_CALL_ID]: context.toolUseId } : {}),
|
|
504
|
-
...toolSpanIdentity(context),
|
|
505
|
-
});
|
|
506
|
-
const availability = this.getAvailability(toolName);
|
|
507
|
-
if (availability !== 'active') {
|
|
508
|
-
const msg = `Tool "${toolName}" is ${availability} and cannot be executed`;
|
|
509
|
-
this.log.warn(msg);
|
|
510
|
-
span.setAttributes({
|
|
511
|
-
[NAMZU.TOOL_SUCCESS]: false,
|
|
512
|
-
[NAMZU.TOOL_ERROR]: msg,
|
|
513
|
-
});
|
|
514
|
-
span.setStatus({ code: SpanStatusCode.ERROR, message: msg });
|
|
515
|
-
return {
|
|
516
|
-
success: false,
|
|
517
|
-
output: '',
|
|
518
|
-
error: msg,
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
// A turn that was narrowed may only call what it was narrowed to.
|
|
522
|
-
//
|
|
523
|
-
// This used to be enforced nowhere. `allowedTools` decided which
|
|
524
|
-
// schemas went into the request and was then carried into this
|
|
525
|
-
// context and read by nothing, so the restriction was a statement
|
|
526
|
-
// about the menu rather than about the kitchen: a model that named
|
|
527
|
-
// a withheld tool — from earlier context, from a gateway holding
|
|
528
|
-
// its own tool list, from a replayed cache prefix — had it run.
|
|
529
|
-
// The type says "restrict which tools the model may call"; this is
|
|
530
|
-
// the line that makes that true.
|
|
531
|
-
//
|
|
532
|
-
// Absent means unrestricted. An EMPTY list does not: it is a turn
|
|
533
|
-
// that may call nothing, and treating it as "no restriction" is
|
|
534
|
-
// the fail-open reading this codebase has already been bitten by
|
|
535
|
-
// once, in the delegate roster.
|
|
536
|
-
//
|
|
537
|
-
// What it says is available is what would run, not the list
|
|
538
|
-
// itself: the list was taken when the request was built, and a
|
|
539
|
-
// name on it may since have been unregistered, or be deferred or
|
|
540
|
-
// suspended. Echoing it sent a model to a name that was then
|
|
541
|
-
// answered "unknown tool". See `callableToolNames`.
|
|
542
|
-
const allowed = context.allowedTools;
|
|
543
|
-
if (allowed !== undefined && !allowed.includes(toolName)) {
|
|
544
|
-
const msg = `Tool "${toolName}" is not available on this step. Available: ${formatToolNames(callableToolNames(this, allowed))}`;
|
|
545
|
-
this.log.warn('Blocked a tool outside the step allow-list', {
|
|
546
|
-
[GENAI.TOOL_NAME]: toolName,
|
|
547
|
-
'namzu.registry.allowed': allowed.length,
|
|
548
|
-
});
|
|
549
|
-
span.setAttributes({
|
|
550
|
-
[NAMZU.TOOL_SUCCESS]: false,
|
|
551
|
-
[NAMZU.TOOL_ERROR]: msg,
|
|
552
|
-
});
|
|
553
|
-
span.setStatus({ code: SpanStatusCode.ERROR, message: msg });
|
|
554
|
-
return {
|
|
555
|
-
success: false,
|
|
556
|
-
output: '',
|
|
557
|
-
error: msg,
|
|
558
|
-
permissionDenied: true,
|
|
559
|
-
};
|
|
560
|
-
}
|
|
561
|
-
const mode = context.permissionContext?.mode ?? 'auto';
|
|
562
|
-
if (mode === 'plan') {
|
|
563
|
-
const isReadOnly = isTrustedReadOnly(tool, finalInput);
|
|
564
|
-
if (!isReadOnly) {
|
|
565
|
-
// The same words the review-time policy uses, so the model gets one
|
|
566
|
-
// instruction whichever door refused it.
|
|
567
|
-
const msg = `plan mode: non-read-only tool "${toolName}" blocked. ${PLAN_MODE_REFUSAL}`;
|
|
568
|
-
span.setAttributes({
|
|
569
|
-
[NAMZU.TOOL_SUCCESS]: false,
|
|
570
|
-
[NAMZU.TOOL_ERROR]: msg,
|
|
571
|
-
});
|
|
572
|
-
span.setStatus({ code: SpanStatusCode.ERROR, message: msg });
|
|
573
|
-
return {
|
|
574
|
-
success: false,
|
|
575
|
-
output: '',
|
|
576
|
-
error: msg,
|
|
577
|
-
permissionDenied: true,
|
|
578
|
-
permissionMessage: msg,
|
|
579
|
-
};
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
try {
|
|
583
|
-
this.log.debug('Executing tool', { 'namzu.tool.name': toolName });
|
|
584
|
-
const startedAt = Date.now();
|
|
585
|
-
const runResultGuardrails = context.toolResultGuardrails;
|
|
586
|
-
const produced = await tool.execute(finalInput, context);
|
|
587
|
-
// Screened here, which is the only place a result can be
|
|
588
|
-
// examined before anything acts on it: the executor applies
|
|
589
|
-
// the output budget to what this returns, and compaction
|
|
590
|
-
// summarises later still. `provenance` is carried in so a
|
|
591
|
-
// screen can tell a connected server's words from a
|
|
592
|
-
// first-party tool's — a connector's result is framed with
|
|
593
|
-
// the server's name, and a screen reading only the value
|
|
594
|
-
// cannot use that.
|
|
595
|
-
const result = await screenToolResult(
|
|
596
|
-
// Explicit configuration wins, at whichever boundary it
|
|
597
|
-
// was made. A registry built WITH `resultGuardrails`
|
|
598
|
-
// has stated its policy — including `[]`, which means
|
|
599
|
-
// none — and a turn must not overrule it. A registry
|
|
600
|
-
// built without one declared none, so the turn's apply;
|
|
601
|
-
// that is the ordinary case, since a host assembles a
|
|
602
|
-
// registry and hands it to a turn it does not own.
|
|
603
|
-
this.resultGuardrails ?? runResultGuardrails, produced, {
|
|
604
|
-
toolName,
|
|
605
|
-
input: finalInput,
|
|
606
|
-
...(tool.provenance ? { provenance: tool.provenance } : {}),
|
|
607
|
-
}, this.log);
|
|
608
|
-
const durationMs = Date.now() - startedAt;
|
|
609
|
-
this.log.debug('Tool completed', {
|
|
610
|
-
'namzu.tool.name': toolName,
|
|
611
|
-
'namzu.registry.success': result.success,
|
|
612
|
-
});
|
|
613
|
-
span.setAttribute(NAMZU.TOOL_SUCCESS, result.success);
|
|
614
|
-
recordToolCall(toolName, result.success, result.success ? undefined : result.error, durationMs);
|
|
615
|
-
if (!result.success && result.error) {
|
|
616
|
-
span.setAttribute(NAMZU.TOOL_ERROR, result.error);
|
|
617
|
-
span.setStatus({
|
|
618
|
-
code: SpanStatusCode.ERROR,
|
|
619
|
-
message: result.error,
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
else {
|
|
623
|
-
span.setStatus({ code: SpanStatusCode.OK });
|
|
624
|
-
}
|
|
625
|
-
return result;
|
|
626
|
-
}
|
|
627
|
-
catch (err) {
|
|
628
|
-
// A terminal refusal must not be converted into a failed
|
|
629
|
-
// tool call. Everything below turns an exception into a
|
|
630
|
-
// result the model reads and works around, which is what
|
|
631
|
-
// `refuse` is for — doing it to a `halt` would silently
|
|
632
|
-
// demote the one verdict that says the turn must not
|
|
633
|
-
// continue.
|
|
634
|
-
if (err instanceof ToolResultHalted) {
|
|
635
|
-
span.setAttributes({
|
|
636
|
-
[NAMZU.TOOL_SUCCESS]: false,
|
|
637
|
-
[NAMZU.TOOL_ERROR]: err.message,
|
|
638
|
-
});
|
|
639
|
-
span.setStatus({
|
|
640
|
-
code: SpanStatusCode.ERROR,
|
|
641
|
-
message: err.message,
|
|
642
|
-
});
|
|
643
|
-
throw err;
|
|
644
|
-
}
|
|
645
|
-
const errorMessage = toErrorMessage(err);
|
|
646
|
-
this.log.error('Tool execution error', {
|
|
647
|
-
'namzu.tool.name': toolName,
|
|
648
|
-
'exception.message': errorMessage,
|
|
649
|
-
});
|
|
650
|
-
span.setAttributes({
|
|
651
|
-
[NAMZU.TOOL_SUCCESS]: false,
|
|
652
|
-
[NAMZU.TOOL_ERROR]: errorMessage,
|
|
653
|
-
});
|
|
654
|
-
span.setStatus({
|
|
655
|
-
code: SpanStatusCode.ERROR,
|
|
656
|
-
message: errorMessage,
|
|
657
|
-
});
|
|
658
|
-
span.recordException(err instanceof Error ? err : new Error(errorMessage));
|
|
659
|
-
return {
|
|
660
|
-
success: false,
|
|
661
|
-
output: '',
|
|
662
|
-
error: `Tool "${toolName}" execution failed: ${errorMessage}`,
|
|
663
|
-
};
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
finally {
|
|
667
|
-
// The only place this span ends. It used to be ended at three
|
|
668
|
-
// early returns and in a finally that opened below them, so
|
|
669
|
-
// anything throwing before that try — `getOrThrow` on a name the
|
|
670
|
-
// registry does not hold, for one — left the span open and the
|
|
671
|
-
// tool's trace unclosed.
|
|
672
|
-
span.end();
|
|
673
|
-
}
|
|
674
|
-
});
|
|
675
|
-
}
|
|
676
|
-
validationFailure(tool, rawInput, error) {
|
|
677
|
-
const errorMessage = error.issues
|
|
678
|
-
.map((issue) => `${issue.path.join('.')}: ${issue.message}`)
|
|
679
|
-
.join('; ');
|
|
680
|
-
const isEmptyInput = rawInput === null ||
|
|
681
|
-
rawInput === undefined ||
|
|
682
|
-
(typeof rawInput === 'object' &&
|
|
683
|
-
!Array.isArray(rawInput) &&
|
|
684
|
-
Object.keys(rawInput).length === 0);
|
|
685
|
-
const requiredHint = describeRequiredInput(tool.inputSchema);
|
|
686
|
-
const recoveryHint = tool.validationErrorHint?.trim()
|
|
687
|
-
? ` ${tool.validationErrorHint.trim()}`
|
|
688
|
-
: '';
|
|
689
|
-
const enrichedMessage = isEmptyInput
|
|
690
|
-
? `Tool "${tool.name}" was called with no arguments. ${requiredHint}${recoveryHint} Retry the call with the required parameters populated.`
|
|
691
|
-
: `Validation failed for "${tool.name}": ${errorMessage}. ${requiredHint}${recoveryHint}`;
|
|
692
|
-
this.log.error('Tool input validation failed', {
|
|
693
|
-
'namzu.tool.name': tool.name,
|
|
694
|
-
'namzu.registry.errors': errorMessage,
|
|
695
|
-
'namzu.registry.empty': isEmptyInput,
|
|
696
|
-
});
|
|
697
|
-
return { success: false, output: '', error: enrichedMessage };
|
|
698
|
-
}
|
|
699
|
-
getByAvailability(states, filter) {
|
|
700
|
-
const candidates = filter ? filter.map((n) => this.getOrThrow(n)) : this.getAll();
|
|
701
|
-
return candidates.filter((t) => states.includes(this.getAvailability(t.name)));
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
81
|
/**
|
|
705
82
|
* One-line discoverability hint for a deferred tool: the first sentence of
|
|
706
83
|
* its description, capped at ~100 chars. Used for the `<deferred_tools>`
|
|
@@ -717,93 +94,4 @@ export function toolDiscoveryHint(description, maxLength = 100) {
|
|
|
717
94
|
return sentence;
|
|
718
95
|
return `${sentence.slice(0, maxLength - 1).trimEnd()}…`;
|
|
719
96
|
}
|
|
720
|
-
/**
|
|
721
|
-
* Lower-cased argument (property) names of a tool's input schema, used by
|
|
722
|
-
* `searchDeferred` ranking. Walks the JSON-Schema rendering (already a
|
|
723
|
-
* registration dependency) instead of Zod internals; opaque schemas simply
|
|
724
|
-
* contribute no argument matches.
|
|
725
|
-
*/
|
|
726
|
-
function listArgumentNames(tool) {
|
|
727
|
-
try {
|
|
728
|
-
// The model-facing schema when there is one: that is what the model
|
|
729
|
-
// was shown, so it is what a search over "which tool takes this
|
|
730
|
-
// argument" has to match against.
|
|
731
|
-
const json = tool.modelInputSchema ?? renderToolSchema(tool.inputSchema);
|
|
732
|
-
return [...collectSchemaPropertyNames(json)].map((key) => key.toLowerCase());
|
|
733
|
-
}
|
|
734
|
-
catch {
|
|
735
|
-
return [];
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
/**
|
|
739
|
-
* Every property name a schema can accept, including the ones that only
|
|
740
|
-
* appear inside a branch.
|
|
741
|
-
*
|
|
742
|
-
* A conditional schema puts its real arguments under `anyOf`/`oneOf`, so
|
|
743
|
-
* reading the top-level `properties` alone finds nothing and the tool is
|
|
744
|
-
* unfindable by the very argument it takes. `seen` guards a schema that
|
|
745
|
-
* refers back to itself.
|
|
746
|
-
*/
|
|
747
|
-
function collectSchemaPropertyNames(schema, names = new Set(), seen = new Set()) {
|
|
748
|
-
if (!schema || typeof schema !== 'object' || Array.isArray(schema))
|
|
749
|
-
return names;
|
|
750
|
-
if (seen.has(schema))
|
|
751
|
-
return names;
|
|
752
|
-
seen.add(schema);
|
|
753
|
-
const record = schema;
|
|
754
|
-
const properties = record.properties;
|
|
755
|
-
if (properties && typeof properties === 'object' && !Array.isArray(properties)) {
|
|
756
|
-
for (const name of Object.keys(properties))
|
|
757
|
-
names.add(name);
|
|
758
|
-
}
|
|
759
|
-
for (const keyword of ['anyOf', 'oneOf', 'allOf']) {
|
|
760
|
-
const branches = record[keyword];
|
|
761
|
-
if (!Array.isArray(branches))
|
|
762
|
-
continue;
|
|
763
|
-
for (const branch of branches)
|
|
764
|
-
collectSchemaPropertyNames(branch, names, seen);
|
|
765
|
-
}
|
|
766
|
-
return names;
|
|
767
|
-
}
|
|
768
|
-
/**
|
|
769
|
-
* Build a one-sentence "Required: <field>: <type>, <field>: <type>"
|
|
770
|
-
* hint from a Zod schema, used to enrich tool-input validation
|
|
771
|
-
* errors so the model can self-correct without round-tripping the
|
|
772
|
-
* full JSON schema again. Walks the schema's JSON-Schema rendering
|
|
773
|
-
* (already a dependency for tool registration) so we don't have to
|
|
774
|
-
* branch over Zod's internal type tree.
|
|
775
|
-
*
|
|
776
|
-
* Returns a fallback string for opaque/non-object schemas — the
|
|
777
|
-
* caller still ships the raw Zod issues separately, so the hint
|
|
778
|
-
* here is bonus context, not the only signal.
|
|
779
|
-
*/
|
|
780
|
-
function describeRequiredInput(schema) {
|
|
781
|
-
try {
|
|
782
|
-
const json = renderToolSchema(schema);
|
|
783
|
-
const required = json.required ?? [];
|
|
784
|
-
if (required.length === 0)
|
|
785
|
-
return 'No required parameters known.';
|
|
786
|
-
const props = json.properties ?? {};
|
|
787
|
-
const lines = required.map((name) => {
|
|
788
|
-
const def = props[name] ?? {};
|
|
789
|
-
const type = def.type ?? 'value';
|
|
790
|
-
const desc = def.description ? ` — ${def.description}` : '';
|
|
791
|
-
return `${name}: ${type}${desc}`;
|
|
792
|
-
});
|
|
793
|
-
return `Required: ${lines.join(', ')}.`;
|
|
794
|
-
}
|
|
795
|
-
catch {
|
|
796
|
-
return 'Could not introspect required parameters.';
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
/**
|
|
800
|
-
* The session and turn a tool span belongs to. A host calling a tool
|
|
801
|
-
* directly may pass a context without them, so each is set only when present.
|
|
802
|
-
*/
|
|
803
|
-
function toolSpanIdentity(context) {
|
|
804
|
-
return {
|
|
805
|
-
...(context.sessionId ? { [GENAI.CONVERSATION_ID]: context.sessionId } : {}),
|
|
806
|
-
...(context.turnId ? { [NAMZU.TURN_ID]: context.turnId } : {}),
|
|
807
|
-
};
|
|
808
|
-
}
|
|
809
97
|
//# sourceMappingURL=execute.js.map
|