@parcha/agentrun-serve 0.1.0-beta.33 → 0.1.0-beta.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +368 -0
- package/README.md +341 -208
- package/dist/adapters.d.ts +3 -4
- package/dist/adapters.js +18 -15
- package/dist/agent-rows.d.ts +99 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +75 -25
- package/dist/agents.d.ts +9 -125
- package/dist/agents.js +15 -305
- package/dist/answer-json.d.ts +23 -0
- package/dist/answer-json.js +58 -0
- package/dist/api-only.d.ts +1 -1
- package/dist/api-only.js +2 -2
- package/dist/archil-settings.d.ts +11 -1
- package/dist/archil-settings.js +10 -0
- package/dist/bash-read-only.d.ts +35 -0
- package/dist/bash-read-only.js +778 -0
- package/dist/box-settings.d.ts +3 -23
- package/dist/box-settings.js +7 -51
- package/dist/boxes.d.ts +17 -0
- package/dist/boxes.js +27 -20
- package/dist/browser-commands.d.ts +5 -2
- package/dist/browser-commands.js +4 -4
- package/dist/browser-computer.d.ts +5 -0
- package/dist/browser-computer.js +21 -0
- package/dist/browser-cost.d.ts +9 -6
- package/dist/browser-cost.js +95 -51
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -51
- package/dist/browser-person.js +94 -277
- package/dist/budget.d.ts +0 -5
- package/dist/budget.js +0 -5
- package/dist/cap.d.ts +14 -8
- package/dist/cap.js +19 -9
- package/dist/cli.js +71 -18
- package/dist/closed-pipes.d.ts +2 -0
- package/dist/closed-pipes.js +13 -0
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +2 -0
- package/dist/computer-keys.d.ts +20 -10
- package/dist/computer-keys.js +36 -54
- package/dist/computer-setting.d.ts +20 -3
- package/dist/computer-setting.js +58 -10
- package/dist/computers.d.ts +35 -2
- package/dist/computers.js +72 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-B7NKTU8E.css +1 -0
- package/dist/console/assets/index-CXZMgJE7.js +550 -0
- package/dist/console/index.html +2 -2
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/decision-cap.d.ts +7 -29
- package/dist/decision-cap.js +3 -94
- package/dist/decision-rows.d.ts +1 -1
- package/dist/decision-rows.js +1 -1
- package/dist/docker-daemon.d.ts +31 -0
- package/dist/docker-daemon.js +56 -0
- package/dist/effort-guidance.js +4 -3
- package/dist/environment.d.ts +0 -3
- package/dist/environment.js +3 -5
- package/dist/errors.d.ts +1 -2
- package/dist/errors.js +9 -9
- package/dist/explain.js +3 -1
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -3
- package/dist/files.js +2 -4
- package/dist/github-connection.d.ts +1 -1
- package/dist/github-connection.js +25 -7
- package/dist/github-faux.d.ts +26 -0
- package/dist/github-faux.js +76 -0
- package/dist/github.d.ts +6 -2
- package/dist/github.js +5 -3
- package/dist/graph-served.d.ts +5 -3
- package/dist/graph-served.js +14 -6
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +9 -16
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +1 -7
- package/dist/harness-install.js +1 -18
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- package/dist/harness-opencode/harness.js +0 -1
- package/dist/harness-opencode/host/policy.js +2 -2
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/verify.d.ts +17 -0
- package/dist/harness-opencode/verify.js +30 -10
- package/dist/harness-table.js +6 -1
- package/dist/heard.js +1 -1
- package/dist/held-fd.d.ts +5 -0
- package/dist/held-fd.js +14 -0
- package/dist/host-calls.d.ts +20 -0
- package/dist/host-calls.js +12 -0
- package/dist/host-tools.d.ts +4 -21
- package/dist/host-tools.js +4 -61
- package/dist/host.d.ts +2 -4
- package/dist/host.js +2 -7
- package/dist/import-summary.d.ts +1 -5
- package/dist/import-summary.js +0 -21
- package/dist/import.d.ts +6 -6
- package/dist/import.js +14 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +8 -2
- package/dist/learn/check.js +85 -31
- package/dist/learn/folder.d.ts +11 -4
- package/dist/learn/folder.js +17 -19
- package/dist/learn/grade.d.ts +18 -1
- package/dist/learn/grade.js +108 -14
- package/dist/learn/index.d.ts +5 -5
- package/dist/learn/index.js +5 -5
- package/dist/learn/learning.sh +1 -14
- package/dist/learn/notes.d.ts +14 -3
- package/dist/learn/notes.js +16 -6
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +83 -6
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +7 -1
- package/dist/learn/secrets.js +86 -19
- package/dist/learn/skills.d.ts +159 -18
- package/dist/learn/skills.js +644 -64
- package/dist/learned-nodes.d.ts +14 -0
- package/dist/learned-nodes.js +8 -0
- package/dist/learned-workflow.d.ts +41 -6
- package/dist/learned-workflow.js +153 -18
- package/dist/learning-routes.d.ts +49 -4
- package/dist/learning-routes.js +113 -31
- package/dist/learning-run.d.ts +16 -31
- package/dist/learning-run.js +31 -38
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +91 -97
- package/dist/learning.js +176 -320
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +12 -2
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +4 -2
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +17 -49
- package/dist/mcp-gateway.js +55 -136
- package/dist/mcp-oauth.d.ts +10 -14
- package/dist/mcp-oauth.js +14 -32
- package/dist/mcp-probe.d.ts +0 -7
- package/dist/mcp-probe.js +4 -10
- package/dist/mcp-servers-store.d.ts +18 -18
- package/dist/mcp-servers-store.js +12 -14
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +9 -7
- package/dist/model.js +51 -27
- package/dist/monid.d.ts +0 -2
- package/dist/monid.js +3 -6
- package/dist/openapi.d.ts +8 -1
- package/dist/openapi.js +156 -58
- package/dist/page.d.ts +1 -3
- package/dist/page.js +6 -18
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +26 -61
- package/dist/pause.d.ts +2 -19
- package/dist/pause.js +5 -74
- package/dist/port-models.d.ts +10 -3
- package/dist/port-models.js +26 -6
- package/dist/propose.d.ts +2 -0
- package/dist/propose.js +80 -45
- package/dist/push-handler.d.ts +1 -1
- package/dist/reflect-range.d.ts +25 -0
- package/dist/reflect-range.js +30 -0
- package/dist/refusal-words.d.ts +5 -1
- package/dist/refusal-words.js +5 -1
- package/dist/rows.d.ts +1 -1
- package/dist/run-cut.d.ts +0 -6
- package/dist/run-cut.js +0 -6
- package/dist/run-db.d.ts +2 -11
- package/dist/run-db.js +2 -37
- package/dist/run-launch.d.ts +21 -2
- package/dist/run-launch.js +14 -5
- package/dist/run-learning-served.d.ts +21 -4
- package/dist/run-learning-served.js +23 -13
- package/dist/run-reads-over-store.d.ts +5 -3
- package/dist/run-reads-over-store.js +25 -14
- package/dist/run-secrets.d.ts +1 -1
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +27 -6
- package/dist/run-view.d.ts +37 -22
- package/dist/run-view.js +85 -38
- package/dist/runnable.d.ts +21 -10
- package/dist/runnable.js +35 -12
- package/dist/runner/adapter-loop.d.ts +36 -5
- package/dist/runner/adapter-loop.js +663 -69
- package/dist/runner/adapter-run-spec.d.ts +42 -8
- package/dist/runner/adapter-run-spec.js +186 -52
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +40 -2
- package/dist/runner/adapters/pi.js +110 -27
- package/dist/runner/beside.d.ts +38 -3
- package/dist/runner/beside.js +54 -5
- package/dist/runner/claim-secrets.d.ts +16 -1
- package/dist/runner/claim-secrets.js +62 -14
- package/dist/runner/cli-run-spec.d.ts +5 -0
- package/dist/runner/cli-run-spec.js +159 -41
- package/dist/runner/commands.js +1 -1
- package/dist/runner/computer-journal.d.ts +15 -2
- package/dist/runner/computer-journal.js +41 -5
- package/dist/runner/conformance/harness.d.ts +1 -0
- package/dist/runner/conformance/harness.js +123 -13
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/dispatch.d.ts +8 -1
- package/dist/runner/dispatch.js +81 -7
- package/dist/runner/end-of-run.d.ts +8 -2
- package/dist/runner/end-of-run.js +10 -4
- package/dist/runner/github-app.d.ts +7 -2
- package/dist/runner/github-app.js +47 -16
- package/dist/runner/harness-loops.d.ts +15 -2
- package/dist/runner/harness-loops.js +38 -2
- package/dist/runner/journal-kinds.d.ts +60 -6
- package/dist/runner/journal-kinds.js +43 -5
- package/dist/runner/journal-reader.d.ts +1 -1
- package/dist/runner/journal-reader.js +2 -2
- package/dist/runner/learning-ask.d.ts +4 -0
- package/dist/runner/learning-ask.js +15 -1
- package/dist/runner/learning-end.d.ts +18 -3
- package/dist/runner/learning-end.js +194 -20
- package/dist/runner/learning-loop.d.ts +7 -0
- package/dist/runner/learning-loop.js +36 -8
- package/dist/runner/learning-seed.d.ts +6 -0
- package/dist/runner/learning-seed.js +6 -0
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.d.ts +61 -9
- package/dist/runner/main.js +144 -20
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +7 -3
- package/dist/runner/mcp-github.d.ts +11 -2
- package/dist/runner/mcp-github.js +55 -4
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +16 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +46 -1
- package/dist/runner/metrics.js +156 -1
- package/dist/runner/model-route.d.ts +16 -0
- package/dist/runner/model-route.js +134 -10
- package/dist/runner/reflect-hook.d.ts +12 -1
- package/dist/runner/reflect-hook.js +33 -3
- package/dist/runner/runner.d.ts +20 -0
- package/dist/runner/runner.js +146 -18
- package/dist/runner/spec-holds.d.ts +7 -2
- package/dist/runner/spec-holds.js +4 -3
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +3 -3
- package/dist/runner/store-secrets.js +8 -12
- package/dist/runner/text-tools.d.ts +44 -0
- package/dist/runner/text-tools.js +237 -0
- package/dist/runner/workflow-host.d.ts +7 -2
- package/dist/runner/workflow-host.js +3 -1
- package/dist/runner/workflow-loop.d.ts +10 -1
- package/dist/runner/workflow-loop.js +14 -6
- package/dist/runner/workflow-spec.d.ts +21 -0
- package/dist/runner/workflow-spec.js +217 -93
- package/dist/runs-over-store.d.ts +14 -3
- package/dist/runs-over-store.js +100 -23
- package/dist/seal-key.d.ts +0 -2
- package/dist/seal-key.js +5 -45
- package/dist/sealed-settings-store.d.ts +19 -4
- package/dist/sealed-settings-store.js +9 -9
- package/dist/sealing.d.ts +4 -0
- package/dist/sealing.js +20 -0
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/secret-name.d.ts +9 -0
- package/dist/secret-name.js +15 -0
- package/dist/secret-writes.d.ts +0 -1
- package/dist/secret-writes.js +0 -1
- package/dist/server-fs.d.ts +4 -0
- package/dist/server-fs.js +8 -2
- package/dist/server-lock.d.ts +0 -24
- package/dist/server-lock.js +5 -85
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +9 -31
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -36
- package/dist/server.d.ts +37 -56
- package/dist/server.js +322 -134
- package/dist/sign-ins-store.d.ts +34 -36
- package/dist/sign-ins-store.js +27 -38
- package/dist/sign-ins.d.ts +2 -119
- package/dist/sign-ins.js +5 -311
- package/dist/standard-webhooks.d.ts +1 -1
- package/dist/standard-webhooks.js +1 -1
- package/dist/stats.d.ts +3 -2
- package/dist/stats.js +1 -1
- package/dist/stop-signals.d.ts +4 -2
- package/dist/stop-signals.js +5 -3
- package/dist/store/agent-body.d.ts +12 -2
- package/dist/store/agent-body.js +22 -4
- package/dist/store/deadline.d.ts +18 -0
- package/dist/store/deadline.js +45 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +2 -2
- package/dist/store/open.d.ts +6 -3
- package/dist/store/open.js +2 -2
- package/dist/store/postgres/connection.d.ts +22 -2
- package/dist/store/postgres/connection.js +211 -41
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +9 -2
- package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
- package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
- package/dist/store/postgres/store.d.ts +9 -2
- package/dist/store/postgres/store.js +9 -0
- package/dist/store/schema.js +1 -1
- package/dist/store/seal.js +2 -2
- package/dist/store/sqlite/connection.js +14 -5
- package/dist/store/sqlite/run-patch.d.ts +3 -0
- package/dist/store/sqlite/run-patch.js +3 -0
- package/dist/store/sqlite/store.js +41 -12
- package/dist/store/store.d.ts +35 -6
- package/dist/store/store.js +12 -2
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +22 -4
- package/dist/store-reads/journal.d.ts +9 -6
- package/dist/store-reads/journal.js +129 -18
- package/dist/store-reads/learning.d.ts +82 -8
- package/dist/store-reads/learning.js +184 -11
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +19 -1
- package/dist/store-view.js +95 -27
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +33 -14
- package/dist/templates.js +82 -46
- package/dist/timeline/group.d.ts +33 -0
- package/dist/timeline/group.js +77 -0
- package/dist/timeline/index.d.ts +7 -0
- package/dist/timeline/index.js +7 -0
- package/dist/timeline/labels.d.ts +79 -0
- package/dist/timeline/labels.js +150 -0
- package/dist/timeline/origin.d.ts +56 -0
- package/dist/timeline/origin.js +92 -0
- package/dist/timeline/render-text.d.ts +11 -0
- package/dist/timeline/render-text.js +62 -0
- package/dist/timeline/timeline.d.ts +282 -0
- package/dist/timeline/timeline.js +1308 -0
- package/dist/timeline/util.d.ts +17 -0
- package/dist/timeline/util.js +49 -0
- package/dist/tool-budget.d.ts +18 -0
- package/dist/tool-budget.js +50 -0
- package/dist/tool-gate.d.ts +47 -218
- package/dist/tool-gate.js +87 -545
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +5 -101
- package/dist/tool-keys.js +8 -267
- package/dist/tool-plane.d.ts +23 -52
- package/dist/tool-plane.js +23 -81
- package/dist/tool-settings-store.d.ts +1 -2
- package/dist/tool-settings-store.js +5 -8
- package/dist/tools.d.ts +67 -25
- package/dist/tools.js +170 -119
- package/dist/trigger-adapter.d.ts +2 -2
- package/dist/trigger-targets.d.ts +13 -1
- package/dist/trigger-targets.js +31 -1
- package/dist/triggers.d.ts +2 -2
- package/dist/triggers.js +3 -3
- package/dist/turn-end.d.ts +1 -1
- package/dist/turn-end.js +1 -1
- package/dist/turns.d.ts +0 -6
- package/dist/turns.js +0 -19
- package/dist/uploads.d.ts +28 -5
- package/dist/uploads.js +83 -10
- package/dist/usage.d.ts +1 -49
- package/dist/usage.js +3 -84
- package/dist/validate.d.ts +4 -0
- package/dist/validate.js +33 -14
- package/dist/webhooks.d.ts +102 -76
- package/dist/webhooks.js +266 -233
- package/dist/workflow-run.d.ts +114 -0
- package/dist/workflow-run.js +144 -0
- package/dist/workspace/archil-claim.d.ts +2 -2
- package/dist/workspace/archil-claim.js +4 -3
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +4 -0
- package/dist/workspace/archil-exec.d.ts +12 -2
- package/dist/workspace/archil-exec.js +16 -0
- package/dist/workspace/archil.d.ts +2 -2
- package/dist/workspace/archil.js +25 -5
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +26 -9
- package/dist/workspace/computer-deps.js +144 -43
- package/dist/workspace/computer-for-claim.d.ts +17 -14
- package/dist/workspace/computer-for-claim.js +99 -26
- package/dist/workspace/computer-hold.d.ts +6 -1
- package/dist/workspace/computer-hold.js +6 -1
- package/dist/workspace/computer-janitor.d.ts +47 -0
- package/dist/workspace/computer-janitor.js +182 -0
- package/dist/workspace/computer-ledger.d.ts +1 -8
- package/dist/workspace/computer-ledger.js +0 -3
- package/dist/workspace/computer-providers.d.ts +5 -3
- package/dist/workspace/computer-providers.js +11 -9
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/hands.d.ts +5 -2
- package/dist/workspace/hands.js +4 -3
- package/dist/workspace/index.d.ts +6 -5
- package/dist/workspace/index.js +4 -4
- package/dist/workspace/local.d.ts +14 -2
- package/dist/workspace/local.js +170 -43
- package/dist/workspace/paths.js +3 -2
- package/dist/workspace/pi-env.d.ts +4 -0
- package/dist/workspace/pi-env.js +3 -2
- package/dist/workspace/resolve-computer.d.ts +55 -10
- package/dist/workspace/resolve-computer.js +66 -14
- package/dist/workspace/run-tools.d.ts +15 -31
- package/dist/workspace/run-tools.js +19 -30
- package/dist/workspace/workspace.d.ts +5 -0
- package/dist/workspace-paths.d.ts +0 -17
- package/dist/workspace-paths.js +1 -41
- package/dist/workspace.d.ts +0 -17
- package/dist/workspace.js +4 -110
- package/package.json +14 -14
- package/skills/agentrun-serve/SKILL.md +1 -1
- package/templates/README.md +11 -5
- package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
- package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
- package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
- package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
- package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
- package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
- package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
- package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
- package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
- package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/templates/release-notes/agent.md +11 -0
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- package/dist/coding-tools.d.ts +0 -47
- package/dist/coding-tools.js +0 -189
- package/dist/computer-adb.d.ts +0 -12
- package/dist/computer-adb.js +0 -14
- package/dist/console/assets/index-Dn0ngwG9.js +0 -535
- package/dist/console/assets/index-DvW6Aled.css +0 -1
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- package/dist/mcp-servers.d.ts +0 -269
- package/dist/mcp-servers.js +0 -456
- package/dist/packs.d.ts +0 -71
- package/dist/packs.js +0 -180
- package/dist/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -171
- package/dist/sessions.d.ts +0 -6
- package/dist/sessions.js +0 -109
- package/dist/workspace/computer-serves.d.ts +0 -12
- package/dist/workspace/computer-serves.js +0 -15
package/dist/cap.js
CHANGED
|
@@ -48,11 +48,9 @@ import { readRunDbSync } from "./run-db.js";
|
|
|
48
48
|
import { durableDecisions } from "@parcha/agentrun-pi/durable";
|
|
49
49
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
50
50
|
import { existsSync } from "node:fs";
|
|
51
|
-
import { providerInputOverhead } from "@parcha/agentrun-kernel/host";
|
|
51
|
+
import { imageInputOf, 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,8 +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
76
|
/** How long after a request ended the next one in its conversation is expected to read its cache: 4 minutes, inside
|
|
81
77
|
* Anthropic's 5 (a cache kept that long from its last use; OpenAI's lasts longer). A request later than that is priced
|
|
82
78
|
* with nothing cached. */
|
|
@@ -657,6 +653,13 @@ export function meterFiguresIn(storeFile) {
|
|
|
657
653
|
return { tools: 0, tokens: null, browser: { usd: 0, seconds: 0 }, others: 0, known: { tokens: 0, browser: 0, others: 0 } };
|
|
658
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)) }))));
|
|
659
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";
|
|
660
663
|
/** meterFiguresIn's figures from a run's entries by conversation, in log order: the one computation, shared by
|
|
661
664
|
* meterFiguresIn (reading a settled run's own database) and the one-store reader (store-reads/cap.ts metersOverStore, over
|
|
662
665
|
* A's journal). Only where the entries come from changes; the figures do not (the money-parity rule), as spentFrom is to
|
|
@@ -673,6 +676,10 @@ export function meterFiguresFrom(rows) {
|
|
|
673
676
|
const known = { tokens: 0, browser: 0, others: 0 };
|
|
674
677
|
for (const { entry } of rows) {
|
|
675
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;
|
|
676
683
|
if (entry.kind === TOOL_STARTED)
|
|
677
684
|
marks.add(data.call);
|
|
678
685
|
else if (entry.kind === TOOL_COST)
|
|
@@ -872,15 +879,18 @@ function outputBound(model) {
|
|
|
872
879
|
return [model.cost, ...(model.cost?.tiers ?? [])].every((rates) => rates?.output === 0) ? 0 : undefined;
|
|
873
880
|
}
|
|
874
881
|
/** A request's input tokens, bounded above: one per UTF-8 byte of what is sent (a byte-level tokenizer never takes
|
|
875
|
-
* fewer than one byte a token,
|
|
876
|
-
*
|
|
882
|
+
* fewer than one byte a token), plus `overhead`: what the provider adds server-side that the body does not hold, and
|
|
883
|
+
* each image at what it is billed as in place of its base64's bytes (below 0 for a large image: piOverhead). The same
|
|
884
|
+
* bound on every harness. */
|
|
877
885
|
export const inputBound = (sent, overhead = 0) => Buffer.byteLength(sent, "utf8") + overhead;
|
|
878
886
|
/** What pi's provider adds server-side to a request of `context`, the same table the model proxy uses, by the model's API
|
|
879
887
|
* kind: undefined for a kind whose additions are not known. The context does not say how the request chooses a tool,
|
|
880
888
|
* so the dearer choice is taken. */
|
|
881
889
|
export function piOverhead(model, context) {
|
|
882
890
|
const parts = (context.messages ?? []).flatMap((message) => (Array.isArray(message.content) ? (message.content) : []));
|
|
883
|
-
|
|
891
|
+
// Each image, in every turn, at what the model's provider bills it as by its size, in place of its base64's bytes in
|
|
892
|
+
// what is sent (imageInputOf, imageTokens).
|
|
893
|
+
return providerInputOverhead(model.api, { tools: (context.tools?.length ?? 0) > 0, toolChoice: "any", images: parts.filter((part) => part?.type === "image").map((part) => imageInputOf(part.data)), ...(model.id ? { model: model.id } : {}) });
|
|
884
894
|
}
|
|
885
895
|
const unmeasured = (cap) => `${SPEND_CAP_REACHED}: Not sent: the size of the next model request's input is unknown, so the run's cap of ${money(cap)} cannot be kept: the run is out of budget.`;
|
|
886
896
|
const noPrice = (cap) => `${SPEND_CAP_REACHED}: Not sent: the next model request's model has no price here, so the run's cap of ${money(cap)} cannot be kept: the run is out of budget.`;
|
package/dist/cli.js
CHANGED
|
@@ -16,14 +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
20
|
import { apiOnlyFrom } from "./api-only.js";
|
|
21
|
-
|
|
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();
|
|
25
|
+
const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--open] [--faux MODULE] [--faux-browser MODULE] [--faux-github] [--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]
|
|
22
26
|
agentrun-serve reset-password [--data DIR]
|
|
23
27
|
agentrun-serve validate-template DIR
|
|
24
28
|
agentrun-serve eval-template DIR [--case NAME ...] [--runs N] [--server URL] [--grader-model PROVIDER/MODEL] [--report FILE] [--faux MODULE]
|
|
25
29
|
agentrun-serve import [--data DIR] [--from claude-code,codex,pi] [--dry-run] [--include-deleted] [--all] [--verbose] [--port N]
|
|
26
|
-
agentrun-serve runner --data DIR [--loops N] [--name NAME]
|
|
30
|
+
agentrun-serve runner --data DIR [--loops N] [--drain-timeout D] [--name NAME]
|
|
27
31
|
agentrun-serve runner --check --data DIR [--name NAME]
|
|
28
32
|
|
|
29
33
|
--data DIR the agent store and its runs (default ~/.local/share/agentrun/agents); the token is DIR/.token, mode 0600
|
|
@@ -36,15 +40,20 @@ const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--
|
|
|
36
40
|
--faux-browser MODULE
|
|
37
41
|
with --faux only: the browser tool's provider and driver from MODULE's default export (a fake
|
|
38
42
|
browser, no vendor, no key), for the console's real-browser tests
|
|
43
|
+
--faux-github with --faux only: a fake GitHub App, connected at the start and answered in this process, so
|
|
44
|
+
GitHub triggers run with nothing sent to GitHub; its webhook secret is in DIR/faux-github.json.
|
|
45
|
+
On a scratch data directory: refused where another GitHub App is connected
|
|
39
46
|
--allow-host NAME another Host name to accept (repeatable)
|
|
40
|
-
--max-runs N the most runs
|
|
41
|
-
|
|
47
|
+
--max-runs N the most runs the runner beside the server holds at once, the rest waiting queued (default
|
|
48
|
+
AGENTRUN_MAX_RUNS, else as many pi runs as this host's memory holds); the capabilities'
|
|
49
|
+
max_concurrent_runs says the same
|
|
42
50
|
--documents DIR a read-only directory of documents a workflow's pdf_pages calls read by file name (default
|
|
43
51
|
AGENTRUN_SERVE_DOCUMENTS)
|
|
44
52
|
--allow-code-nodes run workflows' code nodes, in the run's process with no sandbox (default off, or
|
|
45
53
|
AGENTRUN_SERVE_CODE_NODES=1); off, a workflow with one saves with a warning and its runs are refused
|
|
46
|
-
--drain-timeout D how long
|
|
47
|
-
Docker's 10 s grace); a run
|
|
54
|
+
--drain-timeout D how long the runner beside the server lets each busy run finish its turn when the server stops
|
|
55
|
+
(default 30s; the image's is 6s, inside Docker's 10 s grace); a run still busy then is stopped and
|
|
56
|
+
resumes at the next start
|
|
48
57
|
--learning on|off whether runs learn (default on, or AGENTRUN_SERVE_LEARNING): on, a run of an agent whose definition
|
|
49
58
|
says learning: true starts from what that agent learned and adds to it; off, no run does
|
|
50
59
|
--learning-budget BYTES how much of what an agent learned its run's instructions hold (default
|
|
@@ -53,7 +62,10 @@ const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--
|
|
|
53
62
|
--grade-model MODEL the model that grades what a run proposes to learn (default AGENTRUN_SERVE_GRADE_MODEL, else the
|
|
54
63
|
strong tier, AGENT_MODEL_STRONG, else each run's own model), named as the strong tier takes one
|
|
55
64
|
--no-runner run the server alone, with no runner beside it (default: one runner beside the server); start one or
|
|
56
|
-
more \`agentrun-serve runner --data DIR\` processes on the same data directory to claim and run runs
|
|
65
|
+
more \`agentrun-serve runner --data DIR\` processes on the same data directory to claim and run runs;
|
|
66
|
+
each holds at most --loops N runs (default AGENTRUN_MAX_RUNS, else as many pi runs as its host's
|
|
67
|
+
memory holds; the rest wait queued) and on SIGTERM lets each busy run finish its turn for up to
|
|
68
|
+
--drain-timeout D (default AGENTRUN_DRAIN_TIMEOUT, else 6s), then hands the rest back to resume
|
|
57
69
|
|
|
58
70
|
Without --faux, a revision's model ("provider/model-id", or AGENT_MODEL when it names none; a workflow node's tier maps
|
|
59
71
|
to AGENT_MODEL_FAST or AGENT_MODEL_STRONG, each falling back to AGENT_MODEL) is served by pi-ai's providers with their
|
|
@@ -240,6 +252,7 @@ try {
|
|
|
240
252
|
open: { type: "boolean", default: false },
|
|
241
253
|
faux: { type: "string" },
|
|
242
254
|
"faux-browser": { type: "string" },
|
|
255
|
+
"faux-github": { type: "boolean", default: false },
|
|
243
256
|
"allow-host": { type: "string", multiple: true, default: [] },
|
|
244
257
|
"max-runs": { type: "string" },
|
|
245
258
|
"drain-timeout": { type: "string" },
|
|
@@ -282,6 +295,10 @@ if (values["faux-browser"] && !values.faux) {
|
|
|
282
295
|
console.error(`--faux-browser goes with --faux\n\n${USAGE}`);
|
|
283
296
|
process.exit(2);
|
|
284
297
|
}
|
|
298
|
+
if (values["faux-github"] && !values.faux) {
|
|
299
|
+
console.error(`--faux-github goes with --faux\n\n${USAGE}`);
|
|
300
|
+
process.exit(2);
|
|
301
|
+
}
|
|
285
302
|
const budget = values["learning-budget"];
|
|
286
303
|
if (budget !== undefined && !/^\d+$/.test(budget)) {
|
|
287
304
|
console.error(`--learning-budget takes a whole number of bytes\n\n${USAGE}`);
|
|
@@ -289,8 +306,22 @@ if (budget !== undefined && !/^\d+$/.test(budget)) {
|
|
|
289
306
|
}
|
|
290
307
|
const data = values.data ?? defaultData();
|
|
291
308
|
const given = secret("AGENTRUN_TOKEN") || undefined;
|
|
292
|
-
//
|
|
293
|
-
|
|
309
|
+
// The stop is listened for before anything starts: a SIGTERM or SIGINT during the start (a platform's redeploy, the
|
|
310
|
+
// moment the banner shows) is kept, never the default end by signal that cuts what the start began. Once the start has
|
|
311
|
+
// what a stop closes, the stop below takes over (stopOnSignals), and a stop asked meanwhile runs it, through the same
|
|
312
|
+
// drain. A second signal a while after the first, still during the start, is a person who wants out now: exit 130.
|
|
313
|
+
let stopping;
|
|
314
|
+
let askedAt;
|
|
315
|
+
const signalled = () => {
|
|
316
|
+
if (stopping)
|
|
317
|
+
return stopping();
|
|
318
|
+
if (askedAt === undefined)
|
|
319
|
+
askedAt = Date.now();
|
|
320
|
+
else if (Date.now() - askedAt >= REPEAT_MS)
|
|
321
|
+
process.exit(130);
|
|
322
|
+
};
|
|
323
|
+
process.on("SIGINT", signalled);
|
|
324
|
+
process.on("SIGTERM", signalled);
|
|
294
325
|
// AGENTRUN_API_ONLY=1: the run routes alone (api-only.ts), and no owner; a value that is neither on nor off stops here.
|
|
295
326
|
let apiOnly;
|
|
296
327
|
try {
|
|
@@ -324,7 +355,13 @@ const trustedProxies = (process.env.AGENTRUN_TRUSTED_PROXIES ?? "").split(",").m
|
|
|
324
355
|
try {
|
|
325
356
|
serve = await startServe(serveOptions = {
|
|
326
357
|
onBoxImage,
|
|
327
|
-
|
|
358
|
+
// The owner lock on a Postgres store lost for good: this server can serve nothing more, so it exits non-zero and its
|
|
359
|
+
// platform starts it again, rather than answer 503 for as long as it runs.
|
|
360
|
+
onStoreLost: (error) => {
|
|
361
|
+
console.error(`agentrun-serve: ${error.message}`);
|
|
362
|
+
process.exit(1);
|
|
363
|
+
},
|
|
364
|
+
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"] } : {}), ...(values["faux-github"] ? { fauxGitHub: true } : {}), allowHosts: values["allow-host"],
|
|
328
365
|
...(values["max-runs"] !== undefined ? { maxRuns: Number(values["max-runs"]) } : {}),
|
|
329
366
|
...(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`),
|
|
330
367
|
// The public address is the server's with accounts on or off: the Host names it serves, the webhook URLs it gives.
|
|
@@ -340,16 +377,21 @@ catch (error) {
|
|
|
340
377
|
}
|
|
341
378
|
// The start launches one runner beside the server on the same data dir (design: "server and runner"): it claims and runs
|
|
342
379
|
// every run, sharing only the store. With --no-runner the server runs alone, so the operator starts one or more separate
|
|
343
|
-
// `agentrun runner --data DIR` processes on the same data directory instead.
|
|
380
|
+
// `agentrun runner --data DIR` processes on the same data directory instead. The runner holds what the server's flags say
|
|
381
|
+
// (besideRunnerOptions): at most --max-runs runs at once, the rest waiting queued, and on the stop each busy run finishes
|
|
382
|
+
// its turn for up to --drain-timeout.
|
|
344
383
|
let runnerProc;
|
|
345
|
-
|
|
384
|
+
const { loops, drainMs } = besideRunnerOptions(serveOptions, process.env);
|
|
385
|
+
// A stop asked during the server's start starts no runner: nothing is claimed for the stop to cut.
|
|
386
|
+
if (!values["no-runner"] && askedAt === undefined) {
|
|
346
387
|
try {
|
|
347
388
|
// The beside-runner sees the server's test switches (server.ts fauxEnvOf: --faux and its modules), which the CLI hands
|
|
348
389
|
// the server as options, never through this process's environment: without them a --faux start's runner looks its faux
|
|
349
390
|
// model up in pi-ai's own catalog and every run fails on its first request. A test switch this process inherited from
|
|
350
391
|
// its shell is taken out first, as the server's own environment drops it (runner/main.ts besideRunEnv).
|
|
351
392
|
const { besideRunEnv } = await import("./runner/main.js");
|
|
352
|
-
|
|
393
|
+
// With the computer janitor: what a crashed runner of this server left is ended (never under --faux).
|
|
394
|
+
runnerProc = await runnerBeside(data, { loops, drainMs, env: besideRunEnv(process.env, fauxEnvOf(serveOptions)), janitor: true });
|
|
353
395
|
}
|
|
354
396
|
catch (error) {
|
|
355
397
|
console.error(`agentrun-serve: the runner could not start: ${error.message}`);
|
|
@@ -379,14 +421,25 @@ const record = join(resolve(data), SERVER_FILE);
|
|
|
379
421
|
// (stop-signals.ts). The stop is in place before the record is written: a SIGTERM sent the moment the record appears is
|
|
380
422
|
// a clean stop that removes it, never the default end by signal that leaves it behind.
|
|
381
423
|
const stop = stopOnSignals({
|
|
382
|
-
close: () =>
|
|
383
|
-
|
|
424
|
+
close: () => {
|
|
425
|
+
removeOwnRecord(record);
|
|
426
|
+
// A drain that has runs to wait on says so, as a run's own process did on the server's stop.
|
|
427
|
+
const busy = runnerProc?.runner.held().length ?? 0;
|
|
428
|
+
if (busy > 0 && drainMs > 0)
|
|
429
|
+
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"}`);
|
|
430
|
+
return Promise.all([runnerProc?.close() ?? Promise.resolve(), serve.close()]).then(() => undefined);
|
|
431
|
+
},
|
|
432
|
+
// 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
|
|
433
|
+
// and release are never cut short (besideStopping).
|
|
434
|
+
stopping: () => (runnerProc ? besideStopping(serve.stopping(), runnerProc.runner.held().length, drainMs) : serve.stopping()),
|
|
384
435
|
done: (code) => (removeOwnRecord(record), process.exit(code)),
|
|
385
436
|
say: (line) => console.error(line),
|
|
386
437
|
});
|
|
387
|
-
|
|
388
|
-
process.on("SIGTERM", stop);
|
|
438
|
+
stopping = stop;
|
|
389
439
|
// Written whole under a name of its own, then renamed into place: a reader in another process (the npx command, a test
|
|
390
440
|
// waiting for this server) that finds the record reads all of it, never a file made but not yet filled.
|
|
391
441
|
writeDurableSync(record, `${JSON.stringify({ base_url: serve.baseUrl, pid: process.pid, ...(serve.tokenFile ? { token_file: serve.tokenFile } : {}) })}\n`);
|
|
392
442
|
chmodSync(record, 0o600);
|
|
443
|
+
// A stop asked during the start runs now, as one asked from here on would.
|
|
444
|
+
if (askedAt !== undefined)
|
|
445
|
+
stop(askedAt);
|
|
@@ -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.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import { type ProviderEntry } from "@parcha/agentrun-computer";
|
|
2
|
+
/** One key a provider takes: its name in its descriptor, the create() option it fills, and whether it is needed. */
|
|
2
3
|
export interface ProviderKey {
|
|
3
4
|
readonly name: string;
|
|
4
5
|
readonly option: string;
|
|
5
6
|
readonly required: boolean;
|
|
6
7
|
}
|
|
7
|
-
/**
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export interface ProviderSettings {
|
|
13
|
-
readonly modalApp?: string;
|
|
8
|
+
/** A setting that is no key but fills a create() option: its name in the server's settings, and its default. */
|
|
9
|
+
export interface ProviderSetting {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly option: string;
|
|
12
|
+
readonly default?: string;
|
|
14
13
|
}
|
|
14
|
+
/** The server's settings that are no key, by their names in the descriptors (modalApp): what fills each setting. */
|
|
15
|
+
export type ProviderSettings = Readonly<Record<string, string | undefined>>;
|
|
15
16
|
/** An answer in the registry's shape: a value, or an error with its code and words. */
|
|
16
17
|
export type KeyResult<T> = {
|
|
17
18
|
ok: true;
|
|
@@ -48,13 +49,22 @@ export interface TestableProvider {
|
|
|
48
49
|
}
|
|
49
50
|
/** A provider module's create(), by provider id: the computer package's, or a test's stand-in. */
|
|
50
51
|
export type ProviderFactories = Readonly<Partial<Record<string, (options: Record<string, string>) => TestableProvider | Promise<TestableProvider>>>>;
|
|
51
|
-
/** The table the map reads: each provider's keys and
|
|
52
|
+
/** The table the map reads: each provider's keys, settings and name in words, by id. Serve's own (KEY_TABLE, the
|
|
53
|
+
* computer package's descriptors), or --faux's (keyTableOf its entries). */
|
|
52
54
|
export interface KeyTable {
|
|
53
55
|
readonly keys: Readonly<Record<string, readonly ProviderKey[]>>;
|
|
54
56
|
readonly labels: Readonly<Record<string, string>>;
|
|
57
|
+
readonly settings?: Readonly<Record<string, readonly ProviderSetting[]>>;
|
|
55
58
|
}
|
|
59
|
+
/** The key table of `entries` (the kind registry's PROVIDERS, each from its descriptor). */
|
|
60
|
+
export declare function keyTableOf(entries: readonly Pick<ProviderEntry, "id" | "label" | "keys" | "settings">[]): KeyTable;
|
|
61
|
+
/** Serve's table: every provider the computer package declares. */
|
|
56
62
|
export declare const KEY_TABLE: KeyTable;
|
|
57
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* Provider `providerId`'s create() options from its saved keys (by its descriptor's names) and the server's settings
|
|
65
|
+
* (each of its descriptor's settings, by name, else its default). An id the table does not list is refused, naming the
|
|
66
|
+
* providers it does.
|
|
67
|
+
*/
|
|
58
68
|
export declare function providerOptions(providerId: string, keys: Readonly<Record<string, string>>, settings?: ProviderSettings, table?: KeyTable): OptionsAnswer;
|
|
59
69
|
/**
|
|
60
70
|
* Settings' "test connection" for `providerId` (the kind registry's TestConnection, and serve's ComputerRegistry.test):
|
package/dist/computer-keys.js
CHANGED
|
@@ -1,54 +1,36 @@
|
|
|
1
|
-
// Settings → Computers' keys, serve side: a provider's saved keys, by the names
|
|
2
|
-
//
|
|
3
|
-
// (the registry's TestConnection: one account-level read that never makes a computer), its coded
|
|
1
|
+
// Settings → Computers' keys, serve side: a provider's saved keys, by the names its descriptor declares (the computer
|
|
2
|
+
// package's PROVIDERS, derived from each provider's descriptor), as that provider's create() options, and Settings' "test
|
|
3
|
+
// connection" over them (the registry's TestConnection: one account-level read that never makes a computer), its coded
|
|
4
|
+
// errors in plain words.
|
|
4
5
|
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// on; an empty optional key is left out; a required one not saved refuses in
|
|
8
|
-
// is made. The provider modules themselves (each one's create()) are passed
|
|
9
|
-
//
|
|
10
|
-
// No key is ever in an answer: each value is scrubbed from the provider's
|
|
11
|
-
// only by their names.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
{ name
|
|
17
|
-
|
|
18
|
-
{ name:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
],
|
|
24
|
-
e2b: [{ name: "E2B_API_KEY", option: "apiKey", required: true }],
|
|
25
|
-
orgo: [{ name: "ORGO_API_KEY", option: "apiKey", required: true }],
|
|
26
|
-
"phone-harness": [{ name: "PHONE_HARNESS_API_KEY", option: "apiKey", required: true }],
|
|
27
|
-
browserbase: [
|
|
28
|
-
{ name: "BROWSERBASE_API_KEY", option: "apiKey", required: true },
|
|
29
|
-
{ name: "BROWSERBASE_PROJECT_ID", option: "projectId", required: true },
|
|
30
|
-
],
|
|
31
|
-
kernel: [{ name: "KERNEL_API_KEY", option: "apiKey", required: true }],
|
|
32
|
-
};
|
|
33
|
-
/** Each provider's name in words (the registry's labels). */
|
|
34
|
-
const LABELS = {
|
|
35
|
-
docker: "Docker",
|
|
36
|
-
daytona: "Daytona",
|
|
37
|
-
modal: "Modal",
|
|
38
|
-
e2b: "E2B",
|
|
39
|
-
orgo: "Orgo",
|
|
40
|
-
"phone-harness": "Phone harness",
|
|
41
|
-
browserbase: "Browserbase",
|
|
42
|
-
kernel: "Kernel",
|
|
43
|
-
};
|
|
44
|
-
/** The Modal app a server's computers live in when its settings name none (serve's box app until now). */
|
|
45
|
-
export const DEFAULT_MODAL_APP = "agentrun";
|
|
46
|
-
export const KEY_TABLE = { keys: PROVIDER_KEYS, labels: LABELS };
|
|
6
|
+
// Serve knows no vendor here: each key's name and the option it fills, each setting that is no key (its name in the
|
|
7
|
+
// server's settings, its option and its default), and each provider's label all come from the descriptor. A name a
|
|
8
|
+
// provider does not declare is never passed on; an empty optional key is left out; a required one not saved refuses in
|
|
9
|
+
// words naming what to save, before anything is made. The provider modules themselves (each one's create()) are passed
|
|
10
|
+
// in (workspace/computer-providers.ts makes the computer package's; a test gives stand-ins): a provider with no module
|
|
11
|
+
// here answers that its test is not available. No key is ever in an answer: each value is scrubbed from the provider's
|
|
12
|
+
// words, and the words this module adds name keys only by their names.
|
|
13
|
+
import { PROVIDERS } from "@parcha/agentrun-computer";
|
|
14
|
+
/** The key table of `entries` (the kind registry's PROVIDERS, each from its descriptor). */
|
|
15
|
+
export function keyTableOf(entries) {
|
|
16
|
+
return {
|
|
17
|
+
keys: Object.fromEntries(entries.map((entry) => [entry.id, entry.keys.map(({ name, option, required }) => ({ name, option, required }))])),
|
|
18
|
+
labels: Object.fromEntries(entries.map((entry) => [entry.id, entry.label])),
|
|
19
|
+
settings: Object.fromEntries(entries.map((entry) => [entry.id, (entry.settings ?? []).map(({ name, option, default: fallback }) => ({ name, option, ...(fallback === undefined ? {} : { default: fallback }) }))])),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** Serve's table: every provider the computer package declares. */
|
|
23
|
+
export const KEY_TABLE = keyTableOf(PROVIDERS);
|
|
47
24
|
const has = (record, key) => Object.prototype.hasOwnProperty.call(record, key);
|
|
48
25
|
const labelOf = (providerId, table) => (has(table.labels, providerId) ? table.labels[providerId] : providerId);
|
|
49
26
|
const refused = (code, message) => ({ ok: false, error: { code, message } });
|
|
50
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Provider `providerId`'s create() options from its saved keys (by its descriptor's names) and the server's settings
|
|
29
|
+
* (each of its descriptor's settings, by name, else its default). An id the table does not list is refused, naming the
|
|
30
|
+
* providers it does.
|
|
31
|
+
*/
|
|
51
32
|
export function providerOptions(providerId, keys, settings = {}, table = KEY_TABLE) {
|
|
33
|
+
// The table is every descriptor's (keyTableOf(PROVIDERS)), so an id it does not list is no provider at all.
|
|
52
34
|
if (!has(table.keys, providerId))
|
|
53
35
|
return refused("unsupported", `${providerId} is not a computer provider: ${Object.keys(table.keys).join(", ")}`);
|
|
54
36
|
const label = labelOf(providerId, table);
|
|
@@ -64,8 +46,12 @@ export function providerOptions(providerId, keys, settings = {}, table = KEY_TAB
|
|
|
64
46
|
if (missing.length > 0) {
|
|
65
47
|
return refused("missing_key", `${label} needs ${missing.join(" and ")} saved: save ${missing.length > 1 ? "them" : "it"} in Settings → Computers (PUT /v2/computers/${providerId}/keys)`);
|
|
66
48
|
}
|
|
67
|
-
|
|
68
|
-
|
|
49
|
+
for (const setting of table.settings && has(table.settings, providerId) ? table.settings[providerId] : []) {
|
|
50
|
+
const given = has(settings, setting.name) ? settings[setting.name]?.trim() : undefined;
|
|
51
|
+
const value = given || setting.default;
|
|
52
|
+
if (value !== undefined && value !== "")
|
|
53
|
+
options[setting.option] = value;
|
|
54
|
+
}
|
|
69
55
|
return { ok: true, options };
|
|
70
56
|
}
|
|
71
57
|
/** `text` with every key value in `values` replaced by "[the key]". */
|
|
@@ -98,12 +84,8 @@ function wordsFor(code, providerId, said, table) {
|
|
|
98
84
|
return `${label}'s settings are not valid.${vendor}`;
|
|
99
85
|
case "unsupported":
|
|
100
86
|
return `${label} can't be tested here.${vendor}`;
|
|
101
|
-
|
|
102
|
-
case "
|
|
103
|
-
case "modal":
|
|
104
|
-
case "e2b":
|
|
105
|
-
case "orgo":
|
|
106
|
-
case "phone":
|
|
87
|
+
// The computer package's one code for a vendor's own failure (ComputerErrorCode "vendor"), whatever the vendor.
|
|
88
|
+
case "vendor":
|
|
107
89
|
return `${label} answered with an error.${vendor}`;
|
|
108
90
|
default:
|
|
109
91
|
return `The test of ${label} failed.${vendor}`;
|
|
@@ -2,13 +2,30 @@ 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. `image`: one the provider's descriptor offers for the kind (Orgo's `windows`);
|
|
11
|
+
* absent, the kind's default. A sandbox may ask for GPUs; whether its provider gives them is the claim's check. */
|
|
6
12
|
export type ComputerSetting = {
|
|
7
13
|
readonly kind: "none";
|
|
8
14
|
} | {
|
|
9
|
-
readonly kind:
|
|
15
|
+
readonly kind: "sandbox";
|
|
16
|
+
readonly provider: string;
|
|
17
|
+
readonly image?: string;
|
|
18
|
+
readonly gpu?: GpuSetting;
|
|
19
|
+
} | {
|
|
20
|
+
readonly kind: Exclude<ComputerKind, "none" | "sandbox">;
|
|
10
21
|
readonly provider: string;
|
|
22
|
+
readonly image?: string;
|
|
11
23
|
};
|
|
24
|
+
/** The GPUs a setting asks for, or undefined. */
|
|
25
|
+
export declare const gpuOf: (computer: {
|
|
26
|
+
readonly kind: string;
|
|
27
|
+
readonly gpu?: GpuSetting;
|
|
28
|
+
}) => GpuSetting | undefined;
|
|
12
29
|
/** A place as the v2 API names it. */
|
|
13
30
|
export type PlaceView = {
|
|
14
31
|
mode: "runner";
|
|
@@ -20,7 +37,7 @@ export type PlaceView = {
|
|
|
20
37
|
export declare const placeOfComputer: (computer: ComputerSetting) => PlaceView;
|
|
21
38
|
/** The setting a place says: runner is no computer, a sandbox place a sandbox on its box. */
|
|
22
39
|
export declare const computerOfPlace: (place: PlaceView) => ComputerSetting;
|
|
23
|
-
/** Whether two settings are the one setting. */
|
|
40
|
+
/** Whether two settings are the one setting: the same kind and provider, and the same of each optional field. */
|
|
24
41
|
export declare const sameComputer: (a: ComputerSetting, b: ComputerSetting) => boolean;
|
|
25
42
|
/** What is wrong with `value` as a computer setting, at `field`: its shape only (the providers are the server's). */
|
|
26
43
|
export declare function computerIssues(value: unknown, field: string): InputIssue[];
|
package/dist/computer-setting.js
CHANGED
|
@@ -1,27 +1,73 @@
|
|
|
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);
|
|
9
|
+
/**
|
|
10
|
+
* What a computer of a kind other than none may say beside its kind and provider: the kinds that take it (absent: any),
|
|
11
|
+
* and its own rule, the issues of a value that is wrong at `field`. The providers' offers are the server's, so only the
|
|
12
|
+
* shape is checked here. A sandbox's gpu is { type, count } in the words the computer package's checkGpu uses; whether
|
|
13
|
+
* its provider offers that type and count is the readiness check's and the claim's (resolve-computer.ts).
|
|
14
|
+
*/
|
|
15
|
+
const OPTIONAL = {
|
|
16
|
+
image: {
|
|
17
|
+
check: (value, field) => (typeof value === "string" && value.trim() !== "" && value === value.trim() ? [] : [{ field, reason: "invalid", message: `${field} is the name of an image the provider offers for the kind (GET /computers lists them), with no spaces around it` }]),
|
|
18
|
+
},
|
|
19
|
+
gpu: {
|
|
20
|
+
kinds: ["sandbox"],
|
|
21
|
+
check: (gpu, field) => {
|
|
22
|
+
if (!isObject(gpu) || Object.keys(gpu).some((key) => key !== "type" && key !== "count"))
|
|
23
|
+
return [{ field, reason: "wrong_type", message: "gpu is { type, count }: a GPU type this provider declares, and how many" }];
|
|
24
|
+
if (typeof gpu.type !== "string" || gpu.type === "")
|
|
25
|
+
return [{ field: `${field}.type`, reason: "missing", message: "gpu.type is a GPU type the provider declares (GET /v2/computers lists each provider's)" }];
|
|
26
|
+
if (!GPU_TYPE.test(gpu.type))
|
|
27
|
+
return [{ field: `${field}.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` }];
|
|
28
|
+
if (!Number.isSafeInteger(gpu.count) || gpu.count < 1)
|
|
29
|
+
return [{ field: `${field}.count`, reason: "wrong_type", message: `gpu.count ${JSON.stringify(gpu.count)} is not a whole number from 1` }];
|
|
30
|
+
return [];
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
4
34
|
/** The place the setting reads as: sandbox on its provider, else the runner (no computer holds the run's folder). */
|
|
5
35
|
export const placeOfComputer = (computer) => (computer.kind === "sandbox" ? { mode: "sandbox", box: computer.provider } : { mode: "runner" });
|
|
6
36
|
/** The setting a place says: runner is no computer, a sandbox place a sandbox on its box. */
|
|
7
37
|
export const computerOfPlace = (place) => (place.mode === "sandbox" ? { kind: "sandbox", provider: place.box } : { kind: "none" });
|
|
8
|
-
/** Whether two settings are the one setting. */
|
|
9
|
-
export const sameComputer = (a, b) =>
|
|
38
|
+
/** Whether two settings are the one setting: the same kind and provider, and the same of each optional field. */
|
|
39
|
+
export const sameComputer = (a, b) => {
|
|
40
|
+
if (a.kind !== b.kind)
|
|
41
|
+
return false;
|
|
42
|
+
if (a.kind === "none" || b.kind === "none")
|
|
43
|
+
return true;
|
|
44
|
+
const one = a;
|
|
45
|
+
const other = b;
|
|
46
|
+
return a.provider === b.provider && Object.keys(OPTIONAL).every((key) => JSON.stringify(one[key]) === JSON.stringify(other[key]));
|
|
47
|
+
};
|
|
10
48
|
/** What is wrong with `value` as a computer setting, at `field`: its shape only (the providers are the server's). */
|
|
11
49
|
export function computerIssues(value, field) {
|
|
12
50
|
const bad = (reason, message, fix) => [{ field, reason, message, ...(fix ? { fix } : {}) }];
|
|
51
|
+
const keeps = ["kind", "provider", ...Object.keys(OPTIONAL)];
|
|
13
52
|
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
|
|
53
|
+
return bad("wrong_type", `${field} is an object: {kind}, or {kind, provider}, with ${Object.keys(OPTIONAL).join(" and ")} where its kind takes them`);
|
|
54
|
+
const extra = Object.keys(value).filter((key) => !keeps.includes(key));
|
|
16
55
|
if (extra.length)
|
|
17
|
-
return bad("not_allowed", `${field} keeps only
|
|
56
|
+
return bad("not_allowed", `${field} keeps only ${keeps.join(", ")}, not ${extra.join(" or ")}`, `Remove ${extra.map((key) => `${field}.${key}`).join(" and ")}.`);
|
|
18
57
|
if (typeof value.kind !== "string" || !COMPUTER_KINDS.includes(value.kind))
|
|
19
58
|
return bad(value.kind === undefined ? "missing" : "not_an_option", `${field}.kind is one of ${COMPUTER_KINDS.join(", ")}`);
|
|
20
|
-
|
|
21
|
-
|
|
59
|
+
const kind = value.kind;
|
|
60
|
+
for (const [key, { kinds }] of Object.entries(OPTIONAL)) {
|
|
61
|
+
if (value[key] !== undefined && kinds !== undefined && !kinds.includes(kind))
|
|
62
|
+
return bad("not_allowed", `only a ${kinds.join(" or ")} computer takes a ${key}, not a ${kind} one`, `Remove ${field}.${key}.`);
|
|
63
|
+
}
|
|
64
|
+
if (kind === "none") {
|
|
65
|
+
const named = keeps.filter((key) => key !== "kind" && value[key] !== undefined);
|
|
66
|
+
return named.length === 0 ? [] : bad("not_allowed", `no computer names no ${named.join(" or ")}`, `Remove ${named.map((key) => `${field}.${key}`).join(" and ")}.`);
|
|
67
|
+
}
|
|
22
68
|
if (typeof value.provider !== "string" || value.provider === "")
|
|
23
|
-
return bad("missing", `a ${
|
|
24
|
-
return [];
|
|
69
|
+
return bad("missing", `a ${kind} computer names its provider (Settings → Computers lists them)`);
|
|
70
|
+
return Object.entries(OPTIONAL).flatMap(([key, { check }]) => (value[key] === undefined ? [] : check(value[key], `${field}.${key}`)));
|
|
25
71
|
}
|
|
26
72
|
/** The setting and its place a definition says, from `computer` or `place` (both: they must agree), or undefined when
|
|
27
73
|
* it says neither. Each is checked already (computerIssues, placeIssues). */
|
|
@@ -40,8 +86,10 @@ export function settingOfDefinition(definition) {
|
|
|
40
86
|
export function settingConflict(computer, place, field) {
|
|
41
87
|
if (!isObject(computer) || !isObject(place) || computerIssues(computer, `${field}.computer`).length)
|
|
42
88
|
return [];
|
|
89
|
+
// A place says a kind and a provider only: a computer's image or GPUs are not ones it can contradict.
|
|
43
90
|
const said = computerOfPlace(place);
|
|
44
|
-
|
|
91
|
+
const { kind, provider } = computer;
|
|
92
|
+
if (sameComputer((kind === "none" ? { kind } : { kind, provider }), said))
|
|
45
93
|
return [];
|
|
46
94
|
return [{ field: `${field}.place`, reason: "invalid", message: "computer and place say two settings: give one (place is computer's v2 view)", fix: `Remove ${field}.place, or make it ${JSON.stringify(placeOfComputer(computer))}.` }];
|
|
47
95
|
}
|