@appetize/cli 0.19.0 → 0.20.0
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/CHANGELOG.md +14 -0
- package/LICENSE +1 -0
- package/cli.js +9 -9
- package/config-DfwUvfKT.js +3 -0
- package/daemon.js +1 -1
- package/package.json +3 -3
- package/skills/appetize/SKILL.md +75 -208
- package/skills/appetize/references/commands.md +52 -352
- package/config-D0ukqfLN.js +0 -3
|
@@ -1,396 +1,96 @@
|
|
|
1
1
|
# Command reference
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
same flags at the terminal.
|
|
3
|
+
Behaviour that `appetize <command> --help` does not show. Run that for flags.
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
- [session start](#session-start)
|
|
8
|
-
- [session stop](#session-stop)
|
|
9
|
-
- [build list](#build-list)
|
|
10
|
-
- [build upload](#build-upload)
|
|
11
|
-
- [device list](#device-list)
|
|
12
|
-
- [inspect](#inspect)
|
|
13
|
-
- [tap](#tap)
|
|
14
|
-
- [swipe](#swipe)
|
|
15
|
-
- [type](#type)
|
|
16
|
-
- [press](#press)
|
|
17
|
-
- [rotate](#rotate)
|
|
18
|
-
- [open](#open)
|
|
19
|
-
- [keychain clear](#keychain-clear)
|
|
20
|
-
- [screenshot](#screenshot)
|
|
21
|
-
- [recording start](#recording-start)
|
|
22
|
-
- [recording stop](#recording-stop)
|
|
23
|
-
- [skill install](#skill-install)
|
|
24
|
-
- [Selectors](#selectors)
|
|
25
|
-
- [Environment](#environment)
|
|
26
|
-
- [Exit codes and output streams](#exit-codes-and-output-streams)
|
|
5
|
+
## Output and exit codes
|
|
27
6
|
|
|
28
|
-
|
|
7
|
+
Results go to stdout and hold only what you could not know beforehand; `{}`
|
|
8
|
+
means the command ran. `APPETIZE_OUTPUT` (`json` or `text`) applies when neither
|
|
9
|
+
`--json` nor `--no-json` is passed.
|
|
29
10
|
|
|
30
|
-
|
|
31
|
-
|
|
11
|
+
Failures exit non-zero and print `{ "error": { "message": "…" } }` to stderr,
|
|
12
|
+
plus `hints` when there is something to try, and `sessionDir` once a session is
|
|
13
|
+
found. An expired selector `--timeout` is a failure, which is what makes it a
|
|
14
|
+
wait.
|
|
32
15
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
`--session-id <id>` is accepted by every command except those marked "Takes
|
|
36
|
-
no session". On
|
|
37
|
-
`session start` it names the session being created; everywhere else it picks
|
|
38
|
-
which existing session to act on, defaulting to the sole active one, so pass it
|
|
39
|
-
only when several are running.
|
|
16
|
+
Session directories live under `~/.appetize/cli/sessions/`, or
|
|
17
|
+
`$APPETIZE_CLI_HOME`.
|
|
40
18
|
|
|
41
19
|
## session start
|
|
42
20
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
| `--open` | URL opened once the session is ready |
|
|
53
|
-
| `--proxy` | Proxy traffic: `intercept`, or a custom `http://` url |
|
|
54
|
-
| `--session-id` | Name the session; defaults to a generated 3-word id |
|
|
55
|
-
|
|
56
|
-
Spawns a daemon that holds the session open and prints JSON on stdout. Waiting
|
|
57
|
-
(the default) prints
|
|
58
|
-
`{ adbSerial, baseUrl, controlSocket, logs, sessionId, viewerUrl }`
|
|
59
|
-
once the device is ready; `--no-wait` prints `{ logs, sessionId }` immediately.
|
|
60
|
-
`adbSerial` is present only for an Android session, and only while adb is
|
|
61
|
-
available to it: `adb connect <adbSerial>` attaches to the device until the
|
|
62
|
-
session ends. `viewerUrl` opens the local browser viewer. `logs`
|
|
63
|
-
carries a `device` and a `daemon` path, plus a `network` path — the JSONL capture
|
|
64
|
-
of the app's traffic — when started with `--proxy` (or `--proxy intercept`).
|
|
65
|
-
|
|
66
|
-
Network traffic can be proxied or intercepted for debugging. `--proxy` (or
|
|
67
|
-
`--proxy intercept`) provisions the intercepting proxy so traffic can be
|
|
68
|
-
captured; `--proxy http://host:port` routes through a proxy of your own, and the
|
|
69
|
-
streaming server rejects any other scheme. Interception rewrites TLS, so an app
|
|
70
|
-
that pins certificates may not work under it.
|
|
71
|
-
|
|
72
|
-
`sessionId` is what every other command takes. A generated one looks like
|
|
73
|
-
`tidy-pandas-jump`; a name you pass may use letters, digits, `.`, `-` and `_`,
|
|
74
|
-
and starting a session with an id already in use fails.
|
|
21
|
+
- `--session-id` may use letters, digits, `.`, `-` and `_`. Reusing one fails
|
|
22
|
+
unless `--force` replaces that session.
|
|
23
|
+
- `--no-wait` returns just `sessionId` and `logs`, so you can work while the
|
|
24
|
+
device boots.
|
|
25
|
+
- `adbSerial` appears only while adb is available, and attaches until the
|
|
26
|
+
session ends.
|
|
27
|
+
- `--proxy http://host:port` routes through your own proxy; other schemes are
|
|
28
|
+
rejected. Interception rewrites TLS, so an app that pins certificates may
|
|
29
|
+
fail under it.
|
|
75
30
|
|
|
76
31
|
## session stop
|
|
77
32
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
Signals the daemon to shut down and prints `{ sessionId }`. Reports
|
|
83
|
-
the id even if the daemon had already exited, so it is safe to call twice.
|
|
33
|
+
Waits for the daemon to exit, so logs are complete; `--no-wait` only signals
|
|
34
|
+
it. Safe to call twice.
|
|
84
35
|
|
|
85
36
|
## build list
|
|
86
37
|
|
|
87
|
-
|
|
88
|
-
appetize build list [options]
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
| Flag | Meaning |
|
|
92
|
-
| ------------ | ------------------------------------------- |
|
|
93
|
-
| `--app` | App id to filter by (bundle or package id) |
|
|
94
|
-
| `--endpoint` | Appetize URL; overrides `APPETIZE_ENDPOINT` |
|
|
95
|
-
| `--limit` | Builds per page (default 10, max 200) |
|
|
96
|
-
| `--page` | Page of results to fetch (default 1) |
|
|
97
|
-
|
|
98
|
-
Lists one page of the account's uploaded builds, newest first, printing
|
|
99
|
-
`{ builds, nextPage, total }` on stdout. Each build's `id` is a target
|
|
100
|
-
`session start` takes, alongside `appId`, `platform`, `versionName`,
|
|
101
|
-
`buildNumber` and `created`. Pass a non-null `nextPage` back as `--page` to
|
|
102
|
-
continue. Requires `APPETIZE_API_TOKEN`. Takes no session.
|
|
38
|
+
Newest first. Pass a non-null `nextPage` back as `--page` to continue.
|
|
103
39
|
|
|
104
40
|
## build upload
|
|
105
41
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
| Flag | Meaning |
|
|
111
|
-
| ------------ | --------------------------------------------------- |
|
|
112
|
-
| `--endpoint` | Appetize URL; overrides `APPETIZE_ENDPOINT` |
|
|
113
|
-
| `--note` | Note to store with the build |
|
|
114
|
-
| `--tags` | Comma separated tags to store with the build |
|
|
115
|
-
| `--timeout` | Milliseconds to wait with `--wait` (default 120000) |
|
|
116
|
-
| `--wait` | Wait for the app id and version metadata to resolve |
|
|
117
|
-
|
|
118
|
-
Uploads a `.apk`, `.apks`, `.zip` or `.tar.gz` and prints
|
|
119
|
-
`{ created, id, platform }` on stdout, where `id` is a target `session start`
|
|
120
|
-
takes.
|
|
121
|
-
|
|
122
|
-
The extension decides the platform — `.apk` and `.apks` are Android, `.zip`,
|
|
123
|
-
`.tar.gz` and `.tgz` are iOS — and any other file is refused before uploading.
|
|
124
|
-
|
|
125
|
-
Appetize fills in `appId`, `versionName` and `buildNumber` by processing the
|
|
126
|
-
file after the upload responds, which takes a few seconds and is not needed to
|
|
127
|
-
start a session. `--wait` polls until they appear and prints the full
|
|
128
|
-
`build list` shape, failing once `--timeout` elapses.
|
|
129
|
-
|
|
130
|
-
Requires `APPETIZE_API_TOKEN`. Takes no session.
|
|
42
|
+
The extension decides the platform: `.apk` and `.apks` are Android, `.zip`,
|
|
43
|
+
`.tar.gz` and `.tgz` are iOS. `appId`, `versionName` and `buildNumber` resolve a
|
|
44
|
+
few seconds after upload and are not needed to start a session; `--wait` polls
|
|
45
|
+
for them.
|
|
131
46
|
|
|
132
47
|
## device list
|
|
133
48
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
| Flag | Meaning |
|
|
139
|
-
| ------------ | ------------------------------------------- |
|
|
140
|
-
| `--endpoint` | Appetize URL; overrides `APPETIZE_ENDPOINT` |
|
|
141
|
-
| `--platform` | Platform to filter by: `ios` or `android` |
|
|
142
|
-
|
|
143
|
-
Lists available device models, printing `{ devices }` on stdout. Each device's
|
|
144
|
-
`id` is the `<device-id>` `session start` takes, alongside `name`, `platform`
|
|
145
|
-
and `osVersions` — the values `--device-os-version` accepts. Needs no
|
|
146
|
-
`APPETIZE_API_TOKEN`. Takes no session.
|
|
49
|
+
Needs no `APPETIZE_API_TOKEN`. `osVersions` are the values
|
|
50
|
+
`--device-os-version` accepts.
|
|
147
51
|
|
|
148
52
|
## inspect
|
|
149
53
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
| Flag | Meaning |
|
|
155
|
-
| ----------------------------------------------------- | -------------------------------------------------- |
|
|
156
|
-
| `--select-text`, `--select-test-id`, `--select-index` | Scope to one element — see [Selectors](#selectors) |
|
|
157
|
-
| `--timeout` | Milliseconds to wait for the element |
|
|
158
|
-
| `--pretty` | Indent the JSON |
|
|
159
|
-
|
|
160
|
-
`output` defaults to `inspect.json`; `.json` is added if you omit an extension.
|
|
161
|
-
Writes the hierarchy to that file and prints `{ bytes, nodes, output }` on stdout.
|
|
162
|
-
The JSON is `{ platform, root }`, where each node carries `attributes`, `bounds`
|
|
163
|
-
and `children`. Only currently visible elements appear.
|
|
164
|
-
|
|
165
|
-
Unscoped output on an ordinary screen exceeds 100 KB, so prefer a selector and
|
|
166
|
-
read the file.
|
|
167
|
-
|
|
168
|
-
## tap
|
|
169
|
-
|
|
170
|
-
```
|
|
171
|
-
appetize tap [options]
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
| Flag | Meaning |
|
|
175
|
-
| ------------ | -------------------------------------------------------- |
|
|
176
|
-
| `--select-*` | Element or position to tap — see [Selectors](#selectors) |
|
|
177
|
-
| `--timeout` | Milliseconds to wait for the element |
|
|
178
|
-
|
|
179
|
-
Prints `{}`. Combining an element selector with `--select-x` /
|
|
180
|
-
`--select-y` taps a point within that element, and values outside `0-1` are
|
|
181
|
-
allowed to reach just beyond its edge (e.g. `--select-x=-0.1`).
|
|
182
|
-
|
|
183
|
-
## swipe
|
|
184
|
-
|
|
185
|
-
```
|
|
186
|
-
appetize swipe [options]
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
| Flag | Meaning |
|
|
190
|
-
| ------------- | ------------------------------------------------------ |
|
|
191
|
-
| `--direction` | `down`, `left`, `right` or `up` |
|
|
192
|
-
| `--distance` | Travel as a fraction of the screen (0-1) |
|
|
193
|
-
| `--from-*` | Where the gesture starts — see [Selectors](#selectors) |
|
|
194
|
-
| `--to-*` | Where the gesture ends — see [Selectors](#selectors) |
|
|
195
|
-
| `--duration` | Milliseconds the gesture travels for |
|
|
196
|
-
| `--timeout` | Milliseconds to wait for any `--from`/`--to` elements |
|
|
197
|
-
|
|
198
|
-
Prints `{}`. Two shapes are valid: a `--direction` with an
|
|
199
|
-
optional `--from-*` starting point, or both a `--from-*` and a `--to-*` point to
|
|
200
|
-
form a path. Mixing `--direction` with `--to-*` is an error, as is `--distance`
|
|
201
|
-
without `--direction`.
|
|
54
|
+
Writes `{ platform, root }`, where each node carries `attributes`, `bounds` and
|
|
55
|
+
`children`. `.json` is added if you omit an extension.
|
|
202
56
|
|
|
203
57
|
## type
|
|
204
58
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
| Flag | Meaning |
|
|
210
|
-
| --------- | ---------------------------------- |
|
|
211
|
-
| `--delay` | Milliseconds to wait between steps |
|
|
212
|
-
|
|
213
|
-
Prints `{}`. Bare text is delivered as a string; `{...}` names a
|
|
214
|
-
key delivered as a keystroke. Supported keys: `ArrowDown`, `ArrowLeft`,
|
|
215
|
-
`ArrowRight`, `ArrowUp`, `Backspace`, `Enter`, `Tab`. A token may carry a repeat
|
|
216
|
-
count as in `{Backspace>16/}`, and `{{` types a literal `{`. An unclosed token
|
|
217
|
-
or an unsupported key name fails without typing anything.
|
|
218
|
-
|
|
219
|
-
Typing does not focus a field — tap it first.
|
|
220
|
-
|
|
221
|
-
## press
|
|
222
|
-
|
|
223
|
-
```
|
|
224
|
-
appetize press <button>
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
Prints `{}`. Buttons: `home` and `lock` on both platforms;
|
|
228
|
-
`back`, `menu`, `unlock`, `volumeUp` and `volumeDown` on Android only. Calling
|
|
229
|
-
an Android-only button on iOS fails.
|
|
230
|
-
|
|
231
|
-
There is no keyboard-dismiss action. To dismiss the soft keyboard, see the
|
|
232
|
-
main page.
|
|
233
|
-
|
|
234
|
-
## rotate
|
|
235
|
-
|
|
236
|
-
```
|
|
237
|
-
appetize rotate <orientation>
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
Prints `{}`. Orientations: `portrait`, `landscapeLeft`,
|
|
241
|
-
`landscapeRight`, `upsideDown`.
|
|
59
|
+
Typing does not focus a field — tap it first. `{Backspace>16/}` repeats a key
|
|
60
|
+
and `{{` types a literal `{`. An unclosed token or unknown key fails without
|
|
61
|
+
typing anything.
|
|
242
62
|
|
|
243
63
|
## open
|
|
244
64
|
|
|
245
|
-
|
|
246
|
-
appetize open <url>
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
Prints `{}`. `<url>` is a deep link (`myapp://orders/42`) or an
|
|
250
|
-
http(s) URL. A malformed or scheme-less value is refused.
|
|
251
|
-
|
|
252
|
-
## keychain clear
|
|
253
|
-
|
|
254
|
-
```
|
|
255
|
-
appetize keychain clear
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
Prints `{}`. iOS only: clears the entire keychain. No effect on
|
|
259
|
-
Android.
|
|
260
|
-
|
|
261
|
-
## screenshot
|
|
262
|
-
|
|
263
|
-
```
|
|
264
|
-
appetize screenshot [output]
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
`output` defaults to `screenshot`, and an extension matching the image is added
|
|
268
|
-
if you omit one. Writes a PNG and prints `{ bytes, output }`.
|
|
65
|
+
A scheme-less value is refused. iOS caps URLs at 2048 characters.
|
|
269
66
|
|
|
270
67
|
## recording start
|
|
271
68
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
| Flag | Meaning |
|
|
277
|
-
| --------- | --------------------------------------- |
|
|
278
|
-
| `--force` | Overwrite the file if it already exists |
|
|
279
|
-
|
|
280
|
-
Asks the daemon to open the device video stream and capture it to `output`,
|
|
281
|
-
printing `{ path }`. Capture is opt-in — video is lazy
|
|
282
|
-
device-side, so nothing streams until this runs.
|
|
283
|
-
|
|
284
|
-
`output` is required. `.mp4` is added if you omit an extension, any other
|
|
285
|
-
extension is refused, and the directory must already exist. A relative path
|
|
286
|
-
resolves against your shell rather than the daemon's.
|
|
287
|
-
|
|
288
|
-
Starting while a recording is already running fails, whatever path you name —
|
|
289
|
-
adopting it would hand you a file that began whenever the first call did.
|
|
290
|
-
|
|
291
|
-
The daemon owns the stream and the file, so the command returns as soon as
|
|
292
|
-
capture is running.
|
|
69
|
+
`.mp4` is added if you omit an extension, any other extension is refused, and
|
|
70
|
+
the directory must already exist. Starting while a recording runs fails, as
|
|
71
|
+
does an existing file without `--force`.
|
|
293
72
|
|
|
294
73
|
## recording stop
|
|
295
74
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
Closes the stream and the file, printing `{ path }`. Fails
|
|
301
|
-
with `No video recording in progress` when nothing is recording. Ending the
|
|
302
|
-
session while recording closes the file too, noting it in `daemon.log`.
|
|
303
|
-
|
|
304
|
-
A session that dies unexpectedly still leaves the file playable, losing at most
|
|
305
|
-
the last second.
|
|
306
|
-
|
|
307
|
-
Every frame is written at a constant 30fps, so playback does not track real
|
|
308
|
-
time. A rotation keeps the original dimensions and is noted in `daemon.log`.
|
|
309
|
-
|
|
310
|
-
Recording over an existing file fails unless you pass `--force`, so name a new
|
|
311
|
-
file to record more than once in a session.
|
|
75
|
+
Fails when nothing is recording. Ending the session closes the file too, and a
|
|
76
|
+
session that dies unexpectedly still leaves it playable, losing at most the
|
|
77
|
+
last second. A write failure is reported here, not when it happens.
|
|
312
78
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
A write failure is reported once the recording stops, not when it happens.
|
|
79
|
+
Playback is a constant 30fps, so it does not track real time. A rotation keeps
|
|
80
|
+
the original dimensions.
|
|
317
81
|
|
|
318
82
|
## skill install
|
|
319
83
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
| Flag | Meaning |
|
|
325
|
-
| --------- | -------------------------------------------------------------- |
|
|
326
|
-
| `--agent` | `agents`, `claude`, `codex`, `copilot` or `cursor`; repeatable |
|
|
327
|
-
| `--scope` | `project` (default), or `user` for your home directory |
|
|
328
|
-
|
|
329
|
-
Installs this skill for each agent whose directory is already present — Claude
|
|
330
|
-
Code reads `.claude/skills`, the others `.agents/skills` — and into both when
|
|
331
|
-
none is found. `--agent` names agents directly instead. Takes no session.
|
|
84
|
+
Installs into each agent directory already present — `.claude/skills` for
|
|
85
|
+
Claude Code, `.agents/skills` for the others — and into both when none is.
|
|
332
86
|
|
|
333
87
|
## Selectors
|
|
334
88
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
- `tap --select-*`
|
|
340
|
-
- `swipe --from-*` and `swipe --to-*`
|
|
341
|
-
|
|
342
|
-
Element suffixes, identical under every prefix:
|
|
343
|
-
|
|
344
|
-
| Flag | Meaning |
|
|
345
|
-
| -------------------- | --------------------------------------------------------------------------------------------------------------------- |
|
|
346
|
-
| `--<prefix>-text` | Exact string, or `/regex/flags` such as `/sign in/i` |
|
|
347
|
-
| `--<prefix>-test-id` | Exact match — on Android the whole `resource-id` or the part after its last `/`, on iOS the `accessibilityIdentifier` |
|
|
348
|
-
| `--<prefix>-index` | Which match when several, 0-based |
|
|
349
|
-
|
|
350
|
-
So `inspect --select-text 'Log in'`, `tap --select-test-id save` and
|
|
351
|
-
`swipe --from-test-id card --to-test-id bin` all name elements the same way.
|
|
352
|
-
|
|
353
|
-
Position suffixes, accepted by `tap` and `swipe` (not `inspect`):
|
|
354
|
-
|
|
355
|
-
| Flag | Meaning |
|
|
356
|
-
| ------------------------------ | -------------------------------------------------------------------------------------------- |
|
|
357
|
-
| `--<prefix>-position` | Screen position as `x,y`, each 0-1, e.g. `0.5,0.75` |
|
|
358
|
-
| `--<prefix>-x`, `--<prefix>-y` | Position within the matched element (0-1, negative/>1 to reach outside the selected element) |
|
|
359
|
-
|
|
360
|
-
Pick one kind of match per point. Prefer a test id, then text; reach for a
|
|
361
|
-
position when the target has no identity of its own, such as a canvas or a
|
|
362
|
-
slider track.
|
|
363
|
-
|
|
364
|
-
## Environment
|
|
365
|
-
|
|
366
|
-
| Variable | Meaning |
|
|
367
|
-
| -------------------- | ---------------------------------------------- |
|
|
368
|
-
| `APPETIZE_API_TOKEN` | Authorizes private APIs and session targets |
|
|
369
|
-
| `APPETIZE_ENDPOINT` | Appetize URL used when `--endpoint` is omitted |
|
|
370
|
-
| `APPETIZE_CLI_HOME` | Overrides the session state directory |
|
|
371
|
-
| `APPETIZE_OUTPUT` | `json` or `text` when neither flag is passed |
|
|
372
|
-
|
|
373
|
-
Session state is written to `~/.appetize/cli/sessions/<session-id>/state.json`.
|
|
374
|
-
Device logs stream as JSONL to `device.log.jsonl` beside it, and the daemon's
|
|
375
|
-
own output goes to `daemon.log`.
|
|
376
|
-
|
|
377
|
-
## Exit codes and output streams
|
|
378
|
-
|
|
379
|
-
Commands exit `0` on success and non-zero on failure, printing
|
|
380
|
-
`{ "error": { "message": "…" } }` to stderr (text on a terminal, unless
|
|
381
|
-
`--json`), plus `sessionDir` (the session's
|
|
382
|
-
logs and `state.json`) once a session is found, unless the command was misused.
|
|
383
|
-
A selector `--timeout` that expires is a failure, which is what makes it usable
|
|
384
|
-
as a wait.
|
|
385
|
-
|
|
386
|
-
Results go to stdout as JSON (text on a terminal, unless `--json`) and hold
|
|
387
|
-
only what you could not know beforehand; `{}` means the command ran. stderr
|
|
388
|
-
carries only errors, plus a progress spinner on an interactive terminal.
|
|
389
|
-
|
|
390
|
-
Common failures:
|
|
89
|
+
`inspect --select-*`, `tap --select-*` and `swipe --from-*`/`--to-*` share the
|
|
90
|
+
same suffixes. `-text` is an exact string or `/regex/flags`; `-index` is
|
|
91
|
+
0-based. `-test-id` is an exact match: on Android the whole `resource-id` or the
|
|
92
|
+
part after its last `/`, on iOS the `accessibilityIdentifier`.
|
|
391
93
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
| `No session found for id X` | `endedReason` in the session's `state.json` |
|
|
396
|
-
| `Session is not ready` | `state.phase` in `state.json` under `error.sessionDir` says how far it got |
|
|
94
|
+
Only `tap` and `swipe` take positions. `-position` is a screen `x,y`, each 0-1;
|
|
95
|
+
`-x` and `-y` place the point within the matched element, beyond its edge when
|
|
96
|
+
outside 0-1.
|
package/config-D0ukqfLN.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{Transform as ar}from"stream";import{createRequire as lr}from"module";import{connect as cr}from"node:net";import Fe from"debug";import{JSONRPCServerAndClient as fr,JSONRPCServer as ur,JSONRPCClient as dr,JSONRPC as hr}from"json-rpc-2.0";import{homedir as bt}from"node:os";import{sep as pr,join as te}from"node:path";import{writeFileSync as yr,renameSync as wr,mkdirSync as gt,readFileSync as mr,readdirSync as br}from"node:fs";let ze;try{ze=new TextDecoder}catch{}let p,V,c=0;const je=[],gr=105,Er=57342,Sr=57343,Et=57337,St=6,fe={};let me=11281e4,Y=1681e4,re=je,be=0,k={},_,ge,Ee=0,se=0,N,q,D=[],Ve=[],K,j,Se,vt={useRecords:!1,mapsAsObjects:!0},ve=!1,At=2;try{new Function("")}catch{At=1/0}class pe{constructor(e){if(e&&((e.keyMap||e._keyMap)&&!e.useRecords&&(e.useRecords=!1,e.mapsAsObjects=!0),e.useRecords===!1&&e.mapsAsObjects===void 0&&(e.mapsAsObjects=!0),e.getStructures&&(e.getShared=e.getStructures),e.getShared&&!e.structures&&((e.structures=[]).uninitialized=!0),e.keyMap)){this.mapKey=new Map;for(let[r,s]of Object.entries(e.keyMap))this.mapKey.set(s,r)}Object.assign(this,e)}decodeKey(e){return this.keyMap&&this.mapKey.get(e)||e}encodeKey(e){return this.keyMap&&this.keyMap.hasOwnProperty(e)?this.keyMap[e]:e}encodeKeys(e){if(!this._keyMap)return e;let r=new Map;for(let[s,n]of Object.entries(e))r.set(this._keyMap.hasOwnProperty(s)?this._keyMap[s]:s,n);return r}decodeKeys(e){if(!this._keyMap||e.constructor.name!="Map")return e;if(!this._mapKey){this._mapKey=new Map;for(let[s,n]of Object.entries(this._keyMap))this._mapKey.set(n,s)}let r={};return e.forEach((s,n)=>r[J(this._mapKey.has(n)?this._mapKey.get(n):n)]=s),r}mapDecode(e,r){let s=this.decode(e);return this._keyMap&&s.constructor.name==="Array"?s.map(n=>this.decodeKeys(n)):s}decode(e,r){if(p)return Tt(()=>(Je(),this?this.decode(e,r):pe.prototype.decode.call(vt,e,r)));V=r>-1?r:e.length,c=0,be=0,se=0,ge=null,re=je,N=null,p=e;try{j=e.dataView||(e.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength))}catch(s){throw p=null,e instanceof Uint8Array?s:new Error("Source must be a Uint8Array or Buffer but was a "+(e&&typeof e=="object"?e.constructor.name:typeof e))}if(this instanceof pe){if(k=this,K=this.sharedValues&&(this.pack?new Array(this.maxPrivatePackedValues||16).concat(this.sharedValues):this.sharedValues),this.structures)return _=this.structures,Ie();(!_||_.length>0)&&(_=[])}else k=vt,(!_||_.length>0)&&(_=[]),K=null;return Ie()}decodeMultiple(e,r){let s,n=0;try{let o=e.length;ve=!0;let f=this?this.decode(e,o):Ge.decode(e,o);if(r){if(r(f)===!1)return;for(;c<o;)if(n=c,r(Ie())===!1)return}else{for(s=[f];c<o;)n=c,s.push(Ie());return s}}catch(o){throw o.lastPosition=n,o.values=s,o}finally{ve=!1,Je()}}}function Ie(){try{let t=I();if(N){if(c>=N.postBundlePosition){let e=new Error("Unexpected bundle position");throw e.incomplete=!0,e}c=N.postBundlePosition,N=null}if(c==V)_=null,p=null,q&&(q=null);else if(c>V){let e=new Error("Unexpected end of CBOR data");throw e.incomplete=!0,e}else if(!ve)throw new Error("Data read, but end of buffer not reached");return t}catch(t){throw Je(),(t instanceof RangeError||t.message.startsWith("Unexpected end of buffer"))&&(t.incomplete=!0),t}}function ne(){let t=new Error("Unexpected end of CBOR data");return t.incomplete=!0,t}function I(){if(!(c<V))throw ne();let t=p[c++],e=t>>5;if(t=t&31,t>23)switch(t){case 24:if(c>=V)throw ne();t=p[c++];break;case 25:if(e==7)return kr();t=j.getUint16(c),c+=2;break;case 26:if(e==7){let r=j.getFloat32(c);if(k.useFloat32>2){let s=We[(p[c]&127)<<1|p[c+1]>>7];return c+=4,(s*r+(r>0?.5:-.5)>>0)/s}return c+=4,r}if(t=j.getUint32(c),c+=4,e===1)return-1-t;break;case 27:if(e==7){let r=j.getFloat64(c);return c+=8,r}if(e>1){if(j.getUint32(c)>0)throw new Error("JavaScript does not support arrays, maps, or strings with length over 4294967295");t=j.getUint32(c+4)}else k.int64AsNumber?(t=j.getUint32(c)*4294967296,t+=j.getUint32(c+4)):t=j.getBigUint64(c);c+=8;break;case 31:switch(e){case 2:case 3:throw new Error("Indefinite length not supported for byte or text strings");case 4:let r=[],s,n=0;for(;(s=I())!=fe;){if(n>=me)throw new Error(`Array length exceeds ${me}`);r[n++]=s}return e==4?r:e==3?r.join(""):Buffer.concat(r);case 5:let o;if(k.mapsAsObjects){let f={},m=0;if(k.keyMap)for(;(o=I())!=fe;){if(m++>=Y)throw new Error(`Property count exceeds ${Y}`);f[J(k.decodeKey(o))]=I()}else for(;(o=I())!=fe;){if(m++>=Y)throw new Error(`Property count exceeds ${Y}`);f[J(o)]=I()}return f}else{Se&&(k.mapsAsObjects=!0,Se=!1);let f=new Map;if(k.keyMap){let m=0;for(;(o=I())!=fe;){if(m++>=Y)throw new Error(`Map size exceeds ${Y}`);f.set(k.decodeKey(o),I())}}else{let m=0;for(;(o=I())!=fe;){if(m++>=Y)throw new Error(`Map size exceeds ${Y}`);f.set(o,I())}}return f}case 7:return fe;default:throw new Error("Invalid major type for indefinite length "+e)}default:throw new Error("Unknown token "+t)}switch(e){case 0:return t;case 1:return~t;case 2:return Or(t);case 3:if(se>=c)return ge.slice(c-Ee,(c+=t)-Ee);if(se==0&&V<140&&t<32){let n=t<16?It(t):Ar(t);if(n!=null)return n}return kt(t);case 4:if(t>=me)throw new Error(`Array length exceeds ${me}`);if(t>V-c)throw ne();let r=new Array(t);for(let n=0;n<t;n++)r[n]=I();return r;case 5:if(t>=Y)throw new Error(`Map size exceeds ${me}`);if(t>(V-c)/2)throw ne();if(k.mapsAsObjects){let n={};if(k.keyMap)for(let o=0;o<t;o++)n[J(k.decodeKey(I()))]=I();else for(let o=0;o<t;o++)n[J(I())]=I();return n}else{Se&&(k.mapsAsObjects=!0,Se=!1);let n=new Map;if(k.keyMap)for(let o=0;o<t;o++)n.set(k.decodeKey(I()),I());else for(let o=0;o<t;o++)n.set(I(),I());return n}case 6:if(t>=Et){let n=_[t&8191];if(n)return n.read||(n.read=Ke(n)),n.read();if(t<65536){if(t==Sr){let o=de(),f=I(),m=I();$e(f,m);let y={};if(k.keyMap)for(let v=2;v<o;v++){let g=k.decodeKey(m[v-2]);y[J(g)]=I()}else for(let v=2;v<o;v++){let g=m[v-2];y[J(g)]=I()}return y}else if(t==Er){let o=de(),f=I();for(let m=2;m<o;m++)$e(f++,I());return I()}else if(t==Et)return Cr();if(k.getShared&&(qe(),n=_[t&8191],n))return n.read||(n.read=Ke(n)),n.read()}}let s=D[t];if(s)return s.handlesRead?s(I):s(I());{let n=I();for(let o=0;o<Ve.length;o++){let f=Ve[o](t,n);if(f!==void 0)return f}return new ie(n,t)}case 7:switch(t){case 20:return!1;case 21:return!0;case 22:return null;case 23:return;default:let n=(K||oe())[t];if(n!==void 0)return n;throw new Error("Unknown token "+t)}default:throw isNaN(t)?ne():new Error("Unknown CBOR token "+t)}}const Ot=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function Ke(t){if(!t)throw new Error("Structure is required in record definition");function e(){let r=p[c++];if(r=r&31,r>23)switch(r){case 24:r=p[c++];break;case 25:r=j.getUint16(c),c+=2;break;case 26:r=j.getUint32(c),c+=4;break;default:throw new Error("Expected array header, but got "+p[c-1])}let s=this.compiledReader;for(;s;){if(s.propertyCount===r)return s(I);s=s.next}if(this.slowReads++>=At){let o=this.length==r?this:this.slice(0,r);return s=k.keyMap?new Function("r","return {"+o.map(f=>k.decodeKey(f)).map(f=>Ot.test(f)?J(f)+":r()":"["+JSON.stringify(f)+"]:r()").join(",")+"}"):new Function("r","return {"+o.map(f=>Ot.test(f)?J(f)+":r()":"["+JSON.stringify(f)+"]:r()").join(",")+"}"),this.compiledReader&&(s.next=this.compiledReader),s.propertyCount=r,this.compiledReader=s,s(I)}let n={};if(k.keyMap)for(let o=0;o<r;o++)n[J(k.decodeKey(this[o]))]=I();else for(let o=0;o<r;o++)n[J(this[o])]=I();return n}return t.slowReads=0,e}function J(t){if(typeof t=="string")return t==="__proto__"?"__proto_":t;if(typeof t=="number"||typeof t=="boolean"||typeof t=="bigint")return t.toString();if(t==null)return t+"";throw new Error("Invalid property name type "+typeof t)}let kt=xe;function vr(t){kt=e();function e(r){return function(n){let o=re[be++];if(o==null){if(N)return xe(n);let m=t(c,V,n,p);if(typeof m=="string")o=m,re=je;else if(re=m,be=1,se=1,o=re[0],o===void 0)throw new Error("Unexpected end of buffer")}let f=o.length;return f<=n?(c+=n,o):(ge=o,Ee=c,se=c+f,c+=n,o.slice(0,n))}}}function xe(t){let e;if(t<16&&(e=It(t)))return e;if(t>64&&ze)return ze.decode(p.subarray(c,c+=t));const r=c+t,s=[];for(e="";c<r;){const n=p[c++];if((n&128)===0)s.push(n);else if((n&224)===192)if(n<194||c>=r||(p[c]&192)!==128)s.push(65533);else{const o=p[c++]&63;s.push((n&31)<<6|o)}else if((n&240)===224){const o=c<r?p[c]:0;if(c>=r||(o&192)!==128||n===224&&o<160||n===237&&o>=160)s.push(65533);else if(c++,c>=r||(p[c]&192)!==128)s.push(65533);else{const f=p[c++]&63;s.push((n&31)<<12|(o&63)<<6|f)}}else if((n&248)===240){const o=c<r?p[c]:0;if(n>244||c>=r||(o&192)!==128||n===240&&o<144||n===244&&o>=144)s.push(65533);else if(c++,c>=r||(p[c]&192)!==128)s.push(65533);else{const f=p[c++]&63;if(c>=r||(p[c]&192)!==128)s.push(65533);else{const m=p[c++]&63;let y=(n&7)<<18|(o&63)<<12|f<<6|m;y-=65536,s.push(y>>>10&1023|55296),s.push(56320|y&1023)}}}else s.push(65533);s.length>=4096&&(e+=F.apply(String,s),s.length=0)}return s.length>0&&(e+=F.apply(String,s)),e}let F=String.fromCharCode;function Ar(t){let e=c,r=new Array(t);for(let s=0;s<t;s++){const n=p[c++];if((n&128)>0){c=e;return}r[s]=n}return F.apply(String,r)}function It(t){if(t<4)if(t<2){if(t===0)return"";{let e=p[c++];if((e&128)>1){c-=1;return}return F(e)}}else{let e=p[c++],r=p[c++];if((e&128)>0||(r&128)>0){c-=2;return}if(t<3)return F(e,r);let s=p[c++];if((s&128)>0){c-=3;return}return F(e,r,s)}else{let e=p[c++],r=p[c++],s=p[c++],n=p[c++];if((e&128)>0||(r&128)>0||(s&128)>0||(n&128)>0){c-=4;return}if(t<6){if(t===4)return F(e,r,s,n);{let o=p[c++];if((o&128)>0){c-=5;return}return F(e,r,s,n,o)}}else if(t<8){let o=p[c++],f=p[c++];if((o&128)>0||(f&128)>0){c-=6;return}if(t<7)return F(e,r,s,n,o,f);let m=p[c++];if((m&128)>0){c-=7;return}return F(e,r,s,n,o,f,m)}else{let o=p[c++],f=p[c++],m=p[c++],y=p[c++];if((o&128)>0||(f&128)>0||(m&128)>0||(y&128)>0){c-=8;return}if(t<10){if(t===8)return F(e,r,s,n,o,f,m,y);{let v=p[c++];if((v&128)>0){c-=9;return}return F(e,r,s,n,o,f,m,y,v)}}else if(t<12){let v=p[c++],g=p[c++];if((v&128)>0||(g&128)>0){c-=10;return}if(t<11)return F(e,r,s,n,o,f,m,y,v,g);let M=p[c++];if((M&128)>0){c-=11;return}return F(e,r,s,n,o,f,m,y,v,g,M)}else{let v=p[c++],g=p[c++],M=p[c++],R=p[c++];if((v&128)>0||(g&128)>0||(M&128)>0||(R&128)>0){c-=12;return}if(t<14){if(t===12)return F(e,r,s,n,o,f,m,y,v,g,M,R);{let L=p[c++];if((L&128)>0){c-=13;return}return F(e,r,s,n,o,f,m,y,v,g,M,R,L)}}else{let L=p[c++],U=p[c++];if((L&128)>0||(U&128)>0){c-=14;return}if(t<15)return F(e,r,s,n,o,f,m,y,v,g,M,R,L,U);let P=p[c++];if((P&128)>0){c-=15;return}return F(e,r,s,n,o,f,m,y,v,g,M,R,L,U,P)}}}}}function Or(t){return k.copyBuffers?Uint8Array.prototype.slice.call(p,c,c+=t):p.subarray(c,c+=t)}let xt=new Float32Array(1),Me=new Uint8Array(xt.buffer,0,4);function kr(){let t=p[c++],e=p[c++],r=(t&127)>>2;if(r===31)return e||t&3?NaN:t&128?-1/0:1/0;if(r===0){let s=((t&3)<<8|e)/16777216;return t&128?-s:s}return Me[3]=t&128|(r>>1)+56,Me[2]=(t&7)<<5|e>>3,Me[1]=e<<5,Me[0]=0,xt[0]}new Array(4096);class ie{constructor(e,r){this.value=e,this.tag=r}}D[0]=t=>new Date(t),D[1]=t=>new Date(Math.round(t*1e3)),D[2]=t=>{let e=BigInt(0);for(let r=0,s=t.byteLength;r<s;r++)e=BigInt(t[r])+(e<<BigInt(8));return e},D[3]=t=>BigInt(-1)-D[2](t),D[4]=t=>+(t[1]+"e"+t[0]),D[5]=t=>t[1]*Math.exp(t[0]*Math.log(2));const $e=(t,e)=>{t=t-57344;let r=_[t];r&&r.isShared&&((_.restoreStructures||(_.restoreStructures=[]))[t]=r),_[t]=e,e.read=Ke(e)};D[gr]=t=>{let e=t.length,r=t[1];$e(t[0],r);let s={};for(let n=2;n<e;n++){let o=r[n-2];s[J(o)]=t[n]}return s},D[14]=t=>N?N[0].slice(N.position0,N.position0+=t):new ie(t,14),D[15]=t=>N?N[1].slice(N.position1,N.position1+=t):new ie(t,15);let Ir={Error,RegExp};D[27]=t=>(Ir[t[0]]||Error)(t[1],t[2]);const Mt=t=>{if(p[c++]!=132){let r=new Error("Packed values structure must be followed by a 4 element array");throw p.length<c&&(r.incomplete=!0),r}let e=t();if(!e||!e.length){let r=new Error("Packed values structure must be followed by a 4 element array");throw r.incomplete=!0,r}return K=K?e.concat(K.slice(e.length)):e,K.prefixes=t(),K.suffixes=t(),t()};Mt.handlesRead=!0,D[51]=Mt,D[St]=t=>{if(!K)if(k.getShared)qe();else return new ie(t,St);if(typeof t=="number")return K[16+(t>=0?2*t:-2*t-1)];let e=new Error("No support for non-integer packed references yet");throw t===void 0&&(e.incomplete=!0),e},D[28]=t=>{q||(q=new Map,q.id=0);let e=q.id++,r=c,s=p[c],n;s>>5==4?n=[]:n={};let o={target:n};q.set(e,o);let f=t();return o.used?(Object.getPrototypeOf(n)!==Object.getPrototypeOf(f)&&(c=r,n=f,q.set(e,{target:n}),f=t()),Object.assign(n,f)):(o.target=f,f)},D[28].handlesRead=!0,D[29]=t=>{let e=q.get(t);return e.used=!0,e.target},D[258]=t=>new Set(t),(D[259]=t=>(k.mapsAsObjects&&(k.mapsAsObjects=!1,Se=!0),t())).handlesRead=!0;function ue(t,e){return typeof t=="string"?t+e:t instanceof Array?t.concat(e):Object.assign({},t,e)}function oe(){if(!K)if(k.getShared)qe();else throw new Error("No packed values available");return K}const xr=1399353956;Ve.push((t,e)=>{if(t>=225&&t<=255)return ue(oe().prefixes[t-224],e);if(t>=28704&&t<=32767)return ue(oe().prefixes[t-28672],e);if(t>=1879052288&&t<=2147483647)return ue(oe().prefixes[t-1879048192],e);if(t>=216&&t<=223)return ue(e,oe().suffixes[t-216]);if(t>=27647&&t<=28671)return ue(e,oe().suffixes[t-27639]);if(t>=1811940352&&t<=1879048191)return ue(e,oe().suffixes[t-1811939328]);if(t==xr)return{packedValues:K,structures:_.slice(0),version:e};if(t==55799)return e});const Mr=new Uint8Array(new Uint16Array([1]).buffer)[0]==1,Rt=[Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,typeof BigUint64Array>"u"?{name:"BigUint64Array"}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array>"u"?{name:"BigInt64Array"}:BigInt64Array,Float32Array,Float64Array],Rr=[64,68,69,70,71,72,77,78,79,85,86];for(let t=0;t<Rt.length;t++)Tr(Rt[t],Rr[t]);function Tr(t,e){let r="get"+t.name.slice(0,-5),s;typeof t=="function"?s=t.BYTES_PER_ELEMENT:t=null;for(let n=0;n<2;n++){if(!n&&s==1)continue;let o=s==2?1:s==4?2:s==8?3:0;D[n?e:e-4]=s==1||n==Mr?f=>{if(!t)throw new Error("Could not find typed array for code "+e);return!k.copyBuffers&&(s===1||s===2&&!(f.byteOffset&1)||s===4&&!(f.byteOffset&3)||s===8&&!(f.byteOffset&7))?new t(f.buffer,f.byteOffset,f.byteLength>>o):new t(Uint8Array.prototype.slice.call(f,0).buffer)}:f=>{if(!t)throw new Error("Could not find typed array for code "+e);let m=new DataView(f.buffer,f.byteOffset,f.byteLength),y=f.length>>o,v=new t(y),g=m[r];for(let M=0;M<y;M++)v[M]=g.call(m,M<<o,n);return v}}}function Cr(){let t=de(),e=c+I();for(let s=2;s<t;s++){let n=de();c+=n}let r=c;return c=e,N=[xe(de()),xe(de())],N.position0=0,N.position1=0,N.postBundlePosition=c,c=r,I()}function de(){if(!(c<V))throw ne();let t=p[c++]&31;if(t>23)switch(t){case 24:if(c>=V)throw ne();t=p[c++];break;case 25:t=j.getUint16(c),c+=2;break;case 26:t=j.getUint32(c),c+=4;break}return t}function qe(){if(k.getShared){let t=Tt(()=>(p=null,k.getShared()))||{},e=t.structures||[];k.sharedVersion=t.version,K=k.sharedValues=t.packedValues,_===!0?k.structures=_=e:_.splice.apply(_,[0,e.length].concat(e))}}function Tt(t){let e=V,r=c,s=be,n=Ee,o=se,f=ge,m=re,y=q,v=N,g=new Uint8Array(p.slice(0,V)),M=_,R=k,L=ve,U=t();return V=e,c=r,be=s,Ee=n,se=o,ge=f,re=m,q=y,N=v,p=g,ve=L,_=M,k=R,j=new DataView(p.buffer,p.byteOffset,p.byteLength),U}function Je(){p=null,q=null,_=null}const We=new Array(147);for(let t=0;t<256;t++)We[t]=+("1e"+Math.floor(45.15-t*.30103));let Ge=new pe({useRecords:!1});const Pr=Ge.decode;Ge.decodeMultiple;let Re;try{Re=new TextEncoder}catch{}let He,Ct;const Te=typeof globalThis=="object"&&globalThis.Buffer,Ae=typeof Te<"u",Ze=Ae?Te.allocUnsafeSlow:Uint8Array,Pt=Ae?Te:Uint8Array,Ut=256,Lt=Ae?4294967296:2144337920;let Ye,l,C,i=0,Q,B=null;const Ur=61440,Lr=/[\u0080-\uFFFF]/,$=Symbol("record-id");class _t extends pe{constructor(e){super(e),this.offset=0;let r,s,n,o,f;e=e||{};let m=Pt.prototype.utf8Write?function(a,w){return l.utf8Write(a,w,l.byteLength-w)}:Re&&Re.encodeInto?function(a,w){return Re.encodeInto(a,l.subarray(w)).written}:!1,y=this,v=e.structures||e.saveStructures,g=e.maxSharedStructures;if(g==null&&(g=v?128:0),g>8190)throw new Error("Maximum maxSharedStructure is 8190");let M=e.sequential;M&&(g=0),this.structures||(this.structures=[]),this.saveStructures&&(this.saveShared=this.saveStructures);let R,L,U=e.sharedValues,P;if(U){P=Object.create(null);for(let a=0,w=U.length;a<w;a++)P[U[a]]=a}let W=[],ye=0,G=0;this.mapEncode=function(a,w){return this._keyMap&&!this._mapped&&a.constructor.name==="Array"&&(a=a.map(d=>this.encodeKeys(d))),this.encode(a,w)},this.encode=function(a,w){if(l||(l=new Ze(8192),C=new DataView(l.buffer,0,8192),i=0),Q=l.length-10,Q-i<2048?(l=new Ze(l.length),C=new DataView(l.buffer,0,l.length),Q=l.length-10,i=0):w===Ft&&(i=i+7&2147483640),r=i,y.useSelfDescribedHeader&&(C.setUint32(i,3654940416),i+=3),f=y.structuredClone?new Map:null,y.bundleStrings&&typeof a!="string"?(B=[],B.size=1/0):B=null,s=y.structures,s){if(s.uninitialized){let h=y.getShared()||{};y.structures=s=h.structures||[],y.sharedVersion=h.version;let u=y.sharedValues=h.packedValues;if(u){P={};for(let b=0,E=u.length;b<E;b++)P[u[b]]=b}}let d=s.length;if(d>g&&!M&&(d=g),!s.transitions){s.transitions=Object.create(null);for(let h=0;h<d;h++){let u=s[h];if(!u)continue;let b,E=s.transitions;for(let S=0,A=u.length;S<A;S++){E[$]===void 0&&(E[$]=h);let x=u[S];b=E[x],b||(b=E[x]=Object.create(null)),E=b}E[$]=h|1048576}}M||(s.nextId=d)}if(n&&(n=!1),o=s||[],L=P,e.pack){let d=new Map;if(d.values=[],d.encoder=y,d.maxValues=e.maxPrivatePackedValues||(P?16:1/0),d.objectMap=P||!1,d.samplingPackedValues=R,Ce(a,d),d.values.length>0){l[i++]=216,l[i++]=51,H(4);let h=d.values;O(h),H(0),H(0),L=Object.create(P||null);for(let u=0,b=h.length;u<b;u++)L[h[u]]=u}}Ye=w&tt;try{if(Ye)return;if(O(a),B&&Bt(r,O),y.offset=i,f&&f.idsToInsert){i+=f.idsToInsert.length*2,i>Q&&le(i),y.offset=i;let d=Dr(l.subarray(r,i),f.idsToInsert);return f=null,d}return w&Ft?(l.start=r,l.end=i,l):l.subarray(r,i)}finally{if(s){if(G<10&&G++,s.length>g&&(s.length=g),ye>1e4)s.transitions=null,G=0,ye=0,W.length>0&&(W=[]);else if(W.length>0&&!M){for(let d=0,h=W.length;d<h;d++)W[d][$]=void 0;W=[]}}if(n&&y.saveShared){y.structures.length>g&&(y.structures=y.structures.slice(0,g));let d=l.subarray(r,i);return y.updateSharedData()===!1?y.encode(a):d}w&Fr&&(i=r)}},this.findCommonStringsToPack=()=>(R=new Map,P||(P=Object.create(null)),a=>{let w=a&&a.threshold||4,d=this.pack?a.maxPrivatePackedValues||16:0;U||(U=this.sharedValues=[]);for(let[h,u]of R)u.count>w&&(P[h]=d++,U.push(h),n=!0);for(;this.saveShared&&this.updateSharedData()===!1;);R=null});const O=a=>{i>Q&&(l=le(i));var w=typeof a,d;if(w==="string"){if(L){let E=L[a];if(E>=0){E<16?l[i++]=E+224:(l[i++]=198,E&1?O(15-E>>1):O(E-16>>1));return}else if(R&&!e.pack){let S=R.get(a);S?S.count++:R.set(a,{count:1})}}let h=a.length;if(B&&h>=4&&h<1024){if((B.size+=h)>Ur){let S,A=(B[0]?B[0].length*3+B[1].length:0)+10;i+A>Q&&(l=le(i+A)),l[i++]=217,l[i++]=223,l[i++]=249,l[i++]=B.position?132:130,l[i++]=26,S=i-r,i+=4,B.position&&Bt(r,O),B=["",""],B.size=0,B.position=S}let E=Lr.test(a);B[E?0:1]+=a,l[i++]=E?206:207,O(h);return}let u;h<32?u=1:h<256?u=2:h<65536?u=3:u=5;let b=h*3;if(i+b>Q&&(l=le(i+b)),h<64||!m){let E,S,A,x=i+u;for(E=0;E<h;E++)S=a.charCodeAt(E),S<128?l[x++]=S:S<2048?(l[x++]=S>>6|192,l[x++]=S&63|128):(S&64512)===55296&&((A=a.charCodeAt(E+1))&64512)===56320?(S=65536+((S&1023)<<10)+(A&1023),E++,l[x++]=S>>18|240,l[x++]=S>>12&63|128,l[x++]=S>>6&63|128,l[x++]=S&63|128):(l[x++]=S>>12|224,l[x++]=S>>6&63|128,l[x++]=S&63|128);d=x-i-u}else d=m(a,i+u,b);d<24?l[i++]=96|d:d<256?(u<2&&l.copyWithin(i+2,i+1,i+1+d),l[i++]=120,l[i++]=d):d<65536?(u<3&&l.copyWithin(i+3,i+2,i+2+d),l[i++]=121,l[i++]=d>>8,l[i++]=d&255):(u<5&&l.copyWithin(i+5,i+3,i+3+d),l[i++]=122,C.setUint32(i,d),i+=4),i+=d}else if(w==="number")if(!this.alwaysUseFloat&&a>>>0===a)a<24?l[i++]=a:a<256?(l[i++]=24,l[i++]=a):a<65536?(l[i++]=25,l[i++]=a>>8,l[i++]=a&255):(l[i++]=26,C.setUint32(i,a),i+=4);else if(!this.alwaysUseFloat&&a>>0===a)a>=-24?l[i++]=31-a:a>=-256?(l[i++]=56,l[i++]=~a):a>=-65536?(l[i++]=57,C.setUint16(i,~a),i+=2):(l[i++]=58,C.setUint32(i,~a),i+=4);else if(!this.alwaysUseFloat&&a<0&&a>=-4294967296&&Math.floor(a)===a)l[i++]=58,C.setUint32(i,-1-a),i+=4;else{let h;if((h=this.useFloat32)>0&&a<4294967296&&a>=-2147483648){l[i++]=250,C.setFloat32(i,a);let u;if(h<4||(u=a*We[(l[i]&127)<<1|l[i+1]>>7])>>0===u){i+=4;return}else i--}l[i++]=251,C.setFloat64(i,a),i+=8}else if(w==="object")if(!a)l[i++]=246;else{if(f){let u=f.get(a);if(u){if(l[i++]=216,l[i++]=29,l[i++]=25,!u.references){let b=f.idsToInsert||(f.idsToInsert=[]);u.references=[],b.push(u)}u.references.push(i-r),i+=2;return}else f.set(a,{offset:i-r})}let h=a.constructor;if(h===Object)this.skipFunction===!0&&(a=Object.fromEntries([...Object.keys(a).filter(u=>typeof a[u]!="function").map(u=>[u,a[u]])])),z(a);else if(h===Array){d=a.length,d<24?l[i++]=128|d:H(d);for(let u=0;u<d;u++)O(a[u])}else if(h===Map)if((this.mapsAsObjects?this.useTag259ForMaps!==!1:this.useTag259ForMaps)&&(l[i++]=217,l[i++]=1,l[i++]=3),d=a.size,d<24?l[i++]=160|d:d<256?(l[i++]=184,l[i++]=d):d<65536?(l[i++]=185,l[i++]=d>>8,l[i++]=d&255):(l[i++]=186,C.setUint32(i,d),i+=4),y.keyMap)for(let[u,b]of a)O(y.encodeKey(u)),O(b);else for(let[u,b]of a)O(u),O(b);else{for(let u=0,b=He.length;u<b;u++){let E=Ct[u];if(a instanceof E){let S=He[u],A=S.tag;A==null&&(A=S.getTag&&S.getTag.call(this,a)),A<24?l[i++]=192|A:A<256?(l[i++]=216,l[i++]=A):A<65536?(l[i++]=217,l[i++]=A>>8,l[i++]=A&255):A>-1&&(l[i++]=218,C.setUint32(i,A),i+=4),S.encode.call(this,a,O,le);return}}if(a[Symbol.iterator]){if(Ye){let u=new Error("Iterable should be serialized as iterator");throw u.iteratorNotHandled=!0,u}l[i++]=159;for(let u of a)O(u);l[i++]=255;return}if(a[Symbol.asyncIterator]||Xe(a)){let u=new Error("Iterable/blob should be serialized as iterator");throw u.iteratorNotHandled=!0,u}if(this.useToJSON&&a.toJSON){const u=a.toJSON();if(u!==a)return O(u)}z(a)}}else if(w==="boolean")l[i++]=a?245:244;else if(w==="bigint"){if(a<BigInt(1)<<BigInt(64)&&a>=0)l[i++]=27,C.setBigUint64(i,a);else if(a>-(BigInt(1)<<BigInt(64))&&a<0)l[i++]=59,C.setBigUint64(i,-a-BigInt(1));else if(this.largeBigIntToFloat)l[i++]=251,C.setFloat64(i,Number(a));else{a>=BigInt(0)?l[i++]=194:(l[i++]=195,a=BigInt(-1)-a);let h=[];for(;a;)h.push(Number(a&BigInt(255))),a>>=BigInt(8);Qe(new Uint8Array(h.reverse()),le);return}i+=8}else if(w==="undefined")l[i++]=247;else throw new Error("Unknown type: "+w)},z=this.useRecords===!1?this.variableMapSize?a=>{let w=Object.keys(a),d=Object.values(a),h=w.length;if(h<24?l[i++]=160|h:h<256?(l[i++]=184,l[i++]=h):h<65536?(l[i++]=185,l[i++]=h>>8,l[i++]=h&255):(l[i++]=186,C.setUint32(i,h),i+=4),y.keyMap)for(let u=0;u<h;u++)O(y.encodeKey(w[u])),O(d[u]);else for(let u=0;u<h;u++)O(w[u]),O(d[u])}:a=>{l[i++]=185;let w=i-r;i+=2;let d=0;if(y.keyMap)for(let h in a)(typeof a.hasOwnProperty!="function"||a.hasOwnProperty(h))&&(O(y.encodeKey(h)),O(a[h]),d++);else for(let h in a)(typeof a.hasOwnProperty!="function"||a.hasOwnProperty(h))&&(O(h),O(a[h]),d++);l[w+++r]=d>>8,l[w+r]=d&255}:(a,w)=>{let d,h=o.transitions||(o.transitions=Object.create(null)),u=0,b=0,E,S;if(this.keyMap){S=Object.keys(a).map(x=>this.encodeKey(x)),b=S.length;for(let x=0;x<b;x++){let mt=S[x];d=h[mt],d||(d=h[mt]=Object.create(null),u++),h=d}}else for(let x in a)(typeof a.hasOwnProperty!="function"||a.hasOwnProperty(x))&&(d=h[x],d||(h[$]&1048576&&(E=h[$]&65535),d=h[x]=Object.create(null),u++),h=d,b++);let A=h[$];if(A!==void 0)A&=65535,l[i++]=217,l[i++]=A>>8|224,l[i++]=A&255;else if(S||(S=h.__keys__||(h.__keys__=Object.keys(a))),E===void 0?(A=o.nextId++,A||(A=0,o.nextId=1),A>=Ut&&(o.nextId=(A=g)+1)):A=E,o[A]=S,A<g){l[i++]=217,l[i++]=A>>8|224,l[i++]=A&255,h=o.transitions;for(let x=0;x<b;x++)(h[$]===void 0||h[$]&1048576)&&(h[$]=A),h=h[S[x]];h[$]=A|1048576,n=!0}else{if(h[$]=A,C.setUint32(i,3655335680),i+=3,u&&(ye+=G*u),W.length>=Ut-g&&(W.shift()[$]=void 0),W.push(h),H(b+2),O(57344+A),O(S),w)return;for(let x in a)(typeof a.hasOwnProperty!="function"||a.hasOwnProperty(x))&&O(a[x]);return}if(b<24?l[i++]=128|b:H(b),!w)for(let x in a)(typeof a.hasOwnProperty!="function"||a.hasOwnProperty(x))&&O(a[x])},le=a=>{let w;if(a>16777216){if(a-r>Lt)throw new Error("Encoded buffer would be larger than maximum buffer size");w=Math.min(Lt,Math.round(Math.max((a-r)*(a>67108864?1.25:2),4194304)/4096)*4096)}else w=(Math.max(a-r<<2,l.length-1)>>12)+1<<12;let d=new Ze(w);return C=new DataView(d.buffer,0,w),l.copy?l.copy(d,0,r,a):d.set(l.slice(r,a)),i-=r,r=0,Q=d.length-10,l=d};let ee=100,pt=1e3;this.encodeAsIterable=function(a,w){return yt(a,w,ce)},this.encodeAsAsyncIterable=function(a,w){return yt(a,w,wt)};function*ce(a,w,d){let h=a.constructor;if(h===Object){let u=y.useRecords!==!1;u?z(a,!0):Nt(Object.keys(a).length,160);for(let b in a){let E=a[b];u||O(b),E&&typeof E=="object"?w[b]?yield*ce(E,w[b]):yield*Be(E,w,b):O(E)}}else if(h===Array){let u=a.length;H(u);for(let b=0;b<u;b++){let E=a[b];E&&(typeof E=="object"||i-r>ee)?w.element?yield*ce(E,w.element):yield*Be(E,w,"element"):O(E)}}else if(a[Symbol.iterator]&&!a.buffer){l[i++]=159;for(let u of a)u&&(typeof u=="object"||i-r>ee)?w.element?yield*ce(u,w.element):yield*Be(u,w,"element"):O(u);l[i++]=255}else Xe(a)?(Nt(a.size,64),yield l.subarray(r,i),yield a,we()):a[Symbol.asyncIterator]?(l[i++]=159,yield l.subarray(r,i),yield a,we(),l[i++]=255):O(a);d&&i>r?yield l.subarray(r,i):i-r>ee&&(yield l.subarray(r,i),we())}function*Be(a,w,d){let h=i-r;try{O(a),i-r>ee&&(yield l.subarray(r,i),we())}catch(u){if(u.iteratorNotHandled)w[d]={},i=r+h,yield*ce.call(this,a,w[d]);else throw u}}function we(){ee=pt,y.encode(null,tt)}function yt(a,w,d){return w&&w.chunkThreshold?ee=pt=w.chunkThreshold:ee=100,a&&typeof a=="object"?(y.encode(null,tt),d(a,y.iterateProperties||(y.iterateProperties={}),!0)):[y.encode(a)]}async function*wt(a,w){for(let d of ce(a,w,!0)){let h=d.constructor;if(h===Pt||h===Uint8Array)yield d;else if(Xe(d)){let u=d.stream().getReader(),b;for(;!(b=await u.read()).done;)yield b.value}else if(d[Symbol.asyncIterator])for await(let u of d)we(),u?yield*wt(u,w.async||(w.async={})):yield y.encode(u);else yield d}}}useBuffer(e){l=e,C=new DataView(l.buffer,l.byteOffset,l.byteLength),i=0}clearSharedData(){this.structures&&(this.structures=[]),this.sharedValues&&(this.sharedValues=void 0)}updateSharedData(){let e=this.sharedVersion||0;this.sharedVersion=e+1;let r=this.structures.slice(0),s=new Dt(r,this.sharedValues,this.sharedVersion),n=this.saveShared(s,o=>(o&&o.version||0)==e);return n===!1?(s=this.getShared()||{},this.structures=s.structures||[],this.sharedValues=s.packedValues,this.sharedVersion=s.version,this.structures.nextId=this.structures.length):r.forEach((o,f)=>this.structures[f]=o),n}}function Nt(t,e){t<24?l[i++]=e|t:t<256?(l[i++]=e|24,l[i++]=t):t<65536?(l[i++]=e|25,l[i++]=t>>8,l[i++]=t&255):(l[i++]=e|26,C.setUint32(i,t),i+=4)}class Dt{constructor(e,r,s){this.structures=e,this.packedValues=r,this.version=s}}function H(t){t<24?l[i++]=128|t:t<256?(l[i++]=152,l[i++]=t):t<65536?(l[i++]=153,l[i++]=t>>8,l[i++]=t&255):(l[i++]=154,C.setUint32(i,t),i+=4)}const _r=typeof Blob>"u"?function(){}:Blob;function Xe(t){if(t instanceof _r)return!0;let e=t[Symbol.toStringTag];return e==="Blob"||e==="File"}function Ce(t,e){switch(typeof t){case"string":if(t.length>3){if(e.objectMap[t]>-1||e.values.length>=e.maxValues)return;let s=e.get(t);if(s)++s.count==2&&e.values.push(t);else if(e.set(t,{count:1}),e.samplingPackedValues){let n=e.samplingPackedValues.get(t);n?n.count++:e.samplingPackedValues.set(t,{count:1})}}break;case"object":if(t)if(t instanceof Array)for(let s=0,n=t.length;s<n;s++)Ce(t[s],e);else{let s=!e.encoder.useRecords;for(var r in t)t.hasOwnProperty(r)&&(s&&Ce(r,e),Ce(t[r],e))}break;case"function":console.log(t)}}const Nr=new Uint8Array(new Uint16Array([1]).buffer)[0]==1;Ct=[Date,Set,Error,RegExp,ie,ArrayBuffer,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,typeof BigUint64Array>"u"?function(){}:BigUint64Array,Int8Array,Int16Array,Int32Array,typeof BigInt64Array>"u"?function(){}:BigInt64Array,Float32Array,Float64Array,Dt],He=[{tag:1,encode(t,e){let r=t.getTime()/1e3;(this.useTimestamp32||t.getMilliseconds()===0)&&r>=0&&r<4294967296?(l[i++]=26,C.setUint32(i,r),i+=4):(l[i++]=251,C.setFloat64(i,r),i+=8)}},{tag:258,encode(t,e){let r=Array.from(t);e(r)}},{tag:27,encode(t,e){e([t.name,t.message])}},{tag:27,encode(t,e){e(["RegExp",t.source,t.flags])}},{getTag(t){return t.tag},encode(t,e){e(t.value)}},{encode(t,e,r){Qe(t,r)}},{getTag(t){if(t.constructor===Uint8Array&&(this.tagUint8Array||Ae&&this.tagUint8Array!==!1))return 64},encode(t,e,r){Qe(t,r)}},Z(68,1),Z(69,2),Z(70,4),Z(71,8),Z(72,1),Z(77,2),Z(78,4),Z(79,8),Z(85,4),Z(86,8),{encode(t,e){let r=t.packedValues||[],s=t.structures||[];if(r.values.length>0){l[i++]=216,l[i++]=51,H(4);let n=r.values;e(n),H(0),H(0),packedObjectMap=Object.create(sharedPackedObjectMap||null);for(let o=0,f=n.length;o<f;o++)packedObjectMap[n[o]]=o}if(s){C.setUint32(i,3655335424),i+=3;let n=s.slice(0);n.unshift(57344),n.push(new ie(t.version,1399353956)),e(n)}else e(new ie(t.version,1399353956))}}];function Z(t,e){return!Nr&&e>1&&(t-=4),{tag:t,encode:function(s,n){let o=s.byteLength,f=s.byteOffset||0,m=s.buffer||s;n(Ae?Te.from(m,f,o):new Uint8Array(m,f,o))}}}function Qe(t,e){let r=t.byteLength;r<24?l[i++]=64+r:r<256?(l[i++]=88,l[i++]=r):r<65536?(l[i++]=89,l[i++]=r>>8,l[i++]=r&255):(l[i++]=90,C.setUint32(i,r),i+=4),i+r>=l.length&&e(i+r),l.set(t.buffer?t:new Uint8Array(t),i),i+=r}function Dr(t,e){let r,s=e.length*2,n=t.length-s;e.sort((o,f)=>o.offset>f.offset?1:-1);for(let o=0;o<e.length;o++){let f=e[o];f.id=o;for(let m of f.references)t[m++]=o>>8,t[m]=o&255}for(;r=e.pop();){let o=r.offset;t.copyWithin(o+s,o,n),s-=2;let f=o+s;t[f++]=216,t[f++]=28,n=o}return t}function Bt(t,e){C.setUint32(B.position+t,i-B.position-t+1);let r=B;B=null,e(r[0]),e(r[1])}let et=new _t({useRecords:!1});const Br=et.encode;et.encodeAsIterable,et.encodeAsAsyncIterable;const Ft=512,Fr=1024,tt=2048;class zr extends ar{constructor(e){e||(e={}),e.objectMode=!0,super(e),e.structures=[],this.decoder=e.decoder||new pe(e)}_transform(e,r,s){this.incompleteBuffer&&(e=Buffer.concat([this.incompleteBuffer,e]),this.incompleteBuffer=null);let n;try{n=this.decoder.decodeMultiple(e)}catch(o){if(o.incomplete)this.incompleteBuffer=e.slice(o.lastPosition),n=o.values;else return s(o)}finally{for(let o of n||[])o===null&&(o=this.getNullValue()),this.push(o)}s()}getNullValue(){return Symbol.for(null)}}const jr=process.env.CBOR_NATIVE_ACCELERATION_DISABLED!==void 0&&process.env.CBOR_NATIVE_ACCELERATION_DISABLED.toLowerCase()==="true";if(!jr){let t;try{typeof require=="function"?t=require("cbor-extract"):t=lr(import.meta.url)("cbor-extract"),t&&vr(t.extractStrings)}catch{}}class Vr extends Event{code;reason;wasClean;constructor(e,r={}){super(e,r),this.code=r.code??0,this.reason=r.reason??"",this.wasClean=r.wasClean??!1}}function Kr(t,e){const r="CloseEvent"in globalThis?globalThis.CloseEvent:Vr;return new r(t,e)}class $r{#e=new EventTarget;addEventListener(e,r,s){return this.#e.addEventListener(e,r,s),()=>{this.#e.removeEventListener(e,r,s)}}removeEventListener(e,r,s){this.#e.removeEventListener(e,r,s)}dispatchEvent(e){return this.#e.dispatchEvent(e)}}const T=Symbol.for("@appetizeio/rpc:rpcMethods");class qr extends $r{send;constructor(e){super(),this.send=e}dispatchClose(e){return this.dispatchEvent(Kr("close",e))}dispatchMessage(e){return this.dispatchEvent(new CustomEvent("message",{detail:e}))}}function rt(t){return!!t&&typeof t=="object"&&"jsonrpc"in t}function Jr(){let t,e;return{promise:new Promise((s,n)=>{e=s,t=n}),reject:t,resolve:e}}class Oe{closed=!1;[T];#e;constructor(e,{signal:r}={}){this[T]=new qr(e),this.#e=r,this.#e?.addEventListener("abort",this.#r)}close(e={}){this.closed||(this.closed=!0,this.handleClose(e))}handleClose(e){this.#e?.removeEventListener("abort",this.#r),this[T].dispatchClose(e)}#r=()=>{this.close({code:1e3,reason:String(this.#e?.reason)})}}const zt={useRecords:!1},Wr=new _t(zt);class jt extends Oe{#e=[];#r;constructor(e,{signal:r}={}){super(async f=>{this.#r.write(Wr.encode(f))},{signal:r}),this.#r=e;const s=new zr(zt);s.on("data",f=>{rt(f)&&this[T].dispatchMessage(f)}),s.on("error",()=>{this.close()});const n=f=>{s.write(f)},o=()=>{this.close()};e.on("data",n),e.once("close",o),e.once("error",o),this.#e.push(()=>{e.off("data",n),e.off("close",o),e.off("error",o),s.destroy()})}handleClose(e){for(const r of this.#e.splice(0))r();super.handleClose(e)}}function Gr(t,e){const{promise:r,reject:s,resolve:n}=Jr(),o=cr(t),f=e?.signal,m=()=>{o.off("connect",g),o.off("error",M),f?.removeEventListener("abort",v)},y=R=>{m(),o.destroy(),s(R)},v=()=>{y(new Error("The connection was aborted"))},g=()=>{m();const R=new jt(o,e);R[T].addEventListener("close",()=>{o.destroy()},{once:!0}),n(R)},M=R=>{y(R)};return f?.aborted?(y(new Error("The connection was aborted")),r):(o.once("connect",g),o.once("error",M),f?.addEventListener("abort",v,{once:!0}),r)}const Vt=Fe("appetize.io:error:rpc");function st(t,e){const r=new fr(new ur({errorListener:Vt}),Hr(t),{errorListener:Vt}),s=t[T].addEventListener("message",({detail:o})=>{r.receiveAndSend(o)}),n=t[T].addEventListener("close",()=>{s(),r.rejectAllPendingRequests("Transport closed")},{once:!0});for(const o in e){const f=e[o];f&&r.addMethod(o,f.bind(e))}return{rpc:r,unsub:()=>{s(),n()}}}function Kt(t,e){const{rpc:r,unsub:s}=st(t,e);return{client:r.client,unsub:s}}function Pe(t,e){const r=t[T].addEventListener("message",({detail:n})=>{if("method"in n)try{e({method:n.method,param:n.params})}catch{}}),s=t[T].addEventListener("close",r,{once:!0});return()=>{r(),s()}}function Hr(t){return new dr(t[T].send.bind(t[T]),()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)+1)}function nt(t,e,{leftEffects:r=()=>({}),notifiesLeft:s,notifiesRight:n,rightEffects:o=()=>({})}={}){const f=st(t,{}),m=st(e,{}),y=[()=>{f.unsub(),m.unsub()}],v=()=>{for(const U of y)try{U()}catch{}},g=m.rpc.client,M=f.rpc.client;y.push(t[T].addEventListener("close",()=>{v()},{once:!0}),e[T].addEventListener("close",()=>{v()},{once:!0}));const R=r(g,M);for(const U in R){const P=R[U];P&&f.rpc.addMethod(U,P)}const L=o(M,g);for(const U in L){const P=L[U];P&&m.rpc.addMethod(U,P)}return $t(f.rpc,m.rpc,{notifies:s}),$t(m.rpc,f.rpc,{notifies:n}),v}function $t(t,e,{notifies:r}={}){t.applyServerMiddleware(async(s,n)=>{const o=r?.();if(o){const{id:m,...y}=n;o[T].send(y)}if(t.hasMethod(n.method))return await s(n);if(!n.id)return e.notify(n.method,n.params),null;const f=await e.request(n.method,n.params);return{id:n.id,jsonrpc:hr,result:f}})}function X(t,...e){t.notify(e[0],e[1],e[2])}const Zr=(...t)=>Kt(...t),it=["ArrowDown","ArrowLeft","ArrowRight","ArrowUp","Backspace","Enter","Tab"];function ot(){const t=new Oe(async r=>{e[T].dispatchMessage(r)}),e=new Oe(async r=>{t[T].dispatchMessage(r)});return t[T].addEventListener("close",()=>{e.close()},{once:!0}),e[T].addEventListener("close",()=>{t.close()},{once:!0}),[t,e]}function qt(t,e){const r=[],s=()=>{for(const n of r)n()};r.push(t[T].addEventListener("message",n=>e[T].send(n.detail))),r.push(t[T].addEventListener("close",s,{once:!0})),r.push(e[T].addEventListener("message",n=>t[T].send(n.detail))),r.push(e[T].addEventListener("close",s,{once:!0}))}const ae=Fe("appetize.io:trace:transport:iframe");class Jt extends Oe{onmessage;#e;#r;constructor(e,{origin:r="*",signal:s}={}){super(async n=>{e.postMessage(n,this.#e)},{signal:s}),this.#r=e,this.#e=r,window.addEventListener("message",this.#t)}postMessage(e,r,s){ae("postMessage(legacy)",{message:e,targetOrigin:r,transfer:s}),this.#r.postMessage(e,r??this.#e,s)}handleClose(e){ae("close()"),window.removeEventListener("message",this.#t),super.handleClose(e)}#t=async e=>{if(ae("handleMessage()",e),e.source!==this.#r||(ae("handleMessage() -> source ok"),this.#e!=="*"&&e.origin!==this.#e))return;ae("handleMessage() -> origin ok");const r=e.data;if(!rt(r)){ae("handleMessage() -> legacy"),this.onmessage?.(e);return}ae("handleMessage() -> jsonrpc"),this[T].dispatchMessage(r)}}function Ue(){let t,e;return{promise:new Promise((s,n)=>{e=s,t=n}),reject:t,resolve:e}}const Yr=2*1024*1024,Wt=Fe("appetize:client:acked-writable-stream");class Xr{unacked=0;#e;#r;#t;#s;#n=[];#i;constructor(e){this.#t=e,this.#i=e.window??Yr}abort(e){this.#a(e),this.#t.onAbort?.(e)}async close(){await this.#l(()=>this.unacked===0),this.#t.onClose?.()}fail(e){this.#a(e)&&this.#t.onError?.(e)}start(e){this.#e=e}write(e){const r=e.byteLength;return this.unacked+=r,this.#t.send(e).then(()=>{this.unacked-=r,this.#s&&(this.#s.acked+=r),this.#o()},s=>{this.fail(s)}),this.unacked>=this.#i&&!this.#s&&(this.#s={acked:0,at:performance.now()},Wt("window full: %d bytes unacked, writes stalled",this.unacked)),this.#l(()=>this.unacked<this.#i)}#o(){if(this.#s&&this.unacked<=this.#i/2){const e=performance.now()-this.#s.at;Wt("pressure relieved after %dms: %d bytes acked, %s MB/s",Math.round(e),this.#s.acked,(this.#s.acked/Math.max(e,1)/1e3).toFixed(2)),this.#s=void 0}this.#n=this.#n.filter(e=>e.until()?(e.resolve(void 0),!1):!0)}#a(e){if(this.#r)return!1;this.#r={reason:e},this.#e.error(e);const r=this.#n;this.#n=[];for(const s of r)s.reject(e);return!0}#l(e){if(e())return Promise.resolve();const r={...Ue(),until:e};return this.#n.push(r),r.promise}}class Qr extends WritableStream{get unacked(){return this.#e.unacked}#e;constructor(e){const r=new Xr(e);super({abort:s=>{r.abort(s)},close:()=>r.close(),start:s=>{r.start(s)},write:s=>r.write(s)}),this.#e=r}fail(e){this.#e.fail(e)}}const es=1024*1024;class ts{#e;#r=!1;#t;#s;constructor(e){this.#t=e}cancel(e){this.#n(),this.#t?.(e)}close(){this.#n()&&this.#e.close()}error(e){this.#n()&&this.#e.error(e)}pull(){const e=this.#s;this.#s=void 0,e?.resolve(void 0)}async push(e){if(this.#r)return;this.#s??=Ue();const{promise:r}=this.#s;this.#e.enqueue(e),await r}start(e){this.#e=e}#n(){return this.#r?!1:(this.#r=!0,this.pull(),!0)}}class rs extends ReadableStream{#e;constructor({highWaterMark:e=es,onCancel:r}={}){const s=new ts(r);super({cancel:n=>{s.cancel(n)},pull:()=>{s.pull()},start:n=>{s.start(n)}},new ByteLengthQueuingStrategy({highWaterMark:e})),this.#e=s}close(){this.#e.close()}error(e){this.#e.error(e)}push(e){return this.#e.push(e)}}class ss{closed;readable;writable;#e=[];#r;#t;#s;#n;#i;#o="starting";constructor(e,{onClose:r,receiveBuffer:s,sendWindow:n,signal:o}){if(this.#i=e,this.#r=Ue(),this.closed=this.#r.promise,this.closed.catch(ns),this.#s=new rs({highWaterMark:s,onCancel:()=>{this.#a(void 0)}}),this.readable=this.#s,this.#n=new Qr({onAbort:()=>{this.#a(void 0)},onClose:()=>{this.#a(void 0)},onError:f=>{this.#a(f)},send:f=>e.request("appetizeio.device.server.debug.adbTunnel.data",{data:f}),window:n}),this.writable=this.#n,o){const f=()=>{this.#a(o.reason)};o.addEventListener("abort",f,{once:!0}),this.#e.push(()=>{o.removeEventListener("abort",f)})}this.#e.push(()=>{r(this)})}close=()=>{this.#a(void 0)};detach(){this.#a(void 0,{notifyServer:!1})}async handleData(e){this.#o==="open"&&await this.#s.push(e)}handleStopped({error:e}){this.#o==="open"&&this.#a(e?new Error(e):void 0)}async start(){try{await this.#i.request("appetizeio.device.server.debug.adbTunnel.start",void 0)}catch(e){throw this.#a(e),e}if(this.#o==="closed")throw this.#t?this.#t:new Error("The adb tunnel closed before it started");this.#o="open"}async[Symbol.asyncDispose](){this.close();try{await this.closed}catch{}}#a(e,{notifyServer:r=!0}={}){if(this.#o!=="closed"){this.#o="closed",this.#t=e,r&&X(this.#i,"appetizeio.device.server.debug.adbTunnel.stop",void 0),e?(this.#s.error(e),this.#n.fail(e)):(this.#s.close(),this.#n.fail(new Error("The adb tunnel has stopped")));for(const s of this.#e)s();e?this.#r.reject(e):this.#r.resolve(void 0)}}}function ns(){}class is{readable;ready;#e=[];#r=!1;#t;#s;#n;constructor({label:e,onClose:r,signal:s}){this.#s=e,this.ready=new Promise((o,f)=>{this.#n={reject:f,resolve:o}});let n;if(this.readable=new ReadableStream({cancel:()=>{this.#o()},start:o=>{n=o}}),!n)throw new Error("ReadableStream controller was not initialized");if(this.#t=n,s){const o=()=>{this.fail(s.reason)};s.addEventListener("abort",o,{once:!0}),this.#e.push(()=>{s.removeEventListener("abort",o)})}this.#e.push(()=>{r(this)})}close=()=>{this.#i()};fail(e){this.#i(e)}handleItem(e){this.#t.enqueue(e)}markReady(){if(!this.#n)return;const{resolve:e}=this.#n;this.#n=void 0,e(this)}async*[Symbol.asyncIterator](){const e=this.readable.getReader();try{for(let r=await e.read();!r.done;r=await e.read())yield r.value}finally{await e.cancel()}}#i(e){this.#r||(this.#t.close(),this.#o(e))}#o(e){this.#r=!0;for(const r of this.#e)r();this.#n?.reject(e??new Error(`${this.#s} closed before it started`)),this.#n=void 0}}class os{get subscribers(){return this.#t}#e;#r;#t=new Set;constructor(e){this.#e=e}close(){this.#r=void 0;for(const e of[...this.#t])e.close();this.#t.clear()}add(e){this.#t.add(e)}ensureStarted(){return this.#r||(this.#r=(async()=>{try{return await this.#e.start()}catch(e){throw this.#r=void 0,e}})()),this.#r}release(e){this.#t.delete(e),!(this.#t.size>0||!this.#r)&&(this.#r=void 0,this.#e.stop())}}class Gt extends os{#e;constructor(e){super({start:e.start,stop:e.stop}),this.#e=e.label}async createStream({signal:e}={}){e?.throwIfAborted();const r=new is({label:this.#e,onClose:s=>{this.release(s)},signal:e});this.add(r);try{await this.ensureStarted(),r.markReady()}catch(s){r.fail(s)}return await r.ready}handleNotification(e){for(const r of this.subscribers)r.handleItem(e)}}class as{#e;#r;#t;#s;constructor(e){this.#s=e,this.#r=new Gt({label:"Log stream",start:()=>e.request("appetizeio.device.server.debug.log.start"),stop:()=>{X(e,"appetizeio.device.server.debug.log.stop",void 0)}}),this.#t=new Gt({label:"Proxy intercept stream",start:()=>e.request("appetizeio.device.server.debug.proxyIntercept.start"),stop:()=>{X(e,"appetizeio.device.server.debug.proxyIntercept.stop",void 0)}})}close(){this.#e?.detach(),this.#r.close(),this.#t.close()}async createAdbTunnel({signal:e}={}){e?.throwIfAborted(),this.#e?.close();const r=new ss(this.#s,{onClose:()=>{this.#e=void 0},signal:e});return this.#e=r,await r.start(),r}async createLogStream(e){return await this.#r.createStream(e)}async createProxyInterceptStream(e){return await this.#t.createStream(e)}async handleAdbTunnelData({data:e}){await this.#e?.handleData(e)}handleAdbTunnelStopped(e){this.#e?.handleStopped(e)}handleLogEntry(e){this.#r.handleNotification(e)}handleProxyInterceptEvent(e){this.#t.handleNotification(e)}}function at(t){return{...ls(t),index:t.index,within:t.within?at(t.within):void 0}}function ls(t){switch(t.by){case"testId":return{by:"testId",testId:t.testId};case"text":return{by:"text",text:cs(t.text)}}}function cs(t){return typeof t=="string"?{kind:"exact",value:t}:{flags:t.flags,kind:"regex",source:t.source}}function fs(t){return{press:e=>{X(t,"appetizeio.device.server.keyboard.press",{key:e})}}}function us({onRequest:t,parent:e,proxyInlet:r,signal:s}){const n=new Jt(e,{signal:s}),o=[()=>{n.close()}];return qt(n,r),t&&o.push(Pe(n,f=>{t(f,{source:"parent"})})),{cleanup:()=>{for(const f of o)f()},notifies:()=>e===globalThis.window?void 0:n}}const ds="@appetizeio/rpc:playwrightAdapter",Le=Symbol.for(ds);function hs(t){window[Le]&&console.warn("playwright exposed more than once, overwriting previous adapter");const e={send(r){t[T].send(r)},subscribe(r){return t[T].addEventListener("message",s=>{r(s.detail)})}};return window[Le]=e,()=>{window[Le]===e&&delete window[Le]}}function ps({onRequest:t,proxyInlet:e}){const[r,s]=ot(),o=[hs(s),()=>{r.close()}];return qt(r,e),t&&o.push(Pe(r,f=>{t(f,{source:"parent"})})),{cleanup:()=>{for(const f of o)f()},notifies:()=>r}}function _e(t){return t.by==="position"?{by:"position",x:t.x,y:t.y}:{...at(t),x:t.x,y:t.y}}function ys(t){return"to"in t?{from:_e(t.from),kind:"path",to:_e(t.to)}:{direction:t.direction,distance:t.distance,from:t.from?_e(t.from):void 0,kind:"direction"}}function ws(t){return{down:(e,r)=>{X(t,"appetizeio.device.server.touch.down",{x:e,y:r})},move:(e,r)=>{X(t,"appetizeio.device.server.touch.move",{x:e,y:r})},up:(e,r)=>{X(t,"appetizeio.device.server.touch.up",{x:e,y:r})}}}const ms=new Set(it),bs=/^(?<key>[A-Za-z]+)>(?<repeat>\d+)\/$/u,gs=/(\{\{|\{[^{}]*\})/u;function Es(t){const e=[];let r="";function s(){r.length>0&&(e.push({kind:"text",text:r}),r="")}for(const[n,o]of t.split(gs).entries())if(n%2===0){if(o.includes("{"))throw new Error(`Unclosed "{" in ${JSON.stringify(t)}`);r+=o}else o==="{{"?r+="{":(s(),e.push(vs(o.slice(1,-1))));return s(),e}function Ss(t,e){if(!ms.has(t))throw e.endsWith(">")?new Error(`Holding a key is not supported: {${e}}`):e.startsWith("/")?new Error(`Releasing a key is not supported: {${e}}`):new Error(`{${e}} does not name a supported key. Supported: ${it.join(", ")}. Type characters as text, and escape a literal "{" as "{{".`)}function vs(t){const e=bs.exec(t)?.groups,r=e?.key??t;if(Ss(r,t),!e)return{key:r,kind:"press"};const s=Number(e.repeat);if(s<1)throw new Error(`Repeat for {${t}} must be at least 1`);return{key:r,kind:"press",repeat:s}}const As=Symbol("@appetizeio/client:v1Compat");function Ht(t){return t?.[As]}class Os{readable;ready;get dimensions(){return this.#s}#e=[];#r=!1;#t;#s;#n;#i;constructor({onClose:e,requestKeyFrame:r,signal:s}){this.#n=r,this.ready=new Promise((o,f)=>{this.#i={reject:f,resolve:o}});let n;if(this.readable=new ReadableStream({cancel:()=>{this.#a()},start:o=>{n=o}}),!n)throw new Error("ReadableStream controller was not initialized");if(this.#t=n,s){const o=()=>{this.fail(s.reason)};s.addEventListener("abort",o,{once:!0}),this.#e.push(()=>{s.removeEventListener("abort",o)})}this.#e.push(()=>{e(this)})}close=()=>{this.#o()};fail(e){this.#o(e)}handleChunk(e){if(this.#i){if(e.type!=="key")return;const{resolve:r}=this.#i;this.#i=void 0,this.#s={height:e.height,width:e.width},r(this)}else e.type==="key"&&(this.#s={height:e.height,width:e.width});this.#t.enqueue(e)}requestKeyFrame=()=>{this.#r||this.#n()};async*[Symbol.asyncIterator](){const e=this.readable.getReader();try{for(let r=await e.read();!r.done;r=await e.read())yield r.value}finally{await e.cancel()}}#o(e){this.#r||(this.#t.close(),this.#a(e))}#a(e){this.#r=!0;for(const r of this.#e)r();this.#i?.reject(e??new Error("Video stream closed before the first key chunk")),this.#i=void 0}}class ks{#e=!1;#r;#t;#s=new Set;constructor(e){this.#r=e}close(){this.#t=void 0;for(const e of[...this.#s])e.close()}async createStream({signal:e}={}){e?.throwIfAborted();const r=new Os({onClose:s=>{this.#i(s)},requestKeyFrame:()=>{this.#o()},signal:e});this.#s.add(r);try{await this.#n()}catch(s){r.fail(s)}return await r.ready}handleChunk(e){e.type==="key"&&(this.#e=!1);for(const r of this.#s)r.handleChunk(e)}#n(){return this.#t?(this.#o(),this.#t):(this.#e=!0,this.#t=(async()=>{try{await this.#r.request("appetizeio.device.server.video.start")}catch(e){throw this.#t=void 0,e}})(),this.#t)}#i(e){this.#s.delete(e),!(this.#s.size>0||!this.#t)&&(this.#t=void 0,X(this.#r,"appetizeio.device.server.video.stop",void 0))}#o(){this.#e||(this.#e=!0,X(this.#r,"appetizeio.device.server.video.requestKeyFrame",void 0))}}class Is{debug;keyboard;touch;video;#e;#r=[];#t;constructor(e,r={}){const s=Ht(r)??{},{baseUrl:n,onClose:o,signal:f}=r;this.#e=n?xs(n):void 0;const{onRequest:m,parent:y,proxyRequest:v}=s,g=Ms(m);f?.addEventListener("abort",this.close);const[M,R]=ot(),[L,U]=ot();this.#r.push(()=>{M.close(),R.close(),L.close(),U.close()}),this.#r.push(nt(U,e,{leftEffects:v}));const P=y==="playwright"?ps({onRequest:g,proxyInlet:L}):y?us({onRequest:g,parent:y,proxyInlet:L,signal:f}):void 0;P&&this.#r.push(P.cleanup),this.#r.push(nt(R,L,{notifiesLeft:P?.notifies}));const{client:W,unsub:ye}=Zr(M,{"appetizeio.device.client.debug.adbTunnel.data":z=>G.handleAdbTunnelData(z),"appetizeio.device.client.debug.adbTunnel.stopped":async z=>{G.handleAdbTunnelStopped(z)},"appetizeio.device.client.debug.log.entry":async z=>{G.handleLogEntry(z)},"appetizeio.device.client.debug.proxyIntercept.event":async z=>{G.handleProxyInterceptEvent(z)},"appetizeio.device.client.video.chunk":async z=>{O.handleChunk(z)}});this.#t=W,this.#r.push(ye);const G=new as(this.#t);this.#r.push(()=>{G.close()});const O=new ks(this.#t);this.#r.push(()=>{O.close()}),this.debug=G,this.keyboard=fs(this.#t),this.touch=ws(this.#t),this.video=O,g&&(this.#r.push(Pe(R,z=>{g(z,{source:"self"})})),e instanceof Jt&&this.#r.push(Pe(e,z=>{g(z,{source:"iframe"})}))),this.#r.push(()=>o?.())}async clearKeychain(){await this.#t.request("appetizeio.device.server.clearKeychain")}close=()=>{for(const e of this.#r)try{e()}catch(r){console.error("Device cleanup error:",r)}};async inspect(e,r){return await this.#t.request("appetizeio.device.server.inspect",{options:r,selector:e?at(e):void 0})}async open(e){new URL(e),await this.#t.request("appetizeio.device.server.open",{url:e})}async press(e){await this.#t.request("appetizeio.device.server.press",{action:e})}async rotate(e){return await this.#t.request("appetizeio.device.server.rotate",{orientation:e})}async screenshot(){const e=await this.#t.request("appetizeio.device.server.screenshot"),r=this.#e?new URL(e.url,this.#e).href:e.url,s=await fetch(r);if(!s.ok)throw new Error(`Screenshot download failed: ${String(s.status)} ${s.statusText}`);const n=s.headers.get("content-type")??"application/octet-stream";return{data:new Uint8Array(await s.arrayBuffer()),mimeType:n}}async swipe(e,r){await this.#t.request("appetizeio.device.server.swipe",{gesture:ys(e),options:r})}async tap(e,r){await this.#t.request("appetizeio.device.server.tap",{options:r,selector:_e(e)})}async type(e,r){await this.#t.request("appetizeio.device.server.type",{options:r,steps:Es(e)})}}function xs(t){const e=new URL(t);return e.protocol==="ws:"?e.protocol="http:":e.protocol==="wss:"&&(e.protocol="https:"),e.href}const Ms=t=>{if(t)return(e,r)=>{e.method.startsWith("appetizeio.device.server.")&&t(e,r)}},Rs={dateStyle:"medium",timeStyle:"short"},Ts=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})$/;function lt(t){return Array.isArray(t)?t.map(lt).join(", "):typeof t=="boolean"?t?"yes":"no":typeof t=="number"?t.toLocaleString():Cs(t)}function Cs(t){if(Ts.test(t)){const r=new Date(t);if(!Number.isNaN(r.getTime()))return r.toLocaleString(void 0,Rs)}const e=bt();return t===e?"~":t.startsWith(`${e}${pr}`)?`~${t.slice(e.length)}`:t}class Ne extends Error{details;constructor(e,r={},s){super(e,s===void 0?void 0:{cause:s}),this.name="CommandError",this.details=r}hints(e){return[]}}class De extends Ne{sessionDir;constructor(e,r,s={},n){super(e,Object.assign({sessionDir:r},s),n),this.name="SessionError",this.sessionDir=r}static wrap(e,r){if(e instanceof De||e instanceof he)return e;const s=e instanceof Error?e.message:String(e),n=e instanceof Ne?e.details:{};return new De(s,r,n,e)}hints(){return[`Check the session logs for details: ${lt(this.sessionDir)}`]}}class he extends Ne{constructor(e){super(e),this.name="UsageError"}hints({command:e}){return[`Run 'appetize ${e} --help' for usage`]}}function Ps(t,e,r){const s=e instanceof Error?e.message:String(e);return e instanceof Ne?t==="json"?JSON.stringify({error:{message:s,...e.details}},null,2):[`\u2716 ${s}`,...e.hints(r).map(n=>` ${n}`)].join(`
|
|
2
|
-
`):t==="json"?JSON.stringify({error:{message:s}},null,2):`\u2716 ${s}`}function ct(t){try{return process.kill(t,0),!0}catch{return!1}}const Us=["SIGINT","SIGTERM"],Ls=150;function _s(t){const e=new AbortController,r=setInterval(()=>{ct(t)||(clearInterval(r),e.abort(new Error("The device session exited")))},Ls);return r.unref(),e.signal}function Zt(){const t=new AbortController;for(const e of Us)process.once(e,()=>{t.abort(new Error(`Received ${e}`))});return t.signal}function Ns(t,e){return new Promise((r,s)=>{if(e.aborted){s(Yt(e.reason));return}const n=()=>{clearTimeout(o),s(Yt(e.reason))},o=setTimeout(()=>{e.removeEventListener("abort",n),r()},t);e.addEventListener("abort",n,{once:!0})})}function Yt(t){return t instanceof Error?t:new Error(String(t))}function Ds(t){const e=t.at(-1);return{options:zs(e)?e:{},positionals:t.slice(0,-1).filter(r=>typeof r=="string"),signal:Zt()}}function Bs(t,e){const r=Xt(t,e);return r===void 0?void 0:Qt(r,e)}function Xt(t,e){if(t===void 0)return;const r=typeof t=="boolean"?Number.NaN:Number(t);if(!Number.isFinite(r))throw new he(`${e} expects a number, e.g., ${e}=-0.1`);return r}function ft(t,e){if(t!==void 0){if(typeof t!="string"||t==="")throw new he(`${e} needs a value`);return t}}function Qt(t,e){if(!(t>=0&&t<=1))throw new he(`${e} expects a number between 0 and 1`);return t}function Fs(t,e){const r=ft(t,e);if(r===void 0)throw new he(`${e} needs a value`);return r}function zs(t){return typeof t=="object"&&t!==null}const js="APPETIZEIO_FEATURE_FLAGS";function Vs(){const t={};for(const e of(process.env[js]??"").split(",")){const r=e.trim();r!==""&&(t[r]=!0)}return t}function Ks(){const t=process.env.APPETIZE_API_TOKEN;if(!t)throw new Error("APPETIZE_API_TOKEN must be set");return t}function er(t){return ft(t.endpoint,"--endpoint")??$s()}function $s(){const t=process.env.APPETIZE_ENDPOINT?.trim();return t===""?void 0:t}const qs="https://appetize.io";async function tr(t,{authorize:e=!0,commandOptions:r={},query:s={},...n}={}){const o=new URL(t,er(r)??qs);for(const[y,v]of Object.entries(s))o.searchParams.set(y,v);const f=new Headers(n.headers);e&&f.set("x-api-key",Ks());const m=await fetch(o,{...n,headers:f});if(!m.ok)throw new Error(`The webserver rejected the request (${String(m.status)})`);return await m.json()}const rr=["android","ios"];function sr(t={},e){return tr("/api/v2/service/devices",{authorize:!1,commandOptions:t,signal:e})}function Js(t){return rr.includes(t)}async function Ws(t,e={}){return(await sr(e)).find(s=>s.id===t)?.platform}function Gs(t){let e={...t,updatedAt:new Date().toISOString()};return{path:dt(e.sessionId),save:r=>(e={...e,...r,updatedAt:new Date().toISOString()},rn(e),e)}}function Hs(){const t=ir();return gt(t,{recursive:!0}),br(t).map(e=>ut(e)).filter(e=>e!==void 0)}function Zs(t){if(t!==void 0){const r=ut(t);if(!r)throw new Error(`No session found for id ${t}`);return r}const e=Hs().filter(tn);if(e.length===0)throw new Error("No active sessions");if(e.length>1)throw new Error("Multiple active sessions; specify --session-id");return e[0]}function ut(t){try{return JSON.parse(mr(dt(t),"utf8"))}catch{return}}function Ys(t){return te(ke(t),"control.sock")}function nr(t){return te(ke(t),"daemon.log")}function Xs(t){return te(ke(t),"device.log.jsonl")}function Qs(t,e){return{daemon:nr(t),device:Xs(t),...e==="intercept"?{network:en(t)}:void 0}}function en(t){return te(ke(t),"network.jsonl")}function ke(t){const e=or(t);return gt(e,{recursive:!0}),e}function dt(t){return te(ke(t),"state.json")}function ir(){return process.env.APPETIZE_CLI_HOME??te(bt(),".appetize","cli","sessions")}function or(t){return te(ir(),t)}function tn(t){const e=t.state?.phase;return e==="ended"||e==="error"?!1:ct(t.pid)}function rn(t){const e=dt(t.sessionId),r=`${e}.tmp`;yr(r,`${JSON.stringify(t,null,2)}
|
|
3
|
-
`),wr(r,e)}const ht="APPETIZE_DAEMON_CONFIG";function sn(){const t=process.env[ht];if(!t)throw new Error(`${ht} is not set`);return JSON.parse(t)}function nn(t){return JSON.stringify(t)}export{it as A,Br as B,T as C,Is as D,Pr as E,rt as F,Ht as G,Ue as H,sn as I,Gs as J,Ws as K,jt as L,nt as M,Ys as N,Zt as O,De as S,Oe as T,he as U,Xt as a,Ns as b,sr as c,Gr as d,rr as e,tr as f,Fs as g,nr as h,Js as i,ht as j,ut as k,Vs as l,er as m,Qs as n,or as o,ft as p,ct as q,Qt as r,nn as s,Bs as t,lt as u,Kt as v,Zs as w,_s as x,Ds as y,Ps as z};
|