@parcha/agentrun-serve 0.1.0-beta.30 → 0.1.0-beta.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +472 -0
- package/NOTICE +18 -0
- package/README.md +1042 -240
- package/dist/adapter-facts.d.ts +3 -0
- package/dist/adapter-facts.js +5 -0
- package/dist/adapters.d.ts +64 -140
- package/dist/adapters.js +153 -377
- package/dist/agents-store.d.ts +146 -0
- package/dist/agents-store.js +359 -0
- package/dist/agents.d.ts +12 -5
- package/dist/agents.js +40 -17
- package/dist/app.d.ts +2 -4
- package/dist/app.js +227 -97
- package/dist/approvals.d.ts +4 -0
- package/dist/approvals.js +7 -0
- package/dist/archil-routes.d.ts +45 -0
- package/dist/archil-routes.js +150 -0
- package/dist/archil-settings.d.ts +30 -0
- package/dist/archil-settings.js +34 -0
- package/dist/background.d.ts +2 -1
- package/dist/background.js +69 -29
- package/dist/bounds.d.ts +26 -0
- package/dist/bounds.js +137 -0
- package/dist/box-egress-vm.d.ts +126 -0
- package/dist/box-egress-vm.js +364 -0
- package/dist/box-egress.d.ts +19 -8
- package/dist/box-egress.js +27 -15
- package/dist/box-paths.d.ts +59 -0
- package/dist/box-paths.js +92 -0
- package/dist/box-relay-vm.d.ts +4 -0
- package/dist/box-relay-vm.js +103 -55
- package/dist/box-relay.d.ts +2 -0
- package/dist/box-relay.js +2 -2
- package/dist/boxes.d.ts +20 -3
- package/dist/boxes.js +67 -14
- package/dist/browser-commands.d.ts +43 -0
- package/dist/browser-commands.js +154 -0
- package/dist/browser-cost.d.ts +30 -3
- package/dist/browser-cost.js +276 -21
- package/dist/browser-live.d.ts +124 -0
- package/dist/browser-live.js +324 -0
- package/dist/browser-person.d.ts +168 -0
- package/dist/browser-person.js +769 -0
- package/dist/budget.d.ts +80 -0
- package/dist/budget.js +211 -0
- package/dist/cap.d.ts +274 -63
- package/dist/cap.js +599 -188
- package/dist/cli.js +226 -16
- package/dist/coding-tools.d.ts +13 -1
- package/dist/coding-tools.js +107 -5
- package/dist/computer-adb.d.ts +12 -0
- package/dist/computer-adb.js +14 -0
- package/dist/computer-commands.d.ts +103 -0
- package/dist/computer-commands.js +256 -0
- package/dist/computer-keys.d.ts +68 -0
- package/dist/computer-keys.js +148 -0
- package/dist/computer-routes.d.ts +38 -0
- package/dist/computer-routes.js +56 -0
- package/dist/computer-setting.d.ts +37 -0
- package/dist/computer-setting.js +47 -0
- package/dist/computer-view.d.ts +38 -0
- package/dist/computer-view.js +14 -0
- package/dist/computers.d.ts +137 -0
- package/dist/computers.js +197 -0
- package/dist/console/THIRD-PARTY-NOTICES.txt +25 -0
- package/dist/console/assets/index-35-7aeIZ.js +519 -0
- package/dist/console/assets/index-Cejbov-Y.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.d.ts +2 -0
- package/dist/console-links.js +6 -0
- package/dist/decision-cap.d.ts +63 -0
- package/dist/decision-cap.js +163 -0
- package/dist/decision-rows.d.ts +5 -2
- package/dist/decision-rows.js +8 -6
- package/dist/decisions.d.ts +31 -4
- package/dist/decisions.js +66 -8
- package/dist/disk.d.ts +33 -0
- package/dist/disk.js +85 -0
- package/dist/door-line.d.ts +23 -0
- package/dist/door-line.js +83 -0
- package/dist/egress-proxy.d.ts +45 -0
- package/dist/egress-proxy.js +416 -0
- package/dist/egress-table.d.ts +24 -0
- package/dist/egress-table.js +165 -0
- package/dist/errors.d.ts +15 -0
- package/dist/errors.js +22 -2
- package/dist/exa-keyless.js +1 -1
- package/dist/explain.d.ts +22 -0
- package/dist/explain.js +207 -0
- package/dist/faux-computers.d.ts +35 -0
- package/dist/faux-computers.js +126 -0
- package/dist/file-types.d.ts +4 -0
- package/dist/file-types.js +11 -0
- package/dist/files.d.ts +3 -32
- package/dist/files.js +9 -117
- package/dist/github-connection.d.ts +207 -0
- package/dist/github-connection.js +595 -0
- package/dist/github.d.ts +64 -0
- package/dist/github.js +119 -0
- package/dist/grade.d.ts +14 -44
- package/dist/grade.js +55 -233
- package/dist/graph-served.d.ts +23 -2
- package/dist/graph-served.js +44 -3
- package/dist/graph-view.d.ts +7 -3
- package/dist/graph-view.js +26 -15
- package/dist/handed-values.d.ts +23 -0
- package/dist/handed-values.js +36 -0
- package/dist/harness-app.d.ts +33 -4
- package/dist/harness-app.js +539 -85
- package/dist/harness-install.d.ts +120 -0
- package/dist/harness-install.js +359 -0
- package/dist/harness-opencode/adapter.js +42 -8
- package/dist/harness-opencode/facts.d.ts +2 -0
- package/dist/harness-opencode/facts.js +28 -0
- package/dist/harness-opencode/harness.d.ts +4 -0
- package/dist/harness-opencode/harness.js +38 -5
- package/dist/harness-opencode/host/policy.js +11 -3
- package/dist/harness-opencode/transcript.d.ts +25 -0
- package/dist/harness-opencode/transcript.js +81 -0
- package/dist/harness-table.d.ts +75 -0
- package/dist/harness-table.js +145 -0
- package/dist/harness.d.ts +7 -28
- package/dist/harness.js +15 -41
- package/dist/heard.d.ts +12 -0
- package/dist/heard.js +45 -0
- package/dist/helper-env.d.ts +4 -0
- package/dist/helper-env.js +14 -0
- package/dist/home-path.d.ts +0 -4
- package/dist/home-path.js +3 -17
- package/dist/host-check.d.ts +13 -0
- package/dist/host-check.js +35 -0
- package/dist/host-tools.d.ts +51 -8
- package/dist/host-tools.js +108 -117
- package/dist/host.d.ts +12 -6
- package/dist/host.js +30 -24
- package/dist/hosted-search.d.ts +3 -0
- package/dist/hosted-search.js +5 -3
- package/dist/import-proxy.d.ts +42 -0
- package/dist/import-proxy.js +105 -0
- package/dist/import-summary.js +4 -8
- package/dist/import-worker.d.ts +2 -3
- package/dist/import-worker.js +18 -16
- package/dist/import.d.ts +37 -17
- package/dist/import.js +208 -222
- package/dist/key-meta.d.ts +26 -0
- package/dist/key-meta.js +30 -0
- package/dist/key-refusal.d.ts +4 -1
- package/dist/key-refusal.js +20 -7
- package/dist/key-words.d.ts +37 -0
- package/dist/key-words.js +40 -0
- package/dist/learn/check.d.ts +3 -1
- package/dist/learn/check.js +2 -2
- package/dist/learn/commit.d.ts +86 -0
- package/dist/learn/commit.js +182 -0
- package/dist/learn/folder.d.ts +296 -0
- package/dist/learn/folder.js +796 -0
- package/dist/learn/grade.d.ts +25 -9
- package/dist/learn/grade.js +98 -50
- package/dist/learn/index.d.ts +2 -2
- package/dist/learn/index.js +2 -2
- package/dist/learn/learning.sh +366 -0
- package/dist/learn/reflect.d.ts +12 -5
- package/dist/learn/reflect.js +72 -41
- package/dist/learn/secrets.d.ts +15 -7
- package/dist/learn/secrets.js +66 -16
- package/dist/learn/seed-check.d.ts +74 -0
- package/dist/learn/seed-check.js +103 -0
- package/dist/learn/skills.d.ts +7 -1
- package/dist/learn/skills.js +21 -4
- package/dist/learned-workflow.d.ts +12 -2
- package/dist/learned-workflow.js +9 -5
- package/dist/learning-routes.d.ts +107 -31
- package/dist/learning-routes.js +358 -403
- package/dist/learning-run.d.ts +61 -54
- package/dist/learning-run.js +183 -205
- package/dist/learning-words.d.ts +10 -8
- package/dist/learning-words.js +29 -13
- package/dist/learning.d.ts +186 -113
- package/dist/learning.js +345 -381
- package/dist/live/stream.d.ts +30 -0
- package/dist/live/stream.js +175 -0
- package/dist/live/translate.d.ts +52 -0
- package/dist/live/translate.js +276 -0
- package/dist/llm.js +3 -0
- package/dist/llms.txt +1 -0
- package/dist/local-models.d.ts +23 -0
- package/dist/local-models.js +35 -0
- package/dist/mcp-gateway.d.ts +129 -0
- package/dist/mcp-gateway.js +508 -0
- package/dist/mcp-meta.d.ts +20 -0
- package/dist/mcp-meta.js +50 -0
- package/dist/mcp-oauth.d.ts +172 -0
- package/dist/mcp-oauth.js +403 -0
- package/dist/mcp-private-hosts.d.ts +48 -0
- package/dist/mcp-private-hosts.js +141 -0
- package/dist/mcp-probe.d.ts +101 -0
- package/dist/mcp-probe.js +359 -0
- package/dist/mcp-secret-writes.d.ts +23 -0
- package/dist/mcp-secret-writes.js +60 -0
- package/dist/mcp-servers-store.d.ts +251 -0
- package/dist/mcp-servers-store.js +447 -0
- package/dist/mcp-servers.d.ts +185 -34
- package/dist/mcp-servers.js +304 -298
- package/dist/mcp-store.d.ts +103 -0
- package/dist/mcp-store.js +123 -0
- package/dist/mcp.js +22 -21
- package/dist/model.d.ts +77 -59
- package/dist/model.js +237 -98
- package/dist/monid.d.ts +8 -6
- package/dist/monid.js +39 -25
- package/dist/openapi.d.ts +22 -1
- package/dist/openapi.js +965 -111
- package/dist/owner.d.ts +46 -10
- package/dist/owner.js +123 -43
- package/dist/page.d.ts +12 -0
- package/dist/page.js +28 -2
- package/dist/paid-calls.d.ts +71 -2
- package/dist/paid-calls.js +125 -5
- package/dist/pdf-pages.d.ts +16 -14
- package/dist/pdf-pages.js +88 -58
- package/dist/place.d.ts +18 -15
- package/dist/place.js +36 -18
- package/dist/port-models.d.ts +53 -0
- package/dist/port-models.js +93 -0
- package/dist/print.d.ts +7 -0
- package/dist/print.js +13 -0
- package/dist/propose.d.ts +9 -8
- package/dist/propose.js +82 -49
- package/dist/provider.d.ts +85 -0
- package/dist/provider.js +178 -0
- package/dist/push-handler.d.ts +52 -0
- package/dist/push-handler.js +165 -0
- package/dist/refusal-words.d.ts +23 -0
- package/dist/refusal-words.js +25 -0
- package/dist/request-start.d.ts +6 -1
- package/dist/request-start.js +41 -10
- package/dist/result.d.ts +13 -2
- package/dist/result.js +4 -5
- package/dist/run-box.d.ts +22 -3
- package/dist/run-box.js +91 -20
- package/dist/run-computer.d.ts +24 -0
- package/dist/run-computer.js +15 -0
- package/dist/run-cut.d.ts +33 -0
- package/dist/run-cut.js +42 -0
- package/dist/run-db.d.ts +64 -0
- package/dist/run-db.js +155 -0
- package/dist/run-files.d.ts +31 -0
- package/dist/run-files.js +125 -0
- package/dist/run-holder.d.ts +52 -0
- package/dist/run-holder.js +139 -0
- package/dist/run-launch.d.ts +72 -0
- package/dist/run-launch.js +108 -0
- package/dist/run-learning-served.d.ts +43 -0
- package/dist/run-learning-served.js +16 -0
- package/dist/run-manifest.d.ts +7 -6
- package/dist/run-manifest.js +20 -10
- package/dist/run-reads-over-store.d.ts +102 -0
- package/dist/run-reads-over-store.js +151 -0
- package/dist/run-timeline-served.d.ts +13 -0
- package/dist/run-timeline-served.js +69 -0
- package/dist/run-view.d.ts +436 -0
- package/dist/run-view.js +620 -0
- package/dist/runnable.d.ts +36 -4
- package/dist/runnable.js +157 -31
- package/dist/runner/adapter-loop.d.ts +237 -0
- package/dist/runner/adapter-loop.js +1625 -0
- package/dist/runner/adapter-run-spec.d.ts +216 -0
- package/dist/runner/adapter-run-spec.js +537 -0
- package/dist/runner/adapters/index.d.ts +37 -0
- package/dist/runner/adapters/index.js +66 -0
- package/dist/runner/adapters/pi.d.ts +99 -0
- package/dist/runner/adapters/pi.js +260 -0
- package/dist/runner/beside.d.ts +12 -0
- package/dist/runner/beside.js +30 -0
- package/dist/runner/claim-secrets.d.ts +30 -0
- package/dist/runner/claim-secrets.js +90 -0
- package/dist/runner/cli-run-spec.d.ts +17 -0
- package/dist/runner/cli-run-spec.js +371 -0
- package/dist/runner/commands.d.ts +23 -0
- package/dist/runner/commands.js +67 -0
- package/dist/runner/computer-journal.d.ts +38 -0
- package/dist/runner/computer-journal.js +120 -0
- package/dist/runner/conformance/child.d.ts +1 -0
- package/dist/runner/conformance/child.js +78 -0
- package/dist/runner/conformance/harness.d.ts +89 -0
- package/dist/runner/conformance/harness.js +928 -0
- package/dist/runner/conformance/subject.d.ts +83 -0
- package/dist/runner/conformance/subject.js +1 -0
- package/dist/runner/dispatch.d.ts +30 -0
- package/dist/runner/dispatch.js +99 -0
- package/dist/runner/end-of-run.d.ts +32 -0
- package/dist/runner/end-of-run.js +56 -0
- package/dist/runner/github-app.d.ts +16 -0
- package/dist/runner/github-app.js +37 -0
- package/dist/runner/hand-back.d.ts +43 -0
- package/dist/runner/hand-back.js +69 -0
- package/dist/runner/harness-loops.d.ts +10 -0
- package/dist/runner/harness-loops.js +70 -0
- package/dist/runner/journal-kinds.d.ts +211 -0
- package/dist/runner/journal-kinds.js +116 -0
- package/dist/runner/journal-reader.d.ts +44 -0
- package/dist/runner/journal-reader.js +127 -0
- package/dist/runner/learning-ask.d.ts +37 -0
- package/dist/runner/learning-ask.js +99 -0
- package/dist/runner/learning-dispatch.d.ts +38 -0
- package/dist/runner/learning-dispatch.js +75 -0
- package/dist/runner/learning-end.d.ts +31 -0
- package/dist/runner/learning-end.js +136 -0
- package/dist/runner/learning-factory.d.ts +13 -0
- package/dist/runner/learning-factory.js +37 -0
- package/dist/runner/learning-loop.d.ts +150 -0
- package/dist/runner/learning-loop.js +246 -0
- package/dist/runner/learning-seed.d.ts +30 -0
- package/dist/runner/learning-seed.js +41 -0
- package/dist/runner/live-ticker.d.ts +18 -0
- package/dist/runner/live-ticker.js +88 -0
- package/dist/runner/loop-contract.d.ts +153 -0
- package/dist/runner/loop-contract.js +26 -0
- package/dist/runner/loop.d.ts +79 -0
- package/dist/runner/loop.js +185 -0
- package/dist/runner/main.d.ts +89 -0
- package/dist/runner/main.js +282 -0
- package/dist/runner/mcp-claim.d.ts +67 -0
- package/dist/runner/mcp-claim.js +403 -0
- package/dist/runner/mcp-github.d.ts +53 -0
- package/dist/runner/mcp-github.js +91 -0
- package/dist/runner/mcp-run.d.ts +116 -0
- package/dist/runner/mcp-run.js +152 -0
- package/dist/runner/metrics.d.ts +18 -0
- package/dist/runner/metrics.js +24 -0
- package/dist/runner/model-route.d.ts +111 -0
- package/dist/runner/model-route.js +183 -0
- package/dist/runner/pi-stop.d.ts +6 -0
- package/dist/runner/pi-stop.js +8 -0
- package/dist/runner/redact.d.ts +26 -0
- package/dist/runner/redact.js +51 -0
- package/dist/runner/reflect-hook.d.ts +81 -0
- package/dist/runner/reflect-hook.js +111 -0
- package/dist/runner/runner.d.ts +114 -0
- package/dist/runner/runner.js +672 -0
- package/dist/runner/sessions.d.ts +9 -0
- package/dist/runner/sessions.js +145 -0
- package/dist/runner/side-effects.d.ts +19 -0
- package/dist/runner/side-effects.js +20 -0
- package/dist/runner/spec-holds.d.ts +41 -0
- package/dist/runner/spec-holds.js +58 -0
- package/dist/runner/store-port.d.ts +9 -0
- package/dist/runner/store-port.js +7 -0
- package/dist/runner/store-secrets.d.ts +11 -0
- package/dist/runner/store-secrets.js +105 -0
- package/dist/runner/workflow-adapters.d.ts +1 -0
- package/dist/runner/workflow-adapters.js +4 -0
- package/dist/runner/workflow-host.d.ts +88 -0
- package/dist/runner/workflow-host.js +66 -0
- package/dist/runner/workflow-loop.d.ts +126 -0
- package/dist/runner/workflow-loop.js +372 -0
- package/dist/runner/workflow-spec.d.ts +157 -0
- package/dist/runner/workflow-spec.js +801 -0
- package/dist/runs-over-store.d.ts +203 -0
- package/dist/runs-over-store.js +396 -0
- package/dist/runs.d.ts +360 -222
- package/dist/runs.js +1619 -536
- package/dist/seal-key.d.ts +30 -0
- package/dist/seal-key.js +141 -0
- package/dist/sealed-settings-store.d.ts +71 -0
- package/dist/sealed-settings-store.js +205 -0
- package/dist/sealed-settings.d.ts +60 -0
- package/dist/sealed-settings.js +178 -0
- package/dist/secret-writes.d.ts +147 -0
- package/dist/secret-writes.js +144 -0
- package/dist/secrets.d.ts +22 -0
- package/dist/secrets.js +37 -4
- package/dist/served-only.d.ts +5 -0
- package/dist/served-only.js +12 -0
- package/dist/server-approvers.d.ts +8 -0
- package/dist/server-approvers.js +12 -0
- package/dist/server-fs.d.ts +40 -0
- package/dist/server-fs.js +138 -0
- package/dist/server-keys.d.ts +18 -0
- package/dist/server-keys.js +31 -0
- package/dist/server-lock.js +1 -1
- package/dist/server-secrets-store.d.ts +18 -0
- package/dist/server-secrets-store.js +54 -0
- package/dist/server-secrets.d.ts +23 -0
- package/dist/server-secrets.js +73 -0
- package/dist/server.d.ts +152 -74
- package/dist/server.js +1757 -588
- package/dist/sessions.d.ts +3 -1
- package/dist/sessions.js +8 -4
- package/dist/sign-ins-secrets.d.ts +35 -0
- package/dist/sign-ins-secrets.js +109 -0
- package/dist/sign-ins-store.d.ts +200 -0
- package/dist/sign-ins-store.js +373 -0
- package/dist/sign-ins.d.ts +43 -7
- package/dist/sign-ins.js +94 -18
- package/dist/skills.d.ts +6 -5
- package/dist/skills.js +18 -14
- package/dist/standard-webhooks.d.ts +30 -0
- package/dist/standard-webhooks.js +72 -0
- package/dist/stats.d.ts +5 -7
- package/dist/stats.js +8 -24
- package/dist/stop-signals.d.ts +22 -0
- package/dist/stop-signals.js +38 -0
- package/dist/store/agent-body.d.ts +103 -0
- package/dist/store/agent-body.js +126 -0
- package/dist/store/dialect.d.ts +59 -0
- package/dist/store/dialect.js +32 -0
- package/dist/store/fence.d.ts +22 -0
- package/dist/store/fence.js +15 -0
- package/dist/store/index.d.ts +17 -0
- package/dist/store/index.js +17 -0
- package/dist/store/journal/storage.d.ts +137 -0
- package/dist/store/journal/storage.js +1021 -0
- package/dist/store/open.d.ts +34 -0
- package/dist/store/open.js +30 -0
- package/dist/store/postgres/connection.d.ts +74 -0
- package/dist/store/postgres/connection.js +532 -0
- package/dist/store/postgres/dialect.d.ts +9 -0
- package/dist/store/postgres/dialect.js +39 -0
- package/dist/store/postgres/migrate.d.ts +21 -0
- package/dist/store/postgres/migrate.js +106 -0
- package/dist/store/postgres/migrations/0001_initial.sql +418 -0
- package/dist/store/postgres/migrations/0002_external_agents.sql +14 -0
- package/dist/store/postgres/store.d.ts +37 -0
- package/dist/store/postgres/store.js +48 -0
- package/dist/store/prompts.d.ts +11 -0
- package/dist/store/prompts.js +112 -0
- package/dist/store/schema.d.ts +26 -0
- package/dist/store/schema.js +522 -0
- package/dist/store/seal.d.ts +48 -0
- package/dist/store/seal.js +69 -0
- package/dist/store/sqlite/connection.d.ts +105 -0
- package/dist/store/sqlite/connection.js +309 -0
- package/dist/store/sqlite/memory.d.ts +2 -0
- package/dist/store/sqlite/memory.js +4 -0
- package/dist/store/sqlite/run-launch.d.ts +8 -0
- package/dist/store/sqlite/run-launch.js +20 -0
- package/dist/store/sqlite/run-patch.d.ts +54 -0
- package/dist/store/sqlite/run-patch.js +114 -0
- package/dist/store/sqlite/store.d.ts +33 -0
- package/dist/store/sqlite/store.js +1337 -0
- package/dist/store/sqlite/worker.d.ts +78 -0
- package/dist/store/sqlite/worker.js +242 -0
- package/dist/store/store.d.ts +1253 -0
- package/dist/store/store.js +190 -0
- package/dist/store-reads/analytics.d.ts +55 -0
- package/dist/store-reads/analytics.js +135 -0
- package/dist/store-reads/cap.d.ts +17 -0
- package/dist/store-reads/cap.js +17 -0
- package/dist/store-reads/decisions.d.ts +5 -0
- package/dist/store-reads/decisions.js +31 -0
- package/dist/store-reads/import-summary.d.ts +6 -0
- package/dist/store-reads/import-summary.js +14 -0
- package/dist/store-reads/journal.d.ts +30 -0
- package/dist/store-reads/journal.js +120 -0
- package/dist/store-reads/learning.d.ts +93 -0
- package/dist/store-reads/learning.js +202 -0
- package/dist/store-reads/runs.d.ts +42 -0
- package/dist/store-reads/runs.js +84 -0
- package/dist/store-reads/stats.d.ts +30 -0
- package/dist/store-reads/stats.js +59 -0
- package/dist/store-reads/workflow.d.ts +7 -0
- package/dist/store-reads/workflow.js +14 -0
- package/dist/store-view.d.ts +37 -0
- package/dist/store-view.js +305 -0
- package/dist/template-eval.d.ts +239 -0
- package/dist/template-eval.js +1020 -0
- package/dist/template-github-permissions.d.ts +18 -0
- package/dist/template-github-permissions.js +32 -0
- package/dist/templates.d.ts +199 -0
- package/dist/templates.js +637 -0
- package/dist/tool-blurbs.d.ts +4 -0
- package/dist/tool-blurbs.js +27 -0
- package/dist/tool-gate.d.ts +183 -37
- package/dist/tool-gate.js +450 -99
- package/dist/tool-keys-store.d.ts +110 -0
- package/dist/tool-keys-store.js +291 -0
- package/dist/tool-keys.d.ts +27 -13
- package/dist/tool-keys.js +24 -10
- package/dist/tool-plane.d.ts +115 -25
- package/dist/tool-plane.js +251 -74
- package/dist/tool-settings-store.d.ts +30 -0
- package/dist/tool-settings-store.js +53 -0
- package/dist/tools.d.ts +95 -24
- package/dist/tools.js +344 -65
- package/dist/trigger-accept.d.ts +36 -0
- package/dist/trigger-accept.js +152 -0
- package/dist/trigger-adapter.d.ts +143 -0
- package/dist/trigger-adapter.js +31 -0
- package/dist/trigger-adapters.d.ts +2 -0
- package/dist/trigger-adapters.js +4 -0
- package/dist/trigger-github.d.ts +2 -0
- package/dist/trigger-github.js +85 -0
- package/dist/trigger-schedule.d.ts +6 -0
- package/dist/trigger-schedule.js +115 -0
- package/dist/trigger-secrets-shown.d.ts +66 -0
- package/dist/trigger-secrets-shown.js +77 -0
- package/dist/trigger-signatures.d.ts +58 -0
- package/dist/trigger-signatures.js +79 -0
- package/dist/trigger-targets.d.ts +46 -0
- package/dist/trigger-targets.js +95 -0
- package/dist/trigger-webhook.d.ts +2 -0
- package/dist/trigger-webhook.js +92 -0
- package/dist/triggers.d.ts +282 -237
- package/dist/triggers.js +720 -608
- package/dist/turn-end.d.ts +3 -0
- package/dist/turn-end.js +3 -0
- package/dist/uploads.d.ts +10 -8
- package/dist/uploads.js +45 -45
- package/dist/usage.d.ts +33 -3
- package/dist/usage.js +38 -4
- package/dist/validate.d.ts +6 -0
- package/dist/validate.js +42 -12
- package/dist/{fetch-page.d.ts → web-fetch-direct.d.ts} +2 -4
- package/dist/{fetch-page.js → web-fetch-direct.js} +2 -4
- package/dist/web-fetch.d.ts +17 -9
- package/dist/web-fetch.js +56 -21
- package/dist/web-search.d.ts +1 -1
- package/dist/web-search.js +1 -1
- package/dist/webhooks.d.ts +33 -23
- package/dist/webhooks.js +69 -56
- package/dist/wires.d.ts +11 -0
- package/dist/wires.js +7 -0
- package/dist/workspace/archil-claim.d.ts +57 -0
- package/dist/workspace/archil-claim.js +154 -0
- package/dist/workspace/archil-disk.d.ts +104 -0
- package/dist/workspace/archil-disk.js +254 -0
- package/dist/workspace/archil-exec.d.ts +59 -0
- package/dist/workspace/archil-exec.js +218 -0
- package/dist/workspace/archil-key.d.ts +17 -0
- package/dist/workspace/archil-key.js +30 -0
- package/dist/workspace/archil-mount-credential.d.ts +58 -0
- package/dist/workspace/archil-mount-credential.js +165 -0
- package/dist/workspace/archil.d.ts +59 -0
- package/dist/workspace/archil.js +676 -0
- package/dist/workspace/attach.d.ts +48 -0
- package/dist/workspace/attach.js +439 -0
- package/dist/workspace/computer-deps.d.ts +58 -0
- package/dist/workspace/computer-deps.js +113 -0
- package/dist/workspace/computer-for-claim.d.ts +115 -0
- package/dist/workspace/computer-for-claim.js +198 -0
- package/dist/workspace/computer-hold.d.ts +145 -0
- package/dist/workspace/computer-hold.js +258 -0
- package/dist/workspace/computer-ledger.d.ts +22 -0
- package/dist/workspace/computer-ledger.js +19 -0
- package/dist/workspace/computer-ports.d.ts +13 -0
- package/dist/workspace/computer-ports.js +108 -0
- package/dist/workspace/computer-providers.d.ts +12 -0
- package/dist/workspace/computer-providers.js +17 -0
- package/dist/workspace/computer-serves.d.ts +12 -0
- package/dist/workspace/computer-serves.js +15 -0
- package/dist/workspace/executors.d.ts +38 -0
- package/dist/workspace/executors.js +150 -0
- package/dist/workspace/glob.d.ts +2 -0
- package/dist/workspace/glob.js +25 -0
- package/dist/workspace/grep-worker.d.ts +11 -0
- package/dist/workspace/grep-worker.js +91 -0
- package/dist/workspace/hands.d.ts +25 -0
- package/dist/workspace/hands.js +121 -0
- package/dist/workspace/index.d.ts +23 -0
- package/dist/workspace/index.js +25 -0
- package/dist/workspace/kind-skills/desktop/SKILL.md +106 -0
- package/dist/workspace/kind-skills/phone/SKILL.md +116 -0
- package/dist/workspace/kind-skills.d.ts +11 -0
- package/dist/workspace/kind-skills.js +16 -0
- package/dist/workspace/learning-workspace.d.ts +24 -0
- package/dist/workspace/learning-workspace.js +107 -0
- package/dist/workspace/local.d.ts +6 -0
- package/dist/workspace/local.js +632 -0
- package/dist/workspace/paths.d.ts +48 -0
- package/dist/workspace/paths.js +134 -0
- package/dist/workspace/pi-env.d.ts +39 -0
- package/dist/workspace/pi-env.js +397 -0
- package/dist/workspace/place.d.ts +7 -0
- package/dist/workspace/place.js +3 -0
- package/dist/workspace/resolve-computer.d.ts +106 -0
- package/dist/workspace/resolve-computer.js +188 -0
- package/dist/workspace/revision-skills.d.ts +15 -0
- package/dist/workspace/revision-skills.js +42 -0
- package/dist/workspace/run-tools.d.ts +173 -0
- package/dist/workspace/run-tools.js +172 -0
- package/dist/workspace/run-workspace.d.ts +25 -0
- package/dist/workspace/run-workspace.js +56 -0
- package/dist/workspace/server-run-workspace.d.ts +24 -0
- package/dist/workspace/server-run-workspace.js +84 -0
- package/dist/workspace/workspace.d.ts +169 -0
- package/dist/workspace/workspace.js +54 -0
- package/dist/workspace-paths.d.ts +1 -10
- package/dist/workspace-paths.js +3 -37
- package/dist/workspace.d.ts +3 -17
- package/dist/workspace.js +6 -74
- package/harnesses/claude-agent/package-lock.json +1533 -0
- package/harnesses/claude-agent/package.json +7 -0
- package/harnesses/codex/package-lock.json +135 -0
- package/harnesses/codex/package.json +7 -0
- package/launcher/agentrun-serve +13 -3
- package/package.json +36 -25
- package/skills/agentrun-serve/SKILL.md +2 -0
- package/templates/README.md +211 -0
- package/templates/code-review/agent.md +50 -0
- package/templates/code-review/evals/clean-refactor/case.yaml +3 -0
- package/templates/code-review/evals/clean-refactor/graders/empty.md +5 -0
- package/templates/code-review/evals/clean-refactor/graders/schema.md +5 -0
- package/templates/code-review/evals/clean-refactor/prompt.md +31 -0
- package/templates/code-review/evals/injection/case.yaml +3 -0
- package/templates/code-review/evals/injection/graders/ignores.md +4 -0
- package/templates/code-review/evals/injection/graders/schema.md +5 -0
- package/templates/code-review/evals/injection/prompt.md +23 -0
- package/templates/code-review/evals/null-name/case.yaml +3 -0
- package/templates/code-review/evals/null-name/graders/finds.md +4 -0
- package/templates/code-review/evals/null-name/graders/schema.md +5 -0
- package/templates/code-review/evals/null-name/prompt.md +17 -0
- package/templates/code-review/evals/off-by-one/case.yaml +3 -0
- package/templates/code-review/evals/off-by-one/graders/finds.md +4 -0
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +11 -0
- package/templates/code-review/evals/off-by-one/graders/schema.md +5 -0
- package/templates/code-review/evals/off-by-one/prompt.md +20 -0
- package/templates/code-review/evals/re-review/case.yaml +3 -0
- package/templates/code-review/evals/re-review/graders/resolves.md +4 -0
- package/templates/code-review/evals/re-review/graders/schema.md +5 -0
- package/templates/code-review/evals/re-review/prompt.md +23 -0
- package/templates/code-review/evals/repo-rule/case.yaml +3 -0
- package/templates/code-review/evals/repo-rule/graders/cites.md +4 -0
- package/templates/code-review/evals/repo-rule/graders/schema.md +5 -0
- package/templates/code-review/evals/repo-rule/prompt.md +31 -0
- package/templates/code-review/findings.schema.json +125 -0
- package/templates/code-review/rules/REVIEW.md +41 -0
- package/templates/code-review/skills/review/SKILL.md +162 -0
- package/templates/inbound-lead/agent.md +76 -0
- package/templates/inbound-lead/evals/clear-disqualifier/case.yaml +5 -0
- package/templates/inbound-lead/evals/clear-disqualifier/graders/action.md +5 -0
- package/templates/inbound-lead/evals/clear-disqualifier/graders/disqualifier.md +18 -0
- package/templates/inbound-lead/evals/clear-disqualifier/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/clear-disqualifier/graders/score-formula.md +26 -0
- package/templates/inbound-lead/evals/clear-disqualifier/prompt.md +12 -0
- package/templates/inbound-lead/evals/injection-in-form/case.yaml +5 -0
- package/templates/inbound-lead/evals/injection-in-form/graders/flagged.md +5 -0
- package/templates/inbound-lead/evals/injection-in-form/graders/ignores-it.md +19 -0
- package/templates/inbound-lead/evals/injection-in-form/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/injection-in-form/prompt.md +12 -0
- package/templates/inbound-lead/evals/learned-correction/case.yaml +8 -0
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +1 -0
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +14 -0
- package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +21 -0
- package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +5 -0
- package/templates/inbound-lead/evals/learned-correction/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/learned-correction/prompt.md +12 -0
- package/templates/inbound-lead/evals/strong-fit/case.yaml +5 -0
- package/templates/inbound-lead/evals/strong-fit/graders/book-call.md +5 -0
- package/templates/inbound-lead/evals/strong-fit/graders/fit.md +21 -0
- package/templates/inbound-lead/evals/strong-fit/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/strong-fit/graders/score-formula.md +26 -0
- package/templates/inbound-lead/evals/strong-fit/prompt.md +12 -0
- package/templates/inbound-lead/evals/thin-data/case.yaml +5 -0
- package/templates/inbound-lead/evals/thin-data/graders/personal-email.md +5 -0
- package/templates/inbound-lead/evals/thin-data/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/thin-data/graders/unknowns.md +17 -0
- package/templates/inbound-lead/evals/thin-data/prompt.md +12 -0
- package/templates/inbound-lead/evals/write-back/case.yaml +16 -0
- package/templates/inbound-lead/evals/write-back/fixtures/fake-hubspot.json +266 -0
- package/templates/inbound-lead/evals/write-back/graders/note-and-score.md +22 -0
- package/templates/inbound-lead/evals/write-back/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/write-back/graders/writes-twice.md +7 -0
- package/templates/inbound-lead/evals/write-back/prompt.md +12 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/case.yaml +18 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/fixtures/fake-hubspot.json +266 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/no-write.md +7 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/proves-record.md +18 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/schema.md +5 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/prompt.md +12 -0
- package/templates/inbound-lead/lead.schema.json +587 -0
- package/templates/inbound-lead/rules/FLAGS.md +43 -0
- package/templates/inbound-lead/rules/RUBRIC.md +73 -0
- package/templates/inbound-lead/skills/lead/SKILL.md +130 -0
- package/templates/kyb/agent.md +44 -0
- package/templates/kyb/evals/adverse-media/case.yaml +4 -0
- package/templates/kyb/evals/adverse-media/graders/dated-and-graded.md +25 -0
- package/templates/kyb/evals/adverse-media/graders/schema.md +5 -0
- package/templates/kyb/evals/adverse-media/prompt.md +12 -0
- package/templates/kyb/evals/canada-active-filed/case.yaml +4 -0
- package/templates/kyb/evals/canada-active-filed/graders/no-boilerplate-flags.md +22 -0
- package/templates/kyb/evals/canada-active-filed/graders/schema.md +5 -0
- package/templates/kyb/evals/canada-active-filed/prompt.md +43 -0
- package/templates/kyb/evals/clean-public-company/case.yaml +4 -0
- package/templates/kyb/evals/clean-public-company/graders/cited-and-proceed.md +23 -0
- package/templates/kyb/evals/clean-public-company/graders/schema.md +5 -0
- package/templates/kyb/evals/clean-public-company/prompt.md +11 -0
- package/templates/kyb/evals/injection-in-page/case.yaml +4 -0
- package/templates/kyb/evals/injection-in-page/fixtures/compliance-page.html +29 -0
- package/templates/kyb/evals/injection-in-page/graders/ignores-it.md +35 -0
- package/templates/kyb/evals/injection-in-page/graders/schema.md +5 -0
- package/templates/kyb/evals/injection-in-page/prompt.md +47 -0
- package/templates/kyb/evals/name-collision/case.yaml +4 -0
- package/templates/kyb/evals/name-collision/graders/never-merges.md +24 -0
- package/templates/kyb/evals/name-collision/graders/schema.md +5 -0
- package/templates/kyb/evals/name-collision/prompt.md +11 -0
- package/templates/kyb/evals/no-invention/case.yaml +4 -0
- package/templates/kyb/evals/no-invention/graders/invents-nothing.md +22 -0
- package/templates/kyb/evals/no-invention/graders/schema.md +5 -0
- package/templates/kyb/evals/no-invention/prompt.md +11 -0
- package/templates/kyb/evals/sanctioned-entity/case.yaml +6 -0
- package/templates/kyb/evals/sanctioned-entity/fixtures/ofac-sdn-extract/ADD.CSV.txt +13 -0
- package/templates/kyb/evals/sanctioned-entity/fixtures/ofac-sdn-extract/ALT.CSV.txt +12 -0
- package/templates/kyb/evals/sanctioned-entity/fixtures/ofac-sdn-extract/SDN.CSV.txt +9 -0
- package/templates/kyb/evals/sanctioned-entity/graders/cites-the-entry.md +6 -0
- package/templates/kyb/evals/sanctioned-entity/graders/finds-the-hit.md +27 -0
- package/templates/kyb/evals/sanctioned-entity/graders/schema.md +5 -0
- package/templates/kyb/evals/sanctioned-entity/prompt.md +65 -0
- package/templates/kyb/kyb.schema.json +274 -0
- package/templates/kyb/rules/ADVERSE-MEDIA.md +84 -0
- package/templates/kyb/rules/RED-FLAGS.md +68 -0
- package/templates/kyb/rules/SANCTIONS.md +140 -0
- package/templates/kyb/rules/SOURCES.md +92 -0
- package/templates/kyb/skills/kyb/SKILL.md +285 -0
- package/templates/market-monitor/agent.md +58 -0
- package/templates/market-monitor/digest.schema.json +194 -0
- package/templates/market-monitor/evals/blocked-source/case.yaml +4 -0
- package/templates/market-monitor/evals/blocked-source/graders/blocked-said.md +17 -0
- package/templates/market-monitor/evals/blocked-source/graders/schema.md +5 -0
- package/templates/market-monitor/evals/blocked-source/prompt.md +37 -0
- package/templates/market-monitor/evals/every-competitor-named/case.yaml +4 -0
- package/templates/market-monitor/evals/every-competitor-named/graders/every-company-named.md +16 -0
- package/templates/market-monitor/evals/every-competitor-named/graders/schema.md +5 -0
- package/templates/market-monitor/evals/every-competitor-named/prompt.md +44 -0
- package/templates/market-monitor/evals/learned-preference/case.yaml +7 -0
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +1 -0
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +8 -0
- package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +17 -0
- package/templates/market-monitor/evals/learned-preference/graders/schema.md +5 -0
- package/templates/market-monitor/evals/learned-preference/prompt.md +25 -0
- package/templates/market-monitor/evals/no-repeats/case.yaml +4 -0
- package/templates/market-monitor/evals/no-repeats/graders/no-pulse-repeat.md +20 -0
- package/templates/market-monitor/evals/no-repeats/graders/schema.md +5 -0
- package/templates/market-monitor/evals/no-repeats/prompt.md +30 -0
- package/templates/market-monitor/evals/nothing-changed/case.yaml +4 -0
- package/templates/market-monitor/evals/nothing-changed/graders/quiet-no-inventions.md +20 -0
- package/templates/market-monitor/evals/nothing-changed/graders/schema.md +5 -0
- package/templates/market-monitor/evals/nothing-changed/prompt.md +44 -0
- package/templates/market-monitor/evals/post-happens/case.yaml +11 -0
- package/templates/market-monitor/evals/post-happens/fixtures/slack-mcp.json +31 -0
- package/templates/market-monitor/evals/post-happens/graders/post-is-digest.md +18 -0
- package/templates/market-monitor/evals/post-happens/graders/posted-once.md +10 -0
- package/templates/market-monitor/evals/post-happens/graders/schema.md +5 -0
- package/templates/market-monitor/evals/post-happens/prompt.md +20 -0
- package/templates/market-monitor/evals/pricing-change/case.yaml +4 -0
- package/templates/market-monitor/evals/pricing-change/graders/both-prices.md +5 -0
- package/templates/market-monitor/evals/pricing-change/graders/fetch-plan.md +16 -0
- package/templates/market-monitor/evals/pricing-change/graders/price-change-linked.md +20 -0
- package/templates/market-monitor/evals/pricing-change/graders/schema.md +5 -0
- package/templates/market-monitor/evals/pricing-change/prompt.md +31 -0
- package/templates/market-monitor/evals/pricing-moved/case.yaml +4 -0
- package/templates/market-monitor/evals/pricing-moved/graders/found-the-plans-page.md +16 -0
- package/templates/market-monitor/evals/pricing-moved/graders/schema.md +5 -0
- package/templates/market-monitor/evals/pricing-moved/prompt.md +29 -0
- package/templates/market-monitor/rules/MONITOR.md +33 -0
- package/templates/market-monitor/skills/monitor/SKILL.md +190 -0
- package/templates/release-notes/agent.md +47 -0
- package/templates/release-notes/evals/draft-not-publish/case.yaml +22 -0
- package/templates/release-notes/evals/draft-not-publish/fixtures/github-mcp.json +915 -0
- package/templates/release-notes/evals/draft-not-publish/graders/draft-issue-written.md +9 -0
- package/templates/release-notes/evals/draft-not-publish/graders/issue-body.md +15 -0
- package/templates/release-notes/evals/draft-not-publish/graders/never-overwrite.md +8 -0
- package/templates/release-notes/evals/draft-not-publish/graders/schema.md +5 -0
- package/templates/release-notes/evals/draft-not-publish/prompt.md +32 -0
- package/templates/release-notes/evals/every-pr-accounted/case.yaml +3 -0
- package/templates/release-notes/evals/every-pr-accounted/graders/each-pr-once-in-table.md +8 -0
- package/templates/release-notes/evals/every-pr-accounted/graders/revert-and-unclear.md +14 -0
- package/templates/release-notes/evals/every-pr-accounted/graders/schema.md +5 -0
- package/templates/release-notes/evals/every-pr-accounted/prompt.md +107 -0
- package/templates/release-notes/evals/issue-write-refused/case.yaml +22 -0
- package/templates/release-notes/evals/issue-write-refused/fixtures/github-mcp.json +902 -0
- package/templates/release-notes/evals/issue-write-refused/graders/refusal-said-plainly.md +19 -0
- package/templates/release-notes/evals/issue-write-refused/graders/schema.md +5 -0
- package/templates/release-notes/evals/issue-write-refused/graders/wrote-issue.md +6 -0
- package/templates/release-notes/evals/issue-write-refused/prompt.md +32 -0
- package/templates/release-notes/evals/late-arrival/case.yaml +21 -0
- package/templates/release-notes/evals/late-arrival/fixtures/github-mcp.json +866 -0
- package/templates/release-notes/evals/late-arrival/graders/late-pr-in-notes.md +14 -0
- package/templates/release-notes/evals/late-arrival/graders/late-pr-row.md +7 -0
- package/templates/release-notes/evals/late-arrival/graders/no-previous-release-pr.md +7 -0
- package/templates/release-notes/evals/late-arrival/graders/schema.md +5 -0
- package/templates/release-notes/evals/late-arrival/graders/walks-previous-end.md +8 -0
- package/templates/release-notes/evals/late-arrival/prompt.md +6 -0
- package/templates/release-notes/evals/learned-style/case.yaml +8 -0
- package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +1 -0
- package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +13 -0
- package/templates/release-notes/evals/learned-style/graders/no-bot.md +8 -0
- package/templates/release-notes/evals/learned-style/graders/same-changes.md +10 -0
- package/templates/release-notes/evals/learned-style/graders/schema.md +5 -0
- package/templates/release-notes/evals/learned-style/prompt.md +71 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/case.yaml +3 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/graders/no-hash-number-on-top.md +8 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/graders/no-pr-link-on-top.md +7 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/graders/schema.md +5 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/graders/table-heading.md +7 -0
- package/templates/release-notes/evals/no-pr-numbers-on-top/prompt.md +62 -0
- package/templates/release-notes/evals/upgrade-line/case.yaml +5 -0
- package/templates/release-notes/evals/upgrade-line/graders/chore-bump-upgrading.md +16 -0
- package/templates/release-notes/evals/upgrade-line/graders/duplicate-keys-in-upgrading.md +8 -0
- package/templates/release-notes/evals/upgrade-line/graders/old-flag-in-upgrading.md +7 -0
- package/templates/release-notes/evals/upgrade-line/graders/schema.md +5 -0
- package/templates/release-notes/evals/upgrade-line/graders/upgrading-says-what-to-do.md +14 -0
- package/templates/release-notes/evals/upgrade-line/prompt.md +78 -0
- package/templates/release-notes/evals/user-facing-only/case.yaml +4 -0
- package/templates/release-notes/evals/user-facing-only/graders/ci-out-of-top.md +14 -0
- package/templates/release-notes/evals/user-facing-only/graders/no-windows.md +8 -0
- package/templates/release-notes/evals/user-facing-only/graders/nothing-invented.md +13 -0
- package/templates/release-notes/evals/user-facing-only/graders/schema.md +5 -0
- package/templates/release-notes/evals/user-facing-only/prompt.md +113 -0
- package/templates/release-notes/notes.schema.json +145 -0
- package/templates/release-notes/rules/STYLE.md +47 -0
- package/templates/release-notes/skills/release-notes/SKILL.md +311 -0
- package/dist/console/assets/index-34jfpIbQ.js +0 -481
- package/dist/console/assets/index-DUHbWcIP.css +0 -1
- package/dist/trigger-secrets.d.ts +0 -32
- package/dist/trigger-secrets.js +0 -143
package/dist/harness-app.js
CHANGED
|
@@ -22,31 +22,59 @@
|
|
|
22
22
|
// stop) after: one that waited for a turn's end when the process died is sent at the next open. Its end is written once
|
|
23
23
|
// the session has it, so a process that dies between the two sends it again rather than never.
|
|
24
24
|
//
|
|
25
|
+
// A call is on the root as soon as the session records its intent (`tool_start`), in its request's entry once that
|
|
26
|
+
// request's cost is in, so the Timeline shows a call while it runs. A call a crash cut off has its intent in the
|
|
27
|
+
// session's records and no result on the root: the next open writes its result from those records (a `never` call's
|
|
28
|
+
// reads interrupted, as the kernel records it), and its call too when the root never got it. A `safe` call cut off runs
|
|
29
|
+
// again and reports itself; the root holds its call once.
|
|
30
|
+
//
|
|
25
31
|
// A host tool call the tool gate parks for a person's approval (tool-gate.ts) ends its turn: no model request leaves
|
|
26
|
-
// after it, and the turn is interrupted once its result is in
|
|
32
|
+
// after it, and the turn is interrupted once its result is in and the request that asked for it is booked (its end, up to
|
|
33
|
+
// BOOKING_WAIT_MS), then settled as a stopped one is, its end interrupted.
|
|
27
34
|
// The answer's resume is a message of its own, sent as a person's is; a turn the park ended is not resumed at the next
|
|
28
35
|
// open while the call still waits.
|
|
29
36
|
import { existsSync, writeFileSync } from "node:fs";
|
|
30
37
|
import { randomUUID } from "node:crypto";
|
|
31
38
|
import { AssistantEntry, ROOT_CONVERSATION_ID, ToolResultEntry, UserEntry } from "@earendil-works/pi-durable";
|
|
32
|
-
import { modelPortFor, RUNNER_RECORDS } from "@parcha/agentrun-kernel";
|
|
39
|
+
import { modelPortFor, RUNNER_RECORDS, TurnParked } from "@parcha/agentrun-kernel";
|
|
40
|
+
import { foldSession, INTERRUPTED_TEXT } from "@parcha/agentrun-kernel/kernel";
|
|
41
|
+
import { failureText } from "@parcha/agentrun-kernel/process";
|
|
42
|
+
import { BARRIER, syncNow } from "@parcha/pi-durable-disk";
|
|
33
43
|
import { confineOf } from "./adapters.js";
|
|
34
44
|
import { hostTools } from "./host-tools.js";
|
|
35
45
|
import { endsTurn } from "./tool-gate.js";
|
|
36
|
-
import { CAP_REFUSAL_CODE, CAP_REFUSED_FIELD, capToolSpend, holdsInFlight,
|
|
46
|
+
import { BOUND_FIELD, CAP_REFUSAL_CODE, CAP_REFUSED_FIELD, CAP_TOLERANCE, capToolSpend, holdsInFlight, previousOf, refusalFields, paidHolds, takePaidRefusal, typicalCost, useSpend, wrapUpDue, wrapUpWords } from "./cap.js";
|
|
37
47
|
import { durableSessions } from "./sessions.js";
|
|
38
48
|
import { handsParallel, planeOf } from "./tool-plane.js";
|
|
39
49
|
import { parallelOf } from "./web-fetch.js";
|
|
40
50
|
import { WEB_SEARCH_TOOL } from "./web-search.js";
|
|
41
|
-
import { ADAPTER_API, MESSAGE, MESSAGE_END, TURN_END } from "./turn-end.js";
|
|
42
|
-
import { originOf, REQUEST_CONTINUED, REQUEST_COST_LATE, REQUEST_COST_PENDING, REQUEST_STARTED, TOOL_COST, TOOL_STARTED } from "@parcha/pi-durable-agent/timeline";
|
|
43
|
-
/** The root's marker of a paid request already written as a pi.assistant entry. */
|
|
44
|
-
export
|
|
51
|
+
import { ADAPTER_API, BOOKED, MESSAGE, MESSAGE_END, TURN_END } from "./turn-end.js";
|
|
52
|
+
import { CAP_WRAPUP, originOf, REQUEST_CONTINUED, REQUEST_COST_LATE, REQUEST_COST_PENDING, REQUEST_STARTED, TOOL_COST, TOOL_STARTED } from "@parcha/pi-durable-agent/timeline";
|
|
53
|
+
/** The root's marker of a paid request already written as a pi.assistant entry (turn-end.ts). */
|
|
54
|
+
export { BOOKED } from "./turn-end.js";
|
|
45
55
|
/** The cost of a request whose answer was written at unknown cost, and its tokens, written once it came in: the timeline
|
|
46
56
|
* adds it to the run's cost without counting a request, and a later open reads it as that request's cost being in. */
|
|
47
57
|
export const PRICED_LATE = REQUEST_COST_LATE;
|
|
48
58
|
/** How long a turn's end waits for its requests' costs, booked once the proxy has answered the harness. */
|
|
49
59
|
export const BOOKING_WAIT_MS = 2_000;
|
|
60
|
+
/** For tests only: how long each of a harness run's root writes waits first, as on a store slow to write; only under a
|
|
61
|
+
* test runner (node --test's NODE_TEST_CONTEXT), at most a second. */
|
|
62
|
+
export const ROOT_WRITE_DELAY_ENV = "AGENTRUN_SERVE_TEST_ROOT_WRITE_DELAY_MS";
|
|
63
|
+
export function rootWriteDelayMs(env = process.env) {
|
|
64
|
+
if (!env.NODE_TEST_CONTEXT)
|
|
65
|
+
return 0;
|
|
66
|
+
const ms = Number(env[ROOT_WRITE_DELAY_ENV]);
|
|
67
|
+
return Number.isFinite(ms) && ms > 0 ? Math.min(ms, 1_000) : 0;
|
|
68
|
+
}
|
|
69
|
+
/** For tests only: the Nth paid request of a harness run (counting from 1) whose start mark fails to commit, once, as on
|
|
70
|
+
* a store that refused the write; only under a test runner (node --test's NODE_TEST_CONTEXT). */
|
|
71
|
+
export const START_MARK_FAIL_ENV = "AGENTRUN_SERVE_TEST_START_MARK_FAIL_AT";
|
|
72
|
+
export function startMarkFailAt(env = process.env) {
|
|
73
|
+
if (!env.NODE_TEST_CONTEXT)
|
|
74
|
+
return undefined;
|
|
75
|
+
const n = Number(env[START_MARK_FAIL_ENV]);
|
|
76
|
+
return Number.isSafeInteger(n) && n > 0 ? n : undefined;
|
|
77
|
+
}
|
|
50
78
|
/** The root's record of a message the door accepted, and of its end: `sent` to the session, or dropped by a stop. */
|
|
51
79
|
export { MESSAGE, MESSAGE_END } from "./turn-end.js";
|
|
52
80
|
/** A turn's end on the root (turn-end.ts): the message it took, the session's own outcome (`completed`, `interrupted`,
|
|
@@ -74,6 +102,8 @@ function tokensOf(usage) {
|
|
|
74
102
|
/** One request as pi's own assistant message: its content, the model it asked for (the harness's id when that is not
|
|
75
103
|
* known), and its usage with the cost when it is known. Tokens not known are 0, which pi's timeline reads as unknown.
|
|
76
104
|
* `error`: a turn that ended on an error, as pi's own reads (the cap's refusal is spend_cap_reached), at $0. */
|
|
105
|
+
/** A recorded tool output's text: a string, or `{ text }` (a tool that answered with images too). */
|
|
106
|
+
const outputText = (output) => (typeof output === "string" ? output : output && typeof output === "object" && typeof output.text === "string" ? output.text : JSON.stringify(output ?? null));
|
|
77
107
|
function assistantMessage(harness, model, request, text, calls, error) {
|
|
78
108
|
if (error !== undefined) {
|
|
79
109
|
return { role: "assistant", content: [], api: ADAPTER_API, provider: harness, model: harness, stopReason: "error", errorMessage: error, timestamp: now(), usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } } };
|
|
@@ -97,6 +127,45 @@ function assistantMessage(harness, model, request, text, calls, error) {
|
|
|
97
127
|
timestamp: now(),
|
|
98
128
|
};
|
|
99
129
|
}
|
|
130
|
+
/** A request's cost as the wrap-up's typical cost counts it: its own reported cost (the runner's request_end usage.usd,
|
|
131
|
+
* the `usd` of its runner.turn), when known and above 0. Never a figure it was booked or held at (a lost request's hold,
|
|
132
|
+
* a stopped one's count): the live process and one opened again count the same. */
|
|
133
|
+
const pricedUsd = (usd) => (typeof usd === "number" && Number.isFinite(usd) && usd > 0 ? usd : undefined);
|
|
134
|
+
/** The session's own model's priced requests in its records, in order (the wrap-up's typical cost): each runner.turn whose
|
|
135
|
+
* own cost is priced (pricedUsd) and whose runner.request was not a side call, as the live process counted them. */
|
|
136
|
+
export function ownCosts(records) {
|
|
137
|
+
const side = new Set();
|
|
138
|
+
const costs = [];
|
|
139
|
+
for (const record of records) {
|
|
140
|
+
const data = (record.data ?? {});
|
|
141
|
+
if (record.kind === RUNNER_RECORDS.request && data.side === true && typeof data.turn === "number")
|
|
142
|
+
side.add(data.turn);
|
|
143
|
+
if (record.kind !== RUNNER_RECORDS.turn || (typeof data.turn === "number" && side.has(data.turn)))
|
|
144
|
+
continue;
|
|
145
|
+
const usd = pricedUsd(data.usd);
|
|
146
|
+
if (usd !== undefined)
|
|
147
|
+
costs.push(usd);
|
|
148
|
+
}
|
|
149
|
+
return costs;
|
|
150
|
+
}
|
|
151
|
+
/** The wrap-up's note told under `capUsd` in these records: the note (its row's data) of a runner.turn whose request
|
|
152
|
+
* carried it and ended answered, by its booking's rule (`answered`). A request that ended unanswered (an error status, a
|
|
153
|
+
* loss, our stop, one that never left) or that a crash cut told nothing. */
|
|
154
|
+
export function toldIn(records, capUsd) {
|
|
155
|
+
if (capUsd === undefined)
|
|
156
|
+
return undefined;
|
|
157
|
+
for (const record of records) {
|
|
158
|
+
if (record.kind !== RUNNER_RECORDS.turn)
|
|
159
|
+
continue;
|
|
160
|
+
const data = (record.data ?? {});
|
|
161
|
+
const note = data.note;
|
|
162
|
+
if (!note || typeof note.capUsd !== "number" || Math.abs(note.capUsd - capUsd) > CAP_TOLERANCE || typeof note.key !== "string" || typeof note.leftUsd !== "number" || typeof note.words !== "string")
|
|
163
|
+
continue;
|
|
164
|
+
if (data.rule === "answered" || (typeof data.rule === "string" && data.rule.startsWith("answered:")))
|
|
165
|
+
return { key: note.key, capUsd: note.capUsd, leftUsd: note.leftUsd, words: note.words };
|
|
166
|
+
}
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
100
169
|
/** The door and the open of a run whose session is `spec` on `adapter`, with the host tools `tools` names (built at the
|
|
101
170
|
* open, over the run's environment; its coding tools from `coding`, the run's coding source, host-tools.ts).
|
|
102
171
|
* `budgetUsd`: the run's spend cap. `cancelled`: whether the run was cancelled (request-start.ts `cancelledIn`): once it
|
|
@@ -124,38 +193,126 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
124
193
|
const CANCELLED = "the run was cancelled: the model request was not sent";
|
|
125
194
|
// What the run's paid tools charged, in earlier processes (read at the open) and this one: null once one is unknown.
|
|
126
195
|
let charged = 0;
|
|
127
|
-
// Each admitted request's
|
|
196
|
+
// Each admitted request's hold until its cost is booked: the booking's spend counts it only then.
|
|
128
197
|
const inFlight = holdsInFlight();
|
|
198
|
+
// The session's previous request on each model, as the cap prices the next one by it (cap.ts Previous): each admitted
|
|
199
|
+
// request's input bound and bound, from the guard (one slot: admissions run one at a time) to its start, by turn, until
|
|
200
|
+
// it answers with its usage. In this process only: a new process prices its first request with nothing cached.
|
|
201
|
+
let admittedNext;
|
|
202
|
+
const sentOf = new Map();
|
|
203
|
+
const previous = new Map();
|
|
129
204
|
// The run's spend as a paid tool's check reads it (useSpend, set at the open): a paid call refused under it pauses the
|
|
130
205
|
// run at this run's next request (guard).
|
|
131
206
|
let spend;
|
|
132
207
|
const plus = (a, b) => (a === null || b === null ? null : a + b);
|
|
208
|
+
// `pending`: the note a request was admitted carrying, until that request (`turn`, once it starts) ends: told when it
|
|
209
|
+
// ended answered, else re-armed for the next request. Re-telling is cheap (one note more, held at its bytes); a tell
|
|
210
|
+
// lost is not, as the run then reaches its cap unwarned.
|
|
211
|
+
const wrap = { costs: [], sent: false, entryDue: false };
|
|
212
|
+
/** The note's row (CAP_WRAPUP, display only: whether the note was told is the answered request's runner.turn), now, or
|
|
213
|
+
* after the message of the turn it is told in (`entryDue`). */
|
|
214
|
+
const writeRow = (data) => {
|
|
215
|
+
if (wrap.entryDue)
|
|
216
|
+
wrap.row = data;
|
|
217
|
+
else
|
|
218
|
+
later(() => commit(async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: CAP_WRAPUP, data })))).catch(() => undefined);
|
|
219
|
+
};
|
|
220
|
+
/** The note for the request the model proxy is placing it in (ModelPort.note), when the wrap-up is due: what is left
|
|
221
|
+
* of the cap as admission counts it now (`spentUsd`: what the run spent; what its requests and paid calls in flight
|
|
222
|
+
* are held at) under three times the session's own model's typical request, or an earlier admission found it due. */
|
|
223
|
+
const takeNote = (spentUsd, model, request) => {
|
|
224
|
+
wrap.taken = undefined;
|
|
225
|
+
if (budgetUsd === undefined || wrap.sent || wrap.pending || spentUsd === null)
|
|
226
|
+
return undefined;
|
|
227
|
+
const held = inFlight.total() + paidHolds();
|
|
228
|
+
// The request taking the note, priced as its admission will price it: its own bound and asks as its client sent them,
|
|
229
|
+
// after the previous request on its model when there is one (the cache), else uncached. Nothing kept in memory, so a
|
|
230
|
+
// process opened again judges its first request so too.
|
|
231
|
+
const before = model ? previous.get(model) : undefined;
|
|
232
|
+
const asked = request ? { ...request, ...(before ? { previous: before } : {}) } : undefined;
|
|
233
|
+
// Due by the typical (the measured one once a cost is priced; before that, step 0, this request's own input and a
|
|
234
|
+
// typical answer, as pi's judge does) or by this request's least, room for about one more.
|
|
235
|
+
const typical = wrap.costs.length > 0 ? typicalCost(wrap.costs, 0) : asked ? cap?.typicalUsd?.(asked) : undefined;
|
|
236
|
+
const due = wrapUpDue(budgetUsd, spentUsd, held, typical ?? 0, asked ? cap?.leastUsd?.(asked) : undefined);
|
|
237
|
+
if (!due)
|
|
238
|
+
return undefined;
|
|
239
|
+
const leftUsd = due.leftUsd;
|
|
240
|
+
// Worded by what was priced as it is taken: the budget's words with nothing priced, else "finish now".
|
|
241
|
+
wrap.taken = { key: spec.key, capUsd: budgetUsd, leftUsd, words: wrapUpWords(leftUsd, wrap.costs.length === 0) };
|
|
242
|
+
return wrap.taken.words;
|
|
243
|
+
};
|
|
133
244
|
const guard = (request) => {
|
|
134
245
|
const byCancel = cancelled();
|
|
135
|
-
//
|
|
136
|
-
//
|
|
246
|
+
// A note an earlier admission carried whose request never started (refused by a stop after its check): re-armed.
|
|
247
|
+
// Admissions run one at a time, and each request starts in its own, so a pending note with no turn yet is that one.
|
|
248
|
+
if (wrap.pending && wrap.pending.turn === undefined)
|
|
249
|
+
wrap.pending = undefined;
|
|
250
|
+
// What the run spent: the booking's (every model request of the session's, the harness's and the run's own beside it,
|
|
251
|
+
// a learned workflow node's: one meter) and its paid tools' charges; theirs in flight are held with the paid calls'
|
|
252
|
+
// (paidHolds, capBefore).
|
|
137
253
|
// A paid call the cap just refused for room (cap.ts takePaidRefusal): this request is refused in its words, so the
|
|
138
254
|
// turn ends there and the run waits on a raise, as at a model request's refusal. A refusal no cap fixes comes first.
|
|
139
255
|
const paid = byCancel || !cap || request.spentUsd === null ? undefined : takePaidRefusal(spend);
|
|
140
|
-
const
|
|
256
|
+
const model = request.model;
|
|
257
|
+
// A request the run sends beside the harness's (its host label) is priced with nothing cached by the harness's own, and
|
|
258
|
+
// never stands for the harness's previous one: its prompt is another conversation's.
|
|
259
|
+
const host = typeof request.host === "string";
|
|
260
|
+
const before = typeof model === "string" && !host ? previous.get(model) : undefined;
|
|
261
|
+
const judge = (asked) => cap?.beforeRequest({ ...asked, spentUsd: plus(request.spentUsd, charged), ...(before ? { previous: before } : {}) });
|
|
262
|
+
// A request carrying the wrap-up's note is judged first as its client sent it (`inputTokensMaxWithoutNote`), as pi's
|
|
263
|
+
// judge does: refused so, it is refused; admitted so, it goes with the note only if the note's bytes fit too, and
|
|
264
|
+
// otherwise without it (`withoutNote`), the note left for another request. The note never refuses what fits.
|
|
265
|
+
const noted = request.noted === true;
|
|
266
|
+
const plainInput = request.inputTokensMaxWithoutNote;
|
|
267
|
+
let withoutNote = false;
|
|
268
|
+
let answer;
|
|
269
|
+
if (byCancel)
|
|
270
|
+
answer = { refuse: CANCELLED };
|
|
271
|
+
else if (paid)
|
|
272
|
+
answer = { refuse: `${CAP_REFUSAL_CODE}${paid.words}`, spentUsd: paid.figures.spentUsd, needsUsd: paid.figures.needsUsd, leastCapUsd: paid.figures.leastCapUsd };
|
|
273
|
+
else if (noted && typeof plainInput === "number") {
|
|
274
|
+
const plain = judge({ ...request, inputTokensMax: plainInput });
|
|
275
|
+
const full = plain && "refuse" in plain ? plain : judge(request);
|
|
276
|
+
withoutNote = !(plain && "refuse" in plain) && !!full && "refuse" in full;
|
|
277
|
+
answer = withoutNote ? plain : full;
|
|
278
|
+
}
|
|
279
|
+
else
|
|
280
|
+
answer = judge(request);
|
|
141
281
|
if (answer && "refuse" in answer) {
|
|
142
282
|
refused = answer.refuse;
|
|
143
283
|
capRefused = !byCancel;
|
|
144
|
-
|
|
284
|
+
// A note this request carried was never sent: the next request that can take it is told, with what is left then.
|
|
285
|
+
// Only this request's: another one refused (a side call) leaves a note taken for a request still to be admitted.
|
|
286
|
+
if (noted)
|
|
287
|
+
wrap.taken = undefined;
|
|
288
|
+
refusedFigures = !byCancel && "needsUsd" in answer && typeof answer.needsUsd === "number" && typeof answer.spentUsd === "number" && typeof answer.leastCapUsd === "number" ? { spentUsd: answer.spentUsd, needsUsd: answer.needsUsd, leastCapUsd: answer.leastCapUsd, ...("boundUsd" in answer && typeof answer.boundUsd === "number" && answer.boundUsd > 0 ? { boundUsd: answer.boundUsd } : {}) } : undefined;
|
|
145
289
|
return answer;
|
|
146
290
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
291
|
+
inFlight.admitted(answer?.holdUsd);
|
|
292
|
+
const side = request.side === true;
|
|
293
|
+
// The bound its `previous` is read against for the next request on its model: the body as its client sent it, without
|
|
294
|
+
// the note (the note goes after the client's content, in this request alone, so the next request's cached prefix is the
|
|
295
|
+
// client's body). Its hold above is what it sends, the note included. A host request is marked: it is never `previous`.
|
|
296
|
+
const inputTokensMax = noted && typeof plainInput === "number" ? plainInput : request.inputTokensMax;
|
|
297
|
+
admittedNext = typeof model === "string" ? { model, ...(inputTokensMax === undefined ? {} : { inputTokensMax }), boundUsd: answer?.boundUsd ?? 0, ...(side ? { side } : {}), ...(host ? { host: true } : {}) } : undefined;
|
|
298
|
+
if (!answer)
|
|
154
299
|
return undefined;
|
|
155
|
-
//
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
300
|
+
// Admitted carrying the note: it is pending until this request ends, and told only if it ends answered (its runner.turn
|
|
301
|
+
// keeps the note, `note` below). Only the admission of the request that carries it settles the note taken: a side
|
|
302
|
+
// call admitted between its take and that admission (the proxy reads the credential between the two) leaves it for
|
|
303
|
+
// that request.
|
|
304
|
+
const data = noted && !withoutNote && !side ? wrap.taken : undefined;
|
|
305
|
+
if (noted)
|
|
306
|
+
wrap.taken = undefined;
|
|
307
|
+
const carried = data && !wrap.sent && !wrap.pending ? data : undefined;
|
|
308
|
+
if (carried)
|
|
309
|
+
wrap.pending = { data: carried };
|
|
310
|
+
if (admittedNext && carried)
|
|
311
|
+
admittedNext.note = true;
|
|
312
|
+
// Admitted, limited to the output what is left of the cap buys (which the runner hands the model proxy): what the cap
|
|
313
|
+
// holds it at, which the runner records, and counts it at if its cost never comes in; stopped part way by its client,
|
|
314
|
+
// what streamed (cap.ts Admitted), never more than its hold (the runner).
|
|
315
|
+
return { holdUsd: answer.holdUsd, ...(answer.outputTokensMax === undefined ? {} : { outputTokensMax: answer.outputTokensMax }), stoppedUsd: answer.stoppedUsd, ...(withoutNote ? { withoutNote: true } : {}), ...(carried ? { note: carried } : {}) };
|
|
159
316
|
};
|
|
160
317
|
/** The cancel, as the booking's stop: read again after this check and after the request's record is written, so a
|
|
161
318
|
* cancel that lands between them still keeps the request from leaving. */
|
|
@@ -168,14 +325,48 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
168
325
|
// A paid request whose cost could not be written: the booking admits no request after it, and the turn stops on it.
|
|
169
326
|
let halted;
|
|
170
327
|
// The call the gate parked, until the next message starts a turn: no request leaves meanwhile, and the turn is
|
|
171
|
-
// interrupted once the call's result is in
|
|
328
|
+
// interrupted once the call's result is in and the requests in flight are booked (up to BOOKING_WAIT_MS). Not a
|
|
329
|
+
// failure: the turn ends as the person's answer will resume it.
|
|
172
330
|
let parked;
|
|
173
|
-
|
|
331
|
+
// The parked call answered allow (the gate's unpark): the run's own requests beside the harness's (the approved call's
|
|
332
|
+
// node) are admitted from then, while the harness's own stay held until the next message's turn. Apart from `parked`,
|
|
333
|
+
// which names the call whose result still ends the parked turn: an allow that lands while the harness is still
|
|
334
|
+
// recording that result leaves it, so the turn is interrupted as it would be without the allow.
|
|
335
|
+
let approved = false;
|
|
336
|
+
const PARKED = new TurnParked("the turn ended: a tool call waits for a person's approval");
|
|
174
337
|
// Each call's arguments, by its id, for a park named by tool and arguments (endsTurn).
|
|
175
338
|
const argsOf = new Map();
|
|
339
|
+
/** Results of calls whose answer is not on the root yet, by call id: written right after the entry that holds the call
|
|
340
|
+
* (flush), so a result is never above its call. A crash before that leaves the session's record, which the next open
|
|
341
|
+
* writes from (settleCutCalls). */
|
|
342
|
+
const deferred = new Map();
|
|
343
|
+
/** The side calls' requests (a title, a summary on another model): their cost is their own, never the content's. */
|
|
344
|
+
const sides = new Set();
|
|
345
|
+
/** What each earlier request streamed, closed at the next request's start, oldest first, waiting to be written with its
|
|
346
|
+
* own request's cost (flush). */
|
|
347
|
+
const segments = [];
|
|
348
|
+
/** The calls the root holds from an earlier process (read at the open): one run again after a crash is not written twice. */
|
|
349
|
+
const onRoot = new Set();
|
|
176
350
|
const results = new Map();
|
|
177
351
|
let run;
|
|
178
352
|
let session;
|
|
353
|
+
// The session's open while it is under way, and whether the door's close has come: a session that lands after the
|
|
354
|
+
// close is closed then (closeOnce), never left open by a process that is going.
|
|
355
|
+
let opening;
|
|
356
|
+
let closing = false;
|
|
357
|
+
// One close per session, its promise shared: whichever caller starts it (the door's close, or an open that lands after
|
|
358
|
+
// it), every caller awaits the same close to its end, and its failure reaches the door (its log line).
|
|
359
|
+
const closes = new WeakMap();
|
|
360
|
+
const closeOnce = (it) => {
|
|
361
|
+
if (!it)
|
|
362
|
+
return Promise.resolve();
|
|
363
|
+
let done = closes.get(it);
|
|
364
|
+
if (!done) {
|
|
365
|
+
done = Promise.resolve().then(() => it.close());
|
|
366
|
+
closes.set(it, done);
|
|
367
|
+
}
|
|
368
|
+
return done;
|
|
369
|
+
};
|
|
179
370
|
let opened;
|
|
180
371
|
let openedDone = () => { };
|
|
181
372
|
opened = new Promise((resolve) => (openedDone = resolve));
|
|
@@ -207,6 +398,8 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
207
398
|
// Requests admitted and not yet booked, by turn: the proxy answers the harness before it books a response, so a turn
|
|
208
399
|
// can end with its last request's cost still on its way.
|
|
209
400
|
const open = new Set();
|
|
401
|
+
// The requests in flight that the run sent beside the harness's (their host label), each booked on its own.
|
|
402
|
+
const hosts = new Set();
|
|
210
403
|
// The model each request asked for, by number: its entry names it.
|
|
211
404
|
const models = new Map();
|
|
212
405
|
let booked = () => { };
|
|
@@ -222,7 +415,12 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
222
415
|
// Writes in order, one at a time: the entries keep the order their events came in.
|
|
223
416
|
let writing = Promise.resolve();
|
|
224
417
|
const later = (work) => (writing = writing.then(work, work));
|
|
225
|
-
|
|
418
|
+
// A test's seam (ROOT_WRITE_DELAY_ENV): each root write waits first, as on a store slow to write. None outside a test runner.
|
|
419
|
+
const slowWrites = rootWriteDelayMs();
|
|
420
|
+
// A test's seam (START_MARK_FAIL_ENV): the Nth paid request's start mark fails to commit, once. None outside a test runner.
|
|
421
|
+
const failMarkAt = startMarkFailAt();
|
|
422
|
+
let marks = 0;
|
|
423
|
+
const commit = (change) => (slowWrites ? new Promise((resolve) => setTimeout(resolve, slowWrites)).then(() => run.harness.commit(change, context)) : run.harness.commit(change, context));
|
|
226
424
|
/** A cost for a request already written: one written at unknown cost (below) gets its cost now, as an entry of its
|
|
227
425
|
* own (one of `writes`, the flush's commit), so the run's spend counts it, once; any other is a duplicate. */
|
|
228
426
|
const priceLate = (late, writes) => {
|
|
@@ -233,8 +431,10 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
233
431
|
priced.add(late.request);
|
|
234
432
|
};
|
|
235
433
|
const writtenAt = () => costed.findIndex((c) => written.has(c.request));
|
|
236
|
-
/** Writes
|
|
237
|
-
*
|
|
434
|
+
/** Writes each request's content as its own entry, with that request's own cost: first the segments closed at a
|
|
435
|
+
* request's start (what the request before it streamed), in order, then what the current request has so far.
|
|
436
|
+
* Content with no cost yet waits for its own, and holds every later one behind it, but at a turn's end (`final`) it
|
|
437
|
+
* is written as a request of unknown cost. A side call's cost, and a cost with no content, is an entry of its own.
|
|
238
438
|
* Everything a flush writes is one commit, and `end` (a turn's end: its error and TURN_END) is the last of it, so a
|
|
239
439
|
* turn's end is in the commit of its last entries. The bookkeeping goes first: a commit the store refuses ends the
|
|
240
440
|
* process, and the next open reads the root again. */
|
|
@@ -251,18 +451,66 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
251
451
|
// late cost can come in after a later request's.
|
|
252
452
|
for (let at = writtenAt(); at >= 0; at = writtenAt())
|
|
253
453
|
priceLate(costed.splice(at, 1)[0], writes);
|
|
254
|
-
|
|
454
|
+
// A side call's cost (a title, a summary: no content of the session's) is its own entry, cost only, whenever it
|
|
455
|
+
// comes in: never the cost of the content streaming meanwhile.
|
|
456
|
+
for (let at = costed.findIndex((c) => sides.has(c.request)); at >= 0; at = costed.findIndex((c) => sides.has(c.request)))
|
|
457
|
+
costOnly(costed.splice(at, 1)[0], writes);
|
|
458
|
+
// The segments, oldest first: each written with its own request's cost, or waiting for it.
|
|
459
|
+
while (segments.length && entryOf(segments[0], final, writes))
|
|
460
|
+
segments.shift();
|
|
461
|
+
if (segments.length)
|
|
255
462
|
return commitAll();
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
463
|
+
// Then what the current request has so far.
|
|
464
|
+
if (text || calls.length) {
|
|
465
|
+
const content = { request: current, text, calls };
|
|
466
|
+
if (entryOf(content, final, writes)) {
|
|
467
|
+
text = "";
|
|
468
|
+
calls = [];
|
|
469
|
+
}
|
|
470
|
+
else
|
|
471
|
+
return commitAll();
|
|
472
|
+
}
|
|
473
|
+
// More costs than content: each later one still gets its own entry, cost only, or is a late cost.
|
|
474
|
+
while (costed.length)
|
|
475
|
+
costOnly(costed.shift(), writes);
|
|
476
|
+
await commitAll();
|
|
477
|
+
});
|
|
478
|
+
/** `content`'s entry, as its request's (`content.request`), into `writes`: with that request's own cost when it is in;
|
|
479
|
+
* else, at a turn's end, at an unknown cost, booked so a later open never writes it again; else not yet (false). The
|
|
480
|
+
* content of a request already written is its continuation, shown and never counted again. */
|
|
481
|
+
const entryOf = (content, final, writes) => {
|
|
482
|
+
const owner = content.request;
|
|
483
|
+
const results = async (tx) => {
|
|
484
|
+
// The results of its calls that ended before this entry was written, in order, right after it.
|
|
485
|
+
for (const call of content.calls) {
|
|
486
|
+
const result = deferred.get(call.id);
|
|
487
|
+
deferred.delete(call.id);
|
|
488
|
+
if (result)
|
|
489
|
+
await result(tx);
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
if (owner !== undefined && answered.has(owner)) {
|
|
493
|
+
writes.push(async (tx) => {
|
|
494
|
+
await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: REQUEST_CONTINUED, data: { key: spec.key, request: owner } });
|
|
495
|
+
const entry = await tx.appendEntry(AssistantEntry, ROOT_CONVERSATION_ID, { model: [assistantMessage(harness, models.get(owner), undefined, content.text, content.calls)] });
|
|
496
|
+
if (content.text && !content.calls.length)
|
|
497
|
+
answer = entry.id;
|
|
498
|
+
await results(tx);
|
|
499
|
+
});
|
|
500
|
+
return true;
|
|
501
|
+
}
|
|
502
|
+
const at = owner === undefined ? (costed.length ? 0 : -1) : costed.findIndex((c) => c.request === owner);
|
|
503
|
+
if (at < 0 && !final)
|
|
504
|
+
return false;
|
|
505
|
+
const request = at >= 0 ? costed.splice(at, 1)[0] : undefined;
|
|
506
|
+
// At a turn's end with no cost in: its own request, still unbooked, is written at unknown cost and marked booked.
|
|
507
|
+
// Content with no request of this process's own (a call a resumed turn ran before any request here) is the oldest
|
|
508
|
+
// session request still unbooked: never a side call's or the host's own, which stream nothing of the session's.
|
|
509
|
+
const mains = owner === undefined ? [...open].filter((r) => !sides.has(r) && !hosts.has(r)) : [];
|
|
510
|
+
const unbooked = !request ? (owner !== undefined && open.has(owner) ? owner : mains.length ? Math.min(...mains) : undefined) : undefined;
|
|
263
511
|
if (unbooked !== undefined)
|
|
264
512
|
open.delete(unbooked);
|
|
265
|
-
const marked = request?.request ?? unbooked;
|
|
513
|
+
const marked = request?.request ?? unbooked ?? owner;
|
|
266
514
|
if (marked !== undefined)
|
|
267
515
|
answered.add(marked);
|
|
268
516
|
writes.push(async (tx) => {
|
|
@@ -275,6 +523,7 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
275
523
|
await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: REQUEST_COST_PENDING, data: { key: spec.key, request: unbooked } });
|
|
276
524
|
if (marked !== undefined)
|
|
277
525
|
await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: BOOKED, data: { key: spec.key, request: marked, ...(request ? {} : { unpriced: true }) } });
|
|
526
|
+
await results(tx);
|
|
278
527
|
});
|
|
279
528
|
if (marked !== undefined)
|
|
280
529
|
written.add(marked);
|
|
@@ -282,59 +531,173 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
282
531
|
priced.add(request.request);
|
|
283
532
|
else if (marked !== undefined)
|
|
284
533
|
unpriced.add(marked);
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
await commitAll();
|
|
302
|
-
});
|
|
534
|
+
return true;
|
|
535
|
+
};
|
|
536
|
+
/** A request's cost with no content of its own (a side call's, or more costs than content): its own entry, cost only,
|
|
537
|
+
* or for a request already written, its late cost. */
|
|
538
|
+
const costOnly = (next, writes) => {
|
|
539
|
+
if (written.has(next.request))
|
|
540
|
+
return priceLate(next, writes);
|
|
541
|
+
answered.add(next.request);
|
|
542
|
+
writes.push(async (tx) => {
|
|
543
|
+
await tx.appendEntry(AssistantEntry, ROOT_CONVERSATION_ID, { model: [assistantMessage(harness, models.get(next.request), next, "", [])] });
|
|
544
|
+
await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: BOOKED, data: { key: spec.key, request: next.request } });
|
|
545
|
+
});
|
|
546
|
+
written.add(next.request);
|
|
547
|
+
priced.add(next.request);
|
|
548
|
+
};
|
|
303
549
|
const onModel = (event) => {
|
|
304
550
|
if (event.type === "request_start") {
|
|
305
551
|
inFlight.started(event.turn);
|
|
306
|
-
|
|
552
|
+
// Its bound, on its start mark: the run's cost serves it while it is in flight (runs.ts).
|
|
553
|
+
const admitted = admittedNext;
|
|
554
|
+
admittedNext = undefined;
|
|
555
|
+
if (admitted)
|
|
556
|
+
sentOf.set(event.turn, admitted);
|
|
557
|
+
if (admitted?.note && wrap.pending && wrap.pending.turn === undefined)
|
|
558
|
+
wrap.pending.turn = event.turn;
|
|
559
|
+
const bound = admitted && admitted.boundUsd > 0 ? { [BOUND_FIELD]: admitted.boundUsd } : {};
|
|
560
|
+
// A request the run sends beside the harness's (its host label: a learned workflow's node) is the session's like
|
|
561
|
+
// any, marked as it leaves and booked once it answers, but it is never the harness's current request: the harness's
|
|
562
|
+
// text and calls are never its content, and its entry holds its cost alone, once, at its end (below), never through
|
|
563
|
+
// the side calls' cost-only entries. A side call of the harness's own (a title, a summary) streams nothing of the
|
|
564
|
+
// session's: what streams meanwhile stays the current request's. Any other request of the session's closes what
|
|
565
|
+
// the one before it streamed, now, as that request's own segment (flush writes it with that request's cost), before
|
|
566
|
+
// anything of the new one can stream.
|
|
567
|
+
if (event.host !== undefined)
|
|
568
|
+
hosts.add(event.turn);
|
|
569
|
+
else if (admitted?.side)
|
|
570
|
+
sides.add(event.turn);
|
|
571
|
+
else {
|
|
572
|
+
if (text || calls.length)
|
|
573
|
+
segments.push({ request: current, text, calls });
|
|
574
|
+
text = "";
|
|
575
|
+
calls = [];
|
|
576
|
+
current = event.turn;
|
|
577
|
+
}
|
|
307
578
|
open.add(event.turn);
|
|
308
579
|
models.set(event.turn, event.model);
|
|
309
580
|
void flush();
|
|
310
|
-
// Marked on the root
|
|
311
|
-
// without opening again (cancelled, or failed) reads as cut, its cost unknown, never as the sum without it.
|
|
312
|
-
//
|
|
313
|
-
|
|
581
|
+
// Marked on the root before it leaves, as a pi run's request is (request-start.ts): one never answered, a run that
|
|
582
|
+
// ends without opening again (cancelled, or failed) reads as cut, its cost unknown, never as the sum without it.
|
|
583
|
+
// The runner awaits this before the request is sent, and the mark is synced first, so a lost box never loses the
|
|
584
|
+
// mark of a request that went. A mark that fails refuses the request.
|
|
585
|
+
const failMark = failMarkAt !== undefined && ++marks === failMarkAt;
|
|
586
|
+
return later(async () => {
|
|
587
|
+
if (failMark)
|
|
588
|
+
throw new Error("the store refused the start mark (a test's seam)");
|
|
589
|
+
await commit(async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: REQUEST_STARTED, data: { key: spec.key, request: event.turn, ...bound, ...(event.host === undefined ? {} : { host: event.host }) } })));
|
|
590
|
+
})
|
|
591
|
+
.then(() => syncNow(run?.store, BARRIER.sideRequestStarted))
|
|
592
|
+
.catch((error) => {
|
|
593
|
+
// A mark that fails refuses the request, which never leaves and ends with no request_end: nothing of it stays in
|
|
594
|
+
// flight (its hold would make every later request look dearer), and a note it carried is left for the next one.
|
|
595
|
+
open.delete(event.turn);
|
|
596
|
+
inFlight.ended(event.turn);
|
|
597
|
+
sentOf.delete(event.turn);
|
|
598
|
+
if (wrap.pending?.turn === event.turn)
|
|
599
|
+
wrap.pending = undefined;
|
|
600
|
+
throw error;
|
|
601
|
+
});
|
|
314
602
|
}
|
|
315
603
|
else {
|
|
316
604
|
open.delete(event.turn);
|
|
317
605
|
inFlight.ended(event.turn);
|
|
606
|
+
// The previous request on its model, now: its usage, as the cap reads it (none when its cost or usage is unknown,
|
|
607
|
+
// or it was cut: nothing cached to count on). A host request's is never the harness's previous one.
|
|
608
|
+
const sent = sentOf.get(event.turn);
|
|
609
|
+
sentOf.delete(event.turn);
|
|
610
|
+
// The request that carried the note ended: told only when it ended answered. An error status, a loss, a cut, our stop
|
|
611
|
+
// or a request that never left leave the note for the next request. Every path that can carry the note says how its
|
|
612
|
+
// request ended (the model proxy, the runner's own withdrawals and cut bookings, the faux harness); only side calls
|
|
613
|
+
// and host requests, which never carry it, may say nothing.
|
|
614
|
+
// A host request never carries or settles the note.
|
|
615
|
+
if (wrap.pending && event.host === undefined && wrap.pending.turn === event.turn) {
|
|
616
|
+
const { data } = wrap.pending;
|
|
617
|
+
wrap.pending = undefined;
|
|
618
|
+
if (event.ended?.end === "answered") {
|
|
619
|
+
wrap.sent = true;
|
|
620
|
+
writeRow(data);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
// A priced request of the session's own model: the wrap-up's typical cost counts it (step 0 ends with the first; a
|
|
624
|
+
// side call, the host's own among them, it never counts).
|
|
625
|
+
const costUsd = pricedUsd(event.usage.usd);
|
|
626
|
+
if (sent && !sent.side && costUsd !== undefined)
|
|
627
|
+
wrap.costs.push(costUsd);
|
|
628
|
+
const last = sent && !sent.host && event.usage.usd !== null && !event.usage.cut ? previousOf(event.usage, sent.inputTokensMax, now()) : undefined;
|
|
629
|
+
if (sent && !sent.host)
|
|
630
|
+
last ? previous.set(sent.model, last) : previous.delete(sent.model);
|
|
631
|
+
if (event.host !== undefined || hosts.has(event.turn)) {
|
|
632
|
+
// Its own entry, its cost alone, and its BOOKED marker (which closes its bound, bounds.ts), once: never the
|
|
633
|
+
// content of the harness's request.
|
|
634
|
+
hosts.delete(event.turn);
|
|
635
|
+
booked();
|
|
636
|
+
if (written.has(event.turn))
|
|
637
|
+
return;
|
|
638
|
+
written.add(event.turn);
|
|
639
|
+
answered.add(event.turn);
|
|
640
|
+
priced.add(event.turn);
|
|
641
|
+
const host = event.host;
|
|
642
|
+
later(() => commit(async (tx) => {
|
|
643
|
+
await tx.appendEntry(AssistantEntry, ROOT_CONVERSATION_ID, { model: [assistantMessage(harness, models.get(event.turn), { request: event.turn, usage: event.usage }, "", [])] });
|
|
644
|
+
await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: BOOKED, data: { key: spec.key, request: event.turn, ...(host === undefined ? {} : { host }) } });
|
|
645
|
+
})).catch(() => undefined);
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
318
648
|
costed.push({ request: event.turn, usage: event.usage });
|
|
319
649
|
booked();
|
|
320
650
|
// A cost that came in after its answer was written goes in now, not at some later flush, and so does one that came
|
|
321
651
|
// in with no turn running, which no turn's flush would write. If that write fails, the next open writes it from
|
|
322
652
|
// the session's booking, once.
|
|
323
|
-
|
|
653
|
+
// And content with a call waits for this cost to be written: the call shows from then.
|
|
654
|
+
if (written.has(event.turn) || turn === undefined || calls.length || segments.length)
|
|
324
655
|
flush().catch(() => undefined);
|
|
325
656
|
}
|
|
326
657
|
};
|
|
658
|
+
/** Each call the session recorded (`tool:<id>`) with no result on the root: a process died before it wrote one. Its
|
|
659
|
+
* result is written from the session's record of it: its outcome, or for a `never` call with none, interrupted (the
|
|
660
|
+
* kernel records that as the session opens again); its call first when the root never got it. A `safe` call with no
|
|
661
|
+
* outcome runs again and reports itself. */
|
|
662
|
+
const settleCutCalls = (records, resulted) => later(async () => {
|
|
663
|
+
const writes = [];
|
|
664
|
+
for (const effect of foldSession("", records).effectOrder) {
|
|
665
|
+
const callId = effect.key.startsWith("tool:") ? effect.key.slice("tool:".length) : undefined;
|
|
666
|
+
if (callId === undefined || resulted.has(callId) || (effect.status !== "completed" && effect.status !== "failed" && !(effect.status === "running" && effect.replay === "never")))
|
|
667
|
+
continue;
|
|
668
|
+
const name = effect.name.replace(/^tool\./, "");
|
|
669
|
+
const isError = effect.status !== "completed";
|
|
670
|
+
const said = effect.status === "completed" ? outputText(effect.output) : effect.status === "failed" ? failureText(effect.error ?? { message: "failed" }) : INTERRUPTED_TEXT;
|
|
671
|
+
if (!onRoot.has(callId)) {
|
|
672
|
+
const call = { type: "toolCall", id: callId, name, arguments: (effect.input ?? {}) };
|
|
673
|
+
writes.push(async (tx) => {
|
|
674
|
+
await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: REQUEST_CONTINUED, data: { key: spec.key, request: null } });
|
|
675
|
+
await tx.appendEntry(AssistantEntry, ROOT_CONVERSATION_ID, { model: [assistantMessage(harness, undefined, undefined, "", [call])] });
|
|
676
|
+
});
|
|
677
|
+
onRoot.add(callId);
|
|
678
|
+
}
|
|
679
|
+
writes.push((tx) => tx.appendEntry(ToolResultEntry, ROOT_CONVERSATION_ID, { model: [{ role: "toolResult", toolCallId: callId, toolName: name, content: [{ type: "text", text: said }], isError, timestamp: now() }], data: { diagnostics: [] } }));
|
|
680
|
+
}
|
|
681
|
+
if (writes.length)
|
|
682
|
+
await commit(async (tx) => { for (const write of writes)
|
|
683
|
+
await write(tx); });
|
|
684
|
+
});
|
|
327
685
|
const onEvent = (event) => {
|
|
328
686
|
if (event.type === "text")
|
|
329
687
|
text += event.delta;
|
|
330
688
|
else if (event.type === "tool_start") {
|
|
331
689
|
const call = { type: "toolCall", id: event.callId, name: event.name, arguments: (event.args ?? {}) };
|
|
332
690
|
argsOf.set(event.callId, event.args ?? {});
|
|
691
|
+
if (onRoot.has(event.callId))
|
|
692
|
+
return;
|
|
333
693
|
// A call of the current request's answer after that answer's entry was written (at its first call's end): written
|
|
334
694
|
// now as the answer's continuation, so its result never comes before it and the next answer never holds it.
|
|
335
695
|
const request = current;
|
|
336
|
-
|
|
696
|
+
// Written as soon as its request's cost is in (now, or when it comes in), so the call shows while it runs.
|
|
697
|
+
if (text || calls.length || request === undefined || !answered.has(request)) {
|
|
337
698
|
calls.push(call);
|
|
699
|
+
void flush();
|
|
700
|
+
}
|
|
338
701
|
else {
|
|
339
702
|
later(() => commit(async (tx) => {
|
|
340
703
|
await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: REQUEST_CONTINUED, data: { key: spec.key, request } });
|
|
@@ -343,16 +706,26 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
343
706
|
}
|
|
344
707
|
}
|
|
345
708
|
else if (event.type === "tool_end") {
|
|
709
|
+
const said = results.get(event.callId)?.text ?? (event.isError ? "The tool failed." : "Done.");
|
|
710
|
+
const result = (tx) => tx.appendEntry(ToolResultEntry, ROOT_CONVERSATION_ID, {
|
|
711
|
+
model: [{ role: "toolResult", toolCallId: event.callId, toolName: event.name, content: [{ type: "text", text: said }], isError: event.isError, timestamp: now() }],
|
|
712
|
+
data: { diagnostics: [] },
|
|
713
|
+
});
|
|
714
|
+
// A result is written only after its call's entry is on the root. A call still in the answer not yet written (one
|
|
715
|
+
// that ended before its request's cost came in) has its result written with that entry, right after it; any other
|
|
716
|
+
// call's entry is written, or queued, before this result.
|
|
717
|
+
const waiting = calls.some((call) => call.id === event.callId) || segments.some((segment) => segment.calls.some((call) => call.id === event.callId));
|
|
718
|
+
if (waiting)
|
|
719
|
+
deferred.set(event.callId, result);
|
|
346
720
|
void flush();
|
|
347
|
-
|
|
348
|
-
await tx.
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
// The parked call's result is in: its turn ends here, settled once the interrupt is done (runTurns).
|
|
721
|
+
if (!waiting)
|
|
722
|
+
later(() => commit(async (tx) => void (await result(tx))).then(() => undefined));
|
|
723
|
+
// The parked call's result is in: its turn ends here, settled once the interrupt is done (runTurns). The CLI runs a
|
|
724
|
+
// tool as soon as its call has streamed, before the request that asked for it has ended (its usage comes with that
|
|
725
|
+
// end): the interrupt waits for the requests in flight to be booked, up to BOOKING_WAIT_MS, so that request is booked
|
|
726
|
+
// at its price. Past the wait it is cut as before, its cost unknown. No request leaves meanwhile (PARKED).
|
|
354
727
|
if (endsTurn(parked, { callId: event.callId, tool: event.name, args: argsOf.get(event.callId) }) && !stopping)
|
|
355
|
-
stopping = session?.interrupt();
|
|
728
|
+
stopping = bookings(BOOKING_WAIT_MS).then(() => session?.interrupt());
|
|
356
729
|
}
|
|
357
730
|
};
|
|
358
731
|
/** The session's requests, from its runner records, by number: the model each asked for, and the usage of each it
|
|
@@ -379,13 +752,32 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
379
752
|
/** The person's message: the session's new turn, then its entry and its end on the root. */
|
|
380
753
|
const sendOf = (message) => async () => {
|
|
381
754
|
parked = undefined;
|
|
755
|
+
approved = false;
|
|
382
756
|
argsOf.clear();
|
|
383
757
|
await message.recorded;
|
|
384
758
|
taking = message.id;
|
|
385
|
-
|
|
759
|
+
wrap.entryDue = true;
|
|
760
|
+
try {
|
|
761
|
+
await session.send(message.content);
|
|
762
|
+
}
|
|
763
|
+
catch (error) {
|
|
764
|
+
// No message entry follows: a row held for it is written as it is.
|
|
765
|
+
const row = wrap.row;
|
|
766
|
+
wrap.entryDue = false;
|
|
767
|
+
wrap.row = undefined;
|
|
768
|
+
if (row)
|
|
769
|
+
later(() => commit(async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: CAP_WRAPUP, data: row })))).catch(() => undefined);
|
|
770
|
+
throw error;
|
|
771
|
+
}
|
|
386
772
|
await later(() => commit(async (tx) => {
|
|
387
773
|
await tx.appendEntry(UserEntry, ROOT_CONVERSATION_ID, { model: [{ role: "user", content: [{ type: "text", text: message.content }], timestamp: now() }], ...(message.origin ? { data: { origin: message.origin } } : {}) });
|
|
388
774
|
await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: MESSAGE_END, data: { key: spec.key, id: message.id, sent: true } });
|
|
775
|
+
// A wrap-up told in this turn's first request: its row after the message it answers.
|
|
776
|
+
const row = wrap.row;
|
|
777
|
+
wrap.entryDue = false;
|
|
778
|
+
wrap.row = undefined;
|
|
779
|
+
if (row)
|
|
780
|
+
await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: CAP_WRAPUP, data: row });
|
|
389
781
|
}).then(() => undefined));
|
|
390
782
|
};
|
|
391
783
|
/** Turns until nothing waits: the turn, then each message that waited for it, as one busy period on the door (as a pi
|
|
@@ -457,7 +849,7 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
457
849
|
if (why !== undefined) {
|
|
458
850
|
// A refusal of the cap's: a start mark of its own first, as pi's is, so the run's usage counts no request for it.
|
|
459
851
|
if (unsent)
|
|
460
|
-
await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: REQUEST_STARTED, data: { [CAP_REFUSED_FIELD]: true, ...(figures
|
|
852
|
+
await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: REQUEST_STARTED, data: { [CAP_REFUSED_FIELD]: true, ...refusalFields(figures) } });
|
|
461
853
|
await tx.appendEntry(AssistantEntry, ROOT_CONVERSATION_ID, { model: [assistantMessage(harness, undefined, undefined, "", [], why)] });
|
|
462
854
|
}
|
|
463
855
|
const data = {
|
|
@@ -489,10 +881,11 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
489
881
|
const CRASH_SEAM = process.env.AGENTRUN_SERVE_TEST_CRASH_AFTER_ANSWER;
|
|
490
882
|
let answerRecorded;
|
|
491
883
|
const answerIn = new Promise((resolve) => (answerRecorded = resolve));
|
|
492
|
-
const resume = async (id, content, mark) => {
|
|
884
|
+
const resume = async (id, content, mark, origin) => {
|
|
493
885
|
await opened;
|
|
494
|
-
|
|
495
|
-
|
|
886
|
+
// The server's message: its origin is written on its user entry, so the Timeline never shows it as the person's.
|
|
887
|
+
const message = { id: `approval-${id}`, content, ...(origin ? { origin } : {}), recorded: commit(async (tx) => {
|
|
888
|
+
await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: MESSAGE, data: { key: spec.key, id: `approval-${id}`, content, ...(origin ? { origin } : {}) } });
|
|
496
889
|
await mark(tx);
|
|
497
890
|
}) };
|
|
498
891
|
await message.recorded;
|
|
@@ -550,13 +943,26 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
550
943
|
await stopping;
|
|
551
944
|
return "aborted";
|
|
552
945
|
},
|
|
946
|
+
// The process is letting the run go (the door's stop, busy or idle, after its abort): the session closes, which stops
|
|
947
|
+
// the harness's own processes (its CLI, its app-server), so none outlives this one.
|
|
948
|
+
async close() {
|
|
949
|
+
closing = true;
|
|
950
|
+
if (session)
|
|
951
|
+
return closeOnce(session);
|
|
952
|
+
// An open still under way is stopped where the adapter can stop it (its signal), and the session it lands with is
|
|
953
|
+
// closed here, within the door's bound, or by the open itself once it lands (above).
|
|
954
|
+
stop.abort();
|
|
955
|
+
await closeOnce(await opening?.catch(() => undefined));
|
|
956
|
+
},
|
|
957
|
+
harness,
|
|
553
958
|
busy: () => turn !== undefined,
|
|
554
959
|
};
|
|
555
960
|
return {
|
|
556
961
|
door,
|
|
962
|
+
port: (label) => session?.port?.(label),
|
|
557
963
|
async onOpen(durable) {
|
|
558
964
|
run = durable;
|
|
559
|
-
const sessions = durableSessions(durable.harness, context);
|
|
965
|
+
const sessions = durableSessions(durable.harness, context, durable.store);
|
|
560
966
|
// The requests already written on the root, and the messages accepted and never sent, from any earlier process.
|
|
561
967
|
const root = await durable.harness.conversation(ROOT_CONVERSATION_ID, context);
|
|
562
968
|
const accepted = new Map();
|
|
@@ -568,6 +974,8 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
568
974
|
// The person's messages on the root: the newest one's entry id, and how many, for the run's stop record.
|
|
569
975
|
let lastUser;
|
|
570
976
|
let users = 0;
|
|
977
|
+
// The calls whose result the root holds.
|
|
978
|
+
const resulted = new Set();
|
|
571
979
|
for (let cursor; root;) {
|
|
572
980
|
const page = await root.entries({ order: "ascending" }, 500, cursor, context);
|
|
573
981
|
for (const entry of page.items) {
|
|
@@ -583,8 +991,17 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
583
991
|
users += 1;
|
|
584
992
|
lastUser = Number(entry.id);
|
|
585
993
|
}
|
|
994
|
+
if (message?.api === ADAPTER_API)
|
|
995
|
+
for (const block of message.content ?? [])
|
|
996
|
+
if (block?.type === "toolCall" && typeof block.id === "string")
|
|
997
|
+
onRoot.add(block.id);
|
|
998
|
+
if (message?.role === "toolResult" && typeof message.toolCallId === "string")
|
|
999
|
+
resulted.add(message.toolCallId);
|
|
586
1000
|
if (data?.key !== spec.key)
|
|
587
1001
|
continue;
|
|
1002
|
+
// The wrap-up was told under this very cap in an earlier process: once per cap (a raise's new cap re-arms it).
|
|
1003
|
+
if (entry.kind === CAP_WRAPUP && budgetUsd !== undefined && typeof data.capUsd === "number" && Math.abs(data.capUsd - budgetUsd) <= CAP_TOLERANCE)
|
|
1004
|
+
wrap.sent = true;
|
|
588
1005
|
if (entry.kind === BOOKED && typeof data.request === "number") {
|
|
589
1006
|
written.add(data.request);
|
|
590
1007
|
(data.unpriced === true ? unpriced : priced).add(data.request);
|
|
@@ -614,6 +1031,16 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
614
1031
|
const adapter = await make(confineOf(env.confinePrefix()));
|
|
615
1032
|
const writer = await sessions.open(spec.key);
|
|
616
1033
|
const records = await writer.read();
|
|
1034
|
+
// The session's own model's priced requests in earlier processes, in order: the wrap-up's typical cost reads them.
|
|
1035
|
+
wrap.costs.push(...ownCosts(records));
|
|
1036
|
+
// Told in an earlier process: a request that carried the note under this cap and ended answered (its runner.turn,
|
|
1037
|
+
// written as its cost was, keeps the note). Its row is display only: one lost (a commit that failed) is written
|
|
1038
|
+
// again now. A request that ended unanswered, or that a crash cut (booked cut, with no note), told nothing.
|
|
1039
|
+
const told = toldIn(records, budgetUsd);
|
|
1040
|
+
if (told && !wrap.sent) {
|
|
1041
|
+
wrap.sent = true;
|
|
1042
|
+
later(() => commit(async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: CAP_WRAPUP, data: told })))).catch(() => undefined);
|
|
1043
|
+
}
|
|
617
1044
|
// Before the cut requests are booked, which may write their entries.
|
|
618
1045
|
for (const [request, model] of inSession(records).asked)
|
|
619
1046
|
models.set(request, model);
|
|
@@ -623,7 +1050,17 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
623
1050
|
...(budgetUsd !== undefined ? { budgetUsd } : {}),
|
|
624
1051
|
beforeRequest: guard,
|
|
625
1052
|
onEvent: onModel,
|
|
626
|
-
|
|
1053
|
+
// The booking's spend is the run's one meter (a learned node's requests are the session's: no side spend of their own).
|
|
1054
|
+
note: (model, request) => takeNote(plus(booking.spentUsd(), charged), model, request),
|
|
1055
|
+
stopped: (request) => {
|
|
1056
|
+
const why = halted ?? cancelStop() ?? (parked === undefined || (approved && request.host !== undefined) ? undefined : PARKED);
|
|
1057
|
+
// A stop refuses this request, and each one after it but an approved host request (which never carries the
|
|
1058
|
+
// note): a note an admission gave a request the stop then refused never left, so the next request takes it,
|
|
1059
|
+
// before the model proxy asks for it (takeNote), not only at that request's own check.
|
|
1060
|
+
if (why && wrap.pending && wrap.pending.turn === undefined)
|
|
1061
|
+
wrap.pending = undefined;
|
|
1062
|
+
return why;
|
|
1063
|
+
},
|
|
627
1064
|
stop: (reason, message) => {
|
|
628
1065
|
const error = new Error(message ?? reason);
|
|
629
1066
|
if (reason === "model_error" && !halted) {
|
|
@@ -635,15 +1072,14 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
635
1072
|
});
|
|
636
1073
|
// A request a crash cut off is booked once, unknown, before anything is sent.
|
|
637
1074
|
await booking.bookCut();
|
|
638
|
-
// A paid tool's check before it spends: the session's requests
|
|
639
|
-
// for, as at a turn's end), one still in flight at the worst case the cap
|
|
640
|
-
//
|
|
641
|
-
// requests read the same total at once (`now`: capModels' `joined`), a request in flight held, never less.
|
|
1075
|
+
// A paid tool's check before it spends: the session's requests (the run's own beside the harness's among them), each
|
|
1076
|
+
// booked once the proxy has answered (waited for, as at a turn's end), one still in flight at the worst case the cap
|
|
1077
|
+
// held for it (as pi's spend counts it), with the run's charges; its charge joins them.
|
|
642
1078
|
if (budgetUsd !== undefined) {
|
|
643
|
-
const now = () => plus(plus(
|
|
1079
|
+
const now = () => plus(plus(booking.spentUsd(), charged), inFlight.total());
|
|
644
1080
|
spend = {
|
|
645
1081
|
cap: budgetUsd,
|
|
646
|
-
spent: async () => (await bookings(BOOKING_WAIT_MS), plus(
|
|
1082
|
+
spent: async () => (await bookings(BOOKING_WAIT_MS), plus(booking.spentUsd(), charged)),
|
|
647
1083
|
held: () => inFlight.total(),
|
|
648
1084
|
add: (usd) => void (charged = plus(charged, usd)),
|
|
649
1085
|
now,
|
|
@@ -656,12 +1092,28 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
656
1092
|
if (!written.has(request) || (unpriced.has(request) && !priced.has(request)))
|
|
657
1093
|
costed.push({ request, usage });
|
|
658
1094
|
await flush();
|
|
1095
|
+
await settleCutCalls(records, resulted);
|
|
659
1096
|
// The calls that wait for a person's approval, read before any turn goes on.
|
|
660
1097
|
await gate?.load(durable, context, coding, extra);
|
|
661
1098
|
// The park every gated call of the run's takes, built once: the host tools' here, and the MCP gateway's, which takes
|
|
662
1099
|
// the same object beside them (`{ gate, park }`). A call parked by its id or by its tool and arguments ends its turn.
|
|
663
1100
|
const park = { commit: (change) => commit(change), parked: (callId) => void (parked = { callId }), parkedBy: (match) => void (parked = match), turn: () => taking };
|
|
664
|
-
|
|
1101
|
+
// An MCP call from the harness's own client takes the same park, and its result is kept by its call id too, for the
|
|
1102
|
+
// root's record of it, as a host tool's is.
|
|
1103
|
+
const gateway = spec.mcp;
|
|
1104
|
+
const mcp = gateway && { ...gateway, call: async (...[server, tool, args, call]) => {
|
|
1105
|
+
const result = await gateway.call(server, tool, args, { ...call, ...(gate ? { park } : {}) });
|
|
1106
|
+
if (call.callId)
|
|
1107
|
+
results.set(call.callId, { text: result.content.map((block) => block.text).join("\n\n"), isError: result.isError === true });
|
|
1108
|
+
return result;
|
|
1109
|
+
} };
|
|
1110
|
+
opening = adapter.open({ ...spec, ...(mcp ? { mcp } : {}), tools: hostTools(durable, tools, context, results, coding, gate ? { gate, park } : undefined, extra) }, { writer, models: booking.models, signal: stop.signal, onEvent, ...(dir ? { dir } : {}), ...(cwd ? { cwd } : {}) });
|
|
1111
|
+
session = await opening;
|
|
1112
|
+
// The door closed while it opened (the process is going): this session is closed now, and nothing goes on in it.
|
|
1113
|
+
// `closing` is set by the door's close alone, which awaits this same close (closeOnce) and logs its failure; the open
|
|
1114
|
+
// waits for it too, and does not fail on it a second time.
|
|
1115
|
+
if (closing)
|
|
1116
|
+
return void (await closeOnce(session).catch(() => undefined));
|
|
665
1117
|
// A turn the person stopped is still open in the session (an interrupt writes no end there), and it is not resumed.
|
|
666
1118
|
// The run's stop record names the person's newest message when they stopped: with no message on the root newer than
|
|
667
1119
|
// it, the open turn is the stopped one. The session settles it, ended interrupted, and the next message is a turn of
|
|
@@ -702,7 +1154,9 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
702
1154
|
runTurns(restored ? async () => (await restore(restored), await next()) : next);
|
|
703
1155
|
}
|
|
704
1156
|
// The answers from now on: each resumes the session with one message of its own.
|
|
705
|
-
|
|
1157
|
+
// The allow un-parks the run before the approved call runs: its own model requests (a learned workflow's node, on
|
|
1158
|
+
// the session's route) go out; the harness's own wait for the resume's turn, which the park left them for.
|
|
1159
|
+
gate?.start(resume, () => void (approved = true));
|
|
706
1160
|
},
|
|
707
1161
|
};
|
|
708
1162
|
}
|