@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
package/dist/browser-person.js
CHANGED
|
@@ -20,8 +20,14 @@
|
|
|
20
20
|
// that dies: the run's next claim reads it back from the journal and takes the wait up (`adopt`).
|
|
21
21
|
import { createHash } from "node:crypto";
|
|
22
22
|
import { HOST_PHASE } from "./timeline/index.js";
|
|
23
|
-
/** How long a person's time lasts at most before it expires: an unanswered ask,
|
|
23
|
+
/** How long a person's time lasts at most before it expires: an unanswered ask, a take-over with no input, and a run that
|
|
24
|
+
* waits for its person's answer with its browser kept open. Its worth of session time is held up front. The default of
|
|
25
|
+
* the server setting PERSON_WAIT_ENV. */
|
|
24
26
|
export const PERSON_HOLD_MS = 15 * 60_000;
|
|
27
|
+
/** The server setting for that window, in whole minutes (1 to 360; anything else keeps the 15-minute default): how long a
|
|
28
|
+
* run waiting for its person keeps its browser open, how long an agent's hand-over ask waits, and how long a take-over
|
|
29
|
+
* lasts with no input. One setting for all three, so they never drift apart. */
|
|
30
|
+
export const PERSON_WAIT_ENV = "AGENTRUN_BROWSER_PERSON_WAIT_MIN";
|
|
25
31
|
/** How long a take-over outlasts its viewer. */
|
|
26
32
|
export const PERSON_AWAY_MS = 2 * 60_000;
|
|
27
33
|
/** Under `--faux` only (the tests, beside the fake browser's own FAUX_BROWSER_LOG): the two windows above, in ms, `<hold>,<away>`. */
|
|
@@ -509,7 +515,8 @@ export function personHands(options) {
|
|
|
509
515
|
* and its release lets the browser go, booking its time to then. `pauses: false`: a refusal pauses nothing, the run
|
|
510
516
|
* parks on its question as it would with no browser. Refused in the cap's words when there is no room. `lapsed`
|
|
511
517
|
* settles, in words, at the bound, when the cap refuses a re-hold (a take-over's sharing the session), or when a
|
|
512
|
-
* session it keeps is let go (sessionEnded);
|
|
518
|
+
* session it keeps is let go (sessionEnded); confirmed() writes that lapse's row and ended state once the runner
|
|
519
|
+
* parked the run on it; drop() lets the shares go, once. */
|
|
513
520
|
async wait(callId, tags, since = now()) {
|
|
514
521
|
const user = `wait:${callId}`;
|
|
515
522
|
const held = [];
|
|
@@ -524,25 +531,57 @@ export function personHands(options) {
|
|
|
524
531
|
const expiresAt = since + holdMs;
|
|
525
532
|
if (expiresAt <= now())
|
|
526
533
|
return { refused: waitExpired(holdMs) };
|
|
534
|
+
const record = (row, at) => {
|
|
535
|
+
void note(HOST_PHASE, { summary: row, at });
|
|
536
|
+
try {
|
|
537
|
+
options.waitEnded?.(at, row);
|
|
538
|
+
}
|
|
539
|
+
catch { /* the Screen tab's state is a convenience; the row stands */ }
|
|
540
|
+
};
|
|
527
541
|
for (const tag of new Set(tags)) {
|
|
528
542
|
const refused = await acquire(tag, user, WAIT_WHAT, false, expiresAt);
|
|
529
543
|
if (refused) {
|
|
530
544
|
letGo();
|
|
545
|
+
// The cap has no room for the person's time: the run parks and its release lets the browser go, and the person is told why.
|
|
546
|
+
if (!closed)
|
|
547
|
+
record(`The browser was released while the run waited for you: ${refused.refused}`, now());
|
|
531
548
|
return refused;
|
|
532
549
|
}
|
|
533
550
|
held.push(tag);
|
|
534
551
|
}
|
|
535
|
-
let
|
|
536
|
-
const lapsed = new Promise((resolve) => (
|
|
552
|
+
let settle = () => { };
|
|
553
|
+
const lapsed = new Promise((resolve) => (settle = resolve));
|
|
554
|
+
// The wait ends once: at its window, when a session it keeps ends, or at the cap. Each settles `lapsed` at once, and its
|
|
555
|
+
// timeline row and the Screen tab's state are written when the runner confirms the run parked on it (a lapse during
|
|
556
|
+
// the answer's placement is ignored by the runner: the answer's turn goes on, on the same browser). The answer ends it
|
|
557
|
+
// too (drop: no row, the run goes on).
|
|
558
|
+
let over = false;
|
|
559
|
+
let pending;
|
|
560
|
+
const end = (words, row) => {
|
|
561
|
+
if (over)
|
|
562
|
+
return;
|
|
563
|
+
over = true;
|
|
564
|
+
pending = { row, at: now() };
|
|
565
|
+
settle(words);
|
|
566
|
+
};
|
|
567
|
+
const lapse = (words) => end(words, words === WAIT_SESSION_GONE ? BROWSER_GONE_WHILE_WAITING : `The browser was released while the run waited for you: ${words}`);
|
|
537
568
|
const entry = { tags: new Set(held), lapse };
|
|
538
569
|
waits.set(user, entry);
|
|
539
|
-
bound = timers.set(() =>
|
|
570
|
+
bound = timers.set(() => end(waitExpired(holdMs), releasedAfterWait(holdMs)), Math.max(0, expiresAt - now()));
|
|
540
571
|
// A session let go while its hold was being admitted: told before this wait was there to hear it.
|
|
541
572
|
if (held.some((tag) => ended.has(tag)))
|
|
542
573
|
lapse(WAIT_SESSION_GONE);
|
|
543
574
|
return {
|
|
544
575
|
lapsed,
|
|
576
|
+
confirmed: () => {
|
|
577
|
+
const ended = pending;
|
|
578
|
+
pending = undefined;
|
|
579
|
+
if (ended)
|
|
580
|
+
record(ended.row, ended.at);
|
|
581
|
+
},
|
|
545
582
|
drop: () => {
|
|
583
|
+
over = true;
|
|
584
|
+
pending = undefined;
|
|
546
585
|
if (waits.get(user) === entry)
|
|
547
586
|
waits.delete(user);
|
|
548
587
|
letGo();
|
|
@@ -580,5 +619,15 @@ export function personHands(options) {
|
|
|
580
619
|
* tests' (FAUX_PERSON_MS_ENV). */
|
|
581
620
|
export function personWindows(env, faux) {
|
|
582
621
|
const [hold, away] = (faux ? env[FAUX_PERSON_MS_ENV] ?? "" : "").split(",").map(Number);
|
|
583
|
-
return { holdMs: hold && hold > 0 ? hold :
|
|
622
|
+
return { holdMs: hold && hold > 0 ? hold : personWaitMs(env), awayMs: away && away > 0 ? away : PERSON_AWAY_MS };
|
|
623
|
+
}
|
|
624
|
+
/** The person's window from the server setting PERSON_WAIT_ENV, in ms: whole minutes from 1 to 360, else the default. */
|
|
625
|
+
export function personWaitMs(env) {
|
|
626
|
+
const raw = env[PERSON_WAIT_ENV]?.trim();
|
|
627
|
+
const minutes = raw && /^\d+$/.test(raw) ? Number(raw) : NaN;
|
|
628
|
+
return minutes >= 1 && minutes <= 360 ? minutes * 60_000 : PERSON_HOLD_MS;
|
|
584
629
|
}
|
|
630
|
+
/** The timeline row when a run's wait for its person ends at its window and its browser is let go. */
|
|
631
|
+
export const releasedAfterWait = (holdMs) => `The browser was released after ${Math.round(holdMs / 60_000) || 1} min waiting for you`;
|
|
632
|
+
/** The timeline row when a browser the run kept open for its person ended before their answer (its provider ended it). */
|
|
633
|
+
export const BROWSER_GONE_WHILE_WAITING = "The browser session ended while the run waited for you";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** The store seam: the server's settings (store/store.ts Settings), the three calls this uses. */
|
|
2
|
+
export type WaitEndedSettings = {
|
|
3
|
+
get(key: string): Promise<unknown | undefined>;
|
|
4
|
+
put(key: string, value: unknown): Promise<void>;
|
|
5
|
+
remove(key: string): Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
/** A browser let go while its run waited for its person: when (ISO) and the timeline row's words. */
|
|
8
|
+
export type WaitEnded = {
|
|
9
|
+
at: string;
|
|
10
|
+
why: string;
|
|
11
|
+
};
|
|
12
|
+
/** The run's process, as its wait ends with the browser let go: kept for the Screen tab. */
|
|
13
|
+
export declare function markWaitEnded(settings: WaitEndedSettings, runId: string, ended: WaitEnded, epoch?: number): Promise<void>;
|
|
14
|
+
/** The run's process, as any browser session of the run opens, or at the run's end: nothing ended any more. Given the
|
|
15
|
+
* claim's `epoch`, a message a later claim wrote stays (a follow-up that started on another runner while this claim's
|
|
16
|
+
* loop was still closing keeps its own). */
|
|
17
|
+
export declare function clearWaitEnded(settings: WaitEndedSettings, runId: string, epoch?: number): Promise<void>;
|
|
18
|
+
/** The server's Screen read: for a run that has ended, nothing, and its row goes (a run that ended with no browser after
|
|
19
|
+
* the wait leaves none behind: the runner removes it at the end too, this catches any end that didn't); for a going
|
|
20
|
+
* run, the ended state. */
|
|
21
|
+
export declare function screenWaitEnded(settings: WaitEndedSettings, runId: string, terminal: boolean): Promise<WaitEnded | undefined>;
|
|
22
|
+
/** The ended state, or undefined. One settings read; a value of another shape is no ended state. */
|
|
23
|
+
export declare function readWaitEnded(settings: Pick<WaitEndedSettings, "get">, runId: string): Promise<WaitEnded | undefined>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Why a run's browser is not up while the run is still going, for GET /v2/runs/{run_id}/computer's `none`: the browser
|
|
2
|
+
// was let go while the run waited for its person (browser-person.ts personHands.wait ends with a timeline row saying so),
|
|
3
|
+
// and the run has opened none since. The Screen tab says that, with when, instead of waiting for a browser nobody is
|
|
4
|
+
// opening.
|
|
5
|
+
//
|
|
6
|
+
// One small server setting per run holds it (`browser_wait_ended:<run id>`: { at, why }), written by the run's process as
|
|
7
|
+
// the wait ends and removed as any browser session of the run opens, whatever let the old one go (its idle release, the
|
|
8
|
+
// tool, a close at the park). So a Screen poll, every few seconds on a parked run, reads one row, never the run's journal.
|
|
9
|
+
const keyOf = (runId) => `browser_wait_ended:${runId}`;
|
|
10
|
+
/** The run's process, as its wait ends with the browser let go: kept for the Screen tab. */
|
|
11
|
+
export async function markWaitEnded(settings, runId, ended, epoch) {
|
|
12
|
+
await settings.put(keyOf(runId), epoch === undefined ? ended : { ...ended, epoch });
|
|
13
|
+
}
|
|
14
|
+
/** The run's process, as any browser session of the run opens, or at the run's end: nothing ended any more. Given the
|
|
15
|
+
* claim's `epoch`, a message a later claim wrote stays (a follow-up that started on another runner while this claim's
|
|
16
|
+
* loop was still closing keeps its own). */
|
|
17
|
+
export async function clearWaitEnded(settings, runId, epoch) {
|
|
18
|
+
if (epoch !== undefined) {
|
|
19
|
+
const written = (await settings.get(keyOf(runId)))?.epoch;
|
|
20
|
+
if (typeof written === "number" && written > epoch)
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
await settings.remove(keyOf(runId));
|
|
24
|
+
}
|
|
25
|
+
/** The server's Screen read: for a run that has ended, nothing, and its row goes (a run that ended with no browser after
|
|
26
|
+
* the wait leaves none behind: the runner removes it at the end too, this catches any end that didn't); for a going
|
|
27
|
+
* run, the ended state. */
|
|
28
|
+
export async function screenWaitEnded(settings, runId, terminal) {
|
|
29
|
+
if (terminal) {
|
|
30
|
+
await settings.remove(keyOf(runId)).catch(() => undefined);
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
return readWaitEnded(settings, runId);
|
|
34
|
+
}
|
|
35
|
+
/** The ended state, or undefined. One settings read; a value of another shape is no ended state. */
|
|
36
|
+
export async function readWaitEnded(settings, runId) {
|
|
37
|
+
const value = await settings.get(keyOf(runId));
|
|
38
|
+
if (!value || typeof value !== "object")
|
|
39
|
+
return undefined;
|
|
40
|
+
const { at, why } = value;
|
|
41
|
+
return typeof at === "string" && typeof why === "string" ? { at, why } : undefined;
|
|
42
|
+
}
|
package/dist/cap.d.ts
CHANGED
|
@@ -84,7 +84,7 @@ export declare function wrapUpDue(cap: number, spent: number, held: number, typi
|
|
|
84
84
|
/** The wrap-up's words, what is left to the cent. `nonePriced`: the run's own model has no priced request yet, so its
|
|
85
85
|
* typical cost is the next request's expected cost and the note can come before the run has done anything (step 0):
|
|
86
86
|
* the words say the budget and ask for a short answer, not a finish. Read from the same priced costs live and in a
|
|
87
|
-
* process opened again (
|
|
87
|
+
* process opened again (ownCosts), so a restart picks the same words. */
|
|
88
88
|
export declare const wrapUpWords: (leftUsd: number, nonePriced?: boolean) => string;
|
|
89
89
|
/** A request priced at `price` under `mode`, its input `bound` tokens after `previous` at `now`, plus `feeUsd`: `cost`, what
|
|
90
90
|
* it is held at given its output tokens (its expected input, never more than uncached), and `worst`, its input uncached.
|
|
@@ -167,7 +167,7 @@ export declare const attemptLost: (a: Attempt, last: boolean) => boolean;
|
|
|
167
167
|
export declare const anyAttemptLost: (attempts: readonly Attempt[] | undefined) => boolean;
|
|
168
168
|
export declare function piEnded(message: Pick<AssistantMessage, "stopReason" | "usage" | "api">, began: boolean, attempts: readonly Attempt[] | undefined): Ended;
|
|
169
169
|
/** How pi's error for a request whose start mark could not be written begins (request-start.ts builds it from this): the
|
|
170
|
-
* request never left, so the entry answers none, and
|
|
170
|
+
* request never left, so the entry answers none, and spentFrom leaves it out by this. */
|
|
171
171
|
export declare const MARK_NOT_WRITTEN = "the model request was not sent: its mark could not be written";
|
|
172
172
|
/** pi's error for a request that left and whose end mark the store refused (request-start.ts): its cost is not recorded
|
|
173
173
|
* as booked, so it stays open, read at its start mark's hold, never closed by this entry at its own usage. */
|
|
@@ -194,19 +194,8 @@ export declare const CAP_REFUSAL_PREFIX: RegExp;
|
|
|
194
194
|
* before its end), and the usd of a cost written apart from an answer, a paid tool's charge among them; 0 for anything
|
|
195
195
|
* else, or for a cost that is not a number (which makes the whole spend unknown, by the timeline's verdict). */
|
|
196
196
|
export declare const costOf: (entry: EntryLike) => number;
|
|
197
|
-
/** What the run's
|
|
198
|
-
*
|
|
199
|
-
* then the full amount, never the timeline's total rounded for display. Every response, and each cost written apart
|
|
200
|
-
* from one (a compaction summary's; a harness request's that came in after its answer). A cost that is not a number, or
|
|
201
|
-
* one still pending, leaves it unknown, as the timeline says. These readings are the cap's own, on its copy of the
|
|
202
|
-
* entries (the run's shown cost is the timeline's, unchanged): a request stopped before its end counts at the figure its
|
|
203
|
-
* end mark holds (HELD_FIELD), and one a crash cut (marked as sent, no answer, no end) at the figure its start mark
|
|
204
|
-
* holds (openFigures), each the worst case the cap held for it; without that figure either stays cut, at an unknown
|
|
205
|
-
* cost. A paid call settled at a charge it did not say, like one a crash cut, counts at the figure its mark holds. And
|
|
206
|
-
* this cap's refusals are left out, as none left. Unknown is null, which a cap never reads as $0. */
|
|
207
|
-
export declare function spentIn(storeFile: string): number | null;
|
|
208
|
-
/** What the run's model requests cost, from its entries in log order: the one computation, shared by spentIn (reading a
|
|
209
|
-
* settled run's own database) and the one-store reader (store-reads, reading A's journal). These readings are the cap's
|
|
197
|
+
/** What the run's model requests cost, from its entries in log order: the one computation, which the one-store reader
|
|
198
|
+
* (store-reads/cap.ts spentOverStore) runs over A's journal. These readings are the cap's
|
|
210
199
|
* own, on its copy of the entries (the run's shown cost is the timeline's, unchanged): a request stopped before its end
|
|
211
200
|
* counts at the figure its end mark holds (HELD_FIELD), and one a crash cut (marked as sent, no answer, no end) at the
|
|
212
201
|
* figure its start mark holds (openFigures), each the worst case the cap held for it; without that figure either stays
|
|
@@ -219,7 +208,7 @@ export declare const DECISION_COST = "agentrun.decision_cost";
|
|
|
219
208
|
/** A decision request's hold, kept before it is sent (decision-cap.ts): with no DECISION_COST after it, its process died
|
|
220
209
|
* while it was out, and it counts at this figure. */
|
|
221
210
|
export declare const DECISION_HOLD = "agentrun.decision_hold";
|
|
222
|
-
/** What a workflow run's decisions cost, in its store: what the next process adds to
|
|
211
|
+
/** What a workflow run's decisions cost, in its store: what the next process adds to spentFrom's reading. Per decision
|
|
223
212
|
* (its id):
|
|
224
213
|
* - booked (DECISION_COST entries, at its charge, its hold, or $0 for nothing charged): the larger of what was booked,
|
|
225
214
|
* with any hold no booking ended, and what its receipts say it cost (the costs the timeline's decision rows sum);
|
|
@@ -229,12 +218,6 @@ export declare const DECISION_HOLD = "agentrun.decision_hold";
|
|
|
229
218
|
* - else nothing: no hold is kept before the admission, so a request never sent is never counted.
|
|
230
219
|
* A booking with no decision id is counted as it is. */
|
|
231
220
|
export declare function decisionSpentIn(storeFile: string): number;
|
|
232
|
-
/** The priced answers of `model` (its id) in the run's store, in order: what the wrap-up's typical cost reads from earlier
|
|
233
|
-
* processes (capModels' `wrapUp`). An answer whose cost is unknown or $0, or that was stopped or failed, is none. */
|
|
234
|
-
export declare function costsIn(storeFile: string, model: string): number[];
|
|
235
|
-
/** Whether the run was told its wrap-up under `cap` already (a CAP_WRAPUP entry of that cap): once per cap, across its
|
|
236
|
-
* processes; a raise's new cap re-arms it. */
|
|
237
|
-
export declare function wrapUpSentIn(storeFile: string, cap: number): boolean;
|
|
238
221
|
/** /usage's meters for a run that ended, from its store: `tools`, each TOOL_COST's `usd`, unknown (null) when one is,
|
|
239
222
|
* or when a call was cut (marked, never settled: what it charged no one knows); and `tokens`, the rest of its root
|
|
240
223
|
* conversation as its settled timeline prices it; `browser`, the part of `tools` that is browser session time
|
|
@@ -250,17 +233,6 @@ export type Meters = {
|
|
|
250
233
|
others: number | null;
|
|
251
234
|
notMetered?: number;
|
|
252
235
|
};
|
|
253
|
-
export declare function metersIn(storeFile: string): Meters;
|
|
254
|
-
/** metersIn's meters, and beside them each meter's known dollars: its settled charges' figures, whether or not another of
|
|
255
|
-
* its charges is unknown (a hold, a call cut or never settled, is no charge here: it adds nothing). What a run of
|
|
256
|
-
* unknown cost is known to have spent on each (server.ts /usage). */
|
|
257
|
-
export declare function meterFiguresIn(storeFile: string): Meters & {
|
|
258
|
-
known: {
|
|
259
|
-
tokens: number;
|
|
260
|
-
browser: number;
|
|
261
|
-
others: number;
|
|
262
|
-
};
|
|
263
|
-
};
|
|
264
236
|
/** A browser charge's record on the run's root when the run books its money on the runner's one ledger (browser-cost.ts
|
|
265
237
|
* browserSpend's `paid`): the same record a browser TOOL_COST is, for what the browser's process holds and the seconds
|
|
266
238
|
* it was for, under a kind no cost reads. The charge's money is the ledger's paid step alone, which the cap counts and
|
|
@@ -268,10 +240,10 @@ export declare function meterFiguresIn(storeFile: string): Meters & {
|
|
|
268
240
|
* as every paid tool's on the runner: a TOOL_COST beside it would count the same charge twice. Its seconds are the
|
|
269
241
|
* browser_time meter's (meterFiguresFrom). */
|
|
270
242
|
export declare const BROWSER_CHARGED = "agentrun.browser_charged";
|
|
271
|
-
/**
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
243
|
+
/** /usage's meter figures from a run's entries by conversation, in log order, and beside them each meter's known dollars:
|
|
244
|
+
* its settled charges' figures, whether or not another of its charges is unknown (a hold, a call cut or never settled, is
|
|
245
|
+
* no charge here: it adds nothing). The one computation, which the one-store reader (store-reads/cap.ts metersOverStore)
|
|
246
|
+
* runs over A's journal. A paid tool's charge reaches it as the TOOL_COST / TOOL_UNMETERED the store reader folds back in from the
|
|
275
247
|
* paid-tools session (store-reads/journal.ts withPaidCosts), as the file-backed run's root held each natively. */
|
|
276
248
|
export declare function meterFiguresFrom(rows: readonly {
|
|
277
249
|
conversation: number;
|
|
@@ -284,7 +256,7 @@ export declare function meterFiguresFrom(rows: readonly {
|
|
|
284
256
|
};
|
|
285
257
|
};
|
|
286
258
|
/** What the paid tools of `entries` (TOOL_STARTED and TOOL_COST) spent, as the cap counts it: each charge, and a call
|
|
287
|
-
* settled at a charge it did not say, or a crash cut (marked, never settled), at its held figure, as
|
|
259
|
+
* settled at a charge it did not say, or a crash cut (marked, never settled), at its held figure, as spentFrom counts it;
|
|
288
260
|
* null when one has no figure. The run's reported cost reads such a call unknown instead (the timeline). */
|
|
289
261
|
export declare function capToolSpend(entries: readonly EntryLike[]): number | null;
|
|
290
262
|
/** The worst case of each model request a cap admitted and whose cost is not booked yet, by its turn, for a paid tool's
|
|
@@ -387,13 +359,16 @@ export declare function holdPaid(name: string, hold: {
|
|
|
387
359
|
* raise a request's ceiling up to the model's, whatever maxTokens it asked for. */
|
|
388
360
|
export declare const ceilingTokens: (model: Pick<Model<Api>, "maxTokens" | "contextWindow">) => number;
|
|
389
361
|
/** A request's input tokens, bounded above: one per UTF-8 byte of what is sent (a byte-level tokenizer never takes
|
|
390
|
-
* fewer than one byte a token,
|
|
391
|
-
*
|
|
362
|
+
* fewer than one byte a token), plus `overhead`: what the provider adds server-side that the body does not hold, and
|
|
363
|
+
* each image at what it is billed as in place of its base64's bytes (below 0 for a large image: piOverhead). The same
|
|
364
|
+
* bound on every harness. */
|
|
392
365
|
export declare const inputBound: (sent: string, overhead?: number) => number;
|
|
393
366
|
/** What pi's provider adds server-side to a request of `context`, the same table the model proxy uses, by the model's API
|
|
394
367
|
* kind: undefined for a kind whose additions are not known. The context does not say how the request chooses a tool,
|
|
395
368
|
* so the dearer choice is taken. */
|
|
396
|
-
export declare function piOverhead(model: Pick<Model<Api>, "api"
|
|
369
|
+
export declare function piOverhead(model: Pick<Model<Api>, "api"> & {
|
|
370
|
+
id?: string;
|
|
371
|
+
}, context: Context): number | undefined;
|
|
397
372
|
/** An amount in words: two decimals, or as many as it takes (up to eight) to show it whole ($0.50, $0.105, $0.0005). */
|
|
398
373
|
export declare function money(usd: number): string;
|
|
399
374
|
/** The code a cap's refusal begins with: `spend_cap_reached`, which the server ends the run with, and "out of budget",
|
|
@@ -500,8 +475,8 @@ export declare function requestParts(overhead?: (model: Model<Api>, context: Con
|
|
|
500
475
|
feeUsd: number;
|
|
501
476
|
} | undefined;
|
|
502
477
|
/** The wrap-up on pi (capModels' `wrapUp`): the run's own model (`model`, its id), that model's priced requests so far
|
|
503
|
-
* (`costs
|
|
504
|
-
* cap already (`sent
|
|
478
|
+
* (`costs`; capModels adds each one it books), whether it was told under this
|
|
479
|
+
* cap already (`sent`), and `record`, which writes its row (request-start.ts, CAP_WRAPUP). */
|
|
505
480
|
/** The wrap-up's state on pi. `sent`: told, in an answered request, once per cap. `pending`: a request carries the note
|
|
506
481
|
* and has not ended: no other request takes it until that one is answered (told) or not (re-armed). */
|
|
507
482
|
export type WrapUp = {
|
|
@@ -521,7 +496,7 @@ export type WrapUp = {
|
|
|
521
496
|
* and, under the cap,
|
|
522
497
|
* each request to a model in `unpriced` (one serve has no price for) or whose output is priced and that has no output
|
|
523
498
|
* ceiling, each whose input cannot be bounded, and every request once what the run has spent is unknown: `spent` null
|
|
524
|
-
* (
|
|
499
|
+
* (spentFrom), or an answer since whose cost is unknown. A request's input is inputBound of its context, plus
|
|
525
500
|
* `overhead(model, context)` (piOverhead), what its provider adds server-side; undefined is unmeasured, never 0. It is
|
|
526
501
|
* priced by requestPrice under `mode`, after the previous request of its conversation (the context's last answer, read
|
|
527
502
|
* by previousIn; its end as `now` read it when it settled here, else its own timestamp, which is when it began). Each
|
package/dist/cap.js
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
// timeline (runs.ts withOverCap).
|
|
31
31
|
//
|
|
32
32
|
// A paid tool's charge (monid.run's, monid.ts) is the run's spend too: booked in the run's store as a TOOL_COST, which
|
|
33
|
-
// the run's cost and
|
|
33
|
+
// the run's cost and spentFrom both count, and added to what the run's process counts as spent (useSpend), so the next
|
|
34
34
|
// request's check sees it. A charge the call does not say (null: stopped, timed out, failed with no cost) leaves the
|
|
35
35
|
// run's cost unknown, and the cap counts the call at what it was held at, the bound it let the call go at, as it counts
|
|
36
36
|
// one a crash cut: in the run's process and from its mark in the store. Before each paid call, paidCall holds it as a
|
|
@@ -45,12 +45,12 @@
|
|
|
45
45
|
// (RunSpend.wait, budget.ts): a model node's request before it is sent, a call node's call and a decision before they are
|
|
46
46
|
// admitted again. A refusal inside a call node's effect is told to the call (capRefusals), never only to the model.
|
|
47
47
|
import { readRunDbSync } from "./run-db.js";
|
|
48
|
-
import { durableDecisions } from "
|
|
48
|
+
import { durableDecisions } from "./workflow/readers.js";
|
|
49
49
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
50
50
|
import { existsSync } from "node:fs";
|
|
51
|
-
import { providerInputOverhead } from "@parcha/agentrun-kernel/host";
|
|
51
|
+
import { imageInputOf, providerInputOverhead } from "@parcha/agentrun-kernel/host";
|
|
52
52
|
import { bookRequest, isConnectCode, isGatewayTimeout, rejectionCode } from "@parcha/agentrun-kernel";
|
|
53
|
-
import {
|
|
53
|
+
import { REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, timelineOf, TOOL_COST, TOOL_STARTED } from "./timeline/index.js";
|
|
54
54
|
/** How a request the cap refused begins its error, which the server ends the run with. */
|
|
55
55
|
export const SPEND_CAP_REACHED = "spend_cap_reached";
|
|
56
56
|
/** How near two dollar figures are the same figure: a sum a float puts a hair past the cap (0.0028 + 0.3072 is
|
|
@@ -139,7 +139,7 @@ export function wrapUpDue(cap, spent, held, typical, leastUsd) {
|
|
|
139
139
|
/** The wrap-up's words, what is left to the cent. `nonePriced`: the run's own model has no priced request yet, so its
|
|
140
140
|
* typical cost is the next request's expected cost and the note can come before the run has done anything (step 0):
|
|
141
141
|
* the words say the budget and ask for a short answer, not a finish. Read from the same priced costs live and in a
|
|
142
|
-
* process opened again (
|
|
142
|
+
* process opened again (ownCosts), so a restart picks the same words. */
|
|
143
143
|
export const wrapUpWords = (leftUsd, nonePriced = false) => {
|
|
144
144
|
const left = centsMoney(Math.max(0, leftUsd));
|
|
145
145
|
return nonePriced ? `This run's budget is about ${left}, enough for little work: answer as soon as you can.` : `About ${left} left of this run's budget: finish now with your answer.`;
|
|
@@ -286,7 +286,7 @@ export function piEnded(message, began, attempts) {
|
|
|
286
286
|
return { end: "nothing", label: last === undefined || "code" in last ? "never_left" : "status" };
|
|
287
287
|
}
|
|
288
288
|
/** How pi's error for a request whose start mark could not be written begins (request-start.ts builds it from this): the
|
|
289
|
-
* request never left, so the entry answers none, and
|
|
289
|
+
* request never left, so the entry answers none, and spentFrom leaves it out by this. */
|
|
290
290
|
export const MARK_NOT_WRITTEN = "the model request was not sent: its mark could not be written";
|
|
291
291
|
/** pi's error for a request that left and whose end mark the store refused (request-start.ts): its cost is not recorded
|
|
292
292
|
* as booked, so it stays open, read at its start mark's hold, never closed by this entry at its own usage. */
|
|
@@ -337,7 +337,7 @@ const close = (open, figure) => {
|
|
|
337
337
|
open.splice(at, 1);
|
|
338
338
|
};
|
|
339
339
|
/** The figures of the requests of each kind that `entries` leave open, marked as sent with no answer, cost or end, read in
|
|
340
|
-
* order, as the run's timeline counts them
|
|
340
|
+
* order, as the run's timeline counts them, so the two agree on how many were cut. A start adds
|
|
341
341
|
* its figure. An end mark closes its own start: a stopped request's at the figure it names, a withdrawn one's (`unsent`,
|
|
342
342
|
* which names none) the smallest. An end that names none for a request that left (an older store) closes nothing, so
|
|
343
343
|
* that request stays cut. An answer, or a summary's cost, closes the smallest figure still open, since when requests
|
|
@@ -376,33 +376,8 @@ function openFigures(entries) {
|
|
|
376
376
|
}
|
|
377
377
|
return open;
|
|
378
378
|
}
|
|
379
|
-
/** What the run's
|
|
380
|
-
*
|
|
381
|
-
* then the full amount, never the timeline's total rounded for display. Every response, and each cost written apart
|
|
382
|
-
* from one (a compaction summary's; a harness request's that came in after its answer). A cost that is not a number, or
|
|
383
|
-
* one still pending, leaves it unknown, as the timeline says. These readings are the cap's own, on its copy of the
|
|
384
|
-
* entries (the run's shown cost is the timeline's, unchanged): a request stopped before its end counts at the figure its
|
|
385
|
-
* end mark holds (HELD_FIELD), and one a crash cut (marked as sent, no answer, no end) at the figure its start mark
|
|
386
|
-
* holds (openFigures), each the worst case the cap held for it; without that figure either stays cut, at an unknown
|
|
387
|
-
* cost. A paid call settled at a charge it did not say, like one a crash cut, counts at the figure its mark holds. And
|
|
388
|
-
* this cap's refusals are left out, as none left. Unknown is null, which a cap never reads as $0. */
|
|
389
|
-
export function spentIn(storeFile) {
|
|
390
|
-
if (!existsSync(storeFile))
|
|
391
|
-
return 0;
|
|
392
|
-
// Fresh, read-only and lock-free (run-db.ts): its process may hold it.
|
|
393
|
-
const rows = [];
|
|
394
|
-
readRunDbSync(storeFile, false, (db) => {
|
|
395
|
-
// A read made again (its file changed during it) starts from none.
|
|
396
|
-
rows.length = 0;
|
|
397
|
-
for (const row of db.prepare("SELECT record FROM entries ORDER BY rowid").iterate()) {
|
|
398
|
-
const entry = JSON.parse(String(row.record));
|
|
399
|
-
rows.push(entry);
|
|
400
|
-
}
|
|
401
|
-
});
|
|
402
|
-
return spentFrom(rows);
|
|
403
|
-
}
|
|
404
|
-
/** What the run's model requests cost, from its entries in log order: the one computation, shared by spentIn (reading a
|
|
405
|
-
* settled run's own database) and the one-store reader (store-reads, reading A's journal). These readings are the cap's
|
|
379
|
+
/** What the run's model requests cost, from its entries in log order: the one computation, which the one-store reader
|
|
380
|
+
* (store-reads/cap.ts spentOverStore) runs over A's journal. These readings are the cap's
|
|
406
381
|
* own, on its copy of the entries (the run's shown cost is the timeline's, unchanged): a request stopped before its end
|
|
407
382
|
* counts at the figure its end mark holds (HELD_FIELD), and one a crash cut (marked as sent, no answer, no end) at the
|
|
408
383
|
* figure its start mark holds (openFigures), each the worst case the cap held for it; without that figure either stays
|
|
@@ -546,7 +521,7 @@ export const DECISION_COST = "agentrun.decision_cost";
|
|
|
546
521
|
/** A decision request's hold, kept before it is sent (decision-cap.ts): with no DECISION_COST after it, its process died
|
|
547
522
|
* while it was out, and it counts at this figure. */
|
|
548
523
|
export const DECISION_HOLD = "agentrun.decision_hold";
|
|
549
|
-
/** What a workflow run's decisions cost, in its store: what the next process adds to
|
|
524
|
+
/** What a workflow run's decisions cost, in its store: what the next process adds to spentFrom's reading. Per decision
|
|
550
525
|
* (its id):
|
|
551
526
|
* - booked (DECISION_COST entries, at its charge, its hold, or $0 for nothing charged): the larger of what was booked,
|
|
552
527
|
* with any hold no booking ended, and what its receipts say it cost (the costs the timeline's decision rows sum);
|
|
@@ -597,7 +572,7 @@ export function decisionSpentIn(storeFile) {
|
|
|
597
572
|
}
|
|
598
573
|
for (const receipt of receipts) {
|
|
599
574
|
const usd = figureOf(receipt.cost_usd);
|
|
600
|
-
// A stored receipt row names its decision `decision_id` (
|
|
575
|
+
// A stored receipt row names its decision `decision_id` (workflow/decision-recovery.ts rowOf).
|
|
601
576
|
const id = typeof receipt.decision_id === "string" ? receipt.decision_id : typeof receipt.id === "string" ? receipt.id : undefined;
|
|
602
577
|
if (id !== undefined && usd !== undefined && usd > 0)
|
|
603
578
|
receipted.set(id, (receipted.get(id) ?? 0) + usd);
|
|
@@ -618,7 +593,7 @@ export function decisionSpentIn(storeFile) {
|
|
|
618
593
|
function entriesIn(storeFile) {
|
|
619
594
|
if (!existsSync(storeFile))
|
|
620
595
|
return [];
|
|
621
|
-
// Fresh, read-only and lock-free (run-db.ts), as
|
|
596
|
+
// Fresh, read-only and lock-free (run-db.ts), as the cap's readings did.
|
|
622
597
|
const rows = [];
|
|
623
598
|
readRunDbSync(storeFile, false, (db) => {
|
|
624
599
|
rows.length = 0;
|
|
@@ -627,32 +602,6 @@ function entriesIn(storeFile) {
|
|
|
627
602
|
});
|
|
628
603
|
return rows;
|
|
629
604
|
}
|
|
630
|
-
/** The priced answers of `model` (its id) in the run's store, in order: what the wrap-up's typical cost reads from earlier
|
|
631
|
-
* processes (capModels' `wrapUp`). An answer whose cost is unknown or $0, or that was stopped or failed, is none. */
|
|
632
|
-
export function costsIn(storeFile, model) {
|
|
633
|
-
return entriesIn(storeFile).flatMap((entry) => {
|
|
634
|
-
const message = entry.kind === "pi.assistant" ? entry.model?.[0] : undefined;
|
|
635
|
-
const total = message?.usage?.cost?.total;
|
|
636
|
-
return message?.model === model && message.stopReason !== "error" && message.stopReason !== "aborted" && typeof total === "number" && Number.isFinite(total) && total > 0 ? [total] : [];
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
/** Whether the run was told its wrap-up under `cap` already (a CAP_WRAPUP entry of that cap): once per cap, across its
|
|
640
|
-
* processes; a raise's new cap re-arms it. */
|
|
641
|
-
export function wrapUpSentIn(storeFile, cap) {
|
|
642
|
-
return entriesIn(storeFile).some((entry) => entry.kind === CAP_WRAPUP && typeof entry.data?.capUsd === "number" && Math.abs(entry.data.capUsd - cap) <= CAP_TOLERANCE);
|
|
643
|
-
}
|
|
644
|
-
export function metersIn(storeFile) {
|
|
645
|
-
const { known: _, ...meters } = meterFiguresIn(storeFile);
|
|
646
|
-
return meters;
|
|
647
|
-
}
|
|
648
|
-
/** metersIn's meters, and beside them each meter's known dollars: its settled charges' figures, whether or not another of
|
|
649
|
-
* its charges is unknown (a hold, a call cut or never settled, is no charge here: it adds nothing). What a run of
|
|
650
|
-
* unknown cost is known to have spent on each (server.ts /usage). */
|
|
651
|
-
export function meterFiguresIn(storeFile) {
|
|
652
|
-
if (!existsSync(storeFile))
|
|
653
|
-
return { tools: 0, tokens: null, browser: { usd: 0, seconds: 0 }, others: 0, known: { tokens: 0, browser: 0, others: 0 } };
|
|
654
|
-
return readRunDbSync(storeFile, false, (db) => meterFiguresFrom(db.prepare("SELECT conversation_id AS conversation, record FROM entries ORDER BY rowid").all().map((row) => ({ conversation: Number(row.conversation), entry: JSON.parse(String(row.record)) }))));
|
|
655
|
-
}
|
|
656
605
|
/** A browser charge's record on the run's root when the run books its money on the runner's one ledger (browser-cost.ts
|
|
657
606
|
* browserSpend's `paid`): the same record a browser TOOL_COST is, for what the browser's process holds and the seconds
|
|
658
607
|
* it was for, under a kind no cost reads. The charge's money is the ledger's paid step alone, which the cap counts and
|
|
@@ -660,10 +609,10 @@ export function meterFiguresIn(storeFile) {
|
|
|
660
609
|
* as every paid tool's on the runner: a TOOL_COST beside it would count the same charge twice. Its seconds are the
|
|
661
610
|
* browser_time meter's (meterFiguresFrom). */
|
|
662
611
|
export const BROWSER_CHARGED = "agentrun.browser_charged";
|
|
663
|
-
/**
|
|
664
|
-
*
|
|
665
|
-
*
|
|
666
|
-
*
|
|
612
|
+
/** /usage's meter figures from a run's entries by conversation, in log order, and beside them each meter's known dollars:
|
|
613
|
+
* its settled charges' figures, whether or not another of its charges is unknown (a hold, a call cut or never settled, is
|
|
614
|
+
* no charge here: it adds nothing). The one computation, which the one-store reader (store-reads/cap.ts metersOverStore)
|
|
615
|
+
* runs over A's journal. A paid tool's charge reaches it as the TOOL_COST / TOOL_UNMETERED the store reader folds back in from the
|
|
667
616
|
* paid-tools session (store-reads/journal.ts withPaidCosts), as the file-backed run's root held each natively. */
|
|
668
617
|
export function meterFiguresFrom(rows) {
|
|
669
618
|
const root = rows.reduce((min, row) => Math.min(min, row.conversation), Infinity);
|
|
@@ -702,7 +651,7 @@ export function meterFiguresFrom(rows) {
|
|
|
702
651
|
return { tools, tokens: usage ? (usage.usage?.usd ?? null) : 0, browser, others: otherTools, known, ...(notMetered ? { notMetered } : {}) };
|
|
703
652
|
}
|
|
704
653
|
/** What the paid tools of `entries` (TOOL_STARTED and TOOL_COST) spent, as the cap counts it: each charge, and a call
|
|
705
|
-
* settled at a charge it did not say, or a crash cut (marked, never settled), at its held figure, as
|
|
654
|
+
* settled at a charge it did not say, or a crash cut (marked, never settled), at its held figure, as spentFrom counts it;
|
|
706
655
|
* null when one has no figure. The run's reported cost reads such a call unknown instead (the timeline). */
|
|
707
656
|
export function capToolSpend(entries) {
|
|
708
657
|
const open = new Map();
|
|
@@ -766,7 +715,7 @@ export const runCap = () => runSpend?.cap;
|
|
|
766
715
|
* quote, else an allowance, `basis` saying which) fits the cap, and whenever the spend is unknown; else run, one paid
|
|
767
716
|
* call at a time, so each check sees the charge before it, and held at that figure (paidHolds) until the charge it
|
|
768
717
|
* reports (`charge` of its result, undefined for none) joins the spend. A charge it does not say (null), or a call that
|
|
769
|
-
* fails, counts at its held figure, as its mark does from the store (
|
|
718
|
+
* fails, counts at its held figure, as its mark does from the store (spentFrom), since it may have charged that much.
|
|
770
719
|
* With no cap it just runs. */
|
|
771
720
|
/** A paid call this run's cap refused for room (paidCall): its words, after the code, and its figures as a model
|
|
772
721
|
* request's refusal keeps them (what was taken, and the call's hold as what it needs). The model's next request is
|
|
@@ -879,15 +828,18 @@ function outputBound(model) {
|
|
|
879
828
|
return [model.cost, ...(model.cost?.tiers ?? [])].every((rates) => rates?.output === 0) ? 0 : undefined;
|
|
880
829
|
}
|
|
881
830
|
/** A request's input tokens, bounded above: one per UTF-8 byte of what is sent (a byte-level tokenizer never takes
|
|
882
|
-
* fewer than one byte a token,
|
|
883
|
-
*
|
|
831
|
+
* fewer than one byte a token), plus `overhead`: what the provider adds server-side that the body does not hold, and
|
|
832
|
+
* each image at what it is billed as in place of its base64's bytes (below 0 for a large image: piOverhead). The same
|
|
833
|
+
* bound on every harness. */
|
|
884
834
|
export const inputBound = (sent, overhead = 0) => Buffer.byteLength(sent, "utf8") + overhead;
|
|
885
835
|
/** What pi's provider adds server-side to a request of `context`, the same table the model proxy uses, by the model's API
|
|
886
836
|
* kind: undefined for a kind whose additions are not known. The context does not say how the request chooses a tool,
|
|
887
837
|
* so the dearer choice is taken. */
|
|
888
838
|
export function piOverhead(model, context) {
|
|
889
839
|
const parts = (context.messages ?? []).flatMap((message) => (Array.isArray(message.content) ? (message.content) : []));
|
|
890
|
-
|
|
840
|
+
// Each image, in every turn, at what the model's provider bills it as by its size, in place of its base64's bytes in
|
|
841
|
+
// what is sent (imageInputOf, imageTokens).
|
|
842
|
+
return providerInputOverhead(model.api, { tools: (context.tools?.length ?? 0) > 0, toolChoice: "any", images: parts.filter((part) => part?.type === "image").map((part) => imageInputOf(part.data)), ...(model.id ? { model: model.id } : {}) });
|
|
891
843
|
}
|
|
892
844
|
const unmeasured = (cap) => `${SPEND_CAP_REACHED}: Not sent: the size of the next model request's input is unknown, so the run's cap of ${money(cap)} cannot be kept: the run is out of budget.`;
|
|
893
845
|
const noPrice = (cap) => `${SPEND_CAP_REACHED}: Not sent: the next model request's model has no price here, so the run's cap of ${money(cap)} cannot be kept: the run is out of budget.`;
|
|
@@ -952,7 +904,9 @@ const whyOf = ({ text, figures }) => ({ why: text, figures });
|
|
|
952
904
|
* (RefusalFigures, the pause's spent_usd). */
|
|
953
905
|
const spentOf = (spent, held, cap) => {
|
|
954
906
|
const holds = centsMoney(held);
|
|
955
|
-
|
|
907
|
+
// A spend above $0 that rounds to it reads "less than a cent", never "$0" (the kernel's spentMoney).
|
|
908
|
+
const spentWords = spent > 0 && centsMoney(spent) === "$0" ? "less than a cent" : centsMoney(spent);
|
|
909
|
+
return holds !== "$0" ? `spent ${spentWords} and holds ${holds} for steps still running, of its ${money(cap)} cap` : `spent ${spentWords} of its ${money(cap)} cap`;
|
|
956
910
|
};
|
|
957
911
|
/** An amount in words, to the nearest cent ($0.0237416 is $0.02), as money says it ($1, $0.20, $0). */
|
|
958
912
|
export const centsMoney = (usd) => money(Math.round(usd * 100) / 100);
|
|
@@ -1075,7 +1029,7 @@ export function requestParts(overhead = piOverhead) {
|
|
|
1075
1029
|
* and, under the cap,
|
|
1076
1030
|
* each request to a model in `unpriced` (one serve has no price for) or whose output is priced and that has no output
|
|
1077
1031
|
* ceiling, each whose input cannot be bounded, and every request once what the run has spent is unknown: `spent` null
|
|
1078
|
-
* (
|
|
1032
|
+
* (spentFrom), or an answer since whose cost is unknown. A request's input is inputBound of its context, plus
|
|
1079
1033
|
* `overhead(model, context)` (piOverhead), what its provider adds server-side; undefined is unmeasured, never 0. It is
|
|
1080
1034
|
* priced by requestPrice under `mode`, after the previous request of its conversation (the context's last answer, read
|
|
1081
1035
|
* by previousIn; its end as `now` read it when it settled here, else its own timestamp, which is when it began). Each
|
|
@@ -1248,7 +1202,7 @@ export async function capModels(models, cap, spent, { unpriced = new Set(), over
|
|
|
1248
1202
|
* of what it streamed (stoppedFigure, at most `worst`), unless an attempt before the stop was lost: then at `worst`, as
|
|
1249
1203
|
* its lost mark reads in a later process; one that ended on an error after its response began
|
|
1250
1204
|
* (markResponseBegan: its usage is what had streamed, not what the provider can have billed), or that failed with no
|
|
1251
|
-
* answer, at `worst`, what the cap held for it; each as
|
|
1205
|
+
* answer, at `worst`, what the cap held for it; each as spentFrom reads its end mark. Without a figure (a deferred
|
|
1252
1206
|
* response) it is unknown, as is a cost that is not a number, from then on. */
|
|
1253
1207
|
const count = (answer, turn, worst, stopped, attempts) => {
|
|
1254
1208
|
const plus = (sum, cost) => (sum !== null && typeof cost === "number" && Number.isFinite(cost) ? sum + cost : null);
|
|
@@ -1256,7 +1210,7 @@ export async function capModels(models, cap, spent, { unpriced = new Set(), over
|
|
|
1256
1210
|
// One rule (bookRequest), from how the request ended (piEnded) as its marks read it too.
|
|
1257
1211
|
const at = (message) => message.stopReason === "aborted" ? (stopped && !anyAttemptLost(attempts) ? stopped(message) : worst)
|
|
1258
1212
|
: bookRequest(piEnded(message, responseBegan.has(message), attempts), worst === undefined ? {} : { hold: worst }).usd;
|
|
1259
|
-
// A priced turn answer of the run's own model: the wrap-up's typical cost counts it, as
|
|
1213
|
+
// A priced turn answer of the run's own model: the wrap-up's typical cost counts it, as a process opened again reads it (its
|
|
1260
1214
|
// pi.assistant entries). Never a compaction summary's or a native search's request on the same model (completeSimple
|
|
1261
1215
|
// calls, `turn` false): no pi.assistant entry keeps them, so a process opened again would count without them.
|
|
1262
1216
|
const priced = (message) => {
|
|
@@ -1339,7 +1293,7 @@ export async function capModels(models, cap, spent, { unpriced = new Set(), over
|
|
|
1339
1293
|
const refused = createAssistantMessageEventStream();
|
|
1340
1294
|
const message = refusal(model, judged.why);
|
|
1341
1295
|
// Its own start mark first, so pi's error entry for it answers that mark, never an earlier request a stop or a crash
|
|
1342
|
-
// cut. A mark that cannot be written still ends the request:
|
|
1296
|
+
// cut. A mark that cannot be written still ends the request: spentFrom leaves refusals out either way.
|
|
1343
1297
|
void Promise.resolve()
|
|
1344
1298
|
.then(() => markRefused?.(judged.figures))
|
|
1345
1299
|
.catch(() => undefined)
|