@draht/agent-core 2026.7.30 → 2026.10.4-2
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/dist/agent-loop.d.ts +27 -2
- package/dist/agent-loop.d.ts.map +1 -1
- package/dist/agent-loop.js +181 -63
- package/dist/agent-loop.js.map +1 -1
- package/dist/agent.d.ts +14 -4
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +68 -19
- package/dist/agent.js.map +1 -1
- package/dist/harness/agent-harness.d.ts +713 -91
- package/dist/harness/agent-harness.d.ts.map +1 -1
- package/dist/harness/agent-harness.js +5 -950
- package/dist/harness/agent-harness.js.map +1 -1
- package/dist/harness/compaction/branch-summarization.d.ts +23 -10
- package/dist/harness/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/harness/compaction/branch-summarization.js +39 -36
- package/dist/harness/compaction/branch-summarization.js.map +1 -1
- package/dist/harness/compaction/compaction.d.ts +37 -18
- package/dist/harness/compaction/compaction.d.ts.map +1 -1
- package/dist/harness/compaction/compaction.js +74 -97
- package/dist/harness/compaction/compaction.js.map +1 -1
- package/dist/harness/config.d.ts +9 -0
- package/dist/harness/config.d.ts.map +1 -0
- package/dist/harness/config.js +35 -0
- package/dist/harness/config.js.map +1 -0
- package/dist/harness/context.d.ts +9 -0
- package/dist/harness/context.d.ts.map +1 -0
- package/dist/harness/context.js +13 -0
- package/dist/harness/context.js.map +1 -0
- package/dist/harness/env/nodejs.d.ts +25 -27
- package/dist/harness/env/nodejs.d.ts.map +1 -1
- package/dist/harness/env/nodejs.js +355 -110
- package/dist/harness/env/nodejs.js.map +1 -1
- package/dist/harness/events.d.ts +24 -0
- package/dist/harness/events.d.ts.map +1 -0
- package/dist/harness/events.js +233 -0
- package/dist/harness/events.js.map +1 -0
- package/dist/harness/execution/assistant.d.ts +42 -0
- package/dist/harness/execution/assistant.d.ts.map +1 -0
- package/dist/harness/execution/assistant.js +82 -0
- package/dist/harness/execution/assistant.js.map +1 -0
- package/dist/harness/execution/effect-gate.d.ts +22 -0
- package/dist/harness/execution/effect-gate.d.ts.map +1 -0
- package/dist/harness/execution/effect-gate.js +49 -0
- package/dist/harness/execution/effect-gate.js.map +1 -0
- package/dist/harness/execution/tools.d.ts +67 -0
- package/dist/harness/execution/tools.d.ts.map +1 -0
- package/dist/harness/execution/tools.js +119 -0
- package/dist/harness/execution/tools.js.map +1 -0
- package/dist/harness/hooks.d.ts +38 -0
- package/dist/harness/hooks.d.ts.map +1 -0
- package/dist/harness/hooks.js +406 -0
- package/dist/harness/hooks.js.map +1 -0
- package/dist/harness/messages.d.ts +4 -4
- package/dist/harness/messages.d.ts.map +1 -1
- package/dist/harness/messages.js +4 -3
- package/dist/harness/messages.js.map +1 -1
- package/dist/harness/pico3/bash.d.ts +10 -0
- package/dist/harness/pico3/bash.d.ts.map +1 -0
- package/dist/harness/pico3/bash.js +25 -0
- package/dist/harness/pico3/bash.js.map +1 -0
- package/dist/harness/pico3/bounded.d.ts +21 -0
- package/dist/harness/pico3/bounded.d.ts.map +1 -0
- package/dist/harness/pico3/bounded.js +98 -0
- package/dist/harness/pico3/bounded.js.map +1 -0
- package/dist/harness/pico3/chord.d.ts +41 -0
- package/dist/harness/pico3/chord.d.ts.map +1 -0
- package/dist/harness/pico3/chord.js +147 -0
- package/dist/harness/pico3/chord.js.map +1 -0
- package/dist/harness/pico3/context.d.ts +16 -0
- package/dist/harness/pico3/context.d.ts.map +1 -0
- package/dist/harness/pico3/context.js +88 -0
- package/dist/harness/pico3/context.js.map +1 -0
- package/dist/harness/pico3/harness.d.ts +198 -0
- package/dist/harness/pico3/harness.d.ts.map +1 -0
- package/dist/harness/pico3/harness.js +654 -0
- package/dist/harness/pico3/harness.js.map +1 -0
- package/dist/harness/pico3/hooks.d.ts +10 -0
- package/dist/harness/pico3/hooks.d.ts.map +1 -0
- package/dist/harness/pico3/hooks.js +33 -0
- package/dist/harness/pico3/hooks.js.map +1 -0
- package/dist/harness/pico3/index.d.ts +19 -0
- package/dist/harness/pico3/index.d.ts.map +1 -0
- package/dist/harness/pico3/index.js +15 -0
- package/dist/harness/pico3/index.js.map +1 -0
- package/dist/harness/pico3/jsonl.d.ts +58 -0
- package/dist/harness/pico3/jsonl.d.ts.map +1 -0
- package/dist/harness/pico3/jsonl.js +325 -0
- package/dist/harness/pico3/jsonl.js.map +1 -0
- package/dist/harness/pico3/kinds/collapse.d.ts +49 -0
- package/dist/harness/pico3/kinds/collapse.d.ts.map +1 -0
- package/dist/harness/pico3/kinds/collapse.js +191 -0
- package/dist/harness/pico3/kinds/collapse.js.map +1 -0
- package/dist/harness/pico3/kinds/entries.d.ts +78 -0
- package/dist/harness/pico3/kinds/entries.d.ts.map +1 -0
- package/dist/harness/pico3/kinds/entries.js +13 -0
- package/dist/harness/pico3/kinds/entries.js.map +1 -0
- package/dist/harness/pico3/kinds/frames.d.ts +9 -0
- package/dist/harness/pico3/kinds/frames.d.ts.map +1 -0
- package/dist/harness/pico3/kinds/frames.js +75 -0
- package/dist/harness/pico3/kinds/frames.js.map +1 -0
- package/dist/harness/pico3/kinds/generation.d.ts +94 -0
- package/dist/harness/pico3/kinds/generation.d.ts.map +1 -0
- package/dist/harness/pico3/kinds/generation.js +504 -0
- package/dist/harness/pico3/kinds/generation.js.map +1 -0
- package/dist/harness/pico3/kinds/job.d.ts +44 -0
- package/dist/harness/pico3/kinds/job.d.ts.map +1 -0
- package/dist/harness/pico3/kinds/job.js +143 -0
- package/dist/harness/pico3/kinds/job.js.map +1 -0
- package/dist/harness/pico3/kinds/plugin.d.ts +15 -0
- package/dist/harness/pico3/kinds/plugin.d.ts.map +1 -0
- package/dist/harness/pico3/kinds/plugin.js +35 -0
- package/dist/harness/pico3/kinds/plugin.js.map +1 -0
- package/dist/harness/pico3/kinds/post-tools.d.ts +22 -0
- package/dist/harness/pico3/kinds/post-tools.d.ts.map +1 -0
- package/dist/harness/pico3/kinds/post-tools.js +145 -0
- package/dist/harness/pico3/kinds/post-tools.js.map +1 -0
- package/dist/harness/pico3/kinds/task-api.d.ts +3 -0
- package/dist/harness/pico3/kinds/task-api.d.ts.map +1 -0
- package/dist/harness/pico3/kinds/task-api.js +45 -0
- package/dist/harness/pico3/kinds/task-api.js.map +1 -0
- package/dist/harness/pico3/kinds/tool.d.ts +43 -0
- package/dist/harness/pico3/kinds/tool.d.ts.map +1 -0
- package/dist/harness/pico3/kinds/tool.js +373 -0
- package/dist/harness/pico3/kinds/tool.js.map +1 -0
- package/dist/harness/pico3/legacy-tracker.d.ts +11 -0
- package/dist/harness/pico3/legacy-tracker.d.ts.map +1 -0
- package/dist/harness/pico3/legacy-tracker.js +41 -0
- package/dist/harness/pico3/legacy-tracker.js.map +1 -0
- package/dist/harness/pico3/membrane.d.ts +23 -0
- package/dist/harness/pico3/membrane.d.ts.map +1 -0
- package/dist/harness/pico3/membrane.js +141 -0
- package/dist/harness/pico3/membrane.js.map +1 -0
- package/dist/harness/pico3/memory.d.ts +53 -0
- package/dist/harness/pico3/memory.d.ts.map +1 -0
- package/dist/harness/pico3/memory.js +264 -0
- package/dist/harness/pico3/memory.js.map +1 -0
- package/dist/harness/pico3/scheduler.d.ts +49 -0
- package/dist/harness/pico3/scheduler.d.ts.map +1 -0
- package/dist/harness/pico3/scheduler.js +438 -0
- package/dist/harness/pico3/scheduler.js.map +1 -0
- package/dist/harness/pico3/session.d.ts +264 -0
- package/dist/harness/pico3/session.d.ts.map +1 -0
- package/dist/harness/pico3/session.js +1348 -0
- package/dist/harness/pico3/session.js.map +1 -0
- package/dist/harness/pico3/system.d.ts +126 -0
- package/dist/harness/pico3/system.d.ts.map +1 -0
- package/dist/harness/pico3/system.js +244 -0
- package/dist/harness/pico3/system.js.map +1 -0
- package/dist/harness/pico3/types.d.ts +973 -0
- package/dist/harness/pico3/types.d.ts.map +1 -0
- package/dist/harness/pico3/types.js +106 -0
- package/dist/harness/pico3/types.js.map +1 -0
- package/dist/harness/pico3/view.d.ts +34 -0
- package/dist/harness/pico3/view.d.ts.map +1 -0
- package/dist/harness/pico3/view.js +411 -0
- package/dist/harness/pico3/view.js.map +1 -0
- package/dist/harness/prompt-templates.d.ts +3 -2
- package/dist/harness/prompt-templates.d.ts.map +1 -1
- package/dist/harness/prompt-templates.js +18 -23
- package/dist/harness/prompt-templates.js.map +1 -1
- package/dist/harness/result.d.ts +133 -0
- package/dist/harness/result.d.ts.map +1 -0
- package/dist/harness/result.js +81 -0
- package/dist/harness/result.js.map +1 -0
- package/dist/harness/runtime/drive/boundary.d.ts +28 -0
- package/dist/harness/runtime/drive/boundary.d.ts.map +1 -0
- package/dist/harness/runtime/drive/boundary.js +173 -0
- package/dist/harness/runtime/drive/boundary.js.map +1 -0
- package/dist/harness/runtime/drive/checkpoint.d.ts +8 -0
- package/dist/harness/runtime/drive/checkpoint.d.ts.map +1 -0
- package/dist/harness/runtime/drive/checkpoint.js +133 -0
- package/dist/harness/runtime/drive/checkpoint.js.map +1 -0
- package/dist/harness/runtime/drive/deferred.d.ts +15 -0
- package/dist/harness/runtime/drive/deferred.d.ts.map +1 -0
- package/dist/harness/runtime/drive/deferred.js +179 -0
- package/dist/harness/runtime/drive/deferred.js.map +1 -0
- package/dist/harness/runtime/drive/generation.d.ts +8 -0
- package/dist/harness/runtime/drive/generation.d.ts.map +1 -0
- package/dist/harness/runtime/drive/generation.js +205 -0
- package/dist/harness/runtime/drive/generation.js.map +1 -0
- package/dist/harness/runtime/drive/reconcile.d.ts +5 -0
- package/dist/harness/runtime/drive/reconcile.d.ts.map +1 -0
- package/dist/harness/runtime/drive/reconcile.js +140 -0
- package/dist/harness/runtime/drive/reconcile.js.map +1 -0
- package/dist/harness/runtime/drive/recovery.d.ts +8 -0
- package/dist/harness/runtime/drive/recovery.d.ts.map +1 -0
- package/dist/harness/runtime/drive/recovery.js +85 -0
- package/dist/harness/runtime/drive/recovery.js.map +1 -0
- package/dist/harness/runtime/drive/response.d.ts +23 -0
- package/dist/harness/runtime/drive/response.d.ts.map +1 -0
- package/dist/harness/runtime/drive/response.js +394 -0
- package/dist/harness/runtime/drive/response.js.map +1 -0
- package/dist/harness/runtime/drive/retry.d.ts +4 -0
- package/dist/harness/runtime/drive/retry.d.ts.map +1 -0
- package/dist/harness/runtime/drive/retry.js +34 -0
- package/dist/harness/runtime/drive/retry.js.map +1 -0
- package/dist/harness/runtime/drive/structural.d.ts +32 -0
- package/dist/harness/runtime/drive/structural.d.ts.map +1 -0
- package/dist/harness/runtime/drive/structural.js +929 -0
- package/dist/harness/runtime/drive/structural.js.map +1 -0
- package/dist/harness/runtime/drive/terminal.d.ts +7 -0
- package/dist/harness/runtime/drive/terminal.d.ts.map +1 -0
- package/dist/harness/runtime/drive/terminal.js +49 -0
- package/dist/harness/runtime/drive/terminal.js.map +1 -0
- package/dist/harness/runtime/drive/tool-placement.d.ts +14 -0
- package/dist/harness/runtime/drive/tool-placement.d.ts.map +1 -0
- package/dist/harness/runtime/drive/tool-placement.js +219 -0
- package/dist/harness/runtime/drive/tool-placement.js.map +1 -0
- package/dist/harness/runtime/drive/tools.d.ts +6 -0
- package/dist/harness/runtime/drive/tools.d.ts.map +1 -0
- package/dist/harness/runtime/drive/tools.js +449 -0
- package/dist/harness/runtime/drive/tools.js.map +1 -0
- package/dist/harness/runtime/drive.d.ts +6 -0
- package/dist/harness/runtime/drive.d.ts.map +1 -0
- package/dist/harness/runtime/drive.js +93 -0
- package/dist/harness/runtime/drive.js.map +1 -0
- package/dist/harness/runtime/harness.d.ts +59 -0
- package/dist/harness/runtime/harness.d.ts.map +1 -0
- package/dist/harness/runtime/harness.js +311 -0
- package/dist/harness/runtime/harness.js.map +1 -0
- package/dist/harness/runtime/index.d.ts +2 -0
- package/dist/harness/runtime/index.d.ts.map +1 -0
- package/dist/harness/runtime/index.js +2 -0
- package/dist/harness/runtime/index.js.map +1 -0
- package/dist/harness/runtime/lane.d.ts +118 -0
- package/dist/harness/runtime/lane.d.ts.map +1 -0
- package/dist/harness/runtime/lane.js +1575 -0
- package/dist/harness/runtime/lane.js.map +1 -0
- package/dist/harness/runtime/progress.d.ts +15 -0
- package/dist/harness/runtime/progress.d.ts.map +1 -0
- package/dist/harness/runtime/progress.js +66 -0
- package/dist/harness/runtime/progress.js.map +1 -0
- package/dist/harness/runtime/reducer.d.ts +5 -0
- package/dist/harness/runtime/reducer.d.ts.map +1 -0
- package/dist/harness/runtime/reducer.js +240 -0
- package/dist/harness/runtime/reducer.js.map +1 -0
- package/dist/harness/runtime/restore.d.ts +24 -0
- package/dist/harness/runtime/restore.d.ts.map +1 -0
- package/dist/harness/runtime/restore.js +117 -0
- package/dist/harness/runtime/restore.js.map +1 -0
- package/dist/harness/runtime/transcript.d.ts +21 -0
- package/dist/harness/runtime/transcript.d.ts.map +1 -0
- package/dist/harness/runtime/transcript.js +72 -0
- package/dist/harness/runtime/transcript.js.map +1 -0
- package/dist/harness/runtime/types.d.ts +105 -0
- package/dist/harness/runtime/types.d.ts.map +1 -0
- package/dist/harness/runtime/types.js +61 -0
- package/dist/harness/runtime/types.js.map +1 -0
- package/dist/harness/session/commit.d.ts +53 -0
- package/dist/harness/session/commit.d.ts.map +1 -0
- package/dist/harness/session/commit.js +57 -0
- package/dist/harness/session/commit.js.map +1 -0
- package/dist/harness/session/context.d.ts +10 -0
- package/dist/harness/session/context.d.ts.map +1 -0
- package/dist/harness/session/context.js +49 -0
- package/dist/harness/session/context.js.map +1 -0
- package/dist/harness/session/fork-policy.d.ts +21 -0
- package/dist/harness/session/fork-policy.d.ts.map +1 -0
- package/dist/harness/session/fork-policy.js +55 -0
- package/dist/harness/session/fork-policy.js.map +1 -0
- package/dist/harness/session/fork.d.ts +16 -0
- package/dist/harness/session/fork.d.ts.map +1 -0
- package/dist/harness/session/fork.js +79 -0
- package/dist/harness/session/fork.js.map +1 -0
- package/dist/harness/session/in-memory-storage-state.d.ts +39 -0
- package/dist/harness/session/in-memory-storage-state.d.ts.map +1 -0
- package/dist/harness/session/in-memory-storage-state.js +276 -0
- package/dist/harness/session/in-memory-storage-state.js.map +1 -0
- package/dist/harness/session/index.d.ts +11 -0
- package/dist/harness/session/index.d.ts.map +1 -0
- package/dist/harness/session/index.js +9 -0
- package/dist/harness/session/index.js.map +1 -0
- package/dist/harness/session/jsonl/codec.d.ts +21 -0
- package/dist/harness/session/jsonl/codec.d.ts.map +1 -0
- package/dist/harness/session/jsonl/codec.js +45 -0
- package/dist/harness/session/jsonl/codec.js.map +1 -0
- package/dist/harness/session/jsonl/fork.d.ts +38 -0
- package/dist/harness/session/jsonl/fork.d.ts.map +1 -0
- package/dist/harness/session/jsonl/fork.js +264 -0
- package/dist/harness/session/jsonl/fork.js.map +1 -0
- package/dist/harness/session/jsonl/index.d.ts +4 -0
- package/dist/harness/session/jsonl/index.d.ts.map +1 -0
- package/dist/harness/session/jsonl/index.js +4 -0
- package/dist/harness/session/jsonl/index.js.map +1 -0
- package/dist/harness/session/jsonl/io.d.ts +14 -0
- package/dist/harness/session/jsonl/io.d.ts.map +1 -0
- package/dist/harness/session/jsonl/io.js +86 -0
- package/dist/harness/session/jsonl/io.js.map +1 -0
- package/dist/harness/session/jsonl/legacy-v3.d.ts +44 -0
- package/dist/harness/session/jsonl/legacy-v3.d.ts.map +1 -0
- package/dist/harness/session/jsonl/legacy-v3.js +462 -0
- package/dist/harness/session/jsonl/legacy-v3.js.map +1 -0
- package/dist/harness/session/jsonl/repo.d.ts +35 -0
- package/dist/harness/session/jsonl/repo.d.ts.map +1 -0
- package/dist/harness/session/jsonl/repo.js +301 -0
- package/dist/harness/session/jsonl/repo.js.map +1 -0
- package/dist/harness/session/jsonl/storage.d.ts +41 -0
- package/dist/harness/session/jsonl/storage.d.ts.map +1 -0
- package/dist/harness/session/jsonl/storage.js +200 -0
- package/dist/harness/session/jsonl/storage.js.map +1 -0
- package/dist/harness/session/jsonl/types.d.ts +39 -0
- package/dist/harness/session/jsonl/types.d.ts.map +1 -0
- package/dist/harness/session/jsonl/types.js +3 -0
- package/dist/harness/session/jsonl/types.js.map +1 -0
- package/dist/harness/session/memory.d.ts +48 -0
- package/dist/harness/session/memory.d.ts.map +1 -0
- package/dist/harness/session/memory.js +369 -0
- package/dist/harness/session/memory.js.map +1 -0
- package/dist/harness/session/mutation-line.d.ts +8 -0
- package/dist/harness/session/mutation-line.d.ts.map +1 -0
- package/dist/harness/session/mutation-line.js +21 -0
- package/dist/harness/session/mutation-line.js.map +1 -0
- package/dist/harness/session/session.d.ts +79 -46
- package/dist/harness/session/session.d.ts.map +1 -1
- package/dist/harness/session/session.js +320 -220
- package/dist/harness/session/session.js.map +1 -1
- package/dist/harness/session/testing/benchmark/datasets.d.ts +12 -0
- package/dist/harness/session/testing/benchmark/datasets.d.ts.map +1 -0
- package/dist/harness/session/testing/benchmark/datasets.js +24 -0
- package/dist/harness/session/testing/benchmark/datasets.js.map +1 -0
- package/dist/harness/session/testing/benchmark/session-repo.d.ts +42 -0
- package/dist/harness/session/testing/benchmark/session-repo.d.ts.map +1 -0
- package/dist/harness/session/testing/benchmark/session-repo.js +127 -0
- package/dist/harness/session/testing/benchmark/session-repo.js.map +1 -0
- package/dist/harness/session/testing/benchmark/storage.d.ts +25 -0
- package/dist/harness/session/testing/benchmark/storage.d.ts.map +1 -0
- package/dist/harness/session/testing/benchmark/storage.js +114 -0
- package/dist/harness/session/testing/benchmark/storage.js.map +1 -0
- package/dist/harness/session/testing/conformance/session-repo.d.ts +23 -0
- package/dist/harness/session/testing/conformance/session-repo.d.ts.map +1 -0
- package/dist/harness/session/testing/conformance/session-repo.js +809 -0
- package/dist/harness/session/testing/conformance/session-repo.js.map +1 -0
- package/dist/harness/session/testing/conformance/storage.d.ts +4 -0
- package/dist/harness/session/testing/conformance/storage.d.ts.map +1 -0
- package/dist/harness/session/testing/conformance/storage.js +600 -0
- package/dist/harness/session/testing/conformance/storage.js.map +1 -0
- package/dist/harness/session/testing/gating-storage.d.ts +26 -0
- package/dist/harness/session/testing/gating-storage.d.ts.map +1 -0
- package/dist/harness/session/testing/gating-storage.js +100 -0
- package/dist/harness/session/testing/gating-storage.js.map +1 -0
- package/dist/harness/session/testing/index.d.ts +10 -0
- package/dist/harness/session/testing/index.d.ts.map +1 -0
- package/dist/harness/session/testing/index.js +9 -0
- package/dist/harness/session/testing/index.js.map +1 -0
- package/dist/harness/session/testing/instrumented-storage.d.ts +11 -0
- package/dist/harness/session/testing/instrumented-storage.d.ts.map +1 -0
- package/dist/harness/session/testing/instrumented-storage.js +16 -0
- package/dist/harness/session/testing/instrumented-storage.js.map +1 -0
- package/dist/harness/session/testing/storage-decorator.d.ts +20 -0
- package/dist/harness/session/testing/storage-decorator.d.ts.map +1 -0
- package/dist/harness/session/testing/storage-decorator.js +41 -0
- package/dist/harness/session/testing/storage-decorator.js.map +1 -0
- package/dist/harness/session/testing/types.d.ts +12 -0
- package/dist/harness/session/testing/types.d.ts.map +1 -0
- package/dist/harness/session/testing/types.js +2 -0
- package/dist/harness/session/testing/types.js.map +1 -0
- package/dist/harness/session/types.d.ts +512 -0
- package/dist/harness/session/types.d.ts.map +1 -0
- package/dist/harness/session/types.js +9 -0
- package/dist/harness/session/types.js.map +1 -0
- package/dist/harness/session/values.d.ts +95 -0
- package/dist/harness/session/values.d.ts.map +1 -0
- package/dist/harness/session/values.js +81 -0
- package/dist/harness/session/values.js.map +1 -0
- package/dist/harness/skills.d.ts +6 -4
- package/dist/harness/skills.d.ts.map +1 -1
- package/dist/harness/skills.js +59 -44
- package/dist/harness/skills.js.map +1 -1
- package/dist/harness/telemetry.d.ts +1242 -0
- package/dist/harness/telemetry.d.ts.map +1 -0
- package/dist/harness/telemetry.js +527 -0
- package/dist/harness/telemetry.js.map +1 -0
- package/dist/harness/tools/bash.d.ts +4 -4
- package/dist/harness/tools/bash.d.ts.map +1 -1
- package/dist/harness/tools/bash.js +66 -93
- package/dist/harness/tools/bash.js.map +1 -1
- package/dist/harness/tools/edit.d.ts.map +1 -1
- package/dist/harness/tools/edit.js +24 -11
- package/dist/harness/tools/edit.js.map +1 -1
- package/dist/harness/tools/file-mutation-queue.d.ts +2 -1
- package/dist/harness/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/harness/tools/file-mutation-queue.js +5 -5
- package/dist/harness/tools/file-mutation-queue.js.map +1 -1
- package/dist/harness/tools/image.js +1 -1
- package/dist/harness/tools/image.js.map +1 -1
- package/dist/harness/tools/path-utils.d.ts +3 -2
- package/dist/harness/tools/path-utils.d.ts.map +1 -1
- package/dist/harness/tools/path-utils.js +5 -5
- package/dist/harness/tools/path-utils.js.map +1 -1
- package/dist/harness/tools/read.d.ts +2 -1
- package/dist/harness/tools/read.d.ts.map +1 -1
- package/dist/harness/tools/read.js +4 -6
- package/dist/harness/tools/read.js.map +1 -1
- package/dist/harness/tools/write.d.ts.map +1 -1
- package/dist/harness/tools/write.js +7 -7
- package/dist/harness/tools/write.js.map +1 -1
- package/dist/harness/types.d.ts +126 -502
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js +10 -16
- package/dist/harness/types.js.map +1 -1
- package/dist/harness/utils/adaptive-publisher.d.ts +24 -0
- package/dist/harness/utils/adaptive-publisher.d.ts.map +1 -0
- package/dist/harness/utils/adaptive-publisher.js +79 -0
- package/dist/harness/utils/adaptive-publisher.js.map +1 -0
- package/dist/harness/utils/output-capture.d.ts +31 -0
- package/dist/harness/utils/output-capture.d.ts.map +1 -0
- package/dist/harness/utils/output-capture.js +217 -0
- package/dist/harness/utils/output-capture.js.map +1 -0
- package/dist/harness/utils/shell-output.d.ts +12 -5
- package/dist/harness/utils/shell-output.d.ts.map +1 -1
- package/dist/harness/utils/shell-output.js +64 -174
- package/dist/harness/utils/shell-output.js.map +1 -1
- package/dist/harness/utils/truncate.d.ts +1 -0
- package/dist/harness/utils/truncate.d.ts.map +1 -1
- package/dist/harness/utils/truncate.js +1 -1
- package/dist/harness/utils/truncate.js.map +1 -1
- package/dist/harness/utils/usage.d.ts +4 -0
- package/dist/harness/utils/usage.d.ts.map +1 -0
- package/dist/harness/utils/usage.js +33 -0
- package/dist/harness/utils/usage.js.map +1 -0
- package/dist/index.d.ts +13 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -13
- package/dist/index.js.map +1 -1
- package/dist/proxy.d.ts +6 -3
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +42 -10
- package/dist/proxy.js.map +1 -1
- package/dist/search/index.d.ts +29 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +2 -0
- package/dist/search/index.js.map +1 -0
- package/dist/types.d.ts +113 -31
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +50 -4
- package/dist/harness/session/jsonl-repo.d.ts +0 -26
- package/dist/harness/session/jsonl-repo.d.ts.map +0 -1
- package/dist/harness/session/jsonl-repo.js +0 -100
- package/dist/harness/session/jsonl-repo.js.map +0 -1
- package/dist/harness/session/jsonl-storage.d.ts +0 -42
- package/dist/harness/session/jsonl-storage.d.ts.map +0 -1
- package/dist/harness/session/jsonl-storage.js +0 -286
- package/dist/harness/session/jsonl-storage.js.map +0 -1
- package/dist/harness/session/memory-repo.d.ts +0 -18
- package/dist/harness/session/memory-repo.d.ts.map +0 -1
- package/dist/harness/session/memory-repo.js +0 -44
- package/dist/harness/session/memory-repo.js.map +0 -1
- package/dist/harness/session/memory-storage.d.ts +0 -33
- package/dist/harness/session/memory-storage.d.ts.map +0 -1
- package/dist/harness/session/memory-storage.js +0 -163
- package/dist/harness/session/memory-storage.js.map +0 -1
- package/dist/harness/session/repo-utils.d.ts +0 -11
- package/dist/harness/session/repo-utils.d.ts.map +0 -1
- package/dist/harness/session/repo-utils.js +0 -39
- package/dist/harness/session/repo-utils.js.map +0 -1
package/dist/agent-loop.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Agent loop that works with AgentMessage throughout.
|
|
3
3
|
* Transforms to Message[] only at the LLM call boundary.
|
|
4
4
|
*/
|
|
5
|
-
import { EventStream } from "@draht/ai";
|
|
6
|
-
import type { AgentContext, AgentEvent, AgentLoopConfig, AgentMessage, StreamFn } from "./types.ts";
|
|
5
|
+
import { type AssistantMessage, EventStream } from "@draht/ai";
|
|
6
|
+
import type { AgentContext, AgentEvent, AgentLoopConfig, AgentMessage, AgentTool, AgentToolCall, AgentToolCallOutcome, AgentToolResult, StreamFn } from "./types.ts";
|
|
7
7
|
export type AgentEventSink = (event: AgentEvent) => Promise<void> | void;
|
|
8
8
|
/**
|
|
9
9
|
* Start an agent loop with a new prompt message.
|
|
@@ -21,4 +21,29 @@ export declare function agentLoop(prompts: AgentMessage[], context: AgentContext
|
|
|
21
21
|
export declare function agentLoopContinue(context: AgentContext, config: AgentLoopConfig, signal: AbortSignal | undefined, streamFn: StreamFn): EventStream<AgentEvent, AgentMessage[]>;
|
|
22
22
|
export declare function runAgentLoop(prompts: AgentMessage[], context: AgentContext, config: AgentLoopConfig, emit: AgentEventSink, signal: AbortSignal | undefined, streamFn: StreamFn): Promise<AgentMessage[]>;
|
|
23
23
|
export declare function runAgentLoopContinue(context: AgentContext, config: AgentLoopConfig, emit: AgentEventSink, signal: AbortSignal | undefined, streamFn: StreamFn): Promise<AgentMessage[]>;
|
|
24
|
+
/** The `beforeToolCall` and `afterToolCall` hooks of {@link AgentLoopConfig}. */
|
|
25
|
+
export type ToolCallHooks = Pick<AgentLoopConfig, "beforeToolCall" | "afterToolCall">;
|
|
26
|
+
type ToolUpdateSink = (partialResult: AgentToolResult<any>) => Promise<void> | void;
|
|
27
|
+
/** Options for {@link runToolCall}. */
|
|
28
|
+
export interface RunToolCallOptions extends ToolCallHooks {
|
|
29
|
+
/** Tools the call resolves against. */
|
|
30
|
+
tools: readonly AgentTool<any>[];
|
|
31
|
+
/** Passed to the hooks as the message that issued the call. */
|
|
32
|
+
assistantMessage: AssistantMessage;
|
|
33
|
+
/** Passed to the hooks as the current agent context. */
|
|
34
|
+
context: AgentContext;
|
|
35
|
+
signal?: AbortSignal;
|
|
36
|
+
onUpdate?: ToolUpdateSink;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Run one tool call through the same steps as a model-issued call: argument preparation, schema
|
|
40
|
+
* validation, `beforeToolCall`, execution, and `afterToolCall`. Emits no events and adds no
|
|
41
|
+
* messages. Tools that call other tools use this so the hooks (for example permission checks)
|
|
42
|
+
* apply to those calls too.
|
|
43
|
+
*
|
|
44
|
+
* Never rejects for tool failures: unknown tools, validation errors, blocked calls, and thrown
|
|
45
|
+
* errors come back as `isError: true`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function runToolCall(toolCall: AgentToolCall, options: RunToolCallOptions): Promise<AgentToolCallOutcome>;
|
|
48
|
+
export {};
|
|
24
49
|
//# sourceMappingURL=agent-loop.d.ts.map
|
package/dist/agent-loop.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-loop.d.ts","sourceRoot":"","sources":["../src/agent-loop.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"agent-loop.d.ts","sourceRoot":"","sources":["../src/agent-loop.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,KAAK,gBAAgB,EACrB,WAAW,EASX,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EACX,YAAY,EACZ,UAAU,EACV,eAAe,EACf,YAAY,EACZ,SAAS,EACT,aAAa,EACb,oBAAoB,EACpB,eAAe,EAEf,QAAQ,EACR,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAEzE;;;GAGG;AACH,wBAAgB,SAAS,CACxB,OAAO,EAAE,YAAY,EAAE,EACvB,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,QAAQ,EAAE,QAAQ,GAChB,WAAW,CAAC,UAAU,EAAE,YAAY,EAAE,CAAC,CAiBzC;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAChC,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,QAAQ,EAAE,QAAQ,GAChB,WAAW,CAAC,UAAU,EAAE,YAAY,EAAE,CAAC,CAwBzC;AAED,wBAAsB,YAAY,CACjC,OAAO,EAAE,YAAY,EAAE,EACvB,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,eAAe,EACvB,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,QAAQ,EAAE,QAAQ,GAChB,OAAO,CAAC,YAAY,EAAE,CAAC,CAiBzB;AAED,wBAAsB,oBAAoB,CACzC,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,eAAe,EACvB,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,QAAQ,EAAE,QAAQ,GAChB,OAAO,CAAC,YAAY,EAAE,CAAC,CAiBzB;AAmhBD,iFAAiF;AACjF,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,eAAe,EAAE,gBAAgB,GAAG,eAAe,CAAC,CAAC;AAEtF,KAAK,cAAc,GAAG,CAAC,aAAa,EAAE,eAAe,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAwGpF,uCAAuC;AACvC,MAAM,WAAW,kBAAmB,SAAQ,aAAa;IACxD,uCAAuC;IACvC,KAAK,EAAE,SAAS,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;IACjC,+DAA+D;IAC/D,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,wDAAwD;IACxD,OAAO,EAAE,YAAY,CAAC;IACtB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC1B;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAAC,QAAQ,EAAE,aAAa,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAQrH"}
|
package/dist/agent-loop.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Agent loop that works with AgentMessage throughout.
|
|
3
3
|
* Transforms to Message[] only at the LLM call boundary.
|
|
4
4
|
*/
|
|
5
|
-
import { EventStream, validateToolArguments, } from "@draht/ai";
|
|
5
|
+
import { EventStream, getCurrentTools, getToolStateChanges, normalizeContext, toToolDeclaration, validateToolArguments, } from "@draht/ai";
|
|
6
6
|
import { getDefaultStreamFn } from "./stream-fn.js";
|
|
7
7
|
/**
|
|
8
8
|
* Start an agent loop with a new prompt message.
|
|
@@ -41,16 +41,17 @@ export function agentLoopContinue(context, config, signal, streamFn) {
|
|
|
41
41
|
return stream;
|
|
42
42
|
}
|
|
43
43
|
export async function runAgentLoop(prompts, context, config, emit, signal, streamFn) {
|
|
44
|
-
const
|
|
44
|
+
const initialMessages = declareToolChanges(context, prompts);
|
|
45
|
+
const newMessages = [...initialMessages];
|
|
45
46
|
const currentContext = {
|
|
46
47
|
...context,
|
|
47
|
-
messages: [...context.messages, ...
|
|
48
|
+
messages: [...context.messages, ...initialMessages],
|
|
48
49
|
};
|
|
49
50
|
await emit({ type: "agent_start" });
|
|
50
51
|
await emit({ type: "turn_start" });
|
|
51
|
-
for (const
|
|
52
|
-
await emit({ type: "message_start", message
|
|
53
|
-
await emit({ type: "message_end", message
|
|
52
|
+
for (const message of initialMessages) {
|
|
53
|
+
await emit({ type: "message_start", message });
|
|
54
|
+
await emit({ type: "message_end", message });
|
|
54
55
|
}
|
|
55
56
|
await runLoop(currentContext, newMessages, config, signal, emit, streamFn ?? getDefaultStreamFn());
|
|
56
57
|
return newMessages;
|
|
@@ -78,7 +79,8 @@ function createAgentStream() {
|
|
|
78
79
|
async function runLoop(initialContext, newMessages, initialConfig, signal, emit, streamFunction) {
|
|
79
80
|
let currentContext = initialContext;
|
|
80
81
|
let config = initialConfig;
|
|
81
|
-
let
|
|
82
|
+
let lastCompletedTurn;
|
|
83
|
+
let explicitContinuation = false;
|
|
82
84
|
// Check for steering messages at start (user may have typed while waiting)
|
|
83
85
|
let pendingMessages = (await config.getSteeringMessages?.()) || [];
|
|
84
86
|
// Outer loop: continues when queued follow-up messages arrive after agent would stop
|
|
@@ -86,26 +88,66 @@ async function runLoop(initialContext, newMessages, initialConfig, signal, emit,
|
|
|
86
88
|
let hasMoreToolCalls = true;
|
|
87
89
|
// Inner loop: process tool calls and steering messages
|
|
88
90
|
while (hasMoreToolCalls || pendingMessages.length > 0) {
|
|
89
|
-
|
|
91
|
+
let preparedMessages = [];
|
|
92
|
+
if (lastCompletedTurn) {
|
|
93
|
+
const nextTurnSnapshot = await config.prepareNextTurn?.(lastCompletedTurn);
|
|
94
|
+
if (nextTurnSnapshot) {
|
|
95
|
+
currentContext = nextTurnSnapshot.context ?? currentContext;
|
|
96
|
+
preparedMessages = nextTurnSnapshot.messages ?? [];
|
|
97
|
+
config = {
|
|
98
|
+
...config,
|
|
99
|
+
model: nextTurnSnapshot.model ?? config.model,
|
|
100
|
+
reasoning: nextTurnSnapshot.thinkingLevel === undefined
|
|
101
|
+
? config.reasoning
|
|
102
|
+
: nextTurnSnapshot.thinkingLevel === "off"
|
|
103
|
+
? undefined
|
|
104
|
+
: nextTurnSnapshot.thinkingLevel,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
// Preparation can be long-running (for example, compaction). Pick up steering
|
|
108
|
+
// queued while it ran. Only poll again if the earlier poll returned nothing;
|
|
109
|
+
// otherwise one-at-a-time mode would deliver two messages in this turn.
|
|
110
|
+
if (pendingMessages.length === 0) {
|
|
111
|
+
pendingMessages = (await config.getSteeringMessages?.()) || [];
|
|
112
|
+
}
|
|
90
113
|
await emit({ type: "turn_start" });
|
|
91
114
|
}
|
|
92
|
-
|
|
93
|
-
|
|
115
|
+
// Process prepared and queued messages before the next assistant response.
|
|
116
|
+
for (const message of declareToolChanges(currentContext, [...preparedMessages, ...pendingMessages])) {
|
|
117
|
+
await emit({ type: "message_start", message });
|
|
118
|
+
await emit({ type: "message_end", message });
|
|
119
|
+
currentContext.messages.push(message);
|
|
120
|
+
newMessages.push(message);
|
|
94
121
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
122
|
+
pendingMessages = [];
|
|
123
|
+
const requestUpdate = await config.prepareRequest?.({
|
|
124
|
+
context: currentContext,
|
|
125
|
+
model: config.model,
|
|
126
|
+
thinkingLevel: config.reasoning ?? "off",
|
|
127
|
+
}, signal);
|
|
128
|
+
if (requestUpdate) {
|
|
129
|
+
currentContext = requestUpdate.context ?? currentContext;
|
|
130
|
+
config = {
|
|
131
|
+
...config,
|
|
132
|
+
model: requestUpdate.model ?? config.model,
|
|
133
|
+
reasoning: requestUpdate.thinkingLevel === undefined
|
|
134
|
+
? config.reasoning
|
|
135
|
+
: requestUpdate.thinkingLevel === "off"
|
|
136
|
+
? undefined
|
|
137
|
+
: requestUpdate.thinkingLevel,
|
|
138
|
+
};
|
|
104
139
|
}
|
|
105
140
|
// Stream assistant response
|
|
106
141
|
const message = await streamAssistantResponse(currentContext, config, signal, emit, streamFunction);
|
|
107
142
|
newMessages.push(message);
|
|
108
143
|
if (message.stopReason === "error" || message.stopReason === "aborted") {
|
|
144
|
+
lastCompletedTurn = {
|
|
145
|
+
message,
|
|
146
|
+
toolResults: [],
|
|
147
|
+
context: currentContext,
|
|
148
|
+
newMessages,
|
|
149
|
+
};
|
|
150
|
+
await config.finishTurn?.(lastCompletedTurn, signal);
|
|
109
151
|
await emit({ type: "turn_end", message, toolResults: [] });
|
|
110
152
|
await emit({ type: "agent_end", messages: newMessages });
|
|
111
153
|
return;
|
|
@@ -128,49 +170,89 @@ async function runLoop(initialContext, newMessages, initialConfig, signal, emit,
|
|
|
128
170
|
newMessages.push(result);
|
|
129
171
|
}
|
|
130
172
|
}
|
|
131
|
-
|
|
132
|
-
const nextTurnContext = {
|
|
173
|
+
lastCompletedTurn = {
|
|
133
174
|
message,
|
|
134
175
|
toolResults,
|
|
135
176
|
context: currentContext,
|
|
136
177
|
newMessages,
|
|
137
178
|
};
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
config = {
|
|
142
|
-
...config,
|
|
143
|
-
model: nextTurnSnapshot.model ?? config.model,
|
|
144
|
-
reasoning: nextTurnSnapshot.thinkingLevel === undefined
|
|
145
|
-
? config.reasoning
|
|
146
|
-
: nextTurnSnapshot.thinkingLevel === "off"
|
|
147
|
-
? undefined
|
|
148
|
-
: nextTurnSnapshot.thinkingLevel,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
if (await config.shouldStopAfterTurn?.({
|
|
152
|
-
message,
|
|
153
|
-
toolResults,
|
|
154
|
-
context: currentContext,
|
|
155
|
-
newMessages,
|
|
156
|
-
})) {
|
|
179
|
+
const decision = await config.finishTurn?.(lastCompletedTurn, signal);
|
|
180
|
+
await emit({ type: "turn_end", message, toolResults });
|
|
181
|
+
if (decision?.action === "end") {
|
|
157
182
|
await emit({ type: "agent_end", messages: newMessages });
|
|
158
183
|
return;
|
|
159
184
|
}
|
|
185
|
+
explicitContinuation = decision?.action === "continue";
|
|
160
186
|
pendingMessages = (await config.getSteeringMessages?.()) || [];
|
|
187
|
+
if (hasMoreToolCalls || pendingMessages.length > 0) {
|
|
188
|
+
explicitContinuation = false;
|
|
189
|
+
}
|
|
161
190
|
}
|
|
162
191
|
// Agent would stop here. Check for follow-up messages.
|
|
163
192
|
const followUpMessages = (await config.getFollowUpMessages?.()) || [];
|
|
164
193
|
if (followUpMessages.length > 0) {
|
|
165
194
|
// Set as pending so inner loop processes them
|
|
195
|
+
explicitContinuation = false;
|
|
166
196
|
pendingMessages = followUpMessages;
|
|
167
197
|
continue;
|
|
168
198
|
}
|
|
199
|
+
// No natural request was selected, so fulfill the continuation decision with one context-only turn.
|
|
200
|
+
if (explicitContinuation) {
|
|
201
|
+
explicitContinuation = false;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
169
204
|
// No more messages, exit
|
|
170
205
|
break;
|
|
171
206
|
}
|
|
172
207
|
await emit({ type: "agent_end", messages: newMessages });
|
|
173
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* Declare tool loadout changes to the model.
|
|
211
|
+
*
|
|
212
|
+
* `context.tools` is what the runtime can execute; the transcript's system messages declare
|
|
213
|
+
* what the model may call. Before each request the difference becomes `toolsAdded` and
|
|
214
|
+
* `toolsRemoved` on a system message. When a pending system message exists, its tool fields
|
|
215
|
+
* are treated as intent and replaced with the delta between the committed transcript and
|
|
216
|
+
* the executable set, so replay always yields exactly `context.tools`. Otherwise a new
|
|
217
|
+
* system message is inserted before the first non-system pending message.
|
|
218
|
+
*/
|
|
219
|
+
function declareToolChanges(context, pendingMessages) {
|
|
220
|
+
let systemIndex = -1;
|
|
221
|
+
for (let i = pendingMessages.length - 1; i >= 0; i--) {
|
|
222
|
+
if (pendingMessages[i].role === "system") {
|
|
223
|
+
systemIndex = i;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
const pending = pendingMessages[systemIndex];
|
|
228
|
+
const baseline = pending
|
|
229
|
+
? pendingMessages.map((message, index) => index === systemIndex ? withToolChanges(pending, NO_CHANGES) : message)
|
|
230
|
+
: pendingMessages;
|
|
231
|
+
const changes = getToolStateChanges(getCurrentTools([...context.messages, ...baseline]), (context.tools ?? []).map(toToolDeclaration));
|
|
232
|
+
const unchanged = changes.toolsAdded.length === 0 && changes.toolsRemoved.length === 0;
|
|
233
|
+
if (pending) {
|
|
234
|
+
// Keep the caller's message object when it already declares no tool changes.
|
|
235
|
+
if (unchanged && !pending.toolsAdded?.length && !pending.toolsRemoved?.length)
|
|
236
|
+
return pendingMessages;
|
|
237
|
+
return baseline.map((message, index) => (index === systemIndex ? withToolChanges(pending, changes) : message));
|
|
238
|
+
}
|
|
239
|
+
if (unchanged)
|
|
240
|
+
return pendingMessages;
|
|
241
|
+
const update = withToolChanges({ role: "system", content: "", timestamp: Date.now() }, changes);
|
|
242
|
+
const insertIndex = pendingMessages.findIndex((message) => message.role !== "system");
|
|
243
|
+
const index = insertIndex === -1 ? pendingMessages.length : insertIndex;
|
|
244
|
+
return [...pendingMessages.slice(0, index), update, ...pendingMessages.slice(index)];
|
|
245
|
+
}
|
|
246
|
+
const NO_CHANGES = { toolsAdded: [], toolsRemoved: [] };
|
|
247
|
+
/** Copy a system message with its tool fields replaced by `changes`; empty lists omit the field. */
|
|
248
|
+
function withToolChanges(message, { toolsAdded, toolsRemoved }) {
|
|
249
|
+
const { toolsAdded: _added, toolsRemoved: _removed, ...rest } = message;
|
|
250
|
+
return {
|
|
251
|
+
...rest,
|
|
252
|
+
...(toolsAdded.length > 0 ? { toolsAdded } : {}),
|
|
253
|
+
...(toolsRemoved.length > 0 ? { toolsRemoved } : {}),
|
|
254
|
+
};
|
|
255
|
+
}
|
|
174
256
|
/**
|
|
175
257
|
* Stream an assistant response from the LLM.
|
|
176
258
|
* This is where AgentMessage[] gets transformed to Message[] for the LLM.
|
|
@@ -183,12 +265,7 @@ async function streamAssistantResponse(context, config, signal, emit, streamFunc
|
|
|
183
265
|
}
|
|
184
266
|
// Convert to LLM-compatible messages (AgentMessage[] → Message[])
|
|
185
267
|
const llmMessages = await config.convertToLlm(messages);
|
|
186
|
-
|
|
187
|
-
const llmContext = {
|
|
188
|
-
systemPrompt: context.systemPrompt,
|
|
189
|
-
messages: llmMessages,
|
|
190
|
-
tools: context.tools,
|
|
191
|
-
};
|
|
268
|
+
const llmContext = normalizeContext({ messages: llmMessages });
|
|
192
269
|
// Resolve API key (important for expiring tokens)
|
|
193
270
|
const resolvedApiKey = (config.getApiKey ? await config.getApiKey(config.model.provider) : undefined) || config.apiKey;
|
|
194
271
|
const response = await streamFunction(config.model, llmContext, {
|
|
@@ -196,6 +273,8 @@ async function streamAssistantResponse(context, config, signal, emit, streamFunc
|
|
|
196
273
|
apiKey: resolvedApiKey,
|
|
197
274
|
signal,
|
|
198
275
|
});
|
|
276
|
+
// Record the requested level, whichever stream function answered.
|
|
277
|
+
const result = async () => Object.assign(await response.result(), { thinkingLevel: config.reasoning ?? "off" });
|
|
199
278
|
let partialMessage = null;
|
|
200
279
|
let addedPartial = false;
|
|
201
280
|
for await (const event of response) {
|
|
@@ -227,7 +306,7 @@ async function streamAssistantResponse(context, config, signal, emit, streamFunc
|
|
|
227
306
|
break;
|
|
228
307
|
case "done":
|
|
229
308
|
case "error": {
|
|
230
|
-
const finalMessage = await
|
|
309
|
+
const finalMessage = await result();
|
|
231
310
|
if (addedPartial) {
|
|
232
311
|
context.messages[context.messages.length - 1] = finalMessage;
|
|
233
312
|
}
|
|
@@ -242,7 +321,7 @@ async function streamAssistantResponse(context, config, signal, emit, streamFunc
|
|
|
242
321
|
}
|
|
243
322
|
}
|
|
244
323
|
}
|
|
245
|
-
const finalMessage = await
|
|
324
|
+
const finalMessage = await result();
|
|
246
325
|
if (addedPartial) {
|
|
247
326
|
context.messages[context.messages.length - 1] = finalMessage;
|
|
248
327
|
}
|
|
@@ -312,7 +391,7 @@ async function executeToolCallsSequential(currentContext, assistantMessage, tool
|
|
|
312
391
|
};
|
|
313
392
|
}
|
|
314
393
|
else {
|
|
315
|
-
const executed = await executePreparedToolCall(preparation, signal, emit);
|
|
394
|
+
const executed = await executePreparedToolCall(preparation, signal, emitToolExecutionUpdate(toolCall, emit));
|
|
316
395
|
finalized = await finalizeExecutedToolCall(currentContext, assistantMessage, preparation, executed, config, signal);
|
|
317
396
|
}
|
|
318
397
|
await emitToolExecutionEnd(finalized, emit);
|
|
@@ -353,7 +432,16 @@ async function executeToolCallsParallel(currentContext, assistantMessage, toolCa
|
|
|
353
432
|
continue;
|
|
354
433
|
}
|
|
355
434
|
finalizedCalls.push(async () => {
|
|
356
|
-
|
|
435
|
+
if (signal?.aborted) {
|
|
436
|
+
const finalized = {
|
|
437
|
+
toolCall,
|
|
438
|
+
result: createErrorToolResult("Operation aborted"),
|
|
439
|
+
isError: true,
|
|
440
|
+
};
|
|
441
|
+
await emitToolExecutionEnd(finalized, emit);
|
|
442
|
+
return finalized;
|
|
443
|
+
}
|
|
444
|
+
const executed = await executePreparedToolCall(preparation, signal, emitToolExecutionUpdate(toolCall, emit));
|
|
357
445
|
const finalized = await finalizeExecutedToolCall(currentContext, assistantMessage, preparation, executed, config, signal);
|
|
358
446
|
await emitToolExecutionEnd(finalized, emit);
|
|
359
447
|
return finalized;
|
|
@@ -390,8 +478,8 @@ function prepareToolCallArguments(tool, toolCall) {
|
|
|
390
478
|
arguments: preparedArguments,
|
|
391
479
|
};
|
|
392
480
|
}
|
|
393
|
-
async function prepareToolCall(currentContext, assistantMessage, toolCall, config, signal) {
|
|
394
|
-
const tool =
|
|
481
|
+
async function prepareToolCall(currentContext, assistantMessage, toolCall, config, signal, tools = currentContext.tools ?? []) {
|
|
482
|
+
const tool = tools.find((t) => t.name === toolCall.name);
|
|
395
483
|
if (!tool) {
|
|
396
484
|
return {
|
|
397
485
|
kind: "immediate",
|
|
@@ -417,9 +505,13 @@ async function prepareToolCall(currentContext, assistantMessage, toolCall, confi
|
|
|
417
505
|
};
|
|
418
506
|
}
|
|
419
507
|
if (beforeResult?.block) {
|
|
508
|
+
const result = createErrorToolResult(beforeResult.reason || "Tool execution was blocked");
|
|
509
|
+
if (beforeResult.terminate === true) {
|
|
510
|
+
result.terminate = true;
|
|
511
|
+
}
|
|
420
512
|
return {
|
|
421
513
|
kind: "immediate",
|
|
422
|
-
result
|
|
514
|
+
result,
|
|
423
515
|
isError: true,
|
|
424
516
|
};
|
|
425
517
|
}
|
|
@@ -446,24 +538,45 @@ async function prepareToolCall(currentContext, assistantMessage, toolCall, confi
|
|
|
446
538
|
};
|
|
447
539
|
}
|
|
448
540
|
}
|
|
449
|
-
|
|
541
|
+
function emitToolExecutionUpdate(toolCall, emit) {
|
|
542
|
+
return (partialResult) => emit({
|
|
543
|
+
type: "tool_execution_update",
|
|
544
|
+
toolCallId: toolCall.id,
|
|
545
|
+
toolName: toolCall.name,
|
|
546
|
+
args: toolCall.arguments,
|
|
547
|
+
partialResult,
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Run one tool call through the same steps as a model-issued call: argument preparation, schema
|
|
552
|
+
* validation, `beforeToolCall`, execution, and `afterToolCall`. Emits no events and adds no
|
|
553
|
+
* messages. Tools that call other tools use this so the hooks (for example permission checks)
|
|
554
|
+
* apply to those calls too.
|
|
555
|
+
*
|
|
556
|
+
* Never rejects for tool failures: unknown tools, validation errors, blocked calls, and thrown
|
|
557
|
+
* errors come back as `isError: true`.
|
|
558
|
+
*/
|
|
559
|
+
export async function runToolCall(toolCall, options) {
|
|
560
|
+
const { assistantMessage, context, signal } = options;
|
|
561
|
+
const preparation = await prepareToolCall(context, assistantMessage, toolCall, options, signal, options.tools);
|
|
562
|
+
if (preparation.kind === "immediate") {
|
|
563
|
+
return { toolCall, result: preparation.result, isError: preparation.isError };
|
|
564
|
+
}
|
|
565
|
+
const executed = await executePreparedToolCall(preparation, signal, options.onUpdate ?? (() => { }));
|
|
566
|
+
return finalizeExecutedToolCall(context, assistantMessage, preparation, executed, options, signal);
|
|
567
|
+
}
|
|
568
|
+
async function executePreparedToolCall(prepared, signal, onUpdate) {
|
|
450
569
|
const updateEvents = [];
|
|
451
570
|
let acceptingUpdates = true;
|
|
452
571
|
try {
|
|
453
572
|
const result = await prepared.tool.execute(prepared.toolCall.id, prepared.args, signal, (partialResult) => {
|
|
454
573
|
if (!acceptingUpdates)
|
|
455
574
|
return;
|
|
456
|
-
updateEvents.push(Promise.resolve(
|
|
457
|
-
type: "tool_execution_update",
|
|
458
|
-
toolCallId: prepared.toolCall.id,
|
|
459
|
-
toolName: prepared.toolCall.name,
|
|
460
|
-
args: prepared.toolCall.arguments,
|
|
461
|
-
partialResult,
|
|
462
|
-
})));
|
|
575
|
+
updateEvents.push(Promise.resolve(onUpdate(partialResult)));
|
|
463
576
|
});
|
|
464
577
|
acceptingUpdates = false;
|
|
465
578
|
await Promise.all(updateEvents);
|
|
466
|
-
return { result, isError:
|
|
579
|
+
return { result, isError: result.isError === true };
|
|
467
580
|
}
|
|
468
581
|
catch (error) {
|
|
469
582
|
acceptingUpdates = false;
|
|
@@ -491,6 +604,8 @@ async function finalizeExecutedToolCall(currentContext, assistantMessage, prepar
|
|
|
491
604
|
context: currentContext,
|
|
492
605
|
}, signal);
|
|
493
606
|
if (afterResult) {
|
|
607
|
+
// Structured content not replaced along with the content may no longer match it.
|
|
608
|
+
const structuredContent = afterResult.structuredContent ?? (afterResult.content ? undefined : result.structuredContent);
|
|
494
609
|
result = {
|
|
495
610
|
...result,
|
|
496
611
|
content: afterResult.content ?? result.content,
|
|
@@ -498,6 +613,10 @@ async function finalizeExecutedToolCall(currentContext, assistantMessage, prepar
|
|
|
498
613
|
usage: afterResult.usage ?? result.usage,
|
|
499
614
|
terminate: afterResult.terminate ?? result.terminate,
|
|
500
615
|
};
|
|
616
|
+
if (structuredContent === undefined)
|
|
617
|
+
delete result.structuredContent;
|
|
618
|
+
else
|
|
619
|
+
result.structuredContent = structuredContent;
|
|
501
620
|
isError = afterResult.isError ?? isError;
|
|
502
621
|
}
|
|
503
622
|
}
|
|
@@ -537,7 +656,6 @@ function createToolResultMessage(finalized) {
|
|
|
537
656
|
content: finalized.result.content ?? [],
|
|
538
657
|
details: finalized.result.details,
|
|
539
658
|
usage: finalized.result.usage,
|
|
540
|
-
...(finalized.result.addedToolNames?.length ? { addedToolNames: finalized.result.addedToolNames } : {}),
|
|
541
659
|
isError: finalized.isError,
|
|
542
660
|
timestamp: Date.now(),
|
|
543
661
|
};
|