@parcha/agentrun-computer 0.1.0-beta.36 → 0.1.0-beta.38

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 (155) hide show
  1. package/NOTICE +2 -0
  2. package/README.md +547 -478
  3. package/box/Dockerfile +18 -1
  4. package/box/README.md +13 -0
  5. package/box/build-agent37.mjs +158 -0
  6. package/box/build-daytona.py +2 -2
  7. package/box/build-e2b.mjs +41 -18
  8. package/box/recipe.mjs +43 -0
  9. package/dist/agent37-ssh.d.ts +89 -0
  10. package/dist/agent37-ssh.js +445 -0
  11. package/dist/agent37.d.ts +104 -0
  12. package/dist/agent37.js +402 -0
  13. package/dist/attach.d.ts +146 -0
  14. package/dist/attach.js +469 -0
  15. package/dist/browserbase.d.ts +2 -10
  16. package/dist/browserbase.js +3 -6
  17. package/dist/client.d.ts +45 -4
  18. package/dist/client.js +92 -4
  19. package/dist/computerd-linux-amd64 +0 -0
  20. package/dist/computerd-linux-arm64 +0 -0
  21. package/dist/computerd.json +4 -0
  22. package/dist/conformance/agent37.d.ts +96 -0
  23. package/dist/conformance/agent37.js +154 -0
  24. package/dist/conformance/cases/apps.d.ts +11 -0
  25. package/dist/conformance/cases/apps.js +173 -73
  26. package/dist/conformance/cases/health.js +14 -0
  27. package/dist/conformance/cases/index.js +2 -0
  28. package/dist/conformance/cases/isolation.d.ts +7 -5
  29. package/dist/conformance/cases/isolation.js +44 -14
  30. package/dist/conformance/cases/mount.js +1 -1
  31. package/dist/conformance/cases/provider.js +27 -1
  32. package/dist/conformance/cases/screen.d.ts +3 -0
  33. package/dist/conformance/cases/screen.js +18 -0
  34. package/dist/conformance/cases/settings.d.ts +29 -23
  35. package/dist/conformance/cases/settings.js +76 -58
  36. package/dist/conformance/cases/touch.js +19 -17
  37. package/dist/conformance/cases/ui.d.ts +2 -0
  38. package/dist/conformance/cases/ui.js +475 -0
  39. package/dist/conformance/cli.d.ts +9 -0
  40. package/dist/conformance/cli.js +94 -9
  41. package/dist/conformance/daytona.d.ts +9 -20
  42. package/dist/conformance/daytona.js +12 -21
  43. package/dist/conformance/e2b.d.ts +6 -0
  44. package/dist/conformance/e2b.js +9 -2
  45. package/dist/conformance/exec-stream.d.ts +45 -0
  46. package/dist/conformance/exec-stream.js +486 -0
  47. package/dist/conformance/fixture.d.ts +1 -1
  48. package/dist/conformance/fixture.js +25 -1
  49. package/dist/conformance/modal.d.ts +17 -13
  50. package/dist/conformance/modal.js +18 -9
  51. package/dist/conformance/orgo.d.ts +3 -3
  52. package/dist/conformance/orgo.js +6 -8
  53. package/dist/conformance/phone-harness.d.ts +6 -2
  54. package/dist/conformance/phone-harness.js +21 -4
  55. package/dist/conformance/report.js +1 -1
  56. package/dist/conformance/runner.js +23 -4
  57. package/dist/conformance/sweep.d.ts +50 -0
  58. package/dist/conformance/sweep.js +187 -0
  59. package/dist/conformance/types.d.ts +13 -5
  60. package/dist/conformance/ui-fixture.d.ts +56 -0
  61. package/dist/conformance/ui-fixture.js +43 -0
  62. package/dist/create-requests.d.ts +51 -0
  63. package/dist/create-requests.js +121 -0
  64. package/dist/daytona.d.ts +20 -133
  65. package/dist/daytona.js +405 -1449
  66. package/dist/descriptor.d.ts +11 -1
  67. package/dist/descriptor.js +9 -0
  68. package/dist/descriptors/agent37.d.ts +41 -0
  69. package/dist/descriptors/agent37.js +28 -0
  70. package/dist/descriptors/daytona.d.ts +6 -5
  71. package/dist/descriptors/daytona.js +9 -5
  72. package/dist/descriptors/index.d.ts +42 -7
  73. package/dist/descriptors/index.js +4 -2
  74. package/dist/descriptors/orgo.d.ts +2 -1
  75. package/dist/descriptors/orgo.js +3 -2
  76. package/dist/descriptors/phone-harness.d.ts +1 -1
  77. package/dist/descriptors/phone-harness.js +2 -2
  78. package/dist/descriptors/shared.d.ts +1 -1
  79. package/dist/descriptors/shared.js +2 -2
  80. package/dist/desktop.d.ts +18 -4
  81. package/dist/desktop.js +89 -9
  82. package/dist/docker.d.ts +7 -10
  83. package/dist/docker.js +272 -34
  84. package/dist/drift.js +4 -4
  85. package/dist/e2b.d.ts +16 -290
  86. package/dist/e2b.js +230 -1393
  87. package/dist/fake-ui-driver.d.ts +97 -0
  88. package/dist/fake-ui-driver.js +717 -0
  89. package/dist/host.d.ts +201 -0
  90. package/dist/host.js +8 -0
  91. package/dist/hosted/process.d.ts +81 -0
  92. package/dist/hosted/process.js +259 -0
  93. package/dist/hosted/provider.d.ts +160 -0
  94. package/dist/hosted/provider.js +1415 -0
  95. package/dist/hosted/rest.d.ts +66 -0
  96. package/dist/hosted/rest.js +121 -0
  97. package/dist/hosted/scripts.d.ts +82 -0
  98. package/dist/{child.js → hosted/scripts.js} +118 -12
  99. package/dist/hosted/values.d.ts +5 -0
  100. package/dist/hosted/values.js +8 -0
  101. package/dist/index.d.ts +7 -3
  102. package/dist/index.js +7 -4
  103. package/dist/kernel.d.ts +2 -10
  104. package/dist/kernel.js +3 -6
  105. package/dist/kinds.d.ts +11 -2
  106. package/dist/kinds.js +20 -4
  107. package/dist/local-chrome.d.ts +2 -10
  108. package/dist/local-chrome.js +3 -6
  109. package/dist/modal.d.ts +22 -257
  110. package/dist/modal.js +183 -1280
  111. package/dist/mount-archil.d.ts +8 -4
  112. package/dist/mount-archil.js +22 -11
  113. package/dist/mount.d.ts +10 -4
  114. package/dist/mount.js +8 -4
  115. package/dist/orgo-channel.d.ts +3 -2
  116. package/dist/orgo-channel.js +5 -2
  117. package/dist/orgo-desktop.d.ts +9 -4
  118. package/dist/orgo-desktop.js +33 -13
  119. package/dist/orgo-workspaces.d.ts +47 -0
  120. package/dist/orgo-workspaces.js +94 -0
  121. package/dist/orgo.d.ts +10 -13
  122. package/dist/orgo.js +32 -21
  123. package/dist/phone-harness.d.ts +31 -28
  124. package/dist/phone-harness.js +510 -702
  125. package/dist/png.d.ts +4 -0
  126. package/dist/png.js +27 -0
  127. package/dist/protocol.d.ts +339 -33
  128. package/dist/protocol.js +97 -3
  129. package/dist/provider.d.ts +36 -8
  130. package/dist/provider.js +16 -0
  131. package/dist/providers.d.ts +11 -12
  132. package/dist/result.d.ts +1 -1
  133. package/dist/screen-watch.js +34 -6
  134. package/dist/surface/api.d.ts +260 -0
  135. package/dist/surface/api.js +1 -0
  136. package/dist/surface/core.d.ts +55 -0
  137. package/dist/surface/core.js +475 -0
  138. package/dist/surface/index.d.ts +5 -0
  139. package/dist/surface/index.js +3 -0
  140. package/dist/surface/outline.d.ts +10 -0
  141. package/dist/surface/outline.js +51 -0
  142. package/dist/surface/script.d.ts +10 -0
  143. package/dist/surface/script.js +94 -0
  144. package/dist/ui-engine.d.ts +114 -0
  145. package/dist/ui-engine.js +814 -0
  146. package/package.json +18 -3
  147. package/dist/child.d.ts +0 -42
  148. package/dist/conformance/daytona-sweep.d.ts +0 -18
  149. package/dist/conformance/daytona-sweep.js +0 -126
  150. package/dist/conformance/e2b-diagnose.d.ts +0 -16
  151. package/dist/conformance/e2b-diagnose.js +0 -61
  152. package/dist/conformance/e2b-sweep.d.ts +0 -18
  153. package/dist/conformance/e2b-sweep.js +0 -132
  154. package/dist/conformance/modal-sweep.d.ts +0 -22
  155. package/dist/conformance/modal-sweep.js +0 -213
@@ -151,9 +151,10 @@ export interface AllowCapability {
151
151
  mixed: boolean;
152
152
  }
153
153
  /**
154
- * Who answers a computer's methods. pid1: computerd init is the computer's main process, so its exit ends the computer.
155
- * child: the vendor's own agent is the main process and starts init at boot; init's exit does not end the computer.
156
- * none: no computerd runs; the provider answers the methods itself, from our server (adb, the vendor's API).
154
+ * Whether computerd init runs in the computer, and so keeps init's promises about programs; who answers the wire is
155
+ * hello's business. pid1: init is the computer's main process, so its exit ends the computer. child: the vendor's own
156
+ * agent is the main process and starts init at boot; init's exit does not end the computer. none: no init runs; the
157
+ * provider answers the methods itself (adb, the vendor's API), or a driver on the machine does (an attached Mac).
157
158
  */
158
159
  export type DaemonMode = "pid1" | "child" | "none";
159
160
  export interface ComputerCapabilities {
@@ -178,8 +179,8 @@ export interface ComputerCapabilities {
178
179
  isolation: "container" | "gvisor" | "microvm" | "vm" | "machine" | "host";
179
180
  os: ComputerOs;
180
181
  /**
181
- * With release "stop": true when a stop ends in deletion (Daytona with autoDeleteMinutes 0), so release(ref, "stop")
182
- * leaves no computer, listed or attachable. Absent or false: a stopped computer is kept, listed stopped, until deleted.
182
+ * With release "stop": true when a stop ends in deletion, so release(ref, "stop") leaves no computer, listed or
183
+ * attachable. Absent or false: a stopped computer is kept, listed stopped, until deleted.
183
184
  */
184
185
  stopDeletes?: boolean;
185
186
  daemon: DaemonMode;
@@ -330,6 +331,24 @@ export interface ComputerInfo {
330
331
  export interface CallContext {
331
332
  signal?: AbortSignal;
332
333
  }
334
+ /** One value Settings offers for a picked key (keyChoices): the value saved, and the words a person picks it by. */
335
+ export interface KeyChoice {
336
+ value: string;
337
+ label: string;
338
+ }
339
+ /**
340
+ * create's context: requestId is the caller's id of this request, not of the computer (serve passes the run's claim; a
341
+ * conformance run one per create). Required, with no generated fallback. Every provider names the computer from it
342
+ * (computerNameFor), so a retry of the same request (a timeout, a crash between the vendor's answer and ours) finds
343
+ * the computer the first one made instead of making a second; one that ended is refused as exists.
344
+ */
345
+ export interface CreateContext extends CallContext {
346
+ requestId: string;
347
+ }
348
+ /** The name of the computer one create's request makes: computer- and the first 12 hex digits of its sha256. */
349
+ export declare function computerNameFor(requestId: string): string;
350
+ /** Why a create's request id is not one, or undefined: every provider's create refuses it as invalid. */
351
+ export declare function requestIdProblem(requestId: unknown): string | undefined;
333
352
  /** attach's context: with a claim, an agent's computer is brought back and taken by that run, under that epoch. */
334
353
  export interface AttachContext extends CallContext {
335
354
  claim?: ComputerClaim;
@@ -366,9 +385,11 @@ export interface ComputerProvider {
366
385
  readonly version: string;
367
386
  capabilities(): ComputerCapabilities;
368
387
  check(spec: ComputerSpec): Refusal[];
369
- create(spec: ComputerSpec, context?: {
370
- signal?: AbortSignal;
371
- }): Promise<Result<CreatedComputer>>;
388
+ /**
389
+ * Makes one computer for the spec, once per context.requestId (provider.md, Idempotent create): the same id again
390
+ * while that computer starts or runs answers it, and after it ended is refused exists. Never a second computer.
391
+ */
392
+ create(spec: ComputerSpec, context: CreateContext): Promise<Result<CreatedComputer>>;
372
393
  /**
373
394
  * Finds one computer this provider made, by its id or by labels, with the spec read back from it; none or several is
374
395
  * an error in words. With context.claim (a provider that declares persistence): the agent's computer is brought back
@@ -436,6 +457,13 @@ export interface ComputerProvider {
436
457
  testConnection?(context?: CallContext): Promise<Result<{
437
458
  detail: string;
438
459
  }>>;
460
+ /**
461
+ * The values Settings offers for a key a person picks rather than types (its descriptor key's `picked`), by the
462
+ * create() option it fills, read from the vendor with the provider's other keys and never making a computer: Orgo's
463
+ * workspaces, each its id and its name. ok with each value and its words; an error in words where there is none to
464
+ * pick (an account with no workspace) or the read failed. Optional; a provider whose descriptor picks a key has it.
465
+ */
466
+ keyChoices?(option: string, context?: CallContext): Promise<Result<KeyChoice[]>>;
439
467
  /**
440
468
  * The image its computers start from, made ready on its engine before the first create: built from its recipe, or
441
469
  * pulled by name, when the engine lacks it; ok with the tag to put in spec.image. `onWait` is told once, before a build
package/dist/provider.js CHANGED
@@ -1,3 +1,5 @@
1
+ // The provisioner: one per vendor. It makes, finds and ends computers; the daemon inside does the work.
2
+ import { createHash } from "node:crypto";
1
3
  /** The os and daemon modes each kind may have; no other pair is valid. */
2
4
  export const KIND_SHAPES = {
3
5
  linux: { os: ["linux"], daemon: ["pid1", "child"] },
@@ -110,3 +112,17 @@ export function checkGpu(gpu, { gpu: offered }, mount) {
110
112
  }
111
113
  return [];
112
114
  }
115
+ /** A request id's most characters: it is hashed into the name, never sent. */
116
+ const REQUEST_ID_MAX = 1024;
117
+ /** The name of the computer one create's request makes: computer- and the first 12 hex digits of its sha256. */
118
+ export function computerNameFor(requestId) {
119
+ return `computer-${createHash("sha256").update(requestId, "utf8").digest("hex").slice(0, 12)}`;
120
+ }
121
+ /** Why a create's request id is not one, or undefined: every provider's create refuses it as invalid. */
122
+ export function requestIdProblem(requestId) {
123
+ if (typeof requestId !== "string" || requestId === "")
124
+ return "create needs context.requestId, the caller's id of this request (serve passes the run's claim): a retry with the same id finds the computer the first one made";
125
+ if (requestId.length > REQUEST_ID_MAX || requestId.includes("\0"))
126
+ return `context.requestId is at most ${REQUEST_ID_MAX} characters, with no NUL byte`;
127
+ return undefined;
128
+ }
@@ -1,7 +1,7 @@
1
1
  import type { RunFolder } from "./conformance/types.js";
2
2
  import type { ProviderDescriptor } from "./descriptor.js";
3
3
  import { DESCRIPTORS } from "./descriptors/index.js";
4
- import type { KindCapabilities } from "./kinds.js";
4
+ import type { MachineHost } from "./host.js";
5
5
  import type { MountKind } from "./mount.js";
6
6
  import type { ComputerProvider } from "./provider.js";
7
7
  /** Where the conformance side reads its settings: process.env, or a record of the same shape. */
@@ -20,22 +20,21 @@ export interface ConformanceModule {
20
20
  mountFor?(kind: MountKind, options?: object): RunFolder | undefined | Promise<RunFolder | undefined>;
21
21
  conformanceImage?(options?: object): string | Promise<string>;
22
22
  conformanceNotes?: string[];
23
+ /**
24
+ * A provider on the shared adapter: its MachineHost from the same settings, with no live switch, since it makes
25
+ * nothing by itself. The live sweep lists and deletes through it, and the exec pre-check (--exec-stream) calls its
26
+ * exec alone.
27
+ */
28
+ createHost?(options?: object): MachineHost | Promise<MachineHost>;
23
29
  settingsFromEnv?(env?: ProviderEnv): object;
24
30
  /** Every name settingsFromEnv (and the module) reads, by role: COMPUTER_<ID>_*, or its live switch. */
25
31
  readonly ENV?: Readonly<Record<string, string>>;
26
32
  }
27
- /** What every registry line resolves to: the provider file's module. */
33
+ /**
34
+ * What every registry line resolves to: the provider file's module. Its mount kinds and configurations are its
35
+ * descriptor's (mounts, capabilities), read without loading it.
36
+ */
28
37
  export interface ProviderModule {
29
- /**
30
- * The mount kinds its computers take, the same as its provider's capabilities().mount (none: []): a caller tells which
31
- * provider binds a local folder from the registry alone, without building one.
32
- */
33
- readonly MOUNT: readonly MountKind[];
34
- /**
35
- * The machine kind and groups of each configuration it offers, as its built providers' capabilities() declare them:
36
- * the kind registry's entry for it (PROVIDERS in kinds.ts) holds the same, and derives its setting kinds from them.
37
- */
38
- readonly CAPABILITIES: readonly KindCapabilities[];
39
38
  /**
40
39
  * The provider, built from its options alone, its key included; it reads no environment, and throws in words when an
41
40
  * option is missing or wrong, never echoing a key. Each provider file types its own options.
package/dist/result.d.ts CHANGED
@@ -6,7 +6,7 @@ export type Result<T, E = ComputerError> = {
6
6
  ok: false;
7
7
  error: E;
8
8
  };
9
- export type ComputerErrorCode = "gone" | "refused" | "timeout" | "aborted" | "not_found" | "invalid" | "unsupported" | "denied" | "limit" | "exists" | "not_dir" | "is_dir" | "unauthorized" | "unreachable" | "vendor";
9
+ export type ComputerErrorCode = "gone" | "refused" | "timeout" | "aborted" | "not_found" | "invalid" | "unsupported" | "denied" | "limit" | "exists" | "not_dir" | "is_dir" | "stale" | "unauthorized" | "unreachable" | "vendor";
10
10
  export interface ComputerError {
11
11
  code: ComputerErrorCode;
12
12
  message: string;
@@ -2,13 +2,16 @@
2
2
  //
3
3
  // watchScreen(connection, options) is the internal seam: the screen as pull-paced frames and an input sink on one
4
4
  // connection. screen.watch asks for the frame after the last one given, and the next ask is made only when the caller
5
- // calls next() again, so each next() is the ack of the frame before it. act() sends input.actions on the same
5
+ // calls next() again, so each next() is the ack of the frame before it. A computer that lists screen.ahead (computerd
6
+ // on a desktop) is asked one frame ahead: two asks are kept in flight, the second for the frame after the first's, so
7
+ // its frames come at its own pace and not one each round trip; next() still gives one frame at a time, the newest
8
+ // answered, and a frame bettered before next() asked for it is dropped. act() sends input.actions on the same
6
9
  // connection. close() and the caller's signal end both: the waiting ask is cancelled, the frames end, and act()
7
10
  // refuses in words. A computer that fails makes next() reject with a ScreenWatchError.
8
11
  //
9
12
  // provider.watch(ref, handlers, options) is what the runner's viewer calls (tl-browser's handler shape, final), built
10
13
  // once, by daemonWatch, as an adapter over watchScreen: each frame goes to handlers.frame(frame, ack), and the next is
11
- // asked for only once ack() is called; a computer that goes ends it once with handlers.ended(error), its code gone,
14
+ // given only once ack() is called; a computer that goes ends it once with handlers.ended(error), its code gone,
12
15
  // unreachable, refused or unsupported; close() and the signal end it with no ended(). Every computerd provider and the
13
16
  // phone answer watch() through daemonWatch, on a connection of the watch's own: computerd gives JPEG frames, the phone
14
17
  // client PNG ones. No error in either layer holds a URL or a secret.
@@ -84,18 +87,40 @@ export function watchScreen(connection, options = {}) {
84
87
  ...(options.maxWidth === undefined ? {} : { maxWidth: options.maxWidth }),
85
88
  ...(options.quality === undefined ? {} : { quality: options.quality }),
86
89
  };
90
+ // A computer that lists screen.ahead takes a second ask while the first waits (after one past the newest frame): two
91
+ // are kept in flight, so its frames come at its own pace, not one each round trip. Else one, after each ack.
92
+ // Why it exists: with one ask in flight each frame waits a full round trip, about 7 fps (kit-10, 5-run medians:
93
+ // E2B 7.00 one ask vs 12.96 two, Agent37 6.15 vs 14.53).
94
+ const depth = connection.hello?.features?.["screen.ahead"] === true ? 2 : 1;
87
95
  async function* frames() {
88
- let after = 0;
96
+ /** The seq of the newest frame given. */
97
+ let last = 0;
98
+ /** The asks in flight, oldest first. */
99
+ const asks = [];
100
+ const newer = (answer) => answer?.ok === true && answer.value.changed && answer.value.seq > last;
101
+ const ask = () => {
102
+ while (asks.length < depth) {
103
+ // The ask after one in flight is ahead by one: it waits for the frame after the one the first answers.
104
+ const asked = { promise: client.call("screen.watch", { after: last + asks.length, ...params }, { signal: stop.signal }) };
105
+ void asked.promise.then((answer) => (asked.answer = answer));
106
+ asks.push(asked);
107
+ }
108
+ };
89
109
  for (;;) {
90
110
  if (ended)
91
111
  return;
92
- const asked = await client.call("screen.watch", { after, ...params }, { signal: stop.signal });
112
+ ask();
113
+ // A frame the ask after it has already bettered is dropped: the viewer wants the newest.
114
+ while (asks.length > 1 && asks[0].answer !== undefined && newer(asks[1].answer))
115
+ asks.shift();
116
+ const asked = await asks.shift().promise;
93
117
  if (ended)
94
118
  return;
95
119
  if (!asked.ok)
96
120
  throw new ScreenWatchError(asked.error.code, redactWords(asked.error.message));
97
121
  const answer = asked.value;
98
- if (!answer.changed) {
122
+ if (!answer.changed || answer.seq <= last) {
123
+ // No change within the wait, or a frame given already (two asks may answer the same newest frame).
99
124
  // The computer waited its waitMs; one that answers at once must not spin: timers and the signal run first.
100
125
  await new Promise((resolve) => setImmediate(resolve));
101
126
  continue;
@@ -128,7 +153,10 @@ export function watchScreen(connection, options = {}) {
128
153
  }
129
154
  if (sized && size !== said)
130
155
  throw new ScreenWatchError("invalid", `frame ${answer.seq} ended at ${size} bytes of the ${said} it said`);
131
- after = answer.seq;
156
+ last = answer.seq;
157
+ // Asked ahead, the next asks go out before this frame is drawn: the computer makes the next one meanwhile.
158
+ if (depth > 1)
159
+ ask();
132
160
  yield {
133
161
  seq: answer.seq,
134
162
  format: answer.format ?? "jpeg",
@@ -0,0 +1,260 @@
1
+ import type { ComputerKind, ComputerOs, FileType, InputAction, Point, Rect, ScreenSize, UiExpect, UiNode, UiRef, UiRoute, UiStep } from "../protocol.js";
2
+ /** An image a script can show the model with `image(...)`: base64 PNG or JPEG, with its size in pixels. */
3
+ export interface Image {
4
+ type: "image";
5
+ mimeType: "image/png" | "image/jpeg";
6
+ /** base64. */
7
+ data: string;
8
+ width: number;
9
+ height: number;
10
+ }
11
+ /** What the computer is, from its hello. */
12
+ export interface Card {
13
+ kind: ComputerKind;
14
+ os: ComputerOs;
15
+ /** The OS's own version, as "15" or "26.1", where the computer says it. */
16
+ osVersion?: string;
17
+ arch: string;
18
+ /** The main screen, in points, where the computer has one. */
19
+ screen?: ScreenSize;
20
+ /** What the computer offers (hello.groups): each namespace below is here only with its group. */
21
+ groups: string[];
22
+ /** What its groups can and cannot do here: a feature that is off says why. */
23
+ features: Record<string, true | {
24
+ off: string;
25
+ }>;
26
+ }
27
+ /** One observation of an app's window: its state id, its elements, and its image when asked. */
28
+ export interface State {
29
+ /** The state's id, as "s7". A step at a point names it (an act's `state`), and is refused as stale once the window
30
+ * moved or redrew under the point. */
31
+ id: string;
32
+ app: {
33
+ id: string;
34
+ name: string;
35
+ };
36
+ /** bounds in screen points: where the window sits. Elements' bounds and steps' points are in the window's points. */
37
+ window: {
38
+ id: string;
39
+ title?: string;
40
+ bounds: Rect;
41
+ };
42
+ /** The elements, in reading order, each after its parent. */
43
+ elements: UiNode[];
44
+ /** Elements were left out (too many, or past the reply's size). */
45
+ truncated: boolean;
46
+ /** The elements as compact lines, as computer_observe shows them: `@e12 button "Save"`. */
47
+ outline: string;
48
+ /** The window's image, when asked. Its pixels are not points: a point is pixel × window.bounds[2] / image.width. */
49
+ image?: Image;
50
+ }
51
+ /** How a step reached the app: the protocol's routes, or `input` for raw screen input on a computer with no ui group. */
52
+ export type Route = UiRoute | "input";
53
+ /** What one step did: the route it ran by, and whether a readback confirmed it; or why it was refused. */
54
+ export type StepResult = {
55
+ route: Route;
56
+ verified: boolean;
57
+ } | {
58
+ error: {
59
+ kind: string;
60
+ message: string;
61
+ };
62
+ };
63
+ /** What an act did: each step's result, the expect's outcome, whether the window changed, and the new state. */
64
+ export interface ActResult {
65
+ /** One per step tried, in order. A refused step is the last: the steps after it did not run. */
66
+ steps: StepResult[];
67
+ /** With an expect: met, or unmet when it did not hold before its timeout. */
68
+ expect?: "met" | "unmet";
69
+ /** The window changed after the steps. Absent with raw input, which can't tell. */
70
+ changed?: boolean;
71
+ /** The state after the steps. Absent with raw input, which has no states. */
72
+ state?: string;
73
+ /** The new observation, when asked with `observe`. */
74
+ after?: State;
75
+ }
76
+ /** What raw input did: one result per action tried, in order; a refused one is the last. */
77
+ export interface InputResult {
78
+ steps: StepResult[];
79
+ }
80
+ /** What `observe` takes. */
81
+ export interface ObserveOptions {
82
+ /** Add the window's image. Default false: the elements are usually enough. */
83
+ image?: boolean;
84
+ /** Every element, not only those that can be acted on or have a name. */
85
+ full?: boolean;
86
+ }
87
+ /** What `act` takes, beside its steps. */
88
+ export interface ActOptions {
89
+ /** The state the steps' points were read from. A step at a point needs it; the app's last observe is the default. */
90
+ state?: string;
91
+ /** A condition to wait for after the steps. */
92
+ expect?: UiExpect;
93
+ /** Let steps take the foreground route, which moves the user's pointer and focus. Default false. */
94
+ foreground?: boolean;
95
+ /** Observe again after the steps and return it as `after` (one call instead of two). */
96
+ observe?: boolean | ObserveOptions;
97
+ }
98
+ /** An app, bound by its id: observe it and act on it. Every act waits until the window settles. */
99
+ export interface App {
100
+ readonly id: string;
101
+ /** Observe the app's window: its elements, and its image when asked. */
102
+ observe(options?: ObserveOptions): Promise<State>;
103
+ /** The elements of the app's last observation that match, with no call to the computer: by role (ARIA's, the same on
104
+ * every OS), by the app's own id for it, and by a text its name, value or desc holds (or a RegExp they match). */
105
+ find(query: {
106
+ role?: string;
107
+ id?: string;
108
+ text?: string | RegExp;
109
+ }): UiNode[];
110
+ /** Run steps on the app, in order; the first refused one stops the rest. */
111
+ act(steps: UiStep[], options?: ActOptions): Promise<ActResult>;
112
+ /** The element's default action: the surest, fastest step. */
113
+ press(ref: UiRef, options?: ActOptions): Promise<ActResult>;
114
+ /** Set an element's value: a field's text, a slider's value, a switch's "on" or "off". */
115
+ set(ref: UiRef, value: string, options?: ActOptions): Promise<ActResult>;
116
+ click(at: UiRef | Point, options?: ActOptions & {
117
+ button?: "left" | "right";
118
+ count?: 1 | 2 | 3;
119
+ }): Promise<ActResult>;
120
+ type(text: string, options?: ActOptions & {
121
+ into?: UiRef;
122
+ }): Promise<ActResult>;
123
+ /** A key or a chord: key("enter"), key("super+s"). */
124
+ key(chord: string, options?: ActOptions): Promise<ActResult>;
125
+ /** Scroll by points: dy > 0 shows what is below. */
126
+ scroll(at: UiRef | Point, delta: {
127
+ dx?: number;
128
+ dy?: number;
129
+ }, options?: ActOptions): Promise<ActResult>;
130
+ /** Wait until the condition holds (or, with gone, no longer holds), at most its timeoutMs. */
131
+ waitFor(expect: UiExpect): Promise<ActResult>;
132
+ }
133
+ /** An app the computer has. */
134
+ export interface AppInfo {
135
+ id: string;
136
+ name?: string;
137
+ }
138
+ /** What a shell command did. */
139
+ export interface RunResult {
140
+ stdout: string;
141
+ stderr: string;
142
+ /** null when a signal ended it. */
143
+ exitCode: number | null;
144
+ timedOut: boolean;
145
+ /** Output past what is kept was cut. */
146
+ truncated: boolean;
147
+ }
148
+ /** A file or a directory. */
149
+ export interface FileInfo {
150
+ path: string;
151
+ type: FileType;
152
+ size: number;
153
+ mtimeMs: number;
154
+ }
155
+ /** The computer an agent's code drives. */
156
+ export interface Computer {
157
+ /** What this computer is. */
158
+ readonly card: Card;
159
+ /** @group apps */
160
+ readonly apps: {
161
+ /** The installed apps, and which is in front. */
162
+ list(): Promise<{
163
+ apps: AppInfo[];
164
+ foreground: string | null;
165
+ }>;
166
+ /** Open an app (with background, without taking the front, where the computer can). With the ui group, bind it
167
+ * with app(id). */
168
+ open(id: string, options?: {
169
+ url?: string;
170
+ background?: boolean;
171
+ }): Promise<void>;
172
+ };
173
+ /** Bind an app by its id, open or not, to observe it and act on it. No id: the app in front.
174
+ * @group ui */
175
+ app(id?: string): App;
176
+ /** @group screen */
177
+ readonly screen: {
178
+ /** A screenshot, as an image; with region, only that part, in the whole screen's pixels. */
179
+ shot(options?: {
180
+ region?: Rect;
181
+ }): Promise<Image>;
182
+ };
183
+ /** Raw input at screenshot pixels: the screen, not an app. With the ui group, prefer an app's steps; this reaches
184
+ * what they can't (a drag from one app to another, a swipe from the screen's edge, a pinch, outside every window).
185
+ * @group input.pointer input.touch input.keys */
186
+ readonly input: {
187
+ act(actions: InputAction[]): Promise<InputResult>;
188
+ };
189
+ /** @group exec */
190
+ readonly shell: {
191
+ /** Run a command: a string runs in sh -c, a list is the program and its arguments. */
192
+ run(command: string | string[], options?: {
193
+ cwd?: string;
194
+ timeoutMs?: number;
195
+ env?: Record<string, string>;
196
+ }): Promise<RunResult>;
197
+ };
198
+ /** @group processes */
199
+ readonly processes: {
200
+ /** Start a program that runs on after the call (an app on the desktop, a server), the way shell.run can't: it ends
201
+ * everything its command started. Answers once it started; it and what it starts run until they exit or the
202
+ * computer ends. A string runs in sh -c, a list is the program and its arguments. */
203
+ start(command: string | string[], options?: {
204
+ cwd?: string;
205
+ env?: Record<string, string>;
206
+ }): Promise<{
207
+ pid: number;
208
+ }>;
209
+ };
210
+ /** @group files */
211
+ readonly files: {
212
+ /** A file's text (UTF-8), or with base64 its bytes. */
213
+ read(path: string, options?: {
214
+ encoding?: "utf8" | "base64";
215
+ }): Promise<string>;
216
+ write(path: string, data: string, options?: {
217
+ encoding?: "utf8" | "base64";
218
+ }): Promise<void>;
219
+ list(path: string): Promise<FileInfo[]>;
220
+ stat(path: string): Promise<FileInfo>;
221
+ };
222
+ }
223
+ /** computer_observe: observe an app's window (or, with no ui group, the screen). */
224
+ export interface ObserveArgs {
225
+ /** Default: the app in front. With no ui group, opened or brought in front first. */
226
+ app?: string;
227
+ /** Add the window's picture (always, with no ui group). */
228
+ image?: boolean;
229
+ /** Every element, not only named or actionable ones. */
230
+ full?: boolean;
231
+ }
232
+ /** computer_act: run steps on an app, and check a condition after them. */
233
+ export interface ActArgs {
234
+ /** Default: the state's app, else the app in front. With no ui group, opened or brought in front first. */
235
+ app?: string;
236
+ /** The state a step's point was read from. Default: the last observed. */
237
+ state?: string;
238
+ /** Run in order. Empty with an expect: only wait.
239
+ * @maxItems 100 */
240
+ steps: UiStep[];
241
+ expect?: UiExpect;
242
+ /** Allow moving the person's pointer and focus. */
243
+ foreground?: boolean;
244
+ /** Return the new outline. */
245
+ observe?: boolean;
246
+ }
247
+ /** computer_screenshot: a screenshot of the screen, or of a region of it. */
248
+ export interface ScreenshotArgs {
249
+ /** [x, y, w, h] in screen pixels. */
250
+ region?: Rect;
251
+ }
252
+ /** computer_script: run JavaScript against the `computer` object. */
253
+ export interface ScriptArgs {
254
+ /** An async function's body; `return` what you need. */
255
+ code: string;
256
+ /** For the run's timeline. */
257
+ title?: string;
258
+ /** Default 120000, at most 600000. */
259
+ timeoutMs?: number;
260
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,55 @@
1
+ import type { ComputerClient, HelloResult, UiStep } from "../protocol.js";
2
+ import type { ActResult, Card, Image } from "./api.js";
3
+ /** What a surface can be asked, by name: the members of Computer and the tools' calls. */
4
+ export type SurfaceOp = "observe" | "act" | "screenshot" | "input.act" | "apps.list" | "apps.open" | "shell.run" | "processes.start" | "files.read" | "files.write" | "files.list" | "files.stat";
5
+ export declare const SURFACE_OPS: readonly SurfaceOp[];
6
+ /** One call's answer: the value a script gets, the text a model reads, and the images that go with it. */
7
+ export interface SurfaceAnswer {
8
+ value: unknown;
9
+ text: string;
10
+ images: Image[];
11
+ }
12
+ /** A call the computer refused or failed: `kind` is the protocol's error kind (stale, unsupported, ...) or the
13
+ * connection's (gone, timeout). */
14
+ export declare class SurfaceError extends Error {
15
+ readonly kind: string;
16
+ constructor(kind: string, message: string);
17
+ }
18
+ export interface Surface {
19
+ readonly card: Card;
20
+ /** The ops this computer answers, from its groups. */
21
+ readonly ops: readonly SurfaceOp[];
22
+ call(op: string, args: unknown, options?: {
23
+ signal?: AbortSignal;
24
+ }): Promise<SurfaceAnswer>;
25
+ }
26
+ /** The most bytes files.read gathers into one answer. */
27
+ export declare const MAX_READ_BYTES: number;
28
+ /** The card of a hello. */
29
+ export declare function cardOf(hello: HelloResult): Card;
30
+ /** The ops a computer with these groups answers. */
31
+ export declare function opsOf(groups: readonly string[]): SurfaceOp[];
32
+ /** The name of a step: its first key ("press", "click", ...). */
33
+ export declare const stepName: (step: UiStep) => string;
34
+ /** An element as a step's line names it: its ref, its role, its name, and `[secure]` for a secure field. */
35
+ type Named = {
36
+ role: string;
37
+ name?: string;
38
+ secure: boolean;
39
+ };
40
+ /** A step as its line in an act's answer names it: its name, then the element it acted on as the outline names it
41
+ * (`press @e3 button "Save"`, `type into @e4 textbox "PIN" [secure]`), where that element was seen in an observation;
42
+ * `[secure]` is that element's own flag. A type with no element names none: where the focus is when it runs (which
43
+ * app, which field, after what the steps before it, a person, or the system did) is not known here, so no reader of
44
+ * its line can tell it went to an ordinary field, and none shows what was typed. */
45
+ export declare function stepWords(step: UiStep, named: (ref: string) => Named | undefined): string;
46
+ /** An act's answer as lines: one per step (named by `names`, stepWords), then the expect, then whether it changed and
47
+ * the new state, then the new observation's outline when there is one. */
48
+ export declare function actText(names: readonly string[], result: ActResult): string;
49
+ /** A chord's keys: "ctrl+shift+t" is ctrl, shift, t; a trailing "+" is the plus key ("ctrl++"). */
50
+ export declare const chordKeys: (chord: string) => string[];
51
+ /** The surface of one computer, over its connection. */
52
+ export declare function createSurface(client: ComputerClient, hello: HelloResult): Surface;
53
+ /** A value with its images' data left out: the structured half of an answer whose images travel beside it. */
54
+ export declare function withoutImageData(value: unknown): unknown;
55
+ export {};