@parcha/agentrun-computer 0.1.0-beta.41 → 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.
Files changed (73) hide show
  1. package/NOTICE +2 -0
  2. package/README.md +254 -14
  3. package/box/README.md +2 -2
  4. package/box/build-e2b.mjs +1 -1
  5. package/dist/box-image.d.ts +1 -3
  6. package/dist/box-image.js +1 -11
  7. package/dist/boxd.d.ts +126 -0
  8. package/dist/boxd.js +418 -0
  9. package/dist/cloudflare.d.ts +32 -0
  10. package/dist/cloudflare.js +179 -0
  11. package/dist/computerd-linux-amd64 +0 -0
  12. package/dist/computerd-linux-arm64 +0 -0
  13. package/dist/computerd.json +2 -2
  14. package/dist/conformance/boxd.d.ts +77 -0
  15. package/dist/conformance/boxd.js +113 -0
  16. package/dist/conformance/cases/isolation.js +1 -17
  17. package/dist/conformance/cloudflare.d.ts +42 -0
  18. package/dist/conformance/cloudflare.js +54 -0
  19. package/dist/conformance/dial-only.d.ts +6 -0
  20. package/dist/conformance/dial-only.js +9 -0
  21. package/dist/conformance/e2b.d.ts +12 -3
  22. package/dist/conformance/e2b.js +21 -4
  23. package/dist/conformance/fly.d.ts +52 -0
  24. package/dist/conformance/fly.js +52 -0
  25. package/dist/conformance/modal.d.ts +15 -2
  26. package/dist/conformance/modal.js +36 -3
  27. package/dist/conformance/morph.d.ts +59 -0
  28. package/dist/conformance/morph.js +95 -0
  29. package/dist/conformance/phone-harness.js +2 -2
  30. package/dist/conformance/runner.js +3 -3
  31. package/dist/conformance/sweep.d.ts +1 -6
  32. package/dist/conformance/sweep.js +8 -18
  33. package/dist/descriptors/boxd.d.ts +52 -0
  34. package/dist/descriptors/boxd.js +29 -0
  35. package/dist/descriptors/cloudflare.d.ts +21 -0
  36. package/dist/descriptors/cloudflare.js +29 -0
  37. package/dist/descriptors/e2b.d.ts +4 -0
  38. package/dist/descriptors/e2b.js +3 -0
  39. package/dist/descriptors/fly.d.ts +19 -0
  40. package/dist/descriptors/fly.js +28 -0
  41. package/dist/descriptors/index.d.ts +113 -1
  42. package/dist/descriptors/index.js +7 -2
  43. package/dist/descriptors/modal.d.ts +3 -0
  44. package/dist/descriptors/modal.js +7 -2
  45. package/dist/descriptors/morph.d.ts +15 -0
  46. package/dist/descriptors/morph.js +21 -0
  47. package/dist/descriptors/phone-harness.d.ts +1 -0
  48. package/dist/descriptors/phone-harness.js +2 -0
  49. package/dist/e2b.d.ts +7 -1
  50. package/dist/e2b.js +87 -44
  51. package/dist/fly.d.ts +43 -0
  52. package/dist/fly.js +245 -0
  53. package/dist/host.d.ts +8 -28
  54. package/dist/hosted/process.d.ts +19 -0
  55. package/dist/hosted/process.js +28 -0
  56. package/dist/hosted/provider.d.ts +11 -22
  57. package/dist/hosted/provider.js +30 -201
  58. package/dist/hosted/scripts.d.ts +2 -8
  59. package/dist/hosted/scripts.js +2 -22
  60. package/dist/hosted/ssh-exec.d.ts +2 -1
  61. package/dist/hosted/ssh-exec.js +58 -2
  62. package/dist/hosted/values.d.ts +5 -0
  63. package/dist/hosted/values.js +9 -0
  64. package/dist/index.d.ts +1 -1
  65. package/dist/index.js +2 -2
  66. package/dist/modal.d.ts +6 -0
  67. package/dist/modal.js +20 -10
  68. package/dist/morph.d.ts +65 -0
  69. package/dist/morph.js +495 -0
  70. package/dist/phone-harness.d.ts +15 -5
  71. package/dist/phone-harness.js +50 -15
  72. package/dist/screen-watch.js +2 -2
  73. package/package.json +20 -2
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ export { listProcesses, readAll } from "./processes.js";
11
11
  export { createActionMapper, daemonWatch, redactWords, ScreenWatchError, toAction, watchEndCode, watchScreen, } from "./screen-watch.js";
12
12
  export { HostedProvider, hostedDaemonPath } from "./hosted/provider.js";
13
13
  // The provider classes and their option types are not here: each provider loads by its id through the registry
14
- // (providerFor), or from its own subpath (@parcha/agentrun-computer/docker, /daytona, /modal, /e2b, /agent37, /orgo,
14
+ // (providerFor), or from its own subpath (@parcha/agentrun-computer/docker, /daytona, /modal, /e2b, /agent37, /morph, /orgo,
15
15
  // /phone-harness, /browserbase, /kernel, /local: each the provider file's name).
16
16
  export { VOLUME_SUBPATH_ENGINE } from "./docker/volume.js";
17
17
  export { DEFAULT_DOCKER_IMAGE, DOCKER_BASE, DOCKER_RECIPE, DOCKER_RECIPE_HAS, ensureImage, IMAGE_REPOSITORY, IMAGE_TIMEOUT_MS, imageSourceProblem, RECIPE_LABEL, recipeHash, recipeTag, } from "./docker/image.js";
@@ -28,6 +28,6 @@ export { EPOCH_LABEL, epochOf, epochProblem, IDLE_TTL_LABEL, OWNER_LABEL, OWNER_
28
28
  export { waitUntil } from "./wait.js";
29
29
  export { descriptorOf, isProviderId, providerFor, providerIds, providerModule, providers, } from "./providers.js";
30
30
  export { defineProvider, descriptorProblems, mountsOf } from "./descriptor.js";
31
- export { AGENT37, AGENT37_BASE_TEMPLATE, BROWSER_IMAGE, BROWSERBASE, DAYTONA, DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_GPU_SNAPSHOT, DESCRIPTORS, daytonaGpu, daytonaGpuSnapshot, DOCKER, E2B, KERNEL, LOCAL, MODAL, ORGO, ORGO_BASE_IMAGE, PHONE_GROUPS, PHONE_HARNESS, PHONE_IMAGE, } from "./descriptors/index.js";
31
+ export { AGENT37, AGENT37_BASE_TEMPLATE, BOXD, BOXD_DEFAULT_IMAGE, BROWSER_IMAGE, BROWSERBASE, DAYTONA, DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_GPU_SNAPSHOT, DESCRIPTORS, daytonaGpu, daytonaGpuSnapshot, DOCKER, E2B, KERNEL, LOCAL, MODAL, MORPH, ORGO, ORGO_BASE_IMAGE, PHONE_GROUPS, PHONE_HARNESS, PHONE_IMAGE, } from "./descriptors/index.js";
32
32
  export { configurationOf, entryOf, imagesOf, kindOf, kindServed, PROVIDERS, SETTING_KIND_NAMES, SETTING_KINDS, serves, servingRefusals, } from "./kinds.js";
33
33
  export * from "./conformance/index.js";
package/dist/modal.d.ts CHANGED
@@ -14,6 +14,12 @@ export interface ModalProviderOptions extends Omit<HostedOptions, "kind" | "desk
14
14
  /** The longest lifetime check takes, in ms: at most 24 hours, Modal's longest timeout, which is the default. */
15
15
  maxLifetimeMs?: number;
16
16
  timeouts?: Partial<HostedTimeouts>;
17
+ /**
18
+ * exec (default): the daemon goes in through exec's stdin and each connection is a bridge through Modal's exec. dial:
19
+ * the sandbox's command is the box image's agentrun-dial, and the machine dials the server (options.dial), which
20
+ * every connection goes over.
21
+ */
22
+ connect?: "exec" | "dial";
17
23
  }
18
24
  /** The SDK's default server (modal-client@64880502:js/src/config.ts:143). */
19
25
  export declare const MODAL_DEFAULT_SERVER_URL = "https://api.modal.com:443";
package/dist/modal.js CHANGED
@@ -3,8 +3,8 @@ import { MODAL } from "./descriptors/modal.js";
3
3
  import { DEFAULT_CPUS, DEFAULT_MEMORY_MB, WORK } from "./drift.js";
4
4
  import { HostError } from "./host.js";
5
5
  import { HostedProvider } from "./hosted/provider.js";
6
- import { PID_WRAPPER, pidKill, pidStderr } from "./hosted/scripts.js";
7
- import { isWhole } from "./hosted/values.js";
6
+ import { AGENTRUN_DIAL, PID_WRAPPER, pidKill, pidStderr } from "./hosted/scripts.js";
7
+ import { connectOf, isWhole } from "./hosted/values.js";
8
8
  import { ok } from "./result.js";
9
9
  /** A GPU as the SDK takes it: the type, then :count past one ("T4", "H100:8"). */
10
10
  const modalGpu = ({ type, count }) => (count === 1 ? type : `${type}:${count}`);
@@ -114,18 +114,22 @@ function codeOf(error) {
114
114
  class ModalHost {
115
115
  descriptor = MODAL;
116
116
  facts;
117
+ /** connect exec alone: a dial host has none (HostFacts.connect). */
118
+ exec;
117
119
  #sdk;
118
120
  #appName;
119
121
  /** Each sandbox create or a read gave, by id: let go of at its delete. */
120
122
  #sandboxes = new Map();
121
123
  #app;
122
- constructor(sdk, app) {
124
+ constructor(sdk, app, connect) {
123
125
  this.#sdk = sdk;
124
126
  this.#appName = app;
125
127
  this.facts = {
126
128
  // The sandbox's command is the entrypoint, which becomes init: Modal finishes the sandbox when that main process
127
- // exits (sandbox.ts:384-388), so init's exit ends the computer.
128
- daemon: "pid1",
129
+ // exits (sandbox.ts:384-388), so init's exit ends the computer. On dial the command is agentrun-dial, which
130
+ // starts init as its child and becomes `computerd attach`.
131
+ daemon: connect === "dial" ? "child" : "pid1",
132
+ ...(connect === "dial" ? { connect } : {}),
129
133
  // A GPU computer runs on gVisor, Modal's one GPU runtime (its descriptor's gpu.isolation): vm is every other computer's.
130
134
  isolation: "vm",
131
135
  lifetime: "vendor",
@@ -138,6 +142,8 @@ class ModalHost {
138
142
  user: ["uid"],
139
143
  labels: { count: MAX_TAGS, bytes: MAX_TAG_BYTES },
140
144
  };
145
+ if (connect === "exec")
146
+ this.exec = (id, argv, ctx) => this.#exec(id, argv, ctx);
141
147
  }
142
148
  errorCode(error) {
143
149
  return codeOf(error);
@@ -186,7 +192,10 @@ class ModalHost {
186
192
  */
187
193
  async create(req, ctx) {
188
194
  void ctx;
189
- if (req.command === undefined)
195
+ // A dial machine's command is the box image's agentrun-dial, and its boot env goes in as env, which the SDK sends as
196
+ // an ephemeral Secret (Secret.fromObject, modal@0.11.1 dist/index.js mergeEnvIntoSecrets).
197
+ const command = req.boot === undefined ? req.command : [AGENTRUN_DIAL];
198
+ if (command === undefined)
190
199
  throw new HostError("invalid", "a Modal sandbox's command is the entrypoint the adapter gives a pid1 host, and the request has none");
191
200
  let base;
192
201
  if (MODAL_IMAGE_ID.test(req.image)) {
@@ -202,7 +211,8 @@ class ModalHost {
202
211
  const cpuLimit = cpus / CPUS_PER_CORE;
203
212
  const params = {
204
213
  ...(req.gpu === undefined ? { runtime: "vm" } : { runtime: "gvisor", gpu: modalGpu(req.gpu) }),
205
- command: [...req.command],
214
+ command: [...command],
215
+ ...(req.boot === undefined ? {} : { env: { ...req.boot.env } }),
206
216
  timeoutMs: Math.ceil(req.lifetimeMs / 1000) * 1000,
207
217
  workdir: WORK,
208
218
  cpu: Math.min(CPU_REQUEST, cpuLimit),
@@ -292,7 +302,7 @@ class ModalHost {
292
302
  * (./hosted/scripts.ts): Modal has no kill for an exec, so kill runs pidKill in an exec of its own, which ends the
293
303
  * process and every process under it, then closes its stdin. Not once wait() read its exit: its pid may be another's.
294
304
  */
295
- async exec(id, argv, ctx) {
305
+ async #exec(id, argv, ctx) {
296
306
  const sandbox = await this.#sandbox(id);
297
307
  const program = await sandbox.exec([...PID_WRAPPER, ...argv], { mode: "binary" });
298
308
  const { stderr, pid } = pidStderr(program.stderr);
@@ -336,7 +346,7 @@ export class ModalProvider extends HostedProvider {
336
346
  return ok(boxImageRef());
337
347
  }
338
348
  constructor(options) {
339
- const { app, timeouts = {}, ...rest } = options ?? {};
349
+ const { app, timeouts = {}, connect, ...rest } = options ?? {};
340
350
  const sdk = options?.sdk;
341
351
  const lacks = [
342
352
  ["apps.fromName", sdk?.apps?.fromName],
@@ -349,6 +359,6 @@ export class ModalProvider extends HostedProvider {
349
359
  throw new Error(`options.sdk must be a Modal client; it lacks ${lacks.map(([name]) => name).join(", ")}`);
350
360
  if (typeof app !== "string" || app.trim() === "")
351
361
  throw new Error("options.app, the Modal app's name, is required");
352
- super(new ModalHost(sdk, app), { ...rest, kind: "linux", timeouts: { ...MODAL_TIMEOUTS, ...timeouts } });
362
+ super(new ModalHost(sdk, app, connectOf(connect, "Modal")), { ...rest, kind: "linux", timeouts: { ...MODAL_TIMEOUTS, ...timeouts } });
353
363
  }
354
364
  }
@@ -0,0 +1,65 @@
1
+ import { HostedProvider, type HostedOptions, type HostedTimeouts } from "./hosted/provider.js";
2
+ import { type Ssh2Module } from "./hosted/ssh-exec.js";
3
+ import type { CallContext } from "./provider.js";
4
+ import { type Result } from "./result.js";
5
+ /** One instance as Morph answers it (OpenAPI InstanceModel), as far as this provider reads it. */
6
+ export interface MorphInstance {
7
+ id: string;
8
+ /** pending, ready, paused, saving or error (OpenAPI InstanceStatus). */
9
+ status: string;
10
+ /** Unix seconds. */
11
+ created?: number;
12
+ metadata?: Record<string, string> | null;
13
+ /** ttl_expire_at in Unix seconds; null fields when the instance has no TTL (OpenAPI InstanceTTL). */
14
+ ttl?: {
15
+ ttl_seconds?: number | null;
16
+ ttl_expire_at?: number | null;
17
+ ttl_action?: string | null;
18
+ } | null;
19
+ }
20
+ /** The Morph provider's options: the key and ssh2, then the shared adapter's (HostedOptions). */
21
+ export interface MorphProviderOptions extends Omit<HostedOptions, "kind" | "desktop" | "maxLifetimeMs"> {
22
+ /** The account's API key. The caller passes it; this provider never reads it from the environment. */
23
+ apiKey: string;
24
+ /** The ssh2 package: the host's own, or anything with the same slice. */
25
+ ssh2: Ssh2Module;
26
+ /** The fetch every REST call goes through; default the global one. */
27
+ fetch?: typeof fetch;
28
+ /** Morph's REST API; default https://cloud.morph.so/api. */
29
+ apiUrl?: string;
30
+ /** Morph's SSH gateway; default ssh.cloud.morph.so, port 22. */
31
+ sshHost?: string;
32
+ sshPort?: number;
33
+ /** The longest lifetime check takes: 24 h by default, an assumed cap (Morph states none: unverified). */
34
+ maxLifetimeMs?: number;
35
+ timeouts?: Partial<HostedTimeouts>;
36
+ }
37
+ /** What create() takes: the provider's options, ssh2 optional (default the host's ssh2 package). */
38
+ export interface MorphOptions extends Omit<MorphProviderOptions, "ssh2"> {
39
+ ssh2?: Ssh2Module;
40
+ }
41
+ /**
42
+ * A MorphProvider from its options alone; it reads no environment. The key is options.apiKey, nowhere else (serve passes
43
+ * its MORPH_API_KEY, the conformance module what it reads), and ssh2 is the host's package unless given. Throws in words
44
+ * when an option is missing or wrong, never echoing a key.
45
+ */
46
+ export declare function create(options: MorphOptions): Promise<MorphProvider>;
47
+ /** The conformance CLI's module for Morph: its live switch, the run's cap, its snapshot and the drifted twin. */
48
+ export declare const conformance: () => Promise<typeof import("./conformance/morph.js")>;
49
+ /**
50
+ * Computers that are Morph instances, on the shared adapter. A spec's image is a Morph snapshot id. A server starts
51
+ * every one from the snapshot prepareImage() answers: our box image, built once in the key's own account.
52
+ */
53
+ export declare class MorphProvider extends HostedProvider {
54
+ /**
55
+ * The provider contract's prepareImage (its descriptor declares it): the box image as a snapshot of the key's
56
+ * account, its digest agentrun-box-<recipe hash>, found or built (MorphHost.boxSnapshot), so a new recipe is a new
57
+ * snapshot. ok with the snapshot's id; onWait is told "build" once, before a build, never when the account has one.
58
+ */
59
+ prepareImage(context?: CallContext & {
60
+ onWait?: (making: "build" | "pull", tag: string) => void;
61
+ }): Promise<Result<string>>;
62
+ constructor(options: MorphProviderOptions);
63
+ }
64
+ /** The account a key reaches, in words, for the sweep's scope: the key's sha256 prefix, never the key. */
65
+ export declare function accountOf(apiKey: string, apiUrl?: string): string;