@parcha/agentrun-serve 0.1.0-beta.44 → 0.1.0-beta.46
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 +148 -5
- package/README.md +385 -305
- 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 +62 -19
- package/dist/composio-preset.js +69 -7
- package/dist/composio-triggers.d.ts +14 -0
- package/dist/composio-triggers.js +79 -15
- 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/computers.d.ts +21 -10
- package/dist/computers.js +39 -28
- package/dist/console/assets/index-C2MYaUBa.css +1 -0
- package/dist/console/assets/index-CZZeCReB.js +701 -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 +3 -1
- package/dist/errors.js +7 -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 +9 -1
- package/dist/harness-table.js +20 -3
- package/dist/harness.d.ts +1 -2
- package/dist/harness.js +3 -4
- package/dist/host.js +2 -1
- package/dist/import.d.ts +10 -0
- package/dist/import.js +28 -8
- 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 +23 -89
- package/dist/learn/check.js +57 -335
- 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 +89 -104
- package/dist/learn/corrections.d.ts +13 -0
- package/dist/learn/corrections.js +23 -0
- package/dist/learn/delete.d.ts +5 -5
- package/dist/learn/delete.js +8 -10
- 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 +23 -5
- package/dist/learn/promote.js +40 -2
- package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +30 -38
- package/dist/learn/{skills.js → workflow-draft.js} +48 -58
- package/dist/learn/workflow-nodes.js +1 -1
- package/dist/learned-workflow.js +2 -2
- package/dist/learning-cost.d.ts +38 -24
- package/dist/learning-cost.js +41 -24
- package/dist/learning-routes.d.ts +91 -170
- package/dist/learning-routes.js +183 -421
- package/dist/learning-run.d.ts +19 -40
- package/dist/learning-run.js +23 -93
- package/dist/learning-setting.d.ts +21 -10
- package/dist/learning-setting.js +47 -11
- package/dist/learning-words.d.ts +28 -74
- package/dist/learning-words.js +64 -162
- package/dist/learning.d.ts +61 -392
- package/dist/learning.js +101 -651
- package/dist/live-reach.d.ts +25 -2
- package/dist/live-reach.js +46 -4
- package/dist/llms.txt +1 -1
- package/dist/local-models.d.ts +3 -11
- package/dist/local-models.js +5 -6
- package/dist/mcp-servers-store.d.ts +4 -4
- package/dist/model-form.js +6 -5
- package/dist/model.d.ts +4 -0
- package/dist/model.js +26 -9
- 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 +273 -319
- package/dist/paid-calls.d.ts +8 -0
- package/dist/paid-calls.js +20 -0
- package/dist/particle-provider.d.ts +11 -0
- package/dist/particle-provider.js +135 -0
- 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 +15 -1
- 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 +15 -89
- package/dist/run-listing.d.ts +34 -0
- package/dist/run-listing.js +128 -0
- package/dist/run-model-key.js +1 -1
- 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 +8 -6
- package/dist/runner/adapter-loop.js +16 -12
- package/dist/runner/adapter-run-spec.d.ts +16 -4
- package/dist/runner/adapter-run-spec.js +64 -58
- package/dist/runner/adapters/index.js +22 -0
- package/dist/runner/adapters/pi.d.ts +4 -12
- package/dist/runner/adapters/pi.js +2 -2
- package/dist/runner/audit.d.ts +1 -1
- package/dist/runner/audit.js +30 -13
- package/dist/runner/beside.d.ts +6 -2
- package/dist/runner/beside.js +38 -9
- package/dist/runner/claim-secrets.d.ts +18 -2
- package/dist/runner/claim-secrets.js +42 -18
- package/dist/runner/cli-run-spec.js +55 -51
- package/dist/runner/conformance/harness.d.ts +6 -0
- package/dist/runner/conformance/harness.js +35 -13
- package/dist/runner/conformance/subject.d.ts +6 -0
- 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 +2 -2
- package/dist/runner/feedback-round.js +7 -7
- package/dist/runner/github-app.js +3 -1
- package/dist/runner/harness-loops.d.ts +0 -8
- package/dist/runner/harness-loops.js +11 -59
- package/dist/runner/held.d.ts +170 -0
- package/dist/runner/held.js +57 -0
- package/dist/runner/journal-kinds.d.ts +2 -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 -69
- package/dist/runner/learning-end.js +250 -303
- package/dist/runner/learning-seed.d.ts +15 -33
- package/dist/runner/learning-seed.js +24 -45
- package/dist/runner/loop-contract.d.ts +2 -3
- package/dist/runner/main.d.ts +17 -9
- package/dist/runner/main.js +82 -20
- package/dist/runner/mcp-run.d.ts +11 -0
- package/dist/runner/mcp-run.js +67 -0
- package/dist/runner/memory-claim.d.ts +10 -5
- package/dist/runner/memory-claim.js +12 -6
- 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 +12 -8
- package/dist/runner/promotion.js +37 -28
- package/dist/runner/reflect-hook.d.ts +64 -95
- package/dist/runner/reflect-hook.js +112 -225
- 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 +1230 -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 +1 -5
- 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 +5 -1
- package/dist/runner/workflow-first.d.ts +5 -0
- package/dist/runner/workflow-first.js +4 -0
- package/dist/runner/workflow-spec.js +7 -2
- package/dist/runs-over-store.d.ts +16 -28
- package/dist/runs-over-store.js +31 -38
- package/dist/sdk/runs.d.ts +6 -11
- package/dist/sdk/runs.js +20 -41
- package/dist/sdk/schema.js +3 -4
- 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 +55 -33
- package/dist/server.js +689 -322
- 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 +2 -2
- package/dist/store/index.js +1 -1
- 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/sqlite/connection.d.ts +2 -0
- package/dist/store/sqlite/connection.js +3 -1
- package/dist/store/sqlite/run-patch.d.ts +0 -17
- package/dist/store/sqlite/run-patch.js +4 -33
- package/dist/store/sqlite/store.js +246 -63
- package/dist/store/sqlite/worker.js +25 -0
- package/dist/store/store.d.ts +193 -36
- package/dist/store/store.js +25 -3
- package/dist/store-reads/learning.d.ts +102 -204
- package/dist/store-reads/learning.js +159 -321
- package/dist/store-reads/loop.d.ts +0 -1
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-view.d.ts +29 -1
- package/dist/store-view.js +97 -31
- package/dist/template-eval.d.ts +3 -6
- package/dist/template-eval.js +22 -36
- package/dist/templates.d.ts +8 -4
- package/dist/templates.js +44 -6
- 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/tools.d.ts +2 -2
- package/dist/tools.js +11 -4
- package/dist/triggers.d.ts +65 -6
- package/dist/triggers.js +125 -19
- package/dist/validate.js +1 -1
- package/dist/webhooks.d.ts +7 -2
- package/dist/webhooks.js +12 -5
- 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 +7 -3
- package/dist/workspace/computer-for-claim.js +119 -22
- 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 +33 -19
- 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 -10
- package/templates/README.md +8 -8
- package/templates/inbound-lead/agent.md +5 -4
- 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/kyb/agent.md +2 -1
- 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-BUktRvS-.css +0 -1
- package/dist/console/assets/index-nB9kTfIN.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 -35
- package/dist/learning-evals.js +0 -99
- 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. */
|
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). */
|
package/dist/computers.js
CHANGED
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
// their names only: a provider declares them, Settings takes only those, and the store keeps each sealed under the
|
|
8
8
|
// server's seal key (server-keys.ts); a provider is handed its keys only at the claim, or for its test, both through
|
|
9
9
|
// computer-keys.ts (providerOptions, testConnection), which maps a key's name onto the option it fills.
|
|
10
|
-
import { imagesOf } from "@parcha/agentrun-computer";
|
|
10
|
+
import { connectOf, imagesOf } from "@parcha/agentrun-computer";
|
|
11
11
|
import { BOX_ALLOW_ENV, boxAllowOf } from "./box-settings.js";
|
|
12
|
-
import { KEY_TABLE, keyChoices, providerOptions, testConnection } from "./computer-keys.js";
|
|
12
|
+
import { KEY_TABLE, keyChoices, providerOptions, settingOptions, testConnection } from "./computer-keys.js";
|
|
13
13
|
import { COMPUTER_KINDS, gpuOf } from "./computer-setting.js";
|
|
14
14
|
import { inArchilMode } from "./archil-settings.js";
|
|
15
15
|
import { daemonUp, noDockerWords } from "./docker-daemon.js";
|
|
@@ -20,8 +20,8 @@ import { redacted } from "./key-refusal.js";
|
|
|
20
20
|
import { keyMetaOf, envValue } from "./key-meta.js";
|
|
21
21
|
import { registerNotSecretWrite, registerSecretWrite, secretName } from "./secret-writes.js";
|
|
22
22
|
import { getSealedKey, putSealedKey, removeSealedKey, sealedKeyNames } from "./server-keys.js";
|
|
23
|
-
import { withPaired } from "./workspace/attached-computers.js";
|
|
24
|
-
import { aLabel,
|
|
23
|
+
import { dialApartWords, RUNNER_APART_WORDS, withPaired } from "./workspace/attached-computers.js";
|
|
24
|
+
import { aLabel, entryHere, folderKindOf, needsNetwork, shellChoiceOf } from "./workspace/resolve-computer.js";
|
|
25
25
|
// Every request to a computer's keys is a secret write (secret-writes.ts), whatever its body (a value, a null, an empty
|
|
26
26
|
// body or none), as saveToolKey's is: the server's one dispatch check keeps it to the owner's session before any provider
|
|
27
27
|
// is looked up, so a token learns nothing of which providers exist. The view and the connection test write none.
|
|
@@ -83,38 +83,34 @@ export class KeysRefused extends Error {
|
|
|
83
83
|
}
|
|
84
84
|
/** A run's failure code when its computer cannot be had. */
|
|
85
85
|
export const COMPUTER_UNAVAILABLE = "computer_unavailable";
|
|
86
|
-
/** Why `provider` cannot serve a run's computer of kind `kind` in `mode`, by the
|
|
87
|
-
* A sandbox holds the run's folder: Mode 1 keeps it on this machine, which only a
|
|
88
|
-
* (Docker) reaches; Mode 2 keeps it on the owner's disk, which
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* Archil's client, in the owner's workspace; Modal pulls it; E2B starts its public template) or the operator names it
|
|
93
|
-
* here (Daytona's AGENTRUN_DAYTONA_SNAPSHOT). `provider` is as this server has it (resolve-computer.ts entryHere): a
|
|
94
|
-
* Daytona sandbox mounts the disk only where DAYTONA_ARCHIL_EGRESS names a self-hosted target's Archil egress relay. */
|
|
86
|
+
/** Why `provider` cannot serve a run's computer of kind `kind` in `mode`, by the folder it holds (resolve-computer.ts
|
|
87
|
+
* folderKindOf): undefined when it can. A sandbox holds the run's folder: Mode 1 keeps it on this machine, which only a
|
|
88
|
+
* computer that binds a local folder (Docker) reaches; Mode 2 keeps it on the owner's disk, which a computer holds as an
|
|
89
|
+
* Archil mount where its provider takes one and Archil's image is here, else as a synced folder the runner keeps on the
|
|
90
|
+
* disk (never a local Docker bind). A desktop, phone or browser holds no folder unless its provider takes one, so either
|
|
91
|
+
* mode takes it. `provider` is as this server has it (resolve-computer.ts entryHere). */
|
|
95
92
|
export function modeRefusal(kind, provider, mode) {
|
|
96
|
-
// A desktop with files and exec on a provider that mounts the disk would mount it in Mode 2, so it needs the image too.
|
|
97
|
-
if (kind === "desktop")
|
|
98
|
-
return mode === "disk" && provider.mounts.includes("archil") && !archilImageHere(provider) && provider.capabilities.some((one) => one.kind === "desktop" && one.groups.includes("files") && one.groups.includes("exec")) ? mode2ArchilWhy(provider.label, "desktop", provider.imageEnv) : undefined;
|
|
99
93
|
if (kind !== "sandbox")
|
|
100
94
|
return undefined;
|
|
101
95
|
if (mode === "local" && !provider.mounts.includes("bind"))
|
|
102
96
|
return `${provider.label} can't mount this server's run folders (they are on its own disk): set this agent's computer to sandbox on Docker, or none (Settings → Computers)`;
|
|
103
|
-
if (mode === "disk" &&
|
|
104
|
-
const why = provider.unmounted?.archil;
|
|
97
|
+
if (mode === "disk" && folderKindOf(provider, 2) === undefined) {
|
|
98
|
+
const why = [provider.unmounted?.archil, provider.unmounted?.sync].filter((one) => one !== undefined).join("; ");
|
|
105
99
|
return `${provider.label} can't mount the owner's disk this server keeps run folders on${why ? ` (${why})` : ""}: set this agent's computer to a sandbox that mounts it, or none (Settings → Computers)`;
|
|
106
100
|
}
|
|
107
|
-
return
|
|
101
|
+
return undefined;
|
|
108
102
|
}
|
|
109
103
|
/** The GPUs a sandbox of `provider` gives, as its configuration that serves a sandbox declares them, or undefined. */
|
|
110
104
|
const sandboxGpu = (kinds, provider) => provider.capabilities.find((one) => one.gpu !== undefined && kinds.servingRefusals(one, "sandbox").length === 0)?.gpu;
|
|
111
|
-
/** The mount a sandbox takes in `mode
|
|
112
|
-
|
|
105
|
+
/** The mount a GPU sandbox of `provider` takes in `mode` for the run's folder (resolve-computer.ts folderKindOf, with
|
|
106
|
+
* what its GPU computers take): a bind of this machine, the owner's Archil disk or a synced folder. */
|
|
107
|
+
const folderMount = (provider, gpu, mode) => ({ kind: folderKindOf(provider, mode === "local" ? 1 : 2, gpu?.mounts) ?? (mode === "local" ? "bind" : "archil") });
|
|
113
108
|
/** A sandbox provider's GPUs as Settings shows them, with why a run here cannot have them (gpuRefused's words for its
|
|
114
109
|
* smallest ask, one of its first type, with this mode's mount). Its reason for taking no mount is in `why`, not a
|
|
115
110
|
* field of its own. */
|
|
116
|
-
function gpuView(gpu,
|
|
117
|
-
const
|
|
111
|
+
function gpuView(gpu, provider, mode) {
|
|
112
|
+
const label = provider.label;
|
|
113
|
+
const refused = gpu.types.length ? gpuRefused({ type: gpu.types[0], count: 1 }, gpu, folderMount(provider, gpu, mode), label) : undefined;
|
|
118
114
|
const shown = structuredClone(gpu);
|
|
119
115
|
delete shown.unmounted;
|
|
120
116
|
return { ...shown, ...(refused ? { why: refused.words } : {}) };
|
|
@@ -125,7 +121,8 @@ function gpuRefusal(kinds, computer, provider, mode) {
|
|
|
125
121
|
const asked = gpuOf(computer);
|
|
126
122
|
if (!asked)
|
|
127
123
|
return undefined;
|
|
128
|
-
const
|
|
124
|
+
const gpu = sandboxGpu(kinds, provider);
|
|
125
|
+
const refused = gpuRefused(asked, gpu, folderMount(provider, gpu, mode), provider.label);
|
|
129
126
|
if (!refused)
|
|
130
127
|
return undefined;
|
|
131
128
|
return refused.folder ? `${refused.words} (Settings → Computers)` : `${provider.label} can't give this agent's computer its GPUs: ${refused.words} (Settings → Computers)`;
|
|
@@ -144,6 +141,12 @@ export function createComputerRoutes(options) {
|
|
|
144
141
|
const providerOf = (id) => kinds.PROVIDERS.find((one) => one.id === id);
|
|
145
142
|
const hostOf = (provider) => (Object.hasOwn(hostWhy, provider.id) ? hostWhy[provider.id] : undefined);
|
|
146
143
|
const modeNow = async () => (typeof options.mode === "function" ? options.mode() : options.mode);
|
|
144
|
+
/** Why no run here can use `provider`'s computers, on a server whose runner runs in a process of its own: its machines
|
|
145
|
+
* dial this server (connectOf, with the connect its settings give), or it is a paired computer (`paired`), so the
|
|
146
|
+
* server's attach hub takes its socket, which the runner never reaches. A dial provider's machine reaches a runner
|
|
147
|
+
* that relays its dials (`relayed`, read by relaysNow), so it is null there. Null where its runs can use it. */
|
|
148
|
+
const runsRefused = (provider, relays, paired = false) => options.runnerApart !== true ? null : paired ? RUNNER_APART_WORDS : !relays && connectOf(provider, settingOptions(provider.id, settings, keyTable)) === "dial" ? dialApartWords(provider.label) : null;
|
|
149
|
+
const relaysNow = async () => options.runnerApart === true && options.relayed !== undefined && (await options.relayed());
|
|
147
150
|
/** Why a computer of `kind` on `provider` can't be had for its daemon (a provider that binds a folder of this machine,
|
|
148
151
|
* `said` its answer, in folder `mode`): none answering is the one wording (docker-daemon.ts noDockerWords); else its
|
|
149
152
|
* reason. */
|
|
@@ -157,13 +160,16 @@ export function createComputerRoutes(options) {
|
|
|
157
160
|
const listed = withPaired(options.kinds, rows);
|
|
158
161
|
const paired = rows.map((row) => options.paired.viewOf(row, listed.PROVIDERS.find((provider) => provider.id === row.id)?.kinds ?? []));
|
|
159
162
|
const offline = new Map(rows.flatMap((row, at) => (paired[at].online ? [] : [[row.id, `${row.name} is not attached now: open its driver on that computer, which dials this server`]])));
|
|
163
|
+
const pairedIds = new Set(rows.map((row) => row.id));
|
|
164
|
+
const relays = await relaysNow();
|
|
160
165
|
// Every provider's keys in one read: each a SecretMeta named for its provider, set by the environment or the store row
|
|
161
166
|
// of its key's name.
|
|
162
167
|
const slots = listed.PROVIDERS.flatMap((provider) => provider.keys.map((key) => ({ secret: secretName("computer", provider.id, key.name), env: key.name, row: key.name })));
|
|
163
168
|
const metas = new Map((await keyMetaOf(store, slots, env)).map((meta) => [meta.name, meta]));
|
|
164
169
|
const saved = new Set(slots.filter((slot) => metas.get(slot.secret).set).map((slot) => slot.env));
|
|
165
|
-
// Each provider as this server has it: the mounts its saved keys turn on,
|
|
166
|
-
|
|
170
|
+
// Each provider as this server has it: the mounts its saved keys turn on, whether this server names its image, and no
|
|
171
|
+
// Archil mount where its settings make its machines dial this server.
|
|
172
|
+
const kinds = { ...listed, PROVIDERS: listed.PROVIDERS.map((provider) => entryHere(provider, (name) => saved.has(name) || envValue(env, name) !== undefined, settingOptions(provider.id, settings, keyTable))) };
|
|
167
173
|
const choice = (setting) => shellChoiceOf(setting, mode === "disk" ? 2 : 1, kinds);
|
|
168
174
|
// Under this server's AGENTRUN_BOX_ALLOW none, a computer that needs a network is refused at a
|
|
169
175
|
// run's start and its claim (resolve-computer.ts noNetworkRefusal), so it is never ready here, whatever its keys.
|
|
@@ -190,7 +196,7 @@ export function createComputerRoutes(options) {
|
|
|
190
196
|
const keptImages = images.filter((image) => keeping.some((one) => (one.image ?? provider.defaultImage?.[kind]) === image));
|
|
191
197
|
const persistent = keeping.length === 0 ? undefined : images.length > 0 ? { images: keptImages } : {};
|
|
192
198
|
const picked = provider.keys.filter((key) => key.picked).map((key) => secretName("computer", provider.id, key.name));
|
|
193
|
-
return { id: provider.id, name: provider.label, metered: provider.metered, secrets: provider.keys.map((key) => metas.get(secretName("computer", provider.id, key.name))), required: provider.keys.filter((key) => key.required).map((key) => secretName("computer", provider.id, key.name)), ...(picked.length > 0 ? { picked } : {}), ready: why === undefined, ...(why ? { why } : {}), ...(network ? { network } : {}), ...(images.length > 0 ? { images } : {}), ...(persistent ? { persistent } : {}), ...(gpu ? { gpu: gpuView(gpu, provider
|
|
199
|
+
return { id: provider.id, name: provider.label, metered: provider.metered, secrets: provider.keys.map((key) => metas.get(secretName("computer", provider.id, key.name))), required: provider.keys.filter((key) => key.required).map((key) => secretName("computer", provider.id, key.name)), ...(picked.length > 0 ? { picked } : {}), ready: why === undefined, ...(why ? { why } : {}), runs_refused: runsRefused(provider, relays, pairedIds.has(provider.id)), ...(network ? { network } : {}), ...(images.length > 0 ? { images } : {}), ...(persistent ? { persistent } : {}), ...(gpu ? { gpu: gpuView(gpu, provider, mode) } : {}), ...choice({ kind, provider: provider.id }) };
|
|
194
200
|
});
|
|
195
201
|
const offered = kind === "none" || serving.some((provider) => unusable(kind, provider) === undefined);
|
|
196
202
|
const why = offered ? undefined
|
|
@@ -242,6 +248,11 @@ export function createComputerRoutes(options) {
|
|
|
242
248
|
const provider = providerOf(providerId);
|
|
243
249
|
if (!provider)
|
|
244
250
|
return undefined;
|
|
251
|
+
// A dial provider on a server whose runner runs apart: its account would pass here, in the server's process, while
|
|
252
|
+
// every run's create refuses at the runner. No key fixes that, so it is said first, with no vendor call.
|
|
253
|
+
const apart = runsRefused(provider, await relaysNow());
|
|
254
|
+
if (apart)
|
|
255
|
+
return { ok: false, why: apart };
|
|
245
256
|
const keys = await keysOf(provider);
|
|
246
257
|
const missing = missingKeys(provider, new Set(Object.keys(keys)));
|
|
247
258
|
if (missing.length)
|
|
@@ -290,7 +301,7 @@ export function createComputerRoutes(options) {
|
|
|
290
301
|
return `this agent's computer names the provider ${computer.provider}, which this server does not have: set its computer in Settings → Computers`;
|
|
291
302
|
// The keys set here, saved or the environment's: what the provider is made with, and what turns its mounts on.
|
|
292
303
|
const set = new Set([...(await sealedKeyNames(store)), ...listed.keys.filter((key) => envValue(env, key.name) !== undefined).map((key) => key.name)]);
|
|
293
|
-
const provider = entryHere(listed, (name) => set.has(name) || envValue(env, name) !== undefined);
|
|
304
|
+
const provider = entryHere(listed, (name) => set.has(name) || envValue(env, name) !== undefined, settingOptions(listed.id, settings, keyTable));
|
|
294
305
|
if (!provider.kinds.includes(computer.kind)) {
|
|
295
306
|
const words = [...new Set(provider.capabilities.flatMap((capabilities) => kinds.servingRefusals(capabilities, computer.kind)))];
|
|
296
307
|
return `${provider.label} does not serve a ${computer.kind} computer${words.length ? ` (${words.join("; ")})` : ""}: set this agent's computer to one it serves (Settings → Computers)`;
|