@sema-agent/core 7.59.0 → 7.60.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 +564 -0
- package/dist/agents/agent-definition.d.ts +7 -0
- package/dist/agents/agent-definition.js +12 -0
- package/dist/agents/agent-transcript-tool.d.ts +2 -1
- package/dist/agents/agent-transcript-tool.js +3 -1
- package/dist/agents/child-model-seat.js +6 -3
- package/dist/agents/cumulative-stats.js +0 -1
- package/dist/agents/inherited-tool-pool.d.ts +26 -1
- package/dist/agents/inherited-tool-pool.js +22 -0
- package/dist/agents/retain-ledger.d.ts +11 -1
- package/dist/agents/retain-ledger.js +13 -2
- package/dist/agents/roster-store.d.ts +1 -1
- package/dist/agents/roster-store.js +3 -1
- package/dist/agents/send-message-tool.d.ts +8 -19
- package/dist/agents/send-message-tool.js +11 -38
- package/dist/agents/subagent.d.ts +51 -17
- package/dist/agents/subagent.js +117 -78
- package/dist/agents/tool-filter.d.ts +1 -3
- package/dist/agents/tool-filter.js +4 -12
- package/dist/bench/metrics.d.ts +3 -5
- package/dist/bench/metrics.js +0 -1
- package/dist/brain/degrading.js +3 -1
- package/dist/brain/route-adjudicator.js +3 -1
- package/dist/brain/status-sink.d.ts +7 -1
- package/dist/brain/status-sink.js +6 -0
- package/dist/brain/timeout.d.ts +3 -1
- package/dist/brain/timeout.js +18 -5
- package/dist/core/a2a.d.ts +15 -5
- package/dist/core/a2a.js +34 -19
- package/dist/core/agent-definition.d.ts +20 -0
- package/dist/core/allow-entry.d.ts +2 -0
- package/dist/core/allow-entry.js +3 -1
- package/dist/core/artifact-host.d.ts +0 -2
- package/dist/core/artifact-host.js +0 -1
- package/dist/core/auto-mode-defaults.d.ts +8 -0
- package/dist/core/auto-mode-defaults.js +1 -0
- package/dist/core/auto-mode-rebuild.d.ts +2 -1
- package/dist/core/auto-mode.d.ts +39 -4
- package/dist/core/auto-mode.js +63 -12
- package/dist/core/background-agent-store.d.ts +10 -1
- package/dist/core/background-agent-store.js +3 -2
- package/dist/core/background-shell.d.ts +12 -1
- package/dist/core/background-shell.js +12 -0
- package/dist/core/checkpoint-store.d.ts +8 -13
- package/dist/core/checkpoint-store.js +4 -3
- package/dist/core/compliance.d.ts +1 -1
- package/dist/core/credential-echo.d.ts +52 -0
- package/dist/core/credential-echo.js +65 -0
- package/dist/core/credential-vocabulary.d.ts +13 -3
- package/dist/core/credential-vocabulary.js +12 -4
- package/dist/core/cross-boundary-taint.d.ts +4 -5
- package/dist/core/engine-notice.d.ts +58 -15
- package/dist/core/frame-settlement.d.ts +5 -0
- package/dist/core/frame-settlement.js +4 -0
- package/dist/core/gate-fold.js +7 -5
- package/dist/core/gate-lanes.js +39 -8
- package/dist/core/governance-codes.d.ts +9 -1
- package/dist/core/governance-codes.js +12 -0
- package/dist/core/hands-band-screen.js +0 -1
- package/dist/core/hands-band.d.ts +0 -3
- package/dist/core/hooks.d.ts +39 -56
- package/dist/core/hooks.js +123 -77
- package/dist/core/image-admission.d.ts +104 -51
- package/dist/core/image-admission.js +170 -46
- package/dist/core/image-downsample.d.ts +36 -69
- package/dist/core/image-downsample.js +111 -73
- package/dist/core/integer-option.d.ts +21 -0
- package/dist/core/integer-option.js +13 -0
- package/dist/core/locked-config.d.ts +54 -3
- package/dist/core/locked-config.js +81 -50
- package/dist/core/mcp-call-meta.d.ts +2 -2
- package/dist/core/mcp-call-meta.js +9 -10
- package/dist/core/mcp-failure.d.ts +9 -3
- package/dist/core/mcp-failure.js +10 -0
- package/dist/core/mcp-host-seat.d.ts +92 -0
- package/dist/core/mcp-host-seat.js +131 -0
- package/dist/core/mcp-probe.d.ts +7 -2
- package/dist/core/mcp-probe.js +7 -2
- package/dist/core/mcp-server-spec.d.ts +38 -9
- package/dist/core/mcp-server-spec.js +55 -21
- package/dist/core/mcp.d.ts +17 -6
- package/dist/core/mcp.js +67 -55
- package/dist/core/memory-admission.d.ts +23 -6
- package/dist/core/memory-admission.js +19 -9
- package/dist/core/memory-engine/content-origin.d.ts +13 -0
- package/dist/core/memory-engine/content-origin.js +21 -3
- package/dist/core/memory-engine/index.d.ts +2 -1
- package/dist/core/memory-engine/index.js +2 -1
- package/dist/core/memory-engine/scope-contract.d.ts +13 -3
- package/dist/core/memory-engine/scope-contract.js +2 -2
- package/dist/core/memory-engine/sync-client.d.ts +45 -11
- package/dist/core/memory-engine/sync-client.js +82 -11
- package/dist/core/memory-engine/sync-report.d.ts +103 -0
- package/dist/core/memory-engine/sync-report.js +119 -0
- package/dist/core/memory-engine/sync.d.ts +4 -2
- package/dist/core/mode-policy.d.ts +9 -1
- package/dist/core/mode-policy.js +11 -1
- package/dist/core/model-receipt.d.ts +39 -0
- package/dist/core/model-receipt.js +139 -0
- package/dist/core/mods/agent-stations.d.ts +65 -0
- package/dist/core/mods/agent-stations.js +105 -0
- package/dist/core/mods/kernel/dispatch.d.ts +5 -1
- package/dist/core/mods/kernel/dispatch.js +4 -4
- package/dist/core/mods/kernel/events.d.ts +10 -4
- package/dist/core/mods/kernel/events.js +10 -6
- package/dist/core/mods/kernel/receive.d.ts +5 -0
- package/dist/core/mods/kernel/receive.js +10 -0
- package/dist/core/mods/lifecycle-stations.d.ts +41 -0
- package/dist/core/mods/lifecycle-stations.js +35 -0
- package/dist/core/mods/stations.d.ts +51 -59
- package/dist/core/mods/stations.js +32 -42
- package/dist/core/mods/tool-call.d.ts +10 -4
- package/dist/core/mods/tool-call.js +28 -12
- package/dist/core/mounted-mcp.d.ts +5 -0
- package/dist/core/mounted-mcp.js +2 -2
- package/dist/core/namespaced-rule-name.d.ts +7 -1
- package/dist/core/namespaced-rule-name.js +13 -2
- package/dist/core/oracle-isolation.js +1 -1
- package/dist/core/own-property-receipt.d.ts +3 -0
- package/dist/core/own-property-receipt.js +3 -0
- package/dist/core/park-selfcheck.js +8 -8
- package/dist/core/peer-seat.d.ts +63 -8
- package/dist/core/peer-seat.js +179 -34
- package/dist/core/permission-rule-consent.d.ts +0 -21
- package/dist/core/permission-rule-consent.js +1 -2
- package/dist/core/permission-rule-model.d.ts +4 -2
- package/dist/core/permission-rule-model.js +7 -6
- package/dist/core/protocol-http-auth.d.ts +14 -2
- package/dist/core/protocol-http-auth.js +16 -7
- package/dist/core/read-face-seats.d.ts +7 -5
- package/dist/core/read-face-seats.js +4 -1
- package/dist/core/redaction-marks.d.ts +4 -3
- package/dist/core/redaction-marks.js +2 -2
- package/dist/core/remote-env.d.ts +146 -98
- package/dist/core/remote-env.js +113 -14
- package/dist/core/retention.js +37 -12
- package/dist/core/retired-keys.d.ts +6 -1
- package/dist/core/retired-keys.js +4 -1
- package/dist/core/rewrite-rejudge.d.ts +12 -5
- package/dist/core/rewrite-rejudge.js +9 -5
- package/dist/core/roles.d.ts +37 -3
- package/dist/core/roles.js +126 -78
- package/dist/core/rule-owner.d.ts +3 -0
- package/dist/core/runner/assemble-result.d.ts +0 -5
- package/dist/core/runner/assemble-result.js +0 -1
- package/dist/core/runner/call-hook-stations.d.ts +17 -10
- package/dist/core/runner/call-hook-stations.js +21 -10
- package/dist/core/runner/child-tree.d.ts +7 -8
- package/dist/core/runner/child-tree.js +6 -6
- package/dist/core/runner/classifier-ladder.d.ts +10 -2
- package/dist/core/runner/classifier-ladder.js +39 -8
- package/dist/core/runner/construction-doors.js +5 -0
- package/dist/core/runner/contracts.d.ts +62 -41
- package/dist/core/runner/cross-boundary-lane.d.ts +3 -5
- package/dist/core/runner/cross-boundary-lane.js +11 -2
- package/dist/core/runner/env-capability-census.d.ts +15 -20
- package/dist/core/runner/env-capability-census.js +25 -34
- package/dist/core/runner/file-history-request.d.ts +2 -2
- package/dist/core/runner/file-history-request.js +0 -8
- package/dist/core/runner/gate-exit.d.ts +75 -7
- package/dist/core/runner/gate-exit.js +20 -1
- package/dist/core/runner/git-status-frame.d.ts +5 -2
- package/dist/core/runner/git-status-frame.js +3 -4
- package/dist/core/runner/image.d.ts +7 -2
- package/dist/core/runner/image.js +14 -8
- package/dist/core/runner/inline-image.d.ts +10 -8
- package/dist/core/runner/inline-image.js +11 -9
- package/dist/core/runner/memory-consolidation-driver.js +4 -4
- package/dist/core/runner/permission-rule-lanes.js +1 -1
- package/dist/core/runner/prepare-boundary-parks.d.ts +2 -2
- package/dist/core/runner/prepare-boundary-parks.js +3 -3
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +4 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +4 -3
- package/dist/core/runner/prepare-config-doors.d.ts +6 -1
- package/dist/core/runner/prepare-config-doors.js +14 -9
- package/dist/core/runner/prepare-delegation-surface.d.ts +5 -3
- package/dist/core/runner/prepare-delegation-surface.js +4 -4
- package/dist/core/runner/prepare-file-history.d.ts +10 -12
- package/dist/core/runner/prepare-file-history.js +3 -12
- package/dist/core/runner/prepare-gate-stations.d.ts +4 -3
- package/dist/core/runner/prepare-gate-stations.js +4 -3
- package/dist/core/runner/prepare-hands-readface.d.ts +3 -1
- package/dist/core/runner/prepare-hands-readface.js +15 -7
- package/dist/core/runner/prepare-inherited-gate.d.ts +5 -4
- package/dist/core/runner/prepare-inherited-gate.js +9 -5
- package/dist/core/runner/prepare-memory-engine-session.js +1 -1
- package/dist/core/runner/prepare-memory.d.ts +2 -2
- package/dist/core/runner/prepare-memory.js +2 -2
- package/dist/core/runner/prepare-park-ask.d.ts +3 -5
- package/dist/core/runner/prepare-park-ask.js +3 -8
- package/dist/core/runner/prepare-policy-chain.d.ts +5 -4
- package/dist/core/runner/prepare-policy-chain.js +120 -108
- package/dist/core/runner/prepare-project-context.js +8 -5
- package/dist/core/runner/prepare-prompt-inputs.d.ts +4 -1
- package/dist/core/runner/prepare-prompt-inputs.js +3 -2
- package/dist/core/runner/prepare-protocol-tools.d.ts +5 -3
- package/dist/core/runner/prepare-protocol-tools.js +9 -2
- package/dist/core/runner/prepare-suspend-saga.d.ts +0 -2
- package/dist/core/runner/prepare-suspend-saga.js +5 -7
- package/dist/core/runner/prepare-task.js +41 -27
- package/dist/core/runner/prepare-turn-wiring.d.ts +2 -0
- package/dist/core/runner/prepare-turn-wiring.js +7 -2
- package/dist/core/runner/prepare-wiring-manifest.d.ts +4 -3
- package/dist/core/runner/prepare-wiring-manifest.js +32 -18
- package/dist/core/runner/prepare-workspace-restore.js +3 -3
- package/dist/core/runner/resume-checkpoint-screen.js +4 -4
- package/dist/core/runner/retired-runner-deps.js +4 -1
- package/dist/core/runner/run-attachment-seats.js +3 -3
- package/dist/core/runner/run-brain-sinks.js +1 -0
- package/dist/core/runner/run-git-lane.d.ts +3 -1
- package/dist/core/runner/run-git-lane.js +1 -1
- package/dist/core/runner/run-harness-handlers.d.ts +3 -1
- package/dist/core/runner/run-harness-handlers.js +3 -1
- package/dist/core/runner/run-identity-wiring.js +1 -1
- package/dist/core/runner/run-leg.js +26 -28
- package/dist/core/runner/run-notification-lane.d.ts +3 -1
- package/dist/core/runner/run-notification-lane.js +16 -10
- package/dist/core/runner/run-settle-and-teardown.js +5 -1
- package/dist/core/runner/run-stop-and-final-verify.d.ts +4 -0
- package/dist/core/runner/run-stop-and-final-verify.js +12 -4
- package/dist/core/runner/run-turn-boundary.js +12 -7
- package/dist/core/runner/runtask.d.ts +7 -4
- package/dist/core/runner/runtask.js +19 -11
- package/dist/core/runner/skills-seat.js +2 -2
- package/dist/core/runner/sub-agent-deny-lists.js +10 -7
- package/dist/core/runner/synthetic-tools.js +2 -2
- package/dist/core/runner/tool-disclosure.js +0 -2
- package/dist/core/runner/tool-face-overlay.d.ts +1 -1
- package/dist/core/runner/tool-face-overlay.js +26 -19
- package/dist/core/runner/tool-result-media-seat.d.ts +9 -1
- package/dist/core/runner/tool-result-media-seat.js +17 -1
- package/dist/core/runner/turn-attachments.d.ts +3 -5
- package/dist/core/runner/turn-attachments.js +3 -16
- package/dist/core/runner-deps.d.ts +31 -18
- package/dist/core/secret-env.d.ts +3 -2
- package/dist/core/session-policy-store.d.ts +9 -2
- package/dist/core/session-policy-store.js +16 -1
- package/dist/core/session-store.d.ts +3 -2
- package/dist/core/session-store.js +50 -11
- package/dist/core/skill-grant.d.ts +9 -0
- package/dist/core/skill-grant.js +18 -0
- package/dist/core/store-contracts/tool-result-store-contract.d.ts +1 -1
- package/dist/core/store-contracts/tool-result-store-contract.js +37 -0
- package/dist/core/stub-env.d.ts +5 -5
- package/dist/core/stub-env.js +11 -1
- package/dist/core/swappable-deps.d.ts +17 -43
- package/dist/core/swappable-deps.js +15 -5
- package/dist/core/synthetic-read-verdict.d.ts +1 -1
- package/dist/core/task-event.d.ts +18 -2
- package/dist/core/task-notification.d.ts +88 -5
- package/dist/core/task-notification.js +130 -7
- package/dist/core/task-registry-agent.d.ts +18 -12
- package/dist/core/task-registry-agent.js +18 -6
- package/dist/core/task-registry-monitor.d.ts +7 -0
- package/dist/core/task-registry-monitor.js +28 -1
- package/dist/core/task-registry-shared.d.ts +38 -3
- package/dist/core/task-registry-shared.js +21 -7
- package/dist/core/task-registry-workflow.js +1 -1
- package/dist/core/task-registry.d.ts +50 -35
- package/dist/core/task-registry.js +64 -23
- package/dist/core/task-result.d.ts +3 -12
- package/dist/core/task-spec.d.ts +3 -6
- package/dist/core/task-stream.d.ts +1 -1
- package/dist/core/tool-catalog-entries.js +1 -1
- package/dist/core/tool-face-reader.d.ts +7 -6
- package/dist/core/tool-face-reader.js +4 -3
- package/dist/core/tool-name-aliases.d.ts +19 -0
- package/dist/core/tool-name-aliases.js +54 -2
- package/dist/core/tool-policy.d.ts +5 -4
- package/dist/core/tool-policy.js +1 -1
- package/dist/core/tool-registry.d.ts +5 -5
- package/dist/core/tool-registry.js +2 -2
- package/dist/core/tool-result-store.d.ts +88 -5
- package/dist/core/tool-result-store.js +51 -12
- package/dist/core/tool-spec.d.ts +20 -4
- package/dist/core/trace.d.ts +0 -1
- package/dist/core/types.d.ts +3 -3
- package/dist/core/types.js +1 -1
- package/dist/core/untrusted-text.js +1 -1
- package/dist/core/user-attachment.d.ts +10 -5
- package/dist/core/user-attachment.js +14 -6
- package/dist/engine/execution-env/node-execution-env.d.ts +7 -2
- package/dist/engine/execution-env/node-execution-env.js +12 -1
- package/dist/engine/harness/agent-harness.d.ts +1 -1
- package/dist/engine/harness/agent-harness.js +8 -4
- package/dist/engine/harness/types.d.ts +112 -29
- package/dist/engine/loop/agent-loop.d.ts +12 -12
- package/dist/engine/loop/agent-loop.js +153 -21
- package/dist/engine/loop/types.d.ts +9 -2
- package/dist/engine/lsp/node-lsp-manager.d.ts +3 -3
- package/dist/engine/lsp/node-lsp-manager.js +32 -13
- package/dist/index.d.ts +22 -14
- package/dist/index.js +15 -10
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/orchestration/run-workflow-tool.d.ts +9 -3
- package/dist/orchestration/run-workflow-tool.js +59 -29
- package/dist/orchestration/workflow-governance.d.ts +1 -1
- package/dist/orchestration/workflow-governance.js +2 -1
- package/dist/orchestration/workflow.d.ts +4 -0
- package/dist/orchestration/workflow.js +25 -4
- package/dist/prompts/default.d.ts +1 -10
- package/dist/prompts/default.js +0 -2
- package/dist/stores/file/background-agent-store.d.ts +1 -1
- package/dist/stores/file/background-agent-store.js +3 -1
- package/dist/stores/file/checkpoint-store.d.ts +127 -2
- package/dist/stores/file/checkpoint-store.js +19 -14
- package/dist/stores/file/file-history-store.d.ts +1 -1
- package/dist/stores/file/file-history-store.js +3 -1
- package/dist/stores/file/index.d.ts +4 -3
- package/dist/stores/file/index.js +17 -8
- package/dist/stores/file/mailbox-store.d.ts +1 -1
- package/dist/stores/file/mailbox-store.js +3 -1
- package/dist/stores/file/memory-store.d.ts +1 -1
- package/dist/stores/file/memory-store.js +3 -1
- package/dist/stores/file/session-policy-store.d.ts +1 -1
- package/dist/stores/file/session-policy-store.js +3 -1
- package/dist/stores/file/session-store.d.ts +1 -1
- package/dist/stores/file/session-store.js +3 -1
- package/dist/stores/file/shared-ledger.d.ts +26 -0
- package/dist/stores/file/shared-ledger.js +38 -9
- package/dist/stores/file/tool-result-store.d.ts +20 -2
- package/dist/stores/file/tool-result-store.js +74 -6
- package/dist/stores/file/usage-window-store.d.ts +1 -1
- package/dist/stores/file/usage-window-store.js +3 -1
- package/dist/stores/file/workflow-journal-store.d.ts +1 -11
- package/dist/stores/file/workflow-journal-store.js +3 -2
- package/dist/tools/fs/containment-face.d.ts +5 -0
- package/dist/tools/fs/encoding.d.ts +13 -4
- package/dist/tools/fs/encoding.js +17 -2
- package/dist/tools/fs/fs-bash-background-text.d.ts +7 -0
- package/dist/tools/fs/fs-bash-background-text.js +1 -0
- package/dist/tools/fs/fs-bash.d.ts +8 -4
- package/dist/tools/fs/fs-bash.js +26 -35
- package/dist/tools/fs/fs-pdf.d.ts +2 -2
- package/dist/tools/fs/fs-pdf.js +26 -21
- package/dist/tools/fs/fs-read.d.ts +5 -4
- package/dist/tools/fs/fs-read.js +35 -18
- package/dist/tools/fs/fs-search-tools.js +4 -1
- package/dist/tools/fs/fs-shared.d.ts +11 -13
- package/dist/tools/fs/fs-shared.js +11 -7
- package/dist/tools/fs/fs-write.js +5 -5
- package/dist/tools/fs/index.d.ts +14 -8
- package/dist/tools/fs/index.js +8 -4
- package/dist/tools/fs/read-floor.d.ts +44 -1
- package/dist/tools/fs/read-floor.js +35 -0
- package/dist/tools/fs/removal-targets.d.ts +9 -4
- package/dist/tools/fs/removal-targets.js +17 -9
- package/dist/tools/fs/search.d.ts +3 -3
- package/dist/tools/fs/search.js +4 -4
- package/dist/tools/monitor.d.ts +5 -4
- package/dist/tools/monitor.js +15 -8
- package/dist/tools/scheduler-tools.js +42 -4
- package/dist/tools/web.d.ts +0 -10
- package/dist/tools/web.js +1 -4
- package/package.json +4 -2
- package/test/export-surface.snapshot.json +75 -21
- package/wire-changes/core-stores-sql@7.60.0.json +30 -0
- package/wire-changes/core@7.60.0.json +3274 -0
- package/wire-changes/mods-kernel@7.60.0.json +62 -0
- package/wire-changes/primitives@7.60.0.json +30 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { types } from "node:util";
|
|
2
|
-
import { DECLARATION_PATH_RULES, NO_DECLARATION_PATH_RULES, declarationFaultOf, declarerWord, readToolAxes, receiveDeclaration, toolAxesRefusal } from "./mcp-server-spec.js";
|
|
2
|
+
import { DECLARATION_ENTRY_WORDS, DECLARATION_PATH_RULES, NO_DECLARATION_PATH_RULES, TOOL_AXIS_WORDS, callerText, declarationFaultOf, declarationPath, declarerWord, readToolAxes, receiveDeclaration, toolAxesRefusal, } from "./mcp-server-spec.js";
|
|
3
3
|
import { isPlainRecord, receive } from "./mods/kernel/receive.js";
|
|
4
|
-
import { readToolFaces } from "./tool-face-reader.js";
|
|
4
|
+
import { TOOL_FACE_WORDS, readToolFaces } from "./tool-face-reader.js";
|
|
5
5
|
import { judgeSessionMetaKey } from "./mcp-call-meta.js";
|
|
6
6
|
import { CONFIG_RECEIPT_MODE } from "./own-property-receipt.js";
|
|
7
7
|
import { isToolContentOrigin, TOOL_CONTENT_ORIGINS } from "./memory-engine/content-origin.js";
|
|
8
8
|
import { inlineUntrusted } from "./untrusted-text.js";
|
|
9
9
|
import { assertNoRetiredToolPolicyKeys } from "./retired-keys.js";
|
|
10
|
-
import { CREDENTIALS_MEMBER, declaredCredentials, peerSeatMissing, retiredValueMember } from "./peer-seat.js";
|
|
10
|
+
import { CREDENTIALS_MEMBER, RETIRED_VALUE_MEMBERS, declaredCredentials, peerSeatMissing, retiredValueMember } from "./peer-seat.js";
|
|
11
11
|
export const LOCKED_KEY_REGISTRY = {
|
|
12
12
|
mcp: { specFields: ["mcp"] },
|
|
13
13
|
a2a: { specFields: ["a2a"] },
|
|
@@ -29,7 +29,7 @@ export function resolveLockedKeys(config) {
|
|
|
29
29
|
for (let index = 0; index < listed.length; index++) {
|
|
30
30
|
const key = listed[index];
|
|
31
31
|
if (!Object.hasOwn(LOCKED_KEY_REGISTRY, key)) {
|
|
32
|
-
throw lockDeclarationRefusal(`RunnerDeps.lockedConfig.keys[${index}]`, `is ${
|
|
32
|
+
throw lockDeclarationRefusal(`RunnerDeps.lockedConfig.keys[${index}]`, `is ${callerText(key)}, which is not a member of the locked-key registry (${Object.keys(LOCKED_KEY_REGISTRY).join(", ")})`);
|
|
33
33
|
}
|
|
34
34
|
keys.add(key);
|
|
35
35
|
}
|
|
@@ -38,13 +38,13 @@ export function resolveLockedKeys(config) {
|
|
|
38
38
|
function declaredLockKeys(config) {
|
|
39
39
|
const received = receiveDeclaration(config, NO_DECLARATION_PATH_RULES);
|
|
40
40
|
if (!received.ok)
|
|
41
|
-
throw lockDeclarationRefusal(
|
|
41
|
+
throw lockDeclarationRefusal(declarationPath(received.fault.path, LOCK_DECLARATION_WORDS, "RunnerDeps.lockedConfig"), `cannot be read: ${received.fault.problem}`);
|
|
42
42
|
const copy = received.value;
|
|
43
43
|
if (!isPlainRecord(copy))
|
|
44
|
-
throw lockDeclarationRefusal("RunnerDeps.lockedConfig", `is ${
|
|
44
|
+
throw lockDeclarationRefusal("RunnerDeps.lockedConfig", `is ${callerText(copy)}, not an object with a \`keys\` list`);
|
|
45
45
|
const keys = Object.hasOwn(copy, "keys") ? copy["keys"] : undefined;
|
|
46
46
|
if (!Array.isArray(keys))
|
|
47
|
-
throw lockDeclarationRefusal("RunnerDeps.lockedConfig.keys", `is ${
|
|
47
|
+
throw lockDeclarationRefusal("RunnerDeps.lockedConfig.keys", `is ${callerText(keys)}, not a list of locked keys`);
|
|
48
48
|
return keys;
|
|
49
49
|
}
|
|
50
50
|
function lockDeclarationRefusal(member, problem) {
|
|
@@ -53,16 +53,8 @@ function lockDeclarationRefusal(member, problem) {
|
|
|
53
53
|
export function snapshotMcpEntries(entries) {
|
|
54
54
|
return entries.map((entry) => snapshotDeclaredEntry(entry, "mcp"));
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
for (const key of path) {
|
|
59
|
-
const name = typeof key === "string" && /^\d+$/.test(key) ? JSON.stringify(key) : String(key);
|
|
60
|
-
rendered += typeof key === "number" ? `[${key}]` : rendered === "" ? name : `.${name}`;
|
|
61
|
-
if (rendered.length > 120 + base.length)
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
return rendered;
|
|
65
|
-
}
|
|
56
|
+
const LOCK_DECLARATION_WORDS = new Set(["keys"]);
|
|
57
|
+
const ENTRY_PATH_WORDS = new Set([...DECLARATION_ENTRY_WORDS, ...TOOL_AXIS_WORDS, ...TOOL_FACE_WORDS, ...Object.values(RETIRED_VALUE_MEMBERS).flat(2)]);
|
|
66
58
|
function unreadableDeclaration(at, declarer, member, problem) {
|
|
67
59
|
const refusal = codedError("config.invalid_argument", `${declarerWord(at)}${declarer === undefined ? "" : ` ${declarerNameOf(declarer)}`} declares ${inlineUntrusted(member, 80)} the engine cannot read: ${problem}. A declaration the engine cannot read is refused ` +
|
|
68
60
|
`rather than partly applied — what the caller wrote and what the engine runs on would otherwise differ without anyone being told.`);
|
|
@@ -82,7 +74,7 @@ function capturedName(entry) {
|
|
|
82
74
|
return typeof entry === "object" && entry !== null && !types.isProxy(entry) ? ownDataString(entry, "name") : undefined;
|
|
83
75
|
}
|
|
84
76
|
function entryFaultRefusal(at, declarer, path, problem) {
|
|
85
|
-
return unreadableDeclaration(at, declarer, path.length === 0 ? "an entry" :
|
|
77
|
+
return unreadableDeclaration(at, declarer, path.length === 0 ? "an entry" : declarationPath(path, ENTRY_PATH_WORDS), problem);
|
|
86
78
|
}
|
|
87
79
|
export function snapshotDeclaredEntry(entry, at) {
|
|
88
80
|
const declared = entry;
|
|
@@ -91,7 +83,7 @@ export function snapshotDeclaredEntry(entry, at) {
|
|
|
91
83
|
if (!received.ok)
|
|
92
84
|
throw entryFaultRefusal(at, declarer, received.fault.path, received.fault.problem);
|
|
93
85
|
if (!isPlainRecord(received.value))
|
|
94
|
-
throw unreadableDeclaration(at, declarer, "an entry", `it is ${
|
|
86
|
+
throw unreadableDeclaration(at, declarer, "an entry", `it is ${callerText(received.value)}, not an object`);
|
|
95
87
|
const retired = retiredValueMember(received.value, at);
|
|
96
88
|
if (retired !== undefined) {
|
|
97
89
|
throw declarationRefusal("config.credential_in_declaration", at, declarer, `declares ${retired.join(".")}, a member that carried values and is retired: a declaration names the peer and at most one opaque reference (${CREDENTIALS_MEMBER[at].join(".")}); the pieces a request carries are answered per send by the deployment's peer seat (RunnerDeps.peerSeat). The value is not repeated here.`);
|
|
@@ -116,20 +108,7 @@ function assertPeerSeatFor(entries, at, seat) {
|
|
|
116
108
|
throw missing;
|
|
117
109
|
}
|
|
118
110
|
}
|
|
119
|
-
|
|
120
|
-
try {
|
|
121
|
-
return JSON.stringify(value) ?? String(value);
|
|
122
|
-
}
|
|
123
|
-
catch {
|
|
124
|
-
try {
|
|
125
|
-
return String(value);
|
|
126
|
-
}
|
|
127
|
-
catch {
|
|
128
|
-
return `[unrepresentable ${typeof value}]`;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
const declarerNameOf = (name) => inlineUntrusted(typeof name === "string" ? JSON.stringify(name) : describeDeclared(name), 80);
|
|
111
|
+
const declarerNameOf = (name) => (typeof name === "string" ? inlineUntrusted(JSON.stringify(name), 80) : callerText(name));
|
|
133
112
|
export function judgeEntryToolAxes(copy, at) {
|
|
134
113
|
const { toolAxes: declaredAxes, ...rest } = copy;
|
|
135
114
|
const axes = readToolAxes(declaredAxes, at);
|
|
@@ -150,8 +129,9 @@ function deepFrozen(value) {
|
|
|
150
129
|
}
|
|
151
130
|
return value;
|
|
152
131
|
}
|
|
132
|
+
const FACES_PROBLEM_MAX = 400;
|
|
153
133
|
function toolFacesRefusal(name, problem) {
|
|
154
|
-
return codedError("config.tool_face_invalid", `${declarerWord("mcp")} ${name} declares toolFaces the engine cannot read: ${inlineUntrusted(problem,
|
|
134
|
+
return codedError("config.tool_face_invalid", `${declarerWord("mcp")} ${name} declares toolFaces the engine cannot read: ${inlineUntrusted(problem, FACES_PROBLEM_MAX)}. A per-tool face declaration is the deployment's own ` +
|
|
155
135
|
`narrowing (which argument names a tool's path, how a write is confined, which approval card and rule vocabulary the tool wears), so it is refused ` +
|
|
156
136
|
`rather than partly applied — a member dropped or a word defaulted would mount the tool without the protection its operator declared.`);
|
|
157
137
|
}
|
|
@@ -170,12 +150,25 @@ export function judgeEntrySessionMetaKey(copy) {
|
|
|
170
150
|
return { ok: true, entry: copy };
|
|
171
151
|
return { ok: false, error: codedError("config.invalid_argument", `${declarerWord("mcp")} ${declarerNameOf(copy.name)} declares ${inlineUntrusted(read.problem, 200)}. The key decides where the leg's session id rides on this server's requests, so it is refused rather than dropped or defaulted — a connector keyed on a session it never receives would share one state across every session.`) };
|
|
172
152
|
}
|
|
153
|
+
export function judgeEntryHostTransport(copy) {
|
|
154
|
+
const transport = copy.transport;
|
|
155
|
+
if (!isPlainRecord(transport) || transport["kind"] !== "host")
|
|
156
|
+
return { ok: true, entry: copy };
|
|
157
|
+
const extra = Object.keys(transport).find((member) => member !== "kind" && transport[member] !== undefined);
|
|
158
|
+
const problem = extra !== undefined
|
|
159
|
+
? `a host-supplied transport with the member ${inlineUntrusted(JSON.stringify(extra), 80)}: a host transport carries its kind alone — the host seat carries what each request needs, so a member here would read as in force while nothing carries it`
|
|
160
|
+
: copy.elicitation === true
|
|
161
|
+
? `elicitation on a host-supplied transport: the host seat answers the engine's requests only, so a server's question would have no way back`
|
|
162
|
+
: undefined;
|
|
163
|
+
return problem === undefined ? { ok: true, entry: copy } : { ok: false, error: codedError("config.invalid_argument", `${declarerWord("mcp")} ${declarerNameOf(copy.name)} declares ${problem}.`) };
|
|
164
|
+
}
|
|
173
165
|
export function judgeMcpEntryDeclarations(copy) {
|
|
174
166
|
const axes = judgeEntryToolAxes(copy, "mcp");
|
|
175
167
|
const faces = axes.ok ? judgeEntryToolFaces(axes.entry) : axes;
|
|
176
|
-
|
|
168
|
+
const metaKey = faces.ok ? judgeEntrySessionMetaKey(faces.entry) : faces;
|
|
169
|
+
return metaKey.ok ? judgeEntryHostTransport(metaKey.entry) : metaKey;
|
|
177
170
|
}
|
|
178
|
-
function declaredEntriesOf(declared, at) {
|
|
171
|
+
function declaredEntriesOf(declared, at, where) {
|
|
179
172
|
const field = at;
|
|
180
173
|
const received = receive(declared, CONFIG_RECEIPT_MODE);
|
|
181
174
|
let problem;
|
|
@@ -183,7 +176,7 @@ function declaredEntriesOf(declared, at) {
|
|
|
183
176
|
const list = received.value;
|
|
184
177
|
if (Array.isArray(list) && list !== declared)
|
|
185
178
|
return Array.from({ length: list.length }, (_, index) => list[index]);
|
|
186
|
-
problem = typeof list === "object" && list !== null ? "it is not an array" : `it is ${
|
|
179
|
+
problem = typeof list === "object" && list !== null ? "it is not an array" : `it is ${callerText(list)}`;
|
|
187
180
|
}
|
|
188
181
|
else {
|
|
189
182
|
const fault = declarationFaultOf(received.fault);
|
|
@@ -191,26 +184,65 @@ function declaredEntriesOf(declared, at) {
|
|
|
191
184
|
throw unreadableDeclaration(at, undefined, "an entry", fault.problem);
|
|
192
185
|
problem = fault.problem;
|
|
193
186
|
}
|
|
194
|
-
throw codedError("config.invalid_argument", `TaskSpec.${field} must be a readable array of ${declarerWord(at)} declarations; ${problem}. A list the engine cannot read ` +
|
|
187
|
+
throw codedError("config.invalid_argument", `${where ?? `TaskSpec.${field}`} must be a readable array of ${declarerWord(at)} declarations; ${problem}. A list the engine cannot read ` +
|
|
195
188
|
`is refused rather than read as "no entries" — the declared ${declarerWord(at)}s would otherwise be dropped without anyone being told.`);
|
|
196
189
|
}
|
|
197
|
-
function
|
|
198
|
-
const entries = declaredEntriesOf(declared, "a2a");
|
|
190
|
+
function validatedA2aEntries(entries) {
|
|
199
191
|
if (entries.length === 0)
|
|
200
192
|
return undefined;
|
|
201
193
|
return entries.map((entry) => {
|
|
202
|
-
const judged = judgeEntryToolAxes(
|
|
194
|
+
const judged = judgeEntryToolAxes(received(entry), "a2a");
|
|
203
195
|
if (!judged.ok)
|
|
204
196
|
throw judged.error;
|
|
205
197
|
return judged.entry;
|
|
206
198
|
});
|
|
207
199
|
}
|
|
208
|
-
|
|
209
|
-
|
|
200
|
+
const receiving = (read) => {
|
|
201
|
+
try {
|
|
202
|
+
return { read: read() };
|
|
203
|
+
}
|
|
204
|
+
catch (refused) {
|
|
205
|
+
return { refused };
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
const received = (r) => {
|
|
209
|
+
if ("refused" in r)
|
|
210
|
+
throw r.refused;
|
|
211
|
+
return r.read;
|
|
212
|
+
};
|
|
213
|
+
export function receivePeerDeclarations(spec, deps) {
|
|
214
|
+
const locks = receiving(() => resolveLockedKeys(deps.lockedConfig));
|
|
215
|
+
if ("refused" in locks)
|
|
216
|
+
return { locks };
|
|
217
|
+
const list = (at) => {
|
|
218
|
+
if (locks.read.has(at))
|
|
219
|
+
return undefined;
|
|
220
|
+
const declared = receiving(() => spec[at]);
|
|
221
|
+
if ("refused" in declared)
|
|
222
|
+
return declared;
|
|
223
|
+
if (declared.read === undefined)
|
|
224
|
+
return undefined;
|
|
225
|
+
return receiving(() => declaredEntriesOf(declared.read, at).map((entry) => receiving(() => snapshotDeclaredEntry(entry, at))));
|
|
226
|
+
};
|
|
227
|
+
const mcp = list("mcp");
|
|
228
|
+
const a2a = list("a2a");
|
|
229
|
+
return { locks, ...(mcp !== undefined ? { mcp } : {}), ...(a2a !== undefined ? { a2a } : {}) };
|
|
230
|
+
}
|
|
231
|
+
export function receivedDeclarations(receipt) {
|
|
232
|
+
const copies = (r) => r === undefined || "refused" in r ? undefined : r.read.flatMap((entry) => ("read" in entry ? [entry.read] : []));
|
|
233
|
+
const mcp = copies(receipt.mcp);
|
|
234
|
+
const a2a = copies(receipt.a2a);
|
|
235
|
+
return { ...(mcp !== undefined ? { mcp } : {}), ...(a2a !== undefined ? { a2a } : {}) };
|
|
236
|
+
}
|
|
237
|
+
export function snapshotAndValidateMcpEntries(declared, where) {
|
|
238
|
+
return validatedMcpEntries(snapshotMcpEntries(declaredEntriesOf(declared, "mcp", where)));
|
|
239
|
+
}
|
|
240
|
+
function validatedMcpEntries(copies) {
|
|
241
|
+
return copies.map((copy) => {
|
|
210
242
|
const declared = copy.contentOrigin;
|
|
211
243
|
if (declared !== undefined && !isToolContentOrigin(declared)) {
|
|
212
244
|
throw codedError("config.mcp_content_class", `MCP server ${declarerNameOf(copy.name)} declares contentOrigin ` +
|
|
213
|
-
`${
|
|
245
|
+
`${callerText(declared)}, which is not one of ` +
|
|
214
246
|
`${TOOL_CONTENT_ORIGINS.map((v) => `"${v}"`).join(" | ")}. The declaration decides whether this server's tools ` +
|
|
215
247
|
`mark the session's memory externally exposed — a value this engine cannot read is refused at the door rather ` +
|
|
216
248
|
`than folded to a class, because folding it would let a deployment believe a declaration is in force while every ` +
|
|
@@ -222,8 +254,9 @@ function snapshotAndValidateMcpEntries(declared) {
|
|
|
222
254
|
return judged.entry;
|
|
223
255
|
});
|
|
224
256
|
}
|
|
225
|
-
export function preflightLockedConfig(spec, deps, enter = ENTER_AS_IS) {
|
|
226
|
-
const
|
|
257
|
+
export function preflightLockedConfig(spec, deps, enter = ENTER_AS_IS, receipt) {
|
|
258
|
+
const peers = receipt ?? receivePeerDeclarations(spec, { lockedConfig: deps.lockedConfig });
|
|
259
|
+
const lockedKeys = enter("deps", () => received(peers.locks));
|
|
227
260
|
enter("taskConfig", () => {
|
|
228
261
|
for (const key of lockedKeys) {
|
|
229
262
|
for (const field of LOCKED_KEY_REGISTRY[key].specFields) {
|
|
@@ -240,10 +273,8 @@ export function preflightLockedConfig(spec, deps, enter = ENTER_AS_IS) {
|
|
|
240
273
|
const policies = callerPolicySeats(task, deps, toolPolicyLocked);
|
|
241
274
|
enter(!toolPolicyLocked && task.toolPolicy != null ? "taskConfig" : "deps", () => assertNoRetiredToolPolicyKeys(policies.toolPolicy));
|
|
242
275
|
enter(!toolPolicyLocked && task.basePolicyForResumeEdit != null ? "taskConfig" : "deps", () => assertNoRetiredToolPolicyKeys(policies.basePolicyForResumeEdit));
|
|
243
|
-
const
|
|
244
|
-
const
|
|
245
|
-
const declaredPeers = lockedKeys.has("a2a") ? undefined : spec.a2a;
|
|
246
|
-
const a2a = declaredPeers === undefined ? undefined : enter("taskConfig", () => snapshotAndValidateA2aEntries(declaredPeers));
|
|
276
|
+
const mcp = lockedKeys.has("mcp") || peers.mcp === undefined ? undefined : enter("taskConfig", () => validatedMcpEntries(received(peers.mcp).map(received)));
|
|
277
|
+
const a2a = lockedKeys.has("a2a") || peers.a2a === undefined ? undefined : enter("taskConfig", () => validatedA2aEntries(received(peers.a2a)));
|
|
247
278
|
enter("taskConfig", () => {
|
|
248
279
|
assertPeerSeatFor(mcp, "mcp", deps.peerSeat);
|
|
249
280
|
assertPeerSeatFor(a2a, "a2a", deps.peerSeat);
|
|
@@ -35,8 +35,8 @@ export type SessionMetaKeyReading = {
|
|
|
35
35
|
* prefix of dot-separated labels and a slash, then a name — the format is what a conforming server accepts, and it keeps out names such
|
|
36
36
|
* as `__proto__` that the SDK's own request parse drops) that names no `_meta` member of anyone else's: not the SDK's `progressToken`,
|
|
37
37
|
* not a key under the engine's `sema/` namespace, not under a prefix MCP reserves (the prefix is the text before the first `/`; its
|
|
38
|
-
* labels are DNS labels, so the second one is compared with case folded).
|
|
39
|
-
* text,
|
|
38
|
+
* labels are DNS labels, so the second one is compared with case folded). A refusal says which rule the key breaks and never the key: the
|
|
39
|
+
* key is the declaration's own text, shown in the one caller's-text shape (`callerText`: the redaction mark and its length).
|
|
40
40
|
*/
|
|
41
41
|
export declare function judgeSessionMetaKey(value: unknown): SessionMetaKeyReading;
|
|
42
42
|
/**
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
2
|
import { types } from "node:util";
|
|
3
3
|
import { isPlainRecord } from "./mods/kernel/receive.js";
|
|
4
|
-
import { dataKind } from "./mcp-server-spec.js";
|
|
4
|
+
import { callerText, dataKind } from "./mcp-server-spec.js";
|
|
5
5
|
export const MCP_TOOL_USE_ID_META_KEY = "sema/toolUseId";
|
|
6
6
|
export const MCP_REQUEST_META_KEY = "sema/requestMeta";
|
|
7
7
|
export const MCP_REQUEST_META_MAX_BYTES = 262_144;
|
|
8
8
|
const kindOf = (v) => v === null ? "null" : Array.isArray(v) ? "a list" : typeof v === "object" ? (types.isProxy(v) ? "a Proxy" : "an object that is not a plain record") : `a ${typeof v}`;
|
|
9
|
-
const named = (key) => JSON.stringify(key.length > 60 ? `${key.slice(0, 60)}…` : key);
|
|
10
9
|
export function judgeRequestMeta(value) {
|
|
11
10
|
if (value === undefined)
|
|
12
11
|
return { meta: undefined };
|
|
@@ -23,10 +22,10 @@ export function judgeRequestMeta(value) {
|
|
|
23
22
|
for (const key of Object.getOwnPropertyNames(descriptors)) {
|
|
24
23
|
const d = descriptors[key];
|
|
25
24
|
if (!Object.hasOwn(d, "value") || d.enumerable !== true)
|
|
26
|
-
return { problem: `requestMeta's member ${
|
|
25
|
+
return { problem: `requestMeta's member ${callerText(key)} is not an enumerable data property (a getter is never run)` };
|
|
27
26
|
const v = d.value;
|
|
28
27
|
if (typeof v !== "string")
|
|
29
|
-
return { problem: `requestMeta's member ${
|
|
28
|
+
return { problem: `requestMeta's member ${callerText(key)} is ${kindOf(v)}, not a string` };
|
|
30
29
|
bytes += Buffer.byteLength(key, "utf8") + Buffer.byteLength(v, "utf8");
|
|
31
30
|
Object.defineProperty(copy, key, { value: v, enumerable: true, writable: false, configurable: false });
|
|
32
31
|
members += 1;
|
|
@@ -57,20 +56,20 @@ export function judgeSessionMetaKey(value) {
|
|
|
57
56
|
if (value === "")
|
|
58
57
|
return { problem: "sessionMetaKey is the empty string; it takes a non-empty string" };
|
|
59
58
|
if (value.length > MCP_SESSION_META_KEY_MAX_CHARS)
|
|
60
|
-
return { problem: `sessionMetaKey
|
|
59
|
+
return { problem: `sessionMetaKey is ${value.length} characters; the most is ${MCP_SESSION_META_KEY_MAX_CHARS}` };
|
|
61
60
|
const slash = value.indexOf("/");
|
|
62
61
|
const labels = slash === -1 ? [] : value.slice(0, slash).split(".");
|
|
63
62
|
if (!labels.every((label) => META_LABEL.test(label)))
|
|
64
|
-
return { problem: `sessionMetaKey ${
|
|
63
|
+
return { problem: `sessionMetaKey ${callerText(value)} has a prefix that is not dot-separated labels (a label starts with a letter, ends with a letter or digit, and holds letters, digits and hyphens) followed by a slash` };
|
|
65
64
|
if (!META_NAME.test(value.slice(slash + 1)))
|
|
66
|
-
return { problem: `sessionMetaKey ${
|
|
65
|
+
return { problem: `sessionMetaKey ${callerText(value)} has a name that does not begin and end with a letter or digit, or holds a character other than letters, digits, hyphen, underscore and dot` };
|
|
67
66
|
if (value === SDK_PROGRESS_TOKEN_KEY)
|
|
68
|
-
return { problem: `sessionMetaKey ${
|
|
67
|
+
return { problem: `sessionMetaKey ${callerText(value)} is the key the MCP SDK writes for its own progress token` };
|
|
69
68
|
if (value.startsWith(ENGINE_META_NAMESPACE))
|
|
70
|
-
return { problem: `sessionMetaKey ${
|
|
69
|
+
return { problem: `sessionMetaKey ${callerText(value)} is under the engine's own "${ENGINE_META_NAMESPACE}" namespace` };
|
|
71
70
|
const second = labels[1]?.toLowerCase();
|
|
72
71
|
if (second !== undefined && MCP_RESERVED_LABELS.includes(second))
|
|
73
|
-
return { problem: `sessionMetaKey ${
|
|
72
|
+
return { problem: `sessionMetaKey ${callerText(value)} is under a prefix MCP reserves (second label "${second}")` };
|
|
74
73
|
return { key: value };
|
|
75
74
|
}
|
|
76
75
|
export function mcpCallMeta(toolUseId, requestMeta, sessionMetaKey, sessionId) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AssertAllKeysHandled } from "./ask-origin.js";
|
|
2
2
|
import type { AnnouncedMcpFailure } from "../internal/harness.js";
|
|
3
|
+
import type { McpTransportKind } from "./mcp-server-spec.js";
|
|
3
4
|
/**
|
|
4
5
|
* The closed set of failure classes ({@link McpFailure.kind}):
|
|
5
6
|
* · `connect_refused` — a connect-phase errno (ECONNREFUSED / ENOTFOUND / EAI_AGAIN / EHOSTUNREACH /
|
|
@@ -29,9 +30,12 @@ import type { AnnouncedMcpFailure } from "../internal/harness.js";
|
|
|
29
30
|
* · `credential_unavailable` — the deployment's peer seat did not furnish the request (it threw, did not
|
|
30
31
|
* answer in time, or answered something the engine cannot carry): that request
|
|
31
32
|
* was not sent — a fault for the deployment to fix, not an outage of the server;
|
|
32
|
-
* · `
|
|
33
|
+
* · `host_refused` — the host seat of a host-supplied transport (mcp-host-seat.ts) did not hand the request to the
|
|
34
|
+
* remote: nothing ran, and nothing is said about whether the remote can be reached;
|
|
35
|
+
* · `unknown` — the thrown value carried no structure this table reads, or the host seat took the request
|
|
36
|
+
* and cannot tell how it ended.
|
|
33
37
|
*/
|
|
34
|
-
export declare const MCP_FAILURE_KINDS: readonly ["connect_refused", "connection_failed", "connection_closed", "unauthorized", "http_status", "not_mcp_response", "spawn_failed", "timeout", "protocol", "invalid_config", "credential_unavailable", "unknown"];
|
|
38
|
+
export declare const MCP_FAILURE_KINDS: readonly ["connect_refused", "connection_failed", "connection_closed", "unauthorized", "http_status", "not_mcp_response", "spawn_failed", "timeout", "protocol", "invalid_config", "credential_unavailable", "host_refused", "unknown"];
|
|
35
39
|
export type McpFailureKind = (typeof MCP_FAILURE_KINDS)[number];
|
|
36
40
|
/**
|
|
37
41
|
* Why a server is `unauthorized` ({@link McpAuthorization.reason}), closed:
|
|
@@ -83,6 +87,7 @@ export declare const DELIVERED_BY_KIND: {
|
|
|
83
87
|
readonly protocol: "yes";
|
|
84
88
|
readonly invalid_config: "no";
|
|
85
89
|
readonly credential_unavailable: "no";
|
|
90
|
+
readonly host_refused: "no";
|
|
86
91
|
readonly unknown: "unknown";
|
|
87
92
|
};
|
|
88
93
|
/** The fence over the delivery table: `never` while every kind has a verdict. */
|
|
@@ -146,6 +151,7 @@ export declare const LIVENESS_BY_FAILURE_KIND: {
|
|
|
146
151
|
readonly protocol: "reachable";
|
|
147
152
|
readonly invalid_config: undefined;
|
|
148
153
|
readonly credential_unavailable: undefined;
|
|
154
|
+
readonly host_refused: undefined;
|
|
149
155
|
readonly unknown: "unknown";
|
|
150
156
|
};
|
|
151
157
|
/** The fence over the liveness table: `never` while every kind has a verdict. */
|
|
@@ -172,7 +178,7 @@ export type McpRequestSite = {
|
|
|
172
178
|
* transport is the child process failing to spawn, or on a request over an established connection. */
|
|
173
179
|
export type McpFailureSite = {
|
|
174
180
|
phase: "connect";
|
|
175
|
-
transport:
|
|
181
|
+
transport: McpTransportKind | undefined;
|
|
176
182
|
} | McpRequestSite;
|
|
177
183
|
/**
|
|
178
184
|
* The one MCP failure record. Both fields are always present; `httpStatus` rides only with
|
package/dist/core/mcp-failure.js
CHANGED
|
@@ -2,6 +2,7 @@ import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
|
|
|
2
2
|
import { StreamableHTTPError } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3
3
|
import { proxyTunnelRefusedSentence, readConnectFailure } from "../brain/errors.js";
|
|
4
4
|
import { PeerAuthorizationRefused, PeerSeatFailure } from "./peer-seat.js";
|
|
5
|
+
import { hostSeatVerdictOf } from "./mcp-host-seat.js";
|
|
5
6
|
export const MCP_FAILURE_KINDS = Object.freeze([
|
|
6
7
|
"connect_refused",
|
|
7
8
|
"connection_failed",
|
|
@@ -14,6 +15,7 @@ export const MCP_FAILURE_KINDS = Object.freeze([
|
|
|
14
15
|
"protocol",
|
|
15
16
|
"invalid_config",
|
|
16
17
|
"credential_unavailable",
|
|
18
|
+
"host_refused",
|
|
17
19
|
"unknown",
|
|
18
20
|
]);
|
|
19
21
|
export const MCP_AUTHORIZATION_REASONS = Object.freeze(["rejected", "scope", "none"]);
|
|
@@ -30,6 +32,7 @@ export const DELIVERED_BY_KIND = {
|
|
|
30
32
|
protocol: "yes",
|
|
31
33
|
invalid_config: "no",
|
|
32
34
|
credential_unavailable: "no",
|
|
35
|
+
host_refused: "no",
|
|
33
36
|
unknown: "unknown",
|
|
34
37
|
};
|
|
35
38
|
export const MCP_LIVENESS_STATES = Object.freeze(["reachable", "unreachable", "unknown"]);
|
|
@@ -45,6 +48,7 @@ export const LIVENESS_BY_FAILURE_KIND = {
|
|
|
45
48
|
protocol: "reachable",
|
|
46
49
|
invalid_config: undefined,
|
|
47
50
|
credential_unavailable: undefined,
|
|
51
|
+
host_refused: undefined,
|
|
48
52
|
unknown: "unknown",
|
|
49
53
|
};
|
|
50
54
|
export function livenessOf(outcome, observedAt) {
|
|
@@ -105,6 +109,11 @@ export const FAILURE_CLASSIFIER = [
|
|
|
105
109
|
when: (err) => err instanceof PeerSeatFailure,
|
|
106
110
|
reads: () => ({ kind: "credential_unavailable", unsent: true }),
|
|
107
111
|
},
|
|
112
|
+
{
|
|
113
|
+
name: "host seat did not carry the request",
|
|
114
|
+
when: (err) => hostSeatVerdictOf(err) !== undefined,
|
|
115
|
+
reads: (err) => ({ kind: hostSeatVerdictOf(err).delivered === "no" ? "host_refused" : "unknown" }),
|
|
116
|
+
},
|
|
108
117
|
{
|
|
109
118
|
name: "sdk connection closed",
|
|
110
119
|
when: (err) => err instanceof McpError && err.code === ErrorCode.ConnectionClosed,
|
|
@@ -248,6 +257,7 @@ export function describeHttpTransportFailure(err, at = { phase: "request" }) {
|
|
|
248
257
|
case "protocol":
|
|
249
258
|
case "invalid_config":
|
|
250
259
|
case "credential_unavailable":
|
|
260
|
+
case "host_refused":
|
|
251
261
|
case "unknown":
|
|
252
262
|
return undefined;
|
|
253
263
|
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host seat: an MCP pipe the HOST supplies for one leg, mounted by a declaration whose transport is `{ kind: "host" }`
|
|
3
|
+
* ({@link import("./mcp-server-spec.js").McpServerSpec}). The engine owns the seat's shape and the one adapter that turns it
|
|
4
|
+
* into an MCP transport ({@link HostSeatTransport}); the host owns what is behind it. The declaration is data (it rides
|
|
5
|
+
* `TaskSpec.mcp`, the wiring manifest and a resume config like any other entry); the seat is a live object and rides the
|
|
6
|
+
* trusted channel only (`RunInternals.mcpHostSeats`, keyed by the declaration's `name`), never a spec, a checkpoint or a
|
|
7
|
+
* retained child's snapshot.
|
|
8
|
+
*
|
|
9
|
+
* A host-seat server goes through the one MCP pipeline every server does — the dial, the listing intake, the call lane, the
|
|
10
|
+
* failure record — so its listed `_meta`, its call `_meta` and its tool names are what a stdio or http server's would be.
|
|
11
|
+
* What the adapter does itself, and only this:
|
|
12
|
+
* · answers `initialize` locally: the server's name is the declaration's `name`, its version the empty string (a host-seat
|
|
13
|
+
* declaration states no version), its capabilities `tools` only, no instructions; swallows `notifications/initialized`;
|
|
14
|
+
* · hands `tools/list` and `tools/call` to the seat, one {@link McpHostSeat.request} each, with a signal of the request's own
|
|
15
|
+
* — aborted when the engine cancels that request (its abort, its timeout, the idle watchdog) and when the connection closes;
|
|
16
|
+
* · refuses every other method locally (the request is not handed on), and drops an answer that arrives after its request
|
|
17
|
+
* was cancelled.
|
|
18
|
+
* Every outcome reaches the SDK as a JSON-RPC response: the seat's answer as it gave it, a seat failure as an error response
|
|
19
|
+
* whose `data` is a verdict object only this module mints ({@link hostSeatVerdictOf}) — `send` itself never rejects, so the
|
|
20
|
+
* SDK's per-request handlers are always cleared by the response.
|
|
21
|
+
*/
|
|
22
|
+
import { type JSONRPCMessage } from "@modelcontextprotocol/sdk/types.js";
|
|
23
|
+
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
24
|
+
/** The requests a host seat answers: a listing and a call. */
|
|
25
|
+
export type McpHostSeatMethod = "tools/list" | "tools/call";
|
|
26
|
+
/** A host seat's answer to one request: the JSON-RPC result, or the JSON-RPC error the remote answered with. */
|
|
27
|
+
export type McpHostSeatAnswer = {
|
|
28
|
+
readonly result: unknown;
|
|
29
|
+
} | {
|
|
30
|
+
readonly error: {
|
|
31
|
+
readonly code: number;
|
|
32
|
+
readonly message: string;
|
|
33
|
+
readonly data?: unknown;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The host's MCP pipe for one leg (`RunInternals.mcpHostSeats`, TRUSTED). `request` answers one request; `signal` is that
|
|
38
|
+
* request's own cancellation. A request the host could not hand to the remote, or whose ending it cannot tell, is answered by
|
|
39
|
+
* throwing {@link McpHostSeatFailure}. The engine never disposes a seat: the host releases it when its leg ends.
|
|
40
|
+
*/
|
|
41
|
+
export interface McpHostSeat {
|
|
42
|
+
request(method: McpHostSeatMethod, params: Readonly<Record<string, unknown>>, signal: AbortSignal): Promise<McpHostSeatAnswer>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A host seat's failure to carry one request, in the one fact the host knows: `delivered: "no"` — the request was not handed to the
|
|
46
|
+
* remote (nothing ran; the failure word is `host_refused`); `delivered: "unknown"` — it was handed on and the host cannot tell how it
|
|
47
|
+
* ended (the failure word is `unknown`). `condition` is the host's own sentence about why, read as untrusted text and bounded; the
|
|
48
|
+
* engine adds what the verdict owes the model (retry safety, the verify-first warning of a write-capable tool) itself, so the
|
|
49
|
+
* condition carries none of it. Any other value thrown by a seat — or this class built with a delivery word outside the two — is a
|
|
50
|
+
* request whose ending the engine cannot tell either: it reads as `unknown`, in the engine's own words, never the thrown text.
|
|
51
|
+
*/
|
|
52
|
+
export declare class McpHostSeatFailure extends Error {
|
|
53
|
+
readonly delivered: "no" | "unknown";
|
|
54
|
+
readonly condition: string;
|
|
55
|
+
constructor(o: {
|
|
56
|
+
delivered: "no" | "unknown";
|
|
57
|
+
condition: string;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/** What a host seat said about a request it did not answer: the delivery fact and the sentence a failure renders. */
|
|
61
|
+
export interface HostSeatVerdict {
|
|
62
|
+
readonly delivered: "no" | "unknown";
|
|
63
|
+
readonly condition: string;
|
|
64
|
+
}
|
|
65
|
+
/** The host seat's verdict a failure carries (the SDK's error for a response this module synthesized), else `undefined`. Structure only. */
|
|
66
|
+
export declare function hostSeatVerdictOf(err: unknown): HostSeatVerdict | undefined;
|
|
67
|
+
/** The sentence a host seat's verdict becomes on the call lane: who failed and why, then the tail the delivery fact owes. */
|
|
68
|
+
export declare function hostSeatLine(what: string, serverLabel: string, seat: HostSeatVerdict, writeTail: string): string;
|
|
69
|
+
/** A host-seat declaration whose leg holds no seat of its name: refused at its dial (`config.mcp_host_seat_missing`), nothing sent. */
|
|
70
|
+
export declare function hostSeatMissing(server: string): Error & {
|
|
71
|
+
code: string;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* The one adapter from a {@link McpHostSeat} to the SDK's `Transport` (see the module note). One per connection: `close` aborts every
|
|
75
|
+
* request still in the seat's hands and closes the connection.
|
|
76
|
+
*/
|
|
77
|
+
export declare class HostSeatTransport implements Transport {
|
|
78
|
+
private readonly seat;
|
|
79
|
+
private readonly serverName;
|
|
80
|
+
onclose?: () => void;
|
|
81
|
+
onerror?: (error: Error) => void;
|
|
82
|
+
onmessage?: <T extends JSONRPCMessage>(message: T) => void;
|
|
83
|
+
/** The requests in the seat's hands, by id: an answer is delivered only while its request is still here. */
|
|
84
|
+
private readonly inFlight;
|
|
85
|
+
private closed;
|
|
86
|
+
constructor(seat: McpHostSeat, serverName: string);
|
|
87
|
+
start(): Promise<void>;
|
|
88
|
+
send(message: JSONRPCMessage): Promise<void>;
|
|
89
|
+
close(): Promise<void>;
|
|
90
|
+
/** One response to the request `id`, on its own turn (never inside the `send` that carried the request). */
|
|
91
|
+
private deliver;
|
|
92
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { ErrorCode, McpError, isJSONRPCErrorResponse, isJSONRPCNotification, isJSONRPCRequest, isJSONRPCResultResponse } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
import { inlineUntrusted } from "./untrusted-text.js";
|
|
3
|
+
export class McpHostSeatFailure extends Error {
|
|
4
|
+
delivered;
|
|
5
|
+
condition;
|
|
6
|
+
constructor(o) {
|
|
7
|
+
if (o.delivered !== "no" && o.delivered !== "unknown")
|
|
8
|
+
throw new TypeError(`McpHostSeatFailure: delivered must be "no" or "unknown"`);
|
|
9
|
+
if (typeof o.condition !== "string")
|
|
10
|
+
throw new TypeError("McpHostSeatFailure: condition must be a string");
|
|
11
|
+
super(o.condition);
|
|
12
|
+
this.name = "McpHostSeatFailure";
|
|
13
|
+
this.delivered = o.delivered;
|
|
14
|
+
this.condition = o.condition;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const VERDICTS = new WeakSet();
|
|
18
|
+
function verdict(delivered, condition) {
|
|
19
|
+
const minted = Object.freeze({ delivered, condition: inlineUntrusted(condition, 400) });
|
|
20
|
+
VERDICTS.add(minted);
|
|
21
|
+
return minted;
|
|
22
|
+
}
|
|
23
|
+
export function hostSeatVerdictOf(err) {
|
|
24
|
+
if (!(err instanceof McpError))
|
|
25
|
+
return undefined;
|
|
26
|
+
const data = err.data;
|
|
27
|
+
return typeof data === "object" && data !== null && VERDICTS.has(data) ? data : undefined;
|
|
28
|
+
}
|
|
29
|
+
function verdictOfThrown(thrown) {
|
|
30
|
+
try {
|
|
31
|
+
if (thrown instanceof McpHostSeatFailure) {
|
|
32
|
+
const { delivered, condition } = thrown;
|
|
33
|
+
if ((delivered === "no" || delivered === "unknown") && typeof condition === "string")
|
|
34
|
+
return verdict(delivered, condition);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
}
|
|
39
|
+
return verdict("unknown", "the host seat failed without saying whether it handed the request on");
|
|
40
|
+
}
|
|
41
|
+
function responseOf(id, raw) {
|
|
42
|
+
let answer;
|
|
43
|
+
try {
|
|
44
|
+
answer = JSON.parse(JSON.stringify(raw) ?? "null");
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
answer = undefined;
|
|
48
|
+
}
|
|
49
|
+
const member = (name) => (typeof answer === "object" && answer !== null && Object.hasOwn(answer, name) ? answer[name] : undefined);
|
|
50
|
+
const result = member("result");
|
|
51
|
+
const candidate = result !== undefined ? { jsonrpc: "2.0", id, result } : { jsonrpc: "2.0", id, error: member("error") };
|
|
52
|
+
if (isJSONRPCResultResponse(candidate) || isJSONRPCErrorResponse(candidate))
|
|
53
|
+
return candidate;
|
|
54
|
+
return verdict("unknown", "the host seat answered something the protocol cannot carry as a result or an error");
|
|
55
|
+
}
|
|
56
|
+
export function hostSeatLine(what, serverLabel, seat, writeTail) {
|
|
57
|
+
return seat.delivered === "no"
|
|
58
|
+
? `${what} was not sent to MCP server "${serverLabel}": ${seat.condition}. The host did not hand the request on, so the server did not execute it; sending it again is safe.`
|
|
59
|
+
: `${what} on MCP server "${serverLabel}" ended without an outcome the host could report: ${seat.condition}. The request may or may not have executed on the server — the outcome is unknown.${writeTail}`;
|
|
60
|
+
}
|
|
61
|
+
export function hostSeatMissing(server) {
|
|
62
|
+
return Object.assign(new Error(`MCP server "${inlineUntrusted(server, 120)}" is declared with a host-supplied transport, and this leg holds no host seat of that name (RunInternals.mcpHostSeats) — not dialed`), { code: "config.mcp_host_seat_missing" });
|
|
63
|
+
}
|
|
64
|
+
export class HostSeatTransport {
|
|
65
|
+
seat;
|
|
66
|
+
serverName;
|
|
67
|
+
onclose;
|
|
68
|
+
onerror;
|
|
69
|
+
onmessage;
|
|
70
|
+
inFlight = new Map();
|
|
71
|
+
closed = false;
|
|
72
|
+
constructor(seat, serverName) {
|
|
73
|
+
this.seat = seat;
|
|
74
|
+
this.serverName = serverName;
|
|
75
|
+
}
|
|
76
|
+
async start() { }
|
|
77
|
+
async send(message) {
|
|
78
|
+
if (isJSONRPCNotification(message)) {
|
|
79
|
+
if (message.method === "notifications/cancelled") {
|
|
80
|
+
const id = message.params?.requestId;
|
|
81
|
+
const held = typeof id === "string" || typeof id === "number" ? this.inFlight.get(id) : undefined;
|
|
82
|
+
if (held !== undefined) {
|
|
83
|
+
this.inFlight.delete(id);
|
|
84
|
+
held.abort(new Error("the engine cancelled the request"));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (!isJSONRPCRequest(message))
|
|
90
|
+
return;
|
|
91
|
+
const { id, method } = message;
|
|
92
|
+
const params = (message.params ?? {});
|
|
93
|
+
if (method === "initialize") {
|
|
94
|
+
const protocolVersion = params["protocolVersion"];
|
|
95
|
+
return this.deliver(id, { jsonrpc: "2.0", id, result: { protocolVersion, capabilities: { tools: {} }, serverInfo: { name: this.serverName, version: "" } } });
|
|
96
|
+
}
|
|
97
|
+
if (this.closed)
|
|
98
|
+
return this.deliver(id, verdict("no", "the host seat's connection to this leg is closed"));
|
|
99
|
+
if (method !== "tools/list" && method !== "tools/call")
|
|
100
|
+
return this.deliver(id, verdict("no", `the host seat carries tools/list and tools/call only, and ${inlineUntrusted(method, 80)} was not handed on`));
|
|
101
|
+
const stop = new AbortController();
|
|
102
|
+
this.inFlight.set(id, stop);
|
|
103
|
+
void (async () => {
|
|
104
|
+
let answered;
|
|
105
|
+
try {
|
|
106
|
+
answered = responseOf(id, await this.seat.request(method, params, stop.signal));
|
|
107
|
+
}
|
|
108
|
+
catch (thrown) {
|
|
109
|
+
answered = verdictOfThrown(thrown);
|
|
110
|
+
}
|
|
111
|
+
if (this.inFlight.get(id) !== stop)
|
|
112
|
+
return;
|
|
113
|
+
this.inFlight.delete(id);
|
|
114
|
+
this.deliver(id, answered);
|
|
115
|
+
})();
|
|
116
|
+
}
|
|
117
|
+
async close() {
|
|
118
|
+
if (this.closed)
|
|
119
|
+
return;
|
|
120
|
+
this.closed = true;
|
|
121
|
+
const held = [...this.inFlight.values()];
|
|
122
|
+
this.inFlight.clear();
|
|
123
|
+
for (const stop of held)
|
|
124
|
+
stop.abort(new Error("the connection to the host seat closed"));
|
|
125
|
+
this.onclose?.();
|
|
126
|
+
}
|
|
127
|
+
deliver(id, answered) {
|
|
128
|
+
const message = VERDICTS.has(answered) ? { jsonrpc: "2.0", id, error: { code: ErrorCode.InternalError, message: answered.condition, data: answered } } : answered;
|
|
129
|
+
queueMicrotask(() => this.onmessage?.(message));
|
|
130
|
+
}
|
|
131
|
+
}
|