@parcha/agentrun-serve 0.1.0-beta.40 → 0.1.0-beta.42
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 +130 -0
- package/NOTICE +2 -0
- package/README.md +149 -21
- package/dist/agent-rows.d.ts +1 -1
- package/dist/agents-store.js +3 -1
- package/dist/api-only.d.ts +3 -1
- package/dist/api-only.js +4 -2
- package/dist/api-token.d.ts +30 -0
- package/dist/api-token.js +89 -0
- package/dist/calendar/address.d.ts +49 -0
- package/dist/calendar/address.js +153 -0
- package/dist/calendar/fetch.d.ts +24 -0
- package/dist/calendar/fetch.js +146 -0
- package/dist/calendar/ics-faux.d.ts +39 -0
- package/dist/calendar/ics-faux.js +236 -0
- package/dist/calendar/labels.d.ts +3 -0
- package/dist/calendar/labels.js +61 -0
- package/dist/calendar/names.d.ts +52 -0
- package/dist/calendar/names.js +54 -0
- package/dist/calendar/parse.d.ts +108 -0
- package/dist/calendar/parse.js +625 -0
- package/dist/calendar/routes.d.ts +17 -0
- package/dist/calendar/routes.js +81 -0
- package/dist/calendar/tools.d.ts +23 -0
- package/dist/calendar/tools.js +124 -0
- package/dist/cli.js +22 -6
- package/dist/composio-made.d.ts +54 -0
- package/dist/composio-made.js +83 -0
- package/dist/composio-preset.d.ts +16 -8
- package/dist/composio-preset.js +106 -43
- package/dist/composio-triggers.d.ts +7 -2
- package/dist/composio-triggers.js +13 -7
- package/dist/computer-attach.d.ts +29 -11
- package/dist/computer-attach.js +141 -47
- package/dist/computer-keys.d.ts +4 -0
- package/dist/computer-keys.js +5 -0
- package/dist/computer-record.d.ts +55 -0
- package/dist/computer-record.js +315 -0
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +15 -2
- package/dist/computers.d.ts +11 -1
- package/dist/computers.js +23 -26
- package/dist/console/assets/{index-B8Zn1Iqn.css → index-C3gNPz58.css} +1 -1
- package/dist/console/assets/index-DYJ_wj27.js +711 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.js +9 -2
- package/dist/eval-feed.d.ts +26 -0
- package/dist/eval-feed.js +72 -0
- package/dist/eval-mailbox.d.ts +4 -1
- package/dist/eval-mailbox.js +11 -3
- package/dist/exa-keyless.d.ts +1 -1
- package/dist/exa-keyless.js +1 -1
- package/dist/feed/feed-faux.d.ts +62 -0
- package/dist/feed/feed-faux.js +123 -0
- package/dist/feed/fetch.d.ts +41 -0
- package/dist/feed/fetch.js +128 -0
- package/dist/feed/parse.d.ts +42 -0
- package/dist/feed/parse.js +291 -0
- package/dist/feed/pointer.d.ts +2 -0
- package/dist/feed/pointer.js +17 -0
- package/dist/file-types.js +1 -0
- package/dist/host-command.d.ts +3 -0
- package/dist/host-command.js +18 -0
- package/dist/host.d.ts +3 -0
- package/dist/host.js +3 -0
- package/dist/learn/check.d.ts +17 -1
- package/dist/learn/check.js +240 -5
- package/dist/learn/compile.d.ts +48 -27
- package/dist/learn/compile.js +134 -101
- package/dist/learn/promote.d.ts +61 -5
- package/dist/learn/promote.js +12 -2
- package/dist/learned-nodes.d.ts +21 -4
- package/dist/learned-nodes.js +21 -8
- package/dist/learned-workflow.d.ts +3 -3
- package/dist/learned-workflow.js +14 -5
- package/dist/learning-setting.d.ts +23 -0
- package/dist/learning-setting.js +51 -0
- package/dist/learning-words.d.ts +3 -0
- package/dist/learning-words.js +3 -0
- package/dist/learning.d.ts +3 -2
- package/dist/learning.js +5 -3
- package/dist/mcp-oauth.d.ts +23 -1
- package/dist/mcp-oauth.js +46 -5
- package/dist/mcp-pin-first.d.ts +4 -2
- package/dist/mcp-pin-first.js +4 -3
- package/dist/mcp-private-hosts.d.ts +13 -0
- package/dist/mcp-private-hosts.js +16 -0
- package/dist/mcp-servers-store.d.ts +58 -5
- package/dist/mcp-servers-store.js +136 -17
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +2 -2
- package/dist/observation/http.d.ts +4 -1
- package/dist/observation/http.js +5 -4
- package/dist/openapi.d.ts +1 -0
- package/dist/openapi.js +151 -21
- package/dist/print.d.ts +6 -3
- package/dist/print.js +4 -2
- package/dist/run-files.d.ts +6 -2
- package/dist/run-files.js +29 -7
- package/dist/run-labels.d.ts +23 -0
- package/dist/run-labels.js +79 -0
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-reads-over-store.d.ts +5 -1
- package/dist/run-reads-over-store.js +8 -4
- package/dist/run-recordings.d.ts +20 -0
- package/dist/run-recordings.js +133 -0
- package/dist/run-secrets.js +12 -4
- package/dist/runner/adapter-loop.d.ts +1 -1
- package/dist/runner/adapter-loop.js +94 -16
- package/dist/runner/adapter-run-spec.d.ts +19 -0
- package/dist/runner/adapter-run-spec.js +57 -36
- package/dist/runner/beside.d.ts +6 -3
- package/dist/runner/beside.js +9 -7
- package/dist/runner/cli-run-spec.js +41 -32
- package/dist/runner/conformance/harness.js +69 -14
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/feedback-round.d.ts +9 -25
- package/dist/runner/feedback-round.js +22 -40
- package/dist/runner/learning-end.d.ts +17 -7
- package/dist/runner/learning-end.js +79 -53
- package/dist/runner/main.d.ts +12 -1
- package/dist/runner/main.js +31 -4
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +1 -1
- package/dist/runner/mcp-run.d.ts +6 -2
- package/dist/runner/mcp-run.js +5 -3
- package/dist/runner/model-route.d.ts +4 -2
- package/dist/runner/model-route.js +8 -8
- package/dist/runner/promotion.d.ts +44 -4
- package/dist/runner/promotion.js +323 -21
- package/dist/runner/reflect-hook.d.ts +5 -0
- package/dist/runner/reflect-hook.js +22 -14
- package/dist/runner/store-secrets.js +3 -1
- package/dist/runner/workflow-first.d.ts +6 -11
- package/dist/runner/workflow-first.js +16 -20
- package/dist/runs-over-store.d.ts +1 -1
- package/dist/runs-over-store.js +5 -2
- package/dist/sdk/runs.d.ts +7 -1
- package/dist/sdk/runs.js +21 -7
- package/dist/secret-cut.js +3 -1
- package/dist/secrets.js +5 -3
- package/dist/server.d.ts +31 -5
- package/dist/server.js +240 -61
- package/dist/store/agent-body.d.ts +5 -3
- package/dist/store/agent-body.js +14 -10
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/postgres/dialect.js +1 -0
- package/dist/store/postgres/migrations/0015_run_labels.sql +5 -0
- package/dist/store/postgres/migrations/0016_minted_tokens.sql +21 -0
- package/dist/store/schema.d.ts +9 -0
- package/dist/store/schema.js +26 -2
- package/dist/store/sqlite/connection.js +11 -3
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +3 -2
- package/dist/store/sqlite/store.js +64 -10
- package/dist/store/store.d.ts +38 -1
- package/dist/store-reads/journal.js +2 -1
- package/dist/store-reads/learning.d.ts +1 -1
- package/dist/store-reads/learning.js +6 -1
- package/dist/store-reads/loop.d.ts +1 -0
- package/dist/store-reads/loop.js +14 -4
- package/dist/store-reads/runs.d.ts +4 -3
- package/dist/store-reads/runs.js +3 -2
- package/dist/store-view.d.ts +5 -0
- package/dist/store-view.js +8 -2
- package/dist/template-eval.d.ts +11 -0
- package/dist/template-eval.js +177 -52
- package/dist/templates.d.ts +13 -1
- package/dist/templates.js +89 -18
- package/dist/timeline/computer.js +2 -1
- package/dist/timeline/origin.d.ts +1 -1
- package/dist/timeline/origin.js +2 -2
- package/dist/tool-list.js +1 -0
- package/dist/tools.d.ts +7 -0
- package/dist/tools.js +11 -0
- package/dist/trigger-adapter.d.ts +9 -4
- package/dist/trigger-adapters.js +2 -1
- package/dist/trigger-feed.d.ts +12 -0
- package/dist/trigger-feed.js +420 -0
- package/dist/triggers.d.ts +2 -1
- package/dist/triggers.js +23 -5
- package/dist/validate.js +7 -2
- package/dist/webhooks.js +9 -5
- package/dist/workspace/computer-deps.d.ts +5 -1
- package/dist/workspace/computer-deps.js +2 -2
- package/dist/workspace/computer-for-claim.d.ts +7 -0
- package/dist/workspace/computer-for-claim.js +12 -2
- package/dist/workspace/index.d.ts +1 -0
- package/dist/workspace/index.js +2 -0
- package/dist/workspace/paths.d.ts +4 -0
- package/dist/workspace/paths.js +9 -0
- package/dist/workspace/resolve-computer.d.ts +35 -4
- package/dist/workspace/resolve-computer.js +47 -9
- package/launcher/agentrun-serve +34 -22
- package/package.json +11 -9
- package/templates/README.md +38 -4
- package/dist/console/assets/index-Jbxjcmdp.js +0 -705
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
// A run's video of its desktop's or phone's screen, where the agent's setting asks for one (computer.record: true,
|
|
2
|
+
// computer-setting.ts). The claim (workspace/computer-for-claim.ts) starts it once the computer is attached, beside the
|
|
3
|
+
// live view, and stops it at the computer's release, the run's end or its park.
|
|
4
|
+
//
|
|
5
|
+
// 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
|
+
// 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. Frames go to one ffmpeg per recorded computer, piped in (image2pipe), each stamped as ffmpeg reads it, so the
|
|
8
|
+
// video's frame rate is the screen's own (a screen that does not change adds nothing). At most RECORDING_LIMITS.fps frames
|
|
9
|
+
// a second are written: one that comes sooner waits in a one-frame slot, and a newer one replaces it (thinned). While
|
|
10
|
+
// ffmpeg has not taken the frame before, a newer one replaces the one waiting too (dropped): the encoder falling behind
|
|
11
|
+
// costs frames, never a wait. Both are counted, in the server's log at the recording's end. The long side is
|
|
12
|
+
// RECORDING_LIMITS.edge pixels at most, no audio.
|
|
13
|
+
//
|
|
14
|
+
// The file is fragmented MP4 (H.264), so whatever ends the recording (a crash included) leaves a file that plays up to its
|
|
15
|
+
// last fragment: recordings/<computer>.mp4 in the run's recordings folder (workspace/paths.ts recordingsFolder), beside
|
|
16
|
+
// work/ and never in it. A frame of another image format than the file's (a phone's PNG frames, then JPEG ones) ends that
|
|
17
|
+
// file and goes on in the next, <computer>-2.mp4, since one ffmpeg reads one format; a resumed run's claim starts the
|
|
18
|
+
// next file too. A frame of another size is fitted into the file's own (scaled and padded).
|
|
19
|
+
//
|
|
20
|
+
// Its caps stop it: RECORDING_LIMITS.maxBytes across the run's files (a recording after a park counts the files before
|
|
21
|
+
// it, read from the folder, so a run past it records no more) and maxMs of one recording (from its first frame to its
|
|
22
|
+
// stop or its park). So do ffmpeg ending by itself (a crash, a full disk) and the screen's watch ending past
|
|
23
|
+
// RECORDING_LIMITS.rewatches tries: each says so on the run's timeline, in words. The run itself never fails because of
|
|
24
|
+
// the recorder.
|
|
25
|
+
import { spawn } from "node:child_process";
|
|
26
|
+
import { mkdir, readdir, stat } from "node:fs/promises";
|
|
27
|
+
import { join } from "node:path";
|
|
28
|
+
import { commandOnPath } from "./host-command.js";
|
|
29
|
+
/** The program that encodes the video. */
|
|
30
|
+
export const FFMPEG = "ffmpeg";
|
|
31
|
+
/** The recorder's bounds: frames a second at most; the long side in pixels at most; the caps, in bytes across the run's
|
|
32
|
+
* files and in ms of one recording; how often the caps are checked; how long ffmpeg is given to finish its file once its input ends;
|
|
33
|
+
* how many times in a row a watch that ended is opened again, and after how long. */
|
|
34
|
+
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
|
+
/** Why this server cannot record a screen, in words, or undefined: ffmpeg is on `path` (the server's PATH, read now). */
|
|
36
|
+
export const recorderMissing = (path = process.env.PATH) => commandOnPath(FFMPEG, path) ? undefined : "ffmpeg isn't installed on this server (no ffmpeg command on PATH)";
|
|
37
|
+
/** 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
|
+
const fileName = (tag, n) => `${tag.replace(/[^A-Za-z0-9._-]/g, "_")}${n === 1 ? "" : `-${n}`}.mp4`;
|
|
39
|
+
/** A frame's size fitted to `edge` on its long side, each side even (H.264's 4:2:0 needs it). */
|
|
40
|
+
const fitted = (width, height, edge) => {
|
|
41
|
+
const scale = Math.min(1, edge / Math.max(width, height, 1));
|
|
42
|
+
const even = (side) => Math.max(2, 2 * Math.round((side * scale) / 2));
|
|
43
|
+
return [even(width), even(height)];
|
|
44
|
+
};
|
|
45
|
+
/** ffmpeg's arguments for one file: `format` frames piped in, each stamped as it is read (in ms), fitted into
|
|
46
|
+
* width x height, H.264 at the frames' own times, a key frame every 2 s at most apart, fragmented MP4. The file is on disk
|
|
47
|
+
* as it goes, a fragment at each key frame (run-recordings.ts reads it mid-run): the input is not probed (a quiet screen's
|
|
48
|
+
* few frames would never fill ffmpeg's 5 MB probe), it is decoded on one thread (the PNG decoder's frame threads hold one
|
|
49
|
+
* frame per core back), and each fragment is flushed as it is written. */
|
|
50
|
+
const argsOf = (format, width, height, path) => [
|
|
51
|
+
"-hide_banner", "-loglevel", "error", "-nostats",
|
|
52
|
+
"-probesize", "32", "-analyzeduration", "0", "-fpsprobesize", "0", "-threads", "1", "-use_wallclock_as_timestamps", "1", "-framerate", "1000", "-f", "image2pipe", "-c:v", format === "png" ? "png" : "mjpeg", "-i", "pipe:0",
|
|
53
|
+
"-an", "-vf", `scale=${width}:${height}:force_original_aspect_ratio=decrease,pad=${width}:${height}:(ow-iw)/2:(oh-ih)/2,format=yuv420p`,
|
|
54
|
+
"-fps_mode", "vfr", "-c:v", "libx264", "-preset", "veryfast", "-tune", "zerolatency", "-crf", "28",
|
|
55
|
+
"-force_key_frames", "expr:gte(t,n_forced*2)", "-movflags", "+frag_keyframe+empty_moov+default_base_moof", "-flush_packets", "1", "-f", "mp4", "-n", path,
|
|
56
|
+
];
|
|
57
|
+
/** A length in words: "2 h", "90 min", "45 s". */
|
|
58
|
+
const lengthWords = (ms) => (ms >= 3_600_000 && ms % 3_600_000 === 0 ? `${ms / 3_600_000} h` : ms >= 60_000 && ms % 60_000 === 0 ? `${ms / 60_000} min` : `${Math.round(ms / 1000)} s`);
|
|
59
|
+
/** A size in words: "500 MB". */
|
|
60
|
+
const sizeWords = (bytes) => (bytes >= 1024 * 1024 ? `${Math.round(bytes / (1024 * 1024))} MB` : `${bytes} bytes`);
|
|
61
|
+
/** Starts recording the computer's screen (see the top of this file). It never throws: whatever goes wrong ends the
|
|
62
|
+
* recording with a line on the timeline. */
|
|
63
|
+
export function startRecording(input) {
|
|
64
|
+
const limits = { ...RECORDING_LIMITS, ...input.limits };
|
|
65
|
+
const log = input.log ?? ((line) => void process.stderr.write(`agentrun-serve: ${line}\n`));
|
|
66
|
+
const what = `the ${input.kind}`;
|
|
67
|
+
const say = (words) => {
|
|
68
|
+
try {
|
|
69
|
+
input.say(words);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// The timeline's own failure is not the recording's.
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const gap = 1000 / limits.fps;
|
|
76
|
+
const abort = new AbortController();
|
|
77
|
+
const files = [];
|
|
78
|
+
let watch;
|
|
79
|
+
let part;
|
|
80
|
+
/** The newest switch of files (switchPart): bounded, and awaited by the recording's end. */
|
|
81
|
+
let switching;
|
|
82
|
+
/** The newest frame not written yet, and the newest written. */
|
|
83
|
+
let slot;
|
|
84
|
+
let last;
|
|
85
|
+
/** A frame is being written, or a file opened. */
|
|
86
|
+
let busy = false;
|
|
87
|
+
let wroteAt = Number.NEGATIVE_INFINITY;
|
|
88
|
+
let firstAt;
|
|
89
|
+
let pacer;
|
|
90
|
+
/** The bytes of the files finished before this one. */
|
|
91
|
+
let doneBytes = 0;
|
|
92
|
+
let written = 0;
|
|
93
|
+
let dropped = 0;
|
|
94
|
+
let thinned = 0;
|
|
95
|
+
/** Watches ended in a row with no frame between. */
|
|
96
|
+
let misses = 0;
|
|
97
|
+
/** Set once the recording ends: why, in words, or "" when it was stopped. */
|
|
98
|
+
let over;
|
|
99
|
+
let finished;
|
|
100
|
+
/** Whether ffmpeg took the bytes. */
|
|
101
|
+
const write = (into, bytes) => new Promise((resolve) => {
|
|
102
|
+
if (into.dead || into.ending || !into.child.stdin.writable)
|
|
103
|
+
return resolve(false);
|
|
104
|
+
// The callback comes once ffmpeg's pipe took the bytes, or with the pipe's error: a busy ffmpeg holds it back.
|
|
105
|
+
into.child.stdin.write(bytes, (error) => resolve(!error));
|
|
106
|
+
});
|
|
107
|
+
/** Ends a file: `tail` (the newest frame once more) written, ffmpeg's input closed and its file finished, all within
|
|
108
|
+
* one settleMs deadline, past which ffmpeg is killed: an ffmpeg that stopped reading never holds up the release. */
|
|
109
|
+
const endPart = async (ended, tail) => {
|
|
110
|
+
const deadline = new Promise((resolve) => setTimeout(() => resolve(true), limits.settleMs).unref());
|
|
111
|
+
if (tail)
|
|
112
|
+
await Promise.race([write(ended, tail), deadline]);
|
|
113
|
+
ended.ending = true;
|
|
114
|
+
ended.child.stdin.end();
|
|
115
|
+
const late = await Promise.race([ended.exited.then(() => false), deadline]);
|
|
116
|
+
if (late) {
|
|
117
|
+
log(`ffmpeg did not finish ${ended.name} within ${limits.settleMs} ms; it was killed`);
|
|
118
|
+
ended.child.kill("SIGKILL");
|
|
119
|
+
await ended.exited;
|
|
120
|
+
}
|
|
121
|
+
doneBytes += await stat(ended.path).then((file) => file.size, () => 0);
|
|
122
|
+
};
|
|
123
|
+
/** A file for `frame`'s format: its folder made, its name the first of the series not taken, its ffmpeg started. */
|
|
124
|
+
const openPart = async (frame, before) => {
|
|
125
|
+
let path;
|
|
126
|
+
let name;
|
|
127
|
+
try {
|
|
128
|
+
await mkdir(input.folder, { recursive: true, mode: 0o700 });
|
|
129
|
+
const listed = await readdir(input.folder);
|
|
130
|
+
const taken = new Set(listed);
|
|
131
|
+
// The byte cap is the run's: its first file here counts the files of the run's earlier recordings (a park's).
|
|
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
|
+
}
|
|
136
|
+
let n = 1;
|
|
137
|
+
while (taken.has(fileName(input.tag, n)))
|
|
138
|
+
n += 1;
|
|
139
|
+
name = `recordings/${fileName(input.tag, n)}`;
|
|
140
|
+
path = join(input.folder, fileName(input.tag, n));
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
void finish(`its folder could not be made (${error.code ?? "an error"})`);
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
if (doneBytes >= limits.maxBytes) {
|
|
147
|
+
void finish(`it reached its cap of ${sizeWords(limits.maxBytes)}`);
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
const [width, height] = fitted(frame.frameWidth, frame.frameHeight, limits.edge);
|
|
151
|
+
const child = spawn(input.ffmpeg ?? FFMPEG, argsOf(frame.format, width, height, path), { stdio: ["pipe", "ignore", "pipe"] });
|
|
152
|
+
let exited;
|
|
153
|
+
const opened = { child, format: frame.format, name, path, exited: new Promise((resolve) => (exited = resolve)), dead: false, ending: false, stderr: "" };
|
|
154
|
+
/** Set when ffmpeg did not start (its 'error' comes before any 'close'). */
|
|
155
|
+
let unstarted;
|
|
156
|
+
child.stdin.on("error", () => undefined);
|
|
157
|
+
child.stderr.on("data", (chunk) => void (opened.stderr = (opened.stderr + chunk.toString("utf8")).slice(-2048)));
|
|
158
|
+
child.once("close", (code, signal) => {
|
|
159
|
+
opened.dead = true;
|
|
160
|
+
exited();
|
|
161
|
+
if (opened.ending || unstarted)
|
|
162
|
+
return;
|
|
163
|
+
const why = /no space left on device/i.test(opened.stderr) ? "the disk is full" : `ffmpeg stopped (${signal ? `signal ${signal}` : `exit code ${code}`})`;
|
|
164
|
+
log(`ffmpeg stopped recording ${opened.name}: ${opened.stderr.trim().split("\n").at(-1) ?? ""}`);
|
|
165
|
+
void finish(why);
|
|
166
|
+
});
|
|
167
|
+
unstarted = await new Promise((resolve) => {
|
|
168
|
+
child.once("spawn", () => resolve(undefined));
|
|
169
|
+
child.once("error", (error) => resolve(error));
|
|
170
|
+
});
|
|
171
|
+
if (unstarted) {
|
|
172
|
+
opened.dead = true;
|
|
173
|
+
exited();
|
|
174
|
+
void finish(unstarted.code === "ENOENT" ? "ffmpeg isn't installed on this runner (no ffmpeg command on PATH)" : `ffmpeg could not start (${unstarted.code ?? unstarted.message})`);
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
files.push(name);
|
|
178
|
+
say(before ? `The ${input.kind}'s frames changed from ${before.format.toUpperCase()} to ${frame.format.toUpperCase()}: the recording goes on in ${name}.` : `Recording ${what}'s screen into ${name}.`);
|
|
179
|
+
return opened;
|
|
180
|
+
};
|
|
181
|
+
/** The file for `frame`'s format, made `part`: the one before ended (its newest frame once more, so it lasts until
|
|
182
|
+
* the change), the next opened. The end of the recording waits on it. */
|
|
183
|
+
const switchPart = async (frame) => {
|
|
184
|
+
const before = part;
|
|
185
|
+
part = undefined;
|
|
186
|
+
if (before)
|
|
187
|
+
await endPart(before, last && last.format === before.format ? last.bytes : undefined);
|
|
188
|
+
if (over !== undefined)
|
|
189
|
+
return;
|
|
190
|
+
const opened = await openPart(frame, before);
|
|
191
|
+
if (!opened)
|
|
192
|
+
return;
|
|
193
|
+
// Stopped while it opened: its file ends at once.
|
|
194
|
+
if (over !== undefined)
|
|
195
|
+
return void (await endPart(opened));
|
|
196
|
+
part = opened;
|
|
197
|
+
};
|
|
198
|
+
const put = async (frame) => {
|
|
199
|
+
if (!part || part.format !== frame.format) {
|
|
200
|
+
switching = switchPart(frame);
|
|
201
|
+
await switching;
|
|
202
|
+
if (!part)
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
wroteAt = Date.now();
|
|
206
|
+
firstAt ??= wroteAt;
|
|
207
|
+
if (!(await write(part, frame.bytes)))
|
|
208
|
+
return;
|
|
209
|
+
written += 1;
|
|
210
|
+
last = frame;
|
|
211
|
+
};
|
|
212
|
+
/** The frame waiting goes to ffmpeg, when ffmpeg is free and the frame rate's bound allows. */
|
|
213
|
+
const pump = () => {
|
|
214
|
+
if (over !== undefined || busy || !slot)
|
|
215
|
+
return;
|
|
216
|
+
const wait = wroteAt + gap - Date.now();
|
|
217
|
+
if (wait > 0) {
|
|
218
|
+
pacer ??= setTimeout(() => {
|
|
219
|
+
pacer = undefined;
|
|
220
|
+
pump();
|
|
221
|
+
}, wait).unref();
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const frame = slot;
|
|
225
|
+
slot = undefined;
|
|
226
|
+
busy = true;
|
|
227
|
+
void put(frame).finally(() => {
|
|
228
|
+
busy = false;
|
|
229
|
+
pump();
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
const onFrame = (next, ack) => {
|
|
233
|
+
// Acked at once: the watch never waits on the encoder.
|
|
234
|
+
ack();
|
|
235
|
+
if (over !== undefined)
|
|
236
|
+
return;
|
|
237
|
+
misses = 0;
|
|
238
|
+
if (slot) {
|
|
239
|
+
if (busy)
|
|
240
|
+
dropped += 1;
|
|
241
|
+
else
|
|
242
|
+
thinned += 1;
|
|
243
|
+
}
|
|
244
|
+
slot = next;
|
|
245
|
+
pump();
|
|
246
|
+
};
|
|
247
|
+
const lost = (error) => {
|
|
248
|
+
watch = undefined;
|
|
249
|
+
if (over !== undefined)
|
|
250
|
+
return;
|
|
251
|
+
log(`the ${input.kind}'s screen watch for its recording ended: ${error.code}: ${error.message}`);
|
|
252
|
+
if (error.code !== "gone" && misses < limits.rewatches) {
|
|
253
|
+
misses += 1;
|
|
254
|
+
setTimeout(() => void open(), limits.rewatchMs).unref();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
void finish(error.code === "gone" ? "the computer is gone" : "its screen stopped answering");
|
|
258
|
+
};
|
|
259
|
+
const open = async () => {
|
|
260
|
+
if (over !== undefined)
|
|
261
|
+
return;
|
|
262
|
+
const started = await input.watch({ frame: onFrame, ended: lost }, { signal: abort.signal }).catch((error) => ({ ok: false, error: { code: "unreachable", message: error?.message ?? String(error) } }));
|
|
263
|
+
if (!started.ok)
|
|
264
|
+
return lost(started.error);
|
|
265
|
+
if (over !== undefined)
|
|
266
|
+
return void (await started.value.close().catch(() => undefined));
|
|
267
|
+
watch = started.value;
|
|
268
|
+
};
|
|
269
|
+
const checker = setInterval(() => {
|
|
270
|
+
if (over !== undefined || firstAt === undefined)
|
|
271
|
+
return;
|
|
272
|
+
if (Date.now() - firstAt >= limits.maxMs)
|
|
273
|
+
return void finish(`it reached its cap of ${lengthWords(limits.maxMs)}`);
|
|
274
|
+
const current = part;
|
|
275
|
+
if (current)
|
|
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);
|
|
277
|
+
}, limits.checkMs);
|
|
278
|
+
checker.unref();
|
|
279
|
+
/** The end of the recording, once: `why` in words when it ended by itself (said on the timeline), else stopped. */
|
|
280
|
+
const finish = (why) => (finished ??= (async () => {
|
|
281
|
+
over = why ?? "";
|
|
282
|
+
clearInterval(checker);
|
|
283
|
+
if (pacer)
|
|
284
|
+
clearTimeout(pacer);
|
|
285
|
+
abort.abort();
|
|
286
|
+
const watched = watch;
|
|
287
|
+
watch = undefined;
|
|
288
|
+
const closing = watched?.close().catch(() => undefined);
|
|
289
|
+
if (why)
|
|
290
|
+
say(`The recording of ${what} stopped: ${why}.${files.length ? ` ${files.join(", ")} ${files.length === 1 ? "keeps" : "keep"} what was recorded until then.` : ""}`);
|
|
291
|
+
// A switch of files under way finishes first (the file before it ended, the next one not opened or ended at once),
|
|
292
|
+
// so the stop returns with every ffmpeg done.
|
|
293
|
+
await switching;
|
|
294
|
+
const ending = part;
|
|
295
|
+
part = undefined;
|
|
296
|
+
if (ending) {
|
|
297
|
+
// The newest frame once more, so the video lasts until now (a screen that did not change since has no frame of its
|
|
298
|
+
// own): at a stop and at a cap alike; an ffmpeg that ended takes nothing.
|
|
299
|
+
const newest = slot ?? last;
|
|
300
|
+
await endPart(ending, !busy && newest && newest.format === ending.format ? newest.bytes : undefined);
|
|
301
|
+
}
|
|
302
|
+
await closing;
|
|
303
|
+
if (files.length)
|
|
304
|
+
log(`recorded ${what}'s screen into ${files.join(", ")}: ${written} frames written, ${dropped} dropped while ffmpeg was busy, ${thinned} thinned to ${limits.fps} a second`);
|
|
305
|
+
})());
|
|
306
|
+
void open();
|
|
307
|
+
return {
|
|
308
|
+
async stop(why) {
|
|
309
|
+
if (over === undefined && why === "parked" && files.length > 0)
|
|
310
|
+
say(`The recording of ${what} pauses while the run is parked: it goes on in a new file when the run resumes.`);
|
|
311
|
+
await finish().catch(() => undefined);
|
|
312
|
+
},
|
|
313
|
+
facts: () => ({ files: [...files], written, dropped, thinned, ...(over ? { ended: over } : {}) }),
|
|
314
|
+
};
|
|
315
|
+
}
|
package/dist/computer-setting.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
// An agent's computer, its one setting for where its tools run (Settings → Computers): `computer: { kind, provider?,
|
|
2
|
-
// image?, gpu?, persistent?, surface?, exec? }` on its revision. kind is none, sandbox, desktop, phone or browser;
|
|
2
|
+
// image?, gpu?, persistent?, surface?, exec?, record? }` on its revision. kind is none, sandbox, desktop, phone or browser;
|
|
3
3
|
// provider names one of the computer providers (the computer package's kind registry), and is absent for none; image
|
|
4
4
|
// names one the provider offers for the kind, and absent is the kind's default; a sandbox's gpu is { type, count };
|
|
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
|
-
// shell and no program start on it (run-tools.ts); the owner's own computer calls keep everything.
|
|
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 phone's screen (computer-record.ts). The v2 API's `place` is this
|
|
8
9
|
// setting's view, one to one where it can say it: {mode: "runner"} is {kind: "none"}, and {mode: "sandbox", box: X} is
|
|
9
10
|
// {kind: "sandbox", provider: X}. Writing either sets both. A desktop, phone or browser computer leaves the run's folder
|
|
10
11
|
// on the runner, so its place reads runner.
|
|
11
12
|
import { configurationOf, PROVIDERS, serves } from "@parcha/agentrun-computer";
|
|
13
|
+
import { recorderMissing } from "./computer-record.js";
|
|
12
14
|
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13
15
|
/** The kinds of computer an agent can be given. */
|
|
14
16
|
export const COMPUTER_KINDS = ["none", "sandbox", "desktop", "phone", "browser"];
|
|
@@ -46,6 +48,17 @@ const OPTIONAL = {
|
|
|
46
48
|
kinds: ["desktop", "phone"],
|
|
47
49
|
check: (value, field) => (typeof value === "boolean" ? [] : [{ field, reason: "wrong_type", message: `${field} is false (the agent gets no shell and starts no program on its computer) or true (as absent)` }]),
|
|
48
50
|
},
|
|
51
|
+
// true: each run's video of the screen (computer-record.ts), made with this server's ffmpeg, so a server without one
|
|
52
|
+
// refuses it here.
|
|
53
|
+
record: {
|
|
54
|
+
kinds: ["desktop", "phone"],
|
|
55
|
+
check: (value, field) => {
|
|
56
|
+
if (typeof value !== "boolean")
|
|
57
|
+
return [{ field, reason: "wrong_type", message: `${field} is true (each run records a video of the computer's screen) or false (as absent)` }];
|
|
58
|
+
const missing = value ? recorderMissing() : undefined;
|
|
59
|
+
return missing ? [{ field, reason: "not_allowed", message: `${field} needs ffmpeg, which records the video: ${missing}`, fix: `Install ffmpeg on this server's PATH (Debian: apt install ffmpeg), or remove ${field}.` }] : [];
|
|
60
|
+
},
|
|
61
|
+
},
|
|
49
62
|
gpu: {
|
|
50
63
|
kinds: ["sandbox"],
|
|
51
64
|
check: (gpu, field) => {
|
package/dist/computers.d.ts
CHANGED
|
@@ -37,6 +37,14 @@ export interface ProviderEntry {
|
|
|
37
37
|
readonly mounts: readonly string[];
|
|
38
38
|
/** Why its computers take none of these mounts, each in one sentence (Daytona's archil), as its descriptor says. */
|
|
39
39
|
readonly unmounted?: Readonly<Partial<Record<string, string>>>;
|
|
40
|
+
/** Mounts its computers take only where the operator sets the key named, by mount (Daytona's archil, with
|
|
41
|
+
* DAYTONA_ARCHIL_EGRESS), as its descriptor says: resolve-computer.ts entryHere reads it with the keys set here. */
|
|
42
|
+
readonly mountsWith?: Readonly<Partial<Record<string, string>>>;
|
|
43
|
+
/** The server's environment variable that names the image every computer of it starts from (Daytona's
|
|
44
|
+
* AGENTRUN_DAYTONA_SNAPSHOT), as its descriptor says: set, the operator names its image here (entryHere). */
|
|
45
|
+
readonly imageEnv?: string;
|
|
46
|
+
/** Set by entryHere alone: its imageEnv has a value here. */
|
|
47
|
+
readonly imageNamed?: true;
|
|
40
48
|
/** The network forms its computers make ("none", "open", "allow"), as its descriptor declares them. Absent (a
|
|
41
49
|
* test's fixture): nothing is said of its network. */
|
|
42
50
|
readonly network?: readonly string[];
|
|
@@ -202,7 +210,9 @@ export declare const COMPUTER_UNAVAILABLE = "computer_unavailable";
|
|
|
202
210
|
* local Docker bind). A desktop, phone or browser holds no folder unless its provider mounts it, so either mode takes
|
|
203
211
|
* it. A sandbox that mounts the disk can't start yet either, nor can a desktop that would mount it (resolve-computer.ts
|
|
204
212
|
* mode2ArchilWhy), unless its provider prepares its image (prepareImage: Agent37 registers the box image, which has
|
|
205
|
-
* Archil's client, in the owner's workspace; Modal pulls it; E2B starts its public template)
|
|
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. */
|
|
206
216
|
export declare function modeRefusal(kind: ComputerKind, provider: ProviderEntry, mode: FolderMode): string | undefined;
|
|
207
217
|
/** The routes' work over the server's store: GET /v2/computers (view), PUT /v2/computers/{provider}/keys (saveKeys), POST
|
|
208
218
|
* /v2/computers/{provider}/test (test), and the claim's refusal (claimRefusal). */
|
package/dist/computers.js
CHANGED
|
@@ -7,8 +7,6 @@
|
|
|
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 { accessSync, constants, statSync } from "node:fs";
|
|
11
|
-
import { delimiter, join } from "node:path";
|
|
12
10
|
import { imagesOf } from "@parcha/agentrun-computer";
|
|
13
11
|
import { BOX_ALLOW_ENV, boxAllowOf } from "./box-settings.js";
|
|
14
12
|
import { KEY_TABLE, keyChoices, providerOptions, testConnection } from "./computer-keys.js";
|
|
@@ -16,13 +14,14 @@ import { COMPUTER_KINDS, gpuOf } from "./computer-setting.js";
|
|
|
16
14
|
import { inArchilMode } from "./archil-settings.js";
|
|
17
15
|
import { daemonUp, noDockerWords } from "./docker-daemon.js";
|
|
18
16
|
import { ApiError, invalid } from "./errors.js";
|
|
17
|
+
import { commandOnPath } from "./host-command.js";
|
|
19
18
|
import { gpuRefused } from "./gpu-words.js";
|
|
20
19
|
import { redacted } from "./key-refusal.js";
|
|
21
20
|
import { keyMetaOf, envValue } from "./key-meta.js";
|
|
22
21
|
import { registerNotSecretWrite, registerSecretWrite, secretName } from "./secret-writes.js";
|
|
23
22
|
import { getSealedKey, putSealedKey, removeSealedKey, sealedKeyNames } from "./server-keys.js";
|
|
24
23
|
import { withPaired } from "./workspace/attached-computers.js";
|
|
25
|
-
import { aLabel, mode2ArchilWhy, needsNetwork, shellChoiceOf } from "./workspace/resolve-computer.js";
|
|
24
|
+
import { aLabel, archilImageHere, entryHere, mode2ArchilWhy, needsNetwork, shellChoiceOf } from "./workspace/resolve-computer.js";
|
|
26
25
|
// Every request to a computer's keys is a secret write (secret-writes.ts), whatever its body (a value, a null, an empty
|
|
27
26
|
// body or none), as saveToolKey's is: the server's one dispatch check keeps it to the owner's session before any provider
|
|
28
27
|
// is looked up, so a token learns nothing of which providers exist. The view and the connection test write none.
|
|
@@ -45,18 +44,7 @@ export function hostCommandWhy(label, { command, from, builds }, platform = proc
|
|
|
45
44
|
* words: what Settings → Computers, a run's start and the claim say for it. A command is there when a folder of `path`
|
|
46
45
|
* holds an executable file of its name. */
|
|
47
46
|
export function hostCommandRefusals(providers, path, platform = process.platform, arch = process.arch) {
|
|
48
|
-
|
|
49
|
-
const named = (command) => (platform === "win32" ? [command, ...[".exe", ".cmd", ".bat"].map((extension) => `${command}${extension}`)] : [command]);
|
|
50
|
-
const found = (command) => (path ?? "").split(delimiter).some((folder) => folder !== "" && named(command).some((file) => {
|
|
51
|
-
try {
|
|
52
|
-
accessSync(join(folder, file), constants.X_OK);
|
|
53
|
-
return statSync(join(folder, file)).isFile();
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
}));
|
|
59
|
-
return Object.fromEntries(providers.flatMap((provider) => (provider.hostCommand && !found(provider.hostCommand.command) ? [[provider.id, hostCommandWhy(provider.label, provider.hostCommand, platform, arch)]] : [])));
|
|
47
|
+
return Object.fromEntries(providers.flatMap((provider) => (provider.hostCommand && !commandOnPath(provider.hostCommand.command, path, platform) ? [[provider.id, hostCommandWhy(provider.label, provider.hostCommand, platform, arch)]] : [])));
|
|
60
48
|
}
|
|
61
49
|
/** A computer with no network: its programs run in a network of their own, so a run's allow-list is never offered it. */
|
|
62
50
|
export const NO_NETWORK_WORDS = "no network, so this server's allow-list isn't offered";
|
|
@@ -101,11 +89,13 @@ export const COMPUTER_UNAVAILABLE = "computer_unavailable";
|
|
|
101
89
|
* local Docker bind). A desktop, phone or browser holds no folder unless its provider mounts it, so either mode takes
|
|
102
90
|
* it. A sandbox that mounts the disk can't start yet either, nor can a desktop that would mount it (resolve-computer.ts
|
|
103
91
|
* mode2ArchilWhy), unless its provider prepares its image (prepareImage: Agent37 registers the box image, which has
|
|
104
|
-
* Archil's client, in the owner's workspace; Modal pulls it; E2B starts its public template)
|
|
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. */
|
|
105
95
|
export function modeRefusal(kind, provider, mode) {
|
|
106
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.
|
|
107
97
|
if (kind === "desktop")
|
|
108
|
-
return mode === "disk" && provider.mounts.includes("archil") && !provider
|
|
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;
|
|
109
99
|
if (kind !== "sandbox")
|
|
110
100
|
return undefined;
|
|
111
101
|
if (mode === "local" && !provider.mounts.includes("bind"))
|
|
@@ -114,7 +104,7 @@ export function modeRefusal(kind, provider, mode) {
|
|
|
114
104
|
const why = provider.unmounted?.archil;
|
|
115
105
|
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)`;
|
|
116
106
|
}
|
|
117
|
-
return mode === "disk" && !provider
|
|
107
|
+
return mode === "disk" && !archilImageHere(provider) ? mode2ArchilWhy(provider.label, "sandbox", provider.imageEnv) : undefined;
|
|
118
108
|
}
|
|
119
109
|
/** The GPUs a sandbox of `provider` gives, as its configuration that serves a sandbox declares them, or undefined. */
|
|
120
110
|
const sandboxGpu = (kinds, provider) => provider.capabilities.find((one) => one.gpu !== undefined && kinds.servingRefusals(one, "sandbox").length === 0)?.gpu;
|
|
@@ -164,15 +154,17 @@ export function createComputerRoutes(options) {
|
|
|
164
154
|
const mode = await modeNow();
|
|
165
155
|
// The paired computers, each one more provider of its kind; one not attached now is not ready, saying so.
|
|
166
156
|
const rows = options.paired ? await options.paired.rows() : [];
|
|
167
|
-
const
|
|
168
|
-
const paired = rows.map((row) => options.paired.viewOf(row,
|
|
157
|
+
const listed = withPaired(options.kinds, rows);
|
|
158
|
+
const paired = rows.map((row) => options.paired.viewOf(row, listed.PROVIDERS.find((provider) => provider.id === row.id)?.kinds ?? []));
|
|
169
159
|
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`]])));
|
|
170
|
-
const choice = (setting) => shellChoiceOf(setting, mode === "disk" ? 2 : 1, kinds);
|
|
171
160
|
// Every provider's keys in one read: each a SecretMeta named for its provider, set by the environment or the store row
|
|
172
161
|
// of its key's name.
|
|
173
|
-
const slots =
|
|
162
|
+
const slots = listed.PROVIDERS.flatMap((provider) => provider.keys.map((key) => ({ secret: secretName("computer", provider.id, key.name), env: key.name, row: key.name })));
|
|
174
163
|
const metas = new Map((await keyMetaOf(store, slots, env)).map((meta) => [meta.name, meta]));
|
|
175
164
|
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, and whether this server names its image.
|
|
166
|
+
const kinds = { ...listed, PROVIDERS: listed.PROVIDERS.map((provider) => entryHere(provider, (name) => saved.has(name) || envValue(env, name) !== undefined)) };
|
|
167
|
+
const choice = (setting) => shellChoiceOf(setting, mode === "disk" ? 2 : 1, kinds);
|
|
176
168
|
// Under this server's AGENTRUN_BOX_ALLOW none, a computer that needs a network is refused at a
|
|
177
169
|
// run's start and its claim (resolve-computer.ts noNetworkRefusal), so it is never ready here, whatever its keys.
|
|
178
170
|
const refusedOpen = (provider) => boxAllowOf(env) === "none" && needsNetwork(provider.network);
|
|
@@ -218,7 +210,9 @@ export function createComputerRoutes(options) {
|
|
|
218
210
|
return undefined;
|
|
219
211
|
const declared = new Set(provider.keys.map((key) => key.name));
|
|
220
212
|
const refused = Object.entries(body).flatMap(([name, value]) => !declared.has(name) ? [{ field: name, reason: "not_allowed", message: `${provider.label} takes ${[...declared].join(", ") || "no keys"}, not ${name}` }]
|
|
221
|
-
|
|
213
|
+
// Whitespace alone is no value, as in the environment (key-meta.ts envValue): saved, it would read as set here and
|
|
214
|
+
// as none where a value is read (resolve-computer.ts registryHere), so Settings would show ready what a run refuses.
|
|
215
|
+
: value !== null && (typeof value !== "string" || value.trim() === "") ? [{ field: name, reason: "wrong_type", message: `${name} is a non-empty string, or null to remove it` }] : []);
|
|
222
216
|
if (refused.length)
|
|
223
217
|
throw new KeysRefused(refused);
|
|
224
218
|
for (const [name, value] of Object.entries(body)) {
|
|
@@ -291,9 +285,12 @@ export function createComputerRoutes(options) {
|
|
|
291
285
|
async function claimRefusal(computer) {
|
|
292
286
|
if (computer.kind === "none")
|
|
293
287
|
return undefined;
|
|
294
|
-
const
|
|
295
|
-
if (!
|
|
288
|
+
const listed = providerOf(computer.provider);
|
|
289
|
+
if (!listed)
|
|
296
290
|
return `this agent's computer names the provider ${computer.provider}, which this server does not have: set its computer in Settings → Computers`;
|
|
291
|
+
// The keys set here, saved or the environment's: what the provider is made with, and what turns its mounts on.
|
|
292
|
+
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);
|
|
297
294
|
if (!provider.kinds.includes(computer.kind)) {
|
|
298
295
|
const words = [...new Set(provider.capabilities.flatMap((capabilities) => kinds.servingRefusals(capabilities, computer.kind)))];
|
|
299
296
|
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)`;
|
|
@@ -302,7 +299,7 @@ export function createComputerRoutes(options) {
|
|
|
302
299
|
const refused = modeRefusal(computer.kind, provider, mode) ?? gpuRefusal(kinds, computer, provider, mode) ?? (local(provider) ? daemonWhy(computer.kind, await answers(provider.id), mode) : undefined) ?? hostOf(provider);
|
|
303
300
|
if (refused)
|
|
304
301
|
return refused;
|
|
305
|
-
const missing = missingKeys(provider,
|
|
302
|
+
const missing = missingKeys(provider, set);
|
|
306
303
|
return missing.length ? keysWhy(provider, missing, true) : undefined;
|
|
307
304
|
}
|
|
308
305
|
/** What the claim makes a run's computer with: the options its provider's create() takes, from its saved keys and the
|