@parcha/agentrun-serve 0.1.0-beta.33 → 0.1.0-beta.35
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 +368 -0
- package/README.md +341 -208
- package/dist/adapters.d.ts +3 -4
- package/dist/adapters.js +18 -15
- package/dist/agent-rows.d.ts +99 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +75 -25
- package/dist/agents.d.ts +9 -125
- package/dist/agents.js +15 -305
- package/dist/answer-json.d.ts +23 -0
- package/dist/answer-json.js +58 -0
- package/dist/api-only.d.ts +1 -1
- package/dist/api-only.js +2 -2
- package/dist/archil-settings.d.ts +11 -1
- package/dist/archil-settings.js +10 -0
- package/dist/bash-read-only.d.ts +35 -0
- package/dist/bash-read-only.js +778 -0
- package/dist/box-settings.d.ts +3 -23
- package/dist/box-settings.js +7 -51
- package/dist/boxes.d.ts +17 -0
- package/dist/boxes.js +27 -20
- package/dist/browser-commands.d.ts +5 -2
- package/dist/browser-commands.js +4 -4
- package/dist/browser-computer.d.ts +5 -0
- package/dist/browser-computer.js +21 -0
- package/dist/browser-cost.d.ts +9 -6
- package/dist/browser-cost.js +95 -51
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -51
- package/dist/browser-person.js +94 -277
- package/dist/budget.d.ts +0 -5
- package/dist/budget.js +0 -5
- package/dist/cap.d.ts +14 -8
- package/dist/cap.js +19 -9
- package/dist/cli.js +71 -18
- package/dist/closed-pipes.d.ts +2 -0
- package/dist/closed-pipes.js +13 -0
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +2 -0
- package/dist/computer-keys.d.ts +20 -10
- package/dist/computer-keys.js +36 -54
- package/dist/computer-setting.d.ts +20 -3
- package/dist/computer-setting.js +58 -10
- package/dist/computers.d.ts +35 -2
- package/dist/computers.js +72 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-B7NKTU8E.css +1 -0
- package/dist/console/assets/index-CXZMgJE7.js +550 -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/decision-rows.d.ts +1 -1
- package/dist/decision-rows.js +1 -1
- package/dist/docker-daemon.d.ts +31 -0
- package/dist/docker-daemon.js +56 -0
- package/dist/effort-guidance.js +4 -3
- package/dist/environment.d.ts +0 -3
- package/dist/environment.js +3 -5
- package/dist/errors.d.ts +1 -2
- package/dist/errors.js +9 -9
- package/dist/explain.js +3 -1
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -3
- package/dist/files.js +2 -4
- package/dist/github-connection.d.ts +1 -1
- 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 +6 -2
- package/dist/github.js +5 -3
- package/dist/graph-served.d.ts +5 -3
- package/dist/graph-served.js +14 -6
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +9 -16
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +1 -7
- package/dist/harness-install.js +1 -18
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- package/dist/harness-opencode/harness.js +0 -1
- package/dist/harness-opencode/host/policy.js +2 -2
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/verify.d.ts +17 -0
- package/dist/harness-opencode/verify.js +30 -10
- package/dist/harness-table.js +6 -1
- package/dist/heard.js +1 -1
- package/dist/held-fd.d.ts +5 -0
- package/dist/held-fd.js +14 -0
- package/dist/host-calls.d.ts +20 -0
- package/dist/host-calls.js +12 -0
- package/dist/host-tools.d.ts +4 -21
- package/dist/host-tools.js +4 -61
- package/dist/host.d.ts +2 -4
- package/dist/host.js +2 -7
- package/dist/import-summary.d.ts +1 -5
- package/dist/import-summary.js +0 -21
- package/dist/import.d.ts +6 -6
- package/dist/import.js +14 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +8 -2
- package/dist/learn/check.js +85 -31
- package/dist/learn/folder.d.ts +11 -4
- package/dist/learn/folder.js +17 -19
- package/dist/learn/grade.d.ts +18 -1
- package/dist/learn/grade.js +108 -14
- package/dist/learn/index.d.ts +5 -5
- package/dist/learn/index.js +5 -5
- package/dist/learn/learning.sh +1 -14
- package/dist/learn/notes.d.ts +14 -3
- package/dist/learn/notes.js +16 -6
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +83 -6
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +7 -1
- package/dist/learn/secrets.js +86 -19
- package/dist/learn/skills.d.ts +159 -18
- package/dist/learn/skills.js +644 -64
- package/dist/learned-nodes.d.ts +14 -0
- package/dist/learned-nodes.js +8 -0
- package/dist/learned-workflow.d.ts +41 -6
- package/dist/learned-workflow.js +153 -18
- package/dist/learning-routes.d.ts +49 -4
- package/dist/learning-routes.js +113 -31
- package/dist/learning-run.d.ts +16 -31
- package/dist/learning-run.js +31 -38
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +91 -97
- package/dist/learning.js +176 -320
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +12 -2
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +4 -2
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +17 -49
- package/dist/mcp-gateway.js +55 -136
- package/dist/mcp-oauth.d.ts +10 -14
- package/dist/mcp-oauth.js +14 -32
- package/dist/mcp-probe.d.ts +0 -7
- package/dist/mcp-probe.js +4 -10
- package/dist/mcp-servers-store.d.ts +18 -18
- package/dist/mcp-servers-store.js +12 -14
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +9 -7
- package/dist/model.js +51 -27
- package/dist/monid.d.ts +0 -2
- package/dist/monid.js +3 -6
- package/dist/openapi.d.ts +8 -1
- package/dist/openapi.js +156 -58
- package/dist/page.d.ts +1 -3
- package/dist/page.js +6 -18
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +26 -61
- package/dist/pause.d.ts +2 -19
- package/dist/pause.js +5 -74
- package/dist/port-models.d.ts +10 -3
- package/dist/port-models.js +26 -6
- package/dist/propose.d.ts +2 -0
- package/dist/propose.js +80 -45
- package/dist/push-handler.d.ts +1 -1
- package/dist/reflect-range.d.ts +25 -0
- package/dist/reflect-range.js +30 -0
- package/dist/refusal-words.d.ts +5 -1
- package/dist/refusal-words.js +5 -1
- package/dist/rows.d.ts +1 -1
- package/dist/run-cut.d.ts +0 -6
- package/dist/run-cut.js +0 -6
- package/dist/run-db.d.ts +2 -11
- package/dist/run-db.js +2 -37
- package/dist/run-launch.d.ts +21 -2
- package/dist/run-launch.js +14 -5
- package/dist/run-learning-served.d.ts +21 -4
- package/dist/run-learning-served.js +23 -13
- package/dist/run-reads-over-store.d.ts +5 -3
- package/dist/run-reads-over-store.js +25 -14
- package/dist/run-secrets.d.ts +1 -1
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +27 -6
- package/dist/run-view.d.ts +37 -22
- package/dist/run-view.js +85 -38
- package/dist/runnable.d.ts +21 -10
- package/dist/runnable.js +35 -12
- package/dist/runner/adapter-loop.d.ts +36 -5
- package/dist/runner/adapter-loop.js +663 -69
- package/dist/runner/adapter-run-spec.d.ts +42 -8
- package/dist/runner/adapter-run-spec.js +186 -52
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +40 -2
- package/dist/runner/adapters/pi.js +110 -27
- package/dist/runner/beside.d.ts +38 -3
- package/dist/runner/beside.js +54 -5
- package/dist/runner/claim-secrets.d.ts +16 -1
- package/dist/runner/claim-secrets.js +62 -14
- package/dist/runner/cli-run-spec.d.ts +5 -0
- package/dist/runner/cli-run-spec.js +159 -41
- package/dist/runner/commands.js +1 -1
- package/dist/runner/computer-journal.d.ts +15 -2
- package/dist/runner/computer-journal.js +41 -5
- package/dist/runner/conformance/harness.d.ts +1 -0
- package/dist/runner/conformance/harness.js +123 -13
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/dispatch.d.ts +8 -1
- package/dist/runner/dispatch.js +81 -7
- package/dist/runner/end-of-run.d.ts +8 -2
- package/dist/runner/end-of-run.js +10 -4
- package/dist/runner/github-app.d.ts +7 -2
- package/dist/runner/github-app.js +47 -16
- package/dist/runner/harness-loops.d.ts +15 -2
- package/dist/runner/harness-loops.js +38 -2
- package/dist/runner/journal-kinds.d.ts +60 -6
- package/dist/runner/journal-kinds.js +43 -5
- package/dist/runner/journal-reader.d.ts +1 -1
- package/dist/runner/journal-reader.js +2 -2
- package/dist/runner/learning-ask.d.ts +4 -0
- package/dist/runner/learning-ask.js +15 -1
- package/dist/runner/learning-end.d.ts +18 -3
- package/dist/runner/learning-end.js +194 -20
- package/dist/runner/learning-loop.d.ts +7 -0
- package/dist/runner/learning-loop.js +36 -8
- package/dist/runner/learning-seed.d.ts +6 -0
- package/dist/runner/learning-seed.js +6 -0
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.d.ts +61 -9
- package/dist/runner/main.js +144 -20
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +7 -3
- package/dist/runner/mcp-github.d.ts +11 -2
- package/dist/runner/mcp-github.js +55 -4
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +16 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +46 -1
- package/dist/runner/metrics.js +156 -1
- package/dist/runner/model-route.d.ts +16 -0
- package/dist/runner/model-route.js +134 -10
- package/dist/runner/reflect-hook.d.ts +12 -1
- package/dist/runner/reflect-hook.js +33 -3
- package/dist/runner/runner.d.ts +20 -0
- package/dist/runner/runner.js +146 -18
- package/dist/runner/spec-holds.d.ts +7 -2
- package/dist/runner/spec-holds.js +4 -3
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +3 -3
- package/dist/runner/store-secrets.js +8 -12
- package/dist/runner/text-tools.d.ts +44 -0
- package/dist/runner/text-tools.js +237 -0
- package/dist/runner/workflow-host.d.ts +7 -2
- package/dist/runner/workflow-host.js +3 -1
- package/dist/runner/workflow-loop.d.ts +10 -1
- package/dist/runner/workflow-loop.js +14 -6
- package/dist/runner/workflow-spec.d.ts +21 -0
- package/dist/runner/workflow-spec.js +217 -93
- package/dist/runs-over-store.d.ts +14 -3
- package/dist/runs-over-store.js +100 -23
- package/dist/seal-key.d.ts +0 -2
- package/dist/seal-key.js +5 -45
- package/dist/sealed-settings-store.d.ts +19 -4
- package/dist/sealed-settings-store.js +9 -9
- package/dist/sealing.d.ts +4 -0
- package/dist/sealing.js +20 -0
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/secret-name.d.ts +9 -0
- package/dist/secret-name.js +15 -0
- package/dist/secret-writes.d.ts +0 -1
- package/dist/secret-writes.js +0 -1
- package/dist/server-fs.d.ts +4 -0
- package/dist/server-fs.js +8 -2
- package/dist/server-lock.d.ts +0 -24
- package/dist/server-lock.js +5 -85
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +9 -31
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -36
- package/dist/server.d.ts +37 -56
- package/dist/server.js +322 -134
- package/dist/sign-ins-store.d.ts +34 -36
- package/dist/sign-ins-store.js +27 -38
- package/dist/sign-ins.d.ts +2 -119
- package/dist/sign-ins.js +5 -311
- package/dist/standard-webhooks.d.ts +1 -1
- package/dist/standard-webhooks.js +1 -1
- package/dist/stats.d.ts +3 -2
- package/dist/stats.js +1 -1
- package/dist/stop-signals.d.ts +4 -2
- package/dist/stop-signals.js +5 -3
- package/dist/store/agent-body.d.ts +12 -2
- package/dist/store/agent-body.js +22 -4
- package/dist/store/deadline.d.ts +18 -0
- package/dist/store/deadline.js +45 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +2 -2
- package/dist/store/open.d.ts +6 -3
- package/dist/store/open.js +2 -2
- package/dist/store/postgres/connection.d.ts +22 -2
- package/dist/store/postgres/connection.js +211 -41
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +9 -2
- package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
- package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
- package/dist/store/postgres/store.d.ts +9 -2
- package/dist/store/postgres/store.js +9 -0
- package/dist/store/schema.js +1 -1
- package/dist/store/seal.js +2 -2
- package/dist/store/sqlite/connection.js +14 -5
- package/dist/store/sqlite/run-patch.d.ts +3 -0
- package/dist/store/sqlite/run-patch.js +3 -0
- package/dist/store/sqlite/store.js +41 -12
- package/dist/store/store.d.ts +35 -6
- package/dist/store/store.js +12 -2
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +22 -4
- package/dist/store-reads/journal.d.ts +9 -6
- package/dist/store-reads/journal.js +129 -18
- package/dist/store-reads/learning.d.ts +82 -8
- package/dist/store-reads/learning.js +184 -11
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +19 -1
- package/dist/store-view.js +95 -27
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +33 -14
- package/dist/templates.js +82 -46
- package/dist/timeline/group.d.ts +33 -0
- package/dist/timeline/group.js +77 -0
- package/dist/timeline/index.d.ts +7 -0
- package/dist/timeline/index.js +7 -0
- package/dist/timeline/labels.d.ts +79 -0
- package/dist/timeline/labels.js +150 -0
- package/dist/timeline/origin.d.ts +56 -0
- package/dist/timeline/origin.js +92 -0
- package/dist/timeline/render-text.d.ts +11 -0
- package/dist/timeline/render-text.js +62 -0
- package/dist/timeline/timeline.d.ts +282 -0
- package/dist/timeline/timeline.js +1308 -0
- package/dist/timeline/util.d.ts +17 -0
- package/dist/timeline/util.js +49 -0
- package/dist/tool-budget.d.ts +18 -0
- package/dist/tool-budget.js +50 -0
- package/dist/tool-gate.d.ts +47 -218
- package/dist/tool-gate.js +87 -545
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +5 -101
- package/dist/tool-keys.js +8 -267
- package/dist/tool-plane.d.ts +23 -52
- package/dist/tool-plane.js +23 -81
- package/dist/tool-settings-store.d.ts +1 -2
- package/dist/tool-settings-store.js +5 -8
- package/dist/tools.d.ts +67 -25
- package/dist/tools.js +170 -119
- package/dist/trigger-adapter.d.ts +2 -2
- package/dist/trigger-targets.d.ts +13 -1
- package/dist/trigger-targets.js +31 -1
- package/dist/triggers.d.ts +2 -2
- package/dist/triggers.js +3 -3
- package/dist/turn-end.d.ts +1 -1
- package/dist/turn-end.js +1 -1
- package/dist/turns.d.ts +0 -6
- package/dist/turns.js +0 -19
- package/dist/uploads.d.ts +28 -5
- package/dist/uploads.js +83 -10
- package/dist/usage.d.ts +1 -49
- package/dist/usage.js +3 -84
- package/dist/validate.d.ts +4 -0
- package/dist/validate.js +33 -14
- package/dist/webhooks.d.ts +102 -76
- package/dist/webhooks.js +266 -233
- package/dist/workflow-run.d.ts +114 -0
- package/dist/workflow-run.js +144 -0
- package/dist/workspace/archil-claim.d.ts +2 -2
- package/dist/workspace/archil-claim.js +4 -3
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +4 -0
- package/dist/workspace/archil-exec.d.ts +12 -2
- package/dist/workspace/archil-exec.js +16 -0
- 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/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +26 -9
- package/dist/workspace/computer-deps.js +144 -43
- package/dist/workspace/computer-for-claim.d.ts +17 -14
- package/dist/workspace/computer-for-claim.js +99 -26
- package/dist/workspace/computer-hold.d.ts +6 -1
- package/dist/workspace/computer-hold.js +6 -1
- package/dist/workspace/computer-janitor.d.ts +47 -0
- package/dist/workspace/computer-janitor.js +182 -0
- package/dist/workspace/computer-ledger.d.ts +1 -8
- package/dist/workspace/computer-ledger.js +0 -3
- package/dist/workspace/computer-providers.d.ts +5 -3
- package/dist/workspace/computer-providers.js +11 -9
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/hands.d.ts +5 -2
- package/dist/workspace/hands.js +4 -3
- package/dist/workspace/index.d.ts +6 -5
- package/dist/workspace/index.js +4 -4
- package/dist/workspace/local.d.ts +14 -2
- package/dist/workspace/local.js +170 -43
- 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 +55 -10
- package/dist/workspace/resolve-computer.js +66 -14
- package/dist/workspace/run-tools.d.ts +15 -31
- package/dist/workspace/run-tools.js +19 -30
- package/dist/workspace/workspace.d.ts +5 -0
- package/dist/workspace-paths.d.ts +0 -17
- package/dist/workspace-paths.js +1 -41
- package/dist/workspace.d.ts +0 -17
- package/dist/workspace.js +4 -110
- package/package.json +14 -14
- package/skills/agentrun-serve/SKILL.md +1 -1
- package/templates/README.md +11 -5
- 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/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/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/templates/release-notes/agent.md +11 -0
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- package/dist/coding-tools.d.ts +0 -47
- package/dist/coding-tools.js +0 -189
- package/dist/computer-adb.d.ts +0 -12
- package/dist/computer-adb.js +0 -14
- package/dist/console/assets/index-Dn0ngwG9.js +0 -535
- package/dist/console/assets/index-DvW6Aled.css +0 -1
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- package/dist/mcp-servers.d.ts +0 -269
- package/dist/mcp-servers.js +0 -456
- package/dist/packs.d.ts +0 -71
- package/dist/packs.js +0 -180
- package/dist/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -171
- package/dist/sessions.d.ts +0 -6
- package/dist/sessions.js +0 -109
- package/dist/workspace/computer-serves.d.ts +0 -12
- package/dist/workspace/computer-serves.js +0 -15
|
@@ -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,20 +39,22 @@ 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 } from "./journal-kinds.js";
|
|
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";
|
|
43
45
|
import { PAUSED_WORDS } from "./workflow-loop.js";
|
|
44
46
|
import { heldRedactor, holdClaimed } from "./redact.js";
|
|
45
47
|
import { holdStored } from "./store-secrets.js";
|
|
46
48
|
import { workflowHost } from "./workflow-host.js";
|
|
49
|
+
import { bookedSpend } from "./metrics.js";
|
|
47
50
|
/** A model node's submit tool, by name: pi's SUBMIT_TOOL (packages/pi/src/host-tools.ts). Named here, not imported from
|
|
48
51
|
* @parcha/agentrun-pi, whose root loads its runner and with it pi-coding-agent, an optional peer an installed server
|
|
49
52
|
* does not have: importing it here stopped the runner from starting. workflow-submit-name.test.mjs holds the two equal. */
|
|
50
53
|
export const SUBMIT_TOOL = "submit";
|
|
51
54
|
/** The one session key the workflow's model requests book under (the run's one booking sums it, runBooking). */
|
|
52
|
-
const SESSION =
|
|
53
|
-
/** A call node's tool failure
|
|
55
|
+
const SESSION = WORKFLOW_SESSION;
|
|
56
|
+
/** A call node's tool failure, as app.ts's runEffect completed it (the loop's `failing` reads it). */
|
|
54
57
|
const TOOL_FAILED = "agentrun_serve_tool_failed";
|
|
55
|
-
const CAP_HELD = "agentrun_serve_cap_held";
|
|
56
58
|
/** A tier's provider from the runner's model route (model-route.ts routeOf), the one way the runner resolves a model
|
|
57
59
|
* (the pi adapter's path): the route's provider, model and price for the proxy's booking, and the catalog's cost and
|
|
58
60
|
* output ceiling as the cap prices the hold. So a workflow model node and a pi turn book the same model the same way. */
|
|
@@ -67,6 +69,7 @@ export function routeProviderOf(env) {
|
|
|
67
69
|
export async function providerFromRoute(route) {
|
|
68
70
|
return {
|
|
69
71
|
modelId: route.model,
|
|
72
|
+
...(route.named ? { named: route.named } : {}),
|
|
70
73
|
api: route.provider.api,
|
|
71
74
|
...(route.like ? { like: route.like } : {}),
|
|
72
75
|
origin: route.provider.origin,
|
|
@@ -96,11 +99,13 @@ async function raisedCapOf(harness, context) {
|
|
|
96
99
|
}
|
|
97
100
|
return capUsd;
|
|
98
101
|
}
|
|
99
|
-
/** The run's cap rule, handed to the loop so it parks and takes raises by the kernel cap without importing it.
|
|
102
|
+
/** The run's cap rule, handed to the loop so it parks and takes raises by the kernel cap without importing it. A park
|
|
103
|
+
* 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
|
|
104
|
+
* for the step that parked shows the new pause at the raised cap, and the next raise is checked against that. */
|
|
100
105
|
function capRuleOf(capUsd) {
|
|
101
106
|
return {
|
|
102
107
|
park: (refusal) => {
|
|
103
|
-
const park = parkOf({ message: refusal.message, forGood: refusal.forGood, ...(refusal.figures ? { figures: refusal.figures } : {}) }, capUsd);
|
|
108
|
+
const park = parkOf({ message: refusal.message, forGood: refusal.forGood, ...(refusal.figures ? { figures: refusal.figures } : {}) }, capUsd());
|
|
104
109
|
return park.outcome === "parked"
|
|
105
110
|
? { outcome: "parked", pending: park.pending, words: park.words }
|
|
106
111
|
: { outcome: "failed", error: park.error };
|
|
@@ -143,7 +148,7 @@ export function workflowSpecOf(deps) {
|
|
|
143
148
|
if (unbound !== undefined)
|
|
144
149
|
throw new Error(nodeToolUnboundText(unbound));
|
|
145
150
|
// Every secret the server keeps sealed (store-secrets.ts) held by the runner's one redactor before the workflow runs.
|
|
146
|
-
if (run?.redact)
|
|
151
|
+
if (run?.redact && deps.sealKey)
|
|
147
152
|
await holdStored(heldRedactor(run.redact), deps.store, deps.sealKey, deps.data);
|
|
148
153
|
const tiers = tiersOf(claimed.workflow);
|
|
149
154
|
// The run's own keys, as the server's runnable check reads them: each by its name from the runner's environment first,
|
|
@@ -189,7 +194,7 @@ export function workflowSpecOf(deps) {
|
|
|
189
194
|
const provider = providers.get(resolved) ?? providers.get("default");
|
|
190
195
|
if (!provider)
|
|
191
196
|
throw new Error(`the workflow names tier ${String(tier)}, which this run has no model for`);
|
|
192
|
-
return { provider: providerId(providers.has(resolved) ? resolved : "default"), modelId: provider.modelId };
|
|
197
|
+
return { provider: providerId(providers.has(resolved) ? resolved : "default"), modelId: provider.modelId, ...(provider.named ? { named: provider.named } : {}) };
|
|
193
198
|
};
|
|
194
199
|
const capModelOf = (id) => {
|
|
195
200
|
for (const provider of providers.values())
|
|
@@ -211,6 +216,9 @@ export function workflowSpecOf(deps) {
|
|
|
211
216
|
let decisionCap;
|
|
212
217
|
// The run's paid tool calls on its one cap (TOOL_SESSION), wired at harnessReady: a call node's hold and its request.
|
|
213
218
|
let paidTools;
|
|
219
|
+
// The call nodes' effects as they run (KINDS.nodeEffect on NODE_LOG_SESSION), opened at harnessReady: the run's graph
|
|
220
|
+
// lists its effects from them.
|
|
221
|
+
let nodeLog;
|
|
214
222
|
// The run's own keys with its plane, as an agentic run's tool host gets them: the call nodes' effects and the model
|
|
215
223
|
// nodes' tools run on these.
|
|
216
224
|
const callEnv = callEnvOf(claimedEnv, claimed);
|
|
@@ -218,12 +226,10 @@ export function workflowSpecOf(deps) {
|
|
|
218
226
|
const nodeHost = {
|
|
219
227
|
where: { root: claimed.workRoot, work: claimed.workRoot, ref: { id: claim.runId } },
|
|
220
228
|
env: callEnv,
|
|
221
|
-
coding: { tools: [], extension: { name: "coding", tools: [] } },
|
|
222
229
|
install: (extension) => void installed.push(extension),
|
|
223
230
|
onConversation: () => { },
|
|
224
231
|
beforeResume: () => { },
|
|
225
232
|
beforeRelease: () => { },
|
|
226
|
-
handoverInJournal: true,
|
|
227
233
|
};
|
|
228
234
|
const nodeBindings = await bindNodeTools(nodeNames, nodeHost);
|
|
229
235
|
// Each node tool as the node gets it and the registry holds it: booked on the run's one ledger (bookedNodeTools), in an
|
|
@@ -248,8 +254,8 @@ export function workflowSpecOf(deps) {
|
|
|
248
254
|
tools: [...new Set([...toolsOf(claimed.workflow), ...nodeNames])],
|
|
249
255
|
agentId: claimed.agentId,
|
|
250
256
|
revisionId: claimed.revisionId,
|
|
251
|
-
...(claimed.capUsd !== undefined ? { cap: capRuleOf(claimed.capUsd) } : {}),
|
|
252
|
-
endPatch: async () => endPatchOf(booking, decisionCap, paidTools),
|
|
257
|
+
...(claimed.capUsd !== undefined ? { cap: capRuleOf(() => effectiveCapUsd ?? claimed.capUsd) } : {}),
|
|
258
|
+
endPatch: async () => endPatchOf(booking, decisionCap, paidTools, run?.journal),
|
|
253
259
|
build: (loopHooks) => {
|
|
254
260
|
hooks.setPark(loopHooks);
|
|
255
261
|
const hostDeps = {
|
|
@@ -258,7 +264,7 @@ export function workflowSpecOf(deps) {
|
|
|
258
264
|
// would book beside the run's ledger), and the run's gate over them by name (main's registry.install).
|
|
259
265
|
sharedExtensions: [nodeToolGate(nodeNames, nodePolicy), ...[...nodeTools.values()].flatMap((binding) => binding.extensions)],
|
|
260
266
|
nodeTool: (name) => nodeTools.get(name),
|
|
261
|
-
runEffect: runEffectOf(claimed, complete, callEnv, callPolicyOf(deps.store, claim.runId, claimed), () => paidTools),
|
|
267
|
+
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()),
|
|
262
268
|
workRoot: claimed.workRoot,
|
|
263
269
|
flush: () => deps.store.flush(),
|
|
264
270
|
// A decision node books through the run's one cap (admitted and settled as main holds it); a cap refusal for room
|
|
@@ -305,8 +311,15 @@ export function workflowSpecOf(deps) {
|
|
|
305
311
|
// The run's paid tool calls on the same cap (TOOL_SESSION): a call node's hold before its admission, and the paid
|
|
306
312
|
// request it makes, as an agentic run's tool calls book (paidStep).
|
|
307
313
|
paidTools = await run.tools(await sessions.open(TOOL_SESSION), { flush: () => deps.store.flush() });
|
|
314
|
+
nodeLog = await sessions.open(NODE_LOG_SESSION);
|
|
308
315
|
hooks.setPort(booking.models);
|
|
309
316
|
},
|
|
317
|
+
settle: async () => {
|
|
318
|
+
const left = await hooks.bookingsSettled();
|
|
319
|
+
// Past the bound: the end is written, and each request still unbooked counts at its hold and bound (never less).
|
|
320
|
+
if (left > 0)
|
|
321
|
+
console.warn(`[runner] ${claim.runId}: ${left} model request(s) still unbooked ${CLOSE_MS} ms after the workflow ended; each counts at its hold and bound`);
|
|
322
|
+
},
|
|
310
323
|
release: async () => {
|
|
311
324
|
for (const proxy of proxies)
|
|
312
325
|
await proxy.close().catch(() => undefined);
|
|
@@ -372,18 +385,46 @@ export function pauseAtEffects(cap, hooks, flight) {
|
|
|
372
385
|
}
|
|
373
386
|
/** The proxies start before the booking is wired; their hooks forward to the booking set at harnessReady. A request before
|
|
374
387
|
* then would be a bug (no model request runs before the workflow does), so it refuses loudly. `park` is the loop's hook,
|
|
375
|
-
* set at build, which a cap refusal calls.
|
|
388
|
+
* set at build, which a cap refusal calls. Each request admitted is counted until it is booked: a request a person's
|
|
389
|
+
* stop cut short is booked only once its proxy sees the provider's side end, which can be after its node ended, and the
|
|
390
|
+
* run's end waits for it (bookingsSettled), as the pi adapter's loop does. */
|
|
376
391
|
function deferredHooks() {
|
|
377
392
|
let port;
|
|
378
393
|
let loop;
|
|
394
|
+
let unbooked = 0;
|
|
395
|
+
const bookedAll = [];
|
|
379
396
|
return {
|
|
380
397
|
port: {
|
|
381
|
-
beforeRequest: (request) =>
|
|
382
|
-
|
|
398
|
+
beforeRequest: async (request) => {
|
|
399
|
+
const ticket = await (port ?? missing()).beforeRequest(request);
|
|
400
|
+
unbooked += 1;
|
|
401
|
+
return ticket;
|
|
402
|
+
},
|
|
403
|
+
afterRequest: async (usage, ticket, ended) => {
|
|
404
|
+
try {
|
|
405
|
+
await (port ?? missing()).afterRequest(usage, ticket, ended);
|
|
406
|
+
}
|
|
407
|
+
finally {
|
|
408
|
+
unbooked = Math.max(0, unbooked - 1);
|
|
409
|
+
if (unbooked === 0)
|
|
410
|
+
for (const wake of bookedAll.splice(0))
|
|
411
|
+
wake();
|
|
412
|
+
}
|
|
413
|
+
},
|
|
383
414
|
responded: (ids, ticket) => (port ?? missing()).responded?.(ids, ticket) ?? Promise.resolve(),
|
|
384
415
|
note: (model, request) => (port ?? missing()).note?.(model, request),
|
|
385
416
|
},
|
|
386
417
|
setPort: (p) => { port = p; },
|
|
418
|
+
/** Waits, at most CLOSE_MS, until every request admitted is booked, and says how many are still not. Past the bound
|
|
419
|
+
* the run's end is written anyway, and a request left unbooked reads at its hold and bound, the worst it can have cost. */
|
|
420
|
+
bookingsSettled: async () => {
|
|
421
|
+
if (unbooked === 0)
|
|
422
|
+
return 0;
|
|
423
|
+
let timer;
|
|
424
|
+
await Promise.race([new Promise((resolve) => bookedAll.push(resolve)), new Promise((resolve) => (timer = setTimeout(resolve, CLOSE_MS)))]);
|
|
425
|
+
clearTimeout(timer);
|
|
426
|
+
return unbooked;
|
|
427
|
+
},
|
|
387
428
|
park: (refusal) => loop?.park(refusal),
|
|
388
429
|
// A person's pause, asked where the cap is (the loop's hooks): none before the loop hands its hooks over.
|
|
389
430
|
paused: () => loop?.paused() ?? false,
|
|
@@ -409,7 +450,7 @@ export function callHoldOf(tool, input, env, modelOfTier) {
|
|
|
409
450
|
return NO_HOLD(tool);
|
|
410
451
|
const fee = tool === "web_search" ? parallelSearchFee(searchArgs(input).n) : parallelExtractFee(1);
|
|
411
452
|
// Who charges for it (main's charge row's charged_by), as paidOn names it: the hold is the record its request books under.
|
|
412
|
-
return { usd: fee.usd, name: fee.name, basis: fee.basis, chargedBy: fee.by };
|
|
453
|
+
return { usd: fee.usd, name: fee.name, tool, basis: fee.basis, chargedBy: fee.by };
|
|
413
454
|
}
|
|
414
455
|
if (tool === "llm") {
|
|
415
456
|
const model = modelOfTier(typeof input.tier === "string" ? input.tier : undefined);
|
|
@@ -480,7 +521,7 @@ export function holdAtEffects(cap, deps) {
|
|
|
480
521
|
const call = `${params.node.label}@${params.executionPath ?? ""}`;
|
|
481
522
|
const id = `${call}#hold${(seq += 1)}`;
|
|
482
523
|
try {
|
|
483
|
-
await paid.admit({ id, name: hold.name, holdUsd: hold.usd, basis: hold.basis, call, ...(hold.chargedBy ? { chargedBy: hold.chargedBy } : {}) });
|
|
524
|
+
await paid.admit({ id, name: hold.name, ...(hold.tool ? { tool: hold.tool } : {}), holdUsd: hold.usd, basis: hold.basis, call, ...(hold.chargedBy ? { chargedBy: hold.chargedBy } : {}) });
|
|
484
525
|
}
|
|
485
526
|
catch (error) {
|
|
486
527
|
if (error instanceof CapRefused && !error.forGood) {
|
|
@@ -532,7 +573,7 @@ function callPolicyOf(store, runId, claimed) {
|
|
|
532
573
|
// Nothing read yet: unread, so a policy asked before the first read fails closed too.
|
|
533
574
|
let current = { settings: {}, problems: [], unreadable: true };
|
|
534
575
|
// Only the permission is read here: a workflow never parks, so whether anyone can answer an ask plays no part.
|
|
535
|
-
const gate = runGate({ root: claimed.workRoot, work: claimed.workRoot }, runId, claimed.revision, () => current,
|
|
576
|
+
const gate = runGate({ root: claimed.workRoot, work: claimed.workRoot }, runId, claimed.revision, () => current, true);
|
|
536
577
|
return async (tool) => {
|
|
537
578
|
current = await storeSettings(store);
|
|
538
579
|
return { permission: gate.policy(tool), denyFrom: gate.denyFrom(tool) };
|
|
@@ -562,13 +603,15 @@ export function failingEffects(cap) {
|
|
|
562
603
|
},
|
|
563
604
|
};
|
|
564
605
|
}
|
|
565
|
-
function runEffectOf(claimed, complete, env, policy, paidTools) {
|
|
606
|
+
function runEffectOf(claimed, complete, env, policy, paidTools, log) {
|
|
566
607
|
// An `llm` call gives its call's hold back as its own model request is judged (the cap holds that request itself).
|
|
567
608
|
const completeHeld = async (args, signal) => {
|
|
568
609
|
await releaseCallHold();
|
|
569
610
|
return complete(args, signal);
|
|
570
611
|
};
|
|
571
|
-
|
|
612
|
+
// A line the node log could not take (the claim lost meanwhile) costs the graph a line, never the call.
|
|
613
|
+
const logged = (line) => log(line).catch(() => undefined);
|
|
614
|
+
return (async ({ node, input, signal, executionPath, item }) => {
|
|
572
615
|
// The call's ledger: its paid request books on the run's one ledger, on the hold taken before the call (holdAtEffects)
|
|
573
616
|
// when it has one. No pause: a refusal inside an admitted effect fails the call, never parks the run there.
|
|
574
617
|
const held = heldBooking();
|
|
@@ -577,6 +620,9 @@ function runEffectOf(claimed, complete, env, policy, paidTools) {
|
|
|
577
620
|
const effect = node.via === "tool" && node.tool ? toolOf(node.tool)?.effect : undefined;
|
|
578
621
|
if (!effect)
|
|
579
622
|
throw new Error(`call node "${node.label}": agentrun-serve runs no tool ${node.tool ?? `via ${node.via}`}`);
|
|
623
|
+
// Its start and its end on the run's node log (main's app.ts), which the run's graph lists as its effects.
|
|
624
|
+
const at = { path: executionPath ?? null, item: item?.index ?? null, tool: node.tool, label: node.label };
|
|
625
|
+
await logged({ t: "effect.start", ...at, input, at: new Date().toISOString() });
|
|
580
626
|
// 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,
|
|
581
627
|
// and an ask too, since a call node cannot wait for an approval. Neither runs.
|
|
582
628
|
try {
|
|
@@ -585,10 +631,15 @@ function runEffectOf(claimed, complete, env, policy, paidTools) {
|
|
|
585
631
|
throw new Error(deniedText(node.tool, undefined, denyFrom));
|
|
586
632
|
if (permission === "ask")
|
|
587
633
|
throw new Error(callNodeAskText(node.tool));
|
|
588
|
-
|
|
634
|
+
const output = await effect(input, { signal, env, work: claimed.workRoot, complete: completeHeld, ...(ledger ? { ledger } : {}) });
|
|
635
|
+
await logged({ t: "effect.end", ...at, status: "done", output, at: new Date().toISOString() });
|
|
636
|
+
return output;
|
|
589
637
|
}
|
|
590
638
|
catch (error) {
|
|
591
639
|
const message = String(error?.message ?? error);
|
|
640
|
+
// Whole up to 64 KB, so the server redacts it before it cuts it for the graph (graph-served.ts); a longer one is
|
|
641
|
+
// marked cut.
|
|
642
|
+
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() });
|
|
592
643
|
if (signal.aborted || error?.name === "AbortError")
|
|
593
644
|
throw error;
|
|
594
645
|
return { [TOOL_FAILED]: `call node "${node.label}": ${node.tool} failed: ${message.slice(0, 500)}` };
|
|
@@ -598,71 +649,130 @@ function runEffectOf(claimed, complete, env, policy, paidTools) {
|
|
|
598
649
|
/** The end's cost and metrics: what every model request of the run cost (the booking) plus what its decisions and its
|
|
599
650
|
* call nodes' paid requests cost (the decision cap, the paid tools), one spend for the run. Unknown (no figure) once any
|
|
600
651
|
* part is unknown. */
|
|
601
|
-
|
|
652
|
+
/** What the run's decisions cost by their booking (bookedSpend, "decisions"), read from only what that needs: the root's
|
|
653
|
+
* session keys (journalSessions writes them there) and the decisions session's own conversation, never the run's model
|
|
654
|
+
* or tool records, so the read stays small within the end patch's bound. No decisions session: none, $0. */
|
|
655
|
+
async function decisionsBooked(journal) {
|
|
656
|
+
const root = await entriesOf(journal, ROOT_CONVERSATION_ID, BACKGROUND_CONTEXT);
|
|
657
|
+
const key = root.find((entry) => entry.kind === KINDS.sessionKey && entry.data?.key === DECISION_SESSION);
|
|
658
|
+
const conversation = key?.data?.conversation;
|
|
659
|
+
if (conversation == null)
|
|
660
|
+
return 0;
|
|
661
|
+
const decisions = await entriesOf(journal, conversation, BACKGROUND_CONTEXT);
|
|
662
|
+
return bookedSpend([key, ...decisions], "decisions").usd;
|
|
663
|
+
}
|
|
664
|
+
async function endPatchOf(booking, decisionCap, paidTools, journalOf) {
|
|
602
665
|
if (!booking)
|
|
603
666
|
return {};
|
|
604
667
|
const model = booking.spentUsd();
|
|
605
|
-
|
|
668
|
+
// A decision's cost is what its booking says it charged (bookedSpend over the decisions session's records, as the pi and
|
|
669
|
+
// CLI specs read it): one its provider reported no cost for is unknown, never the hold the cap counts it at
|
|
670
|
+
// (decisionCap.spentUsd, which stays the cap's own figure). With no journal to read, any decision is unknown.
|
|
671
|
+
const decision = !decisionCap ? 0 : journalOf ? await decisionsBooked(journalOf()) : null;
|
|
606
672
|
const paid = paidTools ? paidTools.spentUsd() : 0;
|
|
607
673
|
return model === null || decision === null || paid === null ? {} : { costUsd: model + decision + paid };
|
|
608
674
|
}
|
|
609
675
|
/** The run's one cap as a WorkflowCap: model nodes and call nodes pass through (their money is on the proxy), and a
|
|
610
|
-
* decision node is
|
|
611
|
-
* holds it. The reference is deferred because the cap is not
|
|
676
|
+
* decision node is priced before the DSL driver admits its request (`judge`) and held, sent and settled through the run's
|
|
677
|
+
* decisions once it is admitted (`admitted`), priced as main holds it. The reference is deferred because the cap is not
|
|
678
|
+
* built until the Harness opens. */
|
|
612
679
|
function decisionWorkflowCap(getCap, providers, hooks) {
|
|
613
|
-
|
|
680
|
+
const judging = decisionJudging({ getCap, providers, park: hooks.park, hooks });
|
|
681
|
+
return { node: (fn) => fn, effect: (fn) => fn, judge: judging.before, admitted: judging.admitted };
|
|
614
682
|
}
|
|
615
|
-
/** A decision
|
|
616
|
-
*
|
|
617
|
-
*
|
|
618
|
-
*
|
|
619
|
-
*
|
|
620
|
-
*
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
deps.
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
683
|
+
/** A decision under the run's cap, in two halves around the DSL driver's admission of its request (dsl withRecovery: the
|
|
684
|
+
* request is committed, `decision.request`, before the judge is asked; one asked and never answered is never asked again):
|
|
685
|
+
* - `before`, outside the admission: a request the driver answers from what it decided before (a route's, or one an
|
|
686
|
+
* earlier process admitted that did not fail) holds nothing (askedBefore); a person's pause parks the run; the
|
|
687
|
+
* request is priced as main prices it (holdOf), its catalog read again on a moment's outage.
|
|
688
|
+
* - `admitted`, the judge the driver asks once it has admitted the request: the hold is taken through the kernel cap (its
|
|
689
|
+
* record made durable before the send), the provider is asked, and the hold is settled at what the answer charged (its
|
|
690
|
+
* hold when it reports none). So a hold is never kept for a request the driver did not admit: a process that dies
|
|
691
|
+
* before the admission leaves nothing for the next claim to count beside asking it again. A refusal for room or for no
|
|
692
|
+
* price ends the admitted request failed, unsent, in the driver's commit (asked again by the next claim), and then parks
|
|
693
|
+
* the run, or fails it, through the loop's hook, as a model node's refusal does. A price the catalog still could not
|
|
694
|
+
* read fails the decision node as an unsent connection error, never the cap's stop. */
|
|
695
|
+
function decisionJudging(deps) {
|
|
696
|
+
/** Each request `before` priced, by the params object the driver hands on to `admitted`; and the cap's refusal of one. */
|
|
697
|
+
const priced = new WeakMap();
|
|
698
|
+
const refused = new WeakMap();
|
|
699
|
+
return {
|
|
700
|
+
before(inner, driver) {
|
|
701
|
+
const judge = inner;
|
|
702
|
+
return (async (params) => {
|
|
703
|
+
if (driver && askedBefore(driver, params))
|
|
704
|
+
return judge(params);
|
|
705
|
+
// A person's pause in force parks the run before a new decision is held or sent, as a refusal for room does.
|
|
706
|
+
if (deps.hooks?.paused()) {
|
|
707
|
+
deps.hooks.pause();
|
|
708
|
+
throw new Error(PAUSED_WORDS);
|
|
709
|
+
}
|
|
710
|
+
const id = params.provider ?? deps.providers.default;
|
|
711
|
+
const provider = Object.hasOwn(deps.providers.providers, id) ? deps.providers.providers[id] : undefined;
|
|
712
|
+
// A provider the host lacks is refused by the judge itself (configuration), before anything is held.
|
|
713
|
+
if (!provider)
|
|
714
|
+
return judge(params);
|
|
715
|
+
// The cap is wired at harnessReady, before any node runs; a decision reaching here without it is a bug.
|
|
716
|
+
if (!deps.getCap())
|
|
717
|
+
throw new Error(`decision "${params.label}": the run's decision cap was not wired before the workflow ran`);
|
|
718
|
+
priced.set(params, await decisionRequestOf(provider, params));
|
|
719
|
+
try {
|
|
720
|
+
return await judge(params);
|
|
721
|
+
}
|
|
722
|
+
catch (error) {
|
|
723
|
+
const refusal = refused.get(params);
|
|
724
|
+
if (!refusal)
|
|
725
|
+
throw error;
|
|
726
|
+
// The cap refused the admitted request: the driver ended it failed, unsent; that commit lands before the run
|
|
727
|
+
// parks, so the next claim asks it again rather than finding it asked and never answered. A commit the store
|
|
728
|
+
// refused is thrown, never a park: parked with the request still asked, the next claim would refuse to ask it.
|
|
729
|
+
await driver?.flush();
|
|
730
|
+
deps.park({ message: refusal.message, forGood: refusal.forGood, ...(refusal.figures ? { figures: refusal.figures } : {}) });
|
|
731
|
+
throw refusal;
|
|
732
|
+
}
|
|
733
|
+
finally {
|
|
734
|
+
priced.delete(params);
|
|
735
|
+
refused.delete(params);
|
|
736
|
+
}
|
|
737
|
+
});
|
|
738
|
+
},
|
|
739
|
+
admitted(inner) {
|
|
740
|
+
const judge = inner;
|
|
741
|
+
return (async (params) => {
|
|
742
|
+
const request = priced.get(params);
|
|
743
|
+
const cap = deps.getCap();
|
|
744
|
+
if (!request || !cap)
|
|
745
|
+
return judge(params);
|
|
746
|
+
try {
|
|
747
|
+
await cap.admit(request);
|
|
748
|
+
}
|
|
749
|
+
catch (error) {
|
|
750
|
+
// A refusal the cap read: told to `before` (which parks or fails the run once the driver has ended the request),
|
|
751
|
+
// and thrown here as a request that never left, so the driver ends it failed with nothing spent.
|
|
752
|
+
if (error instanceof CapRefused) {
|
|
753
|
+
refused.set(params, error);
|
|
754
|
+
throw new DecisionProviderError("connection", `${params.label}'s decision was not sent: ${error.message}`, { unsent: true, cause: error });
|
|
755
|
+
}
|
|
756
|
+
// A price the catalog could not read: the decision node fails unsent, as a connection error, never the cap.
|
|
757
|
+
if (error instanceof DecisionPriceUnreadable)
|
|
758
|
+
throw new DecisionProviderError("connection", `${params.label}'s decision was not sent: ${error.message}`, { unsent: true, cause: error });
|
|
759
|
+
throw error;
|
|
760
|
+
}
|
|
761
|
+
try {
|
|
762
|
+
const result = await judge(params);
|
|
763
|
+
await cap.settle(request.id, { end: "charged", usd: finiteUsd(result?.cost_usd) });
|
|
764
|
+
return result;
|
|
765
|
+
}
|
|
766
|
+
catch (error) {
|
|
767
|
+
// Sent and maybe billed (its outcome lost, its answer rejected): at what it was charged, else at its hold (null).
|
|
768
|
+
// One its provider refused unbilled, or that never left, charged nothing: booked at $0 so no later process counts it.
|
|
769
|
+
const charged = chargedCost(error);
|
|
770
|
+
await cap.settle(request.id, { end: "charged", usd: charged !== undefined ? charged : unbilled(error) ? 0 : null });
|
|
771
|
+
throw error;
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
},
|
|
775
|
+
};
|
|
666
776
|
}
|
|
667
777
|
/** A decision's request for the kernel cap, priced as main holds it (serve decision-cap.ts holdOf): Parallel's list price
|
|
668
778
|
* for one request; Jev's published per-input-token price; an OpenRouter Decisions model at its catalog price (per request,
|
|
@@ -687,11 +797,12 @@ async function decisionRequestOf(provider, params) {
|
|
|
687
797
|
return { ...base, model: openrouterModel(model ?? provider.id, null, null) };
|
|
688
798
|
let price;
|
|
689
799
|
try {
|
|
690
|
-
|
|
800
|
+
// Read again on a moment's outage (catalogPrice, CATALOG_TRIES reads), as main reads it.
|
|
801
|
+
price = await catalogPrice(priced, model, params.signal);
|
|
691
802
|
}
|
|
692
803
|
catch {
|
|
693
|
-
// The catalog could not be read: the decision fails unsent as a connection error, never the cap's stop (asModel
|
|
694
|
-
// DecisionPriceUnreadable for "unreadable").
|
|
804
|
+
// The catalog still could not be read: the decision fails unsent as a connection error, never the cap's stop (asModel
|
|
805
|
+
// throws DecisionPriceUnreadable for "unreadable").
|
|
695
806
|
return { ...base, model: "unreadable" };
|
|
696
807
|
}
|
|
697
808
|
if (!price)
|
|
@@ -741,17 +852,30 @@ function nodeToolGate(names, policy) {
|
|
|
741
852
|
name: "tool-gate",
|
|
742
853
|
wraps: [...names].map((name) => wrapTool({ name }, (inner) => ({
|
|
743
854
|
...inner,
|
|
744
|
-
|
|
745
|
-
const { permission, denyFrom } = await policy(inner.name);
|
|
746
|
-
if (permission === "deny")
|
|
747
|
-
return forModel(deniedText(inner.name, undefined, denyFrom), { isError: true });
|
|
748
|
-
if (permission === "ask")
|
|
749
|
-
return forModel(modelNodeAskText(inner.name), { isError: true });
|
|
750
|
-
return inner.execute(args, api, context);
|
|
751
|
-
},
|
|
855
|
+
execute: gatedNodeCall(inner.name, policy, inner.execute),
|
|
752
856
|
}))),
|
|
753
857
|
});
|
|
754
858
|
}
|
|
859
|
+
/** The task memo the gate keeps that it let a call through, before the call runs. */
|
|
860
|
+
const LET_THROUGH = "agentrun.gate.let-through";
|
|
861
|
+
/** `execute` behind the gate, for the tool `name`. A call it lets through is marked so in its task first, so when
|
|
862
|
+
* pi-durable's recovery runs the same call again on a later claim (the first attempt cut with its claim, maybe after it
|
|
863
|
+
* was sent) and the tool is now denied or set to ask, the refusal says that whether it took effect is not known
|
|
864
|
+
* (RAN_UNKNOWN), never that it was not run or that nothing was sent and nothing was charged. */
|
|
865
|
+
export function gatedNodeCall(name, policy, execute) {
|
|
866
|
+
return async (args, api, context) => {
|
|
867
|
+
const task = api;
|
|
868
|
+
const { permission, denyFrom } = await policy(name);
|
|
869
|
+
if (permission !== "allow") {
|
|
870
|
+
// A call an earlier attempt of which this gate let through may have reached its host: whatever refuses it now, its
|
|
871
|
+
// effect is not known, never "not run".
|
|
872
|
+
const ran = (await task.memo(LET_THROUGH, context)) === true ? "unknown" : "no";
|
|
873
|
+
return forModel(permission === "deny" ? deniedText(name, undefined, denyFrom, ran) : modelNodeAskText(name, ran), { isError: true });
|
|
874
|
+
}
|
|
875
|
+
await task.memo(LET_THROUGH, true, context);
|
|
876
|
+
return execute(args, api, context);
|
|
877
|
+
};
|
|
878
|
+
}
|
|
755
879
|
/** `binding`'s tools with each call's paid requests booked on the run's one ledger (Ledger.paid, the paid tool calls on
|
|
756
880
|
* the run's cap, as an agentic run's are), a refusal for room parking the run (Ledger.pause, as main's paidCall pauses):
|
|
757
881
|
* a node's tool call is the node's own turn, so the run parks and resumes it from its journal. */
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { Revision } from "
|
|
2
|
-
import type { MessageOrigin } from "
|
|
1
|
+
import type { Revision } from "./agent-rows.js";
|
|
2
|
+
import type { MessageOrigin } from "./timeline/index.js";
|
|
3
3
|
import { type AgentEntry, type ExternalRef } from "./agents-store.js";
|
|
4
4
|
import { ApiError, type InputIssue } from "./errors.js";
|
|
5
5
|
import { type LearningMode, type Seed, type Shown } from "./learning.js";
|
|
6
6
|
import { type Place } from "./place.js";
|
|
7
7
|
import { type RunLaunch } from "./run-launch.js";
|
|
8
|
-
import type
|
|
8
|
+
import { type ApprovalDecision, type RunMoment } from "./run-view.js";
|
|
9
9
|
import { type NewRevision, type RunOrigin, type RunRow, type Store } from "./store/index.js";
|
|
10
10
|
import { type ToolSettingsMap } from "./tool-plane.js";
|
|
11
11
|
import type { RunTrigger } from "./triggers.js";
|
|
@@ -111,6 +111,12 @@ export interface StartDeps {
|
|
|
111
111
|
/** The uploaded files named by file_ids, ready to copy; throws when one is not ready (server.ts uploads.readyFiles). The
|
|
112
112
|
* copy into the run's work/ is the runner's at its claim; this only checks they are ready before the run starts. */
|
|
113
113
|
readyFiles(ids: readonly unknown[]): Promise<unknown>;
|
|
114
|
+
/** Holds the run's files for it (uploads.ts Uploads.hold) before its row is written, so a file deleted after the start
|
|
115
|
+
* is still the run's at its claim; `release` lets go of a hold whose run was never written (or was another's). */
|
|
116
|
+
readonly files?: {
|
|
117
|
+
hold(runId: string, ids: readonly string[]): Promise<void>;
|
|
118
|
+
release(runId: string): Promise<void>;
|
|
119
|
+
};
|
|
114
120
|
/** Where a revision naming these tools and no place runs here (server.ts fallbackPlace). */
|
|
115
121
|
fallbackPlace(kind: "agentic" | "workflow", tools: readonly unknown[]): Place;
|
|
116
122
|
/** A run's title from its input (server.ts workflowTitle), for a workflow run's title. */
|
|
@@ -128,6 +134,8 @@ export interface StartDeps {
|
|
|
128
134
|
readonly documents?: string;
|
|
129
135
|
/** What a run's box may reach, as the server resolved it, or "none". */
|
|
130
136
|
readonly boxAllow?: readonly string[] | "none";
|
|
137
|
+
/** The operator set that (run-launch.ts boxAllowSet). */
|
|
138
|
+
readonly boxAllowSet?: true;
|
|
131
139
|
/** The run's model, pinned at start: resolved exactly as the old per-run process resolved it from the revision and agent
|
|
132
140
|
* (app.ts's runModels / wireModels over revision.body.model on its harness). The runner reads launch.model alone, so one
|
|
133
141
|
* resolution happens, here. Required. */
|
|
@@ -147,6 +155,9 @@ export interface StartDeps {
|
|
|
147
155
|
}>;
|
|
148
156
|
/** The learning budget in bytes (learning.ts LEARNING_BUDGET), for which notes fit a run's # Learned section. */
|
|
149
157
|
readonly learningBudget?: number;
|
|
158
|
+
/** The model the server names to grade what a run proposes (learning.ts gradeModelOf), put on each learning start; none,
|
|
159
|
+
* the agent's own grades it. */
|
|
160
|
+
readonly gradeModel?: string;
|
|
150
161
|
/** The host's secrets as they are shown now (learning-run.ts shown), for cutting the notes a run is given. */
|
|
151
162
|
shown?(): Shown;
|
|
152
163
|
}
|