@parcha/agentrun-computer 0.1.0-beta.41 → 0.1.0-beta.43
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/NOTICE +2 -0
- package/README.md +254 -14
- package/box/README.md +2 -2
- package/box/build-e2b.mjs +1 -1
- package/dist/box-image.d.ts +1 -3
- package/dist/box-image.js +1 -11
- package/dist/boxd.d.ts +126 -0
- package/dist/boxd.js +418 -0
- package/dist/cloudflare.d.ts +32 -0
- package/dist/cloudflare.js +181 -0
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +2 -2
- package/dist/conformance/boxd.d.ts +77 -0
- package/dist/conformance/boxd.js +113 -0
- package/dist/conformance/cases/isolation.js +1 -17
- package/dist/conformance/cloudflare.d.ts +42 -0
- package/dist/conformance/cloudflare.js +54 -0
- package/dist/conformance/dial-only.d.ts +6 -0
- package/dist/conformance/dial-only.js +9 -0
- package/dist/conformance/e2b.d.ts +12 -3
- package/dist/conformance/e2b.js +21 -4
- package/dist/conformance/fly.d.ts +52 -0
- package/dist/conformance/fly.js +52 -0
- package/dist/conformance/modal.d.ts +15 -2
- package/dist/conformance/modal.js +36 -3
- package/dist/conformance/morph.d.ts +59 -0
- package/dist/conformance/morph.js +95 -0
- package/dist/conformance/phone-harness.js +2 -2
- package/dist/conformance/runner.js +3 -3
- package/dist/conformance/sweep.d.ts +1 -6
- package/dist/conformance/sweep.js +8 -18
- package/dist/descriptors/boxd.d.ts +52 -0
- package/dist/descriptors/boxd.js +29 -0
- package/dist/descriptors/cloudflare.d.ts +21 -0
- package/dist/descriptors/cloudflare.js +29 -0
- package/dist/descriptors/e2b.d.ts +4 -0
- package/dist/descriptors/e2b.js +3 -0
- package/dist/descriptors/fly.d.ts +19 -0
- package/dist/descriptors/fly.js +28 -0
- package/dist/descriptors/index.d.ts +113 -1
- package/dist/descriptors/index.js +7 -2
- package/dist/descriptors/modal.d.ts +3 -0
- package/dist/descriptors/modal.js +7 -2
- package/dist/descriptors/morph.d.ts +15 -0
- package/dist/descriptors/morph.js +21 -0
- package/dist/descriptors/phone-harness.d.ts +1 -0
- package/dist/descriptors/phone-harness.js +2 -0
- package/dist/e2b.d.ts +7 -1
- package/dist/e2b.js +87 -44
- package/dist/fly.d.ts +43 -0
- package/dist/fly.js +245 -0
- package/dist/host.d.ts +8 -28
- package/dist/hosted/process.d.ts +19 -0
- package/dist/hosted/process.js +28 -0
- package/dist/hosted/provider.d.ts +11 -22
- package/dist/hosted/provider.js +30 -201
- package/dist/hosted/scripts.d.ts +2 -8
- package/dist/hosted/scripts.js +2 -22
- package/dist/hosted/ssh-exec.d.ts +2 -1
- package/dist/hosted/ssh-exec.js +58 -2
- package/dist/hosted/values.d.ts +5 -0
- package/dist/hosted/values.js +9 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/modal.d.ts +6 -0
- package/dist/modal.js +20 -10
- package/dist/morph.d.ts +65 -0
- package/dist/morph.js +495 -0
- package/dist/phone-harness.d.ts +15 -5
- package/dist/phone-harness.js +50 -15
- package/dist/screen-watch.js +2 -2
- package/package.json +20 -2
package/dist/fly.js
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// The Fly Machines host: a Linux sandbox on a Fly Machine in the operator's Fly app, over the Machines REST API
|
|
2
|
+
// (https://api.machines.dev, a Bearer token). Fly's exec answers once its command ends (docs.machines.dev/machines/Machines_exec:
|
|
3
|
+
// stdout, stderr and exit_code), which can't carry the stdio bridge, so this host has none: its machines dial the server
|
|
4
|
+
// (facts.connect "dial"). The machine boots the box image with MachineRequest.boot.env, whose CMD runs agentrun-dial
|
|
5
|
+
// while AGENTRUN_ATTACH_URL is set (box/Dockerfile): it fetches the server's computerd, checks its sha256, starts init and
|
|
6
|
+
// dials the attach route with the machine's own token. The rest of the computer is the shared machine-host adapter's
|
|
7
|
+
// (./hosted/provider.ts).
|
|
8
|
+
//
|
|
9
|
+
// Every vendor fact below cites the page it is from; one the docs don't settle says unverified, and the live Core run
|
|
10
|
+
// (packages/serve/scripts/dial-conformance.mjs) is what settles it. Pages: M = docs.fly.io/machines/api/machines-resource,
|
|
11
|
+
// S = docs.fly.io/machines/machine-states, W = docs.fly.io/machines/api/working-with-machines-api, and fly-go, Fly's own
|
|
12
|
+
// Go client (github.com/superfly/fly-go: machine_types.go, flaps/flaps.go).
|
|
13
|
+
import { boxImageRef } from "./box-image.js";
|
|
14
|
+
import { FLY } from "./descriptors/fly.js";
|
|
15
|
+
import { DEADLINE_LABEL, DEFAULT_CPUS, DEFAULT_MEMORY_MB, show } from "./drift.js";
|
|
16
|
+
import { HostError } from "./host.js";
|
|
17
|
+
import { orThrow } from "./hosted/process.js";
|
|
18
|
+
import { HostedProvider } from "./hosted/provider.js";
|
|
19
|
+
import { jsonOf, rest } from "./hosted/rest.js";
|
|
20
|
+
import { dateOf, isWhole } from "./hosted/values.js";
|
|
21
|
+
import { ok } from "./result.js";
|
|
22
|
+
/** The Machines API (W: "https://api.machines.dev"). */
|
|
23
|
+
const API_URL = "https://api.machines.dev";
|
|
24
|
+
/** An app name: Fly's are lowercase letters, digits and hyphens (unverified: W names no rule, only a taken name's 422). */
|
|
25
|
+
const APP = /^[a-z0-9][a-z0-9-]{0,62}$/;
|
|
26
|
+
/** A machine id, held to letters and digits before it reaches a path (M's examples are 14 hex digits). */
|
|
27
|
+
const MACHINE_ID = /^[A-Za-z0-9]{1,64}$/;
|
|
28
|
+
/** Fly never ends a machine on a timer of its own (M names none), so the janitor's cap is ours: a day, as Agent37's. */
|
|
29
|
+
const MAX_LIFETIME_MS = 24 * 60 * 60_000;
|
|
30
|
+
/** Shared CPUs a machine takes (fly-go MachineGuest: "1, 2, 4, 6, 8 ... up to 8 for shared"). */
|
|
31
|
+
const SHARED_CPUS = [1, 2, 4, 6, 8];
|
|
32
|
+
/** fly-go MachineGuest: memory "a multiple of 256 for shared ... between 256 and 2048 (shared) ... per CPU". */
|
|
33
|
+
const MEMORY_STEP_MB = 256;
|
|
34
|
+
const MEMORY_PER_CPU_MB = { least: 256, most: 2048 };
|
|
35
|
+
/**
|
|
36
|
+
* A create pulls the box image before the machine runs, and the machine then fetches its daemon and dials: the wait for
|
|
37
|
+
* its socket is createMs too. Fly's delete stops the machine first (force).
|
|
38
|
+
*/
|
|
39
|
+
const FLY_TIMEOUTS = { createMs: 600_000, goneMs: 120_000 };
|
|
40
|
+
/** W: "1 request, per second, per action", bursts to 3: a 429 is sent again after 1, 2 and 4 s. */
|
|
41
|
+
const RETRY = { attempts: 4, baseMs: 1_000 };
|
|
42
|
+
/**
|
|
43
|
+
* Fly's states (S) as the adapter's. created and the transient ones on the way to started are starting; stopped,
|
|
44
|
+
* suspended and archived machines and those on their way there are stopped (listed, so the janitor ends them);
|
|
45
|
+
* destroying, failed and launch_failed are gone. destroyed, replaced and migrated are records of machines that are no
|
|
46
|
+
* more: undefined, as get and list answer none for them.
|
|
47
|
+
*/
|
|
48
|
+
function stateOf(state) {
|
|
49
|
+
if (state === "started")
|
|
50
|
+
return "running";
|
|
51
|
+
if (["created", "creating", "starting", "restarting", "updating", "replacing"].includes(state))
|
|
52
|
+
return "starting";
|
|
53
|
+
if (["stopping", "stopped", "suspending", "suspended", "archived"].includes(state))
|
|
54
|
+
return "stopped";
|
|
55
|
+
if (["destroying", "failed", "launch_failed"].includes(state))
|
|
56
|
+
return "gone";
|
|
57
|
+
if (["destroyed", "replaced", "migrated"].includes(state))
|
|
58
|
+
return null;
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
/** A machine as the adapter reads one; undefined for a record of one destroyed. */
|
|
62
|
+
function machineOf(found) {
|
|
63
|
+
const state = stateOf(found.state);
|
|
64
|
+
if (state === null)
|
|
65
|
+
return undefined;
|
|
66
|
+
const config = found.config ?? found.incomplete_config ?? {};
|
|
67
|
+
const created = dateOf(found.created_at);
|
|
68
|
+
const why = state === undefined
|
|
69
|
+
? `Fly reads the machine's state ${show(found.state)}, which this provider does not know`
|
|
70
|
+
: found.state === "failed" || found.state === "launch_failed"
|
|
71
|
+
? `Fly reads the machine ${found.state}: it could not start (see fly machine status ${found.id})`
|
|
72
|
+
: undefined;
|
|
73
|
+
return {
|
|
74
|
+
id: found.id,
|
|
75
|
+
labels: { ...(config.metadata ?? {}) },
|
|
76
|
+
state: state ?? "gone",
|
|
77
|
+
...(created ? { createdAt: created } : {}),
|
|
78
|
+
...(why ? { why } : {}),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** An id held to Fly's form before it reaches a path: not_found else. */
|
|
82
|
+
function machineId(id) {
|
|
83
|
+
if (!MACHINE_ID.test(id))
|
|
84
|
+
throw new HostError("not_found", `${JSON.stringify(id)} is not a Fly machine id`);
|
|
85
|
+
return id;
|
|
86
|
+
}
|
|
87
|
+
/** Fly Machines as a dial MachineHost (../host.ts): no exec, no upload. */
|
|
88
|
+
class FlyHost {
|
|
89
|
+
descriptor = FLY;
|
|
90
|
+
facts = {
|
|
91
|
+
// agentrun-dial starts init as a child of the machine's main process; nothing is started through exec.
|
|
92
|
+
daemon: "child",
|
|
93
|
+
// docs.fly.io/machines/overview: "Fly Machines are fast-launching VMs"; Firecracker microVMs (unverified: the
|
|
94
|
+
// Machines pages don't name the hypervisor).
|
|
95
|
+
isolation: "microvm",
|
|
96
|
+
lifetime: "janitor",
|
|
97
|
+
maxLifetimeMs: MAX_LIFETIME_MS,
|
|
98
|
+
// The box image is built for amd64 alone (release.yml's box job); Fly runs it on x86-64 hosts (unverified: no page
|
|
99
|
+
// names an arch; docs.fly.io/machines/overview's own `uname -a` shows x86_64).
|
|
100
|
+
arch: "amd64",
|
|
101
|
+
// Unverified: Fly's init runs hallpass, the SSH server `fly ssh console` reaches, on port 22 of the machine's private
|
|
102
|
+
// address. Declared, so isolation.vendor-agent checks the computer's programs reach none of it.
|
|
103
|
+
vendorAgentPorts: [22],
|
|
104
|
+
// The machine dials the server: Fly's exec answers once the command ends (docs.machines.dev, Machines_exec), so
|
|
105
|
+
// there is no exec and no upload here.
|
|
106
|
+
connect: "dial",
|
|
107
|
+
};
|
|
108
|
+
#client;
|
|
109
|
+
#app;
|
|
110
|
+
constructor(options) {
|
|
111
|
+
this.#app = options.app;
|
|
112
|
+
this.#client = rest({
|
|
113
|
+
base: API_URL,
|
|
114
|
+
// M, W: "Authorization: Bearer <fly_api_token>".
|
|
115
|
+
headers: () => ({ Authorization: `Bearer ${options.apiToken}`, Accept: "application/json" }),
|
|
116
|
+
vendor: FLY.id,
|
|
117
|
+
fetch: options.fetch,
|
|
118
|
+
timeoutMs: 30_000, // every call gives its own: ctx.timeoutMs
|
|
119
|
+
retry: RETRY,
|
|
120
|
+
// fly-go flaps.go handleAPIError: an error's body is { error, message? }; M and W show none.
|
|
121
|
+
explain: ({ status, bytes, what }) => {
|
|
122
|
+
const body = jsonOf(bytes);
|
|
123
|
+
const said = [body?.error, body?.message].filter((part) => typeof part === "string" && part !== "");
|
|
124
|
+
return { message: `${what} answered ${status}${said.length > 0 ? `: ${said.join(": ")}` : ""}` };
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/** One call under /v1/apps/{app}/machines, bounded by ctx: its JSON answer (null for none), or a HostError in Fly's words. */
|
|
129
|
+
async #call(method, path, init, ctx) {
|
|
130
|
+
const answer = orThrow(await this.#client.call(method, this.#client.url(`/v1/apps/${this.#app}/machines${path}`), { ...init, timeoutMs: ctx.timeoutMs }, ctx.signal));
|
|
131
|
+
return jsonOf(answer.bytes);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Any image name a registry path can be (M: config.image, "registry-1.docker.io/library/ubuntu:latest"), and a size
|
|
135
|
+
* of shared CPUs (fly-go MachineGuest).
|
|
136
|
+
*/
|
|
137
|
+
check(spec) {
|
|
138
|
+
const refusals = [];
|
|
139
|
+
const { image, cpus, memoryMb } = spec;
|
|
140
|
+
if (typeof image === "string" && (image.startsWith("-") || /\s/.test(image)))
|
|
141
|
+
refusals.push({ field: "image", message: "an image is a registry path Fly can pull, such as ghcr.io/parcha-ai/agentrun-box:<tag>" });
|
|
142
|
+
if (cpus !== undefined && !SHARED_CPUS.includes(cpus))
|
|
143
|
+
refusals.push({ field: "cpus", message: `a Fly machine has ${SHARED_CPUS.join(", ")} shared CPUs` });
|
|
144
|
+
const each = typeof cpus === "number" && SHARED_CPUS.includes(cpus) ? cpus : DEFAULT_CPUS;
|
|
145
|
+
const least = MEMORY_PER_CPU_MB.least * each;
|
|
146
|
+
const most = MEMORY_PER_CPU_MB.most * each;
|
|
147
|
+
if (memoryMb !== undefined && !(isWhole(memoryMb) && memoryMb % MEMORY_STEP_MB === 0 && memoryMb >= least && memoryMb <= most)) {
|
|
148
|
+
refusals.push({ field: "memoryMb", message: `a Fly machine of ${each} shared CPUs has a multiple of ${MEMORY_STEP_MB} MiB from ${least} to ${most}` });
|
|
149
|
+
}
|
|
150
|
+
return refusals;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* POST /v1/apps/{app}/machines (M, "Create a Machine"): the request's name, the image, the boot env as config.env,
|
|
154
|
+
* the labels as config.metadata, a shared-CPU guest of the spec's size, restart policy "no" and auto_destroy, so the
|
|
155
|
+
* machine is destroyed once its main process ends: agentrun-dial's computerd attach, which exits once init has ended
|
|
156
|
+
* at its deadline (daemon internal/attach). Unverified: that a public ghcr.io image pulls with no registry login (M's
|
|
157
|
+
* example is Docker Hub's), and that Fly's init runs the image's CMD when config.init sets none. No service: Fly's proxy
|
|
158
|
+
* routes nothing to the machine. No region: Fly picks one (M: "near your WireGuard peer"; unverified from outside one).
|
|
159
|
+
* Unverified: whether Fly refuses a taken name, and with what status; a 409 reads exists. Unverified: any bound on
|
|
160
|
+
* metadata keys or values (M names none).
|
|
161
|
+
*/
|
|
162
|
+
async create(req, ctx) {
|
|
163
|
+
if (req.boot === undefined)
|
|
164
|
+
throw new HostError("invalid", "a Fly machine dials the server, and the request has no boot env for it");
|
|
165
|
+
// With no memory asked for, the default, or the most the CPUs take when that is less (one shared CPU: 2048 MiB).
|
|
166
|
+
const cpus = req.cpus ?? DEFAULT_CPUS;
|
|
167
|
+
const memoryMb = req.memoryMb ?? Math.min(DEFAULT_MEMORY_MB, MEMORY_PER_CPU_MB.most * cpus);
|
|
168
|
+
const made = (await this.#call("POST", "", {
|
|
169
|
+
json: {
|
|
170
|
+
name: req.name,
|
|
171
|
+
config: {
|
|
172
|
+
image: req.image,
|
|
173
|
+
env: req.boot.env,
|
|
174
|
+
metadata: req.labels,
|
|
175
|
+
guest: { cpu_kind: "shared", cpus, memory_mb: memoryMb },
|
|
176
|
+
restart: { policy: "no" },
|
|
177
|
+
auto_destroy: true,
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
named: true,
|
|
181
|
+
// Only a 429, a refusal that made nothing, is sent again: a create that got no answer may have made a machine.
|
|
182
|
+
retry: (status) => status === 429,
|
|
183
|
+
}, ctx));
|
|
184
|
+
if (typeof made?.id !== "string" || !MACHINE_ID.test(made.id))
|
|
185
|
+
throw new HostError("vendor", `POST /v1/apps/${this.#app}/machines answered no machine id: ${show(made?.id)}`);
|
|
186
|
+
return { id: made.id };
|
|
187
|
+
}
|
|
188
|
+
/** GET /v1/apps/{app}/machines/{id} (M, "Get a Machine"); 404 is not_found, which the adapter reads as none. */
|
|
189
|
+
async get(id, ctx) {
|
|
190
|
+
return machineOf((await this.#call("GET", `/${machineId(id)}`, { retry: true }, ctx)));
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* GET /v1/apps/{app}/machines?metadata.{key}={value} for each label (M, "List Machines": "filters by metadata pair"),
|
|
194
|
+
* one answer, a list with no page; destroyed machines are left out unless include_deleted is asked. Unverified: that a
|
|
195
|
+
* key holding dots (agentrun.computer.run) filters as itself; the adapter keeps those whose get carries every label.
|
|
196
|
+
*/
|
|
197
|
+
async list(labels, ctx) {
|
|
198
|
+
const query = new URLSearchParams(Object.entries(labels).map(([key, value]) => [`metadata.${key}`, value])).toString();
|
|
199
|
+
const listed = await this.#call("GET", query === "" ? "" : `?${query}`, { retry: true }, ctx);
|
|
200
|
+
if (!Array.isArray(listed))
|
|
201
|
+
throw new HostError("vendor", `GET /v1/apps/${this.#app}/machines answered no list`);
|
|
202
|
+
return listed.filter((one) => typeof one?.id === "string").flatMap((one) => machineOf(one) ?? []);
|
|
203
|
+
}
|
|
204
|
+
/** DELETE /v1/apps/{app}/machines/{id}?force=true (M: "Force stop the Machine if running"); a 404 is done to the adapter. */
|
|
205
|
+
async delete(id, ctx) {
|
|
206
|
+
await this.#call("DELETE", `/${machineId(id)}?force=true`, { retry: true }, ctx);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* The janitor's deadline label moved: POST /v1/apps/{app}/machines/{id}/metadata/{key} { value } (M, "Add or update a
|
|
210
|
+
* metadata key-value pair", 204), that one key alone, so no other label is written. Unverified: that it does not
|
|
211
|
+
* restart a running machine, as M says a config update does.
|
|
212
|
+
*/
|
|
213
|
+
async extend(id, endsAt, ctx) {
|
|
214
|
+
await this.#call("POST", `/${machineId(id)}/metadata/${encodeURIComponent(DEADLINE_LABEL)}`, { json: { value: endsAt.toISOString() }, retry: true }, ctx);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/** A FlyProvider from its options alone; it reads no environment (serve passes the saved FLY_API_TOKEN and FLY_APP). */
|
|
218
|
+
export function create(options) {
|
|
219
|
+
return new FlyProvider(options);
|
|
220
|
+
}
|
|
221
|
+
/** The conformance CLI's module for Fly Machines: its settings, and its dialKit that refuses off the public server. */
|
|
222
|
+
export const conformance = () => import("./conformance/fly.js");
|
|
223
|
+
/**
|
|
224
|
+
* Computers that are Fly Machines, on the shared adapter, each dialing the server that made it: a server with no public
|
|
225
|
+
* https address (AGENTRUN_PUBLIC_URL) refuses a create in words before Fly is called. Kind linux alone.
|
|
226
|
+
*/
|
|
227
|
+
export class FlyProvider extends HostedProvider {
|
|
228
|
+
/**
|
|
229
|
+
* The provider contract's prepareImage (its descriptor declares it): the box image the release publishes, by its
|
|
230
|
+
* public registry tag (box-image.ts). No call: Fly pulls config.image at each create.
|
|
231
|
+
*/
|
|
232
|
+
async prepareImage() {
|
|
233
|
+
return ok(boxImageRef());
|
|
234
|
+
}
|
|
235
|
+
constructor(options) {
|
|
236
|
+
const { apiToken, app, fetch: fetcher = globalThis.fetch, timeouts = {}, ...rest } = options ?? {};
|
|
237
|
+
if (typeof apiToken !== "string" || apiToken === "")
|
|
238
|
+
throw new Error("options.apiToken, a Fly API token, is required: the provider reads no environment, so the caller passes it");
|
|
239
|
+
if (typeof app !== "string" || !APP.test(app))
|
|
240
|
+
throw new Error(`options.app is the name of the Fly app its machines live in (lowercase letters, digits and hyphens), not ${JSON.stringify(app)}`);
|
|
241
|
+
if (typeof fetcher !== "function")
|
|
242
|
+
throw new Error("options.fetch must be a function, as the global fetch is");
|
|
243
|
+
super(new FlyHost({ apiToken, app, fetch: fetcher }), { ...rest, kind: "linux", timeouts: { ...FLY_TIMEOUTS, ...timeouts } });
|
|
244
|
+
}
|
|
245
|
+
}
|
package/dist/host.d.ts
CHANGED
|
@@ -23,8 +23,7 @@ export interface MachineHost {
|
|
|
23
23
|
* carries req.name where the vendor can find it again by listing: the vendor's native name, or a label. A native name
|
|
24
24
|
* the vendor already has throws exists (a REST host's named call: hosted/rest.ts), and the adapter adopts the machine
|
|
25
25
|
* the name lists, as a retry does. An answer that never comes is not a machine the adapter forgets: it lists by
|
|
26
|
-
* req.labels and deletes what it finds.
|
|
27
|
-
* name where it has one (Machine.name), and the adapter writes req.labels into the machine itself.
|
|
26
|
+
* req.labels and deletes what it finds.
|
|
28
27
|
*/
|
|
29
28
|
create(req: MachineRequest, ctx: HostCall): Promise<{
|
|
30
29
|
id: string;
|
|
@@ -43,10 +42,7 @@ export interface MachineHost {
|
|
|
43
42
|
* timer moved: E2B's). It may answer more machines than carry all the labels (a vendor that filters by some, or
|
|
44
43
|
* none): the adapter keeps those whose get does. A listing may lag a create: two creates of one request on two
|
|
45
44
|
* provider instances can then both make a machine, and the adapter deletes every one but the oldest (createdAt), so
|
|
46
|
-
* a vendor may see a second create deleted.
|
|
47
|
-
* name, else every machine: the adapter keeps those of the name and of our image (Machine.image), then reads each
|
|
48
|
-
* one's labels from inside it; one whose read fails or does not end is left out of that listing, in words, except
|
|
49
|
-
* from a listing by a request's name, which that read fails.
|
|
45
|
+
* a vendor may see a second create deleted.
|
|
50
46
|
*/
|
|
51
47
|
list(labels: Record<string, string>, ctx: HostCall): Promise<Machine[]>;
|
|
52
48
|
/**
|
|
@@ -73,7 +69,7 @@ export interface MachineHost {
|
|
|
73
69
|
* - stdout and stderr stay apart. wait() answers the process's own exit code. kill() ends the process in the
|
|
74
70
|
* machine, not only its streams.
|
|
75
71
|
* end() ends stdin where the vendor can (the adapter calls it at once for a command it gives no input); where it
|
|
76
|
-
* can't, end() does nothing, and nothing the adapter runs waits for it: its upload
|
|
72
|
+
* can't, end() does nothing, and nothing the adapter runs waits for it: its upload reads a
|
|
77
73
|
* length, a root command's input is one line, its bridge ends by kill(). A vendor whose exec comes in pieces (a start, an event stream, a call per write, no end or no kill) builds
|
|
78
74
|
* this from them with framedExec (./hosted/framed-exec.ts), as Daytona's does. The exec pre-check (conformance --exec-stream,
|
|
79
75
|
* src/conformance/exec-stream.ts) checks each of these on a machine made by hand, with exec alone.
|
|
@@ -99,7 +95,7 @@ export interface MachineHost {
|
|
|
99
95
|
* (a HostError limit, in words) when no end the vendor takes lands there without moving it earlier than it is or past
|
|
100
96
|
* the most: nothing moves then. The adapter reads the end back with get (deadlineOf, the deadline label: a vendor that
|
|
101
97
|
* keeps no label change reads its moved timer as that label), and init's deadline follows it. Optional: a host without
|
|
102
|
-
* it has no extend
|
|
98
|
+
* it has no extend.
|
|
103
99
|
*/
|
|
104
100
|
extend?(id: string, endsAt: Date, ctx: HostCall): Promise<void>;
|
|
105
101
|
/**
|
|
@@ -173,19 +169,8 @@ export interface MachineRequest {
|
|
|
173
169
|
*/
|
|
174
170
|
export interface Machine {
|
|
175
171
|
id: string;
|
|
176
|
-
/** Every label it carries, the adapter's own included
|
|
172
|
+
/** Every label it carries, the adapter's own included. */
|
|
177
173
|
labels: Record<string, string>;
|
|
178
|
-
/**
|
|
179
|
-
* With facts.labels "machine": the vendor's native name, the MachineRequest.name create gave it, where the vendor
|
|
180
|
-
* keeps one. A machine of a request's name whose labels are not written yet is the request's (provider.md).
|
|
181
|
-
*/
|
|
182
|
-
name?: string;
|
|
183
|
-
/**
|
|
184
|
-
* The image the vendor reads back for this machine. Required in practice with facts.labels "machine": list runs the
|
|
185
|
-
* label read only in a machine of the provider's image option or a box image (isBoxImage), and leaves one with none
|
|
186
|
-
* out, in words.
|
|
187
|
-
*/
|
|
188
|
-
image?: string;
|
|
189
174
|
/**
|
|
190
175
|
* starting: not yet running; stopped: there, not running, and not being deleted (paused, asleep): listed, so the
|
|
191
176
|
* janitor still ends it; gone: being deleted, ended, or failed (why says how).
|
|
@@ -248,12 +233,7 @@ export interface HostFacts {
|
|
|
248
233
|
* value together, the adapter's at their longest. Past either, check() refuses, and so create, before any host call.
|
|
249
234
|
* Absent: no bound. packed: the adapter packs the labels it gives create (packLabels, ./hosted/values.ts: one name to
|
|
250
235
|
* list by, the map in parts of at most valueBytes each), unpacks those get and list answer, and asks list for that
|
|
251
|
-
* name alone; the host stores and answers them as they are. count and bytes are then the packed labels'.
|
|
252
|
-
* the vendor keeps no labels, so the adapter writes them as JSON to a root-only file in the machine (LABEL_FILE,
|
|
253
|
-
* ./hosted/scripts.ts) right after it runs, and reads them back from it: at most 64 KiB as JSON, what a run's output
|
|
254
|
-
* keeps (OUTPUT_MAX, ./hosted/process.ts). Only with lifetime "vendor", since a machine whose labels were never
|
|
255
|
-
* written is ended by the vendor's timer alone, and no extend. get and list answer each machine's image
|
|
256
|
-
* (Machine.image): the labels are read only in one of ours.
|
|
236
|
+
* name alone; the host stores and answers them as they are. count and bytes are then the packed labels'.
|
|
257
237
|
*/
|
|
258
238
|
labels?: {
|
|
259
239
|
count?: number;
|
|
@@ -261,7 +241,7 @@ export interface HostFacts {
|
|
|
261
241
|
packed?: {
|
|
262
242
|
valueBytes?: number;
|
|
263
243
|
};
|
|
264
|
-
}
|
|
244
|
+
};
|
|
265
245
|
/**
|
|
266
246
|
* Paths of the vendor's image that root runs or reads and whose permissions its template build sets wider than
|
|
267
247
|
* root's: create makes each root's alone (owned by root, writable by no group or other user), and everything under a
|
|
@@ -272,7 +252,7 @@ export interface HostFacts {
|
|
|
272
252
|
* dial: the machine's computerd dials the server, and the host has no exec and no upload. The vendor boots the box
|
|
273
253
|
* image with MachineRequest.boot.env, where agentrun-dial fetches the server's daemon, checks its sha256, starts init
|
|
274
254
|
* and dials the attach route with the machine's own token; every connection goes over that socket
|
|
275
|
-
* (HostedOptions.dial).
|
|
255
|
+
* (HostedOptions.dial). Absent: the adapter connects through
|
|
276
256
|
* exec.
|
|
277
257
|
*/
|
|
278
258
|
connect?: "dial";
|
package/dist/hosted/process.d.ts
CHANGED
|
@@ -13,6 +13,16 @@ 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
|
+
* done() asked until it answers a value, pollMs apart: for an image build's waits (a build machine, a snapshot), all
|
|
18
|
+
* held to one end (epoch ms). Past the end is a timeout, the caller's abort aborted, each a HostError in words; an
|
|
19
|
+
* abort is read before each ask, so a cancelled caller is never answered a value it would act on.
|
|
20
|
+
*/
|
|
21
|
+
export declare function until<T>(what: string, { end, pollMs, signal }: {
|
|
22
|
+
end: number;
|
|
23
|
+
pollMs: number;
|
|
24
|
+
signal?: AbortSignal | undefined;
|
|
25
|
+
}, done: () => Promise<T | undefined>): Promise<T>;
|
|
16
26
|
/** A signal that aborts with the caller's, or once ms pass. */
|
|
17
27
|
export declare const bounded: (ms: number, signal?: AbortSignal) => AbortSignal;
|
|
18
28
|
/**
|
|
@@ -59,6 +69,15 @@ export declare function runToExit(host: MachineHost, id: string, argv: readonly
|
|
|
59
69
|
signal?: AbortSignal;
|
|
60
70
|
what: string;
|
|
61
71
|
}): Promise<Result<RunResult>>;
|
|
72
|
+
/**
|
|
73
|
+
* One step of an image build: argv run to its end as runToExit runs it, and anything but exit 0 thrown, a HostError
|
|
74
|
+
* (vendor) with the last of what it printed, so the build fails in the step's own words.
|
|
75
|
+
*/
|
|
76
|
+
export declare function runChecked(host: MachineHost, id: string, argv: readonly string[], options: {
|
|
77
|
+
ms: number;
|
|
78
|
+
signal?: AbortSignal | undefined;
|
|
79
|
+
what: string;
|
|
80
|
+
}): Promise<RunResult>;
|
|
62
81
|
/**
|
|
63
82
|
* The default upload, for a vendor with no file API: the bytes as base64 text through exec's stdin, in pieces, so a
|
|
64
83
|
* vendor whose stdin takes one request at a time (E2B's sendStdin) is never handed a whole binary, and exec carries text
|
package/dist/hosted/process.js
CHANGED
|
@@ -39,6 +39,23 @@ export const pause = (ms, signal) => new Promise((done) => {
|
|
|
39
39
|
else
|
|
40
40
|
signal?.addEventListener("abort", finish, { once: true });
|
|
41
41
|
});
|
|
42
|
+
/**
|
|
43
|
+
* done() asked until it answers a value, pollMs apart: for an image build's waits (a build machine, a snapshot), all
|
|
44
|
+
* held to one end (epoch ms). Past the end is a timeout, the caller's abort aborted, each a HostError in words; an
|
|
45
|
+
* abort is read before each ask, so a cancelled caller is never answered a value it would act on.
|
|
46
|
+
*/
|
|
47
|
+
export async function until(what, { end, pollMs, signal }, done) {
|
|
48
|
+
for (;;) {
|
|
49
|
+
if (signal?.aborted)
|
|
50
|
+
throw new HostError("aborted", `the wait for ${what} was aborted`);
|
|
51
|
+
const value = await done();
|
|
52
|
+
if (value !== undefined)
|
|
53
|
+
return value;
|
|
54
|
+
if (Date.now() > end)
|
|
55
|
+
throw new HostError("timeout", `${what} was not ready by ${new Date(end).toISOString()}`);
|
|
56
|
+
await pause(pollMs, signal);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
42
59
|
/** A signal that aborts with the caller's, or once ms pass. */
|
|
43
60
|
export const bounded = (ms, signal) => (signal ? AbortSignal.any([signal, AbortSignal.timeout(ms)]) : AbortSignal.timeout(ms));
|
|
44
61
|
/**
|
|
@@ -184,6 +201,17 @@ export async function runToExit(host, id, argv, { stdin, ms, signal, what }) {
|
|
|
184
201
|
}
|
|
185
202
|
return result;
|
|
186
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* One step of an image build: argv run to its end as runToExit runs it, and anything but exit 0 thrown, a HostError
|
|
206
|
+
* (vendor) with the last of what it printed, so the build fails in the step's own words.
|
|
207
|
+
*/
|
|
208
|
+
export async function runChecked(host, id, argv, options) {
|
|
209
|
+
const { ms, signal, what } = options;
|
|
210
|
+
const ran = orThrow(await runToExit(host, id, argv, { ms, ...(signal ? { signal } : {}), what }));
|
|
211
|
+
if (ran.exitCode !== 0)
|
|
212
|
+
throw new HostError("vendor", `${what} exited with ${ran.exitCode}: ${`${ran.stderr} ${ran.stdout}`.trim().slice(-300)}`);
|
|
213
|
+
return ran;
|
|
214
|
+
}
|
|
187
215
|
/** A piece of the upload: 192 KiB, which base64 writes as 256 KiB of text, padded at the file's end alone. */
|
|
188
216
|
const UPLOAD_PIECE = 192 * 1024;
|
|
189
217
|
/** The bytes as base64 text, a piece at a time: no more of it in memory at once than one piece. */
|
|
@@ -3,7 +3,7 @@ import { type DesktopOptions } from "../desktop.js";
|
|
|
3
3
|
import { type Machine, type MachineHost } from "../host.js";
|
|
4
4
|
import { type ProviderNote } from "../mount-archil.js";
|
|
5
5
|
import { type AttachedComputer, type AttachContext, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type CreateContext, type CreatedComputer, type NetworkPolicy, type NetworkSpec, type Refusal, type ReleaseContext, type ReleaseHow } from "../provider.js";
|
|
6
|
-
import { type Result } from "../result.js";
|
|
6
|
+
import { type ComputerError, type Result } from "../result.js";
|
|
7
7
|
import { type ScreenWatch, type ScreenWatchHandlers, type WatchOptions } from "../screen-watch.js";
|
|
8
8
|
/** The longest each kind of call may take, and the pauses between polls. */
|
|
9
9
|
export interface HostedTimeouts {
|
|
@@ -66,12 +66,6 @@ export interface HostedOptions {
|
|
|
66
66
|
* Given to the helper's mount and revoke. Unset or empty, the client reaches Archil as the machine's network allows.
|
|
67
67
|
*/
|
|
68
68
|
archilEgress?: string;
|
|
69
|
-
/**
|
|
70
|
-
* The image this provider's computers start from, where its setting names one, exactly as the vendor reads it back
|
|
71
|
-
* (Machine.image). With facts.labels "machine", list reads labels only in a machine of this image or a box image
|
|
72
|
-
* (isBoxImage, ../box-image.ts), and check refuses a spec of any other.
|
|
73
|
-
*/
|
|
74
|
-
image?: string;
|
|
75
69
|
/** What a host whose facts.connect is "dial" needs: create refuses without it, before any call to the vendor. */
|
|
76
70
|
dial?: HostedDial;
|
|
77
71
|
}
|
|
@@ -102,6 +96,12 @@ export declare const timeoutsOf: (timeouts?: Partial<HostedTimeouts>) => HostedT
|
|
|
102
96
|
* route serves, so the sha256 a dial machine checks (AGENTRUN_DAEMON_SHA256) is this file's.
|
|
103
97
|
*/
|
|
104
98
|
export declare function hostedDaemonPath(arch: "amd64" | "arm64"): string;
|
|
99
|
+
/**
|
|
100
|
+
* Whether a create that failed with code may have made a machine, so the request's name is swept. A refusal made
|
|
101
|
+
* nothing: a machine under the name then is another's (exists: another instance's create of the request), never
|
|
102
|
+
* deleted. Any other failure (the vendor's, a timeout) may have made one, answered in time or after create gave up.
|
|
103
|
+
*/
|
|
104
|
+
export declare const mayHaveMade: (code: ComputerError["code"]) => boolean;
|
|
105
105
|
/** An ISO time a label holds, or undefined when it is missing or not the ISO time create writes. */
|
|
106
106
|
export declare function isoOf(written: string | undefined): Date | undefined;
|
|
107
107
|
/**
|
|
@@ -172,26 +172,15 @@ export declare class HostedProvider implements ComputerProvider {
|
|
|
172
172
|
/**
|
|
173
173
|
* The host's listing by labels, bounded by ms: only the machines that carry every one of them, since a vendor's listing
|
|
174
174
|
* may answer more (MachineHost.list). A packed host is asked for PACKED_NAME alone, the name's where one is asked, and
|
|
175
|
-
* its machines' labels unpacked.
|
|
176
|
-
* left out, and the rest kept for foundBy to read.
|
|
175
|
+
* its machines' labels unpacked.
|
|
177
176
|
*/
|
|
178
177
|
export declare function listedBy(host: MachineHost, what: string, labels: Record<string, string>, ms: number, signal?: AbortSignal): Promise<Result<Machine[]>>;
|
|
179
|
-
/** What foundBy reads with: the timeouts, who hears of a machine a listing leaves out, and the provider's image option. */
|
|
180
|
-
type Finding = Pick<HostedTimeouts, "listMs" | "requestMs"> & {
|
|
181
|
-
onNote?: ProviderNote | undefined;
|
|
182
|
-
image?: string | undefined;
|
|
183
|
-
};
|
|
184
178
|
/**
|
|
185
179
|
* The listing finds, get answers (MachineHost.list): the machines the host's listing by labels names, each read now by
|
|
186
|
-
* readMachine, within requestMs
|
|
187
|
-
*
|
|
188
|
-
* labels are not written yet. A label file's read that fails or does not end within requestMs leaves its machine out of
|
|
189
|
-
* this listing alone, told through onNote by its id: one wedged machine never holds up the rest. A listing by a
|
|
190
|
-
* request's name is the exception: what is left of it may be the request's own, so such a read fails it, as a get that
|
|
191
|
-
* fails fails the whole. The label file is read only in a machine whose listed image is ours (ourImage): another's is
|
|
192
|
-
* left out unread, and one that shows no image is left out in words.
|
|
180
|
+
* readMachine, within requestMs. One the vendor no longer has (not found) is dropped, and so is one whose get carries
|
|
181
|
+
* not every label. A get that fails fails the whole listing.
|
|
193
182
|
*/
|
|
194
|
-
export declare function foundBy(host: MachineHost, what: string, labels: Record<string, string>, { listMs, requestMs
|
|
183
|
+
export declare function foundBy(host: MachineHost, what: string, labels: Record<string, string>, { listMs, requestMs }: Pick<HostedTimeouts, "listMs" | "requestMs">, signal?: AbortSignal): Promise<Result<Machine[]>>;
|
|
195
184
|
/**
|
|
196
185
|
* Waits, through waitUntil, until get answers none for a machine after its delete, twice running: the vendor no longer
|
|
197
186
|
* has it. A machine read gone is still going (a vendor still destroying it), so it holds the wait like any other state.
|