@parcha/agentrun-computer 0.1.0-beta.38 → 0.1.0-beta.40
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 +126 -83
- package/box/Dockerfile +5 -54
- package/box/README.md +9 -3
- package/box/build-daytona.py +2 -2
- package/box/build-e2b.mjs +1 -1
- package/box/install.sh +87 -0
- package/box/recipe.d.mts +5 -0
- package/box/recipe.mjs +12 -10
- package/dist/agent37.d.ts +17 -4
- package/dist/agent37.js +98 -17
- package/dist/box-image.d.ts +14 -0
- package/dist/box-image.js +24 -0
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +2 -2
- package/dist/conformance/agent37.d.ts +9 -4
- package/dist/conformance/agent37.js +23 -11
- package/dist/conformance/browserbase.js +3 -3
- package/dist/conformance/cases/apps.d.ts +1 -1
- package/dist/conformance/cases/apps.js +1 -1
- package/dist/conformance/cases/isolation.d.ts +18 -3
- package/dist/conformance/cases/isolation.js +73 -6
- package/dist/conformance/cases/lifetime.js +30 -0
- package/dist/conformance/cases/mount.js +4 -2
- package/dist/conformance/cases/provider.js +88 -1
- package/dist/conformance/cli.js +29 -9
- package/dist/conformance/e2b.js +9 -4
- package/dist/conformance/exec-stream.d.ts +44 -7
- package/dist/conformance/exec-stream.js +347 -88
- package/dist/conformance/kernel.js +2 -2
- package/dist/conformance/modal.js +1 -1
- package/dist/conformance/orgo.js +2 -2
- package/dist/conformance/report.js +3 -0
- package/dist/conformance/runner.js +127 -9
- package/dist/conformance/types.d.ts +21 -0
- package/dist/daytona.d.ts +0 -5
- package/dist/daytona.js +19 -28
- package/dist/descriptor.d.ts +5 -3
- package/dist/descriptors/agent37.d.ts +3 -11
- package/dist/descriptors/agent37.js +9 -10
- package/dist/descriptors/daytona.d.ts +1 -1
- package/dist/descriptors/daytona.js +5 -2
- package/dist/descriptors/docker.d.ts +13 -1
- package/dist/descriptors/docker.js +3 -1
- package/dist/descriptors/e2b.d.ts +2 -9
- package/dist/descriptors/e2b.js +8 -8
- package/dist/descriptors/index.d.ts +21 -19
- package/dist/descriptors/index.js +1 -3
- package/dist/descriptors/modal.d.ts +2 -6
- package/dist/descriptors/modal.js +8 -6
- package/dist/descriptors/orgo.js +2 -1
- package/dist/docker/egress-main.js +23 -15
- package/dist/docker/egress.d.ts +6 -4
- package/dist/docker/egress.js +24 -16
- package/dist/docker/inspect.d.ts +2 -2
- package/dist/docker/inspect.js +5 -5
- package/dist/docker.d.ts +6 -5
- package/dist/docker.js +12 -11
- package/dist/e2b.d.ts +12 -2
- package/dist/e2b.js +42 -19
- package/dist/host.d.ts +113 -59
- package/dist/host.js +5 -0
- package/dist/hosted/framed-exec.d.ts +49 -0
- package/dist/hosted/framed-exec.js +185 -0
- package/dist/hosted/network.d.ts +23 -0
- package/dist/hosted/network.js +77 -0
- package/dist/hosted/process.d.ts +13 -5
- package/dist/hosted/process.js +35 -12
- package/dist/hosted/provider.d.ts +16 -9
- package/dist/hosted/provider.js +475 -170
- package/dist/hosted/rest.d.ts +20 -2
- package/dist/hosted/rest.js +24 -10
- package/dist/hosted/scripts.d.ts +27 -7
- package/dist/hosted/scripts.js +77 -18
- package/dist/{agent37-ssh.d.ts → hosted/ssh-exec.d.ts} +19 -9
- package/dist/{agent37-ssh.js → hosted/ssh-exec.js} +38 -19
- package/dist/hosted/values.d.ts +21 -0
- package/dist/hosted/values.js +55 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/isolation.d.ts +0 -2
- package/dist/isolation.js +3 -4
- package/dist/modal.d.ts +8 -2
- package/dist/modal.js +21 -15
- package/dist/mount-archil.d.ts +5 -4
- package/dist/mount-archil.js +5 -6
- package/dist/orgo.js +6 -4
- package/dist/providers.d.ts +4 -1
- package/dist/surface/api.d.ts +0 -9
- package/dist/surface/core.d.ts +7 -2
- package/dist/surface/core.js +12 -4
- package/dist/surface/index.d.ts +1 -1
- package/dist/surface/index.js +1 -1
- package/dist/surface/script.d.ts +4 -0
- package/dist/surface/script.js +9 -3
- package/package.json +1 -1
- package/box/build-agent37.mjs +0 -158
package/dist/e2b.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HostedProvider, type HostedOptions, type HostedTimeouts } from "./hosted/provider.js";
|
|
2
|
+
import { type Result } from "./result.js";
|
|
2
3
|
/**
|
|
3
4
|
* What every SDK call is given: the key, the domain and the API URL explicitly, and debug false (index.mjs:1126-1152).
|
|
4
5
|
* The SDK's types below are `import type`: erased at build, so nothing loads the SDK from here and the published types
|
|
@@ -51,9 +52,18 @@ export declare function create(options: E2BOptions): Promise<E2BProvider>;
|
|
|
51
52
|
/** The conformance CLI's module for E2B: its live switch, the run's 30-minute cap, its template and the drifted twin. */
|
|
52
53
|
export declare const conformance: () => Promise<typeof import("./conformance/e2b.js")>;
|
|
53
54
|
/**
|
|
54
|
-
* Computers that are E2B sandboxes, on the shared adapter. A spec's image is an E2B template (its name or id)
|
|
55
|
-
*
|
|
55
|
+
* Computers that are E2B sandboxes, on the shared adapter. A spec's image is an E2B template (its name or id). A server
|
|
56
|
+
* starts every one, sandbox or desktop, from the box template prepareImage() answers: the box image (box/Dockerfile)
|
|
57
|
+
* with Archil's client and its root helper, Xvfb, xfwm4 and the desktop's apps, which the provider starts through
|
|
58
|
+
* computerd (desktop.ts). Any other template a spec names must carry what the computer's kind needs.
|
|
56
59
|
*/
|
|
57
60
|
export declare class E2BProvider extends HostedProvider {
|
|
61
|
+
/**
|
|
62
|
+
* The provider contract's prepareImage (its descriptor declares it): the box template the release publishes,
|
|
63
|
+
* public under its E2B team (box-image.ts boxE2bTemplate), which any E2B account starts by that name. No call: E2B
|
|
64
|
+
* starts a public template at create with nothing to pull ahead of it, so onWait is never told. A desktop starts
|
|
65
|
+
* from the same template as a sandbox: the kind is the provider's, not the image's.
|
|
66
|
+
*/
|
|
67
|
+
prepareImage(): Promise<Result<string>>;
|
|
58
68
|
constructor(options: E2BProviderOptions);
|
|
59
69
|
}
|
package/dist/e2b.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { boxE2bTemplate } from "./box-image.js";
|
|
2
|
+
import { E2B } from "./descriptors/e2b.js";
|
|
2
3
|
import { DEADLINE_LABEL, show } from "./drift.js";
|
|
3
4
|
import { HostError } from "./host.js";
|
|
4
5
|
import { deadlineOf, HostedProvider, isoOf, MAX_LABEL, timeoutsOf } from "./hosted/provider.js";
|
|
5
|
-
import {
|
|
6
|
-
import { dateOf, DOMAIN, isWhole } from "./hosted/values.js";
|
|
6
|
+
import { dateOf, DOMAIN, isWhole, sizeRefusals } from "./hosted/values.js";
|
|
7
7
|
import { PassThrough } from "node:stream";
|
|
8
|
+
import { ok } from "./result.js";
|
|
8
9
|
/** Not a literal, so no type checker or bundler resolves the SDK from this package. */
|
|
9
10
|
const E2B_PACKAGE = "e2b";
|
|
10
11
|
const DEFAULT_DOMAIN = "e2b.app";
|
|
@@ -58,6 +59,13 @@ const KEEPALIVE_HEADER = "Keepalive-Ping-Interval";
|
|
|
58
59
|
const KEEPALIVE_S = "50";
|
|
59
60
|
/** The Connect codes envd's process calls answer (connectrpc Code), as this provider's codes. */
|
|
60
61
|
const CONNECT_CODES = { 1: "aborted", 3: "invalid", 4: "timeout", 5: "not_found", 7: "denied", 8: "limit", 16: "denied" };
|
|
62
|
+
/** What create makes root's alone in every E2B computer, before anything else (HostFacts.rootOnly). */
|
|
63
|
+
const ROOT_ONLY = ["/usr/local", "/usr/bin/envd", "/etc/inittab"];
|
|
64
|
+
/** Root's command, as envd starts it: /bin/sh by its path, no login shell, the argv as its own words. */
|
|
65
|
+
const ROOT_SHELL = "/bin/sh";
|
|
66
|
+
const ROOT_SHELL_ARGS = ["-c", 'exec "$@"', "sh"];
|
|
67
|
+
/** The PATH root's command runs with: the system's directories alone, none of /usr/local. */
|
|
68
|
+
const ROOT_PATH = "/usr/sbin:/usr/bin:/sbin:/bin";
|
|
61
69
|
/** The SDK names its errors (index.mjs:86-360); Connect's carry a code. */
|
|
62
70
|
function codeOf(error) {
|
|
63
71
|
const name = error?.name;
|
|
@@ -86,7 +94,7 @@ function createdEnd({ metadata, startedAt }) {
|
|
|
86
94
|
const clearOf = (created) => created + END_SLACK_MS + 1_000;
|
|
87
95
|
/**
|
|
88
96
|
* A sandbox as the adapter reads a machine, from getInfo or the listing alike: E2B's state (a paused one is stopped), its
|
|
89
|
-
* start, its end. E2B keeps no metadata change, so once an extend moved its timer clear of create's end (
|
|
97
|
+
* start, its end. E2B keeps no metadata change, so once an extend moved its timer clear of create's end (extend), the
|
|
90
98
|
* deadline label reads that end, up to the most the computer may live: a restarted provider reads the extend all the same.
|
|
91
99
|
*/
|
|
92
100
|
function machineOf(info) {
|
|
@@ -114,8 +122,10 @@ class E2BHost {
|
|
|
114
122
|
maxLifetimeMs: PRO_MAX_MS,
|
|
115
123
|
arch: "amd64",
|
|
116
124
|
vendorAgentPorts: [ENVD_PORT],
|
|
117
|
-
//
|
|
125
|
+
// The box template has xfwm4 (box/Dockerfile), as E2B Desktop's has: the apps an agent opens are framed and focused.
|
|
118
126
|
windowManager: true,
|
|
127
|
+
// System paths whose permissions E2B's template build sets wider than root's, on its templates and ours alike.
|
|
128
|
+
rootOnly: ROOT_ONLY,
|
|
119
129
|
};
|
|
120
130
|
#Sandbox;
|
|
121
131
|
#connection;
|
|
@@ -134,27 +144,29 @@ class E2BHost {
|
|
|
134
144
|
#api(ms, signal) {
|
|
135
145
|
return { ...this.#connection, requestTimeoutMs: ms, ...(signal ? { signal } : {}) };
|
|
136
146
|
}
|
|
137
|
-
/** An E2B template is a name or id: letters, digits and ._:/- (no shell word, no path out). */
|
|
138
|
-
check(
|
|
139
|
-
|
|
140
|
-
|
|
147
|
+
/** An E2B template is a name or id: letters, digits and ._:/- (no shell word, no path out); its size is the template's. */
|
|
148
|
+
check(spec) {
|
|
149
|
+
const refusals = sizeRefusals(spec, "an E2B computer", "template");
|
|
150
|
+
if (typeof spec.image === "string" && spec.image !== "" && !TEMPLATE.test(spec.image)) {
|
|
151
|
+
refusals.push({ field: "image", message: `an image is the name or id of an E2B template, such as "${boxE2bTemplate()}" (the box template) or "desktop" (E2B Desktop)` });
|
|
141
152
|
}
|
|
142
|
-
return
|
|
153
|
+
return refusals;
|
|
143
154
|
}
|
|
144
155
|
/**
|
|
145
156
|
* Sandbox.create with the lifetime as its timeout in the whole seconds E2B takes (index.mjs:502-504), recorded in a
|
|
146
|
-
* label for its end's arithmetic; no internet access unless the adapter asks
|
|
157
|
+
* label for its end's arithmetic; no internet access unless the adapter asks egress (an Archil computer's root, or the
|
|
158
|
+
* egress proxy of a network open or a list), no
|
|
147
159
|
* public traffic (a project's default may let it in: E2B docs, network/restrict-public-access), and kill at the
|
|
148
160
|
* timeout, never a pause that keeps the computer (index.mjs:5674-5699).
|
|
149
161
|
*/
|
|
150
162
|
async create(req, ctx) {
|
|
151
|
-
const timeoutMs = Math.ceil(
|
|
163
|
+
const timeoutMs = Math.ceil(req.lifetimeMs / 1000) * 1000;
|
|
152
164
|
const options = {
|
|
153
165
|
...this.#api(ctx.timeoutMs),
|
|
154
166
|
timeoutMs,
|
|
155
167
|
metadata: { ...req.labels, [TIMEOUT_LABEL]: String(timeoutMs) },
|
|
156
168
|
envs: {},
|
|
157
|
-
allowInternetAccess: req.
|
|
169
|
+
allowInternetAccess: req.egress,
|
|
158
170
|
network: { allowPublicTraffic: false },
|
|
159
171
|
lifecycle: { onTimeout: "kill" },
|
|
160
172
|
};
|
|
@@ -215,9 +227,9 @@ class E2BHost {
|
|
|
215
227
|
await sandbox.files.write(path, buffer, { user: "root", requestTimeoutMs: ctx.timeoutMs, ...(ctx.signal ? { signal: ctx.signal } : {}) });
|
|
216
228
|
}
|
|
217
229
|
/**
|
|
218
|
-
* A process as root through envd's Process.Start stream,
|
|
219
|
-
*
|
|
220
|
-
* every 50 s. Its stdout and stderr are the bytes each data event carries, passed on as they come: commands.run would
|
|
230
|
+
* A process as root through envd's Process.Start stream, the call commands.run makes (index.mjs:5123-5146) without its
|
|
231
|
+
* login shell: /bin/sh by its path runs the argv as its own words, with PATH the system's directories alone, root by the
|
|
232
|
+
* Basic header (authenticationHeader, index.mjs:1896-1900), and envd's keepalive every 50 s. Its stdout and stderr are the bytes each data event carries, passed on as they come: commands.run would
|
|
221
233
|
* decode them as UTF-8 text first. No deadline on the stream (timeoutMs 0, which the Connect transport reads as none,
|
|
222
234
|
* connect-web connect-transport.js:145-150), so envd never ends it (start.go:39-44); the start alone is bounded by
|
|
223
235
|
* ctx. Writes go one sendStdin at a time, in order; end is closeStdin; kill SIGKILLs it and lets go of its stream.
|
|
@@ -228,7 +240,7 @@ class E2BHost {
|
|
|
228
240
|
const err = new PassThrough();
|
|
229
241
|
const requestTimeoutMs = this.#requestMs;
|
|
230
242
|
const stream = new AbortController();
|
|
231
|
-
const events = sandbox.commands.rpc.start({ process: { cmd:
|
|
243
|
+
const events = sandbox.commands.rpc.start({ process: { cmd: ROOT_SHELL, args: [...ROOT_SHELL_ARGS, ...argv], envs: { PATH: ROOT_PATH } }, stdin: true }, { headers: { Authorization: ROOT, [KEEPALIVE_HEADER]: KEEPALIVE_S }, signal: stream.signal, timeoutMs: 0 })[Symbol.asyncIterator]();
|
|
232
244
|
// The start, within ctx: a stream that gives no start event in time, or the caller's abort, is let go of.
|
|
233
245
|
const startAbort = () => stream.abort(ctx.signal?.reason);
|
|
234
246
|
ctx.signal?.addEventListener("abort", startAbort, { once: true });
|
|
@@ -326,10 +338,21 @@ class E2BHost {
|
|
|
326
338
|
}
|
|
327
339
|
}
|
|
328
340
|
/**
|
|
329
|
-
* Computers that are E2B sandboxes, on the shared adapter. A spec's image is an E2B template (its name or id)
|
|
330
|
-
*
|
|
341
|
+
* Computers that are E2B sandboxes, on the shared adapter. A spec's image is an E2B template (its name or id). A server
|
|
342
|
+
* starts every one, sandbox or desktop, from the box template prepareImage() answers: the box image (box/Dockerfile)
|
|
343
|
+
* with Archil's client and its root helper, Xvfb, xfwm4 and the desktop's apps, which the provider starts through
|
|
344
|
+
* computerd (desktop.ts). Any other template a spec names must carry what the computer's kind needs.
|
|
331
345
|
*/
|
|
332
346
|
export class E2BProvider extends HostedProvider {
|
|
347
|
+
/**
|
|
348
|
+
* The provider contract's prepareImage (its descriptor declares it): the box template the release publishes,
|
|
349
|
+
* public under its E2B team (box-image.ts boxE2bTemplate), which any E2B account starts by that name. No call: E2B
|
|
350
|
+
* starts a public template at create with nothing to pull ahead of it, so onWait is never told. A desktop starts
|
|
351
|
+
* from the same template as a sandbox: the kind is the provider's, not the image's.
|
|
352
|
+
*/
|
|
353
|
+
async prepareImage() {
|
|
354
|
+
return ok(boxE2bTemplate());
|
|
355
|
+
}
|
|
333
356
|
constructor(options) {
|
|
334
357
|
// A caller who still names the option is told it is gone, whatever its value: it once let public traffic in.
|
|
335
358
|
if (typeof options === "object" && options !== null && Object.hasOwn(options, "publicStream"))
|
package/dist/host.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ProviderDescriptor } from "./descriptor.js";
|
|
2
|
-
import type { ComputerCapabilities, ComputerSpec,
|
|
2
|
+
import type { ComputerCapabilities, ComputerSpec, GpuSpec, Refusal } from "./provider.js";
|
|
3
3
|
import type { ComputerErrorCode } from "./result.js";
|
|
4
4
|
/**
|
|
5
5
|
* One vendor's machines. Every call answers its value or throws: a failure whose code the host knows throws a
|
|
@@ -10,15 +10,21 @@ import type { ComputerErrorCode } from "./result.js";
|
|
|
10
10
|
export interface MachineHost {
|
|
11
11
|
/**
|
|
12
12
|
* The provider's descriptor (./descriptors): its id names the vendor of every error of code vendor, its label is the
|
|
13
|
-
* vendor in words, and capabilities() and check() read its network forms, mount kinds and unmounted kinds
|
|
13
|
+
* vendor in words, and capabilities() and check() read its network forms, mount kinds and unmounted kinds, and its
|
|
14
|
+
* configuration of the adapter's kind: the groups and GPUs.
|
|
14
15
|
*/
|
|
15
16
|
readonly descriptor: HostDescriptor;
|
|
16
17
|
readonly facts: HostFacts;
|
|
17
18
|
/**
|
|
18
19
|
* Makes one machine, by its options, and answers its id once the vendor has one. It does not wait for the machine to
|
|
19
|
-
* run (the adapter polls get while it is starting) or to be listed (the adapter waits for that too)
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* run (the adapter polls get while it is starting) or to be listed (the adapter waits for that too), except where the
|
|
21
|
+
* vendor applies a machine's settings only once it is ready: there it may wait for ready within ctx.timeoutMs, set
|
|
22
|
+
* them, and answer then (PROVIDERS.md, create). The machine
|
|
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
|
+
* the vendor already has throws exists (a REST host's named call: hosted/rest.ts), and the adapter adopts the machine
|
|
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. A host with facts.labels "machine" keeps neither: req.name is its native
|
|
27
|
+
* name where it has one (Machine.name), and the adapter writes req.labels into the machine itself.
|
|
22
28
|
*/
|
|
23
29
|
create(req: MachineRequest, ctx: HostCall): Promise<{
|
|
24
30
|
id: string;
|
|
@@ -32,7 +38,8 @@ export interface MachineHost {
|
|
|
32
38
|
* timer moved: E2B's). It may answer more machines than carry all the labels (a vendor that filters by some, or
|
|
33
39
|
* none): the adapter keeps those whose get does. A listing may lag a create: two creates of one request on two
|
|
34
40
|
* provider instances can then both make a machine, and the adapter deletes every one but the oldest (createdAt), so
|
|
35
|
-
* a vendor may see a second create deleted.
|
|
41
|
+
* a vendor may see a second create deleted. With facts.labels "machine" it lists by req.name where the vendor lists by
|
|
42
|
+
* name, else every machine: the adapter keeps those of the name, then reads each one's labels from inside it.
|
|
36
43
|
*/
|
|
37
44
|
list(labels: Record<string, string>, ctx: HostCall): Promise<Machine[]>;
|
|
38
45
|
/**
|
|
@@ -46,21 +53,25 @@ export interface MachineHost {
|
|
|
46
53
|
*
|
|
47
54
|
* exec is the whole protocol: the adapter installs and starts its daemon through it, then talks to the daemon over
|
|
48
55
|
* one exec'd process's stdin and stdout for the computer's whole life (the stdio bridge, spec/computer/stdio.md). So:
|
|
49
|
-
* - Two-way and live. Each write() reaches the process's stdin as it is written, and stdout and stderr
|
|
50
|
-
*
|
|
51
|
-
* -
|
|
52
|
-
* nothing added or dropped.
|
|
56
|
+
* - Two-way and live. Each write() reaches the process's stdin as it is written, and stdout and stderr come back as
|
|
57
|
+
* the process writes them, while it runs. Not request and response, never held until the process exits.
|
|
58
|
+
* - Text intact. UTF-8 text both ways, every code point as it was: long lines, \r and \r\n kept (no terminal, no
|
|
59
|
+
* newline translation), nothing added or dropped. Everything the adapter sends or reads is text (the bridge's JSON
|
|
60
|
+
* lines, its upload in base64), and each write() holds whole characters. An exec that carries bytes carries this.
|
|
53
61
|
* - No timeout. The process runs until it exits or kill() ends it: a vendor's command timeout, and any idle timeout
|
|
54
62
|
* on the stream, are off.
|
|
55
|
-
* - stdout and stderr stay apart. wait() answers the process's own exit code. kill() ends the process
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
63
|
+
* - stdout and stderr stay apart. wait() answers the process's own exit code. kill() ends the process in the
|
|
64
|
+
* machine, not only its streams.
|
|
65
|
+
* end() ends stdin where the vendor can (the adapter calls it at once for a command it gives no input); where it
|
|
66
|
+
* can't, end() does nothing, and nothing the adapter runs waits for it: its upload and its label file's write read a
|
|
67
|
+
* 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
|
|
68
|
+
* this from them with framedExec (./hosted/framed-exec.ts). The exec pre-check (conformance --exec-stream,
|
|
69
|
+
* src/conformance/exec-stream.ts) checks each of these on a machine made by hand, with exec alone.
|
|
59
70
|
*/
|
|
60
71
|
exec(id: string, argv: readonly string[], ctx: HostCall): Promise<MachineProcess>;
|
|
61
72
|
/**
|
|
62
73
|
* Puts bytes at path in the machine, as root. Optional: a vendor with no file API leaves it out, and the adapter
|
|
63
|
-
* streams the file through exec's stdin.
|
|
74
|
+
* streams the file through exec's stdin as base64 text, which root decodes (`base64 -d`, in coreutils and busybox).
|
|
64
75
|
*/
|
|
65
76
|
upload?(id: string, path: string, bytes: Uint8Array, ctx: HostCall): Promise<void>;
|
|
66
77
|
/**
|
|
@@ -74,16 +85,27 @@ export interface MachineHost {
|
|
|
74
85
|
* vendor's own timer (facts.lifetime "vendor"), or the janitor's deadline label (facts.lifetime "janitor"). A refusal
|
|
75
86
|
* (a HostError limit, in words) when no end the vendor takes lands there without moving it earlier than it is or past
|
|
76
87
|
* the most: nothing moves then. The adapter reads the end back with get (deadlineOf, the deadline label: a vendor that
|
|
77
|
-
* keeps no label change reads its moved timer as that label), and init's deadline follows it.
|
|
78
|
-
* it has no extend.
|
|
88
|
+
* keeps no label change reads its moved timer as that label), and init's deadline follows it. With facts.labels
|
|
89
|
+
* "machine", the adapter then moves the deadline label in the machine itself. Optional: a host without it has no extend.
|
|
79
90
|
*/
|
|
80
91
|
extend?(id: string, endsAt: Date, ctx: HostCall): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* The vendor's cheapest call that restarts its idle timer (facts.idleMs) on the machine: Cube's or E2B's setTimeout,
|
|
94
|
+
* Railway's heartbeat. The adapter calls it every idleMs / 3 from create, or attach, until release; one that fails is
|
|
95
|
+
* told through onNote and the next one tries again. Required with facts.idleMs; a host with no idle timer leaves it out.
|
|
96
|
+
*/
|
|
97
|
+
keepalive?(id: string, ctx: HostCall): Promise<void>;
|
|
81
98
|
/**
|
|
82
99
|
* The vendor's own rules of a spec, over the adapter's shared ones: an image name it takes, a GPU's image. No call. The
|
|
83
100
|
* spec is an object, as the caller gave it: its fields are not checked yet (an image may be a number).
|
|
84
101
|
*/
|
|
85
102
|
check?(spec: Partial<ComputerSpec>): Refusal[];
|
|
86
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* How far past the most a deadline may reach MachineRequest.backstopAt is: the janitor ends the machine first while the
|
|
106
|
+
* server runs, and the vendor's clock may be off from the server's.
|
|
107
|
+
*/
|
|
108
|
+
export declare const BACKSTOP_MARGIN_MS = 300000;
|
|
87
109
|
/** A host's failure whose code it knows: thrown by a host member, read by the adapter as that code, in these words. */
|
|
88
110
|
export declare class HostError extends Error {
|
|
89
111
|
readonly code: ComputerErrorCode;
|
|
@@ -94,7 +116,10 @@ export interface HostCall {
|
|
|
94
116
|
signal?: AbortSignal;
|
|
95
117
|
timeoutMs: number;
|
|
96
118
|
}
|
|
97
|
-
/**
|
|
119
|
+
/**
|
|
120
|
+
* What create asks of the vendor. A size (cpus, memoryMb) is passed whenever the spec gives one: a vendor whose size is
|
|
121
|
+
* its image's refuses it in its own check.
|
|
122
|
+
*/
|
|
98
123
|
export interface MachineRequest {
|
|
99
124
|
/** computer-<12 hex digits>, from the create's request id: the vendor's native name, or a label it lists by. */
|
|
100
125
|
name: string;
|
|
@@ -102,19 +127,27 @@ export interface MachineRequest {
|
|
|
102
127
|
image: string;
|
|
103
128
|
/** The caller's labels and the adapter's own (agentrun.computer*, the Archil mount's), every one to be read back. */
|
|
104
129
|
labels: Record<string, string>;
|
|
105
|
-
/**
|
|
106
|
-
lifetimeMs
|
|
130
|
+
/** The spec's lifetime: the vendor's timer (facts.lifetime "vendor"); a janitor's host may leave it. */
|
|
131
|
+
lifetimeMs: number;
|
|
132
|
+
/**
|
|
133
|
+
* An ISO time a margin past the most the machine's deadline may reach: create + maxLifetimeMs + BACKSTOP_MARGIN_MS. A
|
|
134
|
+
* janitor's host whose vendor has a delete or stop timer of its own sets it here (facts.backstop), so the machine still
|
|
135
|
+
* ends when the server that made it is gone. A vendor-lifetime host ignores it.
|
|
136
|
+
*/
|
|
137
|
+
backstopAt: string;
|
|
107
138
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
139
|
+
* Whether the machine reaches out: true for an Archil computer's root, which reaches Archil, and for a network open
|
|
140
|
+
* or a list, whose egress proxy init starts outside its tools' network (./hosted/network.ts). Its tools' own network
|
|
141
|
+
* is init's, loopback alone, read from inside, either way.
|
|
110
142
|
*/
|
|
111
|
-
|
|
143
|
+
egress: boolean;
|
|
112
144
|
/** facts.daemon "pid1" alone: the machine's main process (the entrypoint that waits for the daemon, then becomes init). */
|
|
113
145
|
command?: readonly string[];
|
|
146
|
+
/** A GPU computer's GPUs; the adapter records them in a label too, so no vendor reads them back. */
|
|
114
147
|
gpu?: GpuSpec;
|
|
115
148
|
cpus?: number;
|
|
116
149
|
memoryMb?: number;
|
|
117
|
-
|
|
150
|
+
/** With facts.user: the spec's user, uid:gid. */
|
|
118
151
|
user?: string;
|
|
119
152
|
}
|
|
120
153
|
/**
|
|
@@ -123,22 +156,25 @@ export interface MachineRequest {
|
|
|
123
156
|
*/
|
|
124
157
|
export interface Machine {
|
|
125
158
|
id: string;
|
|
126
|
-
/** Every label it carries, the adapter's own included. */
|
|
159
|
+
/** Every label it carries, the adapter's own included; with facts.labels "machine", none (the adapter reads them). */
|
|
127
160
|
labels: Record<string, string>;
|
|
161
|
+
/**
|
|
162
|
+
* With facts.labels "machine": the vendor's native name, the MachineRequest.name create gave it, where the vendor
|
|
163
|
+
* keeps one. A machine of a request's name whose labels are not written yet is the request's (provider.md).
|
|
164
|
+
*/
|
|
165
|
+
name?: string;
|
|
128
166
|
/**
|
|
129
167
|
* starting: not yet running; stopped: there, not running, and not being deleted (paused, asleep): listed, so the
|
|
130
168
|
* janitor still ends it; gone: being deleted, ended, or failed (why says how).
|
|
131
169
|
*/
|
|
132
170
|
state: "starting" | "running" | "stopped" | "gone";
|
|
133
|
-
/** With facts.lifetime "vendor": when the vendor's timer ends it. */
|
|
171
|
+
/** With facts.lifetime "vendor", or facts.backstop: when the vendor's timer ends it. */
|
|
134
172
|
endsAt?: Date;
|
|
135
173
|
/**
|
|
136
174
|
* When the vendor made it, by its clock, where it says. Two creates of one request on two provider instances can each
|
|
137
175
|
* make a machine before either is listed: the oldest is kept, by this, or by the lowest id where a machine has none.
|
|
138
176
|
*/
|
|
139
177
|
createdAt?: Date;
|
|
140
|
-
/** With facts.gpuReadBack: the GPUs the vendor reads back, absent for a machine with none. A retry is held to them. */
|
|
141
|
-
gpu?: GpuSpec;
|
|
142
178
|
/** The vendor's words for a machine that is gone because it failed: a create stops in them. */
|
|
143
179
|
why?: string;
|
|
144
180
|
}
|
|
@@ -146,56 +182,74 @@ export interface Machine {
|
|
|
146
182
|
export interface MachineProcess {
|
|
147
183
|
stdout: AsyncIterable<Uint8Array>;
|
|
148
184
|
stderr: AsyncIterable<Uint8Array>;
|
|
149
|
-
/** Writes to its stdin, in order; rejects once the process has ended. */
|
|
185
|
+
/** Writes UTF-8 text to its stdin, in order, whole characters each; rejects once the process has ended. */
|
|
150
186
|
write(bytes: Uint8Array): Promise<void>;
|
|
151
|
-
/** Ends its stdin, so it reads end of file. */
|
|
187
|
+
/** Ends its stdin, so it reads end of file, where the vendor can; else nothing (exec's doc). */
|
|
152
188
|
end(): Promise<void>;
|
|
153
189
|
/** Its exit code once it has ended. */
|
|
154
190
|
wait(): Promise<number>;
|
|
155
191
|
/** Ends it, best effort, and lets go of its streams; never throws. */
|
|
156
192
|
kill(): Promise<void>;
|
|
157
193
|
}
|
|
158
|
-
/**
|
|
159
|
-
|
|
160
|
-
|
|
194
|
+
/**
|
|
195
|
+
* What the host reads of its provider's descriptor: its id and label, its network forms and mounts, and its
|
|
196
|
+
* configurations, each kind's groups and GPUs.
|
|
197
|
+
*/
|
|
198
|
+
export type HostDescriptor = Pick<ProviderDescriptor, "id" | "label" | "network" | "mounts" | "unmounted" | "capabilities">;
|
|
199
|
+
/**
|
|
200
|
+
* What a vendor's machines are, static: with its descriptor (network, mounts, each kind's groups and GPUs) and the
|
|
201
|
+
* adapter's options, capabilities() is built from these alone.
|
|
202
|
+
*/
|
|
161
203
|
export interface HostFacts {
|
|
162
|
-
/**
|
|
204
|
+
/**
|
|
205
|
+
* child: the vendor's agent is the machine's first process and starts init, after the adapter closes the session
|
|
206
|
+
* buses in /tmp (/tmp/dbus-*) to the computer's user, since a network namespace does not cut a path socket. pid1:
|
|
207
|
+
* init is the machine's main process (Modal's, whose sandbox ends when it does), started by request.command.
|
|
208
|
+
*/
|
|
163
209
|
daemon: "child" | "pid1";
|
|
164
210
|
isolation: ComputerCapabilities["isolation"];
|
|
165
211
|
/** Who ends a machine at its deadline: the vendor's timer, or the janitor by label. */
|
|
166
212
|
lifetime: "vendor" | "janitor";
|
|
213
|
+
/**
|
|
214
|
+
* A janitor's host claims its create sets the vendor's own delete or stop timer from req.backstopAt, and get reads it
|
|
215
|
+
* back as endsAt (the Core case provider.backstop checks it). Only this lets a janitor's host keep labels "machine".
|
|
216
|
+
*/
|
|
217
|
+
backstop?: true;
|
|
167
218
|
/** The vendor's hard cap of a machine's life; the adapter's maxLifetimeMs may only lower it. */
|
|
168
219
|
maxLifetimeMs: number;
|
|
220
|
+
/**
|
|
221
|
+
* Where the vendor ends or pauses a machine no call reaches for a while (an idle timer that can't be switched off): that
|
|
222
|
+
* window, in whole ms. The adapter then calls keepalive every idleMs / 3 while it holds the machine. Default none.
|
|
223
|
+
*/
|
|
224
|
+
idleMs?: number;
|
|
169
225
|
arch: "amd64" | "arm64";
|
|
170
226
|
/** The TCP ports the vendor's own agent listens on inside the machine (E2B's envd 49983). */
|
|
171
227
|
vendorAgentPorts: number[];
|
|
172
|
-
/**
|
|
173
|
-
* The vendor's own path unix sockets outside /run, as shell patterns with no space (Daytona's D-Bus session bus,
|
|
174
|
-
* /tmp/dbus-*). Init takes others' access off every socket under /run itself; a child host's create does the same
|
|
175
|
-
* for each socket these name, as root, before init starts, since a network namespace does not cut a path socket.
|
|
176
|
-
*/
|
|
177
|
-
vendorSockets?: string[];
|
|
178
228
|
/** Whether its desktops run WINDOW_MANAGER (xfwm4, which its image has) once the display answers. Default none. */
|
|
179
229
|
windowManager?: boolean;
|
|
230
|
+
/** What spec.user may ask for, beside the daemon user: with it, the spec's user goes in MachineRequest.user. */
|
|
231
|
+
user?: Array<"root" | "uid">;
|
|
180
232
|
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
233
|
+
* The most a machine's labels may be, the adapter's own with the caller's: count, how many; bytes, every name and
|
|
234
|
+
* value together, the adapter's at their longest. Past either, check() refuses, and so create, before any host call.
|
|
235
|
+
* Absent: no bound. packed: the host stores the labels as packLabels packs them (./hosted/values.ts: one name to
|
|
236
|
+
* list by, the map in parts of at most valueBytes each) and get answers unpackLabels' map; count and bytes are then
|
|
237
|
+
* the packed labels'. "machine": the vendor keeps no labels, so the adapter writes them as JSON to a root-only file in
|
|
238
|
+
* the machine (LABEL_FILE, ./hosted/scripts.ts) right after it runs, and reads them back from it: at most 64 KiB as
|
|
239
|
+
* JSON, what a run's output keeps (OUTPUT_MAX, ./hosted/process.ts). Only with
|
|
240
|
+
* lifetime "vendor" or backstop: a machine whose labels were never written is ended by the vendor's timer alone.
|
|
183
241
|
*/
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
*
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
measure?: "pairs" | "json";
|
|
198
|
-
};
|
|
199
|
-
/** The runtime a machine of this request runs: "gvisor" only where the vendor runs one (a pid1 host's GPU). */
|
|
200
|
-
runtime?(req: MachineRequest): "vm" | "gvisor";
|
|
242
|
+
labels?: {
|
|
243
|
+
count?: number;
|
|
244
|
+
bytes?: number;
|
|
245
|
+
packed?: {
|
|
246
|
+
valueBytes?: number;
|
|
247
|
+
};
|
|
248
|
+
} | "machine";
|
|
249
|
+
/**
|
|
250
|
+
* Paths of the vendor's image that root runs or reads and whose permissions its template build sets wider than
|
|
251
|
+
* root's: create makes each root's alone (owned by root, writable by no group or other user), and everything under a
|
|
252
|
+
* directory, before the daemon's upload, so the computer's user can change nothing root runs. Default none.
|
|
253
|
+
*/
|
|
254
|
+
rootOnly?: readonly string[];
|
|
201
255
|
}
|
package/dist/host.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How far past the most a deadline may reach MachineRequest.backstopAt is: the janitor ends the machine first while the
|
|
3
|
+
* server runs, and the vendor's clock may be off from the server's.
|
|
4
|
+
*/
|
|
5
|
+
export const BACKSTOP_MARGIN_MS = 300_000;
|
|
1
6
|
/** A host's failure whose code it knows: thrown by a host member, read by the adapter as that code, in these words. */
|
|
2
7
|
export class HostError extends Error {
|
|
3
8
|
code;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { HostCall, MachineProcess } from "../host.js";
|
|
2
|
+
/** One event of a process: output on stdout or stderr, as text or as the base64 of its bytes; or its exit code. */
|
|
3
|
+
export type FramedEvent = {
|
|
4
|
+
stream: "stdout" | "stderr";
|
|
5
|
+
text: string;
|
|
6
|
+
} | {
|
|
7
|
+
stream: "stdout" | "stderr";
|
|
8
|
+
base64: string;
|
|
9
|
+
} | {
|
|
10
|
+
exit: number;
|
|
11
|
+
};
|
|
12
|
+
/** A vendor's exec, as calls about one process: P is what start answers, the vendor's own handle on it (an id). */
|
|
13
|
+
export interface ExecPieces<P> {
|
|
14
|
+
/** Starts argv in the machine as root, within ctx, and answers once it has started. */
|
|
15
|
+
start(argv: readonly string[], ctx: HostCall): Promise<P>;
|
|
16
|
+
/** The process's events from its start, in order; an end with no exit event is an exit the vendor never read (-1). */
|
|
17
|
+
events(handle: P): AsyncIterable<FramedEvent>;
|
|
18
|
+
/** One call that hands text to the process's stdin, answered once the vendor took it. */
|
|
19
|
+
write(handle: P, text: string): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Ends the process's stdin. Leave it out where the vendor has no end of file: end() then does nothing. The cost: a
|
|
22
|
+
* command that reads stdin to its end (cat, a sh reading its script) never ends, and only kill() stops it. Nothing
|
|
23
|
+
* the adapter runs does (its upload reads a length, a root command's input is one line, its bridge ends by kill).
|
|
24
|
+
*/
|
|
25
|
+
end?(handle: P): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Ends the process in the machine. Leave it out where the vendor has none: the process then starts under a sh that
|
|
28
|
+
* writes its pid and its start time on stderr first (framedExec reads that line and passes on the rest), and kill()
|
|
29
|
+
* starts a sh that kills that pid, and every process under it, only while that pid still has that start time.
|
|
30
|
+
*/
|
|
31
|
+
kill?(handle: P): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The sh a process starts under when the vendor has no kill: one line on stderr, its pid and its start time (field 22
|
|
35
|
+
* of /proc/<pid>/stat, counted past the command's name in parentheses, which may hold spaces), then the command in its
|
|
36
|
+
* place, which keeps both.
|
|
37
|
+
*/
|
|
38
|
+
export declare const PID_WRAPPER: string[];
|
|
39
|
+
/**
|
|
40
|
+
* The sh kill() starts, given the pid and start time: a pid whose process has ended, and may be another's now, is let
|
|
41
|
+
* be. Otherwise it kills the process and every process under it (an upload's head and base64 would wait on the open
|
|
42
|
+
* stdin, and hold stderr open, past their sh): each is stopped as it is found, so none forks away, by its parent pid
|
|
43
|
+
* (field 4 of its stat) until a pass over /proc finds no more, and then all are killed.
|
|
44
|
+
*/
|
|
45
|
+
export declare const PID_KILL: string;
|
|
46
|
+
/** argv started through a vendor's pieces, as the MachineProcess exec answers. */
|
|
47
|
+
export declare function framedExec<P>(pieces: ExecPieces<P>, argv: readonly string[], ctx: HostCall): Promise<MachineProcess>;
|
|
48
|
+
/** The JSON value of each line of a body of newline-delimited JSON, as the lines come; a line that is not JSON throws. */
|
|
49
|
+
export declare function ndjson(body: AsyncIterable<Uint8Array>): AsyncIterable<unknown>;
|