@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
package/dist/cap.js
CHANGED
|
@@ -50,9 +50,7 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
50
50
|
import { existsSync } from "node:fs";
|
|
51
51
|
import { providerInputOverhead } from "@parcha/agentrun-kernel/host";
|
|
52
52
|
import { bookRequest, isConnectCode, isGatewayTimeout, rejectionCode } from "@parcha/agentrun-kernel";
|
|
53
|
-
import { CAP_WRAPUP, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, timelineOf, TOOL_COST, TOOL_STARTED } from "
|
|
54
|
-
/** A run's cap in USD, passed to its process. */
|
|
55
|
-
export const CAP_ENV = "AGENTRUN_SERVE_MAX_COST_USD";
|
|
53
|
+
import { CAP_WRAPUP, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, timelineOf, TOOL_COST, TOOL_STARTED } from "./timeline/index.js";
|
|
56
54
|
/** How a request the cap refused begins its error, which the server ends the run with. */
|
|
57
55
|
export const SPEND_CAP_REACHED = "spend_cap_reached";
|
|
58
56
|
/** How near two dollar figures are the same figure: a sum a float puts a hair past the cap (0.0028 + 0.3072 is
|
|
@@ -75,17 +73,6 @@ export const BOUND_FIELD = "boundUsd";
|
|
|
75
73
|
* only a cache miss can pass the cap, by at most the request's bound; "strict" every input token uncached, the worst
|
|
76
74
|
* case, so no request can pass it. */
|
|
77
75
|
export const CAP_MODES = ["expected", "strict"];
|
|
78
|
-
/** A run's cap mode, passed to its process; absent is "expected". */
|
|
79
|
-
export const CAP_MODE_ENV = "AGENTRUN_SERVE_CAP_MODE";
|
|
80
|
-
/** The run's cap mode from its process's environment. */
|
|
81
|
-
export function capModeOf(env) {
|
|
82
|
-
const text = env[CAP_MODE_ENV];
|
|
83
|
-
if (text === undefined || text === "")
|
|
84
|
-
return "expected";
|
|
85
|
-
if (!CAP_MODES.includes(text))
|
|
86
|
-
throw new Error(`${CAP_MODE_ENV} is ${text}, not one of ${CAP_MODES.join(", ")}`);
|
|
87
|
-
return text;
|
|
88
|
-
}
|
|
89
76
|
/** How long after a request ended the next one in its conversation is expected to read its cache: 4 minutes, inside
|
|
90
77
|
* Anthropic's 5 (a cache kept that long from its last use; OpenAI's lasts longer). A request later than that is priced
|
|
91
78
|
* with nothing cached. */
|
|
@@ -313,16 +300,6 @@ const endUnrecorded = (entry) => {
|
|
|
313
300
|
* search's results are billed as input, about 25,000 tokens a search as a working estimate. */
|
|
314
301
|
export const NATIVE_SEARCH_ALLOWANCE_TOKENS = 8 * 25_000;
|
|
315
302
|
export const sideRequests = new WeakMap();
|
|
316
|
-
/** The run's cap from its process's environment; absent for a run without one. */
|
|
317
|
-
export function capOf(env) {
|
|
318
|
-
const text = env[CAP_ENV];
|
|
319
|
-
if (text === undefined || text === "")
|
|
320
|
-
return undefined;
|
|
321
|
-
const cap = Number(text);
|
|
322
|
-
if (!(Number.isFinite(cap) && cap > 0))
|
|
323
|
-
throw new Error(`${CAP_ENV} is ${text}, not a number above 0`);
|
|
324
|
-
return cap;
|
|
325
|
-
}
|
|
326
303
|
/** The code a cap's refusal begins with: `spend_cap_reached: `, or with a note after it, as a request it limited refuses
|
|
327
304
|
* in (CAP_REFUSAL_CODE, "spend_cap_reached (out of budget): "). Every reader of a refusal's text (a run's end, its
|
|
328
305
|
* learning, the spend read back) reads the code through this, never a bare prefix. */
|
|
@@ -676,6 +653,13 @@ export function meterFiguresIn(storeFile) {
|
|
|
676
653
|
return { tools: 0, tokens: null, browser: { usd: 0, seconds: 0 }, others: 0, known: { tokens: 0, browser: 0, others: 0 } };
|
|
677
654
|
return readRunDbSync(storeFile, false, (db) => meterFiguresFrom(db.prepare("SELECT conversation_id AS conversation, record FROM entries ORDER BY rowid").all().map((row) => ({ conversation: Number(row.conversation), entry: JSON.parse(String(row.record)) }))));
|
|
678
655
|
}
|
|
656
|
+
/** A browser charge's record on the run's root when the run books its money on the runner's one ledger (browser-cost.ts
|
|
657
|
+
* browserSpend's `paid`): the same record a browser TOOL_COST is, for what the browser's process holds and the seconds
|
|
658
|
+
* it was for, under a kind no cost reads. The charge's money is the ledger's paid step alone, which the cap counts and
|
|
659
|
+
* the run's cost (adapter-run-spec.ts endPatch), its timeline and its meters (store-reads/journal.ts withPaidCosts) read,
|
|
660
|
+
* as every paid tool's on the runner: a TOOL_COST beside it would count the same charge twice. Its seconds are the
|
|
661
|
+
* browser_time meter's (meterFiguresFrom). */
|
|
662
|
+
export const BROWSER_CHARGED = "agentrun.browser_charged";
|
|
679
663
|
/** meterFiguresIn's figures from a run's entries by conversation, in log order: the one computation, shared by
|
|
680
664
|
* meterFiguresIn (reading a settled run's own database) and the one-store reader (store-reads/cap.ts metersOverStore, over
|
|
681
665
|
* A's journal). Only where the entries come from changes; the figures do not (the money-parity rule), as spentFrom is to
|
|
@@ -692,6 +676,10 @@ export function meterFiguresFrom(rows) {
|
|
|
692
676
|
const known = { tokens: 0, browser: 0, others: 0 };
|
|
693
677
|
for (const { entry } of rows) {
|
|
694
678
|
const data = (entry.data ?? {});
|
|
679
|
+
// On the runner a browser charge's money reaches here from the run's ledger (a TOOL_COST of tool "browser", with no
|
|
680
|
+
// seconds) and its seconds from its record on the root: each counted once.
|
|
681
|
+
if (entry.kind === BROWSER_CHARGED && data.tool === "browser")
|
|
682
|
+
browser.seconds += figureOf(data.seconds) ?? 0;
|
|
695
683
|
if (entry.kind === TOOL_STARTED)
|
|
696
684
|
marks.add(data.call);
|
|
697
685
|
else if (entry.kind === TOOL_COST)
|
|
@@ -925,9 +913,6 @@ export function money(usd) {
|
|
|
925
913
|
* which pi-ai's retry (isRetryableAssistantError, which reads only an error's text) takes as final whatever digits the
|
|
926
914
|
* words after it hold. The words after it are the ones a person reads. */
|
|
927
915
|
export const CAP_REFUSAL_CODE = `${SPEND_CAP_REACHED} (out of budget): `;
|
|
928
|
-
/** A refusal's figures as its start mark keeps them (`spentUsd`, `needsUsd`, `leastCapUsd`, and `boundUsd` when above 0);
|
|
929
|
-
* none without. */
|
|
930
|
-
export const refusalFields = (figures) => figures ? { spentUsd: figures.spentUsd, needsUsd: figures.needsUsd, leastCapUsd: figures.leastCapUsd, ...(typeof figures.boundUsd === "number" && figures.boundUsd > 0 ? { boundUsd: figures.boundUsd } : {}) } : {};
|
|
931
916
|
/** The words of a refusal for room (CAP_REFUSAL_CODE: what is left of the cap cannot buy the request's least), which a
|
|
932
917
|
* higher cap would send; undefined for any other text, a refusal no cap could fix included (an unknown spend, no price,
|
|
933
918
|
* no output ceiling, an input not measured: the bare `spend_cap_reached: ` code). The one reader of that difference. */
|
package/dist/cli.js
CHANGED
|
@@ -16,13 +16,18 @@ import { canOpen } from "./host.js";
|
|
|
16
16
|
import { resetPassword } from "./owner.js";
|
|
17
17
|
import { banner, boxImageLine } from "./print.js";
|
|
18
18
|
import { DEFAULT_PORT, fauxEnvOf, startServe } from "./server.js";
|
|
19
|
-
import { runnerBeside } from "./runner/beside.js";
|
|
19
|
+
import { besideRunnerOptions, besideStopping, runnerBeside } from "./runner/beside.js";
|
|
20
|
+
import { apiOnlyFrom } from "./api-only.js";
|
|
21
|
+
import { surviveClosedPipes } from "./closed-pipes.js";
|
|
22
|
+
// A stdout or stderr its reader closed loses the lines written after, never the process (closed-pipes.ts): for every
|
|
23
|
+
// command, the server and the runner alike.
|
|
24
|
+
surviveClosedPipes();
|
|
20
25
|
const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--open] [--faux MODULE] [--faux-browser MODULE] [--allow-host NAME ...] [--max-runs N] [--drain-timeout D] [--documents DIR] [--allow-code-nodes] [--learning on|off] [--learning-budget BYTES] [--grade-model MODEL] [--no-runner]
|
|
21
26
|
agentrun-serve reset-password [--data DIR]
|
|
22
27
|
agentrun-serve validate-template DIR
|
|
23
28
|
agentrun-serve eval-template DIR [--case NAME ...] [--runs N] [--server URL] [--grader-model PROVIDER/MODEL] [--report FILE] [--faux MODULE]
|
|
24
29
|
agentrun-serve import [--data DIR] [--from claude-code,codex,pi] [--dry-run] [--include-deleted] [--all] [--verbose] [--port N]
|
|
25
|
-
agentrun-serve runner --data DIR [--loops N] [--name NAME]
|
|
30
|
+
agentrun-serve runner --data DIR [--loops N] [--drain-timeout D] [--name NAME]
|
|
26
31
|
agentrun-serve runner --check --data DIR [--name NAME]
|
|
27
32
|
|
|
28
33
|
--data DIR the agent store and its runs (default ~/.local/share/agentrun/agents); the token is DIR/.token, mode 0600
|
|
@@ -36,14 +41,16 @@ const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--
|
|
|
36
41
|
with --faux only: the browser tool's provider and driver from MODULE's default export (a fake
|
|
37
42
|
browser, no vendor, no key), for the console's real-browser tests
|
|
38
43
|
--allow-host NAME another Host name to accept (repeatable)
|
|
39
|
-
--max-runs N the most runs
|
|
40
|
-
|
|
44
|
+
--max-runs N the most runs the runner beside the server holds at once, the rest waiting queued (default
|
|
45
|
+
AGENTRUN_MAX_RUNS, else as many pi runs as this host's memory holds); the capabilities'
|
|
46
|
+
max_concurrent_runs says the same
|
|
41
47
|
--documents DIR a read-only directory of documents a workflow's pdf_pages calls read by file name (default
|
|
42
48
|
AGENTRUN_SERVE_DOCUMENTS)
|
|
43
49
|
--allow-code-nodes run workflows' code nodes, in the run's process with no sandbox (default off, or
|
|
44
50
|
AGENTRUN_SERVE_CODE_NODES=1); off, a workflow with one saves with a warning and its runs are refused
|
|
45
|
-
--drain-timeout D how long
|
|
46
|
-
Docker's 10 s grace); a run
|
|
51
|
+
--drain-timeout D how long the runner beside the server lets each busy run finish its turn when the server stops
|
|
52
|
+
(default 30s; the image's is 6s, inside Docker's 10 s grace); a run still busy then is stopped and
|
|
53
|
+
resumes at the next start
|
|
47
54
|
--learning on|off whether runs learn (default on, or AGENTRUN_SERVE_LEARNING): on, a run of an agent whose definition
|
|
48
55
|
says learning: true starts from what that agent learned and adds to it; off, no run does
|
|
49
56
|
--learning-budget BYTES how much of what an agent learned its run's instructions hold (default
|
|
@@ -52,7 +59,10 @@ const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--
|
|
|
52
59
|
--grade-model MODEL the model that grades what a run proposes to learn (default AGENTRUN_SERVE_GRADE_MODEL, else the
|
|
53
60
|
strong tier, AGENT_MODEL_STRONG, else each run's own model), named as the strong tier takes one
|
|
54
61
|
--no-runner run the server alone, with no runner beside it (default: one runner beside the server); start one or
|
|
55
|
-
more \`agentrun-serve runner --data DIR\` processes on the same data directory to claim and run runs
|
|
62
|
+
more \`agentrun-serve runner --data DIR\` processes on the same data directory to claim and run runs;
|
|
63
|
+
each holds at most --loops N runs (default AGENTRUN_MAX_RUNS, else as many pi runs as its host's
|
|
64
|
+
memory holds; the rest wait queued) and on SIGTERM lets each busy run finish its turn for up to
|
|
65
|
+
--drain-timeout D (default AGENTRUN_DRAIN_TIMEOUT, else 6s), then hands the rest back to resume
|
|
56
66
|
|
|
57
67
|
Without --faux, a revision's model ("provider/model-id", or AGENT_MODEL when it names none; a workflow node's tier maps
|
|
58
68
|
to AGENT_MODEL_FAST or AGENT_MODEL_STRONG, each falling back to AGENT_MODEL) is served by pi-ai's providers with their
|
|
@@ -62,6 +72,10 @@ printed only by the start that made it. AGENTRUN_PUBLIC_URL, when set, is the ad
|
|
|
62
72
|
published port, or a proxy's URL), and the link printed uses it; with none, Render's RENDER_EXTERNAL_URL is. stdout gets one line per request, per run start and
|
|
63
73
|
end, and per refused credential; AGENTRUN_LOG=quiet leaves out the request lines.
|
|
64
74
|
|
|
75
|
+
AGENTRUN_API_ONLY=1 serves the run routes alone, for a server behind its caller's backend: a run's launch, read, list,
|
|
76
|
+
timeline, messages, stop, cancel, kill and cap raise, its files and uploads, capabilities, health and usage. Every other
|
|
77
|
+
address (the page, sign-in, setup, settings, MCP, triggers and their hooks, agents) is a 404, and there are no accounts.
|
|
78
|
+
|
|
65
79
|
The page is for one person, who signs in with a password (AGENTRUN_ACCOUNTS=0 turns this off; the token works for
|
|
66
80
|
scripts and the CLI either way). With no AGENTRUN_PUBLIC_URL, listening on loopback, the first visit to the page sets the
|
|
67
81
|
password; with it, or on any other address, the setup link this server prints carries a code. Sign-in tries are limited
|
|
@@ -284,9 +298,16 @@ if (budget !== undefined && !/^\d+$/.test(budget)) {
|
|
|
284
298
|
}
|
|
285
299
|
const data = values.data ?? defaultData();
|
|
286
300
|
const given = secret("AGENTRUN_TOKEN") || undefined;
|
|
287
|
-
//
|
|
288
|
-
|
|
289
|
-
|
|
301
|
+
// AGENTRUN_API_ONLY=1: the run routes alone (api-only.ts), and no owner; a value that is neither on nor off stops here.
|
|
302
|
+
let apiOnly;
|
|
303
|
+
try {
|
|
304
|
+
apiOnly = apiOnlyFrom(process.env);
|
|
305
|
+
}
|
|
306
|
+
catch (error) {
|
|
307
|
+
console.error(`${error.message}\n\n${USAGE}`);
|
|
308
|
+
process.exit(2);
|
|
309
|
+
}
|
|
310
|
+
const accounts = !apiOnly && process.env.AGENTRUN_ACCOUNTS !== "0";
|
|
290
311
|
// The Docker box image's first build said in words, as it starts and as it ends (print.ts boxImageLine); a line told
|
|
291
312
|
// before the banner is printed waits for it.
|
|
292
313
|
let imageSaid = false;
|
|
@@ -310,12 +331,18 @@ const trustedProxies = (process.env.AGENTRUN_TRUSTED_PROXIES ?? "").split(",").m
|
|
|
310
331
|
try {
|
|
311
332
|
serve = await startServe(serveOptions = {
|
|
312
333
|
onBoxImage,
|
|
334
|
+
// The owner lock on a Postgres store lost for good: this server can serve nothing more, so it exits non-zero and its
|
|
335
|
+
// platform starts it again, rather than answer 503 for as long as it runs.
|
|
336
|
+
onStoreLost: (error) => {
|
|
337
|
+
console.error(`agentrun-serve: ${error.message}`);
|
|
338
|
+
process.exit(1);
|
|
339
|
+
},
|
|
313
340
|
data, port, ...(values.port === undefined ? { nextFreePort: true } : {}), ...(values.listen ? { host: values.listen } : {}), ...(given ? { token: given } : {}), ...(values.faux ? { faux: values.faux } : {}), ...(values["faux-browser"] ? { fauxBrowser: values["faux-browser"] } : {}), allowHosts: values["allow-host"],
|
|
314
341
|
...(values["max-runs"] !== undefined ? { maxRuns: Number(values["max-runs"]) } : {}),
|
|
315
342
|
...(values["drain-timeout"] ? { drainTimeout: values["drain-timeout"] } : {}), ...(values.documents ? { documents: values.documents } : {}), ...(values["allow-code-nodes"] ? { allowCodeNodes: true } : {}), ...(values.learning !== undefined ? { learning: values.learning } : {}), ...(values["grade-model"] ? { gradeModel: values["grade-model"] } : {}), ...(budget !== undefined ? { learningBudget: Number(budget) } : {}), log: (line) => void process.stdout.write(`${line}\n`),
|
|
316
343
|
// The public address is the server's with accounts on or off: the Host names it serves, the webhook URLs it gives.
|
|
317
344
|
...(publicUrl ? { publicUrl } : {}),
|
|
318
|
-
...(accounts ? { accounts, openSetup: !publicUrl, countSessions: true } : {}),
|
|
345
|
+
...(accounts ? { accounts, openSetup: !publicUrl, countSessions: true } : {}), ...(apiOnly ? { apiOnly } : {}),
|
|
319
346
|
// The proxies whose X-Forwarded-For the sign-in limit reads (comma-separated); none unless set.
|
|
320
347
|
...(trustedProxies.length ? { trustedProxies } : {}),
|
|
321
348
|
});
|
|
@@ -326,16 +353,20 @@ catch (error) {
|
|
|
326
353
|
}
|
|
327
354
|
// The start launches one runner beside the server on the same data dir (design: "server and runner"): it claims and runs
|
|
328
355
|
// every run, sharing only the store. With --no-runner the server runs alone, so the operator starts one or more separate
|
|
329
|
-
// `agentrun runner --data DIR` processes on the same data directory instead.
|
|
356
|
+
// `agentrun runner --data DIR` processes on the same data directory instead. The runner holds what the server's flags say
|
|
357
|
+
// (besideRunnerOptions): at most --max-runs runs at once, the rest waiting queued, and on the stop each busy run finishes
|
|
358
|
+
// its turn for up to --drain-timeout.
|
|
330
359
|
let runnerProc;
|
|
360
|
+
const { loops, drainMs } = besideRunnerOptions(serveOptions, process.env);
|
|
331
361
|
if (!values["no-runner"]) {
|
|
332
362
|
try {
|
|
333
363
|
// The beside-runner sees the server's test switches (server.ts fauxEnvOf: --faux and its modules), which the CLI hands
|
|
334
364
|
// the server as options, never through this process's environment: without them a --faux start's runner looks its faux
|
|
335
|
-
// model up in pi-ai's own catalog and every run fails on its first request.
|
|
336
|
-
// its
|
|
337
|
-
const {
|
|
338
|
-
|
|
365
|
+
// model up in pi-ai's own catalog and every run fails on its first request. A test switch this process inherited from
|
|
366
|
+
// its shell is taken out first, as the server's own environment drops it (runner/main.ts besideRunEnv).
|
|
367
|
+
const { besideRunEnv } = await import("./runner/main.js");
|
|
368
|
+
// With the computer janitor: what a crashed runner of this server left is ended (never under --faux).
|
|
369
|
+
runnerProc = await runnerBeside(data, { loops, drainMs, env: besideRunEnv(process.env, fauxEnvOf(serveOptions)), janitor: true });
|
|
339
370
|
}
|
|
340
371
|
catch (error) {
|
|
341
372
|
console.error(`agentrun-serve: the runner could not start: ${error.message}`);
|
|
@@ -345,7 +376,7 @@ if (!values["no-runner"]) {
|
|
|
345
376
|
}
|
|
346
377
|
// A token from the environment is the operator's already, and the stored one is printed by the start that made it only.
|
|
347
378
|
const source = given ? "env" : serve.tokenMade ? "made" : "file";
|
|
348
|
-
for (const line of banner({ url: serve.url, baseUrl: serve.baseUrl, data, token: serve.token, source, accounts, boxes: serve.boxesLine, ...(values.listen ? { listen: values.listen } : {}), ...(publicUrl ? { publicUrl } : {}) }))
|
|
379
|
+
for (const line of banner({ url: serve.url, baseUrl: serve.baseUrl, data, token: serve.token, source, accounts, ...(apiOnly ? { apiOnly } : {}), boxes: serve.boxesLine, ...(values.listen ? { listen: values.listen } : {}), ...(publicUrl ? { publicUrl } : {}) }))
|
|
349
380
|
console.log(line);
|
|
350
381
|
// Open setup (no public address, a loopback listener): the link that sets the password. Any other start printed the
|
|
351
382
|
// setup link with its code as the code was made (owner.ts).
|
|
@@ -356,7 +387,8 @@ for (const line of early.splice(0))
|
|
|
356
387
|
console.log(line);
|
|
357
388
|
// The console's page, once the server listens: never its sign-in link, whose token would sit in the opener's arguments
|
|
358
389
|
// and the browser's history.
|
|
359
|
-
|
|
390
|
+
// API-only: there is no console, so nothing to open.
|
|
391
|
+
if (values.open && !apiOnly && canOpen(process.env))
|
|
360
392
|
spawn(process.platform === "darwin" ? "open" : "xdg-open", [`${publicUrl ?? serve.url}/`], { stdio: "ignore", detached: true }).on("error", () => { }).unref();
|
|
361
393
|
const record = join(resolve(data), SERVER_FILE);
|
|
362
394
|
// The record goes only while it is this server's: a server that takes the lock next writes its own, which this stop must
|
|
@@ -364,8 +396,17 @@ const record = join(resolve(data), SERVER_FILE);
|
|
|
364
396
|
// (stop-signals.ts). The stop is in place before the record is written: a SIGTERM sent the moment the record appears is
|
|
365
397
|
// a clean stop that removes it, never the default end by signal that leaves it behind.
|
|
366
398
|
const stop = stopOnSignals({
|
|
367
|
-
close: () =>
|
|
368
|
-
|
|
399
|
+
close: () => {
|
|
400
|
+
removeOwnRecord(record);
|
|
401
|
+
// A drain that has runs to wait on says so, as a run's own process did on the server's stop.
|
|
402
|
+
const busy = runnerProc?.runner.held().length ?? 0;
|
|
403
|
+
if (busy > 0 && drainMs > 0)
|
|
404
|
+
console.error(`agentrun-serve: stopping: waiting up to ${Math.ceil(drainMs / 1000)} s for ${busy} ${busy === 1 ? "run" : "runs"} to finish ${busy === 1 ? "its turn" : "their turns"}`);
|
|
405
|
+
return Promise.all([runnerProc?.close() ?? Promise.resolve(), serve.close()]).then(() => undefined);
|
|
406
|
+
},
|
|
407
|
+
// The stop's deadline waits out the runner's whole close: its drain, then the stop of the loops left, so a run's end
|
|
408
|
+
// and release are never cut short (besideStopping).
|
|
409
|
+
stopping: () => (runnerProc ? besideStopping(serve.stopping(), runnerProc.runner.held().length, drainMs) : serve.stopping()),
|
|
369
410
|
done: (code) => (removeOwnRecord(record), process.exit(code)),
|
|
370
411
|
say: (line) => console.error(line),
|
|
371
412
|
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// A stdout or stderr its reader closed (a terminal piped to `head`, a launcher that went away) loses the lines written
|
|
2
|
+
// after it, never the process. Without this, a write to it fails with EPIPE, emitted as an 'error' on the stream with no
|
|
3
|
+
// listener, which ends the server or a runner at its next line, console or raw write alike. Any other error on them is
|
|
4
|
+
// still thrown. cli.ts calls it first, for every command.
|
|
5
|
+
/** Keeps this process alive when its stdout or stderr reader has gone: EPIPE on either is dropped. */
|
|
6
|
+
export function surviveClosedPipes(streams = [process.stdout, process.stderr]) {
|
|
7
|
+
for (const stream of streams) {
|
|
8
|
+
stream.on("error", (error) => {
|
|
9
|
+
if (error.code !== "EPIPE")
|
|
10
|
+
throw error;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -13,6 +13,8 @@ export declare const COMPUTER_HAND_BACK = "computer_hand_back";
|
|
|
13
13
|
export declare const holdWords: (computer: ViewedKind) => {
|
|
14
14
|
taken: string;
|
|
15
15
|
ended: Record<Exclude<HoldEnd, "answered">, string>;
|
|
16
|
+
/** The agent is done while the person holds the computer: the run's end waits for the hand-back (#2134). */
|
|
17
|
+
ending: string;
|
|
16
18
|
waiting: (instruction: string) => string;
|
|
17
19
|
answered: Record<AskOutcome, string>;
|
|
18
20
|
};
|
|
@@ -20,6 +20,8 @@ export const holdWords = (computer) => ({
|
|
|
20
20
|
away: `The ${computer} went back to the agent: the live view was closed`,
|
|
21
21
|
released: `The ${computer}'s session ended while you had it`,
|
|
22
22
|
},
|
|
23
|
+
/** The agent is done while the person holds the computer: the run's end waits for the hand-back (#2134). */
|
|
24
|
+
ending: `The agent is done. The run ends when you hand the ${computer} back, or after ${HOLD_IDLE_MS / 60_000} minutes with no input from you`,
|
|
23
25
|
waiting: (instruction) => `Waiting for you: ${instruction}`,
|
|
24
26
|
answered: {
|
|
25
27
|
done: "Done: the owner answered the agent's request.",
|
package/dist/computer-keys.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// The map from a key's name to the option it fills is serve's, and lives here: E2B_API_KEY is E2B's apiKey, the Modal
|
|
6
6
|
// token pair is the Modal client's tokenId and tokenSecret, and so on. A name a provider does not declare is never passed
|
|
7
7
|
// on; an empty optional key is left out; a required one not saved refuses in words naming what to save, before anything
|
|
8
|
-
// is made. The provider modules themselves (each one's create()) are passed in
|
|
9
|
-
//
|
|
8
|
+
// is made. The provider modules themselves (each one's create()) are passed in (workspace/computer-providers.ts makes the
|
|
9
|
+
// computer package's; a test gives stand-ins): a provider with no module here answers that its test is not available.
|
|
10
10
|
// No key is ever in an answer: each value is scrubbed from the provider's words, and the words this module adds name keys
|
|
11
11
|
// only by their names.
|
|
12
12
|
/** Each provider's keys, by the registry's names, and the option each fills. Docker takes none (its host is local). */
|
|
@@ -29,6 +29,8 @@ export const PROVIDER_KEYS = {
|
|
|
29
29
|
{ name: "BROWSERBASE_PROJECT_ID", option: "projectId", required: true },
|
|
30
30
|
],
|
|
31
31
|
kernel: [{ name: "KERNEL_API_KEY", option: "apiKey", required: true }],
|
|
32
|
+
// This machine's Chrome: no key.
|
|
33
|
+
local: [],
|
|
32
34
|
};
|
|
33
35
|
/** Each provider's name in words (the registry's labels). */
|
|
34
36
|
const LABELS = {
|
|
@@ -40,6 +42,7 @@ const LABELS = {
|
|
|
40
42
|
"phone-harness": "Phone harness",
|
|
41
43
|
browserbase: "Browserbase",
|
|
42
44
|
kernel: "Kernel",
|
|
45
|
+
local: "Local Chrome",
|
|
43
46
|
};
|
|
44
47
|
/** The Modal app a server's computers live in when its settings name none (serve's box app until now). */
|
|
45
48
|
export const DEFAULT_MODAL_APP = "agentrun";
|
|
@@ -2,13 +2,27 @@ import type { InputIssue } from "./errors.js";
|
|
|
2
2
|
/** The kinds of computer an agent can be given. */
|
|
3
3
|
export declare const COMPUTER_KINDS: readonly ["none", "sandbox", "desktop", "phone", "browser"];
|
|
4
4
|
export type ComputerKind = (typeof COMPUTER_KINDS)[number];
|
|
5
|
-
/**
|
|
5
|
+
/** A sandbox's GPUs: a type its provider declares (GET /v2/computers lists each provider's) and how many. */
|
|
6
|
+
export type GpuSetting = {
|
|
7
|
+
readonly type: string;
|
|
8
|
+
readonly count: number;
|
|
9
|
+
};
|
|
10
|
+
/** The setting as a revision keeps it. A sandbox may ask for GPUs; whether its provider gives them is the claim's check. */
|
|
6
11
|
export type ComputerSetting = {
|
|
7
12
|
readonly kind: "none";
|
|
8
13
|
} | {
|
|
9
|
-
readonly kind:
|
|
14
|
+
readonly kind: "sandbox";
|
|
15
|
+
readonly provider: string;
|
|
16
|
+
readonly gpu?: GpuSetting;
|
|
17
|
+
} | {
|
|
18
|
+
readonly kind: Exclude<ComputerKind, "none" | "sandbox">;
|
|
10
19
|
readonly provider: string;
|
|
11
20
|
};
|
|
21
|
+
/** The GPUs a setting asks for, or undefined. */
|
|
22
|
+
export declare const gpuOf: (computer: {
|
|
23
|
+
readonly kind: string;
|
|
24
|
+
readonly gpu?: GpuSetting;
|
|
25
|
+
}) => GpuSetting | undefined;
|
|
12
26
|
/** A place as the v2 API names it. */
|
|
13
27
|
export type PlaceView = {
|
|
14
28
|
mode: "runner";
|
|
@@ -20,9 +34,11 @@ export type PlaceView = {
|
|
|
20
34
|
export declare const placeOfComputer: (computer: ComputerSetting) => PlaceView;
|
|
21
35
|
/** The setting a place says: runner is no computer, a sandbox place a sandbox on its box. */
|
|
22
36
|
export declare const computerOfPlace: (place: PlaceView) => ComputerSetting;
|
|
23
|
-
/** Whether two settings are the one setting. */
|
|
37
|
+
/** Whether two settings are the one setting: the kind and the provider (a place says no GPUs, so they are not compared). */
|
|
24
38
|
export declare const sameComputer: (a: ComputerSetting, b: ComputerSetting) => boolean;
|
|
25
|
-
/** What is wrong with `value` as a computer setting, at `field`: its shape only (the providers are the server's).
|
|
39
|
+
/** What is wrong with `value` as a computer setting, at `field`: its shape only (the providers are the server's). A
|
|
40
|
+
* sandbox's gpu is { type, count } in the words the computer package's checkGpu uses; whether its provider offers that
|
|
41
|
+
* type and count is the readiness check's and the claim's (resolve-computer.ts), in checkGpu's own words. */
|
|
26
42
|
export declare function computerIssues(value: unknown, field: string): InputIssue[];
|
|
27
43
|
/** The setting and its place a definition says, from `computer` or `place` (both: they must agree), or undefined when
|
|
28
44
|
* it says neither. Each is checked already (computerIssues, placeIssues). */
|
package/dist/computer-setting.js
CHANGED
|
@@ -1,26 +1,46 @@
|
|
|
1
1
|
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2
2
|
/** The kinds of computer an agent can be given. */
|
|
3
3
|
export const COMPUTER_KINDS = ["none", "sandbox", "desktop", "phone", "browser"];
|
|
4
|
+
/** A GPU type's name as a setting keeps it: the vendor's own ("T4", "A100-80GB", "RTX-PRO-6000"); store/agent-body.ts
|
|
5
|
+
* keeps the same. */
|
|
6
|
+
const GPU_TYPE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
7
|
+
/** The GPUs a setting asks for, or undefined. */
|
|
8
|
+
export const gpuOf = (computer) => (computer.kind === "sandbox" ? computer.gpu : undefined);
|
|
4
9
|
/** The place the setting reads as: sandbox on its provider, else the runner (no computer holds the run's folder). */
|
|
5
10
|
export const placeOfComputer = (computer) => (computer.kind === "sandbox" ? { mode: "sandbox", box: computer.provider } : { mode: "runner" });
|
|
6
11
|
/** The setting a place says: runner is no computer, a sandbox place a sandbox on its box. */
|
|
7
12
|
export const computerOfPlace = (place) => (place.mode === "sandbox" ? { kind: "sandbox", provider: place.box } : { kind: "none" });
|
|
8
|
-
/** Whether two settings are the one setting. */
|
|
13
|
+
/** Whether two settings are the one setting: the kind and the provider (a place says no GPUs, so they are not compared). */
|
|
9
14
|
export const sameComputer = (a, b) => a.kind === b.kind && (a.kind === "none" || a.provider === b.provider);
|
|
10
|
-
/** What is wrong with `value` as a computer setting, at `field`: its shape only (the providers are the server's).
|
|
15
|
+
/** What is wrong with `value` as a computer setting, at `field`: its shape only (the providers are the server's). A
|
|
16
|
+
* sandbox's gpu is { type, count } in the words the computer package's checkGpu uses; whether its provider offers that
|
|
17
|
+
* type and count is the readiness check's and the claim's (resolve-computer.ts), in checkGpu's own words. */
|
|
11
18
|
export function computerIssues(value, field) {
|
|
12
19
|
const bad = (reason, message, fix) => [{ field, reason, message, ...(fix ? { fix } : {}) }];
|
|
13
20
|
if (!isObject(value))
|
|
14
|
-
return bad("wrong_type", `${field} is an object: {kind}, or {kind, provider}`);
|
|
15
|
-
const extra = Object.keys(value).filter((key) => key !== "kind" && key !== "provider");
|
|
21
|
+
return bad("wrong_type", `${field} is an object: {kind}, or {kind, provider}, and a sandbox's optional gpu`);
|
|
22
|
+
const extra = Object.keys(value).filter((key) => key !== "kind" && key !== "provider" && key !== "gpu");
|
|
16
23
|
if (extra.length)
|
|
17
|
-
return bad("not_allowed", `${field} keeps only kind and
|
|
24
|
+
return bad("not_allowed", `${field} keeps only kind, provider and a sandbox's gpu, not ${extra.join(" or ")}`, `Remove ${extra.map((key) => `${field}.${key}`).join(" and ")}.`);
|
|
18
25
|
if (typeof value.kind !== "string" || !COMPUTER_KINDS.includes(value.kind))
|
|
19
26
|
return bad(value.kind === undefined ? "missing" : "not_an_option", `${field}.kind is one of ${COMPUTER_KINDS.join(", ")}`);
|
|
27
|
+
if (value.gpu !== undefined && value.kind !== "sandbox")
|
|
28
|
+
return bad("not_allowed", `only a sandbox computer takes a gpu, not a ${value.kind} one`, `Remove ${field}.gpu.`);
|
|
20
29
|
if (value.kind === "none")
|
|
21
30
|
return value.provider === undefined ? [] : bad("not_allowed", "no computer names no provider", `Remove ${field}.provider.`);
|
|
22
31
|
if (typeof value.provider !== "string" || value.provider === "")
|
|
23
32
|
return bad("missing", `a ${value.kind} computer names its provider (Settings → Computers lists them)`);
|
|
33
|
+
if (value.gpu !== undefined) {
|
|
34
|
+
const gpu = value.gpu;
|
|
35
|
+
if (!isObject(gpu) || Object.keys(gpu).some((key) => key !== "type" && key !== "count"))
|
|
36
|
+
return [{ field: `${field}.gpu`, reason: "wrong_type", message: "gpu is { type, count }: a GPU type this provider declares, and how many" }];
|
|
37
|
+
if (typeof gpu.type !== "string" || gpu.type === "")
|
|
38
|
+
return [{ field: `${field}.gpu.type`, reason: "missing", message: "gpu.type is a GPU type the provider declares (GET /v2/computers lists each provider's)" }];
|
|
39
|
+
if (!GPU_TYPE.test(gpu.type))
|
|
40
|
+
return [{ field: `${field}.gpu.type`, reason: "wrong_type", message: `gpu.type ${JSON.stringify(gpu.type)} is not a GPU type name: letters, digits, dots, underscores and dashes, as GET /v2/computers lists each provider's` }];
|
|
41
|
+
if (!Number.isSafeInteger(gpu.count) || gpu.count < 1)
|
|
42
|
+
return [{ field: `${field}.gpu.count`, reason: "wrong_type", message: `gpu.count ${JSON.stringify(gpu.count)} is not a whole number from 1` }];
|
|
43
|
+
}
|
|
24
44
|
return [];
|
|
25
45
|
}
|
|
26
46
|
/** The setting and its place a definition says, from `computer` or `place` (both: they must agree), or undefined when
|
package/dist/computers.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { type GpuCapability } from "@parcha/agentrun-computer";
|
|
1
2
|
import { type KeyTable, type OptionsAnswer, type ProviderFactories, type ProviderSettings } from "./computer-keys.js";
|
|
2
3
|
import { type ComputerKind, type ComputerSetting } from "./computer-setting.js";
|
|
4
|
+
import { type DockerDaemon } from "./docker-daemon.js";
|
|
3
5
|
import { type KeyEnv, type KeyMeta } from "./key-meta.js";
|
|
4
6
|
import type { Store } from "./store/index.js";
|
|
5
7
|
/** A setting kind as the kind registry's SETTING_KINDS gives it. */
|
|
@@ -8,10 +10,12 @@ export interface SettingKindSpec {
|
|
|
8
10
|
readonly required: readonly string[];
|
|
9
11
|
readonly optional: readonly string[];
|
|
10
12
|
}
|
|
11
|
-
/** A provider configuration's machine kind and groups,
|
|
13
|
+
/** A provider configuration's machine kind and groups, and the GPUs it gives where it declares them, as the kind
|
|
14
|
+
* registry gives them. */
|
|
12
15
|
export type KindCapabilities = {
|
|
13
16
|
readonly kind: string;
|
|
14
17
|
readonly groups: readonly string[];
|
|
18
|
+
readonly gpu?: GpuCapability;
|
|
15
19
|
};
|
|
16
20
|
/** A provider as the kind registry's PROVIDERS gives it. */
|
|
17
21
|
export interface ProviderEntry {
|
|
@@ -24,6 +28,9 @@ export interface ProviderEntry {
|
|
|
24
28
|
}[];
|
|
25
29
|
/** The mounts its computers take; none means it cannot mount the run's folder. */
|
|
26
30
|
readonly mounts: readonly string[];
|
|
31
|
+
/** The network forms its computers make ("none", "open", "allow"), as its module's NETWORK declares them. Absent (a
|
|
32
|
+
* test's fixture): nothing is said of its network. */
|
|
33
|
+
readonly network?: readonly string[];
|
|
27
34
|
readonly metered: boolean;
|
|
28
35
|
readonly capabilities: readonly KindCapabilities[];
|
|
29
36
|
}
|
|
@@ -38,7 +45,7 @@ export type FolderMode = "local" | "disk";
|
|
|
38
45
|
export interface ComputerRoutesOptions {
|
|
39
46
|
/** The server's one store: its sealed keys. */
|
|
40
47
|
readonly store: Pick<Store, "sealedKeys">;
|
|
41
|
-
/** The server's seal key: there is always one (seal-key.ts
|
|
48
|
+
/** The server's seal key: there is always one (seal-key.ts bootSealKey, at the start). */
|
|
42
49
|
readonly sealKey: Buffer;
|
|
43
50
|
readonly kinds: KindRegistry;
|
|
44
51
|
/** Each provider module's create(), by provider id (the computer package's): what a test and a claim make. */
|
|
@@ -54,10 +61,13 @@ export interface ComputerRoutesOptions {
|
|
|
54
61
|
readonly mode: FolderMode | (() => FolderMode | Promise<FolderMode>);
|
|
55
62
|
/** The server's environment: a variable named as a provider's key overrides the saved one (source "env"). */
|
|
56
63
|
readonly env?: KeyEnv;
|
|
64
|
+
/** Whether a provider that binds a folder of this machine (Docker) answers here now, or why not (the server's daemon
|
|
65
|
+
* check, docker-daemon.ts, which keeps its answer a while). Absent: taken as answering. */
|
|
66
|
+
readonly answers?: (provider: string) => Promise<DockerDaemon>;
|
|
57
67
|
}
|
|
58
68
|
/** A provider as Settings shows it: `metered` straight from the kind registry (its computers are billed by the vendor);
|
|
59
69
|
* its keys as SecretMeta under `secrets`, each named "computer:<provider>:<KEY>", and `required`, the names of the ones
|
|
60
|
-
* it needs. */
|
|
70
|
+
* it needs. `network`: what this server's allow-list means for a vendor-hosted computer, in words (networkWords). */
|
|
61
71
|
export type ProviderView = {
|
|
62
72
|
id: string;
|
|
63
73
|
name: string;
|
|
@@ -66,7 +76,25 @@ export type ProviderView = {
|
|
|
66
76
|
required: string[];
|
|
67
77
|
ready: boolean;
|
|
68
78
|
why?: string;
|
|
79
|
+
network?: string;
|
|
80
|
+
gpu?: GpuView;
|
|
69
81
|
};
|
|
82
|
+
/** A sandbox provider's GPUs as Settings shows them: what its configuration declares (the types an agent's
|
|
83
|
+
* `computer.gpu.type` names, the most one computer gets, and the limits it states), and why a run here cannot have
|
|
84
|
+
* them, when it cannot: a GPU computer of it that takes no mount of this server's folder mode. */
|
|
85
|
+
export type GpuView = GpuCapability & {
|
|
86
|
+
why?: string;
|
|
87
|
+
};
|
|
88
|
+
/** A computer with no network: its programs run in a network of their own, so a run's allow-list is never offered it. */
|
|
89
|
+
export declare const NO_NETWORK_WORDS = "no network, so this server's allow-list isn't offered";
|
|
90
|
+
/** A computer on the vendor's own network: open, which this server's allow-list doesn't reach. */
|
|
91
|
+
export declare const VENDOR_NETWORK_WORDS = "the vendor's own network; this server's allow-list doesn't apply";
|
|
92
|
+
/** A browser behind its own egress proxy (Local Chrome): every public host, unless the operator set a list. */
|
|
93
|
+
export declare const OPERATOR_LIST_WORDS = "open unless this server sets AGENTRUN_BOX_ALLOW; then only those hosts";
|
|
94
|
+
/** What this server's allow-list means for a provider's computers, by the network forms it declares: words for one that
|
|
95
|
+
* makes "none" alone, "open" alone, or "open" and "allow" but no "none" (a browser behind its own proxy); none where
|
|
96
|
+
* the allow-list applies as it is (Docker), or nothing is declared. */
|
|
97
|
+
export declare function networkWords(network: readonly string[] | undefined): string | undefined;
|
|
70
98
|
export type KindView = {
|
|
71
99
|
kind: ComputerKind;
|
|
72
100
|
offered: boolean;
|