@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,784 @@
|
|
|
1
|
+
import {} from "../internal/llm.js";
|
|
2
|
+
import { repairTextToolCalls } from "./tool-call-repair.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 { OPENAI_RESERVED, applyExtraBody } from "./request-params.js";
|
|
7
|
+
import { DEFAULT_EFFORT_LEVELS, isThinkingLevel, resolveEffort } from "./reasoning.js";
|
|
8
|
+
import { runStreamingBrain } from "./stream-engine.js";
|
|
9
|
+
/**
|
|
10
|
+
* design/120 P2.0: close an accumulated tool_calls slot into a ToolCall. Returns undefined when the
|
|
11
|
+
* slot has no name or its accumulated arguments are not a valid JSON object (fail-closed: no
|
|
12
|
+
* `toolcall_end` is emitted, the call can never execute in-stream; finalize() then either retries —
|
|
13
|
+
* more deltas may have arrived — or surfaces it via the existing malformed-drop + note path).
|
|
14
|
+
* Idempotent on success (cached); a failure is NOT cached.
|
|
15
|
+
*/
|
|
16
|
+
function closeToolCallAccum(acc) {
|
|
17
|
+
if (acc.closedTc)
|
|
18
|
+
return acc.closedTc;
|
|
19
|
+
if (!acc.name)
|
|
20
|
+
return undefined;
|
|
21
|
+
let args;
|
|
22
|
+
if (acc.args) {
|
|
23
|
+
try {
|
|
24
|
+
const parsed = JSON.parse(acc.args);
|
|
25
|
+
// bug-hunt #6 (kept from finalize): a top-level string/array/number/null must fail closed so a
|
|
26
|
+
// non-object never reaches tool.execute / the MCP wire.
|
|
27
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
|
|
28
|
+
return undefined;
|
|
29
|
+
args = parsed;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
args = {}; // genuinely a no-argument tool call
|
|
37
|
+
}
|
|
38
|
+
if (!acc.id)
|
|
39
|
+
acc.id = `call_${Math.random().toString(36).slice(2)}`;
|
|
40
|
+
acc.closedTc = { type: "toolCall", id: acc.id, name: acc.name, arguments: args };
|
|
41
|
+
return acc.closedTc;
|
|
42
|
+
}
|
|
43
|
+
function textOf(content) {
|
|
44
|
+
if (typeof content === "string") {
|
|
45
|
+
return content;
|
|
46
|
+
}
|
|
47
|
+
return content
|
|
48
|
+
.filter((c) => c.type === "text" && typeof c.text === "string")
|
|
49
|
+
.map((c) => c.text)
|
|
50
|
+
.join("");
|
|
51
|
+
}
|
|
52
|
+
/** TB 战线逮的真 bug(pytorch-model-cli:模型 Read 了 /app/image.png → 我们塞 image_url → DeepSeek
|
|
53
|
+
* 纯文本 API 400 拒收,任务当场死):当 SERVING model 声明无视觉(`Model.input` 不含 "image")时,
|
|
54
|
+
* 图像部件降级为文本占位符,绝不发 image_url/image block。model 元数据缺席 ⇒ 维持今日行为(发图)。
|
|
55
|
+
* 按当次 model 判 = 降级链换模型也各自正确(CC 同款降级姿态)。 */
|
|
56
|
+
function visionOf(model) {
|
|
57
|
+
return model?.input === undefined ? true : model.input.includes("image");
|
|
58
|
+
}
|
|
59
|
+
const IMAGE_OMITTED = "[image omitted: the serving model does not support image input]";
|
|
60
|
+
/** PDF read: OpenAI-compatible chat APIs have NO document content block — a `document` block (base64 PDF
|
|
61
|
+
* from the Read tool) is substituted with this honest placeholder (+ telemetry), never silently dropped
|
|
62
|
+
* and never fake-supported. The model is told the working alternative. Degradation chain v2: the Read tool
|
|
63
|
+
* now forks on the serving model's capabilities (pdftotext text extraction → rendered pages → placeholder),
|
|
64
|
+
* so this brain-level guard only fires for residual paths (e.g. a mid-task failover across API families, or
|
|
65
|
+
* a caller-injected document block). */
|
|
66
|
+
const DOCUMENT_OMITTED = "[PDF document omitted: PDF direct read requires an Anthropic-family model; re-Read the file (the engine will extract text/render pages when possible) or extract the text via Bash instead (e.g. `pdftotext`).]";
|
|
67
|
+
/** Build OpenAI user-message content: a plain string, or multimodal parts when images are present. */
|
|
68
|
+
function toUserContent(content, supportsVision = true) {
|
|
69
|
+
if (typeof content === "string") {
|
|
70
|
+
return content;
|
|
71
|
+
}
|
|
72
|
+
const hasImage = content.some((c) => c.type === "image");
|
|
73
|
+
// PDF read: document blocks never reach an OpenAI-compatible API — count them once here and fold the
|
|
74
|
+
// honest placeholder into every return path below (string or parts), never a silent drop.
|
|
75
|
+
const nDocs = content.filter((c) => c.type === "document").length;
|
|
76
|
+
if (nDocs > 0)
|
|
77
|
+
emitBrainTelemetry({ kind: "document_placeholder", count: nDocs });
|
|
78
|
+
if (!hasImage) {
|
|
79
|
+
const base = textOf(content);
|
|
80
|
+
if (nDocs === 0)
|
|
81
|
+
return base;
|
|
82
|
+
return base ? `${base}\n${DOCUMENT_OMITTED}` : DOCUMENT_OMITTED;
|
|
83
|
+
}
|
|
84
|
+
if (!supportsVision) {
|
|
85
|
+
const n = content.filter((c) => c.type === "image").length;
|
|
86
|
+
emitBrainTelemetry({ kind: "vision_placeholder", count: n }); // [398] C4: silent quality loss → frame
|
|
87
|
+
const base = textOf(content);
|
|
88
|
+
const note = n > 1 ? `[${n} images omitted: the serving model does not support image input]` : IMAGE_OMITTED;
|
|
89
|
+
const withNote = base ? `${base}\n${note}` : note;
|
|
90
|
+
return nDocs > 0 ? `${withNote}\n${DOCUMENT_OMITTED}` : withNote;
|
|
91
|
+
}
|
|
92
|
+
const parts = [];
|
|
93
|
+
for (const c of content) {
|
|
94
|
+
if (c.type === "text" && typeof c.text === "string") {
|
|
95
|
+
parts.push({ type: "text", text: c.text });
|
|
96
|
+
}
|
|
97
|
+
else if (c.type === "image" && c.data && c.mimeType) {
|
|
98
|
+
parts.push({
|
|
99
|
+
type: "image_url",
|
|
100
|
+
image_url: { url: `data:${c.mimeType};base64,${c.data}` },
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
else if (c.type === "document") {
|
|
104
|
+
parts.push({ type: "text", text: DOCUMENT_OMITTED });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return parts;
|
|
108
|
+
}
|
|
109
|
+
function thinkingCompat(model) {
|
|
110
|
+
return (model.compat ?? {});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Enable thinking on the request per the model's `compat.thinkingFormat` (design/46). A bare
|
|
114
|
+
* `reasoning_effort` (the old behavior) only works for the OpenAI family; DeepSeek/Qwen/zai/etc. each
|
|
115
|
+
* need their own switch. Thinking is requested by passing a `reasoning` level; a falsy value OR the
|
|
116
|
+
* explicit `"off"` tier leaves thinking unset (absence = provider default) — the harness already maps
|
|
117
|
+
* `off → undefined`, but a direct/public caller may pass `"off"`, which must NOT become `reasoning_effort:"off"`
|
|
118
|
+
* (an invalid value). Defaults to `"openai"`, so existing configs that don't set `compat.thinkingFormat`
|
|
119
|
+
* behave exactly as before (`reasoning_effort`).
|
|
120
|
+
*/
|
|
121
|
+
function applyThinking(body, model, reasoning) {
|
|
122
|
+
if (!model.reasoning || !reasoning || reasoning === "off")
|
|
123
|
+
return;
|
|
124
|
+
const compat = thinkingCompat(model);
|
|
125
|
+
const supportsEffort = compat.supportsReasoningEffort ?? true; // absent = supported
|
|
126
|
+
// Clamp the requested intensity to a tier THIS endpoint's `reasoning_effort` actually accepts (design/96
|
|
127
|
+
// S5): forwarding a level the endpoint rejects ("xhigh"/"max" to stock OpenAI) 422s the whole request. Only
|
|
128
|
+
// a known ThinkingLevel is mapped; an unrecognized/legacy string passes through unchanged (back-compat).
|
|
129
|
+
const effort = isThinkingLevel(reasoning)
|
|
130
|
+
? resolveEffort(reasoning, compat.reasoningEffortLevels ?? DEFAULT_EFFORT_LEVELS).effective
|
|
131
|
+
: reasoning;
|
|
132
|
+
// design/111 L1 — translate the (clamped) level to THIS model's provider-specific `reasoning_effort` wire
|
|
133
|
+
// value via `thinkingLevelMap`. Semantics (per the field's contract): a MISSING key ⇒ provider default (send
|
|
134
|
+
// the level name as-is = prior behavior); a STRING ⇒ that provider-specific value (e.g. a model that names
|
|
135
|
+
// its tiers differently, or wants a numeric/label form); `null` ⇒ the tier is UNSUPPORTED on this model, so
|
|
136
|
+
// send NO effort value — thinking still enables via the format's own enable key where one exists
|
|
137
|
+
// (deepseek/together/qwen), i.e. it runs at the provider default tier rather than a rejected one. Only a
|
|
138
|
+
// known ThinkingLevel is mapped; a legacy passthrough string is sent unchanged.
|
|
139
|
+
let effortWire = effort;
|
|
140
|
+
if (isThinkingLevel(effort) && model.thinkingLevelMap) {
|
|
141
|
+
const mapped = model.thinkingLevelMap[effort];
|
|
142
|
+
if (mapped === null)
|
|
143
|
+
effortWire = undefined;
|
|
144
|
+
else if (mapped !== undefined)
|
|
145
|
+
effortWire = mapped;
|
|
146
|
+
}
|
|
147
|
+
// Per the thinkingFormat spec, `deepseek` and `together` emit their enable key PLUS `reasoning_effort`
|
|
148
|
+
// (when supported) — the dual key is intentional, not a leak; a provider that doesn't take effort sets
|
|
149
|
+
// `supportsReasoningEffort: false`.
|
|
150
|
+
const format = compat.thinkingFormat ?? "openai";
|
|
151
|
+
switch (format) {
|
|
152
|
+
case "openai":
|
|
153
|
+
if (supportsEffort && effortWire !== undefined)
|
|
154
|
+
body.reasoning_effort = effortWire;
|
|
155
|
+
break;
|
|
156
|
+
case "openrouter":
|
|
157
|
+
body.reasoning = { effort: effortWire };
|
|
158
|
+
break;
|
|
159
|
+
case "deepseek":
|
|
160
|
+
body.thinking = { type: "enabled" };
|
|
161
|
+
if (supportsEffort && effortWire !== undefined)
|
|
162
|
+
body.reasoning_effort = effortWire;
|
|
163
|
+
break;
|
|
164
|
+
case "together":
|
|
165
|
+
body.reasoning = { enabled: true };
|
|
166
|
+
if (supportsEffort && effortWire !== undefined)
|
|
167
|
+
body.reasoning_effort = effortWire;
|
|
168
|
+
break;
|
|
169
|
+
case "qwen":
|
|
170
|
+
case "zai":
|
|
171
|
+
// Binary enable-only: the intensity tier is NOT honored as a gradient (resolveBinary → graded:false).
|
|
172
|
+
body.enable_thinking = true;
|
|
173
|
+
break;
|
|
174
|
+
case "qwen-chat-template": {
|
|
175
|
+
const k = (typeof body.chat_template_kwargs === "object" && body.chat_template_kwargs) || {};
|
|
176
|
+
body.chat_template_kwargs = { ...k, enable_thinking: true };
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
default: {
|
|
180
|
+
// Exhaustiveness guard (#5 anti-drift): a thinkingFormat added upstream must declare how it enables
|
|
181
|
+
// thinking here — the `never` assignment FAILS tsc if a case is missing, so a new format can't silently
|
|
182
|
+
// disable thinking. At runtime (defensive) an unrecognized format leaves thinking unset, the safe choice
|
|
183
|
+
// (we don't know its enable key; sending the wrong one could 422 the request).
|
|
184
|
+
const _exhaustive = format;
|
|
185
|
+
void _exhaustive;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Convert vendored LLM messages + system prompt into OpenAI chat-completions messages.
|
|
192
|
+
*
|
|
193
|
+
* Reasoning replay (design/46): when `replayThinking` is on (default), prior assistant `reasoning_content`
|
|
194
|
+
* is replayed **only on tool-call turns** — DeepSeek requires the thinking on a tool-call turn, while
|
|
195
|
+
* non-tool turns ignore it (so replaying there only bloats the context window for no effect; dropping it
|
|
196
|
+
* keeps the prefix lean → less compaction). Set `replayThinking: false` to never replay. When a provider
|
|
197
|
+
* needs the field present on every assistant message (`compat.requiresReasoningContentOnAssistantMessages`),
|
|
198
|
+
* an empty `reasoning_content` is emitted on non-replay turns.
|
|
199
|
+
*/
|
|
200
|
+
function toOpenAIMessages(ctx, replayThinking = true, model) {
|
|
201
|
+
const supportsVision = visionOf(model);
|
|
202
|
+
const out = [];
|
|
203
|
+
const needsEmptyReasoningField = !!model?.reasoning && thinkingCompat(model).requiresReasoningContentOnAssistantMessages === true;
|
|
204
|
+
if (ctx.systemPrompt) {
|
|
205
|
+
out.push({ role: "system", content: ctx.systemPrompt });
|
|
206
|
+
}
|
|
207
|
+
// design/66 image: OpenAI-compatible chat APIs accept images only on USER messages — the `tool` role
|
|
208
|
+
// is text-only — so images returned by tools are carried in a synthetic user message with a provenance
|
|
209
|
+
// marker (the standard agent-framework pattern; CC doesn't need this — the Anthropic API takes image
|
|
210
|
+
// blocks inside tool_result natively). Buffered and flushed AFTER the whole consecutive tool-result
|
|
211
|
+
// batch: strict providers reject a user message interleaved between an assistant's tool responses.
|
|
212
|
+
let pendingImages = [];
|
|
213
|
+
const flushImages = () => {
|
|
214
|
+
if (pendingImages.length === 0)
|
|
215
|
+
return;
|
|
216
|
+
const ids = [...new Set(pendingImages.map((i) => i.toolCallId))].join(", ");
|
|
217
|
+
out.push({
|
|
218
|
+
role: "user",
|
|
219
|
+
content: [
|
|
220
|
+
{ type: "text", text: `[Image${pendingImages.length > 1 ? "s" : ""} from tool result ${ids}]` },
|
|
221
|
+
...pendingImages.map((i) => ({ type: "image_url", image_url: { url: `data:${i.mimeType};base64,${i.data}` } })),
|
|
222
|
+
],
|
|
223
|
+
});
|
|
224
|
+
pendingImages = [];
|
|
225
|
+
};
|
|
226
|
+
for (const m of ctx.messages) {
|
|
227
|
+
if (m.role !== "toolResult")
|
|
228
|
+
flushImages();
|
|
229
|
+
if (m.role === "user") {
|
|
230
|
+
out.push({ role: "user", content: toUserContent(m.content, supportsVision) });
|
|
231
|
+
}
|
|
232
|
+
else if (m.role === "assistant") {
|
|
233
|
+
const text = m.content
|
|
234
|
+
.filter((c) => c.type === "text")
|
|
235
|
+
.map((c) => c.text)
|
|
236
|
+
.join("");
|
|
237
|
+
const toolCalls = m.content.filter((c) => c.type === "toolCall");
|
|
238
|
+
const msg = { role: "assistant", content: text };
|
|
239
|
+
const reasoning = m.content
|
|
240
|
+
.filter((c) => c.type === "thinking")
|
|
241
|
+
.map((c) => c.thinking)
|
|
242
|
+
.join("");
|
|
243
|
+
// Conditional replay: only tool-call turns (where DeepSeek requires it); non-tool turns drop it.
|
|
244
|
+
if (replayThinking && reasoning && toolCalls.length > 0) {
|
|
245
|
+
msg.reasoning_content = reasoning;
|
|
246
|
+
}
|
|
247
|
+
else if (needsEmptyReasoningField) {
|
|
248
|
+
msg.reasoning_content = ""; // provider requires the field present on every assistant message
|
|
249
|
+
}
|
|
250
|
+
if (toolCalls.length > 0) {
|
|
251
|
+
msg.tool_calls = toolCalls.map((tc) => ({
|
|
252
|
+
id: tc.id,
|
|
253
|
+
type: "function",
|
|
254
|
+
function: { name: tc.name, arguments: JSON.stringify(tc.arguments ?? {}) },
|
|
255
|
+
}));
|
|
256
|
+
}
|
|
257
|
+
out.push(msg);
|
|
258
|
+
}
|
|
259
|
+
else if (m.role === "toolResult") {
|
|
260
|
+
// Error tool results stay text-only (CC source messages.ts:2342: an image in an error
|
|
261
|
+
// tool_result is rejected by the API — sanitize rather than 400 forever).
|
|
262
|
+
const rawImages = !m.isError && Array.isArray(m.content)
|
|
263
|
+
? m.content.filter((c) => c.type === "image" && typeof c.data === "string" && typeof c.mimeType === "string")
|
|
264
|
+
: [];
|
|
265
|
+
const images = supportsVision ? rawImages : [];
|
|
266
|
+
if (!supportsVision && rawImages.length > 0)
|
|
267
|
+
emitBrainTelemetry({ kind: "vision_placeholder", count: rawImages.length }); // [398] C4
|
|
268
|
+
// PDF read: no document block on this API family — replace with the honest placeholder + telemetry.
|
|
269
|
+
const nDocs = Array.isArray(m.content) ? m.content.filter((c) => c.type === "document").length : 0;
|
|
270
|
+
if (nDocs > 0)
|
|
271
|
+
emitBrainTelemetry({ kind: "document_placeholder", count: nDocs });
|
|
272
|
+
const baseText0 = textOf(m.content);
|
|
273
|
+
const baseText = nDocs > 0 ? (baseText0 ? `${baseText0}\n${DOCUMENT_OMITTED}` : DOCUMENT_OMITTED) : baseText0;
|
|
274
|
+
const text = !supportsVision && rawImages.length > 0 ? (baseText ? `${baseText}\n${IMAGE_OMITTED}` : IMAGE_OMITTED) : baseText;
|
|
275
|
+
out.push({
|
|
276
|
+
role: "tool",
|
|
277
|
+
tool_call_id: m.toolCallId,
|
|
278
|
+
content: toolResultText(text, images.length > 0, m.content),
|
|
279
|
+
});
|
|
280
|
+
for (const img of images)
|
|
281
|
+
pendingImages.push({ toolCallId: m.toolCallId, data: img.data, mimeType: img.mimeType });
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
flushImages();
|
|
285
|
+
return out;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* The `tool` role message's text (council #1/Q1): three outcomes, made explicit —
|
|
289
|
+
* 1. the result had text → that text;
|
|
290
|
+
* 2. no text but images travel in the follow-up user message → a pointer sentinel;
|
|
291
|
+
* 3. no text and nothing travels (an ERROR result whose only content was images, stripped by the
|
|
292
|
+
* CC image-in-error rule) → a non-empty placeholder, since a strictly-validating
|
|
293
|
+
* OpenAI-compatible gateway may reject an empty-string tool content with a 400.
|
|
294
|
+
*/
|
|
295
|
+
function toolResultText(text, hasCarriedImages, original) {
|
|
296
|
+
if (text !== "")
|
|
297
|
+
return text;
|
|
298
|
+
if (hasCarriedImages)
|
|
299
|
+
return "(image attached below)";
|
|
300
|
+
return Array.isArray(original) && original.length > 0 ? "(non-text tool result omitted)" : "";
|
|
301
|
+
}
|
|
302
|
+
function toOpenAITools(ctx) {
|
|
303
|
+
if (!ctx.tools || ctx.tools.length === 0) {
|
|
304
|
+
return undefined;
|
|
305
|
+
}
|
|
306
|
+
return ctx.tools.map((t) => ({
|
|
307
|
+
type: "function",
|
|
308
|
+
function: { name: t.name, description: t.description, parameters: t.parameters },
|
|
309
|
+
}));
|
|
310
|
+
}
|
|
311
|
+
function mapFinishReason(reason, hadToolCalls) {
|
|
312
|
+
// toolUse iff tool calls actually SURVIVED accumulation (hadToolCalls). E2: a raw finish_reason of
|
|
313
|
+
// "tool_calls" must NOT independently force toolUse — a provider can report "tool_calls" while every call
|
|
314
|
+
// was dropped (e.g. a delta carrying id/args but never a `name` → the `if (!acc.name) continue` path, which
|
|
315
|
+
// unlike a malformed-JSON drop registers no toolError), and handing the harness a tool-use turn with ZERO
|
|
316
|
+
// tool calls hangs it. With no surviving calls a "tool_calls" finish degrades to a plain "stop".
|
|
317
|
+
if (hadToolCalls) {
|
|
318
|
+
return "toolUse";
|
|
319
|
+
}
|
|
320
|
+
if (reason === "length") {
|
|
321
|
+
return "length";
|
|
322
|
+
}
|
|
323
|
+
return "stop";
|
|
324
|
+
}
|
|
325
|
+
function computeUsage(model, raw) {
|
|
326
|
+
const input = raw?.prompt_tokens ?? 0;
|
|
327
|
+
const output = raw?.completion_tokens ?? 0;
|
|
328
|
+
const total = raw?.total_tokens ?? input + output;
|
|
329
|
+
// Prompt tokens served from the server-side prefix cache (a cache HIT). vLLM/OpenAI expose it as
|
|
330
|
+
// `prompt_tokens_details.cached_tokens`; DeepSeek as `prompt_cache_hit_tokens` (borrowed from
|
|
331
|
+
// CodeWhale's client.rs). Surfaced so a caller can see real cache effectiveness from the response.
|
|
332
|
+
const cacheRead = raw?.prompt_tokens_details?.cached_tokens ?? raw?.prompt_cache_hit_tokens ?? 0;
|
|
333
|
+
const c = model.cost;
|
|
334
|
+
const costInput = (input / 1e6) * (c?.input ?? 0);
|
|
335
|
+
const costOutput = (output / 1e6) * (c?.output ?? 0);
|
|
336
|
+
return {
|
|
337
|
+
input,
|
|
338
|
+
output,
|
|
339
|
+
cacheRead,
|
|
340
|
+
cacheWrite: 0,
|
|
341
|
+
totalTokens: total,
|
|
342
|
+
cost: { input: costInput, output: costOutput, cacheRead: 0, cacheWrite: 0, total: costInput + costOutput },
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Create a Brain that talks to an OpenAI-compatible chat-completions endpoint (your model gateway).
|
|
347
|
+
* Translates the unified Context into an OpenAI request and the streamed response back into the unified
|
|
348
|
+
* AssistantMessageEvent protocol, including native tool calls. The connect/retry/timeout/read-loop
|
|
349
|
+
* machinery lives in the shared {@link runStreamingBrain} engine (design/32); this adapter owns the
|
|
350
|
+
* OpenAI request shaping + chat-completions SSE parsing + finalization.
|
|
351
|
+
*/
|
|
352
|
+
export function createOpenAIBrain(config = {}) {
|
|
353
|
+
const doFetch = config.fetchImpl ?? fetch;
|
|
354
|
+
const stream = (model, context, options) => runStreamingBrain({
|
|
355
|
+
model,
|
|
356
|
+
doFetch,
|
|
357
|
+
signal: options?.signal,
|
|
358
|
+
config,
|
|
359
|
+
httpLabel: "gateway",
|
|
360
|
+
buildRequest: () => {
|
|
361
|
+
const apiKey = options?.apiKey ?? config.apiKey;
|
|
362
|
+
const root = (model.baseUrl || config.baseUrl || "").replace(/\/+$/, "");
|
|
363
|
+
if (!root) {
|
|
364
|
+
throw new Error("createOpenAIBrain: no baseUrl configured (set config.baseUrl or model.baseUrl)");
|
|
365
|
+
}
|
|
366
|
+
const body = {
|
|
367
|
+
model: model.id,
|
|
368
|
+
messages: toOpenAIMessages(context, config.replayThinking, model),
|
|
369
|
+
stream: true,
|
|
370
|
+
stream_options: { include_usage: true },
|
|
371
|
+
};
|
|
372
|
+
const tools = toOpenAITools(context);
|
|
373
|
+
if (tools)
|
|
374
|
+
body.tools = tools;
|
|
375
|
+
if (options?.temperature !== undefined)
|
|
376
|
+
body.temperature = options.temperature;
|
|
377
|
+
if (options?.maxTokens !== undefined) {
|
|
378
|
+
// design/119 #3: honor the declared field name (the knob existed but was never read —
|
|
379
|
+
// newer stock-OpenAI models take max_completion_tokens). Default keeps the prior wire shape.
|
|
380
|
+
const mtField = (model.compat ?? {}).maxTokensField;
|
|
381
|
+
body[mtField ?? "max_tokens"] = options.maxTokens;
|
|
382
|
+
}
|
|
383
|
+
if (options?.stop)
|
|
384
|
+
body.stop = options.stop;
|
|
385
|
+
applyThinking(body, model, options?.reasoning);
|
|
386
|
+
// User-supplied headers (model/config/options) augment the request; the structural + auth headers
|
|
387
|
+
// are hard-locked AFTER the spreads so they can NEVER be overridden (council design/40 security).
|
|
388
|
+
const headers = {
|
|
389
|
+
...model.headers,
|
|
390
|
+
...config.headers,
|
|
391
|
+
...options?.headers,
|
|
392
|
+
};
|
|
393
|
+
headers["content-type"] = "application/json";
|
|
394
|
+
if (apiKey)
|
|
395
|
+
headers["authorization"] = `Bearer ${apiKey}`;
|
|
396
|
+
return { url: `${root}/chat/completions`, headers, body: JSON.stringify(applyExtraBody(body, model.extraBody, OPENAI_RESERVED)) };
|
|
397
|
+
},
|
|
398
|
+
makeParser: (ctrl) => {
|
|
399
|
+
const { out, partial } = ctrl;
|
|
400
|
+
let accumText = "";
|
|
401
|
+
let accumReasoning = "";
|
|
402
|
+
let accumRefusal = ""; // CC-parity B3: a policy refusal streamed in delta.refusal
|
|
403
|
+
let degenerate = false; // tripped if the model loops on the same char/phrase forever
|
|
404
|
+
// Repetition telemetry (clay 2026-07-10): the cut event + allowance-spared hits for THIS stream.
|
|
405
|
+
// Polls re-inspect the same growing text every ~64 chars — dedupe spared by rule+segment so one
|
|
406
|
+
// boot block doesn't log once per poll. Attached to the final message as `repetition`.
|
|
407
|
+
let repCut;
|
|
408
|
+
const repSpared = new Map();
|
|
409
|
+
const pollRepetition = (text) => {
|
|
410
|
+
const insp = inspectDegenerate(text);
|
|
411
|
+
for (const s of insp.spared) {
|
|
412
|
+
const k = `${s.rule} ${s.segment}`;
|
|
413
|
+
const prev = repSpared.get(k);
|
|
414
|
+
if (prev === undefined)
|
|
415
|
+
repSpared.set(k, s);
|
|
416
|
+
else if (s.reps > prev.reps)
|
|
417
|
+
prev.reps = s.reps; // keep the loop's PEAK depth across polls
|
|
418
|
+
}
|
|
419
|
+
if (insp.degenerate)
|
|
420
|
+
repCut = insp.cut;
|
|
421
|
+
return insp.degenerate;
|
|
422
|
+
};
|
|
423
|
+
// design/130 P2b: tripped when the wall clock crossed the soft per-call deadline — a
|
|
424
|
+
// DELIBERATE cut like `degenerate` (salvage the prefix; the loop drives a write-out turn).
|
|
425
|
+
let walltimeCut = false;
|
|
426
|
+
const callDeadlineMs = options?.callDeadlineMs;
|
|
427
|
+
let lastDegenCheck = 0;
|
|
428
|
+
let lastDegenCheckReasoning = 0; // bug-hunt #4: separate cursor for the reasoning accumulator
|
|
429
|
+
const detectRep = config.detectRepetition !== false;
|
|
430
|
+
let emittedTextStart = false;
|
|
431
|
+
let emittedThinkingStart = false;
|
|
432
|
+
let thinkingClosed = false;
|
|
433
|
+
let textIndex = 0;
|
|
434
|
+
const toolAccum = new Map();
|
|
435
|
+
let finishReason = null;
|
|
436
|
+
let usageRaw;
|
|
437
|
+
// Reuse one block object per stream (mutated in place) instead of allocating a fresh full-text
|
|
438
|
+
// snapshot array on every delta — the per-delta `partial` would otherwise carry the whole
|
|
439
|
+
// text-so-far, making a long stream O(n²) in allocation.
|
|
440
|
+
const thinkingBlock = { type: "thinking", thinking: "" };
|
|
441
|
+
const textBlock = { type: "text", text: "" };
|
|
442
|
+
const pushReasoningDelta = (delta) => {
|
|
443
|
+
if (!delta)
|
|
444
|
+
return;
|
|
445
|
+
ctrl.sawContentToken(); // a thinking delta counts as the first token for reasoning models (O5)
|
|
446
|
+
if (thinkingClosed)
|
|
447
|
+
return; // ignore reasoning after the thinking block closed (interleaved)
|
|
448
|
+
if (!emittedThinkingStart) {
|
|
449
|
+
emittedThinkingStart = true;
|
|
450
|
+
partial.content = [thinkingBlock];
|
|
451
|
+
out.push({ type: "thinking_start", contentIndex: 0, partial: { ...partial } });
|
|
452
|
+
}
|
|
453
|
+
accumReasoning += delta;
|
|
454
|
+
thinkingBlock.thinking = accumReasoning;
|
|
455
|
+
out.push({ type: "thinking_delta", contentIndex: 0, delta, partial: { ...partial } });
|
|
456
|
+
// bug-hunt #4: a reasoning model can loop FOREVER inside reasoning_content with NO answer text.
|
|
457
|
+
// The text path (pushTextDelta) polls looksDegenerate, but reasoning had no tripwire — on a
|
|
458
|
+
// no-timeoutSec config that is an unbounded cost window; on the leader path it only aborts after
|
|
459
|
+
// ~24h mislabeled as `timeout` instead of a cheap `degenerate` cut. Poll the reasoning tail on the
|
|
460
|
+
// same ~64-char cadence; on a hit, cut the stream (the `degenerate` flag drives the error path).
|
|
461
|
+
if (detectRep && !degenerate && accumReasoning.length - lastDegenCheckReasoning >= 64) {
|
|
462
|
+
lastDegenCheckReasoning = accumReasoning.length;
|
|
463
|
+
if (pollRepetition(accumReasoning)) {
|
|
464
|
+
degenerate = true;
|
|
465
|
+
ctrl.cancel();
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
const closeThinking = () => {
|
|
470
|
+
if (emittedThinkingStart && !thinkingClosed) {
|
|
471
|
+
thinkingClosed = true;
|
|
472
|
+
out.push({ type: "thinking_end", contentIndex: 0, content: accumReasoning, partial: { ...partial } });
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
const pushTextDelta = (delta) => {
|
|
476
|
+
if (!delta)
|
|
477
|
+
return;
|
|
478
|
+
ctrl.sawContentToken();
|
|
479
|
+
if (!emittedTextStart) {
|
|
480
|
+
closeThinking();
|
|
481
|
+
emittedTextStart = true;
|
|
482
|
+
textIndex = emittedThinkingStart ? 1 : 0;
|
|
483
|
+
partial.content = [textBlock];
|
|
484
|
+
out.push({ type: "text_start", contentIndex: textIndex, partial: { ...partial } });
|
|
485
|
+
}
|
|
486
|
+
accumText += delta;
|
|
487
|
+
textBlock.text = accumText;
|
|
488
|
+
out.push({ type: "text_delta", contentIndex: textIndex, delta, partial: { ...partial } });
|
|
489
|
+
// Poll for degenerate repetition every ~64 chars; on a hit, cancel the stream (read loop ends).
|
|
490
|
+
if (detectRep && !degenerate && accumText.length - lastDegenCheck >= 64) {
|
|
491
|
+
lastDegenCheck = accumText.length;
|
|
492
|
+
if (pollRepetition(accumText)) {
|
|
493
|
+
degenerate = true;
|
|
494
|
+
ctrl.cancel();
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
return {
|
|
499
|
+
// design/124 §0.5-2: tiering introspection — direct reads off the closure accumulators.
|
|
500
|
+
// A streamed refusal counts as substantive (fail-closed: finalize routes it to the
|
|
501
|
+
// `refused` error path; retrying a policy refusal would just re-pay for the same refusal).
|
|
502
|
+
snapshot() {
|
|
503
|
+
const hasCompletedToolCall = [...toolAccum.values()].some((a) => a.closedTc !== undefined);
|
|
504
|
+
const hasSubstantiveText = accumText.trim() !== "" || accumRefusal.trim() !== "";
|
|
505
|
+
return {
|
|
506
|
+
hasSubstantiveText,
|
|
507
|
+
hasCompletedToolCall,
|
|
508
|
+
hasOnlyThinking: accumReasoning.length > 0 && !hasSubstantiveText && !hasCompletedToolCall,
|
|
509
|
+
};
|
|
510
|
+
},
|
|
511
|
+
// design/124 tier B: close the open thinking block (thinking_end at index 0) so the UI
|
|
512
|
+
// stream is sealed before the whole turn is re-sent. Idempotent via `thinkingClosed`.
|
|
513
|
+
sealForRetry() {
|
|
514
|
+
closeThinking();
|
|
515
|
+
},
|
|
516
|
+
onLine(rawLine) {
|
|
517
|
+
// design/130 P2b: poll the soft call deadline once per provider chunk (cheap — one
|
|
518
|
+
// Date.now()). Crossing it cancels the stream deliberately; the salvage below keeps
|
|
519
|
+
// the prefix and the sentinel errorMessage drives the loop's bounded write-out turn.
|
|
520
|
+
// (A fully-stalled stream emits no chunks — the engine's idle watchdog owns that case.)
|
|
521
|
+
if (callDeadlineMs !== undefined && !walltimeCut && !degenerate && Date.now() >= callDeadlineMs) {
|
|
522
|
+
walltimeCut = true;
|
|
523
|
+
ctrl.cancel();
|
|
524
|
+
return; // codex HIGH: do NOT parse the triggering chunk — its delta must not join the salvage
|
|
525
|
+
}
|
|
526
|
+
if (walltimeCut)
|
|
527
|
+
return; // any residual buffered line after the cut is equally dropped
|
|
528
|
+
const line = rawLine.trim();
|
|
529
|
+
if (!line.startsWith("data:"))
|
|
530
|
+
return;
|
|
531
|
+
const data = line.slice(5).trim();
|
|
532
|
+
if (!data || data === "[DONE]")
|
|
533
|
+
return;
|
|
534
|
+
let chunk;
|
|
535
|
+
try {
|
|
536
|
+
chunk = JSON.parse(data);
|
|
537
|
+
}
|
|
538
|
+
catch {
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
if (chunk.usage)
|
|
542
|
+
usageRaw = chunk.usage;
|
|
543
|
+
const choice = chunk.choices?.[0];
|
|
544
|
+
if (!choice)
|
|
545
|
+
return;
|
|
546
|
+
if (choice.finish_reason)
|
|
547
|
+
finishReason = choice.finish_reason;
|
|
548
|
+
const delta = choice.delta;
|
|
549
|
+
// `reasoning` and `reasoning_content` are cross-provider aliases for the same stream — a gateway that
|
|
550
|
+
// mirrors BOTH in one chunk must not double-count it. Prefer `reasoning`, else `reasoning_content`.
|
|
551
|
+
if (delta?.reasoning)
|
|
552
|
+
pushReasoningDelta(delta.reasoning);
|
|
553
|
+
else if (delta?.reasoning_content)
|
|
554
|
+
pushReasoningDelta(delta.reasoning_content);
|
|
555
|
+
if (delta?.refusal) {
|
|
556
|
+
// E1: a refusal token IS the first/next token of this stream. Without resetting the
|
|
557
|
+
// first-token/idle watchdog, a refusal-only stream (no content/reasoning/tool_calls ever)
|
|
558
|
+
// leaves the timers armed → a spurious `[network] first-token timeout` that mislabels (and
|
|
559
|
+
// retries) a policy refusal instead of landing on the intended fail-closed `refused` path.
|
|
560
|
+
ctrl.sawContentToken();
|
|
561
|
+
accumRefusal += delta.refusal; // CC-parity B3
|
|
562
|
+
}
|
|
563
|
+
if (delta?.content)
|
|
564
|
+
pushTextDelta(delta.content);
|
|
565
|
+
if (delta?.tool_calls) {
|
|
566
|
+
ctrl.sawContentToken();
|
|
567
|
+
for (const tc of delta.tool_calls) {
|
|
568
|
+
// Some gateways omit `index` for parallel tool calls — `tc.index ?? 0` would collapse them all into
|
|
569
|
+
// slot 0 (overwriting id/name, concatenating args). A new tool call always carries an `id`, so
|
|
570
|
+
// allocate a fresh slot on id and route an id-less continuation fragment to the most recent slot.
|
|
571
|
+
const idx = tc.index ?? (tc.id ? toolAccum.size : Math.max(0, toolAccum.size - 1));
|
|
572
|
+
if (!toolAccum.has(idx)) {
|
|
573
|
+
// design/120 P2.0: a NEW slot opening means every lower slot's argument stream is
|
|
574
|
+
// complete (the OpenAI wire streams tool calls in index order) — close them and emit
|
|
575
|
+
// `toolcall_end` so an in-stream executor (agent-loop P2) can start those calls while
|
|
576
|
+
// the rest of the response is still streaming. Fail-closed: if an interleaving gateway
|
|
577
|
+
// violates the order assumption, the early parse fails, nothing is emitted (failures
|
|
578
|
+
// are not cached), and finalize() retries with the full accumulation — behavior then
|
|
579
|
+
// degrades to the pre-P2 batch path, never to a malformed execution.
|
|
580
|
+
for (const [prevIdx, prevAcc] of [...toolAccum.entries()].sort((a, b) => a[0] - b[0])) {
|
|
581
|
+
if (prevIdx >= idx || prevAcc.closedTc)
|
|
582
|
+
continue;
|
|
583
|
+
// codex review BLOCKER-1: a slot with EMPTY args must NOT close early. An
|
|
584
|
+
// interleaving gateway can open index 1 while index 0 has only streamed its
|
|
585
|
+
// name — empty args would "successfully" close as a no-argument call `{}`,
|
|
586
|
+
// cache it, and the real argument deltas arriving later would be lost (finalize
|
|
587
|
+
// returns the cache) — wrong in-stream input AND a default-OFF regression. A
|
|
588
|
+
// NON-empty accumulation that parses is self-delimiting (a complete JSON object
|
|
589
|
+
// admits no legal continuation fragments), so closing it early is safe; no-arg
|
|
590
|
+
// calls simply wait for finalize like trailing calls.
|
|
591
|
+
if (prevAcc.args === "")
|
|
592
|
+
continue;
|
|
593
|
+
const closed = closeToolCallAccum(prevAcc);
|
|
594
|
+
if (closed) {
|
|
595
|
+
out.push({ type: "toolcall_end", contentIndex: prevIdx, toolCall: closed, partial: { ...partial } });
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
const acc = toolAccum.get(idx) ?? { id: "", name: "", args: "" };
|
|
600
|
+
if (tc.id)
|
|
601
|
+
acc.id = tc.id;
|
|
602
|
+
if (tc.function?.name)
|
|
603
|
+
acc.name = tc.function.name;
|
|
604
|
+
// Once a slot closed early (non-empty, complete JSON — self-delimiting), a further
|
|
605
|
+
// fragment for it would make the concatenation unparseable; the cached call is the
|
|
606
|
+
// only self-consistent reading, and the emitted toolcall_end may already be
|
|
607
|
+
// executing. Drop such protocol-violating late fragments instead of accumulating a
|
|
608
|
+
// divergence between the cache and finalize (codex review BLOCKER-1 defense belt).
|
|
609
|
+
if (tc.function?.arguments && !acc.closedTc)
|
|
610
|
+
acc.args += tc.function.arguments;
|
|
611
|
+
toolAccum.set(idx, acc);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
},
|
|
615
|
+
finalize() {
|
|
616
|
+
closeThinking();
|
|
617
|
+
if (emittedTextStart) {
|
|
618
|
+
out.push({ type: "text_end", contentIndex: textIndex, content: accumText, partial: { ...partial } });
|
|
619
|
+
}
|
|
620
|
+
const finalContent = [];
|
|
621
|
+
// audit A-5: persist the reasoning as a thinking block (BEFORE text, aligned with the
|
|
622
|
+
// anthropic brain). The harness stores this FINAL message in the session, so without it
|
|
623
|
+
// the `replayThinking` path (file-header note: DeepSeek REQUIRES reasoning_content on
|
|
624
|
+
// tool-call turns) could never fire for messages this brain itself produced — the replay
|
|
625
|
+
// filter looks for `type:"thinking"` blocks that were never there (tests passed only on
|
|
626
|
+
// hand-built messages). Non-replaying providers are unaffected: toOpenAIMessages only
|
|
627
|
+
// serializes thinking when the model's compat opts in.
|
|
628
|
+
if (accumReasoning)
|
|
629
|
+
finalContent.push({ type: "thinking", thinking: accumReasoning });
|
|
630
|
+
if (accumText)
|
|
631
|
+
finalContent.push({ type: "text", text: accumText });
|
|
632
|
+
const toolCalls = [];
|
|
633
|
+
const malformed = [];
|
|
634
|
+
for (const acc of [...toolAccum.entries()].sort((a, b) => a[0] - b[0]).map((e) => e[1])) {
|
|
635
|
+
if (!acc.name)
|
|
636
|
+
continue;
|
|
637
|
+
// design/120 P2.0: parse/id logic lives in closeToolCallAccum (shared with the in-stream
|
|
638
|
+
// `toolcall_end` emission at slot-open — same parse discipline, same cached ToolCall
|
|
639
|
+
// object, so a streamed id and the final content id can never diverge). A slot not yet
|
|
640
|
+
// closed (trailing call — its stream only "ends" at finish, or an early close that
|
|
641
|
+
// failed) is closed HERE but deliberately WITHOUT emitting toolcall_end: finalize also
|
|
642
|
+
// runs on error finals, and emitting an addTool signal one tick before `error` would
|
|
643
|
+
// start a tool the terminal path then has to settle — for zero streaming benefit (the
|
|
644
|
+
// response is already over). The provider contract stays one-directional: every emitted
|
|
645
|
+
// toolcall_end appears in the done content; not every content call emitted an event
|
|
646
|
+
// (trailing calls and text-repair calls below run on the batch path).
|
|
647
|
+
const tc = closeToolCallAccum(acc);
|
|
648
|
+
if (tc) {
|
|
649
|
+
toolCalls.push(tc);
|
|
650
|
+
finalContent.push(tc);
|
|
651
|
+
}
|
|
652
|
+
else {
|
|
653
|
+
// Truncated/invalid arguments (common on finish_reason="length") or a non-object top
|
|
654
|
+
// level. Do NOT execute the tool with empty `{}` — surface it instead.
|
|
655
|
+
malformed.push(`${acc.name}(${acc.args.slice(0, 200)})`);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
// Opt-in: recover tool calls a weak model emitted as text.
|
|
659
|
+
if (config.repairTextToolCalls && toolCalls.length === 0 && accumText && context.tools && context.tools.length > 0) {
|
|
660
|
+
const names = new Set(context.tools.flatMap((t) => [t.name, ...(t.aliases ?? [])]));
|
|
661
|
+
const repaired = repairTextToolCalls(accumText, names);
|
|
662
|
+
if (repaired.toolCalls.length > 0) {
|
|
663
|
+
finalContent.length = 0;
|
|
664
|
+
if (accumReasoning)
|
|
665
|
+
finalContent.push({ type: "thinking", thinking: accumReasoning }); // A-5: survive the rebuild
|
|
666
|
+
if (repaired.cleanedText)
|
|
667
|
+
finalContent.push({ type: "text", text: repaired.cleanedText });
|
|
668
|
+
for (const tc of repaired.toolCalls) {
|
|
669
|
+
finalContent.push(tc);
|
|
670
|
+
toolCalls.push(tc);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
const toolError = malformed.length > 0
|
|
675
|
+
? `tool call argument(s) not valid JSON (likely truncated, finish_reason="${finishReason ?? "?"}"): ${malformed.join("; ")}`
|
|
676
|
+
: undefined;
|
|
677
|
+
const noUsableContent = toolCalls.length === 0 && !accumText.trim();
|
|
678
|
+
// bug-hunt #2: a PARTIAL tool batch — at least one valid call AND a truncated one (a parallel
|
|
679
|
+
// batch cut at the last token by finish_reason="length"). The valid call(s) must still execute
|
|
680
|
+
// (failing the whole task over a recoverable truncation would discard real work — and a brain
|
|
681
|
+
// `error` is a TERMINAL task failure here, not a re-prompt), but the dropped call used to vanish
|
|
682
|
+
// silently (its error rode the `done` event, which the assembler reads only on error turns). Make
|
|
683
|
+
// the loss VISIBLE in the assistant content so the model re-issues it next turn.
|
|
684
|
+
// Make the dropped call(s) visible whenever ANY were malformed — INCLUDING the case where no call
|
|
685
|
+
// survived but there IS text (the `toolCalls.length > 0` guard left that path silent → a clean
|
|
686
|
+
// `done`, so the loop saw zero tool calls and ended the task with the text as a final answer, the
|
|
687
|
+
// intended action lost with zero signal). The note in the assistant content surfaces the loss.
|
|
688
|
+
if (toolError !== undefined) {
|
|
689
|
+
finalContent.push({
|
|
690
|
+
type: "text",
|
|
691
|
+
text: `\n[note: ${malformed.length} tool call(s) were truncated (finish_reason="${finishReason ?? "?"}") and dropped — re-issue them next turn: ${malformed.join("; ")}]`,
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
// A "length" cutoff that produced NO answer text (verbose reasoning ate the whole budget) is a
|
|
695
|
+
// real failure, not an empty "success" — surface it like a malformed-tool turn.
|
|
696
|
+
const truncatedEmpty = finishReason === "length" && noUsableContent && !toolError;
|
|
697
|
+
// service [405] P0: under a DYNAMICALLY shrunk cap (design/130 P1) the truncation is the
|
|
698
|
+
// ENGINE's own doing, not a deployment mistake — fail-louding it turned a recoverable
|
|
699
|
+
// reasoning cut into a dead turn (TB full-89: 14 calls, two solved tasks lost). Degrade to
|
|
700
|
+
// a plain `length` stop: the loop's truncated-output continue picks it up, and the runtime
|
|
701
|
+
// reasoning observation exempts the NEXT call from the cap. Static caps keep bug-hunt
|
|
702
|
+
// F2b's fail-loud (a config error should stay loud).
|
|
703
|
+
const dynamicCut = truncatedEmpty && options?.maxTokensDynamic === true;
|
|
704
|
+
// bug-hunt #3: a provider SAFETY cut (finish_reason="content_filter") censors/truncates output
|
|
705
|
+
// for policy — `mapFinishReason` collapsed it to a clean "stop", reporting a compromised turn as
|
|
706
|
+
// success (the silent false-negative class). Fail closed even if partial text was produced.
|
|
707
|
+
const safetyCut = finishReason === "content_filter";
|
|
708
|
+
// CC-parity B3: OpenAI streams a policy REFUSAL in `delta.refusal` and normally finishes
|
|
709
|
+
// `finish_reason:"stop"` (not content_filter) — so without this it lands as a clean empty "stop"
|
|
710
|
+
// success with the refusal text dropped. Fail closed (parity with anthropic's stop_reason="refusal").
|
|
711
|
+
const refused = accumRefusal.trim().length > 0;
|
|
712
|
+
// bug-hunt #8: a conforming provider ALWAYS closes a stream with a finish_reason. No usable
|
|
713
|
+
// content AND no finish_reason ⇒ a torn stream or an in-band error frame `onLine` swallowed
|
|
714
|
+
// (catch→return) — must NOT surface as an empty "stop" success. (A degenerate cut cancels
|
|
715
|
+
// deliberately and always carries content, so it is excluded.)
|
|
716
|
+
const emptyNoFinish = noUsableContent && finishReason == null && !degenerate && !walltimeCut;
|
|
717
|
+
// P2b: `walltimeCut` wins the whole chain — the cut is OURS (deliberate, wall-clock), so no
|
|
718
|
+
// downstream cause may re-attribute it; the sentinel must survive verbatim for the loop's
|
|
719
|
+
// write-out recovery + the assembler's timeout-with-salvage mapping.
|
|
720
|
+
// `degenerate` wins over `toolError` (design/39 + council): when a turn both loops AND emits a
|
|
721
|
+
// malformed tool call, the loop is the root cause → `DEGENERATE_MESSAGE` must survive so the
|
|
722
|
+
// assembler maps it to `output.degenerate` + salvages the text (the tool-error string is dropped).
|
|
723
|
+
// `toolError` is INTENTIONALLY chosen ahead of `emptyNoFinish` (cross-model review): on the rare
|
|
724
|
+
// collision (a malformed tool call + a torn stream) the tool-error string names the tool and already
|
|
725
|
+
// signals the missing close via `finish_reason="?"` — strictly more specific than the generic frame.
|
|
726
|
+
const errorMessage = walltimeCut
|
|
727
|
+
? WALLTIME_CUTOFF_MESSAGE
|
|
728
|
+
: degenerate
|
|
729
|
+
? DEGENERATE_MESSAGE
|
|
730
|
+
: safetyCut
|
|
731
|
+
? `response cut by the provider content filter (finish_reason="content_filter") — the output was censored/truncated for policy and is unreliable`
|
|
732
|
+
: refused
|
|
733
|
+
? `response refused by the model for policy reasons: ${accumRefusal.trim()}`
|
|
734
|
+
: (toolError ??
|
|
735
|
+
(truncatedEmpty && !dynamicCut
|
|
736
|
+
? accumReasoning.trim()
|
|
737
|
+
? `response truncated at max_tokens (finish_reason="length") with no answer text — the model spent the whole budget on reasoning (${accumReasoning.length} reasoning chars). Raise max_tokens, or disable thinking for this task.`
|
|
738
|
+
: `response truncated at max_tokens (finish_reason="length") with no answer text — raise max_tokens`
|
|
739
|
+
: emptyNoFinish
|
|
740
|
+
? `model stream ended with no content and no finish_reason — the response was lost (a torn stream or an in-band provider error frame)`
|
|
741
|
+
: undefined));
|
|
742
|
+
const errored = walltimeCut ||
|
|
743
|
+
degenerate ||
|
|
744
|
+
safetyCut ||
|
|
745
|
+
refused ||
|
|
746
|
+
emptyNoFinish ||
|
|
747
|
+
(toolError !== undefined && noUsableContent) ||
|
|
748
|
+
(truncatedEmpty && !dynamicCut);
|
|
749
|
+
// Structured cause, mirroring the errorMessage precedence chain: tagged ONLY when truncatedEmpty
|
|
750
|
+
// is the selected cause, so callers can escalate max_tokens without parsing prose.
|
|
751
|
+
const errorKind = !walltimeCut && !degenerate && !safetyCut && !refused && toolError === undefined && truncatedEmpty && !dynamicCut
|
|
752
|
+
? "length_empty"
|
|
753
|
+
: undefined;
|
|
754
|
+
const finalMessage = {
|
|
755
|
+
...partial,
|
|
756
|
+
content: finalContent.length > 0 ? finalContent : [{ type: "text", text: "" }],
|
|
757
|
+
stopReason: errored ? "error" : mapFinishReason(finishReason, toolCalls.length > 0),
|
|
758
|
+
usage: computeUsage(model, usageRaw),
|
|
759
|
+
...(usageRaw === undefined ? { usageMissing: true } : {}), // T1-5: no provider frame → UNKNOWN, not zero
|
|
760
|
+
timestamp: Date.now(),
|
|
761
|
+
...(errorMessage ? { errorMessage } : {}),
|
|
762
|
+
...(errorKind ? { errorKind } : {}),
|
|
763
|
+
// Repetition telemetry: cut event + allowance-spared hits (deduped) observed on this stream.
|
|
764
|
+
...(repCut !== undefined || repSpared.size > 0
|
|
765
|
+
? { repetition: { ...(repCut !== undefined ? { cut: repCut } : {}), ...(repSpared.size > 0 ? { spared: [...repSpared.values()] } : {}) } }
|
|
766
|
+
: {}),
|
|
767
|
+
};
|
|
768
|
+
if (errored) {
|
|
769
|
+
out.push({ type: "error", reason: "error", error: finalMessage });
|
|
770
|
+
}
|
|
771
|
+
else {
|
|
772
|
+
out.push({
|
|
773
|
+
type: "done",
|
|
774
|
+
reason: finalMessage.stopReason,
|
|
775
|
+
message: finalMessage,
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
},
|
|
779
|
+
};
|
|
780
|
+
},
|
|
781
|
+
});
|
|
782
|
+
return { stream };
|
|
783
|
+
}
|
|
784
|
+
//# sourceMappingURL=openai.js.map
|