@parcha/agentrun-serve 0.1.0-beta.35 → 0.1.0-beta.37
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 +298 -0
- package/README.md +417 -219
- package/dist/adapters.d.ts +12 -2
- package/dist/adapters.js +27 -2
- package/dist/agent-rows.d.ts +2 -1
- package/dist/agents-store.d.ts +2 -0
- package/dist/agents-store.js +9 -4
- package/dist/api-only.d.ts +2 -1
- package/dist/api-only.js +3 -1
- package/dist/archil-routes.d.ts +40 -7
- package/dist/archil-routes.js +167 -54
- package/dist/archil-settings.d.ts +79 -7
- package/dist/archil-settings.js +140 -14
- package/dist/attach-conformance-cli.d.ts +1 -0
- package/dist/attach-conformance-cli.js +18 -0
- package/dist/attach-conformance.d.ts +25 -0
- package/dist/attach-conformance.js +343 -0
- package/dist/attach-images.d.ts +15 -0
- package/dist/attach-images.js +59 -0
- package/dist/background.d.ts +0 -6
- package/dist/background.js +0 -28
- package/dist/box-image.d.ts +1 -97
- package/dist/box-image.js +4 -284
- package/dist/box-paths.d.ts +2 -7
- package/dist/box-paths.js +7 -13
- package/dist/box-settings.d.ts +0 -11
- package/dist/box-settings.js +4 -29
- package/dist/browser-commands.js +1 -1
- package/dist/browser-computer.d.ts +47 -3
- package/dist/browser-computer.js +286 -18
- package/dist/browser-cost.d.ts +1 -1
- package/dist/browser-live.d.ts +20 -8
- package/dist/browser-live.js +50 -27
- package/dist/browser-person.d.ts +19 -2
- package/dist/browser-person.js +55 -6
- package/dist/browser-wait-ended.d.ts +23 -0
- package/dist/browser-wait-ended.js +42 -0
- package/dist/cap.d.ts +12 -57
- package/dist/cap.js +20 -160
- package/dist/catalog.d.ts +1 -12
- package/dist/catalog.js +3 -33
- package/dist/cli.js +17 -26
- package/dist/composio-preset.d.ts +36 -0
- package/dist/composio-preset.js +179 -0
- package/dist/computer-attach.d.ts +125 -0
- package/dist/computer-attach.js +330 -0
- package/dist/computer-calls.d.ts +48 -0
- package/dist/computer-calls.js +126 -0
- package/dist/computer-channel.d.ts +57 -0
- package/dist/computer-channel.js +115 -0
- package/dist/computer-commands.d.ts +1 -1
- package/dist/computer-held-routes.d.ts +35 -0
- package/dist/computer-held-routes.js +106 -0
- package/dist/computer-held.d.ts +48 -0
- package/dist/computer-held.js +87 -0
- package/dist/computer-keys.d.ts +21 -1
- package/dist/computer-keys.js +53 -11
- package/dist/computer-live.d.ts +160 -0
- package/dist/computer-live.js +643 -0
- package/dist/computer-routes.d.ts +1 -4
- package/dist/computer-routes.js +3 -5
- package/dist/computer-setting.d.ts +2 -0
- package/dist/computer-setting.js +38 -1
- package/dist/computer-view.d.ts +24 -2
- package/dist/computer-view.js +51 -3
- package/dist/computer-viewer.d.ts +6 -0
- package/dist/computer-viewer.js +297 -0
- package/dist/computers.d.ts +79 -12
- package/dist/computers.js +147 -28
- package/dist/console/assets/index-Cn6JX1uH.js +563 -0
- package/dist/console/assets/index-DRN62V5v.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/docker-daemon.d.ts +2 -2
- package/dist/docker-daemon.js +2 -2
- package/dist/errors.js +5 -5
- package/dist/faux-computers.d.ts +9 -20
- package/dist/faux-computers.js +56 -24
- package/dist/files.d.ts +1 -9
- package/dist/files.js +1 -9
- package/dist/github-connection.d.ts +10 -2
- package/dist/github-connection.js +65 -2
- package/dist/github-faux.js +1 -1
- package/dist/github.d.ts +22 -2
- package/dist/github.js +42 -8
- package/dist/gpu-words.d.ts +14 -0
- package/dist/gpu-words.js +21 -0
- package/dist/graph-view.d.ts +3 -1
- package/dist/graph-view.js +25 -1
- package/dist/handed-values.d.ts +1 -1
- package/dist/handed-values.js +1 -1
- package/dist/harness-install.d.ts +60 -3
- package/dist/harness-install.js +322 -34
- package/dist/harness.d.ts +1 -0
- package/dist/harness.js +36 -2
- package/dist/host-tools.d.ts +9 -10
- package/dist/host-tools.js +7 -7
- package/dist/hosted-search.d.ts +5 -4
- package/dist/hosted-search.js +2 -7
- package/dist/import-sources.d.ts +10 -0
- package/dist/import-sources.js +44 -2
- package/dist/import.d.ts +3 -3
- package/dist/import.js +37 -6
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -2
- package/dist/key-refusal.d.ts +1 -1
- package/dist/key-refusal.js +2 -2
- package/dist/learn/check.d.ts +11 -2
- package/dist/learn/check.js +124 -6
- package/dist/learn/commit.d.ts +43 -7
- package/dist/learn/commit.js +166 -22
- package/dist/learn/folder.d.ts +11 -0
- package/dist/learn/folder.js +37 -1
- package/dist/learn/general.d.ts +66 -0
- package/dist/learn/general.js +73 -0
- package/dist/learn/grade.d.ts +22 -1
- package/dist/learn/grade.js +107 -16
- package/dist/learn/index.d.ts +1 -1
- package/dist/learn/index.js +1 -1
- package/dist/learn/learning.sh +12 -1
- package/dist/learn/notes.d.ts +3 -0
- package/dist/learn/notes.js +3 -0
- package/dist/learn/reflect.d.ts +14 -2
- package/dist/learn/reflect.js +54 -30
- package/dist/learn/skills.d.ts +37 -5
- package/dist/learn/skills.js +60 -7
- package/dist/learned-nodes.d.ts +6 -2
- package/dist/learned-workflow.d.ts +43 -9
- package/dist/learned-workflow.js +128 -37
- package/dist/learning-batch.d.ts +283 -0
- package/dist/learning-batch.js +574 -0
- package/dist/learning-cost.d.ts +79 -0
- package/dist/learning-cost.js +69 -0
- package/dist/learning-evals.d.ts +33 -0
- package/dist/learning-evals.js +98 -0
- package/dist/learning-routes.d.ts +32 -4
- package/dist/learning-routes.js +48 -12
- package/dist/learning-words.d.ts +9 -0
- package/dist/learning-words.js +12 -2
- package/dist/learning.d.ts +39 -19
- package/dist/learning.js +88 -46
- package/dist/live/stream.js +6 -3
- package/dist/live/translate.d.ts +4 -3
- package/dist/live/translate.js +8 -4
- package/dist/live-reach.d.ts +37 -0
- package/dist/live-reach.js +62 -0
- package/dist/mcp-gateway.d.ts +9 -0
- package/dist/mcp-gateway.js +60 -11
- package/dist/mcp-oauth.d.ts +57 -7
- package/dist/mcp-oauth.js +133 -18
- package/dist/mcp-private-hosts.d.ts +4 -4
- package/dist/mcp-private-hosts.js +20 -12
- package/dist/mcp-probe.d.ts +27 -3
- package/dist/mcp-probe.js +106 -29
- package/dist/mcp-secret-writes.js +8 -0
- package/dist/mcp-servers-store.d.ts +38 -15
- package/dist/mcp-servers-store.js +120 -23
- package/dist/mcp-store.d.ts +10 -4
- package/dist/mcp-store.js +17 -6
- package/dist/model-form.d.ts +26 -0
- package/dist/model-form.js +80 -0
- package/dist/model.d.ts +5 -5
- package/dist/model.js +29 -16
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.js +586 -64
- package/dist/owner.d.ts +0 -1
- package/dist/owner.js +0 -2
- package/dist/page.d.ts +18 -0
- package/dist/page.js +48 -20
- package/dist/paid-calls.d.ts +1 -1
- package/dist/paid-calls.js +1 -1
- package/dist/place-offers.d.ts +96 -0
- package/dist/place-offers.js +202 -0
- package/dist/place.d.ts +9 -13
- package/dist/place.js +21 -32
- package/dist/port-models.d.ts +2 -1
- package/dist/port-models.js +5 -3
- package/dist/print.d.ts +16 -9
- package/dist/print.js +15 -17
- package/dist/propose.d.ts +4 -0
- package/dist/propose.js +34 -11
- package/dist/provider.js +3 -2
- package/dist/reflect-range.d.ts +8 -1
- package/dist/reflect-range.js +1 -1
- package/dist/run-cut.d.ts +5 -0
- package/dist/run-cut.js +19 -0
- package/dist/run-launch.d.ts +28 -3
- package/dist/run-launch.js +14 -4
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-manifest.d.ts +2 -2
- package/dist/run-manifest.js +2 -2
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-repo.d.ts +20 -0
- package/dist/run-repo.js +63 -0
- package/dist/run-secrets.js +3 -3
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +56 -44
- package/dist/run-view.d.ts +8 -5
- package/dist/run-view.js +18 -10
- package/dist/runnable.d.ts +2 -2
- package/dist/runnable.js +6 -2
- package/dist/runner/adapter-loop.d.ts +39 -8
- package/dist/runner/adapter-loop.js +770 -83
- package/dist/runner/adapter-run-spec.d.ts +36 -7
- package/dist/runner/adapter-run-spec.js +171 -37
- package/dist/runner/adapters/pi-computer.d.ts +7 -0
- package/dist/runner/adapters/pi-computer.js +43 -0
- package/dist/runner/adapters/pi.d.ts +20 -7
- package/dist/runner/adapters/pi.js +111 -26
- package/dist/runner/beside.d.ts +7 -3
- package/dist/runner/beside.js +26 -12
- package/dist/runner/claim-secrets.d.ts +4 -0
- package/dist/runner/claim-secrets.js +6 -1
- package/dist/runner/cli-run-spec.d.ts +27 -3
- package/dist/runner/cli-run-spec.js +198 -74
- package/dist/runner/commands.d.ts +8 -2
- package/dist/runner/commands.js +31 -6
- package/dist/runner/computer-channel.d.ts +34 -0
- package/dist/runner/computer-channel.js +61 -0
- package/dist/runner/conformance/harness.d.ts +0 -1
- package/dist/runner/conformance/harness.js +87 -18
- package/dist/runner/conformance/subject.d.ts +1 -1
- package/dist/runner/dispatch.js +3 -0
- package/dist/runner/end-of-run.d.ts +22 -12
- package/dist/runner/end-of-run.js +38 -16
- package/dist/runner/github-app.d.ts +2 -1
- package/dist/runner/github-app.js +6 -4
- package/dist/runner/harness-loops.js +16 -2
- package/dist/runner/held-run.d.ts +65 -0
- package/dist/runner/held-run.js +158 -0
- package/dist/runner/journal-kinds.d.ts +35 -6
- package/dist/runner/journal-kinds.js +20 -1
- package/dist/runner/journal-reader.d.ts +5 -4
- package/dist/runner/journal-reader.js +12 -10
- package/dist/runner/learning-ask.d.ts +7 -1
- package/dist/runner/learning-ask.js +21 -6
- package/dist/runner/learning-dispatch.d.ts +22 -0
- package/dist/runner/learning-dispatch.js +77 -10
- package/dist/runner/learning-end.d.ts +37 -1
- package/dist/runner/learning-end.js +115 -14
- package/dist/runner/learning-factory.d.ts +1 -1
- package/dist/runner/learning-factory.js +15 -5
- package/dist/runner/learning-loop.d.ts +139 -7
- package/dist/runner/learning-loop.js +369 -32
- package/dist/runner/learning-seed.d.ts +9 -0
- package/dist/runner/learning-seed.js +14 -1
- package/dist/runner/live-ticker.js +1 -0
- package/dist/runner/loop-contract.d.ts +16 -1
- package/dist/runner/loop-contract.js +6 -0
- package/dist/runner/loop.d.ts +10 -2
- package/dist/runner/loop.js +22 -1
- package/dist/runner/main.d.ts +13 -1
- package/dist/runner/main.js +38 -6
- package/dist/runner/mcp-claim.d.ts +11 -4
- package/dist/runner/mcp-claim.js +140 -23
- package/dist/runner/mcp-github.d.ts +4 -2
- package/dist/runner/mcp-github.js +1 -8
- package/dist/runner/mcp-run.d.ts +6 -4
- package/dist/runner/mcp-run.js +16 -3
- package/dist/runner/metrics.d.ts +15 -2
- package/dist/runner/metrics.js +21 -2
- package/dist/runner/model-route.d.ts +3 -0
- package/dist/runner/model-route.js +5 -2
- package/dist/runner/pr-checkout.d.ts +60 -0
- package/dist/runner/pr-checkout.js +176 -0
- package/dist/runner/reflect-hook.d.ts +19 -0
- package/dist/runner/reflect-hook.js +20 -8
- package/dist/runner/runner.d.ts +26 -0
- package/dist/runner/runner.js +231 -27
- package/dist/runner/scratch-sweep.d.ts +13 -0
- package/dist/runner/scratch-sweep.js +62 -0
- package/dist/runner/sessions.d.ts +1 -1
- package/dist/runner/spec-holds.d.ts +8 -3
- package/dist/runner/spec-holds.js +12 -10
- package/dist/runner/store-port.d.ts +7 -2
- package/dist/runner/store-secrets.js +21 -4
- package/dist/runner/subagent.d.ts +44 -0
- package/dist/runner/subagent.js +190 -0
- package/dist/runner/workflow-host.d.ts +24 -3
- package/dist/runner/workflow-host.js +24 -4
- package/dist/runner/workflow-loop.d.ts +6 -3
- package/dist/runner/workflow-loop.js +9 -8
- package/dist/runner/workflow-spec.d.ts +39 -15
- package/dist/runner/workflow-spec.js +143 -40
- package/dist/runs-over-store.d.ts +16 -6
- package/dist/runs-over-store.js +145 -29
- package/dist/seal-key.js +3 -3
- package/dist/sealed-settings-store.d.ts +5 -2
- package/dist/sealed-settings-store.js +10 -4
- package/dist/sealing.js +1 -2
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/secret-writes.d.ts +5 -4
- package/dist/secret-writes.js +5 -4
- package/dist/server-secrets-store.d.ts +4 -3
- package/dist/server-secrets-store.js +15 -9
- package/dist/server-secrets.js +3 -2
- package/dist/server.d.ts +75 -63
- package/dist/server.js +712 -316
- package/dist/settings-wake.d.ts +21 -0
- package/dist/settings-wake.js +59 -0
- package/dist/standard-webhooks.d.ts +4 -1
- package/dist/standard-webhooks.js +8 -4
- package/dist/store/agent-body.d.ts +9 -2
- package/dist/store/agent-body.js +16 -8
- package/dist/store/command-wake.d.ts +12 -0
- package/dist/store/command-wake.js +37 -0
- package/dist/store/deadline.js +9 -5
- package/dist/store/dialect.d.ts +6 -0
- package/dist/store/dialect.js +5 -0
- package/dist/store/index.d.ts +4 -4
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.d.ts +3 -2
- package/dist/store/journal/storage.js +15 -6
- package/dist/store/postgres/connection.js +9 -4
- package/dist/store/postgres/dialect.js +4 -0
- package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
- package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
- package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
- package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
- package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
- package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
- package/dist/store/schema.d.ts +2 -1
- package/dist/store/schema.js +85 -13
- package/dist/store/seal.d.ts +13 -0
- package/dist/store/seal.js +19 -0
- package/dist/store/sqlite/connection.d.ts +5 -0
- package/dist/store/sqlite/connection.js +88 -47
- package/dist/store/sqlite/run-patch.d.ts +25 -7
- package/dist/store/sqlite/run-patch.js +58 -14
- package/dist/store/sqlite/store.js +331 -59
- package/dist/store/store.d.ts +330 -21
- package/dist/store/store.js +34 -2
- package/dist/store-reads/analytics.js +3 -2
- package/dist/store-reads/cap.d.ts +2 -4
- package/dist/store-reads/cap.js +16 -7
- package/dist/store-reads/decisions.d.ts +3 -3
- package/dist/store-reads/decisions.js +3 -6
- package/dist/store-reads/import-summary.d.ts +1 -1
- package/dist/store-reads/journal.d.ts +5 -4
- package/dist/store-reads/journal.js +118 -27
- package/dist/store-reads/learning.d.ts +34 -4
- package/dist/store-reads/learning.js +137 -23
- package/dist/store-reads/runs.d.ts +7 -5
- package/dist/store-reads/runs.js +17 -10
- package/dist/store-reads/stats.js +5 -1
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-view.d.ts +5 -0
- package/dist/store-view.js +70 -29
- package/dist/template-eval.js +8 -5
- package/dist/template-github-permissions.d.ts +22 -8
- package/dist/template-github-permissions.js +35 -15
- package/dist/templates.d.ts +64 -0
- package/dist/templates.js +101 -16
- package/dist/timeline/timeline.d.ts +30 -1
- package/dist/timeline/timeline.js +29 -13
- package/dist/timeline/util.d.ts +4 -0
- package/dist/timeline/util.js +14 -0
- package/dist/tool-blurbs.js +1 -0
- package/dist/tool-budget.d.ts +27 -7
- package/dist/tool-budget.js +21 -9
- package/dist/tool-gate.d.ts +23 -10
- package/dist/tool-gate.js +60 -44
- package/dist/tool-plane.d.ts +46 -28
- package/dist/tool-plane.js +73 -31
- package/dist/tools.d.ts +31 -38
- package/dist/tools.js +117 -74
- package/dist/trigger-adapter.d.ts +4 -0
- package/dist/trigger-secrets-shown.d.ts +2 -2
- package/dist/trigger-secrets-shown.js +1 -1
- package/dist/trigger-signatures.d.ts +26 -6
- package/dist/trigger-signatures.js +44 -8
- package/dist/trigger-targets.d.ts +2 -0
- package/dist/trigger-targets.js +1 -0
- package/dist/trigger-webhook.js +5 -2
- package/dist/triggers.d.ts +10 -6
- package/dist/triggers.js +37 -7
- package/dist/turn-end.d.ts +0 -3
- package/dist/turn-end.js +0 -3
- package/dist/turns.js +16 -1
- package/dist/usage-lines.d.ts +1 -1
- package/dist/validate.d.ts +6 -0
- package/dist/validate.js +41 -4
- package/dist/web-fetch.d.ts +1 -1
- package/dist/web-search.d.ts +10 -5
- package/dist/web-search.js +7 -6
- package/dist/webhooks.d.ts +147 -103
- package/dist/webhooks.js +564 -324
- package/dist/workflow/decision-recovery.d.ts +23 -0
- package/dist/workflow/decision-recovery.js +80 -0
- package/dist/workflow/decisions.d.ts +134 -0
- package/dist/workflow/decisions.js +46 -0
- package/dist/workflow/host-session.d.ts +5 -0
- package/dist/workflow/host-session.js +85 -0
- package/dist/workflow/host-tools.d.ts +3 -0
- package/dist/workflow/host-tools.js +3 -0
- package/dist/workflow/node-runner.d.ts +113 -0
- package/dist/workflow/node-runner.js +270 -0
- package/dist/workflow/node.d.ts +89 -0
- package/dist/workflow/node.js +101 -0
- package/dist/workflow/operator-error.d.ts +4 -0
- package/dist/workflow/operator-error.js +4 -0
- package/dist/workflow/pi-versions.d.ts +32 -0
- package/dist/workflow/pi-versions.js +65 -0
- package/dist/workflow/record-file.d.ts +10 -0
- package/dist/workflow/record-file.js +56 -0
- package/dist/workflow/record-tool.d.ts +77 -0
- package/dist/workflow/record-tool.js +126 -0
- package/dist/workflow/record.d.ts +151 -0
- package/dist/workflow/record.js +401 -0
- package/dist/workflow/run-error.d.ts +16 -0
- package/dist/workflow/run-error.js +26 -0
- package/dist/workflow/runner.d.ts +6 -0
- package/dist/workflow/runner.js +240 -0
- package/dist/workflow/store.d.ts +23 -0
- package/dist/workflow/store.js +242 -0
- package/dist/workflow/task.d.ts +133 -0
- package/dist/workflow/task.js +412 -0
- package/dist/workflow/thinking.d.ts +3 -0
- package/dist/workflow/thinking.js +7 -0
- package/dist/workflow/tool-context.d.ts +21 -0
- package/dist/workflow/tool-context.js +13 -0
- package/dist/workflow/types.d.ts +126 -0
- package/dist/workflow/types.js +1 -0
- package/dist/workflow-run.d.ts +2 -2
- package/dist/workspace/agent-computer.d.ts +137 -0
- package/dist/workspace/agent-computer.js +292 -0
- package/dist/workspace/archil-claim.d.ts +11 -0
- package/dist/workspace/archil-claim.js +18 -10
- package/dist/workspace/archil-disks.d.ts +49 -0
- package/dist/workspace/archil-disks.js +185 -0
- package/dist/workspace/archil-exec.js +2 -3
- package/dist/workspace/archil-mount-credential.d.ts +20 -4
- package/dist/workspace/archil-mount-credential.js +13 -4
- package/dist/workspace/attached-computers.d.ts +41 -0
- package/dist/workspace/attached-computers.js +114 -0
- package/dist/workspace/computer-deps.d.ts +32 -17
- package/dist/workspace/computer-deps.js +37 -14
- package/dist/workspace/computer-for-claim.d.ts +58 -13
- package/dist/workspace/computer-for-claim.js +267 -26
- package/dist/workspace/computer-hold.d.ts +11 -27
- package/dist/workspace/computer-hold.js +36 -56
- package/dist/workspace/computer-janitor.d.ts +3 -2
- package/dist/workspace/computer-janitor.js +43 -9
- package/dist/workspace/computer-ledger.d.ts +5 -1
- package/dist/workspace/computer-ledger.js +11 -0
- package/dist/workspace/computer-mcp.d.ts +25 -0
- package/dist/workspace/computer-mcp.js +41 -0
- package/dist/workspace/computer-ports.d.ts +4 -13
- package/dist/workspace/computer-ports.js +4 -107
- package/dist/workspace/computer-script.d.ts +37 -0
- package/dist/workspace/computer-script.js +138 -0
- package/dist/workspace/executors.d.ts +1 -1
- package/dist/workspace/index.d.ts +7 -4
- package/dist/workspace/index.js +4 -1
- package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
- package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
- package/dist/workspace/resolve-computer.d.ts +45 -11
- package/dist/workspace/resolve-computer.js +72 -14
- package/dist/workspace/run-disk.d.ts +34 -0
- package/dist/workspace/run-disk.js +91 -0
- package/dist/workspace/run-tools.d.ts +35 -18
- package/dist/workspace/run-tools.js +24 -29
- package/dist/workspace/server-run-workspace.d.ts +3 -2
- package/dist/workspace/server-run-workspace.js +17 -4
- package/dist/workspace.js +1 -1
- package/package.json +19 -21
- package/templates/README.md +9 -6
- package/templates/code-review/agent.md +27 -11
- package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
- package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
- package/templates/code-review/evals/injection/graders/ignores.md +1 -1
- package/templates/code-review/evals/never-flag/case.yaml +3 -0
- package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
- package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
- package/templates/code-review/evals/never-flag/prompt.md +30 -0
- package/templates/code-review/evals/null-name/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
- package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
- package/templates/code-review/evals/re-review/prompt.md +1 -1
- package/templates/code-review/evals/re-review-open/case.yaml +3 -0
- package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
- package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
- package/templates/code-review/evals/re-review-open/prompt.md +27 -0
- package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
- package/templates/code-review/evals/two-defects/case.yaml +3 -0
- package/templates/code-review/evals/two-defects/graders/both.md +4 -0
- package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
- package/templates/code-review/evals/two-defects/prompt.md +25 -0
- package/templates/code-review/findings.schema.json +131 -27
- package/templates/code-review/rules/CODEREVIEW.md +76 -0
- package/templates/code-review/skills/review/DEEP.md +130 -0
- package/templates/code-review/skills/review/REVIEWER.md +116 -0
- package/templates/code-review/skills/review/SKILL.md +104 -154
- package/templates/market-monitor/agent.md +1 -1
- package/dist/box/record.d.ts +0 -6
- package/dist/box/record.js +0 -41
- package/dist/box/sweep.d.ts +0 -53
- package/dist/box/sweep.js +0 -193
- package/dist/box-egress-vm.d.ts +0 -118
- package/dist/box-egress-vm.js +0 -354
- package/dist/box-egress.d.ts +0 -105
- package/dist/box-egress.js +0 -256
- package/dist/box-relay-vm.d.ts +0 -84
- package/dist/box-relay-vm.js +0 -437
- package/dist/box-relay.d.ts +0 -36
- package/dist/box-relay.js +0 -207
- package/dist/boxes.d.ts +0 -109
- package/dist/boxes.js +0 -249
- package/dist/budget.d.ts +0 -71
- package/dist/budget.js +0 -199
- package/dist/console/assets/index-B7NKTU8E.css +0 -1
- package/dist/console/assets/index-CXZMgJE7.js +0 -550
- package/dist/daytona-api.d.ts +0 -10
- package/dist/daytona-api.js +0 -20
- package/dist/egress-proxy.d.ts +0 -45
- package/dist/egress-proxy.js +0 -416
- package/dist/egress-table.d.ts +0 -24
- package/dist/egress-table.js +0 -165
- package/dist/run-db.d.ts +0 -53
- package/dist/run-db.js +0 -116
- package/templates/code-review/rules/REVIEW.md +0 -41
package/dist/box-relay-vm.js
DELETED
|
@@ -1,437 +0,0 @@
|
|
|
1
|
-
// The box relay's VM half: how a run's process reaches its VM box without the VM provider's token. The token and the SDK
|
|
2
|
-
// client are the server's alone (boxes.ts, BOX_KEYS), so a run's process runs pi-transport's VM provider over a client of
|
|
3
|
-
// its own (relayedVmSdk) whose every call comes here, on loopback with its run's own door token (box-relay.ts checks it),
|
|
4
|
-
// and is made here with the server's client only when it is one of the calls a run's tools make of that run's own box:
|
|
5
|
-
// find it, read its state and its tags, start a program in it, and that program's input, output and exit. Nothing else
|
|
6
|
-
// passes: no create, listing, end or tag change (the server makes and seeds the box, pulls its work/ back and ends it),
|
|
7
|
-
// and no call to a sandbox that does not carry the run's label. The SDK speaks gRPC, so the relay carries its calls, not
|
|
8
|
-
// its bytes on the wire: each program started here is held by an id of its own until its exit is read and its output
|
|
9
|
-
// streams are done.
|
|
10
|
-
import { randomUUID } from "node:crypto";
|
|
11
|
-
import { relayAddress } from "./box-relay.js";
|
|
12
|
-
import { redacted } from "./key-refusal.js";
|
|
13
|
-
/** The label that names a box's run (run-box.ts RUN_LABEL), kept here so the run's process loads no more than it needs. */
|
|
14
|
-
const RUN_LABEL = "agentrun.run";
|
|
15
|
-
/** The most bytes one relayed write to a program's input may send. */
|
|
16
|
-
const MAX_INPUT_BYTES = 64 * 2 ** 20;
|
|
17
|
-
/** The most programs one run may hold here at once. */
|
|
18
|
-
const MAX_EXECS_PER_RUN = 64;
|
|
19
|
-
/** How many bytes of a program's output stream the relay holds before it stops reading the stream, until the run's
|
|
20
|
-
* process reads them. */
|
|
21
|
-
const MAX_BUFFERED_BYTES = 16 * 2 ** 20;
|
|
22
|
-
/** How long a program the run's process stopped asking about is held, once it exited. A program is let go:
|
|
23
|
-
* - once its exit was read (or failed to be) and both its output replies ended, whole or broken (settle);
|
|
24
|
-
* - at once when a caller goes away mid-read (the reply's close);
|
|
25
|
-
* - at the run's end (drop), whatever it is doing, a program still starting then included, as it lands;
|
|
26
|
-
* - else EXEC_KEEP_MS after its exit: an exit or an output not read yet is still the caller's to read.
|
|
27
|
-
* A program still running holds its slot until it exits or the run ends. */
|
|
28
|
-
const EXEC_KEEP_MS = 10 * 60_000;
|
|
29
|
-
/** The most programs let go after their exit that the relay remembers as ended, oldest first out. A call the run's
|
|
30
|
-
* process makes of one after it was let go (its input's close, sent apart from its exit's read, can land after it) is
|
|
31
|
-
* answered as already ended, not as no such program. A count, not a clock: the late call comes within moments of the
|
|
32
|
-
* exit, and a count bounds what is held however fast programs end, at about 100 bytes each. */
|
|
33
|
-
const ENDED_MAX = 4096;
|
|
34
|
-
/** The most sandboxes the relay remembers the run of; past it, it asks the provider again. */
|
|
35
|
-
const KNOWN_MAX = 1024;
|
|
36
|
-
/** Its message is the SDK's, which can quote anything: cut of every value the server holds, and of secret-shaped text,
|
|
37
|
-
* by serve's one rule (key-refusal.ts redacted), before it goes to the run's process. */
|
|
38
|
-
const failureOf = (error, secrets = []) => {
|
|
39
|
-
const name = error?.constructor?.name ?? "Error";
|
|
40
|
-
const code = error?.code;
|
|
41
|
-
return { name, ...(typeof code === "number" ? { code } : {}), message: redacted(String(error?.message ?? error), secrets).slice(0, 300) };
|
|
42
|
-
};
|
|
43
|
-
function pump(source) {
|
|
44
|
-
const iterator = source[Symbol.asyncIterator]();
|
|
45
|
-
const state = {
|
|
46
|
-
chunks: [], bytes: 0, done: false, cancelled: false,
|
|
47
|
-
// Let go: what it holds is dropped, the source's read is ended, and whoever waits on it is woken.
|
|
48
|
-
cancel() {
|
|
49
|
-
if (state.cancelled)
|
|
50
|
-
return;
|
|
51
|
-
state.cancelled = true;
|
|
52
|
-
state.chunks.length = 0;
|
|
53
|
-
state.bytes = 0;
|
|
54
|
-
state.done = true;
|
|
55
|
-
void Promise.resolve(iterator.return?.()).catch(() => undefined);
|
|
56
|
-
state.space?.();
|
|
57
|
-
state.wake?.();
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
void (async () => {
|
|
61
|
-
try {
|
|
62
|
-
for (;;) {
|
|
63
|
-
const next = await iterator.next();
|
|
64
|
-
if (next.done || state.cancelled)
|
|
65
|
-
break;
|
|
66
|
-
state.chunks.push(next.value);
|
|
67
|
-
state.bytes += next.value.length;
|
|
68
|
-
state.wake?.();
|
|
69
|
-
while (state.bytes > MAX_BUFFERED_BYTES && !state.cancelled)
|
|
70
|
-
await new Promise((resolve) => (state.space = resolve));
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
if (!state.cancelled)
|
|
75
|
-
state.failure = error ?? new Error("the stream failed");
|
|
76
|
-
}
|
|
77
|
-
state.done = true;
|
|
78
|
-
state.wake?.();
|
|
79
|
-
})();
|
|
80
|
-
return state;
|
|
81
|
-
}
|
|
82
|
-
/** The relay's handler of a run's VM calls, over the server's client `sdk`: `handle(runId, path, req, res)` answers the
|
|
83
|
-
* call at `path` (what follows `/runs/<id>/vm/`), the caller's token already checked. `drop(runId)` lets go of the run's
|
|
84
|
-
* programs (at its end). */
|
|
85
|
-
export function vmRelay(sdk, secrets = () => []) {
|
|
86
|
-
const known = new Map();
|
|
87
|
-
const execs = new Map();
|
|
88
|
-
/** The programs let go after their exit (forget), by id: their run and their exit code, or why it could not be read,
|
|
89
|
-
* up to ENDED_MAX. */
|
|
90
|
-
const ended = new Map();
|
|
91
|
-
/** The program starts each run has under way, from the moment its request is taken (before the sandbox's lookup): each
|
|
92
|
-
* counts toward the run's limit, and one its run's end (drop) marks is let go as it lands, never held. A run is here
|
|
93
|
-
* only while it has one, so an ended run leaves nothing behind. */
|
|
94
|
-
const starting = new Map();
|
|
95
|
-
const startOf = (runId) => {
|
|
96
|
-
const start = { dropped: false };
|
|
97
|
-
const starts = starting.get(runId) ?? new Set();
|
|
98
|
-
starts.add(start);
|
|
99
|
-
starting.set(runId, starts);
|
|
100
|
-
return start;
|
|
101
|
-
};
|
|
102
|
-
const started = (runId, start) => {
|
|
103
|
-
const starts = starting.get(runId);
|
|
104
|
-
starts?.delete(start);
|
|
105
|
-
if (starts && !starts.size)
|
|
106
|
-
starting.delete(runId);
|
|
107
|
-
};
|
|
108
|
-
/** Sandbox `id` and the run its label names, as the provider says; undefined when it has none. */
|
|
109
|
-
const sandboxOf = async (id) => {
|
|
110
|
-
const held = known.get(id);
|
|
111
|
-
if (held)
|
|
112
|
-
return held;
|
|
113
|
-
const sandbox = await sdk.sandboxes.fromId(id);
|
|
114
|
-
const tags = await sandbox.getTags();
|
|
115
|
-
const value = { sandbox, run: typeof tags[RUN_LABEL] === "string" ? tags[RUN_LABEL] : undefined };
|
|
116
|
-
if (known.size >= KNOWN_MAX)
|
|
117
|
-
known.clear();
|
|
118
|
-
known.set(id, value);
|
|
119
|
-
return value;
|
|
120
|
-
};
|
|
121
|
-
const answer = (res, status, body) => {
|
|
122
|
-
res.writeHead(status, { "content-type": "application/json", "cache-control": "no-store" });
|
|
123
|
-
res.end(JSON.stringify(body));
|
|
124
|
-
};
|
|
125
|
-
const failed = (res, error) => void (res.headersSent ? res.destroy() : answer(res, 502, { failure: failureOf(error, secrets()) }));
|
|
126
|
-
const notThere = (res) => answer(res, 404, { failure: { name: "NotFoundError", code: 5, message: "no such sandbox" } });
|
|
127
|
-
const refused = (res, path) => answer(res, 403, { message: `the box relay does not make ${path}: a run's process reaches only its own box's programs and files` });
|
|
128
|
-
const forget = (id) => {
|
|
129
|
-
const held = execs.get(id);
|
|
130
|
-
if (held?.timer)
|
|
131
|
-
clearTimeout(held.timer);
|
|
132
|
-
// Its streams' reads end with it, and a reply still writing one is let go.
|
|
133
|
-
held?.streams.stdout.cancel();
|
|
134
|
-
held?.streams.stderr.cancel();
|
|
135
|
-
execs.delete(id);
|
|
136
|
-
if (held?.exited === undefined)
|
|
137
|
-
return;
|
|
138
|
-
ended.set(id, { run: held.run, code: held.exited, ...(held.lost === undefined ? {} : { lost: failureOf(held.lost, secrets()) }) });
|
|
139
|
-
if (ended.size > ENDED_MAX)
|
|
140
|
-
ended.delete(ended.keys().next().value);
|
|
141
|
-
};
|
|
142
|
-
/** A program is let go once its exit was read and both its streams' replies ended (delivered whole, or broken because
|
|
143
|
-
* the stream failed), or EXEC_KEEP_MS after its exit. */
|
|
144
|
-
const settle = (id) => {
|
|
145
|
-
const held = execs.get(id);
|
|
146
|
-
if (!held || held.exited === undefined)
|
|
147
|
-
return;
|
|
148
|
-
if (held.waited && held.finished.size === 2)
|
|
149
|
-
return forget(id);
|
|
150
|
-
held.timer ??= setTimeout(() => forget(id), EXEC_KEEP_MS);
|
|
151
|
-
held.timer.unref?.();
|
|
152
|
-
};
|
|
153
|
-
async function handle(runId, path, req, res) {
|
|
154
|
-
if (req.method !== "POST")
|
|
155
|
-
return answer(res, 405, { message: "the Modal sandbox relay takes POST" });
|
|
156
|
-
const onSandbox = /^sandbox\/([^/]+)\/(find|poll|tags|exec)$/.exec(path);
|
|
157
|
-
// A start is under way from here: a run's end while its sandbox is looked up, or its program started, still finds it.
|
|
158
|
-
const start = onSandbox?.[2] === "exec" ? startOf(runId) : undefined;
|
|
159
|
-
if (onSandbox)
|
|
160
|
-
try {
|
|
161
|
-
const id = decodeURIComponent(onSandbox[1]);
|
|
162
|
-
let found;
|
|
163
|
-
try {
|
|
164
|
-
found = await sandboxOf(id);
|
|
165
|
-
}
|
|
166
|
-
catch (error) {
|
|
167
|
-
return failureOf(error).name === "NotFoundError" || failureOf(error).code === 5 ? notThere(res) : failed(res, error);
|
|
168
|
-
}
|
|
169
|
-
// A sandbox of another run, or of none, is not there for this one: as the provider answers one it does not have.
|
|
170
|
-
if (found.run !== runId)
|
|
171
|
-
return notThere(res);
|
|
172
|
-
try {
|
|
173
|
-
switch (onSandbox[2]) {
|
|
174
|
-
case "find":
|
|
175
|
-
return answer(res, 200, { id });
|
|
176
|
-
case "poll":
|
|
177
|
-
return answer(res, 200, { code: await found.sandbox.poll() });
|
|
178
|
-
case "tags":
|
|
179
|
-
return answer(res, 200, { tags: await found.sandbox.getTags() });
|
|
180
|
-
default: {
|
|
181
|
-
const body = (await jsonOf(req));
|
|
182
|
-
const command = body?.command;
|
|
183
|
-
if (!Array.isArray(command) || !command.length || !command.every((part) => typeof part === "string"))
|
|
184
|
-
return answer(res, 400, { message: "exec names its command: a list of strings" });
|
|
185
|
-
// Its slot was taken as the request came (startOf), and is given back once the program is held or did not start.
|
|
186
|
-
const others = (starting.get(runId)?.size ?? 1) - 1;
|
|
187
|
-
if ([...execs.values()].filter((held) => held.run === runId).length + others >= MAX_EXECS_PER_RUN)
|
|
188
|
-
return answer(res, 429, { message: `a run holds at most ${MAX_EXECS_PER_RUN} programs in its box at once` });
|
|
189
|
-
const process = await found.sandbox.exec(command, { mode: "binary", ...(typeof body?.workdir === "string" ? { workdir: body.workdir } : {}), ...(typeof body?.timeoutMs === "number" ? { timeoutMs: body.timeoutMs } : {}) });
|
|
190
|
-
// The run's programs were let go while this one started (its end): it is let go too, its output never read.
|
|
191
|
-
if (start.dropped) {
|
|
192
|
-
for (const stream of [process.stdout, process.stderr])
|
|
193
|
-
void Promise.resolve(stream[Symbol.asyncIterator]().return?.()).catch(() => undefined);
|
|
194
|
-
return answer(res, 410, { message: "the run ended while the program started: it is not held" });
|
|
195
|
-
}
|
|
196
|
-
const exec = randomUUID();
|
|
197
|
-
const held = { run: runId, process, streams: { stdout: pump(process.stdout), stderr: pump(process.stderr) }, waited: false, read: new Set(), finished: new Set() };
|
|
198
|
-
execs.set(exec, held);
|
|
199
|
-
process.wait().then((code) => {
|
|
200
|
-
held.exited = code;
|
|
201
|
-
settle(exec);
|
|
202
|
-
}, (error) => {
|
|
203
|
-
held.lost ??= error ?? new Error("the program's exit could not be read");
|
|
204
|
-
held.exited = -1;
|
|
205
|
-
settle(exec);
|
|
206
|
-
});
|
|
207
|
-
return answer(res, 200, { exec });
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
catch (error) {
|
|
212
|
-
return failed(res, error);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
finally {
|
|
216
|
-
if (start)
|
|
217
|
-
started(runId, start);
|
|
218
|
-
}
|
|
219
|
-
const onExec = /^exec\/([^/]+)\/(stdin|stdin-close|stdout|stderr|wait)$/.exec(path);
|
|
220
|
-
if (!onExec)
|
|
221
|
-
return refused(res, path);
|
|
222
|
-
const id = decodeURIComponent(onExec[1]);
|
|
223
|
-
const held = execs.get(id);
|
|
224
|
-
const over = held ? undefined : ended.get(id);
|
|
225
|
-
// A program of this run let go after its exit: its input takes nothing more, and its exit is still its exit (an exit
|
|
226
|
-
// that could not be read still fails). Its output is not held any more, and a read of it fails rather than come back
|
|
227
|
-
// short.
|
|
228
|
-
if (over?.run === runId) {
|
|
229
|
-
req.resume();
|
|
230
|
-
if (onExec[2] === "stdout" || onExec[2] === "stderr")
|
|
231
|
-
return answer(res, 410, { message: `the program ended and was let go: its ${onExec[2]} is no longer held` });
|
|
232
|
-
if (onExec[2] === "wait")
|
|
233
|
-
return over.lost ? answer(res, 502, { failure: over.lost }) : answer(res, 200, { code: over.code, ended: true });
|
|
234
|
-
return answer(res, 200, { ended: true });
|
|
235
|
-
}
|
|
236
|
-
// Another run's program is not there for this one.
|
|
237
|
-
if (!held || held.run !== runId)
|
|
238
|
-
return answer(res, 404, { message: "no such program" });
|
|
239
|
-
try {
|
|
240
|
-
switch (onExec[2]) {
|
|
241
|
-
case "stdin": {
|
|
242
|
-
const bytes = await bytesOf(req);
|
|
243
|
-
if (bytes === null)
|
|
244
|
-
return answer(res, 413, { message: `a write sends at most ${MAX_INPUT_BYTES} bytes` });
|
|
245
|
-
await held.process.stdin.writeBytes(new Uint8Array(bytes));
|
|
246
|
-
return answer(res, 200, {});
|
|
247
|
-
}
|
|
248
|
-
case "stdin-close":
|
|
249
|
-
await held.process.stdin.close();
|
|
250
|
-
return answer(res, 200, {});
|
|
251
|
-
case "wait": {
|
|
252
|
-
// The exit is read whether the provider gives it or fails to: either way the caller has its answer, and the
|
|
253
|
-
// program goes once its streams' replies have ended.
|
|
254
|
-
let code;
|
|
255
|
-
try {
|
|
256
|
-
code = await held.process.wait();
|
|
257
|
-
}
|
|
258
|
-
catch (error) {
|
|
259
|
-
held.waited = true;
|
|
260
|
-
held.lost ??= error ?? new Error("the program's exit could not be read");
|
|
261
|
-
held.exited ??= -1;
|
|
262
|
-
failed(res, error);
|
|
263
|
-
return settle(id);
|
|
264
|
-
}
|
|
265
|
-
held.waited = true;
|
|
266
|
-
answer(res, 200, { code });
|
|
267
|
-
return settle(id);
|
|
268
|
-
}
|
|
269
|
-
default: {
|
|
270
|
-
const name = onExec[2];
|
|
271
|
-
if (held.read.has(name))
|
|
272
|
-
return answer(res, 409, { message: `the program's ${name} is read once` });
|
|
273
|
-
held.read.add(name);
|
|
274
|
-
const stream = held.streams[name];
|
|
275
|
-
res.writeHead(200, { "content-type": "application/octet-stream", "cache-control": "no-store" });
|
|
276
|
-
// A caller that goes away (its process ended, or it stopped reading) lets the stream go: its read is ended and
|
|
277
|
-
// nothing waits on it.
|
|
278
|
-
let gone = false;
|
|
279
|
-
let woke = () => { };
|
|
280
|
-
res.once("close", () => {
|
|
281
|
-
if (res.writableFinished)
|
|
282
|
-
return;
|
|
283
|
-
gone = true;
|
|
284
|
-
stream.cancel();
|
|
285
|
-
woke();
|
|
286
|
-
});
|
|
287
|
-
for (;;) {
|
|
288
|
-
while (stream.chunks.length && !gone) {
|
|
289
|
-
const chunk = stream.chunks.shift();
|
|
290
|
-
stream.bytes -= chunk.length;
|
|
291
|
-
stream.space?.();
|
|
292
|
-
if (!res.write(chunk))
|
|
293
|
-
await new Promise((resolve) => {
|
|
294
|
-
woke = resolve;
|
|
295
|
-
res.once("drain", resolve);
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
if (stream.done || gone)
|
|
299
|
-
break;
|
|
300
|
-
await new Promise((resolve) => (stream.wake = woke = resolve));
|
|
301
|
-
}
|
|
302
|
-
if (gone)
|
|
303
|
-
return void forget(id);
|
|
304
|
-
// A stream that broke, or was let go before it was all sent (the run's end), is a broken answer, never a short
|
|
305
|
-
// one: the caller sees its read fail.
|
|
306
|
-
if (stream.failure !== undefined || stream.cancelled)
|
|
307
|
-
res.destroy();
|
|
308
|
-
else
|
|
309
|
-
res.end();
|
|
310
|
-
// Ended either way: a failed stream holds no slot once its exit is read too.
|
|
311
|
-
held.finished.add(name);
|
|
312
|
-
settle(id);
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
catch (error) {
|
|
318
|
-
return failed(res, error);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
return {
|
|
322
|
-
handle,
|
|
323
|
-
drop(runId) {
|
|
324
|
-
for (const start of starting.get(runId) ?? [])
|
|
325
|
-
start.dropped = true;
|
|
326
|
-
for (const [id, held] of execs)
|
|
327
|
-
if (held.run === runId)
|
|
328
|
-
forget(id);
|
|
329
|
-
},
|
|
330
|
-
/** What the relay holds now, for the tests: its programs, and the runs with a start under way. */
|
|
331
|
-
footprint: () => ({ programs: execs.size, starting: starting.size }),
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
async function bytesOf(req) {
|
|
335
|
-
const parts = [];
|
|
336
|
-
let size = 0;
|
|
337
|
-
for await (const part of req) {
|
|
338
|
-
size += part.length;
|
|
339
|
-
if (size > MAX_INPUT_BYTES)
|
|
340
|
-
return null;
|
|
341
|
-
parts.push(part);
|
|
342
|
-
}
|
|
343
|
-
return Buffer.concat(parts);
|
|
344
|
-
}
|
|
345
|
-
const jsonOf = async (req) => {
|
|
346
|
-
const bytes = await bytesOf(req);
|
|
347
|
-
try {
|
|
348
|
-
return bytes ? JSON.parse(bytes.toString("utf8") || "null") : null;
|
|
349
|
-
}
|
|
350
|
-
catch {
|
|
351
|
-
return null;
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
/** An error as the SDK would throw it, from the relay's answer: its class's name, so pi-transport's provider reads it the
|
|
355
|
-
* same (NotFoundError, a gRPC code). */
|
|
356
|
-
function errorOf(failure, fallback) {
|
|
357
|
-
const name = failure?.name && /^[A-Za-z]+$/.test(failure.name) ? failure.name : "Error";
|
|
358
|
-
const Named = { [name]: class extends Error {
|
|
359
|
-
} }[name];
|
|
360
|
-
return Object.assign(new Named(failure?.message ?? fallback), typeof failure?.code === "number" ? { code: failure.code } : {});
|
|
361
|
-
}
|
|
362
|
-
/** How the run's process's relay client waits on the relay: never on a clock of its own. A program's exit (`wait`) and
|
|
363
|
-
* its output streams take as long as the program runs, which its caller bounds (bash's timeout, and pi-transport's
|
|
364
|
-
* backstop over it); Node's own fetch would give up after 300 s with no answer or no bytes, failing a longer command
|
|
365
|
-
* as lost. */
|
|
366
|
-
export const RELAY_AGENT_OPTIONS = Object.freeze({ headersTimeout: 0, bodyTimeout: 0 });
|
|
367
|
-
/** The SDK client a run's process hands pi-transport's VM provider: each call it makes of a box goes to the relay in data
|
|
368
|
-
* root `root`, with the run's own door token. It finds a sandbox and runs programs in it; it makes, lists and ends none. */
|
|
369
|
-
export function relayedVmSdk(root, runDir, runId, agentOptions = RELAY_AGENT_OPTIONS) {
|
|
370
|
-
// Its own dispatcher, with the waits above: made at its first call, kept for the process.
|
|
371
|
-
let opened;
|
|
372
|
-
const open = () => (opened ??= import("undici").then(({ Agent, fetch }) => ({ dispatcher: new Agent(agentOptions), dial: fetch })));
|
|
373
|
-
const call = async (path, body, json = true) => {
|
|
374
|
-
const [{ url, token }, { dispatcher, dial }] = await Promise.all([relayAddress(root, runDir), open()]);
|
|
375
|
-
return dial(`${url}/runs/${encodeURIComponent(runId)}/vm/${path}`, { method: "POST", headers: { authorization: `Bearer ${token}`, ...(json ? { "content-type": "application/json" } : { "content-type": "application/octet-stream" }) }, ...(body === undefined ? {} : { body: body }), redirect: "error", dispatcher });
|
|
376
|
-
};
|
|
377
|
-
const result = async (path, body) => {
|
|
378
|
-
const answer = await call(path, body === undefined ? undefined : JSON.stringify(body));
|
|
379
|
-
const value = (await answer.json().catch(() => null));
|
|
380
|
-
if (!answer.ok)
|
|
381
|
-
throw errorOf(value?.failure, value?.message ?? `the box relay answered ${answer.status}`);
|
|
382
|
-
return value;
|
|
383
|
-
};
|
|
384
|
-
/** A program's output stream: read from the relay once its reader starts, failing as the relay's answer fails. */
|
|
385
|
-
const stream = (exec, name) => ({
|
|
386
|
-
async *[Symbol.asyncIterator]() {
|
|
387
|
-
const answer = await call(`exec/${exec}/${name}`);
|
|
388
|
-
if (!answer.ok || !answer.body)
|
|
389
|
-
throw errorOf(undefined, `the box relay answered ${answer.status} to the program's ${name}`);
|
|
390
|
-
for await (const chunk of answer.body)
|
|
391
|
-
yield chunk;
|
|
392
|
-
},
|
|
393
|
-
});
|
|
394
|
-
const sandbox = (sandboxId) => {
|
|
395
|
-
const at = `sandbox/${encodeURIComponent(sandboxId)}`;
|
|
396
|
-
return {
|
|
397
|
-
sandboxId,
|
|
398
|
-
poll: async () => (await result(`${at}/poll`, {})).code,
|
|
399
|
-
getTags: async () => (await result(`${at}/tags`, {})).tags,
|
|
400
|
-
terminate: async () => {
|
|
401
|
-
throw new Error("a run's process ends no box: the server does");
|
|
402
|
-
},
|
|
403
|
-
exec: async (command, params) => {
|
|
404
|
-
const { exec } = await result(`${at}/exec`, { command, ...(params.workdir ? { workdir: params.workdir } : {}), ...(params.timeoutMs === undefined ? {} : { timeoutMs: params.timeoutMs }) });
|
|
405
|
-
const id = encodeURIComponent(exec);
|
|
406
|
-
return {
|
|
407
|
-
stdin: {
|
|
408
|
-
writeBytes: async (bytes) => {
|
|
409
|
-
const answer = await call(`exec/${id}/stdin`, bytes, false);
|
|
410
|
-
if (!answer.ok)
|
|
411
|
-
throw errorOf((await answer.json().catch(() => null))?.failure, `the box relay answered ${answer.status} to a write`);
|
|
412
|
-
},
|
|
413
|
-
close: async () => void (await result(`exec/${id}/stdin-close`, {})),
|
|
414
|
-
},
|
|
415
|
-
stdout: stream(id, "stdout"),
|
|
416
|
-
stderr: stream(id, "stderr"),
|
|
417
|
-
wait: async () => (await result(`exec/${id}/wait`, {})).code,
|
|
418
|
-
};
|
|
419
|
-
},
|
|
420
|
-
};
|
|
421
|
-
};
|
|
422
|
-
const none = (what) => () => {
|
|
423
|
-
throw new Error(`a run's process ${what} no box: the server does`);
|
|
424
|
-
};
|
|
425
|
-
return {
|
|
426
|
-
apps: { fromName: none("names") },
|
|
427
|
-
images: { fromRegistry: none("names"), fromId: none("names") },
|
|
428
|
-
sandboxes: {
|
|
429
|
-
create: none("makes"),
|
|
430
|
-
list: none("lists"),
|
|
431
|
-
fromId: async (id) => {
|
|
432
|
-
await result(`sandbox/${encodeURIComponent(id)}/find`, {});
|
|
433
|
-
return sandbox(id);
|
|
434
|
-
},
|
|
435
|
-
},
|
|
436
|
-
};
|
|
437
|
-
}
|
package/dist/box-relay.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { vmRelay } from "./box-relay-vm.js";
|
|
2
|
-
/** The relay's address in the data directory: `{"url": "http://<loopback>:<port>"}`. */
|
|
3
|
-
export declare const BOX_RELAY_FILE = ".box-relay";
|
|
4
|
-
export type BoxRelayOptions = {
|
|
5
|
-
/** The data directory: where the relay's address goes. */
|
|
6
|
-
root: string;
|
|
7
|
-
/** Run `runId`'s own door token, which a call for that run must carry; undefined for a run that has none. */
|
|
8
|
-
tokenOf(runId: string): string | undefined;
|
|
9
|
-
/** Daytona's API and the server's key for it; absent on a server with no Daytona box. */
|
|
10
|
-
apiUrl?: string;
|
|
11
|
-
apiKey?: string;
|
|
12
|
-
/** For tests. Default the global `fetch`. */
|
|
13
|
-
fetch?: typeof fetch;
|
|
14
|
-
/** The VM half (box-relay-vm.ts), on a server with the VM box. */
|
|
15
|
-
vm?: ReturnType<typeof vmRelay>;
|
|
16
|
-
/** Whether `runId` is a run this server holds in a remote box that has not ended. */
|
|
17
|
-
serves(runId: string): boolean;
|
|
18
|
-
/** The run's box, found by its label or made with its work/ seeded (run-box.ts ensureRemoteBox): its id, and whether it is new. */
|
|
19
|
-
ensure(runId: string): Promise<{
|
|
20
|
-
id: string;
|
|
21
|
-
made: boolean;
|
|
22
|
-
replaced?: boolean;
|
|
23
|
-
}>;
|
|
24
|
-
};
|
|
25
|
-
export type BoxRelay = {
|
|
26
|
-
url: string;
|
|
27
|
-
close(): Promise<void>;
|
|
28
|
-
};
|
|
29
|
-
/** Starts the relay on loopback and writes its address; `close` stops it and removes the address. */
|
|
30
|
-
export declare function startBoxRelay(options: BoxRelayOptions): Promise<BoxRelay>;
|
|
31
|
-
/** The relay's address, from the data directory `root`, and the run's own door token, from its directory `runDir`: read
|
|
32
|
-
* at each call. */
|
|
33
|
-
export declare function relayAddress(root: string, runDir: string): Promise<{
|
|
34
|
-
url: string;
|
|
35
|
-
token: string;
|
|
36
|
-
}>;
|