@parcha/agentrun-serve 0.1.0-beta.43 → 0.1.0-beta.45
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 +231 -0
- package/README.md +580 -320
- package/dist/acp-package.d.ts +28 -0
- package/dist/acp-package.js +23 -0
- package/dist/adapter-facts.d.ts +8 -1
- package/dist/adapter-facts.js +9 -1
- package/dist/adapters.d.ts +5 -0
- package/dist/adapters.js +36 -3
- package/dist/agent-delete.d.ts +50 -0
- package/dist/agent-delete.js +125 -0
- package/dist/agents-store.d.ts +9 -3
- package/dist/agents-store.js +22 -8
- package/dist/agents.d.ts +5 -1
- package/dist/agents.js +8 -4
- package/dist/api-only.d.ts +8 -3
- package/dist/api-only.js +10 -4
- package/dist/archil-routes.d.ts +5 -1
- package/dist/archil-routes.js +57 -2
- package/dist/browser-wait-ended.d.ts +2 -0
- package/dist/browser-wait-ended.js +2 -0
- package/dist/calendar/ics-faux.d.ts +3 -1
- package/dist/calendar/ics-faux.js +12 -2
- package/dist/calendar/tools.js +5 -2
- package/dist/chatgpt-plan.js +3 -1
- package/dist/claude-login.d.ts +135 -0
- package/dist/claude-login.js +244 -0
- package/dist/cli.js +92 -22
- package/dist/composio-preset.d.ts +4 -3
- package/dist/composio-preset.js +81 -11
- package/dist/composio-triggers.d.ts +34 -2
- package/dist/composio-triggers.js +261 -31
- package/dist/computer-attach.d.ts +40 -5
- package/dist/computer-attach.js +130 -15
- package/dist/computer-keys.d.ts +3 -0
- package/dist/computer-keys.js +7 -1
- package/dist/computer-live.js +3 -2
- package/dist/computer-lost.d.ts +11 -0
- package/dist/computer-lost.js +19 -0
- package/dist/computer-record.d.ts +10 -2
- package/dist/computer-record.js +50 -18
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +2 -2
- package/dist/computers.d.ts +21 -10
- package/dist/computers.js +39 -28
- package/dist/console/assets/index-3O2Yl6hZ.js +701 -0
- package/dist/console/assets/index-DaFsZuzQ.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.d.ts +1 -1
- package/dist/dial-relay.d.ts +29 -0
- package/dist/dial-relay.js +94 -0
- package/dist/email/tools.js +10 -5
- package/dist/env-proxy.d.ts +2 -0
- package/dist/env-proxy.js +35 -0
- package/dist/errors.d.ts +4 -1
- package/dist/errors.js +10 -4
- package/dist/faux-computers.d.ts +8 -2
- package/dist/faux-computers.js +83 -6
- package/dist/harness-archive.d.ts +67 -0
- package/dist/harness-archive.js +177 -0
- package/dist/harness-goose.d.ts +34 -0
- package/dist/harness-goose.js +87 -0
- package/dist/harness-install.d.ts +21 -0
- package/dist/harness-install.js +24 -11
- package/dist/harness-opencode/adapter.js +1 -1
- package/dist/harness-table.d.ts +59 -3
- package/dist/harness-table.js +119 -14
- package/dist/harness.d.ts +17 -1
- package/dist/harness.js +22 -11
- package/dist/host.d.ts +12 -10
- package/dist/host.js +19 -16
- package/dist/import-worker.d.ts +3 -0
- package/dist/import-worker.js +7 -5
- package/dist/import.d.ts +22 -1
- package/dist/import.js +141 -28
- package/dist/key-check.js +3 -0
- package/dist/learn/audit.d.ts +6 -6
- package/dist/learn/audit.js +3 -7
- package/dist/learn/check.d.ts +26 -89
- package/dist/learn/check.js +58 -336
- package/dist/learn/commit.d.ts +63 -90
- package/dist/learn/commit.js +124 -316
- package/dist/learn/compile.d.ts +53 -50
- package/dist/learn/compile.js +88 -103
- package/dist/learn/corrections.d.ts +13 -0
- package/dist/learn/corrections.js +23 -0
- package/dist/learn/delete.d.ts +17 -0
- package/dist/learn/delete.js +42 -0
- package/dist/learn/folder.d.ts +35 -47
- package/dist/learn/folder.js +118 -134
- package/dist/learn/index.d.ts +3 -5
- package/dist/learn/index.js +6 -9
- package/dist/learn/learning.sh +45 -15
- package/dist/learn/promote.d.ts +20 -2
- package/dist/learn/promote.js +17 -4
- package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +34 -38
- package/dist/learn/{skills.js → workflow-draft.js} +65 -59
- package/dist/learn/workflow-nodes.d.ts +22 -1
- package/dist/learn/workflow-nodes.js +29 -10
- package/dist/learned-workflow.js +2 -2
- package/dist/learning-cost.d.ts +127 -13
- package/dist/learning-cost.js +142 -10
- package/dist/learning-routes.d.ts +99 -170
- package/dist/learning-routes.js +199 -420
- package/dist/learning-run.d.ts +19 -40
- package/dist/learning-run.js +23 -93
- package/dist/learning-setting.d.ts +4 -4
- package/dist/learning-setting.js +6 -6
- package/dist/learning-words.d.ts +28 -74
- package/dist/learning-words.js +64 -162
- package/dist/learning.d.ts +62 -393
- package/dist/learning.js +101 -651
- package/dist/listen-first.d.ts +30 -0
- package/dist/listen-first.js +115 -0
- package/dist/live-reach.d.ts +25 -2
- package/dist/live-reach.js +46 -4
- package/dist/llms.txt +2 -1
- package/dist/local-models.d.ts +3 -11
- package/dist/local-models.js +5 -6
- package/dist/mcp-servers-store.d.ts +16 -16
- package/dist/model-form.js +6 -5
- package/dist/model.d.ts +12 -4
- package/dist/model.js +41 -16
- package/dist/native/binding.js +1 -1
- package/dist/native/connection.js +1 -1
- package/dist/native/discovery.js +1 -1
- package/dist/native/instructions.d.ts +3 -0
- package/dist/native/instructions.js +5 -3
- package/dist/native/remote-worker-bridge.js +9 -43
- package/dist/native/remote.d.ts +8 -15
- package/dist/native/remote.js +3 -3
- package/dist/native/schema.js +1 -1
- package/dist/native/types.d.ts +2 -2
- package/dist/openapi.js +375 -347
- package/dist/owner.d.ts +8 -0
- package/dist/owner.js +11 -0
- package/dist/paid-calls.d.ts +14 -0
- package/dist/paid-calls.js +31 -1
- package/dist/particle-provider.d.ts +11 -0
- package/dist/particle-provider.js +135 -0
- package/dist/place.d.ts +8 -3
- package/dist/place.js +13 -9
- package/dist/port-models.d.ts +12 -4
- package/dist/port-models.js +28 -11
- package/dist/print.d.ts +27 -0
- package/dist/print.js +21 -0
- package/dist/provider.d.ts +7 -0
- package/dist/provider.js +30 -2
- package/dist/reflect-range.js +2 -3
- package/dist/run-launch.d.ts +14 -28
- package/dist/run-launch.js +9 -12
- package/dist/run-learning-served.d.ts +16 -90
- package/dist/run-listing.d.ts +34 -0
- package/dist/run-listing.js +128 -0
- package/dist/run-model-key.d.ts +64 -0
- package/dist/run-model-key.js +147 -0
- package/dist/run-timeline-served.js +5 -3
- package/dist/run-trace.d.ts +97 -0
- package/dist/run-trace.js +253 -0
- package/dist/run-view.d.ts +15 -0
- package/dist/run-view.js +9 -0
- package/dist/runnable.js +2 -1
- package/dist/runner/adapter-loop.d.ts +14 -6
- package/dist/runner/adapter-loop.js +25 -14
- package/dist/runner/adapter-run-spec.d.ts +22 -7
- package/dist/runner/adapter-run-spec.js +130 -77
- package/dist/runner/adapters/index.d.ts +4 -2
- package/dist/runner/adapters/index.js +35 -4
- package/dist/runner/adapters/pi.d.ts +4 -12
- package/dist/runner/adapters/pi.js +2 -2
- package/dist/runner/audit.d.ts +5 -1
- package/dist/runner/audit.js +31 -12
- package/dist/runner/beside.d.ts +7 -2
- package/dist/runner/beside.js +41 -9
- package/dist/runner/claim-secrets.d.ts +66 -1
- package/dist/runner/claim-secrets.js +136 -3
- package/dist/runner/cli-run-spec.d.ts +2 -1
- package/dist/runner/cli-run-spec.js +82 -59
- package/dist/runner/commands.d.ts +3 -6
- package/dist/runner/conformance/harness.d.ts +6 -0
- package/dist/runner/conformance/harness.js +16 -5
- package/dist/runner/dispatch.d.ts +2 -2
- package/dist/runner/end-of-run.d.ts +6 -14
- package/dist/runner/end-of-run.js +8 -33
- package/dist/runner/feedback-round.d.ts +5 -4
- package/dist/runner/feedback-round.js +14 -10
- package/dist/runner/github-app.js +3 -1
- package/dist/runner/harness-loops.d.ts +0 -8
- package/dist/runner/harness-loops.js +30 -56
- package/dist/runner/held.d.ts +170 -0
- package/dist/runner/held.js +57 -0
- package/dist/runner/journal-kinds.d.ts +7 -3
- package/dist/runner/journal-kinds.js +2 -3
- package/dist/runner/learned-first.d.ts +40 -0
- package/dist/runner/learned-first.js +32 -0
- package/dist/runner/learning-end.d.ts +77 -66
- package/dist/runner/learning-end.js +250 -299
- package/dist/runner/learning-seed.d.ts +15 -33
- package/dist/runner/learning-seed.js +24 -45
- package/dist/runner/loop-contract.d.ts +8 -3
- package/dist/runner/loop-contract.js +4 -0
- package/dist/runner/loop.js +6 -2
- package/dist/runner/main.d.ts +18 -9
- package/dist/runner/main.js +82 -22
- package/dist/runner/mcp-run.d.ts +11 -0
- package/dist/runner/mcp-run.js +67 -0
- package/dist/runner/memory-claim.d.ts +14 -6
- package/dist/runner/memory-claim.js +18 -9
- package/dist/runner/model-route.d.ts +7 -4
- package/dist/runner/model-route.js +22 -10
- package/dist/runner/native-loop.d.ts +0 -7
- package/dist/runner/native-loop.js +9 -101
- package/dist/runner/promotion.d.ts +13 -6
- package/dist/runner/promotion.js +63 -17
- package/dist/runner/reflect-hook.d.ts +64 -91
- package/dist/runner/reflect-hook.js +112 -206
- package/dist/runner/run-channel.d.ts +43 -0
- package/dist/runner/run-channel.js +467 -0
- package/dist/runner/run-child-host.d.ts +169 -0
- package/dist/runner/run-child-host.js +1222 -0
- package/dist/runner/run-child.d.ts +1 -0
- package/dist/runner/run-child.js +254 -0
- package/dist/runner/run-errors.d.ts +2 -0
- package/dist/runner/run-errors.js +20 -0
- package/dist/runner/runner.js +58 -9
- package/dist/runner/sdk-ask.d.ts +78 -0
- package/dist/runner/sdk-ask.js +158 -0
- package/dist/runner/sdk-loop.d.ts +2 -4
- package/dist/runner/sdk-loop.js +29 -49
- package/dist/runner/store-secrets.d.ts +5 -3
- package/dist/runner/store-secrets.js +14 -6
- package/dist/runner/workflow-first.d.ts +5 -0
- package/dist/runner/workflow-first.js +4 -0
- package/dist/runner/workflow-spec.js +17 -4
- package/dist/runs-over-store.d.ts +21 -32
- package/dist/runs-over-store.js +44 -41
- package/dist/sdk/runs.d.ts +6 -11
- package/dist/sdk/runs.js +20 -41
- package/dist/sdk/schema.js +3 -4
- package/dist/sdk/workflows.d.ts +1 -1
- package/dist/seal-key.d.ts +5 -0
- package/dist/seal-key.js +7 -0
- package/dist/secrets.d.ts +3 -0
- package/dist/secrets.js +16 -3
- package/dist/server.d.ts +119 -83
- package/dist/server.js +1121 -419
- package/dist/sign-ins-store.d.ts +8 -0
- package/dist/sign-ins-store.js +36 -1
- package/dist/skills.js +1 -1
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.js +3 -0
- package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
- package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
- package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
- package/dist/store/schema.d.ts +53 -4
- package/dist/store/schema.js +137 -6
- package/dist/store/seal.d.ts +20 -2
- package/dist/store/seal.js +24 -8
- package/dist/store/sqlite/connection.d.ts +2 -0
- package/dist/store/sqlite/connection.js +3 -1
- package/dist/store/sqlite/run-launch.d.ts +4 -1
- package/dist/store/sqlite/run-launch.js +12 -0
- package/dist/store/sqlite/run-patch.d.ts +0 -17
- package/dist/store/sqlite/run-patch.js +4 -33
- package/dist/store/sqlite/store.d.ts +3 -2
- package/dist/store/sqlite/store.js +360 -75
- package/dist/store/sqlite/worker.js +25 -0
- package/dist/store/store.d.ts +231 -39
- package/dist/store/store.js +25 -3
- package/dist/store-reads/analytics.js +11 -1
- package/dist/store-reads/learning.d.ts +131 -194
- package/dist/store-reads/learning.js +292 -301
- package/dist/store-reads/loop.d.ts +0 -1
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-reads/stats.js +13 -3
- package/dist/store-view.d.ts +34 -2
- package/dist/store-view.js +108 -41
- package/dist/telemetry.d.ts +59 -0
- package/dist/telemetry.js +153 -0
- package/dist/template-eval.d.ts +3 -6
- package/dist/template-eval.js +22 -36
- package/dist/templates.d.ts +2 -1
- package/dist/templates.js +6 -3
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/timeline.d.ts +5 -1
- package/dist/timeline/timeline.js +16 -0
- package/dist/tool-gate.d.ts +0 -7
- package/dist/tool-gate.js +1 -15
- package/dist/tool-keys-store.d.ts +1 -1
- package/dist/tool-keys.d.ts +6 -4
- package/dist/tool-keys.js +12 -6
- package/dist/tool-plane.d.ts +12 -12
- package/dist/tools.d.ts +13 -13
- package/dist/tools.js +29 -9
- package/dist/trigger-adapter.d.ts +3 -0
- package/dist/trigger-adapters.d.ts +4 -0
- package/dist/trigger-adapters.js +13 -0
- package/dist/trigger-composio.d.ts +58 -1
- package/dist/trigger-composio.js +160 -6
- package/dist/triggers.d.ts +64 -5
- package/dist/triggers.js +141 -17
- package/dist/validate.d.ts +11 -7
- package/dist/validate.js +9 -8
- package/dist/webhooks.d.ts +4 -1
- package/dist/webhooks.js +11 -4
- package/dist/workspace/agent-computer.d.ts +2 -0
- package/dist/workspace/agent-computer.js +2 -0
- package/dist/workspace/archil-claim.d.ts +7 -0
- package/dist/workspace/archil-claim.js +29 -0
- package/dist/workspace/archil.d.ts +9 -1
- package/dist/workspace/archil.js +165 -3
- package/dist/workspace/attach.d.ts +3 -1
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/attached-computers.d.ts +16 -5
- package/dist/workspace/attached-computers.js +25 -9
- package/dist/workspace/computer-deps.js +1 -1
- package/dist/workspace/computer-for-claim.d.ts +22 -8
- package/dist/workspace/computer-for-claim.js +339 -46
- package/dist/workspace/computer-hold.js +2 -1
- package/dist/workspace/computer-kept.d.ts +11 -1
- package/dist/workspace/computer-kept.js +24 -3
- package/dist/workspace/resolve-computer.d.ts +41 -21
- package/dist/workspace/resolve-computer.js +172 -64
- package/dist/workspace/revision-skills.d.ts +1 -2
- package/dist/workspace/revision-skills.js +3 -4
- package/dist/workspace/run-workspace.d.ts +1 -1
- package/dist/workspace/run-workspace.js +5 -0
- package/dist/workspace/synced-folder.d.ts +85 -0
- package/dist/workspace/synced-folder.js +230 -0
- package/dist/workspace/workspace.d.ts +4 -0
- package/launcher/agentrun-serve +1 -1
- package/package.json +10 -9
- package/templates/README.md +7 -7
- package/templates/inbound-lead/agent.md +3 -3
- package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
- package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
- package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
- package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
- package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
- package/templates/inbound-lead/lead.schema.json +6 -5
- package/templates/inbound-lead/rules/RUBRIC.md +4 -4
- package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
- package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
- package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
- package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
- package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
- package/templates/release-notes/evals/learned-style/case.yaml +4 -4
- package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
- package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
- package/templates/release-notes/evals/learned-style/prompt.md +1 -1
- package/dist/console/assets/index-BrcDSBD8.css +0 -1
- package/dist/console/assets/index-Bz6IWncl.js +0 -711
- package/dist/learn/grade.d.ts +0 -138
- package/dist/learn/grade.js +0 -682
- package/dist/learn/notes.d.ts +0 -81
- package/dist/learn/notes.js +0 -178
- package/dist/learn/reflect.d.ts +0 -77
- package/dist/learn/reflect.js +0 -228
- package/dist/learn/relevance.d.ts +0 -24
- package/dist/learn/relevance.js +0 -91
- package/dist/learn/seed-check.d.ts +0 -74
- package/dist/learn/seed-check.js +0 -103
- package/dist/learning-batch.d.ts +0 -291
- package/dist/learning-batch.js +0 -600
- package/dist/learning-evals.d.ts +0 -33
- package/dist/learning-evals.js +0 -98
- package/dist/native/context.d.ts +0 -6
- package/dist/native/context.js +0 -22
- package/dist/propose.d.ts +0 -52
- package/dist/propose.js +0 -224
- package/dist/runner/learning-ask.d.ts +0 -47
- package/dist/runner/learning-ask.js +0 -128
- package/dist/runner/learning-dispatch.d.ts +0 -45
- package/dist/runner/learning-dispatch.js +0 -99
- package/dist/runner/learning-factory.d.ts +0 -16
- package/dist/runner/learning-factory.js +0 -50
- package/dist/runner/learning-loop.d.ts +0 -273
- package/dist/runner/learning-loop.js +0 -521
- package/dist/usage.d.ts +0 -11
- package/dist/usage.js +0 -11
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
- package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
- package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
- package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
package/dist/computer-attach.js
CHANGED
|
@@ -17,13 +17,20 @@
|
|
|
17
17
|
// One process: the hub is this process's memory, so a run takes a paired computer only from a runner in the process
|
|
18
18
|
// that holds its socket (the CLI's start, with its runner beside the server). A runner of its own process refuses one in
|
|
19
19
|
// words (workspace/attached-computers.ts ONE_PROCESS_WORDS); a second server on the same store is refused at its start.
|
|
20
|
+
//
|
|
21
|
+
// A hosted machine a runner in a process of its own made (dial-relay.ts) dials this server the same way, and its token's
|
|
22
|
+
// row names that runner: the server relays its socket to the runner's attach listener (`relay`), where these same routes
|
|
23
|
+
// (`owner`, the runner's) take it into the runner's hub. The relay is two sockets, each with this module's limits (a frame
|
|
24
|
+
// over MAX_LINE_BYTES, a binary frame, ATTACH_IDLE_MS of silence), joined frame by frame: a close of either closes the
|
|
25
|
+
// other with its code.
|
|
20
26
|
import { createHash, randomBytes, randomInt } from "node:crypto";
|
|
21
|
-
import { ATTACH_CLOSE, ATTACH_HEARTBEAT_MS, ATTACH_IDLE_MS, ATTACH_SUBPROTOCOL, hostedDaemonPath, MAX_LINE_BYTES, mintedComputer, PAIRING_CODE_PATTERN, PAIRING_CODE_TTL_MS, PROTOCOL_VERSION, RUN_LABEL } from "@parcha/agentrun-computer";
|
|
22
|
-
import { WebSocketServer } from "ws";
|
|
27
|
+
import { ATTACH_CLOSE, ATTACH_HEARTBEAT_MS, ATTACH_IDLE_MS, ATTACH_PATH, ATTACH_SUBPROTOCOL, hostedDaemonPath, MAX_LINE_BYTES, mintedComputer, PAIRING_CODE_PATTERN, PAIRING_CODE_TTL_MS, PROTOCOL_VERSION, RUN_LABEL } from "@parcha/agentrun-computer";
|
|
28
|
+
import { WebSocket, WebSocketServer } from "ws";
|
|
23
29
|
import { ApiError, invalid } from "./errors.js";
|
|
30
|
+
import { dialHost, LIVE_PROOF_HEADER, relayProof } from "./live-reach.js";
|
|
24
31
|
import { peerKey } from "./owner.js";
|
|
25
32
|
import { registerNotSecretWrite } from "./secret-writes.js";
|
|
26
|
-
import { pairedOf, PAIRED_ID_PREFIX, servesNoKind } from "./workspace/attached-computers.js";
|
|
33
|
+
import { pairedOf, PAIRED_ID_PREFIX, RUNNER_APART_WORDS, servesNoKind } from "./workspace/attached-computers.js";
|
|
27
34
|
// Routes under /computers, where a provider's keys are a secret write (computers.ts): these three write none of the
|
|
28
35
|
// owner's secrets, so the API token may call them as the console's session does.
|
|
29
36
|
registerNotSecretWrite("createPairing", "A pairing code is shown once and kept as its hash: it is a one-time code, not a secret of the owner's.");
|
|
@@ -176,7 +183,7 @@ function featuresOf(features) {
|
|
|
176
183
|
return {};
|
|
177
184
|
return Object.fromEntries(Object.entries(features).flatMap(([name, value]) => (value === true ? [[name, true]] : isObject(value) && typeof value.off === "string" ? [[name, { off: value.off }]] : [])));
|
|
178
185
|
}
|
|
179
|
-
export function pairedView(row, hub, serves) {
|
|
186
|
+
export function pairedView(row, hub, serves, runnerApart = false) {
|
|
180
187
|
const paired = row.hello;
|
|
181
188
|
// Kind and os stay what it paired as (another is refused at hello); the rest follows its driver's live hello.
|
|
182
189
|
const hello = hub.hello(row.id) ?? paired;
|
|
@@ -191,6 +198,7 @@ export function pairedView(row, hub, serves) {
|
|
|
191
198
|
kind: String(paired.kind ?? ""),
|
|
192
199
|
serves: [...serves],
|
|
193
200
|
unserved: serves.length === 0 ? (servesNoKind(row.name, paired) ?? null) : null,
|
|
201
|
+
runs_refused: runnerApart ? RUNNER_APART_WORDS : null,
|
|
194
202
|
os: String(paired.os ?? ""),
|
|
195
203
|
os_version: typeof hello.osVersion === "string" ? hello.osVersion : null,
|
|
196
204
|
device: hello.device && typeof hello.device.maker === "string" && typeof hello.device.model === "string" ? { maker: hello.device.maker, model: hello.device.model } : null,
|
|
@@ -207,10 +215,15 @@ export function pairedView(row, hub, serves) {
|
|
|
207
215
|
seen_at: seen === null ? null : new Date(seen).toISOString(),
|
|
208
216
|
};
|
|
209
217
|
}
|
|
218
|
+
/** The close ws starts on a frame it refuses (its receiver's error codes): 1009 for one over maxPayload, 1007 for text
|
|
219
|
+
* that is not UTF-8; any other is 1002. */
|
|
220
|
+
const RECEIVER_CLOSES = { WS_ERR_UNSUPPORTED_MESSAGE_LENGTH: 1009, WS_ERR_INVALID_UTF8: 1007 };
|
|
210
221
|
/** One WebSocket as the hub takes it (attach.ts AttachSocket): text frames in and out; a ping each heartbeat; closed
|
|
211
222
|
* with ATTACH_CLOSE.idle once nothing (no frame, ping or pong) is heard for idleMs, and with ATTACH_CLOSE.binary on a
|
|
212
|
-
* binary frame. A frame over MAX_LINE_BYTES is the server's maxPayload, which closes it with 1009 itself.
|
|
213
|
-
|
|
223
|
+
* binary frame. A frame over MAX_LINE_BYTES is the server's maxPayload, which closes it with 1009 itself. `closing` is
|
|
224
|
+
* told each close this side starts, when it starts: a peer that does not answer it (an idle one) ends the socket only
|
|
225
|
+
* once ws gives up on it. */
|
|
226
|
+
export function attachSocketOf(ws, timing = { heartbeatMs: ATTACH_HEARTBEAT_MS, idleMs: ATTACH_IDLE_MS }, closing) {
|
|
214
227
|
const texts = [];
|
|
215
228
|
const closes = [];
|
|
216
229
|
let ended;
|
|
@@ -220,6 +233,7 @@ export function attachSocketOf(ws, timing = { heartbeatMs: ATTACH_HEARTBEAT_MS,
|
|
|
220
233
|
if (ws.readyState === ws.CLOSING || ws.readyState === ws.CLOSED)
|
|
221
234
|
return;
|
|
222
235
|
ws.close(code, closeReason(reason));
|
|
236
|
+
closing?.(code, reason);
|
|
223
237
|
};
|
|
224
238
|
const beat = setInterval(() => {
|
|
225
239
|
if (Date.now() - heard >= timing.idleMs)
|
|
@@ -239,8 +253,12 @@ export function attachSocketOf(ws, timing = { heartbeatMs: ATTACH_HEARTBEAT_MS,
|
|
|
239
253
|
for (const listener of texts)
|
|
240
254
|
listener(text);
|
|
241
255
|
});
|
|
242
|
-
// A socket that errs (a frame over maxPayload, a broken frame) is closed by ws, which then emits close
|
|
243
|
-
|
|
256
|
+
// A socket that errs (a frame over maxPayload, a broken frame) is closed by ws, which then emits close; ws stops reading
|
|
257
|
+
// it there, so a peer's answer to that close may never be read: the close it started is told at once.
|
|
258
|
+
ws.on("error", (error) => {
|
|
259
|
+
if (typeof error.code === "string" && error.code.startsWith("WS_ERR_"))
|
|
260
|
+
closing?.(RECEIVER_CLOSES[error.code] ?? 1002, error.message);
|
|
261
|
+
});
|
|
244
262
|
ws.on("close", (code, reason) => {
|
|
245
263
|
clearInterval(beat);
|
|
246
264
|
ended = { code, reason: reason.toString("utf8") };
|
|
@@ -255,17 +273,41 @@ export function attachSocketOf(ws, timing = { heartbeatMs: ATTACH_HEARTBEAT_MS,
|
|
|
255
273
|
};
|
|
256
274
|
}
|
|
257
275
|
/** A request's Bearer token, or undefined. */
|
|
258
|
-
const bearerOf = (authorization) => /^Bearer (\S+)$/.exec(String(authorization ?? ""))?.[1];
|
|
276
|
+
export const bearerOf = (authorization) => /^Bearer (\S+)$/.exec(String(authorization ?? ""))?.[1];
|
|
277
|
+
/** How often a runner's attach listener says it is there (its runner_relays row's seen_at), and how long after its last
|
|
278
|
+
* word the server takes it as gone. */
|
|
279
|
+
export const RELAY_RENEW_MS = 10_000;
|
|
280
|
+
export const RELAY_STALE_MS = 3 * RELAY_RENEW_MS;
|
|
281
|
+
/** How long the server waits for a runner's attach listener to take a relayed dial. */
|
|
282
|
+
export const RELAY_CONNECT_MS = 10_000;
|
|
283
|
+
/** A close code one side of a relay may send the other: its own, or 1001 for one a peer may not send (1005, 1006). */
|
|
284
|
+
const sendable = (code) => ((code >= 1000 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006) || (code >= 3000 && code <= 4999) ? code : ATTACH_CLOSE.going);
|
|
285
|
+
/** Two WebSockets joined frame by frame, each an attach socket with `timing` (attachSocketOf: its idle close, its binary
|
|
286
|
+
* refusal, the server's maxPayload), each closing the other with its code and reason: once it ended, or as soon as it
|
|
287
|
+
* starts a close of its own, so an idle peer's close reaches the other side at once. */
|
|
288
|
+
export function joinSockets(one, other, timing) {
|
|
289
|
+
const sides = [];
|
|
290
|
+
const [a, b] = [one, other].map((ws, at) => attachSocketOf(ws, timing, (code, reason) => sides[1 - at].close(sendable(code), reason)));
|
|
291
|
+
sides.push(a, b);
|
|
292
|
+
a.onText((text) => b.send(text));
|
|
293
|
+
b.onText((text) => a.send(text));
|
|
294
|
+
a.onClose((code, reason) => b.close(sendable(code), reason));
|
|
295
|
+
b.onClose((code, reason) => a.close(sendable(code), reason));
|
|
296
|
+
}
|
|
259
297
|
/** The attach socket's 401: a token no paired computer or hosted machine has good. */
|
|
260
298
|
const TOKEN_REFUSED = "no paired computer or hosted machine has this token: pair the computer again from the console's Computers page (a hosted machine's token ends at its delete or its backstop)";
|
|
261
299
|
/** The daemon route's 401: a token no hosted machine has good. */
|
|
262
300
|
const MACHINE_TOKEN_REFUSED = "no hosted machine has this token: a machine's token ends at its delete or its backstop";
|
|
301
|
+
/** A minted machine's dial, as the words about it say it: by its run where its create named one, the machine after;
|
|
302
|
+
* else by the machine. Never its token. */
|
|
303
|
+
const dialOf = (row) => (row.run !== null ? `a dial for run ${row.run} (machine ${row.machine})` : `a dial for machine ${row.machine}`);
|
|
263
304
|
/** Why a minted machine's socket closed at its token's revoke. */
|
|
264
305
|
const machineGone = (machine) => `${machine} was deleted: its token ends`;
|
|
265
306
|
/** The pairing routes, the attach socket and the daemon route over one store and one hub, and the tokens a dial
|
|
266
307
|
* provider mints. */
|
|
267
308
|
export function createAttachRoutes(options) {
|
|
268
309
|
const { store, hub, log = () => { }, now = Date.now } = options;
|
|
310
|
+
const runsRefused = options.runnerApart === true ? RUNNER_APART_WORDS : null;
|
|
269
311
|
const paired = store.pairedComputers;
|
|
270
312
|
const minted = store.mintedTokens;
|
|
271
313
|
const tries = pairTries(now);
|
|
@@ -279,7 +321,7 @@ export function createAttachRoutes(options) {
|
|
|
279
321
|
const id = `pairing-${randomBytes(9).toString("base64url")}`;
|
|
280
322
|
const expiresAt = now() + PAIRING_CODE_TTL_MS;
|
|
281
323
|
await paired.addCode(id, sha256Hex(code), expiresAt);
|
|
282
|
-
return { id, code, expires_at: new Date(expiresAt).toISOString() };
|
|
324
|
+
return { id, code, expires_at: new Date(expiresAt).toISOString(), runs_refused: runsRefused };
|
|
283
325
|
}
|
|
284
326
|
/** POST /v2/computers/pair: the code traded for the computer's id and token, once; `address` the try's source. */
|
|
285
327
|
async function pair(body, address) {
|
|
@@ -300,7 +342,7 @@ export function createAttachRoutes(options) {
|
|
|
300
342
|
if (!made)
|
|
301
343
|
throw new ApiError("not_found", "no such pairing code: make a new one on the console's Computers page");
|
|
302
344
|
log("computer_paired", { computer: id, kind: hello.kind, os: hello.os, driver: hello.version });
|
|
303
|
-
return { computer: id, token };
|
|
345
|
+
return { computer: id, token, runs_refused: runsRefused };
|
|
304
346
|
}
|
|
305
347
|
/** DELETE /v2/computers/{id}: its token revoked, a run's hold on it ended, its socket closed with 4401. */
|
|
306
348
|
async function remove(id) {
|
|
@@ -314,13 +356,13 @@ export function createAttachRoutes(options) {
|
|
|
314
356
|
* (its name, from its create's request id) until `expiresAt` (its backstop); a revoke (its delete) ends it and closes
|
|
315
357
|
* its socket with 4401. */
|
|
316
358
|
const machineTokens = {
|
|
317
|
-
async mint(machine, { kind, os, arch, expiresAt }) {
|
|
359
|
+
async mint(machine, { kind, os, arch, expiresAt, run }) {
|
|
318
360
|
const until = expiresAt.getTime();
|
|
319
361
|
if (!Number.isFinite(until))
|
|
320
362
|
throw new TypeError(`a machine token's expiresAt is a time, not ${JSON.stringify(expiresAt)}`);
|
|
321
363
|
const token = newMintedToken();
|
|
322
|
-
await minted.mint({ machine, tokenSha256: sha256Hex(token), kind, os, arch, expiresAt: until });
|
|
323
|
-
log("machine_token_minted", { machine, kind, os, arch, expires_at: new Date(until).toISOString() });
|
|
364
|
+
await minted.mint({ machine, tokenSha256: sha256Hex(token), kind, os, arch, expiresAt: until, ...(options.owner ?? {}), ...(run !== undefined ? { run } : {}) });
|
|
365
|
+
log("machine_token_minted", { ...(run !== undefined ? { run } : {}), machine, kind, os, arch, expires_at: new Date(until).toISOString() });
|
|
324
366
|
return token;
|
|
325
367
|
},
|
|
326
368
|
async revoke(machine) {
|
|
@@ -328,6 +370,11 @@ export function createAttachRoutes(options) {
|
|
|
328
370
|
hub.revoke(machine, machineGone(machine));
|
|
329
371
|
log("machine_token_revoked", { machine });
|
|
330
372
|
},
|
|
373
|
+
// The server's relay refusal of this machine's dial, kept on its token's row (relayDial): the minting runner's
|
|
374
|
+
// create, waiting on its own hub, ends in these words at once.
|
|
375
|
+
async refused(machine) {
|
|
376
|
+
return (await minted.get(machine))?.refused ?? undefined;
|
|
377
|
+
},
|
|
331
378
|
};
|
|
332
379
|
const pairedDialer = (row) => ({
|
|
333
380
|
computer: pairedOf(row),
|
|
@@ -350,6 +397,69 @@ export function createAttachRoutes(options) {
|
|
|
350
397
|
const bearer = bearerOf(authorization);
|
|
351
398
|
return bearer?.startsWith(ATTACH_TOKEN_PREFIX) ? minted.byToken(sha256Hex(bearer)) : undefined;
|
|
352
399
|
}
|
|
400
|
+
/** Whether the socket here takes `row`'s machine: on a runner's listener (owner), only a token that runner minted in
|
|
401
|
+
* this incarnation; on the server, one its own process minted (another runner's is relayed, `relayDial`). */
|
|
402
|
+
const takes = (row) => (options.owner ? row.runner === options.owner.runner && row.incarnation === options.owner.incarnation : row.runner === null);
|
|
403
|
+
/** The server's relay of machine `row`'s dial (its token `bearer`) to the runner that minted it: refused 503 in words
|
|
404
|
+
* that name its run, then the machine (dialOf), never its token, where that runner keeps no fresh listener, restarted
|
|
405
|
+
* since, answers at a host this server does not dial, or does not take it; else the machine's socket is joined to one
|
|
406
|
+
* opened to the runner's listener with the proxy's proof for this token, runner and incarnation, each with this
|
|
407
|
+
* module's limits. */
|
|
408
|
+
async function relayDial(row, bearer, req, socket, head, deny) {
|
|
409
|
+
const runner = row.runner;
|
|
410
|
+
const named = { ...(row.run !== null ? { run: row.run } : {}), machine: row.machine, runner };
|
|
411
|
+
const refuse = (why) => {
|
|
412
|
+
const words = `${dialOf(row)}: ${why}`;
|
|
413
|
+
log("machine_relay_refused", { ...named, why: words });
|
|
414
|
+
// Kept on the token's row, where the runner's create waiting for this machine reads it (MachineTokens refused).
|
|
415
|
+
void minted.refuse(sha256Hex(bearer), words).catch((error) => log("machine_relay_refusal_unkept", { ...named, error: error instanceof Error ? error.message : String(error) }));
|
|
416
|
+
deny("503 Service Unavailable", words);
|
|
417
|
+
};
|
|
418
|
+
if (options.relay === undefined)
|
|
419
|
+
return refuse(`runner ${runner} made it, and this server relays no dial to a runner`);
|
|
420
|
+
const at = await options.relay.relays.get(runner);
|
|
421
|
+
if (at === undefined || at.seenAt < now() - RELAY_STALE_MS)
|
|
422
|
+
return refuse(`runner ${runner}, which made it, is not running now (no attach listener of its has said it is there for ${RELAY_STALE_MS / 1000} s): its run makes a new machine at its next claim`);
|
|
423
|
+
if (at.incarnation !== row.incarnation)
|
|
424
|
+
return refuse(`runner ${runner}, which made it, restarted since, and the machine was its earlier process's: its run makes a new machine at its next claim`);
|
|
425
|
+
const host = dialHost(at.host, options.relay.reach);
|
|
426
|
+
if (host === undefined)
|
|
427
|
+
return refuse(`runner ${runner}, which made it, answers at ${at.host}, which is not one of this server's runners' hosts (AGENTRUN_RUNNER_HOSTS)`);
|
|
428
|
+
const proof = relayProof(options.relay.reach, { tokenSha256: sha256Hex(bearer), runner, incarnation: at.incarnation });
|
|
429
|
+
const upstream = new WebSocket(`ws://${host}:${at.port}${ATTACH_PATH}`, ATTACH_SUBPROTOCOL, {
|
|
430
|
+
headers: { authorization: `Bearer ${bearer}`, [LIVE_PROOF_HEADER]: proof },
|
|
431
|
+
maxPayload: MAX_LINE_BYTES, perMessageDeflate: false, followRedirects: false, handshakeTimeout: RELAY_CONNECT_MS,
|
|
432
|
+
});
|
|
433
|
+
let settled = false;
|
|
434
|
+
upstream.once("unexpected-response", (_request, res) => {
|
|
435
|
+
settled = true;
|
|
436
|
+
res.resume();
|
|
437
|
+
upstream.terminate();
|
|
438
|
+
refuse(`runner ${runner}, which made it, did not take it (HTTP ${res.statusCode})`);
|
|
439
|
+
});
|
|
440
|
+
upstream.on("error", (error) => {
|
|
441
|
+
if (settled)
|
|
442
|
+
return;
|
|
443
|
+
settled = true;
|
|
444
|
+
// The library's words name the address and the step, never a header.
|
|
445
|
+
refuse(`runner ${runner}, which made it, did not answer at ${host}:${at.port} (${error.message})`);
|
|
446
|
+
});
|
|
447
|
+
upstream.once("open", () => {
|
|
448
|
+
settled = true;
|
|
449
|
+
if (socket.destroyed || closing) {
|
|
450
|
+
upstream.terminate();
|
|
451
|
+
return void socket.destroy();
|
|
452
|
+
}
|
|
453
|
+
wss.handleUpgrade(req, socket, head, (ws) => {
|
|
454
|
+
for (const one of [ws, upstream]) {
|
|
455
|
+
sockets.add(one);
|
|
456
|
+
one.once("close", () => sockets.delete(one));
|
|
457
|
+
}
|
|
458
|
+
joinSockets(ws, upstream, options.timing);
|
|
459
|
+
log("machine_relayed", named);
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
}
|
|
353
463
|
/** GET /v2/computers/daemon?arch=: the path of this server's computerd build for `arch`, for the minted machine whose
|
|
354
464
|
* token `authorization` bears. 401 for a token no machine has good (unknown, revoked or past its end); 429 past
|
|
355
465
|
* DAEMON_FETCHES_PER_MINUTE a minute by one machine; 422 for an arch with no build. */
|
|
@@ -374,7 +484,10 @@ export function createAttachRoutes(options) {
|
|
|
374
484
|
const bearer = bearerOf(req.headers.authorization);
|
|
375
485
|
const row = !options.machinesOnly && bearer?.startsWith(ATTACH_TOKEN_PREFIX) ? await paired.byToken(sha256Hex(bearer)) : undefined;
|
|
376
486
|
const machine = row === undefined ? await machineBy(req.headers.authorization) : undefined;
|
|
377
|
-
|
|
487
|
+
// Another runner's machine, on the server: relayed to that runner's listener below. On a runner's listener, a token
|
|
488
|
+
// of any other's (another runner's, another incarnation's, the server's) is one it does not know.
|
|
489
|
+
const relayed = machine !== undefined && !options.owner && machine.runner !== null;
|
|
490
|
+
const dialer = row !== undefined ? pairedDialer(row) : machine !== undefined && (relayed || takes(machine)) ? machineDialer(machine) : undefined;
|
|
378
491
|
if (dialer === undefined)
|
|
379
492
|
return deny("401 Unauthorized", options.machinesOnly ? MACHINE_TOKEN_REFUSED : TOKEN_REFUSED, { "www-authenticate": "Bearer" });
|
|
380
493
|
const asked = String(req.headers["sec-websocket-protocol"] ?? "").split(",").map((one) => one.trim()).filter(Boolean);
|
|
@@ -383,6 +496,8 @@ export function createAttachRoutes(options) {
|
|
|
383
496
|
}
|
|
384
497
|
if (socket.destroyed || closing)
|
|
385
498
|
return void socket.destroy();
|
|
499
|
+
if (relayed)
|
|
500
|
+
return relayDial(machine, bearer, req, socket, head, deny);
|
|
386
501
|
wss.handleUpgrade(req, socket, head, (ws) => {
|
|
387
502
|
sockets.add(ws);
|
|
388
503
|
ws.once("close", () => sockets.delete(ws));
|
package/dist/computer-keys.d.ts
CHANGED
|
@@ -80,6 +80,9 @@ export declare const COMPUTER_KEY_NAMES: readonly string[];
|
|
|
80
80
|
* providers it does.
|
|
81
81
|
*/
|
|
82
82
|
export declare function providerOptions(providerId: string, keys: Readonly<Record<string, string>>, settings?: ProviderSettings, table?: KeyTable): OptionsAnswer;
|
|
83
|
+
/** The create() options provider `providerId`'s settings fill from the server's settings (each of its descriptor's
|
|
84
|
+
* settings, by name, else its default), with no key: what a provider is made with that is no secret (its connect). */
|
|
85
|
+
export declare function settingOptions(providerId: string, settings?: ProviderSettings, table?: KeyTable): Record<string, string>;
|
|
83
86
|
/**
|
|
84
87
|
* The values Settings offers for provider `providerId`'s picked key `keyName` (its descriptor key's picked), read by the
|
|
85
88
|
* provider made from its saved keys (its keyChoices, by the option the key fills), never making a computer. ok with each
|
package/dist/computer-keys.js
CHANGED
|
@@ -51,13 +51,19 @@ export function providerOptions(providerId, keys, settings = {}, table = KEY_TAB
|
|
|
51
51
|
if (missing.length > 0) {
|
|
52
52
|
return refused("missing_key", `${label} needs ${missing.join(" and ")} saved: save ${missing.length > 1 ? "them" : "it"} in Settings → Computers (PUT /v2/computers/${providerId}/keys)`);
|
|
53
53
|
}
|
|
54
|
+
return { ok: true, options: { ...options, ...settingOptions(providerId, settings, table) } };
|
|
55
|
+
}
|
|
56
|
+
/** The create() options provider `providerId`'s settings fill from the server's settings (each of its descriptor's
|
|
57
|
+
* settings, by name, else its default), with no key: what a provider is made with that is no secret (its connect). */
|
|
58
|
+
export function settingOptions(providerId, settings = {}, table = KEY_TABLE) {
|
|
59
|
+
const options = {};
|
|
54
60
|
for (const setting of table.settings && has(table.settings, providerId) ? table.settings[providerId] : []) {
|
|
55
61
|
const given = has(settings, setting.name) ? settings[setting.name]?.trim() : undefined;
|
|
56
62
|
const value = given || setting.default;
|
|
57
63
|
if (value !== undefined && value !== "")
|
|
58
64
|
options[setting.option] = value;
|
|
59
65
|
}
|
|
60
|
-
return
|
|
66
|
+
return options;
|
|
61
67
|
}
|
|
62
68
|
/** `text` with every key value in `values` replaced by "[the key]". */
|
|
63
69
|
function scrub(text, values) {
|
package/dist/computer-live.js
CHANGED
|
@@ -26,7 +26,7 @@ import { randomBytes } from "node:crypto";
|
|
|
26
26
|
import { createServer } from "node:http";
|
|
27
27
|
import { createActionMapper, redactWords } from "@parcha/agentrun-computer";
|
|
28
28
|
import { acceptWebSocket, CLOSE_CODES, encodeFrame, tokenMatches } from "@parcha/pi-browser/live-view";
|
|
29
|
-
import { provenFor } from "./live-reach.js";
|
|
29
|
+
import { liveForRun, provenFor } from "./live-reach.js";
|
|
30
30
|
import { computerHoldOf, handBackComputer, takeOverComputer } from "./computer-commands.js";
|
|
31
31
|
import { onComputerHold } from "./runner/computer-journal.js";
|
|
32
32
|
import { sealColumn, sealedAt } from "./store/seal.js";
|
|
@@ -84,7 +84,8 @@ export const claimViewOpener = (at) => (args) => {
|
|
|
84
84
|
store, sealKey: args.sealKey, claim, kind: args.kind, input: args.input, tag: args.tag, watch: args.watch,
|
|
85
85
|
hold: viewerHoldOf(PLACES, store, claim.runId, args.hold),
|
|
86
86
|
...(args.gone ? { gone: args.gone } : {}),
|
|
87
|
-
|
|
87
|
+
// Proved under the claim's run's own key (live-reach.ts liveForRun), as the server asks it.
|
|
88
|
+
...(at ? { at: liveForRun(at, claim.runId) } : {}),
|
|
88
89
|
});
|
|
89
90
|
};
|
|
90
91
|
/** The opener on the server's own machine: loopback. */
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** How many new sandboxes a claim starts in place of ones its provider lost, by default. */
|
|
2
|
+
export declare const LOST_RECREATES = 2;
|
|
3
|
+
/** The code a run past its new sandboxes fails with: the one a computer that cannot be had at the claim is refused with. */
|
|
4
|
+
export declare const COMPUTER_UNAVAILABLE_CODE = "computer_unavailable";
|
|
5
|
+
/** The Timeline's row once a new sandbox replaced a lost one: its name. */
|
|
6
|
+
export declare const lostRecreatedWords: (name: string) => string;
|
|
7
|
+
/** The run's end once its sandbox was lost again after `recreates` new ones (the claim's bound): the provider's words,
|
|
8
|
+
* `why`, last. */
|
|
9
|
+
export declare const lostEnd: (recreates: number, why: string) => string;
|
|
10
|
+
/** The message of a run's end in lostEnd's words: what follows its code; undefined for any other summary. */
|
|
11
|
+
export declare const lostEndMessage: (summary: string | null | undefined) => string | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// A run's sandbox that its provider lost mid-run (deleted by the vendor's own API or console, or gone with no why): the
|
|
2
|
+
// claim starts a new one in its place at the next tool call (workspace/computer-for-claim.ts lostAware), up to
|
|
3
|
+
// LOST_RECREATES times a claim. These are the words of both: the Timeline's row for a new one, and the run's end once the
|
|
4
|
+
// claim has started as many as it may. That end's words begin with its code, so a reader of the run's summary serves it
|
|
5
|
+
// as the error computer_unavailable, its message the words after the code (store-view.ts errorOfRow), as a cap's end is
|
|
6
|
+
// served as spend_cap_reached.
|
|
7
|
+
/** How many new sandboxes a claim starts in place of ones its provider lost, by default. */
|
|
8
|
+
export const LOST_RECREATES = 2;
|
|
9
|
+
/** The code a run past its new sandboxes fails with: the one a computer that cannot be had at the claim is refused with. */
|
|
10
|
+
export const COMPUTER_UNAVAILABLE_CODE = "computer_unavailable";
|
|
11
|
+
/** How lostEnd's words begin, and only theirs. */
|
|
12
|
+
const LOST_END = `${COMPUTER_UNAVAILABLE_CODE}: `;
|
|
13
|
+
/** The Timeline's row once a new sandbox replaced a lost one: its name. */
|
|
14
|
+
export const lostRecreatedWords = (name) => `Its computer was lost; started a new one (${name}).`;
|
|
15
|
+
/** The run's end once its sandbox was lost again after `recreates` new ones (the claim's bound): the provider's words,
|
|
16
|
+
* `why`, last. */
|
|
17
|
+
export const lostEnd = (recreates, why) => `${LOST_END}the run's sandbox was lost ${recreates + 1} ${recreates === 0 ? "time" : "times"}, and a run starts at most ${recreates} new ${recreates === 1 ? "one" : "ones"} in place of a lost one: ${why.replace(/[.!?]+$/, "")}.`;
|
|
18
|
+
/** The message of a run's end in lostEnd's words: what follows its code; undefined for any other summary. */
|
|
19
|
+
export const lostEndMessage = (summary) => typeof summary === "string" && summary.startsWith(LOST_END) ? summary.slice(LOST_END.length) : undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Result, ScreenWatch, ScreenWatchHandlers, WatchOptions } from "@parcha/agentrun-computer";
|
|
2
|
+
import type { LiveViewHost } from "@parcha/pi-browser/live-view";
|
|
2
3
|
/** The program that encodes the video. */
|
|
3
4
|
export declare const FFMPEG = "ffmpeg";
|
|
4
5
|
/** The recorder's bounds: frames a second at most; the long side in pixels at most; the caps, in bytes across the run's
|
|
@@ -35,14 +36,21 @@ export interface Recording {
|
|
|
35
36
|
facts(): RecordingFacts;
|
|
36
37
|
}
|
|
37
38
|
/** The computer's watch, bound to its ref (provider.watch): the recorder gives the handlers and the signal. */
|
|
38
|
-
export type RecordWatch = (handlers: ScreenWatchHandlers, options: WatchOptions) => Promise<Result<ScreenWatch
|
|
39
|
+
export type RecordWatch = (handlers: ScreenWatchHandlers, options: WatchOptions) => Promise<Result<Pick<ScreenWatch, "close">>>;
|
|
40
|
+
/** Browser session `tag`'s screen as the recorder watches it: the run's live view's screencast of it (pi-browser's
|
|
41
|
+
* LiveViewHost.watch), which the live view acks; JPEG frames of the page's size. */
|
|
42
|
+
export declare const browserWatch: (view: Pick<LiveViewHost, "watch">, tag: string) => RecordWatch;
|
|
43
|
+
/** A run's browser sessions' recordings, each by its tag, where its claim records (ClaimBrowser.record): the answer is
|
|
44
|
+
* told session `id` under `tag` at its launch or its reopening, which starts its own (named by its computer, `id`) and
|
|
45
|
+
* ends the one before it under that tag, and null at its release, which ends it. With no `record`, nothing. */
|
|
46
|
+
export declare function sessionRecordings(view: Pick<LiveViewHost, "watch">, record: ((id: string, watch: RecordWatch) => Recording) | undefined): (tag: string, id: string | null) => Promise<void>;
|
|
39
47
|
export type RecordInput = {
|
|
40
48
|
readonly watch: RecordWatch;
|
|
41
49
|
/** The run's recordings folder on this machine (recordingsFolder): made when the first frame comes. */
|
|
42
50
|
readonly folder: string;
|
|
43
51
|
/** The computer's ref id: its file's name. */
|
|
44
52
|
readonly tag: string;
|
|
45
|
-
readonly kind: "desktop" | "phone";
|
|
53
|
+
readonly kind: "desktop" | "phone" | "browser";
|
|
46
54
|
/** A line on the run's timeline. */
|
|
47
55
|
readonly say: (words: string) => void;
|
|
48
56
|
/** For tests: the program run in ffmpeg's place, the bounds, and where a line for the operator goes (default stderr). */
|
package/dist/computer-record.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
// A run's video of its desktop's or
|
|
2
|
-
// computer-setting.ts). The claim (workspace/computer-for-claim.ts) starts it once the computer is attached, beside
|
|
3
|
-
// live view, and stops it at the computer's release, the run's end or its park
|
|
1
|
+
// A run's video of its desktop's, phone's or browser's screen, where the agent's setting asks for one (computer.record:
|
|
2
|
+
// true, computer-setting.ts). The claim (workspace/computer-for-claim.ts) starts it once the computer is attached, beside
|
|
3
|
+
// the live view, and stops it at the computer's release, the run's end or its park; a browser's, each session's from its
|
|
4
|
+
// launch to its release (tools.ts), named by the session's computer.
|
|
4
5
|
//
|
|
5
6
|
// It is a second watch of the computer's screen (the provider's watch, on a connection of its own), so it records with no
|
|
6
7
|
// viewer open, and neither the live viewer's frames and acks nor the agent ever wait on it: each frame is acked as it
|
|
7
|
-
// comes.
|
|
8
|
+
// comes. A browser's is the run's live view's one CDP screencast of the session, shared with its viewer (browserWatch),
|
|
9
|
+
// whose frames come as the page changes. Frames go to one ffmpeg per recorded computer, piped in (image2pipe), each stamped as ffmpeg reads it, so the
|
|
8
10
|
// video's frame rate is the screen's own (a screen that does not change adds nothing). At most RECORDING_LIMITS.fps frames
|
|
9
11
|
// a second are written: one that comes sooner waits in a one-frame slot, and a newer one replaces it (thinned). While
|
|
10
12
|
// ffmpeg has not taken the frame before, a newer one replaces the one waiting too (dropped): the encoder falling behind
|
|
@@ -17,8 +19,8 @@
|
|
|
17
19
|
// file and goes on in the next, <computer>-2.mp4, since one ffmpeg reads one format; a resumed run's claim starts the
|
|
18
20
|
// next file too. A frame of another size is fitted into the file's own (scaled and padded).
|
|
19
21
|
//
|
|
20
|
-
// Its caps stop it: RECORDING_LIMITS.maxBytes across the run's files (
|
|
21
|
-
//
|
|
22
|
+
// Its caps stop it: RECORDING_LIMITS.maxBytes across the run's files (read from the folder at each check, so a park's
|
|
23
|
+
// earlier files and a browser's other sessions recording at once count too, and a run past it records no more) and maxMs of one recording (from its first frame to its
|
|
22
24
|
// stop or its park). So do ffmpeg ending by itself (a crash, a full disk) and the screen's watch ending past
|
|
23
25
|
// RECORDING_LIMITS.rewatches tries: each says so on the run's timeline, in words. The run itself never fails because of
|
|
24
26
|
// the recorder.
|
|
@@ -34,6 +36,32 @@ export const FFMPEG = "ffmpeg";
|
|
|
34
36
|
export const RECORDING_LIMITS = { fps: 10, edge: 1280, maxBytes: 500 * 1024 * 1024, maxMs: 2 * 60 * 60 * 1000, checkMs: 1_000, settleMs: 5_000, rewatches: 3, rewatchMs: 1_000 };
|
|
35
37
|
/** Why this server cannot record a screen, in words, or undefined: ffmpeg is on `path` (the server's PATH, read now). */
|
|
36
38
|
export const recorderMissing = (path = process.env.PATH) => commandOnPath(FFMPEG, path) ? undefined : "ffmpeg isn't installed on this server (no ffmpeg command on PATH)";
|
|
39
|
+
/** Browser session `tag`'s screen as the recorder watches it: the run's live view's screencast of it (pi-browser's
|
|
40
|
+
* LiveViewHost.watch), which the live view acks; JPEG frames of the page's size. */
|
|
41
|
+
export const browserWatch = (view, tag) => async (handlers) => {
|
|
42
|
+
let seq = 0;
|
|
43
|
+
const unwatch = view.watch(tag, {
|
|
44
|
+
frame: (bytes, { w, h }) => handlers.frame({ seq: ++seq, format: "jpeg", bytes, width: w, height: h, frameWidth: w, frameHeight: h }, () => undefined),
|
|
45
|
+
ended: () => handlers.ended({ code: "unreachable", message: "the browser's DevTools socket closed" }),
|
|
46
|
+
});
|
|
47
|
+
return unwatch ? { ok: true, value: { close: async () => unwatch() } } : { ok: false, error: { code: "unreachable", message: "the browser session has no live view" } };
|
|
48
|
+
};
|
|
49
|
+
/** A run's browser sessions' recordings, each by its tag, where its claim records (ClaimBrowser.record): the answer is
|
|
50
|
+
* told session `id` under `tag` at its launch or its reopening, which starts its own (named by its computer, `id`) and
|
|
51
|
+
* ends the one before it under that tag, and null at its release, which ends it. With no `record`, nothing. */
|
|
52
|
+
export function sessionRecordings(view, record) {
|
|
53
|
+
const held = new Map();
|
|
54
|
+
return async (tag, id) => {
|
|
55
|
+
const before = held.get(tag);
|
|
56
|
+
if (before?.id === id)
|
|
57
|
+
return;
|
|
58
|
+
if (record && id !== null)
|
|
59
|
+
held.set(tag, { id, recording: record(id, browserWatch(view, tag)) });
|
|
60
|
+
else
|
|
61
|
+
held.delete(tag);
|
|
62
|
+
await before?.recording.stop("released");
|
|
63
|
+
};
|
|
64
|
+
}
|
|
37
65
|
/** A file's name: the computer's ref id in the characters a file name takes, and the file's number after the first. */
|
|
38
66
|
const fileName = (tag, n) => `${tag.replace(/[^A-Za-z0-9._-]/g, "_")}${n === 1 ? "" : `-${n}`}.mp4`;
|
|
39
67
|
/** A frame's size fitted to `edge` on its long side, each side even (H.264's 4:2:0 needs it). */
|
|
@@ -87,8 +115,6 @@ export function startRecording(input) {
|
|
|
87
115
|
let wroteAt = Number.NEGATIVE_INFINITY;
|
|
88
116
|
let firstAt;
|
|
89
117
|
let pacer;
|
|
90
|
-
/** The bytes of the files finished before this one. */
|
|
91
|
-
let doneBytes = 0;
|
|
92
118
|
let written = 0;
|
|
93
119
|
let dropped = 0;
|
|
94
120
|
let thinned = 0;
|
|
@@ -118,21 +144,25 @@ export function startRecording(input) {
|
|
|
118
144
|
ended.child.kill("SIGKILL");
|
|
119
145
|
await ended.exited;
|
|
120
146
|
}
|
|
121
|
-
|
|
147
|
+
};
|
|
148
|
+
/** The bytes of every video in the run's folder: the byte cap is the run's, so it counts a park's earlier files and the
|
|
149
|
+
* files of the run's other recordings (a browser's sessions, each its own, can record at once). */
|
|
150
|
+
const runBytes = async (listed) => {
|
|
151
|
+
let total = 0;
|
|
152
|
+
for (const one of (listed ?? (await readdir(input.folder).catch(() => []))).filter((name) => name.endsWith(".mp4")))
|
|
153
|
+
total += await stat(join(input.folder, one)).then((file) => file.size, () => 0);
|
|
154
|
+
return total;
|
|
122
155
|
};
|
|
123
156
|
/** A file for `frame`'s format: its folder made, its name the first of the series not taken, its ffmpeg started. */
|
|
124
157
|
const openPart = async (frame, before) => {
|
|
125
158
|
let path;
|
|
126
159
|
let name;
|
|
160
|
+
let bytes;
|
|
127
161
|
try {
|
|
128
162
|
await mkdir(input.folder, { recursive: true, mode: 0o700 });
|
|
129
163
|
const listed = await readdir(input.folder);
|
|
130
164
|
const taken = new Set(listed);
|
|
131
|
-
|
|
132
|
-
if (!before && files.length === 0) {
|
|
133
|
-
for (const earlier of listed.filter((one) => one.endsWith(".mp4")))
|
|
134
|
-
doneBytes += await stat(join(input.folder, earlier)).then((file) => file.size, () => 0);
|
|
135
|
-
}
|
|
165
|
+
bytes = await runBytes(listed);
|
|
136
166
|
let n = 1;
|
|
137
167
|
while (taken.has(fileName(input.tag, n)))
|
|
138
168
|
n += 1;
|
|
@@ -143,7 +173,7 @@ export function startRecording(input) {
|
|
|
143
173
|
void finish(`its folder could not be made (${error.code ?? "an error"})`);
|
|
144
174
|
return undefined;
|
|
145
175
|
}
|
|
146
|
-
if (
|
|
176
|
+
if (bytes >= limits.maxBytes) {
|
|
147
177
|
void finish(`it reached its cap of ${sizeWords(limits.maxBytes)}`);
|
|
148
178
|
return undefined;
|
|
149
179
|
}
|
|
@@ -271,9 +301,8 @@ export function startRecording(input) {
|
|
|
271
301
|
return;
|
|
272
302
|
if (Date.now() - firstAt >= limits.maxMs)
|
|
273
303
|
return void finish(`it reached its cap of ${lengthWords(limits.maxMs)}`);
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
void stat(current.path).then((file) => (doneBytes + file.size >= limits.maxBytes && over === undefined ? finish(`it reached its cap of ${sizeWords(limits.maxBytes)}`) : undefined), () => undefined);
|
|
304
|
+
if (part)
|
|
305
|
+
void runBytes().then((bytes) => (bytes >= limits.maxBytes && over === undefined ? finish(`it reached its cap of ${sizeWords(limits.maxBytes)}`) : undefined));
|
|
277
306
|
}, limits.checkMs);
|
|
278
307
|
checker.unref();
|
|
279
308
|
/** The end of the recording, once: `why` in words when it ended by itself (said on the timeline), else stopped. */
|
|
@@ -299,6 +328,9 @@ export function startRecording(input) {
|
|
|
299
328
|
const newest = slot ?? last;
|
|
300
329
|
await endPart(ending, !busy && newest && newest.format === ending.format ? newest.bytes : undefined);
|
|
301
330
|
}
|
|
331
|
+
// An ended recording keeps no picture: the claim holds each of its run's recordings until its own end.
|
|
332
|
+
slot = undefined;
|
|
333
|
+
last = undefined;
|
|
302
334
|
await closing;
|
|
303
335
|
if (files.length)
|
|
304
336
|
log(`recorded ${what}'s screen into ${files.join(", ")}: ${written} frames written, ${dropped} dropped while ffmpeg was busy, ${thinned} thinned to ${limits.fps} a second`);
|
package/dist/computer-setting.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// persistent: true keeps the agent's own computer between its runs, where the configuration declares persistence. A
|
|
6
6
|
// desktop's or a phone's surface ("code" or "tools") is how the agent drives it, and exec: false gives the agent no
|
|
7
7
|
// shell and no program start on it (run-tools.ts); the owner's own computer calls keep everything. record: true makes
|
|
8
|
-
// each run a video of a desktop's or a
|
|
8
|
+
// each run a video of a desktop's, a phone's or a browser's screen (computer-record.ts). The v2 API's `place` is this
|
|
9
9
|
// setting's view, one to one where it can say it: {mode: "runner"} is {kind: "none"}, and {mode: "sandbox", box: X} is
|
|
10
10
|
// {kind: "sandbox", provider: X}. Writing either sets both. A desktop, phone or browser computer leaves the run's folder
|
|
11
11
|
// on the runner, so its place reads runner.
|
|
@@ -51,7 +51,7 @@ const OPTIONAL = {
|
|
|
51
51
|
// true: each run's video of the screen (computer-record.ts), made with this server's ffmpeg, so a server without one
|
|
52
52
|
// refuses it here.
|
|
53
53
|
record: {
|
|
54
|
-
kinds: ["desktop", "phone"],
|
|
54
|
+
kinds: ["desktop", "phone", "browser"],
|
|
55
55
|
check: (value, field) => {
|
|
56
56
|
if (typeof value !== "boolean")
|
|
57
57
|
return [{ field, reason: "wrong_type", message: `${field} is true (each run records a video of the computer's screen) or false (as absent)` }];
|
package/dist/computers.d.ts
CHANGED
|
@@ -27,6 +27,9 @@ export type KindCapabilities = {
|
|
|
27
27
|
export interface ProviderEntry {
|
|
28
28
|
readonly id: string;
|
|
29
29
|
readonly label: string;
|
|
30
|
+
/** Whether its machines dial this server, as its descriptor declares it (the computer package's connectOf reads it
|
|
31
|
+
* with its settings' connect). Absent: they never do. */
|
|
32
|
+
readonly connect?: "dial" | "either";
|
|
30
33
|
readonly kinds: readonly ComputerKind[];
|
|
31
34
|
readonly keys: readonly {
|
|
32
35
|
readonly name: string;
|
|
@@ -112,6 +115,14 @@ export interface ComputerRoutesOptions {
|
|
|
112
115
|
rows(): Promise<readonly PairedComputerRow[]>;
|
|
113
116
|
viewOf(row: PairedComputerRow, serves: readonly ComputerSettingKind[]): PairedView;
|
|
114
117
|
};
|
|
118
|
+
/** No runner in this server's process (ServeOptions.runnerApart): no run here can use a computer whose socket the
|
|
119
|
+
* server's attach hub takes, a paired computer's or a dial provider's machine's. Each such provider's row says so
|
|
120
|
+
* (runs_refused), and a dial provider's test fails in those words. */
|
|
121
|
+
readonly runnerApart?: boolean;
|
|
122
|
+
/** Whether a runner in a process of its own relays its dials now (dial-relay.ts): its machines dial this server, which
|
|
123
|
+
* relays each socket to it, so a dial provider's runs can use it and its row says nothing. Read once per view and per
|
|
124
|
+
* test. Absent: none does. A paired computer's socket is never relayed. */
|
|
125
|
+
readonly relayed?: () => Promise<boolean>;
|
|
115
126
|
}
|
|
116
127
|
/** A provider as Settings shows it: `metered` straight from the kind registry (its computers are billed by the vendor);
|
|
117
128
|
* its keys as SecretMeta under `secrets`, each named "computer:<provider>:<KEY>", and `required`, the names of the ones
|
|
@@ -119,7 +130,9 @@ export interface ComputerRoutesOptions {
|
|
|
119
130
|
* `images`: the images it offers for the kind, by name, where it offers any to choose. `persistent`: present where an
|
|
120
131
|
* agent's computer of this kind can be kept between its runs (computer.persistent: true), with the images that keep one
|
|
121
132
|
* where it offers images to choose. `picked`: the names of the secrets a person picks from the vendor's own list
|
|
122
|
-
* (GET /v2/computers/{provider}/choices) rather than pastes, where it has any.
|
|
133
|
+
* (GET /v2/computers/{provider}/choices) rather than pastes, where it has any. `runs_refused`: on a server whose runner
|
|
134
|
+
* runs in a process of its own, why no run here can use it and the fix, for a computer whose socket the server's
|
|
135
|
+
* process takes (a dial provider's, a paired one's); else null. */
|
|
123
136
|
export type ProviderView = {
|
|
124
137
|
id: string;
|
|
125
138
|
name: string;
|
|
@@ -129,6 +142,7 @@ export type ProviderView = {
|
|
|
129
142
|
picked?: string[];
|
|
130
143
|
ready: boolean;
|
|
131
144
|
why?: string;
|
|
145
|
+
runs_refused: string | null;
|
|
132
146
|
network?: string;
|
|
133
147
|
images?: string[];
|
|
134
148
|
persistent?: {
|
|
@@ -204,15 +218,12 @@ export declare class KeysRefused extends Error {
|
|
|
204
218
|
}
|
|
205
219
|
/** A run's failure code when its computer cannot be had. */
|
|
206
220
|
export declare const COMPUTER_UNAVAILABLE = "computer_unavailable";
|
|
207
|
-
/** Why `provider` cannot serve a run's computer of kind `kind` in `mode`, by the
|
|
208
|
-
* A sandbox holds the run's folder: Mode 1 keeps it on this machine, which only a
|
|
209
|
-
* (Docker) reaches; Mode 2 keeps it on the owner's disk, which
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
* Archil's client, in the owner's workspace; Modal pulls it; E2B starts its public template) or the operator names it
|
|
214
|
-
* here (Daytona's AGENTRUN_DAYTONA_SNAPSHOT). `provider` is as this server has it (resolve-computer.ts entryHere): a
|
|
215
|
-
* Daytona sandbox mounts the disk only where DAYTONA_ARCHIL_EGRESS names a self-hosted target's Archil egress relay. */
|
|
221
|
+
/** Why `provider` cannot serve a run's computer of kind `kind` in `mode`, by the folder it holds (resolve-computer.ts
|
|
222
|
+
* folderKindOf): undefined when it can. A sandbox holds the run's folder: Mode 1 keeps it on this machine, which only a
|
|
223
|
+
* computer that binds a local folder (Docker) reaches; Mode 2 keeps it on the owner's disk, which a computer holds as an
|
|
224
|
+
* Archil mount where its provider takes one and Archil's image is here, else as a synced folder the runner keeps on the
|
|
225
|
+
* disk (never a local Docker bind). A desktop, phone or browser holds no folder unless its provider takes one, so either
|
|
226
|
+
* mode takes it. `provider` is as this server has it (resolve-computer.ts entryHere). */
|
|
216
227
|
export declare function modeRefusal(kind: ComputerKind, provider: ProviderEntry, mode: FolderMode): string | undefined;
|
|
217
228
|
/** The routes' work over the server's store: GET /v2/computers (view), PUT /v2/computers/{provider}/keys (saveKeys), POST
|
|
218
229
|
* /v2/computers/{provider}/test (test), and the claim's refusal (claimRefusal). */
|