@parcha/agentrun-serve 0.1.0-beta.32 → 0.1.0-beta.34
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 +270 -0
- package/README.md +343 -246
- package/dist/adapters.d.ts +0 -7
- package/dist/adapters.js +11 -22
- package/dist/agent-rows.d.ts +98 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +60 -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 +14 -0
- package/dist/api-only.js +33 -0
- package/dist/archil-routes.d.ts +1 -1
- package/dist/bash-read-only.d.ts +22 -0
- package/dist/bash-read-only.js +701 -0
- package/dist/box-egress-vm.d.ts +0 -8
- package/dist/box-egress-vm.js +0 -10
- package/dist/box-egress.d.ts +0 -4
- package/dist/box-egress.js +1 -16
- package/dist/box-paths.d.ts +25 -2
- package/dist/box-paths.js +79 -11
- package/dist/box-relay.d.ts +0 -11
- package/dist/box-relay.js +0 -20
- package/dist/box-settings.d.ts +26 -0
- package/dist/box-settings.js +63 -0
- package/dist/boxes.d.ts +21 -1
- 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 +94 -51
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -53
- package/dist/browser-person.js +94 -279
- package/dist/budget.d.ts +0 -4
- package/dist/budget.js +0 -7
- package/dist/cap.d.ts +8 -12
- package/dist/cap.js +12 -27
- package/dist/cli.js +61 -20
- 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.js +5 -2
- package/dist/computer-setting.d.ts +20 -4
- package/dist/computer-setting.js +25 -5
- package/dist/computers.d.ts +31 -3
- package/dist/computers.js +70 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-RPHGlXmM.js +540 -0
- package/dist/console/assets/index-opTN5Naq.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/daytona-api.d.ts +0 -11
- package/dist/daytona-api.js +1 -82
- 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/docker-host-addresses.d.ts +37 -0
- package/dist/docker-host-addresses.js +110 -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 +0 -2
- package/dist/errors.js +6 -9
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -11
- package/dist/files.js +2 -21
- package/dist/github-connection.d.ts +2 -2
- package/dist/github-connection.js +1 -1
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +4 -14
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +22 -5
- package/dist/harness-install.js +98 -20
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- 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/harness.d.ts +4 -3
- package/dist/harness.js +16 -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 +62 -24
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +6 -2
- package/dist/learn/check.js +83 -29
- package/dist/learn/folder.d.ts +5 -1
- package/dist/learn/folder.js +10 -3
- package/dist/learn/grade.d.ts +14 -0
- package/dist/learn/grade.js +68 -12
- package/dist/learn/index.d.ts +4 -4
- package/dist/learn/index.js +4 -4
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +79 -4
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +8 -1
- package/dist/learn/secrets.js +95 -15
- package/dist/learn/skills.d.ts +112 -14
- package/dist/learn/skills.js +556 -52
- package/dist/learned-workflow.d.ts +37 -5
- package/dist/learned-workflow.js +106 -12
- package/dist/learning-routes.d.ts +16 -49
- package/dist/learning-routes.js +46 -36
- package/dist/learning-run.d.ts +6 -250
- package/dist/learning-run.js +11 -665
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +93 -77
- package/dist/learning.js +176 -304
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +13 -3
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +11 -52
- package/dist/mcp-gateway.js +44 -148
- 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 +6 -6
- package/dist/mcp-servers-store.js +13 -15
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +6 -7
- package/dist/model.js +43 -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 +124 -50
- package/dist/page.d.ts +1 -3
- package/dist/page.js +9 -19
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +28 -62
- package/dist/pause.d.ts +0 -2
- package/dist/pause.js +1 -8
- package/dist/place.d.ts +0 -5
- package/dist/place.js +0 -10
- package/dist/print.d.ts +2 -1
- package/dist/print.js +4 -2
- package/dist/propose.js +83 -39
- 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 -13
- package/dist/run-db.js +2 -41
- package/dist/run-launch.d.ts +19 -2
- package/dist/run-launch.js +13 -5
- package/dist/run-learning-served.d.ts +46 -2
- package/dist/run-learning-served.js +26 -7
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-reads-over-store.js +15 -6
- package/dist/run-secrets.d.ts +33 -0
- package/dist/run-secrets.js +53 -0
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +19 -5
- package/dist/run-view.d.ts +12 -17
- package/dist/run-view.js +29 -28
- package/dist/runnable.d.ts +18 -10
- package/dist/runnable.js +21 -10
- package/dist/runner/adapter-loop.d.ts +14 -3
- package/dist/runner/adapter-loop.js +464 -62
- package/dist/runner/adapter-run-spec.d.ts +29 -8
- package/dist/runner/adapter-run-spec.js +96 -37
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +15 -1
- package/dist/runner/adapters/pi.js +19 -5
- package/dist/runner/beside.d.ts +30 -3
- package/dist/runner/beside.js +54 -12
- package/dist/runner/claim-secrets.d.ts +10 -1
- package/dist/runner/claim-secrets.js +49 -15
- package/dist/runner/cli-run-spec.d.ts +2 -0
- package/dist/runner/cli-run-spec.js +60 -17
- 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.js +118 -8
- 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.js +1 -1
- package/dist/runner/harness-loops.d.ts +9 -1
- package/dist/runner/harness-loops.js +15 -2
- package/dist/runner/journal-kinds.d.ts +30 -6
- package/dist/runner/journal-kinds.js +20 -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 +113 -11
- package/dist/runner/learning-loop.d.ts +5 -0
- package/dist/runner/learning-loop.js +26 -6
- package/dist/runner/live-ticker.d.ts +1 -1
- package/dist/runner/live-ticker.js +28 -4
- package/dist/runner/loop-contract.d.ts +3 -2
- package/dist/runner/main.d.ts +64 -10
- package/dist/runner/main.js +165 -27
- package/dist/runner/mcp-claim.d.ts +1 -1
- package/dist/runner/mcp-claim.js +2 -3
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +15 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +33 -1
- package/dist/runner/metrics.js +85 -1
- package/dist/runner/model-route.d.ts +13 -0
- package/dist/runner/model-route.js +154 -11
- package/dist/runner/redact.d.ts +8 -2
- package/dist/runner/redact.js +11 -2
- 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 +56 -10
- 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-loop.d.ts +6 -0
- package/dist/runner/workflow-loop.js +6 -4
- package/dist/runner/workflow-spec.d.ts +18 -0
- package/dist/runner/workflow-spec.js +68 -26
- package/dist/runs-over-store.d.ts +8 -3
- package/dist/runs-over-store.js +76 -19
- package/dist/seal-key.d.ts +54 -15
- package/dist/seal-key.js +232 -82
- 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/secrets.d.ts +2 -10
- package/dist/secrets.js +21 -17
- 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 +1 -80
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +10 -32
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -33
- package/dist/server.d.ts +26 -44
- package/dist/server.js +229 -142
- 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/store/agent-body.d.ts +8 -2
- package/dist/store/agent-body.js +16 -4
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +3 -3
- package/dist/store/open.d.ts +18 -5
- package/dist/store/open.js +23 -3
- package/dist/store/postgres/connection.d.ts +18 -2
- package/dist/store/postgres/connection.js +156 -32
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +27 -3
- 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 +49 -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 +64 -20
- package/dist/store/store.d.ts +38 -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 +25 -6
- package/dist/store-reads/journal.js +173 -21
- package/dist/store-reads/learning.d.ts +26 -8
- package/dist/store-reads/learning.js +12 -4
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +91 -23
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +24 -10
- package/dist/templates.js +69 -38
- 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 +274 -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-gate.d.ts +41 -216
- package/dist/tool-gate.js +79 -540
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +9 -104
- package/dist/tool-keys.js +15 -271
- package/dist/tool-plane.d.ts +14 -42
- 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 +31 -19
- package/dist/tools.js +101 -108
- package/dist/trigger-adapter.d.ts +2 -2
- package/dist/trigger-schedule.js +2 -1
- package/dist/trigger-secrets-shown.js +5 -1
- 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.js +1 -1
- package/dist/usage.d.ts +0 -2
- package/dist/usage.js +0 -2
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +23 -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/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +52 -5
- package/dist/workspace/computer-deps.js +154 -19
- package/dist/workspace/computer-for-claim.d.ts +19 -14
- package/dist/workspace/computer-for-claim.js +77 -16
- 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-providers.d.ts +6 -2
- package/dist/workspace/computer-providers.js +1 -1
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/index.d.ts +4 -3
- package/dist/workspace/index.js +4 -4
- package/dist/workspace/local.d.ts +11 -2
- package/dist/workspace/local.js +161 -43
- package/dist/workspace/resolve-computer.d.ts +50 -10
- package/dist/workspace/resolve-computer.js +46 -11
- package/dist/workspace/run-tools.d.ts +13 -31
- package/dist/workspace/run-tools.js +10 -27
- 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 +3 -99
- package/launcher/agentrun-serve +6 -33
- package/package.json +14 -14
- package/templates/README.md +9 -3
- package/templates/inbound-lead/agent.md +1 -1
- package/templates/kyb/agent.md +1 -1
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/dist/app.d.ts +0 -5
- package/dist/app.js +0 -514
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- package/dist/bounds.d.ts +0 -26
- package/dist/bounds.js +0 -137
- 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-35-7aeIZ.js +0 -519
- package/dist/console/assets/index-Cejbov-Y.css +0 -1
- package/dist/content-filter.d.ts +0 -7
- package/dist/content-filter.js +0 -23
- package/dist/disk.d.ts +0 -33
- package/dist/disk.js +0 -85
- package/dist/door-line.d.ts +0 -23
- package/dist/door-line.js +0 -83
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- package/dist/harness-app.d.ts +0 -69
- package/dist/harness-app.js +0 -1162
- 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/request-start.d.ts +0 -27
- package/dist/request-start.js +0 -381
- package/dist/run-box.d.ts +0 -205
- package/dist/run-box.js +0 -661
- package/dist/run-holder.d.ts +0 -52
- package/dist/run-holder.js +0 -139
- package/dist/runs.d.ts +0 -1200
- package/dist/runs.js +0 -4103
- package/dist/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -178
- package/dist/served-only.d.ts +0 -5
- package/dist/served-only.js +0 -12
- 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
|
@@ -14,27 +14,111 @@
|
|
|
14
14
|
//
|
|
15
15
|
// A key goes into the server-side provider call alone (the provider's create() options): the spec a computer is made
|
|
16
16
|
// with names no key, no account key and no database or Redis credential, and carries no environment at all.
|
|
17
|
-
import {
|
|
17
|
+
import { isIP } from "node:net";
|
|
18
|
+
import { posix } from "node:path";
|
|
19
|
+
import { DEFAULT_DOCKER_IMAGE, DOCKER_RECIPE, DOCKER_RECIPE_HAS, DockerProvider, PROVIDERS, providerFor, readBackOf, servingRefusals, SETTING_KINDS } from "@parcha/agentrun-computer";
|
|
18
20
|
import { DOCKER_IMAGE_ENV } from "../box-image.js";
|
|
21
|
+
import { dockerDaemonCheck } from "../docker-daemon.js";
|
|
22
|
+
import { unionOf } from "../docker-host-addresses.js";
|
|
19
23
|
import { envValue, keyReader } from "../key-meta.js";
|
|
24
|
+
import { boxAllowOf, boxAllowSetIn } from "../box-settings.js";
|
|
20
25
|
import { readLaunchBody } from "../run-launch.js";
|
|
21
26
|
import { computerForClaim } from "./computer-for-claim.js";
|
|
22
27
|
import { storeLedger } from "./computer-ledger.js";
|
|
23
28
|
import { computerProviderFactories, computerProviderMakers } from "./computer-providers.js";
|
|
29
|
+
import { needsNetwork, noNetworkRefusal, vendorNetworkOnly } from "./resolve-computer.js";
|
|
24
30
|
/** How long a run's computer lives whatever happens to the server: a bound on a leaked one, never its clean end (the old
|
|
25
31
|
* box's lifetime). The clean end is the run's release. */
|
|
26
32
|
export const COMPUTER_LIFETIME_MS = 24 * 60 * 60_000;
|
|
27
33
|
/** A computer this server cannot make here, with the code the run fails with and its words. */
|
|
28
34
|
const refused = (words) => Object.assign(new Error(words), { code: "computer_unavailable" });
|
|
35
|
+
/** The settings that size a Docker computer (a sandbox or a desktop): its CPUs, its memory (swap included) and how many
|
|
36
|
+
* processes and threads it may hold at once. Unset, the Docker provider's own defaults hold. A vendor's computer sizes
|
|
37
|
+
* itself and is never given them. */
|
|
38
|
+
export const BOX_CPUS_ENV = "AGENTRUN_BOX_CPUS";
|
|
39
|
+
export const BOX_MEMORY_ENV = "AGENTRUN_BOX_MEMORY";
|
|
40
|
+
export const BOX_PIDS_ENV = "AGENTRUN_BOX_PIDS";
|
|
41
|
+
/** Each setting's spec field and what it takes, in an operator's words. */
|
|
42
|
+
const LIMIT_SETTINGS = [
|
|
43
|
+
{ name: BOX_CPUS_ENV, field: "cpus", form: "a number of CPUs, such as 2 or 1.5" },
|
|
44
|
+
{ name: BOX_MEMORY_ENV, field: "memoryMb", form: "a size with its unit (b, k, m or g), such as 512m or 4g" },
|
|
45
|
+
{ name: BOX_PIDS_ENV, field: "pids", form: "a whole number of processes and threads, such as 1024" },
|
|
46
|
+
];
|
|
47
|
+
/** A size's units as Docker reads them, each 1024 of the one before, in MiB. */
|
|
48
|
+
const SIZE_MIB = { b: 1 / (1024 * 1024), k: 1 / 1024, m: 1, g: 1024 };
|
|
49
|
+
/** One setting's value as its spec field: a number where it reads as one, else NaN, which the provider's check refuses. */
|
|
50
|
+
const LIMIT_VALUE = {
|
|
51
|
+
cpus: (value) => (/^\d+(\.\d+)?$/.test(value) ? Number(value) : Number.NaN),
|
|
52
|
+
// Its MiB, the fraction dropped, as Docker reads a size: 0.5g is 512, 6.5m is 6.
|
|
53
|
+
memoryMb: (value) => {
|
|
54
|
+
const size = /^(\d+(?:\.\d+)?)([bkmg])$/i.exec(value);
|
|
55
|
+
return size ? Math.floor(Number(size[1]) * SIZE_MIB[size[2].toLowerCase()]) : Number.NaN;
|
|
56
|
+
},
|
|
57
|
+
pids: (value) => (/^\d+$/.test(value) ? Number(value) : Number.NaN),
|
|
58
|
+
};
|
|
59
|
+
/** Asked only check(): its constructor runs nothing and reads no Docker, and check() reads only the spec. */
|
|
60
|
+
let checker;
|
|
61
|
+
/** A Docker computer's size from `env`'s AGENTRUN_BOX_CPUS, _MEMORY and _PIDS: each one set, as its spec field; none set,
|
|
62
|
+
* none, so the provider's defaults hold. A value the Docker provider would refuse at every create throws, in its own
|
|
63
|
+
* words, naming the setting and what it takes: the server's start reads them (startServe), so no run meets one. */
|
|
64
|
+
export function dockerLimitsOf(env) {
|
|
65
|
+
const limits = {};
|
|
66
|
+
for (const { name, field } of LIMIT_SETTINGS) {
|
|
67
|
+
const value = envValue(env, name)?.trim();
|
|
68
|
+
if (value !== undefined)
|
|
69
|
+
limits[field] = LIMIT_VALUE[field](value);
|
|
70
|
+
}
|
|
71
|
+
if (Object.keys(limits).length === 0)
|
|
72
|
+
return {};
|
|
73
|
+
checker ??= new DockerProvider({ daemonPath: "computerd" });
|
|
74
|
+
const refusals = checker.check({ image: DEFAULT_DOCKER_IMAGE, lifetimeMs: COMPUTER_LIFETIME_MS, network: "none", ...limits });
|
|
75
|
+
for (const { name, field, form } of LIMIT_SETTINGS) {
|
|
76
|
+
const refusal = refusals.find((one) => one.field === field);
|
|
77
|
+
if (refusal)
|
|
78
|
+
throw new Error(`${name} ${JSON.stringify(envValue(env, name).trim())} is refused by the Docker provider: ${refusal.message} (${name} is ${form})`);
|
|
79
|
+
}
|
|
80
|
+
return limits;
|
|
81
|
+
}
|
|
82
|
+
/** The Docker host's own addresses, for a Docker provider whose interfaces aren't that host's (the server in a
|
|
83
|
+
* container): a comma list of IP addresses. The Docker provider's egress proxy refuses them as the host's, so a
|
|
84
|
+
* computer's allow-list never reaches the host itself; without them it refuses any allow-list there. */
|
|
85
|
+
export const DOCKER_HOST_ADDRESSES_ENV = "AGENTRUN_DOCKER_HOST_ADDRESSES";
|
|
86
|
+
/** The variables the local browser's provider finds its Chrome by (the computer package's findChrome): the server's own
|
|
87
|
+
* values are handed to it, and no other variable of the server's. */
|
|
88
|
+
export const CHROME_LOOKUP = ["CHROME_PATH", "PI_BROWSER_CHROME", "PATH"];
|
|
89
|
+
/** `env`'s AGENTRUN_DOCKER_HOST_ADDRESSES: its addresses, each once; undefined when unset or empty, never one made up.
|
|
90
|
+
* An entry that is not an IP address throws, naming it: the server's start checks the setting, so no run meets one. */
|
|
91
|
+
export function dockerHostAddressesOf(env) {
|
|
92
|
+
const value = envValue(env, DOCKER_HOST_ADDRESSES_ENV);
|
|
93
|
+
if (value === undefined)
|
|
94
|
+
return undefined;
|
|
95
|
+
const addresses = [...new Set(value.split(",").map((one) => one.trim()).filter((one) => one !== ""))];
|
|
96
|
+
const bad = addresses.find((one) => isIP(one) === 0);
|
|
97
|
+
if (bad !== undefined)
|
|
98
|
+
throw new Error(`${DOCKER_HOST_ADDRESSES_ENV} is a comma list of the Docker host's own IP addresses (such as 172.17.0.1): ${JSON.stringify(bad)} is not an IP address`);
|
|
99
|
+
return addresses.length > 0 ? addresses : undefined;
|
|
100
|
+
}
|
|
101
|
+
/** Where the Docker provider's daemon copy goes on a server in a container: under the named volume's mount, so the
|
|
102
|
+
* host's Docker reaches it as that volume's subpath, as it reaches the run's folder. */
|
|
103
|
+
export const DAEMON_CACHE_IN_VOLUME = ".agentrun/computerd";
|
|
104
|
+
export function dockerVolumeOf(paths) {
|
|
105
|
+
if (!("paths" in paths))
|
|
106
|
+
return undefined;
|
|
107
|
+
const root = paths.paths.at;
|
|
108
|
+
return { volume: { name: paths.paths.volume, root }, daemonCache: posix.join(root, DAEMON_CACHE_IN_VOLUME) };
|
|
109
|
+
}
|
|
29
110
|
/** The spec a computer of `kind` on `entry` is made with, besides its labels and its mount: its image (Docker's: the
|
|
30
111
|
* owner's AGENTRUN_DOCKER_IMAGE when set, else for a sandbox the package's recipe; any other provider's: its registry
|
|
31
112
|
* entry's defaultImage for the kind, the computer package's PROVIDERS[].defaultImage; a kind with none refused in
|
|
32
|
-
* words, a Docker desktop's saying it needs an image with an X server, which the recipe lacks), the leak bound for its lifetime (its clean end is the run's release), and its network
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
113
|
+
* words, a Docker desktop's saying it needs an image with an X server, which the recipe lacks), the leak bound for its lifetime (its clean end is the run's release), and its network
|
|
114
|
+
* (networkOf): the run's box_allow, or this server's own (AGENTRUN_BOX_ALLOW, read from `env`) for a launch that names
|
|
115
|
+
* none; and a Docker computer's size, AGENTRUN_BOX_CPUS, _MEMORY and _PIDS (dockerLimitsOf, read once here), on
|
|
116
|
+
* Docker's alone. No key and no environment. */
|
|
36
117
|
export function computerSpecOf(env) {
|
|
37
118
|
const named = envValue(env, DOCKER_IMAGE_ENV);
|
|
119
|
+
// This server's allow setting, as a launch is stamped with it (box-settings.ts boxAllowOf; its start checks the setting).
|
|
120
|
+
const current = () => boxAllowOf(env);
|
|
121
|
+
const currentSet = () => boxAllowSetIn(env);
|
|
38
122
|
const imageOf = (entry, kind) => {
|
|
39
123
|
if (entry.id === "docker" && named !== undefined)
|
|
40
124
|
return named;
|
|
@@ -48,24 +132,40 @@ export function computerSpecOf(env) {
|
|
|
48
132
|
throw refused("A Docker desktop needs an image with an X server; set one for desktops.");
|
|
49
133
|
throw refused(`${entry.label} has no image for a ${kind} computer here: pick another provider for this agent's computer in Settings → Computers.`);
|
|
50
134
|
};
|
|
135
|
+
const limits = dockerLimitsOf(env);
|
|
51
136
|
return (entry, kind, run) => ({
|
|
52
137
|
image: imageOf(entry, kind),
|
|
53
138
|
// The leak bound, within the longest the provider makes (E2B's is an hour): a longer one it refuses at create.
|
|
54
139
|
lifetimeMs: Math.min(COMPUTER_LIFETIME_MS, run.maxLifetimeMs ?? COMPUTER_LIFETIME_MS),
|
|
55
|
-
network: networkOf(kind, run),
|
|
140
|
+
network: networkOf(entry, kind, run, current, currentSet),
|
|
141
|
+
// A Docker computer's size, the operator's (dockerLimitsOf); a vendor's sizes itself.
|
|
142
|
+
...(entry.id === "docker" ? limits : {}),
|
|
56
143
|
});
|
|
57
144
|
}
|
|
58
|
-
/** The network a computer of `kind` asks for:
|
|
59
|
-
* "none" but not what the run allows. A
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
|
|
65
|
-
|
|
145
|
+
/** The network a computer of `kind` on `entry` asks for: what the run allows (its box_allow), narrowed to "none" when its
|
|
146
|
+
* provider makes "none" but not what the run allows. A launch that names no box_allow (a row from before every launch
|
|
147
|
+
* was stamped with it) allows what this server allows now (`current`), never "open"; a sandbox with none still has no
|
|
148
|
+
* network, as it always had. A remote computer (Daytona's or E2B's, each one whose capabilities' network is ["none"])
|
|
149
|
+
* runs its programs in a network of their own, so an open or listed network is one it refuses at create; "none" reaches
|
|
150
|
+
* less than the run allows, never more. Under "none", the operator's word for no network at all, a computer whose
|
|
151
|
+
* provider makes no "none" (a cloud phone, a hosted browser, Local Chrome) is refused in words (noNetworkRefusal), as
|
|
152
|
+
* the run's start refuses it (resolve-computer.ts computerReadiness). A vendor-hosted computer that runs only on the
|
|
153
|
+
* vendor's own network (its capabilities' network is ["open"]) is "open" under a list, the default or the operator's,
|
|
154
|
+
* since this server's list can't reach it, and Settings says so (computers.ts networkWords). A browser whose provider
|
|
155
|
+
* makes both "open" and "allow" (Local Chrome, behind its own egress proxy) is held to the operator's list
|
|
156
|
+
* (`boxAllowSet`, the launch's, or this server's now for a launch that names no box_allow) and is "open" under the
|
|
157
|
+
* default list, which is a sandbox's package-install list and no browsing policy. */
|
|
158
|
+
function networkOf(entry, kind, run, current, currentSet) {
|
|
159
|
+
const boxAllow = run.boxAllow ?? (kind === "sandbox" ? "none" : current());
|
|
160
|
+
const set = run.boxAllow !== undefined ? run.boxAllowSet === true : currentSet();
|
|
161
|
+
if (boxAllow === "none" && needsNetwork(run.networks))
|
|
162
|
+
throw refused(noNetworkRefusal(entry.label, kind));
|
|
163
|
+
if (vendorNetworkOnly(run.networks))
|
|
66
164
|
return "open";
|
|
67
|
-
|
|
68
|
-
|
|
165
|
+
if (kind === "browser" && boxAllow !== "none" && run.networks?.includes("open") && run.networks.includes("allow"))
|
|
166
|
+
return set ? { allow: [...boxAllow] } : "open";
|
|
167
|
+
const allowed = boxAllow === "none" ? "none" : { allow: [...boxAllow] };
|
|
168
|
+
const form = allowed === "none" ? "none" : "allow";
|
|
69
169
|
return run.networks && !run.networks.includes(form) && run.networks.includes("none") ? "none" : allowed;
|
|
70
170
|
}
|
|
71
171
|
/** The run's timeline phase while its claim waits on its computer's image (computerForClaim's onImageWait): main's box
|
|
@@ -76,8 +176,9 @@ export const imageWaitWords = (making, image) => making === "build" ? `Preparing
|
|
|
76
176
|
export const claimComputer = async (launch, store, deps) => {
|
|
77
177
|
if (launch.boxAllow !== undefined || !store.runs)
|
|
78
178
|
return computerForClaim(launch, store, deps);
|
|
79
|
-
const
|
|
80
|
-
|
|
179
|
+
const body = readLaunchBody((await store.runs.launch(launch.runId)).body);
|
|
180
|
+
const boxAllow = body?.boxAllow;
|
|
181
|
+
return computerForClaim(boxAllow === undefined ? launch : { ...launch, boxAllow, ...(body?.boxAllowSet ? { boxAllowSet: true } : {}) }, store, deps);
|
|
81
182
|
};
|
|
82
183
|
/** The kind registry a claim composed with `options` resolves a setting against: --faux's when it is given faux, else a
|
|
83
184
|
* test's own, else the computer package's. The one choice: computerDepsFrom makes it, and the server's start check
|
|
@@ -86,6 +187,12 @@ export function claimKinds(options) {
|
|
|
86
187
|
// The faux registry is Settings' shape (computers.ts); the claim reads the same data as resolve-computer.ts's.
|
|
87
188
|
return options.faux?.kinds ?? options.kinds ?? { SETTING_KINDS, PROVIDERS, servingRefusals };
|
|
88
189
|
}
|
|
190
|
+
/** This machine's Docker daemon as the claim asks it once a Docker launch fails: one check per process (its answer
|
|
191
|
+
* kept a while, docker-daemon.ts), in `env`. */
|
|
192
|
+
const dockerDaemonOf = (env) => {
|
|
193
|
+
const check = dockerDaemonCheck({ env: { ...env } });
|
|
194
|
+
return () => check();
|
|
195
|
+
};
|
|
89
196
|
/** computerForClaim and its process-wide deps, composed once; and Settings → Computers' factories from the same makers. */
|
|
90
197
|
export function computerDepsFrom(options) {
|
|
91
198
|
const { env, store, sealKey, faux } = options;
|
|
@@ -95,8 +202,35 @@ export function computerDepsFrom(options) {
|
|
|
95
202
|
// recipe's bare tag, which no registry has.
|
|
96
203
|
const named = envValue(env, DOCKER_IMAGE_ENV);
|
|
97
204
|
const dockerImage = named !== undefined ? { image: named } : { recipe: DOCKER_RECIPE };
|
|
205
|
+
// The operator's Docker host addresses (AGENTRUN_DOCKER_HOST_ADDRESSES), checked once here.
|
|
206
|
+
const namedAddresses = dockerHostAddressesOf(env);
|
|
207
|
+
// Where this process's Docker has the data, read once, when a Docker provider is first built.
|
|
208
|
+
let paths;
|
|
209
|
+
/** The Docker provider's options beside its image: for a server in a container of its Docker's, the named volume that
|
|
210
|
+
* holds its data and the daemon copy's place under it (dockerVolumeOf), and the Docker host's own addresses for its
|
|
211
|
+
* egress proxy, the union of the read through the socket (`hostAddresses`) and the operator's; on a host, the
|
|
212
|
+
* operator's alone (the provider reads its own interfaces). With none, none are given, and the provider refuses an
|
|
213
|
+
* allow-list where it isn't on the Docker host, in its words. The read is made only for a claim whose run's computer
|
|
214
|
+
* has an allow-list (`boxAllow`, the claim's own launch's box_allow, a list): a run launched under a list keeps it
|
|
215
|
+
* across a restart, whatever this process's AGENTRUN_BOX_ALLOW says now; one with none, or no claim, reads nothing.
|
|
216
|
+
* The read itself is once per process (`hostAddresses`). */
|
|
217
|
+
const dockerOptions = async (boxAllow) => {
|
|
218
|
+
const where = options.dockerPaths ? await (paths ??= options.dockerPaths()) : { here: true };
|
|
219
|
+
const volume = dockerVolumeOf(where);
|
|
220
|
+
// A launch that names no box_allow (a row from before every launch was stamped) allows what this server allows now,
|
|
221
|
+
// as its computer's network does (networkOf), so the provider's options follow the same setting.
|
|
222
|
+
const allow = boxAllow ?? boxAllowOf(env);
|
|
223
|
+
const read = volume && Array.isArray(allow) && options.hostAddresses ? await options.hostAddresses() : undefined;
|
|
224
|
+
const addresses = read ? unionOf(read, namedAddresses).addresses : (namedAddresses ?? []);
|
|
225
|
+
return { image: dockerImage, ...(volume ?? {}), ...(addresses.length > 0 ? { egress: { hostAddresses: addresses } } : {}) };
|
|
226
|
+
};
|
|
98
227
|
const load = options.load ?? providerFor;
|
|
99
|
-
|
|
228
|
+
// The local browser finds its Chrome where the server's environment names one (CHROME_PATH, PI_BROWSER_CHROME, else
|
|
229
|
+
// PATH): those three alone, for the claim and Settings → Computers' test alike.
|
|
230
|
+
const chromeEnv = { env: Object.fromEntries(CHROME_LOOKUP.flatMap((name) => (env[name] === undefined ? [] : [[name, env[name]]]))) };
|
|
231
|
+
const providers = computerProviderMakers({
|
|
232
|
+
load: async (id, given, claim) => load(id, id === "docker" ? { ...given, ...(await dockerOptions(claim?.boxAllow)) } : id === "local" ? { ...given, ...chromeEnv } : given),
|
|
233
|
+
});
|
|
100
234
|
const computerDeps = {
|
|
101
235
|
kinds,
|
|
102
236
|
providers,
|
|
@@ -106,6 +240,7 @@ export function computerDepsFrom(options) {
|
|
|
106
240
|
// Under --faux, its launch makes the computer, with its key table: no provider of the package is built.
|
|
107
241
|
...(faux ? { keyTable: faux.keyTable, launch: (entry, spec) => faux.launch(entry, spec) } : {}),
|
|
108
242
|
...(options.answers ? { answers: options.answers } : {}),
|
|
243
|
+
...(options.daemon ? { daemon: options.daemon } : faux ? {} : { daemon: dockerDaemonOf(env) }),
|
|
109
244
|
...(options.openComputerView ? { openComputerView: options.openComputerView } : {}),
|
|
110
245
|
};
|
|
111
246
|
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,20 +20,27 @@ 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
|
-
* that keeps one (the phone's `ledger` option)
|
|
34
|
-
|
|
36
|
+
* that keeps one (the phone's `ledger` option); for a claim, what its run's computer may reach (`boxAllow`, the
|
|
37
|
+
* launch's box_allow), which no provider option carries. The computer package's providers, or a test's stand-in. */
|
|
38
|
+
export type ProviderMakers = Readonly<Partial<Record<string, (options: Record<string, string>, extras: ProviderExtras) => ComputerProvider | Promise<ComputerProvider>>>>;
|
|
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. */
|
|
40
|
+
export type ProviderExtras = {
|
|
35
41
|
readonly ledger: ProviderLedger;
|
|
36
|
-
|
|
42
|
+
readonly boxAllow?: readonly string[] | "none";
|
|
43
|
+
};
|
|
37
44
|
/** Why a live view ends: the computer was released, or the run ended. */
|
|
38
45
|
export type ViewEnd = "released" | "ended";
|
|
39
46
|
/** The live view of a desktop or a phone, proxy-only, as its registration (computer-live.ts
|
|
@@ -77,6 +84,8 @@ export interface ComputerForClaimDeps {
|
|
|
77
84
|
readonly settings?: ProviderSettings;
|
|
78
85
|
/** Whether a provider that binds a folder of this machine answers here now (Docker): the Mode 1 default asks it. */
|
|
79
86
|
readonly answers?: (provider: string) => Promise<boolean>;
|
|
87
|
+
/** Its daemon's answer (docker-daemon.ts), asked when a launch on such a provider fails (ClaimSide.daemon). */
|
|
88
|
+
readonly daemon?: ClaimSide["daemon"];
|
|
80
89
|
/** A launch of the server's own in place of the providers' (--faux's desktop). */
|
|
81
90
|
readonly launch?: ClaimSide["launch"];
|
|
82
91
|
/** The run's folder (mounted only where the provider mounts it) and the mount check attach runs. */
|
|
@@ -91,6 +100,9 @@ export interface ComputerForClaimDeps {
|
|
|
91
100
|
* 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
|
|
92
101
|
* timeline. Absent: nothing is said. */
|
|
93
102
|
readonly onImageWait?: ImageWait;
|
|
103
|
+
/** Why this run's harness takes no computer of `kind`, in words (a CLI harness's of a browser), or undefined: a kind
|
|
104
|
+
* it refuses is refused with code computer_unavailable before anything is made. Absent: every kind. */
|
|
105
|
+
readonly refuseKind?: (kind: Exclude<ComputerSettingKind, "none">) => string | undefined;
|
|
94
106
|
readonly signal?: AbortSignal;
|
|
95
107
|
}
|
|
96
108
|
/** The run's computer at its claim: what runTools takes, the person's hold on a desktop's or phone's ports, and its
|
|
@@ -103,13 +115,6 @@ export interface ClaimComputer {
|
|
|
103
115
|
}
|
|
104
116
|
/** Told once, before the claim waits on its computer's image being built or pulled; never when the host has it. */
|
|
105
117
|
export type ImageWait = (making: "build" | "pull", tag: string) => void;
|
|
106
|
-
/** The runner's start: every computer of `providers` with all of `labels` whose deadline (its agentrun.computer.deadline
|
|
107
|
-
* label) has passed is ended, once (the janitor's sweep), each provider apart. A provider whose vendor ends its own
|
|
108
|
-
* computers answers its refusal in words; nothing throws. */
|
|
109
|
-
export declare function sweepComputers(providers: readonly ComputerProvider[], labels: Readonly<Record<string, string>>, now?: Date): Promise<{
|
|
110
|
-
readonly provider: string;
|
|
111
|
-
readonly swept: Result<Swept>;
|
|
112
|
-
}[]>;
|
|
113
118
|
/** The run's computer for this claim, started and registered; `{ computer: undefined }` for none. Throws with code
|
|
114
119
|
* computer_unavailable and the server's words when the agent's computer cannot be had here. */
|
|
115
120
|
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";
|
|
@@ -39,6 +39,62 @@ async function readyImage(provider, signal, onWait) {
|
|
|
39
39
|
return ready.value;
|
|
40
40
|
}
|
|
41
41
|
const watching = (provider) => typeof provider.watch === "function" ? provider : undefined;
|
|
42
|
+
/** The browser computer `ref`'s CDP URL now: the provider's connect (its signed URL), its words and code when the session
|
|
43
|
+
* has ended. The connection itself is let go once read. */
|
|
44
|
+
async function cdpUrlOf(provider, ref) {
|
|
45
|
+
const connected = await provider.connect(ref);
|
|
46
|
+
if (!connected.ok)
|
|
47
|
+
throw Object.assign(new Error(connected.error.message), { code: connected.error.code });
|
|
48
|
+
const url = connected.value.cdp?.url;
|
|
49
|
+
await connected.value.close().catch(() => undefined);
|
|
50
|
+
if (!url)
|
|
51
|
+
throw new Error(`the ${provider.id} computer ${ref.id} gave no CDP connection`);
|
|
52
|
+
return url;
|
|
53
|
+
}
|
|
54
|
+
/** The label a browser session's computer carries its browser tool's tag in. */
|
|
55
|
+
const SESSION_TAG = "agentrun.session";
|
|
56
|
+
/** A label value of letters, digits and `_.:-` alone, as every provider takes one. */
|
|
57
|
+
const labelValue = (value) => value.replace(/[^A-Za-z0-9_.:-]+/g, "_").slice(0, 63);
|
|
58
|
+
/** A provider failure as an error with the provider's words and code. */
|
|
59
|
+
const failed = (error) => Object.assign(new Error(error.message), { code: error.code });
|
|
60
|
+
/** A browser computer's provider as the run's browser tool opens its sessions through it (ClaimBrowser): nothing is made
|
|
61
|
+
* 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;
|
|
62
|
+
* its release lets go of every one the tool left open. */
|
|
63
|
+
function claimBrowser(provider, spec) {
|
|
64
|
+
const open = new Set();
|
|
65
|
+
const release = async (id) => {
|
|
66
|
+
const released = await provider.release({ id, name: id }, "delete");
|
|
67
|
+
if (!released.ok)
|
|
68
|
+
throw failed(released.error);
|
|
69
|
+
open.delete(id);
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
browser: {
|
|
73
|
+
provider: provider.id,
|
|
74
|
+
maxLifetimeS: Math.floor(spec.lifetimeMs / 1000),
|
|
75
|
+
async open(tag, lifetimeS, signal) {
|
|
76
|
+
const lifetimeMs = Math.min(spec.lifetimeMs, Math.max(1, Math.round(lifetimeS)) * 1000);
|
|
77
|
+
const created = await provider.create({ ...spec, lifetimeMs, labels: { ...spec.labels, [SESSION_TAG]: labelValue(tag) } }, signal ? { signal } : {});
|
|
78
|
+
if (!created.ok)
|
|
79
|
+
throw failed(created.error);
|
|
80
|
+
open.add(created.value.id);
|
|
81
|
+
return created.value.id;
|
|
82
|
+
},
|
|
83
|
+
async find(tag) {
|
|
84
|
+
const listed = await provider.list({ ...spec.labels, [SESSION_TAG]: labelValue(tag) });
|
|
85
|
+
if (!listed.ok)
|
|
86
|
+
throw failed(listed.error);
|
|
87
|
+
return listed.value.map((one) => one.ref.id);
|
|
88
|
+
},
|
|
89
|
+
url: (id) => cdpUrlOf(provider, { id, name: id }),
|
|
90
|
+
close: release,
|
|
91
|
+
},
|
|
92
|
+
async release() {
|
|
93
|
+
for (const id of [...open])
|
|
94
|
+
await release(id).catch(() => undefined);
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
42
98
|
/** `entry`'s computer started through its provider: the run's computers of a lower claim epoch released first (the
|
|
43
99
|
* janitor's releaseOlder: one claim's computer at a time), then made with the run's labels (and the run's folder, when
|
|
44
100
|
* it mounts), connected, its groups from its hello; its read-back is the provider's own; its release deletes it. */
|
|
@@ -81,17 +137,6 @@ async function providerLaunch(provider, claim, spec, signal) {
|
|
|
81
137
|
},
|
|
82
138
|
};
|
|
83
139
|
}
|
|
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
140
|
/** The run's computer for this claim, started and registered; `{ computer: undefined }` for none. Throws with code
|
|
96
141
|
* computer_unavailable and the server's words when the agent's computer cannot be had here. */
|
|
97
142
|
export async function computerForClaim(launch, store, deps) {
|
|
@@ -103,9 +148,10 @@ export async function computerForClaim(launch, store, deps) {
|
|
|
103
148
|
const side = {
|
|
104
149
|
keysOf: providerKeys(deps.kinds, deps.keyOf ?? (async (name) => (deps.sealKey ? await getSealedKey(store, deps.sealKey, name) : undefined))),
|
|
105
150
|
answers: deps.answers ?? (async () => false),
|
|
106
|
-
|
|
151
|
+
...(deps.daemon ? { daemon: deps.daemon } : {}),
|
|
152
|
+
async launch(entry, { kind, keys, mount, gpu, signal }) {
|
|
107
153
|
if (deps.launch) {
|
|
108
|
-
const own = await deps.launch(entry, { kind, keys, ...(mount ? { mount } : {}), ...(signal ? { signal } : {}) });
|
|
154
|
+
const own = await deps.launch(entry, { kind, keys, ...(mount ? { mount } : {}), ...(gpu ? { gpu } : {}), ...(signal ? { signal } : {}) });
|
|
109
155
|
const ownWatch = own.watch;
|
|
110
156
|
made = { id: own.id, ...(ownWatch ? { watch: ownWatch } : {}) };
|
|
111
157
|
madeBy = entry;
|
|
@@ -117,12 +163,13 @@ export async function computerForClaim(launch, store, deps) {
|
|
|
117
163
|
const options = providerOptions(entry.id, keys, deps.settings ?? {}, table);
|
|
118
164
|
if (!options.ok)
|
|
119
165
|
throw new Error(options.error.message);
|
|
120
|
-
const provider = await make(options.options, { ledger: storeLedger(store.computerLedger, entry.id) });
|
|
166
|
+
const provider = await make(options.options, { ledger: storeLedger(store.computerLedger, entry.id), ...(launch.boxAllow === undefined ? {} : { boxAllow: launch.boxAllow }) });
|
|
121
167
|
// What this provider makes, as it declares it: the spec asks for one of its networks, within its lifetime
|
|
122
168
|
// (computer-deps.ts computerSpecOf).
|
|
123
169
|
const { network: networks, maxLifetimeMs } = provider.capabilities();
|
|
124
170
|
const run = {
|
|
125
171
|
...(launch.boxAllow === undefined ? {} : { boxAllow: launch.boxAllow }),
|
|
172
|
+
...(launch.boxAllowSet ? { boxAllowSet: true } : {}),
|
|
126
173
|
...(networks ? { networks } : {}),
|
|
127
174
|
...(typeof maxLifetimeMs === "number" ? { maxLifetimeMs } : {}),
|
|
128
175
|
};
|
|
@@ -130,7 +177,18 @@ export async function computerForClaim(launch, store, deps) {
|
|
|
130
177
|
// pulled) does so first, and the computer starts from the tag it answers: the recipe's tag is in no registry, so a
|
|
131
178
|
// run of it unbuilt would be refused.
|
|
132
179
|
const ready = await readyImage(provider, signal, deps.onImageWait);
|
|
133
|
-
const spec = { ...deps.spec(entry, kind, run), ...(ready ? { image: ready } : {}), labels: runLabels(launch.runId, launch.epoch), ...(mount ? { mount } : {}) };
|
|
180
|
+
const spec = { ...deps.spec(entry, kind, run), ...(ready ? { image: ready } : {}), labels: runLabels(launch.runId, launch.epoch), ...(mount ? { mount } : {}), ...(gpu ? { gpu } : {}) };
|
|
181
|
+
// A browser makes nothing here: the run's browser tool opens each session through it, so a session lives (and is
|
|
182
|
+
// booked) only while the tool holds it.
|
|
183
|
+
if (kind === "browser") {
|
|
184
|
+
// The run's sessions of a lower claim epoch go first, as a computer's do (the janitor's releaseOlder).
|
|
185
|
+
const older = await releaseOlder(provider, launch.runId, launch.epoch, signal ? { signal } : {});
|
|
186
|
+
if (!older.ok)
|
|
187
|
+
throw new Error(older.error.message);
|
|
188
|
+
const opened = claimBrowser(provider, spec);
|
|
189
|
+
madeBy = entry;
|
|
190
|
+
return { id: entry.id, groups: ["cdp"], browser: opened.browser, release: opened.release };
|
|
191
|
+
}
|
|
134
192
|
const launched = await providerLaunch(provider, launch, spec, signal);
|
|
135
193
|
made = { id: launched.id, machine: launched.machine, ...(launched.watch ? { watch: launched.watch } : {}) };
|
|
136
194
|
madeBy = entry;
|
|
@@ -142,6 +200,9 @@ export async function computerForClaim(launch, store, deps) {
|
|
|
142
200
|
throw unavailable(resolved.refused);
|
|
143
201
|
if (resolved.kind === "none")
|
|
144
202
|
return { computer: undefined, release: noop };
|
|
203
|
+
const refusedKind = deps.refuseKind?.(resolved.kind);
|
|
204
|
+
if (refusedKind)
|
|
205
|
+
throw unavailable(refusedKind);
|
|
145
206
|
// The run's mount credential (Mode 2), minted when the mount was made: removed with the computer, or at once when the
|
|
146
207
|
// start fails after it was minted.
|
|
147
208
|
const revoke = async () => { await deps.revokeMount?.(); };
|
|
@@ -65,10 +65,15 @@ export type ComputerHold = {
|
|
|
65
65
|
/** The current take's name, while one is pending or held. */
|
|
66
66
|
current(): string | undefined;
|
|
67
67
|
/** The person takes it: pending while an agent call is in flight, then theirs. False (nothing changes) when a take is
|
|
68
|
-
* pending or held already, or the hold is closed. `by`: the command row that asked. */
|
|
68
|
+
* pending or held already, or the run is ending, or the hold is closed. `by`: the command row that asked. */
|
|
69
69
|
take(options?: {
|
|
70
70
|
readonly by?: number;
|
|
71
71
|
}): boolean;
|
|
72
|
+
/** The run is ending (its agent is done): nothing new is taken from now, and a take in force goes on until it ends, so
|
|
73
|
+
* the run's end can wait for it and no later take is cut by the release (#2134). */
|
|
74
|
+
finish(): void;
|
|
75
|
+
/** Whether the run is ending (finish). */
|
|
76
|
+
finishing(): boolean;
|
|
72
77
|
/** The take ends (`given` by default): false when there was none. A hand-back while the agent's ask is open answers it
|
|
73
78
|
* done, and the take ends `answered`. */
|
|
74
79
|
give(why?: HoldEnd, options?: {
|
|
@@ -38,6 +38,7 @@ export function computerHold(options = {}) {
|
|
|
38
38
|
let inFlight = 0;
|
|
39
39
|
let epoch = 0;
|
|
40
40
|
let closed = false;
|
|
41
|
+
let ending = false;
|
|
41
42
|
let open;
|
|
42
43
|
const waiters = new Set();
|
|
43
44
|
const listeners = new Set();
|
|
@@ -93,7 +94,7 @@ export function computerHold(options = {}) {
|
|
|
93
94
|
state: () => state,
|
|
94
95
|
current: () => take,
|
|
95
96
|
take({ by } = {}) {
|
|
96
|
-
if (closed || state !== "agent")
|
|
97
|
+
if (closed || ending || state !== "agent")
|
|
97
98
|
return false;
|
|
98
99
|
take = by !== undefined ? `c${by}` : `v${now()}-${randomBytes(3).toString("hex")}`;
|
|
99
100
|
epoch++;
|
|
@@ -105,6 +106,10 @@ export function computerHold(options = {}) {
|
|
|
105
106
|
toPerson(by);
|
|
106
107
|
return true;
|
|
107
108
|
},
|
|
109
|
+
finish() {
|
|
110
|
+
ending = true;
|
|
111
|
+
},
|
|
112
|
+
finishing: () => ending,
|
|
108
113
|
give,
|
|
109
114
|
away: () => void give("away"),
|
|
110
115
|
touched() {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type Result, type Swept } from "@parcha/agentrun-computer";
|
|
2
|
+
import { type KeyTable, type ProviderSettings } from "../computer-keys.js";
|
|
3
|
+
import type { Store } from "../store/index.js";
|
|
4
|
+
import type { ComputerDeps } from "./computer-deps.js";
|
|
5
|
+
/** How often the janitor sweeps after its first sweep at the runner's start. */
|
|
6
|
+
export declare const JANITOR_EVERY_MS: number;
|
|
7
|
+
/** The longest close() waits for a sweep it cut: a vendor call that ignores the cut is left to finish on its own. */
|
|
8
|
+
export declare const JANITOR_CLOSE_MS = 5000;
|
|
9
|
+
/** The longest one provider's sweep may take: past it the sweep is cut and left, said as a timeout, and the next provider
|
|
10
|
+
* is swept, so a stuck vendor (a Docker command has no timeout of its own) never stops the others or later sweeps. */
|
|
11
|
+
export declare const JANITOR_PROVIDER_MS: number;
|
|
12
|
+
export interface JanitorDeps {
|
|
13
|
+
/** The store: whose runs a computer's run label names, and the phone provider's ledger. */
|
|
14
|
+
readonly store: Pick<Store, "runs" | "computerLedger">;
|
|
15
|
+
/** The run's computers as the runner composed them (computer-deps.ts computerDepsFrom): the registry, the provider
|
|
16
|
+
* makers and the key reader. */
|
|
17
|
+
readonly computers: Pick<ComputerDeps, "kinds" | "providers" | "keyOf"> & {
|
|
18
|
+
readonly settings?: ProviderSettings;
|
|
19
|
+
readonly keyTable?: KeyTable;
|
|
20
|
+
};
|
|
21
|
+
/** The runs' environment: under --faux (AGENTRUN_SERVE_FAUX) the janitor never starts. */
|
|
22
|
+
readonly env: NodeJS.ProcessEnv;
|
|
23
|
+
/** Where a sweep's outcome and a provider's failure are said. */
|
|
24
|
+
readonly log: (line: string) => void;
|
|
25
|
+
readonly everyMs?: number;
|
|
26
|
+
/** The longest close() waits for a sweep it cut. Default JANITOR_CLOSE_MS. */
|
|
27
|
+
readonly closeMs?: number;
|
|
28
|
+
/** The longest one provider's sweep may take. Default JANITOR_PROVIDER_MS. */
|
|
29
|
+
readonly providerMs?: number;
|
|
30
|
+
/** The clock a computer's deadline is read by. Default Date.now. */
|
|
31
|
+
readonly now?: () => number;
|
|
32
|
+
}
|
|
33
|
+
/** One provider's sweep: what it ended, or why it could not sweep, in words. */
|
|
34
|
+
export type ProviderSweep = {
|
|
35
|
+
readonly provider: string;
|
|
36
|
+
readonly swept: Result<Swept>;
|
|
37
|
+
};
|
|
38
|
+
/** One sweep of every provider this server can list: each provider whose keys it has and whose computers the janitor
|
|
39
|
+
* ends, its computers past their deadline that are this server's and unheld ended. A provider that fails is answered
|
|
40
|
+
* in its words; nothing throws. */
|
|
41
|
+
export declare function sweepServerComputers(deps: Pick<JanitorDeps, "store" | "computers" | "now" | "providerMs">, signal?: AbortSignal): Promise<ProviderSweep[]>;
|
|
42
|
+
/** The janitor: one sweep now, then one every `everyMs`, never two at once. `close()` stops it, cuts a sweep under way
|
|
43
|
+
* and waits for it at most `closeMs`. Under --faux it does nothing. */
|
|
44
|
+
export declare function startJanitor(deps: JanitorDeps): {
|
|
45
|
+
readonly first: Promise<void>;
|
|
46
|
+
close(): Promise<void>;
|
|
47
|
+
};
|