@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
package/dist/box-settings.d.ts
CHANGED
|
@@ -1,31 +1,11 @@
|
|
|
1
1
|
import type { BoxProvider } from "@parcha/pi-transport";
|
|
2
2
|
import { type DockerNetwork, egressBlockedBy } from "./box-egress.js";
|
|
3
|
-
/** The settings that bound a Docker box; unset, their defaults: enough for a build, and safe on a laptop, where one run's
|
|
4
|
-
* runaway build or fork bomb would otherwise starve everything else. */
|
|
5
|
-
export declare const BOX_CPUS_ENV = "AGENTRUN_BOX_CPUS";
|
|
6
|
-
export declare const BOX_MEMORY_ENV = "AGENTRUN_BOX_MEMORY";
|
|
7
|
-
export declare const BOX_PIDS_ENV = "AGENTRUN_BOX_PIDS";
|
|
8
|
-
/** 2 CPUs' time: a CFS quota (pi-transport's Docker provider), which holds whatever CPU count Docker's VM has. */
|
|
9
|
-
export declare const DEFAULT_BOX_CPUS = 2;
|
|
10
|
-
/** 4 GiB, swap included (--memory-swap the same). */
|
|
11
|
-
export declare const DEFAULT_BOX_MEMORY = "4g";
|
|
12
|
-
/** Processes and threads at once. */
|
|
13
|
-
export declare const DEFAULT_BOX_PIDS = 1024;
|
|
14
|
-
/** A Docker box's limits, as pi-transport's Docker provider takes them. */
|
|
15
|
-
export type BoxLimits = {
|
|
16
|
-
cpus: number;
|
|
17
|
-
memory: string;
|
|
18
|
-
pidsLimit: number;
|
|
19
|
-
};
|
|
20
|
-
/** A Docker box's limits from `env`: each setting's value, or its default when unset or empty. A value that is not one, or
|
|
21
|
-
* that every create would fail on (less than a 1 ms quota, less memory than Docker gives, more processes than the kernel
|
|
22
|
-
* allows), throws, naming its setting: the start checks them (startServe), so no run meets one. */
|
|
23
|
-
export declare function boxLimitsOf(env: NodeJS.ProcessEnv): BoxLimits;
|
|
24
|
-
/** A Docker size (boxLimitsOf's memory) in MiB, the fraction dropped. */
|
|
25
|
-
export declare const memoryMbOf: (memory: string) => number;
|
|
26
3
|
/** The setting that names the hosts a box may reach: a comma list of hosts, each a name or `*.` and a name, which
|
|
27
4
|
* replaces the default list; `none` for no network at all. Unset or empty, the default. */
|
|
28
5
|
export declare const BOX_ALLOW_ENV = "AGENTRUN_BOX_ALLOW";
|
|
6
|
+
/** Whether the operator set the setting (a list of their own, or none), not left it to the default: a browser is held to
|
|
7
|
+
* the operator's list, never to the default, which is a sandbox's package-install list and no browsing policy. */
|
|
8
|
+
export declare const boxAllowSetIn: (env: NodeJS.ProcessEnv) => boolean;
|
|
29
9
|
/** The hosts a box reaches when the setting names none: the package registries pip and npm (and yarn) install from, and
|
|
30
10
|
* GitHub for a clone or an archive. */
|
|
31
11
|
export declare const DEFAULT_BOX_ALLOW: readonly string[];
|
package/dist/box-settings.js
CHANGED
|
@@ -1,60 +1,16 @@
|
|
|
1
|
-
// A box's settings as the server reads them at its start: a
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// A box's settings as the server reads them at its start: the hosts a box may reach (AGENTRUN_BOX_ALLOW) and what a
|
|
2
|
+
// server's Docker boxes reach from them, and, under `--faux` only, the tests' faux box provider. A setting that is not one
|
|
3
|
+
// throws, naming it: the start checks each, so no run meets one. A Docker computer's size (AGENTRUN_BOX_CPUS, _MEMORY,
|
|
4
|
+
// _PIDS) is workspace/computer-deps.ts dockerLimitsOf.
|
|
4
5
|
import { pathToFileURL } from "node:url";
|
|
5
6
|
import { egressBlockedBy } from "./box-egress.js";
|
|
6
7
|
import { vmDocker } from "./box-egress-vm.js";
|
|
7
|
-
/** The settings that bound a Docker box; unset, their defaults: enough for a build, and safe on a laptop, where one run's
|
|
8
|
-
* runaway build or fork bomb would otherwise starve everything else. */
|
|
9
|
-
export const BOX_CPUS_ENV = "AGENTRUN_BOX_CPUS";
|
|
10
|
-
export const BOX_MEMORY_ENV = "AGENTRUN_BOX_MEMORY";
|
|
11
|
-
export const BOX_PIDS_ENV = "AGENTRUN_BOX_PIDS";
|
|
12
|
-
/** 2 CPUs' time: a CFS quota (pi-transport's Docker provider), which holds whatever CPU count Docker's VM has. */
|
|
13
|
-
export const DEFAULT_BOX_CPUS = 2;
|
|
14
|
-
/** 4 GiB, swap included (--memory-swap the same). */
|
|
15
|
-
export const DEFAULT_BOX_MEMORY = "4g";
|
|
16
|
-
/** Processes and threads at once. */
|
|
17
|
-
export const DEFAULT_BOX_PIDS = 1024;
|
|
18
|
-
/** The fewest CPUs a quota gives: the kernel's least quota is 1 ms of each 100 ms period. A quota is also a whole number of
|
|
19
|
-
* µs, so a count too large for one (or a long string of digits, which reads as Infinity) is refused too. */
|
|
20
|
-
const MIN_BOX_CPUS = 0.01;
|
|
21
|
-
const MIB = 1024 * 1024;
|
|
22
|
-
/** A size's units as Docker reads them, each 1024 of the one before. */
|
|
23
|
-
const SIZE_UNITS = { b: 1, k: 1024, m: MIB, g: 1024 * MIB };
|
|
24
|
-
/** The least memory Docker gives a container. */
|
|
25
|
-
const MIN_BOX_MEMORY = 6 * MIB;
|
|
26
|
-
/** The most processes a cgroup may be given (the kernel's PID_MAX_LIMIT); above it, every create fails. */
|
|
27
|
-
const MAX_BOX_PIDS = 4_194_304;
|
|
28
|
-
/** A Docker box's limits from `env`: each setting's value, or its default when unset or empty. A value that is not one, or
|
|
29
|
-
* that every create would fail on (less than a 1 ms quota, less memory than Docker gives, more processes than the kernel
|
|
30
|
-
* allows), throws, naming its setting: the start checks them (startServe), so no run meets one. */
|
|
31
|
-
export function boxLimitsOf(env) {
|
|
32
|
-
const read = (name, what, takes) => {
|
|
33
|
-
const value = env[name];
|
|
34
|
-
if (!value)
|
|
35
|
-
return undefined;
|
|
36
|
-
if (!takes(value))
|
|
37
|
-
throw new Error(`${name} is ${what}; it is ${JSON.stringify(value)}`);
|
|
38
|
-
return value;
|
|
39
|
-
};
|
|
40
|
-
const cpus = read(BOX_CPUS_ENV, "a number of CPUs of at least 0.01, such as 2 or 1.5", (value) => /^\d+(\.\d+)?$/.test(value) && Number(value) >= MIN_BOX_CPUS && Number.isSafeInteger(Math.round(Number(value) * 100_000)));
|
|
41
|
-
const memory = read(BOX_MEMORY_ENV, "a size of at least 6m with its unit (b, k, m or g), such as 512m or 4g", (value) => {
|
|
42
|
-
const size = /^(\d+(?:\.\d+)?)([bkmg])$/i.exec(value);
|
|
43
|
-
// Its bytes as Docker reads them, and pi-transport's Docker provider: the number times the unit, the fraction dropped.
|
|
44
|
-
const bytes = size ? Math.floor(Number(size[1]) * SIZE_UNITS[size[2].toLowerCase()]) : 0;
|
|
45
|
-
return Number.isSafeInteger(bytes) && bytes >= MIN_BOX_MEMORY;
|
|
46
|
-
});
|
|
47
|
-
const pids = read(BOX_PIDS_ENV, "a whole number from 1 to 4194304, such as 1024", (value) => /^\d+$/.test(value) && Number(value) >= 1 && Number(value) <= MAX_BOX_PIDS);
|
|
48
|
-
return { cpus: cpus === undefined ? DEFAULT_BOX_CPUS : Number(cpus), memory: memory ?? DEFAULT_BOX_MEMORY, pidsLimit: pids === undefined ? DEFAULT_BOX_PIDS : Number(pids) };
|
|
49
|
-
}
|
|
50
|
-
/** A Docker size (boxLimitsOf's memory) in MiB, the fraction dropped. */
|
|
51
|
-
export const memoryMbOf = (memory) => {
|
|
52
|
-
const size = /^(\d+(?:\.\d+)?)([bkmg])$/i.exec(memory);
|
|
53
|
-
return size ? Math.floor((Number(size[1]) * SIZE_UNITS[size[2].toLowerCase()]) / MIB) : 0;
|
|
54
|
-
};
|
|
55
8
|
/** The setting that names the hosts a box may reach: a comma list of hosts, each a name or `*.` and a name, which
|
|
56
9
|
* replaces the default list; `none` for no network at all. Unset or empty, the default. */
|
|
57
10
|
export const BOX_ALLOW_ENV = "AGENTRUN_BOX_ALLOW";
|
|
11
|
+
/** Whether the operator set the setting (a list of their own, or none), not left it to the default: a browser is held to
|
|
12
|
+
* the operator's list, never to the default, which is a sandbox's package-install list and no browsing policy. */
|
|
13
|
+
export const boxAllowSetIn = (env) => (env[BOX_ALLOW_ENV] ?? "").trim() !== "";
|
|
58
14
|
/** The hosts a box reaches when the setting names none: the package registries pip and npm (and yarn) install from, and
|
|
59
15
|
* GitHub for a clone or an archive. */
|
|
60
16
|
export const DEFAULT_BOX_ALLOW = Object.freeze(["pypi.org", "files.pythonhosted.org", "registry.npmjs.org", "registry.yarnpkg.com", "github.com", "codeload.github.com"]);
|
package/dist/boxes.d.ts
CHANGED
|
@@ -90,3 +90,20 @@ export declare function enabledBoxes(env: NodeJS.ProcessEnv): Set<BoxId>;
|
|
|
90
90
|
export declare function boxRegistry(env: NodeJS.ProcessEnv, options?: BoxRegistryOptions): Promise<BoxRegistry>;
|
|
91
91
|
/** The start's log line: the boxes available, the rest, and why each box AGENTRUN_BOXES lists (`listed`) is not available. */
|
|
92
92
|
export declare function boxesLog(offers: readonly BoxOffer[], listed: ReadonlySet<BoxId>): Record<string, string>;
|
|
93
|
+
/** What `docker version` says of this machine's Docker daemon: it answers (`up`), or why not. `absent`: no daemon
|
|
94
|
+
* answers this process (no docker command, a call that fails, or one that names no daemon); not absent: one is there,
|
|
95
|
+
* and its socket refuses this process (the group it lacks). */
|
|
96
|
+
export type DockerDaemon = {
|
|
97
|
+
readonly up: true;
|
|
98
|
+
} | {
|
|
99
|
+
readonly up: false;
|
|
100
|
+
readonly absent: boolean;
|
|
101
|
+
readonly reason: string;
|
|
102
|
+
};
|
|
103
|
+
/** Asks this machine's Docker daemon its version (`docker version`), as the Docker box's start probe and the Docker
|
|
104
|
+
* computer's check (docker-daemon.ts) do: the CLI is on PATH and its daemon answers this user. `signal` bounds it. */
|
|
105
|
+
export declare function askDockerDaemon(env: NodeJS.ProcessEnv, signal: AbortSignal, groups?: {
|
|
106
|
+
file: string;
|
|
107
|
+
user: string;
|
|
108
|
+
ids: readonly number[];
|
|
109
|
+
}): Promise<DockerDaemon>;
|
package/dist/boxes.js
CHANGED
|
@@ -165,32 +165,39 @@ async function load(name, importer) {
|
|
|
165
165
|
return { ok: false, reason: missing ? `install ${name} to use this box` : `${name} did not load (${errorName(error)})` };
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
|
+
/** Asks this machine's Docker daemon its version (`docker version`), as the Docker box's start probe and the Docker
|
|
169
|
+
* computer's check (docker-daemon.ts) do: the CLI is on PATH and its daemon answers this user. `signal` bounds it. */
|
|
170
|
+
export async function askDockerDaemon(env, signal, groups = ownGroups()) {
|
|
171
|
+
// Its environment is the server's through the cut a run's takes (withoutSecrets): no box key, no other secret, no
|
|
172
|
+
// name shaped like a key.
|
|
173
|
+
const dockerEnv = withoutSecrets(env);
|
|
174
|
+
const answer = await new Promise((resolve) => execFile("docker", ["version", "--format", "{{.Server.Version}}"], { env: dockerEnv, signal, maxBuffer: 64 * 1024 }, (error, stdout, stderr) => {
|
|
175
|
+
const code = error?.code;
|
|
176
|
+
resolve({ ...(error ? { failed: typeof code === "number" ? `exit ${code}` : errorName(error), ...(SOCKET_DENIED.test(String(stderr)) ? { denied: true } : {}) } : {}), out: String(stdout) });
|
|
177
|
+
}));
|
|
178
|
+
const absent = (reason) => ({ up: false, absent: true, reason });
|
|
179
|
+
// The box's probe runs once, at the start: each fix takes a restart. Docker is on by default, so its reason is often a
|
|
180
|
+
// first-time user's first read: what is wrong in plain words, what the probe saw, then what to do.
|
|
181
|
+
if (answer.failed === "ENOENT")
|
|
182
|
+
return absent("Docker isn't running on this machine (no docker command on PATH): install or start Docker, then restart AgentRun");
|
|
183
|
+
// Its socket refused this process: the group it lacks, and how to get it without a reboot (the words, never docker's):
|
|
184
|
+
// a restart alone where the group file already lists this user, else joining it first.
|
|
185
|
+
if (answer.denied)
|
|
186
|
+
return { up: false, absent: false, reason: (await joinedSince(groups)) ? DOCKER_NOT_IN_GROUP : DOCKER_JOIN_GROUP };
|
|
187
|
+
if (answer.failed)
|
|
188
|
+
return absent(`Docker isn't running on this machine, or this user may not use it (docker version failed: ${answer.failed}): start Docker, or add this user to the docker group, then restart AgentRun`);
|
|
189
|
+
if (!answer.out.trim())
|
|
190
|
+
return absent("Docker isn't running on this machine (docker version named no daemon): start Docker, then restart AgentRun");
|
|
191
|
+
return { up: true };
|
|
192
|
+
}
|
|
168
193
|
const PROBES = {
|
|
169
194
|
/** `docker version` names the daemon's version: the CLI is on PATH and its daemon answers this user. */
|
|
170
195
|
async docker(env, signal, options) {
|
|
171
196
|
const boxes = await load(TRANSPORT, () => import("@parcha/pi-transport/box/docker").then((module) => module.dockerBoxes));
|
|
172
197
|
if (!boxes.ok)
|
|
173
198
|
return unavailable("docker", boxes.reason);
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const dockerEnv = withoutSecrets(env);
|
|
177
|
-
const answer = await new Promise((resolve) => execFile("docker", ["version", "--format", "{{.Server.Version}}"], { env: dockerEnv, signal, maxBuffer: 64 * 1024 }, (error, stdout, stderr) => {
|
|
178
|
-
const code = error?.code;
|
|
179
|
-
resolve({ ...(error ? { failed: typeof code === "number" ? `exit ${code}` : errorName(error), ...(SOCKET_DENIED.test(String(stderr)) ? { denied: true } : {}) } : {}), out: String(stdout) });
|
|
180
|
-
}));
|
|
181
|
-
// The probe runs once, at the start: each fix takes a restart. Docker is on by default, so its reason is often a
|
|
182
|
-
// first-time user's first read: what is wrong in plain words, what the probe saw, then what to do.
|
|
183
|
-
if (answer.failed === "ENOENT")
|
|
184
|
-
return unavailable("docker", "Docker isn't running on this machine (no docker command on PATH): install or start Docker, then restart AgentRun");
|
|
185
|
-
// Its socket refused this process: the group it lacks, and how to get it without a reboot (the words, never docker's):
|
|
186
|
-
// a restart alone where the group file already lists this user, else joining it first.
|
|
187
|
-
if (answer.denied)
|
|
188
|
-
return unavailable("docker", (await joinedSince(options.groups ?? ownGroups())) ? DOCKER_NOT_IN_GROUP : DOCKER_JOIN_GROUP);
|
|
189
|
-
if (answer.failed)
|
|
190
|
-
return unavailable("docker", `Docker isn't running on this machine, or this user may not use it (docker version failed: ${answer.failed}): start Docker, or add this user to the docker group, then restart AgentRun`);
|
|
191
|
-
if (!answer.out.trim())
|
|
192
|
-
return unavailable("docker", "Docker isn't running on this machine (docker version named no daemon): start Docker, then restart AgentRun");
|
|
193
|
-
return available("docker", boxes.value());
|
|
199
|
+
const daemon = await askDockerDaemon(env, signal, options.groups);
|
|
200
|
+
return daemon.up ? available("docker", boxes.value()) : unavailable("docker", daemon.reason);
|
|
194
201
|
},
|
|
195
202
|
/** One authenticated read the provider makes anyway: the box with a name no box has (lowercase letters, digits and
|
|
196
203
|
* dashes). An answer of no such box (404) means Daytona took the key; 401 or 403 means it refused it. */
|
|
@@ -14,11 +14,14 @@ export interface JournalEntry {
|
|
|
14
14
|
readonly kind: string;
|
|
15
15
|
readonly data: unknown;
|
|
16
16
|
}
|
|
17
|
+
/** The ask a `waiting` hand-over entry holds, or undefined when the entry is not one (or is damaged). The runner writes the
|
|
18
|
+
* session as `session`; a PendingAsk names it `tag`. The one reading of an ask, the server's and the run's process's. */
|
|
19
|
+
export declare function waitingAsk(data: unknown): PendingAsk | undefined;
|
|
17
20
|
/** The browser ask the run view shows: the newest ask still waiting (unanswered and not expired), or undefined. Over the
|
|
18
|
-
* run's journal entries and its hand-over commands
|
|
21
|
+
* run's journal entries and its hand-over commands. (store-view.ts calls
|
|
19
22
|
* this for the run's served `pending`.) */
|
|
20
23
|
export declare function browserAsk(entries: readonly JournalEntry[], commands?: readonly Command[], now?: number): PendingAsk | undefined;
|
|
21
|
-
/** The ask a hand-over answer targets and how it already stands
|
|
24
|
+
/** The ask a hand-over answer targets and how it already stands: the newest ask still
|
|
22
25
|
* waiting, else the newest ask at all; its answer when it has one, `expired` when it is past its expiry, else open (no
|
|
23
26
|
* answer). Undefined when the run has asked nothing. */
|
|
24
27
|
export declare function handBackTarget(entries: readonly JournalEntry[], commands?: readonly Command[], now?: number): {
|
package/dist/browser-commands.js
CHANGED
|
@@ -10,8 +10,8 @@ export const BROWSER_HANDOVER_KIND = "agent.handover";
|
|
|
10
10
|
const TAG = /^[A-Za-z0-9._:-]{1,200}$/;
|
|
11
11
|
const OUTCOMES = ["done", "cancelled", "expired"];
|
|
12
12
|
/** The ask a `waiting` hand-over entry holds, or undefined when the entry is not one (or is damaged). The runner writes the
|
|
13
|
-
* session as `session`; a PendingAsk names it `tag`. */
|
|
14
|
-
function waitingAsk(data) {
|
|
13
|
+
* session as `session`; a PendingAsk names it `tag`. The one reading of an ask, the server's and the run's process's. */
|
|
14
|
+
export function waitingAsk(data) {
|
|
15
15
|
const v = data;
|
|
16
16
|
if (!v || v.state !== "waiting")
|
|
17
17
|
return undefined;
|
|
@@ -68,13 +68,13 @@ function asksIn(entries) {
|
|
|
68
68
|
return asks.sort((a, b) => Date.parse(b.asked_at) - Date.parse(a.asked_at) || b.id.localeCompare(a.id));
|
|
69
69
|
}
|
|
70
70
|
/** The browser ask the run view shows: the newest ask still waiting (unanswered and not expired), or undefined. Over the
|
|
71
|
-
* run's journal entries and its hand-over commands
|
|
71
|
+
* run's journal entries and its hand-over commands. (store-view.ts calls
|
|
72
72
|
* this for the run's served `pending`.) */
|
|
73
73
|
export function browserAsk(entries, commands = [], now = Date.now()) {
|
|
74
74
|
const answered = answersOf(entries, commands);
|
|
75
75
|
return asksIn(entries).find((ask) => !answered.has(ask.id) && Date.parse(ask.expires_at) > now);
|
|
76
76
|
}
|
|
77
|
-
/** The ask a hand-over answer targets and how it already stands
|
|
77
|
+
/** The ask a hand-over answer targets and how it already stands: the newest ask still
|
|
78
78
|
* waiting, else the newest ask at all; its answer when it has one, `expired` when it is past its expiry, else open (no
|
|
79
79
|
* answer). Undefined when the run has asked nothing. */
|
|
80
80
|
export function handBackTarget(entries, commands = [], now = Date.now()) {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BrowserProvider } from "@parcha/pi-browser";
|
|
2
|
+
import type { ClaimBrowser } from "./workspace/resolve-computer.js";
|
|
3
|
+
/** pi-browser's provider over the claim's browser `computer`. A session its provider says is gone (or not found) is gone;
|
|
4
|
+
* any other failure to read it is thrown in its words. */
|
|
5
|
+
export declare function claimBrowserProvider(computer: ClaimBrowser): BrowserProvider;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** What a session of the claim's browser is opened with: none of a run's session settings (no proxy, Verified browser,
|
|
2
|
+
* place, region or context by id) and no saved profile, which the computer protocol does not carry. */
|
|
3
|
+
const SETTINGS = { proxies: false, verified: false, geolocation: false, region: false, context: false };
|
|
4
|
+
/** pi-browser's provider over the claim's browser `computer`. A session its provider says is gone (or not found) is gone;
|
|
5
|
+
* any other failure to read it is thrown in its words. */
|
|
6
|
+
export function claimBrowserProvider(computer) {
|
|
7
|
+
return {
|
|
8
|
+
name: computer.provider,
|
|
9
|
+
caps: { timeoutModel: "wall-clock", maxLifetimeS: computer.maxLifetimeS, survivesDisconnect: true, releaseIsAsync: false, profiles: false, extension: "preinstalled", settings: SETTINGS },
|
|
10
|
+
create: async (spec, signal) => ({ id: await computer.open(spec.tag, spec.maxLifetimeS, signal), tag: spec.tag }),
|
|
11
|
+
findByTag: async (tag, signal) => (await computer.find(tag, signal)).map((id) => ({ id, tag })),
|
|
12
|
+
status: (ref) => computer.url(ref.id).then(() => "running", (error) => {
|
|
13
|
+
const code = error?.code;
|
|
14
|
+
if (code === "gone" || code === "not_found")
|
|
15
|
+
return "gone";
|
|
16
|
+
throw error;
|
|
17
|
+
}),
|
|
18
|
+
attach: async (ref) => ({ sdkCdpUrl: await computer.url(ref.id) }),
|
|
19
|
+
release: (ref) => computer.close(ref.id),
|
|
20
|
+
};
|
|
21
|
+
}
|
package/dist/browser-cost.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord";
|
|
2
2
|
import type { Refusal } from "@parcha/agentrun-kernel";
|
|
3
|
-
import { type Conversation, type Session, type ToolRegistration, type Tx } from "@earendil-works/pi-durable";
|
|
3
|
+
import { type Harness, type Conversation, type Session, type ToolRegistration, type Tx } from "@earendil-works/pi-durable";
|
|
4
4
|
import type { SessionCharge } from "@parcha/pi-browser";
|
|
5
5
|
import type { BeforeCreate } from "@parcha/pi-browser/durable";
|
|
6
|
+
import { BROWSER_CHARGED } from "./cap.js";
|
|
6
7
|
import { type PaidBooking } from "./paid-calls.js";
|
|
7
8
|
/** The run journal's record of a browser session about to be created at its provider: its tag (pi-browser's, which a
|
|
8
9
|
* reconcile finds the vendor's session by), its conversation and the hold its call keeps for it (`held_usd`, null with
|
|
9
|
-
* no cap). Written with pi-browser's own `creating` record and
|
|
10
|
-
*
|
|
10
|
+
* no cap). Written with pi-browser's own `creating` record and flushed before the vendor is asked, so a lost box never
|
|
11
|
+
* leaves a session billed that no record in the store names. */
|
|
11
12
|
export declare const BROWSER_SESSION_OPEN = "agentrun.browser_session_open";
|
|
12
13
|
/** List prices by pi-browser provider name (`provider.name`): Browserbase's (pi-browser's LIST_PRICES), $0.12 an hour with
|
|
13
|
-
* a one-minute minimum; Kernel's headless browser, about $0.06 an hour billed by the second; a local Chrome (`cdp`),
|
|
14
|
+
* a one-minute minimum; Kernel's headless browser, about $0.06 an hour billed by the second; a local Chrome (`cdp`),
|
|
15
|
+
* free. A computer provider whose descriptor bills nothing (metered false: Local Chrome's) is free too (browserPrice). */
|
|
14
16
|
export declare const BROWSER_PRICES: Readonly<Record<string, {
|
|
15
17
|
usdPerHour: number;
|
|
16
18
|
minimumS: number;
|
|
@@ -32,6 +34,7 @@ export declare function browserPrice(provider: string, env: NodeJS.ProcessEnv):
|
|
|
32
34
|
};
|
|
33
35
|
/** A cap refusal as the run's pause reads it (its words; for good, or for room with its figures). */
|
|
34
36
|
type LedgerRefusal = Refusal;
|
|
37
|
+
export { BROWSER_CHARGED };
|
|
35
38
|
/** One run's browser bookings, for its one provider at `price` with pi-browser's idle window `idleS`. `release` lets go of
|
|
36
39
|
* a conversation's session (pi-browser's release, "close"). `log` takes the line that says a charge went uncounted
|
|
37
40
|
* (default: the server's stderr). */
|
|
@@ -41,12 +44,13 @@ export declare function browserSpend(provider: string, price: {
|
|
|
41
44
|
}, idleS: number, release: (conversation: Pick<Conversation, "id" | "commit">, context: Context) => Promise<void>, log?: (line: string) => void, ledger?: {
|
|
42
45
|
paid?: PaidBooking;
|
|
43
46
|
pause?: (refusal: LedgerRefusal) => Promise<void>;
|
|
47
|
+
flush?: () => Promise<void>;
|
|
44
48
|
}): {
|
|
45
49
|
onCharge: (charge: SessionCharge, tx: Tx, call?: {
|
|
46
50
|
callId: string;
|
|
47
51
|
}) => Promise<void>;
|
|
48
52
|
watch: (harness: Pick<Session, "observeCommits" | "closed">, inventory?: string) => void;
|
|
49
|
-
reopened: (harness: Pick<Session, "snapshot"
|
|
53
|
+
reopened: (harness: Pick<Session, "snapshot"> & Partial<Pick<Harness, "conversation">>, docs: {
|
|
50
54
|
Inventory: unknown;
|
|
51
55
|
Sessions: unknown;
|
|
52
56
|
}, context: Context) => Promise<void>;
|
|
@@ -65,4 +69,3 @@ export declare function browserSpend(provider: string, price: {
|
|
|
65
69
|
stretch: number;
|
|
66
70
|
ledgerIdle: () => Promise<void>;
|
|
67
71
|
};
|
|
68
|
-
export {};
|
package/dist/browser-cost.js
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { addSpend, keepHold, paidCall, runCap, SPEND_CAP_REACHED } from "./cap.js";
|
|
5
|
-
import { paidStep
|
|
2
|
+
import { PROVIDERS } from "@parcha/agentrun-computer";
|
|
3
|
+
import { TOOL_COST } from "./timeline/index.js";
|
|
4
|
+
import { addSpend, BROWSER_CHARGED, keepHold, paidCall, runCap, SPEND_CAP_REACHED } from "./cap.js";
|
|
5
|
+
import { paidStep } from "./paid-calls.js";
|
|
6
6
|
import { logLine } from "./print.js";
|
|
7
7
|
import { forModel } from "./result.js";
|
|
8
8
|
/** The run journal's record of a browser session about to be created at its provider: its tag (pi-browser's, which a
|
|
9
9
|
* reconcile finds the vendor's session by), its conversation and the hold its call keeps for it (`held_usd`, null with
|
|
10
|
-
* no cap). Written with pi-browser's own `creating` record and
|
|
11
|
-
*
|
|
10
|
+
* no cap). Written with pi-browser's own `creating` record and flushed before the vendor is asked, so a lost box never
|
|
11
|
+
* leaves a session billed that no record in the store names. */
|
|
12
12
|
export const BROWSER_SESSION_OPEN = "agentrun.browser_session_open";
|
|
13
13
|
/** List prices by pi-browser provider name (`provider.name`): Browserbase's (pi-browser's LIST_PRICES), $0.12 an hour with
|
|
14
|
-
* a one-minute minimum; Kernel's headless browser, about $0.06 an hour billed by the second; a local Chrome (`cdp`),
|
|
14
|
+
* a one-minute minimum; Kernel's headless browser, about $0.06 an hour billed by the second; a local Chrome (`cdp`),
|
|
15
|
+
* free. A computer provider whose descriptor bills nothing (metered false: Local Chrome's) is free too (browserPrice). */
|
|
15
16
|
export const BROWSER_PRICES = Object.freeze({
|
|
16
17
|
browserbase: { usdPerHour: 0.12, minimumS: 60 },
|
|
17
18
|
kernel: { usdPerHour: 0.06, minimumS: 0 },
|
|
18
19
|
cdp: { usdPerHour: 0, minimumS: 0 },
|
|
19
20
|
});
|
|
21
|
+
/** The free price of a computer provider whose descriptor says it bills nothing, never by its id. */
|
|
22
|
+
const unmeteredPrice = (provider) => PROVIDERS.some((entry) => entry.id === provider && !entry.metered) ? { usdPerHour: 0, minimumS: 0 } : undefined;
|
|
20
23
|
/** An operator's price for a provider, in USD an hour: this prefix and the provider's name in capitals
|
|
21
24
|
* (AGENTRUN_BROWSER_USD_PER_HOUR_BROWSERBASE, _KERNEL, _CDP). */
|
|
22
25
|
export const BROWSER_PRICE_ENV = "AGENTRUN_BROWSER_USD_PER_HOUR_";
|
|
@@ -29,36 +32,44 @@ export const priceEnvOf = (provider) => `${BROWSER_PRICE_ENV}${provider.toUpperC
|
|
|
29
32
|
/** `provider`'s session price: the operator's (a non-negative decimal), else the list's; `usdPerHour` null when neither
|
|
30
33
|
* names one or the operator's cannot be read, which is no price, never $0. */
|
|
31
34
|
export function browserPrice(provider, env) {
|
|
32
|
-
const listed = Object.hasOwn(BROWSER_PRICES, provider) ? BROWSER_PRICES[provider] :
|
|
35
|
+
const listed = Object.hasOwn(BROWSER_PRICES, provider) ? BROWSER_PRICES[provider] : unmeteredPrice(provider);
|
|
33
36
|
const text = env[priceEnvOf(provider)]?.trim();
|
|
34
37
|
const given = text ? (/^(\d+(\.\d*)?|\.\d+)$/.test(text) ? Number(text) : NaN) : undefined;
|
|
35
38
|
return { usdPerHour: given === undefined ? (listed?.usdPerHour ?? null) : Number.isFinite(given) ? given : null, minimumS: listed?.minimumS ?? 0 };
|
|
36
39
|
}
|
|
37
40
|
/** Up to the millionth of a dollar, so the cap's words name a figure never below the hold. */
|
|
38
41
|
const microUsd = (usd) => Math.ceil(Math.round(usd * 1e12) / 1e6) / 1e6;
|
|
42
|
+
export { BROWSER_CHARGED };
|
|
43
|
+
/** The tool a browser step on the run's one ledger names (main's charge's `tool`, the timeline's BROWSER_CHARGE): the run
|
|
44
|
+
* view folds its charge into its call's row, as main's. */
|
|
45
|
+
const BROWSER_TOOL = "browser";
|
|
39
46
|
/** One run's browser bookings, for its one provider at `price` with pi-browser's idle window `idleS`. `release` lets go of
|
|
40
47
|
* a conversation's session (pi-browser's release, "close"). `log` takes the line that says a charge went uncounted
|
|
41
48
|
* (default: the server's stderr). */
|
|
42
49
|
export function browserSpend(provider, price, idleS, release, log = (line) => void process.stderr.write(`agentrun-serve: ${line}\n`), ledger = {}) {
|
|
43
|
-
/** The runner's one ledger (the kernel cap's paidCalls), when the run has one
|
|
44
|
-
*
|
|
45
|
-
* session's
|
|
50
|
+
/** The runner's one ledger (the kernel cap's paidCalls), when the run has one. Its holds are hold-only steps (`hold`:
|
|
51
|
+
* money reserved, never spent, given back when let go or when a claim is lost): each browser call's, held at the hold
|
|
52
|
+
* main takes for it, a session's reserve, a person's time. Its money is its charges: each one paid step of its own,
|
|
53
|
+
* owed (its time is spent at the provider: never refused, however the run's spend stands), settled at the charge,
|
|
54
|
+
* named by its session and time (`ref`) so it is booked once, and booked once its commit is in (booked); a reopen books
|
|
55
|
+
* any the root holds and the ledger lacks (reopened). In place of this process's spend. Every step names its tool
|
|
56
|
+
* ("browser") and, where it has them, its call and session, so the run view folds it as main's charge. */
|
|
46
57
|
const paid = ledger.paid;
|
|
47
|
-
/**
|
|
48
|
-
const chargedUnder = new Map();
|
|
49
|
-
/** The ledger steps of charges under no call, until they are written (ledgerIdle). */
|
|
58
|
+
/** The ledger steps of charges and holds, until they are written (ledgerIdle). */
|
|
50
59
|
const pending = new Set();
|
|
51
60
|
let ledgerSeq = 0;
|
|
52
|
-
/** A hold of `usd` under `name`: on the run's one ledger when it is given (a held paid step,
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
|
|
61
|
+
/** A hold of `usd` under `name`: on the run's one ledger when it is given (a held paid step, given back when the hold is
|
|
62
|
+
* let go, the time it held being booked by the session's own charge), else in this process's holds (keepHold). On the
|
|
63
|
+
* ledger nothing is written to this process's holds or spend. `admitted`: the ledger's answer (refused in the cap's
|
|
64
|
+
* words when it has no room). `owed`: time its provider is already owed, run outside any call (a person's carried
|
|
65
|
+
* time, a session held from a reopen, a delayed release), held as main's keepHold holds it: never refused. A fresh
|
|
66
|
+
* session's reserve and a person's time to come (personTime) are not owed: the cap may refuse them. */
|
|
67
|
+
const holdOf = (name, usd, basis, options = {}) => {
|
|
57
68
|
if (!paid)
|
|
58
69
|
return { hold: keepHold(usd), admitted: Promise.resolve({}) };
|
|
59
70
|
const booking = paid;
|
|
60
71
|
const id = `browser:${name}#${(ledgerSeq += 1)}`;
|
|
61
|
-
const admitted = booking.admit({ id, name, holdUsd: usd, basis, chargedBy: provider }).then(() => ({}), (error) => {
|
|
72
|
+
const admitted = booking.admit({ id, name, holdUsd: usd, basis, chargedBy: provider, tool: BROWSER_TOOL, hold: true, ...(options.tag ? { tag: options.tag } : {}), ...(options.owed ? { owed: true } : {}) }).then(() => ({}), (error) => {
|
|
62
73
|
const capped = error?.code === "spend_cap_reached";
|
|
63
74
|
const refused = capped ? String(error.message) : `${name} could not be held: ${String(error?.message ?? error)}`;
|
|
64
75
|
// The cap's own refusal, as the run's pause reads it (a room refusal's figures; a refusal for good).
|
|
@@ -75,7 +86,8 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
|
|
|
75
86
|
if (dropped)
|
|
76
87
|
return;
|
|
77
88
|
dropped = true;
|
|
78
|
-
|
|
89
|
+
// Given back: a hold is no charge (its time, when it ran, is booked by the session's own charge), never a $0 one.
|
|
90
|
+
const settled = admitted.then((answer) => (answer.refused === undefined ? booking.settle(id, 0, { givenBack: true }) : undefined)).catch(() => undefined);
|
|
79
91
|
pending.add(settled);
|
|
80
92
|
void settled.finally(() => pending.delete(settled));
|
|
81
93
|
},
|
|
@@ -136,32 +148,37 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
|
|
|
136
148
|
const calls = new Map();
|
|
137
149
|
const take = (hold, usd) => void (hold && (hold.usd = Math.max(0, hold.usd - usd)));
|
|
138
150
|
/** Booked in the commit that bills it: a TOOL_COST under the call that ran it (a release's, under its session's last
|
|
139
|
-
* call
|
|
140
|
-
* provider's time books nothing and holds
|
|
151
|
+
* call; on the runner's ledger, a BROWSER_CHARGED, its money the ledger step's), what it cost or null when its time
|
|
152
|
+
* has no price, and the seconds it was for, with what `booked` needs. A free provider's time books nothing and holds
|
|
153
|
+
* nothing. */
|
|
141
154
|
async function onCharge(charge, tx, call) {
|
|
142
155
|
if (rate === 0)
|
|
143
156
|
return;
|
|
144
157
|
const usd = charge.state === "priced" ? charge.usd : null;
|
|
145
|
-
if (paid) {
|
|
146
|
-
const under = call?.callId;
|
|
147
|
-
if (under !== undefined && chargedUnder.has(under)) {
|
|
148
|
-
const so = chargedUnder.get(under) ?? null;
|
|
149
|
-
chargedUnder.set(under, so === null || usd === null ? null : so + usd);
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
// A charge under no call under way (the release's, its top-up to the minute): one more paid request on the ledger,
|
|
153
|
-
// held at nothing (its time is spent already) and settled at the charge.
|
|
154
|
-
const step = paidStep(paid, `${charge.tag}${charge.final ? "@release" : "@charge"}`, { name: "this browser session's time", holdUsd: 0, basis: `${provider}'s session time, billed as it was charged`, by: charge.provider }, async () => undefined, () => usd).catch(() => undefined);
|
|
155
|
-
pending.add(step);
|
|
156
|
-
void step.finally(() => pending.delete(step));
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
158
|
const data = { tool: "browser", charged_by: charge.provider, call: call?.callId ?? sessions.get(charge.tag)?.call ?? null, usd, seconds: charge.seconds, tag: charge.tag, conversation: charge.conversationId, at: charge.at, final: charge.final };
|
|
160
|
-
|
|
159
|
+
// On the ledger, its money is the ledger's, booked once this commit is in (booked): the root keeps the record under a
|
|
160
|
+
// kind no cost reads.
|
|
161
|
+
await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: paid ? BROWSER_CHARGED : TOOL_COST, data });
|
|
162
|
+
}
|
|
163
|
+
/** A charge on the run's one ledger, once its commit is in: one paid step of its own, owed (its time is spent at the
|
|
164
|
+
* provider, so the cap never refuses it, however the run's spend stands), settled at the charge, under its call (the
|
|
165
|
+
* one that ran it, else its session's last; none after a restart that lost it) and named by its session and time, so
|
|
166
|
+
* it is booked once whoever books it (this, or a reopen's: reopened). One that cannot be booked (its claim lost, a
|
|
167
|
+
* write that failed) is said in the log, and booked by the next claim's reopen. */
|
|
168
|
+
function bookOnLedger(booking, data) {
|
|
169
|
+
// Held at its charge (known: it was billed): a claim lost before its settle leaves it booked at that, never unknown
|
|
170
|
+
// (the kernel's bookCut books an owed step at its hold). A charge of an unknown amount holds nothing.
|
|
171
|
+
const owes = typeof data.usd === "number" && Number.isFinite(data.usd) && data.usd > 0 ? data.usd : 0;
|
|
172
|
+
const step = paidStep(booking, data.call ?? undefined, { name: "this browser session's time", holdUsd: owes, basis: `${provider}'s session time, billed as it was charged`, by: data.charged_by, tool: BROWSER_TOOL, tag: data.tag, owed: true, ref: chargeRef(data) }, async () => undefined, () => data.usd).then((stepped) => void ("refused" in stepped && log(logLine("browser_spend_unbooked", { said: `a browser charge of ${data.tag} was not booked on the run's ledger (${stepped.refused.slice(0, 200)}): the next claim's reopen books it` }))), (error) => void log(logLine("browser_spend_unbooked", { said: `a browser charge of ${data.tag} was not booked on the run's ledger (${String(error?.message ?? error).slice(0, 200)}): the next claim's reopen books it` })));
|
|
173
|
+
pending.add(step);
|
|
174
|
+
void step.finally(() => pending.delete(step));
|
|
175
|
+
return step;
|
|
161
176
|
}
|
|
162
177
|
/** A charge whose commit is in (watch): it joins what the run's process counts as spent, and moves the holds. Never
|
|
163
178
|
* inside the commit, so one that fails changes neither. */
|
|
164
179
|
function booked(data) {
|
|
180
|
+
if (paid)
|
|
181
|
+
bookOnLedger(paid, data);
|
|
165
182
|
const usd = data.usd ?? 0;
|
|
166
183
|
const session = sessions.get(data.tag);
|
|
167
184
|
spendIn(data.usd);
|
|
@@ -192,8 +209,31 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
|
|
|
192
209
|
}
|
|
193
210
|
else {
|
|
194
211
|
take(data.call === null ? undefined : calls.get(data.call)?.hold, usd + stretch);
|
|
195
|
-
sessions.set(data.tag, { cid: data.conversation, reserve: holdOf("this browser session's reserve", stretch, `${provider}'s next stretch of session time, held until its release is booked
|
|
212
|
+
sessions.set(data.tag, { cid: data.conversation, reserve: holdOf("this browser session's reserve", stretch, `${provider}'s next stretch of session time, held until its release is booked`, { tag: data.tag }).hold, at: through, call: data.call });
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/** The one booking a charge names on the ledger: its session, its time, and whether it was the session's last. */
|
|
216
|
+
const chargeRef = (data) => `browser:${data.tag}@${data.at}${data.final ? "/final" : ""}`;
|
|
217
|
+
/** At a reopen, on the runner's one ledger: every charge the root holds (BROWSER_CHARGED) is booked there, once by its
|
|
218
|
+
* ref, so one whose commit landed and whose booking did not (its process lost between the two) is counted now; one
|
|
219
|
+
* booked already books nothing. */
|
|
220
|
+
async function bookRootCharges(harness, context) {
|
|
221
|
+
if (!paid)
|
|
222
|
+
return;
|
|
223
|
+
const root = await harness.conversation(ROOT_CONVERSATION_ID, context);
|
|
224
|
+
if (!root)
|
|
225
|
+
return;
|
|
226
|
+
const charges = [];
|
|
227
|
+
for (let cursor = undefined;;) {
|
|
228
|
+
const page = await root.entries({ order: "ascending" }, 500, cursor, context);
|
|
229
|
+
for (const entry of page.items)
|
|
230
|
+
if (entry.kind === BROWSER_CHARGED)
|
|
231
|
+
charges.push(entry.data);
|
|
232
|
+
if (page.next === undefined)
|
|
233
|
+
break;
|
|
234
|
+
cursor = page.next;
|
|
196
235
|
}
|
|
236
|
+
await Promise.all(charges.map((data) => bookOnLedger(paid, data)));
|
|
197
237
|
}
|
|
198
238
|
/** At a reopen, after pi-browser's reconcile: every session its custody still tracks (each row of its inventory: kept,
|
|
199
239
|
* unreached, still releasing, lost) is held from here as if opened in this process, at a stretch beside what it ran
|
|
@@ -202,6 +242,8 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
|
|
|
202
242
|
async function reopened(harness, docs, context) {
|
|
203
243
|
if (rate === 0)
|
|
204
244
|
return;
|
|
245
|
+
if (harness.conversation)
|
|
246
|
+
await bookRootCharges(harness, context);
|
|
205
247
|
const rows = Object.values((await harness.snapshot(docs.Inventory, context))?.rows ?? {});
|
|
206
248
|
for (const row of rows.filter((r) => !sessions.has(r.tag))) {
|
|
207
249
|
const record = (await harness.snapshot(docs.Sessions, row.conversationId, context))?.sessions?.find((s) => s.tag === row.tag);
|
|
@@ -211,7 +253,7 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
|
|
|
211
253
|
continue;
|
|
212
254
|
// Its reserve carries the down time, so its calls count what it runs from here (`at` now), not the down time again.
|
|
213
255
|
const now = Date.now();
|
|
214
|
-
sessions.set(row.tag, { cid: row.conversationId, reserve: holdOf("this browser session's reserve", stretch + usdOf(Math.max(0, now - at) / 1000), `${provider}'s session time since its last charge and its next stretch, held from the reopen
|
|
256
|
+
sessions.set(row.tag, { cid: row.conversationId, reserve: holdOf("this browser session's reserve", stretch + usdOf(Math.max(0, now - at) / 1000), `${provider}'s session time since its last charge and its next stretch, held from the reopen`, { owed: true, tag: row.tag }).hold, at: now, call: null });
|
|
215
257
|
}
|
|
216
258
|
}
|
|
217
259
|
/** The open-session inventory as committed: a session it no longer holds lets go of its reserve (released, billed or
|
|
@@ -230,7 +272,7 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
|
|
|
230
272
|
continue;
|
|
231
273
|
const usd = usdOf(CREATE_DEADLINE_S + stretchS);
|
|
232
274
|
take([...calls.values()].find((c) => c.cid === row.conversationId)?.hold, usd);
|
|
233
|
-
sessions.set(row.tag, { cid: row.conversationId, reserve: holdOf("this browser session's delayed release", usd, `${provider}'s session time for its create's deadline and a stretch, until its release is billed
|
|
275
|
+
sessions.set(row.tag, { cid: row.conversationId, reserve: holdOf("this browser session's delayed release", usd, `${provider}'s session time for its create's deadline and a stretch, until its release is billed`, { owed: true, tag: row.tag }).hold, at: Date.now(), call: null });
|
|
234
276
|
}
|
|
235
277
|
}
|
|
236
278
|
/** Applies each browser charge `harness` commits, and each change of pi-browser's inventory (the document of kind
|
|
@@ -258,7 +300,7 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
|
|
|
258
300
|
advance: (publication) => {
|
|
259
301
|
try {
|
|
260
302
|
for (const change of publication.changes) {
|
|
261
|
-
const data = change.type === "entry" && change.value.kind === TOOL_COST ? change.value.data : undefined;
|
|
303
|
+
const data = change.type === "entry" && (change.value.kind === TOOL_COST || change.value.kind === BROWSER_CHARGED) ? change.value.data : undefined;
|
|
262
304
|
if (data?.tool === "browser" && typeof data.tag === "string")
|
|
263
305
|
booked(data);
|
|
264
306
|
}
|
|
@@ -297,18 +339,19 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
|
|
|
297
339
|
const usd = microUsd(Math.max(0, usdOf(ranS) - carriedUsd) + 2 * stretch);
|
|
298
340
|
const basis = `${provider}'s session time at $${rate} an hour: the ${Math.round(ranS)} s its session ran since its last charge, and twice the next stretch of ${stretchS} s (its ${price.minimumS} s minimum, the ${idleS} s idle window and ${RELEASE_ALLOWANCE_S} s for its release)`;
|
|
299
341
|
if (ledger.paid) {
|
|
300
|
-
// On the runner's one ledger: one
|
|
301
|
-
//
|
|
302
|
-
chargedUnder.set(api.callId, 0);
|
|
342
|
+
// On the runner's one ledger: one hold-only step, held at that same figure and given back when the call returns
|
|
343
|
+
// (or its claim is lost): the call's charges are each their own step (booked).
|
|
303
344
|
calls.set(api.callId, { cid: api.conversationId, hold: { usd, drop: () => { } } });
|
|
304
345
|
try {
|
|
305
346
|
// A provider whose time has no price is held at no figure: the cap's rule refuses it for good, as main does.
|
|
306
|
-
|
|
347
|
+
// One refused for room pauses the run (ledger.pause, the run's own: a native tool task runs in no host tool
|
|
348
|
+
// call's ledger), in the cap's words and figures, as an ask's person time does: its next request is refused
|
|
349
|
+
// and the run parks for a raise.
|
|
350
|
+
const stepped = await paidStep(ledger.paid, api.callId, { name: "this browser call", holdUsd: rate === null ? Number.NaN : usd, basis, by: provider, tool: BROWSER_TOOL, hold: true }, () => tool.execute(args, api, context), () => 0, ledger.pause);
|
|
307
351
|
return "refused" in stepped ? await refuse(stepped.refused, api, context) : stepped.result;
|
|
308
352
|
}
|
|
309
353
|
finally {
|
|
310
354
|
calls.delete(api.callId);
|
|
311
|
-
chargedUnder.delete(api.callId);
|
|
312
355
|
}
|
|
313
356
|
}
|
|
314
357
|
const paid = await paidCall("this browser call", async () => keepHold(usd), () => undefined, { usd, basis });
|
|
@@ -327,13 +370,14 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
|
|
|
327
370
|
};
|
|
328
371
|
}
|
|
329
372
|
/** pi-browser's `beforeCreate`: the session's open recorded in the run's journal (BROWSER_SESSION_OPEN) beside its
|
|
330
|
-
* `creating` record,
|
|
331
|
-
*
|
|
373
|
+
* `creating` record, then flushed to disk (`ledger.flush`, the runner's store flush) before the vendor's session is
|
|
374
|
+
* created. The runner's flush before a tool call comes before the call opens its session, so it never covers this
|
|
375
|
+
* record. A write or a flush that fails throws, and pi-browser creates nothing. */
|
|
332
376
|
const opening = async (open) => {
|
|
333
377
|
const hold = [...calls.values()].find((c) => c.cid === open.conversationId)?.hold;
|
|
334
378
|
const data = { tag: open.tag, conversation: open.conversationId, provider, held_usd: hold ? hold.usd : null };
|
|
335
379
|
await open.commit(async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: BROWSER_SESSION_OPEN, data })));
|
|
336
|
-
await
|
|
380
|
+
await ledger.flush?.();
|
|
337
381
|
};
|
|
338
382
|
/** The cap's refusal as the call's error, and the conversation's session let go, so it runs no longer. */
|
|
339
383
|
async function refuse(why, api, context) {
|
|
@@ -405,7 +449,7 @@ export function browserSpend(provider, price, idleS, release, log = (line) => vo
|
|
|
405
449
|
if (!(to > from))
|
|
406
450
|
return;
|
|
407
451
|
// Spent at the provider already: held on the run's ledger (or this process's holds) until a charge books it.
|
|
408
|
-
const { hold } = holdOf("a person's time in the browser", microUsd(usdOf((to - from) / 1000)), `${provider}'s session time a person used, until the session's next charge books it
|
|
452
|
+
const { hold } = holdOf("a person's time in the browser", microUsd(usdOf((to - from) / 1000)), `${provider}'s session time a person used, until the session's next charge books it`, { owed: true, tag });
|
|
409
453
|
carried.set(tag, [...(carried.get(tag) ?? []), { hold, from, to }]);
|
|
410
454
|
}
|
|
411
455
|
/** Once every ledger step of a charge under no call is written (the runner's one ledger; nothing to wait for without). */
|