@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.
- package/LICENSE +202 -0
- package/NOTICE +8 -0
- package/README.md +2411 -2
- package/box/Dockerfile +69 -0
- package/box/agentrun-archil +168 -0
- package/box/build-daytona.py +26 -0
- package/box/build-e2b.mjs +32 -0
- package/box/build-modal.py +17 -0
- package/dist/actions.d.ts +18 -0
- package/dist/actions.js +139 -0
- package/dist/browser.d.ts +151 -0
- package/dist/browser.js +305 -0
- package/dist/browserbase.d.ts +139 -0
- package/dist/browserbase.js +408 -0
- package/dist/child.d.ts +40 -0
- package/dist/child.js +127 -0
- package/dist/client.d.ts +22 -0
- package/dist/client.js +136 -0
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/conformance/archil.d.ts +68 -0
- package/dist/conformance/archil.js +152 -0
- package/dist/conformance/browserbase.d.ts +35 -0
- package/dist/conformance/browserbase.js +45 -0
- package/dist/conformance/cases/apps.d.ts +2 -0
- package/dist/conformance/cases/apps.js +155 -0
- package/dist/conformance/cases/browser.d.ts +4 -0
- package/dist/conformance/cases/browser.js +105 -0
- package/dist/conformance/cases/drift.d.ts +2 -0
- package/dist/conformance/cases/drift.js +64 -0
- package/dist/conformance/cases/exec.d.ts +2 -0
- package/dist/conformance/cases/exec.js +125 -0
- package/dist/conformance/cases/files.d.ts +2 -0
- package/dist/conformance/cases/files.js +294 -0
- package/dist/conformance/cases/health.d.ts +2 -0
- package/dist/conformance/cases/health.js +71 -0
- package/dist/conformance/cases/index.d.ts +9 -0
- package/dist/conformance/cases/index.js +37 -0
- package/dist/conformance/cases/input.d.ts +12 -0
- package/dist/conformance/cases/input.js +109 -0
- package/dist/conformance/cases/isolation.d.ts +21 -0
- package/dist/conformance/cases/isolation.js +98 -0
- package/dist/conformance/cases/lifetime.d.ts +2 -0
- package/dist/conformance/cases/lifetime.js +64 -0
- package/dist/conformance/cases/mount.d.ts +2 -0
- package/dist/conformance/cases/mount.js +252 -0
- package/dist/conformance/cases/process.d.ts +2 -0
- package/dist/conformance/cases/process.js +240 -0
- package/dist/conformance/cases/provider.d.ts +2 -0
- package/dist/conformance/cases/provider.js +302 -0
- package/dist/conformance/cases/screen.d.ts +9 -0
- package/dist/conformance/cases/screen.js +230 -0
- package/dist/conformance/cases/settings.d.ts +57 -0
- package/dist/conformance/cases/settings.js +142 -0
- package/dist/conformance/cases/touch.d.ts +2 -0
- package/dist/conformance/cases/touch.js +117 -0
- package/dist/conformance/cases/util.d.ts +7 -0
- package/dist/conformance/cases/util.js +8 -0
- package/dist/conformance/cdp.d.ts +13 -0
- package/dist/conformance/cdp.js +88 -0
- package/dist/conformance/cli.d.ts +29 -0
- package/dist/conformance/cli.js +231 -0
- package/dist/conformance/daytona-sweep.d.ts +18 -0
- package/dist/conformance/daytona-sweep.js +126 -0
- package/dist/conformance/daytona.d.ts +83 -0
- package/dist/conformance/daytona.js +107 -0
- package/dist/conformance/docker.d.ts +38 -0
- package/dist/conformance/docker.js +70 -0
- package/dist/conformance/drift-daemon.d.ts +8 -0
- package/dist/conformance/drift-daemon.js +41 -0
- package/dist/conformance/e2b-diagnose.d.ts +16 -0
- package/dist/conformance/e2b-diagnose.js +61 -0
- package/dist/conformance/e2b-sweep.d.ts +18 -0
- package/dist/conformance/e2b-sweep.js +132 -0
- package/dist/conformance/e2b.d.ts +74 -0
- package/dist/conformance/e2b.js +111 -0
- package/dist/conformance/fixture.d.ts +65 -0
- package/dist/conformance/fixture.js +98 -0
- package/dist/conformance/index.d.ts +8 -0
- package/dist/conformance/index.js +8 -0
- package/dist/conformance/kernel.d.ts +31 -0
- package/dist/conformance/kernel.js +40 -0
- package/dist/conformance/kind.d.ts +23 -0
- package/dist/conformance/kind.js +58 -0
- package/dist/conformance/modal-sweep.d.ts +22 -0
- package/dist/conformance/modal-sweep.js +213 -0
- package/dist/conformance/modal.d.ts +69 -0
- package/dist/conformance/modal.js +76 -0
- package/dist/conformance/orgo.d.ts +41 -0
- package/dist/conformance/orgo.js +69 -0
- package/dist/conformance/phone-harness.d.ts +61 -0
- package/dist/conformance/phone-harness.js +241 -0
- package/dist/conformance/png.d.ts +16 -0
- package/dist/conformance/png.js +132 -0
- package/dist/conformance/report.d.ts +2 -0
- package/dist/conformance/report.js +86 -0
- package/dist/conformance/runner.d.ts +11 -0
- package/dist/conformance/runner.js +585 -0
- package/dist/conformance/tar.d.ts +13 -0
- package/dist/conformance/tar.js +105 -0
- package/dist/conformance/types.d.ts +257 -0
- package/dist/conformance/types.js +24 -0
- package/dist/daemon-copy.d.ts +40 -0
- package/dist/daemon-copy.js +259 -0
- package/dist/daytona.d.ts +180 -0
- package/dist/daytona.js +1498 -0
- package/dist/desktop.d.ts +24 -0
- package/dist/desktop.js +68 -0
- package/dist/docker/egress-main.d.ts +1 -0
- package/dist/docker/egress-main.js +68 -0
- package/dist/docker/egress-proxy.d.ts +53 -0
- package/dist/docker/egress-proxy.js +450 -0
- package/dist/docker/egress-table.d.ts +39 -0
- package/dist/docker/egress-table.js +197 -0
- package/dist/docker/egress.d.ts +109 -0
- package/dist/docker/egress.js +318 -0
- package/dist/docker/image.d.ts +49 -0
- package/dist/docker/image.js +302 -0
- package/dist/docker/stage.d.ts +21 -0
- package/dist/docker/stage.js +290 -0
- package/dist/docker/volume.d.ts +24 -0
- package/dist/docker/volume.js +67 -0
- package/dist/docker.d.ts +156 -0
- package/dist/docker.js +1277 -0
- package/dist/drift.d.ts +200 -0
- package/dist/drift.js +416 -0
- package/dist/e2b.d.ts +337 -0
- package/dist/e2b.js +1516 -0
- package/dist/entry.d.ts +2 -0
- package/dist/entry.js +24 -0
- package/dist/files.d.ts +50 -0
- package/dist/files.js +208 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +26 -0
- package/dist/isolation.d.ts +29 -0
- package/dist/isolation.js +71 -0
- package/dist/janitor.d.ts +50 -0
- package/dist/janitor.js +135 -0
- package/dist/kernel.d.ts +113 -0
- package/dist/kernel.js +358 -0
- package/dist/kinds.d.ts +79 -0
- package/dist/kinds.js +133 -0
- package/dist/labels.d.ts +23 -0
- package/dist/labels.js +50 -0
- package/dist/modal.d.ts +302 -0
- package/dist/modal.js +1374 -0
- package/dist/mount-archil.d.ts +164 -0
- package/dist/mount-archil.js +471 -0
- package/dist/mount.d.ts +57 -0
- package/dist/mount.js +104 -0
- package/dist/orgo-channel.d.ts +96 -0
- package/dist/orgo-channel.js +391 -0
- package/dist/orgo.d.ts +139 -0
- package/dist/orgo.js +1006 -0
- package/dist/phone-harness.d.ts +185 -0
- package/dist/phone-harness.js +1420 -0
- package/dist/processes.d.ts +24 -0
- package/dist/processes.js +40 -0
- package/dist/protocol.d.ts +729 -0
- package/dist/protocol.js +54 -0
- package/dist/provider.d.ts +245 -0
- package/dist/provider.js +37 -0
- package/dist/providers.d.ts +68 -0
- package/dist/providers.js +25 -0
- package/dist/result.d.ts +15 -0
- package/dist/result.js +2 -0
- package/dist/screen-watch.d.ts +150 -0
- package/dist/screen-watch.js +490 -0
- package/dist/test-connection.d.ts +17 -0
- package/dist/test-connection.js +26 -0
- package/dist/wait.d.ts +23 -0
- package/dist/wait.js +65 -0
- package/package.json +62 -4
package/dist/protocol.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** The longest line, in bytes without its newline, either side reads or writes. */
|
|
2
|
+
export const MAX_LINE_BYTES = 1024 * 1024;
|
|
3
|
+
/** The most bytes exec.run keeps of each stream: two full streams, in base64, fit one reply line. */
|
|
4
|
+
export const MAX_OUTPUT_BYTES = 360 * 1024;
|
|
5
|
+
/** The notification that cancels a request by id (as in LSP). */
|
|
6
|
+
export const CANCEL_METHOD = "$/cancelRequest";
|
|
7
|
+
/** The most bytes one files.read or tar.pull.read returns: in base64, it fits a line. */
|
|
8
|
+
export const MAX_CHUNK_BYTES = 512 * 1024;
|
|
9
|
+
/** The deepest files.list walks, and the most entries one reply holds. */
|
|
10
|
+
export const MAX_LIST_DEPTH = 16;
|
|
11
|
+
export const MAX_LIST_ENTRIES = 1000;
|
|
12
|
+
/** How much of each stream a process keeps: the last 8 MiB, read by byte offset. */
|
|
13
|
+
export const PROCESS_RING_BYTES = 8 * 1024 * 1024;
|
|
14
|
+
/** How much of a process's output its log file keeps: the first 16 MiB. */
|
|
15
|
+
export const PROCESS_LOG_BYTES = 16 * 1024 * 1024;
|
|
16
|
+
/** How many processes a daemon holds, running or ended; the oldest ended ones are dropped first. */
|
|
17
|
+
export const MAX_PROCESSES = 256;
|
|
18
|
+
/**
|
|
19
|
+
* How much output a daemon's rings hold together. Past it, the rings of the processes that ended first are let go (a
|
|
20
|
+
* read then reports their bytes as dropped); a running process's ring is never let go.
|
|
21
|
+
*/
|
|
22
|
+
export const PROCESS_RETAINED_BYTES = 256 * 1024 * 1024;
|
|
23
|
+
/** The longest a process.read waits for new bytes. */
|
|
24
|
+
export const MAX_READ_WAIT_MS = 30_000;
|
|
25
|
+
/** Every group, in the order the protocol lists them. */
|
|
26
|
+
export const GROUPS = ["exec", "files", "processes", "screen", "input.pointer", "input.keys", "input.touch", "apps", "apps.install", "apps.ui_tree", "cdp", "stream", "downloads"];
|
|
27
|
+
/** The groups a provider answers itself, which a computerd hello never lists. */
|
|
28
|
+
export const PROVIDER_GROUPS = ["cdp", "stream", "downloads"];
|
|
29
|
+
/** The most actions one input.actions batch holds. */
|
|
30
|
+
export const MAX_ACTIONS = 100;
|
|
31
|
+
/**
|
|
32
|
+
* The most time one batch asks for, summed over every action that names a duration: wait, hold, long_press, swipe and
|
|
33
|
+
* pinch (Anthropic's 300 s cap).
|
|
34
|
+
*/
|
|
35
|
+
export const MAX_BATCH_WAIT_MS = 300_000;
|
|
36
|
+
/** The most times one key action presses its keys. */
|
|
37
|
+
export const MAX_KEY_REPEAT = 100;
|
|
38
|
+
/** The one canonical key table. The daemon's Go table (daemon/internal/keys) mirrors it, and a Go test keeps them equal. */
|
|
39
|
+
export const KEYS = [
|
|
40
|
+
"enter", "tab", "space", "backspace", "delete", "escape", "insert",
|
|
41
|
+
"up", "down", "left", "right", "home", "end", "pageup", "pagedown",
|
|
42
|
+
"f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", "f11", "f12",
|
|
43
|
+
"shift", "ctrl", "alt", "super", "capslock",
|
|
44
|
+
];
|
|
45
|
+
/** The most nodes apps.ui_tree returns. */
|
|
46
|
+
export const MAX_UI_NODES = 5000;
|
|
47
|
+
export const JSONRPC_CODES = {
|
|
48
|
+
parse: -32700,
|
|
49
|
+
invalidRequest: -32600,
|
|
50
|
+
methodNotFound: -32601,
|
|
51
|
+
invalidParams: -32602,
|
|
52
|
+
server: -32000,
|
|
53
|
+
requestCancelled: -32800,
|
|
54
|
+
};
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import type { MountKind, MountReadBack, MountSpec } from "./mount.js";
|
|
2
|
+
import type { ComputerClient, ComputerKind, ComputerOs, Group, HelloResult } from "./protocol.js";
|
|
3
|
+
import type { Result } from "./result.js";
|
|
4
|
+
import type { ScreenWatch, ScreenWatchHandlers, WatchOptions } from "./screen-watch.js";
|
|
5
|
+
export type NetworkSpec = "none" | "open" | {
|
|
6
|
+
allow: string[];
|
|
7
|
+
};
|
|
8
|
+
export interface ComputerSpec {
|
|
9
|
+
image: string;
|
|
10
|
+
/** Required: a computer with no deadline is refused. */
|
|
11
|
+
lifetimeMs: number;
|
|
12
|
+
network: NetworkSpec;
|
|
13
|
+
cpus?: number;
|
|
14
|
+
memoryMb?: number;
|
|
15
|
+
pids?: number;
|
|
16
|
+
labels?: Record<string, string>;
|
|
17
|
+
workdir?: string;
|
|
18
|
+
/** uid or uid:gid, in numbers. Unset, the provider's non-root default; root ("0") only when asked here. */
|
|
19
|
+
user?: string;
|
|
20
|
+
/**
|
|
21
|
+
* The run's folder, mounted read-write at /workspace (WORKSPACE), of a kind capabilities().mount declares; check()
|
|
22
|
+
* refuses any other kind before a vendor call. An Archil token is never in a label, a read-back or an error.
|
|
23
|
+
*/
|
|
24
|
+
mount?: MountSpec;
|
|
25
|
+
}
|
|
26
|
+
/** One kind of allowlist entry a provider takes: how many a list may hold, and the ports an entry opens. */
|
|
27
|
+
export interface AllowRule {
|
|
28
|
+
max: number;
|
|
29
|
+
/** The ports an entry opens: these, or "any". */
|
|
30
|
+
ports: number[] | "any";
|
|
31
|
+
}
|
|
32
|
+
/** What a network allowlist may hold, for a provider that declares network "allow". */
|
|
33
|
+
export interface AllowCapability {
|
|
34
|
+
domains?: AllowRule;
|
|
35
|
+
cidrs?: AllowRule;
|
|
36
|
+
/** Whether one allowlist may hold domains and CIDRs together. */
|
|
37
|
+
mixed: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Who answers a computer's methods. pid1: computerd init is the computer's main process, so its exit ends the computer.
|
|
41
|
+
* child: the vendor's own agent is the main process and starts init at boot; init's exit does not end the computer.
|
|
42
|
+
* none: no computerd runs; the provider answers the methods itself, from our server (adb, the vendor's API).
|
|
43
|
+
*/
|
|
44
|
+
export type DaemonMode = "pid1" | "child" | "none";
|
|
45
|
+
export interface ComputerCapabilities {
|
|
46
|
+
/** What the computer is: the shape its tools take. With daemon, it sets which groups are Core. */
|
|
47
|
+
kind: ComputerKind;
|
|
48
|
+
/** Who ends a computer at its deadline: the vendor, or our janitor by label. */
|
|
49
|
+
lifetime: "vendor" | "janitor";
|
|
50
|
+
network: Array<"none" | "open" | "allow">;
|
|
51
|
+
/** With network "allow": what an allowlist may hold and which ports it opens. */
|
|
52
|
+
allow?: AllowCapability;
|
|
53
|
+
/**
|
|
54
|
+
* Whether network() reads the policy back from outside the computer, from the vendor's own report of it. false: the
|
|
55
|
+
* vendor has no read-back, so only a probe from inside the computer stands for one, and an allowlist counts only
|
|
56
|
+
* once the live bypass cases pass (ruling 9).
|
|
57
|
+
*/
|
|
58
|
+
networkReadBack?: boolean;
|
|
59
|
+
isolation: "container" | "gvisor" | "microvm" | "vm" | "machine";
|
|
60
|
+
os: ComputerOs;
|
|
61
|
+
/**
|
|
62
|
+
* With release "stop": true when a stop ends in deletion (Daytona with autoDeleteMinutes 0), so release(ref, "stop")
|
|
63
|
+
* leaves no computer, listed or attachable. Absent or false: a stopped computer is kept, listed stopped, until deleted.
|
|
64
|
+
*/
|
|
65
|
+
stopDeletes?: boolean;
|
|
66
|
+
daemon: DaemonMode;
|
|
67
|
+
/** What each computer offers, as hello repeats it. */
|
|
68
|
+
groups: Group[];
|
|
69
|
+
/** The longest lifetime this provider instance gives a computer: the vendor's hard cap. check() refuses past it. */
|
|
70
|
+
maxLifetimeMs: number;
|
|
71
|
+
/** What spec.user may ask for instead of the non-root default: root ("0"), another uid. Absent: neither. */
|
|
72
|
+
user?: Array<"root" | "uid">;
|
|
73
|
+
/**
|
|
74
|
+
* How release may end a computer. "stop" keeps it, listed as stopped, until it is deleted; a provider that does not
|
|
75
|
+
* declare it refuses release(ref, "stop") in words and leaves the computer as it was.
|
|
76
|
+
*/
|
|
77
|
+
release: Array<"stop" | "delete">;
|
|
78
|
+
/** The kinds of spec.mount this provider takes: bind (a host folder), archil (a folder of an Archil disk). Absent: none. */
|
|
79
|
+
mount?: MountKind[];
|
|
80
|
+
/**
|
|
81
|
+
* The TCP ports the vendor's own agent listens on inside the computer (Daytona's toolbox 2280, E2B's envd 49983), each
|
|
82
|
+
* the provider's own fact: an agent that runs commands as root or with sudo for whoever reaches it. The computer's
|
|
83
|
+
* programs must reach none of them on any address (computerd init --own-network), which isolation.vendor-agent checks
|
|
84
|
+
* on both loopbacks. An empty list: a vendor with no known listener inside (Modal), checked on the interfaces alone.
|
|
85
|
+
* Absent: no vendor's agent runs beside the programs (Docker). A child daemon must declare it.
|
|
86
|
+
*/
|
|
87
|
+
vendorAgentPorts?: number[];
|
|
88
|
+
}
|
|
89
|
+
/** The os and daemon modes each kind may have; no other pair is valid. */
|
|
90
|
+
export declare const KIND_SHAPES: Readonly<Record<ComputerKind, {
|
|
91
|
+
os: readonly ComputerOs[];
|
|
92
|
+
daemon: readonly DaemonMode[];
|
|
93
|
+
}>>;
|
|
94
|
+
/** Why kind, os and daemon are not a valid pair, in words; none when they are. */
|
|
95
|
+
export declare function kindRefusals({ kind, os, daemon }: Pick<ComputerCapabilities, "kind" | "os" | "daemon">): Refusal[];
|
|
96
|
+
/**
|
|
97
|
+
* The one lifetime rule every provider's check() shares, with no vendor call: lifetimeMs is a whole number of
|
|
98
|
+
* milliseconds above 0, and at most capabilities().maxLifetimeMs.
|
|
99
|
+
*/
|
|
100
|
+
export declare function checkLifetime(lifetimeMs: unknown, { lifetime, maxLifetimeMs }: Pick<ComputerCapabilities, "lifetime" | "maxLifetimeMs">): Refusal[];
|
|
101
|
+
/** Why a spec is refused, in words, before any vendor call. */
|
|
102
|
+
export interface Refusal {
|
|
103
|
+
field: string;
|
|
104
|
+
message: string;
|
|
105
|
+
}
|
|
106
|
+
export interface ComputerRef {
|
|
107
|
+
id: string;
|
|
108
|
+
name: string;
|
|
109
|
+
}
|
|
110
|
+
/** A computer's network as read back from the computer itself. `other` is a network the provider never makes, in words. */
|
|
111
|
+
export type NetworkPolicy = NetworkSpec | {
|
|
112
|
+
other: string;
|
|
113
|
+
};
|
|
114
|
+
/** The spec a computer runs with, read back from the computer itself, not from what was asked. */
|
|
115
|
+
export interface ReadBackSpec {
|
|
116
|
+
/** The image as create was asked for it, read back from the computer (Docker's config, Daytona's label). */
|
|
117
|
+
image: string;
|
|
118
|
+
/** What the vendor resolved the image to, by its own name, when it reports one (a Daytona snapshot). */
|
|
119
|
+
snapshot?: string;
|
|
120
|
+
/** uid:gid in numbers: "0:0" is root. */
|
|
121
|
+
user: string;
|
|
122
|
+
network: NetworkPolicy;
|
|
123
|
+
cpus?: number;
|
|
124
|
+
memoryMb?: number;
|
|
125
|
+
pids?: number;
|
|
126
|
+
workdir?: string;
|
|
127
|
+
/** When the computer ends; absent when the provider cannot read it. */
|
|
128
|
+
deadline?: Date;
|
|
129
|
+
/** What the computer says it is, from its hello; absent when it could not be asked (a stopped computer). */
|
|
130
|
+
kind?: ComputerKind;
|
|
131
|
+
/** What is mounted at /workspace, never a token; absent when nothing is. */
|
|
132
|
+
mount?: MountReadBack;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* What a read-back recorded that does not refuse the computer, in words, one line each: under network none, the probe
|
|
136
|
+
* targets that accepted a connection and sent nothing back ("network: none; accepted with no answer (no bytes came
|
|
137
|
+
* back): 1.1.1.1:443, ..."). Recorded, never refused and never hidden. Absent when there is nothing to record.
|
|
138
|
+
*/
|
|
139
|
+
export type ReadBackNotes = string[];
|
|
140
|
+
/** What create returns: the computer's ref, and what its read-back recorded that does not refuse it. */
|
|
141
|
+
export interface CreatedComputer extends ComputerRef {
|
|
142
|
+
notes?: ReadBackNotes;
|
|
143
|
+
}
|
|
144
|
+
/** A computer attach found: its ref, and the spec read back from it, so a caller sees what it attached to (root, open). */
|
|
145
|
+
export interface AttachedComputer extends ComputerRef {
|
|
146
|
+
spec: ReadBackSpec;
|
|
147
|
+
/** What attach's read-back recorded that does not refuse the computer (see ReadBackNotes). */
|
|
148
|
+
notes?: ReadBackNotes;
|
|
149
|
+
}
|
|
150
|
+
/** One computer as list() reads it back. */
|
|
151
|
+
export interface ComputerInfo {
|
|
152
|
+
ref: ComputerRef;
|
|
153
|
+
labels: Record<string, string>;
|
|
154
|
+
/** undefined when the deadline label is missing or unreadable: the janitor deletes such a computer. */
|
|
155
|
+
deadline: Date | undefined;
|
|
156
|
+
state: "running" | "stopped";
|
|
157
|
+
network: NetworkPolicy;
|
|
158
|
+
/** What is mounted at /workspace, read back, never a token; absent when nothing is. */
|
|
159
|
+
mount?: MountReadBack;
|
|
160
|
+
}
|
|
161
|
+
export interface CallContext {
|
|
162
|
+
signal?: AbortSignal;
|
|
163
|
+
}
|
|
164
|
+
/** A live connection to a computer's daemon. */
|
|
165
|
+
export interface ComputerConnection {
|
|
166
|
+
client: ComputerClient;
|
|
167
|
+
hello: HelloResult;
|
|
168
|
+
close(): Promise<void>;
|
|
169
|
+
/**
|
|
170
|
+
* A browser computer's CDP target (group cdp). The URL is a secret, a bearer of the session: never logged, never in a
|
|
171
|
+
* result, a report or an error.
|
|
172
|
+
*/
|
|
173
|
+
cdp?: {
|
|
174
|
+
url: string;
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
export interface ComputerProvider {
|
|
178
|
+
readonly id: string;
|
|
179
|
+
readonly version: string;
|
|
180
|
+
capabilities(): ComputerCapabilities;
|
|
181
|
+
check(spec: ComputerSpec): Refusal[];
|
|
182
|
+
create(spec: ComputerSpec, context?: {
|
|
183
|
+
signal?: AbortSignal;
|
|
184
|
+
}): Promise<Result<CreatedComputer>>;
|
|
185
|
+
/**
|
|
186
|
+
* Finds one computer this provider made, by its id or by labels, with the spec read back from it; none or several is
|
|
187
|
+
* an error in words.
|
|
188
|
+
*/
|
|
189
|
+
attach(ref: {
|
|
190
|
+
id: string;
|
|
191
|
+
} | {
|
|
192
|
+
labels: Record<string, string>;
|
|
193
|
+
}, context?: CallContext): Promise<Result<AttachedComputer>>;
|
|
194
|
+
/** Every computer this provider made that carries all of these labels: the janitor's view. */
|
|
195
|
+
list(labels: Record<string, string>, context?: CallContext): Promise<Result<ComputerInfo[]>>;
|
|
196
|
+
/** Reads the network back; with a policy, sets it, or refuses in words when it cannot. Never wider than asked. */
|
|
197
|
+
network(ref: ComputerRef, policy?: NetworkSpec, context?: CallContext): Promise<Result<NetworkPolicy>>;
|
|
198
|
+
/** Checks hello against this provider's version, kind and groups, and refuses on a mismatch. */
|
|
199
|
+
connect(ref: ComputerRef): Promise<Result<ComputerConnection>>;
|
|
200
|
+
/** Idempotent: a computer already gone is ok. A "stop" capabilities().release does not declare is refused in words. */
|
|
201
|
+
release(ref: ComputerRef, how: "stop" | "delete"): Promise<Result<void>>;
|
|
202
|
+
/**
|
|
203
|
+
* Sets the deadline to now + ttlMs: never earlier than the current deadline, never past created + maxLifetimeMs. A
|
|
204
|
+
* ttlMs that would move it earlier, or past that cap, is refused in words with the deadline unchanged: an extend
|
|
205
|
+
* never shortens a computer's life, and the cap counts from create, not from each call. It moves the vendor's timer,
|
|
206
|
+
* the deadline label and init's own deadline, in that order; when a step fails the computer ends earlier than asked,
|
|
207
|
+
* never later, and the error names what moved. The result is the deadline read back.
|
|
208
|
+
* Optional: a provider without it asks for the whole lifetime at create.
|
|
209
|
+
*/
|
|
210
|
+
extend?(ref: ComputerRef, ttlMs: number, context?: CallContext): Promise<Result<{
|
|
211
|
+
deadline: Date;
|
|
212
|
+
}>>;
|
|
213
|
+
/** A URL that shows the screen live, the vendor's own. Optional. */
|
|
214
|
+
stream?(ref: ComputerRef, options?: {
|
|
215
|
+
viewOnly?: boolean;
|
|
216
|
+
}, context?: CallContext): Promise<Result<{
|
|
217
|
+
url: string;
|
|
218
|
+
expiresAt?: Date;
|
|
219
|
+
}>>;
|
|
220
|
+
/**
|
|
221
|
+
* The computer's live view, for the runner's viewer (src/screen-watch.ts): frames to handlers.frame, each acked
|
|
222
|
+
* before the next; input() and close() on what it answers. Every computerd provider and the phone answer it through
|
|
223
|
+
* daemonWatch, on a connection of the watch's own. Optional; a computer with no screen refuses it as unsupported.
|
|
224
|
+
*/
|
|
225
|
+
watch?(ref: ComputerRef, handlers: ScreenWatchHandlers, options?: WatchOptions): Promise<Result<ScreenWatch>>;
|
|
226
|
+
/**
|
|
227
|
+
* Removes what this provider's computers left behind outside the computers themselves (Docker: an egress proxy and its
|
|
228
|
+
* volume whose computer is gone or whose deadline has passed), with all of these labels, and returns what it removed,
|
|
229
|
+
* by name. Optional; the janitor's sweep calls it after the computers, which release their own parts.
|
|
230
|
+
*/
|
|
231
|
+
sweepLeftovers?(context: {
|
|
232
|
+
labels: Record<string, string>;
|
|
233
|
+
now: Date;
|
|
234
|
+
signal?: AbortSignal;
|
|
235
|
+
}): Promise<Result<string[]>>;
|
|
236
|
+
/**
|
|
237
|
+
* One account-level read with the provider's keys (a list by label, the vendor's whoami) that never creates a
|
|
238
|
+
* computer, so it never spends: Settings' "test connection". ok with words on what it read, or the error: unauthorized
|
|
239
|
+
* for a key the vendor refused, unreachable for a vendor not reached, or another code, its message never carrying a
|
|
240
|
+
* key. Optional.
|
|
241
|
+
*/
|
|
242
|
+
testConnection?(context?: CallContext): Promise<Result<{
|
|
243
|
+
detail: string;
|
|
244
|
+
}>>;
|
|
245
|
+
}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** The os and daemon modes each kind may have; no other pair is valid. */
|
|
2
|
+
export const KIND_SHAPES = {
|
|
3
|
+
linux: { os: ["linux"], daemon: ["pid1", "child"] },
|
|
4
|
+
desktop: { os: ["linux", "windows", "macos"], daemon: ["pid1", "child", "none"] },
|
|
5
|
+
android: { os: ["android"], daemon: ["none"] },
|
|
6
|
+
ios: { os: ["ios"], daemon: ["none"] },
|
|
7
|
+
// A browser: the provider answers it, its CDP target the connection's cdp.
|
|
8
|
+
browser: { os: ["linux"], daemon: ["none"] },
|
|
9
|
+
};
|
|
10
|
+
/** Why kind, os and daemon are not a valid pair, in words; none when they are. */
|
|
11
|
+
export function kindRefusals({ kind, os, daemon }) {
|
|
12
|
+
const shape = Object.hasOwn(KIND_SHAPES, kind) ? KIND_SHAPES[kind] : undefined;
|
|
13
|
+
if (shape === undefined)
|
|
14
|
+
return [{ field: "kind", message: `kind ${JSON.stringify(kind)} is not one of ${Object.keys(KIND_SHAPES).join(", ")}` }];
|
|
15
|
+
const refusals = [];
|
|
16
|
+
if (!shape.os.includes(os))
|
|
17
|
+
refusals.push({ field: "kind", message: `a ${kind} computer runs ${shape.os.join(" or ")}, not os ${JSON.stringify(os)}` });
|
|
18
|
+
if (!shape.daemon.includes(daemon))
|
|
19
|
+
refusals.push({ field: "kind", message: `a ${kind} computer has daemon ${shape.daemon.join(" or ")}, not ${JSON.stringify(daemon)}` });
|
|
20
|
+
return refusals;
|
|
21
|
+
}
|
|
22
|
+
const DAY_MS = 24 * 60 * 60_000;
|
|
23
|
+
const lifetimeWords = (ms) => ms % DAY_MS === 0 ? `${ms / DAY_MS} ${ms === DAY_MS ? "day" : "days"}` : ms % 3_600_000 === 0 ? `${ms / 3_600_000} h` : ms % 60_000 === 0 ? `${ms / 60_000} min` : `${ms / 1000} s`;
|
|
24
|
+
/**
|
|
25
|
+
* The one lifetime rule every provider's check() shares, with no vendor call: lifetimeMs is a whole number of
|
|
26
|
+
* milliseconds above 0, and at most capabilities().maxLifetimeMs.
|
|
27
|
+
*/
|
|
28
|
+
export function checkLifetime(lifetimeMs, { lifetime, maxLifetimeMs }) {
|
|
29
|
+
if (!Number.isSafeInteger(lifetimeMs) || lifetimeMs <= 0) {
|
|
30
|
+
const after = lifetime === "janitor" ? "the janitor deletes the computer" : "the vendor ends the computer";
|
|
31
|
+
return [{ field: "lifetimeMs", message: `lifetimeMs is required: a whole number of milliseconds above 0, after which ${after}` }];
|
|
32
|
+
}
|
|
33
|
+
if (lifetimeMs > maxLifetimeMs) {
|
|
34
|
+
return [{ field: "lifetimeMs", message: `lifetimeMs is at most ${lifetimeWords(maxLifetimeMs)} (${maxLifetimeMs} ms), this provider's cap; ask for a new computer after that` }];
|
|
35
|
+
}
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { RunFolder } from "./conformance/types.js";
|
|
2
|
+
import type { KindCapabilities } from "./kinds.js";
|
|
3
|
+
import type { MountKind } from "./mount.js";
|
|
4
|
+
import type { ComputerProvider } from "./provider.js";
|
|
5
|
+
/** Where the conformance side reads its settings: process.env, or a record of the same shape. */
|
|
6
|
+
export type ProviderEnv = Readonly<Record<string, string | undefined>>;
|
|
7
|
+
/**
|
|
8
|
+
* What a conformance module exports, the CLI's contract for a module given by path too: createProvider(), and optionally
|
|
9
|
+
* createDriftedProvider() for the drift case, conformanceImage() for a run that names no image, conformanceNotes for
|
|
10
|
+
* the report, mountFor() for the mount cases, and settingsFromEnv(env), the provider's options it reads from the
|
|
11
|
+
* environment by its COMPUTER_<ID>_* names, with ENV, those names by role. The CLI passes each function its options,
|
|
12
|
+
* which a module may ignore.
|
|
13
|
+
*/
|
|
14
|
+
export interface ConformanceModule {
|
|
15
|
+
createProvider(options?: object): ComputerProvider | Promise<ComputerProvider>;
|
|
16
|
+
createDriftedProvider?(options?: object): ComputerProvider | Promise<ComputerProvider>;
|
|
17
|
+
/** A fresh run folder for a mount kind the provider declares, with its outside; undefined for a kind it cannot make. */
|
|
18
|
+
mountFor?(kind: MountKind, options?: object): RunFolder | undefined | Promise<RunFolder | undefined>;
|
|
19
|
+
conformanceImage?(options?: object): string | Promise<string>;
|
|
20
|
+
conformanceNotes?: string[];
|
|
21
|
+
settingsFromEnv?(env?: ProviderEnv): object;
|
|
22
|
+
/** Every name settingsFromEnv (and the module) reads, by role: COMPUTER_<ID>_*, or its live switch. */
|
|
23
|
+
readonly ENV?: Readonly<Record<string, string>>;
|
|
24
|
+
}
|
|
25
|
+
/** What every registry line resolves to: the provider file's module. */
|
|
26
|
+
export interface ProviderModule {
|
|
27
|
+
/**
|
|
28
|
+
* The mount kinds its computers take, the same as its provider's capabilities().mount (none: []): a caller tells which
|
|
29
|
+
* provider binds a local folder from the registry alone, without building one.
|
|
30
|
+
*/
|
|
31
|
+
readonly MOUNT: readonly MountKind[];
|
|
32
|
+
/**
|
|
33
|
+
* The machine kind and groups of each configuration it offers, as its built providers' capabilities() declare them:
|
|
34
|
+
* the kind registry's entry for it (PROVIDERS in kinds.ts) holds the same, and derives its setting kinds from them.
|
|
35
|
+
*/
|
|
36
|
+
readonly CAPABILITIES: readonly KindCapabilities[];
|
|
37
|
+
/**
|
|
38
|
+
* The provider, built from its options alone, its key included; it reads no environment, and throws in words when an
|
|
39
|
+
* option is missing or wrong, never echoing a key. Each provider file types its own options.
|
|
40
|
+
*/
|
|
41
|
+
create(options: object): ComputerProvider | Promise<ComputerProvider>;
|
|
42
|
+
/**
|
|
43
|
+
* The module the conformance CLI runs this provider through: the settings it reads from the environment, its run's
|
|
44
|
+
* bounds, its drifted twin, its image and notes. Without one the CLI runs create()'s provider with the CLI's options,
|
|
45
|
+
* and the drift case skips.
|
|
46
|
+
*/
|
|
47
|
+
conformance?(): Promise<ConformanceModule>;
|
|
48
|
+
}
|
|
49
|
+
export declare const providers: {
|
|
50
|
+
docker: () => Promise<typeof import("./docker.js")>;
|
|
51
|
+
modal: () => Promise<typeof import("./modal.js")>;
|
|
52
|
+
daytona: () => Promise<typeof import("./daytona.js")>;
|
|
53
|
+
e2b: () => Promise<typeof import("./e2b.js")>;
|
|
54
|
+
browserbase: () => Promise<typeof import("./browserbase.js")>;
|
|
55
|
+
kernel: () => Promise<typeof import("./kernel.js")>;
|
|
56
|
+
"phone-harness": () => Promise<typeof import("./phone-harness.js")>;
|
|
57
|
+
orgo: () => Promise<typeof import("./orgo.js")>;
|
|
58
|
+
};
|
|
59
|
+
export type ProviderId = keyof typeof providers;
|
|
60
|
+
/** The options a registry id's create() takes. */
|
|
61
|
+
export type ProviderOptions<Id extends ProviderId> = Parameters<Awaited<ReturnType<(typeof providers)[Id]>>["create"]>[0];
|
|
62
|
+
/** Every id, in the registry's order. */
|
|
63
|
+
export declare const providerIds: ProviderId[];
|
|
64
|
+
export declare function isProviderId(id: string): id is ProviderId;
|
|
65
|
+
/** The provider file's module for an id; an id the registry does not hold is refused, naming the ones it does. */
|
|
66
|
+
export declare function providerModule(id: string): Promise<ProviderModule>;
|
|
67
|
+
/** The provider for an id, built by the provider file's create() from the options given, and nothing else. */
|
|
68
|
+
export declare function providerFor<Id extends ProviderId>(id: Id, options: ProviderOptions<Id>): Promise<ComputerProvider>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const providers = {
|
|
2
|
+
docker: () => import("./docker.js"),
|
|
3
|
+
modal: () => import("./modal.js"),
|
|
4
|
+
daytona: () => import("./daytona.js"),
|
|
5
|
+
e2b: () => import("./e2b.js"),
|
|
6
|
+
browserbase: () => import("./browserbase.js"),
|
|
7
|
+
kernel: () => import("./kernel.js"),
|
|
8
|
+
"phone-harness": () => import("./phone-harness.js"),
|
|
9
|
+
orgo: () => import("./orgo.js"),
|
|
10
|
+
};
|
|
11
|
+
/** Every id, in the registry's order. */
|
|
12
|
+
export const providerIds = Object.keys(providers);
|
|
13
|
+
export function isProviderId(id) {
|
|
14
|
+
return Object.hasOwn(providers, id);
|
|
15
|
+
}
|
|
16
|
+
/** The provider file's module for an id; an id the registry does not hold is refused, naming the ones it does. */
|
|
17
|
+
export async function providerModule(id) {
|
|
18
|
+
if (!isProviderId(id))
|
|
19
|
+
throw new Error(`unknown computer provider ${JSON.stringify(id)}: the registry holds ${providerIds.join(", ")}`);
|
|
20
|
+
return providers[id]();
|
|
21
|
+
}
|
|
22
|
+
/** The provider for an id, built by the provider file's create() from the options given, and nothing else. */
|
|
23
|
+
export async function providerFor(id, options) {
|
|
24
|
+
return (await providerModule(id)).create(options);
|
|
25
|
+
}
|
package/dist/result.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** An expected outcome: a value, or an error in words. Expected failures are results, not throws. */
|
|
2
|
+
export type Result<T, E = ComputerError> = {
|
|
3
|
+
ok: true;
|
|
4
|
+
value: T;
|
|
5
|
+
} | {
|
|
6
|
+
ok: false;
|
|
7
|
+
error: E;
|
|
8
|
+
};
|
|
9
|
+
export type ComputerErrorCode = "gone" | "refused" | "timeout" | "aborted" | "not_found" | "invalid" | "unsupported" | "denied" | "limit" | "exists" | "not_dir" | "is_dir" | "unauthorized" | "unreachable" | "docker" | "daytona" | "modal" | "e2b" | "browserbase" | "kernel" | "phone" | "orgo";
|
|
10
|
+
export interface ComputerError {
|
|
11
|
+
code: ComputerErrorCode;
|
|
12
|
+
message: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const ok: <T>(value: T) => Result<T, never>;
|
|
15
|
+
export declare const fail: (code: ComputerErrorCode, message: string) => Result<never>;
|
package/dist/result.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { InputAction, InputActionsResult } from "./protocol.js";
|
|
2
|
+
import type { ComputerConnection, ComputerRef, Refusal } from "./provider.js";
|
|
3
|
+
import { type ComputerError, type ComputerErrorCode, type Result } from "./result.js";
|
|
4
|
+
/** One whole frame of the screen. */
|
|
5
|
+
export interface ScreenFrame {
|
|
6
|
+
/** Rises with each frame of a watch. */
|
|
7
|
+
seq: number;
|
|
8
|
+
format: "jpeg" | "png";
|
|
9
|
+
bytes: Uint8Array;
|
|
10
|
+
/** The screen's real pixels, unscaled: the space every input action's coordinates are in. */
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
/** The image's own pixels, scaled down to maxWidth at most. */
|
|
14
|
+
frameWidth: number;
|
|
15
|
+
frameHeight: number;
|
|
16
|
+
cursor?: [number, number];
|
|
17
|
+
}
|
|
18
|
+
export interface WatchOptions {
|
|
19
|
+
/** Ends the watch as close() does. */
|
|
20
|
+
signal?: AbortSignal;
|
|
21
|
+
/** The frame's width at most; the computer's default (1280) when absent. */
|
|
22
|
+
maxWidth?: number;
|
|
23
|
+
/** JPEG quality, 1 to 100; the computer's default (60) when absent. */
|
|
24
|
+
quality?: number;
|
|
25
|
+
}
|
|
26
|
+
/** watchScreen's answer: pull-paced frames and an input sink on one connection. */
|
|
27
|
+
export interface ScreenFrames {
|
|
28
|
+
/** Pull-paced: each next() is the ack for the frame before it (the caller calls next() once it has drawn a frame). */
|
|
29
|
+
frames: AsyncIterable<ScreenFrame>;
|
|
30
|
+
/** The viewer's mapped events, on the same connection; per-call errors in words, never a URL or a secret. */
|
|
31
|
+
act(actions: InputAction[], options?: {
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
}): Promise<Result<InputActionsResult>>;
|
|
34
|
+
/** Ends the frames and refuses further acts; the signal passed to watchScreen does the same. */
|
|
35
|
+
close(): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
/** Frames that failed: the code, and words with no URL or secret. */
|
|
38
|
+
export declare class ScreenWatchError extends Error {
|
|
39
|
+
readonly code: ComputerErrorCode;
|
|
40
|
+
constructor(code: ComputerErrorCode, message: string);
|
|
41
|
+
}
|
|
42
|
+
/** Why a watch ended without close() or the signal. */
|
|
43
|
+
export type WatchEndCode = "gone" | "unreachable" | "refused" | "unsupported";
|
|
44
|
+
export interface ScreenWatchHandlers {
|
|
45
|
+
/** The latest frame. Call ack() once it is drawn, or at once to drop it: the next frame is asked for only then. */
|
|
46
|
+
frame(frame: ScreenFrame, ack: () => void): void;
|
|
47
|
+
/** The watch ended without close() or the signal, once: the computer is gone or failed. In words, with no URL. */
|
|
48
|
+
ended(error: ComputerError & {
|
|
49
|
+
code: WatchEndCode;
|
|
50
|
+
}): void;
|
|
51
|
+
}
|
|
52
|
+
/** provider.watch's answer. */
|
|
53
|
+
export interface ScreenWatch {
|
|
54
|
+
/** The viewer's events, mapped by toAction, on the watch's connection; per call, its result in words with no URL. */
|
|
55
|
+
input(actions: InputAction[], options?: {
|
|
56
|
+
signal?: AbortSignal;
|
|
57
|
+
}): Promise<Result<InputActionsResult>>;
|
|
58
|
+
/** Ends the watch: no frame and no ended() after it, and its connection is let go. Idempotent. */
|
|
59
|
+
close(): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Words with no URL and no secret: a URL of any scheme, a login, a bearer, a secret-named parameter, a key- or
|
|
63
|
+
* token-shaped value and an endpoint (a host or an IPv4 address with a port) are taken out.
|
|
64
|
+
*/
|
|
65
|
+
export declare function redactWords(words: string): string;
|
|
66
|
+
/** The code a watch ends with for an error the computer gave. */
|
|
67
|
+
export declare function watchEndCode(code: ComputerErrorCode): WatchEndCode;
|
|
68
|
+
/** The screen of the computer on `connection`, as pull-paced frames and an input sink (see the top of this file). */
|
|
69
|
+
export declare function watchScreen(connection: ComputerConnection, options?: WatchOptions): ScreenFrames;
|
|
70
|
+
/**
|
|
71
|
+
* The live view of the computer at ref, through provider's connect(): the one implementation behind every provider's
|
|
72
|
+
* watch(), an adapter over watchScreen on a connection of the watch's own, which it lets go however the watch ends. A
|
|
73
|
+
* computer whose hello declares no screen is refused as unsupported; a connect that fails keeps its code, in words with
|
|
74
|
+
* no URL.
|
|
75
|
+
*/
|
|
76
|
+
export declare function daemonWatch(provider: {
|
|
77
|
+
connect(ref: ComputerRef): Promise<Result<ComputerConnection>>;
|
|
78
|
+
}, ref: ComputerRef, handlers: ScreenWatchHandlers, options?: WatchOptions): Promise<Result<ScreenWatch>>;
|
|
79
|
+
/** An event as the live view's viewer emits it, in the screen's pixels (the frame's width and height). */
|
|
80
|
+
export type ViewerEvent = {
|
|
81
|
+
type: "mouse";
|
|
82
|
+
action: "down" | "up" | "move";
|
|
83
|
+
x: number;
|
|
84
|
+
y: number;
|
|
85
|
+
button: number;
|
|
86
|
+
buttons: number;
|
|
87
|
+
clickCount: number;
|
|
88
|
+
modifiers: number;
|
|
89
|
+
} | {
|
|
90
|
+
type: "wheel";
|
|
91
|
+
x: number;
|
|
92
|
+
y: number;
|
|
93
|
+
dx: number;
|
|
94
|
+
dy: number;
|
|
95
|
+
} | {
|
|
96
|
+
type: "key";
|
|
97
|
+
action: "down" | "up" | "char";
|
|
98
|
+
key: string;
|
|
99
|
+
code: string;
|
|
100
|
+
text?: string;
|
|
101
|
+
modifiers: number;
|
|
102
|
+
} | {
|
|
103
|
+
type: "tap";
|
|
104
|
+
x: number;
|
|
105
|
+
y: number;
|
|
106
|
+
} | {
|
|
107
|
+
type: "swipe";
|
|
108
|
+
x1: number;
|
|
109
|
+
y1: number;
|
|
110
|
+
x2: number;
|
|
111
|
+
y2: number;
|
|
112
|
+
ms: number;
|
|
113
|
+
} | {
|
|
114
|
+
type: "button";
|
|
115
|
+
name: "back" | "home" | "recents";
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* The viewer's event as input actions for a computer of this kind, in the screen's upright pixels: the space the
|
|
119
|
+
* frames' width and height give. Points are rounded to whole pixels. What a kind cannot take is a Refusal in words,
|
|
120
|
+
* naming the event's field, and so is an event whose fields are not what its type says: it never throws.
|
|
121
|
+
*
|
|
122
|
+
* Bounds: a typed text holds 65,536 characters at most (refused past it); a swipe takes 0 to 1,000 ms (clamped); one
|
|
123
|
+
* wheel event moves 20 clicks at most each way (clamped). A shortcut keeps Shift (ctrl+shift+s). A click with a
|
|
124
|
+
* modifier held is one click with its keys, on the up; its down only moves. A desktop never gets ctrl+alt+backspace or
|
|
125
|
+
* ctrl+alt+F1 to F12: they end or switch the X display.
|
|
126
|
+
*
|
|
127
|
+
* toAction is stateless: each event on its own. A modifier released between a press and its release makes the press
|
|
128
|
+
* modified and the release plain, and the click is lost; a viewer maps through createActionMapper, which remembers.
|
|
129
|
+
*/
|
|
130
|
+
export declare function toAction(event: ViewerEvent, kind: "desktop" | "android" | "ios"): InputAction[] | Refusal;
|
|
131
|
+
/** Maps one viewer's events in order, remembering each mouse press until its release: one mapper is one take-over. */
|
|
132
|
+
export interface ActionMapper {
|
|
133
|
+
/**
|
|
134
|
+
* The event as input actions, or a Refusal: toAction's answer, but for a desktop's mouse buttons, whose press decides
|
|
135
|
+
* the strategy for the press and its release together:
|
|
136
|
+
* - a down with a modifier held sends only a move and remembers the keys held then; its up is one click with those
|
|
137
|
+
* keys, whatever is held at the up;
|
|
138
|
+
* - a down with no modifier is a plain down, and its up a plain up, even if a modifier is pressed in between;
|
|
139
|
+
* - an up with no press remembered is toAction's.
|
|
140
|
+
*/
|
|
141
|
+
map(event: ViewerEvent): InputAction[] | Refusal;
|
|
142
|
+
/**
|
|
143
|
+
* Lets go of every button and key this mapper sent a down for and has not released (the take-over ends, or the
|
|
144
|
+
* viewer loses focus), then forgets every press: the ups to send, nothing on a second call. A key is never among
|
|
145
|
+
* them: the protocol presses and releases a key within its action, so the mapper never leaves one down.
|
|
146
|
+
*/
|
|
147
|
+
release(): InputAction[];
|
|
148
|
+
}
|
|
149
|
+
/** A mapper of the viewer's events for a computer of this kind; see ActionMapper. */
|
|
150
|
+
export declare function createActionMapper(kind: "desktop" | "android" | "ios"): ActionMapper;
|