@parcha/agentrun-computer 0.1.0-beta.57 → 0.1.0-beta.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +187 -62
- package/box/Dockerfile +4 -3
- package/box/install.sh +57 -11
- package/dist/agent37.js +6 -9
- package/dist/attach.d.ts +24 -4
- package/dist/attach.js +50 -19
- package/dist/boxd.js +22 -9
- package/dist/browserbase.d.ts +6 -2
- package/dist/browserbase.js +50 -7
- package/dist/child-env.d.ts +11 -0
- package/dist/child-env.js +22 -0
- package/dist/chrome.d.ts +5 -2
- package/dist/chrome.js +5 -2
- package/dist/cloudflare.d.ts +2 -0
- package/dist/cloudflare.js +5 -3
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +1 -1
- package/dist/conformance/agent37.d.ts +10 -38
- package/dist/conformance/agent37.js +25 -113
- package/dist/conformance/archil.d.ts +13 -3
- package/dist/conformance/archil.js +22 -17
- package/dist/conformance/boxd.d.ts +8 -31
- package/dist/conformance/boxd.js +19 -74
- package/dist/conformance/browserbase.d.ts +3 -6
- package/dist/conformance/browserbase.js +6 -17
- package/dist/conformance/cases/health.js +6 -3
- package/dist/conformance/cli.d.ts +3 -1
- package/dist/conformance/cli.js +69 -9
- package/dist/conformance/cloudflare.d.ts +3 -6
- package/dist/conformance/cloudflare.js +7 -15
- package/dist/conformance/daytona.d.ts +6 -20
- package/dist/conformance/daytona.js +22 -57
- package/dist/conformance/dial-only.d.ts +4 -3
- package/dist/conformance/dial-only.js +3 -3
- package/dist/conformance/docker.d.ts +4 -5
- package/dist/conformance/docker.js +8 -14
- package/dist/conformance/e2b.d.ts +10 -36
- package/dist/conformance/e2b.js +27 -84
- package/dist/conformance/fly.d.ts +3 -6
- package/dist/conformance/fly.js +2 -6
- package/dist/conformance/groundbox.d.ts +7 -23
- package/dist/conformance/groundbox.js +16 -56
- package/dist/conformance/index.d.ts +1 -0
- package/dist/conformance/index.js +1 -0
- package/dist/conformance/kernel.d.ts +3 -6
- package/dist/conformance/kernel.js +5 -15
- package/dist/conformance/kind.d.ts +0 -6
- package/dist/conformance/kind.js +0 -4
- package/dist/conformance/local-chrome.d.ts +5 -7
- package/dist/conformance/local-chrome.js +7 -11
- package/dist/conformance/modal.d.ts +10 -38
- package/dist/conformance/modal.js +27 -74
- package/dist/conformance/module-kit.d.ts +87 -0
- package/dist/conformance/module-kit.js +88 -0
- package/dist/conformance/morph.d.ts +7 -23
- package/dist/conformance/morph.js +20 -66
- package/dist/conformance/orgo.d.ts +5 -10
- package/dist/conformance/orgo.js +15 -27
- package/dist/conformance/phone-harness.d.ts +3 -5
- package/dist/conformance/phone-harness.js +3 -11
- package/dist/conformance/runner.d.ts +13 -3
- package/dist/conformance/runner.js +32 -11
- package/dist/conformance/smolcloud.d.ts +7 -23
- package/dist/conformance/smolcloud.js +16 -49
- package/dist/conformance/sweep.d.ts +10 -5
- package/dist/conformance/sweep.js +91 -38
- package/dist/conformance/tti.d.ts +69 -0
- package/dist/conformance/tti.js +205 -0
- package/dist/conformance/types.d.ts +9 -2
- package/dist/daytona.js +60 -20
- package/dist/descriptor.d.ts +10 -0
- package/dist/descriptor.js +7 -0
- package/dist/descriptors/browserbase.d.ts +3 -0
- package/dist/descriptors/browserbase.js +4 -0
- package/dist/descriptors/docker.d.ts +1 -0
- package/dist/descriptors/docker.js +3 -0
- package/dist/descriptors/env-names.d.ts +32 -0
- package/dist/descriptors/env-names.js +60 -0
- package/dist/descriptors/index.d.ts +9 -2
- package/dist/descriptors/kernel.d.ts +3 -0
- package/dist/descriptors/kernel.js +2 -0
- package/dist/descriptors/local-chrome.d.ts +1 -1
- package/dist/descriptors/local-chrome.js +5 -3
- package/dist/descriptors/phone-harness.d.ts +1 -1
- package/dist/descriptors/phone-harness.js +4 -2
- package/dist/docker/egress.d.ts +7 -0
- package/dist/docker/egress.js +8 -0
- package/dist/docker/image.d.ts +5 -1
- package/dist/docker/image.js +12 -8
- package/dist/docker.d.ts +63 -15
- package/dist/docker.js +181 -98
- package/dist/drift.js +6 -6
- package/dist/e2b.d.ts +2 -2
- package/dist/e2b.js +2 -3
- package/dist/groundbox.js +6 -6
- package/dist/host.d.ts +23 -0
- package/dist/hosted/download.d.ts +23 -0
- package/dist/hosted/download.js +144 -0
- package/dist/hosted/process.d.ts +5 -0
- package/dist/hosted/process.js +20 -0
- package/dist/hosted/provider.js +120 -48
- package/dist/hosted/rest.d.ts +19 -8
- package/dist/hosted/rest.js +47 -14
- package/dist/hosted/scripts.d.ts +10 -0
- package/dist/hosted/scripts.js +23 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/janitor.d.ts +7 -1
- package/dist/janitor.js +2 -2
- package/dist/kernel.js +1 -1
- package/dist/local-chrome.d.ts +5 -2
- package/dist/local-chrome.js +4 -2
- package/dist/local-supervisor.js +1 -0
- package/dist/modal.d.ts +6 -5
- package/dist/modal.js +7 -7
- package/dist/morph.js +5 -8
- package/dist/orgo-channel.d.ts +3 -2
- package/dist/orgo-channel.js +3 -3
- package/dist/orgo-desktop.js +2 -4
- package/dist/orgo.js +2 -4
- package/dist/phone-harness.d.ts +7 -5
- package/dist/phone-harness.js +60 -61
- package/dist/protocol.d.ts +10 -0
- package/dist/protocol.js +17 -0
- package/dist/provider.d.ts +6 -2
- package/dist/screen-watch.d.ts +6 -1
- package/dist/screen-watch.js +166 -12
- package/dist/vendor-sdk.d.ts +9 -0
- package/dist/vendor-sdk.js +26 -0
- package/package.json +8 -1
package/dist/host.d.ts
CHANGED
|
@@ -83,6 +83,14 @@ export interface MachineHost {
|
|
|
83
83
|
* streams the file through exec's stdin as base64 text, which root decodes (`base64 -d`, in coreutils and busybox).
|
|
84
84
|
*/
|
|
85
85
|
upload?(id: string, path: string, bytes: Uint8Array, ctx: HostCall): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* The bytes of the file at path in the machine, whole, read as root. Optional, on an exec host alone: one whose exec
|
|
88
|
+
* output is slow has it (Daytona's: its toolbox's files/download, where exec's stdout is a log read at about 0.3 MB/s).
|
|
89
|
+
* A files.read past one chunk then takes its first chunk from the daemon and the rest from one copy of the file the
|
|
90
|
+
* adapter makes as the daemon's user (./hosted/download.ts), so root's read never shows what that user cannot read. A
|
|
91
|
+
* path that is not there throws.
|
|
92
|
+
*/
|
|
93
|
+
download?(id: string, path: string, ctx: HostCall): Promise<Uint8Array>;
|
|
86
94
|
/**
|
|
87
95
|
* What agentrun-dial wrote in a dial machine, for a create whose machine never dialed: the adapter adds its last lines
|
|
88
96
|
* to the timeout's words. undefined when agentrun-dial never started there. A host that started agentrun-dial itself
|
|
@@ -90,6 +98,21 @@ export interface MachineHost {
|
|
|
90
98
|
* words stay as they were.
|
|
91
99
|
*/
|
|
92
100
|
dialLog?(id: string, ctx: HostCall): Promise<string | undefined>;
|
|
101
|
+
/**
|
|
102
|
+
* agentrun-dial's exit code in a dial machine once it has exited; undefined while it runs, or where it never started.
|
|
103
|
+
* A host that started agentrun-dial itself and can read its exit has it (Daytona's: its session command's). The
|
|
104
|
+
* adapter reads it while it waits for the machine to dial: one that exited never dials, so create stops then, in
|
|
105
|
+
* dialLog's words, instead of at createMs, and while it runs and writes, the wait may go past createMs. A read that
|
|
106
|
+
* fails throws, and the wait goes on.
|
|
107
|
+
*/
|
|
108
|
+
dialExit?(id: string, ctx: HostCall): Promise<number | undefined>;
|
|
109
|
+
/**
|
|
110
|
+
* Starts agentrun-dial once more in a dial machine whose agentrun-dial exited, as create started it: the same env and
|
|
111
|
+
* token, so the same machine dials. The adapter calls it at most once per machine, for an exit that leaves nothing of
|
|
112
|
+
* agentrun-dial running (its fetch failed, 3, or its init never listened and was ended, 5); after the start, dialLog
|
|
113
|
+
* and dialExit read the new one. A start the vendor refuses throws, and create fails in the first exit's words.
|
|
114
|
+
*/
|
|
115
|
+
redial?(id: string, ctx: HostCall): Promise<void>;
|
|
93
116
|
/**
|
|
94
117
|
* The code of an error the vendor's client threw: one of ComputerErrorCode. Optional: the adapter reads a HostError's
|
|
95
118
|
* own code, an AbortError as "aborted" and a TimeoutError as "timeout" itself, and anything else a host does not map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { MachineHost } from "../host.js";
|
|
2
|
+
import type { ComputerConnection } from "../provider.js";
|
|
3
|
+
export interface DownloadBounds {
|
|
4
|
+
/** Each of read-stage and read-unstage, and the daemon's read of its own /proc/self/status. */
|
|
5
|
+
execMs: number;
|
|
6
|
+
/** The download of one copy. */
|
|
7
|
+
downloadMs: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* connection, with every files.read past one chunk read from one downloaded copy after its first chunk. A first chunk
|
|
11
|
+
* (offset 0, a whole chunk) whose file runs past it, and is at most the surface's read limit (MAX_READ_BYTES, all a copy
|
|
12
|
+
* holds in memory), makes its file one to copy; a larger file is the daemon's, chunk by chunk. The copy starts at the
|
|
13
|
+
* first read past that chunk, so a reader that stops at one chunk copies nothing. The reads after it, at the offsets the
|
|
14
|
+
* first's reader asks for, are answered from the copy, as the daemon answers (eof once a read reaches the copy's size),
|
|
15
|
+
* and the copy is let go at its end, at the next first chunk of its path, at any call of another method, which may change
|
|
16
|
+
* a file, or, the oldest first, once the files to copy pass COPIES_BYTES in all. A copy let go while it is still coming
|
|
17
|
+
* is stopped, and the reads waiting on it are the daemon's. A copy that fails at any step (the daemon's user unread,
|
|
18
|
+
* read-stage refused, the download, a size other than the daemon read) leaves the daemon to answer every read, as on a
|
|
19
|
+
* host with no download. The copy in the machine is removed once it is downloaded, without holding up the read. A close
|
|
20
|
+
* of the connection or of its client lets every copy go: each read after it, or still waiting on a copy, is the closed
|
|
21
|
+
* daemon client's (gone).
|
|
22
|
+
*/
|
|
23
|
+
export declare function downloadingConnection(host: MachineHost, download: NonNullable<MachineHost["download"]>, id: string, connection: ComputerConnection, bounds: DownloadBounds): ComputerConnection;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// A files.read past one chunk on a host with download (src/host.ts): the daemon answers the first chunk, as it answers
|
|
2
|
+
// every read, and the rest comes from one copy of the file, made as the daemon's user (read-stage) and downloaded whole.
|
|
3
|
+
// On Daytona the bridge is a session command's log, read at about 0.3 MB/s (the sandbox bench, 11-25); its toolbox's
|
|
4
|
+
// files/download is not. The daemon's read is the check: a file it refuses is never copied, and the copy, opened as its
|
|
5
|
+
// user, holds what that user can read and nothing more, whatever the path names by the time it is copied.
|
|
6
|
+
import { randomBytes } from "node:crypto";
|
|
7
|
+
import { posix } from "node:path";
|
|
8
|
+
import { MAX_CHUNK_BYTES } from "../protocol.js";
|
|
9
|
+
import { ok } from "../result.js";
|
|
10
|
+
import { MAX_READ_BYTES } from "../surface/core.js";
|
|
11
|
+
import { hostCall, runToExit, untilAborted } from "./process.js";
|
|
12
|
+
import { READ_COPIES, readStage, readUnstage } from "./scripts.js";
|
|
13
|
+
/**
|
|
14
|
+
* An absolute path as computerd's files.read opens it: cleaned first (filepath.Clean, files.go cleanPath), so a ".."
|
|
15
|
+
* takes off the name before it, a symlinked directory's or not. read-stage's cat opens the path as given, where a ".."
|
|
16
|
+
* after a link leaves the link's target: it is given this one, the file the daemon read.
|
|
17
|
+
*/
|
|
18
|
+
const cleaned = (path) => posix.resolve(path);
|
|
19
|
+
/** A read the daemon may answer from a copy: an absolute path outside /proc (whose self is the reader's), a whole chunk. */
|
|
20
|
+
const copyable = ({ path, length }) => path.startsWith("/") && !cleaned(path).startsWith("/proc/") && (length === undefined || length === MAX_CHUNK_BYTES);
|
|
21
|
+
/** The bytes one connection's copies may hold at once: two files at the read limit. */
|
|
22
|
+
const COPIES_BYTES = 2 * MAX_READ_BYTES;
|
|
23
|
+
/**
|
|
24
|
+
* connection, with every files.read past one chunk read from one downloaded copy after its first chunk. A first chunk
|
|
25
|
+
* (offset 0, a whole chunk) whose file runs past it, and is at most the surface's read limit (MAX_READ_BYTES, all a copy
|
|
26
|
+
* holds in memory), makes its file one to copy; a larger file is the daemon's, chunk by chunk. The copy starts at the
|
|
27
|
+
* first read past that chunk, so a reader that stops at one chunk copies nothing. The reads after it, at the offsets the
|
|
28
|
+
* first's reader asks for, are answered from the copy, as the daemon answers (eof once a read reaches the copy's size),
|
|
29
|
+
* and the copy is let go at its end, at the next first chunk of its path, at any call of another method, which may change
|
|
30
|
+
* a file, or, the oldest first, once the files to copy pass COPIES_BYTES in all. A copy let go while it is still coming
|
|
31
|
+
* is stopped, and the reads waiting on it are the daemon's. A copy that fails at any step (the daemon's user unread,
|
|
32
|
+
* read-stage refused, the download, a size other than the daemon read) leaves the daemon to answer every read, as on a
|
|
33
|
+
* host with no download. The copy in the machine is removed once it is downloaded, without holding up the read. A close
|
|
34
|
+
* of the connection or of its client lets every copy go: each read after it, or still waiting on a copy, is the closed
|
|
35
|
+
* daemon client's (gone).
|
|
36
|
+
*/
|
|
37
|
+
export function downloadingConnection(host, download, id, connection, bounds) {
|
|
38
|
+
const { client } = connection;
|
|
39
|
+
const copies = new Map();
|
|
40
|
+
let closed = false;
|
|
41
|
+
let user;
|
|
42
|
+
/** The daemon's uid and gid, from its own /proc/self/status: each of its four ids the same, else none. */
|
|
43
|
+
const userOf = () => (user ??= (async () => {
|
|
44
|
+
const status = await client.call("files.read", { path: "/proc/self/status" }, { signal: AbortSignal.timeout(bounds.execMs) });
|
|
45
|
+
const text = status.ok ? Buffer.from(status.value.data, "base64").toString("utf8") : "";
|
|
46
|
+
const ids = (name) => new RegExp(`^${name}:\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s*$`, "m").exec(text)?.slice(1) ?? [];
|
|
47
|
+
const [uids, gids] = [ids("Uid"), ids("Gid")];
|
|
48
|
+
const one = (found) => (found.length === 4 && found.every((each) => each === found[0]) ? found[0] : undefined);
|
|
49
|
+
const [uid, gid] = [one(uids), one(gids)];
|
|
50
|
+
if (uid !== undefined && gid !== undefined)
|
|
51
|
+
return [uid, gid];
|
|
52
|
+
user = undefined;
|
|
53
|
+
return undefined;
|
|
54
|
+
})());
|
|
55
|
+
/** path's copy, downloaded until signal aborts: its bytes when they are size long, else undefined. */
|
|
56
|
+
const copyOf = async (path, size, signal) => {
|
|
57
|
+
const who = await userOf();
|
|
58
|
+
if (who === undefined)
|
|
59
|
+
return undefined;
|
|
60
|
+
const copy = `${READ_COPIES}/${randomBytes(16).toString("hex")}`;
|
|
61
|
+
const unstage = () => void runToExit(host, id, readUnstage(copy), { ms: bounds.execMs, what: `removing the copy of ${path}` });
|
|
62
|
+
const staged = await runToExit(host, id, readStage(who[0], who[1], path, copy), { ms: bounds.execMs, signal, what: `copying ${path} as the daemon's user` });
|
|
63
|
+
if (!staged.ok || staged.value.exitCode !== 0) {
|
|
64
|
+
// One that never answered may yet write its copy.
|
|
65
|
+
if (!staged.ok)
|
|
66
|
+
unstage();
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
const got = await hostCall(host, `downloading the copy of ${path}`, (ctx) => download(id, copy, ctx), bounds.downloadMs, signal);
|
|
70
|
+
unstage();
|
|
71
|
+
return got.ok && got.value.length === size ? got.value : undefined;
|
|
72
|
+
};
|
|
73
|
+
/** key's copy let go, and stopped if it is still coming. */
|
|
74
|
+
const letGo = (key) => {
|
|
75
|
+
copies.get(key)?.stop.abort();
|
|
76
|
+
copies.delete(key);
|
|
77
|
+
};
|
|
78
|
+
const letAllGo = () => {
|
|
79
|
+
for (const key of copies.keys())
|
|
80
|
+
letGo(key);
|
|
81
|
+
};
|
|
82
|
+
const drop = () => {
|
|
83
|
+
closed = true;
|
|
84
|
+
letAllGo();
|
|
85
|
+
};
|
|
86
|
+
const reading = {
|
|
87
|
+
async call(method, params, options) {
|
|
88
|
+
if (method !== "files.read" || closed) {
|
|
89
|
+
letAllGo();
|
|
90
|
+
return client.call(method, params, options);
|
|
91
|
+
}
|
|
92
|
+
const read = params;
|
|
93
|
+
const offset = read.offset ?? 0;
|
|
94
|
+
if (offset === 0) {
|
|
95
|
+
letGo(read.path);
|
|
96
|
+
const first = await client.call(method, params, options);
|
|
97
|
+
const answer = first.ok ? first.value : undefined;
|
|
98
|
+
if (answer !== undefined && !answer.eof && answer.size > MAX_CHUNK_BYTES && answer.size <= MAX_READ_BYTES && copyable(read)) {
|
|
99
|
+
// Room for it within COPIES_BYTES: the oldest let go first.
|
|
100
|
+
let held = answer.size;
|
|
101
|
+
for (const each of copies.values())
|
|
102
|
+
held += each.size;
|
|
103
|
+
for (const [key, each] of copies) {
|
|
104
|
+
if (held <= COPIES_BYTES)
|
|
105
|
+
break;
|
|
106
|
+
held -= each.size;
|
|
107
|
+
letGo(key);
|
|
108
|
+
}
|
|
109
|
+
copies.set(read.path, { path: cleaned(read.path), size: answer.size, stop: new AbortController() });
|
|
110
|
+
}
|
|
111
|
+
return first;
|
|
112
|
+
}
|
|
113
|
+
const copy = copies.get(read.path);
|
|
114
|
+
const length = read.length ?? MAX_CHUNK_BYTES;
|
|
115
|
+
if (copy === undefined || !Number.isSafeInteger(offset) || offset < 0 || !Number.isSafeInteger(length) || length < 1 || length > MAX_CHUNK_BYTES)
|
|
116
|
+
return client.call(method, params, options);
|
|
117
|
+
copy.bytes ??= copyOf(copy.path, copy.size, copy.stop.signal);
|
|
118
|
+
const bytes = await untilAborted(copy.bytes, [options?.signal, copy.stop.signal]);
|
|
119
|
+
if (bytes === undefined) {
|
|
120
|
+
if (!options?.signal?.aborted)
|
|
121
|
+
copies.delete(read.path);
|
|
122
|
+
return client.call(method, params, options);
|
|
123
|
+
}
|
|
124
|
+
const data = bytes.subarray(offset, offset + length);
|
|
125
|
+
const eof = data.length < length || offset + data.length >= bytes.length;
|
|
126
|
+
if (eof)
|
|
127
|
+
copies.delete(read.path);
|
|
128
|
+
const answer = { data: Buffer.from(data.buffer, data.byteOffset, data.byteLength).toString("base64"), eof, size: bytes.length };
|
|
129
|
+
return ok(answer);
|
|
130
|
+
},
|
|
131
|
+
close() {
|
|
132
|
+
drop();
|
|
133
|
+
client.close();
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
return {
|
|
137
|
+
...connection,
|
|
138
|
+
client: reading,
|
|
139
|
+
close() {
|
|
140
|
+
drop();
|
|
141
|
+
return connection.close();
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
package/dist/hosted/process.d.ts
CHANGED
|
@@ -13,6 +13,11 @@ export declare const words: (error: unknown) => string;
|
|
|
13
13
|
export declare const redact: (text: string, secrets: readonly (string | undefined)[]) => string;
|
|
14
14
|
/** A pause that ends early when signal aborts; never rejects. */
|
|
15
15
|
export declare const pause: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* What reading answers, or undefined once a signal aborts first: a caller that stopped waiting never waits on a read.
|
|
18
|
+
* Its listener goes when either settles, so a signal given to many waits holds none of them.
|
|
19
|
+
*/
|
|
20
|
+
export declare function untilAborted<T>(reading: Promise<T>, signals: readonly (AbortSignal | undefined)[]): Promise<T | undefined>;
|
|
16
21
|
/**
|
|
17
22
|
* done() asked until it answers a value, pollMs apart: for an image build's waits (a build machine, a snapshot), all
|
|
18
23
|
* held to one end (epoch ms). Past the end is a timeout, the caller's abort aborted, each a HostError in words; an
|
package/dist/hosted/process.js
CHANGED
|
@@ -39,6 +39,26 @@ export const pause = (ms, signal) => new Promise((done) => {
|
|
|
39
39
|
else
|
|
40
40
|
signal?.addEventListener("abort", finish, { once: true });
|
|
41
41
|
});
|
|
42
|
+
/**
|
|
43
|
+
* What reading answers, or undefined once a signal aborts first: a caller that stopped waiting never waits on a read.
|
|
44
|
+
* Its listener goes when either settles, so a signal given to many waits holds none of them.
|
|
45
|
+
*/
|
|
46
|
+
export function untilAborted(reading, signals) {
|
|
47
|
+
const given = signals.filter((signal) => signal !== undefined);
|
|
48
|
+
if (given.length === 0)
|
|
49
|
+
return reading;
|
|
50
|
+
const signal = AbortSignal.any(given);
|
|
51
|
+
if (signal.aborted)
|
|
52
|
+
return Promise.resolve(undefined);
|
|
53
|
+
return new Promise((settle) => {
|
|
54
|
+
const onAbort = () => settle(undefined);
|
|
55
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
56
|
+
reading.then((value) => {
|
|
57
|
+
signal.removeEventListener("abort", onAbort);
|
|
58
|
+
settle(value);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
42
62
|
/**
|
|
43
63
|
* done() asked until it answers a value, pollMs apart: for an image build's waits (a build machine, a snapshot), all
|
|
44
64
|
* held to one end (epoch ms). Past the end is a timeout, the caller's abort aborted, each a HostError in words; an
|
package/dist/hosted/provider.js
CHANGED
|
@@ -27,7 +27,8 @@ import { failFor, ok } from "../result.js";
|
|
|
27
27
|
import { daemonWatch } from "../screen-watch.js";
|
|
28
28
|
import { countTested } from "../test-connection.js";
|
|
29
29
|
import { waitUntil } from "../wait.js";
|
|
30
|
-
import { bounded, CALL_SLACK_MS, hostCall, openBridge, pause, rootOf, runToExit, seconds, uploadThroughExec, words } from "./process.js";
|
|
30
|
+
import { bounded, CALL_SLACK_MS, hostCall, openBridge, pause, rootOf, runToExit, seconds, untilAborted, uploadThroughExec, words } from "./process.js";
|
|
31
|
+
import { downloadingConnection } from "./download.js";
|
|
31
32
|
import { isWhole, PACKED_NAME, packLabels, unpackLabels } from "./values.js";
|
|
32
33
|
import { EGRESS_POLICY, EGRESS_PROXY_USER, EGRESS_RELAY, HOSTED_ALLOW, NETWORK_LABEL, networkFormOf, networkOfForm, networkRefusal, throughProxy } from "./network.js";
|
|
33
34
|
import { ARCHIL_GATE, closedSocketsOf, daemonDrift, hostedCommands, initFlags, installerOf } from "./scripts.js";
|
|
@@ -68,9 +69,18 @@ const LISTED_POLL_MS = 150;
|
|
|
68
69
|
const LISTED_ROUNDS = 2;
|
|
69
70
|
const LISTEN_RETRY_MS = 250;
|
|
70
71
|
const START_POLL_MS = 500;
|
|
71
|
-
/** How much of agentrun-dial's output a dial
|
|
72
|
+
/** How much of agentrun-dial's output a dial failure carries (MachineHost.dialLog): its last lines, cut to these characters. */
|
|
72
73
|
const DIAL_LOG_LINES = 10;
|
|
73
74
|
const DIAL_LOG_CHARS = 800;
|
|
75
|
+
/**
|
|
76
|
+
* agentrun-dial's exits after which it may be started once more in its machine (MachineHost.redial): its fetch failed
|
|
77
|
+
* (3), or its init never listened and was ended (5). Neither leaves anything of it running; any other exit is final.
|
|
78
|
+
*/
|
|
79
|
+
const DIAL_AGAIN = new Set([3, 5]);
|
|
80
|
+
/** The step by which a dial's wait goes past createMs while agentrun-dial runs and writes, up to twice createMs. */
|
|
81
|
+
const DIAL_STEP_MS = 30_000;
|
|
82
|
+
/** What a dial machine needs, after the cause of a dial failure. */
|
|
83
|
+
const DIAL_NEEDS = "the machine must reach that address, and run agentrun-dial (the box image's entrypoint while AGENTRUN_ATTACH_URL is set, or the provider's own start of it)";
|
|
74
84
|
/**
|
|
75
85
|
* A machine token anywhere in what agentrun-dial wrote, not the tail of a longer word (`restart_…`): a dial timeout's
|
|
76
86
|
* words carry `<token>` in its place.
|
|
@@ -359,10 +369,11 @@ export class HostedProvider {
|
|
|
359
369
|
*/
|
|
360
370
|
#dialed() {
|
|
361
371
|
if (this.#dial === undefined) {
|
|
362
|
-
// No dial: a runner in a process of its own (serve's runner subcommand, the image's server-and-runner)
|
|
363
|
-
// the
|
|
372
|
+
// No dial: a runner in a process of its own (serve's runner subcommand, the image's server-and-runner) that relays
|
|
373
|
+
// no socket. The fixes are the ones a paired computer's refusal names (serve's workspace/attached-computers.ts
|
|
374
|
+
// RELAY_FIX, then ONE_PROCESS_FIX).
|
|
364
375
|
return {
|
|
365
|
-
problem: `${this.#label} machines dial in to this server, and this runner runs in a process of its own
|
|
376
|
+
problem: `${this.#label} machines dial in to this server, and this runner runs in a process of its own and relays no machine's socket: give the runner AGENTRUN_PUBLIC_URL (this server's public address), or start the image with the server options alone, without server-and-runner (outside the image: agentrun-serve without --no-runner)`,
|
|
366
377
|
};
|
|
367
378
|
}
|
|
368
379
|
const url = this.#dial.url;
|
|
@@ -1011,7 +1022,8 @@ export class HostedProvider {
|
|
|
1011
1022
|
if (init.value.exitCode !== 0)
|
|
1012
1023
|
return this.#fail("refused", `starting the daemon failed (exit ${init.value.exitCode}): ${`${init.value.stdout} ${init.value.stderr}`.trim().slice(0, 500)}`);
|
|
1013
1024
|
}
|
|
1014
|
-
const
|
|
1025
|
+
const dialNotes = [];
|
|
1026
|
+
const opened = this.#dialing ? await this.#whenDialed(ref, dialNotes, signal) : await this.#openWhenListening(ref, signal);
|
|
1015
1027
|
if (!opened.ok) {
|
|
1016
1028
|
if (opened.error.code === "aborted" || this.#dialing)
|
|
1017
1029
|
return opened;
|
|
@@ -1031,7 +1043,7 @@ export class HostedProvider {
|
|
|
1031
1043
|
await opened.value.close();
|
|
1032
1044
|
}
|
|
1033
1045
|
const listed = await this.#waitListed(ref, signal);
|
|
1034
|
-
return listed.ok ? ok([...closed, ...notes, ...listed.value]) : listed;
|
|
1046
|
+
return listed.ok ? ok([...closed, ...dialNotes, ...notes, ...listed.value]) : listed;
|
|
1035
1047
|
}
|
|
1036
1048
|
/** What init wrote to its log (child) or the vendor's words of the machine (pid1): the end of it, or nothing. */
|
|
1037
1049
|
async #initWords(ref) {
|
|
@@ -1129,7 +1141,13 @@ export class HostedProvider {
|
|
|
1129
1141
|
return ok(deletedSaid(this.host, ref, this.#label, requestMs, { ...connection, hello: hello.value }));
|
|
1130
1142
|
}
|
|
1131
1143
|
const opened = await openBridge(this.host, ref.id, { argv: hostedCommands().stdio, name: ref.name, version: VERSION, requestMs, helloMs, ...(signal ? { signal } : {}) });
|
|
1132
|
-
|
|
1144
|
+
if (!opened.ok)
|
|
1145
|
+
return opened;
|
|
1146
|
+
// A host with download takes a read past one chunk out through it, not the bridge (./download.ts).
|
|
1147
|
+
const download = this.host.download?.bind(this.host);
|
|
1148
|
+
const { execMs, uploadMs } = this.#timeouts;
|
|
1149
|
+
const connection = download === undefined ? opened.value : downloadingConnection(this.host, download, ref.id, opened.value, { execMs, downloadMs: uploadMs });
|
|
1150
|
+
return ok(deletedSaid(this.host, ref, this.#label, requestMs, connection));
|
|
1133
1151
|
}
|
|
1134
1152
|
/** #open, tried again while the bridge finds no daemon listening, until hello or helloMs in all. */
|
|
1135
1153
|
async #openWhenListening(ref, signal) {
|
|
@@ -1148,52 +1166,123 @@ export class HostedProvider {
|
|
|
1148
1166
|
* refused) fails refused in those words as the read answers. The read, one at a time, bounded by requestMs, the time
|
|
1149
1167
|
* left and the signal, holds no poll of the hub back, and the hub is read once more before a timeout: a socket there
|
|
1150
1168
|
* wins. Create then deletes one that failed.
|
|
1169
|
+
*
|
|
1170
|
+
* Where the host reads agentrun-dial's exit (dialExit), it is read too, one at a time, every few polls: one that
|
|
1171
|
+
* exited before the socket came fails refused at once, its words first. An exit in DIAL_AGAIN starts it once more in
|
|
1172
|
+
* the same machine (redial), with a note, and the wait goes on, at least half of createMs from then. And one that runs
|
|
1173
|
+
* and writes is waited for past createMs: its log is read a step (DIAL_STEP_MS, at most a quarter of createMs) before
|
|
1174
|
+
* the deadline, beside the polls, and again at it, and a log that changed between them moves the deadline a step, up
|
|
1175
|
+
* to twice createMs. The hub is read once more after those reads, so a socket that came while they ran wins.
|
|
1151
1176
|
*/
|
|
1152
|
-
async #whenDialed(ref, signal) {
|
|
1177
|
+
async #whenDialed(ref, notes, signal) {
|
|
1153
1178
|
const { createMs, requestMs } = this.#timeouts;
|
|
1154
|
-
const
|
|
1155
|
-
|
|
1179
|
+
const { dialExit, dialLog, redial } = this.host;
|
|
1180
|
+
const began = Date.now();
|
|
1181
|
+
const cap = began + 2 * createMs;
|
|
1182
|
+
const step = Math.min(DIAL_STEP_MS, createMs / 4);
|
|
1183
|
+
let until = began + createMs;
|
|
1184
|
+
// The log's reads for the wait past createMs: a host that cannot say agentrun-dial still runs has none.
|
|
1185
|
+
const readLog = dialExit === undefined || dialLog === undefined
|
|
1186
|
+
? undefined
|
|
1187
|
+
: () => this.#call(`the dial log of ${ref.name}`, (ctx) => dialLog.call(this.host, ref.id, ctx), requestMs, signal).then((read) => (read.ok ? read.value : undefined));
|
|
1188
|
+
let logAt = until - step;
|
|
1189
|
+
// The step's first read, from logAt on: running beside the polls, it holds none of them back.
|
|
1190
|
+
let logged;
|
|
1191
|
+
let refusing;
|
|
1192
|
+
let exiting;
|
|
1193
|
+
let exitAt = began;
|
|
1194
|
+
let first;
|
|
1156
1195
|
for (;;) {
|
|
1157
1196
|
const opened = await this.#open(ref, signal);
|
|
1158
1197
|
if (opened.ok)
|
|
1159
1198
|
return opened;
|
|
1199
|
+
if (readLog !== undefined && logged === undefined && Date.now() >= logAt)
|
|
1200
|
+
logged = readLog();
|
|
1160
1201
|
const left = until - Date.now();
|
|
1161
1202
|
if (left <= 0) {
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1203
|
+
if (logged !== undefined) {
|
|
1204
|
+
const before = await logged;
|
|
1205
|
+
const now = await readLog?.();
|
|
1206
|
+
logged = undefined;
|
|
1207
|
+
if (before !== undefined && now !== undefined && now !== before && until + step <= cap) {
|
|
1208
|
+
until += step;
|
|
1209
|
+
// This read is the next step's first.
|
|
1210
|
+
logged = Promise.resolve(now);
|
|
1211
|
+
continue;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
// A socket that came while the log was read wins.
|
|
1215
|
+
const late = await this.#open(ref, signal);
|
|
1216
|
+
if (late.ok)
|
|
1217
|
+
return late;
|
|
1218
|
+
const said = await this.#dialSaid(ref, signal);
|
|
1219
|
+
return this.#fail("timeout", `${said === undefined ? "" : `${said}; `}${this.#notDialed(ref)} within ${seconds(until - began)}: ${DIAL_NEEDS}`);
|
|
1220
|
+
}
|
|
1221
|
+
const polled = pause(Math.min(this.#startPollMs(), left), signal).then(() => ({ polled: true }));
|
|
1222
|
+
refusing ??= this.#dialRefused(ref.name, Math.min(requestMs, left), signal).then((refused) => ({ refused }));
|
|
1223
|
+
if (exiting === undefined && dialExit !== undefined && Date.now() >= exitAt) {
|
|
1224
|
+
exiting = this.#call(`agentrun-dial's exit in ${ref.name}`, (ctx) => dialExit.call(this.host, ref.id, ctx), Math.min(requestMs, left), signal).then((read) => ({ exited: read.ok ? read.value : undefined }));
|
|
1166
1225
|
}
|
|
1167
|
-
const
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
if (read !== undefined)
|
|
1173
|
-
return this.#fail("refused", `the server refused ${read}`);
|
|
1226
|
+
const read = await Promise.race([refusing, polled, ...(exiting === undefined ? [] : [exiting])]);
|
|
1227
|
+
if ("refused" in read) {
|
|
1228
|
+
refusing = undefined;
|
|
1229
|
+
if (read.refused !== undefined)
|
|
1230
|
+
return this.#fail("refused", `the server refused ${read.refused}`);
|
|
1174
1231
|
await polled;
|
|
1175
1232
|
}
|
|
1233
|
+
else if ("exited" in read) {
|
|
1234
|
+
exiting = undefined;
|
|
1235
|
+
exitAt = Date.now() + this.#startPollMs() * 4;
|
|
1236
|
+
if (read.exited === undefined)
|
|
1237
|
+
await polled;
|
|
1238
|
+
else {
|
|
1239
|
+
// A socket that came as it exited wins.
|
|
1240
|
+
const late = await this.#open(ref, signal);
|
|
1241
|
+
if (late.ok)
|
|
1242
|
+
return late;
|
|
1243
|
+
const said = await this.#dialSaid(ref, signal);
|
|
1244
|
+
const again = first === undefined && DIAL_AGAIN.has(read.exited) && redial !== undefined && !signal?.aborted ? await this.#call(`agentrun-dial's second start in ${ref.name}`, (ctx) => redial.call(this.host, ref.id, ctx), requestMs, signal) : undefined;
|
|
1245
|
+
if (again?.ok) {
|
|
1246
|
+
first = read.exited;
|
|
1247
|
+
notes.push(`agentrun-dial's first start in ${ref.name} exited ${read.exited}${said === undefined ? "" : ` (${said})`}, and it was started once more`);
|
|
1248
|
+
until = Math.min(cap, Math.max(until, Date.now() + createMs / 2));
|
|
1249
|
+
logged = undefined;
|
|
1250
|
+
logAt = until - step;
|
|
1251
|
+
continue;
|
|
1252
|
+
}
|
|
1253
|
+
const restart = again === undefined || again.ok ? "" : `, and starting it once more failed (${again.error.message})`;
|
|
1254
|
+
const before = first === undefined ? "" : `, and its first start exited ${first} before it was started once more`;
|
|
1255
|
+
return this.#fail("refused", `${said === undefined ? "" : `${said}; `}${this.#notDialed(ref)}: agentrun-dial exited ${read.exited}${before}${restart}: ${DIAL_NEEDS}`);
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1176
1258
|
if (signal?.aborted)
|
|
1177
1259
|
return this.#fail("aborted", `create was aborted while it waited for ${ref.name} to dial`);
|
|
1178
1260
|
}
|
|
1179
1261
|
}
|
|
1262
|
+
/** "<name> did not dial <attach URL>[ through <relay>]": a dial failure's words, after its cause. */
|
|
1263
|
+
#notDialed(ref) {
|
|
1264
|
+
const dialed = this.#dialed();
|
|
1265
|
+
const to = "problem" in dialed ? "this server" : dialed.attach;
|
|
1266
|
+
const through = this.#attachEgress === undefined ? "" : ` through ${this.#attachEgress}`;
|
|
1267
|
+
return `${ref.name} did not dial ${to}${through}`;
|
|
1268
|
+
}
|
|
1180
1269
|
/**
|
|
1181
|
-
*
|
|
1182
|
-
* `<token>`, its last DIAL_LOG_LINES lines within DIAL_LOG_CHARS characters, or that it never started
|
|
1183
|
-
* host without dialLog, or a read that fails, outlasts requestMs or is cut by the create's
|
|
1184
|
-
* waits on it.
|
|
1270
|
+
* What a dial failure's words lead with: what the host's dialLog read of agentrun-dial, every machine token replaced
|
|
1271
|
+
* by `<token>`, its last DIAL_LOG_LINES lines within DIAL_LOG_CHARS characters, or that it never started or wrote
|
|
1272
|
+
* nothing. undefined for a host without dialLog, or a read that fails, outlasts requestMs or is cut by the create's
|
|
1273
|
+
* signal, so a cancel never waits on it.
|
|
1185
1274
|
*/
|
|
1186
|
-
async #
|
|
1275
|
+
async #dialSaid(ref, signal) {
|
|
1187
1276
|
const { dialLog } = this.host;
|
|
1188
1277
|
if (dialLog === undefined)
|
|
1189
|
-
return
|
|
1278
|
+
return undefined;
|
|
1190
1279
|
const read = await this.#call(`the dial log of ${ref.name}`, (ctx) => dialLog.call(this.host, ref.id, ctx), this.#timeouts.requestMs, signal);
|
|
1191
1280
|
if (!read.ok)
|
|
1192
|
-
return
|
|
1281
|
+
return undefined;
|
|
1193
1282
|
if (read.value === undefined)
|
|
1194
|
-
return "
|
|
1283
|
+
return "agentrun-dial never started";
|
|
1195
1284
|
const lines = read.value.replaceAll(MACHINE_TOKEN, "<token>").split(/\r?\n/).map((line) => line.trim()).filter((line) => line !== "");
|
|
1196
|
-
return lines.length === 0 ? "
|
|
1285
|
+
return lines.length === 0 ? "agentrun-dial wrote nothing" : `agentrun-dial said: ${lines.slice(-DIAL_LOG_LINES).join(" | ").slice(-DIAL_LOG_CHARS)}`;
|
|
1197
1286
|
}
|
|
1198
1287
|
/**
|
|
1199
1288
|
* Its tools' network as they meet it, against the one create made: the probe, as the computer's own user. Under none,
|
|
@@ -1727,23 +1816,6 @@ async function readMachine(host, id, ms, signal) {
|
|
|
1727
1816
|
return read.error.code === "not_found" ? ok(undefined) : read;
|
|
1728
1817
|
return ok(read.value === undefined ? undefined : unpacked(host, read.value));
|
|
1729
1818
|
}
|
|
1730
|
-
/** What reading answers, or undefined once a signal aborts first: a caller that stopped waiting never waits on a read. */
|
|
1731
|
-
function untilAborted(reading, signals) {
|
|
1732
|
-
const given = signals.filter((signal) => signal !== undefined);
|
|
1733
|
-
if (given.length === 0)
|
|
1734
|
-
return reading;
|
|
1735
|
-
const signal = AbortSignal.any(given);
|
|
1736
|
-
if (signal.aborted)
|
|
1737
|
-
return Promise.resolve(undefined);
|
|
1738
|
-
return new Promise((settle) => {
|
|
1739
|
-
const onAbort = () => settle(undefined);
|
|
1740
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
1741
|
-
reading.then((value) => {
|
|
1742
|
-
signal.removeEventListener("abort", onAbort);
|
|
1743
|
-
settle(value);
|
|
1744
|
-
});
|
|
1745
|
-
});
|
|
1746
|
-
}
|
|
1747
1819
|
/**
|
|
1748
1820
|
* A connection that says its computer was deleted (the vendor's own API can delete it mid-run). Once its client answers
|
|
1749
1821
|
* gone (the stream ended or failed), the machine is read once, and that one read answers every call in flight at that
|
package/dist/hosted/rest.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ComputerErrorCode, type Result } from "../result.js";
|
|
1
|
+
import { type ComputerError, type ComputerErrorCode, type Result } from "../result.js";
|
|
2
2
|
/**
|
|
3
3
|
* A status as a code: 401 and 403 denied, 404 and 410 not found, 408 timeout, 402/429/507 limit, 400/409/422 invalid,
|
|
4
4
|
* else vendor; 409 is exists on a call that carries the machine's name (RestInit.named).
|
|
@@ -37,6 +37,8 @@ export interface RestOptions {
|
|
|
37
37
|
fetch?: typeof fetch;
|
|
38
38
|
/** The bound of a call that gives none. */
|
|
39
39
|
timeoutMs: number;
|
|
40
|
+
/** A signal that fires after ms, which bounds a call; default a timer. Tests give one they fire. */
|
|
41
|
+
timeout?: (ms: number) => AbortSignal;
|
|
40
42
|
retry?: {
|
|
41
43
|
attempts: number;
|
|
42
44
|
baseMs: number;
|
|
@@ -55,6 +57,13 @@ export interface RestOptions {
|
|
|
55
57
|
}
|
|
56
58
|
/** The JSON a body holds; null for none or for text that is not JSON. */
|
|
57
59
|
export declare function jsonOf(bytes: Uint8Array): unknown;
|
|
60
|
+
/**
|
|
61
|
+
* A call's failure. `redirect` marks one the API answered with a redirect, refused unfollowed: its answer is unread,
|
|
62
|
+
* so the vendor may have acted on the call (a 303 after a create is the usual answer to a POST).
|
|
63
|
+
*/
|
|
64
|
+
export interface RestError extends ComputerError {
|
|
65
|
+
redirect?: true;
|
|
66
|
+
}
|
|
58
67
|
/** An accepted answer whose body is read as it comes: an event stream. */
|
|
59
68
|
export interface RestStream {
|
|
60
69
|
status: number;
|
|
@@ -62,20 +71,22 @@ export interface RestStream {
|
|
|
62
71
|
}
|
|
63
72
|
export interface Rest {
|
|
64
73
|
url(path: string): string;
|
|
65
|
-
call(method: string, url: string, init?: RestInit, signal?: AbortSignal): Promise<Result<RestAnswer>>;
|
|
74
|
+
call(method: string, url: string, init?: RestInit, signal?: AbortSignal): Promise<Result<RestAnswer, RestError>>;
|
|
66
75
|
/** call, with the body read as JSON (null for none). */
|
|
67
|
-
json(method: string, url: string, init?: RestInit, signal?: AbortSignal): Promise<Result<unknown>>;
|
|
76
|
+
json(method: string, url: string, init?: RestInit, signal?: AbortSignal): Promise<Result<unknown, RestError>>;
|
|
68
77
|
/**
|
|
69
78
|
* call, with an accepted answer's body handed back unread, as it comes (a process's events). The bound covers the
|
|
70
79
|
* answer's start alone: the body has none but the caller's signal, which ends it too.
|
|
71
80
|
*/
|
|
72
|
-
stream(method: string, url: string, init?: RestInit, signal?: AbortSignal): Promise<Result<RestStream>>;
|
|
81
|
+
stream(method: string, url: string, init?: RestInit, signal?: AbortSignal): Promise<Result<RestStream, RestError>>;
|
|
73
82
|
}
|
|
74
83
|
/**
|
|
75
|
-
* An API's https base URL
|
|
76
|
-
* loopback http included
|
|
77
|
-
*
|
|
78
|
-
*
|
|
84
|
+
* An API's https base URL: its origin and path, normalized, with no trailing slash. Throws in words on another scheme,
|
|
85
|
+
* loopback http included, so a key never crosses in the clear, and on a user or password, a query or a fragment, which
|
|
86
|
+
* no provider's API takes. Every provider that takes a URL from its caller and sends a key to it takes the URL through
|
|
87
|
+
* it: Agent37, boxd, Browserbase, the Cloudflare relay, Daytona (and the toolbox URL Daytona answers with), Groundbox,
|
|
88
|
+
* Kernel, Modal, Morph, Orgo, the phone harness and smol cloud, and so does each sweep scope that names one. E2B takes a
|
|
89
|
+
* host name and Fly nothing, and each builds its https URL itself.
|
|
79
90
|
*/
|
|
80
91
|
export declare function httpsBase(url: string, what: string): string;
|
|
81
92
|
export declare function rest(options: RestOptions): Rest;
|