@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/box-paths.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Where the daemon has the data directory: the named volume mounted at `at
|
|
1
|
+
/** Where the daemon has the data directory: the named volume mounted at `at`. */
|
|
2
2
|
export type BoxPaths = {
|
|
3
3
|
at: string;
|
|
4
4
|
volume: string;
|
|
@@ -11,7 +11,7 @@ export type DockerPaths = {
|
|
|
11
11
|
} | {
|
|
12
12
|
reason: string;
|
|
13
13
|
};
|
|
14
|
-
/** The one way a server in a container runs
|
|
14
|
+
/** The one way a server in a container runs Docker computers. */
|
|
15
15
|
export declare const IN_COMPOSE = "run AgentRun in a container with `docker compose up` from compose.yaml (its named data volume is how boxes reach a run's files)";
|
|
16
16
|
/** An engine that cannot mount a volume's subpath. */
|
|
17
17
|
export declare const OLD_ENGINE = "Docker Engine <26 can't mount a named volume's subpath: upgrade to Docker 26+";
|
|
@@ -42,11 +42,6 @@ export declare function dockerComputerRefusal(paths: DockerPaths, remote: string
|
|
|
42
42
|
export declare function dockerPathsForRuns(env: NodeJS.ProcessEnv, data: string, platform?: NodeJS.Platform): Promise<DockerPaths>;
|
|
43
43
|
/** Under `--faux` only: a file the server reads as its /proc/self/mountinfo (server.ts fauxMountinfo). */
|
|
44
44
|
export declare const FAUX_MOUNTINFO_ENV = "AGENTRUN_SERVE_FAUX_MOUNTINFO";
|
|
45
|
-
/** What the server hands a run's process: the paths, as JSON; empty on a host. */
|
|
46
|
-
export declare const RUN_BOX_PATHS_ENV = "AGENTRUN_RUN_BOX_PATHS";
|
|
47
|
-
/** The directory the runs' egress proxy sockets are in, for a server in a container: on its data volume, so a box can
|
|
48
|
-
* mount its run's (box-egress.ts egressDir). */
|
|
49
|
-
export declare const egressParentOf: (data: string) => string;
|
|
50
45
|
/** Its own container's id, from /proc/self/mountinfo: the source of the /etc/hostname Docker bound in. */
|
|
51
46
|
export declare function ownContainerOf(mountinfo: string): string | undefined;
|
|
52
47
|
/** A mount of a container, as `docker inspect` gives it. */
|
package/dist/box-paths.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
// Where the Docker a server runs
|
|
2
|
-
// a
|
|
1
|
+
// Where the Docker a server runs computers on has the server's files. On a host, the server's paths are the daemon's own,
|
|
2
|
+
// and a computer binds the run's folder by its path: nothing here is asked. A server in a container of that Docker's own, given its
|
|
3
3
|
// socket (compose.yaml at the repository's root), has paths the daemon does not: the daemon has only what it mounted
|
|
4
4
|
// into the server's container. One layout is supported: the data directory on a named volume of the server's own
|
|
5
5
|
// container, as compose.yaml makes it. The server reads its own container's id from /proc/self/mountinfo (Docker binds
|
|
6
6
|
// /etc/hostname from `<its root>/containers/<id>/hostname`), asks Docker for that container's mounts, and takes the
|
|
7
|
-
// named volume that holds the data directory; a
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// start, and docker is unavailable: a guess would make every box fail at its create.
|
|
7
|
+
// named volume that holds the data directory; a run's Docker computer then mounts its run's folder and its daemon copy as
|
|
8
|
+
// that volume's subpaths (`volume-subpath`: Docker Engine 26 and later), never the volume's root (workspace/
|
|
9
|
+
// computer-deps.ts dockerVolumeOf, the Docker provider's `volume`). Any other layout, or an older engine, is a reason,
|
|
10
|
+
// said once at the start, and docker is unavailable: a guess would make every computer fail at its create.
|
|
12
11
|
import { execFile } from "node:child_process";
|
|
13
12
|
import { existsSync } from "node:fs";
|
|
14
13
|
import { readFile } from "node:fs/promises";
|
|
15
14
|
import { FAUX_ENV } from "./model.js";
|
|
16
15
|
import { withoutSecrets } from "./secrets.js";
|
|
17
|
-
/** The one way a server in a container runs
|
|
16
|
+
/** The one way a server in a container runs Docker computers. */
|
|
18
17
|
export const IN_COMPOSE = "run AgentRun in a container with `docker compose up` from compose.yaml (its named data volume is how boxes reach a run's files)";
|
|
19
18
|
/** An engine that cannot mount a volume's subpath. */
|
|
20
19
|
export const OLD_ENGINE = "Docker Engine <26 can't mount a named volume's subpath: upgrade to Docker 26+";
|
|
@@ -96,11 +95,6 @@ export async function dockerPathsForRuns(env, data, platform = process.platform)
|
|
|
96
95
|
}
|
|
97
96
|
/** Under `--faux` only: a file the server reads as its /proc/self/mountinfo (server.ts fauxMountinfo). */
|
|
98
97
|
export const FAUX_MOUNTINFO_ENV = "AGENTRUN_SERVE_FAUX_MOUNTINFO";
|
|
99
|
-
/** What the server hands a run's process: the paths, as JSON; empty on a host. */
|
|
100
|
-
export const RUN_BOX_PATHS_ENV = "AGENTRUN_RUN_BOX_PATHS";
|
|
101
|
-
/** The directory the runs' egress proxy sockets are in, for a server in a container: on its data volume, so a box can
|
|
102
|
-
* mount its run's (box-egress.ts egressDir). */
|
|
103
|
-
export const egressParentOf = (data) => `${data}/box-egress`;
|
|
104
98
|
/** Its own container's id, from /proc/self/mountinfo: the source of the /etc/hostname Docker bound in. */
|
|
105
99
|
export function ownContainerOf(mountinfo) {
|
|
106
100
|
for (const line of mountinfo.split("\n")) {
|
package/dist/box-settings.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { BoxProvider } from "@parcha/pi-transport";
|
|
2
|
-
import { type DockerNetwork, egressBlockedBy } from "./box-egress.js";
|
|
3
1
|
/** The setting that names the hosts a box may reach: a comma list of hosts, each a name or `*.` and a name, which
|
|
4
2
|
* replaces the default list; `none` for no network at all. Unset or empty, the default. */
|
|
5
3
|
export declare const BOX_ALLOW_ENV = "AGENTRUN_BOX_ALLOW";
|
|
@@ -15,12 +13,3 @@ export declare const MAX_BOX_ALLOW = 100;
|
|
|
15
13
|
* unset or empty; `none` for no network. `*`, an IP address, a CIDR, a port, a URL, or more than 100 hosts throws, saying
|
|
16
14
|
* what the setting takes: the start checks it (startServe), so no run meets one. */
|
|
17
15
|
export declare function boxAllowOf(env: NodeJS.ProcessEnv): readonly string[] | "none";
|
|
18
|
-
/** What a server's Docker boxes reach, resolved once at its start: the setting's list (boxAllowOf) where egressBlockedBy
|
|
19
|
-
* (box-egress.ts) finds the daemon is this Linux machine's own, else none with the reason; `none` from the setting, with
|
|
20
|
-
* it as the reason. */
|
|
21
|
-
export declare function boxNetworkOf(env: NodeJS.ProcessEnv, options?: Parameters<typeof egressBlockedBy>[1]): Promise<DockerNetwork>;
|
|
22
|
-
/** Under `--faux` only: a module whose default export, given the data root, is the provider the tests' faux box comes
|
|
23
|
-
* from in place of Docker. */
|
|
24
|
-
export declare const FAUX_BOX_ENV = "AGENTRUN_SERVE_FAUX_BOX";
|
|
25
|
-
/** The tests' faux box provider, from its module. */
|
|
26
|
-
export declare const fauxBoxes: (module: string, root: string) => Promise<BoxProvider>;
|
package/dist/box-settings.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
import { pathToFileURL } from "node:url";
|
|
6
|
-
import { egressBlockedBy } from "./box-egress.js";
|
|
7
|
-
import { vmDocker } from "./box-egress-vm.js";
|
|
1
|
+
// The hosts a run's computer may reach (AGENTRUN_BOX_ALLOW), as the server reads them at its start: a run's launch keeps
|
|
2
|
+
// them (box_allow) and its computer is made with them (workspace/computer-deps.ts). A setting that is not one throws,
|
|
3
|
+
// naming it: the start checks it, so no run meets one. A Docker computer's size (AGENTRUN_BOX_CPUS, _MEMORY, _PIDS) is
|
|
4
|
+
// workspace/computer-deps.ts dockerLimitsOf.
|
|
8
5
|
/** The setting that names the hosts a box may reach: a comma list of hosts, each a name or `*.` and a name, which
|
|
9
6
|
* replaces the default list; `none` for no network at all. Unset or empty, the default. */
|
|
10
7
|
export const BOX_ALLOW_ENV = "AGENTRUN_BOX_ALLOW";
|
|
@@ -39,25 +36,3 @@ export function boxAllowOf(env) {
|
|
|
39
36
|
throw new Error(`${BOX_ALLOW_ENV} names ${hosts.length} hosts; it takes at most ${MAX_BOX_ALLOW}`);
|
|
40
37
|
return Object.freeze(hosts);
|
|
41
38
|
}
|
|
42
|
-
/** What a server's Docker boxes reach, resolved once at its start: the setting's list (boxAllowOf) where egressBlockedBy
|
|
43
|
-
* (box-egress.ts) finds the daemon is this Linux machine's own, else none with the reason; `none` from the setting, with
|
|
44
|
-
* it as the reason. */
|
|
45
|
-
export async function boxNetworkOf(env, options = {}) {
|
|
46
|
-
const allow = boxAllowOf(env);
|
|
47
|
-
if (allow === "none")
|
|
48
|
-
return { allow: "none", reason: `${BOX_ALLOW_ENV} is none` };
|
|
49
|
-
const blocked = await egressBlockedBy(env, options);
|
|
50
|
-
if (!blocked)
|
|
51
|
-
return { allow };
|
|
52
|
-
// On a Mac only: a Docker that docker info names as a VM runtime this server knows gets the proxy container
|
|
53
|
-
// (box-egress-vm.ts); any other stays none, saying why.
|
|
54
|
-
if ((options.platform ?? process.platform) !== "darwin")
|
|
55
|
-
return { allow: "none", reason: blocked };
|
|
56
|
-
const vm = await vmDocker(env, { ...(options.platform ? { platform: options.platform } : {}), ...(options.kernel ? { kernel: options.kernel } : {}), ...(options.timeoutMs ? { timeoutMs: options.timeoutMs } : {}) });
|
|
57
|
-
return "runtime" in vm ? { allow, vm: vm.runtime } : { allow: "none", reason: vm.reason };
|
|
58
|
-
}
|
|
59
|
-
/** Under `--faux` only: a module whose default export, given the data root, is the provider the tests' faux box comes
|
|
60
|
-
* from in place of Docker. */
|
|
61
|
-
export const FAUX_BOX_ENV = "AGENTRUN_SERVE_FAUX_BOX";
|
|
62
|
-
/** The tests' faux box provider, from its module. */
|
|
63
|
-
export const fauxBoxes = async (module, root) => (await import(pathToFileURL(module).href)).default(root);
|
package/dist/browser-commands.js
CHANGED
|
@@ -19,7 +19,7 @@ export function waitingAsk(data) {
|
|
|
19
19
|
const ok = typeof v.id === "string" && typeof tag === "string" && TAG.test(tag) && typeof v.instruction === "string" && typeof v.completion_condition === "string" && Number.isFinite(Date.parse(String(v.asked_at))) && Number.isFinite(Date.parse(String(v.expires_at)));
|
|
20
20
|
return ok ? { id: v.id, tag, instruction: v.instruction, completion_condition: v.completion_condition, asked_at: v.asked_at, expires_at: v.expires_at } : undefined;
|
|
21
21
|
}
|
|
22
|
-
/** A valid `at` (ms): a finite epoch millisecond, as a Timeline phase row's time
|
|
22
|
+
/** A valid `at` (ms): a finite epoch millisecond, as a Timeline phase row's time. */
|
|
23
23
|
const atOf = (value) => (typeof value === "number" && Number.isFinite(value) && Math.abs(value) <= 8.64e15 ? value : undefined);
|
|
24
24
|
/** The ask an answered hand-over entry names, how it ended and when, or undefined when the entry is not one. */
|
|
25
25
|
function answeredEntry(data) {
|
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
import type { BrowserProvider } from "@parcha/pi-browser";
|
|
2
|
+
import { type ComputerProvider } from "@parcha/agentrun-computer";
|
|
2
3
|
import type { ClaimBrowser } from "./workspace/resolve-computer.js";
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
/** What the adapter opens every session with, beside custody's spec. */
|
|
5
|
+
export interface BrowserComputerOptions {
|
|
6
|
+
/** The run's saved sign-in: the vendor's object a session asking for the profile `name` opens on. */
|
|
7
|
+
readonly signIn?: {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly pointer: string;
|
|
10
|
+
};
|
|
11
|
+
/** A headless browser where the provider offers one. */
|
|
12
|
+
readonly headless?: boolean;
|
|
13
|
+
/** Where a server behind a browser gateway holds the sockets of Browserbase's connect hosts (BROWSERBASE_CONNECT_BASE_URL). */
|
|
14
|
+
readonly connectBaseUrl?: string;
|
|
15
|
+
readonly sleep?: (ms: number) => Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
/** pi-browser's provider over `computer`, a browser computer the claim or the plane opened. */
|
|
18
|
+
export declare function claimBrowserProvider(computer: ClaimBrowser, options?: BrowserComputerOptions): BrowserProvider;
|
|
19
|
+
/** The plane's vendor as a computer provider of the registry, made with the run's tool keys by the registry's names
|
|
20
|
+
* (computer-keys.ts providerOptions): the same provider an agent's browser computer is, on the keys the tool plane
|
|
21
|
+
* resolved it by. */
|
|
22
|
+
export declare function planeComputer(vendor: string, env: NodeJS.ProcessEnv): Promise<ComputerProvider>;
|
|
23
|
+
/** The run's browser sessions of a lower claim epoch released, as a computer's are when a claim starts it (the janitor's
|
|
24
|
+
* releaseOlder): a runner that died after the vendor made a session and before its id was kept left one this claim's
|
|
25
|
+
* labels would never find. One that ended may have been saving to the run's sign-in, and this process holds no saver
|
|
26
|
+
* for it, so when any was ended the provider's settle time is waited out before the plane's browser opens a session. */
|
|
27
|
+
export declare function releaseOlderBrowsers(provider: ComputerProvider, run: {
|
|
28
|
+
readonly runId: string;
|
|
29
|
+
readonly epoch: number;
|
|
30
|
+
}, { signal, sleep }?: {
|
|
31
|
+
readonly signal?: AbortSignal;
|
|
32
|
+
readonly sleep?: (ms: number) => Promise<void>;
|
|
33
|
+
}): Promise<void>;
|
|
34
|
+
/** A Browserbase connect URL moved onto the credential proxy that fronts its sockets: only `*.browserbase.com` hosts, with
|
|
35
|
+
* the signing query kept. */
|
|
36
|
+
export declare function rewriteConnectUrl(connectUrl: string, connectBaseUrl: string | undefined): string;
|
|
37
|
+
/** A run's browser over `provider`, a browser computer provider (the plane's vendor, or a test's stand-in), as the claim
|
|
38
|
+
* opens an agent's browser computer: each session made under the run's labels (`run`, when the run holds a claim, so a
|
|
39
|
+
* sweep finds what it left), for at most the provider's longest lifetime. A provider of another kind is refused. */
|
|
40
|
+
export declare function planeBrowser(provider: ComputerProvider, run: {
|
|
41
|
+
readonly runId: string;
|
|
42
|
+
readonly epoch: number;
|
|
43
|
+
} | undefined): ClaimBrowser;
|
|
44
|
+
/** When the run's process lets the run go: closes the download sockets its browser's sessions hold, released or not (a
|
|
45
|
+
* runner that closes leaves a session to the next claim, whose attach opens its own). An open socket would keep the
|
|
46
|
+
* process from exiting. A socket still opening is closed once it opens. */
|
|
47
|
+
export declare function closeHeldSockets(computer: ClaimBrowser): Promise<void>;
|
|
48
|
+
/** Tests only: forgets every session's socket and saver this process holds. */
|
|
49
|
+
export declare function resetBrowserComputerHoldings(): void;
|
package/dist/browser-computer.js
CHANGED
|
@@ -1,21 +1,289 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { BrowserFailureError, browserFailure, cdpCall } from "@parcha/pi-browser";
|
|
2
|
+
import { BROWSER_IMAGE, isBrowserProvider, PROVIDERS, providerFor, releaseOlder, runLabels } from "@parcha/agentrun-computer";
|
|
3
|
+
import { KEY_TABLE, providerOptions } from "./computer-keys.js";
|
|
4
|
+
import { claimBrowser } from "./workspace/computer-for-claim.js";
|
|
5
|
+
/** Custody's own refusal of a second saver, in its words: no session was started. */
|
|
6
|
+
const ONE_SAVER = "one session at a time may save to this agent's saved sign-in, and another session is saving to it now. Wait for it to end, or start without saving. No session was started.";
|
|
7
|
+
const STILL_ENDING = "the session that was saving to this agent's saved sign-in is still ending. Try again in a moment. No session was started.";
|
|
8
|
+
const SAVER_WAIT_MS = 20_000;
|
|
9
|
+
/** A failure custody reads: the provider's words, and a status where the code is one custody tells apart. */
|
|
10
|
+
function withStatus(error) {
|
|
11
|
+
const code = error?.code;
|
|
12
|
+
const status = code === "denied" ? 403 : code === "not_found" ? 404 : code === "limit" ? 429 : undefined;
|
|
13
|
+
return status === undefined || typeof error !== "object" || error === null ? error : Object.assign(error, { status });
|
|
14
|
+
}
|
|
15
|
+
const statused = async (work) => {
|
|
16
|
+
try {
|
|
17
|
+
return await work;
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
throw withStatus(error);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const goneCode = (error) => {
|
|
24
|
+
const code = error?.code;
|
|
25
|
+
return code === "gone" || code === "not_found";
|
|
26
|
+
};
|
|
27
|
+
/** What a session holds in this process, by provider and session id: its download-behaviour socket. */
|
|
28
|
+
const sockets = new Map();
|
|
29
|
+
const opening = new Map();
|
|
30
|
+
/** The sockets each run's browser (the ClaimBrowser its provider is over) opened, by the same keys: let go with the run. */
|
|
31
|
+
const heldBy = new WeakMap();
|
|
32
|
+
const savers = new Map();
|
|
33
|
+
const freeSaver = (tag) => {
|
|
34
|
+
for (const [key, held] of savers)
|
|
35
|
+
if (held.tag === tag)
|
|
36
|
+
savers.delete(key);
|
|
37
|
+
};
|
|
38
|
+
const isSaver = (tag) => [...savers.values()].some((held) => held.tag === tag);
|
|
39
|
+
/** True when `work` ends within `ms`; false at the deadline. */
|
|
40
|
+
async function within(work, ms) {
|
|
41
|
+
let timer;
|
|
42
|
+
try {
|
|
43
|
+
return await Promise.race([work.then(() => true), new Promise((resolve) => { timer = setTimeout(() => resolve(false), Math.max(0, ms)); })]);
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
clearTimeout(timer);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** The one-saver rule: a holder that no longer runs is replaced once its settle time is waited out; the same tag keeps it;
|
|
50
|
+
* the same owner's successor (a relaunch asks for its replacement while the old session is still being released) waits
|
|
51
|
+
* for the release; any other is refused. */
|
|
52
|
+
async function claimSaver(key, tag, owner, signal, sleep) {
|
|
53
|
+
for (const end = Date.now() + SAVER_WAIT_MS;;) {
|
|
54
|
+
const held = savers.get(key);
|
|
55
|
+
if (!held || held.tag === tag)
|
|
56
|
+
return void savers.set(key, { tag, owner });
|
|
57
|
+
const running = held.running ? await held.running().catch(() => true) : true;
|
|
58
|
+
if (running) {
|
|
59
|
+
if (held.owner !== owner)
|
|
60
|
+
throw new BrowserFailureError(browserFailure("refused", `browser profile: ${ONE_SAVER}`));
|
|
61
|
+
if (Date.now() > end)
|
|
62
|
+
throw new BrowserFailureError(browserFailure("refused", `browser profile: ${STILL_ENDING}`));
|
|
63
|
+
signal?.throwIfAborted();
|
|
64
|
+
await sleep(100);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (held.settle && !(await within(held.settle(), end - Date.now())))
|
|
68
|
+
throw new BrowserFailureError(browserFailure("refused", `browser profile: ${STILL_ENDING}`));
|
|
69
|
+
if (savers.get(key) === held)
|
|
70
|
+
savers.delete(key);
|
|
71
|
+
signal?.throwIfAborted();
|
|
72
|
+
await sleep(0);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** pi-browser's provider over `computer`, a browser computer the claim or the plane opened. */
|
|
76
|
+
export function claimBrowserProvider(computer, options = {}) {
|
|
77
|
+
const features = computer.features;
|
|
78
|
+
const sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
79
|
+
const held = (id) => `${computer.provider}|${id}`;
|
|
80
|
+
const mine = heldBy.get(computer) ?? new Set();
|
|
81
|
+
heldBy.set(computer, mine);
|
|
82
|
+
const caps = {
|
|
83
|
+
profiles: features.profiles !== undefined && options.signIn !== undefined,
|
|
84
|
+
// What a session is created with that its record may say: Verified where the provider offers stealth; no proxy,
|
|
85
|
+
// place, region or context by id (serve's policy asks none).
|
|
86
|
+
settings: { proxies: false, verified: features.stealth === true, geolocation: false, region: false, context: false },
|
|
87
|
+
};
|
|
88
|
+
const status = async (ref, signal) => ((await statused(computer.running(ref.id, signal))) ? "running" : "gone");
|
|
89
|
+
const running = (ref) => async () => (await status(ref, AbortSignal.timeout(2_000))) === "running";
|
|
90
|
+
const settle = features.profiles?.settleMs ? () => sleep(features.profiles.settleMs) : undefined;
|
|
91
|
+
const holdSaver = (ref) => {
|
|
92
|
+
for (const one of savers.values())
|
|
93
|
+
if (one.tag === ref.tag)
|
|
94
|
+
Object.assign(one, { running: running(ref), ...(settle ? { settle } : {}) });
|
|
95
|
+
};
|
|
96
|
+
const endSocket = (id) => {
|
|
97
|
+
sockets.get(held(id))?.close();
|
|
98
|
+
sockets.delete(held(id));
|
|
99
|
+
mine.delete(held(id));
|
|
100
|
+
};
|
|
101
|
+
const provider = {
|
|
8
102
|
name: computer.provider,
|
|
9
|
-
caps
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
103
|
+
caps,
|
|
104
|
+
async create(spec, signal) {
|
|
105
|
+
signal?.throwIfAborted();
|
|
106
|
+
const profile = spec.profile;
|
|
107
|
+
if (profile && (!options.signIn || profile.name !== options.signIn.name || !features.profiles)) {
|
|
108
|
+
throw new BrowserFailureError(browserFailure("refused", `browser profile: this run has no saved sign-in named "${profile.name}" to open. No session was started.`));
|
|
109
|
+
}
|
|
110
|
+
const pointer = profile ? options.signIn.pointer : undefined;
|
|
111
|
+
if (profile?.save && pointer)
|
|
112
|
+
await claimSaver(`${computer.provider}|${pointer}`, spec.tag, `${spec.metadata.run}|${spec.metadata.label}`, signal, sleep);
|
|
113
|
+
const session = {
|
|
114
|
+
viewport: { width: spec.viewport.width, height: spec.viewport.height },
|
|
115
|
+
...(features.stealth && spec.verified ? { stealth: true } : {}),
|
|
116
|
+
...(features.headless && options.headless ? { headless: true } : {}),
|
|
117
|
+
...(pointer ? { profile: { pointer, save: profile.save } } : {}),
|
|
118
|
+
};
|
|
119
|
+
// The vendor ends a session at its lifetime from create (wall-clock) or after that long with no client
|
|
120
|
+
// (inactivity): custody's session timeout for the one, its idle release for the other (the session timeout where
|
|
121
|
+
// idle release is off, 0). Never below the vendor's shortest (Kernel's 10 s), which it would refuse.
|
|
122
|
+
const asked = features.timeout === "inactivity" && spec.idleTimeoutS > 0 ? spec.idleTimeoutS : spec.maxLifetimeS;
|
|
123
|
+
const lifetimeS = Math.max(asked, Math.ceil((features.minLifetimeMs ?? 0) / 1000));
|
|
124
|
+
let id;
|
|
125
|
+
try {
|
|
126
|
+
id = await computer.open(spec.tag, lifetimeS, session, signal);
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
// A refusal made nothing, so no session saves. Any other failure may have left its computer running (the provider
|
|
130
|
+
// looks it up by its create label and releases it, and may fail at that too): the claim stays, held by whether the
|
|
131
|
+
// tag still finds a computer, so the next saver replaces it only once none is left.
|
|
132
|
+
if (error?.code === "denied")
|
|
133
|
+
freeSaver(spec.tag);
|
|
134
|
+
else if (isSaver(spec.tag)) {
|
|
135
|
+
for (const one of savers.values()) {
|
|
136
|
+
if (one.tag === spec.tag)
|
|
137
|
+
Object.assign(one, { running: async () => (await computer.find(spec.tag, AbortSignal.timeout(2_000))).length > 0, ...(settle ? { settle } : {}) });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
throw withStatus(error);
|
|
141
|
+
}
|
|
142
|
+
const ref = { id, tag: spec.tag };
|
|
143
|
+
if (isSaver(spec.tag))
|
|
144
|
+
holdSaver(ref);
|
|
145
|
+
return ref;
|
|
146
|
+
},
|
|
147
|
+
async findByTag(tag, signal) {
|
|
148
|
+
const found = (await statused(computer.find(tag, signal))).map((id) => ({ id, tag }));
|
|
149
|
+
// No browser left under a saver's tag: one may have just ended (a create whose reply was lost, found and released
|
|
150
|
+
// by the provider), and the vendor may still be writing the profile back, so its settle time is waited out first.
|
|
151
|
+
if (found.length === 0) {
|
|
152
|
+
if (isSaver(tag) && settle)
|
|
153
|
+
await settle();
|
|
154
|
+
freeSaver(tag);
|
|
155
|
+
}
|
|
156
|
+
for (const ref of found)
|
|
157
|
+
if (isSaver(ref.tag))
|
|
158
|
+
holdSaver(ref);
|
|
159
|
+
return found;
|
|
160
|
+
},
|
|
161
|
+
status,
|
|
162
|
+
async attach(ref, signal) {
|
|
163
|
+
signal?.throwIfAborted();
|
|
164
|
+
const url = rewriteConnectUrl(await statused(computer.url(ref.id)), options.connectBaseUrl);
|
|
165
|
+
// A provider that keeps a session's downloads keeps only what the browser was told to save into its folder, and
|
|
166
|
+
// that lasts as long as the socket that told it: one per session, held until its release. A failure costs the
|
|
167
|
+
// files, not the session.
|
|
168
|
+
const downloads = features.downloads;
|
|
169
|
+
if (downloads && computer.downloads && !sockets.get(held(ref.id))?.open) {
|
|
170
|
+
let pending = opening.get(held(ref.id));
|
|
171
|
+
if (!pending) {
|
|
172
|
+
pending = (async () => {
|
|
173
|
+
const socket = await cdpCall(url, "Browser.setDownloadBehavior", { behavior: "allow", downloadPath: downloads.path, eventsEnabled: true }).catch(() => undefined);
|
|
174
|
+
if (socket) {
|
|
175
|
+
sockets.set(held(ref.id), socket);
|
|
176
|
+
mine.add(held(ref.id));
|
|
177
|
+
}
|
|
178
|
+
})().finally(() => opening.delete(held(ref.id)));
|
|
179
|
+
opening.set(held(ref.id), pending);
|
|
180
|
+
}
|
|
181
|
+
await pending;
|
|
182
|
+
}
|
|
183
|
+
return { sdkCdpUrl: url };
|
|
184
|
+
},
|
|
185
|
+
// The protocol's release takes no signal: a release is never cut short, so no session is left billing.
|
|
186
|
+
async release(ref) {
|
|
187
|
+
await opening.get(held(ref.id));
|
|
188
|
+
endSocket(ref.id);
|
|
189
|
+
try {
|
|
190
|
+
await computer.close(ref.id);
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
// Already gone is released.
|
|
194
|
+
if (!goneCode(error))
|
|
195
|
+
throw withStatus(error);
|
|
196
|
+
}
|
|
197
|
+
if (isSaver(ref.tag) && settle)
|
|
198
|
+
await settle();
|
|
199
|
+
freeSaver(ref.tag);
|
|
200
|
+
},
|
|
20
201
|
};
|
|
202
|
+
const kept = computer.downloads;
|
|
203
|
+
if (kept) {
|
|
204
|
+
provider.downloads = {
|
|
205
|
+
async list(ref) {
|
|
206
|
+
return (await statused(kept.list(ref.id))).map((file) => ({ name: file.name, sizeBytes: file.sizeBytes, modifiedAt: file.modifiedAt }));
|
|
207
|
+
},
|
|
208
|
+
read: (ref, name, maxBytes) => statused(kept.read(ref.id, name, maxBytes)),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
return provider;
|
|
212
|
+
}
|
|
213
|
+
/** The plane's vendor as a computer provider of the registry, made with the run's tool keys by the registry's names
|
|
214
|
+
* (computer-keys.ts providerOptions): the same provider an agent's browser computer is, on the keys the tool plane
|
|
215
|
+
* resolved it by. */
|
|
216
|
+
export async function planeComputer(vendor, env) {
|
|
217
|
+
const keys = Object.fromEntries((KEY_TABLE.keys[vendor] ?? []).flatMap((key) => (typeof env[key.name] === "string" && env[key.name] !== "" ? [[key.name, env[key.name]]] : [])));
|
|
218
|
+
const options = providerOptions(vendor, keys);
|
|
219
|
+
if (!options.ok)
|
|
220
|
+
throw new BrowserFailureError(browserFailure("browser_unavailable", `The browser does not run here: ${options.error.message}.`));
|
|
221
|
+
// The server's own variables the provider's descriptor says it reads (hostEnv: the gateway a server behind one reaches
|
|
222
|
+
// the vendor through), as the claim's providers get them (workspace/computer-deps.ts): the key checks and the sign-in
|
|
223
|
+
// creation already go through that gateway, so the browser's sessions do too.
|
|
224
|
+
const names = PROVIDERS.find((one) => one.id === vendor)?.hostEnv;
|
|
225
|
+
const hostEnv = names ? { env: Object.fromEntries(names.flatMap((name) => (env[name] === undefined ? [] : [[name, String(env[name])]]))) } : {};
|
|
226
|
+
return providerFor(vendor, { ...options.options, ...hostEnv });
|
|
227
|
+
}
|
|
228
|
+
/** The run's browser sessions of a lower claim epoch released, as a computer's are when a claim starts it (the janitor's
|
|
229
|
+
* releaseOlder): a runner that died after the vendor made a session and before its id was kept left one this claim's
|
|
230
|
+
* labels would never find. One that ended may have been saving to the run's sign-in, and this process holds no saver
|
|
231
|
+
* for it, so when any was ended the provider's settle time is waited out before the plane's browser opens a session. */
|
|
232
|
+
export async function releaseOlderBrowsers(provider, run, { signal, sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) } = {}) {
|
|
233
|
+
const older = await releaseOlder(provider, run.runId, run.epoch, signal ? { signal } : {});
|
|
234
|
+
if (!older.ok)
|
|
235
|
+
throw new BrowserFailureError(browserFailure("browser_unavailable", `The browser does not run here: ${older.error.message}.`));
|
|
236
|
+
const settleMs = provider.capabilities().browser?.profiles?.settleMs ?? 0;
|
|
237
|
+
if (settleMs > 0 && older.value.released.length + older.value.detached.length > 0)
|
|
238
|
+
await sleep(settleMs);
|
|
239
|
+
}
|
|
240
|
+
/** A Browserbase connect URL moved onto the credential proxy that fronts its sockets: only `*.browserbase.com` hosts, with
|
|
241
|
+
* the signing query kept. */
|
|
242
|
+
export function rewriteConnectUrl(connectUrl, connectBaseUrl) {
|
|
243
|
+
if (!connectBaseUrl)
|
|
244
|
+
return connectUrl;
|
|
245
|
+
try {
|
|
246
|
+
const target = new URL(connectBaseUrl);
|
|
247
|
+
const url = new URL(connectUrl);
|
|
248
|
+
if (!/(?:^|\.)browserbase\.com$/i.test(url.hostname))
|
|
249
|
+
return connectUrl;
|
|
250
|
+
url.protocol = target.protocol;
|
|
251
|
+
url.host = target.host;
|
|
252
|
+
url.pathname = target.pathname.replace(/\/$/, "") + url.pathname;
|
|
253
|
+
return url.toString();
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
return connectUrl;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/** A run's browser over `provider`, a browser computer provider (the plane's vendor, or a test's stand-in), as the claim
|
|
260
|
+
* opens an agent's browser computer: each session made under the run's labels (`run`, when the run holds a claim, so a
|
|
261
|
+
* sweep finds what it left), for at most the provider's longest lifetime. A provider of another kind is refused. */
|
|
262
|
+
export function planeBrowser(provider, run) {
|
|
263
|
+
if (!isBrowserProvider(provider))
|
|
264
|
+
throw new BrowserFailureError(browserFailure("browser_unavailable", `The browser does not run here: the ${provider.id} provider gives no browser.`));
|
|
265
|
+
const spec = { image: BROWSER_IMAGE, lifetimeMs: provider.capabilities().maxLifetimeMs, network: "open", labels: run ? runLabels(run.runId, run.epoch) : {} };
|
|
266
|
+
return claimBrowser(provider, spec).browser;
|
|
267
|
+
}
|
|
268
|
+
/** When the run's process lets the run go: closes the download sockets its browser's sessions hold, released or not (a
|
|
269
|
+
* runner that closes leaves a session to the next claim, whose attach opens its own). An open socket would keep the
|
|
270
|
+
* process from exiting. A socket still opening is closed once it opens. */
|
|
271
|
+
export async function closeHeldSockets(computer) {
|
|
272
|
+
const mine = heldBy.get(computer);
|
|
273
|
+
if (!mine)
|
|
274
|
+
return;
|
|
275
|
+
await Promise.all([...opening.keys()].filter((key) => key.startsWith(`${computer.provider}|`)).map((key) => opening.get(key)));
|
|
276
|
+
for (const key of mine) {
|
|
277
|
+
sockets.get(key)?.close();
|
|
278
|
+
sockets.delete(key);
|
|
279
|
+
}
|
|
280
|
+
mine.clear();
|
|
281
|
+
}
|
|
282
|
+
/** Tests only: forgets every session's socket and saver this process holds. */
|
|
283
|
+
export function resetBrowserComputerHoldings() {
|
|
284
|
+
for (const socket of sockets.values())
|
|
285
|
+
socket.close();
|
|
286
|
+
sockets.clear();
|
|
287
|
+
opening.clear();
|
|
288
|
+
savers.clear();
|
|
21
289
|
}
|
package/dist/browser-cost.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ import { type PaidBooking } from "./paid-calls.js";
|
|
|
11
11
|
* leaves a session billed that no record in the store names. */
|
|
12
12
|
export declare 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
|
|
15
|
-
*
|
|
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). */
|
|
16
16
|
export declare const BROWSER_PRICES: Readonly<Record<string, {
|
|
17
17
|
usdPerHour: number;
|
|
18
18
|
minimumS: number;
|
package/dist/browser-cost.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
2
|
+
import { PROVIDERS } from "@parcha/agentrun-computer";
|
|
2
3
|
import { TOOL_COST } from "./timeline/index.js";
|
|
3
4
|
import { addSpend, BROWSER_CHARGED, keepHold, paidCall, runCap, SPEND_CAP_REACHED } from "./cap.js";
|
|
4
5
|
import { paidStep } from "./paid-calls.js";
|
|
@@ -10,14 +11,15 @@ import { forModel } from "./result.js";
|
|
|
10
11
|
* leaves a session billed that no record in the store names. */
|
|
11
12
|
export 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
|
-
*
|
|
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
|
-
local: { usdPerHour: 0, minimumS: 0 },
|
|
20
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;
|
|
21
23
|
/** An operator's price for a provider, in USD an hour: this prefix and the provider's name in capitals
|
|
22
24
|
* (AGENTRUN_BROWSER_USD_PER_HOUR_BROWSERBASE, _KERNEL, _CDP). */
|
|
23
25
|
export const BROWSER_PRICE_ENV = "AGENTRUN_BROWSER_USD_PER_HOUR_";
|
|
@@ -30,7 +32,7 @@ export const priceEnvOf = (provider) => `${BROWSER_PRICE_ENV}${provider.toUpperC
|
|
|
30
32
|
/** `provider`'s session price: the operator's (a non-negative decimal), else the list's; `usdPerHour` null when neither
|
|
31
33
|
* names one or the operator's cannot be read, which is no price, never $0. */
|
|
32
34
|
export function browserPrice(provider, env) {
|
|
33
|
-
const listed = Object.hasOwn(BROWSER_PRICES, provider) ? BROWSER_PRICES[provider] :
|
|
35
|
+
const listed = Object.hasOwn(BROWSER_PRICES, provider) ? BROWSER_PRICES[provider] : unmeteredPrice(provider);
|
|
34
36
|
const text = env[priceEnvOf(provider)]?.trim();
|
|
35
37
|
const given = text ? (/^(\d+(\.\d*)?|\.\d+)$/.test(text) ? Number(text) : NaN) : undefined;
|
|
36
38
|
return { usdPerHour: given === undefined ? (listed?.usdPerHour ?? null) : Number.isFinite(given) ? given : null, minimumS: listed?.minimumS ?? 0 };
|
package/dist/browser-person.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
/** How long a person's time lasts at most before it expires: an unanswered ask,
|
|
1
|
+
/** 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
|
|
2
|
+
* waits for its person's answer with its browser kept open. Its worth of session time is held up front. The default of
|
|
3
|
+
* the server setting PERSON_WAIT_ENV. */
|
|
2
4
|
export declare const PERSON_HOLD_MS: number;
|
|
5
|
+
/** The server setting for that window, in whole minutes (1 to 360; anything else keeps the 15-minute default): how long a
|
|
6
|
+
* run waiting for its person keeps its browser open, how long an agent's hand-over ask waits, and how long a take-over
|
|
7
|
+
* lasts with no input. One setting for all three, so they never drift apart. */
|
|
8
|
+
export declare const PERSON_WAIT_ENV = "AGENTRUN_BROWSER_PERSON_WAIT_MIN";
|
|
3
9
|
/** How long a take-over outlasts its viewer. */
|
|
4
10
|
export declare const PERSON_AWAY_MS: number;
|
|
5
11
|
/** Under `--faux` only (the tests, beside the fake browser's own FAUX_BROWSER_LOG): the two windows above, in ms, `<hold>,<away>`. */
|
|
@@ -49,6 +55,9 @@ export declare function personHands(options: {
|
|
|
49
55
|
drop(): void;
|
|
50
56
|
}>;
|
|
51
57
|
note: Note;
|
|
58
|
+
/** A wait on the person's answer ended with its browser let go (its window, the cap, its session gone): when (ms) and
|
|
59
|
+
* the timeline row's words, for the Screen tab's ended state (browser-wait-ended.ts). Never throws out. */
|
|
60
|
+
waitEnded?(at: number, why: string): void;
|
|
52
61
|
holdMs?: number;
|
|
53
62
|
pollMs?: number;
|
|
54
63
|
/** For tests: the timer functions the person's time is held again by. */
|
|
@@ -112,11 +121,13 @@ export declare function personHands(options: {
|
|
|
112
121
|
* and its release lets the browser go, booking its time to then. `pauses: false`: a refusal pauses nothing, the run
|
|
113
122
|
* parks on its question as it would with no browser. Refused in the cap's words when there is no room. `lapsed`
|
|
114
123
|
* settles, in words, at the bound, when the cap refuses a re-hold (a take-over's sharing the session), or when a
|
|
115
|
-
* session it keeps is let go (sessionEnded);
|
|
124
|
+
* session it keeps is let go (sessionEnded); confirmed() writes that lapse's row and ended state once the runner
|
|
125
|
+
* parked the run on it; drop() lets the shares go, once. */
|
|
116
126
|
wait(callId: string, tags: readonly string[], since?: number): Promise<{
|
|
117
127
|
refused: string;
|
|
118
128
|
} | {
|
|
119
129
|
lapsed: Promise<string>;
|
|
130
|
+
confirmed(): void;
|
|
120
131
|
drop(): void;
|
|
121
132
|
}>;
|
|
122
133
|
/** Session `tag` was let go (its release, whatever made it): a wait that kept it open for the person lapses. */
|
|
@@ -130,4 +141,10 @@ export declare function personWindows(env: NodeJS.ProcessEnv, faux: boolean): {
|
|
|
130
141
|
holdMs: number;
|
|
131
142
|
awayMs: number;
|
|
132
143
|
};
|
|
144
|
+
/** The person's window from the server setting PERSON_WAIT_ENV, in ms: whole minutes from 1 to 360, else the default. */
|
|
145
|
+
export declare function personWaitMs(env: NodeJS.ProcessEnv): number;
|
|
146
|
+
/** The timeline row when a run's wait for its person ends at its window and its browser is let go. */
|
|
147
|
+
export declare const releasedAfterWait: (holdMs: number) => string;
|
|
148
|
+
/** The timeline row when a browser the run kept open for its person ended before their answer (its provider ended it). */
|
|
149
|
+
export declare const BROWSER_GONE_WHILE_WAITING = "The browser session ended while the run waited for you";
|
|
133
150
|
export {};
|