@cuylabs/agent-core 4.9.0 → 5.0.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/README.md +11 -12
- package/dist/agent/chat-loop/commit-batch.d.ts +10 -0
- package/dist/agent/chat-loop/commit-batch.d.ts.map +1 -0
- package/dist/agent/chat-loop/context-recovery.d.ts +33 -0
- package/dist/agent/chat-loop/context-recovery.d.ts.map +1 -0
- package/dist/agent/chat-loop/finalize-turn.d.ts +19 -0
- package/dist/agent/chat-loop/finalize-turn.d.ts.map +1 -0
- package/dist/agent/chat-loop/index.d.ts +7 -0
- package/dist/agent/chat-loop/index.d.ts.map +1 -0
- package/dist/agent/chat-loop/loop.d.ts +8 -0
- package/dist/agent/chat-loop/loop.d.ts.map +1 -0
- package/dist/agent/chat-loop/model-step-runner.d.ts +26 -0
- package/dist/agent/chat-loop/model-step-runner.d.ts.map +1 -0
- package/dist/agent/chat-loop/model-step-snapshot.d.ts +49 -0
- package/dist/agent/chat-loop/model-step-snapshot.d.ts.map +1 -0
- package/dist/agent/chat-loop/turn-tools.d.ts +19 -0
- package/dist/agent/chat-loop/turn-tools.d.ts.map +1 -0
- package/dist/agent/chat-loop/types.d.ts +60 -0
- package/dist/agent/chat-loop/types.d.ts.map +1 -0
- package/dist/agent/defaults.d.ts +69 -0
- package/dist/agent/defaults.d.ts.map +1 -0
- package/dist/agent/event-printer.d.ts +94 -0
- package/dist/agent/event-printer.d.ts.map +1 -0
- package/dist/agent/fork.d.ts +59 -0
- package/dist/agent/fork.d.ts.map +1 -0
- package/dist/agent/index.d.ts +17 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/instance/context-management.d.ts +42 -0
- package/dist/agent/instance/context-management.d.ts.map +1 -0
- package/dist/agent/instance/forking.d.ts +26 -0
- package/dist/agent/instance/forking.d.ts.map +1 -0
- package/dist/agent/instance/index.d.ts +182 -0
- package/dist/agent/instance/index.d.ts.map +1 -0
- package/dist/agent/instance/interventions.d.ts +10 -0
- package/dist/agent/instance/interventions.d.ts.map +1 -0
- package/dist/agent/instance/mcp.d.ts +21 -0
- package/dist/agent/instance/mcp.d.ts.map +1 -0
- package/dist/agent/instance/sessions.d.ts +8 -0
- package/dist/agent/instance/sessions.d.ts.map +1 -0
- package/dist/agent/instance/tools.d.ts +16 -0
- package/dist/agent/instance/tools.d.ts.map +1 -0
- package/dist/agent/instance/turn-lifecycle.d.ts +61 -0
- package/dist/agent/instance/turn-lifecycle.d.ts.map +1 -0
- package/dist/agent/session.d.ts +16 -0
- package/dist/agent/session.d.ts.map +1 -0
- package/dist/agent/setup/config.d.ts +8 -0
- package/dist/agent/setup/config.d.ts.map +1 -0
- package/dist/agent/setup/context-window.d.ts +4 -0
- package/dist/agent/setup/context-window.d.ts.map +1 -0
- package/dist/agent/setup/environment.d.ts +5 -0
- package/dist/agent/setup/environment.d.ts.map +1 -0
- package/dist/agent/setup/middleware.d.ts +9 -0
- package/dist/agent/setup/middleware.d.ts.map +1 -0
- package/dist/agent/setup/runtime-config.d.ts +9 -0
- package/dist/agent/setup/runtime-config.d.ts.map +1 -0
- package/dist/agent/setup/state.d.ts +4 -0
- package/dist/agent/setup/state.d.ts.map +1 -0
- package/dist/agent/setup/tools.d.ts +8 -0
- package/dist/agent/setup/tools.d.ts.map +1 -0
- package/dist/agent/setup.d.ts +47 -0
- package/dist/agent/setup.d.ts.map +1 -0
- package/dist/agent/stream-provider.d.ts +27 -0
- package/dist/agent/stream-provider.d.ts.map +1 -0
- package/dist/agent/turn-context/compaction/agent-context.d.ts +76 -0
- package/dist/agent/turn-context/compaction/agent-context.d.ts.map +1 -0
- package/dist/agent/turn-context/compaction/budget.d.ts +4 -0
- package/dist/agent/turn-context/compaction/budget.d.ts.map +1 -0
- package/dist/agent/turn-context/compaction/check.d.ts +45 -0
- package/dist/agent/turn-context/compaction/check.d.ts.map +1 -0
- package/dist/agent/turn-context/compaction/fragments.d.ts +4 -0
- package/dist/agent/turn-context/compaction/fragments.d.ts.map +1 -0
- package/dist/agent/turn-context/compaction/index.d.ts +5 -0
- package/dist/agent/turn-context/compaction/index.d.ts.map +1 -0
- package/dist/agent/turn-context/compaction/memory.d.ts +18 -0
- package/dist/agent/turn-context/compaction/memory.d.ts.map +1 -0
- package/dist/agent/turn-context/compaction/results.d.ts +25 -0
- package/dist/agent/turn-context/compaction/results.d.ts.map +1 -0
- package/dist/agent/turn-context/compaction/summary.d.ts +3 -0
- package/dist/agent/turn-context/compaction/summary.d.ts.map +1 -0
- package/dist/agent/turn-context/compaction/types.d.ts +30 -0
- package/dist/agent/turn-context/compaction/types.d.ts.map +1 -0
- package/dist/agent/turn-context/fit-model-context.d.ts +29 -0
- package/dist/agent/turn-context/fit-model-context.d.ts.map +1 -0
- package/dist/agent/turn-context/index.d.ts +5 -0
- package/dist/agent/turn-context/index.d.ts.map +1 -0
- package/dist/agent/turn-context/system-prompts.d.ts +12 -0
- package/dist/agent/turn-context/system-prompts.d.ts.map +1 -0
- package/dist/agent/types/config.d.ts +206 -0
- package/dist/agent/types/config.d.ts.map +1 -0
- package/dist/agent/types/index.d.ts +11 -0
- package/dist/agent/types/index.d.ts.map +1 -0
- package/dist/agent/types/state.d.ts +16 -0
- package/dist/agent/types/state.d.ts.map +1 -0
- package/dist/agent/types/tracing.d.ts +12 -0
- package/dist/agent/types/tracing.d.ts.map +1 -0
- package/dist/{chunk-KYLPMBHD.js → chunk-336EDIBL.js} +1 -1
- package/dist/chunk-346FIYKT.js +960 -0
- package/dist/{chunk-HSUPTXNV.js → chunk-556CPZ3J.js} +13 -10
- package/dist/chunk-AHDCR7SX.js +83 -0
- package/dist/{chunk-CSR75JVC.js → chunk-ASXF5AC6.js} +1 -1
- package/dist/{chunk-BJC46FIF.js → chunk-BKHWKKSG.js} +2 -2
- package/dist/{chunk-2TTOLHBT.js → chunk-CFBSQLP5.js} +1 -1
- package/dist/chunk-CGP6UNCQ.js +554 -0
- package/dist/{chunk-GJFP5L2V.js → chunk-CNM6OROH.js} +15 -3
- package/dist/chunk-DD7S7ZG4.js +274 -0
- package/dist/chunk-DYZGHHDB.js +1458 -0
- package/dist/chunk-E66PKKDL.js +772 -0
- package/dist/{chunk-H3GRHFFG.js → chunk-EDKZOPUV.js} +63 -306
- package/dist/{chunk-GEBFHREI.js → chunk-GHVW7L4P.js} +71 -5
- package/dist/chunk-JFH6HBUG.js +227 -0
- package/dist/{chunk-MWPU2EVV.js → chunk-JUIL2NJC.js} +4 -81
- package/dist/{chunk-NS7D7JJU.js → chunk-K453AFTL.js} +35 -16
- package/dist/chunk-MJRZ2ZRI.js +498 -0
- package/dist/{chunk-UMIVJDEJ.js → chunk-SAWRDGBE.js} +30 -7
- package/dist/chunk-TYQWH6XH.js +88 -0
- package/dist/{chunk-QJV5XPPS.js → chunk-UEEHZ4QH.js} +1 -1
- package/dist/chunk-UG5PVNZV.js +53 -0
- package/dist/{chunk-BGG2HVIR.js → chunk-V4MIDL5B.js} +9 -0
- package/dist/chunk-W6LWIMIX.js +8 -0
- package/dist/context/assembly/index.d.ts +3 -0
- package/dist/context/assembly/index.d.ts.map +1 -0
- package/dist/context/assembly/prepare.d.ts +11 -0
- package/dist/context/assembly/prepare.d.ts.map +1 -0
- package/dist/context/assembly/types.d.ts +64 -0
- package/dist/context/assembly/types.d.ts.map +1 -0
- package/dist/context/config.d.ts +20 -0
- package/dist/context/config.d.ts.map +1 -0
- package/dist/context/fragments/index.d.ts +4 -0
- package/dist/context/fragments/index.d.ts.map +1 -0
- package/dist/context/fragments/messages.d.ts +12 -0
- package/dist/context/fragments/messages.d.ts.map +1 -0
- package/dist/context/fragments/render.d.ts +16 -0
- package/dist/context/fragments/render.d.ts.map +1 -0
- package/dist/context/fragments/types.d.ts +87 -0
- package/dist/context/fragments/types.d.ts.map +1 -0
- package/dist/context/index.d.ts +13 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +96 -0
- package/dist/context/text/truncation.d.ts +13 -0
- package/dist/context/text/truncation.d.ts.map +1 -0
- package/dist/context/window/budget.d.ts +135 -0
- package/dist/context/window/budget.d.ts.map +1 -0
- package/dist/context/window/compactor.d.ts +89 -0
- package/dist/context/window/compactor.d.ts.map +1 -0
- package/dist/context/window/cut-planner.d.ts +67 -0
- package/dist/context/window/cut-planner.d.ts.map +1 -0
- package/dist/context/window/decision.d.ts +50 -0
- package/dist/context/window/decision.d.ts.map +1 -0
- package/dist/context/window/estimation.d.ts +60 -0
- package/dist/context/window/estimation.d.ts.map +1 -0
- package/dist/context/window/index.d.ts +28 -0
- package/dist/context/window/index.d.ts.map +1 -0
- package/dist/context/window/manager.d.ts +113 -0
- package/dist/context/window/manager.d.ts.map +1 -0
- package/dist/context/window/summary-policy.d.ts +50 -0
- package/dist/context/window/summary-policy.d.ts.map +1 -0
- package/dist/context/window/summary.d.ts +65 -0
- package/dist/context/window/summary.d.ts.map +1 -0
- package/dist/context/window/tool-pruning.d.ts +73 -0
- package/dist/context/window/tool-pruning.d.ts.map +1 -0
- package/dist/dispatch/executor.d.ts +56 -0
- package/dist/dispatch/executor.d.ts.map +1 -0
- package/dist/dispatch/index.d.ts +7 -95
- package/dist/dispatch/index.d.ts.map +1 -0
- package/dist/dispatch/index.js +4 -3
- package/dist/dispatch/results.d.ts +9 -0
- package/dist/dispatch/results.d.ts.map +1 -0
- package/dist/dispatch/runtime.d.ts +19 -0
- package/dist/dispatch/runtime.d.ts.map +1 -0
- package/dist/dispatch/tool-factories.d.ts +8 -0
- package/dist/dispatch/tool-factories.d.ts.map +1 -0
- package/dist/dispatch/tools.d.ts +10 -0
- package/dist/dispatch/tools.d.ts.map +1 -0
- package/dist/dispatch/types.d.ts +131 -0
- package/dist/dispatch/types.d.ts.map +1 -0
- package/dist/events/event-bus/index.d.ts +13 -0
- package/dist/events/event-bus/index.d.ts.map +1 -0
- package/dist/events/event-bus/index.js +6 -0
- package/dist/events/event-bus/local.d.ts +14 -0
- package/dist/events/event-bus/local.d.ts.map +1 -0
- package/dist/events/event-bus/types.d.ts +78 -0
- package/dist/events/event-bus/types.d.ts.map +1 -0
- package/dist/events/index.d.ts +10 -89
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +6 -1
- package/dist/events/signal/index.d.ts +18 -0
- package/dist/events/signal/index.d.ts.map +1 -0
- package/dist/events/signal/index.js +6 -0
- package/dist/events/signal/local.d.ts +22 -0
- package/dist/events/signal/local.d.ts.map +1 -0
- package/dist/events/signal/types.d.ts +69 -0
- package/dist/events/signal/types.d.ts.map +1 -0
- package/dist/execution/index.d.ts +33 -481
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +45 -19
- package/dist/execution/scope/index.d.ts +10 -0
- package/dist/execution/scope/index.d.ts.map +1 -0
- package/dist/execution/scope/index.js +12 -0
- package/dist/execution/scope/run.d.ts +8 -0
- package/dist/execution/scope/run.d.ts.map +1 -0
- package/dist/execution/scope/store.d.ts +6 -0
- package/dist/execution/scope/store.d.ts.map +1 -0
- package/dist/execution/scope/types.d.ts +28 -0
- package/dist/execution/scope/types.d.ts.map +1 -0
- package/dist/execution/shared/usage.d.ts +9 -0
- package/dist/execution/shared/usage.d.ts.map +1 -0
- package/dist/execution/task/index.d.ts +6 -0
- package/dist/execution/task/index.d.ts.map +1 -0
- package/dist/execution/task/observer.d.ts +80 -0
- package/dist/execution/task/observer.d.ts.map +1 -0
- package/dist/execution/task/runner.d.ts +39 -0
- package/dist/execution/task/runner.d.ts.map +1 -0
- package/dist/execution/task/types.d.ts +85 -0
- package/dist/execution/task/types.d.ts.map +1 -0
- package/dist/execution/turn/engine/commit-batch.d.ts +16 -0
- package/dist/execution/turn/engine/commit-batch.d.ts.map +1 -0
- package/dist/execution/turn/engine/engine.d.ts +32 -0
- package/dist/execution/turn/engine/engine.d.ts.map +1 -0
- package/dist/execution/turn/engine/index.d.ts +12 -0
- package/dist/execution/turn/engine/index.d.ts.map +1 -0
- package/dist/execution/turn/engine/types.d.ts +67 -0
- package/dist/execution/turn/engine/types.d.ts.map +1 -0
- package/dist/execution/turn/index.d.ts +18 -0
- package/dist/execution/turn/index.d.ts.map +1 -0
- package/dist/execution/turn/index.js +52 -0
- package/dist/execution/turn/runner/commit.d.ts +11 -0
- package/dist/execution/turn/runner/commit.d.ts.map +1 -0
- package/dist/execution/turn/runner/index.d.ts +16 -0
- package/dist/execution/turn/runner/index.d.ts.map +1 -0
- package/dist/execution/turn/runner/prepare.d.ts +6 -0
- package/dist/execution/turn/runner/prepare.d.ts.map +1 -0
- package/dist/execution/turn/runner/stream-step.d.ts +8 -0
- package/dist/execution/turn/runner/stream-step.d.ts.map +1 -0
- package/dist/execution/turn/runner/tool-batch.d.ts +13 -0
- package/dist/execution/turn/runner/tool-batch.d.ts.map +1 -0
- package/dist/execution/turn/runner/types.d.ts +111 -0
- package/dist/execution/turn/runner/types.d.ts.map +1 -0
- package/dist/execution/turn/state.d.ts +110 -0
- package/dist/execution/turn/state.d.ts.map +1 -0
- package/dist/execution/turn/step-ledger.d.ts +89 -0
- package/dist/execution/turn/step-ledger.d.ts.map +1 -0
- package/dist/execution/turn/step-processing/doom-loop.d.ts +28 -0
- package/dist/execution/turn/step-processing/doom-loop.d.ts.map +1 -0
- package/dist/execution/turn/step-processing/index.d.ts +14 -0
- package/dist/execution/turn/step-processing/index.d.ts.map +1 -0
- package/dist/execution/turn/step-processing/overflow.d.ts +17 -0
- package/dist/execution/turn/step-processing/overflow.d.ts.map +1 -0
- package/dist/execution/turn/step-processing/process.d.ts +7 -0
- package/dist/execution/turn/step-processing/process.d.ts.map +1 -0
- package/dist/execution/turn/step-processing/types.d.ts +65 -0
- package/dist/execution/turn/step-processing/types.d.ts.map +1 -0
- package/dist/execution/workflow/index.d.ts +12 -0
- package/dist/execution/workflow/index.d.ts.map +1 -0
- package/dist/execution/workflow/index.js +39 -0
- package/dist/execution/workflow/planner/apply.d.ts +30 -0
- package/dist/execution/workflow/planner/apply.d.ts.map +1 -0
- package/dist/execution/workflow/planner/helpers.d.ts +6 -0
- package/dist/execution/workflow/planner/helpers.d.ts.map +1 -0
- package/dist/execution/workflow/planner/index.d.ts +13 -0
- package/dist/execution/workflow/planner/index.d.ts.map +1 -0
- package/dist/execution/workflow/planner/plan.d.ts +7 -0
- package/dist/execution/workflow/planner/plan.d.ts.map +1 -0
- package/dist/execution/workflow/planner/types.d.ts +49 -0
- package/dist/execution/workflow/planner/types.d.ts.map +1 -0
- package/dist/execution/workflow/snapshot.d.ts +11 -0
- package/dist/execution/workflow/snapshot.d.ts.map +1 -0
- package/dist/execution/workflow/state.d.ts +161 -0
- package/dist/execution/workflow/state.d.ts.map +1 -0
- package/dist/human/controller.d.ts +24 -0
- package/dist/human/controller.d.ts.map +1 -0
- package/dist/human/handler.d.ts +15 -0
- package/dist/human/handler.d.ts.map +1 -0
- package/dist/human/index.d.ts +5 -0
- package/dist/human/index.d.ts.map +1 -0
- package/dist/human/tool.d.ts +17 -0
- package/dist/human/tool.d.ts.map +1 -0
- package/dist/human/types.d.ts +62 -0
- package/dist/human/types.d.ts.map +1 -0
- package/dist/index.d.ts +66 -567
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2681 -1859
- package/dist/inference/defaults.d.ts +8 -0
- package/dist/inference/defaults.d.ts.map +1 -0
- package/dist/inference/errors/classify.d.ts +5 -0
- package/dist/inference/errors/classify.d.ts.map +1 -0
- package/dist/inference/errors/extract.d.ts +3 -0
- package/dist/inference/errors/extract.d.ts.map +1 -0
- package/dist/inference/errors/index.d.ts +8 -11
- package/dist/inference/errors/index.d.ts.map +1 -0
- package/dist/inference/errors/llm-error.d.ts +14 -0
- package/dist/inference/errors/llm-error.d.ts.map +1 -0
- package/dist/inference/errors/types.d.ts +18 -0
- package/dist/inference/errors/types.d.ts.map +1 -0
- package/dist/inference/errors/utils.d.ts +5 -0
- package/dist/inference/errors/utils.d.ts.map +1 -0
- package/dist/inference/index.d.ts +17 -49
- package/dist/inference/index.d.ts.map +1 -0
- package/dist/inference/index.js +7 -7
- package/dist/inference/middleware-support.d.ts +14 -0
- package/dist/inference/middleware-support.d.ts.map +1 -0
- package/dist/{model-messages-n_ZMZwIm.d.ts → inference/model-messages.d.ts} +4 -6
- package/dist/inference/model-messages.d.ts.map +1 -0
- package/dist/inference/retry.d.ts +73 -0
- package/dist/inference/retry.d.ts.map +1 -0
- package/dist/inference/stream.d.ts +16 -0
- package/dist/inference/stream.d.ts.map +1 -0
- package/dist/inference/toolset.d.ts +26 -0
- package/dist/inference/toolset.d.ts.map +1 -0
- package/dist/inference/types.d.ts +129 -0
- package/dist/inference/types.d.ts.map +1 -0
- package/dist/intervention/follow-up-policy.d.ts +41 -0
- package/dist/intervention/follow-up-policy.d.ts.map +1 -0
- package/dist/intervention/index.d.ts +5 -0
- package/dist/intervention/index.d.ts.map +1 -0
- package/dist/intervention/intervention.d.ts +130 -0
- package/dist/intervention/intervention.d.ts.map +1 -0
- package/dist/intervention/types.d.ts +74 -0
- package/dist/intervention/types.d.ts.map +1 -0
- package/dist/logger/index.d.ts +5 -47
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/logger.d.ts +46 -0
- package/dist/logger/logger.d.ts.map +1 -0
- package/dist/{types-RSCv7nQ4.d.ts → logger/types.d.ts} +6 -7
- package/dist/logger/types.d.ts.map +1 -0
- package/dist/mcp/auth.d.ts +109 -0
- package/dist/mcp/auth.d.ts.map +1 -0
- package/dist/mcp/diagnostics.d.ts +23 -0
- package/dist/mcp/diagnostics.d.ts.map +1 -0
- package/dist/mcp/factories.d.ts +47 -0
- package/dist/mcp/factories.d.ts.map +1 -0
- package/dist/mcp/index.d.ts +14 -175
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/manager.d.ts +45 -0
- package/dist/mcp/manager.d.ts.map +1 -0
- package/dist/mcp/modules.d.ts +6 -0
- package/dist/mcp/modules.d.ts.map +1 -0
- package/dist/{types-DMjoFKKv.d.ts → mcp/types.d.ts} +18 -19
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/memory/config.d.ts +4 -0
- package/dist/memory/config.d.ts.map +1 -0
- package/dist/memory/format.d.ts +8 -0
- package/dist/memory/format.d.ts.map +1 -0
- package/dist/memory/index.d.ts +5 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +14 -0
- package/dist/memory/middleware.d.ts +14 -0
- package/dist/memory/middleware.d.ts.map +1 -0
- package/dist/memory/types.d.ts +251 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/middleware/approval.d.ts +70 -0
- package/dist/middleware/approval.d.ts.map +1 -0
- package/dist/middleware/index.d.ts +25 -110
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +2 -2
- package/dist/middleware/prompt-cache/cache.d.ts +44 -0
- package/dist/middleware/prompt-cache/cache.d.ts.map +1 -0
- package/dist/middleware/prompt-cache/index.d.ts +14 -0
- package/dist/middleware/prompt-cache/index.d.ts.map +1 -0
- package/dist/middleware/prompt-cache/types.d.ts +50 -0
- package/dist/middleware/prompt-cache/types.d.ts.map +1 -0
- package/dist/middleware/runner.d.ts +115 -0
- package/dist/middleware/runner.d.ts.map +1 -0
- package/dist/middleware/telemetry/index.d.ts +12 -0
- package/dist/middleware/telemetry/index.d.ts.map +1 -0
- package/dist/middleware/telemetry/otel.d.ts +4 -0
- package/dist/middleware/telemetry/otel.d.ts.map +1 -0
- package/dist/middleware/telemetry/provider.d.ts +3 -0
- package/dist/middleware/telemetry/provider.d.ts.map +1 -0
- package/dist/middleware/telemetry/types.d.ts +150 -0
- package/dist/middleware/telemetry/types.d.ts.map +1 -0
- package/dist/middleware/types.d.ts +426 -0
- package/dist/middleware/types.d.ts.map +1 -0
- package/dist/models/cache/adapters.d.ts +4 -0
- package/dist/models/cache/adapters.d.ts.map +1 -0
- package/dist/models/cache/index.d.ts +5 -0
- package/dist/models/cache/index.d.ts.map +1 -0
- package/dist/models/cache/manager.d.ts +32 -0
- package/dist/models/cache/manager.d.ts.map +1 -0
- package/dist/models/cache/types.d.ts +17 -0
- package/dist/models/cache/types.d.ts.map +1 -0
- package/dist/models/capability-resolver.d.ts +104 -0
- package/dist/models/capability-resolver.d.ts.map +1 -0
- package/dist/models/identifiers.d.ts +23 -0
- package/dist/models/identifiers.d.ts.map +1 -0
- package/dist/models/index.d.ts +35 -256
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +1 -1
- package/dist/models/overrides.d.ts +10 -0
- package/dist/models/overrides.d.ts.map +1 -0
- package/dist/models/profiles.d.ts +38 -0
- package/dist/models/profiles.d.ts.map +1 -0
- package/dist/models/reasoning/config.d.ts +49 -0
- package/dist/models/reasoning/config.d.ts.map +1 -0
- package/dist/models/reasoning/index.d.ts +12 -4
- package/dist/models/reasoning/index.d.ts.map +1 -0
- package/dist/models/reasoning/index.js +1 -1
- package/dist/models/reasoning/providers.d.ts +63 -0
- package/dist/models/reasoning/providers.d.ts.map +1 -0
- package/dist/{types-CQaXbRsS.d.ts → models/reasoning/types.d.ts} +7 -8
- package/dist/models/reasoning/types.d.ts.map +1 -0
- package/dist/models/remote/fetcher.d.ts +13 -0
- package/dist/models/remote/fetcher.d.ts.map +1 -0
- package/dist/models/remote/index.d.ts +8 -0
- package/dist/models/remote/index.d.ts.map +1 -0
- package/dist/models/remote/network.d.ts +6 -0
- package/dist/models/remote/network.d.ts.map +1 -0
- package/dist/models/remote/source.d.ts +16 -0
- package/dist/models/remote/source.d.ts.map +1 -0
- package/dist/models/remote/transform.d.ts +4 -0
- package/dist/models/remote/transform.d.ts.map +1 -0
- package/dist/models/remote/types.d.ts +28 -0
- package/dist/models/remote/types.d.ts.map +1 -0
- package/dist/models/resolver.d.ts +26 -0
- package/dist/models/resolver.d.ts.map +1 -0
- package/dist/models/types.d.ts +137 -0
- package/dist/models/types.d.ts.map +1 -0
- package/dist/plugin/compatibility.d.ts +11 -0
- package/dist/plugin/compatibility.d.ts.map +1 -0
- package/dist/plugin/define.d.ts +77 -0
- package/dist/plugin/define.d.ts.map +1 -0
- package/dist/plugin/event-bus.d.ts +31 -0
- package/dist/plugin/event-bus.d.ts.map +1 -0
- package/dist/plugin/index.d.ts +9 -458
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/loader.d.ts +63 -0
- package/dist/plugin/loader.d.ts.map +1 -0
- package/dist/plugin/registry.d.ts +81 -0
- package/dist/plugin/registry.d.ts.map +1 -0
- package/dist/plugin/settings.d.ts +36 -0
- package/dist/plugin/settings.d.ts.map +1 -0
- package/dist/plugin/types.d.ts +168 -0
- package/dist/plugin/types.d.ts.map +1 -0
- package/dist/profiles/apply.d.ts +17 -0
- package/dist/profiles/apply.d.ts.map +1 -0
- package/dist/profiles/builtins.d.ts +18 -0
- package/dist/profiles/builtins.d.ts.map +1 -0
- package/dist/profiles/index.d.ts +12 -55
- package/dist/profiles/index.d.ts.map +1 -0
- package/dist/profiles/patterns.d.ts +12 -0
- package/dist/profiles/patterns.d.ts.map +1 -0
- package/dist/profiles/types.d.ts +48 -0
- package/dist/profiles/types.d.ts.map +1 -0
- package/dist/prompt/builder/builder.d.ts +27 -0
- package/dist/prompt/builder/builder.d.ts.map +1 -0
- package/dist/prompt/builder/index.d.ts +11 -0
- package/dist/prompt/builder/index.d.ts.map +1 -0
- package/dist/prompt/builder/priorities.d.ts +13 -0
- package/dist/prompt/builder/priorities.d.ts.map +1 -0
- package/dist/prompt/builder/sections.d.ts +30 -0
- package/dist/prompt/builder/sections.d.ts.map +1 -0
- package/dist/prompt/environment.d.ts +46 -0
- package/dist/prompt/environment.d.ts.map +1 -0
- package/dist/prompt/index.d.ts +31 -220
- package/dist/prompt/index.d.ts.map +1 -0
- package/dist/prompt/index.js +3 -1
- package/dist/prompt/instructions.d.ts +104 -0
- package/dist/prompt/instructions.d.ts.map +1 -0
- package/dist/prompt/templates.d.ts +56 -0
- package/dist/prompt/templates.d.ts.map +1 -0
- package/dist/prompt/types.d.ts +218 -0
- package/dist/prompt/types.d.ts.map +1 -0
- package/dist/safety/errors.d.ts +18 -0
- package/dist/safety/errors.d.ts.map +1 -0
- package/dist/safety/handler.d.ts +16 -0
- package/dist/safety/handler.d.ts.map +1 -0
- package/dist/safety/index.d.ts +11 -133
- package/dist/safety/index.d.ts.map +1 -0
- package/dist/safety/patterns.d.ts +17 -0
- package/dist/safety/patterns.d.ts.map +1 -0
- package/dist/safety/policy.d.ts +31 -0
- package/dist/safety/policy.d.ts.map +1 -0
- package/dist/safety/presets.d.ts +43 -0
- package/dist/safety/presets.d.ts.map +1 -0
- package/dist/safety/risk.d.ts +14 -0
- package/dist/safety/risk.d.ts.map +1 -0
- package/dist/safety/types.d.ts +165 -0
- package/dist/safety/types.d.ts.map +1 -0
- package/dist/sandbox/index.d.ts +2 -81
- package/dist/sandbox/index.d.ts.map +1 -0
- package/dist/sandbox/types.d.ts +79 -0
- package/dist/sandbox/types.d.ts.map +1 -0
- package/dist/sessions/index.d.ts +13 -0
- package/dist/sessions/index.d.ts.map +1 -0
- package/dist/{storage → sessions}/index.js +6 -17
- package/dist/sessions/manager/default.d.ts +11 -0
- package/dist/sessions/manager/default.d.ts.map +1 -0
- package/dist/sessions/manager/index.d.ts +12 -0
- package/dist/sessions/manager/index.d.ts.map +1 -0
- package/dist/sessions/manager/session-manager.d.ts +67 -0
- package/dist/sessions/manager/session-manager.d.ts.map +1 -0
- package/dist/sessions/manager/types.d.ts +42 -0
- package/dist/sessions/manager/types.d.ts.map +1 -0
- package/dist/sessions/store/lock.d.ts +18 -0
- package/dist/sessions/store/lock.d.ts.map +1 -0
- package/dist/sessions/store/memory.d.ts +22 -0
- package/dist/sessions/store/memory.d.ts.map +1 -0
- package/dist/sessions/types.d.ts +215 -0
- package/dist/sessions/types.d.ts.map +1 -0
- package/dist/sessions/utils.d.ts +77 -0
- package/dist/sessions/utils.d.ts.map +1 -0
- package/dist/skill/discovery/constants.d.ts +6 -0
- package/dist/skill/discovery/constants.d.ts.map +1 -0
- package/dist/skill/discovery/dedupe.d.ts +3 -0
- package/dist/skill/discovery/dedupe.d.ts.map +1 -0
- package/dist/skill/discovery/discover.d.ts +3 -0
- package/dist/skill/discovery/discover.d.ts.map +1 -0
- package/dist/skill/discovery/fs.d.ts +4 -0
- package/dist/skill/discovery/fs.d.ts.map +1 -0
- package/dist/skill/discovery/index.d.ts +6 -0
- package/dist/skill/discovery/index.d.ts.map +1 -0
- package/dist/skill/discovery/scan.d.ts +3 -0
- package/dist/skill/discovery/scan.d.ts.map +1 -0
- package/dist/skill/discovery/types.d.ts +15 -0
- package/dist/skill/discovery/types.d.ts.map +1 -0
- package/dist/skill/index.d.ts +67 -89
- package/dist/skill/index.d.ts.map +1 -0
- package/dist/skill/index.js +2 -2
- package/dist/skill/loader/constants.d.ts +5 -0
- package/dist/skill/loader/constants.d.ts.map +1 -0
- package/dist/skill/loader/frontmatter.d.ts +5 -0
- package/dist/skill/loader/frontmatter.d.ts.map +1 -0
- package/dist/skill/loader/index.d.ts +8 -0
- package/dist/skill/loader/index.d.ts.map +1 -0
- package/dist/skill/loader/metadata.d.ts +3 -0
- package/dist/skill/loader/metadata.d.ts.map +1 -0
- package/dist/skill/loader/resources.d.ts +5 -0
- package/dist/skill/loader/resources.d.ts.map +1 -0
- package/dist/skill/registry.d.ts +177 -0
- package/dist/skill/registry.d.ts.map +1 -0
- package/dist/skill/tools.d.ts +77 -0
- package/dist/skill/tools.d.ts.map +1 -0
- package/dist/skill/types.d.ts +291 -0
- package/dist/skill/types.d.ts.map +1 -0
- package/dist/subagents/index.d.ts +8 -179
- package/dist/subagents/index.d.ts.map +1 -0
- package/dist/subagents/index.js +5 -4
- package/dist/subagents/installation.d.ts +23 -0
- package/dist/subagents/installation.d.ts.map +1 -0
- package/dist/subagents/results.d.ts +15 -0
- package/dist/subagents/results.d.ts.map +1 -0
- package/dist/subagents/roles/discovery.d.ts +38 -0
- package/dist/subagents/roles/discovery.d.ts.map +1 -0
- package/dist/subagents/roles/index.d.ts +5 -0
- package/dist/subagents/roles/index.d.ts.map +1 -0
- package/dist/subagents/roles/markdown-profile.d.ts +61 -0
- package/dist/subagents/roles/markdown-profile.d.ts.map +1 -0
- package/dist/subagents/tool-factories.d.ts +11 -0
- package/dist/subagents/tool-factories.d.ts.map +1 -0
- package/dist/subagents/tools.d.ts +13 -0
- package/dist/subagents/tools.d.ts.map +1 -0
- package/dist/subagents/types.d.ts +21 -0
- package/dist/subagents/types.d.ts.map +1 -0
- package/dist/team/coordinator/coordinator.d.ts +342 -0
- package/dist/team/coordinator/coordinator.d.ts.map +1 -0
- package/dist/team/coordinator/inbox.d.ts +99 -0
- package/dist/team/coordinator/inbox.d.ts.map +1 -0
- package/dist/team/coordinator/index.d.ts +19 -0
- package/dist/team/coordinator/index.d.ts.map +1 -0
- package/dist/team/coordinator/planning.d.ts +33 -0
- package/dist/team/coordinator/planning.d.ts.map +1 -0
- package/dist/team/coordinator/policy.d.ts +31 -0
- package/dist/team/coordinator/policy.d.ts.map +1 -0
- package/dist/team/coordinator/round-engine.d.ts +25 -0
- package/dist/team/coordinator/round-engine.d.ts.map +1 -0
- package/dist/team/coordinator/synthesis.d.ts +20 -0
- package/dist/team/coordinator/synthesis.d.ts.map +1 -0
- package/dist/team/coordinator/turn.d.ts +107 -0
- package/dist/team/coordinator/turn.d.ts.map +1 -0
- package/dist/team/coordinator/types.d.ts +344 -0
- package/dist/team/coordinator/types.d.ts.map +1 -0
- package/dist/team/events.d.ts +148 -0
- package/dist/team/events.d.ts.map +1 -0
- package/dist/team/execution.d.ts +51 -0
- package/dist/team/execution.d.ts.map +1 -0
- package/dist/team/index.d.ts +23 -545
- package/dist/team/index.d.ts.map +1 -0
- package/dist/team/index.js +2 -2
- package/dist/team/mailbox.d.ts +91 -0
- package/dist/team/mailbox.d.ts.map +1 -0
- package/dist/team/notifications.d.ts +23 -0
- package/dist/team/notifications.d.ts.map +1 -0
- package/dist/team/permissions.d.ts +88 -0
- package/dist/team/permissions.d.ts.map +1 -0
- package/dist/team/shutdown.d.ts +38 -0
- package/dist/team/shutdown.d.ts.map +1 -0
- package/dist/team/task-board.d.ts +161 -0
- package/dist/team/task-board.d.ts.map +1 -0
- package/dist/team/types.d.ts +233 -0
- package/dist/team/types.d.ts.map +1 -0
- package/dist/team/work-loop.d.ts +30 -0
- package/dist/team/work-loop.d.ts.map +1 -0
- package/dist/tool/executor.d.ts +59 -0
- package/dist/tool/executor.d.ts.map +1 -0
- package/dist/tool/host/index.d.ts +7 -38
- package/dist/tool/host/index.d.ts.map +1 -0
- package/dist/tool/host/local.d.ts +15 -0
- package/dist/tool/host/local.d.ts.map +1 -0
- package/dist/tool/host/registry.d.ts +17 -0
- package/dist/tool/host/registry.d.ts.map +1 -0
- package/dist/{types-C_LCeYNg.d.ts → tool/host/types.d.ts} +6 -7
- package/dist/tool/host/types.d.ts.map +1 -0
- package/dist/tool/index.d.ts +21 -285
- package/dist/tool/index.d.ts.map +1 -0
- package/dist/tool/index.js +4 -3
- package/dist/tool/registry.d.ts +130 -0
- package/dist/tool/registry.d.ts.map +1 -0
- package/dist/tool/replay.d.ts +11 -0
- package/dist/tool/replay.d.ts.map +1 -0
- package/dist/tool/tool-search.d.ts +50 -0
- package/dist/tool/tool-search.d.ts.map +1 -0
- package/dist/tool/tool.d.ts +308 -0
- package/dist/tool/tool.d.ts.map +1 -0
- package/dist/tool/truncation.d.ts +34 -0
- package/dist/tool/truncation.d.ts.map +1 -0
- package/dist/tool/turn-tools.d.ts +71 -0
- package/dist/tool/turn-tools.d.ts.map +1 -0
- package/dist/tracking/file-tracking.d.ts +25 -0
- package/dist/tracking/file-tracking.d.ts.map +1 -0
- package/dist/tracking/index.d.ts +9 -0
- package/dist/tracking/index.d.ts.map +1 -0
- package/dist/tracking/turn-tracker/diff.d.ts +11 -0
- package/dist/tracking/turn-tracker/diff.d.ts.map +1 -0
- package/dist/tracking/turn-tracker/index.d.ts +11 -0
- package/dist/tracking/turn-tracker/index.d.ts.map +1 -0
- package/dist/tracking/turn-tracker/tracker.d.ts +31 -0
- package/dist/tracking/turn-tracker/tracker.d.ts.map +1 -0
- package/dist/tracking/turn-tracker/types.d.ts +66 -0
- package/dist/tracking/turn-tracker/types.d.ts.map +1 -0
- package/dist/types/compaction.d.ts +191 -0
- package/dist/types/compaction.d.ts.map +1 -0
- package/dist/types/doom-loop.d.ts +25 -0
- package/dist/types/doom-loop.d.ts.map +1 -0
- package/dist/types/events.d.ts +196 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/messages.d.ts +119 -0
- package/dist/types/messages.d.ts.map +1 -0
- package/dist/types/stream.d.ts +172 -0
- package/dist/types/stream.d.ts.map +1 -0
- package/dist/types/tool.d.ts +309 -0
- package/dist/types/tool.d.ts.map +1 -0
- package/dist/types/turn-source.d.ts +36 -0
- package/dist/types/turn-source.d.ts.map +1 -0
- package/dist/utils/sleep.d.ts +7 -0
- package/dist/utils/sleep.d.ts.map +1 -0
- package/package.json +49 -12
- package/dist/chunk-CJI7PVS2.js +0 -58
- package/dist/chunk-V6ETEYST.js +0 -2091
- package/dist/index-BCqEGzBj.d.ts +0 -251
- package/dist/instance-Bg61WSyz.d.ts +0 -6004
- package/dist/llm-error-D93FNNLY.d.ts +0 -32
- package/dist/storage/index.d.ts +0 -191
- package/dist/turn-tools/index.d.ts +0 -12
- package/dist/turn-tools/index.js +0 -1
- package/dist/{chunk-O2WCYSXQ.js → chunk-3NBTQHVV.js} +0 -0
- package/dist/{chunk-Q742PSH3.js → chunk-MJML3A2F.js} +36 -36
|
@@ -0,0 +1,772 @@
|
|
|
1
|
+
// src/execution/shared/usage.ts
|
|
2
|
+
function cloneUsage(usage) {
|
|
3
|
+
return { ...usage };
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// src/execution/turn/step-ledger.ts
|
|
7
|
+
var AgentTurnStateConflictError = class extends Error {
|
|
8
|
+
conflict;
|
|
9
|
+
constructor(conflict) {
|
|
10
|
+
super(
|
|
11
|
+
`Conflicting turn-state progress for tool call '${conflict.toolCallId}' at step ${conflict.step}: ${conflict.reason}`
|
|
12
|
+
);
|
|
13
|
+
this.name = "AgentTurnStateConflictError";
|
|
14
|
+
this.conflict = conflict;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var DEFAULT_RESULT_PREVIEW_CHARS = 2e3;
|
|
18
|
+
var DEFAULT_MAX_RAW_RESULT_CHARS = 8e3;
|
|
19
|
+
function cloneToolRecord(toolCall) {
|
|
20
|
+
return {
|
|
21
|
+
...toolCall,
|
|
22
|
+
...toolCall.result !== void 0 ? { result: cloneUnknown(toolCall.result) } : {},
|
|
23
|
+
...toolCall.metadata ? { metadata: structuredClone(toolCall.metadata) } : {},
|
|
24
|
+
...toolCall.replayPolicy ? { replayPolicy: { ...toolCall.replayPolicy } } : {}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function cloneStepRecord(step) {
|
|
28
|
+
return {
|
|
29
|
+
...step,
|
|
30
|
+
toolCalls: step.toolCalls.map(cloneToolRecord),
|
|
31
|
+
...step.usage ? { usage: cloneUsage(step.usage) } : {},
|
|
32
|
+
...step.commit ? { commit: { ...step.commit } } : {}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function cloneAgentTurnStepLedger(ledger) {
|
|
36
|
+
return (ledger ?? []).map(cloneStepRecord);
|
|
37
|
+
}
|
|
38
|
+
function latestTimestamp(left, right) {
|
|
39
|
+
return left > right ? left : right;
|
|
40
|
+
}
|
|
41
|
+
function cloneUnknown(value) {
|
|
42
|
+
try {
|
|
43
|
+
return structuredClone(value);
|
|
44
|
+
} catch {
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function truncateResultPreview(value, maxChars) {
|
|
49
|
+
if (value.length <= maxChars) {
|
|
50
|
+
return { preview: value, truncated: false };
|
|
51
|
+
}
|
|
52
|
+
if (maxChars <= 0) {
|
|
53
|
+
return { preview: "", truncated: true };
|
|
54
|
+
}
|
|
55
|
+
const headChars = Math.ceil(maxChars * 0.7);
|
|
56
|
+
const tailChars = Math.max(0, maxChars - headChars);
|
|
57
|
+
const head = value.slice(0, headChars);
|
|
58
|
+
const tail = tailChars > 0 ? value.slice(-tailChars) : "";
|
|
59
|
+
const omitted = value.length - head.length - tail.length;
|
|
60
|
+
return {
|
|
61
|
+
preview: `${head}
|
|
62
|
+
|
|
63
|
+
... [${omitted} chars truncated] ...${tail ? `
|
|
64
|
+
|
|
65
|
+
${tail}` : ""}`,
|
|
66
|
+
truncated: true
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function serializeToolResult(value) {
|
|
70
|
+
if (typeof value === "string") {
|
|
71
|
+
return { text: value, format: "text" };
|
|
72
|
+
}
|
|
73
|
+
if (value === void 0) {
|
|
74
|
+
return { text: "undefined", format: "undefined" };
|
|
75
|
+
}
|
|
76
|
+
if (value === null || typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
77
|
+
return { text: String(value), format: "primitive" };
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
const json = JSON.stringify(value);
|
|
81
|
+
if (json !== void 0) {
|
|
82
|
+
return { text: json, format: "json" };
|
|
83
|
+
}
|
|
84
|
+
} catch {
|
|
85
|
+
}
|
|
86
|
+
return { text: String(value), format: "unserializable" };
|
|
87
|
+
}
|
|
88
|
+
function captureToolResult(value, options = {}) {
|
|
89
|
+
const { text, format } = serializeToolResult(value);
|
|
90
|
+
const maxPreviewChars = options.maxPreviewChars ?? DEFAULT_RESULT_PREVIEW_CHARS;
|
|
91
|
+
const maxRawResultChars = options.maxRawResultChars ?? DEFAULT_MAX_RAW_RESULT_CHARS;
|
|
92
|
+
const { preview, truncated } = truncateResultPreview(text, maxPreviewChars);
|
|
93
|
+
const mode = options.mode ?? "preview";
|
|
94
|
+
return {
|
|
95
|
+
resultPreview: preview,
|
|
96
|
+
resultCharLength: text.length,
|
|
97
|
+
resultTruncated: truncated,
|
|
98
|
+
resultFormat: format,
|
|
99
|
+
...mode === "full" || mode === "small" && text.length <= maxRawResultChars ? { result: cloneUnknown(value) } : {}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
var STEP_STATUS_RANK = {
|
|
103
|
+
running: 0,
|
|
104
|
+
"waiting-tools": 1,
|
|
105
|
+
completed: 2,
|
|
106
|
+
committing: 3,
|
|
107
|
+
committed: 4,
|
|
108
|
+
failed: 5
|
|
109
|
+
};
|
|
110
|
+
function latestStepStatus(previous, incoming) {
|
|
111
|
+
return STEP_STATUS_RANK[incoming] >= STEP_STATUS_RANK[previous] ? incoming : previous;
|
|
112
|
+
}
|
|
113
|
+
function latestCommitStatus(previous, incoming) {
|
|
114
|
+
return incoming === "committed" || previous === "committing" ? incoming : previous;
|
|
115
|
+
}
|
|
116
|
+
function isTerminalToolStatus(status) {
|
|
117
|
+
return status !== "requested";
|
|
118
|
+
}
|
|
119
|
+
function terminalToolRecordsMatch(previous, incoming) {
|
|
120
|
+
return previous.status === incoming.status && previous.error === incoming.error && previous.resultPreview === incoming.resultPreview && previous.resultCharLength === incoming.resultCharLength && previous.resultTruncated === incoming.resultTruncated && previous.resultFormat === incoming.resultFormat;
|
|
121
|
+
}
|
|
122
|
+
function assertNoToolResultConflict(step, previous, incoming) {
|
|
123
|
+
if (!isTerminalToolStatus(previous.status) || !isTerminalToolStatus(incoming.status)) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (terminalToolRecordsMatch(previous, incoming)) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
throw new AgentTurnStateConflictError({
|
|
130
|
+
kind: "tool-result",
|
|
131
|
+
step,
|
|
132
|
+
toolCallId: previous.toolCallId,
|
|
133
|
+
toolName: incoming.toolName || previous.toolName,
|
|
134
|
+
previousStatus: previous.status,
|
|
135
|
+
incomingStatus: incoming.status,
|
|
136
|
+
reason: previous.status === incoming.status ? "terminal tool results differ" : "terminal tool statuses differ"
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function mergeToolRecord(step, previous, incoming) {
|
|
140
|
+
assertNoToolResultConflict(step, previous, incoming);
|
|
141
|
+
const status = incoming.status === "requested" && previous.status !== "requested" ? previous.status : incoming.status;
|
|
142
|
+
return cloneToolRecord({
|
|
143
|
+
...previous,
|
|
144
|
+
...incoming,
|
|
145
|
+
status,
|
|
146
|
+
...previous.args !== void 0 || incoming.args !== void 0 ? { args: incoming.args ?? previous.args } : {},
|
|
147
|
+
...previous.requestedAt || incoming.requestedAt ? { requestedAt: incoming.requestedAt ?? previous.requestedAt } : {},
|
|
148
|
+
...previous.resolvedAt || incoming.resolvedAt ? { resolvedAt: incoming.resolvedAt ?? previous.resolvedAt } : {},
|
|
149
|
+
...previous.resultPreview !== void 0 || incoming.resultPreview !== void 0 ? { resultPreview: incoming.resultPreview ?? previous.resultPreview } : {},
|
|
150
|
+
...previous.resultCharLength !== void 0 || incoming.resultCharLength !== void 0 ? {
|
|
151
|
+
resultCharLength: incoming.resultCharLength ?? previous.resultCharLength
|
|
152
|
+
} : {},
|
|
153
|
+
...previous.resultTruncated !== void 0 || incoming.resultTruncated !== void 0 ? {
|
|
154
|
+
resultTruncated: incoming.resultTruncated ?? previous.resultTruncated
|
|
155
|
+
} : {},
|
|
156
|
+
...previous.resultFormat || incoming.resultFormat ? { resultFormat: incoming.resultFormat ?? previous.resultFormat } : {},
|
|
157
|
+
...previous.result !== void 0 || incoming.result !== void 0 ? { result: incoming.result ?? previous.result } : {},
|
|
158
|
+
...previous.metadata || incoming.metadata ? {
|
|
159
|
+
metadata: {
|
|
160
|
+
...previous.metadata ?? {},
|
|
161
|
+
...incoming.metadata ?? {}
|
|
162
|
+
}
|
|
163
|
+
} : {},
|
|
164
|
+
...previous.replayPolicy || incoming.replayPolicy ? { replayPolicy: incoming.replayPolicy ?? previous.replayPolicy } : {}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
function mergeCommitRecord(previous, incoming) {
|
|
168
|
+
const base = incoming ?? previous;
|
|
169
|
+
if (!base) {
|
|
170
|
+
return void 0;
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
kind: incoming?.kind ?? previous?.kind ?? base.kind,
|
|
174
|
+
status: previous && incoming ? latestCommitStatus(previous.status, incoming.status) : base.status,
|
|
175
|
+
...previous?.startedAt || incoming?.startedAt ? { startedAt: incoming?.startedAt ?? previous?.startedAt } : {},
|
|
176
|
+
...previous?.finishedAt || incoming?.finishedAt ? { finishedAt: incoming?.finishedAt ?? previous?.finishedAt } : {},
|
|
177
|
+
...previous?.messageRole || incoming?.messageRole ? { messageRole: incoming?.messageRole ?? previous?.messageRole } : {},
|
|
178
|
+
...previous?.pendingToolCallCount !== void 0 || incoming?.pendingToolCallCount !== void 0 ? {
|
|
179
|
+
pendingToolCallCount: incoming?.pendingToolCallCount ?? previous?.pendingToolCallCount
|
|
180
|
+
} : {}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function mergeStepRecord(previous, incoming) {
|
|
184
|
+
const toolsById = /* @__PURE__ */ new Map();
|
|
185
|
+
for (const toolCall of previous.toolCalls) {
|
|
186
|
+
toolsById.set(toolCall.toolCallId, cloneToolRecord(toolCall));
|
|
187
|
+
}
|
|
188
|
+
for (const toolCall of incoming.toolCalls) {
|
|
189
|
+
const existing = toolsById.get(toolCall.toolCallId);
|
|
190
|
+
toolsById.set(
|
|
191
|
+
toolCall.toolCallId,
|
|
192
|
+
existing ? mergeToolRecord(previous.step, existing, toolCall) : cloneToolRecord(toolCall)
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
return cloneStepRecord({
|
|
196
|
+
...previous,
|
|
197
|
+
...incoming,
|
|
198
|
+
status: latestStepStatus(previous.status, incoming.status),
|
|
199
|
+
startedAt: previous.startedAt || incoming.startedAt,
|
|
200
|
+
updatedAt: latestTimestamp(previous.updatedAt, incoming.updatedAt),
|
|
201
|
+
text: incoming.text.length >= previous.text.length ? incoming.text : previous.text,
|
|
202
|
+
toolCalls: Array.from(toolsById.values()),
|
|
203
|
+
...previous.usage || incoming.usage ? { usage: incoming.usage ?? previous.usage } : {},
|
|
204
|
+
...previous.finishReason || incoming.finishReason ? { finishReason: incoming.finishReason ?? previous.finishReason } : {},
|
|
205
|
+
...previous.commit || incoming.commit ? { commit: mergeCommitRecord(previous.commit, incoming.commit) } : {}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
function mergeAgentTurnStepLedgers(previous, incoming) {
|
|
209
|
+
const byStep = /* @__PURE__ */ new Map();
|
|
210
|
+
for (const step of cloneAgentTurnStepLedger(previous)) {
|
|
211
|
+
byStep.set(step.step, step);
|
|
212
|
+
}
|
|
213
|
+
for (const step of cloneAgentTurnStepLedger(incoming)) {
|
|
214
|
+
const existing = byStep.get(step.step);
|
|
215
|
+
byStep.set(step.step, existing ? mergeStepRecord(existing, step) : step);
|
|
216
|
+
}
|
|
217
|
+
return Array.from(byStep.values()).sort(
|
|
218
|
+
(left, right) => left.step - right.step
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
function findStepIndex(ledger, step) {
|
|
222
|
+
return ledger.findIndex((entry) => entry.step === step);
|
|
223
|
+
}
|
|
224
|
+
function getStepNumber(event, options) {
|
|
225
|
+
if ("step" in event && typeof event.step === "number") {
|
|
226
|
+
return event.step;
|
|
227
|
+
}
|
|
228
|
+
return options.currentStep && options.currentStep > 0 ? options.currentStep : void 0;
|
|
229
|
+
}
|
|
230
|
+
function upsertStep(ledger, step, updatedAt, update) {
|
|
231
|
+
const index = findStepIndex(ledger, step);
|
|
232
|
+
const existing = index >= 0 ? ledger[index] : {
|
|
233
|
+
step,
|
|
234
|
+
status: "running",
|
|
235
|
+
startedAt: updatedAt,
|
|
236
|
+
updatedAt,
|
|
237
|
+
text: "",
|
|
238
|
+
toolCalls: []
|
|
239
|
+
};
|
|
240
|
+
const next = update(existing);
|
|
241
|
+
if (index >= 0) {
|
|
242
|
+
ledger[index] = next;
|
|
243
|
+
return ledger;
|
|
244
|
+
}
|
|
245
|
+
ledger.push(next);
|
|
246
|
+
return ledger;
|
|
247
|
+
}
|
|
248
|
+
function upsertToolCall(record, toolCallId, update) {
|
|
249
|
+
const toolIndex = record.toolCalls.findIndex(
|
|
250
|
+
(toolCall) => toolCall.toolCallId === toolCallId
|
|
251
|
+
);
|
|
252
|
+
const existing = toolIndex >= 0 ? record.toolCalls[toolIndex] : {
|
|
253
|
+
toolCallId,
|
|
254
|
+
toolName: "unknown",
|
|
255
|
+
status: "requested"
|
|
256
|
+
};
|
|
257
|
+
const nextTool = update(existing);
|
|
258
|
+
const toolCalls = [...record.toolCalls];
|
|
259
|
+
if (toolIndex >= 0) {
|
|
260
|
+
toolCalls[toolIndex] = nextTool;
|
|
261
|
+
} else {
|
|
262
|
+
toolCalls.push(nextTool);
|
|
263
|
+
}
|
|
264
|
+
return {
|
|
265
|
+
...record,
|
|
266
|
+
toolCalls
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
function toolResultStatus(metadata) {
|
|
270
|
+
return metadata?.approvalCorrection ? "denied" : "succeeded";
|
|
271
|
+
}
|
|
272
|
+
function commitKind(boundary) {
|
|
273
|
+
if (boundary === "step-commit-start" || boundary === "step-commit-finish") {
|
|
274
|
+
return "step";
|
|
275
|
+
}
|
|
276
|
+
if (boundary === "output-commit-start" || boundary === "output-commit-finish") {
|
|
277
|
+
return "output";
|
|
278
|
+
}
|
|
279
|
+
return void 0;
|
|
280
|
+
}
|
|
281
|
+
function commitStatus(boundary) {
|
|
282
|
+
if (boundary.endsWith("-start")) {
|
|
283
|
+
return "committing";
|
|
284
|
+
}
|
|
285
|
+
if (boundary.endsWith("-finish")) {
|
|
286
|
+
return "committed";
|
|
287
|
+
}
|
|
288
|
+
return void 0;
|
|
289
|
+
}
|
|
290
|
+
function getCurrentAgentTurnStepRecord(ledger) {
|
|
291
|
+
const current = ledger?.at(-1);
|
|
292
|
+
return current ? cloneStepRecord(current) : void 0;
|
|
293
|
+
}
|
|
294
|
+
function advanceAgentTurnStepLedger(ledger, event, updatedAt, options = {}) {
|
|
295
|
+
const next = cloneAgentTurnStepLedger(ledger);
|
|
296
|
+
const step = getStepNumber(event, options);
|
|
297
|
+
switch (event.type) {
|
|
298
|
+
case "step-start":
|
|
299
|
+
return upsertStep(next, event.step, updatedAt, (record) => {
|
|
300
|
+
const rest = { ...record };
|
|
301
|
+
delete rest.usage;
|
|
302
|
+
delete rest.finishReason;
|
|
303
|
+
delete rest.commit;
|
|
304
|
+
return {
|
|
305
|
+
...rest,
|
|
306
|
+
status: "running",
|
|
307
|
+
startedAt: record.startedAt || updatedAt,
|
|
308
|
+
updatedAt,
|
|
309
|
+
text: "",
|
|
310
|
+
toolCalls: []
|
|
311
|
+
};
|
|
312
|
+
});
|
|
313
|
+
case "text-delta":
|
|
314
|
+
if (!step) return next;
|
|
315
|
+
return upsertStep(next, step, updatedAt, (record) => ({
|
|
316
|
+
...record,
|
|
317
|
+
status: record.status === "failed" ? record.status : "running",
|
|
318
|
+
updatedAt,
|
|
319
|
+
text: `${record.text}${event.text}`
|
|
320
|
+
}));
|
|
321
|
+
case "tool-start":
|
|
322
|
+
if (!step) return next;
|
|
323
|
+
return upsertStep(
|
|
324
|
+
next,
|
|
325
|
+
step,
|
|
326
|
+
updatedAt,
|
|
327
|
+
(record) => upsertToolCall(
|
|
328
|
+
{
|
|
329
|
+
...record,
|
|
330
|
+
status: "waiting-tools",
|
|
331
|
+
updatedAt
|
|
332
|
+
},
|
|
333
|
+
event.toolCallId,
|
|
334
|
+
(toolCall) => ({
|
|
335
|
+
...toolCall,
|
|
336
|
+
toolCallId: event.toolCallId,
|
|
337
|
+
toolName: event.toolName,
|
|
338
|
+
args: event.input,
|
|
339
|
+
status: "requested",
|
|
340
|
+
requestedAt: updatedAt,
|
|
341
|
+
...options.toolReplayPolicy ? { replayPolicy: options.toolReplayPolicy } : {}
|
|
342
|
+
})
|
|
343
|
+
)
|
|
344
|
+
);
|
|
345
|
+
case "tool-result":
|
|
346
|
+
if (!step) return next;
|
|
347
|
+
return upsertStep(
|
|
348
|
+
next,
|
|
349
|
+
step,
|
|
350
|
+
updatedAt,
|
|
351
|
+
(record) => upsertToolCall(
|
|
352
|
+
{
|
|
353
|
+
...record,
|
|
354
|
+
status: "waiting-tools",
|
|
355
|
+
updatedAt
|
|
356
|
+
},
|
|
357
|
+
event.toolCallId,
|
|
358
|
+
(toolCall) => ({
|
|
359
|
+
...toolCall,
|
|
360
|
+
toolCallId: event.toolCallId,
|
|
361
|
+
toolName: event.toolName,
|
|
362
|
+
status: toolResultStatus(event.metadata),
|
|
363
|
+
...captureToolResult(event.result, options.toolResultCapture),
|
|
364
|
+
resolvedAt: updatedAt,
|
|
365
|
+
...event.metadata ? { metadata: structuredClone(event.metadata) } : {},
|
|
366
|
+
...options.toolReplayPolicy ? { replayPolicy: options.toolReplayPolicy } : {}
|
|
367
|
+
})
|
|
368
|
+
)
|
|
369
|
+
);
|
|
370
|
+
case "tool-error":
|
|
371
|
+
if (!step) return next;
|
|
372
|
+
return upsertStep(
|
|
373
|
+
next,
|
|
374
|
+
step,
|
|
375
|
+
updatedAt,
|
|
376
|
+
(record) => upsertToolCall(
|
|
377
|
+
{
|
|
378
|
+
...record,
|
|
379
|
+
status: "waiting-tools",
|
|
380
|
+
updatedAt
|
|
381
|
+
},
|
|
382
|
+
event.toolCallId,
|
|
383
|
+
(toolCall) => ({
|
|
384
|
+
...toolCall,
|
|
385
|
+
toolCallId: event.toolCallId,
|
|
386
|
+
toolName: event.toolName,
|
|
387
|
+
status: "failed",
|
|
388
|
+
error: event.error,
|
|
389
|
+
resolvedAt: updatedAt,
|
|
390
|
+
...options.toolReplayPolicy ? { replayPolicy: options.toolReplayPolicy } : {}
|
|
391
|
+
})
|
|
392
|
+
)
|
|
393
|
+
);
|
|
394
|
+
case "step-finish":
|
|
395
|
+
return upsertStep(next, event.step, updatedAt, (record) => ({
|
|
396
|
+
...record,
|
|
397
|
+
status: event.finishReason === "tool-calls" ? "waiting-tools" : "completed",
|
|
398
|
+
updatedAt,
|
|
399
|
+
...event.usage ? { usage: cloneUsage(event.usage) } : {},
|
|
400
|
+
...event.finishReason ? { finishReason: event.finishReason } : {}
|
|
401
|
+
}));
|
|
402
|
+
case "turn-boundary": {
|
|
403
|
+
const kind = commitKind(event.boundary);
|
|
404
|
+
const status = commitStatus(event.boundary);
|
|
405
|
+
if (!step || !kind || !status) {
|
|
406
|
+
return next;
|
|
407
|
+
}
|
|
408
|
+
return upsertStep(next, step, updatedAt, (record) => ({
|
|
409
|
+
...record,
|
|
410
|
+
status,
|
|
411
|
+
updatedAt,
|
|
412
|
+
commit: {
|
|
413
|
+
kind,
|
|
414
|
+
status,
|
|
415
|
+
...status === "committing" ? { startedAt: updatedAt } : {
|
|
416
|
+
...record.commit?.startedAt ? { startedAt: record.commit.startedAt } : {},
|
|
417
|
+
finishedAt: updatedAt
|
|
418
|
+
},
|
|
419
|
+
...event.messageRole ? { messageRole: event.messageRole } : {},
|
|
420
|
+
...event.pendingToolCallCount !== void 0 ? { pendingToolCallCount: event.pendingToolCallCount } : record.commit?.pendingToolCallCount !== void 0 ? { pendingToolCallCount: record.commit.pendingToolCallCount } : {}
|
|
421
|
+
}
|
|
422
|
+
}));
|
|
423
|
+
}
|
|
424
|
+
case "error":
|
|
425
|
+
if (!step) return next;
|
|
426
|
+
return failAgentTurnStepLedger(next, event.error, updatedAt, step);
|
|
427
|
+
default:
|
|
428
|
+
return next;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
function failAgentTurnStepLedger(ledger, error, updatedAt, currentStep) {
|
|
432
|
+
const next = cloneAgentTurnStepLedger(ledger);
|
|
433
|
+
const step = currentStep && currentStep > 0 ? currentStep : next.at(-1)?.step;
|
|
434
|
+
if (!step) {
|
|
435
|
+
return next;
|
|
436
|
+
}
|
|
437
|
+
return upsertStep(next, step, updatedAt, (record) => ({
|
|
438
|
+
...record,
|
|
439
|
+
status: "failed",
|
|
440
|
+
updatedAt,
|
|
441
|
+
toolCalls: record.toolCalls.map(
|
|
442
|
+
(toolCall) => toolCall.status === "requested" ? {
|
|
443
|
+
...toolCall,
|
|
444
|
+
status: "failed",
|
|
445
|
+
error: error.message,
|
|
446
|
+
resolvedAt: updatedAt
|
|
447
|
+
} : toolCall
|
|
448
|
+
)
|
|
449
|
+
}));
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// src/execution/turn/state.ts
|
|
453
|
+
var EMPTY_USAGE = {
|
|
454
|
+
inputTokens: 0,
|
|
455
|
+
outputTokens: 0,
|
|
456
|
+
totalTokens: 0
|
|
457
|
+
};
|
|
458
|
+
function normalizeUsage(usage) {
|
|
459
|
+
if (!usage) {
|
|
460
|
+
return cloneUsage(EMPTY_USAGE);
|
|
461
|
+
}
|
|
462
|
+
return {
|
|
463
|
+
inputTokens: usage.inputTokens ?? 0,
|
|
464
|
+
outputTokens: usage.outputTokens ?? 0,
|
|
465
|
+
totalTokens: usage.totalTokens ?? 0
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
function removeActiveToolCall(toolCalls, toolCallId) {
|
|
469
|
+
return toolCalls.filter((toolCall) => toolCall.toolCallId !== toolCallId);
|
|
470
|
+
}
|
|
471
|
+
function cloneActiveToolCall(toolCall) {
|
|
472
|
+
return {
|
|
473
|
+
...toolCall,
|
|
474
|
+
...toolCall.replayPolicy ? { replayPolicy: { ...toolCall.replayPolicy } } : {}
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
function cloneResolvedToolCall(toolCall) {
|
|
478
|
+
return {
|
|
479
|
+
...toolCall,
|
|
480
|
+
...toolCall.metadata ? { metadata: structuredClone(toolCall.metadata) } : {},
|
|
481
|
+
...toolCall.replayPolicy ? { replayPolicy: { ...toolCall.replayPolicy } } : {}
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
function toolOutcomeStatus(outcome) {
|
|
485
|
+
return outcome === "result" ? "succeeded" : "failed";
|
|
486
|
+
}
|
|
487
|
+
function stringifyForConflict(value) {
|
|
488
|
+
try {
|
|
489
|
+
return JSON.stringify(value);
|
|
490
|
+
} catch {
|
|
491
|
+
return void 0;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
function resolvedToolCallsMatch(previous, incoming) {
|
|
495
|
+
if (previous.outcome !== incoming.outcome) {
|
|
496
|
+
return false;
|
|
497
|
+
}
|
|
498
|
+
if (Object.is(previous.value, incoming.value)) {
|
|
499
|
+
return true;
|
|
500
|
+
}
|
|
501
|
+
const previousJson = stringifyForConflict(previous.value);
|
|
502
|
+
const incomingJson = stringifyForConflict(incoming.value);
|
|
503
|
+
return previousJson !== void 0 && previousJson === incomingJson;
|
|
504
|
+
}
|
|
505
|
+
function mergeResolvedToolCalls(step, previous, incoming) {
|
|
506
|
+
const byId = /* @__PURE__ */ new Map();
|
|
507
|
+
for (const toolCall of previous) {
|
|
508
|
+
byId.set(toolCall.toolCallId, cloneResolvedToolCall(toolCall));
|
|
509
|
+
}
|
|
510
|
+
for (const toolCall of incoming) {
|
|
511
|
+
const existing = byId.get(toolCall.toolCallId);
|
|
512
|
+
if (existing && !resolvedToolCallsMatch(existing, toolCall)) {
|
|
513
|
+
throw new AgentTurnStateConflictError({
|
|
514
|
+
kind: "tool-result",
|
|
515
|
+
step,
|
|
516
|
+
toolCallId: toolCall.toolCallId,
|
|
517
|
+
toolName: toolCall.toolName || existing.toolName,
|
|
518
|
+
previousStatus: toolOutcomeStatus(existing.outcome),
|
|
519
|
+
incomingStatus: toolOutcomeStatus(toolCall.outcome),
|
|
520
|
+
reason: "resolved tool-call results differ"
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
byId.set(toolCall.toolCallId, cloneResolvedToolCall(toolCall));
|
|
524
|
+
}
|
|
525
|
+
return Array.from(byId.values());
|
|
526
|
+
}
|
|
527
|
+
function mergeActiveToolCalls(previous, incoming, resolved) {
|
|
528
|
+
const resolvedIds = new Set(resolved.map((toolCall) => toolCall.toolCallId));
|
|
529
|
+
const byId = /* @__PURE__ */ new Map();
|
|
530
|
+
for (const toolCall of previous) {
|
|
531
|
+
if (!resolvedIds.has(toolCall.toolCallId)) {
|
|
532
|
+
byId.set(toolCall.toolCallId, cloneActiveToolCall(toolCall));
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
for (const toolCall of incoming) {
|
|
536
|
+
if (!resolvedIds.has(toolCall.toolCallId)) {
|
|
537
|
+
byId.set(toolCall.toolCallId, cloneActiveToolCall(toolCall));
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
return Array.from(byId.values());
|
|
541
|
+
}
|
|
542
|
+
function createAgentTurnState(options) {
|
|
543
|
+
const restore = options.restoreFrom;
|
|
544
|
+
return {
|
|
545
|
+
sessionId: options.sessionId,
|
|
546
|
+
phase: "initializing",
|
|
547
|
+
step: restore?.step ?? 0,
|
|
548
|
+
response: restore?.response ?? "",
|
|
549
|
+
usage: restore?.usage ? cloneUsage(restore.usage) : cloneUsage(EMPTY_USAGE),
|
|
550
|
+
eventCount: restore?.eventCount ?? 0,
|
|
551
|
+
activeToolCalls: [],
|
|
552
|
+
resolvedToolCalls: [],
|
|
553
|
+
stepLedger: [],
|
|
554
|
+
startedAt: options.startedAt,
|
|
555
|
+
updatedAt: options.startedAt
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
function advanceAgentTurnState(state, event, updatedAt, options = {}) {
|
|
559
|
+
const next = {
|
|
560
|
+
...state,
|
|
561
|
+
usage: cloneUsage(state.usage),
|
|
562
|
+
activeToolCalls: state.activeToolCalls.map((toolCall) => ({ ...toolCall })),
|
|
563
|
+
resolvedToolCalls: state.resolvedToolCalls.map((toolCall) => ({
|
|
564
|
+
...toolCall,
|
|
565
|
+
...toolCall.metadata ? { metadata: structuredClone(toolCall.metadata) } : {}
|
|
566
|
+
})),
|
|
567
|
+
stepLedger: cloneAgentTurnStepLedger(state.stepLedger),
|
|
568
|
+
eventCount: state.eventCount + 1,
|
|
569
|
+
lastEvent: event,
|
|
570
|
+
updatedAt
|
|
571
|
+
};
|
|
572
|
+
switch (event.type) {
|
|
573
|
+
case "step-start":
|
|
574
|
+
next.phase = "running-model";
|
|
575
|
+
next.step = event.step;
|
|
576
|
+
next.maxSteps = event.maxSteps;
|
|
577
|
+
next.activeToolCalls = [];
|
|
578
|
+
next.resolvedToolCalls = [];
|
|
579
|
+
next.lastFinishReason = void 0;
|
|
580
|
+
delete next.error;
|
|
581
|
+
break;
|
|
582
|
+
case "text-delta":
|
|
583
|
+
next.response += event.text;
|
|
584
|
+
break;
|
|
585
|
+
case "tool-start":
|
|
586
|
+
next.phase = "running-tools";
|
|
587
|
+
next.activeToolCalls = [
|
|
588
|
+
...removeActiveToolCall(next.activeToolCalls, event.toolCallId),
|
|
589
|
+
{
|
|
590
|
+
toolCallId: event.toolCallId,
|
|
591
|
+
toolName: event.toolName,
|
|
592
|
+
input: event.input,
|
|
593
|
+
startedAt: updatedAt,
|
|
594
|
+
...options.toolReplayPolicy ? { replayPolicy: options.toolReplayPolicy } : {}
|
|
595
|
+
}
|
|
596
|
+
];
|
|
597
|
+
break;
|
|
598
|
+
case "tool-result":
|
|
599
|
+
next.phase = "running-tools";
|
|
600
|
+
next.activeToolCalls = removeActiveToolCall(
|
|
601
|
+
next.activeToolCalls,
|
|
602
|
+
event.toolCallId
|
|
603
|
+
);
|
|
604
|
+
next.resolvedToolCalls = [
|
|
605
|
+
...next.resolvedToolCalls,
|
|
606
|
+
{
|
|
607
|
+
toolCallId: event.toolCallId,
|
|
608
|
+
toolName: event.toolName,
|
|
609
|
+
outcome: "result",
|
|
610
|
+
value: event.result,
|
|
611
|
+
...event.metadata ? { metadata: structuredClone(event.metadata) } : {},
|
|
612
|
+
resolvedAt: updatedAt,
|
|
613
|
+
...options.toolReplayPolicy ? { replayPolicy: options.toolReplayPolicy } : {}
|
|
614
|
+
}
|
|
615
|
+
];
|
|
616
|
+
break;
|
|
617
|
+
case "tool-error":
|
|
618
|
+
next.phase = "running-tools";
|
|
619
|
+
next.activeToolCalls = removeActiveToolCall(
|
|
620
|
+
next.activeToolCalls,
|
|
621
|
+
event.toolCallId
|
|
622
|
+
);
|
|
623
|
+
next.resolvedToolCalls = [
|
|
624
|
+
...next.resolvedToolCalls,
|
|
625
|
+
{
|
|
626
|
+
toolCallId: event.toolCallId,
|
|
627
|
+
toolName: event.toolName,
|
|
628
|
+
outcome: "error",
|
|
629
|
+
value: event.error,
|
|
630
|
+
resolvedAt: updatedAt,
|
|
631
|
+
...options.toolReplayPolicy ? { replayPolicy: options.toolReplayPolicy } : {}
|
|
632
|
+
}
|
|
633
|
+
];
|
|
634
|
+
break;
|
|
635
|
+
case "step-finish":
|
|
636
|
+
next.phase = "committing-step";
|
|
637
|
+
next.step = event.step;
|
|
638
|
+
next.usage = normalizeUsage(event.usage ?? next.usage);
|
|
639
|
+
next.lastFinishReason = event.finishReason;
|
|
640
|
+
break;
|
|
641
|
+
case "turn-boundary":
|
|
642
|
+
next.lastBoundary = {
|
|
643
|
+
kind: event.boundary,
|
|
644
|
+
createdAt: updatedAt,
|
|
645
|
+
...event.step !== void 0 ? { step: event.step } : {},
|
|
646
|
+
...event.messageRole ? { messageRole: event.messageRole } : {},
|
|
647
|
+
...event.pendingToolCallCount !== void 0 ? { pendingToolCallCount: event.pendingToolCallCount } : {}
|
|
648
|
+
};
|
|
649
|
+
switch (event.boundary) {
|
|
650
|
+
case "input-commit-start":
|
|
651
|
+
case "input-commit-finish":
|
|
652
|
+
case "intervention-commit-start":
|
|
653
|
+
case "intervention-commit-finish":
|
|
654
|
+
next.phase = "committing-input";
|
|
655
|
+
break;
|
|
656
|
+
case "step-commit-start":
|
|
657
|
+
case "step-commit-finish":
|
|
658
|
+
next.phase = "committing-step";
|
|
659
|
+
break;
|
|
660
|
+
case "output-commit-start":
|
|
661
|
+
case "output-commit-finish":
|
|
662
|
+
next.phase = "committing-output";
|
|
663
|
+
break;
|
|
664
|
+
}
|
|
665
|
+
break;
|
|
666
|
+
case "complete":
|
|
667
|
+
next.phase = "completed";
|
|
668
|
+
next.usage = normalizeUsage(event.usage ?? next.usage);
|
|
669
|
+
break;
|
|
670
|
+
case "error":
|
|
671
|
+
next.phase = "failed";
|
|
672
|
+
next.error = event.error.message;
|
|
673
|
+
break;
|
|
674
|
+
default:
|
|
675
|
+
break;
|
|
676
|
+
}
|
|
677
|
+
next.stepLedger = advanceAgentTurnStepLedger(
|
|
678
|
+
state.stepLedger,
|
|
679
|
+
event,
|
|
680
|
+
updatedAt,
|
|
681
|
+
{
|
|
682
|
+
currentStep: next.step || state.step,
|
|
683
|
+
...options.toolReplayPolicy ? { toolReplayPolicy: options.toolReplayPolicy } : {},
|
|
684
|
+
...options.toolResultCapture ? { toolResultCapture: options.toolResultCapture } : {}
|
|
685
|
+
}
|
|
686
|
+
);
|
|
687
|
+
return next;
|
|
688
|
+
}
|
|
689
|
+
function failAgentTurnState(state, error, updatedAt) {
|
|
690
|
+
return {
|
|
691
|
+
...state,
|
|
692
|
+
usage: cloneUsage(state.usage),
|
|
693
|
+
activeToolCalls: state.activeToolCalls.map((toolCall) => ({ ...toolCall })),
|
|
694
|
+
resolvedToolCalls: state.resolvedToolCalls.map((toolCall) => ({
|
|
695
|
+
...toolCall,
|
|
696
|
+
...toolCall.metadata ? { metadata: structuredClone(toolCall.metadata) } : {}
|
|
697
|
+
})),
|
|
698
|
+
stepLedger: failAgentTurnStepLedger(
|
|
699
|
+
state.stepLedger,
|
|
700
|
+
error,
|
|
701
|
+
updatedAt,
|
|
702
|
+
state.step
|
|
703
|
+
),
|
|
704
|
+
phase: "failed",
|
|
705
|
+
error: error.message,
|
|
706
|
+
updatedAt
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
function mergeAgentTurnStateProgress(previous, incoming) {
|
|
710
|
+
if (!previous) {
|
|
711
|
+
return {
|
|
712
|
+
...incoming,
|
|
713
|
+
usage: cloneUsage(incoming.usage),
|
|
714
|
+
activeToolCalls: incoming.activeToolCalls.map(cloneActiveToolCall),
|
|
715
|
+
resolvedToolCalls: incoming.resolvedToolCalls.map(cloneResolvedToolCall),
|
|
716
|
+
stepLedger: cloneAgentTurnStepLedger(incoming.stepLedger)
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
const resolvedToolCalls = mergeResolvedToolCalls(
|
|
720
|
+
incoming.step || previous.step,
|
|
721
|
+
previous.resolvedToolCalls,
|
|
722
|
+
incoming.resolvedToolCalls
|
|
723
|
+
);
|
|
724
|
+
return {
|
|
725
|
+
...incoming,
|
|
726
|
+
usage: cloneUsage(incoming.usage),
|
|
727
|
+
activeToolCalls: mergeActiveToolCalls(
|
|
728
|
+
previous.activeToolCalls,
|
|
729
|
+
incoming.activeToolCalls,
|
|
730
|
+
resolvedToolCalls
|
|
731
|
+
),
|
|
732
|
+
resolvedToolCalls,
|
|
733
|
+
stepLedger: mergeAgentTurnStepLedgers(
|
|
734
|
+
previous.stepLedger,
|
|
735
|
+
incoming.stepLedger
|
|
736
|
+
)
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
// src/types/messages.ts
|
|
741
|
+
function accumulateUsage(current, next) {
|
|
742
|
+
if (!next) return current;
|
|
743
|
+
if (!current) {
|
|
744
|
+
return {
|
|
745
|
+
inputTokens: next.inputTokens ?? 0,
|
|
746
|
+
outputTokens: next.outputTokens ?? 0,
|
|
747
|
+
totalTokens: next.totalTokens ?? 0,
|
|
748
|
+
cacheReadTokens: (next.cacheReadTokens ?? 0) || void 0,
|
|
749
|
+
cacheWriteTokens: (next.cacheWriteTokens ?? 0) || void 0
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
const cacheRead = (current.cacheReadTokens ?? 0) + (next.cacheReadTokens ?? 0);
|
|
753
|
+
const cacheWrite = (current.cacheWriteTokens ?? 0) + (next.cacheWriteTokens ?? 0);
|
|
754
|
+
return {
|
|
755
|
+
inputTokens: (current.inputTokens ?? 0) + (next.inputTokens ?? 0),
|
|
756
|
+
outputTokens: (current.outputTokens ?? 0) + (next.outputTokens ?? 0),
|
|
757
|
+
totalTokens: (current.totalTokens ?? 0) + (next.totalTokens ?? 0),
|
|
758
|
+
cacheReadTokens: cacheRead || void 0,
|
|
759
|
+
cacheWriteTokens: cacheWrite || void 0
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
export {
|
|
764
|
+
cloneUsage,
|
|
765
|
+
AgentTurnStateConflictError,
|
|
766
|
+
getCurrentAgentTurnStepRecord,
|
|
767
|
+
createAgentTurnState,
|
|
768
|
+
advanceAgentTurnState,
|
|
769
|
+
failAgentTurnState,
|
|
770
|
+
mergeAgentTurnStateProgress,
|
|
771
|
+
accumulateUsage
|
|
772
|
+
};
|