@sema-agent/core 7.57.0 → 7.59.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 +1161 -0
- package/README.md +6 -4
- package/dist/agents/cc-peer-directory.js +8 -8
- package/dist/agents/child-model-seat.d.ts +4 -2
- package/dist/agents/child-model-seat.js +5 -3
- package/dist/agents/peer-directory.d.ts +9 -0
- package/dist/agents/peer-directory.js +6 -2
- package/dist/agents/send-message-tool.js +21 -12
- package/dist/agents/subagent-steps.js +2 -4
- package/dist/agents/subagent.js +33 -34
- package/dist/brain/anthropic.js +161 -45
- package/dist/brain/errors.d.ts +9 -3
- package/dist/brain/errors.js +7 -1
- package/dist/brain/failover.js +2 -1
- package/dist/brain/open-responses.js +3 -3
- package/dist/brain/openai.js +103 -53
- package/dist/brain/provider-dialect.d.ts +11 -0
- package/dist/brain/provider-dialect.js +5 -2
- package/dist/brain/reasoning-request.js +5 -4
- package/dist/brain/reasoning.d.ts +19 -0
- package/dist/brain/reasoning.js +17 -2
- package/dist/brain/request-route.d.ts +4 -1
- package/dist/brain/request-route.js +4 -1
- package/dist/brain/route-adjudicator.d.ts +84 -18
- package/dist/brain/route-adjudicator.js +89 -22
- package/dist/brain/route-conformance.js +1 -1
- package/dist/brain/stream-engine.js +84 -49
- package/dist/brain/stream-shared.d.ts +30 -0
- package/dist/brain/stream-shared.js +34 -1
- package/dist/brain/timeout.d.ts +62 -5
- package/dist/brain/timeout.js +93 -6
- package/dist/core/a2a.d.ts +2 -1
- package/dist/core/a2a.js +23 -10
- package/dist/core/account-row.d.ts +61 -0
- package/dist/core/account-row.js +51 -0
- package/dist/core/advisor-verdict.d.ts +2 -1
- package/dist/core/advisor-verdict.js +1 -1
- package/dist/core/allow-entry.d.ts +20 -7
- package/dist/core/allow-entry.js +18 -9
- package/dist/core/approval-object.d.ts +29 -15
- package/dist/core/approval-object.js +47 -19
- package/dist/core/ask-origin.d.ts +21 -2
- package/dist/core/ask-origin.js +5 -1
- package/dist/core/auto-compaction.d.ts +4 -0
- package/dist/core/auto-compaction.js +2 -2
- package/dist/core/auto-mode-directive.d.ts +29 -5
- package/dist/core/auto-mode-directive.js +38 -8
- package/dist/core/background-agent-store.d.ts +16 -3
- package/dist/core/checkpoint-requirements.d.ts +19 -1
- package/dist/core/checkpoint-requirements.js +5 -1
- package/dist/core/checkpoint-store.d.ts +85 -23
- package/dist/core/checkpoint-store.js +31 -9
- package/dist/core/child-clamp-seats.d.ts +29 -0
- package/dist/core/child-clamp-seats.js +56 -1
- package/dist/core/compliance.d.ts +2 -2
- package/dist/core/compliance.js +1 -1
- package/dist/core/effective-path-target.d.ts +8 -2
- package/dist/core/effective-path-target.js +8 -3
- package/dist/core/engine-notice.d.ts +99 -9
- package/dist/core/engine-notice.js +19 -5
- package/dist/core/fs-write-gate-policy.d.ts +4 -2
- package/dist/core/fs-write-gate-policy.js +7 -3
- package/dist/core/gate-fold.js +7 -4
- package/dist/core/gate-lanes.js +19 -6
- package/dist/core/gate-outcome.d.ts +32 -3
- package/dist/core/gate-outcome.js +19 -1
- package/dist/core/git-worktree-env.d.ts +53 -11
- package/dist/core/git-worktree-env.js +96 -12
- package/dist/core/governance-codes.d.ts +9 -1
- package/dist/core/governance-codes.js +13 -0
- package/dist/core/hooks.d.ts +35 -4
- package/dist/core/hooks.js +17 -11
- package/dist/core/human-input-projection.d.ts +1 -0
- package/dist/core/human-input-projection.js +3 -0
- package/dist/core/image-admission.d.ts +6 -5
- package/dist/core/image-admission.js +18 -14
- package/dist/core/locked-config.d.ts +20 -3
- package/dist/core/locked-config.js +40 -3
- package/dist/core/mailbox-store.d.ts +45 -1
- package/dist/core/mailbox-store.js +53 -9
- package/dist/core/mcp-call-meta.d.ts +66 -0
- package/dist/core/mcp-call-meta.js +103 -0
- package/dist/core/mcp-connection-pool.d.ts +3 -1
- package/dist/core/mcp-connection-pool.js +3 -1
- package/dist/core/mcp-failure.d.ts +117 -15
- package/dist/core/mcp-failure.js +71 -3
- package/dist/core/mcp-probe.d.ts +4 -0
- package/dist/core/mcp-probe.js +1 -1
- package/dist/core/mcp-server-link.d.ts +27 -3
- package/dist/core/mcp-server-link.js +25 -1
- package/dist/core/mcp-server-spec.d.ts +46 -18
- package/dist/core/mcp-server-spec.js +1 -18
- package/dist/core/mcp.d.ts +16 -20
- package/dist/core/mcp.js +112 -55
- package/dist/core/memory-engine/consolidation-driver.d.ts +2 -4
- package/dist/core/memory-engine/consolidation-driver.js +3 -3
- package/dist/core/memory-engine/consolidation.d.ts +4 -0
- package/dist/core/memory-engine/consolidation.js +1 -0
- package/dist/core/memory-engine/delegation-settlement.js +5 -12
- package/dist/core/memory-engine/distiller.js +2 -2
- package/dist/core/memory-engine/dual-root.d.ts +50 -1
- package/dist/core/memory-engine/dual-root.js +44 -1
- package/dist/core/memory-engine/engine.d.ts +67 -14
- package/dist/core/memory-engine/engine.js +384 -212
- package/dist/core/memory-engine/export-bundle.d.ts +23 -0
- package/dist/core/memory-engine/export-bundle.js +23 -4
- package/dist/core/memory-engine/file-backend.d.ts +128 -55
- package/dist/core/memory-engine/file-backend.js +290 -117
- package/dist/core/memory-engine/index.d.ts +1 -1
- package/dist/core/memory-engine/layout.d.ts +59 -11
- package/dist/core/memory-engine/layout.js +190 -40
- package/dist/core/memory-engine/memory-backend-contract.d.ts +1 -1
- package/dist/core/memory-engine/memory-backend-contract.js +39 -2
- package/dist/core/memory-engine/scope-contract.d.ts +45 -4
- package/dist/core/memory-engine/scope-contract.js +80 -11
- package/dist/core/memory-engine/sync-client.d.ts +9 -1
- package/dist/core/memory-engine/sync-client.js +31 -8
- package/dist/core/memory-engine/sync.d.ts +5 -0
- package/dist/core/memory-engine/types.d.ts +6 -0
- package/dist/core/mode-policy.d.ts +8 -5
- package/dist/core/mode-policy.js +5 -4
- package/dist/core/mods/classic-events.d.ts +5 -1
- package/dist/core/mods/host.js +1 -1
- package/dist/core/mods/kernel/dispatch.d.ts +3 -0
- package/dist/core/mods/kernel/dispatch.js +12 -9
- package/dist/core/mods/kernel/events.d.ts +6 -1
- package/dist/core/mods/kernel/events.js +2 -2
- package/dist/core/mods/kernel/registration.d.ts +9 -1
- package/dist/core/mods/kernel/registration.js +3 -0
- package/dist/core/mods/kernel/site-rules.d.ts +3 -0
- package/dist/core/mods/kernel/site-rules.js +10 -0
- package/dist/core/mods/package.d.ts +23 -0
- package/dist/core/mods/package.js +118 -0
- package/dist/core/mods/stations.d.ts +33 -12
- package/dist/core/mods/stations.js +45 -11
- package/dist/core/mods/tool-call.d.ts +5 -1
- package/dist/core/mods/tool-call.js +13 -4
- package/dist/core/parent-spec-seat.d.ts +8 -3
- package/dist/core/parent-spec-seat.js +2 -0
- package/dist/core/park-selfcheck.js +6 -0
- package/dist/core/path-guard-rows.d.ts +20 -0
- package/dist/core/path-guard-rows.js +11 -0
- package/dist/core/peer-seat.d.ts +248 -0
- package/dist/core/peer-seat.js +439 -0
- package/dist/core/permission-rule-consent.js +10 -4
- package/dist/core/permission-rule-model.d.ts +16 -0
- package/dist/core/permission-rule-model.js +1 -1
- package/dist/core/present-plan-tool.d.ts +20 -3
- package/dist/core/present-plan-tool.js +48 -4
- package/dist/core/protocol-http-auth.d.ts +40 -29
- package/dist/core/protocol-http-auth.js +30 -32
- package/dist/core/redaction-marks.d.ts +16 -0
- package/dist/core/redaction-marks.js +16 -0
- package/dist/core/redaction-passes.js +8 -9
- package/dist/core/resume-startup-cause.js +1 -0
- package/dist/core/retention.d.ts +41 -15
- package/dist/core/retention.js +59 -12
- package/dist/core/rewrite-rejudge.d.ts +38 -0
- package/dist/core/rewrite-rejudge.js +42 -2
- package/dist/core/roles.d.ts +34 -2
- package/dist/core/roles.js +43 -4
- package/dist/core/run-origin.d.ts +40 -0
- package/dist/core/run-origin.js +37 -0
- package/dist/core/runner/advertised-writable-dirs.d.ts +57 -38
- package/dist/core/runner/advertised-writable-dirs.js +126 -0
- package/dist/core/runner/announce-once-ledger.d.ts +5 -4
- package/dist/core/runner/announce-once-ledger.js +4 -2
- package/dist/core/runner/call-hook-stations.js +2 -2
- package/dist/core/runner/compaction-restate.d.ts +15 -6
- package/dist/core/runner/compaction-restate.js +28 -2
- package/dist/core/runner/contracts.d.ts +33 -21
- package/dist/core/runner/credential-origin-seat.js +4 -3
- package/dist/core/runner/cwd-alignment-probe.d.ts +20 -0
- package/dist/core/runner/cwd-alignment-probe.js +21 -0
- package/dist/core/runner/decide-continuation.d.ts +2 -2
- package/dist/core/runner/gate-exit.d.ts +30 -8
- package/dist/core/runner/gate-exit.js +15 -8
- package/dist/core/runner/image-removed-seat.d.ts +12 -0
- package/dist/core/runner/image-removed-seat.js +19 -0
- package/dist/core/runner/inline-image.js +1 -1
- package/dist/core/runner/memory-consolidation-driver.js +3 -3
- package/dist/core/runner/park-commit.d.ts +1 -1
- package/dist/core/runner/park-commit.js +3 -0
- package/dist/core/runner/prepare-ask-lane.d.ts +1 -1
- package/dist/core/runner/prepare-ask-lane.js +2 -1
- package/dist/core/runner/prepare-boundary-parks.js +2 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +5 -5
- package/dist/core/runner/prepare-caps-and-workflow.js +3 -1
- package/dist/core/runner/prepare-config-doors.d.ts +8 -5
- package/dist/core/runner/prepare-config-doors.js +14 -10
- package/dist/core/runner/prepare-context-lane.js +2 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +8 -0
- package/dist/core/runner/prepare-delegation-surface.js +16 -18
- package/dist/core/runner/prepare-gate-stations.js +1 -1
- package/dist/core/runner/prepare-hands-readface.d.ts +11 -3
- package/dist/core/runner/prepare-hands-readface.js +9 -1
- package/dist/core/runner/prepare-inherited-gate.d.ts +1 -3
- package/dist/core/runner/prepare-inherited-gate.js +14 -27
- package/dist/core/runner/prepare-memory.d.ts +3 -0
- package/dist/core/runner/prepare-memory.js +26 -37
- package/dist/core/runner/prepare-park-ask.d.ts +1 -1
- package/dist/core/runner/prepare-park-ask.js +2 -1
- package/dist/core/runner/prepare-policy-chain.d.ts +7 -7
- package/dist/core/runner/prepare-policy-chain.js +18 -15
- package/dist/core/runner/prepare-project-context.d.ts +2 -2
- package/dist/core/runner/prepare-project-context.js +2 -2
- package/dist/core/runner/prepare-prompt-inputs.d.ts +1 -1
- package/dist/core/runner/prepare-prompt-inputs.js +8 -19
- package/dist/core/runner/prepare-protocol-tools.d.ts +4 -2
- package/dist/core/runner/prepare-protocol-tools.js +11 -3
- package/dist/core/runner/prepare-run-refs.d.ts +2 -3
- package/dist/core/runner/prepare-run-refs.js +4 -1
- package/dist/core/runner/prepare-suspend-saga.d.ts +2 -0
- package/dist/core/runner/prepare-suspend-saga.js +2 -1
- package/dist/core/runner/prepare-task.js +28 -13
- package/dist/core/runner/prepare-wiring-manifest.d.ts +2 -1
- package/dist/core/runner/prepare-wiring-manifest.js +4 -3
- package/dist/core/runner/prepare-workspace-restore.d.ts +3 -0
- package/dist/core/runner/prepare-workspace-restore.js +4 -4
- package/dist/core/runner/reply-pricing.d.ts +30 -0
- package/dist/core/runner/reply-pricing.js +19 -0
- package/dist/core/runner/resume-admission.js +5 -3
- package/dist/core/runner/resume-apply.js +6 -1
- package/dist/core/runner/resume-checkpoint-screen.js +2 -0
- package/dist/core/runner/resume-policy-outcome.js +5 -5
- package/dist/core/runner/role-seat-defaulted.d.ts +44 -0
- package/dist/core/runner/role-seat-defaulted.js +40 -0
- package/dist/core/runner/run-brain-sinks.js +2 -0
- package/dist/core/runner/run-harness-handlers.d.ts +3 -4
- package/dist/core/runner/run-harness-handlers.js +1 -8
- package/dist/core/runner/run-identity-wiring.d.ts +2 -5
- package/dist/core/runner/run-identity-wiring.js +6 -4
- package/dist/core/runner/run-leg.d.ts +2 -0
- package/dist/core/runner/run-leg.js +42 -29
- package/dist/core/runner/run-notification-lane.js +3 -0
- package/dist/core/runner/run-stop-and-final-verify.js +2 -2
- package/dist/core/runner/run-terminal-adoption.d.ts +2 -5
- package/dist/core/runner/run-terminal-adoption.js +9 -3
- package/dist/core/runner/run-turn-boundary.js +77 -70
- package/dist/core/runner/runtask.d.ts +1 -1
- package/dist/core/runner/runtask.js +2 -2
- package/dist/core/runner/side-call-account.d.ts +1 -1
- package/dist/core/runner/side-call-account.js +3 -18
- package/dist/core/runner/sub-agent-deny-lists.d.ts +24 -0
- package/dist/core/runner/sub-agent-deny-lists.js +10 -0
- package/dist/core/runner/terminal-account.js +3 -3
- package/dist/core/runner/tool-end-body.js +2 -1
- package/dist/core/runner/tool-occurrence.d.ts +5 -2
- package/dist/core/runner/tool-occurrence.js +4 -3
- package/dist/core/runner/turn-attachments.d.ts +26 -22
- package/dist/core/runner/turn-attachments.js +24 -26
- package/dist/core/runner/write-protection-station.d.ts +8 -2
- package/dist/core/runner/write-protection-station.js +2 -0
- package/dist/core/runner-deps.d.ts +3 -3
- package/dist/core/secret-env.d.ts +32 -2
- package/dist/core/secret-env.js +65 -3
- package/dist/core/sensitive-path-policy.js +9 -10
- package/dist/core/session-log-transfer.d.ts +24 -0
- package/dist/core/session-log-transfer.js +166 -0
- package/dist/core/session-policy-store.d.ts +3 -1
- package/dist/core/session-policy-store.js +13 -9
- package/dist/core/session-store.d.ts +86 -24
- package/dist/core/session-store.js +162 -24
- package/dist/core/session.d.ts +92 -1
- package/dist/core/shell-read-silence.js +1 -0
- package/dist/core/side-query.d.ts +11 -1
- package/dist/core/side-query.js +9 -0
- package/dist/core/skill-grant-binding.d.ts +31 -2
- package/dist/core/skill-grant-binding.js +31 -1
- package/dist/core/skill-grant.d.ts +8 -5
- package/dist/core/skill-grant.js +6 -6
- package/dist/core/steer-replay.d.ts +4 -2
- package/dist/core/steer-replay.js +2 -1
- package/dist/core/store-contracts/background-agent-store-contract.js +27 -0
- package/dist/core/store-contracts/checkpoint-store-contract.js +20 -2
- package/dist/core/store-contracts/mailbox-store-contract.js +31 -1
- package/dist/core/store-contracts/session-repo-contract.js +112 -5
- package/dist/core/store-contracts/session-store-contract.d.ts +4 -1
- package/dist/core/store-contracts/session-store-contract.js +236 -2
- package/dist/core/synthetic-read-verdict.js +2 -1
- package/dist/core/task-event.d.ts +92 -8
- package/dist/core/task-notification.js +16 -10
- package/dist/core/task-registry-agent.js +1 -0
- package/dist/core/task-registry-shared.d.ts +7 -1
- package/dist/core/task-spec.d.ts +49 -1
- package/dist/core/task-stream.d.ts +2 -1
- package/dist/core/terminal-cause.d.ts +11 -1
- package/dist/core/tool-catalog-entries.js +1 -0
- package/dist/core/tool-check-reading.d.ts +1 -0
- package/dist/core/tool-check-reading.js +3 -3
- package/dist/core/tool-policy.d.ts +16 -0
- package/dist/core/tool-result-store.d.ts +17 -10
- package/dist/core/tool-result-store.js +3 -1
- package/dist/core/tool-roster.d.ts +112 -5
- package/dist/core/tool-roster.js +42 -1
- package/dist/core/tool-spec.d.ts +3 -1
- package/dist/core/types.d.ts +3 -3
- package/dist/core/types.js +1 -1
- package/dist/core/untrusted-egress.d.ts +0 -2
- package/dist/core/untrusted-egress.js +10 -14
- package/dist/core/user-attachment.js +1 -1
- package/dist/core/wiring-manifest.d.ts +18 -6
- package/dist/core/wiring-manifest.js +4 -3
- package/dist/core/workspace-snapshot.d.ts +44 -0
- package/dist/core/workspace-snapshot.js +34 -0
- package/dist/core/write-protect.d.ts +43 -3
- package/dist/core/write-protect.js +43 -16
- package/dist/engine/compaction/compaction.js +29 -3
- package/dist/engine/execution-env/node-execution-env.d.ts +4 -3
- package/dist/engine/execution-env/node-execution-env.js +24 -23
- package/dist/engine/execution-env/symlink-chain.d.ts +7 -5
- package/dist/engine/harness/agent-harness.d.ts +30 -2
- package/dist/engine/harness/agent-harness.js +43 -12
- package/dist/engine/harness/messages.d.ts +3 -1
- package/dist/engine/harness/messages.js +3 -2
- package/dist/engine/harness/types.d.ts +56 -7
- package/dist/engine/harness/types.js +5 -1
- package/dist/engine/llm/rejected-images.d.ts +46 -0
- package/dist/engine/llm/rejected-images.js +54 -0
- package/dist/engine/llm/tool-turns.d.ts +2 -1
- package/dist/engine/llm/types.d.ts +30 -10
- package/dist/engine/llm/types.js +1 -1
- package/dist/engine/loop/agent-loop.d.ts +8 -0
- package/dist/engine/loop/agent-loop.js +52 -15
- package/dist/engine/loop/types.d.ts +3 -1
- package/dist/engine/session/import-validate.js +3 -0
- package/dist/engine/session/memory-repo.d.ts +17 -9
- package/dist/engine/session/memory-repo.js +44 -34
- package/dist/engine/session/path-to-root.d.ts +38 -0
- package/dist/engine/session/path-to-root.js +39 -0
- package/dist/engine/session/repo-utils.d.ts +22 -4
- package/dist/engine/session/repo-utils.js +49 -1
- package/dist/engine/session/storage-base.d.ts +10 -1
- package/dist/engine/session/storage-base.js +11 -22
- package/dist/index.d.ts +29 -16
- package/dist/index.js +21 -11
- package/dist/internal/harness-types.d.ts +2 -2
- package/dist/internal/harness.d.ts +3 -2
- package/dist/internal/harness.js +2 -2
- package/dist/internal/llm.d.ts +1 -0
- package/dist/orchestration/workflow-observe.d.ts +17 -1
- package/dist/orchestration/workflow-observe.js +20 -0
- package/dist/orchestration/workflow-types.d.ts +32 -7
- package/dist/orchestration/workflow.js +739 -489
- package/dist/shell/counting-pass.d.ts +50 -0
- package/dist/shell/counting-pass.js +502 -0
- package/dist/shell/lex.d.ts +4 -2
- package/dist/shell/lex.js +93 -34
- package/dist/shell/shell-words.d.ts +1 -1
- package/dist/shell/shell-words.js +7 -6
- package/dist/stores/file/index.d.ts +4 -1
- package/dist/stores/file/index.js +4 -1
- package/dist/stores/file/mailbox-store.js +6 -10
- package/dist/stores/file/session-store.d.ts +15 -8
- package/dist/stores/file/session-store.js +28 -13
- package/dist/tools/fs/fs-bash.d.ts +6 -0
- package/dist/tools/fs/fs-bash.js +6 -3
- package/dist/tools/fs/fs-write.d.ts +6 -3
- package/dist/tools/fs/fs-write.js +8 -7
- package/dist/tools/fs/index.d.ts +3 -0
- package/dist/tools/fs/index.js +7 -3
- package/dist/tools/fs/program-read-model.d.ts +13 -0
- package/dist/tools/fs/program-read-model.js +15 -0
- package/dist/tools/fs/program-read-model.rows.js +1 -1
- package/dist/tools/fs/read-deny.d.ts +13 -10
- package/dist/tools/fs/read-deny.js +25 -5
- package/dist/tools/fs/read-floor.d.ts +19 -0
- package/dist/tools/fs/read-floor.js +23 -0
- package/dist/tools/fs/safety.js +40 -8
- package/dist/tools/fs/search.js +6 -24
- package/dist/tools/fs/shell-read-check.d.ts +9 -2
- package/dist/tools/fs/shell-read-check.js +61 -16
- package/dist/tools/fs/shell-read-establish.js +2 -1
- package/dist/tools/fs/shell-read-identity.js +1 -1
- package/dist/tools/fs/shell-read-judge.d.ts +26 -9
- package/dist/tools/fs/shell-read-judge.js +10 -6
- package/dist/tools/fs/shell-read-plan.d.ts +6 -1
- package/dist/tools/fs/shell-read-plan.js +22 -15
- package/dist/tools/fs/shell-read-start.js +1 -0
- package/dist/tools/fs/shell-reentry-text.d.ts +15 -1
- package/dist/tools/fs/shell-reentry-text.js +25 -3
- package/dist/tools/monitor.d.ts +4 -0
- package/dist/tools/monitor.js +2 -0
- package/dist/tools/worktree.d.ts +42 -15
- package/dist/tools/worktree.js +60 -32
- package/package.json +5 -2
- package/test/export-surface.snapshot.json +149 -1
- package/wire-changes/core-stores-sql@7.58.0.json +29 -0
- package/wire-changes/core-stores-sql@7.59.0.json +29 -0
- package/wire-changes/core@7.58.0.json +2188 -0
- package/wire-changes/core@7.59.0.json +2459 -0
- package/wire-changes/mods-kernel@7.58.0.json +81 -0
- package/wire-changes/mods-kernel@7.59.0.json +29 -0
- package/wire-changes/primitives@7.58.0.json +29 -0
- package/wire-changes/primitives@7.59.0.json +29 -0
- package/dist/primitives/credential-ref.d.ts +0 -89
- package/dist/primitives/credential-ref.js +0 -125
- package/dist/primitives/index.d.ts +0 -2
- package/dist/primitives/index.js +0 -1
|
@@ -93,6 +93,36 @@ export interface TurnCapFacts {
|
|
|
93
93
|
outputTokens: number | undefined;
|
|
94
94
|
capTokens: number | undefined;
|
|
95
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* The door's reading of a stream frame's members, one reading for every lane's frame decoder: a member the
|
|
98
|
+
* lane reads is taken only in the shape the wire defines — an object (non-null, non-array), an array, a string (`word`),
|
|
99
|
+
* a count. `null` and absent state nothing (`undefined`, not recorded). Any other value is a member in no shape: it reads
|
|
100
|
+
* as `undefined` — never coerced, never dereferenced — and the reader records it (`outOfShape`), so the lane says the loss
|
|
101
|
+
* where that member's loss is already said. A lane keeps one reader per outlet (the frame, the call stream, the usage), so
|
|
102
|
+
* one outlet's record never speaks for another's.
|
|
103
|
+
*/
|
|
104
|
+
export interface MemberReader {
|
|
105
|
+
object(v: unknown): Record<string, unknown> | undefined;
|
|
106
|
+
array(v: unknown): readonly unknown[] | undefined;
|
|
107
|
+
word(v: unknown): string | undefined;
|
|
108
|
+
count(v: unknown): number | undefined;
|
|
109
|
+
/** Did a member this reader read hold a value in no shape? */
|
|
110
|
+
readonly outOfShape: boolean;
|
|
111
|
+
}
|
|
112
|
+
export declare function memberReader(): MemberReader;
|
|
113
|
+
/** The word a seat reads when something arrived there in no word shape — the echo seat's placeholder: an ending in no
|
|
114
|
+
* word, a late frame the door could not read. */
|
|
115
|
+
export declare const NO_WORD = "?";
|
|
116
|
+
/** The stream's ending seat as both wires read it (`finish_reason`, `stop_reason`), before AND after the end, by one rule:
|
|
117
|
+
* a falsy value states no ending (as it always read); a string is the provider's word; any other value (a number, `true`,
|
|
118
|
+
* an object) is an ending in no word the engine reads — {@link NO_WORD}. */
|
|
119
|
+
export declare function endingWordOf(raw: unknown): string | null;
|
|
120
|
+
/** Did the ending seat hold a non-word ({@link endingWordOf}'s third answer) — not a provider that spelled `?`? */
|
|
121
|
+
export declare function endingInNoWord(raw: unknown): boolean;
|
|
122
|
+
/** The one sentence a turn's dropped frames are stated in (the `bad_frame` note), for the three lanes: `data:` frames that
|
|
123
|
+
* were not valid JSON, or that held members in no shape the stream defines ({@link MemberReader}) — counted together, the
|
|
124
|
+
* first one's bytes as the sample. */
|
|
125
|
+
export declare function droppedFramesNote(count: number, sample: string | undefined): string;
|
|
96
126
|
/**
|
|
97
127
|
* The structured account of a turn that FAILED for its dropped tool calls (`AssistantMessage.modelOutputInvalid`) —
|
|
98
128
|
* the lane calls it on the arm whose message is the dropped-calls sentence. `cause` is `truncated` when any call's
|
|
@@ -48,7 +48,40 @@ export function truncationCauseClause(facts) {
|
|
|
48
48
|
}
|
|
49
49
|
return terminalFrameSeen ? "" : "; the stream ended before its stop frame — the connection closed mid-response";
|
|
50
50
|
}
|
|
51
|
-
const
|
|
51
|
+
const isCount = (v) => typeof v === "number" && Number.isInteger(v) && v >= 0;
|
|
52
|
+
const countOf = (v) => (isCount(v) ? v : undefined);
|
|
53
|
+
export function memberReader() {
|
|
54
|
+
let outOfShape = false;
|
|
55
|
+
const take = (v, inShape) => {
|
|
56
|
+
if (v === null || v === undefined)
|
|
57
|
+
return undefined;
|
|
58
|
+
if (inShape(v))
|
|
59
|
+
return v;
|
|
60
|
+
outOfShape = true;
|
|
61
|
+
return undefined;
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
object: (v) => take(v, (x) => typeof x === "object" && !Array.isArray(x)),
|
|
65
|
+
array: (v) => take(v, Array.isArray),
|
|
66
|
+
word: (v) => take(v, (x) => typeof x === "string"),
|
|
67
|
+
count: (v) => take(v, isCount),
|
|
68
|
+
get outOfShape() {
|
|
69
|
+
return outOfShape;
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export const NO_WORD = "?";
|
|
74
|
+
export function endingWordOf(raw) {
|
|
75
|
+
if (!raw)
|
|
76
|
+
return null;
|
|
77
|
+
return typeof raw === "string" ? raw : NO_WORD;
|
|
78
|
+
}
|
|
79
|
+
export function endingInNoWord(raw) {
|
|
80
|
+
return endingWordOf(raw) === NO_WORD && raw !== NO_WORD;
|
|
81
|
+
}
|
|
82
|
+
export function droppedFramesNote(count, sample) {
|
|
83
|
+
return `\n[note: ${count} provider stream frame(s) were not valid JSON or not in the stream's frame shape; what could not be read was dropped — the streamed output may be missing content (first sample: ${JSON.stringify(sample)})]`;
|
|
84
|
+
}
|
|
52
85
|
export function modelOutputInvalidOf(drops, cap) {
|
|
53
86
|
if (drops.truncated > 0) {
|
|
54
87
|
const outputTokens = countOf(cap.outputTokens);
|
package/dist/brain/timeout.d.ts
CHANGED
|
@@ -47,7 +47,8 @@ export declare function resolveStallTimeoutMs(value: number | undefined, knob: s
|
|
|
47
47
|
* prefill BEFORE writing headers is silent here for minutes and healthy; the 30s "connect" clock
|
|
48
48
|
* this replaces cut that prefill and re-sent the same body ten times. 300s is the reference
|
|
49
49
|
* implementation's window for a non-first-party route; the window grows with the request body
|
|
50
|
-
* ({@link firstByteWindow}) and the one retry is widened
|
|
50
|
+
* up to {@link FIRST_BYTE_WINDOW_CAP_MS} ({@link firstByteWindow}) and the one retry is widened
|
|
51
|
+
* ({@link FIRST_BYTE_RETRY_WINDOW_FACTOR}).
|
|
51
52
|
* - first-token 600s: bounds the headers→first-delta wait, NOT the model's thought (the first
|
|
52
53
|
* THINKING delta already counts as the first token, design/17 O5), so a slow reasoner is safe. A
|
|
53
54
|
* minutes-scale bound is FALSE for a self-hosted server working through a long prefill AFTER
|
|
@@ -86,8 +87,17 @@ export declare const RETIRED_TIMEOUT_KNOBS: {
|
|
|
86
87
|
export declare function refuseRetiredTimeoutKnobs(holder: object | undefined, level: keyof typeof RETIRED_TIMEOUT_KNOBS, where: string): void;
|
|
87
88
|
/** The first-byte window grows with the request body: one second per this many bytes, rounded up (the
|
|
88
89
|
* reference implementation's allowance) — a large context on a slow uplink is still UPLOADING when a
|
|
89
|
-
* fixed window would call the gateway silent. */
|
|
90
|
+
* fixed window would call the gateway silent. The growth stops at {@link FIRST_BYTE_WINDOW_CAP_MS}. */
|
|
90
91
|
export declare const FIRST_BYTE_UPLOAD_BYTES_PER_SECOND = 32768;
|
|
92
|
+
/**
|
|
93
|
+
* The most the upload allowance may grow a first-byte window to: 599 s, the reference implementation's
|
|
94
|
+
* default (its request timeout, 600 s, less one second). Without it the window grew with the body without
|
|
95
|
+
* bound — a 40 MB request (a context full of screenshots) armed 300 s + 1 280 s, so a gateway that never
|
|
96
|
+
* answered was given up on after ~26 minutes. The cap bounds the ALLOWANCE only: a knob (or its widened
|
|
97
|
+
* retry) already at or above it is the window as set and gains no allowance — a deployment that chose a
|
|
98
|
+
* longer wait is never shortened behind its back.
|
|
99
|
+
*/
|
|
100
|
+
export declare const FIRST_BYTE_WINDOW_CAP_MS = 599000;
|
|
91
101
|
/** A first-byte stall is re-sent at most this many times by default ({@link BrainTimeoutConfig.firstByteRetries}),
|
|
92
102
|
* out of its OWN budget rather than `maxRetries` (the reference implementation: "normally one retry, not the
|
|
93
103
|
* session budget"); the shared ladder counts transport failures, and this is not one. */
|
|
@@ -106,7 +116,9 @@ export declare function resolveWatchdogMs(configured: number | undefined, adviso
|
|
|
106
116
|
export interface FirstByteWindow {
|
|
107
117
|
/** The knob's value for THIS attempt (the configured value, widened on the retry). */
|
|
108
118
|
knobMs: number;
|
|
109
|
-
/** The upload allowance
|
|
119
|
+
/** The upload allowance granted for the request body, ms: one second per
|
|
120
|
+
* {@link FIRST_BYTE_UPLOAD_BYTES_PER_SECOND} bytes, granted up to {@link FIRST_BYTE_WINDOW_CAP_MS} and no
|
|
121
|
+
* further (0 for an empty body, and for a knob already at the cap). */
|
|
110
122
|
allowanceMs: number;
|
|
111
123
|
/** What is actually armed: `knobMs + allowanceMs`, capped at {@link MAX_TIMER_DELAY_MS}. `0` = off. */
|
|
112
124
|
windowMs: number;
|
|
@@ -127,8 +139,9 @@ export interface BrainTimeoutConfig {
|
|
|
127
139
|
/**
|
|
128
140
|
* `fetch()` call → response headers, ms: the window a gateway has to START answering (until 7.33.0 a
|
|
129
141
|
* knob named `connectTimeoutMs` bounded this wait; it is gone — the connect clock is the transport's). Absent ⇒
|
|
130
|
-
* {@link STALL_FIRST_BYTE_MS}; the armed window grows with the request body
|
|
131
|
-
*
|
|
142
|
+
* {@link STALL_FIRST_BYTE_MS}; the armed window grows with the request body up to
|
|
143
|
+
* {@link FIRST_BYTE_WINDOW_CAP_MS} ({@link firstByteWindow}); a value at or above that cap is the window
|
|
144
|
+
* as set. A stall earns ONE retry at a widened window ({@link firstByteRetries}), then fails naming this knob.
|
|
132
145
|
* Fires as a `stall` (this process cancelled its own request), never as a transport fault. `0` ⇒ off.
|
|
133
146
|
*/
|
|
134
147
|
firstByteTimeoutMs?: number;
|
|
@@ -157,16 +170,60 @@ export interface BrainTimeoutConfig {
|
|
|
157
170
|
*/
|
|
158
171
|
idleTimeoutMs?: number;
|
|
159
172
|
}
|
|
173
|
+
/** How often the wall clock is read while a wait is judged for a host suspend (the reference
|
|
174
|
+
* implementation's sampling period). */
|
|
175
|
+
export declare const SUSPEND_SAMPLE_MS = 1000;
|
|
176
|
+
/** A gap between two samples longer than this is time this process did not run — the host slept, or the
|
|
177
|
+
* process was stopped — and is counted as slept, whole (the reference implementation's threshold). A
|
|
178
|
+
* shorter gap is a busy event loop, not a suspend. */
|
|
179
|
+
export declare const SUSPEND_GAP_MS = 5000;
|
|
180
|
+
/**
|
|
181
|
+
* The ONE host-suspend judgment every model-call wait reads — the response headers, the first token, the
|
|
182
|
+
* silence between deltas. A host that sleeps (a laptop lid closed over lunch) stops every timer; on waking,
|
|
183
|
+
* the connection the wait was on is usually gone, and a timer clock that did not count the sleep would
|
|
184
|
+
* leave the wait to run out its whole window on it. So while a wait is armed the wall clock is read every
|
|
185
|
+
* {@link SUSPEND_SAMPLE_MS}: the sampler is SCHEDULED on the timer clock, so a gap between two readings
|
|
186
|
+
* longer than {@link SUSPEND_GAP_MS} is time the timers did not run, and it is counted as slept. The armed
|
|
187
|
+
* wait ends — `onSuspend(sleptMs)`, once — at the first sample where the sleep it has seen exceeds half its
|
|
188
|
+
* window; a deadline calls {@link SuspendWatch.check} before it judges, so a deadline that runs before the
|
|
189
|
+
* next sample names the same suspend.
|
|
190
|
+
*
|
|
191
|
+
* The wall clock alone, not a monotonic reading beside it: a monotonic clock that counts sleep (the host's
|
|
192
|
+
* choice, not the engine's) cannot see a suspend at all, while a gap between samples scheduled on the timer
|
|
193
|
+
* clock is visible whichever way the host counts. A forward step of the wall clock reads as a suspend and
|
|
194
|
+
* costs one reconnect; a backward step is not counted.
|
|
195
|
+
*/
|
|
196
|
+
export interface SuspendWatch {
|
|
197
|
+
/** Judge a new wait of `windowMs` from now — the sleep seen before this call is not its sleep. Replaces any
|
|
198
|
+
* armed wait; `0` (a watchdog that is off) judges nothing. */
|
|
199
|
+
arm(windowMs: number, onSuspend: (sleptMs: number) => void): void;
|
|
200
|
+
/** The armed wait ended (headers, the first token, the attempt). */
|
|
201
|
+
disarm(): void;
|
|
202
|
+
/** Read the clock now: `true` when this reading ended the armed wait as a suspend (its `onSuspend` ran). */
|
|
203
|
+
check(): boolean;
|
|
204
|
+
/** Stop for good (the attempt is over). */
|
|
205
|
+
dispose(): void;
|
|
206
|
+
}
|
|
207
|
+
export declare function watchSuspend(): SuspendWatch;
|
|
160
208
|
/**
|
|
161
209
|
* A per-attempt abort controller that fires at the first-byte deadline while still forwarding an
|
|
162
210
|
* outer (task) abort. The returned `signal` governs the **whole** request including the streamed body
|
|
163
211
|
* — so once headers arrive, call `clearTimer()` (NOT `dispose()`) to stop the deadline while keeping
|
|
164
212
|
* the outer-abort link alive for the body read; call `dispose()` only when the request is fully done
|
|
165
213
|
* or being discarded.
|
|
214
|
+
*
|
|
215
|
+
* The header wait is also judged for a host suspend ({@link SuspendWatch}, armed with the same window):
|
|
216
|
+
* a suspend aborts the signal like the deadline does, and is told apart by {@link suspendedMs} rather than
|
|
217
|
+
* {@link timedOut}. The same watch is handed on (`suspend`) for the waits after the headers; `dispose()`
|
|
218
|
+
* ends it.
|
|
166
219
|
*/
|
|
167
220
|
export declare function createAttemptController(firstByteWindowMs: number | undefined, outerSignal: AbortSignal | undefined): {
|
|
168
221
|
signal: AbortSignal;
|
|
169
222
|
timedOut: () => boolean;
|
|
223
|
+
/** How long the host was suspended across the header wait, when that is what ended it; else undefined. */
|
|
224
|
+
suspendedMs: () => number | undefined;
|
|
225
|
+
/** The attempt's suspend judgment, for the waits after the headers (first token, idle). */
|
|
226
|
+
suspend: SuspendWatch;
|
|
170
227
|
clearTimer: () => void;
|
|
171
228
|
/** Abort this attempt's signal. The signal handed to `doFetch` is how an injected fetch wrapper
|
|
172
229
|
* learns it may release its transport, so an attempt being ABANDONED (its error body cut short by
|
package/dist/brain/timeout.js
CHANGED
|
@@ -34,6 +34,7 @@ export function refuseRetiredTimeoutKnobs(holder, level, where) {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
export const FIRST_BYTE_UPLOAD_BYTES_PER_SECOND = 32_768;
|
|
37
|
+
export const FIRST_BYTE_WINDOW_CAP_MS = 599_000;
|
|
37
38
|
export const FIRST_BYTE_RETRY_BUDGET = 1;
|
|
38
39
|
export function resolveFirstByteRetries(value) {
|
|
39
40
|
if (value === undefined)
|
|
@@ -53,7 +54,8 @@ export function firstByteWindow(knobMs, bodyBytes, retryIndex) {
|
|
|
53
54
|
if (knobMs === undefined || knobMs <= 0)
|
|
54
55
|
return { knobMs: 0, allowanceMs: 0, windowMs: 0 };
|
|
55
56
|
const widened = knobMs * FIRST_BYTE_RETRY_WINDOW_FACTOR ** Math.max(0, retryIndex);
|
|
56
|
-
const
|
|
57
|
+
const uploadMs = Math.ceil(Math.max(0, bodyBytes) / FIRST_BYTE_UPLOAD_BYTES_PER_SECOND) * 1000;
|
|
58
|
+
const allowanceMs = Math.min(uploadMs, Math.max(0, FIRST_BYTE_WINDOW_CAP_MS - widened));
|
|
57
59
|
return { knobMs: widened, allowanceMs, windowMs: Math.min(widened + allowanceMs, MAX_TIMER_DELAY_MS) };
|
|
58
60
|
}
|
|
59
61
|
export function firstByteLaneKnobMs(knobMs) {
|
|
@@ -62,6 +64,76 @@ export function firstByteLaneKnobMs(knobMs) {
|
|
|
62
64
|
total += firstByteWindow(knobMs, 0, retryIndex).knobMs;
|
|
63
65
|
return total;
|
|
64
66
|
}
|
|
67
|
+
export const SUSPEND_SAMPLE_MS = 1_000;
|
|
68
|
+
export const SUSPEND_GAP_MS = 5_000;
|
|
69
|
+
export function watchSuspend() {
|
|
70
|
+
let readAt = 0;
|
|
71
|
+
let sleptMs = 0;
|
|
72
|
+
let wait;
|
|
73
|
+
let timer;
|
|
74
|
+
let disposed = false;
|
|
75
|
+
const read = () => {
|
|
76
|
+
const now = Date.now();
|
|
77
|
+
const gap = now - readAt;
|
|
78
|
+
readAt = now;
|
|
79
|
+
if (gap > SUSPEND_GAP_MS)
|
|
80
|
+
sleptMs += gap;
|
|
81
|
+
};
|
|
82
|
+
const stopSampling = () => {
|
|
83
|
+
if (timer !== undefined)
|
|
84
|
+
clearTimeout(timer);
|
|
85
|
+
timer = undefined;
|
|
86
|
+
};
|
|
87
|
+
const check = () => {
|
|
88
|
+
if (wait === undefined)
|
|
89
|
+
return false;
|
|
90
|
+
read();
|
|
91
|
+
const slept = sleptMs - wait.sleptAtArm;
|
|
92
|
+
if (!(slept > wait.windowMs / 2))
|
|
93
|
+
return false;
|
|
94
|
+
const { onSuspend } = wait;
|
|
95
|
+
wait = undefined;
|
|
96
|
+
stopSampling();
|
|
97
|
+
onSuspend(slept);
|
|
98
|
+
return true;
|
|
99
|
+
};
|
|
100
|
+
const sample = () => {
|
|
101
|
+
timer = setTimeout(() => {
|
|
102
|
+
timer = undefined;
|
|
103
|
+
if (!check() && wait !== undefined)
|
|
104
|
+
sample();
|
|
105
|
+
}, SUSPEND_SAMPLE_MS);
|
|
106
|
+
timer.unref?.();
|
|
107
|
+
};
|
|
108
|
+
return {
|
|
109
|
+
arm(windowMs, onSuspend) {
|
|
110
|
+
if (disposed)
|
|
111
|
+
return;
|
|
112
|
+
if (timer !== undefined)
|
|
113
|
+
read();
|
|
114
|
+
else
|
|
115
|
+
readAt = Date.now();
|
|
116
|
+
if (!(windowMs > 0)) {
|
|
117
|
+
wait = undefined;
|
|
118
|
+
stopSampling();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
wait = { windowMs, sleptAtArm: sleptMs, onSuspend };
|
|
122
|
+
if (timer === undefined)
|
|
123
|
+
sample();
|
|
124
|
+
},
|
|
125
|
+
disarm() {
|
|
126
|
+
wait = undefined;
|
|
127
|
+
stopSampling();
|
|
128
|
+
},
|
|
129
|
+
check,
|
|
130
|
+
dispose() {
|
|
131
|
+
disposed = true;
|
|
132
|
+
wait = undefined;
|
|
133
|
+
stopSampling();
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
65
137
|
export function createAttemptController(firstByteWindowMs, outerSignal) {
|
|
66
138
|
const ac = new AbortController();
|
|
67
139
|
let timedOut = false;
|
|
@@ -73,24 +145,39 @@ export function createAttemptController(firstByteWindowMs, outerSignal) {
|
|
|
73
145
|
outerSignal.addEventListener("abort", onAbort, { once: true });
|
|
74
146
|
}
|
|
75
147
|
let timer;
|
|
148
|
+
let suspendedMs;
|
|
149
|
+
const suspend = watchSuspend();
|
|
150
|
+
const clearTimer = () => {
|
|
151
|
+
if (timer)
|
|
152
|
+
clearTimeout(timer);
|
|
153
|
+
timer = undefined;
|
|
154
|
+
suspend.disarm();
|
|
155
|
+
};
|
|
76
156
|
if (firstByteWindowMs && firstByteWindowMs > 0) {
|
|
157
|
+
suspend.arm(firstByteWindowMs, (slept) => {
|
|
158
|
+
suspendedMs = slept;
|
|
159
|
+
clearTimer();
|
|
160
|
+
ac.abort();
|
|
161
|
+
});
|
|
77
162
|
timer = setTimeout(() => {
|
|
163
|
+
timer = undefined;
|
|
164
|
+
if (suspend.check())
|
|
165
|
+
return;
|
|
166
|
+
suspend.disarm();
|
|
78
167
|
timedOut = true;
|
|
79
168
|
ac.abort();
|
|
80
169
|
}, firstByteWindowMs);
|
|
81
170
|
}
|
|
82
|
-
const clearTimer = () => {
|
|
83
|
-
if (timer)
|
|
84
|
-
clearTimeout(timer);
|
|
85
|
-
timer = undefined;
|
|
86
|
-
};
|
|
87
171
|
return {
|
|
88
172
|
signal: ac.signal,
|
|
89
173
|
timedOut: () => timedOut,
|
|
174
|
+
suspendedMs: () => suspendedMs,
|
|
175
|
+
suspend,
|
|
90
176
|
clearTimer,
|
|
91
177
|
abort: () => ac.abort(),
|
|
92
178
|
dispose: () => {
|
|
93
179
|
clearTimer();
|
|
180
|
+
suspend.dispose();
|
|
94
181
|
if (outerSignal)
|
|
95
182
|
outerSignal.removeEventListener("abort", onAbort);
|
|
96
183
|
},
|
package/dist/core/a2a.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AgentTool } from "../internal/harness-types.js";
|
|
2
|
+
import { type PeerSeat } from "./peer-seat.js";
|
|
2
3
|
import { type HostFloor } from "./host-floor.js";
|
|
3
4
|
import type { A2aServerSpec, ToolEffect } from "./types.js";
|
|
4
5
|
/** The hard per-skill description bound (ruled 2026-08-03: ~2KiB). */
|
|
@@ -97,4 +98,4 @@ export declare class A2aRpcError extends Error {
|
|
|
97
98
|
* `allSettled` keeps it fail-open: one unreachable peer is a skipped peer with a warning, never a task
|
|
98
99
|
* that cannot start.
|
|
99
100
|
*/
|
|
100
|
-
export declare function materializeA2aTools(specs: readonly A2aServerSpec[], principal?: string, signal?: AbortSignal, hostFloor?: HostFloor): Promise<MaterializedA2a>;
|
|
101
|
+
export declare function materializeA2aTools(specs: readonly A2aServerSpec[], principal?: string, signal?: AbortSignal, hostFloor?: HostFloor, peerSeat?: PeerSeat): Promise<MaterializedA2a>;
|
package/dist/core/a2a.js
CHANGED
|
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { Type } from "typebox";
|
|
3
3
|
import { A2A_TASK_STATES } from "./a2a-task-state.js";
|
|
4
4
|
import { assertEndpointBound, carriesDeclaredHeaders, resolveProtocolHttpHeaders, underDeclaredHeaders } from "./protocol-http-auth.js";
|
|
5
|
+
import { PeerCarrier, carriedHttpHeaders, peerSeatMissing } from "./peer-seat.js";
|
|
5
6
|
import { fetchFollowing, hopRefusal, HOST_FLOOR_REFUSED_CODE } from "./host-floor.js";
|
|
6
7
|
import { describeHttpTransportFailure } from "./mcp-failure.js";
|
|
7
8
|
import { findNamespacePrefixCollision, mintNamespacePrefix, mintNamespacedToolName } from "./protocol-naming.js";
|
|
@@ -147,18 +148,23 @@ async function requestJson(t, what, init) {
|
|
|
147
148
|
const doFetch = resolveFetch();
|
|
148
149
|
const deadline = withRequestDeadline(init.signal, init.timeoutMs);
|
|
149
150
|
const peerLabel = inlineUntrusted(t.peer, A2A_ID_MAX_CHARS);
|
|
151
|
+
const pieces = await t.carrier.next(init.signal, init.url);
|
|
152
|
+
const carried = carriedHttpHeaders(A2A_NAMESPACE.id, t.carrier, pieces, t.principalHeader, t.principal);
|
|
153
|
+
assertEndpointBound(A2A_NAMESPACE.id, t.peer, init.url, t.declared, carried === undefined ? undefined : { ...carried });
|
|
150
154
|
try {
|
|
151
155
|
const followed = await fetchFollowing(doFetch, new URL(init.url), {
|
|
152
156
|
method: init.method,
|
|
153
|
-
headers: underDeclaredHeaders({ accept: "application/json", "a2a-version": A2A_PROTOCOL_VERSION, ...(init.body !== undefined ? { "content-type": "application/json" } : {}) },
|
|
157
|
+
headers: underDeclaredHeaders({ accept: "application/json", "a2a-version": A2A_PROTOCOL_VERSION, ...(init.body !== undefined ? { "content-type": "application/json" } : {}) }, carried === undefined ? undefined : { ...carried }),
|
|
154
158
|
...(init.body !== undefined ? { body: init.body } : {}),
|
|
155
159
|
signal: deadline.signal,
|
|
156
|
-
}, { refusal: (url) => hopRefusal(url, t.floor, false), follows: () => !carriesDeclaredHeaders(
|
|
160
|
+
}, { refusal: (url) => hopRefusal(url, t.floor, false), follows: () => !carriesDeclaredHeaders(carried === undefined ? undefined : { ...carried }), maxRedirects: A2A_MAX_REDIRECTS });
|
|
157
161
|
if (followed.kind === "refused")
|
|
158
162
|
throw Object.assign(new Error(`a2a: ${what} on peer "${peerLabel}" is not sent — ${followed.reason}`), { code: HOST_FLOOR_REFUSED_CODE });
|
|
159
163
|
if (followed.kind === "too_many")
|
|
160
164
|
throw new Error(`a2a: ${what} on peer "${peerLabel}" was redirected more than ${A2A_MAX_REDIRECTS} times`);
|
|
161
165
|
const res = followed.res;
|
|
166
|
+
if (res.status === 401)
|
|
167
|
+
await t.carrier.rejected(pieces, init.signal, init.url);
|
|
162
168
|
const text = await readBoundedText(res, `${what} from A2A peer "${peerLabel}"`);
|
|
163
169
|
return { status: res.status, text };
|
|
164
170
|
}
|
|
@@ -559,16 +565,23 @@ function declaredPeerOf(declared, index) {
|
|
|
559
565
|
const judged = judgeEntryToolAxes(snapshot, "a2a");
|
|
560
566
|
return judged.ok ? { spec: judged.entry } : { spec: snapshot, refusal: judged.error };
|
|
561
567
|
}
|
|
562
|
-
async function materializePeer(peer, principal, lifecycle, signal, floor) {
|
|
568
|
+
async function materializePeer(peer, principal, lifecycle, signal, floor, seat) {
|
|
563
569
|
if ("refusal" in peer)
|
|
564
570
|
throw peer.refusal;
|
|
565
571
|
const { spec } = peer;
|
|
566
572
|
const declaredAxes = spec.toolAxes;
|
|
567
|
-
const
|
|
568
|
-
|
|
573
|
+
const missing = peerSeatMissing(`a2a: peer "${inlineUntrusted(spec.name, 120)}"`, spec.credentials, seat);
|
|
574
|
+
if (missing !== undefined)
|
|
575
|
+
throw missing;
|
|
576
|
+
resolveProtocolHttpHeaders(A2A_NAMESPACE.id, spec.principalHeader !== undefined ? { principalHeader: spec.principalHeader } : {}, principal);
|
|
577
|
+
const declared = spec.cardUrl === undefined ? [spec.url] : [spec.url, spec.cardUrl];
|
|
578
|
+
const identity = { protocol: "a2a", peer: spec.name, url: spec.url, ...(spec.cardUrl !== undefined ? { cardUrl: spec.cardUrl } : {}), destination: spec.url, ...(spec.credentials !== undefined ? { credentials: spec.credentials } : {}) };
|
|
579
|
+
const carrier = new PeerCarrier(seat, identity, principal, "a2a", spec.principalHeader !== undefined);
|
|
580
|
+
const asks = { carrier, principalHeader: spec.principalHeader, principal, declared, floor };
|
|
581
|
+
const discovery = { peer: spec.name, endpoint: spec.url, ...asks };
|
|
569
582
|
const card = readCard(spec.name, await discoverCardBody(spec, discovery, signal), spec.url);
|
|
570
|
-
assertEndpointBound(A2A_NAMESPACE.id, spec.name, card.endpoint,
|
|
571
|
-
const transport = { peer: spec.name, endpoint: card.endpoint,
|
|
583
|
+
assertEndpointBound(A2A_NAMESPACE.id, spec.name, card.endpoint, declared, carrier.last?.headers === undefined ? undefined : { ...carrier.last.headers });
|
|
584
|
+
const transport = { peer: spec.name, endpoint: card.endpoint, ...asks };
|
|
572
585
|
const tools = [];
|
|
573
586
|
const skillAxes = [];
|
|
574
587
|
for (const skill of card.skills) {
|
|
@@ -598,7 +611,7 @@ function asPeerWarning(spec, err) {
|
|
|
598
611
|
warning.code = "a2a.peer_unavailable";
|
|
599
612
|
return warning;
|
|
600
613
|
}
|
|
601
|
-
export async function materializeA2aTools(specs, principal, signal, hostFloor) {
|
|
614
|
+
export async function materializeA2aTools(specs, principal, signal, hostFloor, peerSeat) {
|
|
602
615
|
const peers = specs.map((spec, index) => declaredPeerOf(spec, index));
|
|
603
616
|
if (peers.length > 0) {
|
|
604
617
|
const collision = findNamespacePrefixCollision(A2A_NAMESPACE, peers.map((p) => p.spec.name));
|
|
@@ -616,7 +629,7 @@ export async function materializeA2aTools(specs, principal, signal, hostFloor) {
|
|
|
616
629
|
const toolAxes = [];
|
|
617
630
|
const warnings = [];
|
|
618
631
|
const statuses = [];
|
|
619
|
-
const settled = await Promise.allSettled(peers.map((peer) => materializePeer(peer, principal, lifecycle, signal, hostFloor)));
|
|
632
|
+
const settled = await Promise.allSettled(peers.map((peer) => materializePeer(peer, principal, lifecycle, signal, hostFloor, peerSeat)));
|
|
620
633
|
for (let i = 0; i < peers.length; i++) {
|
|
621
634
|
const spec = peers[i].spec;
|
|
622
635
|
const outcome = settled[i];
|
|
@@ -651,7 +664,7 @@ export async function materializeA2aTools(specs, principal, signal, hostFloor) {
|
|
|
651
664
|
}
|
|
652
665
|
const previous = statuses.find((s) => s.name === spec.name)?.toolNames ?? [];
|
|
653
666
|
try {
|
|
654
|
-
const fresh = await materializePeer(target, principal, lifecycle, signal, hostFloor);
|
|
667
|
+
const fresh = await materializePeer(target, principal, lifecycle, signal, hostFloor, peerSeat);
|
|
655
668
|
const names = fresh.tools.map((t) => t.name);
|
|
656
669
|
results.push({
|
|
657
670
|
peer: spec.name,
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The engine's account LINE and its one reading. A host that keeps a session's spend (a result frame's total, a `/cost`
|
|
3
|
+
* view, a server's session aggregate) keeps the engine-priced lines it is handed — one per finished run, one per side query — and
|
|
4
|
+
* reads them back through {@link foldAccount}; no host re-sums, re-prices, or decides for itself what an unpriced line means.
|
|
5
|
+
*
|
|
6
|
+
* What the engine owns: the pricing (`priceReply`, the arithmetic every run lane already uses) and the line's shape. What it
|
|
7
|
+
* does not own: where lines are kept — persistence is the host's, so "a resumed session includes its history" is the fold of
|
|
8
|
+
* the history lines the host supplies plus this run's line.
|
|
9
|
+
*/
|
|
10
|
+
import type { TaskResult } from "./task-result.js";
|
|
11
|
+
/** Who caused a line of the account: a run (the user's turns and everything the run's own agent caused — its compaction,
|
|
12
|
+
* classifier, mods, advisor and delegated sub-agents are INSIDE the run's line) or a side query (`Runner.sideQuery`, the one-shot
|
|
13
|
+
* utility call that belongs to no run). A closed set: the fold's `byOrigin` is total over it by its type. */
|
|
14
|
+
export declare const ACCOUNT_ORIGINS: readonly ["run", "side_query"];
|
|
15
|
+
export type AccountOrigin = (typeof ACCOUNT_ORIGINS)[number];
|
|
16
|
+
/** One priced line. `costMicroUsd` is integer micro-USD and ABSENT when any spend in the line was unpriced — unknown, never a
|
|
17
|
+
* fabricated 0 (the run's `stats.costMicroUsd` law); `usageMissing` marks figures that are a lower bound because a reply
|
|
18
|
+
* reported no usage. */
|
|
19
|
+
export interface AccountRow {
|
|
20
|
+
origin: AccountOrigin;
|
|
21
|
+
tokens: number;
|
|
22
|
+
costMicroUsd?: number;
|
|
23
|
+
usageMissing?: true;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The line a finished run contributes: its own usage plus its delegated sub-agents' (`stats.nested`) — the fully reconciled
|
|
27
|
+
* spend of the run. Unknown stays unknown: a run whose own or delegated spend was unpriced yields a line without a cost.
|
|
28
|
+
*
|
|
29
|
+
* The line is exactly what the result's `stats` says, so it is exact for a run that did not durably resume and that no
|
|
30
|
+
* background delegate outlived. `stats` itself is not one interval across a durable resume chain — a leg's own usage is per leg
|
|
31
|
+
* (a `resource_limit` chain's folds the earlier slices in), its delegated usage is cumulative over the chain, and an unknown
|
|
32
|
+
* mark does not survive the chain or the delegation rollup — so the lines of ONE chain are not additive, and spend a background
|
|
33
|
+
* delegate books after the result settled is in no line. Spend the engine books after the result — the prompt-suggestion pass,
|
|
34
|
+
* memory consolidation — is on its own face. The reading that has none of these gaps is an account the engine keeps, minted where
|
|
35
|
+
* each interval is known.
|
|
36
|
+
*/
|
|
37
|
+
export declare function accountRowOfResult(result: {
|
|
38
|
+
readonly stats: Pick<TaskResult["stats"], "tokens" | "costMicroUsd" | "usageMissing" | "nested">;
|
|
39
|
+
}): AccountRow;
|
|
40
|
+
/** A fold of lines: how many, their tokens, their cost (absent as soon as any one line's cost is unknown), and whether any
|
|
41
|
+
* figure is a lower bound. An empty fold is a known zero. */
|
|
42
|
+
export interface AccountTotal {
|
|
43
|
+
rows: number;
|
|
44
|
+
tokens: number;
|
|
45
|
+
costMicroUsd?: number;
|
|
46
|
+
usageMissing?: true;
|
|
47
|
+
}
|
|
48
|
+
/** The session's account: the total over every line, and the same fold per origin. */
|
|
49
|
+
export interface SessionAccount extends AccountTotal {
|
|
50
|
+
byOrigin: Record<AccountOrigin, AccountTotal>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* THE reading of a session's account: fold the lines a host holds — history lines it persisted, this run's line, side-query lines —
|
|
54
|
+
* into one total and one total per origin. A line whose cost is unknown makes every total that contains it unknown (cost
|
|
55
|
+
* absent), because a sum that skipped it would present a lower bound as the whole. A malformed line (origin outside the closed set,
|
|
56
|
+
* a negative or non-finite number, a cost spelled as anything but an absent key) is refused loudly rather than summed.
|
|
57
|
+
*
|
|
58
|
+
* Which total a field shows is the host's mapping, stated once so the hosts agree: a run result frame's `total_cost_usd` is
|
|
59
|
+
* `byOrigin.run` (the run lines, history included, side queries not in it); a session's cumulative figure is the whole fold.
|
|
60
|
+
*/
|
|
61
|
+
export declare function foldAccount(rows: Iterable<AccountRow>): SessionAccount;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export const ACCOUNT_ORIGINS = Object.freeze(["run", "side_query"]);
|
|
2
|
+
export function accountRowOfResult(result) {
|
|
3
|
+
const { tokens, costMicroUsd, usageMissing, nested } = result.stats;
|
|
4
|
+
const known = costMicroUsd !== undefined && (nested === undefined || nested.costMicroUsd !== undefined);
|
|
5
|
+
return {
|
|
6
|
+
origin: "run",
|
|
7
|
+
tokens: tokens + (nested?.tokens ?? 0),
|
|
8
|
+
...(known ? { costMicroUsd: costMicroUsd + (nested?.costMicroUsd ?? 0) } : {}),
|
|
9
|
+
...(usageMissing === true ? { usageMissing: true } : {}),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function addRow(total, row) {
|
|
13
|
+
total.rows += 1;
|
|
14
|
+
total.tokens += row.tokens;
|
|
15
|
+
total.costMicroUsd = total.costMicroUsd === undefined || row.costMicroUsd === undefined ? undefined : total.costMicroUsd + row.costMicroUsd;
|
|
16
|
+
if (row.usageMissing === true)
|
|
17
|
+
total.usageMissing = true;
|
|
18
|
+
}
|
|
19
|
+
function settled(total) {
|
|
20
|
+
const { costMicroUsd, ...rest } = total;
|
|
21
|
+
return { ...rest, ...(costMicroUsd !== undefined ? { costMicroUsd } : {}) };
|
|
22
|
+
}
|
|
23
|
+
function checkedRow(row, index) {
|
|
24
|
+
const bad = (why) => {
|
|
25
|
+
throw new TypeError(`foldAccount: row ${index} ${why}`);
|
|
26
|
+
};
|
|
27
|
+
if (typeof row !== "object" || row === null)
|
|
28
|
+
return bad("is not an object");
|
|
29
|
+
const { origin, tokens, costMicroUsd, usageMissing } = row;
|
|
30
|
+
if (!ACCOUNT_ORIGINS.includes(origin))
|
|
31
|
+
bad(`has origin ${JSON.stringify(origin)}, outside ${JSON.stringify(ACCOUNT_ORIGINS)}`);
|
|
32
|
+
if (typeof tokens !== "number" || !Number.isFinite(tokens) || tokens < 0)
|
|
33
|
+
bad("has tokens that are not a finite non-negative number");
|
|
34
|
+
if (costMicroUsd !== undefined && (typeof costMicroUsd !== "number" || !Number.isInteger(costMicroUsd) || costMicroUsd < 0))
|
|
35
|
+
bad("has costMicroUsd that is not a non-negative integer of micro-USD (an unknown cost is an absent key; a USD figure is not micro-USD)");
|
|
36
|
+
if (usageMissing !== undefined && usageMissing !== true)
|
|
37
|
+
bad("has usageMissing other than true (an absent key is the only other reading)");
|
|
38
|
+
return { origin: origin, tokens: tokens, ...(costMicroUsd !== undefined ? { costMicroUsd: costMicroUsd } : {}), ...(usageMissing === true ? { usageMissing: true } : {}) };
|
|
39
|
+
}
|
|
40
|
+
export function foldAccount(rows) {
|
|
41
|
+
const empty = () => ({ rows: 0, tokens: 0, costMicroUsd: 0 });
|
|
42
|
+
const byOrigin = { run: empty(), side_query: empty() };
|
|
43
|
+
const all = empty();
|
|
44
|
+
let index = 0;
|
|
45
|
+
for (const raw of rows) {
|
|
46
|
+
const row = checkedRow(raw, index++);
|
|
47
|
+
addRow(byOrigin[row.origin], row);
|
|
48
|
+
addRow(all, row);
|
|
49
|
+
}
|
|
50
|
+
return { ...settled(all), byOrigin: { run: settled(byOrigin.run), side_query: settled(byOrigin.side_query) } };
|
|
51
|
+
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* The closed sets the answers are spelled in live beside them.
|
|
7
7
|
*/
|
|
8
8
|
import type { SessionTreeEntry } from "../internal/harness-types.js";
|
|
9
|
+
import type { AssistantMessage } from "../internal/llm.js";
|
|
9
10
|
import { type BrainErrorCode } from "../brain/errors.js";
|
|
10
11
|
import type { AssertAllKeysHandled } from "./ask-origin.js";
|
|
11
12
|
import type { EngineNotice, Model, ModelRef, RunnerDeps } from "./types.js";
|
|
@@ -86,7 +87,7 @@ export type HoldCausesCoverEveryBrainCode = AssertAllKeysHandled<Exclude<BrainEr
|
|
|
86
87
|
/** What a failed advisor request said about itself — the fields the hold reads and the card carries. */
|
|
87
88
|
export interface AdvisorFailure {
|
|
88
89
|
readonly code?: BrainErrorCode;
|
|
89
|
-
readonly errorKind?: "
|
|
90
|
+
readonly errorKind?: AssistantMessage["errorKind"];
|
|
90
91
|
readonly inputTooLongRuledOut?: true;
|
|
91
92
|
}
|
|
92
93
|
/** Whether this failure switches the advisor off for the conversation ({@link ADVISOR_HOLD_CAUSES}). */
|
|
@@ -62,7 +62,7 @@ export function advisorFailureHolds(f) {
|
|
|
62
62
|
const row = ADVISOR_HOLD_CAUSES[f.code];
|
|
63
63
|
return row === "hold" || (row === "hold_unless_window" && f.errorKind !== "input_too_long" && f.inputTooLongRuledOut === true);
|
|
64
64
|
}
|
|
65
|
-
const ERROR_KINDS = new Set(["input_too_long", "degenerate", "length_empty"]);
|
|
65
|
+
const ERROR_KINDS = new Set(["input_too_long", "degenerate", "length_empty", "image_unprocessable"]);
|
|
66
66
|
export function advisorHoldOf(entries) {
|
|
67
67
|
for (let i = entries.length - 1; i >= 0; i--) {
|
|
68
68
|
const e = entries[i];
|