@parcha/agentrun-computer 0.1.0-beta.34 → 0.1.0-beta.35

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.
Files changed (99) hide show
  1. package/README.md +144 -26
  2. package/dist/browser.d.ts +12 -13
  3. package/dist/browser.js +16 -14
  4. package/dist/browserbase.d.ts +3 -5
  5. package/dist/browserbase.js +16 -13
  6. package/dist/chrome.js +1 -1
  7. package/dist/computerd-linux-amd64 +0 -0
  8. package/dist/computerd-linux-arm64 +0 -0
  9. package/dist/conformance/browserbase.js +1 -1
  10. package/dist/conformance/cases/provider.js +78 -3
  11. package/dist/conformance/daytona.js +2 -1
  12. package/dist/conformance/e2b.js +2 -1
  13. package/dist/conformance/fixture.js +24 -2
  14. package/dist/conformance/kernel.js +1 -1
  15. package/dist/conformance/kind.js +2 -1
  16. package/dist/conformance/{local.d.ts → local-chrome.d.ts} +7 -7
  17. package/dist/conformance/{local.js → local-chrome.js} +11 -11
  18. package/dist/conformance/orgo.d.ts +11 -5
  19. package/dist/conformance/orgo.js +37 -8
  20. package/dist/conformance/phone-harness.js +2 -1
  21. package/dist/conformance/report.js +3 -2
  22. package/dist/conformance/runner.js +25 -7
  23. package/dist/conformance/types.d.ts +21 -8
  24. package/dist/conformance/types.js +10 -0
  25. package/dist/conformance/windows-fixture.d.ts +1 -0
  26. package/dist/conformance/windows-fixture.js +37 -0
  27. package/dist/daytona.d.ts +3 -34
  28. package/dist/daytona.js +34 -61
  29. package/dist/descriptor.d.ts +94 -0
  30. package/dist/descriptor.js +81 -0
  31. package/dist/descriptors/browserbase.d.ts +24 -0
  32. package/dist/descriptors/browserbase.js +18 -0
  33. package/dist/descriptors/daytona.d.ts +62 -0
  34. package/dist/descriptors/daytona.js +49 -0
  35. package/dist/descriptors/docker.d.ts +12 -0
  36. package/dist/descriptors/docker.js +17 -0
  37. package/dist/descriptors/e2b.d.ts +22 -0
  38. package/dist/descriptors/e2b.js +19 -0
  39. package/dist/descriptors/index.d.ts +229 -0
  40. package/dist/descriptors/index.js +19 -0
  41. package/dist/descriptors/kernel.d.ts +20 -0
  42. package/dist/descriptors/kernel.js +15 -0
  43. package/dist/descriptors/local-chrome.d.ts +17 -0
  44. package/dist/descriptors/local-chrome.js +21 -0
  45. package/dist/descriptors/modal.d.ts +50 -0
  46. package/dist/descriptors/modal.js +38 -0
  47. package/dist/descriptors/orgo.d.ts +88 -0
  48. package/dist/descriptors/orgo.js +44 -0
  49. package/dist/descriptors/phone-harness.d.ts +28 -0
  50. package/dist/descriptors/phone-harness.js +20 -0
  51. package/dist/descriptors/shared.d.ts +7 -0
  52. package/dist/descriptors/shared.js +6 -0
  53. package/dist/desktop.d.ts +4 -4
  54. package/dist/desktop.js +4 -4
  55. package/dist/docker/egress.d.ts +1 -1
  56. package/dist/docker/image.js +17 -15
  57. package/dist/docker/inspect.d.ts +147 -0
  58. package/dist/docker/inspect.js +335 -0
  59. package/dist/docker.d.ts +6 -6
  60. package/dist/docker.js +46 -42
  61. package/dist/drift.d.ts +3 -145
  62. package/dist/drift.js +5 -334
  63. package/dist/e2b.d.ts +2 -8
  64. package/dist/e2b.js +16 -22
  65. package/dist/index.d.ts +8 -11
  66. package/dist/index.js +13 -11
  67. package/dist/isolation.js +2 -2
  68. package/dist/janitor.d.ts +18 -1
  69. package/dist/janitor.js +67 -19
  70. package/dist/kernel.d.ts +3 -5
  71. package/dist/kernel.js +19 -16
  72. package/dist/kinds.d.ts +54 -34
  73. package/dist/kinds.js +19 -117
  74. package/dist/labels.d.ts +12 -0
  75. package/dist/labels.js +39 -1
  76. package/dist/{local.d.ts → local-chrome.d.ts} +5 -8
  77. package/dist/{local.js → local-chrome.js} +19 -16
  78. package/dist/local-supervisor.d.ts +3 -3
  79. package/dist/local-supervisor.js +3 -3
  80. package/dist/modal.d.ts +3 -22
  81. package/dist/modal.js +15 -31
  82. package/dist/mount-archil.js +4 -4
  83. package/dist/orgo-channel.js +16 -13
  84. package/dist/orgo-desktop.d.ts +153 -0
  85. package/dist/orgo-desktop.js +1614 -0
  86. package/dist/orgo-names.d.ts +52 -0
  87. package/dist/orgo-names.js +84 -0
  88. package/dist/orgo.d.ts +18 -15
  89. package/dist/orgo.js +46 -107
  90. package/dist/phone-harness.d.ts +4 -10
  91. package/dist/phone-harness.js +45 -46
  92. package/dist/provider.d.ts +91 -10
  93. package/dist/provider.js +42 -0
  94. package/dist/providers.d.ts +23 -24
  95. package/dist/providers.js +14 -17
  96. package/dist/result.d.ts +11 -1
  97. package/dist/result.js +11 -0
  98. package/dist/test-connection.js +2 -2
  99. package/package.json +42 -2
package/dist/labels.js CHANGED
@@ -2,8 +2,12 @@
2
2
  // and computers: a new claim is epoch + 1, and it releases every computer of the run labelled with a lower epoch
3
3
  // (releaseOlder, in janitor.ts). Both names live here alone, with the run label's hash: a provider whose computers keep
4
4
  // only that (Orgo's names) lists it under RUN_HASH_LABEL, so a caller can still tell whose run a computer is.
5
+ //
6
+ // An agent's persistent computer carries its owner as two more labels, set at create: agentrun.owner=agent:<id>, and
7
+ // the owner's idle TTL when it set one. The run and epoch labels then name the claim that holds it now.
5
8
  import { createHash } from "node:crypto";
6
9
  import { epochProblem } from "./mount.js";
10
+ import { ownerProblem } from "./provider.js";
7
11
  import { fail, ok } from "./result.js";
8
12
  export { epochProblem };
9
13
  /** The run a computer works for. */
@@ -33,8 +37,42 @@ export function runHash(run) {
33
37
  }
34
38
  return out;
35
39
  }
40
+ /** The agent a persistent computer belongs to, as agent:<id>. */
41
+ export const OWNER_LABEL = "agentrun.owner";
42
+ /** The owner's idle TTL of a persistent computer, in milliseconds, in decimal: how long it may stay detached. */
43
+ export const IDLE_TTL_LABEL = "agentrun.idle-ttl-ms";
44
+ /** A whole number as a label holds it: decimal digits, no sign, no leading zero, no space. */
45
+ const DECIMAL = /^(?:0|[1-9][0-9]*)$/;
46
+ /** The labels of an agent's computer: its owner, and its idle TTL when the owner set one. Throws, in words, on an owner that is not one. */
47
+ export function ownerLabels(owner) {
48
+ const problem = ownerProblem(owner);
49
+ if (problem !== undefined)
50
+ throw new TypeError(problem);
51
+ return { [OWNER_LABEL]: `agent:${owner.agent}`, ...(owner.idleTtlMs === undefined ? {} : { [IDLE_TTL_LABEL]: String(owner.idleTtlMs) }) };
52
+ }
53
+ /**
54
+ * A computer's owner, read from its labels: undefined for a run's computer (no owner label). An owner label that is not
55
+ * agent:<id>, or an idle TTL that is not a decimal whole number above 0, is invalid, in words naming what it reads.
56
+ */
57
+ export function ownerOf(labels) {
58
+ if (typeof labels !== "object" || labels === null || Array.isArray(labels))
59
+ return fail("invalid", "the computer's labels are not a map of names to strings");
60
+ if (!Object.hasOwn(labels, OWNER_LABEL))
61
+ return ok(undefined);
62
+ const text = labels[OWNER_LABEL];
63
+ const agent = typeof text === "string" && text.startsWith("agent:") ? text.slice("agent:".length) : undefined;
64
+ if (agent === undefined || ownerProblem({ agent }) !== undefined)
65
+ return fail("invalid", `the label ${OWNER_LABEL} reads ${JSON.stringify(text)}, not agent:<id>`);
66
+ if (!Object.hasOwn(labels, IDLE_TTL_LABEL))
67
+ return ok({ agent });
68
+ const ttl = labels[IDLE_TTL_LABEL];
69
+ const idleTtlMs = typeof ttl === "string" && DECIMAL.test(ttl) ? Number(ttl) : Number.NaN;
70
+ if (!(Number.isSafeInteger(idleTtlMs) && idleTtlMs > 0))
71
+ return fail("invalid", `the label ${IDLE_TTL_LABEL} reads ${JSON.stringify(ttl)}, not a whole number of milliseconds above 0`);
72
+ return ok({ agent, idleTtlMs });
73
+ }
36
74
  /** An epoch as a label holds it: decimal digits, no sign, no leading zero, no space. */
37
- const EPOCH_TEXT = /^(?:0|[1-9][0-9]*)$/;
75
+ const EPOCH_TEXT = DECIMAL;
38
76
  /**
39
77
  * 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
40
78
  * strictest rule the providers share for a label's value (Docker, Daytona and Modal each refuse only a NUL), so every
@@ -1,21 +1,18 @@
1
1
  import type { KindCapabilities } from "./kinds.js";
2
2
  import type { MountKind } from "./mount.js";
3
- import type { AttachedComputer, CallContext, ComputerCapabilities, ComputerConnection, ComputerInfo, ComputerProvider, ComputerRef, ComputerSpec, CreatedComputer, NetworkForm, NetworkPolicy, NetworkSpec, Refusal } from "./provider.js";
3
+ import type { AttachedComputer, CallContext, ComputerCapabilities, ComputerConnection, ComputerInfo, ComputerProvider, ComputerRef, ComputerSpec, CreatedComputer, NetworkPolicy, NetworkSpec, Refusal } from "./provider.js";
4
4
  import { type Result } from "./result.js";
5
5
  /** The longest a local browser lives: a day, as pi-browser's local Chrome. */
6
6
  export declare const LOCAL_MAX_LIFETIME_MS: number;
7
- /** A browser takes no mount. */
7
+ /** A browser takes no mount: its descriptor's (descriptors/local-chrome.ts). */
8
8
  export declare const MOUNT: readonly MountKind[];
9
- /** The networks a local browser runs on, through its egress proxy: public addresses ("open"), or only the hosts of a list
10
- * ("allow"), public ones still. It cannot have none: a browser with no network has nothing to do. */
11
- export declare const NETWORK: readonly NetworkForm[];
12
9
  /** A spec's network as this browser's proxy takes it: open (no list), a list (parseAllow's), or why it can't. */
13
10
  export declare function browserNetworkOf(network: unknown): {
14
11
  allow?: string[];
15
12
  } | {
16
13
  problem: string;
17
14
  };
18
- /** The one configuration it offers: a browser with a CDP target. No live view: a person watching runs it headed. */
15
+ /** The one configuration it offers, its descriptor's: a browser with a CDP target. */
19
16
  export declare const CAPABILITIES: readonly KindCapabilities[];
20
17
  export interface LocalBrowserOptions {
21
18
  /** The Chrome or Chromium to run; default the one findChrome finds in `env`, then in the usual places. */
@@ -35,7 +32,7 @@ export interface LocalBrowserOptions {
35
32
  /** Computers that are this machine's Chrome. */
36
33
  export declare class LocalBrowserProvider implements ComputerProvider {
37
34
  #private;
38
- readonly id = "local";
35
+ readonly id = "local-chrome";
39
36
  readonly version: string;
40
37
  readonly root: string;
41
38
  constructor({ executablePath, env, headed, root, uid }?: LocalBrowserOptions);
@@ -86,4 +83,4 @@ export declare class LocalBrowserProvider implements ComputerProvider {
86
83
  /** The provider, built from its options alone: no key, and no environment read but the `env` it is given. */
87
84
  export declare function create(options?: LocalBrowserOptions): LocalBrowserProvider;
88
85
  /** The conformance CLI's module for the local browser: its live switch, its image and its notes. */
89
- export declare const conformance: () => Promise<typeof import("./conformance/local.js")>;
86
+ export declare const conformance: () => Promise<typeof import("./conformance/local-chrome.js")>;
@@ -27,11 +27,13 @@ import { lstat, mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises
27
27
  import { tmpdir } from "node:os";
28
28
  import { join, resolve } from "node:path";
29
29
  import { fileURLToPath } from "node:url";
30
- import { BROWSER_IMAGE, browserClient, browserHello, carries, labelsProblem } from "./browser.js";
30
+ import { browserClient, browserHello, carries, labelsProblem } from "./browser.js";
31
31
  import { alive, answeringPath, CHROME_FLAGS, checkChrome, findChrome, killTree, NO_CHROME, AS_ROOT, runsWith, singletonDir } from "./chrome.js";
32
+ import { LOCAL } from "./descriptors/local-chrome.js";
33
+ import { BROWSER_IMAGE } from "./descriptors/shared.js";
32
34
  import { parseAllow } from "./docker/egress-proxy.js";
33
35
  import { BROWSER_FILE, CHROME_PID_FILE, EGRESS_SOCKET_FILE, PROFILE_DIR, READY_MS, STATE_FILE, SUPERVISOR_FILE } from "./local-supervisor.js";
34
- import { checkLifetime } from "./provider.js";
36
+ import { checkTenure, runLifetimeMs } from "./provider.js";
35
37
  import { fail, ok } from "./result.js";
36
38
  const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
37
39
  const SUPERVISOR = fileURLToPath(new URL("./local-supervisor.js", import.meta.url));
@@ -43,11 +45,11 @@ const WINDOW = "--window-size=1280,800";
43
45
  const SOCKET_PATH_MAX = 107;
44
46
  /** How long a release waits for the supervisor, then for Chrome, to end. */
45
47
  const END_MS = 10_000;
46
- /** A browser takes no mount. */
47
- export const MOUNT = [];
48
- /** The networks a local browser runs on, through its egress proxy: public addresses ("open"), or only the hosts of a list
49
- * ("allow"), public ones still. It cannot have none: a browser with no network has nothing to do. */
50
- export const NETWORK = ["open", "allow"];
48
+ /** A browser takes no mount: its descriptor's (descriptors/local-chrome.ts). */
49
+ export const MOUNT = LOCAL.mounts;
50
+ /** The networks a local browser runs on, its descriptor's: through its egress proxy, public addresses ("open"), or only
51
+ * the hosts of a list ("allow"), public ones still. */
52
+ const NETWORK = LOCAL.network;
51
53
  /** A spec's network as this browser's proxy takes it: open (no list), a list (parseAllow's), or why it can't. */
52
54
  export function browserNetworkOf(network) {
53
55
  if (network === "open")
@@ -73,8 +75,8 @@ const networkRecord = (network) => {
73
75
  };
74
76
  /** A browser's network as list, attach and network() read it back from browser.json. */
75
77
  const networkRead = (record) => (record.allow ? { allow: [...record.allow] } : "open");
76
- /** The one configuration it offers: a browser with a CDP target. No live view: a person watching runs it headed. */
77
- export const CAPABILITIES = [{ kind: "browser", groups: ["cdp"] }];
78
+ /** The one configuration it offers, its descriptor's: a browser with a CDP target. */
79
+ export const CAPABILITIES = LOCAL.capabilities;
78
80
  const ID = /^lb-[0-9a-f]{16}$/;
79
81
  const idProblem = (id) => (typeof id === "string" && ID.test(id) ? undefined : `${typeof id === "string" ? JSON.stringify(id) : String(id)} is not a local browser's id`);
80
82
  const refOf = (id) => ({ id, name: id });
@@ -90,7 +92,7 @@ const readJson = async (file) => {
90
92
  };
91
93
  /** Computers that are this machine's Chrome. */
92
94
  export class LocalBrowserProvider {
93
- id = "local";
95
+ id = "local-chrome";
94
96
  version = VERSION;
95
97
  #executablePath;
96
98
  #env;
@@ -143,10 +145,11 @@ export class LocalBrowserProvider {
143
145
  check(spec) {
144
146
  const refusals = [];
145
147
  const given = (typeof spec === "object" && spec !== null ? spec : {});
146
- const { image, lifetimeMs, network, labels } = given;
148
+ const { image, lifetimeMs, owner, network, labels } = given;
147
149
  if (image !== BROWSER_IMAGE)
148
150
  refusals.push({ field: "image", message: `a local browser is this machine's Chrome: image is "${BROWSER_IMAGE}", not ${JSON.stringify(image)}` });
149
- refusals.push(...checkLifetime(lifetimeMs, this.capabilities()));
151
+ // A run's browser: it declares no persistence, so an agent's (spec.owner) is refused in words.
152
+ refusals.push(...checkTenure({ lifetimeMs, owner }, this.capabilities(), LOCAL.label));
150
153
  const net = browserNetworkOf(network);
151
154
  if ("problem" in net)
152
155
  refusals.push({ field: "network", message: net.problem });
@@ -196,11 +199,11 @@ export class LocalBrowserProvider {
196
199
  return fail("invalid", `the local browser's root ${this.root} is too long for a Unix socket under it: set the root option to a shorter directory`);
197
200
  const now = Date.now();
198
201
  const record = {
199
- provider: "local",
202
+ provider: LOCAL.id,
200
203
  id,
201
204
  labels: { ...spec.labels },
202
205
  created: new Date(now).toISOString(),
203
- deadline: new Date(now + spec.lifetimeMs).toISOString(),
206
+ deadline: new Date(now + runLifetimeMs(spec)).toISOString(),
204
207
  executablePath: this.executable(),
205
208
  args: [...CHROME_FLAGS, ...(this.#headed ? [] : ["--headless=new"]), WINDOW],
206
209
  ...networkRecord(spec.network),
@@ -296,7 +299,7 @@ export class LocalBrowserProvider {
296
299
  }
297
300
  async #record(id) {
298
301
  const record = await readJson(join(this.#dir(id), BROWSER_FILE));
299
- return record?.provider === "local" && record.id === id ? record : undefined;
302
+ return record?.provider === LOCAL.id && record.id === id ? record : undefined;
300
303
  }
301
304
  /** Chrome's state, when the Chrome it names still runs on this browser's profile. */
302
305
  async #live(id) {
@@ -469,4 +472,4 @@ export function create(options = {}) {
469
472
  return new LocalBrowserProvider(options ?? {});
470
473
  }
471
474
  /** The conformance CLI's module for the local browser: its live switch, its image and its notes. */
472
- export const conformance = () => import("./conformance/local.js");
475
+ export const conformance = () => import("./conformance/local-chrome.js");
@@ -1,4 +1,4 @@
1
- /** The browser's record, written by local.ts before the supervisor starts: the label a list finds it by. */
1
+ /** The browser's record, written by local-chrome.ts before the supervisor starts: the label a list finds it by. */
2
2
  export declare const BROWSER_FILE = "browser.json";
3
3
  /** What the supervisor writes once Chrome answers: the pids and ports a connect and a release read. */
4
4
  export declare const STATE_FILE = "state.json";
@@ -17,9 +17,9 @@ export declare const BROWSER_MAX_TUNNELS = 128;
17
17
  export declare const BROWSER_MAX_CONNECTIONS = 100000;
18
18
  /** How long Chrome has to answer on its debugging port. */
19
19
  export declare const READY_MS = 20000;
20
- /** What local.ts writes in browser.json. */
20
+ /** What local-chrome.ts writes in browser.json. */
21
21
  export interface BrowserRecord {
22
- provider: "local";
22
+ provider: "local-chrome";
23
23
  id: string;
24
24
  labels: Record<string, string>;
25
25
  /** ISO times. */
@@ -1,4 +1,4 @@
1
- // One local browser's supervisor: a detached Node process of its own per browser (local.ts starts it), so the browser
1
+ // One local browser's supervisor: a detached Node process of its own per browser (local-chrome.ts starts it), so the browser
2
2
  // outlives neither its deadline nor its release, whatever becomes of the process that made it. It reads the browser's
3
3
  // directory (browser.json), starts the browser's egress proxy (docker/egress-proxy.ts: with no list, every public host
4
4
  // and nothing else; with the record's list, only its hosts, public ones still) on a Unix socket in that directory, with
@@ -6,7 +6,7 @@
6
6
  // (Chrome takes a proxy over TCP alone; the relay passes each connection to the socket unread, the proxy decides), then
7
7
  // starts Chrome behind that fence (chrome.ts chromeFence) with a fresh profile in the directory and a debugging port
8
8
  // Chrome picks on 127.0.0.1. Once Chrome's DevTools socket answers it writes state.json and one line on stdout, which
9
- // local.ts waits for; a Chrome that never does is reported on that line in words and nothing is left.
9
+ // local-chrome.ts waits for; a Chrome that never does is reported on that line in words and nothing is left.
10
10
  //
11
11
  // It then ends the browser (Chrome's whole process group, the proxy, the relay, Chrome's singleton socket directory and
12
12
  // the browser's directory) at the first of: the deadline in browser.json, SIGTERM (a release), or Chrome's own exit. So a
@@ -21,7 +21,7 @@ import { join, resolve } from "node:path";
21
21
  import { alive, chromeFence, killTree, NO_SANDBOX, ownDebugger, answeringPath, singletonDir } from "./chrome.js";
22
22
  import { startEgressProxy } from "./docker/egress-proxy.js";
23
23
  import { isCommand } from "./entry.js";
24
- /** The browser's record, written by local.ts before the supervisor starts: the label a list finds it by. */
24
+ /** The browser's record, written by local-chrome.ts before the supervisor starts: the label a list finds it by. */
25
25
  export const BROWSER_FILE = "browser.json";
26
26
  /** What the supervisor writes once Chrome answers: the pids and ports a connect and a release read. */
27
27
  export const STATE_FILE = "state.json";
package/dist/modal.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { KindCapabilities } from "./kinds.js";
2
2
  import { type MountKind } from "./mount.js";
3
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 GpuCapability, type NetworkForm, type NetworkPolicy, type NetworkSpec, type Refusal } from "./provider.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, type ReleaseHow } from "./provider.js";
5
5
  import { type Result } from "./result.js";
6
6
  import { type ScreenWatch, type ScreenWatchHandlers, type WatchOptions } from "./screen-watch.js";
7
7
  /** The App sandboxes are made in (modal-client@64880502:js/src/app.ts:32-61). */
@@ -142,29 +142,10 @@ export interface ModalProviderOptions {
142
142
  }
143
143
  /** The mount kinds a Modal computer takes, as capabilities().mount declares them: the run's folder on an Archil disk. */
144
144
  export declare const MOUNT: readonly MountKind[];
145
- /** The network a Modal computer's programs get: none, a network of their own (isolation.ts OWN_NETWORK_ONLY). */
146
- export declare const NETWORK: readonly NetworkForm[];
147
145
  /** The runtime a Modal sandbox runs under: vm, or gvisor for a GPU computer (Modal offers GPUs on gVisor only). */
148
146
  export type ModalRuntime = "vm" | "gvisor";
149
- /**
150
- * The GPU types Modal takes, by its own names (guide/gpu, 11-10): "A100" is the 40 GB one, "A100-40GB" its explicit
151
- * name. Its "H100!" and "B200+" variants (no upgrade to an H200; a B200 or B300) are not offered: what a computer gets
152
- * should be what it asked for.
153
- */
154
- export declare const MODAL_GPU_TYPES: readonly ["T4", "L4", "A10", "L40S", "A100", "A100-40GB", "A100-80GB", "RTX-PRO-6000", "H100", "H200", "B200", "B300"];
155
- /** The most GPUs Modal gives one container: 8 (guide/gpu; an A10 container takes at most 4, which Modal refuses in words past). */
156
- export declare const MODAL_GPU_MAX = 8;
157
- /**
158
- * The GPUs Modal offers, as capabilities().gpu and CAPABILITIES declare them: on gVisor, Modal's one GPU runtime;
159
- * preemptible, as Modal may end a GPU container to free capacity; no mount yet, the Archil client's FUSE mount not
160
- * being proven on gVisor; and the loopback fence made inside a user namespace, as gVisor's root may not make a network
161
- * namespace itself (a live probe, 11-11: unshare -n refused, unshare -Urn allowed).
162
- */
163
- export declare const MODAL_GPU: Readonly<GpuCapability>;
164
- /** The machine kind, groups and GPUs of its one configuration: a linux computer, with GPUs when asked. */
147
+ /** The machine kind, groups and GPUs of its one configuration (its descriptor's): a linux computer, with GPUs when asked. */
165
148
  export declare const CAPABILITIES: readonly KindCapabilities[];
166
- /** A registry tag for linux/amd64 that Modal can pull: the default when a setting names no image. */
167
- export declare const MODAL_DEFAULT_IMAGE = "debian:bookworm-slim";
168
149
  /** The SDK's default server (modal-client@64880502:js/src/config.ts:143). */
169
150
  export declare const MODAL_DEFAULT_SERVER_URL = "https://api.modal.com:443";
170
151
  /** What modalClient gives the SDK's ModalClient: the token, explicitly, so the SDK fills none of it in. */
@@ -325,5 +306,5 @@ export declare class ModalProvider implements ComputerProvider {
325
306
  * loses nothing (every call that changed it synced, and the next claim revokes the hold), so it is said through
326
307
  * onNote, and the release succeeds once the sandbox is gone.
327
308
  */
328
- release(ref: ComputerRef, how: "stop" | "delete", { signal }?: CallContext): Promise<Result<void>>;
309
+ release(ref: ComputerRef, how: ReleaseHow, { signal }?: CallContext): Promise<Result<void>>;
329
310
  }
package/dist/modal.js CHANGED
@@ -6,44 +6,28 @@ import { readFileSync } from "node:fs";
6
6
  import { Readable, Writable } from "node:stream";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { DaemonClient } from "./client.js";
9
+ import { MODAL, MODAL_DEFAULT_IMAGE, MODAL_GPU } from "./descriptors/modal.js";
9
10
  import { COMPUTER_LABEL, DAEMON_IN_COMPUTER, DEADLINE_LABEL, DEFAULT_CPUS, DEFAULT_MEMORY_MB, helloDrift, probeNetworkDrift, probeNotes, probeReportOf, WORK, } from "./drift.js";
10
11
  import { OWN_NETWORK_ONLY, probeOwnNetworkDrift, TOOL_USER } from "./isolation.js";
11
12
  import { releaseOlder } from "./janitor.js";
12
13
  import { EPOCH_LABEL, epochOf, RUN_LABEL } from "./labels.js";
13
14
  import { checkMount, readBackOf } from "./mount.js";
14
15
  import { ARCHIL_HELPER, ARCHIL_MOUNT_LABEL, ARCHIL_TOOL_UID, archilMount, archilRefusals, archilRelease, claimEpoch, mountDrift, readArchilMount, recordedArchil as recordedArchilOf, syncingClient, } from "./mount-archil.js";
15
- import { checkGpu, checkLifetime, } from "./provider.js";
16
- import { fail, ok } from "./result.js";
16
+ import { checkGpu, checkTenure, runLifetimeMs, } from "./provider.js";
17
+ import { failFor, ok, vendorFail } from "./result.js";
17
18
  import { daemonWatch } from "./screen-watch.js";
18
19
  import { connectionError } from "./test-connection.js";
19
20
  import { waitUntil } from "./wait.js";
21
+ /** This module's failures: one with code vendor names Modal. */
22
+ const fail = failFor("modal");
20
23
  /** The mount kinds a Modal computer takes, as capabilities().mount declares them: the run's folder on an Archil disk. */
21
- export const MOUNT = ["archil"];
22
- /** The network a Modal computer's programs get: none, a network of their own (isolation.ts OWN_NETWORK_ONLY). */
23
- export const NETWORK = ["none"];
24
- /**
25
- * The GPU types Modal takes, by its own names (guide/gpu, 11-10): "A100" is the 40 GB one, "A100-40GB" its explicit
26
- * name. Its "H100!" and "B200+" variants (no upgrade to an H200; a B200 or B300) are not offered: what a computer gets
27
- * should be what it asked for.
28
- */
29
- export const MODAL_GPU_TYPES = ["T4", "L4", "A10", "L40S", "A100", "A100-40GB", "A100-80GB", "RTX-PRO-6000", "H100", "H200", "B200", "B300"];
30
- /** The most GPUs Modal gives one container: 8 (guide/gpu; an A10 container takes at most 4, which Modal refuses in words past). */
31
- export const MODAL_GPU_MAX = 8;
32
- /**
33
- * The GPUs Modal offers, as capabilities().gpu and CAPABILITIES declare them: on gVisor, Modal's one GPU runtime;
34
- * preemptible, as Modal may end a GPU container to free capacity; no mount yet, the Archil client's FUSE mount not
35
- * being proven on gVisor; and the loopback fence made inside a user namespace, as gVisor's root may not make a network
36
- * namespace itself (a live probe, 11-11: unshare -n refused, unshare -Urn allowed).
37
- */
38
- export const MODAL_GPU = Object.freeze({ types: [...MODAL_GPU_TYPES], max: MODAL_GPU_MAX, isolation: "gvisor", preemptible: true, mounts: [], fence: "userns-netns" });
39
- /** A copy of MODAL_GPU, so no caller can change the provider's own. */
24
+ export const MOUNT = MODAL.mounts;
25
+ /** A copy of its descriptor's MODAL_GPU, so no caller can change the provider's own. */
40
26
  const modalGpuCapability = () => ({ ...MODAL_GPU, types: [...MODAL_GPU.types], mounts: [] });
41
27
  /** A GPU as the SDK takes it: the type, then :count past one ("T4", "H100:8"). */
42
28
  const modalGpu = ({ type, count }) => (count === 1 ? type : `${type}:${count}`);
43
- /** The machine kind, groups and GPUs of its one configuration: a linux computer, with GPUs when asked. */
44
- export const CAPABILITIES = [{ kind: "linux", groups: ["exec", "files", "processes"], gpu: modalGpuCapability() }];
45
- /** A registry tag for linux/amd64 that Modal can pull: the default when a setting names no image. */
46
- export const MODAL_DEFAULT_IMAGE = "debian:bookworm-slim";
29
+ /** The machine kind, groups and GPUs of its one configuration (its descriptor's): a linux computer, with GPUs when asked. */
30
+ export const CAPABILITIES = MODAL.capabilities;
47
31
  /** The SDK's default server (modal-client@64880502:js/src/config.ts:143). */
48
32
  export const MODAL_DEFAULT_SERVER_URL = "https://api.modal.com:443";
49
33
  /** Not a literal, so no type checker or bundler resolves the SDK from this package. */
@@ -317,7 +301,7 @@ function codeOf(error) {
317
301
  // TaskExecStart, when its command, init, has exited). Gone, so create waits to read why.
318
302
  if (code === 9)
319
303
  return "gone";
320
- return "modal";
304
+ return "vendor";
321
305
  }
322
306
  /** Settles with the promise's result, or a timeout or abort in words once ms pass or signal aborts. */
323
307
  function race(promise, what, ms, signal) {
@@ -589,7 +573,7 @@ export class ModalProvider {
589
573
  return {
590
574
  kind: "linux",
591
575
  lifetime: "vendor",
592
- network: [...NETWORK],
576
+ network: [...MODAL.network],
593
577
  networkReadBack: false,
594
578
  isolation: "vm",
595
579
  os: "linux",
@@ -621,7 +605,7 @@ export class ModalProvider {
621
605
  }
622
606
  else if (image.includes("\0"))
623
607
  refuse("image", NUL);
624
- refusals.push(...checkLifetime(lifetimeMs, this.capabilities()));
608
+ refusals.push(...checkTenure(given, this.capabilities(), "Modal"));
625
609
  if (network === "open" || (typeof network === "object" && network !== null && "allow" in network))
626
610
  refuse("network", OWN_NETWORK_ONLY);
627
611
  else if (network !== "none")
@@ -685,7 +669,7 @@ export class ModalProvider {
685
669
  if (!app.ok)
686
670
  return app;
687
671
  const name = `computer-${randomBytes(6).toString("hex")}`;
688
- const deadline = new Date(Date.now() + spec.lifetimeMs).toISOString();
672
+ const deadline = new Date(Date.now() + runLifetimeMs(spec)).toISOString();
689
673
  // An Archil mount is made under the run's claim (check() held the spec to both labels), for the tool user alone.
690
674
  const archil = spec.mount?.kind === "archil" ? { mount: spec.mount, run: spec.labels?.[RUN_LABEL], epoch: claimEpoch(spec.labels) } : undefined;
691
675
  const user = archil === undefined ? (userOf(spec.user) ?? this.#user) : ARCHIL_USER;
@@ -740,7 +724,7 @@ export class ModalProvider {
740
724
  ...(spec.gpu === undefined ? {} : { gpu: modalGpu(spec.gpu) }),
741
725
  command,
742
726
  // Modal ends the sandbox at its timeout: the lifetime, in the whole seconds the SDK takes.
743
- timeoutMs: Math.ceil(spec.lifetimeMs / 1000) * 1000,
727
+ timeoutMs: Math.ceil(runLifetimeMs(spec) / 1000) * 1000,
744
728
  workdir,
745
729
  cpu: Math.min(CPU_REQUEST, cpuLimit),
746
730
  cpuLimit,
@@ -1144,7 +1128,7 @@ export class ModalProvider {
1144
1128
  return fail("timeout", `the daemon in ${name} did not answer hello within ${seconds(totalMs)}`);
1145
1129
  if (hello.error.code !== "gone")
1146
1130
  return hello;
1147
- return { ...fail("modal", `cannot reach the daemon in ${name}: ${stderr.trim() || hello.error.message}`), notListening: true };
1131
+ return { ...vendorFail("modal", `cannot reach the daemon in ${name}: ${stderr.trim() || hello.error.message}`), notListening: true };
1148
1132
  }
1149
1133
  return ok({ client, hello: hello.value, close });
1150
1134
  }
@@ -11,7 +11,7 @@ import { createHash } from "node:crypto";
11
11
  import { readFileSync } from "node:fs";
12
12
  import { EPOCH_LABEL, epochOf, RUN_LABEL, runProblem } from "./labels.js";
13
13
  import { readBackOf, WORKSPACE } from "./mount.js";
14
- import { fail, ok } from "./result.js";
14
+ import { fail, failAs, ok } from "./result.js";
15
15
  /** Where the image has the root helper, root:root 0755. */
16
16
  export const ARCHIL_HELPER = "/usr/local/sbin/agentrun-archil";
17
17
  /** The user computerd runs every tool as in a computer with an Archil mount: no sudo, no capability, no token. */
@@ -173,7 +173,7 @@ export async function archilMount({ root, mount, self: computer, releaseOlder, t
173
173
  const step = async (argv, what, stdin) => {
174
174
  const ran = await root.run(argv, { timeoutMs, ...(stdin === undefined ? {} : { stdin }), ...(signal ? { signal } : {}) });
175
175
  if (!ran.ok)
176
- return fail(ran.error.code, `archil ${what} in the computer could not run: ${scrub(ran.error.message, mount.token)}`);
176
+ return failAs(ran.error, `archil ${what} in the computer could not run: ${scrub(ran.error.message, mount.token)}`);
177
177
  return ran;
178
178
  };
179
179
  const failed = (what, ran, code = "refused") => fail(code, `archil ${what} in the computer failed (exit ${ran.exitCode}): ${scrub(ran.output, mount.token)}`);
@@ -186,7 +186,7 @@ export async function archilMount({ root, mount, self: computer, releaseOlder, t
186
186
  }
187
187
  const older = await releaseOlder();
188
188
  if (!older.ok)
189
- return fail(older.error.code, `the takeover could not release the run's lower epochs, so nothing was revoked or mounted: ${older.error.message}`);
189
+ return failAs(older.error, `the takeover could not release the run's lower epochs, so nothing was revoked or mounted: ${older.error.message}`);
190
190
  const twinsOf = (kept) => kept.filter((ref) => ref.id !== computer.id).map((ref) => ref.name);
191
191
  const twins = twinsOf(older.value.kept);
192
192
  // Right before any force, the run's listing is read again: a higher epoch made since (two creates of one run
@@ -194,7 +194,7 @@ export async function archilMount({ root, mount, self: computer, releaseOlder, t
194
194
  const beforeForce = async () => {
195
195
  const again = await releaseOlder();
196
196
  if (!again.ok)
197
- return fail(again.error.code, `the run's computers, listed again right before the force, stop it, so nothing was revoked: ${again.error.message}`);
197
+ return failAs(again.error, `the run's computers, listed again right before the force, stop it, so nothing was revoked: ${again.error.message}`);
198
198
  const late = twinsOf(again.value.kept);
199
199
  if (late.length > 0)
200
200
  return fail("refused", `the run has ${late.join(", ")} at this claim's same epoch, listed right before the force: a create never forces off a computer of its own epoch, so nothing was revoked`);
@@ -14,7 +14,9 @@
14
14
  // memory for the call. Neither is in a word this module returns.
15
15
  import { randomBytes } from "node:crypto";
16
16
  import { PassThrough, Writable } from "node:stream";
17
- import { fail, ok } from "./result.js";
17
+ import { errorOf, failFor, ok, vendorFail } from "./result.js";
18
+ /** This module's failures: one with code vendor names Orgo. */
19
+ const fail = failFor("orgo");
18
20
  /** Orgo's API. */
19
21
  export const ORGO_API_URL = "https://www.orgo.ai/api";
20
22
  /** The most Orgo's one-step upload takes. */
@@ -31,7 +33,7 @@ const SESSION = "agentrun-init";
31
33
  export const quote = (word) => `'${word.replaceAll("'", "'\\''")}'`;
32
34
  /** An argv as one bash command line. */
33
35
  export const commandLine = (argv) => argv.map(quote).join(" ");
34
- const codeOfStatus = (status) => status === 401 || status === 403 ? "denied" : status === 404 ? "not_found" : status === 429 ? "limit" : status === 400 || status === 422 ? "invalid" : status === 409 ? "refused" : "orgo";
36
+ const codeOfStatus = (status) => status === 401 || status === 403 ? "denied" : status === 404 ? "not_found" : status === 429 ? "limit" : status === 400 || status === 422 ? "invalid" : status === 409 ? "refused" : "vendor";
35
37
  /** Orgo's REST API with a key: every call bounded, every failure a code and words that never hold the key. */
36
38
  export function orgoRest({ apiKey, apiUrl = ORGO_API_URL, fetch: fetcher = globalThis.fetch }) {
37
39
  const base = apiUrl.replace(/\/+$/, "");
@@ -58,7 +60,7 @@ export function orgoRest({ apiKey, apiUrl = ORGO_API_URL, fetch: fetcher = globa
58
60
  return fail("aborted", `${what} was aborted`);
59
61
  if (bound.aborted)
60
62
  return fail("timeout", `${what} did not answer within ${timeoutMs / 1000} s`);
61
- return fail("orgo", `${what} failed: ${scrub(error instanceof Error ? error.message : String(error))}`);
63
+ return vendorFail("orgo", `${what} failed: ${scrub(error instanceof Error ? error.message : String(error))}`);
62
64
  }
63
65
  const text = await response.text().catch(() => "");
64
66
  let parsed;
@@ -73,7 +75,8 @@ export function orgoRest({ apiKey, apiUrl = ORGO_API_URL, fetch: fetcher = globa
73
75
  const { error, code } = (parsed ?? {});
74
76
  const words = typeof error === "string" ? error : text || response.statusText;
75
77
  const orgoCode = typeof code === "string" ? code : undefined;
76
- return { ...fail(codeOfStatus(response.status), `${what} answered ${response.status}: ${scrub(words)}${orgoCode ? ` (${orgoCode})` : ""}`), status: response.status, ...(orgoCode ? { orgoCode } : {}) };
78
+ const error_ = errorOf(codeOfStatus(response.status), `${what} answered ${response.status}: ${scrub(words)}${orgoCode ? ` (${orgoCode})` : ""}`, "orgo");
79
+ return { ok: false, error: error_, status: response.status, ...(orgoCode ? { orgoCode } : {}) };
77
80
  },
78
81
  };
79
82
  }
@@ -93,16 +96,16 @@ async function typeLine(terminal, line, heard, { deadline, echoMs }) {
93
96
  for (let tries = 1; tries <= TYPE_TRIES; tries++) {
94
97
  const ended = terminal.ended();
95
98
  if (ended !== undefined)
96
- return fail("orgo", ended);
99
+ return vendorFail("orgo", ended);
97
100
  terminal.send(line);
98
101
  if (await terminal.waitFor(() => heard() || terminal.ended() !== undefined, Math.min(echoMs, left()))) {
99
102
  const after = terminal.ended();
100
- return after !== undefined && !heard() ? fail("orgo", after) : ok(undefined);
103
+ return after !== undefined && !heard() ? vendorFail("orgo", after) : ok(undefined);
101
104
  }
102
105
  if (Date.now() >= deadline)
103
106
  return fail("timeout", `the line was typed ${tries} ${tries === 1 ? "time" : "times"}, and the shell had not echoed it`);
104
107
  }
105
- return fail("orgo", `the line was typed ${TYPE_TRIES} times, and the shell never echoed it`);
108
+ return vendorFail("orgo", `the line was typed ${TYPE_TRIES} times, and the shell never echoed it`);
106
109
  }
107
110
  /** A frame's bytes as text, when they are: a string, an ArrayBuffer or a typed array; a Blob is read, in order. */
108
111
  function frameText(data) {
@@ -131,7 +134,7 @@ export function orgoTerminalChannel({ rest, workspaceId, webSocket = defaultWebS
131
134
  return ran;
132
135
  const { exit_code: exitCode, output } = ran.value ?? {};
133
136
  if (typeof exitCode !== "number")
134
- return fail("orgo", `Orgo's bash call answered no exit code (${JSON.stringify(ran.value)?.slice(0, 200)})`);
137
+ return vendorFail("orgo", `Orgo's bash call answered no exit code (${JSON.stringify(ran.value)?.slice(0, 200)})`);
135
138
  return ok({ exitCode, output: typeof output === "string" ? output : "" });
136
139
  };
137
140
  const open = async (computer, { session, timeoutMs, signal }) => {
@@ -140,7 +143,7 @@ export function orgoTerminalChannel({ rest, workspaceId, webSocket = defaultWebS
140
143
  return read;
141
144
  const password = read.value?.vnc_password;
142
145
  if (typeof password !== "string" || password === "")
143
- return fail("orgo", `Orgo gave no terminal password for ${computer}: is it running?`);
146
+ return vendorFail("orgo", `Orgo gave no terminal password for ${computer}: is it running?`);
144
147
  const url = new URL(`/desktops/${encodeURIComponent(computer)}/ws/terminal`, rest.origin.replace(/^http/, "ws"));
145
148
  url.searchParams.set("token", password);
146
149
  if (session !== undefined)
@@ -150,7 +153,7 @@ export function orgoTerminalChannel({ rest, workspaceId, webSocket = defaultWebS
150
153
  socket = webSocket(url.href);
151
154
  }
152
155
  catch (error) {
153
- return fail("orgo", `the terminal of ${computer} could not be opened: ${String(error?.message ?? error).replaceAll(password, "[password]").slice(0, 200)}`);
156
+ return vendorFail("orgo", `the terminal of ${computer} could not be opened: ${String(error?.message ?? error).replaceAll(password, "[password]").slice(0, 200)}`);
154
157
  }
155
158
  const outputs = [];
156
159
  const ends = [];
@@ -278,7 +281,7 @@ export function orgoTerminalChannel({ rest, workspaceId, webSocket = defaultWebS
278
281
  });
279
282
  terminal.onEnd((words) => {
280
283
  clearTimeout(timer);
281
- settle(fail("orgo", `the terminal of ${computer} did not open: ${words}`));
284
+ settle(vendorFail("orgo", `the terminal of ${computer} did not open: ${words}`));
282
285
  });
283
286
  });
284
287
  if (!opened.ok) {
@@ -309,7 +312,7 @@ export function orgoTerminalChannel({ rest, workspaceId, webSocket = defaultWebS
309
312
  const ran = await bash(computer, `setsid -f ${detached}`, timeoutMs, signal);
310
313
  if (!ran.ok)
311
314
  return ran;
312
- return ran.value.exitCode === 0 ? ok(undefined) : fail("orgo", `starting ${argv[0]} from bash exited ${ran.value.exitCode}: ${ran.value.output.trim().slice(0, 300)}`);
315
+ return ran.value.exitCode === 0 ? ok(undefined) : vendorFail("orgo", `starting ${argv[0]} from bash exited ${ran.value.exitCode}: ${ran.value.output.trim().slice(0, 300)}`);
313
316
  }
314
317
  const deadline = Date.now() + timeoutMs;
315
318
  const terminal = await open(computer, { session: SESSION, timeoutMs, ...(signal ? { signal } : {}) });
@@ -350,7 +353,7 @@ export function orgoTerminalChannel({ rest, workspaceId, webSocket = defaultWebS
350
353
  const sent = () => `the terminal sent ${terminal.seen()} and no marker; its last bytes: ${JSON.stringify(before.slice(-300))}`;
351
354
  terminal.onEnd((words) => {
352
355
  said = words;
353
- settle(fail("orgo", `computerd's bridge in ${computer} ended before it started: ${words}; ${sent()}`));
356
+ settle(vendorFail("orgo", `computerd's bridge in ${computer} ended before it started: ${words}; ${sent()}`));
354
357
  readable.end();
355
358
  });
356
359
  const late = (why) => fail("timeout", `computerd's bridge in ${computer} did not start within ${timeoutMs / 1000} s: ${why}; ${sent()}`);