@parcha/agentrun-computer 0.1.0-beta.35 → 0.1.0-beta.37
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.
- package/NOTICE +2 -0
- package/README.md +423 -323
- package/box/Dockerfile +3 -1
- package/box/agentrun-archil +59 -7
- package/box/build-agent37.mjs +177 -0
- package/box/build-daytona.py +20 -4
- package/dist/agent37.d.ts +165 -0
- package/dist/agent37.js +759 -0
- package/dist/attach.d.ts +146 -0
- package/dist/attach.js +469 -0
- package/dist/browser.d.ts +61 -10
- package/dist/browser.js +125 -3
- package/dist/browserbase.d.ts +46 -23
- package/dist/browserbase.js +162 -17
- package/dist/chrome.d.ts +3 -4
- package/dist/chrome.js +6 -11
- package/dist/client.d.ts +33 -1
- package/dist/client.js +53 -0
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/conformance/agent37.d.ts +96 -0
- package/dist/conformance/agent37.js +154 -0
- package/dist/conformance/cases/apps.d.ts +5 -0
- package/dist/conformance/cases/apps.js +160 -73
- package/dist/conformance/cases/health.js +14 -0
- package/dist/conformance/cases/index.js +2 -0
- package/dist/conformance/cases/provider.js +27 -1
- package/dist/conformance/cases/screen.d.ts +3 -0
- package/dist/conformance/cases/screen.js +18 -0
- package/dist/conformance/cases/settings.d.ts +29 -23
- package/dist/conformance/cases/settings.js +76 -58
- package/dist/conformance/cases/touch.js +19 -17
- package/dist/conformance/cases/ui.d.ts +2 -0
- package/dist/conformance/cases/ui.js +475 -0
- package/dist/conformance/cli.d.ts +9 -0
- package/dist/conformance/cli.js +28 -3
- package/dist/conformance/daytona.d.ts +4 -0
- package/dist/conformance/daytona.js +5 -0
- package/dist/conformance/e2b.d.ts +6 -0
- package/dist/conformance/e2b.js +9 -2
- package/dist/conformance/fixture.d.ts +1 -1
- package/dist/conformance/fixture.js +25 -1
- package/dist/conformance/modal.d.ts +17 -13
- package/dist/conformance/modal.js +18 -9
- package/dist/conformance/orgo.d.ts +3 -3
- package/dist/conformance/orgo.js +6 -8
- package/dist/conformance/phone-harness.d.ts +6 -2
- package/dist/conformance/phone-harness.js +21 -4
- package/dist/conformance/report.js +1 -1
- package/dist/conformance/runner.js +23 -4
- package/dist/conformance/sweep.d.ts +50 -0
- package/dist/conformance/sweep.js +187 -0
- package/dist/conformance/types.d.ts +11 -3
- package/dist/conformance/ui-fixture.d.ts +56 -0
- package/dist/conformance/ui-fixture.js +43 -0
- package/dist/create-requests.d.ts +51 -0
- package/dist/create-requests.js +121 -0
- package/dist/daytona.d.ts +15 -5
- package/dist/daytona.js +58 -38
- package/dist/descriptor.d.ts +29 -2
- package/dist/descriptor.js +13 -0
- package/dist/descriptors/agent37.d.ts +41 -0
- package/dist/descriptors/agent37.js +28 -0
- package/dist/descriptors/browserbase.d.ts +1 -0
- package/dist/descriptors/browserbase.js +2 -0
- package/dist/descriptors/daytona.d.ts +23 -2
- package/dist/descriptors/daytona.js +34 -2
- package/dist/descriptors/index.d.ts +66 -3
- package/dist/descriptors/index.js +5 -3
- package/dist/descriptors/kernel.d.ts +1 -0
- package/dist/descriptors/kernel.js +2 -0
- package/dist/descriptors/modal.d.ts +4 -0
- package/dist/descriptors/modal.js +11 -1
- package/dist/descriptors/orgo.d.ts +13 -1
- package/dist/descriptors/orgo.js +9 -3
- package/dist/descriptors/phone-harness.d.ts +6 -1
- package/dist/descriptors/phone-harness.js +5 -2
- package/dist/docker/egress.d.ts +4 -3
- package/dist/docker/egress.js +7 -6
- package/dist/docker.d.ts +7 -4
- package/dist/docker.js +278 -34
- package/dist/e2b.d.ts +9 -165
- package/dist/e2b.js +282 -1342
- package/dist/fake-ui-driver.d.ts +97 -0
- package/dist/fake-ui-driver.js +717 -0
- package/dist/host.d.ts +182 -0
- package/dist/host.js +1 -0
- package/dist/hosted/process.d.ts +67 -0
- package/dist/hosted/process.js +228 -0
- package/dist/hosted/provider.d.ts +146 -0
- package/dist/hosted/provider.js +1364 -0
- package/dist/hosted/scripts.d.ts +76 -0
- package/dist/{child.js → hosted/scripts.js} +93 -12
- package/dist/index.d.ts +11 -7
- package/dist/index.js +10 -7
- package/dist/janitor.d.ts +5 -4
- package/dist/janitor.js +1 -1
- package/dist/kernel.d.ts +17 -27
- package/dist/kernel.js +94 -18
- package/dist/kinds.d.ts +17 -5
- package/dist/kinds.js +20 -4
- package/dist/labels.d.ts +10 -2
- package/dist/labels.js +30 -7
- package/dist/local-chrome.d.ts +5 -5
- package/dist/local-chrome.js +10 -5
- package/dist/modal.d.ts +23 -181
- package/dist/modal.js +273 -1232
- package/dist/mount-archil.d.ts +25 -3
- package/dist/mount-archil.js +39 -8
- package/dist/orgo-channel.d.ts +3 -2
- package/dist/orgo-channel.js +5 -2
- package/dist/orgo-desktop.d.ts +23 -9
- package/dist/orgo-desktop.js +328 -66
- package/dist/orgo-names.d.ts +129 -3
- package/dist/orgo-names.js +211 -8
- package/dist/orgo-workspaces.d.ts +47 -0
- package/dist/orgo-workspaces.js +94 -0
- package/dist/orgo.d.ts +27 -10
- package/dist/orgo.js +411 -81
- package/dist/phone-harness.d.ts +31 -21
- package/dist/phone-harness.js +510 -681
- package/dist/png.d.ts +4 -0
- package/dist/png.js +27 -0
- package/dist/protocol.d.ts +338 -30
- package/dist/protocol.js +96 -3
- package/dist/provider.d.ts +97 -7
- package/dist/provider.js +24 -3
- package/dist/result.d.ts +1 -1
- package/dist/surface/api.d.ts +248 -0
- package/dist/surface/api.js +1 -0
- package/dist/surface/core.d.ts +42 -0
- package/dist/surface/core.js +393 -0
- package/dist/surface/index.d.ts +5 -0
- package/dist/surface/index.js +3 -0
- package/dist/surface/outline.d.ts +8 -0
- package/dist/surface/outline.js +50 -0
- package/dist/surface/script.d.ts +10 -0
- package/dist/surface/script.js +92 -0
- package/dist/ui-engine.d.ts +114 -0
- package/dist/ui-engine.js +798 -0
- package/package.json +17 -1
- package/dist/child.d.ts +0 -42
- package/dist/conformance/e2b-diagnose.d.ts +0 -16
- package/dist/conformance/e2b-diagnose.js +0 -61
- package/dist/conformance/e2b-sweep.d.ts +0 -18
- package/dist/conformance/e2b-sweep.js +0 -132
- package/dist/conformance/modal-sweep.d.ts +0 -22
- package/dist/conformance/modal-sweep.js +0 -213
package/dist/provider.d.ts
CHANGED
|
@@ -12,6 +12,11 @@ export type NetworkForm = "none" | "open" | "allow";
|
|
|
12
12
|
export interface ComputerOwner {
|
|
13
13
|
/** The agent's id: a non-empty string with no NUL byte (ownerProblem). */
|
|
14
14
|
agent: string;
|
|
15
|
+
/**
|
|
16
|
+
* The server the agent is on, where more than one server shares a vendor account: two servers may each have an agent
|
|
17
|
+
* of one id, and each owns its own computer. A non-empty string with no NUL byte. Absent: the agent's id alone.
|
|
18
|
+
*/
|
|
19
|
+
server?: string;
|
|
15
20
|
/** How long the computer may stay detached before the janitor deletes it. Absent: it stays until it is deleted. */
|
|
16
21
|
idleTtlMs?: number;
|
|
17
22
|
}
|
|
@@ -45,6 +50,11 @@ export interface ComputerSpec {
|
|
|
45
50
|
* refuses any other kind before a vendor call. An Archil token is never in a label, a read-back or an error.
|
|
46
51
|
*/
|
|
47
52
|
mount?: MountSpec;
|
|
53
|
+
/**
|
|
54
|
+
* A browser's own options, for a provider whose capabilities().browser declares what they ask; check() refuses, in
|
|
55
|
+
* words and before any vendor call, one it does not declare.
|
|
56
|
+
*/
|
|
57
|
+
browser?: BrowserSpec;
|
|
48
58
|
/**
|
|
49
59
|
* GPUs for the computer: a type the provider declares (capabilities().gpu.types, the vendor's own name, such as Modal's
|
|
50
60
|
* "A100-80GB" or Daytona's "H100") and how many, 1 up to capabilities().gpu.max. check() refuses one the provider does
|
|
@@ -80,6 +90,14 @@ export interface GpuCapability {
|
|
|
80
90
|
};
|
|
81
91
|
/** The mount kinds a GPU computer takes, where fewer than capabilities().mount: none yet proven on its GPU computers. */
|
|
82
92
|
mounts?: MountKind[];
|
|
93
|
+
/**
|
|
94
|
+
* Why a GPU computer takes none of the other mounts, in words naming no field: a fact of the vendor's runtime, or
|
|
95
|
+
* (yet) one not proven there. checkGpu's refusal of a mount gives it, and serve's refusal of the run's folder.
|
|
96
|
+
*/
|
|
97
|
+
unmounted?: {
|
|
98
|
+
why: string;
|
|
99
|
+
yet: boolean;
|
|
100
|
+
};
|
|
83
101
|
/**
|
|
84
102
|
* How init holds a GPU computer's programs off its network, where it is not the plain network namespace: on Modal's
|
|
85
103
|
* gVisor, "userns-netns", one made inside a user namespace, as root there may not make one (measured). The fence holds
|
|
@@ -87,6 +105,38 @@ export interface GpuCapability {
|
|
|
87
105
|
*/
|
|
88
106
|
fence?: NetworkFence;
|
|
89
107
|
}
|
|
108
|
+
/** A browser session's options beside the protocol's. A flag set false asks for nothing, so it is never refused. */
|
|
109
|
+
export interface BrowserSpec {
|
|
110
|
+
viewport?: {
|
|
111
|
+
width: number;
|
|
112
|
+
height: number;
|
|
113
|
+
};
|
|
114
|
+
/** A saved profile the session opens: the pointer profiles.create gave, and whether the session saves back to it. */
|
|
115
|
+
profile?: {
|
|
116
|
+
pointer: string;
|
|
117
|
+
save: boolean;
|
|
118
|
+
};
|
|
119
|
+
/** The vendor's anti-bot mode (Browserbase's Verified browser and its CAPTCHA solver). */
|
|
120
|
+
stealth?: boolean;
|
|
121
|
+
headless?: boolean;
|
|
122
|
+
}
|
|
123
|
+
/** What a browser provider's sessions offer beyond the protocol: each optional feature is there only when declared. */
|
|
124
|
+
export interface BrowserFeatures {
|
|
125
|
+
/** "wall-clock": the vendor ends a session lifetimeMs after create; "inactivity": that long after its last connection closes. */
|
|
126
|
+
timeout: "wall-clock" | "inactivity";
|
|
127
|
+
/** The shortest lifetimeMs a session takes (Kernel's shortest idle timeout); absent, any above 0. */
|
|
128
|
+
minLifetimeMs?: number;
|
|
129
|
+
/** settleMs: how long after a saving session ends the vendor may still be writing the profile back. */
|
|
130
|
+
profiles?: {
|
|
131
|
+
settleMs: number;
|
|
132
|
+
};
|
|
133
|
+
stealth?: true;
|
|
134
|
+
headless?: true;
|
|
135
|
+
/** path: the directory a driver points Browser.setDownloadBehavior at, so the vendor keeps what is saved there. */
|
|
136
|
+
downloads?: {
|
|
137
|
+
path: string;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
90
140
|
/** One kind of allowlist entry a provider takes: how many a list may hold, and the ports an entry opens. */
|
|
91
141
|
export interface AllowRule {
|
|
92
142
|
max: number;
|
|
@@ -101,9 +151,10 @@ export interface AllowCapability {
|
|
|
101
151
|
mixed: boolean;
|
|
102
152
|
}
|
|
103
153
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
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).
|
|
107
158
|
*/
|
|
108
159
|
export type DaemonMode = "pid1" | "child" | "none";
|
|
109
160
|
export interface ComputerCapabilities {
|
|
@@ -166,6 +217,8 @@ export interface ComputerCapabilities {
|
|
|
166
217
|
vendorAgentPorts?: number[];
|
|
167
218
|
/** The GPUs spec.gpu may ask for. Absent: none, and check() refuses any spec.gpu. */
|
|
168
219
|
gpu?: GpuCapability;
|
|
220
|
+
/** With kind browser: what its sessions offer beyond the protocol, which spec.browser asks for. */
|
|
221
|
+
browser?: BrowserFeatures;
|
|
169
222
|
}
|
|
170
223
|
/** The os and daemon modes each kind may have; no other pair is valid. */
|
|
171
224
|
export declare const KIND_SHAPES: Readonly<Record<ComputerKind, {
|
|
@@ -278,6 +331,24 @@ export interface ComputerInfo {
|
|
|
278
331
|
export interface CallContext {
|
|
279
332
|
signal?: AbortSignal;
|
|
280
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;
|
|
281
352
|
/** attach's context: with a claim, an agent's computer is brought back and taken by that run, under that epoch. */
|
|
282
353
|
export interface AttachContext extends CallContext {
|
|
283
354
|
claim?: ComputerClaim;
|
|
@@ -287,6 +358,15 @@ export interface AttachContext extends CallContext {
|
|
|
287
358
|
* computer stops with its state kept, still the agent's (a provider that declares persistence; refused otherwise).
|
|
288
359
|
*/
|
|
289
360
|
export type ReleaseHow = "stop" | "delete" | "detach";
|
|
361
|
+
/**
|
|
362
|
+
* release's context: with a claim (a provider that declares persistence), a delete of an agent's computer is that claim's
|
|
363
|
+
* alone: done only while the computer still carries exactly the claim's run and epoch and no attach or detach holds it,
|
|
364
|
+
* else refused in words (fenced, or busy) with the computer as it was. So a claim that made the computer and lost it
|
|
365
|
+
* deletes it only where no later claim has taken it. A provider with no persistence has no agent's computer to fence.
|
|
366
|
+
*/
|
|
367
|
+
export interface ReleaseContext extends CallContext {
|
|
368
|
+
claim?: ComputerClaim;
|
|
369
|
+
}
|
|
290
370
|
/** A live connection to a computer's daemon. */
|
|
291
371
|
export interface ComputerConnection {
|
|
292
372
|
client: ComputerClient;
|
|
@@ -305,9 +385,11 @@ export interface ComputerProvider {
|
|
|
305
385
|
readonly version: string;
|
|
306
386
|
capabilities(): ComputerCapabilities;
|
|
307
387
|
check(spec: ComputerSpec): Refusal[];
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
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>>;
|
|
311
393
|
/**
|
|
312
394
|
* Finds one computer this provider made, by its id or by labels, with the spec read back from it; none or several is
|
|
313
395
|
* an error in words. With context.claim (a provider that declares persistence): the agent's computer is brought back
|
|
@@ -329,8 +411,9 @@ export interface ComputerProvider {
|
|
|
329
411
|
/**
|
|
330
412
|
* Idempotent: a computer already gone is ok. A "stop" capabilities().release does not declare is refused in words. A
|
|
331
413
|
* "detach" is refused in words, the computer as it was, on a provider with no persistence and on a run's computer.
|
|
414
|
+
* context.claim: a delete under that claim alone (ReleaseContext).
|
|
332
415
|
*/
|
|
333
|
-
release(ref: ComputerRef, how: ReleaseHow): Promise<Result<void>>;
|
|
416
|
+
release(ref: ComputerRef, how: ReleaseHow, context?: ReleaseContext): Promise<Result<void>>;
|
|
334
417
|
/**
|
|
335
418
|
* Sets the deadline to now + ttlMs: never earlier than the current deadline, never past created + maxLifetimeMs. A
|
|
336
419
|
* ttlMs that would move it earlier, or past that cap, is refused in words with the deadline unchanged: an extend
|
|
@@ -374,6 +457,13 @@ export interface ComputerProvider {
|
|
|
374
457
|
testConnection?(context?: CallContext): Promise<Result<{
|
|
375
458
|
detail: string;
|
|
376
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[]>>;
|
|
377
467
|
/**
|
|
378
468
|
* The image its computers start from, made ready on its engine before the first create: built from its recipe, or
|
|
379
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"] },
|
|
@@ -47,12 +49,16 @@ export function runLifetimeMs(spec) {
|
|
|
47
49
|
/** Why owner is not an agent's ownership, in words, or undefined when it is one. */
|
|
48
50
|
export function ownerProblem(owner) {
|
|
49
51
|
if (typeof owner !== "object" || owner === null || Array.isArray(owner))
|
|
50
|
-
return "owner is { agent, idleTtlMs? }";
|
|
51
|
-
const { agent, idleTtlMs } = owner;
|
|
52
|
+
return "owner is { agent, server?, idleTtlMs? }";
|
|
53
|
+
const { agent, server, idleTtlMs } = owner;
|
|
52
54
|
if (typeof agent !== "string" || agent === "")
|
|
53
55
|
return "owner.agent must be the agent's id, a non-empty string";
|
|
54
56
|
if (agent.includes("\0"))
|
|
55
57
|
return "owner.agent cannot hold a NUL byte: no provider takes one in a label";
|
|
58
|
+
if (server !== undefined && (typeof server !== "string" || server === ""))
|
|
59
|
+
return "owner.server, when given, is the server's id, a non-empty string";
|
|
60
|
+
if (typeof server === "string" && server.includes("\0"))
|
|
61
|
+
return "owner.server cannot hold a NUL byte: no provider takes one in a label";
|
|
56
62
|
if (idleTtlMs !== undefined && !(Number.isSafeInteger(idleTtlMs) && idleTtlMs > 0))
|
|
57
63
|
return `owner.idleTtlMs is a whole number of milliseconds above 0, not ${JSON.stringify(idleTtlMs)}`;
|
|
58
64
|
return undefined;
|
|
@@ -101,7 +107,22 @@ export function checkGpu(gpu, { gpu: offered }, mount) {
|
|
|
101
107
|
// A mount that is not an object with a kind (null among them) is checkMount's refusal; nothing is read from it here.
|
|
102
108
|
const kind = typeof mount === "object" && mount !== null ? mount.kind : undefined;
|
|
103
109
|
if (kind !== undefined && offered.mounts !== undefined && !offered.mounts.includes(kind)) {
|
|
104
|
-
|
|
110
|
+
const why = offered.unmounted?.why ?? "it is not proven on this provider's GPU computers yet";
|
|
111
|
+
return refuse(`a GPU computer here takes no ${String(kind)} mount: ${why}; ask for a GPU computer without a mount, or a mount without a GPU`);
|
|
105
112
|
}
|
|
106
113
|
return [];
|
|
107
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
|
+
}
|
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;
|
|
@@ -0,0 +1,248 @@
|
|
|
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 files */
|
|
199
|
+
readonly files: {
|
|
200
|
+
/** A file's text (UTF-8), or with base64 its bytes. */
|
|
201
|
+
read(path: string, options?: {
|
|
202
|
+
encoding?: "utf8" | "base64";
|
|
203
|
+
}): Promise<string>;
|
|
204
|
+
write(path: string, data: string, options?: {
|
|
205
|
+
encoding?: "utf8" | "base64";
|
|
206
|
+
}): Promise<void>;
|
|
207
|
+
list(path: string): Promise<FileInfo[]>;
|
|
208
|
+
stat(path: string): Promise<FileInfo>;
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
/** computer_observe: observe an app's window (or, with no ui group, the screen). */
|
|
212
|
+
export interface ObserveArgs {
|
|
213
|
+
/** Default: the app in front. */
|
|
214
|
+
app?: string;
|
|
215
|
+
/** Add the window's picture (always, with no ui group). */
|
|
216
|
+
image?: boolean;
|
|
217
|
+
/** Every element, not only named or actionable ones. */
|
|
218
|
+
full?: boolean;
|
|
219
|
+
}
|
|
220
|
+
/** computer_act: run steps on an app, and check a condition after them. */
|
|
221
|
+
export interface ActArgs {
|
|
222
|
+
/** Default: the state's app, else the app in front. */
|
|
223
|
+
app?: string;
|
|
224
|
+
/** The state a step's point was read from. Default: the last observed. */
|
|
225
|
+
state?: string;
|
|
226
|
+
/** Run in order. Empty with an expect: only wait.
|
|
227
|
+
* @maxItems 100 */
|
|
228
|
+
steps: UiStep[];
|
|
229
|
+
expect?: UiExpect;
|
|
230
|
+
/** Allow moving the person's pointer and focus. */
|
|
231
|
+
foreground?: boolean;
|
|
232
|
+
/** Return the new outline. */
|
|
233
|
+
observe?: boolean;
|
|
234
|
+
}
|
|
235
|
+
/** computer_screenshot: a screenshot of the screen, or of a region of it. */
|
|
236
|
+
export interface ScreenshotArgs {
|
|
237
|
+
/** [x, y, w, h] in screen pixels. */
|
|
238
|
+
region?: Rect;
|
|
239
|
+
}
|
|
240
|
+
/** computer_script: run JavaScript against the `computer` object. */
|
|
241
|
+
export interface ScriptArgs {
|
|
242
|
+
/** An async function's body; `return` what you need. */
|
|
243
|
+
code: string;
|
|
244
|
+
/** For the run's timeline. */
|
|
245
|
+
title?: string;
|
|
246
|
+
/** Default 120000, at most 600000. */
|
|
247
|
+
timeoutMs?: number;
|
|
248
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
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" | "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 act's answer as lines: one per step (named by `names`), then the expect, then whether it changed and the new
|
|
35
|
+
* state, then the new observation's outline when there is one. */
|
|
36
|
+
export declare function actText(names: readonly string[], result: ActResult): string;
|
|
37
|
+
/** A chord's keys: "ctrl+shift+t" is ctrl, shift, t; a trailing "+" is the plus key ("ctrl++"). */
|
|
38
|
+
export declare const chordKeys: (chord: string) => string[];
|
|
39
|
+
/** The surface of one computer, over its connection. */
|
|
40
|
+
export declare function createSurface(client: ComputerClient, hello: HelloResult): Surface;
|
|
41
|
+
/** A value with its images' data left out: the structured half of an answer whose images travel beside it. */
|
|
42
|
+
export declare function withoutImageData(value: unknown): unknown;
|