copilotz 1.0.0-rc.47 → 1.0.0-rc.49
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/AGENTS.md +4 -4
- package/CHANGELOG.md +32 -0
- package/README.md +2 -2
- package/package.json +6 -2
- package/plugins/compute/computers/contract.d.ts +8 -6
- package/plugins/compute/computers/contract.js +7 -5
- package/plugins/compute/computers/program/browser/actions.d.ts +6 -0
- package/plugins/compute/computers/program/browser/actions.js +256 -0
- package/plugins/compute/computers/program/browser/async.d.ts +27 -0
- package/plugins/compute/computers/program/browser/async.js +65 -0
- package/plugins/compute/computers/program/browser/batch.d.ts +2 -0
- package/plugins/compute/computers/program/browser/batch.js +46 -0
- package/plugins/compute/computers/program/browser/cdp.d.ts +40 -0
- package/plugins/compute/computers/program/browser/cdp.js +151 -0
- package/plugins/compute/computers/program/browser/chrome.d.ts +64 -0
- package/plugins/compute/computers/program/browser/chrome.js +249 -0
- package/plugins/compute/computers/program/browser/control.d.ts +18 -0
- package/plugins/compute/computers/program/browser/control.js +65 -0
- package/plugins/compute/computers/program/browser/live.d.ts +95 -0
- package/plugins/compute/computers/program/browser/live.js +345 -0
- package/plugins/compute/computers/program/browser/math.d.ts +8 -0
- package/plugins/compute/computers/program/browser/math.js +38 -0
- package/plugins/compute/computers/program/browser/mod.d.ts +32 -0
- package/plugins/compute/computers/program/browser/mod.js +202 -0
- package/plugins/compute/computers/program/browser/page.d.ts +56 -0
- package/plugins/compute/computers/program/browser/page.js +346 -0
- package/plugins/compute/computers/program/browser/profile.d.ts +14 -0
- package/plugins/compute/computers/program/browser/profile.js +70 -0
- package/plugins/compute/computers/program/browser/refs.d.ts +35 -0
- package/plugins/compute/computers/program/browser/refs.js +79 -0
- package/plugins/compute/computers/program/browser/schema.d.ts +73 -0
- package/plugins/compute/computers/program/browser/schema.js +73 -0
- package/plugins/compute/computers/program/browser/session.d.ts +62 -0
- package/plugins/compute/computers/program/browser/session.js +294 -0
- package/plugins/compute/computers/program/browser/storage.d.ts +8 -0
- package/plugins/compute/computers/program/browser/storage.js +70 -0
- package/plugins/compute/computers/program/browser/types.d.ts +93 -0
- package/plugins/compute/computers/program/browser/types.js +1 -0
- package/plugins/compute/computers/program/computer.d.ts +58 -0
- package/plugins/compute/computers/program/computer.js +285 -0
- package/plugins/compute/computers/program/mod.d.ts +8 -0
- package/plugins/compute/computers/program/mod.js +8 -0
- package/plugins/compute/computers/program/pool.d.ts +39 -0
- package/plugins/compute/computers/program/pool.js +335 -0
- package/plugins/compute/computers/program/state.d.ts +69 -0
- package/plugins/compute/computers/program/state.js +198 -0
- package/plugins/compute/computers/program/update.d.ts +17 -0
- package/plugins/compute/computers/program/update.js +144 -0
- package/plugins/compute/computers/program/version.d.ts +1 -1
- package/plugins/compute/computers/program/version.js +1 -1
- package/plugins/compute/computers/program/workloads/answer.d.ts +13 -0
- package/plugins/compute/computers/program/workloads/answer.js +29 -0
- package/plugins/compute/computers/program/workloads/archive.d.ts +6 -0
- package/plugins/compute/computers/program/workloads/archive.js +128 -0
- package/plugins/compute/computers/program/workloads/browser.d.ts +16 -0
- package/plugins/compute/computers/program/workloads/browser.js +17 -0
- package/plugins/compute/computers/program/workloads/files.d.ts +13 -0
- package/plugins/compute/computers/program/workloads/files.js +236 -0
- package/plugins/compute/computers/program/workloads/http.d.ts +20 -0
- package/plugins/compute/computers/program/workloads/http.js +168 -0
- package/plugins/compute/computers/program/workloads/info.d.ts +8 -0
- package/plugins/compute/computers/program/workloads/info.js +22 -0
- package/plugins/compute/computers/program/workloads/jobs.d.ts +32 -0
- package/plugins/compute/computers/program/workloads/jobs.js +287 -0
- package/plugins/compute/computers/program/workloads/ports.d.ts +5 -0
- package/plugins/compute/computers/program/workloads/ports.js +160 -0
- package/plugins/compute/computers/program/workloads/processes.d.ts +23 -0
- package/plugins/compute/computers/program/workloads/processes.js +103 -0
- package/plugins/compute/computers/program/workloads/search.d.ts +23 -0
- package/plugins/compute/computers/program/workloads/search.js +170 -0
- package/plugins/compute/computers/program/workloads/shell.d.ts +21 -0
- package/plugins/compute/computers/program/workloads/shell.js +140 -0
- package/plugins/compute/computers/program/workloads/spaces.d.ts +13 -0
- package/plugins/compute/computers/program/workloads/spaces.js +47 -0
- package/plugins/compute/computers/program/workloads/streams.d.ts +20 -0
- package/plugins/compute/computers/program/workloads/streams.js +94 -0
- package/plugins/compute/computers/program/workloads/terminal.d.ts +26 -0
- package/plugins/compute/computers/program/workloads/terminal.js +384 -0
- package/plugins/compute/computers/resources/downloads.js +1 -1
- package/plugins/compute/computers/shared/pool.d.ts +45 -0
- package/plugins/compute/computers/shared/pool.js +16 -0
- package/plugins/compute/contract.d.ts +2 -5
- package/plugins/compute/contract.js +2 -5
- package/plugins/compute/mod.d.ts +3 -8
- package/plugins/compute/mod.js +3 -8
- package/plugins/compute/web.d.ts +2 -6
- package/plugins/compute/web.js +2 -6
- package/testing/mod.d.ts +6 -1
- package/testing/mod.js +10 -3
- package/plugins/compute/apps/actions/build.d.ts +0 -1
- package/plugins/compute/apps/actions/build.js +0 -99
- package/plugins/compute/apps/actions/configure.d.ts +0 -1
- package/plugins/compute/apps/actions/configure.js +0 -74
- package/plugins/compute/apps/actions/list.d.ts +0 -1
- package/plugins/compute/apps/actions/list.js +0 -13
- package/plugins/compute/apps/actions/meter.d.ts +0 -1
- package/plugins/compute/apps/actions/meter.js +0 -43
- package/plugins/compute/apps/actions/publish.d.ts +0 -1
- package/plugins/compute/apps/actions/publish.js +0 -41
- package/plugins/compute/apps/actions/redeploy.d.ts +0 -1
- package/plugins/compute/apps/actions/redeploy.js +0 -26
- package/plugins/compute/apps/actions/remove.d.ts +0 -1
- package/plugins/compute/apps/actions/remove.js +0 -47
- package/plugins/compute/apps/adapters/cloudrun.d.ts +0 -90
- package/plugins/compute/apps/adapters/cloudrun.js +0 -353
- package/plugins/compute/apps/adapters/front.d.ts +0 -24
- package/plugins/compute/apps/adapters/front.js +0 -131
- package/plugins/compute/apps/adapters/local.d.ts +0 -15
- package/plugins/compute/apps/adapters/local.js +0 -139
- package/plugins/compute/apps/adapters/tar.d.ts +0 -29
- package/plugins/compute/apps/adapters/tar.js +0 -178
- package/plugins/compute/apps/collections/app.d.ts +0 -143
- package/plugins/compute/apps/collections/app.js +0 -60
- package/plugins/compute/apps/contract.d.ts +0 -73
- package/plugins/compute/apps/contract.js +0 -8
- package/plugins/compute/apps/mod.d.ts +0 -42
- package/plugins/compute/apps/mod.js +0 -76
- package/plugins/compute/apps/resources/tools.d.ts +0 -10
- package/plugins/compute/apps/resources/tools.js +0 -85
- package/plugins/compute/apps/shared/archive.d.ts +0 -24
- package/plugins/compute/apps/shared/archive.js +0 -69
- package/plugins/compute/apps/shared/claims.d.ts +0 -28
- package/plugins/compute/apps/shared/claims.js +0 -18
- package/plugins/compute/apps/shared/environment.d.ts +0 -8
- package/plugins/compute/apps/shared/environment.js +0 -15
- package/plugins/compute/apps/shared/errors.d.ts +0 -4
- package/plugins/compute/apps/shared/errors.js +0 -4
- package/plugins/compute/apps/shared/host.d.ts +0 -19
- package/plugins/compute/apps/shared/host.js +0 -19
- package/plugins/compute/apps/shared/label.d.ts +0 -21
- package/plugins/compute/apps/shared/label.js +0 -51
- package/plugins/compute/apps/shared/meter.d.ts +0 -17
- package/plugins/compute/apps/shared/meter.js +0 -29
- package/plugins/compute/apps/shared/publish.d.ts +0 -41
- package/plugins/compute/apps/shared/publish.js +0 -141
- package/plugins/compute/apps/shared/settings.d.ts +0 -49
- package/plugins/compute/apps/shared/settings.js +0 -22
- package/plugins/compute/apps/views/web/apps.d.ts +0 -54
- package/plugins/compute/apps/views/web/apps.js +0 -48
- package/plugins/compute/apps/views/web/env.d.ts +0 -54
- package/plugins/compute/apps/views/web/env.js +0 -195
- package/plugins/compute/apps/views/web/publish.d.ts +0 -24
- package/plugins/compute/apps/views/web/publish.js +0 -158
- package/plugins/compute/apps/views/web/space.d.ts +0 -16
- package/plugins/compute/apps/views/web/space.js +0 -138
- package/plugins/compute/apps/views/web/style.d.ts +0 -7
- package/plugins/compute/apps/views/web/style.js +0 -155
- package/plugins/compute/apps/web.d.ts +0 -17
- package/plugins/compute/apps/web.js +0 -35
- package/plugins/compute/cloud/actions/create.d.ts +0 -1
- package/plugins/compute/cloud/actions/create.js +0 -79
- package/plugins/compute/cloud/actions/daily.d.ts +0 -1
- package/plugins/compute/cloud/actions/daily.js +0 -75
- package/plugins/compute/cloud/actions/destroy.d.ts +0 -1
- package/plugins/compute/cloud/actions/destroy.js +0 -71
- package/plugins/compute/cloud/actions/may.d.ts +0 -1
- package/plugins/compute/cloud/actions/may.js +0 -15
- package/plugins/compute/cloud/actions/org.d.ts +0 -1
- package/plugins/compute/cloud/actions/org.js +0 -21
- package/plugins/compute/cloud/actions/pool-tick.d.ts +0 -4
- package/plugins/compute/cloud/actions/pool-tick.js +0 -96
- package/plugins/compute/cloud/actions/pool.d.ts +0 -3
- package/plugins/compute/cloud/actions/pool.js +0 -100
- package/plugins/compute/cloud/actions/release.d.ts +0 -1
- package/plugins/compute/cloud/actions/release.js +0 -58
- package/plugins/compute/cloud/actions/remote.d.ts +0 -10
- package/plugins/compute/cloud/actions/remote.js +0 -26
- package/plugins/compute/cloud/actions/tick.d.ts +0 -1
- package/plugins/compute/cloud/actions/tick.js +0 -105
- package/plugins/compute/cloud/actions/touch.d.ts +0 -1
- package/plugins/compute/cloud/actions/touch.js +0 -32
- package/plugins/compute/cloud/actions/vms.d.ts +0 -7
- package/plugins/compute/cloud/actions/vms.js +0 -213
- package/plugins/compute/cloud/actions/wake.d.ts +0 -1
- package/plugins/compute/cloud/actions/wake.js +0 -153
- package/plugins/compute/cloud/adapters/gce/index.d.ts +0 -73
- package/plugins/compute/cloud/adapters/gce/index.js +0 -242
- package/plugins/compute/cloud/adapters/local.d.ts +0 -48
- package/plugins/compute/cloud/adapters/local.js +0 -188
- package/plugins/compute/cloud/collections/cloud-computer.d.ts +0 -109
- package/plugins/compute/cloud/collections/cloud-computer.js +0 -89
- package/plugins/compute/cloud/collections/pool-vm.d.ts +0 -79
- package/plugins/compute/cloud/collections/pool-vm.js +0 -36
- package/plugins/compute/cloud/collections/pool-want.d.ts +0 -94
- package/plugins/compute/cloud/collections/pool-want.js +0 -27
- package/plugins/compute/cloud/contract.d.ts +0 -242
- package/plugins/compute/cloud/contract.js +0 -73
- package/plugins/compute/cloud/mod.d.ts +0 -97
- package/plugins/compute/cloud/mod.js +0 -209
- package/plugins/compute/cloud/processors/mark.d.ts +0 -9
- package/plugins/compute/cloud/processors/mark.js +0 -13
- package/plugins/compute/cloud/resources/tools.d.ts +0 -3
- package/plugins/compute/cloud/resources/tools.js +0 -238
- package/plugins/compute/cloud/shared/host.d.ts +0 -11
- package/plugins/compute/cloud/shared/host.js +0 -29
- package/plugins/compute/cloud/shared/may.d.ts +0 -21
- package/plugins/compute/cloud/shared/may.js +0 -22
- package/plugins/compute/cloud/shared/meter.d.ts +0 -36
- package/plugins/compute/cloud/shared/meter.js +0 -68
- package/plugins/compute/cloud/shared/names.d.ts +0 -10
- package/plugins/compute/cloud/shared/names.js +0 -11
- package/plugins/compute/cloud/shared/people.d.ts +0 -19
- package/plugins/compute/cloud/shared/people.js +0 -12
- package/plugins/compute/cloud/shared/records.d.ts +0 -31
- package/plugins/compute/cloud/shared/records.js +0 -18
- package/plugins/compute/cloud/shared/settings.d.ts +0 -70
- package/plugins/compute/cloud/shared/settings.js +0 -47
- package/plugins/compute/cloud/shared/time.d.ts +0 -21
- package/plugins/compute/cloud/shared/time.js +0 -33
- package/plugins/compute/cloud/views/web/cloud.d.ts +0 -79
- package/plugins/compute/cloud/views/web/cloud.js +0 -122
- package/plugins/compute/cloud/views/web/computer.d.ts +0 -37
- package/plugins/compute/cloud/views/web/computer.js +0 -195
- package/plugins/compute/cloud/views/web/new.d.ts +0 -27
- package/plugins/compute/cloud/views/web/new.js +0 -103
- package/plugins/compute/cloud/views/web/style.d.ts +0 -6
- package/plugins/compute/cloud/views/web/style.js +0 -84
- package/plugins/compute/cloud/web.d.ts +0 -19
- package/plugins/compute/cloud/web.js +0 -61
- /package/plugins/compute/{cloud/shared/google.d.ts → google.d.ts} +0 -0
- /package/plugins/compute/{cloud/shared/google.js → google.js} +0 -0
package/AGENTS.md
CHANGED
|
@@ -4,7 +4,7 @@ A guide for coding agents (Claude Code, Codex, Cursor, Gemini) building an app w
|
|
|
4
4
|
it whole before you write code. The last section is for work on Copilotz itself.
|
|
5
5
|
|
|
6
6
|
It ships in the package (`node_modules/copilotz/AGENTS.md`, and `@copilotz/copilotz` on JSR) and
|
|
7
|
-
goes with `copilotz@1.0.0-rc.
|
|
7
|
+
goes with `copilotz@1.0.0-rc.49`. Every docs page is Markdown at
|
|
8
8
|
`https://copilotz.com/docs/<slug>.md`, and https://copilotz.com/llms.txt lists them all. When you're
|
|
9
9
|
unsure of a name, fetch its page or read the package's types (`node_modules/copilotz/**/*.d.ts`).
|
|
10
10
|
Don't guess.
|
|
@@ -64,12 +64,12 @@ There's no project generator. Set a project up as the docs' courses do, on Node
|
|
|
64
64
|
```sh
|
|
65
65
|
mkdir my-app && cd my-app
|
|
66
66
|
npm init -y && npm pkg set type=module
|
|
67
|
-
npm install copilotz@1.0.0-rc.
|
|
67
|
+
npm install copilotz@1.0.0-rc.49 react@19 react-dom@19
|
|
68
68
|
npm install -D typescript @types/node @types/react @types/react-dom esbuild
|
|
69
69
|
```
|
|
70
70
|
|
|
71
71
|
Pin the version: npm's `latest` tag still points at an early release candidate. On Deno, run
|
|
72
|
-
`deno add jsr:@copilotz/copilotz` and map `"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.
|
|
72
|
+
`deno add jsr:@copilotz/copilotz` and map `"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.49"` in
|
|
73
73
|
`deno.json`, so imports read the same.
|
|
74
74
|
|
|
75
75
|
Node runs `.ts` files as they are, so there's no build step. It doesn't run `.tsx`: tests that load
|
|
@@ -108,7 +108,7 @@ line `@AGENTS.md` (Claude Code reads `CLAUDE.md`, and follows the import). Keep
|
|
|
108
108
|
```markdown
|
|
109
109
|
# AGENTS.md
|
|
110
110
|
|
|
111
|
-
This app runs on Copilotz (copilotz@1.0.0-rc.
|
|
111
|
+
This app runs on Copilotz (copilotz@1.0.0-rc.49). Read node_modules/copilotz/AGENTS.md first;
|
|
112
112
|
https://copilotz.com/llms.txt lists the docs, as Markdown.
|
|
113
113
|
|
|
114
114
|
- `npm test` runs every test offline, with a scripted model: run it after each change.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
+
## 1.0.0-rc.49 — 2026-11-13
|
|
2
|
+
|
|
3
|
+
**Breaking: hosted computers and apps are Compass's, not Copilotz's.** `cloud`, `cloudPool`,
|
|
4
|
+
`remotePool`, `apps`, `cloudWeb`, `appsWeb` and their hosts (`gceHost`, `localHost` and
|
|
5
|
+
`createLocalHost`, `cloudRun`, `cloudRunHost`, `localApps`) are no longer in
|
|
6
|
+
`copilotz/plugins/compute` or `/web`, nor their contracts in `/contract`: a hosting model (Google
|
|
7
|
+
Cloud's, `*.copilotz.app`) and its prices are one product's (see design/plugins.md). Compass keeps
|
|
8
|
+
them, with the same names, so its data and routes don't change.
|
|
9
|
+
|
|
10
|
+
Computers people connect stay, as standard plugins, with the computer program and its downloads
|
|
11
|
+
(`computers`, `computersWeb`, `computersTerminal`, `computerDownloads`), and so do connected
|
|
12
|
+
accounts (`accounts`, `accountsWeb`); their reference pages are now published.
|
|
13
|
+
|
|
14
|
+
- **The program's pool mode** (`computer pool`, what a hosted computer's VM runs) is part of
|
|
15
|
+
computers' contract: `POOL`, `POOL_KIND`, `PoolAssign` and `PoolRelease`, from
|
|
16
|
+
`copilotz/plugins/compute/contract` (they were cloud's). Its code is a new entry point,
|
|
17
|
+
`copilotz/plugins/compute/program` (`startPool`), for an app's local VMs and tests.
|
|
18
|
+
- **Google's tokens** stay: `googleToken`, and now `verifyIdentityToken` (who a Compute Engine VM
|
|
19
|
+
is), from `copilotz/plugins/compute`.
|
|
20
|
+
- Computers' contract also has `TerminalResult` (what a `terminal` call answers), and
|
|
21
|
+
`copilotz/testing` has Oxian's `createWorker`, so an app's tests fake a computer on the same Oxian
|
|
22
|
+
as its runtime.
|
|
23
|
+
- `scripts/cloud/` (setting up Google Cloud for cloud computers) went with them.
|
|
24
|
+
|
|
25
|
+
## 1.0.0-rc.48 — 2026-11-13
|
|
26
|
+
|
|
27
|
+
- **Oxian 0.23.6:** each end of a worker connection keeps about 70 bytes per finished stream instead
|
|
28
|
+
of about 170, for the connection's life (its handoff, at about 49,000 streams). A public MCP app,
|
|
29
|
+
whose Hypervisor and worker share a process, keeps about 0.2 MiB less heap per 1,000 calls.
|
|
30
|
+
- `copilotz/testing`'s `host()` on Deno loaded Oxian 0.23.4's adapter beside the runtime's own
|
|
31
|
+
Oxian; it now names the same version.
|
|
32
|
+
|
|
1
33
|
## 1.0.0-rc.47 — 2026-11-13
|
|
2
34
|
|
|
3
35
|
(rc.46 was tagged but never published: a file wasn't formatted, and a test read Windows line endings
|
package/README.md
CHANGED
|
@@ -152,7 +152,7 @@ ana sees: Tue 10:00, Wed 15:00
|
|
|
152
152
|
```sh
|
|
153
153
|
npm install copilotz@next # Node 24+ (npm, pnpm, yarn)
|
|
154
154
|
bun add copilotz@next # Bun
|
|
155
|
-
deno add jsr:@copilotz/copilotz@^1.0.0-rc.
|
|
155
|
+
deno add jsr:@copilotz/copilotz@^1.0.0-rc.49 # Deno 2.9+ (or `deno add npm:copilotz@next`)
|
|
156
156
|
```
|
|
157
157
|
|
|
158
158
|
Until 1.0, the release candidates are on npm's `next` tag, and a plain `npm install copilotz` or
|
|
@@ -166,7 +166,7 @@ OPENAI_API_KEY=sk-… node salon.ts # or bun salon.ts, or deno run -A salon.t
|
|
|
166
166
|
```
|
|
167
167
|
|
|
168
168
|
On Deno, map the name `copilotz` in `deno.json`
|
|
169
|
-
(`"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.
|
|
169
|
+
(`"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.49"`) so the imports read the same everywhere.
|
|
170
170
|
Copilotz runs on Node 24+, Deno 2.9+ and Bun, and it's built on web standards for Cloudflare Workers
|
|
171
171
|
and the browser.
|
|
172
172
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "copilotz",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.49",
|
|
4
4
|
"description": "The open-source runtime that makes your app usable by people, your own agents and their assistants.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agents",
|
|
@@ -192,6 +192,10 @@
|
|
|
192
192
|
"types": "./plugins/compute/computers/resources/downloads.d.ts",
|
|
193
193
|
"default": "./plugins/compute/computers/resources/downloads.js"
|
|
194
194
|
},
|
|
195
|
+
"./plugins/compute/program": {
|
|
196
|
+
"types": "./plugins/compute/computers/program/mod.d.ts",
|
|
197
|
+
"default": "./plugins/compute/computers/program/mod.js"
|
|
198
|
+
},
|
|
195
199
|
"./plugins/interfaces": {
|
|
196
200
|
"types": "./plugins/interfaces/mod.d.ts",
|
|
197
201
|
"default": "./plugins/interfaces/mod.js"
|
|
@@ -291,7 +295,7 @@
|
|
|
291
295
|
"ink": "8.0.0",
|
|
292
296
|
"json-schema-to-ts": "3.1.1",
|
|
293
297
|
"ominipg": "0.11.2",
|
|
294
|
-
"oxianjs": "0.23.
|
|
298
|
+
"oxianjs": "0.23.6",
|
|
295
299
|
"pg": "8.23.1",
|
|
296
300
|
"temml": "0.14.0"
|
|
297
301
|
},
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The computers plugin's contract, for plugins that build on it (
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* by
|
|
2
|
+
* The computers plugin's contract, for plugins that build on it (an app's
|
|
3
|
+
* own, such as hosted computers or published apps): the work a computer
|
|
4
|
+
* serves and its shapes (shared/workloads.ts), the program's pool mode
|
|
5
|
+
* (shared/pool.ts), and a space's environment as people read it (`envVar`).
|
|
6
|
+
* Other plugins send it work by these names through `ctx.workers`, and call
|
|
7
|
+
* the plugin's Actions by name.
|
|
7
8
|
*/
|
|
8
|
-
export { type ArchiveInput, type Failed, type HttpRequestHead, type HttpResponseHead, type Job, type JobsStartInput, type Scope, WORK, } from "./shared/workloads.js";
|
|
9
|
+
export { type ArchiveInput, type Failed, type HttpRequestHead, type HttpResponseHead, type Job, type JobsStartInput, type Scope, type TerminalResult, WORK, } from "./shared/workloads.js";
|
|
10
|
+
export { POOL, POOL_KIND, type PoolAssign, type PoolRelease } from "./shared/pool.js";
|
|
9
11
|
export type { EnvVar } from "./collections/env-var.js";
|
|
10
12
|
/**
|
|
11
13
|
* What a View the computers' web front end draws under a space's
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The computers plugin's contract, for plugins that build on it (
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* by
|
|
2
|
+
* The computers plugin's contract, for plugins that build on it (an app's
|
|
3
|
+
* own, such as hosted computers or published apps): the work a computer
|
|
4
|
+
* serves and its shapes (shared/workloads.ts), the program's pool mode
|
|
5
|
+
* (shared/pool.ts), and a space's environment as people read it (`envVar`).
|
|
6
|
+
* Other plugins send it work by these names through `ctx.workers`, and call
|
|
7
|
+
* the plugin's Actions by name.
|
|
7
8
|
*/
|
|
8
9
|
export { WORK, } from "./shared/workloads.js";
|
|
10
|
+
export { POOL, POOL_KIND } from "./shared/pool.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Session } from "./session.js";
|
|
2
|
+
import type { Action } from "./types.js";
|
|
3
|
+
/** Where `web_search` goes unless the engine is told otherwise. */
|
|
4
|
+
export declare const SEARCH_URL = "https://html.duckduckgo.com/html/";
|
|
5
|
+
/** Does one action on the session's current tab. */
|
|
6
|
+
export declare function perform(session: Session, action: Action, signal: AbortSignal): Promise<Record<string, unknown>>;
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One browser action, bounded by its signal. The engine owns admission and
|
|
3
|
+
* the batch's deadline; an action that only acts (a click, a key) answers
|
|
4
|
+
* with the page as it reads after.
|
|
5
|
+
*/
|
|
6
|
+
import { rm } from "node:fs/promises";
|
|
7
|
+
import { delay, race } from "./async.js";
|
|
8
|
+
import { finite, keyPress } from "./page.js";
|
|
9
|
+
import { commitDownload, stageUpload, workspacePath } from "./storage.js";
|
|
10
|
+
/** Where `web_search` goes unless the engine is told otherwise. */
|
|
11
|
+
export const SEARCH_URL = "https://html.duckduckgo.com/html/";
|
|
12
|
+
/** Clicks what starts a download, and moves the file to `action.path` in the space's folder. */
|
|
13
|
+
async function download(session, page, action, signal) {
|
|
14
|
+
if (!action.path)
|
|
15
|
+
throw new Error("download.path is required");
|
|
16
|
+
const root = session.workdir;
|
|
17
|
+
await workspacePath(root, action.path, true);
|
|
18
|
+
const client = session.client();
|
|
19
|
+
let guid = "";
|
|
20
|
+
let suggestedFilename = "";
|
|
21
|
+
let resolve;
|
|
22
|
+
let reject;
|
|
23
|
+
const completion = new Promise((yes, no) => {
|
|
24
|
+
resolve = yes;
|
|
25
|
+
reject = no;
|
|
26
|
+
});
|
|
27
|
+
void completion.catch(() => { });
|
|
28
|
+
const offBegin = client.on("Browser.downloadWillBegin", (e) => {
|
|
29
|
+
if (e.frameId === page.frameId && !guid) {
|
|
30
|
+
guid = e.guid;
|
|
31
|
+
suggestedFilename = e.suggestedFilename;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
const offProgress = client.on("Browser.downloadProgress", (e) => {
|
|
35
|
+
if (e.guid !== guid)
|
|
36
|
+
return;
|
|
37
|
+
if (e.state === "completed")
|
|
38
|
+
resolve();
|
|
39
|
+
else if (e.state === "canceled")
|
|
40
|
+
reject(new Error("Download canceled"));
|
|
41
|
+
});
|
|
42
|
+
try {
|
|
43
|
+
await client.send("Browser.setDownloadBehavior", {
|
|
44
|
+
behavior: "allowAndName",
|
|
45
|
+
downloadPath: session.staging,
|
|
46
|
+
eventsEnabled: true,
|
|
47
|
+
}, signal);
|
|
48
|
+
await page.click(action, signal);
|
|
49
|
+
await race(completion, signal);
|
|
50
|
+
await commitDownload(root, action.path, `${session.staging}/${guid}`);
|
|
51
|
+
await rm(`${session.staging}/${guid}`, { force: true });
|
|
52
|
+
return { path: action.path, suggestedFilename };
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
offBegin();
|
|
56
|
+
offProgress();
|
|
57
|
+
if (signal.aborted && guid) {
|
|
58
|
+
await client.send("Browser.cancelDownload", { guid }).catch(() => { });
|
|
59
|
+
}
|
|
60
|
+
await client.send("Browser.setDownloadBehavior", { behavior: "deny" }).catch(() => { });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** Searches DuckDuckGo's HTML page in a tab of its own, and reads its results. */
|
|
64
|
+
async function search(session, action, signal) {
|
|
65
|
+
const query = action.query?.trim();
|
|
66
|
+
if (!query)
|
|
67
|
+
throw new Error("Search query is required");
|
|
68
|
+
const url = new URL(session.options.searchUrl ?? SEARCH_URL);
|
|
69
|
+
url.searchParams.set("q", query);
|
|
70
|
+
for (const [key, value] of Object.entries({
|
|
71
|
+
kl: action.region,
|
|
72
|
+
kad: action.language,
|
|
73
|
+
kp: action.safeSearch === "strict" ? "1" : action.safeSearch === "off" ? "-1" : undefined,
|
|
74
|
+
df: action.timeRange
|
|
75
|
+
? { day: "d", week: "w", month: "m", year: "y" }[action.timeRange]
|
|
76
|
+
: undefined,
|
|
77
|
+
}))
|
|
78
|
+
if (value)
|
|
79
|
+
url.searchParams.set(key, value);
|
|
80
|
+
const original = session.page;
|
|
81
|
+
let page;
|
|
82
|
+
try {
|
|
83
|
+
page = await session.newPage(url.href, signal);
|
|
84
|
+
const count = Math.max(1, Math.min(action.count ?? 5, 25));
|
|
85
|
+
const found = await page.evaluate(`(() => { const clean = s => (s ?? '').replace(/\\s+/g,' ').trim(); const real = a => { try { const u = new URL(a.href); return u.searchParams.get('uddg') ?? (/(^|\\.)duckduckgo\\.com$/.test(u.hostname) && u.pathname.startsWith('/y.js') ? null : a.href); } catch { return null; } }; const results = Array.from(document.querySelectorAll('a.result__a')).map(a => ({title:clean(a.textContent),url:real(a),snippet:clean(a.closest('.result')?.querySelector('.result__snippet')?.textContent)})).filter(r => r.url).slice(0,${count}); return {results,blocked:!results.length && /anomaly-modal|g-recaptcha|are you a human|challenge-form|bots use DuckDuckGo/i.test(document.documentElement.innerHTML)}; })()`, signal);
|
|
86
|
+
return {
|
|
87
|
+
success: !found.blocked,
|
|
88
|
+
provider: "duckduckgo-html",
|
|
89
|
+
query,
|
|
90
|
+
...found,
|
|
91
|
+
count: found.results.length,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
if (page) {
|
|
96
|
+
await session.client().send("Target.closeTarget", { targetId: page.id }).catch(() => { });
|
|
97
|
+
}
|
|
98
|
+
if (session.pages.has(original.id))
|
|
99
|
+
await session.select(original.id, signal).catch(() => { });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** Does one action on the session's current tab. */
|
|
103
|
+
export async function perform(session, action, signal) {
|
|
104
|
+
if (action.intercept)
|
|
105
|
+
throw new Error("Browser request interception code is disabled");
|
|
106
|
+
const page = session.page;
|
|
107
|
+
const cdp = page.cdp;
|
|
108
|
+
switch (action.action) {
|
|
109
|
+
case "navigate":
|
|
110
|
+
await page.navigate(action.url, signal, action.waitUntil, action.renderMath);
|
|
111
|
+
return await page.summary(signal);
|
|
112
|
+
case "click":
|
|
113
|
+
await page.click(action, signal);
|
|
114
|
+
break;
|
|
115
|
+
case "type":
|
|
116
|
+
case "fill":
|
|
117
|
+
await page.fill(action, signal);
|
|
118
|
+
break;
|
|
119
|
+
case "read":
|
|
120
|
+
return await page.read(action, signal);
|
|
121
|
+
case "evaluate":
|
|
122
|
+
return { result: await page.evaluate(action.expression, signal) };
|
|
123
|
+
case "screenshot": {
|
|
124
|
+
let clip;
|
|
125
|
+
if (action.selector || action.ref) {
|
|
126
|
+
const object = await page.object(action, signal);
|
|
127
|
+
try {
|
|
128
|
+
await page.box(object, signal, false);
|
|
129
|
+
clip = await page.call(object, "function() { const r=this.getBoundingClientRect(); return {x:r.x+scrollX,y:r.y+scrollY,width:r.width,height:r.height,scale:1}; }", signal);
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
await page.release(object);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if (action.fullPage ?? true) {
|
|
136
|
+
const { cssContentSize } = await cdp.send("Page.getLayoutMetrics", {}, signal);
|
|
137
|
+
clip = { ...cssContentSize, scale: 1 };
|
|
138
|
+
}
|
|
139
|
+
const { data } = await cdp.send("Page.captureScreenshot", {
|
|
140
|
+
format: "png",
|
|
141
|
+
fromSurface: true,
|
|
142
|
+
captureBeyondViewport: true,
|
|
143
|
+
...(clip ? { clip } : {}),
|
|
144
|
+
}, signal);
|
|
145
|
+
return { mime: "image/png", dataUrl: `data:image/png;base64,${data}` };
|
|
146
|
+
}
|
|
147
|
+
case "wait": {
|
|
148
|
+
if (!action.until) {
|
|
149
|
+
await delay(action.timeoutMs ?? session.options.actionTimeoutMs ?? 30_000, signal);
|
|
150
|
+
}
|
|
151
|
+
else if (action.until === "selector") {
|
|
152
|
+
const object = await page.object(action, signal);
|
|
153
|
+
try {
|
|
154
|
+
await page.box(object, signal, false);
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
await page.release(object);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else
|
|
161
|
+
await page.wait(action.until, signal);
|
|
162
|
+
return { waitedFor: { ...action, action: undefined } };
|
|
163
|
+
}
|
|
164
|
+
case "mouseMove": {
|
|
165
|
+
const steps = Math.max(1, Math.min(action.steps ?? 1, 100));
|
|
166
|
+
for (let i = 1; i <= steps; i++) {
|
|
167
|
+
await page.mouse({ ...action, x: finite(action.x, "x") * i / steps, y: finite(action.y, "y") * i / steps }, signal, true);
|
|
168
|
+
}
|
|
169
|
+
return { x: action.x, y: action.y, ...(action.steps ? { steps: action.steps } : {}) };
|
|
170
|
+
}
|
|
171
|
+
case "mouseClick":
|
|
172
|
+
await page.mouse(action, signal);
|
|
173
|
+
break;
|
|
174
|
+
case "scroll":
|
|
175
|
+
await cdp.send("Input.dispatchMouseEvent", {
|
|
176
|
+
type: "mouseWheel",
|
|
177
|
+
x: action.x ?? page.width / 2,
|
|
178
|
+
y: action.y ?? page.height / 2,
|
|
179
|
+
deltaX: finite(action.deltaX ?? 0, "deltaX"),
|
|
180
|
+
deltaY: finite(action.deltaY ?? 0, "deltaY"),
|
|
181
|
+
}, signal);
|
|
182
|
+
break;
|
|
183
|
+
case "keyPress":
|
|
184
|
+
await keyPress(cdp, action.key, signal, action.delayMs);
|
|
185
|
+
break;
|
|
186
|
+
case "download":
|
|
187
|
+
return await download(session, page, action, signal);
|
|
188
|
+
case "upload": {
|
|
189
|
+
if (!action.path)
|
|
190
|
+
throw new Error("upload.path is required");
|
|
191
|
+
const file = await stageUpload(session.workdir, action.path, session.staging);
|
|
192
|
+
const objectId = await page.object(action, signal);
|
|
193
|
+
try {
|
|
194
|
+
await cdp.send("DOM.setFileInputFiles", { files: [file], objectId }, signal);
|
|
195
|
+
}
|
|
196
|
+
finally {
|
|
197
|
+
await page.release(objectId);
|
|
198
|
+
}
|
|
199
|
+
return { path: action.path };
|
|
200
|
+
}
|
|
201
|
+
case "web_search":
|
|
202
|
+
return await search(session, action, signal);
|
|
203
|
+
case "back":
|
|
204
|
+
case "forward":
|
|
205
|
+
await page.history(action.action, signal);
|
|
206
|
+
break;
|
|
207
|
+
case "reload":
|
|
208
|
+
await cdp.send("Page.reload", {}, signal);
|
|
209
|
+
await page.wait("domcontentloaded", signal);
|
|
210
|
+
break;
|
|
211
|
+
case "dialog":
|
|
212
|
+
await cdp.send("Page.handleJavaScriptDialog", {
|
|
213
|
+
accept: action.accept === true,
|
|
214
|
+
promptText: action.text ?? "",
|
|
215
|
+
}, signal);
|
|
216
|
+
return { handled: true };
|
|
217
|
+
case "tabs": {
|
|
218
|
+
if (action.operation === "new") {
|
|
219
|
+
await session.newPage(action.url ?? "about:blank", signal);
|
|
220
|
+
}
|
|
221
|
+
else if (action.operation === "select") {
|
|
222
|
+
await session.select(action.tabId, signal);
|
|
223
|
+
}
|
|
224
|
+
else if (action.operation === "close") {
|
|
225
|
+
const id = action.tabId ?? page.id;
|
|
226
|
+
if (!(await session.targets(signal)).some((t) => t.targetId === id)) {
|
|
227
|
+
throw new Error("Unknown tab");
|
|
228
|
+
}
|
|
229
|
+
await session.client().send("Target.closeTarget", { targetId: id }, signal);
|
|
230
|
+
// A closing tab is still listed for a moment: select another, not it.
|
|
231
|
+
const remaining = (await session.targets(signal)).filter((t) => t.targetId !== id);
|
|
232
|
+
if (remaining.length)
|
|
233
|
+
await session.select(remaining[0].targetId, signal);
|
|
234
|
+
else
|
|
235
|
+
await session.newPage("about:blank", signal);
|
|
236
|
+
}
|
|
237
|
+
return {
|
|
238
|
+
tabs: (await session.targets(signal)).map((target) => ({
|
|
239
|
+
id: target.targetId,
|
|
240
|
+
url: target.url,
|
|
241
|
+
title: target.title,
|
|
242
|
+
active: target.targetId === session.page?.id,
|
|
243
|
+
})),
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
case "control":
|
|
247
|
+
return session.control.state();
|
|
248
|
+
case "snapshot":
|
|
249
|
+
return { ...await page.summary(signal), ...await page.snapshot(signal) };
|
|
250
|
+
case "close":
|
|
251
|
+
return { closed: true };
|
|
252
|
+
default:
|
|
253
|
+
throw new Error(`Unsupported browser action ${action.action}`);
|
|
254
|
+
}
|
|
255
|
+
return await page.read({ action: "read" }, signal);
|
|
256
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deadlines, races and queues for the browser engine. Cancellation always
|
|
3
|
+
* reaches the operation underneath; nothing is replayed behind the caller.
|
|
4
|
+
*/
|
|
5
|
+
/** A browser error, with a code its answer carries. */
|
|
6
|
+
export declare function browserError(code: string, message: string): Error & {
|
|
7
|
+
code: string;
|
|
8
|
+
};
|
|
9
|
+
/** Whether an error is the engine's own (it has a code to show). */
|
|
10
|
+
export declare const isBrowserError: (error: unknown) => error is Error & {
|
|
11
|
+
code: string;
|
|
12
|
+
};
|
|
13
|
+
/** An abort signal that fires after `ms`, or with `parent`. */
|
|
14
|
+
export declare function deadline(ms: number, parent?: AbortSignal): {
|
|
15
|
+
signal: AbortSignal;
|
|
16
|
+
dispose(): void;
|
|
17
|
+
};
|
|
18
|
+
/** `task`, unless `signal` aborts first. */
|
|
19
|
+
export declare function race<T>(task: Promise<T>, signal: AbortSignal): Promise<T>;
|
|
20
|
+
/** Waits `ms`, unless `signal` aborts first. */
|
|
21
|
+
export declare function delay(ms: number, signal?: AbortSignal): Promise<void>;
|
|
22
|
+
/** Runs functions one after another. */
|
|
23
|
+
export type Queue = {
|
|
24
|
+
run<T>(fn: () => Promise<T>): Promise<T>;
|
|
25
|
+
};
|
|
26
|
+
export declare function createQueue(): Queue;
|
|
27
|
+
export declare const message: (error: unknown) => string;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deadlines, races and queues for the browser engine. Cancellation always
|
|
3
|
+
* reaches the operation underneath; nothing is replayed behind the caller.
|
|
4
|
+
*/
|
|
5
|
+
/** A browser error, with a code its answer carries. */
|
|
6
|
+
export function browserError(code, message) {
|
|
7
|
+
return Object.assign(new Error(message), { code, browser: true });
|
|
8
|
+
}
|
|
9
|
+
/** Whether an error is the engine's own (it has a code to show). */
|
|
10
|
+
export const isBrowserError = (error) => error instanceof Error && error.browser === true;
|
|
11
|
+
/** An abort signal that fires after `ms`, or with `parent`. */
|
|
12
|
+
export function deadline(ms, parent) {
|
|
13
|
+
const controller = new AbortController();
|
|
14
|
+
const abort = () => controller.abort(parent?.reason);
|
|
15
|
+
parent?.addEventListener("abort", abort, { once: true });
|
|
16
|
+
if (parent?.aborted)
|
|
17
|
+
abort();
|
|
18
|
+
const timer = setTimeout(() => controller.abort(browserError("timeout", "Browser deadline exceeded")), ms);
|
|
19
|
+
return {
|
|
20
|
+
signal: controller.signal,
|
|
21
|
+
dispose() {
|
|
22
|
+
clearTimeout(timer);
|
|
23
|
+
parent?.removeEventListener("abort", abort);
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** `task`, unless `signal` aborts first. */
|
|
28
|
+
export function race(task, signal) {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
const abort = () => reject(signal.reason);
|
|
31
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
32
|
+
task.then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
33
|
+
if (signal.aborted)
|
|
34
|
+
abort();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/** Waits `ms`, unless `signal` aborts first. */
|
|
38
|
+
export function delay(ms, signal) {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
const finish = () => {
|
|
41
|
+
signal?.removeEventListener("abort", abort);
|
|
42
|
+
resolve();
|
|
43
|
+
};
|
|
44
|
+
const timer = setTimeout(finish, ms);
|
|
45
|
+
const abort = () => {
|
|
46
|
+
clearTimeout(timer);
|
|
47
|
+
signal?.removeEventListener("abort", abort);
|
|
48
|
+
reject(signal?.reason);
|
|
49
|
+
};
|
|
50
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
51
|
+
if (signal?.aborted)
|
|
52
|
+
abort();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
export function createQueue() {
|
|
56
|
+
let tail = Promise.resolve();
|
|
57
|
+
return {
|
|
58
|
+
run(fn) {
|
|
59
|
+
const result = tail.then(fn);
|
|
60
|
+
tail = result.catch(() => { });
|
|
61
|
+
return result;
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export const message = (error) => error instanceof Error ? error.message : String(error);
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { Action, Request, Result } from "./types.js";
|
|
2
|
+
export declare function runBatch(request: Request, signal: AbortSignal, actionTimeout: number, execute: (action: Action, signal: AbortSignal) => Promise<Record<string, unknown>>, retire: () => Promise<void>): Promise<Omit<Result, "window">>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A batch of actions, one after another, each within its own timeout. A
|
|
3
|
+
* timeout spoils the batch even when it goes on after errors: what was
|
|
4
|
+
* uncertain is never replayed, and the browser is retired (its Chrome stops,
|
|
5
|
+
* to start again on its next batch).
|
|
6
|
+
*/
|
|
7
|
+
import { deadline, isBrowserError, message, race } from "./async.js";
|
|
8
|
+
export async function runBatch(request, signal, actionTimeout, execute, retire) {
|
|
9
|
+
const result = { success: true, stoppedEarly: false, results: [] };
|
|
10
|
+
for (const [actionIndex, action] of request.actions.entries()) {
|
|
11
|
+
// A bare wait takes its whole time: give it a moment more to finish.
|
|
12
|
+
const ms = (action.timeoutMs ?? actionTimeout) +
|
|
13
|
+
(action.action === "wait" && !action.until ? 100 : 0);
|
|
14
|
+
const limit = deadline(Math.min(ms, 300_000), signal);
|
|
15
|
+
try {
|
|
16
|
+
limit.signal.throwIfAborted();
|
|
17
|
+
const value = await race(execute(action, limit.signal), limit.signal);
|
|
18
|
+
result.results.push({ action: action.action, actionIndex, success: true, ...value });
|
|
19
|
+
if (value.success === false)
|
|
20
|
+
result.success = false;
|
|
21
|
+
if (action.action === "close")
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
result.success = false;
|
|
26
|
+
result.results.push({
|
|
27
|
+
action: action.action,
|
|
28
|
+
actionIndex,
|
|
29
|
+
success: false,
|
|
30
|
+
error: message(error),
|
|
31
|
+
code: isBrowserError(error) ? error.code : signal.aborted ? "aborted" : "action_failed",
|
|
32
|
+
});
|
|
33
|
+
const spoiled = limit.signal.aborted || (isBrowserError(error) && error.code === "timeout");
|
|
34
|
+
if (spoiled)
|
|
35
|
+
await retire().catch(() => { });
|
|
36
|
+
if (spoiled || (request.stopOnError ?? true)) {
|
|
37
|
+
result.stoppedEarly = actionIndex < request.actions.length - 1;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
limit.dispose();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chrome DevTools over a pipe: Chrome reads commands on fd 3 and writes
|
|
3
|
+
* replies and events on fd 4, each a JSON message ending in NUL. No debugging
|
|
4
|
+
* port is opened, so nothing else on the machine can reach this browser.
|
|
5
|
+
*/
|
|
6
|
+
import type { Readable, Writable } from "node:stream";
|
|
7
|
+
export type Params = Record<string, unknown>;
|
|
8
|
+
export type Packet = {
|
|
9
|
+
id?: number;
|
|
10
|
+
method?: string;
|
|
11
|
+
params?: Params;
|
|
12
|
+
result?: Params;
|
|
13
|
+
error?: {
|
|
14
|
+
code: number;
|
|
15
|
+
message: string;
|
|
16
|
+
};
|
|
17
|
+
sessionId?: string;
|
|
18
|
+
};
|
|
19
|
+
/** How packets come and go. */
|
|
20
|
+
export type Wire = {
|
|
21
|
+
send(packet: Packet): Promise<void>;
|
|
22
|
+
/** Hears every packet, then the end (with an error if it broke). */
|
|
23
|
+
listen(packet: (packet: Packet) => void, end: (error?: unknown) => void): void;
|
|
24
|
+
close(): Promise<void>;
|
|
25
|
+
};
|
|
26
|
+
/** Commands and events, for the browser or one of its pages. */
|
|
27
|
+
export type DevTools = {
|
|
28
|
+
send<T = Params>(method: string, params?: Params, signal?: AbortSignal): Promise<T>;
|
|
29
|
+
on<T = Params>(method: string, listener: (params: T) => void): () => void;
|
|
30
|
+
};
|
|
31
|
+
/** A DevTools connection: the browser's, with its pages' sessions. */
|
|
32
|
+
export type Client = DevTools & {
|
|
33
|
+
session(sessionId: string): DevTools;
|
|
34
|
+
readonly closed: boolean;
|
|
35
|
+
close(): Promise<void>;
|
|
36
|
+
};
|
|
37
|
+
/** The pipe protocol on a child's streams: NUL-delimited JSON. */
|
|
38
|
+
export declare function pipeWire(readable: Readable, writable: Writable): Wire;
|
|
39
|
+
/** A DevTools client on `wire`; a command unanswered in `timeoutMs` fails. */
|
|
40
|
+
export declare function createClient(wire: Wire, timeoutMs?: number): Client;
|