@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,3 +1,4 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
1
2
|
import { toErrorMessage } from '../../utils/error.js';
|
|
2
3
|
import { generateMCPClientId } from '../../utils/id.js';
|
|
3
4
|
import { SCOPE_ATTRIBUTE } from '../../utils/log/types.js';
|
|
@@ -8,7 +9,7 @@ import { classifyModernHttpFailure, defaultMcpEraCache, mcpEraCacheKey, resolveM
|
|
|
8
9
|
import { MCPHttpStatusError, MCPInputRequiredError, isHeaderMismatchError, protocolErrorFromReply, } from './errors.js';
|
|
9
10
|
import { HttpSseTransport } from './http-sse.js';
|
|
10
11
|
import { StdioTransport } from './stdio.js';
|
|
11
|
-
import { StreamableHttpTransport } from './streamable-http.js';
|
|
12
|
+
import { MCPSubscriptionResponseError, StreamableHttpTransport } from './streamable-http.js';
|
|
12
13
|
import { validateMcpHeaderAnnotations } from './x-mcp-header.js';
|
|
13
14
|
import { DEFAULT_MCP_ERA_PROBE_TIMEOUT_MS, DEFAULT_MCP_REQUEST_TIMEOUT_MS, JSON_RPC_METHOD_NOT_FOUND, MCP_DISCOVER_METHOD, MCP_LEGACY_VERSIONS, MCP_METHOD_HEADER, MCP_NAME_HEADER, MCP_PROTOCOL_VERSION_HEADER, MCP_SUPPORTED_PROTOCOL_VERSIONS, } from '../../constants/mcp/index.js';
|
|
14
15
|
import { NAMZU } from '../../constants/telemetry/index.js';
|
|
@@ -17,7 +18,83 @@ import { VERSION } from '../../version.js';
|
|
|
17
18
|
const MAX_LIST_PAGES = 100;
|
|
18
19
|
/** A cancellation notification must never become the next unbounded wait. */
|
|
19
20
|
const CANCEL_NOTIFICATION_TIMEOUT_MS = 1_000;
|
|
21
|
+
const MAX_PROGRESS_MESSAGE_BYTES = 512;
|
|
22
|
+
const ANSI_CSI_PATTERN = new RegExp(`${String.fromCharCode(27)}\\[[0-?]*[ -/]*[@-~]`, 'g');
|
|
23
|
+
const SUBSCRIPTION_ID_META_KEY = 'io.modelcontextprotocol/subscriptionId';
|
|
24
|
+
const SUBSCRIPTION_RETRY_MAX_MS = 30_000;
|
|
25
|
+
/** Auth may refresh; timeouts, conflicts and rate limits can clear without reconnecting. */
|
|
26
|
+
const RETRYABLE_SUBSCRIPTION_CLIENT_STATUSES = new Set([401, 403, 408, 409, 425, 429]);
|
|
27
|
+
const SUBSCRIPTION_NOTIFICATIONS = {
|
|
28
|
+
'notifications/tools/list_changed': 'toolsListChanged',
|
|
29
|
+
'notifications/prompts/list_changed': 'promptsListChanged',
|
|
30
|
+
'notifications/resources/list_changed': 'resourcesListChanged',
|
|
31
|
+
};
|
|
32
|
+
function subscriptionFilter(capabilities) {
|
|
33
|
+
return {
|
|
34
|
+
...(capabilities?.tools?.listChanged === true ? { toolsListChanged: true } : {}),
|
|
35
|
+
...(capabilities?.prompts?.listChanged === true ? { promptsListChanged: true } : {}),
|
|
36
|
+
...(capabilities?.resources?.listChanged === true
|
|
37
|
+
? { resourcesListChanged: true }
|
|
38
|
+
: {}),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function acknowledgedFilter(value, requested) {
|
|
42
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
43
|
+
return undefined;
|
|
44
|
+
const record = value;
|
|
45
|
+
const acknowledged = {};
|
|
46
|
+
for (const [key, entry] of Object.entries(record)) {
|
|
47
|
+
if (!Object.hasOwn(requested, key) || (entry !== true && entry !== false))
|
|
48
|
+
return undefined;
|
|
49
|
+
if (entry === true)
|
|
50
|
+
acknowledged[key] = true;
|
|
51
|
+
}
|
|
52
|
+
return acknowledged;
|
|
53
|
+
}
|
|
54
|
+
/** A rejected listen request with the same inputs cannot heal by repeating it. */
|
|
55
|
+
function isPermanentSubscriptionFailure(error, requestId) {
|
|
56
|
+
if (!(error instanceof MCPHttpStatusError || error instanceof MCPSubscriptionResponseError))
|
|
57
|
+
return false;
|
|
58
|
+
try {
|
|
59
|
+
const reply = JSON.parse(error.bodyText);
|
|
60
|
+
if (reply?.jsonrpc === '2.0' &&
|
|
61
|
+
reply.id === requestId &&
|
|
62
|
+
reply.method === undefined &&
|
|
63
|
+
reply.error?.code === JSON_RPC_METHOD_NOT_FOUND) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// Only a failed HTTP status can determine policy without a JSON-RPC reply.
|
|
69
|
+
}
|
|
70
|
+
return (error instanceof MCPHttpStatusError &&
|
|
71
|
+
error.status >= 400 &&
|
|
72
|
+
error.status < 500 &&
|
|
73
|
+
!RETRYABLE_SUBSCRIPTION_CLIENT_STATUSES.has(error.status));
|
|
74
|
+
}
|
|
20
75
|
const NAMZU_CLIENT_INFO = { name: 'namzu-sdk', version: VERSION };
|
|
76
|
+
/** Keep server-authored status text safe and small before it reaches a host UI. */
|
|
77
|
+
function progressMessage(value) {
|
|
78
|
+
if (typeof value !== 'string')
|
|
79
|
+
return undefined;
|
|
80
|
+
const plain = value
|
|
81
|
+
.slice(0, MAX_PROGRESS_MESSAGE_BYTES * 4)
|
|
82
|
+
.replace(ANSI_CSI_PATTERN, '')
|
|
83
|
+
.replace(/[\p{Cc}\p{Cf}\p{Cs}]/gu, ' ')
|
|
84
|
+
.trim();
|
|
85
|
+
if (!plain)
|
|
86
|
+
return undefined;
|
|
87
|
+
let bounded = '';
|
|
88
|
+
let bytes = 0;
|
|
89
|
+
for (const character of plain) {
|
|
90
|
+
const length = Buffer.byteLength(character, 'utf8');
|
|
91
|
+
if (bytes + length > MAX_PROGRESS_MESSAGE_BYTES)
|
|
92
|
+
break;
|
|
93
|
+
bounded += character;
|
|
94
|
+
bytes += length;
|
|
95
|
+
}
|
|
96
|
+
return bounded;
|
|
97
|
+
}
|
|
21
98
|
/**
|
|
22
99
|
* The three header names the protocol owns, lower-cased for matching.
|
|
23
100
|
*
|
|
@@ -60,13 +137,18 @@ export class MCPClient {
|
|
|
60
137
|
status = 'disconnected';
|
|
61
138
|
serverInfo;
|
|
62
139
|
serverCapabilities;
|
|
140
|
+
serverInstructions;
|
|
63
141
|
era;
|
|
64
142
|
connectedAt;
|
|
65
143
|
error;
|
|
66
144
|
pendingRequests = new Map();
|
|
67
145
|
nextRequestId = 1;
|
|
146
|
+
progressRequests = new Map();
|
|
68
147
|
notificationHandlers = [];
|
|
69
148
|
lifecycleListeners = [];
|
|
149
|
+
modernSubscription;
|
|
150
|
+
subscriptionRestartTimer;
|
|
151
|
+
subscriptionFailures = 0;
|
|
70
152
|
/** Best-effort protocol cancellations still belong to this connection generation. */
|
|
71
153
|
cancellationControllers = new Set();
|
|
72
154
|
log;
|
|
@@ -108,6 +190,7 @@ export class MCPClient {
|
|
|
108
190
|
if (this.status === 'connected') {
|
|
109
191
|
throw new Error(`MCPClient already connected to "${this.config.serverName}"`);
|
|
110
192
|
}
|
|
193
|
+
this.stopModernSubscription(false);
|
|
111
194
|
this.status = 'connecting';
|
|
112
195
|
// Tool schemas belong to a listing, and a listing belongs to a
|
|
113
196
|
// connection. Carrying bindings across a reconnect would mirror the
|
|
@@ -122,6 +205,7 @@ export class MCPClient {
|
|
|
122
205
|
try {
|
|
123
206
|
this.transport.onMessage((msg) => this.handleMessage(msg));
|
|
124
207
|
this.transport.onClose(() => {
|
|
208
|
+
this.stopModernSubscription(false);
|
|
125
209
|
this.status = 'disconnected';
|
|
126
210
|
this.abortCancellations(new Error('MCP transport closed'));
|
|
127
211
|
this.log.info('MCP transport closed');
|
|
@@ -129,6 +213,7 @@ export class MCPClient {
|
|
|
129
213
|
this.rejectAllPending(`MCP transport to "${this.config.serverName}" closed`);
|
|
130
214
|
});
|
|
131
215
|
this.transport.onError((err) => {
|
|
216
|
+
this.stopModernSubscription(false);
|
|
132
217
|
this.status = 'error';
|
|
133
218
|
this.abortCancellations(err);
|
|
134
219
|
this.error = err.message;
|
|
@@ -220,6 +305,7 @@ export class MCPClient {
|
|
|
220
305
|
this.era = { kind: 'legacy', version: negotiated };
|
|
221
306
|
this.serverInfo = result.serverInfo;
|
|
222
307
|
this.serverCapabilities = result.capabilities;
|
|
308
|
+
this.serverInstructions = result.instructions;
|
|
223
309
|
await this.notify('notifications/initialized', {});
|
|
224
310
|
return result;
|
|
225
311
|
}
|
|
@@ -380,6 +466,7 @@ export class MCPClient {
|
|
|
380
466
|
const result = this.modernInitializeResult(era.version, resolution.discover);
|
|
381
467
|
this.serverInfo = result.serverInfo;
|
|
382
468
|
this.serverCapabilities = result.capabilities;
|
|
469
|
+
this.serverInstructions = result.instructions;
|
|
383
470
|
this.status = 'connected';
|
|
384
471
|
this.connectedAt = Date.now();
|
|
385
472
|
this.emitLifecycle({
|
|
@@ -391,6 +478,7 @@ export class MCPClient {
|
|
|
391
478
|
[NAMZU.SERVER_NAME]: result.serverInfo.name,
|
|
392
479
|
};
|
|
393
480
|
this.log.info('Connected to MCP server', connectedAttributes);
|
|
481
|
+
this.startModernSubscription();
|
|
394
482
|
return result;
|
|
395
483
|
}
|
|
396
484
|
/**
|
|
@@ -401,6 +489,9 @@ export class MCPClient {
|
|
|
401
489
|
* not name itself is reported under the name the operator gave it.
|
|
402
490
|
* Inventing a placeholder like "unknown" would put a word in the
|
|
403
491
|
* server's mouth in the one field a person reads to identify it.
|
|
492
|
+
*
|
|
493
|
+
* `instructions` is left unset: the modern era has no `initialize`
|
|
494
|
+
* round trip, so there is nothing in a `DiscoverResult` to carry it.
|
|
404
495
|
*/
|
|
405
496
|
modernInitializeResult(version, discover) {
|
|
406
497
|
return {
|
|
@@ -409,8 +500,140 @@ export class MCPClient {
|
|
|
409
500
|
serverInfo: serverInfoFromDiscover(discover) ?? { name: this.config.serverName },
|
|
410
501
|
};
|
|
411
502
|
}
|
|
503
|
+
/** Subscribe only to change kinds the modern server actually advertised. */
|
|
504
|
+
startModernSubscription() {
|
|
505
|
+
if (this.status !== 'connected' || this.era?.kind !== 'modern' || this.modernSubscription) {
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
const requested = subscriptionFilter(this.serverCapabilities);
|
|
509
|
+
if (Object.keys(requested).length === 0)
|
|
510
|
+
return;
|
|
511
|
+
const id = this.nextRequestId++;
|
|
512
|
+
const controller = new AbortController();
|
|
513
|
+
const envelope = buildEnvelope({
|
|
514
|
+
era: this.era,
|
|
515
|
+
method: 'subscriptions/listen',
|
|
516
|
+
params: { notifications: requested },
|
|
517
|
+
clientInfo: this.config.clientInfo ?? NAMZU_CLIENT_INFO,
|
|
518
|
+
capabilities: this.config.capabilities ?? {},
|
|
519
|
+
});
|
|
520
|
+
const subscription = {
|
|
521
|
+
id,
|
|
522
|
+
requested,
|
|
523
|
+
controller,
|
|
524
|
+
ackTimer: setTimeout(() => {
|
|
525
|
+
this.finishModernSubscription(subscription, 'acknowledgment timed out', true);
|
|
526
|
+
}, this.requestTimeoutMs),
|
|
527
|
+
};
|
|
528
|
+
subscription.ackTimer.unref?.();
|
|
529
|
+
this.modernSubscription = subscription;
|
|
530
|
+
const message = {
|
|
531
|
+
jsonrpc: '2.0',
|
|
532
|
+
id,
|
|
533
|
+
method: 'subscriptions/listen',
|
|
534
|
+
params: envelope.params,
|
|
535
|
+
};
|
|
536
|
+
try {
|
|
537
|
+
const options = {
|
|
538
|
+
signal: controller.signal,
|
|
539
|
+
...this.eraHeaderOptions(envelope.headers),
|
|
540
|
+
};
|
|
541
|
+
const transport = this.transport;
|
|
542
|
+
const streaming = transport instanceof StreamableHttpTransport;
|
|
543
|
+
const sending = transport instanceof StreamableHttpTransport
|
|
544
|
+
? transport.sendSubscription(message, options, (frame) => {
|
|
545
|
+
if (this.modernSubscription !== subscription)
|
|
546
|
+
return;
|
|
547
|
+
// This callback belongs to the listen POST alone, so its first
|
|
548
|
+
// JSON-RPC frame must be this request's acknowledgment.
|
|
549
|
+
if (!subscription.acknowledged) {
|
|
550
|
+
const meta = frame.params?._meta;
|
|
551
|
+
const frameId = meta && typeof meta === 'object' && !Array.isArray(meta)
|
|
552
|
+
? meta[SUBSCRIPTION_ID_META_KEY]
|
|
553
|
+
: undefined;
|
|
554
|
+
if (frame.method !== 'notifications/subscriptions/acknowledged' || frameId !== id) {
|
|
555
|
+
// A final JSON-RPC result is a valid graceful or error close.
|
|
556
|
+
if (frame.id === id)
|
|
557
|
+
this.handleMessage(frame);
|
|
558
|
+
else
|
|
559
|
+
this.finishModernSubscription(subscription, 'first stream message was not its acknowledgment', true);
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
this.handleMessage(frame);
|
|
564
|
+
})
|
|
565
|
+
: transport.send(message, options);
|
|
566
|
+
void sending.then(() => {
|
|
567
|
+
// stdio's send only writes the request. Its eventual result
|
|
568
|
+
// arrives through handleMessage, whereas HTTP's send owns the
|
|
569
|
+
// response stream and settling means it closed.
|
|
570
|
+
if (streaming)
|
|
571
|
+
this.finishModernSubscription(subscription, 'stream ended', false);
|
|
572
|
+
}, (err) => {
|
|
573
|
+
if (!controller.signal.aborted) {
|
|
574
|
+
this.failModernSubscription(subscription, err);
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
catch (err) {
|
|
579
|
+
this.failModernSubscription(subscription, err);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
failModernSubscription(subscription, error) {
|
|
583
|
+
if (this.modernSubscription !== subscription)
|
|
584
|
+
return;
|
|
585
|
+
const retry = !isPermanentSubscriptionFailure(error, subscription.id);
|
|
586
|
+
if (!retry) {
|
|
587
|
+
this.log.warn('Modern MCP subscription rejected; live updates stopped until reconnection', {
|
|
588
|
+
'namzu.connector.server': this.config.serverName,
|
|
589
|
+
'namzu.connector.reason': toErrorMessage(error),
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
this.finishModernSubscription(subscription, toErrorMessage(error), true, retry);
|
|
593
|
+
}
|
|
594
|
+
/** Stop one subscription, and retry with a bounded delay while connected. */
|
|
595
|
+
finishModernSubscription(subscription, reason, cancelPeer, retry = true) {
|
|
596
|
+
if (this.modernSubscription !== subscription)
|
|
597
|
+
return;
|
|
598
|
+
this.modernSubscription = undefined;
|
|
599
|
+
clearTimeout(subscription.ackTimer);
|
|
600
|
+
subscription.controller.abort(new Error(`MCP subscription ${reason}`));
|
|
601
|
+
if (cancelPeer && !(this.transport instanceof StreamableHttpTransport) && this.isConnected()) {
|
|
602
|
+
this.sendCancellation(subscription.id, `Subscription ${reason}`);
|
|
603
|
+
}
|
|
604
|
+
if (!retry || this.status !== 'connected' || this.era?.kind !== 'modern')
|
|
605
|
+
return;
|
|
606
|
+
this.subscriptionFailures++;
|
|
607
|
+
const delay = Math.min(1_000 * 2 ** Math.min(this.subscriptionFailures - 1, 5), SUBSCRIPTION_RETRY_MAX_MS);
|
|
608
|
+
this.log.warn('Modern MCP subscription ended; retrying', {
|
|
609
|
+
'namzu.connector.server': this.config.serverName,
|
|
610
|
+
'namzu.connector.reason': reason,
|
|
611
|
+
'namzu.connector.retry_ms': delay,
|
|
612
|
+
});
|
|
613
|
+
this.subscriptionRestartTimer = setTimeout(() => {
|
|
614
|
+
this.subscriptionRestartTimer = undefined;
|
|
615
|
+
this.startModernSubscription();
|
|
616
|
+
}, delay);
|
|
617
|
+
this.subscriptionRestartTimer.unref?.();
|
|
618
|
+
}
|
|
619
|
+
stopModernSubscription(cancelPeer) {
|
|
620
|
+
if (this.subscriptionRestartTimer)
|
|
621
|
+
clearTimeout(this.subscriptionRestartTimer);
|
|
622
|
+
this.subscriptionRestartTimer = undefined;
|
|
623
|
+
const subscription = this.modernSubscription;
|
|
624
|
+
this.modernSubscription = undefined;
|
|
625
|
+
this.subscriptionFailures = 0;
|
|
626
|
+
if (!subscription)
|
|
627
|
+
return;
|
|
628
|
+
clearTimeout(subscription.ackTimer);
|
|
629
|
+
subscription.controller.abort(new Error('MCP connection closed'));
|
|
630
|
+
if (cancelPeer && !(this.transport instanceof StreamableHttpTransport) && this.isConnected()) {
|
|
631
|
+
this.sendCancellation(subscription.id, 'Subscription closed');
|
|
632
|
+
}
|
|
633
|
+
}
|
|
412
634
|
async disconnect() {
|
|
413
635
|
const reason = new Error('MCPClient disconnecting');
|
|
636
|
+
this.stopModernSubscription(true);
|
|
414
637
|
this.abortCancellations(reason);
|
|
415
638
|
const alreadyDisconnected = this.status === 'disconnected';
|
|
416
639
|
this.rejectAllPending('MCPClient disconnecting');
|
|
@@ -442,6 +665,7 @@ export class MCPClient {
|
|
|
442
665
|
status: this.status,
|
|
443
666
|
serverInfo: this.serverInfo,
|
|
444
667
|
serverCapabilities: this.serverCapabilities,
|
|
668
|
+
serverInstructions: this.serverInstructions,
|
|
445
669
|
connectedAt: this.connectedAt,
|
|
446
670
|
error: this.error,
|
|
447
671
|
};
|
|
@@ -675,8 +899,32 @@ export class MCPClient {
|
|
|
675
899
|
cursor = next;
|
|
676
900
|
}
|
|
677
901
|
}
|
|
902
|
+
/**
|
|
903
|
+
* Returns an unsubscribe, mirroring {@link onLifecycle} below — a listener
|
|
904
|
+
* that cannot be removed keeps whatever it closes over (a discovery
|
|
905
|
+
* object, a logger, a caller's own state) referenced by this client for
|
|
906
|
+
* as long as the client lives, even after the listener's own owner is
|
|
907
|
+
* done with it.
|
|
908
|
+
*/
|
|
678
909
|
onNotification(handler) {
|
|
679
910
|
this.notificationHandlers.push(handler);
|
|
911
|
+
// A list may have changed between the first fetch and the subscription
|
|
912
|
+
// acknowledgment. Reconcile when a listener joins an already-acknowledged
|
|
913
|
+
// stream, as well as when a stream is acknowledged with listeners present.
|
|
914
|
+
const subscription = this.modernSubscription;
|
|
915
|
+
if (subscription?.acknowledged) {
|
|
916
|
+
queueMicrotask(() => {
|
|
917
|
+
if (this.modernSubscription === subscription &&
|
|
918
|
+
this.notificationHandlers.includes(handler)) {
|
|
919
|
+
this.reconcileSubscription(subscription, handler);
|
|
920
|
+
}
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
return () => {
|
|
924
|
+
const index = this.notificationHandlers.indexOf(handler);
|
|
925
|
+
if (index >= 0)
|
|
926
|
+
this.notificationHandlers.splice(index, 1);
|
|
927
|
+
};
|
|
680
928
|
}
|
|
681
929
|
/**
|
|
682
930
|
* Watch this client come up, go down, or fail.
|
|
@@ -688,9 +936,7 @@ export class MCPClient {
|
|
|
688
936
|
* this adds no state, it just says out loud what the client already
|
|
689
937
|
* knew.
|
|
690
938
|
*
|
|
691
|
-
* Returns an unsubscribe
|
|
692
|
-
* bug this avoids repeating: a listener that cannot be removed keeps a
|
|
693
|
-
* disposed host object alive for as long as the client lives.
|
|
939
|
+
* Returns an unsubscribe, the same shape `onNotification` above returns.
|
|
694
940
|
*/
|
|
695
941
|
onLifecycle(listener) {
|
|
696
942
|
this.lifecycleListeners.push(listener);
|
|
@@ -746,10 +992,20 @@ export class MCPClient {
|
|
|
746
992
|
// Refuse before allocating an id or asking the transport to do work.
|
|
747
993
|
options?.signal?.throwIfAborted();
|
|
748
994
|
const id = this.nextRequestId++;
|
|
995
|
+
const progressToken = method === 'tools/call' && options?.onProgress ? randomUUID() : undefined;
|
|
996
|
+
const requestParams = progressToken === undefined
|
|
997
|
+
? params
|
|
998
|
+
: {
|
|
999
|
+
...params,
|
|
1000
|
+
_meta: {
|
|
1001
|
+
...params._meta,
|
|
1002
|
+
progressToken,
|
|
1003
|
+
},
|
|
1004
|
+
};
|
|
749
1005
|
const envelope = buildEnvelope({
|
|
750
1006
|
era: this.era,
|
|
751
1007
|
method,
|
|
752
|
-
params,
|
|
1008
|
+
params: requestParams,
|
|
753
1009
|
clientInfo: this.config.clientInfo ?? NAMZU_CLIENT_INFO,
|
|
754
1010
|
capabilities: this.config.capabilities ?? {},
|
|
755
1011
|
...this.paramHeaderBindings(method, params),
|
|
@@ -782,6 +1038,8 @@ export class MCPClient {
|
|
|
782
1038
|
options?.signal?.removeEventListener('abort', onCallerAbort);
|
|
783
1039
|
if (this.pendingRequests.get(id) === entry)
|
|
784
1040
|
this.pendingRequests.delete(id);
|
|
1041
|
+
if (progressToken !== undefined)
|
|
1042
|
+
this.progressRequests.delete(progressToken);
|
|
785
1043
|
};
|
|
786
1044
|
const settle = (terminal, value) => {
|
|
787
1045
|
if (settled)
|
|
@@ -822,6 +1080,9 @@ export class MCPClient {
|
|
|
822
1080
|
entry.reject(reason);
|
|
823
1081
|
};
|
|
824
1082
|
this.pendingRequests.set(id, entry);
|
|
1083
|
+
if (progressToken !== undefined && options?.onProgress) {
|
|
1084
|
+
this.progressRequests.set(progressToken, { onProgress: options.onProgress });
|
|
1085
|
+
}
|
|
825
1086
|
const timer = setTimeout(() => {
|
|
826
1087
|
const error = new Error(`MCP request "${method}" to "${this.config.serverName}" timed out after ${this.requestTimeoutMs}ms`);
|
|
827
1088
|
error.name = 'TimeoutError';
|
|
@@ -1044,6 +1305,11 @@ export class MCPClient {
|
|
|
1044
1305
|
await this.transport.send(message, this.eraHeaderOptions(envelope.headers));
|
|
1045
1306
|
}
|
|
1046
1307
|
handleMessage(message) {
|
|
1308
|
+
if (message.method === 'notifications/progress' && message.id === undefined) {
|
|
1309
|
+
this.handleProgressNotification(message.params);
|
|
1310
|
+
}
|
|
1311
|
+
if (this.handleModernSubscriptionMessage(message))
|
|
1312
|
+
return;
|
|
1047
1313
|
if (message.id !== undefined) {
|
|
1048
1314
|
const pending = this.pendingRequests.get(message.id);
|
|
1049
1315
|
if (pending) {
|
|
@@ -1089,6 +1355,118 @@ export class MCPClient {
|
|
|
1089
1355
|
});
|
|
1090
1356
|
}
|
|
1091
1357
|
}
|
|
1358
|
+
handleProgressNotification(params) {
|
|
1359
|
+
const token = params?.progressToken;
|
|
1360
|
+
if (typeof token !== 'string')
|
|
1361
|
+
return;
|
|
1362
|
+
const pending = this.progressRequests.get(token);
|
|
1363
|
+
if (!pending)
|
|
1364
|
+
return;
|
|
1365
|
+
const progress = params?.progress;
|
|
1366
|
+
if (typeof progress !== 'number' || !Number.isFinite(progress) || progress < 0)
|
|
1367
|
+
return;
|
|
1368
|
+
if (pending.lastProgress !== undefined && progress <= pending.lastProgress)
|
|
1369
|
+
return;
|
|
1370
|
+
pending.lastProgress = progress;
|
|
1371
|
+
const total = params?.total;
|
|
1372
|
+
const message = progressMessage(params?.message);
|
|
1373
|
+
const update = {
|
|
1374
|
+
progress,
|
|
1375
|
+
...(typeof total === 'number' && Number.isFinite(total) && total > 0 ? { total } : {}),
|
|
1376
|
+
...(message === undefined ? {} : { message }),
|
|
1377
|
+
};
|
|
1378
|
+
try {
|
|
1379
|
+
pending.onProgress(update);
|
|
1380
|
+
}
|
|
1381
|
+
catch (error) {
|
|
1382
|
+
this.log.warn('MCP progress listener threw', {
|
|
1383
|
+
'exception.message': toErrorMessage(error),
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
/**
|
|
1388
|
+
* The modern subscription stream is authority-scoped by its request ID.
|
|
1389
|
+
* A bare or wrong-ID list_changed notification must not refresh a live
|
|
1390
|
+
* toolset, and no event may precede its acknowledgment.
|
|
1391
|
+
*/
|
|
1392
|
+
handleModernSubscriptionMessage(message) {
|
|
1393
|
+
if (this.era?.kind !== 'modern')
|
|
1394
|
+
return false;
|
|
1395
|
+
const subscription = this.modernSubscription;
|
|
1396
|
+
if (subscription && message.id === subscription.id) {
|
|
1397
|
+
if (message.error?.code === JSON_RPC_METHOD_NOT_FOUND) {
|
|
1398
|
+
this.log.warn('Modern MCP subscription rejected; live updates stopped until reconnection', {
|
|
1399
|
+
'namzu.connector.server': this.config.serverName,
|
|
1400
|
+
'namzu.connector.reason': `MCP error ${message.error.code}: ${message.error.message}`,
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
1403
|
+
this.finishModernSubscription(subscription, message.error
|
|
1404
|
+
? `server rejected subscription: ${message.error.message}`
|
|
1405
|
+
: 'server closed stream', false, message.error?.code !== JSON_RPC_METHOD_NOT_FOUND && message.error !== undefined);
|
|
1406
|
+
return true;
|
|
1407
|
+
}
|
|
1408
|
+
const method = message.method;
|
|
1409
|
+
if (!method)
|
|
1410
|
+
return false;
|
|
1411
|
+
const isAck = method === 'notifications/subscriptions/acknowledged';
|
|
1412
|
+
const kind = Object.hasOwn(SUBSCRIPTION_NOTIFICATIONS, method)
|
|
1413
|
+
? SUBSCRIPTION_NOTIFICATIONS[method]
|
|
1414
|
+
: undefined;
|
|
1415
|
+
const isSubscribedEvent = isAck || kind !== undefined || method === 'notifications/resources/updated';
|
|
1416
|
+
if (!isSubscribedEvent)
|
|
1417
|
+
return false;
|
|
1418
|
+
const meta = message.params?._meta;
|
|
1419
|
+
const id = meta && typeof meta === 'object' && !Array.isArray(meta)
|
|
1420
|
+
? meta[SUBSCRIPTION_ID_META_KEY]
|
|
1421
|
+
: undefined;
|
|
1422
|
+
if (!subscription || id !== subscription.id || message.id !== undefined) {
|
|
1423
|
+
this.log.warn('Ignoring MCP subscription notification without the active subscription ID', {
|
|
1424
|
+
'namzu.connector.server': this.config.serverName,
|
|
1425
|
+
'namzu.connector.method': method,
|
|
1426
|
+
});
|
|
1427
|
+
return true;
|
|
1428
|
+
}
|
|
1429
|
+
if (isAck) {
|
|
1430
|
+
if (subscription.acknowledged) {
|
|
1431
|
+
this.finishModernSubscription(subscription, 'duplicate acknowledgment', true);
|
|
1432
|
+
return true;
|
|
1433
|
+
}
|
|
1434
|
+
const acknowledged = acknowledgedFilter(message.params?.notifications, subscription.requested);
|
|
1435
|
+
if (!acknowledged) {
|
|
1436
|
+
this.finishModernSubscription(subscription, 'invalid acknowledgment filter', true);
|
|
1437
|
+
return true;
|
|
1438
|
+
}
|
|
1439
|
+
subscription.acknowledged = acknowledged;
|
|
1440
|
+
clearTimeout(subscription.ackTimer);
|
|
1441
|
+
for (const handler of [...this.notificationHandlers]) {
|
|
1442
|
+
this.reconcileSubscription(subscription, handler);
|
|
1443
|
+
}
|
|
1444
|
+
return true;
|
|
1445
|
+
}
|
|
1446
|
+
if (!subscription.acknowledged) {
|
|
1447
|
+
this.finishModernSubscription(subscription, 'notification arrived before acknowledgment', true);
|
|
1448
|
+
return true;
|
|
1449
|
+
}
|
|
1450
|
+
if (!kind || subscription.acknowledged[kind] !== true) {
|
|
1451
|
+
this.log.warn('Ignoring unrequested MCP subscription notification', {
|
|
1452
|
+
'namzu.connector.server': this.config.serverName,
|
|
1453
|
+
'namzu.connector.method': method,
|
|
1454
|
+
});
|
|
1455
|
+
return true;
|
|
1456
|
+
}
|
|
1457
|
+
for (const handler of [...this.notificationHandlers])
|
|
1458
|
+
handler(method, message.params);
|
|
1459
|
+
return true;
|
|
1460
|
+
}
|
|
1461
|
+
/** Re-list once when a subscription becomes live; it may have missed a change while opening. */
|
|
1462
|
+
reconcileSubscription(subscription, handler) {
|
|
1463
|
+
if (this.modernSubscription !== subscription)
|
|
1464
|
+
return;
|
|
1465
|
+
for (const [method, kind] of Object.entries(SUBSCRIPTION_NOTIFICATIONS)) {
|
|
1466
|
+
if (subscription.acknowledged?.[kind])
|
|
1467
|
+
handler(method);
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1092
1470
|
requireConnected() {
|
|
1093
1471
|
if (this.status !== 'connected') {
|
|
1094
1472
|
throw new Error(`MCPClient "${this.config.serverName}" is not connected (status: ${this.status})`);
|