@kritchoff/agent-browser 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +903 -0
  3. package/README.sdk.md +77 -0
  4. package/bin/agent-browser-linux-x64 +0 -0
  5. package/bin/agent-browser.js +109 -0
  6. package/dist/actions.d.ts +17 -0
  7. package/dist/actions.d.ts.map +1 -0
  8. package/dist/actions.js +1427 -0
  9. package/dist/actions.js.map +1 -0
  10. package/dist/browser.d.ts +474 -0
  11. package/dist/browser.d.ts.map +1 -0
  12. package/dist/browser.js +1566 -0
  13. package/dist/browser.js.map +1 -0
  14. package/dist/cdp-client.d.ts +103 -0
  15. package/dist/cdp-client.d.ts.map +1 -0
  16. package/dist/cdp-client.js +223 -0
  17. package/dist/cdp-client.js.map +1 -0
  18. package/dist/daemon.d.ts +60 -0
  19. package/dist/daemon.d.ts.map +1 -0
  20. package/dist/daemon.js +401 -0
  21. package/dist/daemon.js.map +1 -0
  22. package/dist/dualmode-config.d.ts +37 -0
  23. package/dist/dualmode-config.d.ts.map +1 -0
  24. package/dist/dualmode-config.js +44 -0
  25. package/dist/dualmode-config.js.map +1 -0
  26. package/dist/dualmode-fetcher.d.ts +60 -0
  27. package/dist/dualmode-fetcher.d.ts.map +1 -0
  28. package/dist/dualmode-fetcher.js +449 -0
  29. package/dist/dualmode-fetcher.js.map +1 -0
  30. package/dist/dualmode-types.d.ts +183 -0
  31. package/dist/dualmode-types.d.ts.map +1 -0
  32. package/dist/dualmode-types.js +8 -0
  33. package/dist/dualmode-types.js.map +1 -0
  34. package/dist/ios-actions.d.ts +11 -0
  35. package/dist/ios-actions.d.ts.map +1 -0
  36. package/dist/ios-actions.js +228 -0
  37. package/dist/ios-actions.js.map +1 -0
  38. package/dist/ios-manager.d.ts +266 -0
  39. package/dist/ios-manager.d.ts.map +1 -0
  40. package/dist/ios-manager.js +1073 -0
  41. package/dist/ios-manager.js.map +1 -0
  42. package/dist/protocol.d.ts +26 -0
  43. package/dist/protocol.d.ts.map +1 -0
  44. package/dist/protocol.js +832 -0
  45. package/dist/protocol.js.map +1 -0
  46. package/dist/snapshot.d.ts +83 -0
  47. package/dist/snapshot.d.ts.map +1 -0
  48. package/dist/snapshot.js +653 -0
  49. package/dist/snapshot.js.map +1 -0
  50. package/dist/stream-server.d.ts +117 -0
  51. package/dist/stream-server.d.ts.map +1 -0
  52. package/dist/stream-server.js +305 -0
  53. package/dist/stream-server.js.map +1 -0
  54. package/dist/types.d.ts +742 -0
  55. package/dist/types.d.ts.map +1 -0
  56. package/dist/types.js +2 -0
  57. package/dist/types.js.map +1 -0
  58. package/docker-compose.sdk.yml +45 -0
  59. package/package.json +85 -0
  60. package/scripts/benchmark.sh +80 -0
  61. package/scripts/build-all-platforms.sh +68 -0
  62. package/scripts/check-version-sync.js +39 -0
  63. package/scripts/copy-native.js +36 -0
  64. package/scripts/fast_reset.sh +108 -0
  65. package/scripts/postinstall.js +235 -0
  66. package/scripts/publish_images.sh +55 -0
  67. package/scripts/snapshot_manager.sh +293 -0
  68. package/scripts/start-android-agent.sh +49 -0
  69. package/scripts/sync-version.js +69 -0
  70. package/scripts/vaccine-run +26 -0
  71. package/sdk.sh +153 -0
  72. package/skills/agent-browser/SKILL.md +217 -0
  73. package/skills/agent-browser/references/authentication.md +202 -0
  74. package/skills/agent-browser/references/commands.md +259 -0
  75. package/skills/agent-browser/references/proxy-support.md +188 -0
  76. package/skills/agent-browser/references/session-management.md +193 -0
  77. package/skills/agent-browser/references/snapshot-refs.md +194 -0
  78. package/skills/agent-browser/references/video-recording.md +173 -0
  79. package/skills/agent-browser/templates/authenticated-session.sh +97 -0
  80. package/skills/agent-browser/templates/capture-workflow.sh +69 -0
  81. package/skills/agent-browser/templates/form-automation.sh +62 -0
  82. package/skills/skill-creator/LICENSE.txt +202 -0
  83. package/skills/skill-creator/SKILL.md +356 -0
  84. package/skills/skill-creator/references/output-patterns.md +82 -0
  85. package/skills/skill-creator/references/workflows.md +28 -0
  86. package/skills/skill-creator/scripts/init_skill.py +303 -0
  87. package/skills/skill-creator/scripts/package_skill.py +113 -0
  88. package/skills/skill-creator/scripts/quick_validate.py +95 -0
@@ -0,0 +1,832 @@
1
+ import { z } from 'zod';
2
+ // Base schema for all commands
3
+ const baseCommandSchema = z.object({
4
+ id: z.string(),
5
+ action: z.string(),
6
+ });
7
+ // Individual action schemas
8
+ const launchSchema = baseCommandSchema.extend({
9
+ action: z.literal('launch'),
10
+ headless: z.boolean().optional(),
11
+ viewport: z
12
+ .object({
13
+ width: z.number().positive(),
14
+ height: z.number().positive(),
15
+ })
16
+ .optional(),
17
+ browser: z.enum(['chromium', 'firefox', 'webkit']).optional(),
18
+ cdpPort: z.number().positive().optional(),
19
+ cdpUrl: z
20
+ .string()
21
+ .url()
22
+ .refine((url) => url.startsWith('ws://') ||
23
+ url.startsWith('wss://') ||
24
+ url.startsWith('http://') ||
25
+ url.startsWith('https://'), { message: 'CDP URL must start with ws://, wss://, http://, or https://' })
26
+ .optional(),
27
+ executablePath: z.string().optional(),
28
+ extensions: z.array(z.string()).optional(),
29
+ headers: z.record(z.string()).optional(),
30
+ proxy: z
31
+ .object({
32
+ server: z.string().min(1),
33
+ bypass: z.string().optional(),
34
+ username: z.string().optional(),
35
+ password: z.string().optional(),
36
+ })
37
+ .optional(),
38
+ args: z.array(z.string()).optional(),
39
+ userAgent: z.string().optional(),
40
+ provider: z.string().optional(),
41
+ ignoreHTTPSErrors: z.boolean().optional(),
42
+ profile: z.string().optional(),
43
+ storageState: z.string().optional(),
44
+ });
45
+ const navigateSchema = baseCommandSchema.extend({
46
+ action: z.literal('navigate'),
47
+ url: z.string().min(1),
48
+ waitUntil: z.enum(['load', 'domcontentloaded', 'networkidle']).optional(),
49
+ headers: z.record(z.string()).optional(),
50
+ });
51
+ const clickSchema = baseCommandSchema.extend({
52
+ action: z.literal('click'),
53
+ selector: z.string().min(1),
54
+ button: z.enum(['left', 'right', 'middle']).optional(),
55
+ clickCount: z.number().positive().optional(),
56
+ delay: z.number().nonnegative().optional(),
57
+ });
58
+ const typeSchema = baseCommandSchema.extend({
59
+ action: z.literal('type'),
60
+ selector: z.string().min(1),
61
+ text: z.string(),
62
+ delay: z.number().nonnegative().optional(),
63
+ clear: z.boolean().optional(),
64
+ });
65
+ const fillSchema = baseCommandSchema.extend({
66
+ action: z.literal('fill'),
67
+ selector: z.string().min(1),
68
+ value: z.string(),
69
+ });
70
+ const checkSchema = baseCommandSchema.extend({
71
+ action: z.literal('check'),
72
+ selector: z.string().min(1),
73
+ });
74
+ const uncheckSchema = baseCommandSchema.extend({
75
+ action: z.literal('uncheck'),
76
+ selector: z.string().min(1),
77
+ });
78
+ const uploadSchema = baseCommandSchema.extend({
79
+ action: z.literal('upload'),
80
+ selector: z.string().min(1),
81
+ files: z.union([z.string(), z.array(z.string())]),
82
+ });
83
+ const dblclickSchema = baseCommandSchema.extend({
84
+ action: z.literal('dblclick'),
85
+ selector: z.string().min(1),
86
+ });
87
+ const focusSchema = baseCommandSchema.extend({
88
+ action: z.literal('focus'),
89
+ selector: z.string().min(1),
90
+ });
91
+ const dragSchema = baseCommandSchema.extend({
92
+ action: z.literal('drag'),
93
+ source: z.string().min(1),
94
+ target: z.string().min(1),
95
+ });
96
+ const frameSchema = baseCommandSchema.extend({
97
+ action: z.literal('frame'),
98
+ selector: z.string().min(1).optional(),
99
+ name: z.string().optional(),
100
+ url: z.string().optional(),
101
+ });
102
+ const mainframeSchema = baseCommandSchema.extend({
103
+ action: z.literal('mainframe'),
104
+ });
105
+ const getByRoleSchema = baseCommandSchema.extend({
106
+ action: z.literal('getbyrole'),
107
+ role: z.string().min(1),
108
+ name: z.string().optional(),
109
+ exact: z.boolean().optional(),
110
+ subaction: z.enum(['click', 'fill', 'check', 'hover']),
111
+ value: z.string().optional(),
112
+ });
113
+ const getByTextSchema = baseCommandSchema.extend({
114
+ action: z.literal('getbytext'),
115
+ text: z.string().min(1),
116
+ exact: z.boolean().optional(),
117
+ subaction: z.enum(['click', 'hover']),
118
+ });
119
+ const getByLabelSchema = baseCommandSchema.extend({
120
+ action: z.literal('getbylabel'),
121
+ label: z.string().min(1),
122
+ exact: z.boolean().optional(),
123
+ subaction: z.enum(['click', 'fill', 'check']),
124
+ value: z.string().optional(),
125
+ });
126
+ const getByPlaceholderSchema = baseCommandSchema.extend({
127
+ action: z.literal('getbyplaceholder'),
128
+ placeholder: z.string().min(1),
129
+ exact: z.boolean().optional(),
130
+ subaction: z.enum(['click', 'fill']),
131
+ value: z.string().optional(),
132
+ });
133
+ const cookiesGetSchema = baseCommandSchema.extend({
134
+ action: z.literal('cookies_get'),
135
+ urls: z.array(z.string()).optional(),
136
+ });
137
+ const cookiesSetSchema = baseCommandSchema.extend({
138
+ action: z.literal('cookies_set'),
139
+ cookies: z.array(z.object({
140
+ name: z.string(),
141
+ value: z.string(),
142
+ url: z.string().optional(),
143
+ domain: z.string().optional(),
144
+ path: z.string().optional(),
145
+ expires: z.number().optional(),
146
+ httpOnly: z.boolean().optional(),
147
+ secure: z.boolean().optional(),
148
+ sameSite: z.enum(['Strict', 'Lax', 'None']).optional(),
149
+ })),
150
+ });
151
+ const cookiesClearSchema = baseCommandSchema.extend({
152
+ action: z.literal('cookies_clear'),
153
+ });
154
+ const storageGetSchema = baseCommandSchema.extend({
155
+ action: z.literal('storage_get'),
156
+ key: z.string().optional(),
157
+ type: z.enum(['local', 'session']),
158
+ });
159
+ const storageSetSchema = baseCommandSchema.extend({
160
+ action: z.literal('storage_set'),
161
+ key: z.string().min(1),
162
+ value: z.string(),
163
+ type: z.enum(['local', 'session']),
164
+ });
165
+ const storageClearSchema = baseCommandSchema.extend({
166
+ action: z.literal('storage_clear'),
167
+ type: z.enum(['local', 'session']),
168
+ });
169
+ const dialogSchema = baseCommandSchema.extend({
170
+ action: z.literal('dialog'),
171
+ response: z.enum(['accept', 'dismiss']),
172
+ promptText: z.string().optional(),
173
+ });
174
+ const pdfSchema = baseCommandSchema.extend({
175
+ action: z.literal('pdf'),
176
+ path: z.string().min(1),
177
+ format: z
178
+ .enum(['Letter', 'Legal', 'Tabloid', 'Ledger', 'A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'A6'])
179
+ .optional(),
180
+ });
181
+ const routeSchema = baseCommandSchema.extend({
182
+ action: z.literal('route'),
183
+ url: z.string().min(1),
184
+ response: z
185
+ .object({
186
+ status: z.number().optional(),
187
+ body: z.string().optional(),
188
+ contentType: z.string().optional(),
189
+ headers: z.record(z.string()).optional(),
190
+ })
191
+ .optional(),
192
+ abort: z.boolean().optional(),
193
+ });
194
+ const unrouteSchema = baseCommandSchema.extend({
195
+ action: z.literal('unroute'),
196
+ url: z.string().optional(),
197
+ });
198
+ const requestsSchema = baseCommandSchema.extend({
199
+ action: z.literal('requests'),
200
+ filter: z.string().optional(),
201
+ clear: z.boolean().optional(),
202
+ });
203
+ const downloadSchema = baseCommandSchema.extend({
204
+ action: z.literal('download'),
205
+ selector: z.string().min(1),
206
+ path: z.string().min(1),
207
+ });
208
+ const geolocationSchema = baseCommandSchema.extend({
209
+ action: z.literal('geolocation'),
210
+ latitude: z.number(),
211
+ longitude: z.number(),
212
+ accuracy: z.number().optional(),
213
+ });
214
+ const permissionsSchema = baseCommandSchema.extend({
215
+ action: z.literal('permissions'),
216
+ permissions: z.array(z.string()),
217
+ grant: z.boolean(),
218
+ });
219
+ const viewportSchema = baseCommandSchema.extend({
220
+ action: z.literal('viewport'),
221
+ width: z.number().positive(),
222
+ height: z.number().positive(),
223
+ });
224
+ const userAgentSchema = baseCommandSchema.extend({
225
+ action: z.literal('useragent'),
226
+ userAgent: z.string().min(1),
227
+ });
228
+ const deviceSchema = baseCommandSchema.extend({
229
+ action: z.literal('device'),
230
+ device: z.string().min(1),
231
+ });
232
+ const backSchema = baseCommandSchema.extend({
233
+ action: z.literal('back'),
234
+ });
235
+ const forwardSchema = baseCommandSchema.extend({
236
+ action: z.literal('forward'),
237
+ });
238
+ const reloadSchema = baseCommandSchema.extend({
239
+ action: z.literal('reload'),
240
+ });
241
+ const urlSchema = baseCommandSchema.extend({
242
+ action: z.literal('url'),
243
+ });
244
+ const titleSchema = baseCommandSchema.extend({
245
+ action: z.literal('title'),
246
+ });
247
+ const getAttributeSchema = baseCommandSchema.extend({
248
+ action: z.literal('getattribute'),
249
+ selector: z.string().min(1),
250
+ attribute: z.string().min(1),
251
+ });
252
+ const getTextSchema = baseCommandSchema.extend({
253
+ action: z.literal('gettext'),
254
+ selector: z.string().min(1),
255
+ });
256
+ const isVisibleSchema = baseCommandSchema.extend({
257
+ action: z.literal('isvisible'),
258
+ selector: z.string().min(1),
259
+ });
260
+ const isEnabledSchema = baseCommandSchema.extend({
261
+ action: z.literal('isenabled'),
262
+ selector: z.string().min(1),
263
+ });
264
+ const isCheckedSchema = baseCommandSchema.extend({
265
+ action: z.literal('ischecked'),
266
+ selector: z.string().min(1),
267
+ });
268
+ const countSchema = baseCommandSchema.extend({
269
+ action: z.literal('count'),
270
+ selector: z.string().min(1),
271
+ });
272
+ const boundingBoxSchema = baseCommandSchema.extend({
273
+ action: z.literal('boundingbox'),
274
+ selector: z.string().min(1),
275
+ });
276
+ const stylesSchema = baseCommandSchema.extend({
277
+ action: z.literal('styles'),
278
+ selector: z.string().min(1),
279
+ });
280
+ const videoStartSchema = baseCommandSchema.extend({
281
+ action: z.literal('video_start'),
282
+ path: z.string().min(1),
283
+ });
284
+ const videoStopSchema = baseCommandSchema.extend({
285
+ action: z.literal('video_stop'),
286
+ });
287
+ // Recording schemas (Playwright native video recording)
288
+ const recordingStartSchema = baseCommandSchema.extend({
289
+ action: z.literal('recording_start'),
290
+ path: z.string().min(1),
291
+ url: z.string().min(1).optional(),
292
+ });
293
+ const recordingStopSchema = baseCommandSchema.extend({
294
+ action: z.literal('recording_stop'),
295
+ });
296
+ const recordingRestartSchema = baseCommandSchema.extend({
297
+ action: z.literal('recording_restart'),
298
+ path: z.string().min(1),
299
+ url: z.string().min(1).optional(),
300
+ });
301
+ const traceStartSchema = baseCommandSchema.extend({
302
+ action: z.literal('trace_start'),
303
+ screenshots: z.boolean().optional(),
304
+ snapshots: z.boolean().optional(),
305
+ });
306
+ const traceStopSchema = baseCommandSchema.extend({
307
+ action: z.literal('trace_stop'),
308
+ path: z.string().min(1),
309
+ });
310
+ const harStartSchema = baseCommandSchema.extend({
311
+ action: z.literal('har_start'),
312
+ });
313
+ const harStopSchema = baseCommandSchema.extend({
314
+ action: z.literal('har_stop'),
315
+ path: z.string().min(1),
316
+ });
317
+ const stateSaveSchema = baseCommandSchema.extend({
318
+ action: z.literal('state_save'),
319
+ path: z.string().min(1),
320
+ });
321
+ const stateLoadSchema = baseCommandSchema.extend({
322
+ action: z.literal('state_load'),
323
+ path: z.string().min(1),
324
+ });
325
+ const consoleSchema = baseCommandSchema.extend({
326
+ action: z.literal('console'),
327
+ clear: z.boolean().optional(),
328
+ });
329
+ const errorsSchema = baseCommandSchema.extend({
330
+ action: z.literal('errors'),
331
+ clear: z.boolean().optional(),
332
+ });
333
+ const keyboardSchema = baseCommandSchema.extend({
334
+ action: z.literal('keyboard'),
335
+ keys: z.string().min(1),
336
+ });
337
+ const wheelSchema = baseCommandSchema.extend({
338
+ action: z.literal('wheel'),
339
+ deltaX: z.number().optional(),
340
+ deltaY: z.number().optional(),
341
+ selector: z.string().optional(),
342
+ });
343
+ const tapSchema = baseCommandSchema.extend({
344
+ action: z.literal('tap'),
345
+ selector: z.string().min(1),
346
+ });
347
+ const clipboardSchema = baseCommandSchema.extend({
348
+ action: z.literal('clipboard'),
349
+ operation: z.enum(['copy', 'paste', 'read']),
350
+ text: z.string().optional(),
351
+ });
352
+ const highlightSchema = baseCommandSchema.extend({
353
+ action: z.literal('highlight'),
354
+ selector: z.string().min(1),
355
+ });
356
+ const clearSchema = baseCommandSchema.extend({
357
+ action: z.literal('clear'),
358
+ selector: z.string().min(1),
359
+ });
360
+ const selectAllSchema = baseCommandSchema.extend({
361
+ action: z.literal('selectall'),
362
+ selector: z.string().min(1),
363
+ });
364
+ const innerTextSchema = baseCommandSchema.extend({
365
+ action: z.literal('innertext'),
366
+ selector: z.string().min(1),
367
+ });
368
+ const innerHtmlSchema = baseCommandSchema.extend({
369
+ action: z.literal('innerhtml'),
370
+ selector: z.string().min(1),
371
+ });
372
+ const inputValueSchema = baseCommandSchema.extend({
373
+ action: z.literal('inputvalue'),
374
+ selector: z.string().min(1),
375
+ });
376
+ const setValueSchema = baseCommandSchema.extend({
377
+ action: z.literal('setvalue'),
378
+ selector: z.string().min(1),
379
+ value: z.string(),
380
+ });
381
+ const dispatchSchema = baseCommandSchema.extend({
382
+ action: z.literal('dispatch'),
383
+ selector: z.string().min(1),
384
+ event: z.string().min(1),
385
+ eventInit: z.record(z.unknown()).optional(),
386
+ });
387
+ const evalHandleSchema = baseCommandSchema.extend({
388
+ action: z.literal('evalhandle'),
389
+ script: z.string().min(1),
390
+ });
391
+ const exposeSchema = baseCommandSchema.extend({
392
+ action: z.literal('expose'),
393
+ name: z.string().min(1),
394
+ });
395
+ const addScriptSchema = baseCommandSchema.extend({
396
+ action: z.literal('addscript'),
397
+ content: z.string().optional(),
398
+ url: z.string().optional(),
399
+ });
400
+ const addStyleSchema = baseCommandSchema.extend({
401
+ action: z.literal('addstyle'),
402
+ content: z.string().optional(),
403
+ url: z.string().optional(),
404
+ });
405
+ const emulateMediaSchema = baseCommandSchema.extend({
406
+ action: z.literal('emulatemedia'),
407
+ media: z.enum(['screen', 'print']).nullable().optional(),
408
+ colorScheme: z.enum(['light', 'dark', 'no-preference']).nullable().optional(),
409
+ reducedMotion: z.enum(['reduce', 'no-preference']).nullable().optional(),
410
+ forcedColors: z.enum(['active', 'none']).nullable().optional(),
411
+ });
412
+ const offlineSchema = baseCommandSchema.extend({
413
+ action: z.literal('offline'),
414
+ offline: z.boolean(),
415
+ });
416
+ const headersSchema = baseCommandSchema.extend({
417
+ action: z.literal('headers'),
418
+ headers: z.record(z.string()),
419
+ });
420
+ const pauseSchema = baseCommandSchema.extend({
421
+ action: z.literal('pause'),
422
+ });
423
+ const getByAltTextSchema = baseCommandSchema.extend({
424
+ action: z.literal('getbyalttext'),
425
+ text: z.string().min(1),
426
+ exact: z.boolean().optional(),
427
+ subaction: z.enum(['click', 'hover']),
428
+ });
429
+ const getByTitleSchema = baseCommandSchema.extend({
430
+ action: z.literal('getbytitle'),
431
+ text: z.string().min(1),
432
+ exact: z.boolean().optional(),
433
+ subaction: z.enum(['click', 'hover']),
434
+ });
435
+ const getByTestIdSchema = baseCommandSchema.extend({
436
+ action: z.literal('getbytestid'),
437
+ testId: z.string().min(1),
438
+ subaction: z.enum(['click', 'fill', 'check', 'hover']),
439
+ value: z.string().optional(),
440
+ });
441
+ const nthSchema = baseCommandSchema.extend({
442
+ action: z.literal('nth'),
443
+ selector: z.string().min(1),
444
+ index: z.number(),
445
+ subaction: z.enum(['click', 'fill', 'check', 'hover', 'text']),
446
+ value: z.string().optional(),
447
+ });
448
+ const waitForUrlSchema = baseCommandSchema.extend({
449
+ action: z.literal('waitforurl'),
450
+ url: z.string().min(1),
451
+ timeout: z.number().positive().optional(),
452
+ });
453
+ const waitForLoadStateSchema = baseCommandSchema.extend({
454
+ action: z.literal('waitforloadstate'),
455
+ state: z.enum(['load', 'domcontentloaded', 'networkidle']),
456
+ timeout: z.number().positive().optional(),
457
+ });
458
+ const setContentSchema = baseCommandSchema.extend({
459
+ action: z.literal('setcontent'),
460
+ html: z.string(),
461
+ });
462
+ const timezoneSchema = baseCommandSchema.extend({
463
+ action: z.literal('timezone'),
464
+ timezone: z.string().min(1),
465
+ });
466
+ const localeSchema = baseCommandSchema.extend({
467
+ action: z.literal('locale'),
468
+ locale: z.string().min(1),
469
+ });
470
+ const credentialsSchema = baseCommandSchema.extend({
471
+ action: z.literal('credentials'),
472
+ username: z.string(),
473
+ password: z.string(),
474
+ });
475
+ const mouseMoveSchema = baseCommandSchema.extend({
476
+ action: z.literal('mousemove'),
477
+ x: z.number(),
478
+ y: z.number(),
479
+ });
480
+ const mouseDownSchema = baseCommandSchema.extend({
481
+ action: z.literal('mousedown'),
482
+ button: z.enum(['left', 'right', 'middle']).optional(),
483
+ });
484
+ const mouseUpSchema = baseCommandSchema.extend({
485
+ action: z.literal('mouseup'),
486
+ button: z.enum(['left', 'right', 'middle']).optional(),
487
+ });
488
+ const bringToFrontSchema = baseCommandSchema.extend({
489
+ action: z.literal('bringtofront'),
490
+ });
491
+ const waitForFunctionSchema = baseCommandSchema.extend({
492
+ action: z.literal('waitforfunction'),
493
+ expression: z.string().min(1),
494
+ timeout: z.number().positive().optional(),
495
+ });
496
+ const scrollIntoViewSchema = baseCommandSchema.extend({
497
+ action: z.literal('scrollintoview'),
498
+ selector: z.string().min(1),
499
+ });
500
+ const addInitScriptSchema = baseCommandSchema.extend({
501
+ action: z.literal('addinitscript'),
502
+ script: z.string().min(1),
503
+ });
504
+ const keyDownSchema = baseCommandSchema.extend({
505
+ action: z.literal('keydown'),
506
+ key: z.string().min(1),
507
+ });
508
+ const keyUpSchema = baseCommandSchema.extend({
509
+ action: z.literal('keyup'),
510
+ key: z.string().min(1),
511
+ });
512
+ const insertTextSchema = baseCommandSchema.extend({
513
+ action: z.literal('inserttext'),
514
+ text: z.string(),
515
+ });
516
+ const multiSelectSchema = baseCommandSchema.extend({
517
+ action: z.literal('multiselect'),
518
+ selector: z.string().min(1),
519
+ values: z.array(z.string()),
520
+ });
521
+ const waitForDownloadSchema = baseCommandSchema.extend({
522
+ action: z.literal('waitfordownload'),
523
+ path: z.string().optional(),
524
+ timeout: z.number().positive().optional(),
525
+ });
526
+ const responseBodySchema = baseCommandSchema.extend({
527
+ action: z.literal('responsebody'),
528
+ url: z.string().min(1),
529
+ timeout: z.number().positive().optional(),
530
+ });
531
+ // Screencast schemas for streaming browser viewport
532
+ const screencastStartSchema = baseCommandSchema.extend({
533
+ action: z.literal('screencast_start'),
534
+ format: z.enum(['jpeg', 'png']).optional(),
535
+ quality: z.number().min(0).max(100).optional(),
536
+ maxWidth: z.number().positive().optional(),
537
+ maxHeight: z.number().positive().optional(),
538
+ everyNthFrame: z.number().positive().optional(),
539
+ });
540
+ const screencastStopSchema = baseCommandSchema.extend({
541
+ action: z.literal('screencast_stop'),
542
+ });
543
+ // Input injection schemas for pair browsing
544
+ const inputMouseSchema = baseCommandSchema.extend({
545
+ action: z.literal('input_mouse'),
546
+ type: z.enum(['mousePressed', 'mouseReleased', 'mouseMoved', 'mouseWheel']),
547
+ x: z.number(),
548
+ y: z.number(),
549
+ button: z.enum(['left', 'right', 'middle', 'none']).optional(),
550
+ clickCount: z.number().positive().optional(),
551
+ deltaX: z.number().optional(),
552
+ deltaY: z.number().optional(),
553
+ modifiers: z.number().optional(),
554
+ });
555
+ const inputKeyboardSchema = baseCommandSchema.extend({
556
+ action: z.literal('input_keyboard'),
557
+ type: z.enum(['keyDown', 'keyUp', 'char']),
558
+ key: z.string().optional(),
559
+ code: z.string().optional(),
560
+ text: z.string().optional(),
561
+ modifiers: z.number().optional(),
562
+ });
563
+ const inputTouchSchema = baseCommandSchema.extend({
564
+ action: z.literal('input_touch'),
565
+ type: z.enum(['touchStart', 'touchEnd', 'touchMove', 'touchCancel']),
566
+ touchPoints: z.array(z.object({
567
+ x: z.number(),
568
+ y: z.number(),
569
+ id: z.number().optional(),
570
+ })),
571
+ modifiers: z.number().optional(),
572
+ });
573
+ // iOS-specific schemas
574
+ const swipeSchema = baseCommandSchema.extend({
575
+ action: z.literal('swipe'),
576
+ direction: z.enum(['up', 'down', 'left', 'right']),
577
+ distance: z.number().positive().optional(),
578
+ });
579
+ const deviceListSchema = baseCommandSchema.extend({
580
+ action: z.literal('device_list'),
581
+ });
582
+ const pressSchema = baseCommandSchema.extend({
583
+ action: z.literal('press'),
584
+ key: z.string().min(1),
585
+ selector: z.string().min(1).optional(),
586
+ });
587
+ const screenshotSchema = baseCommandSchema.extend({
588
+ action: z.literal('screenshot'),
589
+ path: z.string().nullable().optional(),
590
+ fullPage: z.boolean().optional(),
591
+ selector: z.string().min(1).nullish(),
592
+ format: z.enum(['png', 'jpeg']).optional(),
593
+ quality: z.number().min(0).max(100).optional(),
594
+ });
595
+ const snapshotSchema = baseCommandSchema.extend({
596
+ action: z.literal('snapshot'),
597
+ interactive: z.boolean().optional(),
598
+ maxDepth: z.number().nonnegative().optional(),
599
+ compact: z.boolean().optional(),
600
+ selector: z.string().optional(),
601
+ });
602
+ const evaluateSchema = baseCommandSchema.extend({
603
+ action: z.literal('evaluate'),
604
+ script: z.string().min(1),
605
+ args: z.array(z.unknown()).optional(),
606
+ });
607
+ const waitSchema = baseCommandSchema.extend({
608
+ action: z.literal('wait'),
609
+ selector: z.string().min(1).optional(),
610
+ timeout: z.number().positive().optional(),
611
+ state: z.enum(['attached', 'detached', 'visible', 'hidden']).optional(),
612
+ });
613
+ const scrollSchema = baseCommandSchema.extend({
614
+ action: z.literal('scroll'),
615
+ selector: z.string().min(1).optional(),
616
+ x: z.number().optional(),
617
+ y: z.number().optional(),
618
+ direction: z.enum(['up', 'down', 'left', 'right']).optional(),
619
+ amount: z.number().positive().optional(),
620
+ });
621
+ const selectSchema = baseCommandSchema.extend({
622
+ action: z.literal('select'),
623
+ selector: z.string().min(1),
624
+ values: z.union([z.string(), z.array(z.string())]),
625
+ });
626
+ const hoverSchema = baseCommandSchema.extend({
627
+ action: z.literal('hover'),
628
+ selector: z.string().min(1),
629
+ });
630
+ const contentSchema = baseCommandSchema.extend({
631
+ action: z.literal('content'),
632
+ selector: z.string().min(1).optional(),
633
+ });
634
+ const closeSchema = baseCommandSchema.extend({
635
+ action: z.literal('close'),
636
+ });
637
+ // Tab/Window schemas
638
+ const tabNewSchema = baseCommandSchema.extend({
639
+ action: z.literal('tab_new'),
640
+ url: z.string().min(1).optional(),
641
+ });
642
+ const tabListSchema = baseCommandSchema.extend({
643
+ action: z.literal('tab_list'),
644
+ });
645
+ const tabSwitchSchema = baseCommandSchema.extend({
646
+ action: z.literal('tab_switch'),
647
+ index: z.number().nonnegative(),
648
+ });
649
+ const tabCloseSchema = baseCommandSchema.extend({
650
+ action: z.literal('tab_close'),
651
+ index: z.number().nonnegative().optional(),
652
+ });
653
+ const windowNewSchema = baseCommandSchema.extend({
654
+ action: z.literal('window_new'),
655
+ viewport: z
656
+ .object({
657
+ width: z.number().positive(),
658
+ height: z.number().positive(),
659
+ })
660
+ .optional(),
661
+ });
662
+ // Union schema for all commands
663
+ const commandSchema = z.discriminatedUnion('action', [
664
+ launchSchema,
665
+ navigateSchema,
666
+ clickSchema,
667
+ typeSchema,
668
+ fillSchema,
669
+ checkSchema,
670
+ uncheckSchema,
671
+ uploadSchema,
672
+ dblclickSchema,
673
+ focusSchema,
674
+ dragSchema,
675
+ frameSchema,
676
+ mainframeSchema,
677
+ getByRoleSchema,
678
+ getByTextSchema,
679
+ getByLabelSchema,
680
+ getByPlaceholderSchema,
681
+ pressSchema,
682
+ screenshotSchema,
683
+ snapshotSchema,
684
+ evaluateSchema,
685
+ waitSchema,
686
+ scrollSchema,
687
+ selectSchema,
688
+ hoverSchema,
689
+ contentSchema,
690
+ closeSchema,
691
+ tabNewSchema,
692
+ tabListSchema,
693
+ tabSwitchSchema,
694
+ tabCloseSchema,
695
+ windowNewSchema,
696
+ cookiesGetSchema,
697
+ cookiesSetSchema,
698
+ cookiesClearSchema,
699
+ storageGetSchema,
700
+ storageSetSchema,
701
+ storageClearSchema,
702
+ dialogSchema,
703
+ pdfSchema,
704
+ routeSchema,
705
+ unrouteSchema,
706
+ requestsSchema,
707
+ downloadSchema,
708
+ geolocationSchema,
709
+ permissionsSchema,
710
+ viewportSchema,
711
+ userAgentSchema,
712
+ deviceSchema,
713
+ backSchema,
714
+ forwardSchema,
715
+ reloadSchema,
716
+ urlSchema,
717
+ titleSchema,
718
+ getAttributeSchema,
719
+ getTextSchema,
720
+ isVisibleSchema,
721
+ isEnabledSchema,
722
+ isCheckedSchema,
723
+ countSchema,
724
+ boundingBoxSchema,
725
+ stylesSchema,
726
+ videoStartSchema,
727
+ videoStopSchema,
728
+ recordingStartSchema,
729
+ recordingStopSchema,
730
+ recordingRestartSchema,
731
+ traceStartSchema,
732
+ traceStopSchema,
733
+ harStartSchema,
734
+ harStopSchema,
735
+ stateSaveSchema,
736
+ stateLoadSchema,
737
+ consoleSchema,
738
+ errorsSchema,
739
+ keyboardSchema,
740
+ wheelSchema,
741
+ tapSchema,
742
+ clipboardSchema,
743
+ highlightSchema,
744
+ clearSchema,
745
+ selectAllSchema,
746
+ innerTextSchema,
747
+ innerHtmlSchema,
748
+ inputValueSchema,
749
+ setValueSchema,
750
+ dispatchSchema,
751
+ evalHandleSchema,
752
+ exposeSchema,
753
+ addScriptSchema,
754
+ addStyleSchema,
755
+ emulateMediaSchema,
756
+ offlineSchema,
757
+ headersSchema,
758
+ pauseSchema,
759
+ getByAltTextSchema,
760
+ getByTitleSchema,
761
+ getByTestIdSchema,
762
+ nthSchema,
763
+ waitForUrlSchema,
764
+ waitForLoadStateSchema,
765
+ setContentSchema,
766
+ timezoneSchema,
767
+ localeSchema,
768
+ credentialsSchema,
769
+ mouseMoveSchema,
770
+ mouseDownSchema,
771
+ mouseUpSchema,
772
+ bringToFrontSchema,
773
+ waitForFunctionSchema,
774
+ scrollIntoViewSchema,
775
+ addInitScriptSchema,
776
+ keyDownSchema,
777
+ keyUpSchema,
778
+ insertTextSchema,
779
+ multiSelectSchema,
780
+ waitForDownloadSchema,
781
+ responseBodySchema,
782
+ screencastStartSchema,
783
+ screencastStopSchema,
784
+ inputMouseSchema,
785
+ inputKeyboardSchema,
786
+ inputTouchSchema,
787
+ swipeSchema,
788
+ deviceListSchema,
789
+ ]);
790
+ /**
791
+ * Parse a JSON string into a validated command
792
+ */
793
+ export function parseCommand(input) {
794
+ // First, try to parse JSON
795
+ let json;
796
+ try {
797
+ json = JSON.parse(input);
798
+ }
799
+ catch {
800
+ return { success: false, error: 'Invalid JSON' };
801
+ }
802
+ // Extract id for error responses if possible
803
+ const id = typeof json === 'object' && json !== null && 'id' in json
804
+ ? String(json.id)
805
+ : undefined;
806
+ // Validate against schema
807
+ const result = commandSchema.safeParse(json);
808
+ if (!result.success) {
809
+ const errors = result.error.errors.map((e) => `${e.path.join('.')}: ${e.message}`).join(', ');
810
+ return { success: false, error: `Validation error: ${errors}`, id };
811
+ }
812
+ return { success: true, command: result.data };
813
+ }
814
+ /**
815
+ * Create a success response
816
+ */
817
+ export function successResponse(id, data) {
818
+ return { id, success: true, data };
819
+ }
820
+ /**
821
+ * Create an error response
822
+ */
823
+ export function errorResponse(id, error) {
824
+ return { id, success: false, error };
825
+ }
826
+ /**
827
+ * Serialize a response to JSON string
828
+ */
829
+ export function serializeResponse(response) {
830
+ return JSON.stringify(response);
831
+ }
832
+ //# sourceMappingURL=protocol.js.map