@sema-agent/core 1.279.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +104 -0
- package/NOTICE.md +30 -0
- package/README.md +143 -0
- package/README.zh-CN.md +138 -0
- package/dist/agents/agent-definition.d.ts +3 -0
- package/dist/agents/agent-definition.d.ts.map +1 -0
- package/dist/agents/agent-definition.js +9 -0
- package/dist/agents/agent-definition.js.map +1 -0
- package/dist/agents/builtin-agents.d.ts +9 -0
- package/dist/agents/builtin-agents.d.ts.map +1 -0
- package/dist/agents/builtin-agents.js +114 -0
- package/dist/agents/builtin-agents.js.map +1 -0
- package/dist/agents/cascade.d.ts +44 -0
- package/dist/agents/cascade.d.ts.map +1 -0
- package/dist/agents/cascade.js +153 -0
- package/dist/agents/cascade.js.map +1 -0
- package/dist/agents/observer.d.ts +122 -0
- package/dist/agents/observer.d.ts.map +1 -0
- package/dist/agents/observer.js +365 -0
- package/dist/agents/observer.js.map +1 -0
- package/dist/agents/repair-loop.d.ts +49 -0
- package/dist/agents/repair-loop.d.ts.map +1 -0
- package/dist/agents/repair-loop.js +147 -0
- package/dist/agents/repair-loop.js.map +1 -0
- package/dist/agents/session-util.d.ts +3 -0
- package/dist/agents/session-util.d.ts.map +1 -0
- package/dist/agents/session-util.js +4 -0
- package/dist/agents/session-util.js.map +1 -0
- package/dist/agents/subagent-steps.d.ts +31 -0
- package/dist/agents/subagent-steps.d.ts.map +1 -0
- package/dist/agents/subagent-steps.js +167 -0
- package/dist/agents/subagent-steps.js.map +1 -0
- package/dist/agents/subagent.d.ts +152 -0
- package/dist/agents/subagent.d.ts.map +1 -0
- package/dist/agents/subagent.js +1698 -0
- package/dist/agents/subagent.js.map +1 -0
- package/dist/agents/suspend-guard.d.ts +6 -0
- package/dist/agents/suspend-guard.d.ts.map +1 -0
- package/dist/agents/suspend-guard.js +19 -0
- package/dist/agents/suspend-guard.js.map +1 -0
- package/dist/agents/teacher.d.ts +70 -0
- package/dist/agents/teacher.d.ts.map +1 -0
- package/dist/agents/teacher.js +462 -0
- package/dist/agents/teacher.js.map +1 -0
- package/dist/agents/team.d.ts +92 -0
- package/dist/agents/team.d.ts.map +1 -0
- package/dist/agents/team.js +231 -0
- package/dist/agents/team.js.map +1 -0
- package/dist/agents/tool-filter.d.ts +4 -0
- package/dist/agents/tool-filter.d.ts.map +1 -0
- package/dist/agents/tool-filter.js +18 -0
- package/dist/agents/tool-filter.js.map +1 -0
- package/dist/agents/verify.d.ts +46 -0
- package/dist/agents/verify.d.ts.map +1 -0
- package/dist/agents/verify.js +177 -0
- package/dist/agents/verify.js.map +1 -0
- package/dist/bench/metrics.d.ts +259 -0
- package/dist/bench/metrics.d.ts.map +1 -0
- package/dist/bench/metrics.js +439 -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 +373 -0
- package/dist/bin/sema-tb.js.map +1 -0
- package/dist/bin/tb-env.d.ts +2 -0
- package/dist/bin/tb-env.d.ts.map +1 -0
- package/dist/bin/tb-env.js +15 -0
- package/dist/bin/tb-env.js.map +1 -0
- package/dist/brain/anthropic.d.ts +16 -0
- package/dist/brain/anthropic.d.ts.map +1 -0
- package/dist/brain/anthropic.js +635 -0
- package/dist/brain/anthropic.js.map +1 -0
- package/dist/brain/circuit-breaker.d.ts +26 -0
- package/dist/brain/circuit-breaker.d.ts.map +1 -0
- package/dist/brain/circuit-breaker.js +118 -0
- package/dist/brain/circuit-breaker.js.map +1 -0
- package/dist/brain/degrading.d.ts +33 -0
- package/dist/brain/degrading.d.ts.map +1 -0
- package/dist/brain/degrading.js +175 -0
- package/dist/brain/degrading.js.map +1 -0
- package/dist/brain/errors.d.ts +14 -0
- package/dist/brain/errors.d.ts.map +1 -0
- package/dist/brain/errors.js +43 -0
- package/dist/brain/errors.js.map +1 -0
- package/dist/brain/failover.d.ts +3 -0
- package/dist/brain/failover.d.ts.map +1 -0
- package/dist/brain/failover.js +85 -0
- package/dist/brain/failover.js.map +1 -0
- package/dist/brain/model-presets.d.ts +5 -0
- package/dist/brain/model-presets.d.ts.map +1 -0
- package/dist/brain/model-presets.js +30 -0
- package/dist/brain/model-presets.js.map +1 -0
- package/dist/brain/openai.d.ts +13 -0
- package/dist/brain/openai.d.ts.map +1 -0
- package/dist/brain/openai.js +581 -0
- package/dist/brain/openai.js.map +1 -0
- package/dist/brain/reasoning.d.ts +33 -0
- package/dist/brain/reasoning.d.ts.map +1 -0
- package/dist/brain/reasoning.js +84 -0
- package/dist/brain/reasoning.js.map +1 -0
- package/dist/brain/repetition.d.ts +16 -0
- package/dist/brain/repetition.d.ts.map +1 -0
- package/dist/brain/repetition.js +96 -0
- package/dist/brain/repetition.js.map +1 -0
- package/dist/brain/request-params.d.ts +6 -0
- package/dist/brain/request-params.d.ts.map +1 -0
- package/dist/brain/request-params.js +44 -0
- package/dist/brain/request-params.js.map +1 -0
- package/dist/brain/retry.d.ts +3 -0
- package/dist/brain/retry.d.ts.map +1 -0
- package/dist/brain/retry.js +23 -0
- package/dist/brain/retry.js.map +1 -0
- package/dist/brain/routing.d.ts +7 -0
- package/dist/brain/routing.d.ts.map +1 -0
- package/dist/brain/routing.js +34 -0
- package/dist/brain/routing.js.map +1 -0
- package/dist/brain/status-sink.d.ts +27 -0
- package/dist/brain/status-sink.d.ts.map +1 -0
- package/dist/brain/status-sink.js +20 -0
- package/dist/brain/status-sink.js.map +1 -0
- package/dist/brain/stream-engine.d.ts +37 -0
- package/dist/brain/stream-engine.d.ts.map +1 -0
- package/dist/brain/stream-engine.js +295 -0
- package/dist/brain/stream-engine.js.map +1 -0
- package/dist/brain/timeout.d.ts +12 -0
- package/dist/brain/timeout.d.ts.map +1 -0
- package/dist/brain/timeout.js +34 -0
- package/dist/brain/timeout.js.map +1 -0
- package/dist/brain/tool-call-repair.d.ts +6 -0
- package/dist/brain/tool-call-repair.d.ts.map +1 -0
- package/dist/brain/tool-call-repair.js +58 -0
- package/dist/brain/tool-call-repair.js.map +1 -0
- package/dist/brain/walltime.d.ts +2 -0
- package/dist/brain/walltime.d.ts.map +1 -0
- package/dist/brain/walltime.js +2 -0
- package/dist/brain/walltime.js.map +1 -0
- package/dist/core/arg-summary.d.ts +3 -0
- package/dist/core/arg-summary.d.ts.map +1 -0
- package/dist/core/arg-summary.js +76 -0
- package/dist/core/arg-summary.js.map +1 -0
- package/dist/core/ask-question.d.ts +36 -0
- package/dist/core/ask-question.d.ts.map +1 -0
- package/dist/core/ask-question.js +171 -0
- package/dist/core/ask-question.js.map +1 -0
- package/dist/core/auto-compaction.d.ts +88 -0
- package/dist/core/auto-compaction.d.ts.map +1 -0
- package/dist/core/auto-compaction.js +253 -0
- package/dist/core/auto-compaction.js.map +1 -0
- package/dist/core/auto-mode-prompt-assets.d.ts +3 -0
- package/dist/core/auto-mode-prompt-assets.d.ts.map +1 -0
- package/dist/core/auto-mode-prompt-assets.js +3 -0
- package/dist/core/auto-mode-prompt-assets.js.map +1 -0
- package/dist/core/auto-mode-prompt.d.ts +22 -0
- package/dist/core/auto-mode-prompt.d.ts.map +1 -0
- package/dist/core/auto-mode-prompt.js +84 -0
- package/dist/core/auto-mode-prompt.js.map +1 -0
- package/dist/core/auto-mode.d.ts +35 -0
- package/dist/core/auto-mode.d.ts.map +1 -0
- package/dist/core/auto-mode.js +100 -0
- package/dist/core/auto-mode.js.map +1 -0
- package/dist/core/auto-promote.d.ts +26 -0
- package/dist/core/auto-promote.d.ts.map +1 -0
- package/dist/core/auto-promote.js +93 -0
- package/dist/core/auto-promote.js.map +1 -0
- package/dist/core/background-shell.d.ts +41 -0
- package/dist/core/background-shell.d.ts.map +1 -0
- package/dist/core/background-shell.js +21 -0
- package/dist/core/background-shell.js.map +1 -0
- package/dist/core/cache-break-detector.d.ts +29 -0
- package/dist/core/cache-break-detector.d.ts.map +1 -0
- package/dist/core/cache-break-detector.js +80 -0
- package/dist/core/cache-break-detector.js.map +1 -0
- package/dist/core/canonical-json.d.ts +3 -0
- package/dist/core/canonical-json.d.ts.map +1 -0
- package/dist/core/canonical-json.js +68 -0
- package/dist/core/canonical-json.js.map +1 -0
- package/dist/core/checkpoint-store.d.ts +257 -0
- package/dist/core/checkpoint-store.d.ts.map +1 -0
- package/dist/core/checkpoint-store.js +292 -0
- package/dist/core/checkpoint-store.js.map +1 -0
- package/dist/core/consolidate-scope.d.ts +19 -0
- package/dist/core/consolidate-scope.d.ts.map +1 -0
- package/dist/core/consolidate-scope.js +96 -0
- package/dist/core/consolidate-scope.js.map +1 -0
- package/dist/core/context-edit.d.ts +18 -0
- package/dist/core/context-edit.d.ts.map +1 -0
- package/dist/core/context-edit.js +98 -0
- package/dist/core/context-edit.js.map +1 -0
- package/dist/core/context-guard.d.ts +14 -0
- package/dist/core/context-guard.d.ts.map +1 -0
- package/dist/core/context-guard.js +110 -0
- package/dist/core/context-guard.js.map +1 -0
- package/dist/core/dynamic-recall.d.ts +33 -0
- package/dist/core/dynamic-recall.d.ts.map +1 -0
- package/dist/core/dynamic-recall.js +77 -0
- package/dist/core/dynamic-recall.js.map +1 -0
- package/dist/core/exec-gate.d.ts +30 -0
- package/dist/core/exec-gate.d.ts.map +1 -0
- package/dist/core/exec-gate.js +106 -0
- package/dist/core/exec-gate.js.map +1 -0
- package/dist/core/exec-output-tail.d.ts +15 -0
- package/dist/core/exec-output-tail.d.ts.map +1 -0
- package/dist/core/exec-output-tail.js +39 -0
- package/dist/core/exec-output-tail.js.map +1 -0
- package/dist/core/file-snapshot-store.d.ts +53 -0
- package/dist/core/file-snapshot-store.d.ts.map +1 -0
- package/dist/core/file-snapshot-store.js +244 -0
- package/dist/core/file-snapshot-store.js.map +1 -0
- package/dist/core/git-worktree-env.d.ts +16 -0
- package/dist/core/git-worktree-env.d.ts.map +1 -0
- package/dist/core/git-worktree-env.js +40 -0
- package/dist/core/git-worktree-env.js.map +1 -0
- package/dist/core/hooks.d.ts +128 -0
- package/dist/core/hooks.d.ts.map +1 -0
- package/dist/core/hooks.js +184 -0
- package/dist/core/hooks.js.map +1 -0
- package/dist/core/lsp-diagnostics.d.ts +31 -0
- package/dist/core/lsp-diagnostics.d.ts.map +1 -0
- package/dist/core/lsp-diagnostics.js +79 -0
- package/dist/core/lsp-diagnostics.js.map +1 -0
- package/dist/core/lsp-protocol.d.ts +10 -0
- package/dist/core/lsp-protocol.d.ts.map +1 -0
- package/dist/core/lsp-protocol.js +136 -0
- package/dist/core/lsp-protocol.js.map +1 -0
- package/dist/core/lsp-session.d.ts +27 -0
- package/dist/core/lsp-session.d.ts.map +1 -0
- package/dist/core/lsp-session.js +134 -0
- package/dist/core/lsp-session.js.map +1 -0
- package/dist/core/lsp.d.ts +56 -0
- package/dist/core/lsp.d.ts.map +1 -0
- package/dist/core/lsp.js +130 -0
- package/dist/core/lsp.js.map +1 -0
- package/dist/core/mcp.d.ts +108 -0
- package/dist/core/mcp.d.ts.map +1 -0
- package/dist/core/mcp.js +692 -0
- package/dist/core/mcp.js.map +1 -0
- package/dist/core/media-byte-cap.d.ts +13 -0
- package/dist/core/media-byte-cap.d.ts.map +1 -0
- package/dist/core/media-byte-cap.js +51 -0
- package/dist/core/media-byte-cap.js.map +1 -0
- package/dist/core/memory-engine/data-plane.d.ts +60 -0
- package/dist/core/memory-engine/data-plane.d.ts.map +1 -0
- package/dist/core/memory-engine/data-plane.js +198 -0
- package/dist/core/memory-engine/data-plane.js.map +1 -0
- package/dist/core/memory-engine/dual-root.d.ts +16 -0
- package/dist/core/memory-engine/dual-root.d.ts.map +1 -0
- package/dist/core/memory-engine/dual-root.js +75 -0
- package/dist/core/memory-engine/dual-root.js.map +1 -0
- package/dist/core/memory-engine/engine.d.ts +67 -0
- package/dist/core/memory-engine/engine.d.ts.map +1 -0
- package/dist/core/memory-engine/engine.js +828 -0
- package/dist/core/memory-engine/engine.js.map +1 -0
- package/dist/core/memory-engine/file-backend.d.ts +55 -0
- package/dist/core/memory-engine/file-backend.d.ts.map +1 -0
- package/dist/core/memory-engine/file-backend.js +752 -0
- package/dist/core/memory-engine/file-backend.js.map +1 -0
- package/dist/core/memory-engine/frontmatter.d.ts +13 -0
- package/dist/core/memory-engine/frontmatter.d.ts.map +1 -0
- package/dist/core/memory-engine/frontmatter.js +119 -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 +12 -0
- package/dist/core/memory-engine/index.js.map +1 -0
- package/dist/core/memory-engine/layout.d.ts +44 -0
- package/dist/core/memory-engine/layout.d.ts.map +1 -0
- package/dist/core/memory-engine/layout.js +459 -0
- package/dist/core/memory-engine/layout.js.map +1 -0
- package/dist/core/memory-engine/memory-backend-contract.d.ts +10 -0
- package/dist/core/memory-engine/memory-backend-contract.d.ts.map +1 -0
- package/dist/core/memory-engine/memory-backend-contract.js +269 -0
- package/dist/core/memory-engine/memory-backend-contract.js.map +1 -0
- package/dist/core/memory-engine/migrate.d.ts +8 -0
- package/dist/core/memory-engine/migrate.d.ts.map +1 -0
- package/dist/core/memory-engine/migrate.js +23 -0
- package/dist/core/memory-engine/migrate.js.map +1 -0
- package/dist/core/memory-engine/scan.d.ts +8 -0
- package/dist/core/memory-engine/scan.d.ts.map +1 -0
- package/dist/core/memory-engine/scan.js +49 -0
- package/dist/core/memory-engine/scan.js.map +1 -0
- package/dist/core/memory-engine/scope-contract.d.ts +44 -0
- package/dist/core/memory-engine/scope-contract.d.ts.map +1 -0
- package/dist/core/memory-engine/scope-contract.js +205 -0
- package/dist/core/memory-engine/scope-contract.js.map +1 -0
- package/dist/core/memory-engine/sync-client.d.ts +57 -0
- package/dist/core/memory-engine/sync-client.d.ts.map +1 -0
- package/dist/core/memory-engine/sync-client.js +257 -0
- package/dist/core/memory-engine/sync-client.js.map +1 -0
- package/dist/core/memory-engine/sync.d.ts +37 -0
- package/dist/core/memory-engine/sync.d.ts.map +1 -0
- package/dist/core/memory-engine/sync.js +68 -0
- package/dist/core/memory-engine/sync.js.map +1 -0
- package/dist/core/memory-engine/types.d.ts +128 -0
- package/dist/core/memory-engine/types.d.ts.map +1 -0
- package/dist/core/memory-engine/types.js +2 -0
- package/dist/core/memory-engine/types.js.map +1 -0
- package/dist/core/memory-recall.d.ts +82 -0
- package/dist/core/memory-recall.d.ts.map +1 -0
- package/dist/core/memory-recall.js +352 -0
- package/dist/core/memory-recall.js.map +1 -0
- package/dist/core/memory-vector.d.ts +4 -0
- package/dist/core/memory-vector.d.ts.map +1 -0
- package/dist/core/memory-vector.js +31 -0
- package/dist/core/memory-vector.js.map +1 -0
- package/dist/core/memory.d.ts +112 -0
- package/dist/core/memory.d.ts.map +1 -0
- package/dist/core/memory.js +512 -0
- package/dist/core/memory.js.map +1 -0
- package/dist/core/message-utils.d.ts +4 -0
- package/dist/core/message-utils.d.ts.map +1 -0
- package/dist/core/message-utils.js +7 -0
- package/dist/core/message-utils.js.map +1 -0
- package/dist/core/oracle-isolation.d.ts +16 -0
- package/dist/core/oracle-isolation.d.ts.map +1 -0
- package/dist/core/oracle-isolation.js +50 -0
- package/dist/core/oracle-isolation.js.map +1 -0
- package/dist/core/permission-rules.d.ts +35 -0
- package/dist/core/permission-rules.d.ts.map +1 -0
- package/dist/core/permission-rules.js +270 -0
- package/dist/core/permission-rules.js.map +1 -0
- package/dist/core/present-plan-tool.d.ts +8 -0
- package/dist/core/present-plan-tool.d.ts.map +1 -0
- package/dist/core/present-plan-tool.js +82 -0
- package/dist/core/present-plan-tool.js.map +1 -0
- package/dist/core/pricing.d.ts +22 -0
- package/dist/core/pricing.d.ts.map +1 -0
- package/dist/core/pricing.js +23 -0
- package/dist/core/pricing.js.map +1 -0
- package/dist/core/property-harness.d.ts +40 -0
- package/dist/core/property-harness.d.ts.map +1 -0
- package/dist/core/property-harness.js +121 -0
- package/dist/core/property-harness.js.map +1 -0
- package/dist/core/push-queue.d.ts +9 -0
- package/dist/core/push-queue.d.ts.map +1 -0
- package/dist/core/push-queue.js +41 -0
- package/dist/core/push-queue.js.map +1 -0
- package/dist/core/remote-env.d.ts +105 -0
- package/dist/core/remote-env.d.ts.map +1 -0
- package/dist/core/remote-env.js +27 -0
- package/dist/core/remote-env.js.map +1 -0
- package/dist/core/roles.d.ts +35 -0
- package/dist/core/roles.d.ts.map +1 -0
- package/dist/core/roles.js +182 -0
- package/dist/core/roles.js.map +1 -0
- package/dist/core/runner/active-skill-scope.d.ts +26 -0
- package/dist/core/runner/active-skill-scope.d.ts.map +1 -0
- package/dist/core/runner/active-skill-scope.js +116 -0
- package/dist/core/runner/active-skill-scope.js.map +1 -0
- package/dist/core/runner/assemble-result.d.ts +89 -0
- package/dist/core/runner/assemble-result.d.ts.map +1 -0
- package/dist/core/runner/assemble-result.js +141 -0
- package/dist/core/runner/assemble-result.js.map +1 -0
- package/dist/core/runner/call-cap.d.ts +38 -0
- package/dist/core/runner/call-cap.d.ts.map +1 -0
- package/dist/core/runner/call-cap.js +76 -0
- package/dist/core/runner/call-cap.js.map +1 -0
- package/dist/core/runner/grounding-signal.d.ts +2 -0
- package/dist/core/runner/grounding-signal.d.ts.map +1 -0
- package/dist/core/runner/grounding-signal.js +32 -0
- package/dist/core/runner/grounding-signal.js.map +1 -0
- package/dist/core/runner/image.d.ts +6 -0
- package/dist/core/runner/image.d.ts.map +1 -0
- package/dist/core/runner/image.js +116 -0
- package/dist/core/runner/image.js.map +1 -0
- package/dist/core/runner/memory-consolidation.d.ts +52 -0
- package/dist/core/runner/memory-consolidation.d.ts.map +1 -0
- package/dist/core/runner/memory-consolidation.js +253 -0
- package/dist/core/runner/memory-consolidation.js.map +1 -0
- package/dist/core/runner/prepare-task.d.ts +219 -0
- package/dist/core/runner/prepare-task.d.ts.map +1 -0
- package/dist/core/runner/prepare-task.js +2087 -0
- package/dist/core/runner/prepare-task.js.map +1 -0
- package/dist/core/runner/prompt-suggestions.d.ts +26 -0
- package/dist/core/runner/prompt-suggestions.d.ts.map +1 -0
- package/dist/core/runner/prompt-suggestions.js +104 -0
- package/dist/core/runner/prompt-suggestions.js.map +1 -0
- package/dist/core/runner/runtask.d.ts +53 -0
- package/dist/core/runner/runtask.d.ts.map +1 -0
- package/dist/core/runner/runtask.js +2703 -0
- package/dist/core/runner/runtask.js.map +1 -0
- package/dist/core/runner/session-rule-policy.d.ts +11 -0
- package/dist/core/runner/session-rule-policy.d.ts.map +1 -0
- package/dist/core/runner/session-rule-policy.js +76 -0
- package/dist/core/runner/session-rule-policy.js.map +1 -0
- package/dist/core/runner/strict-output-schema.d.ts +21 -0
- package/dist/core/runner/strict-output-schema.d.ts.map +1 -0
- package/dist/core/runner/strict-output-schema.js +304 -0
- package/dist/core/runner/strict-output-schema.js.map +1 -0
- package/dist/core/runner/synthetic-tools.d.ts +30 -0
- package/dist/core/runner/synthetic-tools.d.ts.map +1 -0
- package/dist/core/runner/synthetic-tools.js +124 -0
- package/dist/core/runner/synthetic-tools.js.map +1 -0
- package/dist/core/runner/tool-disclosure.d.ts +46 -0
- package/dist/core/runner/tool-disclosure.d.ts.map +1 -0
- package/dist/core/runner/tool-disclosure.js +220 -0
- package/dist/core/runner/tool-disclosure.js.map +1 -0
- package/dist/core/runner/turn-attachments.d.ts +110 -0
- package/dist/core/runner/turn-attachments.d.ts.map +1 -0
- package/dist/core/runner/turn-attachments.js +334 -0
- package/dist/core/runner/turn-attachments.js.map +1 -0
- package/dist/core/runner/usage-accounting.d.ts +19 -0
- package/dist/core/runner/usage-accounting.d.ts.map +1 -0
- package/dist/core/runner/usage-accounting.js +30 -0
- package/dist/core/runner/usage-accounting.js.map +1 -0
- package/dist/core/runtime.d.ts +4 -0
- package/dist/core/runtime.d.ts.map +1 -0
- package/dist/core/runtime.js +12 -0
- package/dist/core/runtime.js.map +1 -0
- package/dist/core/safety-axis-vocab.d.ts +10 -0
- package/dist/core/safety-axis-vocab.d.ts.map +1 -0
- package/dist/core/safety-axis-vocab.js +12 -0
- package/dist/core/safety-axis-vocab.js.map +1 -0
- package/dist/core/safety-merge-corpus.d.ts +11 -0
- package/dist/core/safety-merge-corpus.d.ts.map +1 -0
- package/dist/core/safety-merge-corpus.js +195 -0
- package/dist/core/safety-merge-corpus.js.map +1 -0
- package/dist/core/scheduler.d.ts +55 -0
- package/dist/core/scheduler.d.ts.map +1 -0
- package/dist/core/scheduler.js +32 -0
- package/dist/core/scheduler.js.map +1 -0
- package/dist/core/secret-env.d.ts +3 -0
- package/dist/core/secret-env.d.ts.map +1 -0
- package/dist/core/secret-env.js +13 -0
- package/dist/core/secret-env.js.map +1 -0
- package/dist/core/select-model.d.ts +11 -0
- package/dist/core/select-model.d.ts.map +1 -0
- package/dist/core/select-model.js +44 -0
- package/dist/core/select-model.js.map +1 -0
- package/dist/core/sensitive-path-policy.d.ts +9 -0
- package/dist/core/sensitive-path-policy.d.ts.map +1 -0
- package/dist/core/sensitive-path-policy.js +61 -0
- package/dist/core/sensitive-path-policy.js.map +1 -0
- package/dist/core/session-policy-store.d.ts +38 -0
- package/dist/core/session-policy-store.d.ts.map +1 -0
- package/dist/core/session-policy-store.js +112 -0
- package/dist/core/session-policy-store.js.map +1 -0
- package/dist/core/session-reconcile.d.ts +15 -0
- package/dist/core/session-reconcile.d.ts.map +1 -0
- package/dist/core/session-reconcile.js +48 -0
- package/dist/core/session-reconcile.js.map +1 -0
- package/dist/core/session-store.d.ts +36 -0
- package/dist/core/session-store.d.ts.map +1 -0
- package/dist/core/session-store.js +192 -0
- package/dist/core/session-store.js.map +1 -0
- package/dist/core/session.d.ts +44 -0
- package/dist/core/session.d.ts.map +1 -0
- package/dist/core/session.js +27 -0
- package/dist/core/session.js.map +1 -0
- package/dist/core/spec-contract.d.ts +58 -0
- package/dist/core/spec-contract.d.ts.map +1 -0
- package/dist/core/spec-contract.js +256 -0
- package/dist/core/spec-contract.js.map +1 -0
- package/dist/core/strategy-store.d.ts +25 -0
- package/dist/core/strategy-store.d.ts.map +1 -0
- package/dist/core/strategy-store.js +81 -0
- package/dist/core/strategy-store.js.map +1 -0
- package/dist/core/stub-env.d.ts +28 -0
- package/dist/core/stub-env.d.ts.map +1 -0
- package/dist/core/stub-env.js +61 -0
- package/dist/core/stub-env.js.map +1 -0
- package/dist/core/task-notification.d.ts +56 -0
- package/dist/core/task-notification.d.ts.map +1 -0
- package/dist/core/task-notification.js +200 -0
- package/dist/core/task-notification.js.map +1 -0
- package/dist/core/task-outcome.d.ts +27 -0
- package/dist/core/task-outcome.d.ts.map +1 -0
- package/dist/core/task-outcome.js +12 -0
- package/dist/core/task-outcome.js.map +1 -0
- package/dist/core/task-registry.d.ts +188 -0
- package/dist/core/task-registry.d.ts.map +1 -0
- package/dist/core/task-registry.js +1443 -0
- package/dist/core/task-registry.js.map +1 -0
- package/dist/core/tighten-task-spec.d.ts +6 -0
- package/dist/core/tighten-task-spec.d.ts.map +1 -0
- package/dist/core/tighten-task-spec.js +50 -0
- package/dist/core/tighten-task-spec.js.map +1 -0
- package/dist/core/tool-detach.d.ts +10 -0
- package/dist/core/tool-detach.d.ts.map +1 -0
- package/dist/core/tool-detach.js +41 -0
- package/dist/core/tool-detach.js.map +1 -0
- package/dist/core/tool-errors.d.ts +8 -0
- package/dist/core/tool-errors.d.ts.map +1 -0
- package/dist/core/tool-errors.js +132 -0
- package/dist/core/tool-errors.js.map +1 -0
- package/dist/core/tool-name-aliases.d.ts +3 -0
- package/dist/core/tool-name-aliases.d.ts.map +1 -0
- package/dist/core/tool-name-aliases.js +60 -0
- package/dist/core/tool-name-aliases.js.map +1 -0
- package/dist/core/tool-policy.d.ts +75 -0
- package/dist/core/tool-policy.d.ts.map +1 -0
- package/dist/core/tool-policy.js +363 -0
- package/dist/core/tool-policy.js.map +1 -0
- package/dist/core/tool-result-budget.d.ts +17 -0
- package/dist/core/tool-result-budget.d.ts.map +1 -0
- package/dist/core/tool-result-budget.js +103 -0
- package/dist/core/tool-result-budget.js.map +1 -0
- package/dist/core/tool-result-store.d.ts +55 -0
- package/dist/core/tool-result-store.d.ts.map +1 -0
- package/dist/core/tool-result-store.js +154 -0
- package/dist/core/tool-result-store.js.map +1 -0
- package/dist/core/tools.d.ts +6 -0
- package/dist/core/tools.d.ts.map +1 -0
- package/dist/core/tools.js +61 -0
- package/dist/core/tools.js.map +1 -0
- package/dist/core/trace.d.ts +208 -0
- package/dist/core/trace.d.ts.map +1 -0
- package/dist/core/trace.js +10 -0
- package/dist/core/trace.js.map +1 -0
- package/dist/core/types.d.ts +684 -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 +7 -0
- package/dist/core/untrusted-egress.d.ts.map +1 -0
- package/dist/core/untrusted-egress.js +23 -0
- package/dist/core/untrusted-egress.js.map +1 -0
- package/dist/core/untrusted-text.d.ts +5 -0
- package/dist/core/untrusted-text.d.ts.map +1 -0
- package/dist/core/untrusted-text.js +36 -0
- package/dist/core/untrusted-text.js.map +1 -0
- package/dist/core/warm-resume.d.ts +6 -0
- package/dist/core/warm-resume.d.ts.map +1 -0
- package/dist/core/warm-resume.js +11 -0
- package/dist/core/warm-resume.js.map +1 -0
- package/dist/core/with-retry.d.ts +19 -0
- package/dist/core/with-retry.d.ts.map +1 -0
- package/dist/core/with-retry.js +36 -0
- package/dist/core/with-retry.js.map +1 -0
- package/dist/core/workflow-journal-store.d.ts +16 -0
- package/dist/core/workflow-journal-store.d.ts.map +1 -0
- package/dist/core/workflow-journal-store.js +34 -0
- package/dist/core/workflow-journal-store.js.map +1 -0
- package/dist/core/workflow-run-store-contract.d.ts +6 -0
- package/dist/core/workflow-run-store-contract.d.ts.map +1 -0
- package/dist/core/workflow-run-store-contract.js +144 -0
- package/dist/core/workflow-run-store-contract.js.map +1 -0
- package/dist/core/workflow-run-store.d.ts +54 -0
- package/dist/core/workflow-run-store.d.ts.map +1 -0
- package/dist/core/workflow-run-store.js +86 -0
- package/dist/core/workflow-run-store.js.map +1 -0
- package/dist/engine/compaction/compaction.d.ts +63 -0
- package/dist/engine/compaction/compaction.d.ts.map +1 -0
- package/dist/engine/compaction/compaction.js +770 -0
- package/dist/engine/compaction/compaction.js.map +1 -0
- package/dist/engine/compaction/utils.d.ts +19 -0
- package/dist/engine/compaction/utils.d.ts.map +1 -0
- package/dist/engine/compaction/utils.js +167 -0
- package/dist/engine/compaction/utils.js.map +1 -0
- package/dist/engine/execution-env/kill-tree.d.ts +10 -0
- package/dist/engine/execution-env/kill-tree.d.ts.map +1 -0
- package/dist/engine/execution-env/kill-tree.js +143 -0
- package/dist/engine/execution-env/kill-tree.js.map +1 -0
- package/dist/engine/execution-env/node-execution-env.d.ts +98 -0
- package/dist/engine/execution-env/node-execution-env.d.ts.map +1 -0
- package/dist/engine/execution-env/node-execution-env.js +945 -0
- package/dist/engine/execution-env/node-execution-env.js.map +1 -0
- package/dist/engine/harness/agent-harness.d.ts +112 -0
- package/dist/engine/harness/agent-harness.d.ts.map +1 -0
- package/dist/engine/harness/agent-harness.js +932 -0
- package/dist/engine/harness/agent-harness.js.map +1 -0
- package/dist/engine/harness/messages.d.ts +12 -0
- package/dist/engine/harness/messages.d.ts.map +1 -0
- package/dist/engine/harness/messages.js +102 -0
- package/dist/engine/harness/messages.js.map +1 -0
- package/dist/engine/harness/types.d.ts +484 -0
- package/dist/engine/harness/types.d.ts.map +1 -0
- package/dist/engine/harness/types.js +91 -0
- package/dist/engine/harness/types.js.map +1 -0
- package/dist/engine/llm/diagnostics.d.ts +19 -0
- package/dist/engine/llm/diagnostics.d.ts.map +1 -0
- package/dist/engine/llm/diagnostics.js +28 -0
- package/dist/engine/llm/diagnostics.js.map +1 -0
- package/dist/engine/llm/event-stream.d.ts +22 -0
- package/dist/engine/llm/event-stream.d.ts.map +1 -0
- package/dist/engine/llm/event-stream.js +91 -0
- package/dist/engine/llm/event-stream.js.map +1 -0
- package/dist/engine/llm/index.d.ts +5 -0
- package/dist/engine/llm/index.d.ts.map +1 -0
- package/dist/engine/llm/index.js +5 -0
- package/dist/engine/llm/index.js.map +1 -0
- package/dist/engine/llm/types.d.ts +359 -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 +5 -0
- package/dist/engine/llm/validation.d.ts.map +1 -0
- package/dist/engine/llm/validation.js +293 -0
- package/dist/engine/llm/validation.js.map +1 -0
- package/dist/engine/loop/agent-loop.d.ts +19 -0
- package/dist/engine/loop/agent-loop.d.ts.map +1 -0
- package/dist/engine/loop/agent-loop.js +1087 -0
- package/dist/engine/loop/agent-loop.js.map +1 -0
- package/dist/engine/loop/runtime-deps.d.ts +10 -0
- package/dist/engine/loop/runtime-deps.d.ts.map +1 -0
- package/dist/engine/loop/runtime-deps.js +19 -0
- package/dist/engine/loop/runtime-deps.js.map +1 -0
- package/dist/engine/loop/types.d.ts +209 -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 +3 -0
- package/dist/engine/lsp/frame-decoder.d.ts.map +1 -0
- package/dist/engine/lsp/frame-decoder.js +36 -0
- package/dist/engine/lsp/frame-decoder.js.map +1 -0
- package/dist/engine/lsp/node-lsp-manager.d.ts +49 -0
- package/dist/engine/lsp/node-lsp-manager.d.ts.map +1 -0
- package/dist/engine/lsp/node-lsp-manager.js +267 -0
- package/dist/engine/lsp/node-lsp-manager.js.map +1 -0
- package/dist/engine/lsp/stdio-lsp-transport.d.ts +32 -0
- package/dist/engine/lsp/stdio-lsp-transport.d.ts.map +1 -0
- package/dist/engine/lsp/stdio-lsp-transport.js +154 -0
- package/dist/engine/lsp/stdio-lsp-transport.js.map +1 -0
- package/dist/engine/session/import-validate.d.ts +13 -0
- package/dist/engine/session/import-validate.d.ts.map +1 -0
- package/dist/engine/session/import-validate.js +56 -0
- package/dist/engine/session/import-validate.js.map +1 -0
- package/dist/engine/session/memory-repo.d.ts +20 -0
- package/dist/engine/session/memory-repo.d.ts.map +1 -0
- package/dist/engine/session/memory-repo.js +54 -0
- package/dist/engine/session/memory-repo.js.map +1 -0
- package/dist/engine/session/memory-storage.d.ts +12 -0
- package/dist/engine/session/memory-storage.d.ts.map +1 -0
- package/dist/engine/session/memory-storage.js +16 -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 +27 -0
- package/dist/engine/session/session.d.ts.map +1 -0
- package/dist/engine/session/session.js +197 -0
- package/dist/engine/session/session.js.map +1 -0
- package/dist/engine/session/storage-base.d.ts +30 -0
- package/dist/engine/session/storage-base.d.ts.map +1 -0
- package/dist/engine/session/storage-base.js +138 -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 +156 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +141 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/harness.d.ts +19 -0
- package/dist/internal/harness.d.ts.map +1 -0
- package/dist/internal/harness.js +13 -0
- package/dist/internal/harness.js.map +1 -0
- package/dist/internal/llm.d.ts +3 -0
- package/dist/internal/llm.d.ts.map +1 -0
- package/dist/internal/llm.js +2 -0
- package/dist/internal/llm.js.map +1 -0
- package/dist/orchestration/builtin-workflows.d.ts +11 -0
- package/dist/orchestration/builtin-workflows.d.ts.map +1 -0
- package/dist/orchestration/builtin-workflows.js +134 -0
- package/dist/orchestration/builtin-workflows.js.map +1 -0
- package/dist/orchestration/dev-vm-script-runner.d.ts +5 -0
- package/dist/orchestration/dev-vm-script-runner.d.ts.map +1 -0
- package/dist/orchestration/dev-vm-script-runner.js +68 -0
- package/dist/orchestration/dev-vm-script-runner.js.map +1 -0
- package/dist/orchestration/goal.d.ts +40 -0
- package/dist/orchestration/goal.d.ts.map +1 -0
- package/dist/orchestration/goal.js +190 -0
- package/dist/orchestration/goal.js.map +1 -0
- package/dist/orchestration/run-spec.d.ts +21 -0
- package/dist/orchestration/run-spec.d.ts.map +1 -0
- package/dist/orchestration/run-spec.js +201 -0
- package/dist/orchestration/run-spec.js.map +1 -0
- package/dist/orchestration/run-workflow-tool.d.ts +80 -0
- package/dist/orchestration/run-workflow-tool.d.ts.map +1 -0
- package/dist/orchestration/run-workflow-tool.js +431 -0
- package/dist/orchestration/run-workflow-tool.js.map +1 -0
- package/dist/orchestration/workflow-governance.d.ts +30 -0
- package/dist/orchestration/workflow-governance.d.ts.map +1 -0
- package/dist/orchestration/workflow-governance.js +125 -0
- package/dist/orchestration/workflow-governance.js.map +1 -0
- package/dist/orchestration/workflow-meta.d.ts +13 -0
- package/dist/orchestration/workflow-meta.d.ts.map +1 -0
- package/dist/orchestration/workflow-meta.js +367 -0
- package/dist/orchestration/workflow-meta.js.map +1 -0
- package/dist/orchestration/workflow-observe.d.ts +18 -0
- package/dist/orchestration/workflow-observe.d.ts.map +1 -0
- package/dist/orchestration/workflow-observe.js +73 -0
- package/dist/orchestration/workflow-observe.js.map +1 -0
- package/dist/orchestration/workflow-primitives.d.ts +12 -0
- package/dist/orchestration/workflow-primitives.d.ts.map +1 -0
- package/dist/orchestration/workflow-primitives.js +56 -0
- package/dist/orchestration/workflow-primitives.js.map +1 -0
- package/dist/orchestration/workflow-sandbox-conformance.d.ts +5 -0
- package/dist/orchestration/workflow-sandbox-conformance.d.ts.map +1 -0
- package/dist/orchestration/workflow-sandbox-conformance.js +220 -0
- package/dist/orchestration/workflow-sandbox-conformance.js.map +1 -0
- package/dist/orchestration/workflow-script-runner.d.ts +39 -0
- package/dist/orchestration/workflow-script-runner.d.ts.map +1 -0
- package/dist/orchestration/workflow-script-runner.js +23 -0
- package/dist/orchestration/workflow-script-runner.js.map +1 -0
- package/dist/orchestration/workflow-script-store.d.ts +20 -0
- package/dist/orchestration/workflow-script-store.d.ts.map +1 -0
- package/dist/orchestration/workflow-script-store.js +73 -0
- package/dist/orchestration/workflow-script-store.js.map +1 -0
- package/dist/orchestration/workflow-size-guideline.d.ts +10 -0
- package/dist/orchestration/workflow-size-guideline.d.ts.map +1 -0
- package/dist/orchestration/workflow-size-guideline.js +38 -0
- package/dist/orchestration/workflow-size-guideline.js.map +1 -0
- package/dist/orchestration/workflow.d.ts +281 -0
- package/dist/orchestration/workflow.d.ts.map +1 -0
- package/dist/orchestration/workflow.js +1095 -0
- package/dist/orchestration/workflow.js.map +1 -0
- package/dist/prompts/default.d.ts +104 -0
- package/dist/prompts/default.d.ts.map +1 -0
- package/dist/prompts/default.js +397 -0
- package/dist/prompts/default.js.map +1 -0
- package/dist/prompts/supervisor.d.ts +5 -0
- package/dist/prompts/supervisor.d.ts.map +1 -0
- package/dist/prompts/supervisor.js +107 -0
- package/dist/prompts/supervisor.js.map +1 -0
- package/dist/scenarios/env.d.ts +13 -0
- package/dist/scenarios/env.d.ts.map +1 -0
- package/dist/scenarios/env.js +40 -0
- package/dist/scenarios/env.js.map +1 -0
- package/dist/scenarios/full-body.d.ts +13 -0
- package/dist/scenarios/full-body.d.ts.map +1 -0
- package/dist/scenarios/full-body.js +20 -0
- package/dist/scenarios/full-body.js.map +1 -0
- package/dist/scenarios/scenario-registry.d.ts +47 -0
- package/dist/scenarios/scenario-registry.d.ts.map +1 -0
- package/dist/scenarios/scenario-registry.js +139 -0
- package/dist/scenarios/scenario-registry.js.map +1 -0
- package/dist/scenarios/teacher-quickstart.d.ts +14 -0
- package/dist/scenarios/teacher-quickstart.d.ts.map +1 -0
- package/dist/scenarios/teacher-quickstart.js +13 -0
- package/dist/scenarios/teacher-quickstart.js.map +1 -0
- package/dist/server/http.d.ts +19 -0
- package/dist/server/http.d.ts.map +1 -0
- package/dist/server/http.js +115 -0
- package/dist/server/http.js.map +1 -0
- package/dist/stores/file/checkpoint-store.d.ts +40 -0
- package/dist/stores/file/checkpoint-store.d.ts.map +1 -0
- package/dist/stores/file/checkpoint-store.js +198 -0
- package/dist/stores/file/checkpoint-store.js.map +1 -0
- package/dist/stores/file/file-snapshot-store.d.ts +25 -0
- package/dist/stores/file/file-snapshot-store.d.ts.map +1 -0
- package/dist/stores/file/file-snapshot-store.js +313 -0
- package/dist/stores/file/file-snapshot-store.js.map +1 -0
- package/dist/stores/file/fs-atomic.d.ts +24 -0
- package/dist/stores/file/fs-atomic.d.ts.map +1 -0
- package/dist/stores/file/fs-atomic.js +276 -0
- package/dist/stores/file/fs-atomic.js.map +1 -0
- package/dist/stores/file/index.d.ts +45 -0
- package/dist/stores/file/index.d.ts.map +1 -0
- package/dist/stores/file/index.js +77 -0
- package/dist/stores/file/index.js.map +1 -0
- package/dist/stores/file/memory-store.d.ts +35 -0
- package/dist/stores/file/memory-store.d.ts.map +1 -0
- package/dist/stores/file/memory-store.js +300 -0
- package/dist/stores/file/memory-store.js.map +1 -0
- package/dist/stores/file/session-policy-store.d.ts +11 -0
- package/dist/stores/file/session-policy-store.d.ts.map +1 -0
- package/dist/stores/file/session-policy-store.js +96 -0
- package/dist/stores/file/session-policy-store.js.map +1 -0
- package/dist/stores/file/session-store.d.ts +24 -0
- package/dist/stores/file/session-store.d.ts.map +1 -0
- package/dist/stores/file/session-store.js +134 -0
- package/dist/stores/file/session-store.js.map +1 -0
- package/dist/stores/file/tool-result-store.d.ts +12 -0
- package/dist/stores/file/tool-result-store.d.ts.map +1 -0
- package/dist/stores/file/tool-result-store.js +44 -0
- package/dist/stores/file/tool-result-store.js.map +1 -0
- package/dist/stores/file/workflow-journal-store.d.ts +17 -0
- package/dist/stores/file/workflow-journal-store.d.ts.map +1 -0
- package/dist/stores/file/workflow-journal-store.js +104 -0
- package/dist/stores/file/workflow-journal-store.js.map +1 -0
- package/dist/stores/file/workflow-run-store.d.ts +41 -0
- package/dist/stores/file/workflow-run-store.d.ts.map +1 -0
- package/dist/stores/file/workflow-run-store.js +147 -0
- package/dist/stores/file/workflow-run-store.js.map +1 -0
- package/dist/stores/pg.d.ts +96 -0
- package/dist/stores/pg.d.ts.map +1 -0
- package/dist/stores/pg.js +451 -0
- package/dist/stores/pg.js.map +1 -0
- package/dist/tools/fs/encoding.d.ts +16 -0
- package/dist/tools/fs/encoding.d.ts.map +1 -0
- package/dist/tools/fs/encoding.js +44 -0
- package/dist/tools/fs/encoding.js.map +1 -0
- package/dist/tools/fs/gh-rate-limit.d.ts +3 -0
- package/dist/tools/fs/gh-rate-limit.d.ts.map +1 -0
- package/dist/tools/fs/gh-rate-limit.js +16 -0
- package/dist/tools/fs/gh-rate-limit.js.map +1 -0
- package/dist/tools/fs/index.d.ts +74 -0
- package/dist/tools/fs/index.d.ts.map +1 -0
- package/dist/tools/fs/index.js +1576 -0
- package/dist/tools/fs/index.js.map +1 -0
- package/dist/tools/fs/pdf.d.ts +47 -0
- package/dist/tools/fs/pdf.d.ts.map +1 -0
- package/dist/tools/fs/pdf.js +124 -0
- package/dist/tools/fs/pdf.js.map +1 -0
- package/dist/tools/fs/repo-map.d.ts +5 -0
- package/dist/tools/fs/repo-map.d.ts.map +1 -0
- package/dist/tools/fs/repo-map.js +209 -0
- package/dist/tools/fs/repo-map.js.map +1 -0
- package/dist/tools/fs/safety.d.ts +52 -0
- package/dist/tools/fs/safety.d.ts.map +1 -0
- package/dist/tools/fs/safety.js +314 -0
- package/dist/tools/fs/safety.js.map +1 -0
- package/dist/tools/fs/search.d.ts +57 -0
- package/dist/tools/fs/search.d.ts.map +1 -0
- package/dist/tools/fs/search.js +574 -0
- package/dist/tools/fs/search.js.map +1 -0
- package/dist/tools/gitea-issue.d.ts +14 -0
- package/dist/tools/gitea-issue.d.ts.map +1 -0
- package/dist/tools/gitea-issue.js +74 -0
- package/dist/tools/gitea-issue.js.map +1 -0
- package/dist/tools/monitor.d.ts +20 -0
- package/dist/tools/monitor.d.ts.map +1 -0
- package/dist/tools/monitor.js +90 -0
- package/dist/tools/monitor.js.map +1 -0
- package/dist/tools/scheduler-tools.d.ts +15 -0
- package/dist/tools/scheduler-tools.d.ts.map +1 -0
- package/dist/tools/scheduler-tools.js +338 -0
- package/dist/tools/scheduler-tools.js.map +1 -0
- package/dist/tools/sql-adapters.d.ts +14 -0
- package/dist/tools/sql-adapters.d.ts.map +1 -0
- package/dist/tools/sql-adapters.js +13 -0
- package/dist/tools/sql-adapters.js.map +1 -0
- package/dist/tools/sql.d.ts +11 -0
- package/dist/tools/sql.d.ts.map +1 -0
- package/dist/tools/sql.js +104 -0
- package/dist/tools/sql.js.map +1 -0
- package/dist/tools/task-list.d.ts +14 -0
- package/dist/tools/task-list.d.ts.map +1 -0
- package/dist/tools/task-list.js +318 -0
- package/dist/tools/task-list.js.map +1 -0
- package/dist/tools/todo.d.ts +3 -0
- package/dist/tools/todo.d.ts.map +1 -0
- package/dist/tools/todo.js +97 -0
- package/dist/tools/todo.js.map +1 -0
- package/dist/tools/web.d.ts +26 -0
- package/dist/tools/web.d.ts.map +1 -0
- package/dist/tools/web.js +498 -0
- package/dist/tools/web.js.map +1 -0
- package/dist/tools/worktree.d.ts +18 -0
- package/dist/tools/worktree.d.ts.map +1 -0
- package/dist/tools/worktree.js +288 -0
- package/dist/tools/worktree.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,1087 @@
|
|
|
1
|
+
import { EventStream as LlmEventStream } from "../llm/index.js";
|
|
2
|
+
import { findToolByName, validateToolArguments } from "../llm/index.js";
|
|
3
|
+
import { TOMBSTONED_TOOLS } from "../../core/tool-name-aliases.js";
|
|
4
|
+
import { resolveAgentCoreStreamFn } from "./runtime-deps.js";
|
|
5
|
+
const EMPTY_USAGE = {
|
|
6
|
+
input: 0,
|
|
7
|
+
output: 0,
|
|
8
|
+
cacheRead: 0,
|
|
9
|
+
cacheWrite: 0,
|
|
10
|
+
totalTokens: 0,
|
|
11
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
12
|
+
};
|
|
13
|
+
const EventStreamConstructor = LlmEventStream;
|
|
14
|
+
function appendTextDeltaToAssistantMessage(message, contentIndex, delta) {
|
|
15
|
+
const content = [...message.content];
|
|
16
|
+
const currentContent = content[contentIndex];
|
|
17
|
+
content[contentIndex] =
|
|
18
|
+
currentContent?.type === "text"
|
|
19
|
+
? { ...currentContent, text: currentContent.text + delta }
|
|
20
|
+
: { type: "text", text: delta };
|
|
21
|
+
return { ...message, content };
|
|
22
|
+
}
|
|
23
|
+
function resolveAssistantMessageUpdate(event, currentMessage) {
|
|
24
|
+
if ("partial" in event && event.partial) {
|
|
25
|
+
return event.partial;
|
|
26
|
+
}
|
|
27
|
+
if (event.type === "text_delta") {
|
|
28
|
+
return appendTextDeltaToAssistantMessage(currentMessage, event.contentIndex, event.delta);
|
|
29
|
+
}
|
|
30
|
+
return currentMessage;
|
|
31
|
+
}
|
|
32
|
+
export function agentLoop(prompts, context, config, signal, streamFn, runtime) {
|
|
33
|
+
const stream = createAgentStream();
|
|
34
|
+
void runAgentLoop(prompts, context, config, async (event) => {
|
|
35
|
+
stream.push(event);
|
|
36
|
+
}, signal, streamFn, runtime)
|
|
37
|
+
.then((messages) => {
|
|
38
|
+
stream.end(messages);
|
|
39
|
+
})
|
|
40
|
+
.catch((error) => {
|
|
41
|
+
pushLoopFailure(stream, config, error, signal?.aborted === true);
|
|
42
|
+
});
|
|
43
|
+
return stream;
|
|
44
|
+
}
|
|
45
|
+
export function agentLoopContinue(context, config, signal, streamFn, runtime) {
|
|
46
|
+
if (context.messages.length === 0) {
|
|
47
|
+
throw new Error("Cannot continue: no messages in context");
|
|
48
|
+
}
|
|
49
|
+
if (context.messages[context.messages.length - 1].role === "assistant") {
|
|
50
|
+
throw new Error("Cannot continue from message role: assistant");
|
|
51
|
+
}
|
|
52
|
+
const stream = createAgentStream();
|
|
53
|
+
void runAgentLoopContinue(context, config, async (event) => {
|
|
54
|
+
stream.push(event);
|
|
55
|
+
}, signal, streamFn, runtime)
|
|
56
|
+
.then((messages) => {
|
|
57
|
+
stream.end(messages);
|
|
58
|
+
})
|
|
59
|
+
.catch((error) => {
|
|
60
|
+
pushLoopFailure(stream, config, error, signal?.aborted === true);
|
|
61
|
+
});
|
|
62
|
+
return stream;
|
|
63
|
+
}
|
|
64
|
+
export async function runAgentLoop(prompts, context, config, emit, signal, streamFn, runtime, trace) {
|
|
65
|
+
const newMessages = [...prompts];
|
|
66
|
+
const currentContext = {
|
|
67
|
+
...context,
|
|
68
|
+
messages: [...context.messages, ...prompts],
|
|
69
|
+
};
|
|
70
|
+
await emit({ type: "agent_start" });
|
|
71
|
+
await emit({ type: "turn_start" });
|
|
72
|
+
for (const prompt of prompts) {
|
|
73
|
+
await emit({ type: "message_start", message: prompt });
|
|
74
|
+
await emit({ type: "message_end", message: prompt });
|
|
75
|
+
}
|
|
76
|
+
await runLoop(currentContext, newMessages, config, signal, emit, streamFn, runtime, trace);
|
|
77
|
+
return newMessages;
|
|
78
|
+
}
|
|
79
|
+
export async function runAgentLoopContinue(context, config, emit, signal, streamFn, runtime, trace) {
|
|
80
|
+
if (context.messages.length === 0) {
|
|
81
|
+
throw new Error("Cannot continue: no messages in context");
|
|
82
|
+
}
|
|
83
|
+
if (context.messages[context.messages.length - 1].role === "assistant") {
|
|
84
|
+
throw new Error("Cannot continue from message role: assistant");
|
|
85
|
+
}
|
|
86
|
+
const newMessages = [];
|
|
87
|
+
const currentContext = { ...context };
|
|
88
|
+
await emit({ type: "agent_start" });
|
|
89
|
+
await emit({ type: "turn_start" });
|
|
90
|
+
await runLoop(currentContext, newMessages, config, signal, emit, streamFn, runtime, trace);
|
|
91
|
+
return newMessages;
|
|
92
|
+
}
|
|
93
|
+
function createAgentStream() {
|
|
94
|
+
return new EventStreamConstructor((event) => event.type === "agent_end", (event) => (event.type === "agent_end" ? event.messages : []));
|
|
95
|
+
}
|
|
96
|
+
function createLoopFailureMessage(config, error, aborted) {
|
|
97
|
+
return {
|
|
98
|
+
role: "assistant",
|
|
99
|
+
content: [{ type: "text", text: "" }],
|
|
100
|
+
api: config.model.api,
|
|
101
|
+
provider: config.model.provider,
|
|
102
|
+
model: config.model.id,
|
|
103
|
+
usage: EMPTY_USAGE,
|
|
104
|
+
stopReason: aborted ? "aborted" : "error",
|
|
105
|
+
errorMessage: error instanceof Error ? error.message : String(error),
|
|
106
|
+
timestamp: Date.now(),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function pushLoopFailure(stream, config, error, aborted) {
|
|
110
|
+
const failureMessage = createLoopFailureMessage(config, error, aborted);
|
|
111
|
+
stream.push({ type: "message_start", message: failureMessage });
|
|
112
|
+
stream.push({ type: "message_end", message: failureMessage });
|
|
113
|
+
stream.push({ type: "turn_end", message: failureMessage, toolResults: [] });
|
|
114
|
+
stream.push({ type: "agent_end", messages: [failureMessage] });
|
|
115
|
+
}
|
|
116
|
+
const PROMPT_TOO_LONG_RE = /context.{0,3}length|context_length|context window (?:limit|exceeded)|reached its context window|prompt is too long|too many tokens|maximum context|exceeds? .{0,30}(?:context|token)|input is too long|\b413\b/i;
|
|
117
|
+
function isBlankFailureContent(message) {
|
|
118
|
+
return message.content.every((c) => c.type === "text" ? c.text.trim() === "" : c.type === "thinking" ? c.thinking.trim() === "" : false);
|
|
119
|
+
}
|
|
120
|
+
function defaultDetectPromptTooLong(message) {
|
|
121
|
+
return message.stopReason === "error" && PROMPT_TOO_LONG_RE.test(message.errorMessage ?? "");
|
|
122
|
+
}
|
|
123
|
+
function createPtlWithholdBuffer(emit, detect) {
|
|
124
|
+
const held = [];
|
|
125
|
+
let liveStartEmitted = false;
|
|
126
|
+
const isCandidate = (message) => message.role === "assistant" &&
|
|
127
|
+
message.stopReason === "error" &&
|
|
128
|
+
detect(message) &&
|
|
129
|
+
isBlankFailureContent(message);
|
|
130
|
+
return {
|
|
131
|
+
sink: async (event) => {
|
|
132
|
+
if (event.type === "message_start" && isCandidate(event.message)) {
|
|
133
|
+
held.push(event);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (event.type === "message_end" && !liveStartEmitted && isCandidate(event.message)) {
|
|
137
|
+
held.push(event);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (event.type === "message_start")
|
|
141
|
+
liveStartEmitted = true;
|
|
142
|
+
await emit(event);
|
|
143
|
+
},
|
|
144
|
+
async flush() {
|
|
145
|
+
for (const event of held.splice(0))
|
|
146
|
+
await emit(event);
|
|
147
|
+
},
|
|
148
|
+
discard() {
|
|
149
|
+
held.length = 0;
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function createMalformedToolUseNudge() {
|
|
154
|
+
return {
|
|
155
|
+
role: "custom",
|
|
156
|
+
customType: "loop:malformed-tool-use-retry",
|
|
157
|
+
content: "Your previous response indicated tool use but contained no valid tool call. Re-issue the tool call(s) now, with complete and valid JSON arguments — provide exactly one JSON value per parameter, and do not truncate.",
|
|
158
|
+
display: false,
|
|
159
|
+
timestamp: Date.now(),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function createThinkingOnlyNudge() {
|
|
163
|
+
return {
|
|
164
|
+
role: "custom",
|
|
165
|
+
customType: "loop:thinking-only-retry",
|
|
166
|
+
content: "Your previous response had no visible output — it contained only internal reasoning. Respond now with your answer as visible text (or make the required tool calls); do not end the turn with reasoning alone.",
|
|
167
|
+
display: false,
|
|
168
|
+
timestamp: Date.now(),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function createMidstreamPartialContinueNudge() {
|
|
172
|
+
return {
|
|
173
|
+
role: "custom",
|
|
174
|
+
customType: "loop:midstream-partial-continue",
|
|
175
|
+
content: "Your previous response was cut off mid-stream by a connection failure — the content above may be incomplete. Continue EXACTLY where you left off; do not repeat any content you already produced, do not re-introduce or summarize.",
|
|
176
|
+
display: false,
|
|
177
|
+
timestamp: Date.now(),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function createDegenerateRecoveryNudge() {
|
|
181
|
+
return {
|
|
182
|
+
role: "custom",
|
|
183
|
+
customType: "loop:degenerate-output-recovery",
|
|
184
|
+
content: "Your previous reply degenerated into repetition and was cut off. Do NOT repeat or continue that text. " +
|
|
185
|
+
"Take a DIFFERENT approach: state your next concrete step or conclusion in one short sentence, then proceed normally.",
|
|
186
|
+
display: false,
|
|
187
|
+
timestamp: Date.now(),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function createWalltimeCutoffRecoveryNudge() {
|
|
191
|
+
return {
|
|
192
|
+
role: "custom",
|
|
193
|
+
customType: "loop:walltime-cutoff-recovery",
|
|
194
|
+
content: "Your previous response crossed the task's wall-clock deadline and was cut off (the partial text above is preserved). " +
|
|
195
|
+
"This is the FINAL turn: write your best current answer / deliverables NOW in one short response — no new work, no long commands.",
|
|
196
|
+
display: false,
|
|
197
|
+
timestamp: Date.now(),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function createReasoningCutContinueNudge() {
|
|
201
|
+
return {
|
|
202
|
+
role: "custom",
|
|
203
|
+
customType: "loop:truncated-output-continue",
|
|
204
|
+
content: "Your previous response hit the output-token limit before producing any visible text (the budget went to internal reasoning). " +
|
|
205
|
+
"Do NOT restart the long reasoning: state your current best answer or next concrete action directly as visible text (or make the required tool call) now.",
|
|
206
|
+
display: false,
|
|
207
|
+
timestamp: Date.now(),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function createContinueNudge() {
|
|
211
|
+
return {
|
|
212
|
+
role: "custom",
|
|
213
|
+
customType: "loop:truncated-output-continue",
|
|
214
|
+
content: "Your previous response was cut off because it hit the output-token limit. Continue EXACTLY where you left off — do not repeat any content you already produced, do not re-introduce or summarize.",
|
|
215
|
+
display: false,
|
|
216
|
+
timestamp: Date.now(),
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
async function runLoop(initialContext, newMessages, initialConfig, signal, emit, streamFn, runtime, trace) {
|
|
220
|
+
const state = {
|
|
221
|
+
context: initialContext,
|
|
222
|
+
config: initialConfig,
|
|
223
|
+
newMessages,
|
|
224
|
+
firstTurn: true,
|
|
225
|
+
pendingMessages: (await initialConfig.getSteeringMessages?.()) || [],
|
|
226
|
+
hasMoreToolCalls: true,
|
|
227
|
+
truncatedOutputContinues: 0,
|
|
228
|
+
staticReasoningCutRecoveries: initialContext.messages.filter((m) => m.role === "assistant" && m.staticReasoningCut === true).length,
|
|
229
|
+
degenerateContinues: 0,
|
|
230
|
+
walltimeCutoffContinues: 0,
|
|
231
|
+
malformedToolUseRetries: 0,
|
|
232
|
+
thinkingOnlyRetries: 0,
|
|
233
|
+
midstreamPartialContinues: 0,
|
|
234
|
+
};
|
|
235
|
+
while (true) {
|
|
236
|
+
if (!state.hasMoreToolCalls && state.pendingMessages.length === 0) {
|
|
237
|
+
const followUpMessages = (await state.config.getFollowUpMessages?.()) || [];
|
|
238
|
+
if (followUpMessages.length === 0) {
|
|
239
|
+
trace?.({ kind: "terminal", reason: "completed" });
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
state.pendingMessages = followUpMessages;
|
|
243
|
+
trace?.({ kind: "continue", reason: "follow_up_injected" });
|
|
244
|
+
}
|
|
245
|
+
const outcome = await runSingleTurn(state, signal, emit, streamFn, runtime, trace);
|
|
246
|
+
if (outcome.kind === "terminal") {
|
|
247
|
+
trace?.({ kind: "terminal", reason: outcome.reason });
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
if (outcome.recovered) {
|
|
251
|
+
trace?.({ kind: "continue", reason: outcome.recovered });
|
|
252
|
+
}
|
|
253
|
+
else if (state.pendingMessages.length > 0) {
|
|
254
|
+
trace?.({ kind: "continue", reason: "steer_injected" });
|
|
255
|
+
}
|
|
256
|
+
else if (state.hasMoreToolCalls) {
|
|
257
|
+
trace?.({ kind: "continue", reason: "next_turn" });
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
await emit({ type: "agent_end", messages: state.newMessages });
|
|
261
|
+
}
|
|
262
|
+
const MAX_STATIC_REASONING_CUT_RECOVERIES = 2;
|
|
263
|
+
async function runSingleTurn(state, signal, emit, streamFn, runtime, trace) {
|
|
264
|
+
if (signal?.aborted) {
|
|
265
|
+
await emit({ type: "agent_end", messages: state.newMessages });
|
|
266
|
+
return { kind: "terminal", reason: "aborted_before_stream" };
|
|
267
|
+
}
|
|
268
|
+
if (!state.firstTurn) {
|
|
269
|
+
await emit({ type: "turn_start" });
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
state.firstTurn = false;
|
|
273
|
+
}
|
|
274
|
+
if (state.pendingMessages.length > 0) {
|
|
275
|
+
for (const message of state.pendingMessages) {
|
|
276
|
+
await emit({ type: "message_start", message });
|
|
277
|
+
await emit({ type: "message_end", message });
|
|
278
|
+
state.context.messages.push(message);
|
|
279
|
+
state.newMessages.push(message);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
let executor = new StreamToolExecutor(state.context, state.config, signal, emit);
|
|
283
|
+
const staticReasoningCutDowngrade = state.config.recovery?.truncatedOutput !== undefined &&
|
|
284
|
+
state.staticReasoningCutRecoveries < MAX_STATIC_REASONING_CUT_RECOVERIES;
|
|
285
|
+
const ptl = state.config.recovery?.promptTooLong;
|
|
286
|
+
const ptlDetect = ptl?.detect ?? defaultDetectPromptTooLong;
|
|
287
|
+
const withholdEnabled = ptl !== undefined && (ptl.withholdErrorEvents ?? true);
|
|
288
|
+
let withhold = withholdEnabled ? createPtlWithholdBuffer(emit, ptlDetect) : undefined;
|
|
289
|
+
let message;
|
|
290
|
+
try {
|
|
291
|
+
message = await streamAssistantResponse(state.context, state.config, signal, withhold?.sink ?? emit, streamFn, runtime, executor, staticReasoningCutDowngrade);
|
|
292
|
+
}
|
|
293
|
+
finally {
|
|
294
|
+
await executor.settle();
|
|
295
|
+
}
|
|
296
|
+
{
|
|
297
|
+
if (ptl) {
|
|
298
|
+
const detect = ptlDetect;
|
|
299
|
+
const maxRetries = ptl.maxRetries ?? 2;
|
|
300
|
+
let attempt = 0;
|
|
301
|
+
while (message.stopReason === "error" &&
|
|
302
|
+
!signal?.aborted &&
|
|
303
|
+
detect(message) &&
|
|
304
|
+
isBlankFailureContent(message) &&
|
|
305
|
+
executor.admittedCount === 0 &&
|
|
306
|
+
attempt < maxRetries) {
|
|
307
|
+
attempt++;
|
|
308
|
+
if (state.context.messages[state.context.messages.length - 1] === message) {
|
|
309
|
+
state.context.messages.pop();
|
|
310
|
+
}
|
|
311
|
+
let replaced;
|
|
312
|
+
try {
|
|
313
|
+
replaced = await ptl.recover(state.context.messages, attempt);
|
|
314
|
+
}
|
|
315
|
+
catch {
|
|
316
|
+
replaced = undefined;
|
|
317
|
+
}
|
|
318
|
+
if (!replaced) {
|
|
319
|
+
state.context.messages.push(message);
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
withhold?.discard();
|
|
323
|
+
withhold = withholdEnabled ? createPtlWithholdBuffer(emit, ptlDetect) : undefined;
|
|
324
|
+
state.context.messages = replaced;
|
|
325
|
+
trace?.({ kind: "continue", reason: "reactive_compact_retry" });
|
|
326
|
+
executor = new StreamToolExecutor(state.context, state.config, signal, emit);
|
|
327
|
+
try {
|
|
328
|
+
message = await streamAssistantResponse(state.context, state.config, signal, withhold?.sink ?? emit, streamFn, runtime, executor, staticReasoningCutDowngrade);
|
|
329
|
+
}
|
|
330
|
+
finally {
|
|
331
|
+
await executor.settle();
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
await withhold?.flush();
|
|
337
|
+
state.newMessages.push(message);
|
|
338
|
+
if (message.staticReasoningCut === true)
|
|
339
|
+
state.staticReasoningCutRecoveries++;
|
|
340
|
+
{
|
|
341
|
+
const degen = state.config.recovery?.degenerateOutput;
|
|
342
|
+
if (degen &&
|
|
343
|
+
message.stopReason === "error" &&
|
|
344
|
+
!signal?.aborted &&
|
|
345
|
+
degen.detect(message) &&
|
|
346
|
+
executor.admittedCount === 0 &&
|
|
347
|
+
message.content.every((b) => b.type !== "toolCall") &&
|
|
348
|
+
state.degenerateContinues < (degen.maxContinues ?? 2)) {
|
|
349
|
+
state.degenerateContinues++;
|
|
350
|
+
await emit({ type: "turn_end", message, toolResults: [] });
|
|
351
|
+
const drained = (await state.config.getSteeringMessages?.()) || [];
|
|
352
|
+
state.pendingMessages = drained.length > 0 ? drained : [createDegenerateRecoveryNudge()];
|
|
353
|
+
return { kind: "ran", recovered: "degenerate_output_recovery" };
|
|
354
|
+
}
|
|
355
|
+
if (message.stopReason !== "error")
|
|
356
|
+
state.degenerateContinues = 0;
|
|
357
|
+
}
|
|
358
|
+
{
|
|
359
|
+
const wc = state.config.recovery?.walltimeCutoff;
|
|
360
|
+
if (wc &&
|
|
361
|
+
message.stopReason === "error" &&
|
|
362
|
+
!signal?.aborted &&
|
|
363
|
+
wc.detect(message) &&
|
|
364
|
+
executor.admittedCount === 0 &&
|
|
365
|
+
message.content.every((b) => b.type !== "toolCall") &&
|
|
366
|
+
state.walltimeCutoffContinues < (wc.maxContinues ?? 1)) {
|
|
367
|
+
state.walltimeCutoffContinues++;
|
|
368
|
+
await emit({ type: "turn_end", message, toolResults: [] });
|
|
369
|
+
const drained = (await state.config.getSteeringMessages?.()) || [];
|
|
370
|
+
state.pendingMessages = drained.length > 0 ? drained : [createWalltimeCutoffRecoveryNudge()];
|
|
371
|
+
return { kind: "ran", recovered: "walltime_cutoff_recovery" };
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
if (message.stopReason === "error" || message.stopReason === "aborted") {
|
|
375
|
+
const errorFinalResults = await harvestExecutorOnErrorFinal(executor, state, message, signal, emit);
|
|
376
|
+
if (state.config.recovery?.walltimeCutoff?.detect(message)) {
|
|
377
|
+
const covered = new Set(errorFinalResults.map((r) => r.toolCallId));
|
|
378
|
+
for (const tc of message.content.filter((c) => c.type === "toolCall")) {
|
|
379
|
+
if (covered.has(tc.id))
|
|
380
|
+
continue;
|
|
381
|
+
const synthetic = {
|
|
382
|
+
role: "toolResult",
|
|
383
|
+
toolCallId: tc.id,
|
|
384
|
+
toolName: tc.name,
|
|
385
|
+
content: [{ type: "text", text: "[call aborted by walltime cutoff — never executed]" }],
|
|
386
|
+
isError: true,
|
|
387
|
+
timestamp: Date.now(),
|
|
388
|
+
};
|
|
389
|
+
await emitToolResultMessage(synthetic, emit);
|
|
390
|
+
state.context.messages.push(synthetic);
|
|
391
|
+
state.newMessages.push(synthetic);
|
|
392
|
+
errorFinalResults.push(synthetic);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
await emit({ type: "turn_end", message, toolResults: errorFinalResults });
|
|
396
|
+
await emit({ type: "agent_end", messages: state.newMessages });
|
|
397
|
+
return { kind: "terminal", reason: "assistant_error" };
|
|
398
|
+
}
|
|
399
|
+
const toolCalls = message.content.filter((c) => c.type === "toolCall");
|
|
400
|
+
const toolResults = [];
|
|
401
|
+
state.hasMoreToolCalls = false;
|
|
402
|
+
if (toolCalls.length > 0) {
|
|
403
|
+
const executedToolBatch = await executeToolCalls(state.context, message, state.config, signal, emit, executor);
|
|
404
|
+
toolResults.push(...executedToolBatch.messages);
|
|
405
|
+
state.hasMoreToolCalls = !executedToolBatch.terminate;
|
|
406
|
+
for (const result of toolResults) {
|
|
407
|
+
state.context.messages.push(result);
|
|
408
|
+
state.newMessages.push(result);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
for (const orphan of executor.remaining()) {
|
|
413
|
+
executor.take(orphan.toolCall.id);
|
|
414
|
+
await closeOrphanedStreamEntry(orphan, emit);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
await emit({ type: "turn_end", message, toolResults });
|
|
418
|
+
const nextTurnContext = {
|
|
419
|
+
message,
|
|
420
|
+
toolResults,
|
|
421
|
+
context: state.context,
|
|
422
|
+
newMessages: state.newMessages,
|
|
423
|
+
};
|
|
424
|
+
const nextTurnSnapshot = await state.config.prepareNextTurn?.(nextTurnContext);
|
|
425
|
+
if (nextTurnSnapshot) {
|
|
426
|
+
state.context = nextTurnSnapshot.context ?? state.context;
|
|
427
|
+
state.config = Object.assign({}, state.config, {
|
|
428
|
+
model: nextTurnSnapshot.model ?? state.config.model,
|
|
429
|
+
reasoning: nextTurnSnapshot.thinkingLevel === undefined
|
|
430
|
+
? state.config.reasoning
|
|
431
|
+
: nextTurnSnapshot.thinkingLevel === "off"
|
|
432
|
+
? undefined
|
|
433
|
+
: nextTurnSnapshot.thinkingLevel,
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
if (await state.config.shouldStopAfterTurn?.({
|
|
437
|
+
message,
|
|
438
|
+
toolResults,
|
|
439
|
+
context: state.context,
|
|
440
|
+
newMessages: state.newMessages,
|
|
441
|
+
})) {
|
|
442
|
+
await emit({ type: "agent_end", messages: state.newMessages });
|
|
443
|
+
return { kind: "terminal", reason: "stop_requested" };
|
|
444
|
+
}
|
|
445
|
+
state.pendingMessages = (await state.config.getSteeringMessages?.()) || [];
|
|
446
|
+
const truncated = state.config.recovery?.truncatedOutput;
|
|
447
|
+
if (message.stopReason === "length") {
|
|
448
|
+
if (truncated &&
|
|
449
|
+
toolCalls.length === 0 &&
|
|
450
|
+
state.pendingMessages.length === 0 &&
|
|
451
|
+
state.truncatedOutputContinues < (truncated.maxContinues ?? 3)) {
|
|
452
|
+
state.truncatedOutputContinues++;
|
|
453
|
+
state.midstreamPartialContinues = 0;
|
|
454
|
+
const noVisibleText = !message.content.some((c) => c.type === "text" && c.text.trim() !== "");
|
|
455
|
+
state.pendingMessages = [...state.pendingMessages, noVisibleText ? createReasoningCutContinueNudge() : createContinueNudge()];
|
|
456
|
+
return { kind: "ran", recovered: "max_output_tokens_recovery" };
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
else {
|
|
460
|
+
state.truncatedOutputContinues = 0;
|
|
461
|
+
}
|
|
462
|
+
if (message.stopReason === "stop" && message.partialFinalized === true) {
|
|
463
|
+
if (toolCalls.length === 0 &&
|
|
464
|
+
state.pendingMessages.length === 0 &&
|
|
465
|
+
state.midstreamPartialContinues < 3) {
|
|
466
|
+
state.midstreamPartialContinues++;
|
|
467
|
+
state.pendingMessages = [createMidstreamPartialContinueNudge()];
|
|
468
|
+
return { kind: "ran", recovered: "midstream_partial_recovery" };
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
state.midstreamPartialContinues = 0;
|
|
473
|
+
}
|
|
474
|
+
const malformed = state.config.recovery?.malformedToolUse;
|
|
475
|
+
if (malformed &&
|
|
476
|
+
message.stopReason === "toolUse" &&
|
|
477
|
+
toolCalls.length === 0 &&
|
|
478
|
+
state.pendingMessages.length === 0 &&
|
|
479
|
+
state.malformedToolUseRetries < (malformed.maxRetries ?? 1)) {
|
|
480
|
+
state.malformedToolUseRetries++;
|
|
481
|
+
state.pendingMessages = [createMalformedToolUseNudge()];
|
|
482
|
+
return { kind: "ran", recovered: "malformed_tool_use_retry" };
|
|
483
|
+
}
|
|
484
|
+
const thinkingOnly = state.config.recovery?.thinkingOnly;
|
|
485
|
+
if (thinkingOnly &&
|
|
486
|
+
message.stopReason === "stop" &&
|
|
487
|
+
toolCalls.length === 0 &&
|
|
488
|
+
state.pendingMessages.length === 0 &&
|
|
489
|
+
state.thinkingOnlyRetries < (thinkingOnly.maxRetries ?? 1) &&
|
|
490
|
+
message.content.some((c) => c.type === "thinking") &&
|
|
491
|
+
!message.content.some((c) => c.type === "text" && c.text.trim() !== "")) {
|
|
492
|
+
state.thinkingOnlyRetries++;
|
|
493
|
+
state.pendingMessages = [createThinkingOnlyNudge()];
|
|
494
|
+
return { kind: "ran", recovered: "thinking_only_retry" };
|
|
495
|
+
}
|
|
496
|
+
return { kind: "ran" };
|
|
497
|
+
}
|
|
498
|
+
async function streamAssistantResponse(context, config, signal, emit, streamFn, runtime, executor, staticReasoningCutDowngrade) {
|
|
499
|
+
let messages = context.messages;
|
|
500
|
+
if (config.transformContext) {
|
|
501
|
+
messages = await config.transformContext(messages, signal);
|
|
502
|
+
}
|
|
503
|
+
const llmMessages = await config.convertToLlm(messages);
|
|
504
|
+
const llmContext = {
|
|
505
|
+
systemPrompt: context.systemPrompt,
|
|
506
|
+
messages: llmMessages,
|
|
507
|
+
tools: context.tools,
|
|
508
|
+
};
|
|
509
|
+
const streamFunction = resolveAgentCoreStreamFn(runtime, streamFn);
|
|
510
|
+
const resolvedApiKey = (config.getApiKey ? await config.getApiKey(config.model.provider) : undefined) || config.apiKey;
|
|
511
|
+
const perCallMaxTokens = config.maxTokensPerCall?.();
|
|
512
|
+
const perCallDeadlineMs = config.callDeadlineMsPerCall?.();
|
|
513
|
+
const response = await streamFunction(config.model, llmContext, {
|
|
514
|
+
...config,
|
|
515
|
+
...(perCallMaxTokens !== undefined ? { maxTokens: perCallMaxTokens, maxTokensDynamic: true } : {}),
|
|
516
|
+
...(perCallDeadlineMs !== undefined ? { callDeadlineMs: perCallDeadlineMs } : {}),
|
|
517
|
+
...(staticReasoningCutDowngrade === true ? { staticReasoningCutDowngrade: true } : {}),
|
|
518
|
+
apiKey: resolvedApiKey,
|
|
519
|
+
signal,
|
|
520
|
+
});
|
|
521
|
+
let partialMessage = null;
|
|
522
|
+
let addedPartial = false;
|
|
523
|
+
for await (const event of response) {
|
|
524
|
+
switch (event.type) {
|
|
525
|
+
case "start": {
|
|
526
|
+
const message = event.partial;
|
|
527
|
+
partialMessage = message;
|
|
528
|
+
context.messages.push(message);
|
|
529
|
+
addedPartial = true;
|
|
530
|
+
await emit({ type: "message_start", message: { ...message } });
|
|
531
|
+
break;
|
|
532
|
+
}
|
|
533
|
+
case "text_start":
|
|
534
|
+
case "text_delta":
|
|
535
|
+
case "text_end":
|
|
536
|
+
case "thinking_start":
|
|
537
|
+
case "thinking_delta":
|
|
538
|
+
case "thinking_end":
|
|
539
|
+
case "toolcall_start":
|
|
540
|
+
case "toolcall_delta":
|
|
541
|
+
case "toolcall_end":
|
|
542
|
+
if (partialMessage) {
|
|
543
|
+
const message = resolveAssistantMessageUpdate(event, partialMessage);
|
|
544
|
+
partialMessage = message;
|
|
545
|
+
context.messages[context.messages.length - 1] = message;
|
|
546
|
+
await emit({
|
|
547
|
+
type: "message_update",
|
|
548
|
+
assistantMessageEvent: event,
|
|
549
|
+
message: { ...message },
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
if (event.type === "toolcall_end" && executor) {
|
|
553
|
+
executor.maybeAdmit(event.toolCall, partialMessage);
|
|
554
|
+
}
|
|
555
|
+
break;
|
|
556
|
+
case "done":
|
|
557
|
+
case "error": {
|
|
558
|
+
const finalMessage = await response.result();
|
|
559
|
+
if (executor && (finalMessage.stopReason === "error" || finalMessage.stopReason === "aborted")) {
|
|
560
|
+
mergeBackAdmittedCalls(finalMessage, executor);
|
|
561
|
+
}
|
|
562
|
+
if (addedPartial) {
|
|
563
|
+
context.messages[context.messages.length - 1] = finalMessage;
|
|
564
|
+
}
|
|
565
|
+
else {
|
|
566
|
+
context.messages.push(finalMessage);
|
|
567
|
+
}
|
|
568
|
+
if (!addedPartial) {
|
|
569
|
+
await emit({ type: "message_start", message: { ...finalMessage } });
|
|
570
|
+
}
|
|
571
|
+
await emit({ type: "message_end", message: finalMessage });
|
|
572
|
+
return finalMessage;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
const finalMessage = await response.result();
|
|
577
|
+
if (executor && (finalMessage.stopReason === "error" || finalMessage.stopReason === "aborted")) {
|
|
578
|
+
mergeBackAdmittedCalls(finalMessage, executor);
|
|
579
|
+
}
|
|
580
|
+
if (addedPartial) {
|
|
581
|
+
context.messages[context.messages.length - 1] = finalMessage;
|
|
582
|
+
}
|
|
583
|
+
else {
|
|
584
|
+
context.messages.push(finalMessage);
|
|
585
|
+
await emit({ type: "message_start", message: { ...finalMessage } });
|
|
586
|
+
}
|
|
587
|
+
await emit({ type: "message_end", message: finalMessage });
|
|
588
|
+
return finalMessage;
|
|
589
|
+
}
|
|
590
|
+
async function executeToolCalls(currentContext, assistantMessage, config, signal, emit, executor) {
|
|
591
|
+
const toolCalls = assistantMessage.content.filter((c) => c.type === "toolCall");
|
|
592
|
+
if (config.toolExecution === "sequential") {
|
|
593
|
+
return executeToolCallsSequential(currentContext, assistantMessage, toolCalls, config, signal, emit);
|
|
594
|
+
}
|
|
595
|
+
return executeToolCallsPartitioned(currentContext, assistantMessage, toolCalls, config, signal, emit, executor);
|
|
596
|
+
}
|
|
597
|
+
async function executeToolCallsSequential(currentContext, assistantMessage, toolCalls, config, signal, emit) {
|
|
598
|
+
const finalizedCalls = [];
|
|
599
|
+
const messages = [];
|
|
600
|
+
for (const toolCall of toolCalls) {
|
|
601
|
+
await emit({
|
|
602
|
+
type: "tool_execution_start",
|
|
603
|
+
toolCallId: toolCall.id,
|
|
604
|
+
toolName: toolCall.name,
|
|
605
|
+
args: toolCall.arguments,
|
|
606
|
+
});
|
|
607
|
+
const preparation = await prepareToolCall(currentContext, assistantMessage, toolCall, config, signal);
|
|
608
|
+
let finalized;
|
|
609
|
+
if (preparation.kind === "immediate") {
|
|
610
|
+
finalized = {
|
|
611
|
+
toolCall,
|
|
612
|
+
result: preparation.result,
|
|
613
|
+
isError: preparation.isError,
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
else {
|
|
617
|
+
const executed = await executePreparedToolCall(preparation, signal, emit);
|
|
618
|
+
finalized = await finalizeExecutedToolCall(currentContext, assistantMessage, preparation, executed, config, signal);
|
|
619
|
+
}
|
|
620
|
+
await emitToolExecutionEnd(finalized, emit);
|
|
621
|
+
const toolResultMessage = createToolResultMessage(finalized);
|
|
622
|
+
await emitToolResultMessage(toolResultMessage, emit);
|
|
623
|
+
finalizedCalls.push(finalized);
|
|
624
|
+
messages.push(toolResultMessage);
|
|
625
|
+
if (signal?.aborted) {
|
|
626
|
+
break;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
return {
|
|
630
|
+
messages,
|
|
631
|
+
terminate: shouldTerminateToolBatch(finalizedCalls),
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
function isCallConcurrencySafe(tool, args) {
|
|
635
|
+
if (!tool)
|
|
636
|
+
return false;
|
|
637
|
+
if (tool.executionMode === "parallel")
|
|
638
|
+
return true;
|
|
639
|
+
if (!tool.isConcurrencySafe)
|
|
640
|
+
return false;
|
|
641
|
+
try {
|
|
642
|
+
return tool.isConcurrencySafe(args) === true;
|
|
643
|
+
}
|
|
644
|
+
catch {
|
|
645
|
+
return false;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
function isBatchSafeToolCall(tool, toolCall) {
|
|
649
|
+
if (!tool)
|
|
650
|
+
return false;
|
|
651
|
+
let args;
|
|
652
|
+
try {
|
|
653
|
+
args = validateToolArguments(tool, prepareToolCallArguments(tool, toolCall));
|
|
654
|
+
}
|
|
655
|
+
catch {
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
return isCallConcurrencySafe(tool, args);
|
|
659
|
+
}
|
|
660
|
+
function partitionToolCalls(toolCalls, tools) {
|
|
661
|
+
const batches = [];
|
|
662
|
+
for (const tc of toolCalls) {
|
|
663
|
+
const safe = isBatchSafeToolCall(findToolByName(tools, tc.name), tc);
|
|
664
|
+
const last = batches[batches.length - 1];
|
|
665
|
+
if (safe && last?.safe) {
|
|
666
|
+
last.calls.push(tc);
|
|
667
|
+
}
|
|
668
|
+
else {
|
|
669
|
+
batches.push({ safe, calls: [tc] });
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
return batches;
|
|
673
|
+
}
|
|
674
|
+
async function runCapped(thunks, limit) {
|
|
675
|
+
const results = new Array(thunks.length);
|
|
676
|
+
let next = 0;
|
|
677
|
+
const workers = Array.from({ length: Math.max(1, Math.min(limit, thunks.length)) }, async () => {
|
|
678
|
+
while (next < thunks.length) {
|
|
679
|
+
const i = next++;
|
|
680
|
+
results[i] = await thunks[i]();
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
await Promise.all(workers);
|
|
684
|
+
return results;
|
|
685
|
+
}
|
|
686
|
+
async function executeToolCallsPartitioned(currentContext, assistantMessage, toolCalls, config, signal, emit, executor) {
|
|
687
|
+
const cap = config.maxToolConcurrency ?? 10;
|
|
688
|
+
const allFinalized = [];
|
|
689
|
+
const messages = [];
|
|
690
|
+
const remainingCalls = [];
|
|
691
|
+
for (const toolCall of toolCalls) {
|
|
692
|
+
const held = executor?.take(toolCall.id);
|
|
693
|
+
if (!held) {
|
|
694
|
+
remainingCalls.push(toolCall);
|
|
695
|
+
continue;
|
|
696
|
+
}
|
|
697
|
+
const finalized = await finalizeStreamEntry(currentContext, assistantMessage, held, config, signal);
|
|
698
|
+
await emitToolExecutionEnd(finalized, emit);
|
|
699
|
+
const toolResultMessage = createToolResultMessage(finalized);
|
|
700
|
+
await emitToolResultMessage(toolResultMessage, emit);
|
|
701
|
+
allFinalized.push(finalized);
|
|
702
|
+
messages.push(toolResultMessage);
|
|
703
|
+
}
|
|
704
|
+
if (executor) {
|
|
705
|
+
for (const orphan of executor.remaining()) {
|
|
706
|
+
executor.take(orphan.toolCall.id);
|
|
707
|
+
await closeOrphanedStreamEntry(orphan, emit);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
const batches = partitionToolCalls(remainingCalls, currentContext.tools);
|
|
711
|
+
outer: for (const batch of batches) {
|
|
712
|
+
if (signal?.aborted)
|
|
713
|
+
break;
|
|
714
|
+
const entries = [];
|
|
715
|
+
for (const toolCall of batch.calls) {
|
|
716
|
+
await emit({
|
|
717
|
+
type: "tool_execution_start",
|
|
718
|
+
toolCallId: toolCall.id,
|
|
719
|
+
toolName: toolCall.name,
|
|
720
|
+
args: toolCall.arguments,
|
|
721
|
+
});
|
|
722
|
+
const preparation = await prepareToolCall(currentContext, assistantMessage, toolCall, config, signal);
|
|
723
|
+
if (preparation.kind === "immediate") {
|
|
724
|
+
const finalized = { toolCall, result: preparation.result, isError: preparation.isError };
|
|
725
|
+
await emitToolExecutionEnd(finalized, emit);
|
|
726
|
+
entries.push({ finalized, toolCall });
|
|
727
|
+
}
|
|
728
|
+
else {
|
|
729
|
+
entries.push({ prepared: preparation, toolCall });
|
|
730
|
+
}
|
|
731
|
+
if (signal?.aborted) {
|
|
732
|
+
await settleBatch(entries, true);
|
|
733
|
+
break outer;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
await settleBatch(entries, batch.safe);
|
|
737
|
+
}
|
|
738
|
+
return { messages, terminate: shouldTerminateToolBatch(allFinalized) };
|
|
739
|
+
async function settleBatch(entries, concurrent) {
|
|
740
|
+
const runOne = (prepared) => async () => {
|
|
741
|
+
const executed = await executePreparedToolCall(prepared, signal, emit);
|
|
742
|
+
const finalized = await finalizeExecutedToolCall(currentContext, assistantMessage, prepared, executed, config, signal);
|
|
743
|
+
await emitToolExecutionEnd(finalized, emit);
|
|
744
|
+
return finalized;
|
|
745
|
+
};
|
|
746
|
+
const preparedEntries = entries.filter((e) => e.prepared);
|
|
747
|
+
let executedResults;
|
|
748
|
+
if (concurrent && preparedEntries.length > 1) {
|
|
749
|
+
executedResults = await runCapped(preparedEntries.map((e) => runOne(e.prepared)), cap);
|
|
750
|
+
}
|
|
751
|
+
else {
|
|
752
|
+
executedResults = [];
|
|
753
|
+
for (const e of preparedEntries) {
|
|
754
|
+
executedResults.push(await runOne(e.prepared)());
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
let idx = 0;
|
|
758
|
+
for (const e of entries) {
|
|
759
|
+
const finalized = e.finalized ?? executedResults[idx++];
|
|
760
|
+
if (!finalized)
|
|
761
|
+
continue;
|
|
762
|
+
allFinalized.push(finalized);
|
|
763
|
+
const toolResultMessage = createToolResultMessage(finalized);
|
|
764
|
+
await emitToolResultMessage(toolResultMessage, emit);
|
|
765
|
+
messages.push(toolResultMessage);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
class StreamToolExecutor {
|
|
770
|
+
context;
|
|
771
|
+
config;
|
|
772
|
+
signal;
|
|
773
|
+
emit;
|
|
774
|
+
entries = new Map();
|
|
775
|
+
admittedOrder = [];
|
|
776
|
+
barrier = false;
|
|
777
|
+
inFlight = 0;
|
|
778
|
+
constructor(context, config, signal, emit) {
|
|
779
|
+
this.context = context;
|
|
780
|
+
this.config = config;
|
|
781
|
+
this.signal = signal;
|
|
782
|
+
this.emit = emit;
|
|
783
|
+
}
|
|
784
|
+
get admittedCount() {
|
|
785
|
+
return this.admittedOrder.length;
|
|
786
|
+
}
|
|
787
|
+
admittedToolCalls() {
|
|
788
|
+
return this.admittedOrder.map((id) => this.entries.get(id)?.toolCall).filter((tc) => tc !== undefined);
|
|
789
|
+
}
|
|
790
|
+
maybeAdmit(toolCall, partialAssistant) {
|
|
791
|
+
if (this.barrier)
|
|
792
|
+
return;
|
|
793
|
+
if (this.config.streamingToolExecution !== true ||
|
|
794
|
+
this.config.toolExecution === "sequential" ||
|
|
795
|
+
this.signal?.aborted ||
|
|
796
|
+
partialAssistant === null ||
|
|
797
|
+
!isBatchSafeToolCall(findToolByName(this.context.tools, toolCall.name), toolCall) ||
|
|
798
|
+
this.inFlight >= (this.config.maxToolConcurrency ?? 10) ||
|
|
799
|
+
this.entries.has(toolCall.id)) {
|
|
800
|
+
this.barrier = true;
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
const entry = { toolCall, promise: Promise.resolve() };
|
|
804
|
+
this.entries.set(toolCall.id, entry);
|
|
805
|
+
this.admittedOrder.push(toolCall.id);
|
|
806
|
+
entry.promise = this.runOne(entry, partialAssistant);
|
|
807
|
+
}
|
|
808
|
+
async runOne(entry, partialAssistant) {
|
|
809
|
+
this.inFlight++;
|
|
810
|
+
try {
|
|
811
|
+
await this.emit({
|
|
812
|
+
type: "tool_execution_start",
|
|
813
|
+
toolCallId: entry.toolCall.id,
|
|
814
|
+
toolName: entry.toolCall.name,
|
|
815
|
+
args: entry.toolCall.arguments,
|
|
816
|
+
});
|
|
817
|
+
const preparation = await prepareToolCall(this.context, partialAssistant, entry.toolCall, this.config, this.signal);
|
|
818
|
+
if (preparation.kind === "immediate") {
|
|
819
|
+
entry.immediate = preparation;
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
entry.prepared = preparation;
|
|
823
|
+
entry.executed = await executePreparedToolCall(preparation, this.signal, this.emit);
|
|
824
|
+
}
|
|
825
|
+
catch (error) {
|
|
826
|
+
entry.immediate = {
|
|
827
|
+
kind: "immediate",
|
|
828
|
+
result: createErrorToolResult(error instanceof Error ? error.message : String(error)),
|
|
829
|
+
isError: true,
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
finally {
|
|
833
|
+
this.inFlight--;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
async settle() {
|
|
837
|
+
this.barrier = true;
|
|
838
|
+
await Promise.all([...this.entries.values()].map((e) => e.promise));
|
|
839
|
+
}
|
|
840
|
+
take(id) {
|
|
841
|
+
const entry = this.entries.get(id);
|
|
842
|
+
if (entry)
|
|
843
|
+
this.entries.delete(id);
|
|
844
|
+
return entry;
|
|
845
|
+
}
|
|
846
|
+
remaining() {
|
|
847
|
+
return this.admittedOrder
|
|
848
|
+
.map((id) => this.entries.get(id))
|
|
849
|
+
.filter((e) => e !== undefined);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
async function finalizeStreamEntry(currentContext, assistantMessage, entry, config, signal) {
|
|
853
|
+
if (entry.prepared && entry.executed) {
|
|
854
|
+
return finalizeExecutedToolCall(currentContext, assistantMessage, entry.prepared, entry.executed, config, signal);
|
|
855
|
+
}
|
|
856
|
+
const immediate = entry.immediate ?? {
|
|
857
|
+
kind: "immediate",
|
|
858
|
+
result: createErrorToolResult("in-stream execution produced no outcome"),
|
|
859
|
+
isError: true,
|
|
860
|
+
};
|
|
861
|
+
return { toolCall: entry.toolCall, result: immediate.result, isError: immediate.isError };
|
|
862
|
+
}
|
|
863
|
+
async function closeOrphanedStreamEntry(entry, emit) {
|
|
864
|
+
await emit({
|
|
865
|
+
type: "tool_execution_end",
|
|
866
|
+
toolCallId: entry.toolCall.id,
|
|
867
|
+
toolName: entry.toolCall.name,
|
|
868
|
+
result: createErrorToolResult("in-stream result dropped: the call is missing from the final assistant content (provider contract breach)"),
|
|
869
|
+
isError: true,
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
async function harvestExecutorOnErrorFinal(executor, state, finalMessage, signal, emit) {
|
|
873
|
+
const held = executor.remaining();
|
|
874
|
+
if (held.length === 0)
|
|
875
|
+
return [];
|
|
876
|
+
const results = [];
|
|
877
|
+
const persistedCallIds = new Set(finalMessage.content.filter((c) => c.type === "toolCall").map((c) => c.id));
|
|
878
|
+
for (const entry of held) {
|
|
879
|
+
executor.take(entry.toolCall.id);
|
|
880
|
+
if (!persistedCallIds.has(entry.toolCall.id)) {
|
|
881
|
+
await closeOrphanedStreamEntry(entry, emit);
|
|
882
|
+
continue;
|
|
883
|
+
}
|
|
884
|
+
const finalized = await finalizeStreamEntry(state.context, finalMessage, entry, state.config, signal);
|
|
885
|
+
await emitToolExecutionEnd(finalized, emit);
|
|
886
|
+
const toolResultMessage = createToolResultMessage(finalized);
|
|
887
|
+
await emitToolResultMessage(toolResultMessage, emit);
|
|
888
|
+
state.context.messages.push(toolResultMessage);
|
|
889
|
+
state.newMessages.push(toolResultMessage);
|
|
890
|
+
results.push(toolResultMessage);
|
|
891
|
+
}
|
|
892
|
+
return results;
|
|
893
|
+
}
|
|
894
|
+
function mergeBackAdmittedCalls(finalMessage, executor) {
|
|
895
|
+
const admitted = executor.admittedToolCalls();
|
|
896
|
+
if (admitted.length === 0)
|
|
897
|
+
return;
|
|
898
|
+
const present = new Set(finalMessage.content.filter((c) => c.type === "toolCall").map((c) => c.id));
|
|
899
|
+
const missing = admitted.filter((tc) => !present.has(tc.id));
|
|
900
|
+
if (missing.length === 0)
|
|
901
|
+
return;
|
|
902
|
+
finalMessage.content = [...finalMessage.content, ...missing];
|
|
903
|
+
}
|
|
904
|
+
function shouldTerminateToolBatch(finalizedCalls) {
|
|
905
|
+
return (finalizedCalls.length > 0 &&
|
|
906
|
+
finalizedCalls.every((finalized) => finalized.result.terminate === true));
|
|
907
|
+
}
|
|
908
|
+
function prepareToolCallArguments(tool, toolCall) {
|
|
909
|
+
if (!tool.prepareArguments) {
|
|
910
|
+
return toolCall;
|
|
911
|
+
}
|
|
912
|
+
const preparedArguments = tool.prepareArguments(toolCall.arguments);
|
|
913
|
+
if (preparedArguments === toolCall.arguments) {
|
|
914
|
+
return toolCall;
|
|
915
|
+
}
|
|
916
|
+
return {
|
|
917
|
+
...toolCall,
|
|
918
|
+
arguments: preparedArguments,
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
async function prepareToolCall(currentContext, assistantMessage, toolCall, config, signal) {
|
|
922
|
+
const tool = findToolByName(currentContext.tools, toolCall.name);
|
|
923
|
+
if (!tool) {
|
|
924
|
+
const tombstone = TOMBSTONED_TOOLS[toolCall.name];
|
|
925
|
+
if (tombstone !== undefined) {
|
|
926
|
+
return {
|
|
927
|
+
kind: "immediate",
|
|
928
|
+
result: createErrorToolResult(tombstone),
|
|
929
|
+
isError: true,
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
const available = (currentContext.tools ?? []).map((t) => t.name).join(", ");
|
|
933
|
+
return {
|
|
934
|
+
kind: "immediate",
|
|
935
|
+
result: createErrorToolResult(`Tool ${toolCall.name} not found.${available ? ` Available tools: ${available}` : ""}`),
|
|
936
|
+
isError: true,
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
try {
|
|
940
|
+
const preparedToolCall = prepareToolCallArguments(tool, toolCall);
|
|
941
|
+
let finalArgs = validateToolArguments(tool, preparedToolCall);
|
|
942
|
+
if (config.beforeToolCall) {
|
|
943
|
+
const beforeResult = await config.beforeToolCall({
|
|
944
|
+
assistantMessage,
|
|
945
|
+
toolCall,
|
|
946
|
+
args: finalArgs,
|
|
947
|
+
context: currentContext,
|
|
948
|
+
}, signal);
|
|
949
|
+
if (signal?.aborted) {
|
|
950
|
+
return {
|
|
951
|
+
kind: "immediate",
|
|
952
|
+
result: createErrorToolResult("Operation aborted"),
|
|
953
|
+
isError: true,
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
if (beforeResult?.block) {
|
|
957
|
+
return {
|
|
958
|
+
kind: "immediate",
|
|
959
|
+
result: createErrorToolResult(beforeResult.reason || "Tool execution was blocked"),
|
|
960
|
+
isError: true,
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
if (beforeResult?.updatedInput !== undefined) {
|
|
964
|
+
finalArgs = validateToolArguments(tool, {
|
|
965
|
+
...preparedToolCall,
|
|
966
|
+
arguments: beforeResult.updatedInput,
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
if (signal?.aborted) {
|
|
971
|
+
return {
|
|
972
|
+
kind: "immediate",
|
|
973
|
+
result: createErrorToolResult("Operation aborted"),
|
|
974
|
+
isError: true,
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
return {
|
|
978
|
+
kind: "prepared",
|
|
979
|
+
toolCall,
|
|
980
|
+
tool,
|
|
981
|
+
args: finalArgs,
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
catch (error) {
|
|
985
|
+
return {
|
|
986
|
+
kind: "immediate",
|
|
987
|
+
result: createErrorToolResult(error instanceof Error ? error.message : String(error)),
|
|
988
|
+
isError: true,
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
async function executePreparedToolCall(prepared, signal, emit) {
|
|
993
|
+
const updateEvents = [];
|
|
994
|
+
let acceptingUpdates = true;
|
|
995
|
+
if (signal?.aborted) {
|
|
996
|
+
return { result: createErrorToolResult("operation aborted before execution"), isError: true };
|
|
997
|
+
}
|
|
998
|
+
try {
|
|
999
|
+
const result = await prepared.tool.execute(prepared.toolCall.id, prepared.args, signal, (partialResult) => {
|
|
1000
|
+
if (!acceptingUpdates) {
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
1003
|
+
updateEvents.push(Promise.resolve(emit({
|
|
1004
|
+
type: "tool_execution_update",
|
|
1005
|
+
toolCallId: prepared.toolCall.id,
|
|
1006
|
+
toolName: prepared.toolCall.name,
|
|
1007
|
+
args: prepared.toolCall.arguments,
|
|
1008
|
+
partialResult,
|
|
1009
|
+
})));
|
|
1010
|
+
});
|
|
1011
|
+
acceptingUpdates = false;
|
|
1012
|
+
await Promise.all(updateEvents);
|
|
1013
|
+
return { result, isError: false };
|
|
1014
|
+
}
|
|
1015
|
+
catch (error) {
|
|
1016
|
+
acceptingUpdates = false;
|
|
1017
|
+
await Promise.all(updateEvents);
|
|
1018
|
+
return {
|
|
1019
|
+
result: createErrorToolResult(error instanceof Error ? error.message : String(error)),
|
|
1020
|
+
isError: true,
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
async function finalizeExecutedToolCall(currentContext, assistantMessage, prepared, executed, config, signal) {
|
|
1025
|
+
let result = executed.result;
|
|
1026
|
+
let isError = executed.isError;
|
|
1027
|
+
if (config.afterToolCall) {
|
|
1028
|
+
try {
|
|
1029
|
+
const afterResult = await config.afterToolCall({
|
|
1030
|
+
assistantMessage,
|
|
1031
|
+
toolCall: prepared.toolCall,
|
|
1032
|
+
args: prepared.args,
|
|
1033
|
+
result,
|
|
1034
|
+
isError,
|
|
1035
|
+
context: currentContext,
|
|
1036
|
+
}, signal);
|
|
1037
|
+
if (afterResult) {
|
|
1038
|
+
result = {
|
|
1039
|
+
content: afterResult.content ?? result.content,
|
|
1040
|
+
details: afterResult.details ?? result.details,
|
|
1041
|
+
terminate: afterResult.terminate ?? result.terminate,
|
|
1042
|
+
};
|
|
1043
|
+
isError = afterResult.isError ?? isError;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
catch (error) {
|
|
1047
|
+
const note = `[post-tool processing failed (the tool already executed): ${error instanceof Error ? error.message : String(error)}]`;
|
|
1048
|
+
result = { ...result, content: [...result.content, { type: "text", text: note }] };
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
return {
|
|
1052
|
+
toolCall: prepared.toolCall,
|
|
1053
|
+
result,
|
|
1054
|
+
isError,
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
function createErrorToolResult(message) {
|
|
1058
|
+
return {
|
|
1059
|
+
content: [{ type: "text", text: message }],
|
|
1060
|
+
details: {},
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
async function emitToolExecutionEnd(finalized, emit) {
|
|
1064
|
+
await emit({
|
|
1065
|
+
type: "tool_execution_end",
|
|
1066
|
+
toolCallId: finalized.toolCall.id,
|
|
1067
|
+
toolName: finalized.toolCall.name,
|
|
1068
|
+
result: finalized.result,
|
|
1069
|
+
isError: finalized.isError,
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
function createToolResultMessage(finalized) {
|
|
1073
|
+
return {
|
|
1074
|
+
role: "toolResult",
|
|
1075
|
+
toolCallId: finalized.toolCall.id,
|
|
1076
|
+
toolName: finalized.toolCall.name,
|
|
1077
|
+
content: finalized.result.content,
|
|
1078
|
+
details: finalized.result.details,
|
|
1079
|
+
isError: finalized.isError,
|
|
1080
|
+
timestamp: Date.now(),
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
async function emitToolResultMessage(toolResultMessage, emit) {
|
|
1084
|
+
await emit({ type: "message_start", message: toolResultMessage });
|
|
1085
|
+
await emit({ type: "message_end", message: toolResultMessage });
|
|
1086
|
+
}
|
|
1087
|
+
//# sourceMappingURL=agent-loop.js.map
|