@parcha/agentrun-computer 0.1.0-beta.61 → 0.1.0-beta.62

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.
@@ -0,0 +1,31 @@
1
+ // Render's descriptor: a Linux sandbox on a Render Sandbox (a microVM) in the operator's Render workspace, started from
2
+ // our box image, imported once into the workspace as a sandbox build by its prepareImage() (box-image.ts).
3
+ // Its machines dial the server (MachineHost facts.connect "dial"): Render's runs answer a command with no stdin, so
4
+ // nothing reaches into a sandbox from outside, and its computerd dials the server's attach route instead.
5
+ import { defineProvider } from "../descriptor.js";
6
+ import { SANDBOX } from "./shared.js";
7
+ export const RENDER = defineProvider({
8
+ id: "render",
9
+ label: "Render",
10
+ keys: [
11
+ { name: "RENDER_API_KEY", option: "apiKey", required: true },
12
+ // The workspace (owner) every sandbox is made in and listed from: Render's list needs it (tea-... or usr-...).
13
+ { name: "RENDER_WORKSPACE_ID", option: "ownerId", required: true },
14
+ ],
15
+ metered: true,
16
+ // Its machines dial the server: Render's runs take no stdin, so nothing reaches into one.
17
+ connect: "dial",
18
+ // None: a machine that dials takes no Archil mount (mountsOf).
19
+ mounts: [],
20
+ // None: its programs run in init's network of their own, their loopback alone (isolation.ts). Open and a list: their
21
+ // one way out is init's egress proxy, which reaches the public internet alone, and with a list its hosts alone
22
+ // (hosted/network.ts). The sandbox itself always reaches out (Render's allow-all): it fetches its daemon from the
23
+ // server and dials it.
24
+ network: ["none", "open", "allow"],
25
+ // A linux computer alone: no desktop yet.
26
+ capabilities: [SANDBOX],
27
+ // No default image: Render's base image has no agentrun-dial, so every computer starts from the box build its
28
+ // prepareImage() answers.
29
+ prepareImage: true,
30
+ load: () => import("../render.js"),
31
+ });
@@ -29,7 +29,7 @@ import { countTested } from "../test-connection.js";
29
29
  import { waitUntil } from "../wait.js";
30
30
  import { bounded, CALL_SLACK_MS, hostCall, openBridge, pause, rootOf, runToExit, seconds, untilAborted, uploadThroughExec, words } from "./process.js";
31
31
  import { downloadingConnection } from "./download.js";
32
- import { isWhole, PACKED_NAME, packLabels, unpackLabels } from "./values.js";
32
+ import { isPackedKey, isWhole, PACKED_NAME, packLabels, unpackLabels } from "./values.js";
33
33
  import { EGRESS_POLICY, EGRESS_PROXY_USER, EGRESS_RELAY, HOSTED_ALLOW, NETWORK_LABEL, networkFormOf, networkOfForm, networkRefusal, throughProxy } from "./network.js";
34
34
  import { ARCHIL_GATE, closedSocketsOf, daemonDrift, hostedCommands, initFlags, installerOf } from "./scripts.js";
35
35
  const VERSION = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8")).version;
@@ -1962,6 +1962,9 @@ function labelProblem(key, value) {
1962
1962
  return `the label ${key} is in the provider's own namespace (${COMPUTER_LABEL})`;
1963
1963
  if (key === MOUNT_LABEL)
1964
1964
  return `the label ${key} is the provider's own: it records a computer's mount`;
1965
+ // Labels stored as given (an older server's, a host that doesn't pack) under one of these would read back as a packed map.
1966
+ if (isPackedKey(key))
1967
+ return `the label ${key} is reserved: ${PACKED_NAME} and ${PACKED_NAME}-<n> (${PACKED_NAME}-0, ${PACKED_NAME}-1 and on) hold a computer's packed labels`;
1965
1968
  return undefined;
1966
1969
  }
1967
1970
  /** "a" or "an" before a vendor's name, by its first letter. */
@@ -89,6 +89,12 @@ export interface Rest {
89
89
  * host name and Fly nothing, and each builds its https URL itself.
90
90
  */
91
91
  export declare function httpsBase(url: string, what: string): string;
92
+ /**
93
+ * httpsBase's rule over `schemes` (each as URL.protocol gives it, `https:`): the same refusals in the same words, the
94
+ * same normalized form. For a URL a key goes to whose own protocol allows another scheme: a socket's wss, or the http
95
+ * of an OpenTelemetry collector or of a server on loopback.
96
+ */
97
+ export declare function keyBase(url: string, what: string, schemes: readonly string[]): string;
92
98
  export declare function rest(options: RestOptions): Rest;
93
99
  /** The JSON value of each line of a body of newline-delimited JSON, as the lines come; a line that is not JSON throws. */
94
100
  export declare function ndjson(body: AsyncIterable<Uint8Array>): AsyncIterable<unknown>;
@@ -64,6 +64,14 @@ const NO_BODY = { async *[Symbol.asyncIterator]() { } };
64
64
  * host name and Fly nothing, and each builds its https URL itself.
65
65
  */
66
66
  export function httpsBase(url, what) {
67
+ return keyBase(url, what, ["https:"]);
68
+ }
69
+ /**
70
+ * httpsBase's rule over `schemes` (each as URL.protocol gives it, `https:`): the same refusals in the same words, the
71
+ * same normalized form. For a URL a key goes to whose own protocol allows another scheme: a socket's wss, or the http
72
+ * of an OpenTelemetry collector or of a server on loopback.
73
+ */
74
+ export function keyBase(url, what, schemes) {
67
75
  let parsed;
68
76
  try {
69
77
  parsed = new URL(url);
@@ -72,8 +80,9 @@ export function httpsBase(url, what) {
72
80
  // Nothing of the string is echoed: it may carry a key in its query.
73
81
  throw new Error(`${what} is not a URL`);
74
82
  }
75
- if (parsed.protocol !== "https:")
76
- throw new Error(`${what} must be https, so the key never crosses in the clear: ${parsed.protocol}`);
83
+ const clear = schemes.includes("http:") || schemes.includes("ws:") ? "" : ", so the key never crosses in the clear";
84
+ if (!schemes.includes(parsed.protocol))
85
+ throw new Error(`${what} must be ${schemes.map((scheme) => scheme.replace(/:$/, "")).join(" or ")}${clear}: ${parsed.protocol}`);
77
86
  // The words give the origin alone: a user, a password or a query may be a key.
78
87
  if (parsed.username !== "" || parsed.password !== "")
79
88
  throw new Error(`${what} takes no user or password, since the key goes to it: ${parsed.origin}`);
@@ -9,6 +9,8 @@ export declare function sizeRefusals(spec: Partial<ComputerSpec>, computer: stri
9
9
  export declare function dateOf(value: unknown, unit?: "ms" | "s"): Date | undefined;
10
10
  /** The label a packed machine is listed by (packLabels): its value is the machine's name, MachineRequest.name. */
11
11
  export declare const PACKED_NAME = "agentrun";
12
+ /** A key the packed map stores under: PACKED_NAME, or agentrun-<n>. A caller's label is refused under one (labelProblem). */
13
+ export declare function isPackedKey(key: string): boolean;
12
14
  /**
13
15
  * A machine's labels as a vendor whose labels can't hold them as they are stores them (facts.labels.packed): a cap of 5
14
16
  * tags, Kubernetes' values, Cloudflare's 16-byte names, a list of strings. PACKED_NAME, the one label a host's list
@@ -17,6 +17,10 @@ export function dateOf(value, unit = "ms") {
17
17
  export const PACKED_NAME = "agentrun";
18
18
  /** The packed map's parts: agentrun-0, agentrun-1, and on. */
19
19
  const PART = `${PACKED_NAME}-`;
20
+ /** A key the packed map stores under: PACKED_NAME, or agentrun-<n>. A caller's label is refused under one (labelProblem). */
21
+ export function isPackedKey(key) {
22
+ return key === PACKED_NAME || new RegExp(`^${PART}[0-9]+$`).test(key);
23
+ }
20
24
  /** The most bytes of a packed map's JSON: unpackLabels inflates no more. */
21
25
  const PACKED_JSON_MAX = 1 << 20;
22
26
  /**
package/dist/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export { listProcesses, readAll, type ReadAllResult } from "./processes.js";
14
14
  export { type ActionMapper, createActionMapper, daemonWatch, redactWords, type ScreenFrame, type ScreenFrames, type ScreenWatch, ScreenWatchError, type ScreenWatchHandlers, toAction, type ViewerEvent, type WatchEndCode, watchEndCode, type WatchOptions, watchScreen, } from "./screen-watch.js";
15
15
  export type { HostCall, HostFacts, Machine, MachineHost, MachineProcess, MachineRequest } from "./host.js";
16
16
  export { HostedProvider, type HostedDial, type HostedOptions, type HostedTimeouts, hostedDaemonPath } from "./hosted/provider.js";
17
+ export { httpsBase, keyBase } from "./hosted/rest.js";
17
18
  export { type DockerVolume, VOLUME_SUBPATH_ENGINE } from "./docker/volume.js";
18
19
  export { DEFAULT_DOCKER_IMAGE, DOCKER_BASE, DOCKER_RECIPE, DOCKER_RECIPE_HAS, ensureImage, type EnsureImageOptions, IMAGE_REPOSITORY, IMAGE_TIMEOUT_MS, type ImageSource, imageSourceProblem, type Making, RECIPE_LABEL, recipeHash, recipeTag, } from "./docker/image.js";
19
20
  export { ADB_ENV_NAMES, adbEnv, BASE_ENV_NAMES, CHROME_ENV_NAMES, childEnv, chromeEnv, DOCKER_ENV_NAMES, dockerEnv, type HostEnv } from "./child-env.js";
package/dist/index.js CHANGED
@@ -13,6 +13,9 @@ export { TarReader, tarEntry, tarOf, tarStream, untar, untarStream } from "./tar
13
13
  export { listProcesses, readAll } from "./processes.js";
14
14
  export { createActionMapper, daemonWatch, redactWords, ScreenWatchError, toAction, watchEndCode, watchScreen, } from "./screen-watch.js";
15
15
  export { HostedProvider, hostedDaemonPath } from "./hosted/provider.js";
16
+ // The one rule for a URL a key is sent to, which serve applies to the URLs it reads from its environment too: httpsBase,
17
+ // and keyBase for one whose protocol allows another scheme (a socket's wss, a collector's or loopback's http).
18
+ export { httpsBase, keyBase } from "./hosted/rest.js";
16
19
  // The provider classes and their option types are not here: each provider loads by its id through the registry
17
20
  // (providerFor), or from its own subpath (@parcha/agentrun-computer/docker, /daytona, /modal, /e2b, /agent37, /morph, /orgo,
18
21
  // /phone-harness, /browserbase, /kernel, /local, /smolcloud, /groundbox: each the provider file's name).
package/dist/kernel.js CHANGED
@@ -20,7 +20,7 @@ import { randomBytes } from "node:crypto";
20
20
  import { readFileSync } from "node:fs";
21
21
  import { KERNEL } from "./descriptors/kernel.js";
22
22
  import { BROWSER_IMAGE } from "./descriptors/shared.js";
23
- import { cdpUrlProblem, browserClient, browserHello, BrowserVendorError, CREATE_LABEL, carries, causeOf, checkBrowser, createUncertain, DEFAULT_CONFIRM, ATTEMPT_LABEL, convergedBrowser, heldBrowser, newAttempt, defaultSleep, idProblem, labelsOf, labelsProblem, memoryUrls, pointerOk, queryable, RECOVER_MS, recoverCreate, leftToConverge, releaseConfirmed, boundedRelease, restCall, causedFail, vendorFailure, withoutCreateLabel, } from "./browser.js";
23
+ import { cdpUrlProblem, browserClient, browserHello, BrowserVendorError, CREATE_LABEL, carries, causeOf, checkBrowser, createUncertain, DEFAULT_CONFIRM, ATTEMPT_LABEL, convergedBrowser, heldBrowser, newAttempt, defaultSleep, idProblem, labelsOf, labelsProblem, memoryUrls, pointerOk, queryable, RECOVER_MS, recoverCreate, releaseConfirmed, boundedRelease, restCall, causedFail, vendorFailure, withoutCreateLabel, } from "./browser.js";
24
24
  import { CreateRequests, endedWords, labelsDiffer, otherSpecWords } from "./create-requests.js";
25
25
  import { httpsBase } from "./hosted/rest.js";
26
26
  import { runLifetimeMs, } from "./provider.js";
@@ -323,13 +323,13 @@ export class KernelProvider {
323
323
  const found = await this.#browsers(labels, signal);
324
324
  return found.ok ? ok(found.value.map((b) => b.id)) : found;
325
325
  };
326
- const leave = (id, signal) => this.#leftToConverge(request, id, signal);
327
- return recoverCreate("browser", find, (id, signal) => this.release(refOf(id), "delete", { signal }), this.#sleep, this.#cleanupMs, leave);
326
+ const made = (signal) => this.#requestBrowsers(request, signal);
327
+ return recoverCreate("browser", find, (id, signal) => this.release(refOf(id), "delete", { signal }), this.#sleep, this.#cleanupMs, made);
328
328
  }
329
- /** Whether a lost create's browser is left to another create of its request (leftToConverge); a listing that fails releases it. */
330
- async #leftToConverge(request, id, signal) {
329
+ /** The request's browsers, deleted ones included, for a lost create's recovery (recoverCreate, leftToConverge). */
330
+ async #requestBrowsers(request, signal) {
331
331
  const made = await this.#browsers({ [CREATE_LABEL]: request }, signal, true);
332
- return made.ok && leftToConverge(id, made.value.map((row) => ({ ...heldOf(row), live: row.deleted === undefined })));
332
+ return made.ok ? ok(made.value.map((row) => ({ ...heldOf(row), live: row.deleted === undefined }))) : made;
333
333
  }
334
334
  /**
335
335
  * Settings' test: one page of the organization's active browsers (GET /browsers?status=active), which makes nothing.
@@ -409,7 +409,7 @@ export class KernelProvider {
409
409
  * browser still starting, which bills), and a row with deleted_at is dropped here; so list and attach show a starting
410
410
  * browser, as Browserbase lists a PENDING session, and a lost create's recovery misses none. The match is the
411
411
  * provider's own, so a lane that drops the filter never hands back another's. A page that cannot be read fails the
412
- * whole list: a release trusts it. `withDeleted` keeps the deleted rows too, marked deleted (#leftToConverge).
412
+ * whole list: a release trusts it. `withDeleted` keeps the deleted rows too, marked deleted (#requestBrowsers).
413
413
  */
414
414
  async #browsers(labels, signal, withDeleted = false) {
415
415
  const problem = labelsProblem(labels);
@@ -418,8 +418,7 @@ export class KernelProvider {
418
418
  if (Object.keys(labels).length === 0)
419
419
  return fail("invalid", "list and attach take at least one label: a Kernel organization holds browsers this provider did not make");
420
420
  const first = Object.entries(labels).find(queryable);
421
- const found = [];
422
- const seen = new Set();
421
+ const found = new Map();
423
422
  const call = "GET /browsers";
424
423
  for (let offset = 0, pages = 0; pages < MAX_PAGES; pages++) {
425
424
  const query = new URLSearchParams({ status: "all", ...(first === undefined ? {} : { [`tags[${first[0]}]`]: first[1] }), limit: "100", offset: String(offset) });
@@ -437,14 +436,21 @@ export class KernelProvider {
437
436
  return vendorFailure("kernel", NAME, call, new BrowserVendorError(NAME, call, page.status, "not_a_list"));
438
437
  for (const row of page.json) {
439
438
  const id = text(row?.session_id);
440
- if (id !== "" && (withDeleted || !row.deleted_at) && carries(row.tags, labels) && !seen.has(id)) {
441
- seen.add(id);
442
- const createdAt = text(row.created_at);
443
- found.push({ id, tags: withoutCreateLabel(labelsOf(row.tags)), ...(createdAt === "" ? {} : { createdAt }), ...(row.deleted_at ? { deleted: true } : {}) });
439
+ if (id === "" || (!withDeleted && row.deleted_at) || !carries(row.tags, labels))
440
+ continue;
441
+ const before = found.get(id);
442
+ // A browser listed twice (pages shifted under the read) reads as deleted once either row says so: a delete is
443
+ // never undone.
444
+ if (before !== undefined) {
445
+ if (row.deleted_at && before.deleted === undefined)
446
+ found.set(id, { ...before, deleted: true });
447
+ continue;
444
448
  }
449
+ const createdAt = text(row.created_at);
450
+ found.set(id, { id, tags: withoutCreateLabel(labelsOf(row.tags)), ...(createdAt === "" ? {} : { createdAt }), ...(row.deleted_at ? { deleted: true } : {}) });
445
451
  }
446
452
  if (page.headers.get("x-has-more") !== "true")
447
- return ok(found);
453
+ return ok([...found.values()]);
448
454
  const next = Number(page.headers.get("x-next-offset"));
449
455
  if (!Number.isInteger(next) || next <= offset)
450
456
  return vendorFail("kernel", "Kernel reported more browsers without the next page's offset");
@@ -18,7 +18,8 @@ export declare function orgoWorkspaces(rest: OrgoRest, { timeoutMs, signal }: {
18
18
  }): Promise<Result<OrgoWorkspace[]>>;
19
19
  /**
20
20
  * The workspace a provider whose settings name none uses: the key's account's one workspace. Several are refused in
21
- * words naming them and pointing at Settings, where a person picks one; none is refused saying to make one.
21
+ * words naming each and its id, pointing at Settings, where a person picks one, or at ORGO_WORKSPACE_ID; none is
22
+ * refused saying to make one.
22
23
  */
23
24
  export declare function soleWorkspace(rest: OrgoRest, context: {
24
25
  timeoutMs: number;
@@ -4,6 +4,8 @@ const fail = failFor("orgo");
4
4
  export const NO_WORKSPACE = "this Orgo key's account has no workspace: make one at orgo.ai";
5
5
  /** A workspace in words: its name, and its status when it is not active. */
6
6
  export const workspaceWords = (workspace) => (workspace.status === undefined ? workspace.name : `${workspace.name} (${workspace.status})`);
7
+ /** A workspace in words with its id, the value ORGO_WORKSPACE_ID takes: `name = id`, or the id alone when it is the name. */
8
+ const workspaceWithId = (workspace) => (workspace.name === workspace.id ? workspaceWords(workspace) : `${workspaceWords(workspace)} = ${workspace.id}`);
7
9
  /** Every workspace the key's account sees, deleted ones left out, in Orgo's order. An HTTP failure keeps its code. */
8
10
  export async function orgoWorkspaces(rest, { timeoutMs, signal }) {
9
11
  const read = await rest.request("GET", "/workspaces", { timeoutMs, ...(signal ? { signal } : {}) });
@@ -24,7 +26,8 @@ export async function orgoWorkspaces(rest, { timeoutMs, signal }) {
24
26
  }
25
27
  /**
26
28
  * The workspace a provider whose settings name none uses: the key's account's one workspace. Several are refused in
27
- * words naming them and pointing at Settings, where a person picks one; none is refused saying to make one.
29
+ * words naming each and its id, pointing at Settings, where a person picks one, or at ORGO_WORKSPACE_ID; none is
30
+ * refused saying to make one.
28
31
  */
29
32
  export async function soleWorkspace(rest, context) {
30
33
  const listed = await orgoWorkspaces(rest, context);
@@ -35,7 +38,7 @@ export async function soleWorkspace(rest, context) {
35
38
  return fail("not_found", NO_WORKSPACE);
36
39
  if (more.length === 0)
37
40
  return ok(only.id);
38
- return fail("invalid", `this Orgo key's account has ${listed.value.length} workspaces (${listed.value.map(workspaceWords).join(", ")}): pick the one its computers live in, in Settings → Computers (ORGO_WORKSPACE_ID)`);
41
+ return fail("invalid", `this Orgo key's account has ${listed.value.length} workspaces (${listed.value.map(workspaceWithId).join(", ")}): pick one in Settings → Computers or set ORGO_WORKSPACE_ID to its id`);
39
42
  }
40
43
  /**
41
44
  * keyChoices for an Orgo provider: workspaceId's choices, every workspace the key's account sees, each its id and its
@@ -0,0 +1,34 @@
1
+ import { HostedProvider, type HostedOptions, type HostedTimeouts } from "./hosted/provider.js";
2
+ import type { CallContext } from "./provider.js";
3
+ import { type Result } from "./result.js";
4
+ /** The Render provider's options: the key and the workspace, then the shared adapter's (HostedOptions). */
5
+ export interface RenderProviderOptions extends Omit<HostedOptions, "desktop" | "maxLifetimeMs"> {
6
+ /** A Render API key that may make sandboxes in the workspace. The caller passes it; this provider reads no environment. */
7
+ apiKey: string;
8
+ /** The workspace (owner) its sandboxes are made in and listed from: tea-… for a team, usr-… for a person. */
9
+ ownerId: string;
10
+ /** The fetch every call goes through; default the global one. */
11
+ fetch?: typeof fetch;
12
+ /** The longest lifetime check takes, in ms: at most a day, the default. */
13
+ maxLifetimeMs?: number;
14
+ timeouts?: Partial<HostedTimeouts>;
15
+ }
16
+ /** A RenderProvider from its options alone; it reads no environment (serve passes the saved RENDER_API_KEY and RENDER_WORKSPACE_ID). */
17
+ export declare function create(options: RenderProviderOptions): RenderProvider;
18
+ /** The conformance CLI's module for Render: its settings, and its dialKit that refuses off the public server. */
19
+ export declare const conformance: () => Promise<typeof import("./conformance/render.js")>;
20
+ /**
21
+ * Computers that are Render Sandboxes, on the shared adapter, each dialing the server that made it: a server with no
22
+ * public https address (AGENTRUN_PUBLIC_URL) refuses a create in words before Render is called. Kind linux.
23
+ */
24
+ export declare class RenderProvider extends HostedProvider {
25
+ /**
26
+ * The provider contract's prepareImage (its descriptor declares it): the box image as a build of the workspace's
27
+ * default sandbox group (RenderHost.boxBuild), found or imported. ok with the build's name; onWait is told "build"
28
+ * once, before an import, never when the workspace has one.
29
+ */
30
+ prepareImage(context?: CallContext & {
31
+ onWait?: (making: "build" | "pull", tag: string) => void;
32
+ }): Promise<Result<string>>;
33
+ constructor(options: RenderProviderOptions);
34
+ }