@spicrawl/mcp 0.0.0-stage → 0.1.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +61 -0
  3. package/README.md +251 -2
  4. package/dist/client.d.ts +89 -0
  5. package/dist/client.js +187 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/http.d.ts +27 -0
  8. package/dist/http.js +220 -0
  9. package/dist/http.js.map +1 -0
  10. package/dist/index.d.ts +30 -0
  11. package/dist/index.js +79 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/server.d.ts +16 -0
  14. package/dist/server.js +141 -0
  15. package/dist/server.js.map +1 -0
  16. package/dist/tools/actions.d.ts +534 -0
  17. package/dist/tools/actions.js +103 -0
  18. package/dist/tools/actions.js.map +1 -0
  19. package/dist/tools/batch.d.ts +2 -0
  20. package/dist/tools/batch.js +307 -0
  21. package/dist/tools/batch.js.map +1 -0
  22. package/dist/tools/browser.d.ts +2 -0
  23. package/dist/tools/browser.js +101 -0
  24. package/dist/tools/browser.js.map +1 -0
  25. package/dist/tools/common.d.ts +64 -0
  26. package/dist/tools/common.js +64 -0
  27. package/dist/tools/common.js.map +1 -0
  28. package/dist/tools/docs.d.ts +12 -0
  29. package/dist/tools/docs.js +277 -0
  30. package/dist/tools/docs.js.map +1 -0
  31. package/dist/tools/pdf.d.ts +11 -0
  32. package/dist/tools/pdf.js +36 -0
  33. package/dist/tools/pdf.js.map +1 -0
  34. package/dist/tools/requests.d.ts +2 -0
  35. package/dist/tools/requests.js +71 -0
  36. package/dist/tools/requests.js.map +1 -0
  37. package/dist/tools/scrape.d.ts +2 -0
  38. package/dist/tools/scrape.js +213 -0
  39. package/dist/tools/scrape.js.map +1 -0
  40. package/dist/tools/screenshots.d.ts +15 -0
  41. package/dist/tools/screenshots.js +69 -0
  42. package/dist/tools/screenshots.js.map +1 -0
  43. package/dist/tools/sessions.d.ts +2 -0
  44. package/dist/tools/sessions.js +145 -0
  45. package/dist/tools/sessions.js.map +1 -0
  46. package/dist/tools/usage.d.ts +2 -0
  47. package/dist/tools/usage.js +93 -0
  48. package/dist/tools/usage.js.map +1 -0
  49. package/package.json +67 -4
@@ -0,0 +1,534 @@
1
+ import { z } from "zod";
2
+ export declare const ActionSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
3
+ type: z.ZodLiteral<"click">;
4
+ } & {
5
+ selector: z.ZodString;
6
+ wait_for_navigation: z.ZodOptional<z.ZodBoolean>;
7
+ until: z.ZodOptional<z.ZodEnum<["load", "domcontentloaded", "networkidle"]>>;
8
+ } & {
9
+ timeout_ms: z.ZodOptional<z.ZodNumber>;
10
+ on_error: z.ZodOptional<z.ZodEnum<["fail", "skip"]>>;
11
+ label: z.ZodOptional<z.ZodString>;
12
+ }, "strict", z.ZodTypeAny, {
13
+ type: "click";
14
+ selector: string;
15
+ timeout_ms?: number | undefined;
16
+ on_error?: "fail" | "skip" | undefined;
17
+ label?: string | undefined;
18
+ wait_for_navigation?: boolean | undefined;
19
+ until?: "load" | "domcontentloaded" | "networkidle" | undefined;
20
+ }, {
21
+ type: "click";
22
+ selector: string;
23
+ timeout_ms?: number | undefined;
24
+ on_error?: "fail" | "skip" | undefined;
25
+ label?: string | undefined;
26
+ wait_for_navigation?: boolean | undefined;
27
+ until?: "load" | "domcontentloaded" | "networkidle" | undefined;
28
+ }>, z.ZodObject<{
29
+ type: z.ZodLiteral<"fill">;
30
+ } & {
31
+ selector: z.ZodString;
32
+ value: z.ZodString;
33
+ secret: z.ZodOptional<z.ZodBoolean>;
34
+ } & {
35
+ timeout_ms: z.ZodOptional<z.ZodNumber>;
36
+ on_error: z.ZodOptional<z.ZodEnum<["fail", "skip"]>>;
37
+ label: z.ZodOptional<z.ZodString>;
38
+ }, "strict", z.ZodTypeAny, {
39
+ type: "fill";
40
+ value: string;
41
+ selector: string;
42
+ timeout_ms?: number | undefined;
43
+ on_error?: "fail" | "skip" | undefined;
44
+ label?: string | undefined;
45
+ secret?: boolean | undefined;
46
+ }, {
47
+ type: "fill";
48
+ value: string;
49
+ selector: string;
50
+ timeout_ms?: number | undefined;
51
+ on_error?: "fail" | "skip" | undefined;
52
+ label?: string | undefined;
53
+ secret?: boolean | undefined;
54
+ }>, z.ZodObject<{
55
+ type: z.ZodLiteral<"wait_for">;
56
+ } & {
57
+ selector: z.ZodOptional<z.ZodString>;
58
+ ms: z.ZodOptional<z.ZodNumber>;
59
+ } & {
60
+ timeout_ms: z.ZodOptional<z.ZodNumber>;
61
+ on_error: z.ZodOptional<z.ZodEnum<["fail", "skip"]>>;
62
+ label: z.ZodOptional<z.ZodString>;
63
+ }, "strict", z.ZodTypeAny, {
64
+ type: "wait_for";
65
+ timeout_ms?: number | undefined;
66
+ on_error?: "fail" | "skip" | undefined;
67
+ label?: string | undefined;
68
+ selector?: string | undefined;
69
+ ms?: number | undefined;
70
+ }, {
71
+ type: "wait_for";
72
+ timeout_ms?: number | undefined;
73
+ on_error?: "fail" | "skip" | undefined;
74
+ label?: string | undefined;
75
+ selector?: string | undefined;
76
+ ms?: number | undefined;
77
+ }>, z.ZodObject<{
78
+ type: z.ZodLiteral<"wait_for_navigation">;
79
+ } & {
80
+ until: z.ZodOptional<z.ZodEnum<["load", "domcontentloaded", "networkidle"]>>;
81
+ } & {
82
+ timeout_ms: z.ZodOptional<z.ZodNumber>;
83
+ on_error: z.ZodOptional<z.ZodEnum<["fail", "skip"]>>;
84
+ label: z.ZodOptional<z.ZodString>;
85
+ }, "strict", z.ZodTypeAny, {
86
+ type: "wait_for_navigation";
87
+ timeout_ms?: number | undefined;
88
+ on_error?: "fail" | "skip" | undefined;
89
+ label?: string | undefined;
90
+ until?: "load" | "domcontentloaded" | "networkidle" | undefined;
91
+ }, {
92
+ type: "wait_for_navigation";
93
+ timeout_ms?: number | undefined;
94
+ on_error?: "fail" | "skip" | undefined;
95
+ label?: string | undefined;
96
+ until?: "load" | "domcontentloaded" | "networkidle" | undefined;
97
+ }>, z.ZodObject<{
98
+ type: z.ZodLiteral<"scroll">;
99
+ } & {
100
+ y: z.ZodOptional<z.ZodNumber>;
101
+ to_bottom: z.ZodOptional<z.ZodBoolean>;
102
+ selector: z.ZodOptional<z.ZodString>;
103
+ } & {
104
+ timeout_ms: z.ZodOptional<z.ZodNumber>;
105
+ on_error: z.ZodOptional<z.ZodEnum<["fail", "skip"]>>;
106
+ label: z.ZodOptional<z.ZodString>;
107
+ }, "strict", z.ZodTypeAny, {
108
+ type: "scroll";
109
+ timeout_ms?: number | undefined;
110
+ on_error?: "fail" | "skip" | undefined;
111
+ label?: string | undefined;
112
+ selector?: string | undefined;
113
+ y?: number | undefined;
114
+ to_bottom?: boolean | undefined;
115
+ }, {
116
+ type: "scroll";
117
+ timeout_ms?: number | undefined;
118
+ on_error?: "fail" | "skip" | undefined;
119
+ label?: string | undefined;
120
+ selector?: string | undefined;
121
+ y?: number | undefined;
122
+ to_bottom?: boolean | undefined;
123
+ }>, z.ZodObject<{
124
+ type: z.ZodLiteral<"select">;
125
+ } & {
126
+ selector: z.ZodString;
127
+ value: z.ZodOptional<z.ZodString>;
128
+ values: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
129
+ } & {
130
+ timeout_ms: z.ZodOptional<z.ZodNumber>;
131
+ on_error: z.ZodOptional<z.ZodEnum<["fail", "skip"]>>;
132
+ label: z.ZodOptional<z.ZodString>;
133
+ }, "strict", z.ZodTypeAny, {
134
+ type: "select";
135
+ selector: string;
136
+ values?: string[] | undefined;
137
+ value?: string | undefined;
138
+ timeout_ms?: number | undefined;
139
+ on_error?: "fail" | "skip" | undefined;
140
+ label?: string | undefined;
141
+ }, {
142
+ type: "select";
143
+ selector: string;
144
+ values?: string[] | undefined;
145
+ value?: string | undefined;
146
+ timeout_ms?: number | undefined;
147
+ on_error?: "fail" | "skip" | undefined;
148
+ label?: string | undefined;
149
+ }>, z.ZodObject<{
150
+ type: z.ZodLiteral<"evaluate">;
151
+ } & {
152
+ expression: z.ZodString;
153
+ return_value: z.ZodOptional<z.ZodBoolean>;
154
+ await_promise: z.ZodOptional<z.ZodBoolean>;
155
+ } & {
156
+ timeout_ms: z.ZodOptional<z.ZodNumber>;
157
+ on_error: z.ZodOptional<z.ZodEnum<["fail", "skip"]>>;
158
+ label: z.ZodOptional<z.ZodString>;
159
+ }, "strict", z.ZodTypeAny, {
160
+ type: "evaluate";
161
+ expression: string;
162
+ timeout_ms?: number | undefined;
163
+ on_error?: "fail" | "skip" | undefined;
164
+ label?: string | undefined;
165
+ return_value?: boolean | undefined;
166
+ await_promise?: boolean | undefined;
167
+ }, {
168
+ type: "evaluate";
169
+ expression: string;
170
+ timeout_ms?: number | undefined;
171
+ on_error?: "fail" | "skip" | undefined;
172
+ label?: string | undefined;
173
+ return_value?: boolean | undefined;
174
+ await_promise?: boolean | undefined;
175
+ }>, z.ZodObject<{
176
+ type: z.ZodLiteral<"screenshot">;
177
+ } & {
178
+ full_page: z.ZodOptional<z.ZodBoolean>;
179
+ selector: z.ZodOptional<z.ZodString>;
180
+ format: z.ZodOptional<z.ZodEnum<["png", "jpeg", "webp"]>>;
181
+ quality: z.ZodOptional<z.ZodNumber>;
182
+ } & {
183
+ timeout_ms: z.ZodOptional<z.ZodNumber>;
184
+ on_error: z.ZodOptional<z.ZodEnum<["fail", "skip"]>>;
185
+ label: z.ZodOptional<z.ZodString>;
186
+ }, "strict", z.ZodTypeAny, {
187
+ type: "screenshot";
188
+ format?: "png" | "jpeg" | "webp" | undefined;
189
+ timeout_ms?: number | undefined;
190
+ on_error?: "fail" | "skip" | undefined;
191
+ label?: string | undefined;
192
+ selector?: string | undefined;
193
+ full_page?: boolean | undefined;
194
+ quality?: number | undefined;
195
+ }, {
196
+ type: "screenshot";
197
+ format?: "png" | "jpeg" | "webp" | undefined;
198
+ timeout_ms?: number | undefined;
199
+ on_error?: "fail" | "skip" | undefined;
200
+ label?: string | undefined;
201
+ selector?: string | undefined;
202
+ full_page?: boolean | undefined;
203
+ quality?: number | undefined;
204
+ }>]>;
205
+ export type Action = z.infer<typeof ActionSchema>;
206
+ export declare const ActionsSchema: z.ZodEffects<z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
207
+ type: z.ZodLiteral<"click">;
208
+ } & {
209
+ selector: z.ZodString;
210
+ wait_for_navigation: z.ZodOptional<z.ZodBoolean>;
211
+ until: z.ZodOptional<z.ZodEnum<["load", "domcontentloaded", "networkidle"]>>;
212
+ } & {
213
+ timeout_ms: z.ZodOptional<z.ZodNumber>;
214
+ on_error: z.ZodOptional<z.ZodEnum<["fail", "skip"]>>;
215
+ label: z.ZodOptional<z.ZodString>;
216
+ }, "strict", z.ZodTypeAny, {
217
+ type: "click";
218
+ selector: string;
219
+ timeout_ms?: number | undefined;
220
+ on_error?: "fail" | "skip" | undefined;
221
+ label?: string | undefined;
222
+ wait_for_navigation?: boolean | undefined;
223
+ until?: "load" | "domcontentloaded" | "networkidle" | undefined;
224
+ }, {
225
+ type: "click";
226
+ selector: string;
227
+ timeout_ms?: number | undefined;
228
+ on_error?: "fail" | "skip" | undefined;
229
+ label?: string | undefined;
230
+ wait_for_navigation?: boolean | undefined;
231
+ until?: "load" | "domcontentloaded" | "networkidle" | undefined;
232
+ }>, z.ZodObject<{
233
+ type: z.ZodLiteral<"fill">;
234
+ } & {
235
+ selector: z.ZodString;
236
+ value: z.ZodString;
237
+ secret: z.ZodOptional<z.ZodBoolean>;
238
+ } & {
239
+ timeout_ms: z.ZodOptional<z.ZodNumber>;
240
+ on_error: z.ZodOptional<z.ZodEnum<["fail", "skip"]>>;
241
+ label: z.ZodOptional<z.ZodString>;
242
+ }, "strict", z.ZodTypeAny, {
243
+ type: "fill";
244
+ value: string;
245
+ selector: string;
246
+ timeout_ms?: number | undefined;
247
+ on_error?: "fail" | "skip" | undefined;
248
+ label?: string | undefined;
249
+ secret?: boolean | undefined;
250
+ }, {
251
+ type: "fill";
252
+ value: string;
253
+ selector: string;
254
+ timeout_ms?: number | undefined;
255
+ on_error?: "fail" | "skip" | undefined;
256
+ label?: string | undefined;
257
+ secret?: boolean | undefined;
258
+ }>, z.ZodObject<{
259
+ type: z.ZodLiteral<"wait_for">;
260
+ } & {
261
+ selector: z.ZodOptional<z.ZodString>;
262
+ ms: z.ZodOptional<z.ZodNumber>;
263
+ } & {
264
+ timeout_ms: z.ZodOptional<z.ZodNumber>;
265
+ on_error: z.ZodOptional<z.ZodEnum<["fail", "skip"]>>;
266
+ label: z.ZodOptional<z.ZodString>;
267
+ }, "strict", z.ZodTypeAny, {
268
+ type: "wait_for";
269
+ timeout_ms?: number | undefined;
270
+ on_error?: "fail" | "skip" | undefined;
271
+ label?: string | undefined;
272
+ selector?: string | undefined;
273
+ ms?: number | undefined;
274
+ }, {
275
+ type: "wait_for";
276
+ timeout_ms?: number | undefined;
277
+ on_error?: "fail" | "skip" | undefined;
278
+ label?: string | undefined;
279
+ selector?: string | undefined;
280
+ ms?: number | undefined;
281
+ }>, z.ZodObject<{
282
+ type: z.ZodLiteral<"wait_for_navigation">;
283
+ } & {
284
+ until: z.ZodOptional<z.ZodEnum<["load", "domcontentloaded", "networkidle"]>>;
285
+ } & {
286
+ timeout_ms: z.ZodOptional<z.ZodNumber>;
287
+ on_error: z.ZodOptional<z.ZodEnum<["fail", "skip"]>>;
288
+ label: z.ZodOptional<z.ZodString>;
289
+ }, "strict", z.ZodTypeAny, {
290
+ type: "wait_for_navigation";
291
+ timeout_ms?: number | undefined;
292
+ on_error?: "fail" | "skip" | undefined;
293
+ label?: string | undefined;
294
+ until?: "load" | "domcontentloaded" | "networkidle" | undefined;
295
+ }, {
296
+ type: "wait_for_navigation";
297
+ timeout_ms?: number | undefined;
298
+ on_error?: "fail" | "skip" | undefined;
299
+ label?: string | undefined;
300
+ until?: "load" | "domcontentloaded" | "networkidle" | undefined;
301
+ }>, z.ZodObject<{
302
+ type: z.ZodLiteral<"scroll">;
303
+ } & {
304
+ y: z.ZodOptional<z.ZodNumber>;
305
+ to_bottom: z.ZodOptional<z.ZodBoolean>;
306
+ selector: z.ZodOptional<z.ZodString>;
307
+ } & {
308
+ timeout_ms: z.ZodOptional<z.ZodNumber>;
309
+ on_error: z.ZodOptional<z.ZodEnum<["fail", "skip"]>>;
310
+ label: z.ZodOptional<z.ZodString>;
311
+ }, "strict", z.ZodTypeAny, {
312
+ type: "scroll";
313
+ timeout_ms?: number | undefined;
314
+ on_error?: "fail" | "skip" | undefined;
315
+ label?: string | undefined;
316
+ selector?: string | undefined;
317
+ y?: number | undefined;
318
+ to_bottom?: boolean | undefined;
319
+ }, {
320
+ type: "scroll";
321
+ timeout_ms?: number | undefined;
322
+ on_error?: "fail" | "skip" | undefined;
323
+ label?: string | undefined;
324
+ selector?: string | undefined;
325
+ y?: number | undefined;
326
+ to_bottom?: boolean | undefined;
327
+ }>, z.ZodObject<{
328
+ type: z.ZodLiteral<"select">;
329
+ } & {
330
+ selector: z.ZodString;
331
+ value: z.ZodOptional<z.ZodString>;
332
+ values: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
333
+ } & {
334
+ timeout_ms: z.ZodOptional<z.ZodNumber>;
335
+ on_error: z.ZodOptional<z.ZodEnum<["fail", "skip"]>>;
336
+ label: z.ZodOptional<z.ZodString>;
337
+ }, "strict", z.ZodTypeAny, {
338
+ type: "select";
339
+ selector: string;
340
+ values?: string[] | undefined;
341
+ value?: string | undefined;
342
+ timeout_ms?: number | undefined;
343
+ on_error?: "fail" | "skip" | undefined;
344
+ label?: string | undefined;
345
+ }, {
346
+ type: "select";
347
+ selector: string;
348
+ values?: string[] | undefined;
349
+ value?: string | undefined;
350
+ timeout_ms?: number | undefined;
351
+ on_error?: "fail" | "skip" | undefined;
352
+ label?: string | undefined;
353
+ }>, z.ZodObject<{
354
+ type: z.ZodLiteral<"evaluate">;
355
+ } & {
356
+ expression: z.ZodString;
357
+ return_value: z.ZodOptional<z.ZodBoolean>;
358
+ await_promise: z.ZodOptional<z.ZodBoolean>;
359
+ } & {
360
+ timeout_ms: z.ZodOptional<z.ZodNumber>;
361
+ on_error: z.ZodOptional<z.ZodEnum<["fail", "skip"]>>;
362
+ label: z.ZodOptional<z.ZodString>;
363
+ }, "strict", z.ZodTypeAny, {
364
+ type: "evaluate";
365
+ expression: string;
366
+ timeout_ms?: number | undefined;
367
+ on_error?: "fail" | "skip" | undefined;
368
+ label?: string | undefined;
369
+ return_value?: boolean | undefined;
370
+ await_promise?: boolean | undefined;
371
+ }, {
372
+ type: "evaluate";
373
+ expression: string;
374
+ timeout_ms?: number | undefined;
375
+ on_error?: "fail" | "skip" | undefined;
376
+ label?: string | undefined;
377
+ return_value?: boolean | undefined;
378
+ await_promise?: boolean | undefined;
379
+ }>, z.ZodObject<{
380
+ type: z.ZodLiteral<"screenshot">;
381
+ } & {
382
+ full_page: z.ZodOptional<z.ZodBoolean>;
383
+ selector: z.ZodOptional<z.ZodString>;
384
+ format: z.ZodOptional<z.ZodEnum<["png", "jpeg", "webp"]>>;
385
+ quality: z.ZodOptional<z.ZodNumber>;
386
+ } & {
387
+ timeout_ms: z.ZodOptional<z.ZodNumber>;
388
+ on_error: z.ZodOptional<z.ZodEnum<["fail", "skip"]>>;
389
+ label: z.ZodOptional<z.ZodString>;
390
+ }, "strict", z.ZodTypeAny, {
391
+ type: "screenshot";
392
+ format?: "png" | "jpeg" | "webp" | undefined;
393
+ timeout_ms?: number | undefined;
394
+ on_error?: "fail" | "skip" | undefined;
395
+ label?: string | undefined;
396
+ selector?: string | undefined;
397
+ full_page?: boolean | undefined;
398
+ quality?: number | undefined;
399
+ }, {
400
+ type: "screenshot";
401
+ format?: "png" | "jpeg" | "webp" | undefined;
402
+ timeout_ms?: number | undefined;
403
+ on_error?: "fail" | "skip" | undefined;
404
+ label?: string | undefined;
405
+ selector?: string | undefined;
406
+ full_page?: boolean | undefined;
407
+ quality?: number | undefined;
408
+ }>]>, "many">, ({
409
+ type: "click";
410
+ selector: string;
411
+ timeout_ms?: number | undefined;
412
+ on_error?: "fail" | "skip" | undefined;
413
+ label?: string | undefined;
414
+ wait_for_navigation?: boolean | undefined;
415
+ until?: "load" | "domcontentloaded" | "networkidle" | undefined;
416
+ } | {
417
+ type: "fill";
418
+ value: string;
419
+ selector: string;
420
+ timeout_ms?: number | undefined;
421
+ on_error?: "fail" | "skip" | undefined;
422
+ label?: string | undefined;
423
+ secret?: boolean | undefined;
424
+ } | {
425
+ type: "wait_for";
426
+ timeout_ms?: number | undefined;
427
+ on_error?: "fail" | "skip" | undefined;
428
+ label?: string | undefined;
429
+ selector?: string | undefined;
430
+ ms?: number | undefined;
431
+ } | {
432
+ type: "wait_for_navigation";
433
+ timeout_ms?: number | undefined;
434
+ on_error?: "fail" | "skip" | undefined;
435
+ label?: string | undefined;
436
+ until?: "load" | "domcontentloaded" | "networkidle" | undefined;
437
+ } | {
438
+ type: "scroll";
439
+ timeout_ms?: number | undefined;
440
+ on_error?: "fail" | "skip" | undefined;
441
+ label?: string | undefined;
442
+ selector?: string | undefined;
443
+ y?: number | undefined;
444
+ to_bottom?: boolean | undefined;
445
+ } | {
446
+ type: "select";
447
+ selector: string;
448
+ values?: string[] | undefined;
449
+ value?: string | undefined;
450
+ timeout_ms?: number | undefined;
451
+ on_error?: "fail" | "skip" | undefined;
452
+ label?: string | undefined;
453
+ } | {
454
+ type: "evaluate";
455
+ expression: string;
456
+ timeout_ms?: number | undefined;
457
+ on_error?: "fail" | "skip" | undefined;
458
+ label?: string | undefined;
459
+ return_value?: boolean | undefined;
460
+ await_promise?: boolean | undefined;
461
+ } | {
462
+ type: "screenshot";
463
+ format?: "png" | "jpeg" | "webp" | undefined;
464
+ timeout_ms?: number | undefined;
465
+ on_error?: "fail" | "skip" | undefined;
466
+ label?: string | undefined;
467
+ selector?: string | undefined;
468
+ full_page?: boolean | undefined;
469
+ quality?: number | undefined;
470
+ })[], ({
471
+ type: "click";
472
+ selector: string;
473
+ timeout_ms?: number | undefined;
474
+ on_error?: "fail" | "skip" | undefined;
475
+ label?: string | undefined;
476
+ wait_for_navigation?: boolean | undefined;
477
+ until?: "load" | "domcontentloaded" | "networkidle" | undefined;
478
+ } | {
479
+ type: "fill";
480
+ value: string;
481
+ selector: string;
482
+ timeout_ms?: number | undefined;
483
+ on_error?: "fail" | "skip" | undefined;
484
+ label?: string | undefined;
485
+ secret?: boolean | undefined;
486
+ } | {
487
+ type: "wait_for";
488
+ timeout_ms?: number | undefined;
489
+ on_error?: "fail" | "skip" | undefined;
490
+ label?: string | undefined;
491
+ selector?: string | undefined;
492
+ ms?: number | undefined;
493
+ } | {
494
+ type: "wait_for_navigation";
495
+ timeout_ms?: number | undefined;
496
+ on_error?: "fail" | "skip" | undefined;
497
+ label?: string | undefined;
498
+ until?: "load" | "domcontentloaded" | "networkidle" | undefined;
499
+ } | {
500
+ type: "scroll";
501
+ timeout_ms?: number | undefined;
502
+ on_error?: "fail" | "skip" | undefined;
503
+ label?: string | undefined;
504
+ selector?: string | undefined;
505
+ y?: number | undefined;
506
+ to_bottom?: boolean | undefined;
507
+ } | {
508
+ type: "select";
509
+ selector: string;
510
+ values?: string[] | undefined;
511
+ value?: string | undefined;
512
+ timeout_ms?: number | undefined;
513
+ on_error?: "fail" | "skip" | undefined;
514
+ label?: string | undefined;
515
+ } | {
516
+ type: "evaluate";
517
+ expression: string;
518
+ timeout_ms?: number | undefined;
519
+ on_error?: "fail" | "skip" | undefined;
520
+ label?: string | undefined;
521
+ return_value?: boolean | undefined;
522
+ await_promise?: boolean | undefined;
523
+ } | {
524
+ type: "screenshot";
525
+ format?: "png" | "jpeg" | "webp" | undefined;
526
+ timeout_ms?: number | undefined;
527
+ on_error?: "fail" | "skip" | undefined;
528
+ label?: string | undefined;
529
+ selector?: string | undefined;
530
+ full_page?: boolean | undefined;
531
+ quality?: number | undefined;
532
+ })[]>;
533
+ /** Map typed steps onto the API's keyed shape: {kind: {fields}, timeout_ms?, on_error?, label?}. */
534
+ export declare function toApiActions(steps: Action[]): Record<string, unknown>[];
@@ -0,0 +1,103 @@
1
+ import { z } from "zod";
2
+ // ---------------------------------------------------------------------------
3
+ // Browser actions for spicrawl_scrape, as an explicit discriminated union.
4
+ //
5
+ // The API's step shape is an object keyed by its kind — {"click": {...}} — which
6
+ // a JSON schema can only describe as "any object". Agents given that schema
7
+ // guessed field names (`scroll.pixels`, `evaluate.script`) and got 400s. Here
8
+ // each step is `{type, ...fields}` with its fields spelt exactly as the Go
9
+ // router (api/internal/router/actions.go) reads them; toApiActions maps it back
10
+ // onto the keyed shape. Only kinds the API supports are offered: there is no
11
+ // hover or press step to map to.
12
+ // ---------------------------------------------------------------------------
13
+ const until = z
14
+ .enum(["load", "domcontentloaded", "networkidle"])
15
+ .describe("Load state the new document must reach. Default load.");
16
+ /** Keys every step accepts; they sit beside the kind key in the API shape. */
17
+ const meta = {
18
+ timeout_ms: z.number().int().min(1).optional().describe("Budget for this step in ms. The step fails (or is skipped) when it runs out."),
19
+ on_error: z.enum(["fail", "skip"]).optional().describe("fail (default) aborts the workflow; skip records the failure and continues."),
20
+ label: z.string().optional().describe("Name echoed in the response's `actions` and `screenshots`."),
21
+ };
22
+ const META_KEYS = Object.keys(meta);
23
+ const step = (type, fields, description) => z.object({ type: z.literal(type), ...fields, ...meta }).strict().describe(description);
24
+ export const ActionSchema = z.discriminatedUnion("type", [
25
+ step("click", {
26
+ selector: z.string().min(1).describe("CSS selector of the element to click."),
27
+ wait_for_navigation: z.boolean().optional().describe("The click navigates: finish the step only once the new page has loaded."),
28
+ until: until.optional(),
29
+ }, "Click an element. On a checkbox or radio this toggles it (there is no 'set checked'); read its state with evaluate if it matters."),
30
+ step("fill", {
31
+ selector: z.string().min(1),
32
+ value: z.string(),
33
+ secret: z.boolean().optional().describe("A credential: redacted from logs and the request log."),
34
+ }, "Type a value into an input."),
35
+ step("wait_for", {
36
+ selector: z.string().min(1).optional().describe("CSS selector to wait for."),
37
+ ms: z.number().int().min(1).optional().describe("Or: sleep this many ms."),
38
+ }, "Wait for a selector to appear, or sleep `ms`."),
39
+ step("wait_for_navigation", { until: until.optional() }, "Wait for a navigation started by the previous step (a click, a form submit, a redirect) to load."),
40
+ step("scroll", {
41
+ y: z.number().int().optional().describe("Pixels to scroll down (negative scrolls up)."),
42
+ to_bottom: z.boolean().optional().describe("Scroll to the bottom repeatedly until the page stops growing (infinite scroll)."),
43
+ selector: z.string().min(1).optional().describe("Scroll this element into view."),
44
+ }, "Scroll the page: give exactly one of y, to_bottom or selector."),
45
+ step("select", {
46
+ selector: z.string().min(1).describe("CSS selector of the <select>."),
47
+ value: z.string().optional(),
48
+ values: z.array(z.string()).optional().describe("Several options, for a multi-select."),
49
+ }, "Choose option(s) in a <select> by value."),
50
+ step("evaluate", {
51
+ expression: z.string().min(1).describe("JavaScript expression evaluated in the page."),
52
+ return_value: z.boolean().optional().describe("Return the value under `actions` in the response (forces format json)."),
53
+ await_promise: z.boolean().optional(),
54
+ }, "Run JavaScript in the page."),
55
+ step("screenshot", {
56
+ full_page: z.boolean().optional(),
57
+ selector: z.string().min(1).optional().describe("Capture only this element."),
58
+ format: z.enum(["png", "jpeg", "webp"]).optional(),
59
+ quality: z.number().int().min(1).max(100).optional(),
60
+ }, "Capture the page at this point. The image is returned as an image block; the response becomes the JSON envelope whatever `format` says."),
61
+ ]);
62
+ export const ActionsSchema = z
63
+ .array(ActionSchema)
64
+ .superRefine((steps, ctx) => {
65
+ steps.forEach((s, i) => {
66
+ if (s.type === "scroll" && [s.y !== undefined, s.to_bottom === true, s.selector !== undefined].filter(Boolean).length !== 1) {
67
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: [i], message: "scroll needs exactly one of y, to_bottom or selector" });
68
+ }
69
+ if (s.type === "wait_for" && s.selector === undefined && s.ms === undefined) {
70
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: [i], message: "wait_for needs selector or ms" });
71
+ }
72
+ if (s.type === "select" && s.value === undefined && !s.values?.length) {
73
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: [i], message: "select needs value or values" });
74
+ }
75
+ if (s.type === "click" && s.until !== undefined && s.wait_for_navigation !== true) {
76
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: [i], message: "click.until only applies with wait_for_navigation: true" });
77
+ }
78
+ });
79
+ })
80
+ .describe("Browser steps run in order before capture (render only). Each step is {type, ...fields}. Examples: " +
81
+ '[{"type":"click","selector":"#load-more"},{"type":"wait_for","selector":".item:nth-child(20)","timeout_ms":5000}] · ' +
82
+ 'infinite scroll: [{"type":"scroll","to_bottom":true},{"type":"wait_for","ms":1000}] · ' +
83
+ 'login: [{"type":"fill","selector":"#user","value":"me"},{"type":"fill","selector":"#pass","value":"…","secret":true},' +
84
+ '{"type":"click","selector":"button[type=submit]","wait_for_navigation":true}]. ' +
85
+ "A screenshot step switches the response to the JSON envelope (a FORMAT_COERCED warning says so).");
86
+ /** Map typed steps onto the API's keyed shape: {kind: {fields}, timeout_ms?, on_error?, label?}. */
87
+ export function toApiActions(steps) {
88
+ return steps.map((s) => {
89
+ const { type, ...rest } = s;
90
+ const body = {};
91
+ const out = {};
92
+ for (const [k, v] of Object.entries(rest)) {
93
+ if (v === undefined)
94
+ continue;
95
+ if (META_KEYS.includes(k))
96
+ out[k] = v;
97
+ else
98
+ body[k] = v;
99
+ }
100
+ return { [type]: body, ...out };
101
+ });
102
+ }
103
+ //# sourceMappingURL=actions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/tools/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,8EAA8E;AAC9E,2EAA2E;AAC3E,EAAE;AACF,iFAAiF;AACjF,4EAA4E;AAC5E,8EAA8E;AAC9E,2EAA2E;AAC3E,gFAAgF;AAChF,6EAA6E;AAC7E,iCAAiC;AACjC,8EAA8E;AAE9E,MAAM,KAAK,GAAG,CAAC;KACZ,IAAI,CAAC,CAAC,MAAM,EAAE,kBAAkB,EAAE,aAAa,CAAC,CAAC;KACjD,QAAQ,CAAC,uDAAuD,CA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