@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type DockerVolume } from "@parcha/agentrun-computer";
|
|
1
|
+
import { type ComputerSpec, type DockerVolume } from "@parcha/agentrun-computer";
|
|
2
2
|
import type { DockerPaths } from "../box-paths.js";
|
|
3
3
|
import { type HostRead } from "../docker-host-addresses.js";
|
|
4
4
|
import type { ProviderFactories } from "../computer-keys.js";
|
|
@@ -7,10 +7,22 @@ import { type KeyEnv } from "../key-meta.js";
|
|
|
7
7
|
import type { Store } from "../store/index.js";
|
|
8
8
|
import { type ClaimComputer, type ClaimLaunch, computerForClaim, type ComputerForClaimDeps, type OpenComputerView } from "./computer-for-claim.js";
|
|
9
9
|
import { type ProviderLoad } from "./computer-providers.js";
|
|
10
|
-
import type
|
|
10
|
+
import { type KindRegistry } from "./resolve-computer.js";
|
|
11
11
|
/** How long a run's computer lives whatever happens to the server: a bound on a leaked one, never its clean end (the old
|
|
12
12
|
* box's lifetime). The clean end is the run's release. */
|
|
13
13
|
export declare const COMPUTER_LIFETIME_MS: number;
|
|
14
|
+
/** The settings that size a Docker computer (a sandbox or a desktop): its CPUs, its memory (swap included) and how many
|
|
15
|
+
* processes and threads it may hold at once. Unset, the Docker provider's own defaults hold. A vendor's computer sizes
|
|
16
|
+
* itself and is never given them. */
|
|
17
|
+
export declare const BOX_CPUS_ENV = "AGENTRUN_BOX_CPUS";
|
|
18
|
+
export declare const BOX_MEMORY_ENV = "AGENTRUN_BOX_MEMORY";
|
|
19
|
+
export declare const BOX_PIDS_ENV = "AGENTRUN_BOX_PIDS";
|
|
20
|
+
/** A Docker computer's size, as the Docker provider takes it on its spec. */
|
|
21
|
+
export type DockerLimits = Pick<ComputerSpec, "cpus" | "memoryMb" | "pids">;
|
|
22
|
+
/** A Docker computer's size from `env`'s AGENTRUN_BOX_CPUS, _MEMORY and _PIDS: each one set, as its spec field; none set,
|
|
23
|
+
* none, so the provider's defaults hold. A value the Docker provider would refuse at every create throws, in its own
|
|
24
|
+
* words, naming the setting and what it takes: the server's start reads them (startServe), so no run meets one. */
|
|
25
|
+
export declare function dockerLimitsOf(env: KeyEnv): DockerLimits;
|
|
14
26
|
/** The Docker host's own addresses, for a Docker provider whose interfaces aren't that host's (the server in a
|
|
15
27
|
* container): a comma list of IP addresses. The Docker provider's egress proxy refuses them as the host's, so a
|
|
16
28
|
* computer's allow-list never reaches the host itself; without them it refuses any allow-list there. */
|
|
@@ -53,19 +65,24 @@ export interface ComputerDepsOptions {
|
|
|
53
65
|
readonly hostAddresses?: () => Promise<HostRead>;
|
|
54
66
|
/** Whether a provider that binds a folder of this machine answers here now (Docker), for the Mode 1 default. */
|
|
55
67
|
readonly answers?: ComputerForClaimDeps["answers"];
|
|
68
|
+
/** This machine's Docker daemon, asked when a Docker launch fails (docker-daemon.ts dockerDaemonCheck over `env`
|
|
69
|
+
* unless given; none under --faux, whose launch is its own). */
|
|
70
|
+
readonly daemon?: ComputerForClaimDeps["daemon"];
|
|
56
71
|
/** The live view's registration for a desktop or a phone (proxy-only): absent, no view is opened. */
|
|
57
72
|
readonly openComputerView?: OpenComputerView;
|
|
58
73
|
/** --faux's computers (faux-computers.ts), in place of the computer package's: their kind registry, key table, launch
|
|
59
74
|
* and factories. */
|
|
60
75
|
readonly faux?: FauxComputers;
|
|
61
76
|
}
|
|
62
|
-
/** The spec a computer of `kind` on `entry` is made with, besides its labels and its mount: its image (
|
|
63
|
-
* owner's AGENTRUN_DOCKER_IMAGE when set, else for a sandbox
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
77
|
+
/** The spec a computer of `kind` on `entry` is made with, besides its labels and its mount: its image (a provider that
|
|
78
|
+
* prepares its own image, its descriptor's prepareImage: the owner's AGENTRUN_DOCKER_IMAGE when set, else for a sandbox
|
|
79
|
+
* the package's recipe, which its prepareImage() builds; any other provider's: its descriptor's defaultImage for the
|
|
80
|
+
* kind, the computer package's PROVIDERS[].defaultImage; a kind with none refused in words, a prepared desktop's saying
|
|
81
|
+
* it needs an image with an X server, which the recipe lacks), the leak bound for its lifetime (its clean end is the
|
|
82
|
+
* run's release), and its network (networkOf): the run's box_allow, or this server's own (AGENTRUN_BOX_ALLOW, read
|
|
83
|
+
* from `env`) for a launch that names none; and the size of a computer on this machine's container engine (its
|
|
84
|
+
* descriptor's `local`), AGENTRUN_BOX_CPUS, _MEMORY and _PIDS (dockerLimitsOf, read once here): a vendor's computer
|
|
85
|
+
* sizes itself. No key and no environment. */
|
|
69
86
|
export declare function computerSpecOf(env: KeyEnv): ComputerForClaimDeps["spec"];
|
|
70
87
|
/** The run's timeline phase while its claim waits on its computer's image (computerForClaim's onImageWait): main's box
|
|
71
88
|
* image row, the computer's noun for the box's. */
|
|
@@ -17,18 +17,70 @@
|
|
|
17
17
|
import { isIP } from "node:net";
|
|
18
18
|
import { posix } from "node:path";
|
|
19
19
|
import { DEFAULT_DOCKER_IMAGE, DOCKER_RECIPE, DOCKER_RECIPE_HAS, PROVIDERS, providerFor, readBackOf, servingRefusals, SETTING_KINDS } from "@parcha/agentrun-computer";
|
|
20
|
+
// The local container engine's provider, for its check() of the operator's size settings at the start (dockerLimitsOf).
|
|
21
|
+
import { DockerProvider } from "@parcha/agentrun-computer/docker";
|
|
20
22
|
import { DOCKER_IMAGE_ENV } from "../box-image.js";
|
|
23
|
+
import { dockerDaemonCheck } from "../docker-daemon.js";
|
|
21
24
|
import { unionOf } from "../docker-host-addresses.js";
|
|
22
25
|
import { envValue, keyReader } from "../key-meta.js";
|
|
26
|
+
import { boxAllowOf, boxAllowSetIn } from "../box-settings.js";
|
|
23
27
|
import { readLaunchBody } from "../run-launch.js";
|
|
24
28
|
import { computerForClaim } from "./computer-for-claim.js";
|
|
25
29
|
import { storeLedger } from "./computer-ledger.js";
|
|
26
30
|
import { computerProviderFactories, computerProviderMakers } from "./computer-providers.js";
|
|
31
|
+
import { needsNetwork, noNetworkRefusal, vendorNetworkOnly } from "./resolve-computer.js";
|
|
27
32
|
/** How long a run's computer lives whatever happens to the server: a bound on a leaked one, never its clean end (the old
|
|
28
33
|
* box's lifetime). The clean end is the run's release. */
|
|
29
34
|
export const COMPUTER_LIFETIME_MS = 24 * 60 * 60_000;
|
|
30
35
|
/** A computer this server cannot make here, with the code the run fails with and its words. */
|
|
31
36
|
const refused = (words) => Object.assign(new Error(words), { code: "computer_unavailable" });
|
|
37
|
+
/** The settings that size a Docker computer (a sandbox or a desktop): its CPUs, its memory (swap included) and how many
|
|
38
|
+
* processes and threads it may hold at once. Unset, the Docker provider's own defaults hold. A vendor's computer sizes
|
|
39
|
+
* itself and is never given them. */
|
|
40
|
+
export const BOX_CPUS_ENV = "AGENTRUN_BOX_CPUS";
|
|
41
|
+
export const BOX_MEMORY_ENV = "AGENTRUN_BOX_MEMORY";
|
|
42
|
+
export const BOX_PIDS_ENV = "AGENTRUN_BOX_PIDS";
|
|
43
|
+
/** Each setting's spec field and what it takes, in an operator's words. */
|
|
44
|
+
const LIMIT_SETTINGS = [
|
|
45
|
+
{ name: BOX_CPUS_ENV, field: "cpus", form: "a number of CPUs, such as 2 or 1.5" },
|
|
46
|
+
{ name: BOX_MEMORY_ENV, field: "memoryMb", form: "a size with its unit (b, k, m or g), such as 512m or 4g" },
|
|
47
|
+
{ name: BOX_PIDS_ENV, field: "pids", form: "a whole number of processes and threads, such as 1024" },
|
|
48
|
+
];
|
|
49
|
+
/** A size's units as Docker reads them, each 1024 of the one before, in MiB. */
|
|
50
|
+
const SIZE_MIB = { b: 1 / (1024 * 1024), k: 1 / 1024, m: 1, g: 1024 };
|
|
51
|
+
/** One setting's value as its spec field: a number where it reads as one, else NaN, which the provider's check refuses. */
|
|
52
|
+
const LIMIT_VALUE = {
|
|
53
|
+
cpus: (value) => (/^\d+(\.\d+)?$/.test(value) ? Number(value) : Number.NaN),
|
|
54
|
+
// Its MiB, the fraction dropped, as Docker reads a size: 0.5g is 512, 6.5m is 6.
|
|
55
|
+
memoryMb: (value) => {
|
|
56
|
+
const size = /^(\d+(?:\.\d+)?)([bkmg])$/i.exec(value);
|
|
57
|
+
return size ? Math.floor(Number(size[1]) * SIZE_MIB[size[2].toLowerCase()]) : Number.NaN;
|
|
58
|
+
},
|
|
59
|
+
pids: (value) => (/^\d+$/.test(value) ? Number(value) : Number.NaN),
|
|
60
|
+
};
|
|
61
|
+
/** Asked only check(): its constructor runs nothing and reads no Docker, and check() reads only the spec. */
|
|
62
|
+
let checker;
|
|
63
|
+
/** A Docker computer's size from `env`'s AGENTRUN_BOX_CPUS, _MEMORY and _PIDS: each one set, as its spec field; none set,
|
|
64
|
+
* none, so the provider's defaults hold. A value the Docker provider would refuse at every create throws, in its own
|
|
65
|
+
* words, naming the setting and what it takes: the server's start reads them (startServe), so no run meets one. */
|
|
66
|
+
export function dockerLimitsOf(env) {
|
|
67
|
+
const limits = {};
|
|
68
|
+
for (const { name, field } of LIMIT_SETTINGS) {
|
|
69
|
+
const value = envValue(env, name)?.trim();
|
|
70
|
+
if (value !== undefined)
|
|
71
|
+
limits[field] = LIMIT_VALUE[field](value);
|
|
72
|
+
}
|
|
73
|
+
if (Object.keys(limits).length === 0)
|
|
74
|
+
return {};
|
|
75
|
+
checker ??= new DockerProvider({ daemonPath: "computerd" });
|
|
76
|
+
const refusals = checker.check({ image: DEFAULT_DOCKER_IMAGE, lifetimeMs: COMPUTER_LIFETIME_MS, network: "none", ...limits });
|
|
77
|
+
for (const { name, field, form } of LIMIT_SETTINGS) {
|
|
78
|
+
const refusal = refusals.find((one) => one.field === field);
|
|
79
|
+
if (refusal)
|
|
80
|
+
throw new Error(`${name} ${JSON.stringify(envValue(env, name).trim())} is refused by the Docker provider: ${refusal.message} (${name} is ${form})`);
|
|
81
|
+
}
|
|
82
|
+
return limits;
|
|
83
|
+
}
|
|
32
84
|
/** The Docker host's own addresses, for a Docker provider whose interfaces aren't that host's (the server in a
|
|
33
85
|
* container): a comma list of IP addresses. The Docker provider's egress proxy refuses them as the host's, so a
|
|
34
86
|
* computer's allow-list never reaches the host itself; without them it refuses any allow-list there. */
|
|
@@ -54,46 +106,69 @@ export function dockerVolumeOf(paths) {
|
|
|
54
106
|
const root = paths.paths.at;
|
|
55
107
|
return { volume: { name: paths.paths.volume, root }, daemonCache: posix.join(root, DAEMON_CACHE_IN_VOLUME) };
|
|
56
108
|
}
|
|
57
|
-
/** The spec a computer of `kind` on `entry` is made with, besides its labels and its mount: its image (
|
|
58
|
-
* owner's AGENTRUN_DOCKER_IMAGE when set, else for a sandbox
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
109
|
+
/** The spec a computer of `kind` on `entry` is made with, besides its labels and its mount: its image (a provider that
|
|
110
|
+
* prepares its own image, its descriptor's prepareImage: the owner's AGENTRUN_DOCKER_IMAGE when set, else for a sandbox
|
|
111
|
+
* the package's recipe, which its prepareImage() builds; any other provider's: its descriptor's defaultImage for the
|
|
112
|
+
* kind, the computer package's PROVIDERS[].defaultImage; a kind with none refused in words, a prepared desktop's saying
|
|
113
|
+
* it needs an image with an X server, which the recipe lacks), the leak bound for its lifetime (its clean end is the
|
|
114
|
+
* run's release), and its network (networkOf): the run's box_allow, or this server's own (AGENTRUN_BOX_ALLOW, read
|
|
115
|
+
* from `env`) for a launch that names none; and the size of a computer on this machine's container engine (its
|
|
116
|
+
* descriptor's `local`), AGENTRUN_BOX_CPUS, _MEMORY and _PIDS (dockerLimitsOf, read once here): a vendor's computer
|
|
117
|
+
* sizes itself. No key and no environment. */
|
|
64
118
|
export function computerSpecOf(env) {
|
|
65
119
|
const named = envValue(env, DOCKER_IMAGE_ENV);
|
|
120
|
+
// This server's allow setting, as a launch is stamped with it (box-settings.ts boxAllowOf; its start checks the setting).
|
|
121
|
+
const current = () => boxAllowOf(env);
|
|
122
|
+
const currentSet = () => boxAllowSetIn(env);
|
|
66
123
|
const imageOf = (entry, kind) => {
|
|
67
|
-
if (entry.
|
|
124
|
+
if (entry.prepareImage && named !== undefined)
|
|
68
125
|
return named;
|
|
69
|
-
//
|
|
70
|
-
|
|
126
|
+
// A sandbox whose provider prepares its image: the package's own recipe, which its prepareImage() builds (the
|
|
127
|
+
// descriptor gives it no default).
|
|
128
|
+
if (entry.prepareImage && kind === "sandbox")
|
|
71
129
|
return DEFAULT_DOCKER_IMAGE;
|
|
72
130
|
const image = entry.defaultImage?.[kind];
|
|
73
131
|
if (image !== undefined)
|
|
74
132
|
return image;
|
|
75
|
-
if (entry.
|
|
76
|
-
throw refused(
|
|
133
|
+
if (entry.prepareImage && kind === "desktop")
|
|
134
|
+
throw refused(`A ${entry.label} desktop needs an image with an X server; set one for desktops.`);
|
|
77
135
|
throw refused(`${entry.label} has no image for a ${kind} computer here: pick another provider for this agent's computer in Settings → Computers.`);
|
|
78
136
|
};
|
|
79
|
-
|
|
80
|
-
|
|
137
|
+
const limits = dockerLimitsOf(env);
|
|
138
|
+
return (entry, kind, run, image) => ({
|
|
139
|
+
// The setting's configuration's image (Orgo's `windows`), else the kind's.
|
|
140
|
+
image: image ?? imageOf(entry, kind),
|
|
81
141
|
// The leak bound, within the longest the provider makes (E2B's is an hour): a longer one it refuses at create.
|
|
82
142
|
lifetimeMs: Math.min(COMPUTER_LIFETIME_MS, run.maxLifetimeMs ?? COMPUTER_LIFETIME_MS),
|
|
83
|
-
network: networkOf(kind, run),
|
|
143
|
+
network: networkOf(entry, kind, run, current, currentSet),
|
|
144
|
+
// The size of a computer on this machine's container engine, the operator's (dockerLimitsOf); a vendor's sizes itself.
|
|
145
|
+
...(entry.local ? limits : {}),
|
|
84
146
|
});
|
|
85
147
|
}
|
|
86
|
-
/** The network a computer of `kind` asks for:
|
|
87
|
-
* "none" but not what the run allows. A
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
|
|
93
|
-
|
|
148
|
+
/** The network a computer of `kind` on `entry` asks for: what the run allows (its box_allow), narrowed to "none" when its
|
|
149
|
+
* provider makes "none" but not what the run allows. A launch that names no box_allow (a row from before every launch
|
|
150
|
+
* was stamped with it) allows what this server allows now (`current`), never "open"; a sandbox with none still has no
|
|
151
|
+
* network, as it always had. A remote computer (Daytona's or E2B's, each one whose capabilities' network is ["none"])
|
|
152
|
+
* runs its programs in a network of their own, so an open or listed network is one it refuses at create; "none" reaches
|
|
153
|
+
* less than the run allows, never more. Under "none", the operator's word for no network at all, a computer whose
|
|
154
|
+
* provider makes no "none" (a cloud phone, a hosted browser, Local Chrome) is refused in words (noNetworkRefusal), as
|
|
155
|
+
* the run's start refuses it (resolve-computer.ts computerReadiness). A vendor-hosted computer that runs only on the
|
|
156
|
+
* vendor's own network (its capabilities' network is ["open"]) is "open" under a list, the default or the operator's,
|
|
157
|
+
* since this server's list can't reach it, and Settings says so (computers.ts networkWords). A browser whose provider
|
|
158
|
+
* makes both "open" and "allow" (Local Chrome, behind its own egress proxy) is held to the operator's list
|
|
159
|
+
* (`boxAllowSet`, the launch's, or this server's now for a launch that names no box_allow) and is "open" under the
|
|
160
|
+
* default list, which is a sandbox's package-install list and no browsing policy. */
|
|
161
|
+
function networkOf(entry, kind, run, current, currentSet) {
|
|
162
|
+
const boxAllow = run.boxAllow ?? (kind === "sandbox" ? "none" : current());
|
|
163
|
+
const set = run.boxAllow !== undefined ? run.boxAllowSet === true : currentSet();
|
|
164
|
+
if (boxAllow === "none" && needsNetwork(run.networks))
|
|
165
|
+
throw refused(noNetworkRefusal(entry.label, kind));
|
|
166
|
+
if (vendorNetworkOnly(run.networks))
|
|
94
167
|
return "open";
|
|
95
|
-
|
|
96
|
-
|
|
168
|
+
if (kind === "browser" && boxAllow !== "none" && run.networks?.includes("open") && run.networks.includes("allow"))
|
|
169
|
+
return set ? { allow: [...boxAllow] } : "open";
|
|
170
|
+
const allowed = boxAllow === "none" ? "none" : { allow: [...boxAllow] };
|
|
171
|
+
const form = allowed === "none" ? "none" : "allow";
|
|
97
172
|
return run.networks && !run.networks.includes(form) && run.networks.includes("none") ? "none" : allowed;
|
|
98
173
|
}
|
|
99
174
|
/** The run's timeline phase while its claim waits on its computer's image (computerForClaim's onImageWait): main's box
|
|
@@ -104,8 +179,9 @@ export const imageWaitWords = (making, image) => making === "build" ? `Preparing
|
|
|
104
179
|
export const claimComputer = async (launch, store, deps) => {
|
|
105
180
|
if (launch.boxAllow !== undefined || !store.runs)
|
|
106
181
|
return computerForClaim(launch, store, deps);
|
|
107
|
-
const
|
|
108
|
-
|
|
182
|
+
const body = readLaunchBody((await store.runs.launch(launch.runId)).body);
|
|
183
|
+
const boxAllow = body?.boxAllow;
|
|
184
|
+
return computerForClaim(boxAllow === undefined ? launch : { ...launch, boxAllow, ...(body?.boxAllowSet ? { boxAllowSet: true } : {}) }, store, deps);
|
|
109
185
|
};
|
|
110
186
|
/** The kind registry a claim composed with `options` resolves a setting against: --faux's when it is given faux, else a
|
|
111
187
|
* test's own, else the computer package's. The one choice: computerDepsFrom makes it, and the server's start check
|
|
@@ -114,36 +190,60 @@ export function claimKinds(options) {
|
|
|
114
190
|
// The faux registry is Settings' shape (computers.ts); the claim reads the same data as resolve-computer.ts's.
|
|
115
191
|
return options.faux?.kinds ?? options.kinds ?? { SETTING_KINDS, PROVIDERS, servingRefusals };
|
|
116
192
|
}
|
|
193
|
+
/** This machine's Docker daemon as the claim asks it once a Docker launch fails: one check per process (its answer
|
|
194
|
+
* kept a while, docker-daemon.ts), in `env`. */
|
|
195
|
+
const dockerDaemonOf = (env) => {
|
|
196
|
+
const check = dockerDaemonCheck({ env: { ...env } });
|
|
197
|
+
return () => check();
|
|
198
|
+
};
|
|
117
199
|
/** computerForClaim and its process-wide deps, composed once; and Settings → Computers' factories from the same makers. */
|
|
118
200
|
export function computerDepsFrom(options) {
|
|
119
201
|
const { env, store, sealKey, faux } = options;
|
|
120
202
|
const kinds = claimKinds(options);
|
|
121
|
-
//
|
|
122
|
-
// when
|
|
123
|
-
// recipe's bare tag, which no registry has.
|
|
203
|
+
// A provider that prepares its own image (its descriptor's prepareImage) is given that image's source, which its
|
|
204
|
+
// prepareImage() makes ready (built from the recipe when the engine lacks it, or pulled by name): the owner's
|
|
205
|
+
// AGENTRUN_DOCKER_IMAGE, else the package's recipe. Never the recipe's bare tag, which no registry has.
|
|
124
206
|
const named = envValue(env, DOCKER_IMAGE_ENV);
|
|
125
|
-
const
|
|
207
|
+
const preparedImage = named !== undefined ? { image: named } : { recipe: DOCKER_RECIPE };
|
|
126
208
|
// The operator's Docker host addresses (AGENTRUN_DOCKER_HOST_ADDRESSES), checked once here.
|
|
127
209
|
const namedAddresses = dockerHostAddressesOf(env);
|
|
128
210
|
// Where this process's Docker has the data, read once, when a Docker provider is first built.
|
|
129
211
|
let paths;
|
|
130
|
-
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* allow-list where it isn't on the
|
|
135
|
-
* has an allow-list (`boxAllow`, the claim's own
|
|
136
|
-
*
|
|
137
|
-
* The read itself is once per process
|
|
138
|
-
|
|
212
|
+
/** A local provider's host options (its descriptor's `local`: its computers run on this machine's container engine):
|
|
213
|
+
* for a server in a container of that engine's, the named volume that holds its data and the daemon copy's place
|
|
214
|
+
* under it (dockerVolumeOf), and the host's own addresses for its egress proxy, the union of the read through the
|
|
215
|
+
* socket (`hostAddresses`) and the operator's; on a host, the operator's alone (the provider reads its own
|
|
216
|
+
* interfaces). With none, none are given, and the provider refuses an allow-list where it isn't on the host, in its
|
|
217
|
+
* words. The read is made only for a claim whose run's computer has an allow-list (`boxAllow`, the claim's own
|
|
218
|
+
* launch's box_allow, a list): a run launched under a list keeps it across a restart, whatever this process's
|
|
219
|
+
* AGENTRUN_BOX_ALLOW says now; one with none, or no claim, reads nothing. The read itself is once per process
|
|
220
|
+
* (`hostAddresses`). */
|
|
221
|
+
const localHostOptions = async (boxAllow) => {
|
|
139
222
|
const where = options.dockerPaths ? await (paths ??= options.dockerPaths()) : { here: true };
|
|
140
223
|
const volume = dockerVolumeOf(where);
|
|
141
|
-
|
|
224
|
+
// A launch that names no box_allow (a row from before every launch was stamped) allows what this server allows now,
|
|
225
|
+
// as its computer's network does (networkOf), so the provider's options follow the same setting.
|
|
226
|
+
const allow = boxAllow ?? boxAllowOf(env);
|
|
227
|
+
const read = volume && Array.isArray(allow) && options.hostAddresses ? await options.hostAddresses() : undefined;
|
|
142
228
|
const addresses = read ? unionOf(read, namedAddresses).addresses : (namedAddresses ?? []);
|
|
143
|
-
return {
|
|
229
|
+
return { ...(volume ?? {}), ...(addresses.length > 0 ? { egress: { hostAddresses: addresses } } : {}) };
|
|
230
|
+
};
|
|
231
|
+
/** The server's own values of the environment variables a provider declares it reads on this machine (hostEnv: Local
|
|
232
|
+
* Chrome's, where it finds Chrome), and no other variable of the server's. */
|
|
233
|
+
const hostEnvOf = (names) => Object.fromEntries(names.flatMap((name) => (env[name] === undefined ? [] : [[name, String(env[name])]])));
|
|
234
|
+
/** The options a provider takes beside its keys, by what its descriptor declares, never by its id: the image source
|
|
235
|
+
* for one that prepares its image, the host options for a local one, the host environment it reads. */
|
|
236
|
+
const declaredOptions = async (id, boxAllow) => {
|
|
237
|
+
const entry = kinds.PROVIDERS.find((one) => one.id === id);
|
|
238
|
+
return {
|
|
239
|
+
...(entry?.prepareImage ? { image: preparedImage } : {}),
|
|
240
|
+
...(entry?.local ? await localHostOptions(boxAllow) : {}),
|
|
241
|
+
...(entry?.hostEnv ? { env: hostEnvOf(entry.hostEnv) } : {}),
|
|
242
|
+
};
|
|
144
243
|
};
|
|
145
244
|
const load = options.load ?? providerFor;
|
|
146
|
-
|
|
245
|
+
// The claim and Settings → Computers' test alike.
|
|
246
|
+
const providers = computerProviderMakers({ load: async (id, given, claim) => load(id, { ...given, ...(await declaredOptions(id, claim?.boxAllow)) }) });
|
|
147
247
|
const computerDeps = {
|
|
148
248
|
kinds,
|
|
149
249
|
providers,
|
|
@@ -153,6 +253,7 @@ export function computerDepsFrom(options) {
|
|
|
153
253
|
// Under --faux, its launch makes the computer, with its key table: no provider of the package is built.
|
|
154
254
|
...(faux ? { keyTable: faux.keyTable, launch: (entry, spec) => faux.launch(entry, spec) } : {}),
|
|
155
255
|
...(options.answers ? { answers: options.answers } : {}),
|
|
256
|
+
...(options.daemon ? { daemon: options.daemon } : faux ? {} : { daemon: dockerDaemonOf(env) }),
|
|
156
257
|
...(options.openComputerView ? { openComputerView: options.openComputerView } : {}),
|
|
157
258
|
};
|
|
158
259
|
const factories = faux?.factories ?? computerProviderFactories(providers, (id) => storeLedger(store.computerLedger, id));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ComputerProvider, ComputerSpec
|
|
1
|
+
import type { ComputerProvider, ComputerSpec } from "@parcha/agentrun-computer";
|
|
2
2
|
import { type PlaceView } from "../computer-setting.js";
|
|
3
3
|
import { type KeyTable, type ProviderSettings } from "../computer-keys.js";
|
|
4
4
|
import type { Store } from "../store/index.js";
|
|
@@ -20,19 +20,22 @@ export interface ClaimLaunch {
|
|
|
20
20
|
/** What the run's computer may reach, as its launch resolved it (run-launch.ts boxAllow): "none" or absent is no
|
|
21
21
|
* network, a list an allow-list. The computer's spec takes it. */
|
|
22
22
|
readonly boxAllow?: readonly string[] | "none";
|
|
23
|
+
/** The operator set that (run-launch.ts boxAllowSet), not the default. */
|
|
24
|
+
readonly boxAllowSet?: true;
|
|
23
25
|
}
|
|
24
|
-
/** What of the run a computer's spec is made from, besides its kind and provider: what it may reach
|
|
25
|
-
* provider declares it makes (its capabilities()): its networks and its longest
|
|
26
|
-
* run allows. */
|
|
26
|
+
/** What of the run a computer's spec is made from, besides its kind and provider: what it may reach, and whether the
|
|
27
|
+
* operator set that; and what the provider declares it makes (its capabilities()): its networks and its longest
|
|
28
|
+
* lifetime. Absent, the spec asks as the run allows. */
|
|
27
29
|
export interface ComputerRun {
|
|
28
30
|
readonly boxAllow?: readonly string[] | "none";
|
|
31
|
+
readonly boxAllowSet?: true;
|
|
29
32
|
readonly networks?: readonly ("none" | "open" | "allow")[];
|
|
30
33
|
readonly maxLifetimeMs?: number;
|
|
31
34
|
}
|
|
32
35
|
/** A provider module's create(), by provider id: its options from the saved keys, and the store's ledger for a provider
|
|
33
36
|
* that keeps one (the phone's `ledger` option); for a claim, what its run's computer may reach (`boxAllow`, the
|
|
34
37
|
* launch's box_allow), which no provider option carries. The computer package's providers, or a test's stand-in. */
|
|
35
|
-
export type ProviderMakers = Readonly<Partial<Record<string, (options: Record<string,
|
|
38
|
+
export type ProviderMakers = Readonly<Partial<Record<string, (options: Readonly<Record<string, unknown>>, extras: ProviderExtras) => ComputerProvider | Promise<ComputerProvider>>>>;
|
|
36
39
|
/** What a provider is made with beside its options: the store's ledger, and the claim's box_allow when a claim makes it. */
|
|
37
40
|
export type ProviderExtras = {
|
|
38
41
|
readonly ledger: ProviderLedger;
|
|
@@ -71,8 +74,9 @@ export interface ComputerForClaimDeps {
|
|
|
71
74
|
/** The server's seal key: absent, no key is opened, so a provider that needs one is refused in words. */
|
|
72
75
|
readonly sealKey: Buffer | undefined;
|
|
73
76
|
readonly providers: ProviderMakers;
|
|
74
|
-
/** What a computer of `kind` is made with, besides its labels and its mount: image, lifetime, network (from `run`).
|
|
75
|
-
|
|
77
|
+
/** What a computer of `kind` is made with, besides its labels and its mount: image, lifetime, network (from `run`).
|
|
78
|
+
* `image`: the one the setting's configuration names, over the kind's default. */
|
|
79
|
+
readonly spec: (entry: ProviderEntry, kind: Exclude<ComputerSettingKind, "none">, run: ComputerRun, image?: string) => Omit<ComputerSpec, "labels" | "mount">;
|
|
76
80
|
/** A provider key's value by its name, as the server reads it (key-meta.ts keyReader: the environment's, else the
|
|
77
81
|
* saved one). Absent: the saved one alone, opened with `sealKey`. */
|
|
78
82
|
readonly keyOf?: (name: string) => Promise<string | undefined>;
|
|
@@ -81,6 +85,8 @@ export interface ComputerForClaimDeps {
|
|
|
81
85
|
readonly settings?: ProviderSettings;
|
|
82
86
|
/** Whether a provider that binds a folder of this machine answers here now (Docker): the Mode 1 default asks it. */
|
|
83
87
|
readonly answers?: (provider: string) => Promise<boolean>;
|
|
88
|
+
/** Its daemon's answer (docker-daemon.ts), asked when a launch on such a provider fails (ClaimSide.daemon). */
|
|
89
|
+
readonly daemon?: ClaimSide["daemon"];
|
|
84
90
|
/** A launch of the server's own in place of the providers' (--faux's desktop). */
|
|
85
91
|
readonly launch?: ClaimSide["launch"];
|
|
86
92
|
/** The run's folder (mounted only where the provider mounts it) and the mount check attach runs. */
|
|
@@ -95,6 +101,9 @@ export interface ComputerForClaimDeps {
|
|
|
95
101
|
* a host that lacks it, or a named image pulled); never when the host has it. The run's caller says it on the run's
|
|
96
102
|
* timeline. Absent: nothing is said. */
|
|
97
103
|
readonly onImageWait?: ImageWait;
|
|
104
|
+
/** Why this run's harness takes no computer of `kind`, in words (a CLI harness's of a browser), or undefined: a kind
|
|
105
|
+
* it refuses is refused with code computer_unavailable before anything is made. Absent: every kind. */
|
|
106
|
+
readonly refuseKind?: (kind: Exclude<ComputerSettingKind, "none">) => string | undefined;
|
|
98
107
|
readonly signal?: AbortSignal;
|
|
99
108
|
}
|
|
100
109
|
/** The run's computer at its claim: what runTools takes, the person's hold on a desktop's or phone's ports, and its
|
|
@@ -105,15 +114,9 @@ export interface ClaimComputer {
|
|
|
105
114
|
readonly hold?: RunHold;
|
|
106
115
|
release(why?: ViewEnd): Promise<void>;
|
|
107
116
|
}
|
|
117
|
+
/** The provider's watch of a computer's screen (ComputerProvider.watch), where it has one. */
|
|
108
118
|
/** Told once, before the claim waits on its computer's image being built or pulled; never when the host has it. */
|
|
109
119
|
export type ImageWait = (making: "build" | "pull", tag: string) => void;
|
|
110
|
-
/** The runner's start: every computer of `providers` with all of `labels` whose deadline (its agentrun.computer.deadline
|
|
111
|
-
* label) has passed is ended, once (the janitor's sweep), each provider apart. A provider whose vendor ends its own
|
|
112
|
-
* computers answers its refusal in words; nothing throws. */
|
|
113
|
-
export declare function sweepComputers(providers: readonly ComputerProvider[], labels: Readonly<Record<string, string>>, now?: Date): Promise<{
|
|
114
|
-
readonly provider: string;
|
|
115
|
-
readonly swept: Result<Swept>;
|
|
116
|
-
}[]>;
|
|
117
120
|
/** The run's computer for this claim, started and registered; `{ computer: undefined }` for none. Throws with code
|
|
118
121
|
* computer_unavailable and the server's words when the agent's computer cannot be had here. */
|
|
119
122
|
export declare function computerForClaim(launch: ClaimLaunch, store: Pick<Store, "agents" | "sealedKeys" | "computerLedger">, deps: ComputerForClaimDeps): Promise<ClaimComputer>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { releaseOlder, runLabels
|
|
1
|
+
import { releaseOlder, runLabels } from "@parcha/agentrun-computer";
|
|
2
2
|
import { computerOfPlace } from "../computer-setting.js";
|
|
3
3
|
import { KEY_TABLE, providerOptions } from "../computer-keys.js";
|
|
4
4
|
import { getSealedKey } from "../server-keys.js";
|
|
@@ -27,18 +27,82 @@ function phonePlatform(machine, entry) {
|
|
|
27
27
|
const said = machine ?? entry?.capabilities.find((one) => one.kind === "android" || one.kind === "ios")?.kind;
|
|
28
28
|
return said === "ios" ? "ios" : "android";
|
|
29
29
|
}
|
|
30
|
-
/** The image `provider` made ready, when
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
/** The image `provider` made ready, when its descriptor declares it prepares its image (`entry.prepareImage`): its
|
|
31
|
+
* prepareImage(), its recipe built when the engine lacks it or its image by name pulled, answering the tag to start
|
|
32
|
+
* from; undefined for any other provider, which starts from its spec's image. A provider whose descriptor declares it
|
|
33
|
+
* and that has none breaks the contract, in words. A failure is the provider's words. `onWait`: told once if the claim
|
|
34
|
+
* waits on a build or a pull. */
|
|
35
|
+
async function readyImage(entry, provider, signal, onWait) {
|
|
36
|
+
if (!entry.prepareImage)
|
|
35
37
|
return undefined;
|
|
36
|
-
|
|
38
|
+
if (provider.prepareImage === undefined)
|
|
39
|
+
throw new Error(`${entry.label}'s descriptor says it prepares its image, but its provider has no prepareImage()`);
|
|
40
|
+
const ready = await provider.prepareImage({ ...(signal ? { signal } : {}), ...(onWait ? { onWait } : {}) });
|
|
37
41
|
if (!ready.ok)
|
|
38
42
|
throw new Error(ready.error.message);
|
|
39
43
|
return ready.value;
|
|
40
44
|
}
|
|
41
45
|
const watching = (provider) => typeof provider.watch === "function" ? provider : undefined;
|
|
46
|
+
/** The browser computer `ref`'s CDP URL now: the provider's connect (its signed URL), its words and code when the session
|
|
47
|
+
* has ended. The connection itself is let go once read. */
|
|
48
|
+
async function cdpUrlOf(provider, ref) {
|
|
49
|
+
const connected = await provider.connect(ref);
|
|
50
|
+
if (!connected.ok)
|
|
51
|
+
throw Object.assign(new Error(connected.error.message), { code: connected.error.code });
|
|
52
|
+
const url = connected.value.cdp?.url;
|
|
53
|
+
await connected.value.close().catch(() => undefined);
|
|
54
|
+
if (!url)
|
|
55
|
+
throw new Error(`the ${provider.id} computer ${ref.id} gave no CDP connection`);
|
|
56
|
+
return url;
|
|
57
|
+
}
|
|
58
|
+
/** The label a browser session's computer carries its browser tool's tag in. */
|
|
59
|
+
const SESSION_TAG = "agentrun.session";
|
|
60
|
+
/** A label value of letters, digits and `_.:-` alone, as every provider takes one. */
|
|
61
|
+
const labelValue = (value) => value.replace(/[^A-Za-z0-9_.:-]+/g, "_").slice(0, 63);
|
|
62
|
+
/** A provider failure as an error with the provider's words and code. */
|
|
63
|
+
const failed = (error) => Object.assign(new Error(error.message), { code: error.code });
|
|
64
|
+
/** A browser computer's provider as the run's browser tool opens its sessions through it (ClaimBrowser): nothing is made
|
|
65
|
+
* at the claim. A session's computer is made at the tool's call, under the run's labels (`spec`'s) and the tool's tag;
|
|
66
|
+
* its release lets go of every one the tool left open. */
|
|
67
|
+
function claimBrowser(provider, spec) {
|
|
68
|
+
// A run's browser: the claim's spec always carries its lifetime (computerSpecOf); an agent's computer (owner) has none.
|
|
69
|
+
const lifetime = spec.lifetimeMs;
|
|
70
|
+
if (lifetime === undefined)
|
|
71
|
+
throw new TypeError("a run's browser needs lifetimeMs: the claim's spec carries none");
|
|
72
|
+
const open = new Set();
|
|
73
|
+
const release = async (id) => {
|
|
74
|
+
const released = await provider.release({ id, name: id }, "delete");
|
|
75
|
+
if (!released.ok)
|
|
76
|
+
throw failed(released.error);
|
|
77
|
+
open.delete(id);
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
browser: {
|
|
81
|
+
provider: provider.id,
|
|
82
|
+
maxLifetimeS: Math.floor(lifetime / 1000),
|
|
83
|
+
async open(tag, lifetimeS, signal) {
|
|
84
|
+
const lifetimeMs = Math.min(lifetime, Math.max(1, Math.round(lifetimeS)) * 1000);
|
|
85
|
+
const created = await provider.create({ ...spec, lifetimeMs, labels: { ...spec.labels, [SESSION_TAG]: labelValue(tag) } }, signal ? { signal } : {});
|
|
86
|
+
if (!created.ok)
|
|
87
|
+
throw failed(created.error);
|
|
88
|
+
open.add(created.value.id);
|
|
89
|
+
return created.value.id;
|
|
90
|
+
},
|
|
91
|
+
async find(tag) {
|
|
92
|
+
const listed = await provider.list({ ...spec.labels, [SESSION_TAG]: labelValue(tag) });
|
|
93
|
+
if (!listed.ok)
|
|
94
|
+
throw failed(listed.error);
|
|
95
|
+
return listed.value.map((one) => one.ref.id);
|
|
96
|
+
},
|
|
97
|
+
url: (id) => cdpUrlOf(provider, { id, name: id }),
|
|
98
|
+
close: release,
|
|
99
|
+
},
|
|
100
|
+
async release() {
|
|
101
|
+
for (const id of [...open])
|
|
102
|
+
await release(id).catch(() => undefined);
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
42
106
|
/** `entry`'s computer started through its provider: the run's computers of a lower claim epoch released first (the
|
|
43
107
|
* janitor's releaseOlder: one claim's computer at a time), then made with the run's labels (and the run's folder, when
|
|
44
108
|
* it mounts), connected, its groups from its hello; its read-back is the provider's own; its release deletes it. */
|
|
@@ -81,17 +145,6 @@ async function providerLaunch(provider, claim, spec, signal) {
|
|
|
81
145
|
},
|
|
82
146
|
};
|
|
83
147
|
}
|
|
84
|
-
/** The runner's start: every computer of `providers` with all of `labels` whose deadline (its agentrun.computer.deadline
|
|
85
|
-
* label) has passed is ended, once (the janitor's sweep), each provider apart. A provider whose vendor ends its own
|
|
86
|
-
* computers answers its refusal in words; nothing throws. */
|
|
87
|
-
export async function sweepComputers(providers, labels, now = new Date()) {
|
|
88
|
-
const out = [];
|
|
89
|
-
for (const provider of providers) {
|
|
90
|
-
const swept = await sweep(provider, { labels: { ...labels }, now }).catch((error) => ({ ok: false, error: { code: "refused", message: error instanceof Error ? error.message : String(error) } }));
|
|
91
|
-
out.push({ provider: provider.id, swept });
|
|
92
|
-
}
|
|
93
|
-
return out;
|
|
94
|
-
}
|
|
95
148
|
/** The run's computer for this claim, started and registered; `{ computer: undefined }` for none. Throws with code
|
|
96
149
|
* computer_unavailable and the server's words when the agent's computer cannot be had here. */
|
|
97
150
|
export async function computerForClaim(launch, store, deps) {
|
|
@@ -103,9 +156,10 @@ export async function computerForClaim(launch, store, deps) {
|
|
|
103
156
|
const side = {
|
|
104
157
|
keysOf: providerKeys(deps.kinds, deps.keyOf ?? (async (name) => (deps.sealKey ? await getSealedKey(store, deps.sealKey, name) : undefined))),
|
|
105
158
|
answers: deps.answers ?? (async () => false),
|
|
106
|
-
|
|
159
|
+
...(deps.daemon ? { daemon: deps.daemon } : {}),
|
|
160
|
+
async launch(entry, { kind, keys, configuration, mount, gpu, signal }) {
|
|
107
161
|
if (deps.launch) {
|
|
108
|
-
const own = await deps.launch(entry, { kind, keys, ...(mount ? { mount } : {}), ...(signal ? { signal } : {}) });
|
|
162
|
+
const own = await deps.launch(entry, { kind, keys, configuration, ...(mount ? { mount } : {}), ...(gpu ? { gpu } : {}), ...(signal ? { signal } : {}) });
|
|
109
163
|
const ownWatch = own.watch;
|
|
110
164
|
made = { id: own.id, ...(ownWatch ? { watch: ownWatch } : {}) };
|
|
111
165
|
madeBy = entry;
|
|
@@ -117,20 +171,36 @@ export async function computerForClaim(launch, store, deps) {
|
|
|
117
171
|
const options = providerOptions(entry.id, keys, deps.settings ?? {}, table);
|
|
118
172
|
if (!options.ok)
|
|
119
173
|
throw new Error(options.error.message);
|
|
120
|
-
|
|
174
|
+
// The configuration the setting selected is built by its own create() options (Orgo's Windows: { os: "windows" }),
|
|
175
|
+
// beside the keys'.
|
|
176
|
+
const provider = await make({ ...options.options, ...configuration.options }, { ledger: storeLedger(store.computerLedger, entry.id), ...(launch.boxAllow === undefined ? {} : { boxAllow: launch.boxAllow }) });
|
|
121
177
|
// What this provider makes, as it declares it: the spec asks for one of its networks, within its lifetime
|
|
122
178
|
// (computer-deps.ts computerSpecOf).
|
|
123
179
|
const { network: networks, maxLifetimeMs } = provider.capabilities();
|
|
124
180
|
const run = {
|
|
125
181
|
...(launch.boxAllow === undefined ? {} : { boxAllow: launch.boxAllow }),
|
|
182
|
+
...(launch.boxAllowSet ? { boxAllowSet: true } : {}),
|
|
126
183
|
...(networks ? { networks } : {}),
|
|
127
184
|
...(typeof maxLifetimeMs === "number" ? { maxLifetimeMs } : {}),
|
|
128
185
|
};
|
|
129
|
-
// A provider that
|
|
130
|
-
// pulled) does so first, and the computer starts from the tag it answers: the recipe's tag is in no
|
|
131
|
-
// run of it unbuilt would be refused.
|
|
132
|
-
|
|
133
|
-
const
|
|
186
|
+
// A provider that declares it prepares its own image (its prepareImage(): its recipe built when the engine lacks it,
|
|
187
|
+
// an image by name pulled) does so first, and the computer starts from the tag it answers: the recipe's tag is in no
|
|
188
|
+
// registry, so a run of it unbuilt would be refused. The spec comes first, so a setting it refuses builds nothing. A
|
|
189
|
+
// configuration that names its image starts from it, else the kind's default.
|
|
190
|
+
const asked = deps.spec(entry, kind, run, configuration.image);
|
|
191
|
+
const ready = await readyImage(entry, provider, signal, deps.onImageWait);
|
|
192
|
+
const spec = { ...asked, ...(ready ? { image: ready } : {}), labels: runLabels(launch.runId, launch.epoch), ...(mount ? { mount } : {}), ...(gpu ? { gpu } : {}) };
|
|
193
|
+
// A browser makes nothing here: the run's browser tool opens each session through it, so a session lives (and is
|
|
194
|
+
// booked) only while the tool holds it.
|
|
195
|
+
if (kind === "browser") {
|
|
196
|
+
// The run's sessions of a lower claim epoch go first, as a computer's do (the janitor's releaseOlder).
|
|
197
|
+
const older = await releaseOlder(provider, launch.runId, launch.epoch, signal ? { signal } : {});
|
|
198
|
+
if (!older.ok)
|
|
199
|
+
throw new Error(older.error.message);
|
|
200
|
+
const opened = claimBrowser(provider, spec);
|
|
201
|
+
madeBy = entry;
|
|
202
|
+
return { id: entry.id, groups: ["cdp"], browser: opened.browser, release: opened.release };
|
|
203
|
+
}
|
|
134
204
|
const launched = await providerLaunch(provider, launch, spec, signal);
|
|
135
205
|
made = { id: launched.id, machine: launched.machine, ...(launched.watch ? { watch: launched.watch } : {}) };
|
|
136
206
|
madeBy = entry;
|
|
@@ -142,6 +212,9 @@ export async function computerForClaim(launch, store, deps) {
|
|
|
142
212
|
throw unavailable(resolved.refused);
|
|
143
213
|
if (resolved.kind === "none")
|
|
144
214
|
return { computer: undefined, release: noop };
|
|
215
|
+
const refusedKind = deps.refuseKind?.(resolved.kind);
|
|
216
|
+
if (refusedKind)
|
|
217
|
+
throw unavailable(refusedKind);
|
|
145
218
|
// The run's mount credential (Mode 2), minted when the mount was made: removed with the computer, or at once when the
|
|
146
219
|
// start fails after it was minted.
|
|
147
220
|
const revoke = async () => { await deps.revokeMount?.(); };
|