@parcha/agentrun-serve 0.1.0-beta.57 → 0.1.0-beta.59
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 +376 -0
- package/README.md +393 -118
- package/dist/acp-package.d.ts +5 -1
- package/dist/acp-package.js +19 -2
- package/dist/adapters.d.ts +23 -2
- package/dist/adapters.js +106 -33
- package/dist/agents-store.js +1 -1
- package/dist/answer-text.d.ts +3 -0
- package/dist/answer-text.js +22 -0
- package/dist/api-only.d.ts +2 -4
- package/dist/api-only.js +2 -4
- package/dist/attach-conformance.js +5 -4
- package/dist/box-paths.d.ts +7 -5
- package/dist/box-paths.js +12 -8
- package/dist/browser-computer.d.ts +3 -8
- package/dist/browser-computer.js +12 -35
- package/dist/browser-cost.js +94 -20
- package/dist/capacity.d.ts +1 -1
- package/dist/capacity.js +3 -3
- package/dist/chatgpt-plan.d.ts +5 -0
- package/dist/chatgpt-plan.js +25 -11
- package/dist/claude-login-token.d.ts +121 -0
- package/dist/claude-login-token.js +797 -0
- package/dist/claude-login.d.ts +119 -34
- package/dist/claude-login.js +551 -79
- package/dist/claude-sign-in.d.ts +3 -0
- package/dist/claude-sign-in.js +10 -1
- package/dist/cli.js +325 -328
- package/dist/composio-made.d.ts +1 -6
- package/dist/composio-made.js +1 -6
- package/dist/composio-owners.d.ts +26 -0
- package/dist/composio-owners.js +36 -0
- package/dist/composio-preset.d.ts +56 -23
- package/dist/composio-preset.js +173 -77
- package/dist/composio-triggers.d.ts +4 -4
- package/dist/composio-triggers.js +6 -7
- package/dist/compute-cost.js +11 -2
- package/dist/computer-attach.d.ts +40 -19
- package/dist/computer-attach.js +326 -62
- package/dist/computer-held-routes.d.ts +1 -1
- package/dist/computer-held-routes.js +9 -4
- package/dist/computer-keys.d.ts +11 -1
- package/dist/computer-keys.js +26 -1
- package/dist/computer-record.js +3 -1
- package/dist/computer-view.d.ts +5 -3
- package/dist/computer-view.js +10 -6
- package/dist/computer-viewer.js +36 -7
- package/dist/computers.d.ts +12 -11
- package/dist/computers.js +11 -8
- package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
- package/dist/console/assets/backend-BztxEAvb.js +166 -0
- package/dist/console/assets/index-LwNL4L9q.js +619 -0
- package/dist/console/assets/share-L84tlUDW.js +6 -0
- package/dist/console/assets/styles-CaRKlHke.js +291 -0
- package/dist/console/assets/styles-DQo8rzY-.css +1 -0
- package/dist/console/index.html +4 -3
- package/dist/console/share.html +17 -0
- package/dist/decisions.d.ts +17 -7
- package/dist/decisions.js +41 -15
- package/dist/dial-relay.d.ts +25 -4
- package/dist/dial-relay.js +139 -5
- package/dist/docker-daemon.js +4 -5
- package/dist/docker-host-addresses.js +29 -11
- package/dist/email/account.d.ts +6 -0
- package/dist/email/account.js +6 -0
- package/dist/email/authentication.d.ts +21 -0
- package/dist/email/authentication.js +106 -0
- package/dist/email/email-faux.d.ts +11 -2
- package/dist/email/email-faux.js +21 -5
- package/dist/email/mail.d.ts +25 -0
- package/dist/email/mail.js +58 -2
- package/dist/email/names.js +2 -2
- package/dist/email/tools.d.ts +9 -4
- package/dist/email/tools.js +95 -13
- package/dist/env-switch.d.ts +13 -5
- package/dist/env-switch.js +24 -6
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/fal-price.d.ts +12 -4
- package/dist/fal-price.js +110 -26
- package/dist/faux-computers.js +1 -1
- package/dist/filed-answer.d.ts +2 -2
- package/dist/filed-answer.js +2 -2
- package/dist/graph-served.d.ts +10 -5
- package/dist/graph-served.js +40 -10
- package/dist/handed-values.js +1 -2
- package/dist/harness-check.d.ts +2 -1
- package/dist/harness-check.js +45 -12
- package/dist/harness-keys.js +9 -6
- package/dist/harness-opencode/facts.js +2 -0
- package/dist/harness-recipe-entry.d.ts +9 -3
- package/dist/harness-recipe-entry.js +18 -9
- package/dist/harness-recipe.d.ts +21 -0
- package/dist/harness-recipe.js +25 -3
- package/dist/harness-table.d.ts +8 -0
- package/dist/harness-table.js +17 -6
- package/dist/helper-env.d.ts +4 -1
- package/dist/helper-env.js +4 -1
- package/dist/host-check.d.ts +2 -3
- package/dist/host-check.js +13 -7
- package/dist/hosted-search.js +1 -1
- package/dist/import.d.ts +11 -8
- package/dist/import.js +437 -186
- package/dist/key-refusal.d.ts +9 -2
- package/dist/key-refusal.js +86 -32
- package/dist/learn/audit.d.ts +8 -5
- package/dist/learn/audit.js +15 -7
- package/dist/learn/compile.d.ts +5 -2
- package/dist/learn/compile.js +45 -21
- package/dist/learn/field-check.d.ts +111 -0
- package/dist/learn/field-check.js +174 -0
- package/dist/learn/ledger.d.ts +173 -0
- package/dist/learn/ledger.js +225 -0
- package/dist/learn/promote.d.ts +82 -39
- package/dist/learn/promote.js +61 -66
- package/dist/learn/secrets.d.ts +4 -0
- package/dist/learn/secrets.js +12 -0
- package/dist/learned-nodes.d.ts +8 -5
- package/dist/learned-nodes.js +8 -5
- package/dist/learned-workflow.d.ts +2 -1
- package/dist/learned-workflow.js +13 -10
- package/dist/learning-cost.d.ts +40 -21
- package/dist/learning-cost.js +30 -21
- package/dist/learning-setting.d.ts +6 -0
- package/dist/learning-setting.js +11 -1
- package/dist/listen-first.d.ts +5 -4
- package/dist/listen-first.js +4 -5
- package/dist/live-reach.d.ts +9 -0
- package/dist/live-reach.js +9 -0
- package/dist/mcp-api-only-origins.d.ts +23 -3
- package/dist/mcp-api-only-origins.js +57 -17
- package/dist/mcp-gateway.d.ts +16 -2
- package/dist/mcp-gateway.js +41 -3
- package/dist/mcp-oauth.d.ts +1 -1
- package/dist/mcp-oauth.js +3 -2
- package/dist/mcp-probe.d.ts +3 -0
- package/dist/mcp-probe.js +3 -0
- package/dist/mcp-secret-writes.d.ts +24 -2
- package/dist/mcp-secret-writes.js +30 -2
- package/dist/mcp-servers-store.d.ts +52 -14
- package/dist/mcp-servers-store.js +165 -61
- package/dist/mcp-sources.d.ts +1 -2
- package/dist/mcp-sources.js +1 -2
- package/dist/mcp-store.d.ts +5 -5
- package/dist/mcp-store.js +3 -3
- package/dist/mcp.js +1 -1
- package/dist/micro.d.ts +2 -0
- package/dist/micro.js +2 -0
- package/dist/model-gateway.d.ts +1 -1
- package/dist/model-gateway.js +20 -36
- package/dist/model.d.ts +5 -4
- package/dist/model.js +7 -6
- package/dist/monid.d.ts +14 -1
- package/dist/monid.js +103 -26
- package/dist/ollama-provider.d.ts +23 -9
- package/dist/ollama-provider.js +49 -20
- package/dist/openapi.js +234 -61
- package/dist/otel/genai.d.ts +83 -7
- package/dist/otel/genai.js +69 -9
- package/dist/otel/tracer.d.ts +42 -13
- package/dist/otel/tracer.js +241 -56
- package/dist/page.d.ts +7 -1
- package/dist/page.js +76 -22
- package/dist/paid-calls.d.ts +6 -4
- package/dist/paid-calls.js +15 -7
- package/dist/place-offers.d.ts +59 -34
- package/dist/place-offers.js +100 -58
- package/dist/place.d.ts +13 -14
- package/dist/place.js +56 -41
- package/dist/print.js +1 -1
- package/dist/provider.d.ts +5 -4
- package/dist/provider.js +26 -13
- package/dist/redact/match.d.ts +27 -9
- package/dist/redact/match.js +266 -57
- package/dist/run-census.d.ts +1 -1
- package/dist/run-census.js +4 -5
- package/dist/run-cut.js +4 -5
- package/dist/run-export-store.d.ts +15 -0
- package/dist/run-export-store.js +30 -0
- package/dist/run-export.d.ts +139 -0
- package/dist/run-export.js +379 -0
- package/dist/run-file-cut.d.ts +5 -0
- package/dist/run-file-cut.js +13 -0
- package/dist/run-launch.js +16 -3
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-model-key.d.ts +15 -6
- package/dist/run-model-key.js +30 -31
- package/dist/run-reads-over-store.js +4 -4
- package/dist/run-secrets.js +3 -5
- package/dist/run-timeline-served.js +3 -1
- package/dist/run-view.d.ts +1 -2
- package/dist/run-view.js +2 -1
- package/dist/runnable.js +2 -2
- package/dist/runner/adapter-loop.d.ts +35 -18
- package/dist/runner/adapter-loop.js +97 -63
- package/dist/runner/adapter-run-spec.d.ts +34 -14
- package/dist/runner/adapter-run-spec.js +120 -75
- package/dist/runner/adapters/pi.js +4 -2
- package/dist/runner/audit.d.ts +8 -5
- package/dist/runner/audit.js +37 -17
- package/dist/runner/beside.d.ts +9 -2
- package/dist/runner/beside.js +29 -13
- package/dist/runner/claim-secrets.d.ts +27 -18
- package/dist/runner/claim-secrets.js +61 -47
- package/dist/runner/cli-run-spec.d.ts +18 -0
- package/dist/runner/cli-run-spec.js +93 -46
- package/dist/runner/compare-end.d.ts +2 -1
- package/dist/runner/compare-end.js +25 -10
- package/dist/runner/conformance/harness.js +2 -3
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/harness-loops.js +3 -3
- package/dist/runner/held.d.ts +19 -4
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/journal-kinds.js +22 -4
- package/dist/runner/learned-first.js +20 -4
- package/dist/runner/learning-end.d.ts +2 -8
- package/dist/runner/learning-end.js +11 -19
- package/dist/runner/live-ticker.js +7 -5
- package/dist/runner/loop-contract.d.ts +0 -2
- package/dist/runner/loop.d.ts +7 -0
- package/dist/runner/loop.js +1 -0
- package/dist/runner/main.d.ts +11 -6
- package/dist/runner/main.js +24 -18
- package/dist/runner/mcp-claim.js +24 -7
- package/dist/runner/mcp-run.d.ts +3 -6
- package/dist/runner/mcp-run.js +3 -4
- package/dist/runner/meta-tools.js +3 -2
- package/dist/runner/metrics.d.ts +7 -0
- package/dist/runner/metrics.js +19 -0
- package/dist/runner/model-route.d.ts +10 -7
- package/dist/runner/model-route.js +79 -15
- package/dist/runner/native-loop.js +10 -8
- package/dist/runner/presence.d.ts +11 -4
- package/dist/runner/presence.js +11 -6
- package/dist/runner/promotion.d.ts +25 -13
- package/dist/runner/promotion.js +125 -50
- package/dist/runner/redact.d.ts +3 -1
- package/dist/runner/redact.js +5 -3
- package/dist/runner/reflect-hook.js +1 -1
- package/dist/runner/responses-fetch.d.ts +36 -0
- package/dist/runner/responses-fetch.js +511 -0
- package/dist/runner/run-child-host.d.ts +38 -12
- package/dist/runner/run-child-host.js +231 -83
- package/dist/runner/run-child.js +11 -4
- package/dist/runner/runner-check.js +5 -1
- package/dist/runner/runner.d.ts +5 -3
- package/dist/runner/runner.js +14 -10
- package/dist/runner/save-slots.js +2 -1
- package/dist/runner/sdk-loop.js +8 -8
- package/dist/runner/spec-holds.d.ts +8 -1
- package/dist/runner/spec-holds.js +9 -4
- package/dist/runner/subagent.d.ts +11 -0
- package/dist/runner/subagent.js +17 -3
- package/dist/runner/workflow-calls.d.ts +9 -0
- package/dist/runner/workflow-calls.js +150 -0
- package/dist/runner/workflow-first.d.ts +138 -37
- package/dist/runner/workflow-first.js +230 -99
- package/dist/runner/workflow-spec.js +2 -2
- package/dist/runs-over-store.js +8 -7
- package/dist/save-once.d.ts +14 -0
- package/dist/save-once.js +31 -0
- package/dist/scrub-command.d.ts +34 -31
- package/dist/scrub-command.js +116 -147
- package/dist/sdk/runs.d.ts +6 -0
- package/dist/sdk/runs.js +89 -10
- package/dist/seal-key.js +4 -4
- package/dist/secret-cut.d.ts +3 -0
- package/dist/secret-cut.js +7 -1
- package/dist/secret-rules.d.ts +8 -1
- package/dist/secret-rules.js +482 -53
- package/dist/secrets.d.ts +51 -9
- package/dist/secrets.js +311 -21
- package/dist/server-keys.d.ts +4 -3
- package/dist/server-keys.js +4 -3
- package/dist/server-secrets-store.js +2 -4
- package/dist/server.d.ts +33 -10
- package/dist/server.js +454 -136
- package/dist/share-context.d.ts +22 -0
- package/dist/share-context.js +76 -0
- package/dist/shell-lex.d.ts +105 -0
- package/dist/shell-lex.js +646 -0
- package/dist/sign-ins-store.d.ts +5 -7
- package/dist/sign-ins-store.js +12 -16
- package/dist/sign-ins.d.ts +7 -11
- package/dist/sign-ins.js +40 -41
- package/dist/skills/agentrun-serve/SKILL.md +5 -2
- package/dist/slots.d.ts +9 -0
- package/dist/slots.js +45 -0
- package/dist/start-switches.d.ts +6 -5
- package/dist/start-switches.js +8 -4
- package/dist/stats.d.ts +5 -1
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.js +2 -2
- package/dist/store/dialect.d.ts +4 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/mcp-record-keys.d.ts +10 -0
- package/dist/store/mcp-record-keys.js +13 -0
- package/dist/store/postgres/dialect.js +2 -0
- package/dist/store/postgres/migrations/0028_learning_ledger.sql +44 -0
- package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
- package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
- package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
- package/dist/store/postgres/store.js +4 -0
- package/dist/store/schema.d.ts +44 -4
- package/dist/store/schema.js +111 -11
- package/dist/store/seal.d.ts +4 -1
- package/dist/store/sqlite/run-launch.d.ts +3 -10
- package/dist/store/sqlite/run-launch.js +12 -23
- package/dist/store/sqlite/run-patch.d.ts +19 -2
- package/dist/store/sqlite/run-patch.js +67 -2
- package/dist/store/sqlite/store.d.ts +3 -0
- package/dist/store/sqlite/store.js +177 -32
- package/dist/store/store-schema.js +3 -4
- package/dist/store/store.d.ts +74 -25
- package/dist/store/store.js +14 -11
- package/dist/store-reads/analytics.d.ts +2 -1
- package/dist/store-reads/analytics.js +7 -5
- package/dist/store-reads/learning.d.ts +102 -136
- package/dist/store-reads/learning.js +251 -302
- package/dist/store-reads/stats.d.ts +2 -2
- package/dist/store-reads/stats.js +13 -7
- package/dist/store-view.js +10 -7
- package/dist/suggestions.d.ts +1 -1
- package/dist/suggestions.js +29 -13
- package/dist/template-eval.d.ts +91 -9
- package/dist/template-eval.js +448 -105
- package/dist/template-import.d.ts +0 -10
- package/dist/template-import.js +5 -10
- package/dist/timeline/labels.d.ts +1 -1
- package/dist/timeline/labels.js +4 -3
- package/dist/timeline/timeline.d.ts +23 -11
- package/dist/timeline/timeline.js +115 -31
- package/dist/timeline/web-calls.d.ts +14 -14
- package/dist/timeline/web-calls.js +18 -30
- package/dist/tool-gate.d.ts +13 -1
- package/dist/tool-gate.js +43 -3
- package/dist/tool-keys-store.js +2 -4
- package/dist/tool-keys.d.ts +11 -0
- package/dist/tool-keys.js +16 -0
- package/dist/tool-plane.d.ts +50 -11
- package/dist/tool-plane.js +94 -30
- package/dist/tools.d.ts +5 -1
- package/dist/tools.js +7 -7
- package/dist/trigger-email.js +12 -6
- package/dist/triggers.d.ts +15 -34
- package/dist/triggers.js +119 -126
- package/dist/validate.d.ts +8 -1
- package/dist/validate.js +163 -23
- package/dist/web-fake.d.ts +2 -1
- package/dist/web-fake.js +8 -6
- package/dist/web-fetch.d.ts +8 -6
- package/dist/web-fetch.js +13 -11
- package/dist/web-holds.d.ts +32 -0
- package/dist/web-holds.js +86 -0
- package/dist/web-run.d.ts +32 -5
- package/dist/web-run.js +75 -28
- package/dist/web-save.d.ts +4 -9
- package/dist/web-save.js +27 -55
- package/dist/web-search.js +14 -25
- package/dist/wires.d.ts +4 -3
- package/dist/wires.js +5 -4
- package/dist/workspace/archil-claim.d.ts +12 -5
- package/dist/workspace/archil-claim.js +45 -5
- package/dist/workspace/attach.js +52 -19
- package/dist/workspace/attached-computers.d.ts +38 -11
- package/dist/workspace/attached-computers.js +81 -16
- package/dist/workspace/computer-deps.d.ts +29 -7
- package/dist/workspace/computer-deps.js +36 -18
- package/dist/workspace/computer-for-claim.d.ts +21 -4
- package/dist/workspace/computer-for-claim.js +166 -57
- package/dist/workspace/computer-intervals.d.ts +2 -0
- package/dist/workspace/computer-intervals.js +1 -1
- package/dist/workspace/computer-janitor.d.ts +48 -14
- package/dist/workspace/computer-janitor.js +153 -44
- package/dist/workspace/computer-kept.d.ts +158 -32
- package/dist/workspace/computer-kept.js +288 -63
- package/dist/workspace/computer-providers.d.ts +8 -3
- package/dist/workspace/computer-providers.js +12 -5
- package/dist/workspace/index.d.ts +1 -1
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/local.js +41 -1
- package/dist/workspace/mount-revoke-left.d.ts +31 -0
- package/dist/workspace/mount-revoke-left.js +72 -0
- package/dist/workspace/paired-route.d.ts +91 -0
- package/dist/workspace/paired-route.js +152 -0
- package/dist/workspace/resolve-computer.d.ts +5 -2
- package/dist/workspace/resolve-computer.js +9 -3
- package/dist/workspace/run-end-computers.d.ts +11 -5
- package/dist/workspace/run-end-computers.js +153 -28
- package/dist/workspace/run-tools.d.ts +22 -3
- package/dist/workspace/run-tools.js +17 -5
- package/dist/workspace/run-workspace.d.ts +14 -1
- package/dist/workspace/run-workspace.js +34 -1
- package/dist/workspace/workspace.d.ts +6 -0
- package/dist/wrapped.d.ts +8 -2
- package/dist/wrapped.js +21 -6
- package/package.json +12 -13
- package/skills/agentrun-serve/SKILL.md +5 -2
- package/templates/README.md +25 -9
- package/dist/console/assets/backend-DVhHzJX2.js +0 -166
- package/dist/console/assets/index-Bwn1oTem.css +0 -1
- package/dist/console/assets/index-okP-y8PK.js +0 -747
package/dist/paid-calls.d.ts
CHANGED
|
@@ -54,10 +54,10 @@ export declare function booking<T extends ToolRegistration>(tool: T): T;
|
|
|
54
54
|
export declare const bookedIn: <T>(ledger: Ledger | undefined, work: () => Promise<T>) => Promise<T>;
|
|
55
55
|
/** `send`, one request to a paid provider at `fee`, on the run's one ledger under the call it runs in (Ledger.paid):
|
|
56
56
|
* admitted at the fee's price, then sent, then settled at what it may have charged (its price on a 2xx, a 408 or a 5xx
|
|
57
|
-
* or when it threw after it was sent
|
|
58
|
-
* less. It throws PaidRefused, in the cap's words, when the cap does not hold its price, when its hold could not be kept,
|
|
57
|
+
* or when it threw after it was sent, or what `charged` says it cost, never above its price; $0 on another 4xx); a
|
|
58
|
+
* settle that cannot be written leaves it at its hold, never less, and `settled` hears which. It throws PaidRefused, in the cap's words, when the cap does not hold its price, when its hold could not be kept,
|
|
59
59
|
* or when the call has no run's ledger, and then nothing is sent. A request that throws throws, settled at its price. */
|
|
60
|
-
export declare function paidRequest(fee: Fee, send: () => Promise<Response
|
|
60
|
+
export declare function paidRequest(fee: Fee, send: () => Promise<Response>, charged?: () => number, settled?: (booked: boolean) => void): Promise<Response>;
|
|
61
61
|
/** paidStep's chargeOf for a step that charged nothing and is given back: its mark settled with no charge row. */
|
|
62
62
|
export declare const GIVEN_BACK = "given back";
|
|
63
63
|
/** Whether the current work runs inside a call's ledger (bookedIn): a host tool call of the run's, or a workflow call
|
|
@@ -85,7 +85,8 @@ export declare const stopRunWith: (pause: NonNullable<Ledger["pause"]>) => (word
|
|
|
85
85
|
* or why its hold could not be kept), then `run`, then settled at `chargeOf` its outcome (null: at its hold; GIVEN_BACK:
|
|
86
86
|
* given back, nothing charged, as a hold-only step's: a request its provider refused unrun leaves no charge row). One refused
|
|
87
87
|
* for room pauses the run through `pause`, else through the ledger of the call it runs in (bookedIn's), as main's
|
|
88
|
-
* paidCall pauses: a step outside any host tool call (a pi-native tool's, the browser's) passes the run's own.
|
|
88
|
+
* paidCall pauses: a step outside any host tool call (a pi-native tool's, the browser's) passes the run's own. A settle
|
|
89
|
+
* that could not be written leaves the step at its hold, and its result says so (`unsettled`). */
|
|
89
90
|
export declare function paidStep<T>(paid: PaidBooking, call: string | undefined, fee: {
|
|
90
91
|
name: string;
|
|
91
92
|
holdUsd: number;
|
|
@@ -105,4 +106,5 @@ export declare function paidStep<T>(paid: PaidBooking, call: string | undefined,
|
|
|
105
106
|
refused: string;
|
|
106
107
|
} | {
|
|
107
108
|
result: T;
|
|
109
|
+
unsettled?: true;
|
|
108
110
|
}>;
|
package/dist/paid-calls.js
CHANGED
|
@@ -56,16 +56,23 @@ export const bookedIn = (ledger, work) => (ledger ? ledgers.run(ledger, work) :
|
|
|
56
56
|
const billed = (status) => (status >= 200 && status < 300) || status === 408 || status >= 500;
|
|
57
57
|
/** `send`, one request to a paid provider at `fee`, on the run's one ledger under the call it runs in (Ledger.paid):
|
|
58
58
|
* admitted at the fee's price, then sent, then settled at what it may have charged (its price on a 2xx, a 408 or a 5xx
|
|
59
|
-
* or when it threw after it was sent
|
|
60
|
-
* less. It throws PaidRefused, in the cap's words, when the cap does not hold its price, when its hold could not be kept,
|
|
59
|
+
* or when it threw after it was sent, or what `charged` says it cost, never above its price; $0 on another 4xx); a
|
|
60
|
+
* settle that cannot be written leaves it at its hold, never less, and `settled` hears which. It throws PaidRefused, in the cap's words, when the cap does not hold its price, when its hold could not be kept,
|
|
61
61
|
* or when the call has no run's ledger, and then nothing is sent. A request that throws throws, settled at its price. */
|
|
62
|
-
export async function paidRequest(fee, send) {
|
|
62
|
+
export async function paidRequest(fee, send, charged, settled) {
|
|
63
63
|
const ledger = ledgers.getStore();
|
|
64
64
|
if (!ledger?.paid)
|
|
65
65
|
throw new PaidRefused(unbookedRefusal(fee.name));
|
|
66
|
-
const
|
|
66
|
+
const said = () => {
|
|
67
|
+
// `charged` may be the provider's estimate (Jev's, where it reports no cost): booked on purpose, as nearer the real
|
|
68
|
+
// charge than the hold, and never above the hold (Math.min below).
|
|
69
|
+
const usd = charged?.();
|
|
70
|
+
return typeof usd === "number" && Number.isFinite(usd) && usd >= 0 ? Math.min(usd, fee.usd) : fee.usd;
|
|
71
|
+
};
|
|
72
|
+
const stepped = await paidStep(ledger.paid, ledger.call, { name: fee.name, holdUsd: fee.usd, basis: fee.basis, by: fee.by }, send, (outcome) => ("thrown" in outcome ? fee.usd : billed(outcome.result.status) ? said() : 0));
|
|
67
73
|
if ("refused" in stepped)
|
|
68
74
|
throw new PaidRefused(stepped.refused);
|
|
75
|
+
settled?.(stepped.unsettled !== true);
|
|
69
76
|
return stepped.result;
|
|
70
77
|
}
|
|
71
78
|
/** paidStep's chargeOf for a step that charged nothing and is given back: its mark settled with no charge row. */
|
|
@@ -115,7 +122,8 @@ export const stopRunWith = (pause) => async (words) => {
|
|
|
115
122
|
* or why its hold could not be kept), then `run`, then settled at `chargeOf` its outcome (null: at its hold; GIVEN_BACK:
|
|
116
123
|
* given back, nothing charged, as a hold-only step's: a request its provider refused unrun leaves no charge row). One refused
|
|
117
124
|
* for room pauses the run through `pause`, else through the ledger of the call it runs in (bookedIn's), as main's
|
|
118
|
-
* paidCall pauses: a step outside any host tool call (a pi-native tool's, the browser's) passes the run's own.
|
|
125
|
+
* paidCall pauses: a step outside any host tool call (a pi-native tool's, the browser's) passes the run's own. A settle
|
|
126
|
+
* that could not be written leaves the step at its hold, and its result says so (`unsettled`). */
|
|
119
127
|
export async function paidStep(paid, call, fee, run, chargeOf, pause) {
|
|
120
128
|
const id = `${call ?? fee.ref ?? fee.name}#${(paidSeq += 1)}`;
|
|
121
129
|
let admitted;
|
|
@@ -138,8 +146,8 @@ export async function paidStep(paid, call, fee, run, chargeOf, pause) {
|
|
|
138
146
|
}
|
|
139
147
|
// A hold-only step (`hold`) is given back, never a charge: its money is booked by its own charges' steps.
|
|
140
148
|
const charge = fee.hold ? GIVEN_BACK : chargeOf(outcome);
|
|
141
|
-
await (charge === GIVEN_BACK ? paid.settle(id, 0, { givenBack: true }) : paid.settle(id, charge)).
|
|
149
|
+
const landed = await (charge === GIVEN_BACK ? paid.settle(id, 0, { givenBack: true }) : paid.settle(id, charge)).then(() => true, () => false);
|
|
142
150
|
if ("thrown" in outcome)
|
|
143
151
|
throw outcome.thrown;
|
|
144
|
-
return outcome;
|
|
152
|
+
return landed ? outcome : { ...outcome, unsettled: true };
|
|
145
153
|
}
|
package/dist/place-offers.d.ts
CHANGED
|
@@ -1,13 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { type ProviderEntry } from "@parcha/agentrun-computer";
|
|
2
|
+
/**
|
|
3
|
+
* Whether a computer provider can be a box, read from its descriptor's facts (PROVIDERS' entry). A place names a box
|
|
4
|
+
* alone, no kind, image or network, so a run in it gets a sandbox computer on that provider with no image named
|
|
5
|
+
* (computer-setting.ts computerOfPlace), resolved and started by the claim as any computer setting is
|
|
6
|
+
* (workspace/resolve-computer.ts, computer-deps.ts computerSpecOf), and it needs:
|
|
7
|
+
* - a Linux shell with files and processes, for bash and the background tools: the provider serves the sandbox kind;
|
|
8
|
+
* - the run's folder in that shell: it takes a bind, an Archil mount or a synced folder (its derived mounts; a provider
|
|
9
|
+
* whose machines keep their own disk where the folder would be takes none);
|
|
10
|
+
* - an image with none named: its default sandbox image, or the one its prepareImage() makes;
|
|
11
|
+
* - what places.allow says: its computers keep to a host list, or reach nothing (its network forms hold allow or none).
|
|
12
|
+
* One that reaches only its vendor's own network can't be held to the list.
|
|
13
|
+
* Which mode's folder it takes (a bind in Mode 1, Archil or a synced one in Mode 2) is the run's start's check, as for
|
|
14
|
+
* any computer setting: the mode can change while the server runs.
|
|
15
|
+
*/
|
|
16
|
+
export declare const isBox: (entry: ProviderEntry) => boolean;
|
|
17
|
+
/** Every box a place may name, in the order capabilities lists them (Settings' order of providers). */
|
|
18
|
+
export declare const BOX_IDS: readonly string[];
|
|
19
|
+
/** The boxes on this machine's container engine (their descriptor's `local`: Docker's), the boxes a server sets up when
|
|
20
|
+
* AGENTRUN_BOXES is not set at all. Their engine is Docker, so a local box is probed at the start with `docker
|
|
21
|
+
* version` (probeDocker), its computers mount this server's paths (box-paths.ts) and keep out the Docker host's own
|
|
22
|
+
* addresses (docker-host-addresses.ts). */
|
|
23
|
+
export declare const LOCAL_BOXES: readonly string[];
|
|
4
24
|
/** A box as capabilities show it: whether this server has it, and why when not (or how it was checked); `state`, which
|
|
5
25
|
* capabilities derive from it (place.ts stated). `network`: what an available box reaches (BOX_NETWORKS), with
|
|
6
26
|
* `network_reason` when it is available and has none for a cause of its own (a daemon elsewhere). `host_addresses`: for Docker from a container (compose.yaml), the Docker host's own addresses
|
|
7
27
|
* its computers' egress proxy refuses as the host's (docker-host-addresses.ts: the read through the socket and
|
|
8
28
|
* AGENTRUN_DOCKER_HOST_ADDRESSES). */
|
|
9
29
|
export type BoxOffer = {
|
|
10
|
-
id:
|
|
30
|
+
id: string;
|
|
11
31
|
available: boolean;
|
|
12
32
|
state?: BoxState;
|
|
13
33
|
reason?: string;
|
|
@@ -21,47 +41,45 @@ export type BoxNetwork = (typeof BOX_NETWORKS)[number];
|
|
|
21
41
|
/** A box's state in capabilities: ready (available) or unavailable. */
|
|
22
42
|
export declare const BOX_STATES: readonly ["ready", "unavailable"];
|
|
23
43
|
export type BoxState = (typeof BOX_STATES)[number];
|
|
24
|
-
/** The remote boxes' keys: secrets the server holds and its computer providers read, which no run is handed
|
|
25
|
-
* (run-secrets.ts SERVER_ONLY). */
|
|
26
|
-
export declare const BOX_KEYS: readonly string[];
|
|
27
44
|
/** The setting that lists the boxes to set up: a comma list of box ids, empty or `none` for no box. */
|
|
28
45
|
export declare const BOXES_ENV = "AGENTRUN_BOXES";
|
|
29
|
-
/**
|
|
30
|
-
export declare const DEFAULT_BOXES: readonly BoxId[];
|
|
31
|
-
/** Whether `env` leaves the boxes to this server's default (DEFAULT_BOXES): AGENTRUN_BOXES is not set at all. */
|
|
46
|
+
/** Whether `env` leaves the boxes to this server's default (LOCAL_BOXES): AGENTRUN_BOXES is not set at all. */
|
|
32
47
|
export declare const boxesByDefault: (env: NodeJS.ProcessEnv) => boolean;
|
|
33
|
-
/** The boxes `env` lists in AGENTRUN_BOXES,
|
|
48
|
+
/** The boxes `env` lists in AGENTRUN_BOXES, LOCAL_BOXES when it is not set, none when it is empty or `none`; a name
|
|
34
49
|
* that is no box throws, naming it, and so does `none` with another. */
|
|
35
|
-
export declare function enabledBoxes(env: NodeJS.ProcessEnv): Set<
|
|
50
|
+
export declare function enabledBoxes(env: NodeJS.ProcessEnv): Set<string>;
|
|
36
51
|
/** The start's log line: the boxes available, the rest, and why each box AGENTRUN_BOXES lists (`listed`) is not available. */
|
|
37
|
-
export declare function boxesLog(offers: readonly BoxOffer[], listed: ReadonlySet<
|
|
52
|
+
export declare function boxesLog(offers: readonly BoxOffer[], listed: ReadonlySet<string>): Record<string, string>;
|
|
38
53
|
/** Why docker is unavailable when its daemon refuses this server's process its socket (EACCES on /var/run/docker.sock)
|
|
39
54
|
* and the group file lists this user in the docker group: this process started before the user joined it (a systemd
|
|
40
55
|
* user manager that has run since, kept by linger), so a restart of that manager, or a new login, gives it the group. */
|
|
41
56
|
export declare const DOCKER_NOT_IN_GROUP = "This server's process isn't in the docker group: restart your user manager with `sudo systemctl restart user@$(id -u)`, or log in again if linger is off";
|
|
42
57
|
/** The same, when the group file does not list this user in the docker group (or cannot say): joining comes first. */
|
|
43
58
|
export declare const DOCKER_JOIN_GROUP = "This server's process isn't in the docker group: add this user to it with `sudo usermod -aG docker $USER`, then restart your user manager with `sudo systemctl restart user@$(id -u)`, or log in again if linger is off";
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*
|
|
48
|
-
|
|
59
|
+
/** No Docker daemon for this server, as Settings → Computers says it (docker-daemon.ts noDockerWords). */
|
|
60
|
+
export declare const NO_DOCKER_HERE = "No Docker on this server: Render and most hosted services run none.";
|
|
61
|
+
/** Why docker is unavailable to a server in AgentRun's image that has no Docker socket: a hosted service (Fly.io, Render,
|
|
62
|
+
* a Kubernetes pod), the one-container `docker run` and deploy/'s compose file give it none, so it asks a daemon that is
|
|
63
|
+
* not there. Starting Docker or joining its group would not help. Hosted, there is no host socket to give, so the way is
|
|
64
|
+
* a vendor's computer, as Settings → Computers says (its opening sentence is the same); on a machine the person runs,
|
|
65
|
+
* compose.yaml at the repository's root mounts the host's socket, which is root on that host (compose.yaml's own header
|
|
66
|
+
* says so), so the words say that too. */
|
|
67
|
+
export declare const DOCKER_NO_SOCKET = "No Docker on this server: Render and most hosted services run none. Its agents get file tools and web_fetch but no shell. For a shell, use a vendor computer (Settings \u2192 Computers); or, on a machine you run, give this server the host's Docker socket, as `docker compose up -d` with compose.yaml at the repository's root does. That socket is root on the host, so give it only where you would give AgentRun root";
|
|
49
68
|
/** The same, for a container given the socket and refused it: the group compose.yaml adds (DOCKER_GID) is not the
|
|
50
69
|
* socket's. usermod in the container would not last past its restart. */
|
|
51
70
|
export declare const DOCKER_SOCKET_GROUP = "This server's container may not use the Docker socket: set DOCKER_GID in .env to the socket's group, as compose.yaml says, then run `docker compose up -d` again";
|
|
52
|
-
/**
|
|
53
|
-
* path is there (`exists`: the socket a failed probe names). What a failed probe says to do. */
|
|
71
|
+
/** Where this server runs: on a host, in AgentRun's own image (IMAGE_ENV), or in some other container; and how it tells
|
|
72
|
+
* whether a path is there (`exists`: the socket a failed probe names). What a failed probe says to do. */
|
|
54
73
|
export type ContainerFacts = {
|
|
55
|
-
|
|
56
|
-
image?: boolean;
|
|
74
|
+
where: "host" | "image" | "other";
|
|
57
75
|
exists?: (path: string) => boolean;
|
|
58
76
|
};
|
|
59
77
|
/** Set by AgentRun's image (packages/serve/docker/Dockerfile): the socket advice (DOCKER_NO_SOCKET, DOCKER_SOCKET_GROUP)
|
|
60
78
|
* is for it alone, and Kubernetes and other containerd runtimes, which write no mark of their own, run it too. */
|
|
61
79
|
export declare const IMAGE_ENV = "AGENTRUN_IN_IMAGE";
|
|
62
|
-
/** A container: AgentRun's image (IMAGE_ENV), or
|
|
63
|
-
*
|
|
64
|
-
export declare const containerOf: (env: NodeJS.ProcessEnv,
|
|
80
|
+
/** A container: AgentRun's image (IMAGE_ENV), or any other that computer's containerSigns sees under `root` (the
|
|
81
|
+
* filesystem's root; the tests' seam): a runtime's mark or a container's cgroup, such as a Kubernetes pod's. */
|
|
82
|
+
export declare const containerOf: (env: NodeJS.ProcessEnv, root?: string) => ContainerFacts;
|
|
65
83
|
/** How long Docker's probe may take. */
|
|
66
84
|
export declare const PROBE_TIMEOUT_MS = 5000;
|
|
67
85
|
/** What `docker version` says of this machine's Docker daemon: it answers (`up`), or why not. `absent`: no daemon
|
|
@@ -97,19 +115,26 @@ export type PlaceOffersOptions = {
|
|
|
97
115
|
/** Whether this server runs in a container, and how a path is checked, which say a failed probe's fix (containerReason);
|
|
98
116
|
* default this process's. */
|
|
99
117
|
container?: ContainerFacts;
|
|
100
|
-
/** Under --faux only:
|
|
118
|
+
/** Under --faux only: the local box answers, whatever AGENTRUN_BOXES lists, and nothing asks Docker. */
|
|
101
119
|
fauxDocker?: boolean;
|
|
120
|
+
/** Told the architecture of the Docker daemon the probe found (amd64, arm64), when Docker answers and names it: the
|
|
121
|
+
* server's check that a Docker computer's daemon is built for it (box-paths.ts dockerComputerRefusal) asks Docker
|
|
122
|
+
* nothing more. */
|
|
123
|
+
dockerArch?: (arch: string) => void;
|
|
102
124
|
};
|
|
103
|
-
/** Every box, in BOX_IDS order, as this server has it at its start (`env`: its environment, its secrets readable): a box
|
|
104
|
-
*
|
|
125
|
+
/** Every box, in BOX_IDS order, as this server has it at its start (`env`: its environment, its secrets readable): a box
|
|
126
|
+
* AGENTRUN_BOXES does not list is not enabled; a local box by Docker's probe (or `fauxDocker`); a vendor's by its
|
|
127
|
+
* provider's required keys. Rejects only for a name in AGENTRUN_BOXES that is no box. No reason holds a key or an
|
|
128
|
+
* answer's body. */
|
|
105
129
|
export declare function placeOffers(env: NodeJS.ProcessEnv, options?: PlaceOffersOptions): Promise<BoxOffer[]>;
|
|
106
|
-
/** What each available box reaches, from the server's host list (`allow`, box-settings.ts boxAllowOf)
|
|
130
|
+
/** What each available box reaches, from the server's host list (`allow`, box-settings.ts boxAllowOf). A local box's
|
|
107
131
|
* computers through their egress proxy (an allowlist), with the Docker host's own addresses it refuses when the server
|
|
108
|
-
* runs in a container (`hostAddresses`), or unavailable where `
|
|
109
|
-
* (box-paths.ts dockerComputerRefusal, docker-host-addresses.ts noHostAddresses)
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
|
|
132
|
+
* runs in a container (`local.hostAddresses`), or unavailable where `local.refused` says Docker can't run a computer
|
|
133
|
+
* here (box-paths.ts dockerComputerRefusal, docker-host-addresses.ts noHostAddresses). A vendor's box as its provider's
|
|
134
|
+
* network forms say: the list where its computers keep to one, through the egress proxy their init starts
|
|
135
|
+
* (@parcha/agentrun-computer's hosted/network.ts); nothing where they make no network but none, as the claim narrows
|
|
136
|
+
* them (computer-deps.ts networkOf), saying so. With `allow` none, none has a network. */
|
|
137
|
+
export declare function withNetworks(offers: readonly BoxOffer[], allow: readonly string[] | "none", local?: {
|
|
113
138
|
refused?: string;
|
|
114
139
|
hostAddresses?: readonly string[];
|
|
115
140
|
faux?: boolean;
|
package/dist/place-offers.js
CHANGED
|
@@ -1,42 +1,65 @@
|
|
|
1
1
|
// The boxes a place may name, as capabilities show them (places.boxes), read from the computers runs execute on: a
|
|
2
2
|
// sandbox place on box X is a sandbox computer on provider X (computer-setting.ts computerOfPlace), which a run's claim
|
|
3
|
-
// starts (workspace/).
|
|
3
|
+
// starts (workspace/). Which providers are boxes is their descriptors' facts (isBox), never a list of names. Read once,
|
|
4
|
+
// at the server's start: each fix takes a restart.
|
|
4
5
|
//
|
|
5
|
-
// AGENTRUN_BOXES lists the boxes to set up. Not set at all, it is
|
|
6
|
-
// Docker and offers it when Docker answers, so a new agent lands in its box
|
|
7
|
-
// to list. Set, it wins: a box it does not list is never probed and is
|
|
8
|
-
// lists it, an empty value or `none` sets up no box, and a name in it
|
|
9
|
-
// what to do next.
|
|
10
|
-
// provider requires are set (the server's environment, else saved in
|
|
11
|
-
// at the start: a key the vendor refuses fails the run's computer
|
|
6
|
+
// AGENTRUN_BOXES lists the boxes to set up. Not set at all, it is the boxes on this machine's container engine alone
|
|
7
|
+
// (LOCAL_BOXES, Docker's): a plain start probes Docker and offers it when Docker answers, so a new agent lands in its box
|
|
8
|
+
// (place.ts); every other box is the operator's to list. Set, it wins: a box it does not list is never probed and is
|
|
9
|
+
// unavailable, its reason naming the setting that lists it, an empty value or `none` sets up no box, and a name in it
|
|
10
|
+
// that is no box refuses the start. Every reason says what to do next. A local box is probed (`docker version`); a
|
|
11
|
+
// vendor's box is offered when the keys its computer provider requires are set (the server's environment, else saved in
|
|
12
|
+
// Settings → Computers), and is not asked anything at the start: a key the vendor refuses fails the run's computer
|
|
13
|
+
// start, in the vendor's words.
|
|
12
14
|
import { execFile } from "node:child_process";
|
|
13
15
|
import { existsSync } from "node:fs";
|
|
14
16
|
import { readFile } from "node:fs/promises";
|
|
15
17
|
import { userInfo } from "node:os";
|
|
16
|
-
import { PROVIDERS } from "@parcha/agentrun-computer";
|
|
18
|
+
import { containerSigns, PROVIDERS } from "@parcha/agentrun-computer";
|
|
19
|
+
import { BOX_ALLOW_ENV } from "./box-settings.js";
|
|
17
20
|
import { withoutSecrets } from "./secrets.js";
|
|
18
|
-
/**
|
|
19
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Whether a computer provider can be a box, read from its descriptor's facts (PROVIDERS' entry). A place names a box
|
|
23
|
+
* alone, no kind, image or network, so a run in it gets a sandbox computer on that provider with no image named
|
|
24
|
+
* (computer-setting.ts computerOfPlace), resolved and started by the claim as any computer setting is
|
|
25
|
+
* (workspace/resolve-computer.ts, computer-deps.ts computerSpecOf), and it needs:
|
|
26
|
+
* - a Linux shell with files and processes, for bash and the background tools: the provider serves the sandbox kind;
|
|
27
|
+
* - the run's folder in that shell: it takes a bind, an Archil mount or a synced folder (its derived mounts; a provider
|
|
28
|
+
* whose machines keep their own disk where the folder would be takes none);
|
|
29
|
+
* - an image with none named: its default sandbox image, or the one its prepareImage() makes;
|
|
30
|
+
* - what places.allow says: its computers keep to a host list, or reach nothing (its network forms hold allow or none).
|
|
31
|
+
* One that reaches only its vendor's own network can't be held to the list.
|
|
32
|
+
* Which mode's folder it takes (a bind in Mode 1, Archil or a synced one in Mode 2) is the run's start's check, as for
|
|
33
|
+
* any computer setting: the mode can change while the server runs.
|
|
34
|
+
*/
|
|
35
|
+
export const isBox = (entry) => entry.kinds.includes("sandbox") &&
|
|
36
|
+
entry.mounts.length > 0 &&
|
|
37
|
+
(entry.defaultImage?.sandbox !== undefined || entry.prepareImage === true) &&
|
|
38
|
+
(entry.network.includes("allow") || entry.network.includes("none"));
|
|
39
|
+
/** Every box a place may name, in the order capabilities lists them (Settings' order of providers). */
|
|
40
|
+
export const BOX_IDS = PROVIDERS.filter(isBox).map((entry) => entry.id);
|
|
41
|
+
/** The provider entry of box `id`. */
|
|
42
|
+
const boxEntry = (id) => PROVIDERS.find((entry) => entry.id === id);
|
|
43
|
+
/** The boxes on this machine's container engine (their descriptor's `local`: Docker's), the boxes a server sets up when
|
|
44
|
+
* AGENTRUN_BOXES is not set at all. Their engine is Docker, so a local box is probed at the start with `docker
|
|
45
|
+
* version` (probeDocker), its computers mount this server's paths (box-paths.ts) and keep out the Docker host's own
|
|
46
|
+
* addresses (docker-host-addresses.ts). */
|
|
47
|
+
export const LOCAL_BOXES = BOX_IDS.filter((id) => boxEntry(id).local === true);
|
|
20
48
|
/** What an available box reaches: the hosts of `places.allow` (`allowlist`), or nothing (`none`). */
|
|
21
49
|
export const BOX_NETWORKS = ["allowlist", "none"];
|
|
22
50
|
/** A box's state in capabilities: ready (available) or unavailable. */
|
|
23
51
|
export const BOX_STATES = ["ready", "unavailable"];
|
|
24
|
-
/** The remote boxes' keys: secrets the server holds and its computer providers read, which no run is handed
|
|
25
|
-
* (run-secrets.ts SERVER_ONLY). */
|
|
26
|
-
export const BOX_KEYS = ["DAYTONA_API_KEY", "MODAL_TOKEN_ID", "MODAL_TOKEN_SECRET"];
|
|
27
52
|
/** The setting that lists the boxes to set up: a comma list of box ids, empty or `none` for no box. */
|
|
28
53
|
export const BOXES_ENV = "AGENTRUN_BOXES";
|
|
29
|
-
/** The boxes a server sets up when AGENTRUN_BOXES is not set at all: Docker, probed as if listed. */
|
|
30
|
-
export const DEFAULT_BOXES = ["docker"];
|
|
31
54
|
/** The AGENTRUN_BOXES that sets up no box, as an empty one does. */
|
|
32
55
|
const NO_BOXES = "none";
|
|
33
|
-
/** Whether `env` leaves the boxes to this server's default (
|
|
56
|
+
/** Whether `env` leaves the boxes to this server's default (LOCAL_BOXES): AGENTRUN_BOXES is not set at all. */
|
|
34
57
|
export const boxesByDefault = (env) => env[BOXES_ENV] === undefined;
|
|
35
|
-
/** The boxes `env` lists in AGENTRUN_BOXES,
|
|
58
|
+
/** The boxes `env` lists in AGENTRUN_BOXES, LOCAL_BOXES when it is not set, none when it is empty or `none`; a name
|
|
36
59
|
* that is no box throws, naming it, and so does `none` with another. */
|
|
37
60
|
export function enabledBoxes(env) {
|
|
38
61
|
if (boxesByDefault(env))
|
|
39
|
-
return new Set(
|
|
62
|
+
return new Set(LOCAL_BOXES);
|
|
40
63
|
const names = env[BOXES_ENV].split(",").map((name) => name.trim()).filter(Boolean);
|
|
41
64
|
if (names.includes(NO_BOXES)) {
|
|
42
65
|
if (names.length > 1)
|
|
@@ -82,26 +105,29 @@ const ownGroups = () => {
|
|
|
82
105
|
catch { }
|
|
83
106
|
return { file: "/etc/group", user, ids: process.getgroups?.() ?? [] };
|
|
84
107
|
};
|
|
85
|
-
/**
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
*
|
|
89
|
-
|
|
108
|
+
/** No Docker daemon for this server, as Settings → Computers says it (docker-daemon.ts noDockerWords). */
|
|
109
|
+
export const NO_DOCKER_HERE = "No Docker on this server: Render and most hosted services run none.";
|
|
110
|
+
/** Why docker is unavailable to a server in AgentRun's image that has no Docker socket: a hosted service (Fly.io, Render,
|
|
111
|
+
* a Kubernetes pod), the one-container `docker run` and deploy/'s compose file give it none, so it asks a daemon that is
|
|
112
|
+
* not there. Starting Docker or joining its group would not help. Hosted, there is no host socket to give, so the way is
|
|
113
|
+
* a vendor's computer, as Settings → Computers says (its opening sentence is the same); on a machine the person runs,
|
|
114
|
+
* compose.yaml at the repository's root mounts the host's socket, which is root on that host (compose.yaml's own header
|
|
115
|
+
* says so), so the words say that too. */
|
|
116
|
+
export const DOCKER_NO_SOCKET = `${NO_DOCKER_HERE} Its agents get file tools and web_fetch but no shell. For a shell, use a vendor computer (Settings → Computers); or, on a machine you run, give this server the host's Docker socket, as \`docker compose up -d\` with compose.yaml at the repository's root does. That socket is root on the host, so give it only where you would give AgentRun root`;
|
|
90
117
|
/** The same, for a container given the socket and refused it: the group compose.yaml adds (DOCKER_GID) is not the
|
|
91
118
|
* socket's. usermod in the container would not last past its restart. */
|
|
92
119
|
export const DOCKER_SOCKET_GROUP = "This server's container may not use the Docker socket: set DOCKER_GID in .env to the socket's group, as compose.yaml says, then run `docker compose up -d` again";
|
|
93
120
|
/** Set by AgentRun's image (packages/serve/docker/Dockerfile): the socket advice (DOCKER_NO_SOCKET, DOCKER_SOCKET_GROUP)
|
|
94
121
|
* is for it alone, and Kubernetes and other containerd runtimes, which write no mark of their own, run it too. */
|
|
95
122
|
export const IMAGE_ENV = "AGENTRUN_IN_IMAGE";
|
|
96
|
-
/** A container: AgentRun's image (IMAGE_ENV), or
|
|
97
|
-
*
|
|
98
|
-
export const containerOf = (env,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
};
|
|
123
|
+
/** A container: AgentRun's image (IMAGE_ENV), or any other that computer's containerSigns sees under `root` (the
|
|
124
|
+
* filesystem's root; the tests' seam): a runtime's mark or a container's cgroup, such as a Kubernetes pod's. */
|
|
125
|
+
export const containerOf = (env, root = "/") => ({
|
|
126
|
+
where: env[IMAGE_ENV] === "1" ? "image" : containerSigns(root) !== undefined ? "other" : "host",
|
|
127
|
+
});
|
|
102
128
|
/** A reason in a container that is not AgentRun's image: the host's words, said to be the container's (its own Docker, its
|
|
103
129
|
* own docker group), never compose.yaml's, which is not there to use. */
|
|
104
|
-
const inOtherContainer = (container, reason) => (container.
|
|
130
|
+
const inOtherContainer = (container, reason) => (container.where === "other" ? `This server runs in a container. ${reason}` : reason);
|
|
105
131
|
/** The daemon address docker names when it cannot connect ("Cannot connect to the Docker daemon at unix:///….sock."):
|
|
106
132
|
* the one its DOCKER_HOST or current context resolved to. Matched, never shown. */
|
|
107
133
|
const DAEMON_AT = /docker daemon at ([a-z]+:\/\/\S+?)\.?(?:\s|$)/i;
|
|
@@ -117,7 +143,7 @@ function socketThere(endpoint, env, exists) {
|
|
|
117
143
|
* a host and in another container (inOtherContainer), and for a socket that is there and whose daemon does not answer
|
|
118
144
|
* (the host's Docker is down). */
|
|
119
145
|
const containerReason = (answer, env, container) => {
|
|
120
|
-
if (
|
|
146
|
+
if (container.where !== "image" || answer.failed === undefined)
|
|
121
147
|
return undefined;
|
|
122
148
|
if (answer.denied)
|
|
123
149
|
return DOCKER_SOCKET_GROUP;
|
|
@@ -149,13 +175,16 @@ export async function askDockerDaemon(env, signal, groups = ownGroups(), contain
|
|
|
149
175
|
const code = error?.code;
|
|
150
176
|
resolve({ ...(error ? { failed: typeof code === "number" ? `exit ${code}` : errorName(error), ...(SOCKET_DENIED.test(String(stderr)) ? { denied: true } : {}), ...endpointIn(stderr) } : {}), out: String(stdout) });
|
|
151
177
|
}));
|
|
152
|
-
|
|
178
|
+
// An absent daemon's reason is read by no one: Settings → Computers and a run's start say noDockerWords instead
|
|
179
|
+
// (computers.ts, resolve-computer.ts), so only a refused socket's words are said to be another container's.
|
|
180
|
+
const absent = (reason) => ({ up: false, absent: true, reason });
|
|
153
181
|
// The box's probe runs once, at the start: each fix takes a restart. Docker is on by default, so its reason is often a
|
|
154
182
|
// first-time user's first read: what is wrong in plain words, what the probe saw, then what to do.
|
|
155
|
-
// In
|
|
156
|
-
|
|
183
|
+
// In AgentRun's image, a socket that refused this process is that socket's group's to fix (containerReason), never the
|
|
184
|
+
// host's; a socket that is not there is no daemon, which every reader words as none (noDockerWords).
|
|
185
|
+
const inside = answer.denied ? containerReason(answer, env, container) : undefined;
|
|
157
186
|
if (inside !== undefined)
|
|
158
|
-
return { up: false, absent:
|
|
187
|
+
return { up: false, absent: false, reason: inside };
|
|
159
188
|
if (answer.failed === "ENOENT")
|
|
160
189
|
return absent("Docker isn't running on this machine (no docker command on PATH): install or start Docker, then restart AgentRun");
|
|
161
190
|
// Its socket refused this process: the group it lacks, and how to get it without a reboot (the words, never docker's):
|
|
@@ -169,13 +198,13 @@ export async function askDockerDaemon(env, signal, groups = ownGroups(), contain
|
|
|
169
198
|
return { up: true };
|
|
170
199
|
}
|
|
171
200
|
/** Docker's offer: `docker version` names the daemon's version, so the CLI is on PATH and its daemon answers this user.
|
|
172
|
-
* Bounded by `timeoutMs`; never rejects. */
|
|
173
|
-
async function probeDocker(env, timeoutMs, groups, container) {
|
|
201
|
+
* The same call names the daemon's architecture, told to `arch` when it does. Bounded by `timeoutMs`; never rejects. */
|
|
202
|
+
async function probeDocker(env, timeoutMs, groups, container, arch) {
|
|
174
203
|
const no = (reason) => ({ id: "docker", available: false, reason: inOtherContainer(container, reason) });
|
|
175
204
|
// Its environment is the server's through the cut a run's takes (withoutSecrets): no box key, no other secret, no
|
|
176
205
|
// name shaped like a key.
|
|
177
206
|
const dockerEnv = withoutSecrets(env);
|
|
178
|
-
const answer = await new Promise((resolve) => execFile("docker", ["version", "--format", "{{.Server.Version}}"], { env: dockerEnv, timeout: timeoutMs, killSignal: "SIGKILL", maxBuffer: 64 * 1024 }, (error, stdout, stderr) => {
|
|
207
|
+
const answer = await new Promise((resolve) => execFile("docker", ["version", "--format", "{{.Server.Version}} {{.Server.Arch}}"], { env: dockerEnv, timeout: timeoutMs, killSignal: "SIGKILL", maxBuffer: 64 * 1024 }, (error, stdout, stderr) => {
|
|
179
208
|
const failed = error;
|
|
180
209
|
const code = failed?.code;
|
|
181
210
|
resolve({ ...(failed ? { failed: typeof code === "number" ? `exit ${code}` : errorName(failed), ...(failed.killed ? { late: true } : {}), ...(SOCKET_DENIED.test(String(stderr)) ? { denied: true } : {}), ...endpointIn(stderr) } : {}), out: String(stdout) });
|
|
@@ -197,12 +226,15 @@ async function probeDocker(env, timeoutMs, groups, container) {
|
|
|
197
226
|
return no(`Docker isn't running on this machine, or this user may not use it (docker version failed: ${answer.failed}): start Docker, or add this user to the docker group, then restart AgentRun`);
|
|
198
227
|
if (!answer.out.trim())
|
|
199
228
|
return no("Docker isn't running on this machine (docker version named no daemon): start Docker, then restart AgentRun");
|
|
229
|
+
const named = /^\S+\s+(\S+)$/.exec(answer.out.trim())?.[1];
|
|
230
|
+
if (named !== undefined)
|
|
231
|
+
arch?.(named);
|
|
200
232
|
return { id: "docker", available: true };
|
|
201
233
|
}
|
|
202
|
-
/** A
|
|
234
|
+
/** A vendor's box's offer: available when every key its computer provider requires is set, read as a run's claim reads
|
|
203
235
|
* it (`keyOf`: the server's environment, else the key saved in Settings → Computers); nothing is asked of the vendor. */
|
|
204
236
|
async function remoteOffer(id, keyOf) {
|
|
205
|
-
const required = (
|
|
237
|
+
const required = boxEntry(id).keys.filter((key) => key.required).map((key) => key.name);
|
|
206
238
|
const missing = [];
|
|
207
239
|
for (const name of required)
|
|
208
240
|
if ((await keyOf(name)) === undefined)
|
|
@@ -211,41 +243,51 @@ async function remoteOffer(id, keyOf) {
|
|
|
211
243
|
return { id, available: false, reason: `needs ${missing.join(" and ")}` };
|
|
212
244
|
return { id, available: true, reason: "configured; not probed at start" };
|
|
213
245
|
}
|
|
214
|
-
/** Every box, in BOX_IDS order, as this server has it at its start (`env`: its environment, its secrets readable): a box
|
|
215
|
-
*
|
|
246
|
+
/** Every box, in BOX_IDS order, as this server has it at its start (`env`: its environment, its secrets readable): a box
|
|
247
|
+
* AGENTRUN_BOXES does not list is not enabled; a local box by Docker's probe (or `fauxDocker`); a vendor's by its
|
|
248
|
+
* provider's required keys. Rejects only for a name in AGENTRUN_BOXES that is no box. No reason holds a key or an
|
|
249
|
+
* answer's body. */
|
|
216
250
|
export async function placeOffers(env, options = {}) {
|
|
217
251
|
const enabled = enabledBoxes(env);
|
|
218
252
|
const keyOf = options.keyOf ?? (async (name) => env[name] || undefined);
|
|
219
253
|
return Promise.all(BOX_IDS.map(async (id) => {
|
|
254
|
+
const local = LOCAL_BOXES.includes(id);
|
|
220
255
|
// The tests' faux docker stands in whatever AGENTRUN_BOXES lists, as the old faux box did.
|
|
221
|
-
if (
|
|
256
|
+
if (local && options.fauxDocker)
|
|
222
257
|
return { id, available: true, reason: "a faux docker (tests)" };
|
|
223
258
|
if (!enabled.has(id))
|
|
224
259
|
return { id, available: false, reason: notEnabled(id, enabled) };
|
|
225
|
-
|
|
226
|
-
|
|
260
|
+
// A local box's engine is Docker (LOCAL_BOXES), so its probe is Docker's own, which answers as the docker box.
|
|
261
|
+
if (local)
|
|
262
|
+
return probeDocker(env, options.timeoutMs ?? PROBE_TIMEOUT_MS, options.groups ?? ownGroups(), options.container ?? containerOf(env), options.dockerArch);
|
|
227
263
|
return remoteOffer(id, keyOf);
|
|
228
264
|
}));
|
|
229
265
|
}
|
|
230
|
-
/** What each available box reaches, from the server's host list (`allow`, box-settings.ts boxAllowOf)
|
|
266
|
+
/** What each available box reaches, from the server's host list (`allow`, box-settings.ts boxAllowOf). A local box's
|
|
231
267
|
* computers through their egress proxy (an allowlist), with the Docker host's own addresses it refuses when the server
|
|
232
|
-
* runs in a container (`hostAddresses`), or unavailable where `
|
|
233
|
-
* (box-paths.ts dockerComputerRefusal, docker-host-addresses.ts noHostAddresses)
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
|
|
268
|
+
* runs in a container (`local.hostAddresses`), or unavailable where `local.refused` says Docker can't run a computer
|
|
269
|
+
* here (box-paths.ts dockerComputerRefusal, docker-host-addresses.ts noHostAddresses). A vendor's box as its provider's
|
|
270
|
+
* network forms say: the list where its computers keep to one, through the egress proxy their init starts
|
|
271
|
+
* (@parcha/agentrun-computer's hosted/network.ts); nothing where they make no network but none, as the claim narrows
|
|
272
|
+
* them (computer-deps.ts networkOf), saying so. With `allow` none, none has a network. */
|
|
273
|
+
export function withNetworks(offers, allow, local = {}) {
|
|
237
274
|
return offers.map((offer) => {
|
|
238
275
|
if (!offer.available)
|
|
239
276
|
return offer;
|
|
240
|
-
if (offer.id
|
|
241
|
-
if (
|
|
242
|
-
return { id: offer.id, available: false, state: "unavailable", reason:
|
|
243
|
-
if (
|
|
277
|
+
if (LOCAL_BOXES.includes(offer.id)) {
|
|
278
|
+
if (local.refused !== undefined)
|
|
279
|
+
return { id: offer.id, available: false, state: "unavailable", reason: local.refused };
|
|
280
|
+
if (local.faux)
|
|
244
281
|
return { ...offer, network: "none", network_reason: "a faux docker (tests)" };
|
|
245
282
|
if (allow === "none")
|
|
246
283
|
return { ...offer, network: "none", network_reason: "AGENTRUN_BOX_ALLOW is none" };
|
|
247
|
-
return { ...offer, network: "allowlist", ...(
|
|
284
|
+
return { ...offer, network: "allowlist", ...(local.hostAddresses?.length ? { host_addresses: [...local.hostAddresses] } : {}) };
|
|
248
285
|
}
|
|
249
|
-
|
|
286
|
+
if (allow === "none")
|
|
287
|
+
return { ...offer, network: "none" };
|
|
288
|
+
const entry = boxEntry(offer.id);
|
|
289
|
+
if (entry.network.includes("allow"))
|
|
290
|
+
return { ...offer, network: "allowlist" };
|
|
291
|
+
return { ...offer, network: "none", network_reason: `${entry.label}'s computers run with no network, whatever ${BOX_ALLOW_ENV} lists` };
|
|
250
292
|
});
|
|
251
293
|
}
|
package/dist/place.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type BoxOffer } from "./place-offers.js";
|
|
2
2
|
import { type InputIssue } from "./errors.js";
|
|
3
3
|
export declare const PLACE_MODES: readonly ["runner", "sandbox"];
|
|
4
4
|
export type PlaceMode = (typeof PLACE_MODES)[number];
|
|
@@ -6,15 +6,13 @@ export type Place = {
|
|
|
6
6
|
mode: "runner";
|
|
7
7
|
} | {
|
|
8
8
|
mode: "sandbox";
|
|
9
|
-
box:
|
|
9
|
+
box: string;
|
|
10
10
|
};
|
|
11
|
-
/**
|
|
12
|
-
export declare const RUN_BOXES: readonly BoxId[];
|
|
13
|
-
/** The boxes this server gives runs, from what it found at its start (place-offers.ts): a box runs execute in that it
|
|
14
|
-
* has, and no other. */
|
|
11
|
+
/** Every box, from what this server found at its start (place-offers.ts): one it did not find is not set up. */
|
|
15
12
|
export declare function boxAvailability(registry: readonly BoxOffer[]): BoxOffer[];
|
|
16
|
-
/** The place a new agentic definition that names none is saved with: the
|
|
17
|
-
* `reason` saying why, in
|
|
13
|
+
/** The place a new agentic definition that names none is saved with: the local box (Docker's) where this server has it;
|
|
14
|
+
* else none, so the agent runs on the runner as it did before, with `reason` saying why, in its probe's own words. A
|
|
15
|
+
* workflow is never given one. */
|
|
18
16
|
export declare function newAgentPlace(registry: readonly BoxOffer[]): {
|
|
19
17
|
place: Place;
|
|
20
18
|
} | {
|
|
@@ -35,13 +33,14 @@ export declare function defaultPlaceOf(kind: "agentic" | "workflow", tools: read
|
|
|
35
33
|
* this list to; written out here, since background.ts reads this module). A definition that names its tools, an empty
|
|
36
34
|
* list included, keeps exactly those. */
|
|
37
35
|
export declare const NEW_AGENT_TOOLS: readonly string[];
|
|
38
|
-
/** Why a sandbox-only tool (bash) cannot run on this server: no box
|
|
39
|
-
* Undefined when one is. */
|
|
40
|
-
export declare function noBoxReason(registry: readonly BoxOffer[]): string | undefined;
|
|
36
|
+
/** Why a sandbox-only tool (bash) cannot run on this server: no box is available, each box AGENTRUN_BOXES lists
|
|
37
|
+
* (`listed`) with its reason, then the boxes it does not list. Undefined when one is. */
|
|
38
|
+
export declare function noBoxReason(registry: readonly BoxOffer[], listed: ReadonlySet<string>): string | undefined;
|
|
41
39
|
/** The start banner's words on the boxes: which are ready for a sandbox agent's tools, then why each box is not that
|
|
42
|
-
* AGENTRUN_BOXES lists (`listed`),
|
|
43
|
-
* `byDefault`, with AGENTRUN_BOXES not set at all: short,
|
|
44
|
-
|
|
40
|
+
* AGENTRUN_BOXES lists (`listed`), and, when none is ready, the boxes it does not list, with what to do.
|
|
41
|
+
* `byDefault`, with AGENTRUN_BOXES not set at all: short, the local box alone, said to be on by default, or why it is
|
|
42
|
+
* not. */
|
|
43
|
+
export declare function boxesLine(registry: readonly BoxOffer[], listed: ReadonlySet<string>, allow?: readonly string[] | "none", byDefault?: boolean): string;
|
|
45
44
|
/** `places` in capabilities: the modes a revision may name, the place a new agent is saved with and a revision that
|
|
46
45
|
* names none runs in (`default_place`, with `default_reason` when it is the runner), each box, and the hosts a box whose
|
|
47
46
|
* `network` is `allowlist` reaches (`allow`, box-settings.ts boxAllowOf; empty for `none`). */
|