@parcha/agentrun-computer 0.1.0-beta.40 → 0.1.0-beta.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +2 -0
- package/README.md +285 -28
- package/box/Dockerfile +6 -4
- package/box/README.md +10 -2
- package/box/build-daytona.py +3 -1
- package/box/build-e2b.mjs +1 -1
- package/box/install.sh +68 -7
- package/dist/attach.d.ts +46 -1
- package/dist/attach.js +48 -4
- package/dist/box-image.d.ts +1 -1
- package/dist/box-image.js +1 -1
- package/dist/boxd.d.ts +126 -0
- package/dist/boxd.js +418 -0
- package/dist/cloudflare.d.ts +32 -0
- package/dist/cloudflare.js +179 -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/cases/provider.js +42 -26
- package/dist/conformance/cli.js +4 -1
- package/dist/conformance/cloudflare.d.ts +42 -0
- package/dist/conformance/cloudflare.js +54 -0
- package/dist/conformance/daytona.d.ts +25 -0
- package/dist/conformance/daytona.js +26 -1
- 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/exec-stream.js +14 -6
- 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 +5 -1
- package/dist/conformance/sweep.d.ts +1 -1
- package/dist/conformance/sweep.js +1 -1
- package/dist/conformance/types.d.ts +21 -0
- package/dist/daytona.d.ts +8 -1
- package/dist/daytona.js +124 -101
- package/dist/descriptor.d.ts +22 -1
- package/dist/descriptor.js +18 -0
- 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/daytona.d.ts +12 -3
- package/dist/descriptors/daytona.js +15 -7
- 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 +121 -2
- 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 +52 -48
- package/dist/hosted/framed-exec.d.ts +8 -19
- package/dist/hosted/framed-exec.js +21 -87
- package/dist/hosted/process.d.ts +21 -0
- package/dist/hosted/process.js +37 -2
- package/dist/hosted/provider.d.ts +32 -6
- package/dist/hosted/provider.js +239 -236
- package/dist/hosted/rest.d.ts +19 -0
- package/dist/hosted/rest.js +76 -0
- package/dist/hosted/scripts.d.ts +52 -8
- package/dist/hosted/scripts.js +118 -23
- package/dist/hosted/ssh-exec.d.ts +9 -7
- package/dist/hosted/ssh-exec.js +93 -54
- package/dist/hosted/values.d.ts +5 -0
- package/dist/hosted/values.js +9 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -4
- package/dist/kinds.d.ts +2 -0
- package/dist/modal.d.ts +6 -0
- package/dist/modal.js +40 -17
- 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/providers.d.ts +4 -2
- package/dist/screen-watch.js +2 -2
- package/package.json +20 -2
package/dist/fly.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { HostedProvider, type HostedOptions, type HostedTimeouts } from "./hosted/provider.js";
|
|
2
|
+
import { type Result } from "./result.js";
|
|
3
|
+
/** One machine as the Machines API answers it (M, "Machine properties"; fly-go Machine), as far as this host reads it. */
|
|
4
|
+
export interface FlyMachine {
|
|
5
|
+
id: string;
|
|
6
|
+
state: string;
|
|
7
|
+
created_at?: string;
|
|
8
|
+
config?: {
|
|
9
|
+
metadata?: Record<string, string> | null;
|
|
10
|
+
} | null;
|
|
11
|
+
/** fly-go: the config rebuilt in part while host_status isn't "ok". */
|
|
12
|
+
incomplete_config?: {
|
|
13
|
+
metadata?: Record<string, string> | null;
|
|
14
|
+
} | null;
|
|
15
|
+
}
|
|
16
|
+
/** The Fly provider's options: the token and the app, then the shared adapter's (HostedOptions). */
|
|
17
|
+
export interface FlyProviderOptions extends Omit<HostedOptions, "kind" | "desktop" | "maxLifetimeMs"> {
|
|
18
|
+
/** A Fly API token that may make machines in the app. The caller passes it; this provider reads no environment. */
|
|
19
|
+
apiToken: string;
|
|
20
|
+
/** The Fly app the machines live in, made by the operator beforehand (fly apps create). */
|
|
21
|
+
app: string;
|
|
22
|
+
/** The fetch every call goes through; default the global one. */
|
|
23
|
+
fetch?: typeof fetch;
|
|
24
|
+
/** The longest lifetime check takes, in ms: at most 24 h, the janitor's cap, which is the default. */
|
|
25
|
+
maxLifetimeMs?: number;
|
|
26
|
+
timeouts?: Partial<HostedTimeouts>;
|
|
27
|
+
}
|
|
28
|
+
/** A FlyProvider from its options alone; it reads no environment (serve passes the saved FLY_API_TOKEN and FLY_APP). */
|
|
29
|
+
export declare function create(options: FlyProviderOptions): FlyProvider;
|
|
30
|
+
/** The conformance CLI's module for Fly Machines: its settings, and its dialKit that refuses off the public server. */
|
|
31
|
+
export declare const conformance: () => Promise<typeof import("./conformance/fly.js")>;
|
|
32
|
+
/**
|
|
33
|
+
* Computers that are Fly Machines, on the shared adapter, each dialing the server that made it: a server with no public
|
|
34
|
+
* https address (AGENTRUN_PUBLIC_URL) refuses a create in words before Fly is called. Kind linux alone.
|
|
35
|
+
*/
|
|
36
|
+
export declare class FlyProvider extends HostedProvider {
|
|
37
|
+
/**
|
|
38
|
+
* The provider contract's prepareImage (its descriptor declares it): the box image the release publishes, by its
|
|
39
|
+
* public registry tag (box-image.ts). No call: Fly pulls config.image at each create.
|
|
40
|
+
*/
|
|
41
|
+
prepareImage(): Promise<Result<string>>;
|
|
42
|
+
constructor(options: FlyProviderOptions);
|
|
43
|
+
}
|
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,13 +23,17 @@ 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;
|
|
31
30
|
}>;
|
|
32
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* One machine as the vendor reads it now; undefined once the vendor no longer has it (not found is that, or a
|
|
33
|
+
* HostError not_found), and for a record the vendor keeps of a machine that is deleted and will not come back
|
|
34
|
+
* (Hyperbrowser's closed, Blaxel's TERMINATED), which list leaves out too. gone is one still being destroyed: it holds
|
|
35
|
+
* the wait after a delete, so a host that reads a kept record gone waits out goneMs on every delete.
|
|
36
|
+
*/
|
|
33
37
|
get(id: string, ctx: HostCall): Promise<Machine | undefined>;
|
|
34
38
|
/**
|
|
35
39
|
* The machines of the account the vendor's listing shows for these labels, every page, within ctx.timeoutMs in all.
|
|
@@ -38,8 +42,7 @@ export interface MachineHost {
|
|
|
38
42
|
* timer moved: E2B's). It may answer more machines than carry all the labels (a vendor that filters by some, or
|
|
39
43
|
* none): the adapter keeps those whose get does. A listing may lag a create: two creates of one request on two
|
|
40
44
|
* provider instances can then both make a machine, and the adapter deletes every one but the oldest (createdAt), so
|
|
41
|
-
* a vendor may see a second create deleted.
|
|
42
|
-
* name, else every machine: the adapter keeps those of the name, then reads each one's labels from inside it.
|
|
45
|
+
* a vendor may see a second create deleted.
|
|
43
46
|
*/
|
|
44
47
|
list(labels: Record<string, string>, ctx: HostCall): Promise<Machine[]>;
|
|
45
48
|
/**
|
|
@@ -57,18 +60,24 @@ export interface MachineHost {
|
|
|
57
60
|
* the process writes them, while it runs. Not request and response, never held until the process exits.
|
|
58
61
|
* - Text intact. UTF-8 text both ways, every code point as it was: long lines, \r and \r\n kept (no terminal, no
|
|
59
62
|
* 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.
|
|
63
|
+
* lines, its upload in base64), and each write() holds whole characters. An exec that carries bytes carries this. A
|
|
64
|
+
* vendor whose input call ends what it is given with a newline (Daytona's) holds a write's last partial line until
|
|
65
|
+
* its newline or end(), so the process reads its stdin as written: the bridge's lines end in one, and what is
|
|
66
|
+
* read by length is followed by end().
|
|
61
67
|
* - No timeout. The process runs until it exits or kill() ends it: a vendor's command timeout, and any idle timeout
|
|
62
68
|
* on the stream, are off.
|
|
63
69
|
* - stdout and stderr stay apart. wait() answers the process's own exit code. kill() ends the process in the
|
|
64
70
|
* machine, not only its streams.
|
|
65
71
|
* 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
|
|
72
|
+
* can't, end() does nothing, and nothing the adapter runs waits for it: its upload reads a
|
|
67
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
|
|
68
|
-
* this from them with framedExec (./hosted/framed-exec.ts). The exec pre-check (conformance --exec-stream,
|
|
74
|
+
* this from them with framedExec (./hosted/framed-exec.ts), as Daytona's does. The exec pre-check (conformance --exec-stream,
|
|
69
75
|
* src/conformance/exec-stream.ts) checks each of these on a machine made by hand, with exec alone.
|
|
76
|
+
*
|
|
77
|
+
* Every host has it but one whose facts.connect is "dial", which has none (and no upload): its machine's computerd
|
|
78
|
+
* dials the server instead.
|
|
70
79
|
*/
|
|
71
|
-
exec(id: string, argv: readonly string[], ctx: HostCall): Promise<MachineProcess>;
|
|
80
|
+
exec?(id: string, argv: readonly string[], ctx: HostCall): Promise<MachineProcess>;
|
|
72
81
|
/**
|
|
73
82
|
* Puts bytes at path in the machine, as root. Optional: a vendor with no file API leaves it out, and the adapter
|
|
74
83
|
* streams the file through exec's stdin as base64 text, which root decodes (`base64 -d`, in coreutils and busybox).
|
|
@@ -85,16 +94,10 @@ export interface MachineHost {
|
|
|
85
94
|
* vendor's own timer (facts.lifetime "vendor"), or the janitor's deadline label (facts.lifetime "janitor"). A refusal
|
|
86
95
|
* (a HostError limit, in words) when no end the vendor takes lands there without moving it earlier than it is or past
|
|
87
96
|
* the most: nothing moves then. The adapter reads the end back with get (deadlineOf, the deadline label: a vendor that
|
|
88
|
-
* keeps no label change reads its moved timer as that label), and init's deadline follows it.
|
|
89
|
-
*
|
|
97
|
+
* keeps no label change reads its moved timer as that label), and init's deadline follows it. Optional: a host without
|
|
98
|
+
* it has no extend.
|
|
90
99
|
*/
|
|
91
100
|
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>;
|
|
98
101
|
/**
|
|
99
102
|
* 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
|
|
100
103
|
* spec is an object, as the caller gave it: its fields are not checked yet (an image may be a number).
|
|
@@ -131,14 +134,15 @@ export interface MachineRequest {
|
|
|
131
134
|
lifetimeMs: number;
|
|
132
135
|
/**
|
|
133
136
|
* 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
|
|
135
|
-
*
|
|
137
|
+
* janitor's host whose vendor has a delete or stop timer of its own sets it here, so the machine still ends when the
|
|
138
|
+
* server that made it is gone. A vendor-lifetime host ignores it.
|
|
136
139
|
*/
|
|
137
140
|
backstopAt: string;
|
|
138
141
|
/**
|
|
139
142
|
* 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)
|
|
141
|
-
*
|
|
143
|
+
* or a list, whose egress proxy init starts outside its tools' network (./hosted/network.ts), and for every dial
|
|
144
|
+
* machine (boot), which fetches its daemon from the server and dials it. Its tools' own network is init's, loopback
|
|
145
|
+
* alone, read from inside, either way.
|
|
142
146
|
*/
|
|
143
147
|
egress: boolean;
|
|
144
148
|
/** facts.daemon "pid1" alone: the machine's main process (the entrypoint that waits for the daemon, then becomes init). */
|
|
@@ -149,6 +153,15 @@ export interface MachineRequest {
|
|
|
149
153
|
memoryMb?: number;
|
|
150
154
|
/** With facts.user: the spec's user, uid:gid. */
|
|
151
155
|
user?: string;
|
|
156
|
+
/**
|
|
157
|
+
* facts.connect "dial" alone: what the machine's environment holds, every name and value as given, in the vendor's
|
|
158
|
+
* secret-env field where it has one. The box image's agentrun-dial reads it (spec/computer/attach.md, Hosted machines
|
|
159
|
+
* that dial): AGENTRUN_ATTACH_URL, AGENTRUN_ATTACH_TOKEN, AGENTRUN_DAEMON_URL, AGENTRUN_DAEMON_SHA256 and
|
|
160
|
+
* AGENTRUN_INIT_ARGS.
|
|
161
|
+
*/
|
|
162
|
+
boot?: {
|
|
163
|
+
env: Record<string, string>;
|
|
164
|
+
};
|
|
152
165
|
}
|
|
153
166
|
/**
|
|
154
167
|
* One machine as the vendor reads it back. The adapter holds the rest itself: what create asked is in the labels, what
|
|
@@ -156,19 +169,14 @@ export interface MachineRequest {
|
|
|
156
169
|
*/
|
|
157
170
|
export interface Machine {
|
|
158
171
|
id: string;
|
|
159
|
-
/** Every label it carries, the adapter's own included
|
|
172
|
+
/** Every label it carries, the adapter's own included. */
|
|
160
173
|
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;
|
|
166
174
|
/**
|
|
167
175
|
* starting: not yet running; stopped: there, not running, and not being deleted (paused, asleep): listed, so the
|
|
168
176
|
* janitor still ends it; gone: being deleted, ended, or failed (why says how).
|
|
169
177
|
*/
|
|
170
178
|
state: "starting" | "running" | "stopped" | "gone";
|
|
171
|
-
/** With facts.lifetime "vendor"
|
|
179
|
+
/** With facts.lifetime "vendor": when the vendor's timer ends it. */
|
|
172
180
|
endsAt?: Date;
|
|
173
181
|
/**
|
|
174
182
|
* When the vendor made it, by its clock, where it says. Two creates of one request on two provider instances can each
|
|
@@ -202,26 +210,17 @@ export type HostDescriptor = Pick<ProviderDescriptor, "id" | "label" | "network"
|
|
|
202
210
|
*/
|
|
203
211
|
export interface HostFacts {
|
|
204
212
|
/**
|
|
205
|
-
* child: the vendor
|
|
206
|
-
* buses in /tmp (/tmp/dbus-*) to the computer's user, since a network namespace does not cut a
|
|
207
|
-
* init is the machine's main process (Modal's, whose sandbox ends when it does), started by
|
|
213
|
+
* child: the vendor starts the adapter's processes through exec, and the adapter starts init that way at boot, after
|
|
214
|
+
* it closes the session buses in /tmp (/tmp/dbus-*) to the computer's user, since a network namespace does not cut a
|
|
215
|
+
* path socket. pid1: init is the machine's main process (Modal's, whose sandbox ends when it does), started by
|
|
216
|
+
* request.command.
|
|
208
217
|
*/
|
|
209
218
|
daemon: "child" | "pid1";
|
|
210
219
|
isolation: ComputerCapabilities["isolation"];
|
|
211
220
|
/** Who ends a machine at its deadline: the vendor's timer, or the janitor by label. */
|
|
212
221
|
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;
|
|
218
222
|
/** The vendor's hard cap of a machine's life; the adapter's maxLifetimeMs may only lower it. */
|
|
219
223
|
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;
|
|
225
224
|
arch: "amd64" | "arm64";
|
|
226
225
|
/** The TCP ports the vendor's own agent listens on inside the machine (E2B's envd 49983). */
|
|
227
226
|
vendorAgentPorts: number[];
|
|
@@ -232,12 +231,9 @@ export interface HostFacts {
|
|
|
232
231
|
/**
|
|
233
232
|
* The most a machine's labels may be, the adapter's own with the caller's: count, how many; bytes, every name and
|
|
234
233
|
* 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
|
|
236
|
-
* list by, the map in parts of at most valueBytes each)
|
|
237
|
-
*
|
|
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.
|
|
234
|
+
* Absent: no bound. packed: the adapter packs the labels it gives create (packLabels, ./hosted/values.ts: one name to
|
|
235
|
+
* list by, the map in parts of at most valueBytes each), unpacks those get and list answer, and asks list for that
|
|
236
|
+
* name alone; the host stores and answers them as they are. count and bytes are then the packed labels'.
|
|
241
237
|
*/
|
|
242
238
|
labels?: {
|
|
243
239
|
count?: number;
|
|
@@ -245,11 +241,19 @@ export interface HostFacts {
|
|
|
245
241
|
packed?: {
|
|
246
242
|
valueBytes?: number;
|
|
247
243
|
};
|
|
248
|
-
}
|
|
244
|
+
};
|
|
249
245
|
/**
|
|
250
246
|
* Paths of the vendor's image that root runs or reads and whose permissions its template build sets wider than
|
|
251
247
|
* root's: create makes each root's alone (owned by root, writable by no group or other user), and everything under a
|
|
252
248
|
* directory, before the daemon's upload, so the computer's user can change nothing root runs. Default none.
|
|
253
249
|
*/
|
|
254
250
|
rootOnly?: readonly string[];
|
|
251
|
+
/**
|
|
252
|
+
* dial: the machine's computerd dials the server, and the host has no exec and no upload. The vendor boots the box
|
|
253
|
+
* image with MachineRequest.boot.env, where agentrun-dial fetches the server's daemon, checks its sha256, starts init
|
|
254
|
+
* and dials the attach route with the machine's own token; every connection goes over that socket
|
|
255
|
+
* (HostedOptions.dial). Absent: the adapter connects through
|
|
256
|
+
* exec.
|
|
257
|
+
*/
|
|
258
|
+
connect?: "dial";
|
|
255
259
|
}
|
|
@@ -13,7 +13,11 @@ export type FramedEvent = {
|
|
|
13
13
|
export interface ExecPieces<P> {
|
|
14
14
|
/** Starts argv in the machine as root, within ctx, and answers once it has started. */
|
|
15
15
|
start(argv: readonly string[], ctx: HostCall): Promise<P>;
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* The process's events from its start, in order; an end with no exit event is an exit the vendor never read (-1),
|
|
18
|
+
* and one that throws fails wait() with its error. framedExec stops reading at the exit event, which returns the
|
|
19
|
+
* iterator: a generator's finally lets go of what it holds.
|
|
20
|
+
*/
|
|
17
21
|
events(handle: P): AsyncIterable<FramedEvent>;
|
|
18
22
|
/** One call that hands text to the process's stdin, answered once the vendor took it. */
|
|
19
23
|
write(handle: P, text: string): Promise<void>;
|
|
@@ -24,26 +28,11 @@ export interface ExecPieces<P> {
|
|
|
24
28
|
*/
|
|
25
29
|
end?(handle: P): Promise<void>;
|
|
26
30
|
/**
|
|
27
|
-
* Ends the process in the machine. Leave it out where the vendor has none: the process then starts under
|
|
28
|
-
* writes its pid and its start time on stderr first (framedExec
|
|
29
|
-
* starts
|
|
31
|
+
* Ends the process in the machine. Leave it out where the vendor has none: the process then starts under
|
|
32
|
+
* PID_WRAPPER (./scripts.ts), which writes its pid and its start time on stderr first (framedExec takes that line off),
|
|
33
|
+
* and kill() starts pidKill, which kills that pid, and every process under it, only while that pid has that start time.
|
|
30
34
|
*/
|
|
31
35
|
kill?(handle: P): Promise<void>;
|
|
32
36
|
}
|
|
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
37
|
/** argv started through a vendor's pieces, as the MachineProcess exec answers. */
|
|
47
38
|
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>;
|