@parcha/agentrun-computer 0.0.0-stage → 0.1.0-beta.33
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/LICENSE +202 -0
- package/NOTICE +8 -0
- package/README.md +2411 -2
- package/box/Dockerfile +69 -0
- package/box/agentrun-archil +168 -0
- package/box/build-daytona.py +26 -0
- package/box/build-e2b.mjs +32 -0
- package/box/build-modal.py +17 -0
- package/dist/actions.d.ts +18 -0
- package/dist/actions.js +139 -0
- package/dist/browser.d.ts +151 -0
- package/dist/browser.js +305 -0
- package/dist/browserbase.d.ts +139 -0
- package/dist/browserbase.js +408 -0
- package/dist/child.d.ts +40 -0
- package/dist/child.js +127 -0
- package/dist/client.d.ts +22 -0
- package/dist/client.js +136 -0
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/conformance/archil.d.ts +68 -0
- package/dist/conformance/archil.js +152 -0
- package/dist/conformance/browserbase.d.ts +35 -0
- package/dist/conformance/browserbase.js +45 -0
- package/dist/conformance/cases/apps.d.ts +2 -0
- package/dist/conformance/cases/apps.js +155 -0
- package/dist/conformance/cases/browser.d.ts +4 -0
- package/dist/conformance/cases/browser.js +105 -0
- package/dist/conformance/cases/drift.d.ts +2 -0
- package/dist/conformance/cases/drift.js +64 -0
- package/dist/conformance/cases/exec.d.ts +2 -0
- package/dist/conformance/cases/exec.js +125 -0
- package/dist/conformance/cases/files.d.ts +2 -0
- package/dist/conformance/cases/files.js +294 -0
- package/dist/conformance/cases/health.d.ts +2 -0
- package/dist/conformance/cases/health.js +71 -0
- package/dist/conformance/cases/index.d.ts +9 -0
- package/dist/conformance/cases/index.js +37 -0
- package/dist/conformance/cases/input.d.ts +12 -0
- package/dist/conformance/cases/input.js +109 -0
- package/dist/conformance/cases/isolation.d.ts +21 -0
- package/dist/conformance/cases/isolation.js +98 -0
- package/dist/conformance/cases/lifetime.d.ts +2 -0
- package/dist/conformance/cases/lifetime.js +64 -0
- package/dist/conformance/cases/mount.d.ts +2 -0
- package/dist/conformance/cases/mount.js +252 -0
- package/dist/conformance/cases/process.d.ts +2 -0
- package/dist/conformance/cases/process.js +240 -0
- package/dist/conformance/cases/provider.d.ts +2 -0
- package/dist/conformance/cases/provider.js +302 -0
- package/dist/conformance/cases/screen.d.ts +9 -0
- package/dist/conformance/cases/screen.js +230 -0
- package/dist/conformance/cases/settings.d.ts +57 -0
- package/dist/conformance/cases/settings.js +142 -0
- package/dist/conformance/cases/touch.d.ts +2 -0
- package/dist/conformance/cases/touch.js +117 -0
- package/dist/conformance/cases/util.d.ts +7 -0
- package/dist/conformance/cases/util.js +8 -0
- package/dist/conformance/cdp.d.ts +13 -0
- package/dist/conformance/cdp.js +88 -0
- package/dist/conformance/cli.d.ts +29 -0
- package/dist/conformance/cli.js +231 -0
- package/dist/conformance/daytona-sweep.d.ts +18 -0
- package/dist/conformance/daytona-sweep.js +126 -0
- package/dist/conformance/daytona.d.ts +83 -0
- package/dist/conformance/daytona.js +107 -0
- package/dist/conformance/docker.d.ts +38 -0
- package/dist/conformance/docker.js +70 -0
- package/dist/conformance/drift-daemon.d.ts +8 -0
- package/dist/conformance/drift-daemon.js +41 -0
- package/dist/conformance/e2b-diagnose.d.ts +16 -0
- package/dist/conformance/e2b-diagnose.js +61 -0
- package/dist/conformance/e2b-sweep.d.ts +18 -0
- package/dist/conformance/e2b-sweep.js +132 -0
- package/dist/conformance/e2b.d.ts +74 -0
- package/dist/conformance/e2b.js +111 -0
- package/dist/conformance/fixture.d.ts +65 -0
- package/dist/conformance/fixture.js +98 -0
- package/dist/conformance/index.d.ts +8 -0
- package/dist/conformance/index.js +8 -0
- package/dist/conformance/kernel.d.ts +31 -0
- package/dist/conformance/kernel.js +40 -0
- package/dist/conformance/kind.d.ts +23 -0
- package/dist/conformance/kind.js +58 -0
- package/dist/conformance/modal-sweep.d.ts +22 -0
- package/dist/conformance/modal-sweep.js +213 -0
- package/dist/conformance/modal.d.ts +69 -0
- package/dist/conformance/modal.js +76 -0
- package/dist/conformance/orgo.d.ts +41 -0
- package/dist/conformance/orgo.js +69 -0
- package/dist/conformance/phone-harness.d.ts +61 -0
- package/dist/conformance/phone-harness.js +241 -0
- package/dist/conformance/png.d.ts +16 -0
- package/dist/conformance/png.js +132 -0
- package/dist/conformance/report.d.ts +2 -0
- package/dist/conformance/report.js +86 -0
- package/dist/conformance/runner.d.ts +11 -0
- package/dist/conformance/runner.js +585 -0
- package/dist/conformance/tar.d.ts +13 -0
- package/dist/conformance/tar.js +105 -0
- package/dist/conformance/types.d.ts +257 -0
- package/dist/conformance/types.js +24 -0
- package/dist/daemon-copy.d.ts +40 -0
- package/dist/daemon-copy.js +259 -0
- package/dist/daytona.d.ts +180 -0
- package/dist/daytona.js +1498 -0
- package/dist/desktop.d.ts +24 -0
- package/dist/desktop.js +68 -0
- package/dist/docker/egress-main.d.ts +1 -0
- package/dist/docker/egress-main.js +68 -0
- package/dist/docker/egress-proxy.d.ts +53 -0
- package/dist/docker/egress-proxy.js +450 -0
- package/dist/docker/egress-table.d.ts +39 -0
- package/dist/docker/egress-table.js +197 -0
- package/dist/docker/egress.d.ts +109 -0
- package/dist/docker/egress.js +318 -0
- package/dist/docker/image.d.ts +49 -0
- package/dist/docker/image.js +302 -0
- package/dist/docker/stage.d.ts +21 -0
- package/dist/docker/stage.js +290 -0
- package/dist/docker/volume.d.ts +24 -0
- package/dist/docker/volume.js +67 -0
- package/dist/docker.d.ts +156 -0
- package/dist/docker.js +1277 -0
- package/dist/drift.d.ts +200 -0
- package/dist/drift.js +416 -0
- package/dist/e2b.d.ts +337 -0
- package/dist/e2b.js +1516 -0
- package/dist/entry.d.ts +2 -0
- package/dist/entry.js +24 -0
- package/dist/files.d.ts +50 -0
- package/dist/files.js +208 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +26 -0
- package/dist/isolation.d.ts +29 -0
- package/dist/isolation.js +71 -0
- package/dist/janitor.d.ts +50 -0
- package/dist/janitor.js +135 -0
- package/dist/kernel.d.ts +113 -0
- package/dist/kernel.js +358 -0
- package/dist/kinds.d.ts +79 -0
- package/dist/kinds.js +133 -0
- package/dist/labels.d.ts +23 -0
- package/dist/labels.js +50 -0
- package/dist/modal.d.ts +302 -0
- package/dist/modal.js +1374 -0
- package/dist/mount-archil.d.ts +164 -0
- package/dist/mount-archil.js +471 -0
- package/dist/mount.d.ts +57 -0
- package/dist/mount.js +104 -0
- package/dist/orgo-channel.d.ts +96 -0
- package/dist/orgo-channel.js +391 -0
- package/dist/orgo.d.ts +139 -0
- package/dist/orgo.js +1006 -0
- package/dist/phone-harness.d.ts +185 -0
- package/dist/phone-harness.js +1420 -0
- package/dist/processes.d.ts +24 -0
- package/dist/processes.js +40 -0
- package/dist/protocol.d.ts +729 -0
- package/dist/protocol.js +54 -0
- package/dist/provider.d.ts +245 -0
- package/dist/provider.js +37 -0
- package/dist/providers.d.ts +68 -0
- package/dist/providers.js +25 -0
- package/dist/result.d.ts +15 -0
- package/dist/result.js +2 -0
- package/dist/screen-watch.d.ts +150 -0
- package/dist/screen-watch.js +490 -0
- package/dist/test-connection.d.ts +17 -0
- package/dist/test-connection.js +26 -0
- package/dist/wait.d.ts +23 -0
- package/dist/wait.js +65 -0
- package/package.json +62 -4
package/dist/kinds.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// The kind registry: the computer an agent is given, its setting kind, and the providers Settings offers for it. Two
|
|
2
|
+
// axes: the machine kind is the protocol's (capabilities().kind, KIND_SHAPES); the setting kind is what an agent is
|
|
3
|
+
// given in Settings, `computer: { kind, provider? }`, as machine kinds and capability groups. Whether a provider serves
|
|
4
|
+
// a setting kind is computed from its capabilities alone (serves), never kept beside them: a provider that drops a
|
|
5
|
+
// group stops serving the kind. The model's tools are not here: they live in the kernel's tool registry, keyed by
|
|
6
|
+
// these groups.
|
|
7
|
+
// The default images are values: each from the provider module that owns it. Those modules import this one for types
|
|
8
|
+
// alone, so this is no import cycle.
|
|
9
|
+
import { BROWSER_IMAGE } from "./browser.js";
|
|
10
|
+
import { DAYTONA_DEFAULT_SNAPSHOT } from "./daytona.js";
|
|
11
|
+
import { E2B_BASE_TEMPLATE, E2B_DESKTOP_TEMPLATE } from "./e2b.js";
|
|
12
|
+
import { MODAL_DEFAULT_IMAGE } from "./modal.js";
|
|
13
|
+
import { ORGO_BASE_IMAGE } from "./orgo.js";
|
|
14
|
+
import { PHONE_IMAGE } from "./phone-harness.js";
|
|
15
|
+
export const SETTING_KINDS = {
|
|
16
|
+
none: { machineKinds: [], required: [], optional: [] },
|
|
17
|
+
sandbox: { machineKinds: ["linux"], required: ["exec", "files", "processes"], optional: [] },
|
|
18
|
+
desktop: { machineKinds: ["desktop"], required: ["screen", "input.pointer", "input.keys"], optional: ["exec", "files", "processes", "apps", "stream"] },
|
|
19
|
+
phone: { machineKinds: ["android", "ios"], required: ["screen", "input.touch", "apps"], optional: ["input.keys", "apps.install", "apps.ui_tree", "stream"] },
|
|
20
|
+
browser: { machineKinds: ["browser"], required: ["cdp"], optional: ["stream", "downloads"] },
|
|
21
|
+
};
|
|
22
|
+
/** Every setting kind, in the table's order. */
|
|
23
|
+
export const SETTING_KIND_NAMES = Object.keys(SETTING_KINDS);
|
|
24
|
+
/** Why capabilities do not serve a setting kind, in words; none when they do. */
|
|
25
|
+
export function servingRefusals(capabilities, kind) {
|
|
26
|
+
const spec = Object.hasOwn(SETTING_KINDS, kind) ? SETTING_KINDS[kind] : undefined;
|
|
27
|
+
if (spec === undefined)
|
|
28
|
+
return [`${JSON.stringify(kind)} is not a setting kind: ${SETTING_KIND_NAMES.join(", ")}`];
|
|
29
|
+
if (spec.machineKinds.length === 0)
|
|
30
|
+
return [`kind ${kind} is no computer: no provider serves it`];
|
|
31
|
+
const refusals = [];
|
|
32
|
+
if (!spec.machineKinds.includes(capabilities.kind))
|
|
33
|
+
refusals.push(`kind ${kind} is a ${spec.machineKinds.join(" or ")} machine, not a ${capabilities.kind} one`);
|
|
34
|
+
const groups = Array.isArray(capabilities.groups) ? capabilities.groups : [];
|
|
35
|
+
const missing = spec.required.filter((group) => !groups.includes(group));
|
|
36
|
+
if (missing.length > 0)
|
|
37
|
+
refusals.push(`kind ${kind} needs groups ${missing.join(", ")}, which the provider does not declare`);
|
|
38
|
+
return refusals;
|
|
39
|
+
}
|
|
40
|
+
/** Whether a provider with these capabilities serves the kind: its machine kind is one of the kind's, and it declares every required group. */
|
|
41
|
+
export function serves(capabilities, kind) {
|
|
42
|
+
return servingRefusals(capabilities, kind).length === 0;
|
|
43
|
+
}
|
|
44
|
+
/** The setting kind these capabilities serve, or undefined when they serve none. Machine kinds are apart, so at most one. */
|
|
45
|
+
export function kindOf(capabilities) {
|
|
46
|
+
return SETTING_KIND_NAMES.find((kind) => serves(capabilities, kind));
|
|
47
|
+
}
|
|
48
|
+
const SANDBOX = { kind: "linux", groups: ["exec", "files", "processes"] };
|
|
49
|
+
const LINUX_DESKTOP = { kind: "desktop", groups: ["exec", "files", "processes", "screen", "input.pointer", "input.keys"] };
|
|
50
|
+
/** An entry with its kinds derived from its capabilities. */
|
|
51
|
+
function entry(fields) {
|
|
52
|
+
return { ...fields, kinds: SETTING_KIND_NAMES.filter((kind) => fields.capabilities.some((one) => serves(one, kind))) };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Every provider Settings offers, each with its provider file in the registry;
|
|
56
|
+
* a unit test then holds each to its module (CAPABILITIES, MOUNT). daytona, modal and e2b take archil mounts.
|
|
57
|
+
*/
|
|
58
|
+
export const PROVIDERS = [
|
|
59
|
+
entry({ id: "docker", label: "Docker", keys: [], mounts: ["bind"], metered: false, capabilities: [SANDBOX, LINUX_DESKTOP] }),
|
|
60
|
+
entry({
|
|
61
|
+
id: "daytona",
|
|
62
|
+
label: "Daytona",
|
|
63
|
+
keys: [
|
|
64
|
+
{ name: "DAYTONA_API_KEY", required: true },
|
|
65
|
+
{ name: "DAYTONA_API_URL", required: false },
|
|
66
|
+
{ name: "DAYTONA_TARGET", required: false },
|
|
67
|
+
],
|
|
68
|
+
mounts: ["archil"],
|
|
69
|
+
metered: true,
|
|
70
|
+
capabilities: [SANDBOX],
|
|
71
|
+
defaultImage: { sandbox: DAYTONA_DEFAULT_SNAPSHOT },
|
|
72
|
+
}),
|
|
73
|
+
entry({
|
|
74
|
+
id: "modal",
|
|
75
|
+
label: "Modal",
|
|
76
|
+
keys: [
|
|
77
|
+
{ name: "MODAL_TOKEN_ID", required: true },
|
|
78
|
+
{ name: "MODAL_TOKEN_SECRET", required: true },
|
|
79
|
+
],
|
|
80
|
+
mounts: ["archil"],
|
|
81
|
+
metered: true,
|
|
82
|
+
capabilities: [SANDBOX],
|
|
83
|
+
defaultImage: { sandbox: MODAL_DEFAULT_IMAGE },
|
|
84
|
+
}),
|
|
85
|
+
entry({
|
|
86
|
+
id: "e2b",
|
|
87
|
+
label: "E2B",
|
|
88
|
+
keys: [{ name: "E2B_API_KEY", required: true }],
|
|
89
|
+
mounts: ["archil"],
|
|
90
|
+
metered: true,
|
|
91
|
+
capabilities: [SANDBOX, LINUX_DESKTOP],
|
|
92
|
+
defaultImage: { sandbox: E2B_BASE_TEMPLATE, desktop: E2B_DESKTOP_TEMPLATE },
|
|
93
|
+
}),
|
|
94
|
+
entry({
|
|
95
|
+
id: "orgo",
|
|
96
|
+
label: "Orgo",
|
|
97
|
+
keys: [{ name: "ORGO_API_KEY", required: true }],
|
|
98
|
+
mounts: [],
|
|
99
|
+
metered: true,
|
|
100
|
+
capabilities: [LINUX_DESKTOP],
|
|
101
|
+
defaultImage: { desktop: ORGO_BASE_IMAGE },
|
|
102
|
+
}),
|
|
103
|
+
entry({
|
|
104
|
+
id: "phone-harness",
|
|
105
|
+
label: "Phone harness",
|
|
106
|
+
keys: [{ name: "PHONE_HARNESS_API_KEY", required: true }],
|
|
107
|
+
mounts: [],
|
|
108
|
+
metered: true,
|
|
109
|
+
capabilities: [{ kind: "android", groups: ["screen", "input.touch", "input.keys", "apps", "apps.ui_tree"] }],
|
|
110
|
+
defaultImage: { phone: PHONE_IMAGE },
|
|
111
|
+
}),
|
|
112
|
+
entry({
|
|
113
|
+
id: "browserbase",
|
|
114
|
+
label: "Browserbase",
|
|
115
|
+
keys: [
|
|
116
|
+
{ name: "BROWSERBASE_API_KEY", required: true },
|
|
117
|
+
{ name: "BROWSERBASE_PROJECT_ID", required: true },
|
|
118
|
+
],
|
|
119
|
+
mounts: [],
|
|
120
|
+
metered: true,
|
|
121
|
+
capabilities: [{ kind: "browser", groups: ["cdp", "stream"] }],
|
|
122
|
+
defaultImage: { browser: BROWSER_IMAGE },
|
|
123
|
+
}),
|
|
124
|
+
entry({
|
|
125
|
+
id: "kernel",
|
|
126
|
+
label: "Kernel",
|
|
127
|
+
keys: [{ name: "KERNEL_API_KEY", required: true }],
|
|
128
|
+
mounts: [],
|
|
129
|
+
metered: true,
|
|
130
|
+
capabilities: [{ kind: "browser", groups: ["cdp", "stream"] }],
|
|
131
|
+
defaultImage: { browser: BROWSER_IMAGE },
|
|
132
|
+
}),
|
|
133
|
+
];
|
package/dist/labels.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { epochProblem } from "./mount.js";
|
|
2
|
+
import { type Result } from "./result.js";
|
|
3
|
+
export { epochProblem };
|
|
4
|
+
/** The run a computer works for. */
|
|
5
|
+
export declare const RUN_LABEL = "agentrun.run";
|
|
6
|
+
/** The claim epoch of the run's runner that made the computer, in decimal. */
|
|
7
|
+
export declare const EPOCH_LABEL = "agentrun.epoch";
|
|
8
|
+
/**
|
|
9
|
+
* Why run is not a run id, in words, or undefined when it is one: a non-empty string with no NUL byte. That is the
|
|
10
|
+
* strictest rule the providers share for a label's value (Docker, Daytona and Modal each refuse only a NUL), so every
|
|
11
|
+
* provider takes it.
|
|
12
|
+
*/
|
|
13
|
+
export declare function runProblem(run: unknown): string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The labels of a computer of this run, made under this claim epoch: { "agentrun.run": run, "agentrun.epoch": "<epoch>" }.
|
|
16
|
+
* A run or an epoch that is not one is a caller's mistake, so it throws, in words.
|
|
17
|
+
*/
|
|
18
|
+
export declare function runLabels(run: string, epoch: number): Record<string, string>;
|
|
19
|
+
/**
|
|
20
|
+
* A computer's claim epoch, read from its labels. A missing label is not_found; a value other than a decimal whole number
|
|
21
|
+
* with no sign, leading zero or space, up to 2^53 - 1, is not an epoch: invalid, in words naming what it reads.
|
|
22
|
+
*/
|
|
23
|
+
export declare function epochOf(labels: Record<string, string> | undefined): Result<number>;
|
package/dist/labels.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// The run and its claim epoch, as two labels every computer of a run carries. The claim epoch is the one fence for runs
|
|
2
|
+
// and computers: a new claim is epoch + 1, and it releases every computer of the run labelled with a lower epoch
|
|
3
|
+
// (releaseOlder, in janitor.ts). Both names live here alone.
|
|
4
|
+
import { epochProblem } from "./mount.js";
|
|
5
|
+
import { fail, ok } from "./result.js";
|
|
6
|
+
export { epochProblem };
|
|
7
|
+
/** The run a computer works for. */
|
|
8
|
+
export const RUN_LABEL = "agentrun.run";
|
|
9
|
+
/** The claim epoch of the run's runner that made the computer, in decimal. */
|
|
10
|
+
export const EPOCH_LABEL = "agentrun.epoch";
|
|
11
|
+
/** An epoch as a label holds it: decimal digits, no sign, no leading zero, no space. */
|
|
12
|
+
const EPOCH_TEXT = /^(?:0|[1-9][0-9]*)$/;
|
|
13
|
+
/**
|
|
14
|
+
* Why run is not a run id, in words, or undefined when it is one: a non-empty string with no NUL byte. That is the
|
|
15
|
+
* strictest rule the providers share for a label's value (Docker, Daytona and Modal each refuse only a NUL), so every
|
|
16
|
+
* provider takes it.
|
|
17
|
+
*/
|
|
18
|
+
export function runProblem(run) {
|
|
19
|
+
if (typeof run !== "string" || run === "")
|
|
20
|
+
return "a run id must be a non-empty string";
|
|
21
|
+
if (run.includes("\0"))
|
|
22
|
+
return "a run id cannot hold a NUL byte: no provider takes one in a label";
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The labels of a computer of this run, made under this claim epoch: { "agentrun.run": run, "agentrun.epoch": "<epoch>" }.
|
|
27
|
+
* A run or an epoch that is not one is a caller's mistake, so it throws, in words.
|
|
28
|
+
*/
|
|
29
|
+
export function runLabels(run, epoch) {
|
|
30
|
+
const problem = runProblem(run) ?? epochProblem(epoch);
|
|
31
|
+
if (problem !== undefined)
|
|
32
|
+
throw new TypeError(problem);
|
|
33
|
+
return { [RUN_LABEL]: run, [EPOCH_LABEL]: String(epoch) };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A computer's claim epoch, read from its labels. A missing label is not_found; a value other than a decimal whole number
|
|
37
|
+
* with no sign, leading zero or space, up to 2^53 - 1, is not an epoch: invalid, in words naming what it reads.
|
|
38
|
+
*/
|
|
39
|
+
export function epochOf(labels) {
|
|
40
|
+
if (typeof labels !== "object" || labels === null || Array.isArray(labels))
|
|
41
|
+
return fail("invalid", "the computer's labels are not a map of names to strings");
|
|
42
|
+
if (!Object.hasOwn(labels, EPOCH_LABEL))
|
|
43
|
+
return fail("not_found", `the computer carries no ${EPOCH_LABEL} label`);
|
|
44
|
+
const text = labels[EPOCH_LABEL];
|
|
45
|
+
const epoch = typeof text === "string" && EPOCH_TEXT.test(text) ? Number(text) : Number.NaN;
|
|
46
|
+
if (!Number.isSafeInteger(epoch)) {
|
|
47
|
+
return fail("invalid", `the label ${EPOCH_LABEL} reads ${JSON.stringify(text)}, not an epoch: a decimal whole number with no sign, leading zero or space`);
|
|
48
|
+
}
|
|
49
|
+
return ok(epoch);
|
|
50
|
+
}
|
package/dist/modal.d.ts
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import type { KindCapabilities } from "./kinds.js";
|
|
2
|
+
import { type MountKind } from "./mount.js";
|
|
3
|
+
import { type ProviderNote } from "./mount-archil.js";
|
|
4
|
+
import { type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type CreatedComputer, type NetworkPolicy, type NetworkSpec, type Refusal } from "./provider.js";
|
|
5
|
+
import { type Result } from "./result.js";
|
|
6
|
+
import { type ScreenWatch, type ScreenWatchHandlers, type WatchOptions } from "./screen-watch.js";
|
|
7
|
+
/** The App sandboxes are made in (modal-client@64880502:js/src/app.ts:32-61). */
|
|
8
|
+
export interface ModalApp {
|
|
9
|
+
readonly appId: string;
|
|
10
|
+
}
|
|
11
|
+
/** An Image, built on Modal's side when a sandbox is created from it (js/src/image.ts:311-401). */
|
|
12
|
+
export interface ModalImage {
|
|
13
|
+
dockerfileCommands(commands: string[]): ModalImage;
|
|
14
|
+
}
|
|
15
|
+
/** What sandboxes.create is given: every field is one of the SDK's SandboxCreateParams (js/src/sandbox.ts:356-474). */
|
|
16
|
+
export interface ModalCreateParams {
|
|
17
|
+
runtime: "vm";
|
|
18
|
+
command: string[];
|
|
19
|
+
timeoutMs: number;
|
|
20
|
+
workdir: string;
|
|
21
|
+
cpu: number;
|
|
22
|
+
cpuLimit: number;
|
|
23
|
+
memoryMiB: number;
|
|
24
|
+
memoryLimitMiB: number;
|
|
25
|
+
blockNetwork?: true;
|
|
26
|
+
tags: Record<string, string>;
|
|
27
|
+
}
|
|
28
|
+
/** A program's stdin in binary mode: the SDK's ModalWriteStream (js/src/streams.ts:33-39) and WritableStream's close. */
|
|
29
|
+
export interface ModalByteSink {
|
|
30
|
+
writeBytes(bytes: Uint8Array): Promise<void>;
|
|
31
|
+
close(): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
/** One program started by exec in binary mode: the part of the SDK's ContainerProcess read here (sandbox.ts:2774-2914). */
|
|
34
|
+
export interface ModalProcess {
|
|
35
|
+
readonly stdin: ModalByteSink;
|
|
36
|
+
readonly stdout: AsyncIterable<Uint8Array>;
|
|
37
|
+
readonly stderr: AsyncIterable<Uint8Array>;
|
|
38
|
+
wait(): Promise<number>;
|
|
39
|
+
}
|
|
40
|
+
/** The part of the SDK's Sandbox called here (sandbox.ts:1624-2772). */
|
|
41
|
+
export interface ModalSandbox {
|
|
42
|
+
readonly sandboxId: string;
|
|
43
|
+
exec(command: string[], params: {
|
|
44
|
+
mode: "binary";
|
|
45
|
+
}): Promise<ModalProcess>;
|
|
46
|
+
/** null while the sandbox runs, its exit code once it has finished. */
|
|
47
|
+
poll(): Promise<number | null>;
|
|
48
|
+
getTags(): Promise<Record<string, string>>;
|
|
49
|
+
terminate(): Promise<void>;
|
|
50
|
+
/** The sandbox's own command's output (the SDK's ModalReadStream): read only to say why a create's sandbox ended. */
|
|
51
|
+
readonly stdout?: {
|
|
52
|
+
readText(): Promise<string>;
|
|
53
|
+
};
|
|
54
|
+
readonly stderr?: {
|
|
55
|
+
readText(): Promise<string>;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** The part of the SDK's ModalClient this provider calls. The host passes its own client. */
|
|
59
|
+
export interface ModalSdk {
|
|
60
|
+
readonly apps: {
|
|
61
|
+
fromName(name: string, params: {
|
|
62
|
+
createIfMissing: boolean;
|
|
63
|
+
}): Promise<ModalApp>;
|
|
64
|
+
};
|
|
65
|
+
/** fromId opens an image Modal already holds (im-..., as box/build-modal.py prints it); a spec naming one needs it. */
|
|
66
|
+
readonly images: {
|
|
67
|
+
fromRegistry(tag: string): ModalImage;
|
|
68
|
+
fromId?(id: string): Promise<ModalImage>;
|
|
69
|
+
};
|
|
70
|
+
readonly sandboxes: {
|
|
71
|
+
create(app: ModalApp, image: ModalImage, params: ModalCreateParams): Promise<ModalSandbox>;
|
|
72
|
+
fromId(id: string): Promise<ModalSandbox>;
|
|
73
|
+
list(params: {
|
|
74
|
+
appId: string;
|
|
75
|
+
tags: Record<string, string>;
|
|
76
|
+
}): AsyncIterable<ModalSandbox>;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/** The longest each kind of call may take, in ms. */
|
|
80
|
+
export interface ModalTimeouts {
|
|
81
|
+
/** sandboxes.create, which builds the image layer and waits for the sandbox to be scheduled. */
|
|
82
|
+
createMs: number;
|
|
83
|
+
/** Every other SDK call: apps.fromName, fromId, getTags, poll, terminate, exec's start. */
|
|
84
|
+
callMs: number;
|
|
85
|
+
/** A new connection, from the start of the bridge's exec (at most callMs of it) to the daemon's hello. */
|
|
86
|
+
helloMs: number;
|
|
87
|
+
/** The probe, run through the daemon. */
|
|
88
|
+
probeMs: number;
|
|
89
|
+
/** One whole list, every page and every sandbox's tags. */
|
|
90
|
+
listMs: number;
|
|
91
|
+
/** The daemon's upload, from the exec's start to its exit. The entrypoint waits this long and one call more. */
|
|
92
|
+
uploadMs: number;
|
|
93
|
+
/**
|
|
94
|
+
* How long release delete, and a create that refuses its sandbox (drift, an abort, a failed upload), wait after the
|
|
95
|
+
* terminate for poll to read the sandbox finished: Modal ends a sandbox asynchronously, and lists it until then. Each
|
|
96
|
+
* wait also ends on the caller's abort.
|
|
97
|
+
*/
|
|
98
|
+
releaseMs: number;
|
|
99
|
+
/** The first pause between two of those polls; the pauses double up to 5 s. */
|
|
100
|
+
releasePollMs: number;
|
|
101
|
+
/** Each root step of an Archil mount through exec (the preflight, mount or revoke, serve), and its checkin at release. */
|
|
102
|
+
mountMs: number;
|
|
103
|
+
}
|
|
104
|
+
export interface ModalProviderOptions {
|
|
105
|
+
/** The host's Modal client, or anything with the same slice. */
|
|
106
|
+
sdk: ModalSdk;
|
|
107
|
+
/** Told what is no failure of the call it came from: a release that did not let an Archil folder go cleanly. */
|
|
108
|
+
onNote?: ProviderNote;
|
|
109
|
+
/** The Modal App the sandboxes live in; made when missing. */
|
|
110
|
+
app: string;
|
|
111
|
+
/**
|
|
112
|
+
* A registry image holding the daemon for linux/amd64 at /computerd, pinned by digest (name@sha256:<64 hex>), copied
|
|
113
|
+
* into each computer's image with COPY --from. Without it the daemon is uploaded (daemonPath).
|
|
114
|
+
*/
|
|
115
|
+
daemonImage?: string;
|
|
116
|
+
/**
|
|
117
|
+
* The daemon binary for linux/amd64 on this machine, streamed into each computer right after create when no
|
|
118
|
+
* daemonImage is given. Default this package's dist/computerd-linux-amd64 (npm run build:daemon).
|
|
119
|
+
*/
|
|
120
|
+
daemonPath?: string;
|
|
121
|
+
/** The longest lifetime check takes, in ms, declared as capabilities().maxLifetimeMs: at most 24 hours, Modal's longest timeout, which is the default. */
|
|
122
|
+
maxLifetimeMs?: number;
|
|
123
|
+
/**
|
|
124
|
+
* Who a computer runs as when its spec does not say: uid:gid in numbers, never root or root's group. Default 2510:2510
|
|
125
|
+
* (TOOL_USER). Init refuses to start while another process in the sandbox holds the uid.
|
|
126
|
+
*/
|
|
127
|
+
user?: string;
|
|
128
|
+
timeouts?: Partial<ModalTimeouts>;
|
|
129
|
+
/**
|
|
130
|
+
* The addresses the probe tries, to show none of them answers a computer with network none: host:port over TCP, or
|
|
131
|
+
* host:port/udp, a DNS query over UDP.
|
|
132
|
+
*/
|
|
133
|
+
probeTargets?: string[];
|
|
134
|
+
}
|
|
135
|
+
/** The mount kinds a Modal computer takes, as capabilities().mount declares them: the run's folder on an Archil disk. */
|
|
136
|
+
export declare const MOUNT: readonly MountKind[];
|
|
137
|
+
/** The machine kind and groups of its one configuration: a linux computer. */
|
|
138
|
+
export declare const CAPABILITIES: readonly KindCapabilities[];
|
|
139
|
+
/** A registry tag for linux/amd64 that Modal can pull: the default when a setting names no image. */
|
|
140
|
+
export declare const MODAL_DEFAULT_IMAGE = "debian:bookworm-slim";
|
|
141
|
+
/** The SDK's default server (modal-client@64880502:js/src/config.ts:143). */
|
|
142
|
+
export declare const MODAL_DEFAULT_SERVER_URL = "https://api.modal.com:443";
|
|
143
|
+
/** What modalClient gives the SDK's ModalClient: the token, explicitly, so the SDK fills none of it in. */
|
|
144
|
+
export interface ModalClientParams {
|
|
145
|
+
tokenId: string;
|
|
146
|
+
tokenSecret: string;
|
|
147
|
+
}
|
|
148
|
+
/** The SDK's ModalClient constructor, or a stand-in for one. */
|
|
149
|
+
export type ModalClientConstructor = new (params: ModalClientParams) => unknown;
|
|
150
|
+
/** What modalClient takes: the token, the server it goes to, and the SDK's client class. */
|
|
151
|
+
export interface ModalClientOptions {
|
|
152
|
+
/** The Modal token's id and secret. Serve passes its MODAL_TOKEN_ID and MODAL_TOKEN_SECRET; the conformance module the token it reads. */
|
|
153
|
+
tokenId: string;
|
|
154
|
+
tokenSecret: string;
|
|
155
|
+
/** The server the token goes to; default the SDK's, https://api.modal.com:443. */
|
|
156
|
+
serverUrl?: string;
|
|
157
|
+
/** The SDK's ModalClient; imported from the host's modal package by default. */
|
|
158
|
+
ModalClient?: ModalClientConstructor;
|
|
159
|
+
}
|
|
160
|
+
/** What create() takes: the provider's options, the client's in place of the SDK. */
|
|
161
|
+
export interface ModalCreateOptions extends Omit<ModalProviderOptions, "sdk">, ModalClientOptions {
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* A Modal client given the token passed in, and nothing of the environment: a tokenId and tokenSecret passed to
|
|
165
|
+
* ModalClient replace what the environment or the profile held, and clear any OAuth credentials (client.ts:124-148), so a
|
|
166
|
+
* MODAL_TOKEN_ID or ~/.modal.toml on the host is never used. The key goes only to options.serverUrl, else the SDK's
|
|
167
|
+
* default (config.ts:143). ModalClient cannot take a server explicitly: it declares `endpoint` (client.ts:51) and never
|
|
168
|
+
* reads it, and the control-plane client is made from the profile's serverUrl (client.ts:131, 175, 281), which getProfile
|
|
169
|
+
* takes from MODAL_SERVER_URL before any profile's server_url (config.ts:140-143), the profile being MODAL_PROFILE's or the
|
|
170
|
+
* active one in MODAL_CONFIG_PATH or ~/.modal.toml (config.ts:76-82, 126-137).
|
|
171
|
+
*
|
|
172
|
+
* So this is the library's one touch of the environment, a guard and not a setting (README, Settings): an ambient
|
|
173
|
+
* MODAL_SERVER_URL is refused, and MODAL_SERVER_URL is set to the chosen server only while the client is constructed,
|
|
174
|
+
* and put back after, so no profile can redirect the key. process.env is the whole process's: constructions run one at a
|
|
175
|
+
* time, each waiting for the last, so none sees another's server. The modal package is the host's: it is imported only
|
|
176
|
+
* here.
|
|
177
|
+
*/
|
|
178
|
+
export declare function modalClient({ tokenId, tokenSecret, serverUrl, ModalClient }: ModalClientOptions): Promise<ModalSdk>;
|
|
179
|
+
/**
|
|
180
|
+
* A ModalProvider from its options alone: the client as modalClient makes it from the token and server passed in, the
|
|
181
|
+
* app (required), and the daemon copied from options.daemonImage when given, else uploaded (options.daemonPath, else this
|
|
182
|
+
* package's build): given both, the image wins and no upload path is passed on, as the class takes one or the other. It
|
|
183
|
+
* reads no environment but the guard modalClient keeps: serve passes its MODAL_TOKEN_ID, MODAL_TOKEN_SECRET and
|
|
184
|
+
* AGENTRUN_BOX_APP, the conformance module the settings it reads. The app and the token are checked before any client
|
|
185
|
+
* is made, and neither is ever echoed.
|
|
186
|
+
*/
|
|
187
|
+
export declare function create(options: ModalCreateOptions): Promise<ModalProvider>;
|
|
188
|
+
/** The conformance CLI's module for Modal: its live switch, the run's 30-minute cap and the drifted twin. */
|
|
189
|
+
export declare const conformance: () => Promise<typeof import("./conformance/modal.js")>;
|
|
190
|
+
/**
|
|
191
|
+
* What an Archil computer's entrypoint waits for, beside the daemon, before it becomes init: root makes it through exec
|
|
192
|
+
* once the run's folder is mounted, so no tool program runs before that. The daemon's directory is root's alone.
|
|
193
|
+
*/
|
|
194
|
+
export declare const ARCHIL_GATE = "/opt/agentrun/archil-mounted";
|
|
195
|
+
/**
|
|
196
|
+
* The commands the provider sends into a sandbox when it uploads the daemon, exactly: the sandbox's command
|
|
197
|
+
* (entrypoint, which also waits for `gate` when given: an Archil computer's), the upload, and a connection's bridge
|
|
198
|
+
* (stdio). Exported so a test can run them where Modal would.
|
|
199
|
+
*/
|
|
200
|
+
export declare function modalCommands({ deadline, user, waitSeconds, sha256, daemon, home, gate, }?: {
|
|
201
|
+
deadline?: string;
|
|
202
|
+
user?: string;
|
|
203
|
+
waitSeconds?: number;
|
|
204
|
+
sha256?: string;
|
|
205
|
+
daemon?: string;
|
|
206
|
+
home?: string;
|
|
207
|
+
gate?: string;
|
|
208
|
+
}): {
|
|
209
|
+
entrypoint: string[];
|
|
210
|
+
upload: string[];
|
|
211
|
+
hold: string[];
|
|
212
|
+
stdio: string[];
|
|
213
|
+
};
|
|
214
|
+
export interface UntilFinishedOptions {
|
|
215
|
+
/** The sandbox in words, for the errors, such as its name or id. */
|
|
216
|
+
name: string;
|
|
217
|
+
/** The longest the whole wait takes, in ms. */
|
|
218
|
+
boundMs: number;
|
|
219
|
+
/** The longest one poll may take, in ms. */
|
|
220
|
+
callMs: number;
|
|
221
|
+
/** The first pause between two polls, in ms; each pause doubles up to maxMs. */
|
|
222
|
+
minMs: number;
|
|
223
|
+
/** The longest pause between two polls, in ms. */
|
|
224
|
+
maxMs: number;
|
|
225
|
+
/** Ends the wait early, as aborted; a wait that must finish whatever its caller does is given none. */
|
|
226
|
+
signal?: AbortSignal;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* The one wait after a terminate, which returns before Modal has ended the sandbox (sandbox.ts:1292-1296, 2238-2251):
|
|
230
|
+
* polls through waitUntil until poll reads an exit code (null while it runs, sandbox.ts:2761-2771) or Modal no longer
|
|
231
|
+
* knows the sandbox. Past boundMs it is a timeout, and on the signal's abort an abort, each saying what poll last read;
|
|
232
|
+
* it never reports a sandbox finished that it did not read finished. release delete, a create that refuses its
|
|
233
|
+
* sandbox, and modal-sweep --after all wait through it.
|
|
234
|
+
*/
|
|
235
|
+
export declare function untilFinished(poll: () => Promise<number | null>, { name, boundMs, callMs, minMs, maxMs, signal }: UntilFinishedOptions): Promise<Result<void>>;
|
|
236
|
+
/**
|
|
237
|
+
* Computers that are Modal sandboxes on the VM runtime. The daemon is uploaded right after create, streamed through an
|
|
238
|
+
* exec's stdin, while the sandbox's command, a small sh entrypoint, waits for it and then becomes `computerd init`; or,
|
|
239
|
+
* with daemonImage, it comes in as a layer of the computer's image (COPY --from) and is the command itself. A
|
|
240
|
+
* connection is `computerd stdio` through exec, so a computer with network none is still reached, and needs no network
|
|
241
|
+
* to get its daemon either way. Modal ends each sandbox at its timeout, so the lifetime is the vendor's. Modal reads no
|
|
242
|
+
* network policy back, so the daemon's probe stands for one: network none is honoured only when none of its addresses
|
|
243
|
+
* answers (an address that accepts and sends nothing back is named in the read-back's notes), and an allowlist is
|
|
244
|
+
* refused until the live bypass cases pass.
|
|
245
|
+
*/
|
|
246
|
+
export declare class ModalProvider implements ComputerProvider {
|
|
247
|
+
#private;
|
|
248
|
+
readonly id = "modal";
|
|
249
|
+
readonly version: string;
|
|
250
|
+
constructor({ sdk, app, daemonImage, daemonPath, maxLifetimeMs, user, timeouts, probeTargets, onNote }: ModalProviderOptions);
|
|
251
|
+
/**
|
|
252
|
+
* daemon pid1: the sandbox's command is init itself (with daemonImage) or the entrypoint that execs into it, and Modal
|
|
253
|
+
* finishes the sandbox when that main process exits (sandbox.ts:384-388), so init's exit ends the computer. Whether
|
|
254
|
+
* Modal gives that process the number 1 is not documented; init reaps as a subreaper either way. maxLifetimeMs is this
|
|
255
|
+
* instance's cap: Modal's 24 hours unless the provider was made with less. Init starts with --own-network whatever
|
|
256
|
+
* Modal runs in the sandbox (no listener of its own there is documented, so no port is declared), and network none is
|
|
257
|
+
* all a computer takes until a proxy carries open out of the daemon's own network.
|
|
258
|
+
*/
|
|
259
|
+
capabilities(): ComputerCapabilities;
|
|
260
|
+
check(spec: ComputerSpec): Refusal[];
|
|
261
|
+
create(spec: ComputerSpec, { signal }?: CallContext): Promise<Result<CreatedComputer>>;
|
|
262
|
+
/**
|
|
263
|
+
* Settings' test: the provider's app read without making it (createIfMissing false), which makes nothing. An app not
|
|
264
|
+
* made yet is a connection all the same: the token was taken, and the first computer makes the app.
|
|
265
|
+
*/
|
|
266
|
+
testConnection({ signal }?: CallContext): Promise<Result<{
|
|
267
|
+
detail: string;
|
|
268
|
+
}>>;
|
|
269
|
+
/** The live view: screen.watch on a connection of the watch's own (daemonWatch); a sandbox has no screen. */
|
|
270
|
+
watch(ref: ComputerRef, handlers: ScreenWatchHandlers, options?: WatchOptions): Promise<Result<ScreenWatch>>;
|
|
271
|
+
connect(ref: ComputerRef): Promise<Result<ComputerConnection>>;
|
|
272
|
+
attach(ref: {
|
|
273
|
+
id: string;
|
|
274
|
+
} | {
|
|
275
|
+
labels: Record<string, string>;
|
|
276
|
+
}, { signal }?: CallContext): Promise<Result<AttachedComputer>>;
|
|
277
|
+
/**
|
|
278
|
+
* Every running computer this provider made that carries all of these labels. Modal's list asks for running sandboxes
|
|
279
|
+
* only (includeFinished: false, sandbox.ts:1135-1140), yet a sandbox terminated a moment ago is still listed: each one
|
|
280
|
+
* listed is polled, and one that poll reads finished (an exit code, not null, sandbox.ts:2761-2771) or no longer
|
|
281
|
+
* finds is left out.
|
|
282
|
+
*/
|
|
283
|
+
list(labels: Record<string, string>, { signal }?: CallContext): Promise<Result<ComputerInfo[]>>;
|
|
284
|
+
/**
|
|
285
|
+
* Modal reads no policy back. Open is open, nothing being wider; none is read back by the probe from inside, and is
|
|
286
|
+
* another network in words when any of its addresses answered (an address that only accepted, and sent nothing back,
|
|
287
|
+
* leaves it none). A change is refused: it is fixed at create.
|
|
288
|
+
*/
|
|
289
|
+
network(ref: ComputerRef, policy?: NetworkSpec, { signal }?: CallContext): Promise<Result<NetworkPolicy>>;
|
|
290
|
+
/**
|
|
291
|
+
* delete terminates, and is idempotent: a sandbox already finished, or one Modal no longer knows, is ok. Modal ends a
|
|
292
|
+
* sandbox asynchronously (terminate returns before it has finished unless asked to wait, sandbox.ts:1292-1296 and
|
|
293
|
+
* 2238-2251), so delete then polls through untilFinished, as a refusing create does, with pauses that double from
|
|
294
|
+
* releasePollMs to 5 s, until poll reads an exit code (null while it runs, sandbox.ts:2761-2771) or Modal no longer
|
|
295
|
+
* knows it, within releaseMs and the caller's signal. Past releaseMs it is a timeout that says what poll last read,
|
|
296
|
+
* never done. An Archil computer that still runs lets go of the run's folder first (archilRelease: the final sync
|
|
297
|
+
* through computerd, then checkin as root); the terminate runs whatever that answers. A folder not let go cleanly
|
|
298
|
+
* loses nothing (every call that changed it synced, and the next claim revokes the hold), so it is said through
|
|
299
|
+
* onNote, and the release succeeds once the sandbox is gone.
|
|
300
|
+
*/
|
|
301
|
+
release(ref: ComputerRef, how: "stop" | "delete", { signal }?: CallContext): Promise<Result<void>>;
|
|
302
|
+
}
|