@sema-ai/core 1.275.1
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 +5433 -0
- package/LICENSE +27 -0
- package/NOTICE.md +30 -0
- package/README.md +1040 -0
- package/dist/agents/agent-definition.d.ts +10 -0
- package/dist/agents/agent-definition.d.ts.map +1 -0
- package/dist/agents/agent-definition.js +18 -0
- package/dist/agents/agent-definition.js.map +1 -0
- package/dist/agents/builtin-agents.d.ts +69 -0
- package/dist/agents/builtin-agents.d.ts.map +1 -0
- package/dist/agents/builtin-agents.js +177 -0
- package/dist/agents/builtin-agents.js.map +1 -0
- package/dist/agents/cascade.d.ts +101 -0
- package/dist/agents/cascade.d.ts.map +1 -0
- package/dist/agents/cascade.js +189 -0
- package/dist/agents/cascade.js.map +1 -0
- package/dist/agents/observer.d.ts +209 -0
- package/dist/agents/observer.d.ts.map +1 -0
- package/dist/agents/observer.js +495 -0
- package/dist/agents/observer.js.map +1 -0
- package/dist/agents/repair-loop.d.ts +236 -0
- package/dist/agents/repair-loop.d.ts.map +1 -0
- package/dist/agents/repair-loop.js +293 -0
- package/dist/agents/repair-loop.js.map +1 -0
- package/dist/agents/session-util.d.ts +8 -0
- package/dist/agents/session-util.d.ts.map +1 -0
- package/dist/agents/session-util.js +9 -0
- package/dist/agents/session-util.js.map +1 -0
- package/dist/agents/subagent-steps.d.ts +93 -0
- package/dist/agents/subagent-steps.d.ts.map +1 -0
- package/dist/agents/subagent-steps.js +206 -0
- package/dist/agents/subagent-steps.js.map +1 -0
- package/dist/agents/subagent.d.ts +441 -0
- package/dist/agents/subagent.d.ts.map +1 -0
- package/dist/agents/subagent.js +2492 -0
- package/dist/agents/subagent.js.map +1 -0
- package/dist/agents/suspend-guard.d.ts +35 -0
- package/dist/agents/suspend-guard.d.ts.map +1 -0
- package/dist/agents/suspend-guard.js +48 -0
- package/dist/agents/suspend-guard.js.map +1 -0
- package/dist/agents/teacher.d.ts +137 -0
- package/dist/agents/teacher.d.ts.map +1 -0
- package/dist/agents/teacher.js +575 -0
- package/dist/agents/teacher.js.map +1 -0
- package/dist/agents/team.d.ts +211 -0
- package/dist/agents/team.d.ts.map +1 -0
- package/dist/agents/team.js +293 -0
- package/dist/agents/team.js.map +1 -0
- package/dist/agents/tool-filter.d.ts +29 -0
- package/dist/agents/tool-filter.d.ts.map +1 -0
- package/dist/agents/tool-filter.js +50 -0
- package/dist/agents/tool-filter.js.map +1 -0
- package/dist/agents/verify.d.ts +177 -0
- package/dist/agents/verify.d.ts.map +1 -0
- package/dist/agents/verify.js +305 -0
- package/dist/agents/verify.js.map +1 -0
- package/dist/bench/metrics.d.ts +714 -0
- package/dist/bench/metrics.d.ts.map +1 -0
- package/dist/bench/metrics.js +618 -0
- package/dist/bench/metrics.js.map +1 -0
- package/dist/bin/sema-tb.d.ts +3 -0
- package/dist/bin/sema-tb.d.ts.map +1 -0
- package/dist/bin/sema-tb.js +516 -0
- package/dist/bin/sema-tb.js.map +1 -0
- package/dist/bin/tb-env.d.ts +13 -0
- package/dist/bin/tb-env.d.ts.map +1 -0
- package/dist/bin/tb-env.js +26 -0
- package/dist/bin/tb-env.js.map +1 -0
- package/dist/brain/anthropic.d.ts +46 -0
- package/dist/brain/anthropic.d.ts.map +1 -0
- package/dist/brain/anthropic.js +830 -0
- package/dist/brain/anthropic.js.map +1 -0
- package/dist/brain/circuit-breaker.d.ts +46 -0
- package/dist/brain/circuit-breaker.d.ts.map +1 -0
- package/dist/brain/circuit-breaker.js +173 -0
- package/dist/brain/circuit-breaker.js.map +1 -0
- package/dist/brain/degrading.d.ts +98 -0
- package/dist/brain/degrading.d.ts.map +1 -0
- package/dist/brain/degrading.js +249 -0
- package/dist/brain/degrading.js.map +1 -0
- package/dist/brain/errors.d.ts +31 -0
- package/dist/brain/errors.d.ts.map +1 -0
- package/dist/brain/errors.js +58 -0
- package/dist/brain/errors.js.map +1 -0
- package/dist/brain/failover.d.ts +18 -0
- package/dist/brain/failover.d.ts.map +1 -0
- package/dist/brain/failover.js +118 -0
- package/dist/brain/failover.js.map +1 -0
- package/dist/brain/model-presets.d.ts +36 -0
- package/dist/brain/model-presets.d.ts.map +1 -0
- package/dist/brain/model-presets.js +54 -0
- package/dist/brain/model-presets.js.map +1 -0
- package/dist/brain/openai.d.ts +43 -0
- package/dist/brain/openai.d.ts.map +1 -0
- package/dist/brain/openai.js +784 -0
- package/dist/brain/openai.js.map +1 -0
- package/dist/brain/reasoning.d.ts +138 -0
- package/dist/brain/reasoning.d.ts.map +1 -0
- package/dist/brain/reasoning.js +146 -0
- package/dist/brain/reasoning.js.map +1 -0
- package/dist/brain/repetition.d.ts +60 -0
- package/dist/brain/repetition.d.ts.map +1 -0
- package/dist/brain/repetition.js +121 -0
- package/dist/brain/repetition.js.map +1 -0
- package/dist/brain/request-params.d.ts +29 -0
- package/dist/brain/request-params.d.ts.map +1 -0
- package/dist/brain/request-params.js +78 -0
- package/dist/brain/request-params.js.map +1 -0
- package/dist/brain/retry.d.ts +18 -0
- package/dist/brain/retry.d.ts.map +1 -0
- package/dist/brain/retry.js +42 -0
- package/dist/brain/retry.js.map +1 -0
- package/dist/brain/routing.d.ts +19 -0
- package/dist/brain/routing.d.ts.map +1 -0
- package/dist/brain/routing.js +44 -0
- package/dist/brain/routing.js.map +1 -0
- package/dist/brain/status-sink.d.ts +46 -0
- package/dist/brain/status-sink.d.ts.map +1 -0
- package/dist/brain/status-sink.js +36 -0
- package/dist/brain/status-sink.js.map +1 -0
- package/dist/brain/stream-engine.d.ts +85 -0
- package/dist/brain/stream-engine.d.ts.map +1 -0
- package/dist/brain/stream-engine.js +391 -0
- package/dist/brain/stream-engine.js.map +1 -0
- package/dist/brain/timeout.d.ts +44 -0
- package/dist/brain/timeout.d.ts.map +1 -0
- package/dist/brain/timeout.js +41 -0
- package/dist/brain/timeout.js.map +1 -0
- package/dist/brain/tool-call-repair.d.ts +15 -0
- package/dist/brain/tool-call-repair.d.ts.map +1 -0
- package/dist/brain/tool-call-repair.js +67 -0
- package/dist/brain/tool-call-repair.js.map +1 -0
- package/dist/brain/walltime.d.ts +14 -0
- package/dist/brain/walltime.d.ts.map +1 -0
- package/dist/brain/walltime.js +14 -0
- package/dist/brain/walltime.js.map +1 -0
- package/dist/core/arg-summary.d.ts +19 -0
- package/dist/core/arg-summary.d.ts.map +1 -0
- package/dist/core/arg-summary.js +96 -0
- package/dist/core/arg-summary.js.map +1 -0
- package/dist/core/ask-question.d.ts +113 -0
- package/dist/core/ask-question.d.ts.map +1 -0
- package/dist/core/ask-question.js +246 -0
- package/dist/core/ask-question.js.map +1 -0
- package/dist/core/auto-compaction.d.ts +341 -0
- package/dist/core/auto-compaction.d.ts.map +1 -0
- package/dist/core/auto-compaction.js +495 -0
- package/dist/core/auto-compaction.js.map +1 -0
- package/dist/core/auto-promote.d.ts +126 -0
- package/dist/core/auto-promote.d.ts.map +1 -0
- package/dist/core/auto-promote.js +171 -0
- package/dist/core/auto-promote.js.map +1 -0
- package/dist/core/background-shell.d.ts +128 -0
- package/dist/core/background-shell.d.ts.map +1 -0
- package/dist/core/background-shell.js +42 -0
- package/dist/core/background-shell.js.map +1 -0
- package/dist/core/cache-break-detector.d.ts +63 -0
- package/dist/core/cache-break-detector.d.ts.map +1 -0
- package/dist/core/cache-break-detector.js +0 -0
- package/dist/core/cache-break-detector.js.map +1 -0
- package/dist/core/canonical-json.d.ts +45 -0
- package/dist/core/canonical-json.d.ts.map +1 -0
- package/dist/core/canonical-json.js +132 -0
- package/dist/core/canonical-json.js.map +1 -0
- package/dist/core/checkpoint-store.d.ts +1101 -0
- package/dist/core/checkpoint-store.d.ts.map +1 -0
- package/dist/core/checkpoint-store.js +514 -0
- package/dist/core/checkpoint-store.js.map +1 -0
- package/dist/core/consolidate-scope.d.ts +94 -0
- package/dist/core/consolidate-scope.d.ts.map +1 -0
- package/dist/core/consolidate-scope.js +158 -0
- package/dist/core/consolidate-scope.js.map +1 -0
- package/dist/core/context-edit.d.ts +82 -0
- package/dist/core/context-edit.d.ts.map +1 -0
- package/dist/core/context-edit.js +149 -0
- package/dist/core/context-edit.js.map +1 -0
- package/dist/core/context-guard.d.ts +43 -0
- package/dist/core/context-guard.d.ts.map +1 -0
- package/dist/core/context-guard.js +171 -0
- package/dist/core/context-guard.js.map +1 -0
- package/dist/core/dynamic-recall.d.ts +100 -0
- package/dist/core/dynamic-recall.d.ts.map +1 -0
- package/dist/core/dynamic-recall.js +108 -0
- package/dist/core/dynamic-recall.js.map +1 -0
- package/dist/core/exec-gate.d.ts +74 -0
- package/dist/core/exec-gate.d.ts.map +1 -0
- package/dist/core/exec-gate.js +143 -0
- package/dist/core/exec-gate.js.map +1 -0
- package/dist/core/exec-output-tail.d.ts +37 -0
- package/dist/core/exec-output-tail.d.ts.map +1 -0
- package/dist/core/exec-output-tail.js +63 -0
- package/dist/core/exec-output-tail.js.map +1 -0
- package/dist/core/file-snapshot-store.d.ts +137 -0
- package/dist/core/file-snapshot-store.d.ts.map +1 -0
- package/dist/core/file-snapshot-store.js +319 -0
- package/dist/core/file-snapshot-store.js.map +1 -0
- package/dist/core/git-worktree-env.d.ts +41 -0
- package/dist/core/git-worktree-env.d.ts.map +1 -0
- package/dist/core/git-worktree-env.js +64 -0
- package/dist/core/git-worktree-env.js.map +1 -0
- package/dist/core/hooks.d.ts +372 -0
- package/dist/core/hooks.d.ts.map +1 -0
- package/dist/core/hooks.js +269 -0
- package/dist/core/hooks.js.map +1 -0
- package/dist/core/lsp-diagnostics.d.ts +74 -0
- package/dist/core/lsp-diagnostics.d.ts.map +1 -0
- package/dist/core/lsp-diagnostics.js +125 -0
- package/dist/core/lsp-diagnostics.js.map +1 -0
- package/dist/core/lsp-protocol.d.ts +28 -0
- package/dist/core/lsp-protocol.d.ts.map +1 -0
- package/dist/core/lsp-protocol.js +179 -0
- package/dist/core/lsp-protocol.js.map +1 -0
- package/dist/core/lsp-session.d.ts +56 -0
- package/dist/core/lsp-session.d.ts.map +1 -0
- package/dist/core/lsp-session.js +185 -0
- package/dist/core/lsp-session.js.map +1 -0
- package/dist/core/lsp.d.ts +132 -0
- package/dist/core/lsp.d.ts.map +1 -0
- package/dist/core/lsp.js +147 -0
- package/dist/core/lsp.js.map +1 -0
- package/dist/core/mcp.d.ts +294 -0
- package/dist/core/mcp.d.ts.map +1 -0
- package/dist/core/mcp.js +992 -0
- package/dist/core/mcp.js.map +1 -0
- package/dist/core/media-byte-cap.d.ts +34 -0
- package/dist/core/media-byte-cap.d.ts.map +1 -0
- package/dist/core/media-byte-cap.js +76 -0
- package/dist/core/media-byte-cap.js.map +1 -0
- package/dist/core/memory-engine/data-plane.d.ts +103 -0
- package/dist/core/memory-engine/data-plane.d.ts.map +1 -0
- package/dist/core/memory-engine/data-plane.js +272 -0
- package/dist/core/memory-engine/data-plane.js.map +1 -0
- package/dist/core/memory-engine/dual-root.d.ts +40 -0
- package/dist/core/memory-engine/dual-root.d.ts.map +1 -0
- package/dist/core/memory-engine/dual-root.js +95 -0
- package/dist/core/memory-engine/dual-root.js.map +1 -0
- package/dist/core/memory-engine/engine.d.ts +161 -0
- package/dist/core/memory-engine/engine.d.ts.map +1 -0
- package/dist/core/memory-engine/engine.js +1110 -0
- package/dist/core/memory-engine/engine.js.map +1 -0
- package/dist/core/memory-engine/file-backend.d.ts +162 -0
- package/dist/core/memory-engine/file-backend.d.ts.map +1 -0
- package/dist/core/memory-engine/file-backend.js +948 -0
- package/dist/core/memory-engine/file-backend.js.map +1 -0
- package/dist/core/memory-engine/frontmatter.d.ts +24 -0
- package/dist/core/memory-engine/frontmatter.d.ts.map +1 -0
- package/dist/core/memory-engine/frontmatter.js +135 -0
- package/dist/core/memory-engine/frontmatter.js.map +1 -0
- package/dist/core/memory-engine/index.d.ts +13 -0
- package/dist/core/memory-engine/index.d.ts.map +1 -0
- package/dist/core/memory-engine/index.js +28 -0
- package/dist/core/memory-engine/index.js.map +1 -0
- package/dist/core/memory-engine/layout.d.ts +123 -0
- package/dist/core/memory-engine/layout.d.ts.map +1 -0
- package/dist/core/memory-engine/layout.js +643 -0
- package/dist/core/memory-engine/layout.js.map +1 -0
- package/dist/core/memory-engine/memory-backend-contract.d.ts +22 -0
- package/dist/core/memory-engine/memory-backend-contract.d.ts.map +1 -0
- package/dist/core/memory-engine/memory-backend-contract.js +271 -0
- package/dist/core/memory-engine/memory-backend-contract.js.map +1 -0
- package/dist/core/memory-engine/migrate.d.ts +17 -0
- package/dist/core/memory-engine/migrate.d.ts.map +1 -0
- package/dist/core/memory-engine/migrate.js +35 -0
- package/dist/core/memory-engine/migrate.js.map +1 -0
- package/dist/core/memory-engine/scan.d.ts +20 -0
- package/dist/core/memory-engine/scan.d.ts.map +1 -0
- package/dist/core/memory-engine/scan.js +84 -0
- package/dist/core/memory-engine/scan.js.map +1 -0
- package/dist/core/memory-engine/scope-contract.d.ts +104 -0
- package/dist/core/memory-engine/scope-contract.d.ts.map +1 -0
- package/dist/core/memory-engine/scope-contract.js +288 -0
- package/dist/core/memory-engine/scope-contract.js.map +1 -0
- package/dist/core/memory-engine/sync-client.d.ts +100 -0
- package/dist/core/memory-engine/sync-client.d.ts.map +1 -0
- package/dist/core/memory-engine/sync-client.js +328 -0
- package/dist/core/memory-engine/sync-client.js.map +1 -0
- package/dist/core/memory-engine/sync.d.ts +97 -0
- package/dist/core/memory-engine/sync.d.ts.map +1 -0
- package/dist/core/memory-engine/sync.js +91 -0
- package/dist/core/memory-engine/sync.js.map +1 -0
- package/dist/core/memory-engine/types.d.ts +279 -0
- package/dist/core/memory-engine/types.d.ts.map +1 -0
- package/dist/core/memory-engine/types.js +9 -0
- package/dist/core/memory-engine/types.js.map +1 -0
- package/dist/core/memory-recall.d.ts +261 -0
- package/dist/core/memory-recall.d.ts.map +1 -0
- package/dist/core/memory-recall.js +600 -0
- package/dist/core/memory-recall.js.map +1 -0
- package/dist/core/memory-vector.d.ts +24 -0
- package/dist/core/memory-vector.d.ts.map +1 -0
- package/dist/core/memory-vector.js +51 -0
- package/dist/core/memory-vector.js.map +1 -0
- package/dist/core/memory.d.ts +502 -0
- package/dist/core/memory.d.ts.map +1 -0
- package/dist/core/memory.js +881 -0
- package/dist/core/memory.js.map +1 -0
- package/dist/core/message-utils.d.ts +7 -0
- package/dist/core/message-utils.d.ts.map +1 -0
- package/dist/core/message-utils.js +10 -0
- package/dist/core/message-utils.js.map +1 -0
- package/dist/core/oracle-isolation.d.ts +85 -0
- package/dist/core/oracle-isolation.d.ts.map +1 -0
- package/dist/core/oracle-isolation.js +121 -0
- package/dist/core/oracle-isolation.js.map +1 -0
- package/dist/core/permission-rules.d.ts +102 -0
- package/dist/core/permission-rules.d.ts.map +1 -0
- package/dist/core/permission-rules.js +357 -0
- package/dist/core/permission-rules.js.map +1 -0
- package/dist/core/present-plan-tool.d.ts +28 -0
- package/dist/core/present-plan-tool.d.ts.map +1 -0
- package/dist/core/present-plan-tool.js +119 -0
- package/dist/core/present-plan-tool.js.map +1 -0
- package/dist/core/pricing.d.ts +48 -0
- package/dist/core/pricing.d.ts.map +1 -0
- package/dist/core/pricing.js +46 -0
- package/dist/core/pricing.js.map +1 -0
- package/dist/core/property-harness.d.ts +126 -0
- package/dist/core/property-harness.d.ts.map +1 -0
- package/dist/core/property-harness.js +192 -0
- package/dist/core/property-harness.js.map +1 -0
- package/dist/core/push-queue.d.ts +10 -0
- package/dist/core/push-queue.d.ts.map +1 -0
- package/dist/core/push-queue.js +42 -0
- package/dist/core/push-queue.js.map +1 -0
- package/dist/core/remote-env.d.ts +432 -0
- package/dist/core/remote-env.d.ts.map +1 -0
- package/dist/core/remote-env.js +77 -0
- package/dist/core/remote-env.js.map +1 -0
- package/dist/core/roles.d.ts +74 -0
- package/dist/core/roles.d.ts.map +1 -0
- package/dist/core/roles.js +272 -0
- package/dist/core/roles.js.map +1 -0
- package/dist/core/runner/active-skill-scope.d.ts +64 -0
- package/dist/core/runner/active-skill-scope.d.ts.map +1 -0
- package/dist/core/runner/active-skill-scope.js +197 -0
- package/dist/core/runner/active-skill-scope.js.map +1 -0
- package/dist/core/runner/assemble-result.d.ts +191 -0
- package/dist/core/runner/assemble-result.d.ts.map +1 -0
- package/dist/core/runner/assemble-result.js +250 -0
- package/dist/core/runner/assemble-result.js.map +1 -0
- package/dist/core/runner/call-cap.d.ts +130 -0
- package/dist/core/runner/call-cap.d.ts.map +1 -0
- package/dist/core/runner/call-cap.js +151 -0
- package/dist/core/runner/call-cap.js.map +1 -0
- package/dist/core/runner/grounding-signal.d.ts +12 -0
- package/dist/core/runner/grounding-signal.d.ts.map +1 -0
- package/dist/core/runner/grounding-signal.js +94 -0
- package/dist/core/runner/grounding-signal.js.map +1 -0
- package/dist/core/runner/image.d.ts +23 -0
- package/dist/core/runner/image.d.ts.map +1 -0
- package/dist/core/runner/image.js +151 -0
- package/dist/core/runner/image.js.map +1 -0
- package/dist/core/runner/memory-consolidation.d.ts +112 -0
- package/dist/core/runner/memory-consolidation.d.ts.map +1 -0
- package/dist/core/runner/memory-consolidation.js +372 -0
- package/dist/core/runner/memory-consolidation.js.map +1 -0
- package/dist/core/runner/prepare-task.d.ts +583 -0
- package/dist/core/runner/prepare-task.d.ts.map +1 -0
- package/dist/core/runner/prepare-task.js +3612 -0
- package/dist/core/runner/prepare-task.js.map +1 -0
- package/dist/core/runner/prompt-suggestions.d.ts +33 -0
- package/dist/core/runner/prompt-suggestions.d.ts.map +1 -0
- package/dist/core/runner/prompt-suggestions.js +116 -0
- package/dist/core/runner/prompt-suggestions.js.map +1 -0
- package/dist/core/runner/runtask.d.ts +274 -0
- package/dist/core/runner/runtask.d.ts.map +1 -0
- package/dist/core/runner/runtask.js +4606 -0
- package/dist/core/runner/runtask.js.map +1 -0
- package/dist/core/runner/session-rule-policy.d.ts +28 -0
- package/dist/core/runner/session-rule-policy.d.ts.map +1 -0
- package/dist/core/runner/session-rule-policy.js +110 -0
- package/dist/core/runner/session-rule-policy.js.map +1 -0
- package/dist/core/runner/strict-output-schema.d.ts +36 -0
- package/dist/core/runner/strict-output-schema.d.ts.map +1 -0
- package/dist/core/runner/strict-output-schema.js +365 -0
- package/dist/core/runner/strict-output-schema.js.map +1 -0
- package/dist/core/runner/synthetic-tools.d.ts +72 -0
- package/dist/core/runner/synthetic-tools.d.ts.map +1 -0
- package/dist/core/runner/synthetic-tools.js +203 -0
- package/dist/core/runner/synthetic-tools.js.map +1 -0
- package/dist/core/runner/tool-disclosure.d.ts +117 -0
- package/dist/core/runner/tool-disclosure.d.ts.map +1 -0
- package/dist/core/runner/tool-disclosure.js +0 -0
- package/dist/core/runner/tool-disclosure.js.map +1 -0
- package/dist/core/runner/turn-attachments.d.ts +381 -0
- package/dist/core/runner/turn-attachments.d.ts.map +1 -0
- package/dist/core/runner/turn-attachments.js +596 -0
- package/dist/core/runner/turn-attachments.js.map +1 -0
- package/dist/core/runner/usage-accounting.d.ts +35 -0
- package/dist/core/runner/usage-accounting.d.ts.map +1 -0
- package/dist/core/runner/usage-accounting.js +45 -0
- package/dist/core/runner/usage-accounting.js.map +1 -0
- package/dist/core/runtime.d.ts +9 -0
- package/dist/core/runtime.d.ts.map +1 -0
- package/dist/core/runtime.js +17 -0
- package/dist/core/runtime.js.map +1 -0
- package/dist/core/safety-axis-vocab.d.ts +33 -0
- package/dist/core/safety-axis-vocab.d.ts.map +1 -0
- package/dist/core/safety-axis-vocab.js +35 -0
- package/dist/core/safety-axis-vocab.js.map +1 -0
- package/dist/core/safety-merge-corpus.d.ts +48 -0
- package/dist/core/safety-merge-corpus.d.ts.map +1 -0
- package/dist/core/safety-merge-corpus.js +203 -0
- package/dist/core/safety-merge-corpus.js.map +1 -0
- package/dist/core/scheduler.d.ts +126 -0
- package/dist/core/scheduler.d.ts.map +1 -0
- package/dist/core/scheduler.js +54 -0
- package/dist/core/scheduler.js.map +1 -0
- package/dist/core/secret-env.d.ts +23 -0
- package/dist/core/secret-env.d.ts.map +1 -0
- package/dist/core/secret-env.js +35 -0
- package/dist/core/secret-env.js.map +1 -0
- package/dist/core/select-model.d.ts +26 -0
- package/dist/core/select-model.d.ts.map +1 -0
- package/dist/core/select-model.js +58 -0
- package/dist/core/select-model.js.map +1 -0
- package/dist/core/sensitive-path-policy.d.ts +24 -0
- package/dist/core/sensitive-path-policy.d.ts.map +1 -0
- package/dist/core/sensitive-path-policy.js +96 -0
- package/dist/core/sensitive-path-policy.js.map +1 -0
- package/dist/core/session-policy-store.d.ts +102 -0
- package/dist/core/session-policy-store.d.ts.map +1 -0
- package/dist/core/session-policy-store.js +177 -0
- package/dist/core/session-policy-store.js.map +1 -0
- package/dist/core/session-reconcile.d.ts +63 -0
- package/dist/core/session-reconcile.d.ts.map +1 -0
- package/dist/core/session-reconcile.js +71 -0
- package/dist/core/session-reconcile.js.map +1 -0
- package/dist/core/session-store.d.ts +99 -0
- package/dist/core/session-store.d.ts.map +1 -0
- package/dist/core/session-store.js +298 -0
- package/dist/core/session-store.js.map +1 -0
- package/dist/core/session.d.ts +144 -0
- package/dist/core/session.d.ts.map +1 -0
- package/dist/core/session.js +56 -0
- package/dist/core/session.js.map +1 -0
- package/dist/core/spec-contract.d.ts +147 -0
- package/dist/core/spec-contract.d.ts.map +1 -0
- package/dist/core/spec-contract.js +340 -0
- package/dist/core/spec-contract.js.map +1 -0
- package/dist/core/strategy-store.d.ts +50 -0
- package/dist/core/strategy-store.d.ts.map +1 -0
- package/dist/core/strategy-store.js +100 -0
- package/dist/core/strategy-store.js.map +1 -0
- package/dist/core/stub-env.d.ts +35 -0
- package/dist/core/stub-env.d.ts.map +1 -0
- package/dist/core/stub-env.js +69 -0
- package/dist/core/stub-env.js.map +1 -0
- package/dist/core/task-notification.d.ts +115 -0
- package/dist/core/task-notification.d.ts.map +1 -0
- package/dist/core/task-notification.js +247 -0
- package/dist/core/task-notification.js.map +1 -0
- package/dist/core/task-outcome.d.ts +80 -0
- package/dist/core/task-outcome.d.ts.map +1 -0
- package/dist/core/task-outcome.js +40 -0
- package/dist/core/task-outcome.js.map +1 -0
- package/dist/core/task-registry.d.ts +349 -0
- package/dist/core/task-registry.d.ts.map +1 -0
- package/dist/core/task-registry.js +1751 -0
- package/dist/core/task-registry.js.map +1 -0
- package/dist/core/tighten-task-spec.d.ts +27 -0
- package/dist/core/tighten-task-spec.d.ts.map +1 -0
- package/dist/core/tighten-task-spec.js +95 -0
- package/dist/core/tighten-task-spec.js.map +1 -0
- package/dist/core/tool-detach.d.ts +31 -0
- package/dist/core/tool-detach.d.ts.map +1 -0
- package/dist/core/tool-detach.js +62 -0
- package/dist/core/tool-detach.js.map +1 -0
- package/dist/core/tool-errors.d.ts +72 -0
- package/dist/core/tool-errors.d.ts.map +1 -0
- package/dist/core/tool-errors.js +194 -0
- package/dist/core/tool-errors.js.map +1 -0
- package/dist/core/tool-name-aliases.d.ts +5 -0
- package/dist/core/tool-name-aliases.d.ts.map +1 -0
- package/dist/core/tool-name-aliases.js +130 -0
- package/dist/core/tool-name-aliases.js.map +1 -0
- package/dist/core/tool-policy.d.ts +295 -0
- package/dist/core/tool-policy.d.ts.map +1 -0
- package/dist/core/tool-policy.js +567 -0
- package/dist/core/tool-policy.js.map +1 -0
- package/dist/core/tool-result-budget.d.ts +44 -0
- package/dist/core/tool-result-budget.d.ts.map +1 -0
- package/dist/core/tool-result-budget.js +140 -0
- package/dist/core/tool-result-budget.js.map +1 -0
- package/dist/core/tool-result-store.d.ts +136 -0
- package/dist/core/tool-result-store.d.ts.map +1 -0
- package/dist/core/tool-result-store.js +219 -0
- package/dist/core/tool-result-store.js.map +1 -0
- package/dist/core/tools.d.ts +14 -0
- package/dist/core/tools.d.ts.map +1 -0
- package/dist/core/tools.js +98 -0
- package/dist/core/tools.js.map +1 -0
- package/dist/core/trace.d.ts +340 -0
- package/dist/core/trace.d.ts.map +1 -0
- package/dist/core/trace.js +12 -0
- package/dist/core/trace.js.map +1 -0
- package/dist/core/types.d.ts +2828 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/untrusted-egress.d.ts +32 -0
- package/dist/core/untrusted-egress.d.ts.map +1 -0
- package/dist/core/untrusted-egress.js +49 -0
- package/dist/core/untrusted-egress.js.map +1 -0
- package/dist/core/untrusted-text.d.ts +64 -0
- package/dist/core/untrusted-text.d.ts.map +1 -0
- package/dist/core/untrusted-text.js +119 -0
- package/dist/core/untrusted-text.js.map +1 -0
- package/dist/core/warm-resume.d.ts +23 -0
- package/dist/core/warm-resume.d.ts.map +1 -0
- package/dist/core/warm-resume.js +28 -0
- package/dist/core/warm-resume.js.map +1 -0
- package/dist/core/with-retry.d.ts +43 -0
- package/dist/core/with-retry.d.ts.map +1 -0
- package/dist/core/with-retry.js +59 -0
- package/dist/core/with-retry.js.map +1 -0
- package/dist/core/workflow-journal-store.d.ts +44 -0
- package/dist/core/workflow-journal-store.d.ts.map +1 -0
- package/dist/core/workflow-journal-store.js +47 -0
- package/dist/core/workflow-journal-store.js.map +1 -0
- package/dist/core/workflow-run-store-contract.d.ts +31 -0
- package/dist/core/workflow-run-store-contract.d.ts.map +1 -0
- package/dist/core/workflow-run-store-contract.js +191 -0
- package/dist/core/workflow-run-store-contract.js.map +1 -0
- package/dist/core/workflow-run-store.d.ts +149 -0
- package/dist/core/workflow-run-store.d.ts.map +1 -0
- package/dist/core/workflow-run-store.js +110 -0
- package/dist/core/workflow-run-store.js.map +1 -0
- package/dist/engine/compaction/compaction.d.ts +139 -0
- package/dist/engine/compaction/compaction.d.ts.map +1 -0
- package/dist/engine/compaction/compaction.js +1030 -0
- package/dist/engine/compaction/compaction.js.map +1 -0
- package/dist/engine/compaction/utils.d.ts +45 -0
- package/dist/engine/compaction/utils.d.ts.map +1 -0
- package/dist/engine/compaction/utils.js +203 -0
- package/dist/engine/compaction/utils.js.map +1 -0
- package/dist/engine/execution-env/kill-tree.d.ts +20 -0
- package/dist/engine/execution-env/kill-tree.d.ts.map +1 -0
- package/dist/engine/execution-env/kill-tree.js +183 -0
- package/dist/engine/execution-env/kill-tree.js.map +1 -0
- package/dist/engine/execution-env/node-execution-env.d.ts +133 -0
- package/dist/engine/execution-env/node-execution-env.d.ts.map +1 -0
- package/dist/engine/execution-env/node-execution-env.js +1031 -0
- package/dist/engine/execution-env/node-execution-env.js.map +1 -0
- package/dist/engine/harness/agent-harness.d.ts +174 -0
- package/dist/engine/harness/agent-harness.d.ts.map +1 -0
- package/dist/engine/harness/agent-harness.js +1053 -0
- package/dist/engine/harness/agent-harness.js.map +1 -0
- package/dist/engine/harness/messages.d.ts +17 -0
- package/dist/engine/harness/messages.d.ts.map +1 -0
- package/dist/engine/harness/messages.js +122 -0
- package/dist/engine/harness/messages.js.map +1 -0
- package/dist/engine/harness/types.d.ts +713 -0
- package/dist/engine/harness/types.d.ts.map +1 -0
- package/dist/engine/harness/types.js +100 -0
- package/dist/engine/harness/types.js.map +1 -0
- package/dist/engine/llm/diagnostics.d.ts +23 -0
- package/dist/engine/llm/diagnostics.d.ts.map +1 -0
- package/dist/engine/llm/diagnostics.js +32 -0
- package/dist/engine/llm/diagnostics.js.map +1 -0
- package/dist/engine/llm/event-stream.d.ts +25 -0
- package/dist/engine/llm/event-stream.d.ts.map +1 -0
- package/dist/engine/llm/event-stream.js +103 -0
- package/dist/engine/llm/event-stream.js.map +1 -0
- package/dist/engine/llm/index.d.ts +12 -0
- package/dist/engine/llm/index.d.ts.map +1 -0
- package/dist/engine/llm/index.js +12 -0
- package/dist/engine/llm/index.js.map +1 -0
- package/dist/engine/llm/types.d.ts +753 -0
- package/dist/engine/llm/types.d.ts.map +1 -0
- package/dist/engine/llm/types.js +2 -0
- package/dist/engine/llm/types.js.map +1 -0
- package/dist/engine/llm/validation.d.ts +8 -0
- package/dist/engine/llm/validation.d.ts.map +1 -0
- package/dist/engine/llm/validation.js +318 -0
- package/dist/engine/llm/validation.js.map +1 -0
- package/dist/engine/loop/agent-loop.d.ts +74 -0
- package/dist/engine/loop/agent-loop.d.ts.map +1 -0
- package/dist/engine/loop/agent-loop.js +1490 -0
- package/dist/engine/loop/agent-loop.js.map +1 -0
- package/dist/engine/loop/runtime-deps.d.ts +17 -0
- package/dist/engine/loop/runtime-deps.d.ts.map +1 -0
- package/dist/engine/loop/runtime-deps.js +21 -0
- package/dist/engine/loop/runtime-deps.js.map +1 -0
- package/dist/engine/loop/types.d.ts +609 -0
- package/dist/engine/loop/types.d.ts.map +1 -0
- package/dist/engine/loop/types.js +2 -0
- package/dist/engine/loop/types.js.map +1 -0
- package/dist/engine/lsp/frame-decoder.d.ts +16 -0
- package/dist/engine/lsp/frame-decoder.d.ts.map +1 -0
- package/dist/engine/lsp/frame-decoder.js +53 -0
- package/dist/engine/lsp/frame-decoder.js.map +1 -0
- package/dist/engine/lsp/node-lsp-manager.d.ts +105 -0
- package/dist/engine/lsp/node-lsp-manager.d.ts.map +1 -0
- package/dist/engine/lsp/node-lsp-manager.js +343 -0
- package/dist/engine/lsp/node-lsp-manager.js.map +1 -0
- package/dist/engine/lsp/stdio-lsp-transport.d.ts +37 -0
- package/dist/engine/lsp/stdio-lsp-transport.d.ts.map +1 -0
- package/dist/engine/lsp/stdio-lsp-transport.js +185 -0
- package/dist/engine/lsp/stdio-lsp-transport.js.map +1 -0
- package/dist/engine/session/import-validate.d.ts +44 -0
- package/dist/engine/session/import-validate.d.ts.map +1 -0
- package/dist/engine/session/import-validate.js +92 -0
- package/dist/engine/session/import-validate.js.map +1 -0
- package/dist/engine/session/memory-repo.d.ts +25 -0
- package/dist/engine/session/memory-repo.d.ts.map +1 -0
- package/dist/engine/session/memory-repo.js +59 -0
- package/dist/engine/session/memory-repo.js.map +1 -0
- package/dist/engine/session/memory-storage.d.ts +14 -0
- package/dist/engine/session/memory-storage.d.ts.map +1 -0
- package/dist/engine/session/memory-storage.js +17 -0
- package/dist/engine/session/memory-storage.js.map +1 -0
- package/dist/engine/session/repo-utils.d.ts +11 -0
- package/dist/engine/session/repo-utils.d.ts.map +1 -0
- package/dist/engine/session/repo-utils.js +40 -0
- package/dist/engine/session/repo-utils.js.map +1 -0
- package/dist/engine/session/session.d.ts +34 -0
- package/dist/engine/session/session.d.ts.map +1 -0
- package/dist/engine/session/session.js +227 -0
- package/dist/engine/session/session.js.map +1 -0
- package/dist/engine/session/storage-base.d.ts +38 -0
- package/dist/engine/session/storage-base.d.ts.map +1 -0
- package/dist/engine/session/storage-base.js +157 -0
- package/dist/engine/session/storage-base.js.map +1 -0
- package/dist/engine/session/timestamps.d.ts +3 -0
- package/dist/engine/session/timestamps.d.ts.map +1 -0
- package/dist/engine/session/timestamps.js +15 -0
- package/dist/engine/session/timestamps.js.map +1 -0
- package/dist/engine/session/uuid.d.ts +2 -0
- package/dist/engine/session/uuid.d.ts.map +1 -0
- package/dist/engine/session/uuid.js +50 -0
- package/dist/engine/session/uuid.js.map +1 -0
- package/dist/index.d.ts +160 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +374 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/harness.d.ts +26 -0
- package/dist/internal/harness.d.ts.map +1 -0
- package/dist/internal/harness.js +24 -0
- package/dist/internal/harness.js.map +1 -0
- package/dist/internal/llm.d.ts +9 -0
- package/dist/internal/llm.d.ts.map +1 -0
- package/dist/internal/llm.js +8 -0
- package/dist/internal/llm.js.map +1 -0
- package/dist/orchestration/builtin-workflows.d.ts +44 -0
- package/dist/orchestration/builtin-workflows.d.ts.map +1 -0
- package/dist/orchestration/builtin-workflows.js +165 -0
- package/dist/orchestration/builtin-workflows.js.map +1 -0
- package/dist/orchestration/dev-vm-script-runner.d.ts +24 -0
- package/dist/orchestration/dev-vm-script-runner.d.ts.map +1 -0
- package/dist/orchestration/dev-vm-script-runner.js +106 -0
- package/dist/orchestration/dev-vm-script-runner.js.map +1 -0
- package/dist/orchestration/goal.d.ts +97 -0
- package/dist/orchestration/goal.d.ts.map +1 -0
- package/dist/orchestration/goal.js +248 -0
- package/dist/orchestration/goal.js.map +1 -0
- package/dist/orchestration/run-spec.d.ts +63 -0
- package/dist/orchestration/run-spec.d.ts.map +1 -0
- package/dist/orchestration/run-spec.js +274 -0
- package/dist/orchestration/run-spec.js.map +1 -0
- package/dist/orchestration/run-workflow-tool.d.ts +187 -0
- package/dist/orchestration/run-workflow-tool.d.ts.map +1 -0
- package/dist/orchestration/run-workflow-tool.js +612 -0
- package/dist/orchestration/run-workflow-tool.js.map +1 -0
- package/dist/orchestration/workflow-governance.d.ts +70 -0
- package/dist/orchestration/workflow-governance.d.ts.map +1 -0
- package/dist/orchestration/workflow-governance.js +176 -0
- package/dist/orchestration/workflow-governance.js.map +1 -0
- package/dist/orchestration/workflow-meta.d.ts +41 -0
- package/dist/orchestration/workflow-meta.d.ts.map +1 -0
- package/dist/orchestration/workflow-meta.js +426 -0
- package/dist/orchestration/workflow-meta.js.map +1 -0
- package/dist/orchestration/workflow-observe.d.ts +77 -0
- package/dist/orchestration/workflow-observe.d.ts.map +1 -0
- package/dist/orchestration/workflow-observe.js +177 -0
- package/dist/orchestration/workflow-observe.js.map +1 -0
- package/dist/orchestration/workflow-primitives.d.ts +31 -0
- package/dist/orchestration/workflow-primitives.d.ts.map +1 -0
- package/dist/orchestration/workflow-primitives.js +104 -0
- package/dist/orchestration/workflow-primitives.js.map +1 -0
- package/dist/orchestration/workflow-sandbox-conformance.d.ts +34 -0
- package/dist/orchestration/workflow-sandbox-conformance.d.ts.map +1 -0
- package/dist/orchestration/workflow-sandbox-conformance.js +301 -0
- package/dist/orchestration/workflow-sandbox-conformance.js.map +1 -0
- package/dist/orchestration/workflow-script-runner.d.ts +127 -0
- package/dist/orchestration/workflow-script-runner.d.ts.map +1 -0
- package/dist/orchestration/workflow-script-runner.js +48 -0
- package/dist/orchestration/workflow-script-runner.js.map +1 -0
- package/dist/orchestration/workflow-script-store.d.ts +99 -0
- package/dist/orchestration/workflow-script-store.d.ts.map +1 -0
- package/dist/orchestration/workflow-script-store.js +133 -0
- package/dist/orchestration/workflow-script-store.js.map +1 -0
- package/dist/orchestration/workflow-size-guideline.d.ts +50 -0
- package/dist/orchestration/workflow-size-guideline.d.ts.map +1 -0
- package/dist/orchestration/workflow-size-guideline.js +78 -0
- package/dist/orchestration/workflow-size-guideline.js.map +1 -0
- package/dist/orchestration/workflow.d.ts +624 -0
- package/dist/orchestration/workflow.d.ts.map +1 -0
- package/dist/orchestration/workflow.js +1596 -0
- package/dist/orchestration/workflow.js.map +1 -0
- package/dist/prompts/default.d.ts +474 -0
- package/dist/prompts/default.d.ts.map +1 -0
- package/dist/prompts/default.js +676 -0
- package/dist/prompts/default.js.map +1 -0
- package/dist/prompts/supervisor.d.ts +60 -0
- package/dist/prompts/supervisor.d.ts.map +1 -0
- package/dist/prompts/supervisor.js +162 -0
- package/dist/prompts/supervisor.js.map +1 -0
- package/dist/scenarios/env.d.ts +41 -0
- package/dist/scenarios/env.d.ts.map +1 -0
- package/dist/scenarios/env.js +65 -0
- package/dist/scenarios/env.js.map +1 -0
- package/dist/scenarios/full-body.d.ts +47 -0
- package/dist/scenarios/full-body.d.ts.map +1 -0
- package/dist/scenarios/full-body.js +36 -0
- package/dist/scenarios/full-body.js.map +1 -0
- package/dist/scenarios/scenario-registry.d.ts +107 -0
- package/dist/scenarios/scenario-registry.d.ts.map +1 -0
- package/dist/scenarios/scenario-registry.js +192 -0
- package/dist/scenarios/scenario-registry.js.map +1 -0
- package/dist/scenarios/teacher-quickstart.d.ts +41 -0
- package/dist/scenarios/teacher-quickstart.d.ts.map +1 -0
- package/dist/scenarios/teacher-quickstart.js +32 -0
- package/dist/scenarios/teacher-quickstart.js.map +1 -0
- package/dist/server/http.d.ts +36 -0
- package/dist/server/http.d.ts.map +1 -0
- package/dist/server/http.js +144 -0
- package/dist/server/http.js.map +1 -0
- package/dist/stores/file/checkpoint-store.d.ts +62 -0
- package/dist/stores/file/checkpoint-store.d.ts.map +1 -0
- package/dist/stores/file/checkpoint-store.js +250 -0
- package/dist/stores/file/checkpoint-store.js.map +1 -0
- package/dist/stores/file/file-snapshot-store.d.ts +43 -0
- package/dist/stores/file/file-snapshot-store.d.ts.map +1 -0
- package/dist/stores/file/file-snapshot-store.js +374 -0
- package/dist/stores/file/file-snapshot-store.js.map +1 -0
- package/dist/stores/file/fs-atomic.d.ts +95 -0
- package/dist/stores/file/fs-atomic.d.ts.map +1 -0
- package/dist/stores/file/fs-atomic.js +415 -0
- package/dist/stores/file/fs-atomic.js.map +1 -0
- package/dist/stores/file/index.d.ts +98 -0
- package/dist/stores/file/index.d.ts.map +1 -0
- package/dist/stores/file/index.js +109 -0
- package/dist/stores/file/index.js.map +1 -0
- package/dist/stores/file/memory-store.d.ts +95 -0
- package/dist/stores/file/memory-store.d.ts.map +1 -0
- package/dist/stores/file/memory-store.js +393 -0
- package/dist/stores/file/memory-store.js.map +1 -0
- package/dist/stores/file/session-policy-store.d.ts +24 -0
- package/dist/stores/file/session-policy-store.d.ts.map +1 -0
- package/dist/stores/file/session-policy-store.js +123 -0
- package/dist/stores/file/session-policy-store.js.map +1 -0
- package/dist/stores/file/session-store.d.ts +34 -0
- package/dist/stores/file/session-store.d.ts.map +1 -0
- package/dist/stores/file/session-store.js +175 -0
- package/dist/stores/file/session-store.js.map +1 -0
- package/dist/stores/file/tool-result-store.d.ts +23 -0
- package/dist/stores/file/tool-result-store.d.ts.map +1 -0
- package/dist/stores/file/tool-result-store.js +61 -0
- package/dist/stores/file/tool-result-store.js.map +1 -0
- package/dist/stores/file/workflow-journal-store.d.ts +36 -0
- package/dist/stores/file/workflow-journal-store.d.ts.map +1 -0
- package/dist/stores/file/workflow-journal-store.js +157 -0
- package/dist/stores/file/workflow-journal-store.js.map +1 -0
- package/dist/stores/file/workflow-run-store.d.ts +58 -0
- package/dist/stores/file/workflow-run-store.d.ts.map +1 -0
- package/dist/stores/file/workflow-run-store.js +178 -0
- package/dist/stores/file/workflow-run-store.js.map +1 -0
- package/dist/stores/pg.d.ts +210 -0
- package/dist/stores/pg.d.ts.map +1 -0
- package/dist/stores/pg.js +652 -0
- package/dist/stores/pg.js.map +1 -0
- package/dist/tools/fs/encoding.d.ts +51 -0
- package/dist/tools/fs/encoding.d.ts.map +1 -0
- package/dist/tools/fs/encoding.js +74 -0
- package/dist/tools/fs/encoding.js.map +1 -0
- package/dist/tools/fs/gh-rate-limit.d.ts +19 -0
- package/dist/tools/fs/gh-rate-limit.d.ts.map +1 -0
- package/dist/tools/fs/gh-rate-limit.js +35 -0
- package/dist/tools/fs/gh-rate-limit.js.map +1 -0
- package/dist/tools/fs/index.d.ts +246 -0
- package/dist/tools/fs/index.d.ts.map +1 -0
- package/dist/tools/fs/index.js +2130 -0
- package/dist/tools/fs/index.js.map +1 -0
- package/dist/tools/fs/pdf.d.ts +106 -0
- package/dist/tools/fs/pdf.d.ts.map +1 -0
- package/dist/tools/fs/pdf.js +178 -0
- package/dist/tools/fs/pdf.js.map +1 -0
- package/dist/tools/fs/repo-map.d.ts +15 -0
- package/dist/tools/fs/repo-map.d.ts.map +1 -0
- package/dist/tools/fs/repo-map.js +251 -0
- package/dist/tools/fs/repo-map.js.map +1 -0
- package/dist/tools/fs/safety.d.ts +168 -0
- package/dist/tools/fs/safety.d.ts.map +1 -0
- package/dist/tools/fs/safety.js +479 -0
- package/dist/tools/fs/safety.js.map +1 -0
- package/dist/tools/fs/search.d.ts +118 -0
- package/dist/tools/fs/search.d.ts.map +1 -0
- package/dist/tools/fs/search.js +650 -0
- package/dist/tools/fs/search.js.map +1 -0
- package/dist/tools/gitea-issue.d.ts +39 -0
- package/dist/tools/gitea-issue.d.ts.map +1 -0
- package/dist/tools/gitea-issue.js +91 -0
- package/dist/tools/gitea-issue.js.map +1 -0
- package/dist/tools/monitor.d.ts +64 -0
- package/dist/tools/monitor.d.ts.map +1 -0
- package/dist/tools/monitor.js +135 -0
- package/dist/tools/monitor.js.map +1 -0
- package/dist/tools/scheduler-tools.d.ts +48 -0
- package/dist/tools/scheduler-tools.d.ts.map +1 -0
- package/dist/tools/scheduler-tools.js +449 -0
- package/dist/tools/scheduler-tools.js.map +1 -0
- package/dist/tools/sql-adapters.d.ts +32 -0
- package/dist/tools/sql-adapters.d.ts.map +1 -0
- package/dist/tools/sql-adapters.js +31 -0
- package/dist/tools/sql-adapters.js.map +1 -0
- package/dist/tools/sql.d.ts +36 -0
- package/dist/tools/sql.d.ts.map +1 -0
- package/dist/tools/sql.js +131 -0
- package/dist/tools/sql.js.map +1 -0
- package/dist/tools/task-list.d.ts +26 -0
- package/dist/tools/task-list.d.ts.map +1 -0
- package/dist/tools/task-list.js +352 -0
- package/dist/tools/task-list.js.map +1 -0
- package/dist/tools/todo.d.ts +11 -0
- package/dist/tools/todo.d.ts.map +1 -0
- package/dist/tools/todo.js +126 -0
- package/dist/tools/todo.js.map +1 -0
- package/dist/tools/web.d.ts +59 -0
- package/dist/tools/web.d.ts.map +1 -0
- package/dist/tools/web.js +607 -0
- package/dist/tools/web.js.map +1 -0
- package/dist/tools/worktree.d.ts +88 -0
- package/dist/tools/worktree.d.ts.map +1 -0
- package/dist/tools/worktree.js +434 -0
- package/dist/tools/worktree.js.map +1 -0
- package/docs/A1-ATTRIBUTION-ROUND1-2026-07-09.md +181 -0
- package/docs/AB-ORACLE-GATE-VERDICT-2026-07-10.md +100 -0
- package/docs/ANCHOR-GAP-INVENTORY-2026-07-09.md +143 -0
- package/docs/ARCHITECTURE.md +125 -0
- package/docs/BUGHUNT-2026-07-05-NIGHT.md +98 -0
- package/docs/BUILD.md +63 -0
- package/docs/CANCEL-ASYNC-ATTRIBUTION-2026-07-09.md +98 -0
- package/docs/CC-198-VS-201-DRIFT-2026-07-09.md +70 -0
- package/docs/CC-BASELINE-FAKE-ZERO-AUDIT-2026-07-09.md +51 -0
- package/docs/CC-DRIFT-198-206-AGENT-TYPES-2026-07-10.md +82 -0
- package/docs/CC-DRIFT-198-206-CHANGELOG-2026-07-10.md +82 -0
- package/docs/CC-DRIFT-198-206-REMINDERS-2026-07-10.md +96 -0
- package/docs/CC-DRIFT-198-206-ROADMAP-2026-07-10.md +110 -0
- package/docs/CC-DRIFT-198-206-TOOL-INVENTORY-2026-07-10.md +53 -0
- package/docs/CC-DRIFT-198-206-USAGE-CONSTANTS-2026-07-10.md +64 -0
- package/docs/CC-DRIFT-198-206-WORKFLOW-2026-07-10.md +83 -0
- package/docs/CC-PARITY-CHECKLIST.md +220 -0
- package/docs/CC-PARITY-DEEP-SWEEP-2026-07-07.md +149 -0
- package/docs/CC-SUBAGENT-PROMPT-STUDY-2026-07-09.md +219 -0
- package/docs/CC-TASK-REMINDER-CADENCE-STUDY-2026-07-09.md +396 -0
- package/docs/CC-TOOL-PARITY-SWEEP-2026-07.md +56 -0
- package/docs/CC-TOOL-PROMPT-DEEP-DIFF-2026-07-08.md +274 -0
- package/docs/CC-TOOLSURFACE-DEEP-DIVE-2026-07-07.md +197 -0
- package/docs/CC206-OBSERVER-ANCHORS-2026-07-11.md +463 -0
- package/docs/CC207-CORE-SWEEP-BACKLOG-2026-07-12.md +155 -0
- package/docs/CENTER-CONTROL-PLANE-SEAM.md +86 -0
- package/docs/CLEANUP-CONTRACT-ANCHOR-2026-07-09.md +83 -0
- package/docs/COLD-START-RSI-2026-07-09.md +72 -0
- package/docs/COMPACTION-LIVE-AUDIT-2026-07-09.md +114 -0
- package/docs/CONTEXT-lifecycle-extension-points-and-stop-attribution.md +71 -0
- package/docs/COREWARS-POLYGLOT-TRIAGE-2026-07-09.md +85 -0
- package/docs/DEADTARGET-OVERFULL-HBOX-2026-07-10.md +92 -0
- package/docs/DEADTARGET-PATH-TRACING-REVERSE-2026-07-10.md +87 -0
- package/docs/DEADTARGET-WINNING-AVG-COREWARS-2026-07-10.md +96 -0
- package/docs/DEEPSEEK-API-LIMITS-PROBE-2026-07-09.md +118 -0
- package/docs/DESIGN-140-MOCK-VERIFY-2026-07-11.md +79 -0
- package/docs/DESIGN-140-VERIFICATION-2026-07-11.md +43 -0
- package/docs/DESIGN-DRAFT-workflow-collab-2026-07-11.md +56 -0
- package/docs/DESIGN-ORACLE-GROUNDING-GATE-2026-07-10.md +167 -0
- package/docs/DESIGN-TFRAG-RECONCILE-SCAFFOLD-2026-07-09.md +102 -0
- package/docs/EXP-PA2-PE-DESIGN-2026-07-11.md +220 -0
- package/docs/EXT-DOGFOOD-2026-07-12.md +50 -0
- package/docs/FINAL-VERIFY-SURFACE-AUDIT-2026-07-09.md +44 -0
- package/docs/FRAG-RECON-INVESTIGATION-2026-07-09.md +183 -0
- package/docs/HANDOFF.md +121 -0
- package/docs/KNOWN-ISSUES.md +96 -0
- package/docs/LEGW-WINDOW-TAX-2026-07-10.md +82 -0
- package/docs/LIVE-PROBE-BATCH-2026-07-11.md +207 -0
- package/docs/M2-CERT-ATTRIBUTION-2026-07-10.md +61 -0
- package/docs/M25-LEG-VARIANCE-ATTRIBUTION-2026-07-10.md +81 -0
- package/docs/MAILMAN-TIMEOUT-ATTRIBUTION-2026-07-10.md +88 -0
- package/docs/MEMORY-BACKEND-DIALECT-NOTES.md +69 -0
- package/docs/MTEB-ESCAPE-HATCH-ATTRIBUTION-2026-07-09.md +57 -0
- package/docs/MTEB-LEADERBOARD-ATTRIBUTION-2026-07-10.md +134 -0
- package/docs/ORACLE-GATE-NEGATIVE-SAMPLE-2026-07-11.md +28 -0
- package/docs/PARITY-CONTEXT-TRANSACTIONS-2026-07-10.md +67 -0
- package/docs/PARITY-PROGRESS-MATRIX-2026-07-10.md +37 -0
- package/docs/PARITY-SPOT-AGENT-TYPES-2026-07-10.md +70 -0
- package/docs/PARITY-SPOT-REMINDERS-2026-07-10.md +144 -0
- package/docs/PARITY-SPOT-TOOL-INVENTORY-2026-07-10.md +61 -0
- package/docs/PARITY-SPOT-USAGE-CONSTANTS-2026-07-10.md +95 -0
- package/docs/PARITY-SPOT-WORKFLOW-2026-07-10.md +93 -0
- package/docs/PASSWORD-RECOVERY-PANEL-VERDICT-2026-07-10.md +62 -0
- package/docs/R8-R9-FINALIZE-COORDINATION-2026-07-09.md +124 -0
- package/docs/REPL-CODE-MODE-EVALUATION-2026-07-10.md +187 -0
- package/docs/REPORT-1249-TARGETED.md +48 -0
- package/docs/RESEARCH-3P-MEMORY-SWAP-2026-07-12.md +273 -0
- package/docs/ROADMAP.md +111 -0
- package/docs/RSI-CLOUD-DEPLOY-2026-07-06.md +289 -0
- package/docs/RSI-PROCESS-AI-COLDSTART-2026-07-11.md +68 -0
- package/docs/S18-THOROUGHNESS-AUDIT-2026-07-09.md +113 -0
- package/docs/SERVICE-INTEGRATION-GUIDE.md +298 -0
- package/docs/SUBAGENT-STREAM-RESILIENCE-PARITY-2026-07-10.md +118 -0
- package/docs/SWEBENCH-PRO-RECON-2026-07-11.md +31 -0
- package/docs/TB-EFFICIENCY-TELEMETRY-2026-07-08.md +114 -0
- package/docs/TB-FAILURE-AUTOPSY-2026-07-05-RERUN.md +67 -0
- package/docs/TB-FAIRNESS-AUDIT-2026-07-08.md +141 -0
- package/docs/TB-FULL-1257-2026-07-08.md +77 -0
- package/docs/TB-LEG-GAP-ATTRIBUTION-1261-1263-2026-07-11.md +154 -0
- package/docs/TB-REGRESSION-DAEMON-KILL-2026-07-08.md +58 -0
- package/docs/TB-RSI-CROSSCHECK-2026-07-06.md +68 -0
- package/docs/TB-RSI-LEDGER.md +30 -0
- package/docs/TB-STABLE-SET-2026-07-08.md +127 -0
- package/docs/TB21-RECON-2026-07-11.md +28 -0
- package/docs/TEST-DESIGN-BATCH-1-2-3.md +97 -0
- package/docs/THIRD-PARTY-INTEGRATION.md +45 -0
- package/docs/TOKEN-ESTIMATE-CALIBRATION-LIVE-2026-07-09.md +102 -0
- package/docs/audit-2026-06-10-/347/254/254/344/272/214/350/275/256-/347/251/272/347/231/275/345/214/272/344/270/216/345/277/230/346/216/245/347/272/277.md +147 -0
- package/docs/audit-2026-06-10-/350/256/241/347/256/227bug/346/211/253/346/217/217.md +163 -0
- package/docs/audit-2026-06-11-/344/277/256/345/244/215/345/244/215/345/256/241/344/270/216/345/233/236/345/275/222/344/270/223/346/211/253.md +95 -0
- package/docs/audit-2026-06-12-design71-P1/346/275/234/344/274/217/351/235/242/350/243/201/345/206/263/344/270/216/345/220/236/351/224/231/345/256/241/350/256/241.md +45 -0
- package/docs/audit-2026-06-12-/345/205/254/345/274/200/346/227/213/351/222/256/346/264/273/346/200/247/344/270/216vendored/346/255/273/350/267/257.md +63 -0
- package/docs/audit-2026-06-15/ADDENDUM-second-pass.md +88 -0
- package/docs/audit-2026-06-15/ARCHITECTURE-AND-ROADMAP.md +187 -0
- package/docs/audit-2026-06-15/DOC-CORRECTIONS.md +105 -0
- package/docs/audit-2026-06-15/INDEX.md +49 -0
- package/docs/audit-2026-06-15/ORCHESTRATION-STATUS.md +98 -0
- package/docs/audit-2026-06-15/PRODUCTION-ISSUES.md +189 -0
- package/docs/audit-2026-06-15/REFERENCES-literature.md +139 -0
- package/docs/audit-2026-06-15/VENDOR-REFACTOR-PLAN.md +96 -0
- package/docs/cc-probe-198/README.md +72 -0
- package/docs/cc-probe-198/STABILITY-AUDIT.md +118 -0
- package/docs/cc-probe-198/live-schema-monitor-worktree-2026-07-09.json +56 -0
- package/docs/cc-probe-198/mount-variants.json +536 -0
- package/docs/cc-probe-198/plan-mode-run.json +1 -0
- package/docs/cc-probe-198/probe-bash-bg.json +224 -0
- package/docs/cc-probe-198/probe-edit-mismatch.json +120 -0
- package/docs/cc-probe-198/probe-read-missing.json +62 -0
- package/docs/cc-probe-198/probe-search-empty.json +127 -0
- package/docs/cc-probe-198/probe-task-family.json +227 -0
- package/docs/cc-probe-198/probes.status +6 -0
- package/docs/cc-probe-198/raw-capture-interactive.json +948 -0
- package/docs/cc-probe-198/raw-capture-print.json +787 -0
- package/docs/cc-probe-198/raw-capture2-interactive.json +948 -0
- package/docs/cc-probe-198/raw-capture2-print.json +787 -0
- package/docs/cc-probe-198/system-prompt.txt +135 -0
- package/docs/cc-probe-198/tools-array.json +962 -0
- package/docs/durability-boundary.md +63 -0
- package/docs/fix-2026-06-10-/350/256/241/347/256/227bug/344/277/256/345/244/215-search/346/211/271.md +75 -0
- package/docs/fix-2026-06-11-/347/254/254/344/272/214/350/275/256-/344/277/256/345/244/215-search/346/211/271.md +62 -0
- package/docs/parity-sweep/REPORT-DYNAMIC.md +97 -0
- package/docs/parity-sweep/REPORT-STATIC-GGB.md +127 -0
- package/docs/parity-sweep/REPORT-STATIC-RWE.md +133 -0
- package/docs/vendor-history.md +385 -0
- package/docs/vendored-upstream-diff-2026-07.md +83 -0
- package/package.json +70 -0
|
@@ -0,0 +1,830 @@
|
|
|
1
|
+
import {} from "../internal/llm.js";
|
|
2
|
+
import { BrainError } from "./errors.js";
|
|
3
|
+
import { DEGENERATE_MESSAGE, inspectDegenerate } from "./repetition.js";
|
|
4
|
+
import { WALLTIME_CUTOFF_MESSAGE } from "./walltime.js";
|
|
5
|
+
import { emitBrainTelemetry } from "./status-sink.js";
|
|
6
|
+
import { ANTHROPIC_RESERVED, applyExtraBody } from "./request-params.js";
|
|
7
|
+
import { isThinkingLevel, reasoningBudgetShare, resolveEffort } from "./reasoning.js";
|
|
8
|
+
import { runStreamingBrain } from "./stream-engine.js";
|
|
9
|
+
/** Anthropic's hard floor for an extended-thinking budget. */
|
|
10
|
+
const MIN_THINKING_TOKENS = 1024;
|
|
11
|
+
/**
|
|
12
|
+
* Resolve `max_tokens` and `budget_tokens` for extended thinking. Anthropic requires
|
|
13
|
+
* `1024 ≤ budget_tokens < max_tokens` (422 otherwise) — unsatisfiable when the caller's `max_tokens`
|
|
14
|
+
* is itself ≤ 1024, so we raise `max_tokens` to host a minimum budget plus answer room. `budget` is
|
|
15
|
+
* then clamped strictly below `max_tokens`.
|
|
16
|
+
*/
|
|
17
|
+
function thinkingBudget(maxTokens, share, fixed, hardCap = false) {
|
|
18
|
+
// design/119 #2 review (codex H4): an EXPLICIT per-request cap (options.maxTokens) is a hard bound —
|
|
19
|
+
// never raise it. The raise applies only to the model/default-sourced value (pre-existing behavior).
|
|
20
|
+
const max = hardCap ? maxTokens : Math.max(maxTokens, MIN_THINKING_TOKENS * 2); // ≥1024 thinking + ≥1024 answer room
|
|
21
|
+
const want = fixed ?? Math.floor(max * share);
|
|
22
|
+
const budget = Math.min(Math.max(MIN_THINKING_TOKENS, want), max - 1);
|
|
23
|
+
return { max, budget };
|
|
24
|
+
}
|
|
25
|
+
const EPHEMERAL = { type: "ephemeral" };
|
|
26
|
+
/** PDF read: honest placeholder when the serving Anthropic model declares no vision (document processing
|
|
27
|
+
* requires a vision-capable model) — mirrors the image placeholder discipline (service [398] C4). */
|
|
28
|
+
const DOCUMENT_OMITTED_NO_VISION = "[PDF document omitted: the serving model does not support document input; extract the text via Bash instead (e.g. `pdftotext`).]";
|
|
29
|
+
function textOf(content) {
|
|
30
|
+
return typeof content === "string"
|
|
31
|
+
? content
|
|
32
|
+
: content.filter((c) => c.type === "text" && typeof c.text === "string").map((c) => c.text).join("");
|
|
33
|
+
}
|
|
34
|
+
/** A user/tool-result message's content blocks (text + images + tool_result). 无视觉模型 ⇒ 图像块降级为
|
|
35
|
+
* 文本占位符(TB 战线 pytorch-model-cli 逮的 400 类;model 元数据缺席 = 维持今日行为发图)。 */
|
|
36
|
+
function toUserBlocks(content, supportsVision = true) {
|
|
37
|
+
if (typeof content === "string") {
|
|
38
|
+
return [{ type: "text", text: content }];
|
|
39
|
+
}
|
|
40
|
+
const blocks = [];
|
|
41
|
+
let omitted = 0; // service [398] C4: count placeholder substitutions → one telemetry frame
|
|
42
|
+
for (const c of content) {
|
|
43
|
+
if (c.type === "text" && typeof c.text === "string") {
|
|
44
|
+
blocks.push({ type: "text", text: c.text });
|
|
45
|
+
}
|
|
46
|
+
else if (c.type === "image" && c.data && c.mimeType) {
|
|
47
|
+
if (supportsVision)
|
|
48
|
+
blocks.push({ type: "image", source: { type: "base64", media_type: c.mimeType, data: c.data } });
|
|
49
|
+
else {
|
|
50
|
+
omitted++;
|
|
51
|
+
blocks.push({ type: "text", text: "[image omitted: the serving model does not support image input]" });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (omitted > 0)
|
|
56
|
+
emitBrainTelemetry({ kind: "vision_placeholder", count: omitted });
|
|
57
|
+
return blocks;
|
|
58
|
+
}
|
|
59
|
+
/** Convert unified messages → Anthropic messages, replaying thinking (with signature) + merging
|
|
60
|
+
* consecutive same-role messages (Anthropic requires strict user/assistant alternation). */
|
|
61
|
+
function toAnthropicMessages(ctx, model) {
|
|
62
|
+
const supportsVision = model?.input === undefined ? true : model.input.includes("image");
|
|
63
|
+
const raw = [];
|
|
64
|
+
// PDF read: document blocks hoisted out of tool_result batches (see the toolResult branch below).
|
|
65
|
+
let pendingDocs = [];
|
|
66
|
+
const flushDocs = () => {
|
|
67
|
+
if (pendingDocs.length === 0)
|
|
68
|
+
return;
|
|
69
|
+
raw.push({ role: "user", content: pendingDocs });
|
|
70
|
+
pendingDocs = [];
|
|
71
|
+
};
|
|
72
|
+
for (const m of ctx.messages) {
|
|
73
|
+
if (m.role !== "toolResult")
|
|
74
|
+
flushDocs();
|
|
75
|
+
if (m.role === "user") {
|
|
76
|
+
raw.push({ role: "user", content: toUserBlocks(m.content, supportsVision) });
|
|
77
|
+
}
|
|
78
|
+
else if (m.role === "assistant") {
|
|
79
|
+
const blocks = [];
|
|
80
|
+
for (const c of m.content) {
|
|
81
|
+
if (c.type === "thinking") {
|
|
82
|
+
const tc = c;
|
|
83
|
+
const sig = tc.thinkingSignature;
|
|
84
|
+
if (tc.redacted) {
|
|
85
|
+
// CC-parity B2: a redacted_thinking block must go back as `{type:"redacted_thinking",data}` with
|
|
86
|
+
// its opaque payload (stored in thinkingSignature). Without this the required block vanishes on
|
|
87
|
+
// replay and Anthropic 400s the continuation of a thinking+tool-use turn.
|
|
88
|
+
if (sig)
|
|
89
|
+
blocks.push({ type: "redacted_thinking", data: sig });
|
|
90
|
+
}
|
|
91
|
+
else if (sig) {
|
|
92
|
+
// Replay normal extended-thinking blocks ONLY with their signature (Anthropic rejects otherwise);
|
|
93
|
+
// a signature-less thinking block (e.g. from another provider) is dropped.
|
|
94
|
+
blocks.push({ type: "thinking", thinking: c.thinking, signature: sig });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else if (c.type === "text" && c.text) {
|
|
98
|
+
blocks.push({ type: "text", text: c.text });
|
|
99
|
+
}
|
|
100
|
+
else if (c.type === "toolCall") {
|
|
101
|
+
blocks.push({ type: "tool_use", id: c.id, name: c.name, input: c.arguments ?? {} });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
raw.push({ role: "assistant", content: blocks.length ? blocks : [{ type: "text", text: NO_CONTENT }] });
|
|
105
|
+
}
|
|
106
|
+
else if (m.role === "toolResult") {
|
|
107
|
+
// design/66 image: the Anthropic API accepts image blocks INSIDE tool_result.content natively
|
|
108
|
+
// (CC messages.ts:2526) — pass blocks through when a tool returned an image. Two CC-parity rules:
|
|
109
|
+
// an is_error tool_result must contain ONLY text (image-in-error 400s forever — messages.ts:2342),
|
|
110
|
+
// and all-text content keeps the legacy string shape.
|
|
111
|
+
// PDF read: `document` blocks do NOT ride inside tool_result — CC (FileReadTool.ts:1000-1016) emits
|
|
112
|
+
// the PDF as a document block on a SEPARATE user message (createUserMessage, isMeta), never inside
|
|
113
|
+
// tool_result content. We buffer them (pendingDocs) and flush AFTER the whole consecutive tool-result
|
|
114
|
+
// batch, so tool_result blocks stay first in the coalesced user message (API ordering constraint) even
|
|
115
|
+
// with parallel PDF reads. In error results documents are sanitized away like images (text-only rule);
|
|
116
|
+
// a no-vision model gets an honest text placeholder + telemetry instead (never a silent drop).
|
|
117
|
+
const parts = Array.isArray(m.content) ? m.content : undefined;
|
|
118
|
+
const docs = parts ? parts.filter((c) => c.type === "document") : [];
|
|
119
|
+
const rest = docs.length > 0 && parts ? parts.filter((c) => c.type !== "document") : m.content;
|
|
120
|
+
const hasImage = !m.isError && Array.isArray(rest) && rest.some((c) => c.type === "image");
|
|
121
|
+
let inner = hasImage ? toUserBlocks(rest, supportsVision) : textOf(rest);
|
|
122
|
+
if (docs.length > 0 && !m.isError) {
|
|
123
|
+
if (supportsVision) {
|
|
124
|
+
for (const d of docs) {
|
|
125
|
+
if (d.data && d.mimeType)
|
|
126
|
+
pendingDocs.push({ type: "document", source: { type: "base64", media_type: d.mimeType, data: d.data } });
|
|
127
|
+
}
|
|
128
|
+
const pointer = "(PDF document attached below)";
|
|
129
|
+
if (typeof inner === "string")
|
|
130
|
+
inner = inner ? `${inner}\n${pointer}` : pointer;
|
|
131
|
+
else
|
|
132
|
+
inner.push({ type: "text", text: pointer });
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
emitBrainTelemetry({ kind: "document_placeholder", count: docs.length });
|
|
136
|
+
const note = DOCUMENT_OMITTED_NO_VISION;
|
|
137
|
+
if (typeof inner === "string")
|
|
138
|
+
inner = inner ? `${inner}\n${note}` : note;
|
|
139
|
+
else
|
|
140
|
+
inner.push({ type: "text", text: note });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
raw.push({
|
|
144
|
+
role: "user",
|
|
145
|
+
content: [
|
|
146
|
+
{
|
|
147
|
+
type: "tool_result",
|
|
148
|
+
tool_use_id: m.toolCallId,
|
|
149
|
+
content: inner,
|
|
150
|
+
...(m.isError ? { is_error: true } : {}),
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
flushDocs();
|
|
157
|
+
// Coalesce consecutive same-role messages (e.g. several tool results in a row).
|
|
158
|
+
const merged = [];
|
|
159
|
+
for (const msg of raw) {
|
|
160
|
+
const prev = merged[merged.length - 1];
|
|
161
|
+
if (prev && prev.role === msg.role) {
|
|
162
|
+
prev.content.push(...msg.content);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
merged.push({ role: msg.role, content: [...msg.content] });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return merged;
|
|
169
|
+
}
|
|
170
|
+
function toAnthropicTools(ctx, cacheBreakpoints) {
|
|
171
|
+
if (!ctx.tools || ctx.tools.length === 0) {
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
174
|
+
return ctx.tools.map((t, i) => ({
|
|
175
|
+
name: t.name,
|
|
176
|
+
description: t.description,
|
|
177
|
+
input_schema: t.parameters,
|
|
178
|
+
...(cacheBreakpoints && i === ctx.tools.length - 1 ? { cache_control: EPHEMERAL } : {}),
|
|
179
|
+
}));
|
|
180
|
+
}
|
|
181
|
+
// CC-parity round-2 B1: Anthropic 400s ("text content blocks must contain non-whitespace text") on an
|
|
182
|
+
// empty/whitespace assistant content block. A non-final empty assistant turn (a clean empty `end_turn`, or a
|
|
183
|
+
// stored `text:""` whose only block was filtered at replay, or a cross-provider signature-less-thinking-only
|
|
184
|
+
// turn) would replay an empty block and DETERMINISTICALLY poison the session (every later request 400s).
|
|
185
|
+
// Substitute a non-empty placeholder at SEND time (mirrors CC's `ensureNonEmptyAssistantContent`,
|
|
186
|
+
// messages.ts:4933 + NO_CONTENT_MESSAGE). Send-time only → the stored message keeps `text:""` (result semantics
|
|
187
|
+
// unchanged); this is the load-bearing catch-all that also covers already-stored/old-session empties.
|
|
188
|
+
const NO_CONTENT = "(no content)";
|
|
189
|
+
function mapStopReason(reason, hadToolUse) {
|
|
190
|
+
if (hadToolUse || reason === "tool_use")
|
|
191
|
+
return "toolUse";
|
|
192
|
+
if (reason === "max_tokens")
|
|
193
|
+
return "length";
|
|
194
|
+
return "stop";
|
|
195
|
+
}
|
|
196
|
+
/** CC-parity B1: map an Anthropic mid-stream error frame's `error.type` to our BrainError code so the
|
|
197
|
+
* failover/breaker/degrading stack classifies it. overloaded_error/api_error and unknowns are transient
|
|
198
|
+
* server errors (retryable, mirroring the SDK's withRetry); auth/rate-limit/invalid are terminal-ish. */
|
|
199
|
+
function anthropicStreamErrorCode(t) {
|
|
200
|
+
switch (t) {
|
|
201
|
+
case "rate_limit_error":
|
|
202
|
+
return "rate_limit";
|
|
203
|
+
case "authentication_error":
|
|
204
|
+
case "permission_error":
|
|
205
|
+
return "auth";
|
|
206
|
+
case "invalid_request_error":
|
|
207
|
+
return "invalid_request";
|
|
208
|
+
default:
|
|
209
|
+
return "server";
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function computeUsage(model, u) {
|
|
213
|
+
const input = u.input_tokens ?? 0;
|
|
214
|
+
const output = u.output_tokens ?? 0;
|
|
215
|
+
const cacheRead = u.cache_read_input_tokens ?? 0;
|
|
216
|
+
const cacheWrite = u.cache_creation_input_tokens ?? 0;
|
|
217
|
+
const c = model.cost;
|
|
218
|
+
const costInput = (input / 1e6) * (c?.input ?? 0);
|
|
219
|
+
const costOutput = (output / 1e6) * (c?.output ?? 0);
|
|
220
|
+
const costCacheRead = (cacheRead / 1e6) * (c?.cacheRead ?? 0);
|
|
221
|
+
const costCacheWrite = (cacheWrite / 1e6) * (c?.cacheWrite ?? 0);
|
|
222
|
+
return {
|
|
223
|
+
input,
|
|
224
|
+
output,
|
|
225
|
+
cacheRead,
|
|
226
|
+
cacheWrite,
|
|
227
|
+
// A-3: cacheRead/cacheWrite occupy the context window too, so they MUST be in totalTokens. Anthropic's
|
|
228
|
+
// `input_tokens` excludes cache (API semantics), and downstream calculateContextTokens short-circuits on
|
|
229
|
+
// a non-zero totalTokens — omitting cache here made the compaction anchor severely underestimate a
|
|
230
|
+
// cache-heavy long task (most prompt is cacheRead) → compaction never fired → provider context overflow.
|
|
231
|
+
totalTokens: input + output + cacheRead + cacheWrite,
|
|
232
|
+
cost: {
|
|
233
|
+
input: costInput,
|
|
234
|
+
output: costOutput,
|
|
235
|
+
cacheRead: costCacheRead,
|
|
236
|
+
cacheWrite: costCacheWrite,
|
|
237
|
+
total: costInput + costOutput + costCacheRead + costCacheWrite,
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* design/120 P2.0: close a streamed tool_use block into a ToolCall. Returns undefined when the block
|
|
243
|
+
* has no name or its accumulated input_json is not a valid JSON object (fail-closed: no `toolcall_end`
|
|
244
|
+
* is emitted for it, so it can never execute in-stream; finalize() then surfaces it via the existing
|
|
245
|
+
* malformed-drop + note path). Idempotent on success (cached); a failure is NOT cached so finalize can
|
|
246
|
+
* retry with the complete accumulation.
|
|
247
|
+
*/
|
|
248
|
+
function closeToolUseBlock(acc) {
|
|
249
|
+
if (acc.closedTc)
|
|
250
|
+
return acc.closedTc;
|
|
251
|
+
if (!acc.toolName)
|
|
252
|
+
return undefined;
|
|
253
|
+
let args;
|
|
254
|
+
if (acc.toolJson) {
|
|
255
|
+
try {
|
|
256
|
+
const parsed = JSON.parse(acc.toolJson);
|
|
257
|
+
// bug-hunt #6 (kept from finalize): a top-level string/array/number/null must fail closed so a
|
|
258
|
+
// non-object never reaches tool.execute / the MCP wire.
|
|
259
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
|
|
260
|
+
return undefined;
|
|
261
|
+
args = parsed;
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
return undefined; // truncated/invalid input_json — finalize's malformed path reports it
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
args = {}; // genuinely a no-argument tool call (empty input_schema)
|
|
269
|
+
}
|
|
270
|
+
if (!acc.toolId)
|
|
271
|
+
acc.toolId = `toolu_${Math.random().toString(36).slice(2)}`;
|
|
272
|
+
acc.closedTc = { type: "toolCall", id: acc.toolId, name: acc.toolName, arguments: args };
|
|
273
|
+
return acc.closedTc;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Create a Brain for the Anthropic Messages API (`/v1/messages`) with **prompt caching** and
|
|
277
|
+
* **extended-thinking replay**. Translates the unified Context into an Anthropic request and the
|
|
278
|
+
* streamed response back into the unified AssistantMessageEvent protocol. The connect/retry/timeout/
|
|
279
|
+
* read-loop machinery lives in the shared {@link runStreamingBrain} engine (design/32); this adapter
|
|
280
|
+
* owns the Anthropic request shaping + typed content-block SSE parsing + finalization.
|
|
281
|
+
*/
|
|
282
|
+
export function createAnthropicBrain(config = {}) {
|
|
283
|
+
const doFetch = config.fetchImpl ?? fetch;
|
|
284
|
+
const cacheBreakpoints = config.cacheBreakpoints !== false;
|
|
285
|
+
const stream = (model, context, options) => {
|
|
286
|
+
// [477] 文案修: whether THIS request actually carried a `thinking` field — set by buildRequest
|
|
287
|
+
// (re-set on every retry attempt), read by finalize() so the truncatedEmpty fail-loud message
|
|
288
|
+
// only suggests thinkingBudgetShare when that knob is actually in play for the request.
|
|
289
|
+
let thinkingRequested = false;
|
|
290
|
+
return runStreamingBrain({
|
|
291
|
+
model,
|
|
292
|
+
doFetch,
|
|
293
|
+
signal: options?.signal,
|
|
294
|
+
config,
|
|
295
|
+
httpLabel: "anthropic",
|
|
296
|
+
buildRequest: () => {
|
|
297
|
+
const apiKey = options?.apiKey ?? config.apiKey;
|
|
298
|
+
const root = (model.baseUrl || config.baseUrl || "https://api.anthropic.com").replace(/\/+$/, "");
|
|
299
|
+
const system = context.systemPrompt
|
|
300
|
+
? [{ type: "text", text: context.systemPrompt, ...(cacheBreakpoints ? { cache_control: EPHEMERAL } : {}) }]
|
|
301
|
+
: undefined;
|
|
302
|
+
const body = {
|
|
303
|
+
model: model.id,
|
|
304
|
+
max_tokens: options?.maxTokens ?? model.maxTokens ?? config.defaultMaxTokens ?? 4096,
|
|
305
|
+
messages: toAnthropicMessages(context, model),
|
|
306
|
+
stream: true,
|
|
307
|
+
};
|
|
308
|
+
if (system)
|
|
309
|
+
body.system = system;
|
|
310
|
+
const tools = toAnthropicTools(context, cacheBreakpoints);
|
|
311
|
+
if (tools)
|
|
312
|
+
body.tools = tools;
|
|
313
|
+
// design/119 (CC 2.1.198 rebaseline): per-endpoint capability bits for the Fable-5 class.
|
|
314
|
+
const anthCompat = (model.compat ?? {});
|
|
315
|
+
// CC 198 sends temperature only to a legacy allowlist — a `supportsTemperature:false` model
|
|
316
|
+
// (Fable-5 class) never receives it, independent of thinking state (sIn semantics, not just
|
|
317
|
+
// the thinking-enabled 400 rule below).
|
|
318
|
+
if (options?.temperature !== undefined && anthCompat.supportsTemperature !== false) {
|
|
319
|
+
body.temperature = options.temperature;
|
|
320
|
+
}
|
|
321
|
+
if (model.reasoning && options?.reasoning && options.reasoning !== "off") {
|
|
322
|
+
// `"off"` is treated as absence (no thinking block). The StreamOptions type excludes "off" and the
|
|
323
|
+
// harness already maps off→undefined, but defend the public primitive: a raw/untyped caller passing
|
|
324
|
+
// the string "off" must NOT enable thinking at the 1024-token floor (the opposite of off). Hence the
|
|
325
|
+
// cast — the guard is belt-and-suspenders against an out-of-contract input, not a type-reachable one.
|
|
326
|
+
// The requested intensity tier sets the budget share so a higher tier actually buys more thinking
|
|
327
|
+
// (design/96 S5: before this, the share was fixed regardless of tier). Explicit config still wins:
|
|
328
|
+
// thinkingBudgetTokens (fixed) > thinkingBudgetShare > tier-derived share > 0.5 default. A non-tier
|
|
329
|
+
// `reasoning` value (legacy boolean/unknown) falls through to the 0.5 default (back-compat).
|
|
330
|
+
if (anthCompat.thinkingMode === "adaptive") {
|
|
331
|
+
// design/119 (CC 198): adaptive-thinking models take `{type:"adaptive"}` with NO
|
|
332
|
+
// budget_tokens (they 400 on a budget) and no max_tokens bump — the intensity rides
|
|
333
|
+
// `output_config.effort` below. `off` stays "omit the field" (these models also reject
|
|
334
|
+
// `{type:"disabled"}`), which is the pre-existing off behavior of this brain.
|
|
335
|
+
body.thinking = { type: "adaptive" };
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
const hardCap = options?.maxTokens !== undefined;
|
|
339
|
+
if (hardCap && body.max_tokens < MIN_THINKING_TOKENS * 2) {
|
|
340
|
+
// design/119 #2 review (codex H4): the caller's explicit per-request output cap is too
|
|
341
|
+
// small to host a legal thinking budget (≥1024) plus answer room — the CAP WINS and
|
|
342
|
+
// thinking is skipped for this request (the alternative silently raised max_tokens above
|
|
343
|
+
// the documented hard bound). Temperature stays (no thinking ⇒ no 400 rule).
|
|
344
|
+
body.thinking = undefined;
|
|
345
|
+
delete body.thinking;
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
const tierShare = isThinkingLevel(options.reasoning) ? reasoningBudgetShare(options.reasoning) : undefined;
|
|
349
|
+
const share = config.thinkingBudgetShare ?? tierShare ?? 0.5;
|
|
350
|
+
const { max, budget } = thinkingBudget(body.max_tokens, share, config.thinkingBudgetTokens, hardCap);
|
|
351
|
+
body.max_tokens = max;
|
|
352
|
+
body.thinking = { type: "enabled", budget_tokens: budget };
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
// CC-parity round-3: Anthropic 400s `temperature != 1` when extended thinking is enabled. A caller
|
|
356
|
+
// setting a non-1 temperature (e.g. `temperature: 0` for determinism) on a reasoning model would 400
|
|
357
|
+
// EVERY request. Drop it here (the API's only legal value under thinking is 1, which it defaults to) —
|
|
358
|
+
// mirrors CC claude.ts (`temperature = !hasThinking ? (override ?? 1) : undefined`). The non-thinking
|
|
359
|
+
// path keeps the caller's temperature (set at :293 above).
|
|
360
|
+
if (body.thinking !== undefined)
|
|
361
|
+
delete body.temperature;
|
|
362
|
+
}
|
|
363
|
+
// design/119 (CC 198): effort is ORTHOGONAL to thinking form — an endpoint that declares
|
|
364
|
+
// `effortLevels` carries the requested intensity as `output_config.effort` (string tier) plus
|
|
365
|
+
// the `effort-2025-11-24` beta. Clamped DOWN into the declared set with the same resolver the
|
|
366
|
+
// `reasoning.resolved` trace uses (resolveReasoning format:"effort"), so trace and wire can't
|
|
367
|
+
// drift. `minimal` isn't a wire tier — it clamps to the lowest declared level. Thinking `off`
|
|
368
|
+
// sends no output_config (intensity of nothing).
|
|
369
|
+
const betas = [];
|
|
370
|
+
let sendEffortBeta = false;
|
|
371
|
+
if (anthCompat.effortLevels &&
|
|
372
|
+
anthCompat.effortLevels.length > 0 &&
|
|
373
|
+
model.reasoning &&
|
|
374
|
+
options?.reasoning &&
|
|
375
|
+
options.reasoning !== "off" &&
|
|
376
|
+
isThinkingLevel(options.reasoning)) {
|
|
377
|
+
const { effective } = resolveEffort(options.reasoning, anthCompat.effortLevels.filter(isThinkingLevel));
|
|
378
|
+
const wireEffort = effective === "minimal" ? "low" : effective;
|
|
379
|
+
body.output_config = { effort: wireEffort };
|
|
380
|
+
sendEffortBeta = true;
|
|
381
|
+
}
|
|
382
|
+
if (sendEffortBeta)
|
|
383
|
+
betas.push("effort-2025-11-24");
|
|
384
|
+
// design/119 S4: context_management (declared endpoints only) — with thinking enabled, tell
|
|
385
|
+
// the server to KEEP all thinking blocks (opt-out of default clearing; cross-turn reasoning
|
|
386
|
+
// continuity, CC vhc :591212). Response-side applied_edits is not consumed (CC doesn't either).
|
|
387
|
+
if (anthCompat.contextManagement && body.thinking !== undefined) {
|
|
388
|
+
body.context_management = { edits: [{ type: "clear_thinking_20251015", keep: "all" }] };
|
|
389
|
+
betas.push("context-management-2025-06-27");
|
|
390
|
+
}
|
|
391
|
+
// design/119 S4: interleaved thinking beta — CC 198 attaches it whenever the model supports it
|
|
392
|
+
// (kzr :132494 gates only on the capability + a disable env; no tools/thinking condition), so a
|
|
393
|
+
// declared endpoint gets it unconditionally.
|
|
394
|
+
if (anthCompat.interleavedThinking) {
|
|
395
|
+
betas.push("interleaved-thinking-2025-05-14");
|
|
396
|
+
}
|
|
397
|
+
// User-supplied headers augment; structural + auth headers hard-locked AFTER (council design/40).
|
|
398
|
+
const headers = {
|
|
399
|
+
...model.headers,
|
|
400
|
+
...config.headers,
|
|
401
|
+
...options?.headers,
|
|
402
|
+
};
|
|
403
|
+
if (betas.length > 0) {
|
|
404
|
+
const existing = (headers["anthropic-beta"] ?? "").split(",").map((b) => b.trim()).filter(Boolean);
|
|
405
|
+
for (const beta of betas) {
|
|
406
|
+
if (!existing.includes(beta))
|
|
407
|
+
existing.push(beta);
|
|
408
|
+
}
|
|
409
|
+
headers["anthropic-beta"] = existing.join(",");
|
|
410
|
+
}
|
|
411
|
+
headers["content-type"] = "application/json";
|
|
412
|
+
headers["anthropic-version"] = config.version ?? "2023-06-01";
|
|
413
|
+
if (apiKey)
|
|
414
|
+
headers["x-api-key"] = apiKey;
|
|
415
|
+
// [477]: record whether the outgoing body carries a thinking field (per attempt — a retry
|
|
416
|
+
// rebuilds the request and re-evaluates; the value is identical for a same-shape retry).
|
|
417
|
+
thinkingRequested = body.thinking !== undefined;
|
|
418
|
+
return { url: `${root}/v1/messages`, headers, body: JSON.stringify(applyExtraBody(body, model.extraBody, ANTHROPIC_RESERVED)) };
|
|
419
|
+
},
|
|
420
|
+
makeParser: (ctrl) => {
|
|
421
|
+
const { out, partial } = ctrl;
|
|
422
|
+
const blocks = new Map();
|
|
423
|
+
const usageRaw = {};
|
|
424
|
+
let stopReason = null;
|
|
425
|
+
let stopDetails;
|
|
426
|
+
let nextContentIndex = 0;
|
|
427
|
+
let degenerate = false; // tripped if the model loops on the same char/phrase forever
|
|
428
|
+
// Repetition telemetry (clay 2026-07-10): the cut event + allowance-spared hits for THIS stream.
|
|
429
|
+
// Polls re-inspect the same growing text every ~64 chars — dedupe spared by rule+segment so one
|
|
430
|
+
// boot block doesn't log once per poll. Attached to the final message as `repetition`.
|
|
431
|
+
let repCut;
|
|
432
|
+
const repSpared = new Map();
|
|
433
|
+
const pollRepetition = (text) => {
|
|
434
|
+
const insp = inspectDegenerate(text);
|
|
435
|
+
for (const s of insp.spared) {
|
|
436
|
+
const k = `${s.rule} ${s.segment}`;
|
|
437
|
+
const prev = repSpared.get(k);
|
|
438
|
+
if (prev === undefined)
|
|
439
|
+
repSpared.set(k, s);
|
|
440
|
+
else if (s.reps > prev.reps)
|
|
441
|
+
prev.reps = s.reps; // keep the loop's PEAK depth across polls
|
|
442
|
+
}
|
|
443
|
+
if (insp.degenerate)
|
|
444
|
+
repCut = insp.cut;
|
|
445
|
+
return insp.degenerate;
|
|
446
|
+
};
|
|
447
|
+
// design/130 P2b: tripped when the wall clock crossed the soft per-call deadline — a
|
|
448
|
+
// DELIBERATE cut like `degenerate` (salvage the prefix; the loop drives a write-out turn).
|
|
449
|
+
let walltimeCut = false;
|
|
450
|
+
const callDeadlineMs = options?.callDeadlineMs;
|
|
451
|
+
let lastDegenCheck = 0;
|
|
452
|
+
let lastDegenCheckThinking = 0; // bug-hunt #4: separate cursor for the thinking block
|
|
453
|
+
const detectRep = config.detectRepetition !== false;
|
|
454
|
+
const handleEvent = (evt) => {
|
|
455
|
+
switch (evt.type) {
|
|
456
|
+
case "message_start": {
|
|
457
|
+
const u = evt.message?.usage;
|
|
458
|
+
if (u) {
|
|
459
|
+
usageRaw.input_tokens = u.input_tokens;
|
|
460
|
+
usageRaw.cache_read_input_tokens = u.cache_read_input_tokens;
|
|
461
|
+
usageRaw.cache_creation_input_tokens = u.cache_creation_input_tokens;
|
|
462
|
+
}
|
|
463
|
+
break;
|
|
464
|
+
}
|
|
465
|
+
case "content_block_start": {
|
|
466
|
+
ctrl.sawContentToken(); // a block opened (thinking/text/tool_use) — the gateway is producing
|
|
467
|
+
const idx = evt.index;
|
|
468
|
+
const cb = evt.content_block;
|
|
469
|
+
const acc = { type: "text", text: "", signature: "", toolId: "", toolName: "", toolJson: "" };
|
|
470
|
+
if (cb.type === "thinking" || cb.type === "redacted_thinking") {
|
|
471
|
+
acc.type = "thinking";
|
|
472
|
+
// CC-parity B2: a redacted_thinking block carries no deltas — its whole payload is `cb.data`
|
|
473
|
+
// delivered at block_start. Stash it in `signature` (the replay carrier) + mark redacted, so
|
|
474
|
+
// finalize emits it with the payload preserved and replay sends it back as redacted_thinking.
|
|
475
|
+
if (cb.type === "redacted_thinking") {
|
|
476
|
+
acc.redacted = true;
|
|
477
|
+
acc.signature = cb.data ?? "";
|
|
478
|
+
}
|
|
479
|
+
acc.pb = { type: "thinking", thinking: "" };
|
|
480
|
+
partial.content = [acc.pb];
|
|
481
|
+
out.push({ type: "thinking_start", contentIndex: idx, partial: { ...partial } });
|
|
482
|
+
}
|
|
483
|
+
else if (cb.type === "tool_use") {
|
|
484
|
+
acc.type = "tool_use";
|
|
485
|
+
acc.toolId = cb.id ?? "";
|
|
486
|
+
acc.toolName = cb.name ?? "";
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
acc.type = "text";
|
|
490
|
+
acc.pb = { type: "text", text: "" };
|
|
491
|
+
partial.content = [acc.pb];
|
|
492
|
+
out.push({ type: "text_start", contentIndex: idx, partial: { ...partial } });
|
|
493
|
+
}
|
|
494
|
+
blocks.set(idx, acc);
|
|
495
|
+
nextContentIndex = Math.max(nextContentIndex, idx + 1);
|
|
496
|
+
break;
|
|
497
|
+
}
|
|
498
|
+
case "content_block_delta": {
|
|
499
|
+
ctrl.sawContentToken();
|
|
500
|
+
const idx = evt.index;
|
|
501
|
+
const acc = blocks.get(idx);
|
|
502
|
+
if (!acc)
|
|
503
|
+
break;
|
|
504
|
+
const d = evt.delta;
|
|
505
|
+
if (d.type === "text_delta" && d.text) {
|
|
506
|
+
acc.text += d.text;
|
|
507
|
+
if (acc.pb && acc.pb.type === "text")
|
|
508
|
+
acc.pb.text = acc.text;
|
|
509
|
+
out.push({ type: "text_delta", contentIndex: idx, delta: d.text, partial: { ...partial } });
|
|
510
|
+
// Poll for degenerate repetition (~every 64 chars); on a hit, cancel the stream (read loop ends).
|
|
511
|
+
if (detectRep && !degenerate && acc.text.length - lastDegenCheck >= 64) {
|
|
512
|
+
lastDegenCheck = acc.text.length;
|
|
513
|
+
if (pollRepetition(acc.text)) {
|
|
514
|
+
degenerate = true;
|
|
515
|
+
ctrl.cancel();
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
else if (d.type === "thinking_delta" && d.thinking) {
|
|
520
|
+
acc.text += d.thinking;
|
|
521
|
+
if (acc.pb && acc.pb.type === "thinking")
|
|
522
|
+
acc.pb.thinking = acc.text;
|
|
523
|
+
out.push({ type: "thinking_delta", contentIndex: idx, delta: d.thinking, partial: { ...partial } });
|
|
524
|
+
// bug-hunt #4: a reasoning model can loop forever inside the thinking block with no answer.
|
|
525
|
+
// The text path polls looksDegenerate; mirror it for thinking (separate cursor) so a looping
|
|
526
|
+
// extended-thinking turn is cut cheaply instead of running to the timeout.
|
|
527
|
+
if (detectRep && !degenerate && acc.text.length - lastDegenCheckThinking >= 64) {
|
|
528
|
+
lastDegenCheckThinking = acc.text.length;
|
|
529
|
+
if (pollRepetition(acc.text)) {
|
|
530
|
+
degenerate = true;
|
|
531
|
+
ctrl.cancel();
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
else if (d.type === "signature_delta" && d.signature) {
|
|
536
|
+
acc.signature += d.signature;
|
|
537
|
+
}
|
|
538
|
+
else if (d.type === "input_json_delta" && d.partial_json) {
|
|
539
|
+
acc.toolJson += d.partial_json;
|
|
540
|
+
}
|
|
541
|
+
break;
|
|
542
|
+
}
|
|
543
|
+
case "content_block_stop": {
|
|
544
|
+
const idx = evt.index;
|
|
545
|
+
const acc = blocks.get(idx);
|
|
546
|
+
if (acc)
|
|
547
|
+
acc.stopped = true; // design/124: sealForRetry() must not double-close this block
|
|
548
|
+
if (acc?.type === "thinking") {
|
|
549
|
+
out.push({ type: "thinking_end", contentIndex: idx, content: acc.text, partial: { ...partial } });
|
|
550
|
+
}
|
|
551
|
+
else if (acc?.type === "text") {
|
|
552
|
+
out.push({ type: "text_end", contentIndex: idx, content: acc.text, partial: { ...partial } });
|
|
553
|
+
}
|
|
554
|
+
else if (acc?.type === "tool_use") {
|
|
555
|
+
// design/120 P2.0: the block's input_json is complete — emit `toolcall_end` NOW so an
|
|
556
|
+
// in-stream tool executor (agent-loop P2) can start the call while the model is still
|
|
557
|
+
// streaming. Fail-closed: a malformed close emits nothing (the call can never execute
|
|
558
|
+
// in-stream) and finalize()'s malformed-drop + note path reports it as before. Provider
|
|
559
|
+
// contract (llm/types.ts): every emitted toolcall_end's call appears in the `done`
|
|
560
|
+
// message's content — guaranteed here because finalize() reuses the cached closedTc.
|
|
561
|
+
const tc = closeToolUseBlock(acc);
|
|
562
|
+
if (tc) {
|
|
563
|
+
out.push({ type: "toolcall_end", contentIndex: idx, toolCall: tc, partial: { ...partial } });
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
break;
|
|
567
|
+
}
|
|
568
|
+
case "message_delta": {
|
|
569
|
+
const d = evt.delta;
|
|
570
|
+
if (d?.stop_reason)
|
|
571
|
+
stopReason = d.stop_reason;
|
|
572
|
+
// design/119 S4 (CC 198 :593078): a refusal carries stop_details{category,explanation} —
|
|
573
|
+
// capture for diagnostics so the caller can distinguish refusal classes (cyber/AUP) and
|
|
574
|
+
// build refusal-failover policy. Dropped before = fail-closed but opaque.
|
|
575
|
+
if (d?.stop_details)
|
|
576
|
+
stopDetails = d.stop_details;
|
|
577
|
+
// CC-parity round-2 B2: the closing `message_delta` carries the final `output_tokens` AND may
|
|
578
|
+
// CORRECT the input/cache counts set at `message_start`. We used to read ONLY output_tokens (a
|
|
579
|
+
// narrow cast), discarding a non-zero cache/input refinement → wrong cost + a cache-break
|
|
580
|
+
// false-signal downstream (computeUsage feeds usageCostMicroUsd + the cache-break detector).
|
|
581
|
+
// Merge all four like CC's `updateUsage` (claude.ts), guarding input/cache with `> 0` so a
|
|
582
|
+
// delta-0 (the common case: Anthropic emits 0 for unchanged fields) never clobbers message_start.
|
|
583
|
+
const u = evt.usage;
|
|
584
|
+
if (u) {
|
|
585
|
+
if (u.output_tokens !== undefined)
|
|
586
|
+
usageRaw.output_tokens = u.output_tokens;
|
|
587
|
+
if (u.input_tokens != null && u.input_tokens > 0)
|
|
588
|
+
usageRaw.input_tokens = u.input_tokens;
|
|
589
|
+
if (u.cache_read_input_tokens != null && u.cache_read_input_tokens > 0) {
|
|
590
|
+
usageRaw.cache_read_input_tokens = u.cache_read_input_tokens;
|
|
591
|
+
}
|
|
592
|
+
if (u.cache_creation_input_tokens != null && u.cache_creation_input_tokens > 0) {
|
|
593
|
+
usageRaw.cache_creation_input_tokens = u.cache_creation_input_tokens;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
break;
|
|
597
|
+
}
|
|
598
|
+
case "error": {
|
|
599
|
+
// CC-parity B1: Anthropic emits a mid-stream `{type:"error",error:{type,message}}` frame AFTER
|
|
600
|
+
// the 200 OK (e.g. overloaded_error/api_error during generation). The official SDK THROWS on it
|
|
601
|
+
// (→ CC retries via withRetry); our parser used to fall through to the default no-op and
|
|
602
|
+
// finalize() reported the partial content as a clean `stop` SUCCESS — a silent false-negative
|
|
603
|
+
// with no retry. Throw a coded BrainError: it propagates out of onLine → runStreamingBrain's
|
|
604
|
+
// catch → a `[code]`-prefixed error event that the failover/breaker/degrading stack classifies
|
|
605
|
+
// (transient overloaded/api → server → retried). design/124 r3 (CC 2.1.199): the ENGINE
|
|
606
|
+
// may downgrade an overload-class ("server") frame to a tier-A partial finalize when
|
|
607
|
+
// substantive text already streamed; every other class stays fail-closed (B1).
|
|
608
|
+
const e = evt.error;
|
|
609
|
+
throw new BrainError(anthropicStreamErrorCode(e?.type), `anthropic stream error (${e?.type ?? "unknown"}): ${e?.message ?? ""}`);
|
|
610
|
+
}
|
|
611
|
+
default:
|
|
612
|
+
break; // ping / message_stop / unknown
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
return {
|
|
616
|
+
// design/124 §0.5-2: tiering introspection — direct reads off the accumulated blocks. A
|
|
617
|
+
// redacted_thinking block (payload delivered whole at block_start, no deltas) counts as
|
|
618
|
+
// thinking streamed; a tool_use block only counts as completed once it CLOSED successfully
|
|
619
|
+
// (closedTc cached ⟺ its toolcall_end was emitted at content_block_stop).
|
|
620
|
+
snapshot() {
|
|
621
|
+
const accs = [...blocks.values()];
|
|
622
|
+
const hasSubstantiveText = accs.some((a) => a.type === "text" && a.text.trim() !== "");
|
|
623
|
+
const hasCompletedToolCall = accs.some((a) => a.closedTc !== undefined);
|
|
624
|
+
const hasThinking = accs.some((a) => a.type === "thinking" && (a.text.length > 0 || a.redacted === true));
|
|
625
|
+
return {
|
|
626
|
+
hasSubstantiveText,
|
|
627
|
+
hasCompletedToolCall,
|
|
628
|
+
hasOnlyThinking: hasThinking && !hasSubstantiveText && !hasCompletedToolCall,
|
|
629
|
+
};
|
|
630
|
+
},
|
|
631
|
+
// design/124 tier B: emit `thinking_end` for every thinking block still OPEN (no
|
|
632
|
+
// content_block_stop seen) so the UI stream is sealed before the whole turn is re-sent.
|
|
633
|
+
// Idempotent (marks the block stopped).
|
|
634
|
+
sealForRetry() {
|
|
635
|
+
for (const [idx, acc] of [...blocks.entries()].sort((a, b) => a[0] - b[0])) {
|
|
636
|
+
if (acc.type === "thinking" && !acc.stopped) {
|
|
637
|
+
acc.stopped = true;
|
|
638
|
+
out.push({ type: "thinking_end", contentIndex: idx, content: acc.text, partial: { ...partial } });
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
},
|
|
642
|
+
onLine(rawLine) {
|
|
643
|
+
// design/130 P2b: poll the soft call deadline once per provider chunk (cheap — one
|
|
644
|
+
// Date.now()). Crossing it cancels the stream deliberately; the salvage below keeps
|
|
645
|
+
// the prefix and the sentinel errorMessage drives the loop's bounded write-out turn.
|
|
646
|
+
// (A fully-stalled stream emits no chunks — the engine's idle watchdog owns that case.)
|
|
647
|
+
if (callDeadlineMs !== undefined && !walltimeCut && !degenerate && Date.now() >= callDeadlineMs) {
|
|
648
|
+
walltimeCut = true;
|
|
649
|
+
ctrl.cancel();
|
|
650
|
+
return; // codex HIGH: do NOT parse the triggering chunk — its delta must not join the salvage
|
|
651
|
+
}
|
|
652
|
+
if (walltimeCut)
|
|
653
|
+
return; // any residual buffered line after the cut is equally dropped
|
|
654
|
+
const line = rawLine.trim();
|
|
655
|
+
if (!line.startsWith("data:"))
|
|
656
|
+
return; // ignore `event:` lines; data: carries the JSON
|
|
657
|
+
const data = line.slice(5).trim();
|
|
658
|
+
if (!data)
|
|
659
|
+
return;
|
|
660
|
+
let evt;
|
|
661
|
+
try {
|
|
662
|
+
evt = JSON.parse(data);
|
|
663
|
+
}
|
|
664
|
+
catch {
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
handleEvent(evt);
|
|
668
|
+
},
|
|
669
|
+
finalize() {
|
|
670
|
+
// --- assemble final message, preserving block order (thinking → text → tool_use) ---
|
|
671
|
+
const finalContent = [];
|
|
672
|
+
const toolCalls = [];
|
|
673
|
+
const malformed = [];
|
|
674
|
+
let anyText = false;
|
|
675
|
+
// [477]: reasoning OBSERVED on this stream (a non-empty or redacted thinking block) —
|
|
676
|
+
// the brain-local equivalent of the runner's callCapRef.reasoningObserved, decided from
|
|
677
|
+
// what actually streamed so it needs no cross-layer plumbing.
|
|
678
|
+
let reasoningSeen = false;
|
|
679
|
+
for (const [, acc] of [...blocks.entries()].sort((a, b) => a[0] - b[0])) {
|
|
680
|
+
if (acc.type === "thinking") {
|
|
681
|
+
if (acc.text.length > 0 || acc.redacted === true)
|
|
682
|
+
reasoningSeen = true;
|
|
683
|
+
const block = { type: "thinking", thinking: acc.text };
|
|
684
|
+
if (acc.signature)
|
|
685
|
+
block.thinkingSignature = acc.signature; // store for replay
|
|
686
|
+
if (acc.redacted)
|
|
687
|
+
block.redacted = true; // CC-parity B2: round-trips as redacted_thinking
|
|
688
|
+
finalContent.push(block);
|
|
689
|
+
}
|
|
690
|
+
else if (acc.type === "text") {
|
|
691
|
+
if (acc.text) {
|
|
692
|
+
finalContent.push({ type: "text", text: acc.text });
|
|
693
|
+
if (acc.text.trim())
|
|
694
|
+
anyText = true;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
else if (acc.type === "tool_use" && acc.toolName) {
|
|
698
|
+
// design/120 P2.0: parse/id logic lives in closeToolUseBlock (shared with the in-stream
|
|
699
|
+
// `toolcall_end` emission at content_block_stop — same parse discipline, same cached
|
|
700
|
+
// ToolCall object, so the streamed id and the final content id can never diverge).
|
|
701
|
+
const tc = closeToolUseBlock(acc);
|
|
702
|
+
if (tc) {
|
|
703
|
+
toolCalls.push(tc);
|
|
704
|
+
finalContent.push(tc);
|
|
705
|
+
}
|
|
706
|
+
else {
|
|
707
|
+
// Truncated/invalid input_json (common on stop_reason="max_tokens") or a non-object
|
|
708
|
+
// top level. Do NOT execute the tool with empty `{}` — surface it instead.
|
|
709
|
+
malformed.push(`${acc.toolName}(${acc.toolJson.slice(0, 200)})`);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
const doneReason = mapStopReason(stopReason, toolCalls.length > 0);
|
|
714
|
+
const noUsableContent = toolCalls.length === 0 && !anyText;
|
|
715
|
+
const toolError = malformed.length > 0
|
|
716
|
+
? `tool call argument(s) not valid JSON (likely truncated, stop_reason="${stopReason ?? "?"}"): ${malformed.join("; ")}`
|
|
717
|
+
: undefined;
|
|
718
|
+
// bug-hunt #2: a partial tool batch (valid call + a truncated one). Keep executing the valid
|
|
719
|
+
// call (a brain error is a terminal task failure here), but make the dropped call VISIBLE so the
|
|
720
|
+
// model re-issues it — it otherwise vanished silently (errorMessage rode the `done` event).
|
|
721
|
+
// Emit the note whenever ANY call was malformed — INCLUDING text + all-calls-truncated (the
|
|
722
|
+
// `toolCalls.length > 0` guard left that silent → clean `done`, loop ended the task prematurely).
|
|
723
|
+
if (toolError !== undefined) {
|
|
724
|
+
finalContent.push({
|
|
725
|
+
type: "text",
|
|
726
|
+
text: `\n[note: ${malformed.length} tool call(s) were truncated (stop_reason="${stopReason ?? "?"}") and dropped — re-issue them next turn: ${malformed.join("; ")}]`,
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
const truncatedEmpty = stopReason === "max_tokens" && noUsableContent && !toolError;
|
|
730
|
+
// service [405] P0: dynamic-cap truncation is the ENGINE's own doing — recoverable
|
|
731
|
+
// `length` stop, not the static-config fail-loud error (see openai.ts, same discipline).
|
|
732
|
+
const dynamicCut = truncatedEmpty && options?.maxTokensDynamic === true;
|
|
733
|
+
// Blackboard [477] — the STATIC leg of the [405] family: a budget-ignoring thinking
|
|
734
|
+
// model (Qwen anthropic 形态) burns the whole STATIC max_tokens on one long thought →
|
|
735
|
+
// truncatedEmpty used to fail loud even though the loop's reasoning-cut continue nudge
|
|
736
|
+
// recovers this shape verbatim. Downgrade to a recoverable `length` ONLY when (a) the
|
|
737
|
+
// stream actually carried reasoning (a no-reasoning truncatedEmpty is still a genuine
|
|
738
|
+
// config bug — fail loud, unchanged) and (b) the caller opted in for THIS call (the loop
|
|
739
|
+
// grants it while its 2-per-run stop-loss budget lasts; direct callers like the
|
|
740
|
+
// compaction summarizer never grant it, keeping their length_empty escalation contract).
|
|
741
|
+
const staticReasoningCut = truncatedEmpty && !dynamicCut && reasoningSeen && options?.staticReasoningCutDowngrade === true;
|
|
742
|
+
// bug-hunt #3: a provider SAFETY cut (Anthropic stop_reason="refusal") — `mapStopReason`
|
|
743
|
+
// collapsed it to a clean "stop", reporting a refused/compromised turn as success. Fail closed.
|
|
744
|
+
const safetyCut = stopReason === "refusal";
|
|
745
|
+
// design/119 (CC 198): 4.5+ models can end a 200 stream with
|
|
746
|
+
// stop_reason="model_context_window_exceeded" — the context no longer fits. Mapping it to
|
|
747
|
+
// a clean "stop" would report a silently-incomplete turn as success AND bypass the loop's
|
|
748
|
+
// prompt-too-long recovery. Fail closed as an error whose message the PTL classifier
|
|
749
|
+
// matches (agent-loop PROMPT_TOO_LONG_RE), so a wired recovery can compact and retry.
|
|
750
|
+
const contextWindowExceeded = stopReason === "model_context_window_exceeded";
|
|
751
|
+
// bug-hunt #8: a conforming stream always sends a message_delta stop_reason. No content AND no
|
|
752
|
+
// stop_reason ⇒ a torn stream / swallowed error frame — must not be an empty "stop" success.
|
|
753
|
+
const emptyNoFinish = noUsableContent && stopReason == null && !degenerate && !walltimeCut;
|
|
754
|
+
// P2b: `walltimeCut` wins the whole chain — the cut is OURS (deliberate, wall-clock), so no
|
|
755
|
+
// downstream cause may re-attribute it; the sentinel must survive verbatim for the loop's
|
|
756
|
+
// write-out recovery + the assembler's timeout-with-salvage mapping.
|
|
757
|
+
// `degenerate` wins over `toolError` (design/39 + council): the loop is the root cause, so
|
|
758
|
+
// `DEGENERATE_MESSAGE` must survive for the assembler to map it to `output.degenerate` + salvage.
|
|
759
|
+
// `toolError` is INTENTIONALLY ahead of `emptyNoFinish` (cross-model review): on the rare collision
|
|
760
|
+
// the tool-error string is more specific (names the tool, signals the missing close via `?`).
|
|
761
|
+
const errorMessage = walltimeCut
|
|
762
|
+
? WALLTIME_CUTOFF_MESSAGE
|
|
763
|
+
: degenerate
|
|
764
|
+
? DEGENERATE_MESSAGE
|
|
765
|
+
: safetyCut
|
|
766
|
+
? `response refused by the model (stop_reason="refusal"${stopDetails?.category ? `, category="${stopDetails.category}"` : ""}) — ${stopDetails?.explanation ?? "the output was withheld for policy and is unreliable"}`
|
|
767
|
+
: contextWindowExceeded
|
|
768
|
+
? `[invalid_request] model context window exceeded (stop_reason="model_context_window_exceeded") — the conversation no longer fits the model's context window`
|
|
769
|
+
: (toolError ??
|
|
770
|
+
(truncatedEmpty && !dynamicCut && !staticReasoningCut
|
|
771
|
+
// [477] 文案修: only suggest the knobs that are actually in play. A request that
|
|
772
|
+
// never carried a thinking field must not point at thinkingBudgetShare.
|
|
773
|
+
? thinkingRequested
|
|
774
|
+
? `response truncated at max_tokens with no answer text — extended thinking likely consumed the entire budget; raise max_tokens or lower thinkingBudgetShare`
|
|
775
|
+
: reasoningSeen
|
|
776
|
+
? `response truncated at max_tokens with no answer text — the model emitted reasoning although no thinking was requested (a budget-ignoring gateway?) and it consumed the entire output budget; raise max_tokens`
|
|
777
|
+
: `response truncated at max_tokens with no answer text; raise max_tokens`
|
|
778
|
+
: emptyNoFinish
|
|
779
|
+
? `model stream ended with no content and no stop_reason — the response was lost (a torn stream or an in-band provider error frame)`
|
|
780
|
+
: undefined));
|
|
781
|
+
const errored = walltimeCut ||
|
|
782
|
+
degenerate ||
|
|
783
|
+
safetyCut ||
|
|
784
|
+
contextWindowExceeded ||
|
|
785
|
+
emptyNoFinish ||
|
|
786
|
+
(toolError !== undefined && noUsableContent) ||
|
|
787
|
+
(truncatedEmpty && !dynamicCut && !staticReasoningCut);
|
|
788
|
+
// Structured cause, mirroring the errorMessage precedence chain: tagged ONLY when truncatedEmpty
|
|
789
|
+
// is the selected cause, so callers can escalate max_tokens without parsing prose.
|
|
790
|
+
const errorKind = !walltimeCut && !degenerate && !safetyCut && toolError === undefined && truncatedEmpty && !dynamicCut && !staticReasoningCut
|
|
791
|
+
? "length_empty"
|
|
792
|
+
: undefined;
|
|
793
|
+
const finalMessage = {
|
|
794
|
+
...partial,
|
|
795
|
+
content: finalContent.length > 0 ? finalContent : [{ type: "text", text: "" }],
|
|
796
|
+
stopReason: errored ? "error" : doneReason,
|
|
797
|
+
usage: computeUsage(model, usageRaw),
|
|
798
|
+
...(Object.keys(usageRaw).length === 0 ? { usageMissing: true } : {}), // T1-5: no provider frame → UNKNOWN
|
|
799
|
+
timestamp: Date.now(),
|
|
800
|
+
...(errorMessage ? { errorMessage } : {}),
|
|
801
|
+
...(errorKind ? { errorKind } : {}),
|
|
802
|
+
// Repetition telemetry: cut event + allowance-spared hits (deduped) observed on this stream.
|
|
803
|
+
...(repCut !== undefined || repSpared.size > 0
|
|
804
|
+
? { repetition: { ...(repCut !== undefined ? { cut: repCut } : {}), ...(repSpared.size > 0 ? { spared: [...repSpared.values()] } : {}) } }
|
|
805
|
+
: {}),
|
|
806
|
+
// [477]: tag the downgraded turn so the loop can count it against the 2-per-run stop-loss.
|
|
807
|
+
...(staticReasoningCut ? { staticReasoningCut: true } : {}),
|
|
808
|
+
...(stopDetails
|
|
809
|
+
? {
|
|
810
|
+
diagnostics: [
|
|
811
|
+
...(partial.diagnostics ?? []),
|
|
812
|
+
{ type: "stop_details", timestamp: Date.now(), details: { ...stopDetails } },
|
|
813
|
+
],
|
|
814
|
+
}
|
|
815
|
+
: {}),
|
|
816
|
+
};
|
|
817
|
+
if (errored) {
|
|
818
|
+
out.push({ type: "error", reason: "error", error: finalMessage });
|
|
819
|
+
}
|
|
820
|
+
else {
|
|
821
|
+
out.push({ type: "done", reason: doneReason, message: finalMessage });
|
|
822
|
+
}
|
|
823
|
+
},
|
|
824
|
+
};
|
|
825
|
+
},
|
|
826
|
+
});
|
|
827
|
+
};
|
|
828
|
+
return { stream };
|
|
829
|
+
}
|
|
830
|
+
//# sourceMappingURL=anthropic.js.map
|