@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.
Files changed (173) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +8 -0
  3. package/README.md +2411 -2
  4. package/box/Dockerfile +69 -0
  5. package/box/agentrun-archil +168 -0
  6. package/box/build-daytona.py +26 -0
  7. package/box/build-e2b.mjs +32 -0
  8. package/box/build-modal.py +17 -0
  9. package/dist/actions.d.ts +18 -0
  10. package/dist/actions.js +139 -0
  11. package/dist/browser.d.ts +151 -0
  12. package/dist/browser.js +305 -0
  13. package/dist/browserbase.d.ts +139 -0
  14. package/dist/browserbase.js +408 -0
  15. package/dist/child.d.ts +40 -0
  16. package/dist/child.js +127 -0
  17. package/dist/client.d.ts +22 -0
  18. package/dist/client.js +136 -0
  19. package/dist/computerd-linux-amd64 +0 -0
  20. package/dist/computerd-linux-arm64 +0 -0
  21. package/dist/conformance/archil.d.ts +68 -0
  22. package/dist/conformance/archil.js +152 -0
  23. package/dist/conformance/browserbase.d.ts +35 -0
  24. package/dist/conformance/browserbase.js +45 -0
  25. package/dist/conformance/cases/apps.d.ts +2 -0
  26. package/dist/conformance/cases/apps.js +155 -0
  27. package/dist/conformance/cases/browser.d.ts +4 -0
  28. package/dist/conformance/cases/browser.js +105 -0
  29. package/dist/conformance/cases/drift.d.ts +2 -0
  30. package/dist/conformance/cases/drift.js +64 -0
  31. package/dist/conformance/cases/exec.d.ts +2 -0
  32. package/dist/conformance/cases/exec.js +125 -0
  33. package/dist/conformance/cases/files.d.ts +2 -0
  34. package/dist/conformance/cases/files.js +294 -0
  35. package/dist/conformance/cases/health.d.ts +2 -0
  36. package/dist/conformance/cases/health.js +71 -0
  37. package/dist/conformance/cases/index.d.ts +9 -0
  38. package/dist/conformance/cases/index.js +37 -0
  39. package/dist/conformance/cases/input.d.ts +12 -0
  40. package/dist/conformance/cases/input.js +109 -0
  41. package/dist/conformance/cases/isolation.d.ts +21 -0
  42. package/dist/conformance/cases/isolation.js +98 -0
  43. package/dist/conformance/cases/lifetime.d.ts +2 -0
  44. package/dist/conformance/cases/lifetime.js +64 -0
  45. package/dist/conformance/cases/mount.d.ts +2 -0
  46. package/dist/conformance/cases/mount.js +252 -0
  47. package/dist/conformance/cases/process.d.ts +2 -0
  48. package/dist/conformance/cases/process.js +240 -0
  49. package/dist/conformance/cases/provider.d.ts +2 -0
  50. package/dist/conformance/cases/provider.js +302 -0
  51. package/dist/conformance/cases/screen.d.ts +9 -0
  52. package/dist/conformance/cases/screen.js +230 -0
  53. package/dist/conformance/cases/settings.d.ts +57 -0
  54. package/dist/conformance/cases/settings.js +142 -0
  55. package/dist/conformance/cases/touch.d.ts +2 -0
  56. package/dist/conformance/cases/touch.js +117 -0
  57. package/dist/conformance/cases/util.d.ts +7 -0
  58. package/dist/conformance/cases/util.js +8 -0
  59. package/dist/conformance/cdp.d.ts +13 -0
  60. package/dist/conformance/cdp.js +88 -0
  61. package/dist/conformance/cli.d.ts +29 -0
  62. package/dist/conformance/cli.js +231 -0
  63. package/dist/conformance/daytona-sweep.d.ts +18 -0
  64. package/dist/conformance/daytona-sweep.js +126 -0
  65. package/dist/conformance/daytona.d.ts +83 -0
  66. package/dist/conformance/daytona.js +107 -0
  67. package/dist/conformance/docker.d.ts +38 -0
  68. package/dist/conformance/docker.js +70 -0
  69. package/dist/conformance/drift-daemon.d.ts +8 -0
  70. package/dist/conformance/drift-daemon.js +41 -0
  71. package/dist/conformance/e2b-diagnose.d.ts +16 -0
  72. package/dist/conformance/e2b-diagnose.js +61 -0
  73. package/dist/conformance/e2b-sweep.d.ts +18 -0
  74. package/dist/conformance/e2b-sweep.js +132 -0
  75. package/dist/conformance/e2b.d.ts +74 -0
  76. package/dist/conformance/e2b.js +111 -0
  77. package/dist/conformance/fixture.d.ts +65 -0
  78. package/dist/conformance/fixture.js +98 -0
  79. package/dist/conformance/index.d.ts +8 -0
  80. package/dist/conformance/index.js +8 -0
  81. package/dist/conformance/kernel.d.ts +31 -0
  82. package/dist/conformance/kernel.js +40 -0
  83. package/dist/conformance/kind.d.ts +23 -0
  84. package/dist/conformance/kind.js +58 -0
  85. package/dist/conformance/modal-sweep.d.ts +22 -0
  86. package/dist/conformance/modal-sweep.js +213 -0
  87. package/dist/conformance/modal.d.ts +69 -0
  88. package/dist/conformance/modal.js +76 -0
  89. package/dist/conformance/orgo.d.ts +41 -0
  90. package/dist/conformance/orgo.js +69 -0
  91. package/dist/conformance/phone-harness.d.ts +61 -0
  92. package/dist/conformance/phone-harness.js +241 -0
  93. package/dist/conformance/png.d.ts +16 -0
  94. package/dist/conformance/png.js +132 -0
  95. package/dist/conformance/report.d.ts +2 -0
  96. package/dist/conformance/report.js +86 -0
  97. package/dist/conformance/runner.d.ts +11 -0
  98. package/dist/conformance/runner.js +585 -0
  99. package/dist/conformance/tar.d.ts +13 -0
  100. package/dist/conformance/tar.js +105 -0
  101. package/dist/conformance/types.d.ts +257 -0
  102. package/dist/conformance/types.js +24 -0
  103. package/dist/daemon-copy.d.ts +40 -0
  104. package/dist/daemon-copy.js +259 -0
  105. package/dist/daytona.d.ts +180 -0
  106. package/dist/daytona.js +1498 -0
  107. package/dist/desktop.d.ts +24 -0
  108. package/dist/desktop.js +68 -0
  109. package/dist/docker/egress-main.d.ts +1 -0
  110. package/dist/docker/egress-main.js +68 -0
  111. package/dist/docker/egress-proxy.d.ts +53 -0
  112. package/dist/docker/egress-proxy.js +450 -0
  113. package/dist/docker/egress-table.d.ts +39 -0
  114. package/dist/docker/egress-table.js +197 -0
  115. package/dist/docker/egress.d.ts +109 -0
  116. package/dist/docker/egress.js +318 -0
  117. package/dist/docker/image.d.ts +49 -0
  118. package/dist/docker/image.js +302 -0
  119. package/dist/docker/stage.d.ts +21 -0
  120. package/dist/docker/stage.js +290 -0
  121. package/dist/docker/volume.d.ts +24 -0
  122. package/dist/docker/volume.js +67 -0
  123. package/dist/docker.d.ts +156 -0
  124. package/dist/docker.js +1277 -0
  125. package/dist/drift.d.ts +200 -0
  126. package/dist/drift.js +416 -0
  127. package/dist/e2b.d.ts +337 -0
  128. package/dist/e2b.js +1516 -0
  129. package/dist/entry.d.ts +2 -0
  130. package/dist/entry.js +24 -0
  131. package/dist/files.d.ts +50 -0
  132. package/dist/files.js +208 -0
  133. package/dist/index.d.ts +27 -0
  134. package/dist/index.js +26 -0
  135. package/dist/isolation.d.ts +29 -0
  136. package/dist/isolation.js +71 -0
  137. package/dist/janitor.d.ts +50 -0
  138. package/dist/janitor.js +135 -0
  139. package/dist/kernel.d.ts +113 -0
  140. package/dist/kernel.js +358 -0
  141. package/dist/kinds.d.ts +79 -0
  142. package/dist/kinds.js +133 -0
  143. package/dist/labels.d.ts +23 -0
  144. package/dist/labels.js +50 -0
  145. package/dist/modal.d.ts +302 -0
  146. package/dist/modal.js +1374 -0
  147. package/dist/mount-archil.d.ts +164 -0
  148. package/dist/mount-archil.js +471 -0
  149. package/dist/mount.d.ts +57 -0
  150. package/dist/mount.js +104 -0
  151. package/dist/orgo-channel.d.ts +96 -0
  152. package/dist/orgo-channel.js +391 -0
  153. package/dist/orgo.d.ts +139 -0
  154. package/dist/orgo.js +1006 -0
  155. package/dist/phone-harness.d.ts +185 -0
  156. package/dist/phone-harness.js +1420 -0
  157. package/dist/processes.d.ts +24 -0
  158. package/dist/processes.js +40 -0
  159. package/dist/protocol.d.ts +729 -0
  160. package/dist/protocol.js +54 -0
  161. package/dist/provider.d.ts +245 -0
  162. package/dist/provider.js +37 -0
  163. package/dist/providers.d.ts +68 -0
  164. package/dist/providers.js +25 -0
  165. package/dist/result.d.ts +15 -0
  166. package/dist/result.js +2 -0
  167. package/dist/screen-watch.d.ts +150 -0
  168. package/dist/screen-watch.js +490 -0
  169. package/dist/test-connection.d.ts +17 -0
  170. package/dist/test-connection.js +26 -0
  171. package/dist/wait.d.ts +23 -0
  172. package/dist/wait.js +65 -0
  173. package/package.json +62 -4
package/dist/client.js ADDED
@@ -0,0 +1,136 @@
1
+ import { CANCEL_METHOD, JSONRPC_CODES, MAX_LINE_BYTES, } from "./protocol.js";
2
+ import { fail, ok } from "./result.js";
3
+ const KINDS = new Set([
4
+ "not_found",
5
+ "invalid",
6
+ "timeout",
7
+ "aborted",
8
+ "denied",
9
+ "limit",
10
+ "unsupported",
11
+ "exists",
12
+ "not_dir",
13
+ "is_dir",
14
+ ]);
15
+ /** A daemon's error reply as a ComputerError: its kind when it names one, else what its JSON-RPC code means. */
16
+ function fromReply(error) {
17
+ const message = typeof error.message === "string" ? error.message : "the daemon answered with an error";
18
+ const kind = error.data?.kind;
19
+ if (typeof kind === "string" && KINDS.has(kind))
20
+ return { code: kind, message };
21
+ if (error.code === JSONRPC_CODES.methodNotFound)
22
+ return { code: "unsupported", message };
23
+ if (error.code === JSONRPC_CODES.requestCancelled)
24
+ return { code: "aborted", message };
25
+ return { code: "invalid", message };
26
+ }
27
+ /**
28
+ * Calls a daemon's methods. Each call gets its own id; replies may come in any order. An aborted call sends
29
+ * $/cancelRequest and returns `aborted` at once; the daemon still ends what the call started. When the stream ends,
30
+ * every pending and later call fails with `gone`. A line that is not a reply to a pending call is dropped.
31
+ */
32
+ export class DaemonClient {
33
+ #writable;
34
+ #readable;
35
+ #pending = new Map();
36
+ #nextId = 1;
37
+ #chunks = [];
38
+ #buffered = 0;
39
+ #gone;
40
+ constructor({ readable, writable }) {
41
+ this.#readable = readable;
42
+ this.#writable = writable;
43
+ readable.on("data", (chunk) => this.#read(typeof chunk === "string" ? Buffer.from(chunk) : chunk));
44
+ readable.on("end", () => this.#end("the daemon's stream ended"));
45
+ readable.on("close", () => this.#end("the daemon's stream closed"));
46
+ readable.on("error", (error) => this.#end(`the daemon's stream failed: ${error.message}`));
47
+ writable.on("error", (error) => this.#end(`the daemon's stream failed: ${error.message}`));
48
+ }
49
+ async call(method, params, options = {}) {
50
+ const { signal } = options;
51
+ if (this.#gone)
52
+ return { ok: false, error: this.#gone };
53
+ if (signal?.aborted)
54
+ return fail("aborted", `${method} was aborted before it was sent`);
55
+ const id = this.#nextId++;
56
+ const line = `${JSON.stringify({ jsonrpc: "2.0", id, method, params })}\n`;
57
+ if (Buffer.byteLength(line) - 1 > MAX_LINE_BYTES)
58
+ return fail("limit", `the ${method} request is over the 1 MiB line limit`);
59
+ return new Promise((resolve) => {
60
+ const onAbort = () => {
61
+ if (!this.#pending.delete(id))
62
+ return;
63
+ this.#write({ jsonrpc: "2.0", method: CANCEL_METHOD, params: { id } });
64
+ resolve(fail("aborted", `${method} was aborted`));
65
+ };
66
+ this.#pending.set(id, (result) => {
67
+ signal?.removeEventListener("abort", onAbort);
68
+ resolve(result);
69
+ });
70
+ signal?.addEventListener("abort", onAbort, { once: true });
71
+ this.#writable.write(line);
72
+ });
73
+ }
74
+ /** Ends the connection: pending and later calls fail with `gone`. */
75
+ close() {
76
+ this.#end("the connection was closed");
77
+ this.#writable.end();
78
+ this.#readable.destroy();
79
+ }
80
+ #write(message) {
81
+ if (!this.#gone && this.#writable.writable)
82
+ this.#writable.write(`${JSON.stringify(message)}\n`);
83
+ }
84
+ #read(chunk) {
85
+ let start = 0;
86
+ let at;
87
+ while (!this.#gone && (at = chunk.indexOf(0x0a, start)) >= 0) {
88
+ const piece = chunk.subarray(start, at);
89
+ start = at + 1;
90
+ if (this.#buffered + piece.length > MAX_LINE_BYTES)
91
+ return this.#overflow();
92
+ const line = this.#chunks.length === 0 ? piece : Buffer.concat([...this.#chunks, piece]);
93
+ this.#chunks = [];
94
+ this.#buffered = 0;
95
+ this.#line(line.toString("utf8"));
96
+ }
97
+ if (this.#gone || start === chunk.length)
98
+ return;
99
+ this.#buffered += chunk.length - start;
100
+ if (this.#buffered > MAX_LINE_BYTES)
101
+ return this.#overflow();
102
+ this.#chunks.push(chunk.subarray(start));
103
+ }
104
+ #overflow() {
105
+ this.#chunks = [];
106
+ this.#buffered = 0;
107
+ this.#end("the daemon sent a line over the 1 MiB limit");
108
+ this.#readable.destroy();
109
+ }
110
+ #line(text) {
111
+ let message;
112
+ try {
113
+ message = JSON.parse(text);
114
+ }
115
+ catch {
116
+ return;
117
+ }
118
+ if (typeof message?.id !== "number")
119
+ return;
120
+ const settle = this.#pending.get(message.id);
121
+ if (settle === undefined)
122
+ return;
123
+ this.#pending.delete(message.id);
124
+ settle(message.error != null ? { ok: false, error: fromReply(message.error) } : ok(message.result));
125
+ }
126
+ #end(why) {
127
+ if (this.#gone)
128
+ return;
129
+ const gone = { code: "gone", message: why };
130
+ this.#gone = gone;
131
+ const pending = [...this.#pending.values()];
132
+ this.#pending.clear();
133
+ for (const settle of pending)
134
+ settle({ ok: false, error: gone });
135
+ }
136
+ }
Binary file
Binary file
@@ -0,0 +1,68 @@
1
+ import type { RunFolder } from "./types.js";
2
+ /** The settings of the Archil mount cases, by the names a conformance module reads them from. */
3
+ export declare const ARCHIL_ENV: {
4
+ /** The disk the run folders are made on: dsk-<16 hex digits>, or owner/name. */
5
+ readonly archilDisk: "COMPUTER_ARCHIL_DISK";
6
+ /** Its region, such as aws-us-east-1. */
7
+ readonly archilRegion: "COMPUTER_ARCHIL_REGION";
8
+ /** A disk token, which the mount in the computer takes. */
9
+ readonly archilToken: "COMPUTER_ARCHIL_TOKEN";
10
+ /** The account API key, which the object API outside takes. */
11
+ readonly archilKey: "COMPUTER_ARCHIL_API_KEY";
12
+ /** The disk's S3-compatible endpoint, https on an Archil host of the region: the key goes to it. */
13
+ readonly archilS3Url: "COMPUTER_ARCHIL_S3_URL";
14
+ };
15
+ /** The part of an Archil disk's object API a run folder is reached through from outside: keys relative to the disk's root. */
16
+ export interface ArchilObjects {
17
+ getObject(key: string): Promise<Uint8Array>;
18
+ putObject(key: string, body: Uint8Array): Promise<unknown>;
19
+ deleteObject(key: string): Promise<void>;
20
+ }
21
+ /** The SDK's Archil client constructor, as far as a run folder calls it. */
22
+ export type ArchilConstructor = new (options: {
23
+ apiKey: string;
24
+ region: string;
25
+ s3BaseUrl: string;
26
+ baseUrl?: string;
27
+ }) => {
28
+ disks: {
29
+ get(id: string): Promise<ArchilObjects>;
30
+ };
31
+ };
32
+ export interface ArchilRunFolderOptions {
33
+ /** The disk: dsk-<16 hex digits>, or owner/name. */
34
+ disk: string;
35
+ /** Its region, such as aws-us-east-1. */
36
+ region: string;
37
+ /** The disk token the mount takes. */
38
+ token: string;
39
+ /** The folder's agent; default "conformance". */
40
+ agent?: string;
41
+ /** The folder's run; default a fresh one. */
42
+ run?: string;
43
+ /** The disk's object API. Default: the SDK's client (Archil), with apiKey and s3BaseUrl. */
44
+ objects?: ArchilObjects;
45
+ /** The account API key, for the SDK's client. */
46
+ apiKey?: string;
47
+ /** The disk's S3-compatible endpoint, for the SDK's client. */
48
+ s3BaseUrl?: string;
49
+ /** Another control plane than the region's, for the SDK's client. */
50
+ baseUrl?: string;
51
+ /** The SDK's Archil client; default the host's `disk` package's. */
52
+ Archil?: ArchilConstructor;
53
+ /** For tests: the package the SDK's client is imported from; default `disk`. */
54
+ sdkPackage?: string;
55
+ }
56
+ /**
57
+ * The Archil mount cases' settings from the COMPUTER_ARCHIL_* names (ARCHIL_ENV); undefined when none is set. Some set
58
+ * and some not, a disk or region of another shape, or an S3 endpoint the key must not go to, is a mistake said in
59
+ * words that name the setting and hold no secret.
60
+ */
61
+ export declare function archilSettings(env: Record<string, string | undefined>): Required<Pick<ArchilRunFolderOptions, "disk" | "region" | "token" | "apiKey" | "s3BaseUrl">> | undefined;
62
+ /**
63
+ * A fresh run folder, agents/<agent>/runs/<run>/work on the disk, and the Archil mount that reaches it, with the token.
64
+ * Outside, a file reads undefined when it is not there (the SDK's 404), and any other failure is thrown; a path is
65
+ * inside the folder or refused. close removes every file the case wrote or read there (so those the computer wrote and
66
+ * the case read back), and the folder's other keys are the disk's to keep.
67
+ */
68
+ export declare function archilRunFolder(options: ArchilRunFolderOptions): Promise<RunFolder>;
@@ -0,0 +1,152 @@
1
+ // The Archil run folder for the mount cases, shared by every remote provider's conformance module (Daytona, Modal,
2
+ // E2B): a fresh agents/<agent>/runs/<run>/work on the owner's disk, the mount that reaches it from inside a computer,
3
+ // and its outside, read and written through the disk's object API. The object API is given, or the host's own Archil
4
+ // SDK (the npm package `disk`, not a dependency of this package, imported only here and only when asked): `new Archil({
5
+ // apiKey, region, s3BaseUrl })`, then `disks.get(disk)`, whose disk has getObject, putObject and deleteObject with keys
6
+ // relative to the disk's root, and rejects with the HTTP `status` when there was an answer (404: not there). Every
7
+ // setting is passed to the SDK, so it reads none of its own from the environment.
8
+ //
9
+ // Two secrets ride here, never in a word: the disk token, which only the mount takes (the root helper's stdin in the
10
+ // computer), and the account API key, which only the SDK takes, for the object API. The settings are options; each
11
+ // module reads them from the COMPUTER_ARCHIL_* names ARCHIL_ENV lists (archilSettings).
12
+ import { randomBytes } from "node:crypto";
13
+ import { ARCHIL_REGION } from "../mount-archil.js";
14
+ /** The settings of the Archil mount cases, by the names a conformance module reads them from. */
15
+ export const ARCHIL_ENV = {
16
+ /** The disk the run folders are made on: dsk-<16 hex digits>, or owner/name. */
17
+ archilDisk: "COMPUTER_ARCHIL_DISK",
18
+ /** Its region, such as aws-us-east-1. */
19
+ archilRegion: "COMPUTER_ARCHIL_REGION",
20
+ /** A disk token, which the mount in the computer takes. */
21
+ archilToken: "COMPUTER_ARCHIL_TOKEN",
22
+ /** The account API key, which the object API outside takes. */
23
+ archilKey: "COMPUTER_ARCHIL_API_KEY",
24
+ /** The disk's S3-compatible endpoint, https on an Archil host of the region: the key goes to it. */
25
+ archilS3Url: "COMPUTER_ARCHIL_S3_URL",
26
+ };
27
+ /** Not a literal, so no type checker or bundler resolves the SDK from this package. */
28
+ const ARCHIL_PACKAGE = "disk";
29
+ // The shapes the root helper takes (box/agentrun-archil), so a run folder is one a computer can mount.
30
+ const DISK = /^(?:dsk-[0-9a-f]{16}|[A-Za-z0-9][A-Za-z0-9._@+-]{0,127}\/[A-Za-z0-9][A-Za-z0-9._-]{0,127})$/;
31
+ const REGION = new RegExp(`^${ARCHIL_REGION}$`);
32
+ const SEGMENT = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
33
+ /** Why an S3 endpoint is not one the account key may go to, or undefined: https, on an Archil host of the region. */
34
+ function s3Problem(s3BaseUrl, region) {
35
+ let url;
36
+ try {
37
+ url = new URL(s3BaseUrl);
38
+ }
39
+ catch {
40
+ return "is not a URL";
41
+ }
42
+ if (url.protocol !== "https:")
43
+ return "must be https: the account key goes to it";
44
+ if (url.username !== "" || url.password !== "" || url.search !== "" || url.hash !== "")
45
+ return "carries more than a scheme, a host and a path";
46
+ const [, provider = "", location = ""] = /^([a-z0-9]+)-(.+)$/.exec(region) ?? [];
47
+ const host = url.hostname.toLowerCase();
48
+ if (!host.endsWith(".archil.com") || !host.includes(`.${location}.${provider}.`))
49
+ return `must be an Archil host of the region ${region}, not ${host}`;
50
+ return undefined;
51
+ }
52
+ /**
53
+ * The Archil mount cases' settings from the COMPUTER_ARCHIL_* names (ARCHIL_ENV); undefined when none is set. Some set
54
+ * and some not, a disk or region of another shape, or an S3 endpoint the key must not go to, is a mistake said in
55
+ * words that name the setting and hold no secret.
56
+ */
57
+ export function archilSettings(env) {
58
+ const names = Object.values(ARCHIL_ENV);
59
+ if (names.every((name) => !env[name]))
60
+ return undefined;
61
+ const missing = names.filter((name) => !env[name]);
62
+ if (missing.length > 0)
63
+ throw new Error(`the Archil mount cases need ${names.join(", ")} together: ${missing.join(", ")} is not set`);
64
+ const read = (name) => env[name];
65
+ const [disk, region, token, apiKey, s3BaseUrl] = [read(ARCHIL_ENV.archilDisk), read(ARCHIL_ENV.archilRegion), read(ARCHIL_ENV.archilToken), read(ARCHIL_ENV.archilKey), read(ARCHIL_ENV.archilS3Url)];
66
+ if (!DISK.test(disk))
67
+ throw new Error(`${ARCHIL_ENV.archilDisk} is a disk id (dsk- and 16 hex digits) or owner/name`);
68
+ if (!REGION.test(region))
69
+ throw new Error(`${ARCHIL_ENV.archilRegion} is a provider, a dash and its region, such as aws-us-east-1`);
70
+ const s3 = s3Problem(s3BaseUrl, region);
71
+ if (s3 !== undefined)
72
+ throw new Error(`${ARCHIL_ENV.archilS3Url} ${s3}`);
73
+ return { disk, region, token, apiKey, s3BaseUrl };
74
+ }
75
+ /** An SDK failure in words: its status and message, with the key taken out. */
76
+ function failure(what, error, apiKey) {
77
+ const status = error?.status;
78
+ const message = (error instanceof Error ? error.message : String(error)).replaceAll(apiKey, "[key]").replace(/\s+/g, " ").slice(0, 300);
79
+ return Object.assign(new Error(`${what}: ${message}`), typeof status === "number" ? { status } : {});
80
+ }
81
+ /** The disk's object API from the SDK's client: every setting given, the disk looked up once. */
82
+ async function sdkObjects({ disk, region, apiKey, s3BaseUrl, baseUrl, Archil, sdkPackage = ARCHIL_PACKAGE }) {
83
+ if (!apiKey || !s3BaseUrl)
84
+ throw new Error(`the Archil run folder reaches its disk through the object API: give objects, or apiKey and s3BaseUrl (${ARCHIL_ENV.archilKey}, ${ARCHIL_ENV.archilS3Url})`);
85
+ let Client = Archil;
86
+ if (Client === undefined) {
87
+ try {
88
+ Client = (await import(sdkPackage)).Archil;
89
+ }
90
+ catch (error) {
91
+ const why = (error instanceof Error ? error.message : String(error)).replaceAll(apiKey, "[key]").slice(0, 200);
92
+ throw new Error(`the Archil run folder needs Archil's Node SDK, the package ${JSON.stringify(sdkPackage)}: it is serve's dependency, pinned in the lockfile, so npm ci at the repository root installs it (${why})`);
93
+ }
94
+ }
95
+ try {
96
+ return await new Client({ apiKey, region, s3BaseUrl, ...(baseUrl === undefined ? {} : { baseUrl }) }).disks.get(disk);
97
+ }
98
+ catch (error) {
99
+ throw failure(`looking up the Archil disk ${disk}`, error, apiKey);
100
+ }
101
+ }
102
+ /**
103
+ * A fresh run folder, agents/<agent>/runs/<run>/work on the disk, and the Archil mount that reaches it, with the token.
104
+ * Outside, a file reads undefined when it is not there (the SDK's 404), and any other failure is thrown; a path is
105
+ * inside the folder or refused. close removes every file the case wrote or read there (so those the computer wrote and
106
+ * the case read back), and the folder's other keys are the disk's to keep.
107
+ */
108
+ export async function archilRunFolder(options) {
109
+ const { disk, region, token, agent = "conformance", run = `c${randomBytes(6).toString("hex")}` } = options;
110
+ if (!SEGMENT.test(agent))
111
+ throw new Error("the Archil run folder's agent is letters, digits, _ and -, starting with a letter or digit");
112
+ if (!SEGMENT.test(run))
113
+ throw new Error("the Archil run folder's run is letters, digits, _ and -, starting with a letter or digit");
114
+ const objects = options.objects ?? (await sdkObjects(options));
115
+ const folder = `agents/${agent}/runs/${run}/work`;
116
+ const touched = new Set();
117
+ const key = (path) => {
118
+ if (typeof path !== "string" || path === "" || path.startsWith("/") || path.split("/").includes(".."))
119
+ throw new Error(`a run folder's file is a path inside it, not ${JSON.stringify(path)}`);
120
+ const at = `${folder}/${path}`;
121
+ touched.add(at);
122
+ return at;
123
+ };
124
+ // The folder is there before any computer mounts it: its own marker (a key ending in /, a folder on the disk), removed
125
+ // last at close.
126
+ const marker = `${folder}/`;
127
+ await objects.putObject(marker, new Uint8Array());
128
+ touched.add(marker);
129
+ return {
130
+ mount: { kind: "archil", disk, region, folder, token },
131
+ run,
132
+ read: async (path) => {
133
+ const at = key(path);
134
+ try {
135
+ return await objects.getObject(at);
136
+ }
137
+ catch (error) {
138
+ if (error?.status === 404)
139
+ return undefined;
140
+ throw error;
141
+ }
142
+ },
143
+ write: async (path, data) => {
144
+ await objects.putObject(key(path), data);
145
+ },
146
+ close: async () => {
147
+ // Deepest first, so a folder's marker goes after what is in it.
148
+ for (const at of [...touched].sort((a, b) => b.length - a.length))
149
+ await objects.deleteObject(at).catch(() => { });
150
+ },
151
+ };
152
+ }
@@ -0,0 +1,35 @@
1
+ import { type BrowserbaseProvider, type BrowserbaseProviderOptions } from "../browserbase.js";
2
+ /** The environment this module reads, by name, each for the option its comment names, and the live switch. */
3
+ export declare const BROWSERBASE_ENV: {
4
+ readonly live: "AGENTRUN_COMPUTER_LIVE_BROWSERBASE";
5
+ /** apiKey, required: the Browserbase API key. */
6
+ readonly key: "COMPUTER_BROWSERBASE_API_KEY";
7
+ /** projectId: the project sessions are made in; a key behind a credential proxy names none. */
8
+ readonly project: "COMPUTER_BROWSERBASE_PROJECT_ID";
9
+ /** apiUrl: Browserbase's API; default https://api.browserbase.com. */
10
+ readonly url: "COMPUTER_BROWSERBASE_API_URL";
11
+ };
12
+ /** The names this module reads, under the conformance modules' common name (ConformanceModule.ENV). */
13
+ export declare const ENV: {
14
+ readonly live: "AGENTRUN_COMPUTER_LIVE_BROWSERBASE";
15
+ /** apiKey, required: the Browserbase API key. */
16
+ readonly key: "COMPUTER_BROWSERBASE_API_KEY";
17
+ /** projectId: the project sessions are made in; a key behind a credential proxy names none. */
18
+ readonly project: "COMPUTER_BROWSERBASE_PROJECT_ID";
19
+ /** apiUrl: Browserbase's API; default https://api.browserbase.com. */
20
+ readonly url: "COMPUTER_BROWSERBASE_API_URL";
21
+ };
22
+ /** What this module reads from the environment: the key, and each other option whose name is set. */
23
+ export type BrowserbaseSettings = Pick<BrowserbaseProviderOptions, "apiKey" | "projectId" | "apiUrl">;
24
+ /** The provider's options this module reads from env, each only when its name is set; throws in words without the key, never echoing one. */
25
+ export declare function settingsFromEnv(env?: Record<string, string | undefined>): BrowserbaseSettings;
26
+ /** For the run's report: what this configuration means for the suite. */
27
+ export declare const conformanceNotes: string[];
28
+ export interface BrowserbaseModuleOptions extends Pick<BrowserbaseProviderOptions, "fetch" | "sleep" | "confirm"> {
29
+ /** Where the settings are read; default process.env. */
30
+ env?: Record<string, string | undefined>;
31
+ }
32
+ /** The image every computer of the run asks for: the vendor's Chromium. */
33
+ export declare function conformanceImage(): string;
34
+ /** The provider the CLI runs; throws in words without the live switch, or when the key is missing. */
35
+ export declare function createProvider({ env, ...transport }?: BrowserbaseModuleOptions): Promise<BrowserbaseProvider>;
@@ -0,0 +1,45 @@
1
+ // Browserbase for the conformance CLI: `npm run conformance -w @parcha/agentrun-computer -- --provider browserbase`.
2
+ // It makes a real, billed Browserbase session, so it runs only with AGENTRUN_COMPUTER_LIVE_BROWSERBASE=1 and a key the
3
+ // lead has OKed, under COMPUTER_BROWSERBASE_API_KEY (and COMPUTER_BROWSERBASE_PROJECT_ID for a direct key). The provider
4
+ // reads no environment: this module reads its own COMPUTER_BROWSERBASE_* names (never BROWSERBASE_API_KEY, which may
5
+ // hold another project's key) and passes each to create() as its option. The live switch is checked first, before any
6
+ // other setting is read. The run makes one session, shared by every case, and releases it.
7
+ import { BROWSER_IMAGE } from "../browser.js";
8
+ import { create } from "../browserbase.js";
9
+ /** The environment this module reads, by name, each for the option its comment names, and the live switch. */
10
+ export const BROWSERBASE_ENV = {
11
+ live: "AGENTRUN_COMPUTER_LIVE_BROWSERBASE",
12
+ /** apiKey, required: the Browserbase API key. */
13
+ key: "COMPUTER_BROWSERBASE_API_KEY",
14
+ /** projectId: the project sessions are made in; a key behind a credential proxy names none. */
15
+ project: "COMPUTER_BROWSERBASE_PROJECT_ID",
16
+ /** apiUrl: Browserbase's API; default https://api.browserbase.com. */
17
+ url: "COMPUTER_BROWSERBASE_API_URL",
18
+ };
19
+ /** The names this module reads, under the conformance modules' common name (ConformanceModule.ENV). */
20
+ export const ENV = BROWSERBASE_ENV;
21
+ /** The provider's options this module reads from env, each only when its name is set; throws in words without the key, never echoing one. */
22
+ export function settingsFromEnv(env = process.env) {
23
+ const apiKey = env[BROWSERBASE_ENV.key];
24
+ if (apiKey === undefined || apiKey === "") {
25
+ throw new Error(`set ${BROWSERBASE_ENV.key} to a Browserbase API key: the conformance module reads it there and nowhere else, never from BROWSERBASE_API_KEY`);
26
+ }
27
+ const projectId = env[BROWSERBASE_ENV.project] || undefined;
28
+ const apiUrl = env[BROWSERBASE_ENV.url] || undefined;
29
+ return { apiKey, ...(projectId === undefined ? {} : { projectId }), ...(apiUrl === undefined ? {} : { apiUrl }) };
30
+ }
31
+ /** For the run's report: what this configuration means for the suite. */
32
+ export const conformanceNotes = [
33
+ "browserbase: one session for the whole run, released by its last case (browser.release) and again at the run's end; Browserbase bills at least one minute of it. Browserbase keeps a session's downloads and recordings; the suite does not test them.",
34
+ ];
35
+ /** The image every computer of the run asks for: the vendor's Chromium. */
36
+ export function conformanceImage() {
37
+ return BROWSER_IMAGE;
38
+ }
39
+ /** The provider the CLI runs; throws in words without the live switch, or when the key is missing. */
40
+ export async function createProvider({ env = process.env, ...transport } = {}) {
41
+ if (env[BROWSERBASE_ENV.live] !== "1") {
42
+ throw new Error(`the Browserbase conformance module makes a real, billed session: set ${BROWSERBASE_ENV.live}=1, with a key the lead has OKed, to run it`);
43
+ }
44
+ return create({ ...settingsFromEnv(env), ...transport });
45
+ }
@@ -0,0 +1,2 @@
1
+ import type { Case } from "../types.js";
2
+ export declare const appsCases: Case[];
@@ -0,0 +1,155 @@
1
+ // Apps: the fixture installs, is listed, comes to the front when launched and leaves it when terminated; the UI tree has
2
+ // the protocol's shape, inside the screen, with the fixture's button found by its id. A phone's stock Settings app is
3
+ // listed, launched and terminated with no install, which needs the apps group alone: its launch is seen in the UI tree
4
+ // (Settings' list) when the phone has one, else in a screenshot that is not the one before. On a phone that takes no
5
+ // fixture file the tree's shape is checked on Settings, with its rows found (settings.ts).
6
+ import { MAX_UI_NODES } from "../../protocol.js";
7
+ import { FIXTURE_BUTTON } from "../fixture.js";
8
+ import { shoot } from "./screen.js";
9
+ import { openSettings, rowsOf, settingsApp, textsOf, throughSettings } from "./settings.js";
10
+ /** Whether the provider and the computer both declare group. */
11
+ const declares = (t, group) => t.provider.capabilities().groups.includes(group) && t.hello.groups.includes(group);
12
+ /** A screenshot's pixels sampled on a 16 x 16 grid, with its size: two different screens differ in it. */
13
+ async function screenPrint(t) {
14
+ const { image } = await shoot(t);
15
+ const samples = [];
16
+ for (let j = 0; j < 16; j++) {
17
+ for (let i = 0; i < 16; i++)
18
+ samples.push(image.rgb(Math.floor(((i + 0.5) * image.width) / 16), Math.floor(((j + 0.5) * image.height) / 16)).join(","));
19
+ }
20
+ return `${image.width}x${image.height}:${samples.join(";")}`;
21
+ }
22
+ /**
23
+ * What the screen shows now, as the case compares it: the UI tree's texts when the phone has a tree, else a
24
+ * screenshot's print. Undefined when it has neither, and the launch cannot be seen.
25
+ */
26
+ async function shown(t) {
27
+ if (declares(t, "apps.ui_tree"))
28
+ return JSON.stringify(textsOf(await t.call("apps.ui_tree", {})));
29
+ if (declares(t, "screen"))
30
+ return screenPrint(t);
31
+ return undefined;
32
+ }
33
+ const BOOLEANS = ["clickable", "focused", "selected", "checked", "scrollable"];
34
+ const STRINGS = ["id", "text", "label"];
35
+ /** The first way node (at path) breaks the protocol's UiNode, in words, or undefined; counts nodes as it walks. */
36
+ function shapeOf(node, path, screen, seen) {
37
+ if (typeof node !== "object" || node === null)
38
+ return `${path} is not an object`;
39
+ const n = node;
40
+ seen.nodes++;
41
+ if (seen.nodes > MAX_UI_NODES)
42
+ return `the tree holds more than ${MAX_UI_NODES} nodes`;
43
+ if (typeof n.role !== "string" || n.role === "")
44
+ return `${path}.role is ${JSON.stringify(n.role)}, not the platform's class`;
45
+ for (const field of STRINGS)
46
+ if (n[field] !== undefined && typeof n[field] !== "string")
47
+ return `${path}.${field} is ${JSON.stringify(n[field])}, not a string`;
48
+ if (typeof n.enabled !== "boolean")
49
+ return `${path}.enabled is ${JSON.stringify(n.enabled)}, not a boolean`;
50
+ for (const field of BOOLEANS)
51
+ if (n[field] !== undefined && typeof n[field] !== "boolean")
52
+ return `${path}.${field} is ${JSON.stringify(n[field])}, not a boolean`;
53
+ const bounds = n.bounds;
54
+ if (!(Array.isArray(bounds) && bounds.length === 4 && bounds.every((v) => typeof v === "number" && Number.isFinite(v)) && bounds[2] >= 0 && bounds[3] >= 0)) {
55
+ return `${path}.bounds is ${JSON.stringify(bounds)}, not [x, y, w, h]`;
56
+ }
57
+ if (screen !== undefined) {
58
+ const [x, y, w, h] = bounds;
59
+ if (x < 0 || y < 0 || x + w > screen[2] || y + h > screen[3])
60
+ return `${path}.bounds ${JSON.stringify(bounds)} reach outside the ${screen[2]}x${screen[3]} screenshot`;
61
+ }
62
+ if (!Array.isArray(n.children))
63
+ return `${path}.children is ${JSON.stringify(n.children)}, not a list`;
64
+ if (n.id === FIXTURE_BUTTON.id)
65
+ seen.button ??= node;
66
+ for (const [i, child] of n.children.entries()) {
67
+ const wrong = shapeOf(child, `${path}.children[${i}]`, screen, seen);
68
+ if (wrong !== undefined)
69
+ return wrong;
70
+ }
71
+ return undefined;
72
+ }
73
+ const foreground = async (t) => (await t.call("apps.list", {})).foreground;
74
+ export const appsCases = [
75
+ {
76
+ id: "apps.install-launch",
77
+ level: "core",
78
+ group: "apps",
79
+ needs: ["apps.install", "apps", "files"],
80
+ async run(t) {
81
+ // The fixture is written with files.write, installed with apps.install and launched.
82
+ const fixture = await t.fixture();
83
+ const id = t.present(fixture.app, "the fixture names the app it installed");
84
+ const listed = await t.call("apps.list", {});
85
+ t.assert(Array.isArray(listed.apps) && listed.apps.every((app) => typeof app?.id === "string"), `apps.list gives apps with ids: ${JSON.stringify(listed.apps).slice(0, 300)}`);
86
+ t.assert(listed.apps.some((app) => app.id === id), `apps.list holds the installed ${id}`);
87
+ await t.until(async () => (await foreground(t)) === id, `${id} in front after apps.launch`);
88
+ t.deepEqual(await t.call("apps.terminate", { id }), {}, `apps.terminate ${id}`);
89
+ await t.until(async () => (await foreground(t)) !== id, `${id} no longer in front after apps.terminate`);
90
+ t.deepEqual(await t.call("apps.launch", { id }), {}, `apps.launch ${id}`);
91
+ await t.until(async () => (await foreground(t)) === id, `${id} in front after a second apps.launch`);
92
+ },
93
+ },
94
+ {
95
+ id: "apps.launch-terminate",
96
+ level: "core",
97
+ group: "apps",
98
+ needs: ["apps"],
99
+ async run(t) {
100
+ // The phone's own Settings app: listed; launched, in front and shown; terminated, and no longer in front.
101
+ const app = settingsApp(t);
102
+ const listed = await t.call("apps.list", {});
103
+ t.assert(Array.isArray(listed.apps) && listed.apps.every((one) => typeof one?.id === "string"), `apps.list gives apps with ids: ${JSON.stringify(listed.apps).slice(0, 300)}`);
104
+ t.assert(listed.apps.some((one) => one.id === app), `apps.list holds ${app}`);
105
+ t.deepEqual(await t.call("apps.terminate", { id: app }), {}, `apps.terminate ${app}`);
106
+ await t.until(async () => (await foreground(t)) !== app, `${app} not in front after apps.terminate`);
107
+ const before = await shown(t);
108
+ if (before === undefined)
109
+ return t.skip("no way to see a launch: the computer declares neither apps.ui_tree nor screen");
110
+ t.deepEqual(await t.call("apps.launch", { id: app }), {}, `apps.launch ${app}`);
111
+ await t.until(async () => (await foreground(t)) === app, `${app} in front after apps.launch`);
112
+ // apps.list's word is not enough: the screen must show it.
113
+ if (declares(t, "apps.ui_tree")) {
114
+ await t.until(async () => {
115
+ const tree = await t.call("apps.ui_tree", {});
116
+ return rowsOf(tree).length > 0 && JSON.stringify(textsOf(tree)) !== before;
117
+ }, `${app} shown after apps.launch: Settings' list in apps.ui_tree, not the screen before it`);
118
+ }
119
+ else {
120
+ await t.until(async () => (await screenPrint(t)) !== before, `${app} shown after apps.launch: a screenshot other than the one before it`);
121
+ }
122
+ t.deepEqual(await t.call("apps.terminate", { id: app }), {}, `apps.terminate ${app}, launched`);
123
+ await t.until(async () => (await foreground(t)) !== app, `${app} no longer in front after apps.terminate`);
124
+ const missing = await t.client.call("apps.launch", { id: "ai.agentrun.no.such.app" }, { signal: t.signal });
125
+ t.refused(missing, "apps.launch of an app that is not installed", ["not_found"]);
126
+ },
127
+ },
128
+ {
129
+ id: "apps.ui-tree-shape",
130
+ level: "core",
131
+ group: "apps",
132
+ needs: ["apps.ui_tree"],
133
+ async run(t) {
134
+ const settings = throughSettings(t);
135
+ if (settings)
136
+ await openSettings(t);
137
+ else
138
+ await t.fixture();
139
+ const screen = t.provider.capabilities().groups.includes("screen") ? await t.call("screen.shot", {}) : undefined;
140
+ const rect = screen ? [0, 0, screen.width, screen.height] : undefined;
141
+ const tree = await t.call("apps.ui_tree", {});
142
+ const seen = { nodes: 0 };
143
+ const wrong = shapeOf(tree.root, "root", rect, seen);
144
+ t.assert(wrong === undefined, `apps.ui_tree: ${wrong}`);
145
+ t.equal(tree.nodes, seen.nodes, "apps.ui_tree's nodes, against the nodes in its tree");
146
+ t.equal(typeof tree.truncated, "boolean", "apps.ui_tree's truncated is a boolean");
147
+ if (settings) {
148
+ t.assert(rowsOf(tree).length > 0, "Settings' list, with its rows, in apps.ui_tree");
149
+ return;
150
+ }
151
+ const button = t.present(seen.button, `the fixture's button, by its id ${FIXTURE_BUTTON.id}, in apps.ui_tree`);
152
+ t.equal(button.text, FIXTURE_BUTTON.text, "the fixture's button's text");
153
+ },
154
+ },
155
+ ];
@@ -0,0 +1,4 @@
1
+ import type { Case } from "../types.js";
2
+ export declare const browserOnlyCases: Case[];
3
+ /** What the CLI runs for a browser: the health cases (hello and ping from the provider, the kind consistent), then these. */
4
+ export declare const browserCases: Case[];