@parcha/agentrun-serve 0.1.0-beta.34 → 0.1.0-beta.36
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 +263 -0
- package/README.md +339 -179
- package/dist/adapters.d.ts +15 -2
- package/dist/adapters.js +34 -2
- package/dist/agent-rows.d.ts +3 -1
- package/dist/agents-store.d.ts +2 -0
- package/dist/agents-store.js +25 -5
- package/dist/api-only.d.ts +2 -1
- package/dist/api-only.js +3 -1
- package/dist/archil-routes.d.ts +40 -7
- package/dist/archil-routes.js +167 -54
- package/dist/archil-settings.d.ts +90 -8
- package/dist/archil-settings.js +150 -14
- package/dist/attach-images.d.ts +15 -0
- package/dist/attach-images.js +59 -0
- package/dist/background.d.ts +0 -6
- package/dist/background.js +0 -28
- package/dist/bash-read-only.d.ts +13 -0
- package/dist/bash-read-only.js +77 -0
- package/dist/box-image.d.ts +1 -97
- package/dist/box-image.js +4 -284
- package/dist/box-paths.d.ts +2 -7
- package/dist/box-paths.js +7 -13
- package/dist/box-settings.d.ts +0 -11
- package/dist/box-settings.js +4 -29
- package/dist/browser-commands.js +1 -1
- package/dist/browser-computer.d.ts +47 -3
- package/dist/browser-computer.js +286 -18
- package/dist/browser-cost.d.ts +2 -2
- package/dist/browser-cost.js +6 -4
- package/dist/browser-person.d.ts +19 -2
- package/dist/browser-person.js +55 -6
- package/dist/browser-wait-ended.d.ts +23 -0
- package/dist/browser-wait-ended.js +42 -0
- package/dist/cap.d.ts +19 -44
- package/dist/cap.js +31 -77
- package/dist/cli.js +36 -27
- package/dist/computer-keys.d.ts +20 -10
- package/dist/computer-keys.js +36 -57
- package/dist/computer-routes.d.ts +1 -4
- package/dist/computer-routes.js +3 -5
- package/dist/computer-setting.d.ts +8 -5
- package/dist/computer-setting.js +91 -26
- package/dist/computer-view.d.ts +11 -2
- package/dist/computer-view.js +2 -1
- package/dist/computers.d.ts +54 -8
- package/dist/computers.js +101 -22
- package/dist/console/assets/index-BI4Byidu.js +550 -0
- package/dist/console/assets/index-C19gUF2n.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/decision-cap.d.ts +7 -29
- package/dist/decision-cap.js +3 -94
- package/dist/docker-daemon.d.ts +2 -2
- package/dist/docker-daemon.js +2 -2
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +8 -5
- package/dist/explain.js +3 -1
- package/dist/faux-computers.js +4 -0
- package/dist/files.d.ts +1 -9
- package/dist/files.js +1 -9
- package/dist/github-connection.js +25 -7
- package/dist/github-faux.d.ts +26 -0
- package/dist/github-faux.js +76 -0
- package/dist/github.d.ts +28 -4
- package/dist/github.js +46 -10
- package/dist/gpu-words.d.ts +14 -0
- package/dist/gpu-words.js +21 -0
- package/dist/graph-served.d.ts +5 -3
- package/dist/graph-served.js +14 -6
- package/dist/graph-view.d.ts +2 -0
- package/dist/graph-view.js +29 -2
- package/dist/handed-values.d.ts +1 -1
- package/dist/handed-values.js +1 -1
- package/dist/harness-install.d.ts +60 -3
- package/dist/harness-install.js +322 -34
- package/dist/harness-opencode/harness.js +0 -1
- package/dist/harness-opencode/host/policy.js +2 -2
- package/dist/harness.js +1 -1
- package/dist/host-tools.d.ts +8 -9
- package/dist/host-tools.js +7 -7
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -2
- package/dist/key-refusal.d.ts +1 -1
- package/dist/key-refusal.js +2 -2
- package/dist/learn/check.d.ts +10 -2
- package/dist/learn/check.js +126 -8
- package/dist/learn/commit.d.ts +40 -6
- package/dist/learn/commit.js +164 -20
- package/dist/learn/folder.d.ts +11 -3
- package/dist/learn/folder.js +40 -16
- package/dist/learn/grade.d.ts +22 -2
- package/dist/learn/grade.js +127 -19
- package/dist/learn/index.d.ts +2 -2
- package/dist/learn/index.js +2 -2
- package/dist/learn/learning.sh +11 -13
- package/dist/learn/notes.d.ts +17 -3
- package/dist/learn/notes.js +19 -6
- package/dist/learn/reflect.d.ts +5 -2
- package/dist/learn/reflect.js +48 -32
- package/dist/learn/skills.d.ts +52 -5
- package/dist/learn/skills.js +104 -21
- package/dist/learned-nodes.d.ts +18 -0
- package/dist/learned-nodes.js +8 -0
- package/dist/learned-workflow.d.ts +27 -13
- package/dist/learned-workflow.js +110 -38
- package/dist/learning-cost.d.ts +79 -0
- package/dist/learning-cost.js +69 -0
- package/dist/learning-routes.d.ts +48 -2
- package/dist/learning-routes.js +99 -28
- package/dist/learning-run.d.ts +7 -5
- package/dist/learning-run.js +9 -6
- package/dist/learning-words.d.ts +3 -0
- package/dist/learning-words.js +6 -2
- package/dist/learning.d.ts +13 -28
- package/dist/learning.js +4 -18
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +4 -2
- package/dist/mcp-gateway.d.ts +6 -0
- package/dist/mcp-gateway.js +11 -1
- package/dist/mcp-probe.d.ts +8 -1
- package/dist/mcp-probe.js +62 -20
- package/dist/mcp-secret-writes.js +4 -0
- package/dist/mcp-servers-store.d.ts +12 -12
- package/dist/mcp-servers-store.js +8 -3
- package/dist/model.d.ts +8 -5
- package/dist/model.js +14 -6
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.js +236 -55
- package/dist/owner.d.ts +0 -1
- package/dist/owner.js +0 -2
- package/dist/pause.d.ts +2 -19
- package/dist/pause.js +5 -74
- package/dist/place-offers.d.ts +97 -0
- package/dist/place-offers.js +206 -0
- package/dist/place.d.ts +9 -13
- package/dist/place.js +22 -32
- package/dist/port-models.d.ts +12 -4
- package/dist/port-models.js +31 -9
- package/dist/print.d.ts +1 -8
- package/dist/print.js +1 -14
- package/dist/propose.d.ts +3 -0
- package/dist/propose.js +25 -19
- package/dist/run-cut.d.ts +5 -0
- package/dist/run-cut.js +19 -0
- package/dist/run-db.js +3 -3
- package/dist/run-launch.d.ts +18 -3
- package/dist/run-launch.js +11 -5
- package/dist/run-learning-served.d.ts +12 -1
- package/dist/run-manifest.d.ts +2 -2
- package/dist/run-manifest.js +2 -2
- package/dist/run-reads-over-store.d.ts +4 -2
- package/dist/run-reads-over-store.js +10 -8
- package/dist/run-secrets.js +3 -3
- package/dist/run-timeline-served.js +60 -38
- package/dist/run-view.d.ts +35 -16
- package/dist/run-view.js +64 -35
- package/dist/runnable.d.ts +6 -3
- package/dist/runnable.js +20 -4
- package/dist/runner/adapter-loop.d.ts +46 -5
- package/dist/runner/adapter-loop.js +381 -56
- package/dist/runner/adapter-run-spec.d.ts +46 -4
- package/dist/runner/adapter-run-spec.js +200 -45
- package/dist/runner/adapters/pi.d.ts +39 -3
- package/dist/runner/adapters/pi.js +124 -29
- package/dist/runner/beside.d.ts +8 -0
- package/dist/runner/beside.js +24 -2
- package/dist/runner/claim-secrets.d.ts +6 -0
- package/dist/runner/claim-secrets.js +15 -1
- package/dist/runner/cli-run-spec.d.ts +10 -0
- package/dist/runner/cli-run-spec.js +207 -64
- package/dist/runner/commands.d.ts +5 -1
- package/dist/runner/commands.js +3 -3
- package/dist/runner/conformance/harness.d.ts +1 -1
- package/dist/runner/conformance/harness.js +13 -10
- package/dist/runner/github-app.d.ts +7 -2
- package/dist/runner/github-app.js +46 -15
- package/dist/runner/harness-loops.d.ts +6 -1
- package/dist/runner/harness-loops.js +24 -1
- package/dist/runner/journal-kinds.d.ts +53 -7
- package/dist/runner/journal-kinds.js +29 -1
- package/dist/runner/learning-end.d.ts +15 -0
- package/dist/runner/learning-end.js +113 -20
- package/dist/runner/learning-factory.js +6 -2
- package/dist/runner/learning-loop.d.ts +75 -1
- package/dist/runner/learning-loop.js +215 -22
- package/dist/runner/learning-seed.d.ts +8 -0
- package/dist/runner/learning-seed.js +7 -1
- package/dist/runner/loop-contract.d.ts +12 -0
- package/dist/runner/loop-contract.js +6 -0
- package/dist/runner/loop.d.ts +5 -1
- package/dist/runner/loop.js +20 -0
- package/dist/runner/main.d.ts +9 -4
- package/dist/runner/main.js +38 -13
- package/dist/runner/mcp-claim.d.ts +7 -0
- package/dist/runner/mcp-claim.js +35 -2
- package/dist/runner/mcp-github.d.ts +15 -4
- package/dist/runner/mcp-github.js +55 -11
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +2 -0
- package/dist/runner/metrics.d.ts +18 -1
- package/dist/runner/metrics.js +81 -1
- package/dist/runner/model-route.d.ts +6 -0
- package/dist/runner/model-route.js +5 -2
- package/dist/runner/pr-checkout.d.ts +59 -0
- package/dist/runner/pr-checkout.js +176 -0
- package/dist/runner/reflect-hook.d.ts +1 -0
- package/dist/runner/reflect-hook.js +3 -3
- package/dist/runner/runner.js +136 -19
- package/dist/runner/spec-holds.d.ts +13 -3
- package/dist/runner/spec-holds.js +13 -10
- package/dist/runner/store-port.d.ts +4 -1
- package/dist/runner/store-secrets.js +17 -1
- package/dist/runner/subagent.d.ts +44 -0
- package/dist/runner/subagent.js +188 -0
- package/dist/runner/workflow-host.d.ts +25 -4
- package/dist/runner/workflow-host.js +26 -4
- package/dist/runner/workflow-loop.d.ts +9 -3
- package/dist/runner/workflow-loop.js +17 -10
- package/dist/runner/workflow-spec.d.ts +28 -13
- package/dist/runner/workflow-spec.js +247 -102
- package/dist/runs-over-store.d.ts +18 -7
- package/dist/runs-over-store.js +149 -31
- package/dist/seal-key.d.ts +0 -2
- package/dist/seal-key.js +0 -2
- package/dist/sealing.js +1 -2
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/server-lock.js +4 -5
- package/dist/server.d.ts +49 -63
- package/dist/server.js +429 -230
- package/dist/stop-signals.d.ts +4 -2
- package/dist/stop-signals.js +5 -3
- package/dist/store/agent-body.d.ts +14 -3
- package/dist/store/agent-body.js +22 -8
- package/dist/store/deadline.d.ts +18 -0
- package/dist/store/deadline.js +49 -0
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/connection.d.ts +4 -0
- package/dist/store/postgres/connection.js +64 -13
- package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
- package/dist/store/schema.d.ts +2 -1
- package/dist/store/schema.js +11 -8
- package/dist/store/seal.d.ts +13 -0
- package/dist/store/seal.js +19 -0
- package/dist/store/sqlite/connection.d.ts +5 -0
- package/dist/store/sqlite/connection.js +88 -82
- package/dist/store/sqlite/run-patch.d.ts +18 -2
- package/dist/store/sqlite/run-patch.js +31 -2
- package/dist/store/sqlite/store.js +65 -11
- package/dist/store/store.d.ts +62 -12
- package/dist/store/store.js +22 -1
- package/dist/store-reads/analytics.js +3 -2
- package/dist/store-reads/cap.d.ts +1 -3
- package/dist/store-reads/cap.js +8 -6
- package/dist/store-reads/decisions.d.ts +2 -2
- package/dist/store-reads/decisions.js +3 -6
- package/dist/store-reads/journal.js +83 -15
- package/dist/store-reads/learning.d.ts +73 -3
- package/dist/store-reads/learning.js +232 -9
- package/dist/store-reads/runs.d.ts +6 -4
- package/dist/store-reads/runs.js +17 -10
- package/dist/store-reads/stats.js +5 -1
- package/dist/store-view.d.ts +15 -1
- package/dist/store-view.js +88 -29
- package/dist/template-eval.js +2 -1
- package/dist/templates.d.ts +73 -4
- package/dist/templates.js +113 -23
- package/dist/timeline/timeline.d.ts +11 -1
- package/dist/timeline/timeline.js +19 -4
- package/dist/tool-blurbs.js +1 -0
- package/dist/tool-budget.d.ts +26 -0
- package/dist/tool-budget.js +56 -0
- package/dist/tool-gate.d.ts +13 -3
- package/dist/tool-gate.js +15 -7
- package/dist/tool-plane.d.ts +42 -29
- package/dist/tool-plane.js +64 -27
- package/dist/tools.d.ts +53 -39
- package/dist/tools.js +174 -79
- package/dist/trigger-signatures.d.ts +1 -0
- package/dist/trigger-signatures.js +3 -1
- package/dist/triggers.d.ts +3 -3
- package/dist/triggers.js +2 -2
- package/dist/turn-end.d.ts +0 -3
- package/dist/turn-end.js +0 -3
- package/dist/uploads.d.ts +28 -5
- package/dist/uploads.js +82 -9
- package/dist/usage-lines.d.ts +1 -1
- package/dist/usage.d.ts +1 -47
- package/dist/usage.js +3 -82
- package/dist/validate.d.ts +8 -0
- package/dist/validate.js +40 -3
- package/dist/webhooks.d.ts +2 -1
- package/dist/webhooks.js +5 -2
- package/dist/workflow/decision-recovery.d.ts +23 -0
- package/dist/workflow/decision-recovery.js +80 -0
- package/dist/workflow/decisions.d.ts +134 -0
- package/dist/workflow/decisions.js +46 -0
- package/dist/workflow/host-session.d.ts +5 -0
- package/dist/workflow/host-session.js +85 -0
- package/dist/workflow/host-tools.d.ts +3 -0
- package/dist/workflow/host-tools.js +3 -0
- package/dist/workflow/node-runner.d.ts +112 -0
- package/dist/workflow/node-runner.js +270 -0
- package/dist/workflow/node.d.ts +88 -0
- package/dist/workflow/node.js +99 -0
- package/dist/workflow/operator-error.d.ts +4 -0
- package/dist/workflow/operator-error.js +4 -0
- package/dist/workflow/pi-versions.d.ts +9 -0
- package/dist/workflow/pi-versions.js +8 -0
- package/dist/workflow/readers.d.ts +36 -0
- package/dist/workflow/readers.js +145 -0
- package/dist/workflow/record-file.d.ts +10 -0
- package/dist/workflow/record-file.js +56 -0
- package/dist/workflow/record-tool.d.ts +76 -0
- package/dist/workflow/record-tool.js +126 -0
- package/dist/workflow/record.d.ts +151 -0
- package/dist/workflow/record.js +401 -0
- package/dist/workflow/run-error.d.ts +16 -0
- package/dist/workflow/run-error.js +26 -0
- package/dist/workflow/runner.d.ts +6 -0
- package/dist/workflow/runner.js +240 -0
- package/dist/workflow/store.d.ts +23 -0
- package/dist/workflow/store.js +242 -0
- package/dist/workflow/task.d.ts +133 -0
- package/dist/workflow/task.js +411 -0
- package/dist/workflow/thinking.d.ts +3 -0
- package/dist/workflow/thinking.js +7 -0
- package/dist/workflow/tool-context.d.ts +21 -0
- package/dist/workflow/tool-context.js +13 -0
- package/dist/workflow/types.d.ts +126 -0
- package/dist/workflow/types.js +1 -0
- package/dist/workflow/wal.d.ts +11 -0
- package/dist/workflow/wal.js +106 -0
- package/dist/workflow-run.d.ts +1 -1
- package/dist/workspace/agent-computer.d.ts +137 -0
- package/dist/workspace/agent-computer.js +292 -0
- package/dist/workspace/archil-claim.d.ts +13 -2
- package/dist/workspace/archil-claim.js +22 -13
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +4 -0
- package/dist/workspace/archil-disks.d.ts +49 -0
- package/dist/workspace/archil-disks.js +185 -0
- package/dist/workspace/archil-exec.d.ts +12 -2
- package/dist/workspace/archil-exec.js +18 -3
- package/dist/workspace/archil-mount-credential.d.ts +20 -4
- package/dist/workspace/archil-mount-credential.js +13 -4
- package/dist/workspace/archil.d.ts +2 -2
- package/dist/workspace/archil.js +25 -5
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/computer-deps.d.ts +18 -11
- package/dist/workspace/computer-deps.js +64 -40
- package/dist/workspace/computer-for-claim.d.ts +47 -9
- package/dist/workspace/computer-for-claim.js +236 -24
- package/dist/workspace/computer-janitor.d.ts +3 -2
- package/dist/workspace/computer-janitor.js +43 -9
- package/dist/workspace/computer-ledger.d.ts +3 -8
- package/dist/workspace/computer-ledger.js +7 -3
- package/dist/workspace/computer-providers.d.ts +5 -3
- package/dist/workspace/computer-providers.js +11 -9
- package/dist/workspace/hands.d.ts +5 -2
- package/dist/workspace/hands.js +4 -3
- package/dist/workspace/index.d.ts +5 -4
- package/dist/workspace/index.js +2 -1
- package/dist/workspace/local.d.ts +3 -0
- package/dist/workspace/local.js +9 -0
- package/dist/workspace/paths.js +3 -2
- package/dist/workspace/pi-env.d.ts +4 -0
- package/dist/workspace/pi-env.js +3 -2
- package/dist/workspace/resolve-computer.d.ts +48 -12
- package/dist/workspace/resolve-computer.js +88 -19
- package/dist/workspace/run-disk.d.ts +34 -0
- package/dist/workspace/run-disk.js +91 -0
- package/dist/workspace/run-tools.d.ts +6 -4
- package/dist/workspace/run-tools.js +17 -9
- package/dist/workspace/server-run-workspace.d.ts +3 -2
- package/dist/workspace/server-run-workspace.js +17 -4
- package/dist/workspace/workspace.d.ts +5 -0
- package/dist/workspace.d.ts +0 -3
- package/dist/workspace.js +2 -15
- package/package.json +11 -16
- package/skills/agentrun-serve/SKILL.md +1 -1
- package/templates/README.md +11 -8
- package/templates/code-review/agent.md +27 -11
- package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
- package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
- package/templates/code-review/evals/injection/graders/ignores.md +1 -1
- package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
- package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
- package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
- package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
- package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
- package/templates/code-review/evals/never-flag/case.yaml +3 -0
- package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
- package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
- package/templates/code-review/evals/never-flag/prompt.md +30 -0
- package/templates/code-review/evals/null-name/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
- package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
- package/templates/code-review/evals/re-review/prompt.md +1 -1
- package/templates/code-review/evals/re-review-open/case.yaml +3 -0
- package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
- package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
- package/templates/code-review/evals/re-review-open/prompt.md +27 -0
- package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
- package/templates/code-review/evals/two-defects/case.yaml +3 -0
- package/templates/code-review/evals/two-defects/graders/both.md +4 -0
- package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
- package/templates/code-review/evals/two-defects/prompt.md +25 -0
- package/templates/code-review/findings.schema.json +131 -27
- package/templates/code-review/rules/CODEREVIEW.md +76 -0
- package/templates/code-review/skills/review/DEEP.md +130 -0
- package/templates/code-review/skills/review/REVIEWER.md +116 -0
- package/templates/code-review/skills/review/SKILL.md +104 -154
- package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
- package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
- package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
- package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
- package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
- package/templates/release-notes/agent.md +11 -0
- package/dist/box/record.d.ts +0 -6
- package/dist/box/record.js +0 -41
- package/dist/box/sweep.d.ts +0 -53
- package/dist/box/sweep.js +0 -193
- package/dist/box-egress-vm.d.ts +0 -118
- package/dist/box-egress-vm.js +0 -354
- package/dist/box-egress.d.ts +0 -105
- package/dist/box-egress.js +0 -256
- package/dist/box-relay-vm.d.ts +0 -84
- package/dist/box-relay-vm.js +0 -437
- package/dist/box-relay.d.ts +0 -36
- package/dist/box-relay.js +0 -207
- package/dist/boxes.d.ts +0 -109
- package/dist/boxes.js +0 -249
- package/dist/budget.d.ts +0 -76
- package/dist/budget.js +0 -204
- package/dist/console/assets/index-RPHGlXmM.js +0 -540
- package/dist/console/assets/index-opTN5Naq.css +0 -1
- package/dist/daytona-api.d.ts +0 -10
- package/dist/daytona-api.js +0 -20
- package/dist/egress-proxy.d.ts +0 -45
- package/dist/egress-proxy.js +0 -416
- package/dist/egress-table.d.ts +0 -24
- package/dist/egress-table.js +0 -165
- package/templates/code-review/rules/REVIEW.md +0 -41
|
@@ -15,11 +15,11 @@ import { defineExtension, ROOT_CONVERSATION_ID, wrapTool } from "@earendil-works
|
|
|
15
15
|
import { chargedCost, DecisionProviderError, EffectFailure, inspectWorkflow } from "@parcha/agentrun-dsl";
|
|
16
16
|
import { modelPortFor } from "@parcha/agentrun-kernel";
|
|
17
17
|
import { startModelProxy } from "@parcha/agentrun-kernel/host";
|
|
18
|
-
import { CapRefused, checkRaise, DECISION_SESSION, followUpOf, parkOf, runCap } from "@parcha/agentrun-kernel/kernel/cap";
|
|
18
|
+
import { CapRefused, checkRaise, DecisionPriceUnreadable, DECISION_SESSION, followUpOf, parkOf, runCap } from "@parcha/agentrun-kernel/kernel/cap";
|
|
19
19
|
import { completer } from "../llm.js";
|
|
20
|
-
// The
|
|
21
|
-
//
|
|
22
|
-
import { askedBefore, JEV_INPUT_USD, PARALLEL_DECISION_USD } from "../decision-cap.js";
|
|
20
|
+
// The decision providers' list prices, the catalog's read and the replay check (decision-cap.ts), with holdOf, which the
|
|
21
|
+
// parity tests hold this cap's figures to.
|
|
22
|
+
import { askedBefore, catalogPrice, JEV_INPUT_USD, PARALLEL_DECISION_USD } from "../decision-cap.js";
|
|
23
23
|
import { decisionProvidersIn } from "../decisions.js";
|
|
24
24
|
import { imageLoader } from "../pdf-pages.js";
|
|
25
25
|
import { llmTiers, nodeTiers, workflowNodes } from "../model.js";
|
|
@@ -39,19 +39,19 @@ import { PI_WIRES, storeSettings } from "./adapter-run-spec.js";
|
|
|
39
39
|
import { policyFor } from "./adapters/pi.js";
|
|
40
40
|
import { sessionProvider } from "../port-models.js";
|
|
41
41
|
import { journalSessions } from "./sessions.js";
|
|
42
|
-
import { KINDS, WORKFLOW_SESSION } from "./journal-kinds.js";
|
|
43
|
-
import {
|
|
42
|
+
import { KINDS, NODE_LOG_SESSION, WORKFLOW_SESSION } from "./journal-kinds.js";
|
|
43
|
+
import { cutStrings } from "../key-refusal.js";
|
|
44
|
+
import { CLOSE_MS, entriesOf } from "./loop.js";
|
|
44
45
|
import { PAUSED_WORDS } from "./workflow-loop.js";
|
|
45
46
|
import { heldRedactor, holdClaimed } from "./redact.js";
|
|
46
47
|
import { holdStored } from "./store-secrets.js";
|
|
47
48
|
import { workflowHost } from "./workflow-host.js";
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
* does not have: importing it here stopped the runner from starting. workflow-submit-name.test.mjs holds the two equal. */
|
|
51
|
-
export const SUBMIT_TOOL = "submit";
|
|
49
|
+
import { SUBMIT_TOOL } from "../workflow/host-tools.js";
|
|
50
|
+
import { bookedSpend } from "./metrics.js";
|
|
52
51
|
/** The one session key the workflow's model requests book under (the run's one booking sums it, runBooking). */
|
|
53
52
|
const SESSION = WORKFLOW_SESSION;
|
|
54
|
-
/** A call node's tool failure and a cap-held effect, as
|
|
53
|
+
/** A call node's tool failure and a cap-held effect, as the runner's effect completed them (the loop's `failing` reads the
|
|
54
|
+
* first; holdAtEffects reads the second). */
|
|
55
55
|
const TOOL_FAILED = "agentrun_serve_tool_failed";
|
|
56
56
|
const CAP_HELD = "agentrun_serve_cap_held";
|
|
57
57
|
/** A tier's provider from the runner's model route (model-route.ts routeOf), the one way the runner resolves a model
|
|
@@ -68,6 +68,7 @@ export function routeProviderOf(env) {
|
|
|
68
68
|
export async function providerFromRoute(route) {
|
|
69
69
|
return {
|
|
70
70
|
modelId: route.model,
|
|
71
|
+
...(route.named ? { named: route.named } : {}),
|
|
71
72
|
api: route.provider.api,
|
|
72
73
|
...(route.like ? { like: route.like } : {}),
|
|
73
74
|
origin: route.provider.origin,
|
|
@@ -97,11 +98,13 @@ async function raisedCapOf(harness, context) {
|
|
|
97
98
|
}
|
|
98
99
|
return capUsd;
|
|
99
100
|
}
|
|
100
|
-
/** The run's cap rule, handed to the loop so it parks and takes raises by the kernel cap without importing it.
|
|
101
|
+
/** The run's cap rule, handed to the loop so it parks and takes raises by the kernel cap without importing it. A park
|
|
102
|
+
* names the cap the run is held to when it parks (`capUsd()`: this claim's raise, else the launch's), so a raise too small
|
|
103
|
+
* for the step that parked shows the new pause at the raised cap, and the next raise is checked against that. */
|
|
101
104
|
function capRuleOf(capUsd) {
|
|
102
105
|
return {
|
|
103
106
|
park: (refusal) => {
|
|
104
|
-
const park = parkOf({ message: refusal.message, forGood: refusal.forGood, ...(refusal.figures ? { figures: refusal.figures } : {}) }, capUsd);
|
|
107
|
+
const park = parkOf({ message: refusal.message, forGood: refusal.forGood, ...(refusal.figures ? { figures: refusal.figures } : {}) }, capUsd());
|
|
105
108
|
return park.outcome === "parked"
|
|
106
109
|
? { outcome: "parked", pending: park.pending, words: park.words }
|
|
107
110
|
: { outcome: "failed", error: park.error };
|
|
@@ -166,6 +169,8 @@ export function workflowSpecOf(deps) {
|
|
|
166
169
|
const hooks = deferredHooks();
|
|
167
170
|
// The call nodes' effects in flight: a model request inside one is not where a pause lands (pauseAtEffects).
|
|
168
171
|
const flight = { count: 0 };
|
|
172
|
+
// The workflow's steps under way, by label: a model request the cap holds names its node when one step alone is open.
|
|
173
|
+
const steps = openSteps();
|
|
169
174
|
// What a model node offers its model: its `submit` and the tools its node names. The session proxy's policy drops every
|
|
170
175
|
// tool definition it is not given, so it admits this whole set by name (as pi's admits its session's tools); main's
|
|
171
176
|
// nodes send their requests straight to the provider (app.ts:117), unfiltered.
|
|
@@ -190,7 +195,7 @@ export function workflowSpecOf(deps) {
|
|
|
190
195
|
const provider = providers.get(resolved) ?? providers.get("default");
|
|
191
196
|
if (!provider)
|
|
192
197
|
throw new Error(`the workflow names tier ${String(tier)}, which this run has no model for`);
|
|
193
|
-
return { provider: providerId(providers.has(resolved) ? resolved : "default"), modelId: provider.modelId };
|
|
198
|
+
return { provider: providerId(providers.has(resolved) ? resolved : "default"), modelId: provider.modelId, ...(provider.named ? { named: provider.named } : {}) };
|
|
194
199
|
};
|
|
195
200
|
const capModelOf = (id) => {
|
|
196
201
|
for (const provider of providers.values())
|
|
@@ -212,6 +217,9 @@ export function workflowSpecOf(deps) {
|
|
|
212
217
|
let decisionCap;
|
|
213
218
|
// The run's paid tool calls on its one cap (TOOL_SESSION), wired at harnessReady: a call node's hold and its request.
|
|
214
219
|
let paidTools;
|
|
220
|
+
// The call nodes' effects as they run (KINDS.nodeEffect on NODE_LOG_SESSION), opened at harnessReady: the run's graph
|
|
221
|
+
// lists its effects from them.
|
|
222
|
+
let nodeLog;
|
|
215
223
|
// The run's own keys with its plane, as an agentic run's tool host gets them: the call nodes' effects and the model
|
|
216
224
|
// nodes' tools run on these.
|
|
217
225
|
const callEnv = callEnvOf(claimedEnv, claimed);
|
|
@@ -247,17 +255,24 @@ export function workflowSpecOf(deps) {
|
|
|
247
255
|
tools: [...new Set([...toolsOf(claimed.workflow), ...nodeNames])],
|
|
248
256
|
agentId: claimed.agentId,
|
|
249
257
|
revisionId: claimed.revisionId,
|
|
250
|
-
...(claimed.capUsd !== undefined ? { cap: capRuleOf(claimed.capUsd) } : {}),
|
|
251
|
-
endPatch: async () => endPatchOf(booking, decisionCap, paidTools),
|
|
258
|
+
...(claimed.capUsd !== undefined ? { cap: capRuleOf(() => effectiveCapUsd ?? claimed.capUsd) } : {}),
|
|
259
|
+
endPatch: async () => endPatchOf(booking, decisionCap, paidTools, run?.journal),
|
|
252
260
|
build: (loopHooks) => {
|
|
253
261
|
hooks.setPark(loopHooks);
|
|
254
262
|
const hostDeps = {
|
|
255
263
|
modelOf,
|
|
264
|
+
// Each model node's execution, kept on the node log (KINDS.nodeModel) before it runs: its path, the tier it asked
|
|
265
|
+
// for and the model id that tier's route sends it to, so the run's graph says what each execution ran on, and a
|
|
266
|
+
// later claim with another model of the tier never rewrites an earlier one's.
|
|
267
|
+
onModelNode: async ({ executionPath, tier }) => {
|
|
268
|
+
await nodeLog?.append([{ kind: KINDS.nodeModel, data: { path: executionPath, ...(tier ? { tier } : {}), model: modelOf(tier).modelId } }]);
|
|
269
|
+
},
|
|
270
|
+
steps,
|
|
256
271
|
// The nodes' tools as the registry holds them (their booked registrations, never their bindings' own raw ones, which
|
|
257
272
|
// would book beside the run's ledger), and the run's gate over them by name (main's registry.install).
|
|
258
273
|
sharedExtensions: [nodeToolGate(nodeNames, nodePolicy), ...[...nodeTools.values()].flatMap((binding) => binding.extensions)],
|
|
259
274
|
nodeTool: (name) => nodeTools.get(name),
|
|
260
|
-
runEffect: runEffectOf(claimed, complete, callEnv, callPolicyOf(deps.store, claim.runId, claimed), () => paidTools),
|
|
275
|
+
runEffect: runEffectOf(claimed, complete, callEnv, callPolicyOf(deps.store, claim.runId, claimed), () => paidTools, (line) => nodeLog?.append([{ kind: KINDS.nodeEffect, data: (run?.redact ? cutStrings(line, run.redact) : line) }]) ?? Promise.resolve()),
|
|
261
276
|
workRoot: claimed.workRoot,
|
|
262
277
|
flush: () => deps.store.flush(),
|
|
263
278
|
// A decision node books through the run's one cap (admitted and settled as main holds it); a cap refusal for room
|
|
@@ -267,12 +282,13 @@ export function workflowSpecOf(deps) {
|
|
|
267
282
|
// A person's pause holds a call node before its effect starts (before the engine admits it), as main's gate did;
|
|
268
283
|
// a call node's tool failure the driver recorded as its effect's outcome is thrown past the driver
|
|
269
284
|
// (failingEffects, main's `failing`), on the first run and on a resume that answers it from its receipt alike.
|
|
270
|
-
//
|
|
271
|
-
// refuses for room parks the run
|
|
285
|
+
// Once the engine has admitted it, each call's most cost is held on the run's one ledger (holdAtEffects): a hold
|
|
286
|
+
// the cap refuses for room ends the effect held, nothing sent, and parks the run once that end is durable.
|
|
272
287
|
cap: pauseAtEffects(holdAtEffects(failingEffects(decisions ? decisionWorkflowCap(() => decisionCap, decisions, hooks) : identityWorkflowCap()), {
|
|
273
288
|
paid: () => paidTools,
|
|
274
289
|
holdOf: (tool, input) => callHoldOf(tool, input, callEnv, tierModel),
|
|
275
290
|
park: (refusal) => hooks.park(refusal),
|
|
291
|
+
flush: () => deps.store.flush(),
|
|
276
292
|
}), hooks, flight),
|
|
277
293
|
};
|
|
278
294
|
return workflowHost(hostDeps);
|
|
@@ -292,7 +308,7 @@ export function workflowSpecOf(deps) {
|
|
|
292
308
|
key: SESSION,
|
|
293
309
|
label: SESSION,
|
|
294
310
|
// The model booking is the run's rule itself (no second booking); a refusal parks the run through the loop's hook.
|
|
295
|
-
beforeRequest: parkOnRefusal(run.before, hooks, flight),
|
|
311
|
+
beforeRequest: parkOnRefusal(run.before, hooks, flight, steps),
|
|
296
312
|
onEvent: async (event) => { if (event.type === "request_start")
|
|
297
313
|
await deps.store.flush(); },
|
|
298
314
|
});
|
|
@@ -304,6 +320,7 @@ export function workflowSpecOf(deps) {
|
|
|
304
320
|
// The run's paid tool calls on the same cap (TOOL_SESSION): a call node's hold before its admission, and the paid
|
|
305
321
|
// request it makes, as an agentic run's tool calls book (paidStep).
|
|
306
322
|
paidTools = await run.tools(await sessions.open(TOOL_SESSION), { flush: () => deps.store.flush() });
|
|
323
|
+
nodeLog = await sessions.open(NODE_LOG_SESSION);
|
|
307
324
|
hooks.setPort(booking.models);
|
|
308
325
|
},
|
|
309
326
|
settle: async () => {
|
|
@@ -323,7 +340,7 @@ export function workflowSpecOf(deps) {
|
|
|
323
340
|
/** The run's rule with a park on a refusal: `before` (runCap's one rule for the model session) is asked, and on a refusal
|
|
324
341
|
* the run parks through the loop's hook (parkOf decides room vs for good from the refusal), the same as the pi adapter's
|
|
325
342
|
* parkAtCap. It still returns the refusal, so the proxy refuses the request and the node's turn ends. */
|
|
326
|
-
export function parkOnRefusal(before, hooks, flight = { count: 0 }) {
|
|
343
|
+
export function parkOnRefusal(before, hooks, flight = { count: 0 }, steps) {
|
|
327
344
|
const park = hooks.park;
|
|
328
345
|
return async (request) => {
|
|
329
346
|
// A person's pause in force parks the run here, before the request is sent, as a refusal does: the request is
|
|
@@ -341,11 +358,33 @@ export function parkOnRefusal(before, hooks, flight = { count: 0 }) {
|
|
|
341
358
|
// words instead (the net under the call's hold, holdAtEffects).
|
|
342
359
|
if (verdict && "refuse" in verdict && flight.count === 0) {
|
|
343
360
|
const refusal = verdict;
|
|
344
|
-
|
|
361
|
+
// Its node: the one workflow step under way (every model request goes through the run's one port, which names no
|
|
362
|
+
// node); none when several run at once, as a map's items do.
|
|
363
|
+
const node = steps?.only();
|
|
364
|
+
park({ message: refusal.refuse, forGood: refusal.forGood ?? true, ...(refusal.figures ? { figures: refusal.figures } : {}), ...(node !== undefined ? { node } : {}) });
|
|
345
365
|
}
|
|
346
366
|
return verdict;
|
|
347
367
|
};
|
|
348
368
|
}
|
|
369
|
+
export function openSteps() {
|
|
370
|
+
const open = new Map();
|
|
371
|
+
return {
|
|
372
|
+
start: (label) => void open.set(label, (open.get(label) ?? 0) + 1),
|
|
373
|
+
end: (label) => {
|
|
374
|
+
const left = (open.get(label) ?? 0) - 1;
|
|
375
|
+
if (left > 0)
|
|
376
|
+
open.set(label, left);
|
|
377
|
+
else
|
|
378
|
+
open.delete(label);
|
|
379
|
+
},
|
|
380
|
+
only: () => {
|
|
381
|
+
if (open.size !== 1)
|
|
382
|
+
return undefined;
|
|
383
|
+
const [[label, count]] = [...open];
|
|
384
|
+
return count === 1 ? label : undefined;
|
|
385
|
+
},
|
|
386
|
+
};
|
|
387
|
+
}
|
|
349
388
|
/** `cap` with a person's pause before each call node's effect starts: applied outside the cap's own effect wrapper, which
|
|
350
389
|
* is outside the engine's recovery wrapper (the one that admits the effect, dsl recovery/driver.ts wrapEffect), so a
|
|
351
390
|
* paused call node is never admitted. A pause in force parks the run there (hooks.pause, which aborts the node's
|
|
@@ -492,38 +531,72 @@ function reservedBooking(held) {
|
|
|
492
531
|
settle: async (_id, usd) => settleReservation(held, usd),
|
|
493
532
|
};
|
|
494
533
|
}
|
|
495
|
-
/** `cap` with each call node's most cost held on the run's one ledger
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
*
|
|
500
|
-
*
|
|
534
|
+
/** `cap` with each call node's most cost held on the run's one ledger, in two halves around the DSL driver's admission of
|
|
535
|
+
* its effect (dsl recovery/driver.ts wrapEffect: the effect is committed admitted before it is dispatched, and one
|
|
536
|
+
* admitted and never completed is never dispatched again):
|
|
537
|
+
* - `admittedEffect`, the effect the driver runs once it has admitted it: the call is priced (`holdOf`) and its hold
|
|
538
|
+
* taken (its record made durable before anything is sent), so a hold is never kept for an effect the driver did not
|
|
539
|
+
* admit: a process that dies before the admission leaves nothing for the next claim to count beside running the call
|
|
540
|
+
* again, and one that dies after it leaves the effect admitted, which the next claim never runs again, under the one
|
|
541
|
+
* hold it counts. Held, the effect runs with the hold as its reservation; what is not taken is given back at its end.
|
|
542
|
+
* A hold the cap refuses ends the effect completed with nothing sent: refused for room, as held (CAP_HELD); refused
|
|
543
|
+
* for good, as the call's failure in the cap's words (TOOL_FAILED). So does the net: a call whose answer cost more
|
|
544
|
+
* than its hold (an `llm` answer priced at its usage).
|
|
545
|
+
* - `effect`, outside the driver: an effect this process ended held parks the run (`park`, as a model request's refusal
|
|
546
|
+
* does) once that end is durable (`flush`), and waits on the node's signal. One an earlier claim ended held (its
|
|
547
|
+
* receipt, replayed) is the park that claim made: the call goes again, a new effect judged at this claim's cap. */
|
|
501
548
|
export function holdAtEffects(cap, deps) {
|
|
502
549
|
let seq = 0;
|
|
550
|
+
/** The held ends this process made, by the outcome the driver completed each effect with, and the cap's refusal. */
|
|
551
|
+
const heldHere = new WeakMap();
|
|
552
|
+
// A returned failure (`ok: false`): a continuation never answers a call from it.
|
|
553
|
+
const failed = (label, words) => ({ ok: false, [TOOL_FAILED]: `call node "${label}": ${words}` });
|
|
503
554
|
return {
|
|
504
555
|
...cap,
|
|
505
556
|
effect: (fn) => {
|
|
506
557
|
const inner = cap.effect(fn);
|
|
558
|
+
return (async (params) => {
|
|
559
|
+
for (;;) {
|
|
560
|
+
const value = await inner(params);
|
|
561
|
+
if (!value || typeof value !== "object" || !Object.hasOwn(value, CAP_HELD))
|
|
562
|
+
return value;
|
|
563
|
+
const refused = heldHere.get(value);
|
|
564
|
+
// An earlier claim's park at this call (its receipt): the raise this claim took sends the call again.
|
|
565
|
+
if (!refused)
|
|
566
|
+
continue;
|
|
567
|
+
heldHere.delete(value);
|
|
568
|
+
// The effect's held end lands before the run parks, so the next claim replays it and goes again.
|
|
569
|
+
await deps.flush();
|
|
570
|
+
deps.park({ message: refused.message, forGood: false, ...(refused.figures ? { figures: refused.figures } : {}) });
|
|
571
|
+
const signal = params.signal;
|
|
572
|
+
if (signal && !signal.aborted)
|
|
573
|
+
await new Promise((resolve) => signal.addEventListener("abort", () => resolve(), { once: true }));
|
|
574
|
+
throw signal?.reason ?? refused;
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
},
|
|
578
|
+
admittedEffect: (fn) => {
|
|
579
|
+
const inner = (cap.admittedEffect ? cap.admittedEffect(fn) : fn);
|
|
507
580
|
return (async (params) => {
|
|
508
581
|
const tool = params.node.tool;
|
|
509
|
-
const hold = tool ? deps.holdOf(tool, params.input ?? {}) : undefined;
|
|
510
582
|
const paid = deps.paid();
|
|
583
|
+
const hold = tool && paid ? deps.holdOf(tool, params.input ?? {}) : undefined;
|
|
511
584
|
if (!hold || hold.usd <= 0 || !paid)
|
|
512
585
|
return inner(params);
|
|
513
586
|
const call = `${params.node.label}@${params.executionPath ?? ""}`;
|
|
514
|
-
|
|
587
|
+
// Keyed by the effect the driver admitted, so a later claim never writes a second hold under the same id.
|
|
588
|
+
const id = `${call}#${params.effect?.id ?? `hold${(seq += 1)}`}`;
|
|
515
589
|
try {
|
|
516
590
|
await paid.admit({ id, name: hold.name, holdUsd: hold.usd, basis: hold.basis, call, ...(hold.chargedBy ? { chargedBy: hold.chargedBy } : {}) });
|
|
517
591
|
}
|
|
518
592
|
catch (error) {
|
|
519
593
|
if (error instanceof CapRefused && !error.forGood) {
|
|
520
|
-
|
|
521
|
-
const
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
throw signal?.reason ?? error;
|
|
594
|
+
// Held, nothing sent: an outcome a continuation never answers a call from (`ok: false`, a returned failure).
|
|
595
|
+
const outcome = { ok: false, [CAP_HELD]: error.message };
|
|
596
|
+
heldHere.set(outcome, error);
|
|
597
|
+
return outcome;
|
|
525
598
|
}
|
|
526
|
-
|
|
599
|
+
return failed(params.node.label, error?.message ?? String(error));
|
|
527
600
|
}
|
|
528
601
|
const held = { id, call, hold, paid, taken: false, settled: false };
|
|
529
602
|
try {
|
|
@@ -533,7 +606,7 @@ export function holdAtEffects(cap, deps) {
|
|
|
533
606
|
if (usage && hold.llm?.price) {
|
|
534
607
|
const charged = pricingOf(hold.llm.price)({ cached: 0, fresh: usage.input_tokens ?? 0 }, usage.output_tokens ?? 0);
|
|
535
608
|
if (charged > hold.usd + 1e-12)
|
|
536
|
-
|
|
609
|
+
return failed(params.node.label, `its answer cost ${money(charged)}, above the ${money(hold.usd)} it held before it ran.`);
|
|
537
610
|
}
|
|
538
611
|
return value;
|
|
539
612
|
}
|
|
@@ -595,13 +668,15 @@ export function failingEffects(cap) {
|
|
|
595
668
|
},
|
|
596
669
|
};
|
|
597
670
|
}
|
|
598
|
-
function runEffectOf(claimed, complete, env, policy, paidTools) {
|
|
671
|
+
function runEffectOf(claimed, complete, env, policy, paidTools, log) {
|
|
599
672
|
// An `llm` call gives its call's hold back as its own model request is judged (the cap holds that request itself).
|
|
600
673
|
const completeHeld = async (args, signal) => {
|
|
601
674
|
await releaseCallHold();
|
|
602
675
|
return complete(args, signal);
|
|
603
676
|
};
|
|
604
|
-
|
|
677
|
+
// A line the node log could not take (the claim lost meanwhile) costs the graph a line, never the call.
|
|
678
|
+
const logged = (line) => log(line).catch(() => undefined);
|
|
679
|
+
return (async ({ node, input, signal, executionPath, item }) => {
|
|
605
680
|
// The call's ledger: its paid request books on the run's one ledger, on the hold taken before the call (holdAtEffects)
|
|
606
681
|
// when it has one. No pause: a refusal inside an admitted effect fails the call, never parks the run there.
|
|
607
682
|
const held = heldBooking();
|
|
@@ -610,6 +685,9 @@ function runEffectOf(claimed, complete, env, policy, paidTools) {
|
|
|
610
685
|
const effect = node.via === "tool" && node.tool ? toolOf(node.tool)?.effect : undefined;
|
|
611
686
|
if (!effect)
|
|
612
687
|
throw new Error(`call node "${node.label}": agentrun-serve runs no tool ${node.tool ?? `via ${node.via}`}`);
|
|
688
|
+
// Its start and its end on the run's node log (main's app.ts), which the run's graph lists as its effects.
|
|
689
|
+
const at = { path: executionPath ?? null, item: item?.index ?? null, tool: node.tool, label: node.label };
|
|
690
|
+
await logged({ t: "effect.start", ...at, input, at: new Date().toISOString() });
|
|
613
691
|
// Its tool's permission now (main's app.ts:382-384): a deny set since the run started is refused in the gate's words,
|
|
614
692
|
// and an ask too, since a call node cannot wait for an approval. Neither runs.
|
|
615
693
|
try {
|
|
@@ -618,84 +696,148 @@ function runEffectOf(claimed, complete, env, policy, paidTools) {
|
|
|
618
696
|
throw new Error(deniedText(node.tool, undefined, denyFrom));
|
|
619
697
|
if (permission === "ask")
|
|
620
698
|
throw new Error(callNodeAskText(node.tool));
|
|
621
|
-
|
|
699
|
+
const output = await effect(input, { signal, env, work: claimed.workRoot, complete: completeHeld, ...(ledger ? { ledger } : {}) });
|
|
700
|
+
await logged({ t: "effect.end", ...at, status: "done", output, at: new Date().toISOString() });
|
|
701
|
+
return output;
|
|
622
702
|
}
|
|
623
703
|
catch (error) {
|
|
624
704
|
const message = String(error?.message ?? error);
|
|
705
|
+
// Whole up to 64 KB, so the server redacts it before it cuts it for the graph (graph-served.ts); a longer one is
|
|
706
|
+
// marked cut.
|
|
707
|
+
await logged({ t: "effect.end", ...at, status: "failed", error: message.slice(0, 65_536), ...(message.length > 65_536 ? { error_truncated: true } : {}), at: new Date().toISOString() });
|
|
625
708
|
if (signal.aborted || error?.name === "AbortError")
|
|
626
709
|
throw error;
|
|
627
|
-
return { [TOOL_FAILED]: `call node "${node.label}": ${node.tool} failed: ${message.slice(0, 500)}` };
|
|
710
|
+
return { ok: false, [TOOL_FAILED]: `call node "${node.label}": ${node.tool} failed: ${message.slice(0, 500)}` };
|
|
628
711
|
}
|
|
629
712
|
});
|
|
630
713
|
}
|
|
631
714
|
/** The end's cost and metrics: what every model request of the run cost (the booking) plus what its decisions and its
|
|
632
715
|
* call nodes' paid requests cost (the decision cap, the paid tools), one spend for the run. Unknown (no figure) once any
|
|
633
716
|
* part is unknown. */
|
|
634
|
-
|
|
717
|
+
/** What the run's decisions cost by their booking (bookedSpend, "decisions"), read from only what that needs: the root's
|
|
718
|
+
* session keys (journalSessions writes them there) and the decisions session's own conversation, never the run's model
|
|
719
|
+
* or tool records, so the read stays small within the end patch's bound. No decisions session: none, $0. */
|
|
720
|
+
async function decisionsBooked(journal) {
|
|
721
|
+
const root = await entriesOf(journal, ROOT_CONVERSATION_ID, BACKGROUND_CONTEXT);
|
|
722
|
+
const key = root.find((entry) => entry.kind === KINDS.sessionKey && entry.data?.key === DECISION_SESSION);
|
|
723
|
+
const conversation = key?.data?.conversation;
|
|
724
|
+
if (conversation == null)
|
|
725
|
+
return 0;
|
|
726
|
+
const decisions = await entriesOf(journal, conversation, BACKGROUND_CONTEXT);
|
|
727
|
+
return bookedSpend([key, ...decisions], "decisions").usd;
|
|
728
|
+
}
|
|
729
|
+
async function endPatchOf(booking, decisionCap, paidTools, journalOf) {
|
|
635
730
|
if (!booking)
|
|
636
731
|
return {};
|
|
637
732
|
const model = booking.spentUsd();
|
|
638
|
-
|
|
733
|
+
// A decision's cost is what its booking says it charged (bookedSpend over the decisions session's records, as the pi and
|
|
734
|
+
// CLI specs read it): one its provider reported no cost for is unknown, never the hold the cap counts it at
|
|
735
|
+
// (decisionCap.spentUsd, which stays the cap's own figure). With no journal to read, any decision is unknown.
|
|
736
|
+
const decision = !decisionCap ? 0 : journalOf ? await decisionsBooked(journalOf()) : null;
|
|
639
737
|
const paid = paidTools ? paidTools.spentUsd() : 0;
|
|
640
738
|
return model === null || decision === null || paid === null ? {} : { costUsd: model + decision + paid };
|
|
641
739
|
}
|
|
642
740
|
/** The run's one cap as a WorkflowCap: model nodes and call nodes pass through (their money is on the proxy), and a
|
|
643
|
-
* decision node is
|
|
644
|
-
* holds it. The reference is deferred because the cap is not
|
|
741
|
+
* decision node is priced before the DSL driver admits its request (`judge`) and held, sent and settled through the run's
|
|
742
|
+
* decisions once it is admitted (`admitted`), priced as main holds it. The reference is deferred because the cap is not
|
|
743
|
+
* built until the Harness opens. */
|
|
645
744
|
function decisionWorkflowCap(getCap, providers, hooks) {
|
|
646
|
-
|
|
745
|
+
const judging = decisionJudging({ getCap, providers, park: hooks.park, hooks });
|
|
746
|
+
return { node: (fn) => fn, effect: (fn) => fn, judge: judging.before, admitted: judging.admitted };
|
|
647
747
|
}
|
|
648
|
-
/** A decision
|
|
649
|
-
*
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
*
|
|
653
|
-
*
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
deps.
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
748
|
+
/** A decision under the run's cap, in two halves around the DSL driver's admission of its request (dsl withRecovery: the
|
|
749
|
+
* request is committed, `decision.request`, before the judge is asked; one asked and never answered is never asked again):
|
|
750
|
+
* - `before`, outside the admission: a request the driver answers from what it decided before (a route's, or one an
|
|
751
|
+
* earlier process admitted that did not fail) holds nothing (askedBefore); a person's pause parks the run; the
|
|
752
|
+
* request is priced as main prices it (holdOf), its catalog read again on a moment's outage.
|
|
753
|
+
* - `admitted`, the judge the driver asks once it has admitted the request: the hold is taken through the kernel cap (its
|
|
754
|
+
* record made durable before the send), the provider is asked, and the hold is settled at what the answer charged (its
|
|
755
|
+
* hold when it reports none). So a hold is never kept for a request the driver did not admit: a process that dies
|
|
756
|
+
* before the admission leaves nothing for the next claim to count beside asking it again. A refusal for room or for no
|
|
757
|
+
* price ends the admitted request failed, unsent, in the driver's commit (asked again by the next claim), and then parks
|
|
758
|
+
* the run, or fails it, through the loop's hook, as a model node's refusal does. A price the catalog still could not
|
|
759
|
+
* read fails the decision node as an unsent connection error, never the cap's stop. */
|
|
760
|
+
function decisionJudging(deps) {
|
|
761
|
+
/** Each request `before` priced, by the params object the driver hands on to `admitted`; and the cap's refusal of one. */
|
|
762
|
+
const priced = new WeakMap();
|
|
763
|
+
const refused = new WeakMap();
|
|
764
|
+
return {
|
|
765
|
+
before(inner, driver) {
|
|
766
|
+
const judge = inner;
|
|
767
|
+
return (async (params) => {
|
|
768
|
+
if (driver && askedBefore(driver, params))
|
|
769
|
+
return judge(params);
|
|
770
|
+
// A person's pause in force parks the run before a new decision is held or sent, as a refusal for room does.
|
|
771
|
+
if (deps.hooks?.paused()) {
|
|
772
|
+
deps.hooks.pause();
|
|
773
|
+
throw new Error(PAUSED_WORDS);
|
|
774
|
+
}
|
|
775
|
+
const id = params.provider ?? deps.providers.default;
|
|
776
|
+
const provider = Object.hasOwn(deps.providers.providers, id) ? deps.providers.providers[id] : undefined;
|
|
777
|
+
// A provider the host lacks is refused by the judge itself (configuration), before anything is held.
|
|
778
|
+
if (!provider)
|
|
779
|
+
return judge(params);
|
|
780
|
+
// The cap is wired at harnessReady, before any node runs; a decision reaching here without it is a bug.
|
|
781
|
+
if (!deps.getCap())
|
|
782
|
+
throw new Error(`decision "${params.label}": the run's decision cap was not wired before the workflow ran`);
|
|
783
|
+
priced.set(params, await decisionRequestOf(provider, params));
|
|
784
|
+
try {
|
|
785
|
+
return await judge(params);
|
|
786
|
+
}
|
|
787
|
+
catch (error) {
|
|
788
|
+
const refusal = refused.get(params);
|
|
789
|
+
if (!refusal)
|
|
790
|
+
throw error;
|
|
791
|
+
// The cap refused the admitted request: the driver ended it failed, unsent; that commit lands before the run
|
|
792
|
+
// parks, so the next claim asks it again rather than finding it asked and never answered. A commit the store
|
|
793
|
+
// refused is thrown, never a park: parked with the request still asked, the next claim would refuse to ask it.
|
|
794
|
+
await driver?.flush();
|
|
795
|
+
deps.park({ message: refusal.message, forGood: refusal.forGood, ...(refusal.figures ? { figures: refusal.figures } : {}) });
|
|
796
|
+
throw refusal;
|
|
797
|
+
}
|
|
798
|
+
finally {
|
|
799
|
+
priced.delete(params);
|
|
800
|
+
refused.delete(params);
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
},
|
|
804
|
+
admitted(inner) {
|
|
805
|
+
const judge = inner;
|
|
806
|
+
return (async (params) => {
|
|
807
|
+
const request = priced.get(params);
|
|
808
|
+
const cap = deps.getCap();
|
|
809
|
+
if (!request || !cap)
|
|
810
|
+
return judge(params);
|
|
811
|
+
try {
|
|
812
|
+
await cap.admit(request);
|
|
813
|
+
}
|
|
814
|
+
catch (error) {
|
|
815
|
+
// A refusal the cap read: told to `before` (which parks or fails the run once the driver has ended the request),
|
|
816
|
+
// and thrown here as a request that never left, so the driver ends it failed with nothing spent.
|
|
817
|
+
if (error instanceof CapRefused) {
|
|
818
|
+
refused.set(params, error);
|
|
819
|
+
throw new DecisionProviderError("connection", `${params.label}'s decision was not sent: ${error.message}`, { unsent: true, cause: error });
|
|
820
|
+
}
|
|
821
|
+
// A price the catalog could not read: the decision node fails unsent, as a connection error, never the cap.
|
|
822
|
+
if (error instanceof DecisionPriceUnreadable)
|
|
823
|
+
throw new DecisionProviderError("connection", `${params.label}'s decision was not sent: ${error.message}`, { unsent: true, cause: error });
|
|
824
|
+
throw error;
|
|
825
|
+
}
|
|
826
|
+
try {
|
|
827
|
+
const result = await judge(params);
|
|
828
|
+
await cap.settle(request.id, { end: "charged", usd: finiteUsd(result?.cost_usd) });
|
|
829
|
+
return result;
|
|
830
|
+
}
|
|
831
|
+
catch (error) {
|
|
832
|
+
// Sent and maybe billed (its outcome lost, its answer rejected): at what it was charged, else at its hold (null).
|
|
833
|
+
// One its provider refused unbilled, or that never left, charged nothing: booked at $0 so no later process counts it.
|
|
834
|
+
const charged = chargedCost(error);
|
|
835
|
+
await cap.settle(request.id, { end: "charged", usd: charged !== undefined ? charged : unbilled(error) ? 0 : null });
|
|
836
|
+
throw error;
|
|
837
|
+
}
|
|
838
|
+
});
|
|
839
|
+
},
|
|
840
|
+
};
|
|
699
841
|
}
|
|
700
842
|
/** A decision's request for the kernel cap, priced as main holds it (serve decision-cap.ts holdOf): Parallel's list price
|
|
701
843
|
* for one request; Jev's published per-input-token price; an OpenRouter Decisions model at its catalog price (per request,
|
|
@@ -707,8 +849,10 @@ async function decisionRequestOf(provider, params) {
|
|
|
707
849
|
const questions = Object.keys(params.questions).length;
|
|
708
850
|
const images = Object.keys(params.images ?? {}).length;
|
|
709
851
|
const base = { kind: "decision", id, inputTokens, questions, images };
|
|
852
|
+
// Parallel charges by the request, nothing by the token: priced at $0 a token and its request price, never as a model
|
|
853
|
+
// with no price (which the cap refuses, failing every capped workflow's Parallel decision).
|
|
710
854
|
if (provider.id === "parallel")
|
|
711
|
-
return { ...base, model: openrouterModel("parallel",
|
|
855
|
+
return { ...base, model: openrouterModel("parallel", { input: 0, output: 0 }, null), requestUsd: PARALLEL_DECISION_USD };
|
|
712
856
|
if (provider.id === "jev")
|
|
713
857
|
return { ...base, model: { id: "jev", api: "openrouter", price: { input: JEV_INPUT_USD * 1e6, output: 0 }, outputCeiling: null } };
|
|
714
858
|
const priced = provider;
|
|
@@ -720,11 +864,12 @@ async function decisionRequestOf(provider, params) {
|
|
|
720
864
|
return { ...base, model: openrouterModel(model ?? provider.id, null, null) };
|
|
721
865
|
let price;
|
|
722
866
|
try {
|
|
723
|
-
|
|
867
|
+
// Read again on a moment's outage (catalogPrice, CATALOG_TRIES reads), as main reads it.
|
|
868
|
+
price = await catalogPrice(priced, model, params.signal);
|
|
724
869
|
}
|
|
725
870
|
catch {
|
|
726
|
-
// The catalog could not be read: the decision fails unsent as a connection error, never the cap's stop (asModel
|
|
727
|
-
// DecisionPriceUnreadable for "unreadable").
|
|
871
|
+
// The catalog still could not be read: the decision fails unsent as a connection error, never the cap's stop (asModel
|
|
872
|
+
// throws DecisionPriceUnreadable for "unreadable").
|
|
728
873
|
return { ...base, model: "unreadable" };
|
|
729
874
|
}
|
|
730
875
|
if (!price)
|
|
@@ -813,7 +958,7 @@ function bookedNodeTools(binding, paid, park) {
|
|
|
813
958
|
})),
|
|
814
959
|
};
|
|
815
960
|
}
|
|
816
|
-
/** The tool names a workflow's model node offers its model: the node's `submit` (
|
|
961
|
+
/** The tool names a workflow's model node offers its model: the node's `submit` (SUBMIT_TOOL) and every tool the
|
|
817
962
|
* workflow's model nodes name. */
|
|
818
963
|
export function nodeOffer(workflow) {
|
|
819
964
|
return [...new Set([SUBMIT_TOOL, ...workflowTools(workflowNodes(workflow, inspectWorkflow(workflow))).nodes])];
|