@burdenoff/ui-engine 2026.1127.3 → 2026.1127.5

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 (65) hide show
  1. package/README.md +71 -5
  2. package/dist/analyze/analyze.d.ts +19 -0
  3. package/dist/analyze/context.d.ts +40 -0
  4. package/dist/analyze/index.d.ts +10 -0
  5. package/dist/analyze/messages.d.ts +39 -0
  6. package/dist/analyze/rules/fixed-wait.d.ts +6 -0
  7. package/dist/analyze/rules/hardware-input.d.ts +2 -0
  8. package/dist/analyze/rules/index.d.ts +3 -0
  9. package/dist/analyze/rules/inline-target.d.ts +2 -0
  10. package/dist/analyze/rules/masked-value.d.ts +8 -0
  11. package/dist/analyze/rules/no-cleanup.d.ts +2 -0
  12. package/dist/analyze/rules/plain-text-secret.d.ts +2 -0
  13. package/dist/analyze/rules/rule.d.ts +15 -0
  14. package/dist/analyze/rules/secret-origin.d.ts +7 -0
  15. package/dist/analyze/rules/sensitive-screenshot.d.ts +2 -0
  16. package/dist/analyze/rules/single-method-target.d.ts +2 -0
  17. package/dist/analyze/rules/unknown-variable.d.ts +2 -0
  18. package/dist/analyze/rules/unused-value.d.ts +2 -0
  19. package/dist/analyze/sensitive.d.ts +14 -0
  20. package/dist/analyze/types.d.ts +66 -0
  21. package/dist/analyze.d.ts +2 -0
  22. package/dist/analyze.js +26 -0
  23. package/dist/dom-runtime.iife.js +1 -1
  24. package/dist/dom-runtime.js +27 -532
  25. package/dist/drivers/dom-driver.d.ts +44 -0
  26. package/dist/drivers/index.d.ts +7 -0
  27. package/dist/drivers/snapshot-driver.d.ts +59 -0
  28. package/dist/drivers.d.ts +2 -0
  29. package/dist/drivers.js +172 -0
  30. package/dist/index-21hvbvx1.js +340 -0
  31. package/dist/{index-q1b0j9yr.js → index-5k26keah.js} +58 -592
  32. package/dist/index-77pcz6n3.js +303 -0
  33. package/dist/index-8w0f6rsz.js +402 -0
  34. package/dist/index-9s5nphx0.js +99 -0
  35. package/dist/index-c88tvyj1.js +743 -0
  36. package/dist/index-ct2xctrq.js +229 -0
  37. package/dist/index-g7724awk.js +224 -0
  38. package/dist/index-gvavb597.js +195 -0
  39. package/dist/index-r2a9rftv.js +1740 -0
  40. package/dist/index-s7qdecev.js +489 -0
  41. package/dist/index-vg8r40y7.js +220 -0
  42. package/dist/index-xner4tgb.js +810 -0
  43. package/dist/index-ycs2bz1a.js +589 -0
  44. package/dist/index.d.ts +2 -0
  45. package/dist/index.js +163 -49
  46. package/dist/interpret/compile.d.ts +58 -0
  47. package/dist/interpret/driver.d.ts +171 -0
  48. package/dist/interpret/errors.d.ts +194 -0
  49. package/dist/interpret/events.d.ts +73 -0
  50. package/dist/interpret/expr.d.ts +35 -0
  51. package/dist/interpret/index.d.ts +13 -0
  52. package/dist/interpret/run.d.ts +77 -0
  53. package/dist/interpret.d.ts +2 -0
  54. package/dist/interpret.js +84 -0
  55. package/dist/script/adapters/browser-action-contract.d.ts +5 -2
  56. package/dist/script/limits.d.ts +2 -0
  57. package/dist/script.js +60 -50
  58. package/dist/target/index.d.ts +1 -1
  59. package/dist/target/resolve.d.ts +18 -1
  60. package/dist/target.js +23 -19
  61. package/dist/testing/fake-web-driver.d.ts +28 -0
  62. package/dist/testing/index.d.ts +3 -2
  63. package/dist/testing.js +55 -0
  64. package/package.json +15 -3
  65. package/dist/index-zwrxw3zp.js +0 -1988
@@ -0,0 +1,810 @@
1
+ import {
2
+ uiScriptRegistry2,
3
+ NAME_PATTERN2,
4
+ uiScriptSchema2,
5
+ canonicalJson2,
6
+ soleRoleMethod,
7
+ uiStepFingerprint2,
8
+ UiScriptError2,
9
+ parseUiScript2
10
+ } from "./index-c88tvyj1.js";
11
+ import {
12
+ sha256Hex2,
13
+ RecordingError2,
14
+ parseRecording2
15
+ } from "./index-cs6acyjn.js";
16
+ import {
17
+ MAX_LIST_ITEMS2,
18
+ MAX_LIST_PAGES2,
19
+ MAX_STEP_TIMEOUT_MS2,
20
+ MAX_INTENT_LENGTH2,
21
+ LEGACY_MAX_BROWSER_STEPS2,
22
+ LEGACY_MAX_STEPS_BYTES2,
23
+ LEGACY_MAX_STEP_TIMEOUT_MS2,
24
+ jsonByteLength2
25
+ } from "./index-9s5nphx0.js";
26
+ // src/script/hash.ts
27
+ var UI_SCRIPT_SCHEMA_HASH2 = "e6860649ad1cba906fb704ce4b62b3ea4380203e6628c809571602f4d0947884";
28
+ function schemaHashOf2(jsonSchema) {
29
+ return sha256Hex2(canonicalJson2(jsonSchema));
30
+ }
31
+ // src/script/json-schema.ts
32
+ import { z } from "zod";
33
+ var UI_SCRIPT_SCHEMA_TITLE2 = "FluidGrids UI script v1";
34
+ function uiScriptJsonSchema2() {
35
+ const generated = z.toJSONSchema(uiScriptSchema2, {
36
+ target: "draft-2020-12",
37
+ io: "input",
38
+ unrepresentable: "throw",
39
+ metadata: uiScriptRegistry2
40
+ });
41
+ const { $schema, ...rest } = generated;
42
+ return { $schema, title: UI_SCRIPT_SCHEMA_TITLE2, ...rest };
43
+ }
44
+ // src/script/adapters/browser-action-contract.ts
45
+ var BROWSER_STEP_ACTIONS2 = [
46
+ "navigate",
47
+ "waitFor",
48
+ "click",
49
+ "type",
50
+ "select",
51
+ "check",
52
+ "pressKey",
53
+ "scroll",
54
+ "extract",
55
+ "extractList",
56
+ "getPageText",
57
+ "getPageHtml",
58
+ "screenshot",
59
+ "closeTab"
60
+ ];
61
+ // src/script/adapters/from-browser-action.ts
62
+ var LEGACY_ACTIONS = new Set(BROWSER_STEP_ACTIONS2);
63
+ function isRecord(value) {
64
+ return typeof value === "object" && value !== null && !Array.isArray(value);
65
+ }
66
+ function text(value) {
67
+ return typeof value === "string" && value.trim() ? value : undefined;
68
+ }
69
+ function css(selector) {
70
+ return { methods: [{ kind: "css", selector: selector.trim() }] };
71
+ }
72
+ function intIn(value, min, max) {
73
+ const number = typeof value === "string" && value.trim() ? Number(value) : value;
74
+ return typeof number === "number" && Number.isInteger(number) && number >= min && number <= max ? number : undefined;
75
+ }
76
+ function readStepList(value, what) {
77
+ let list = value;
78
+ if (typeof value === "string") {
79
+ try {
80
+ list = JSON.parse(value);
81
+ } catch {
82
+ throw new UiScriptError2("INVALID_SCRIPT", `The ${what} are not valid JSON`);
83
+ }
84
+ }
85
+ if (!Array.isArray(list) || list.length === 0) {
86
+ throw new UiScriptError2("INVALID_SCRIPT", `The ${what} must be a non-empty list of steps`);
87
+ }
88
+ return list;
89
+ }
90
+ function fromBrowserActionSteps2(steps, options = {}) {
91
+ const list = readStepList(steps, "Run in Browser steps");
92
+ const script = {
93
+ scriptVersion: 1,
94
+ ...options.name ? { name: options.name } : {},
95
+ steps: list.map((step, index) => convertStep(step, index))
96
+ };
97
+ return parseUiScript2(script);
98
+ }
99
+ function convertStep(raw, index) {
100
+ const where = `Step ${index + 1}`;
101
+ const refuse = (message) => {
102
+ throw new UiScriptError2("INVALID_SCRIPT", `${where}: ${message}`, String(index));
103
+ };
104
+ if (!isRecord(raw) || typeof raw.action !== "string" || !LEGACY_ACTIONS.has(raw.action)) {
105
+ return refuse("has no known Run in Browser action");
106
+ }
107
+ const name = text(raw.name);
108
+ if (name !== undefined && !NAME_PATTERN2.test(name)) {
109
+ refuse(`the result name "${name.slice(0, 64)}" must be letters, digits or _ and start with a letter or _`);
110
+ }
111
+ const timeoutMs = intIn(raw.timeoutMs, 0, MAX_STEP_TIMEOUT_MS2);
112
+ const note = text(raw.note)?.slice(0, MAX_INTENT_LENGTH2);
113
+ const base = {
114
+ id: `s${index + 1}`,
115
+ ...name === undefined ? {} : { saveAs: name },
116
+ ...timeoutMs === undefined ? {} : { timeoutMs },
117
+ ...note === undefined ? {} : { note }
118
+ };
119
+ const selector = text(raw.selector);
120
+ const needSelector = () => selector ? css(selector) : refuse(`${String(raw.action)} needs a selector`);
121
+ const value = typeof raw.value === "string" ? raw.value : undefined;
122
+ switch (raw.action) {
123
+ case "navigate":
124
+ return { ...base, action: "navigate", url: text(raw.url) ?? refuse("navigate needs a url") };
125
+ case "waitFor":
126
+ case "click": {
127
+ const label = text(raw.text);
128
+ if (raw.action === "waitFor" && !selector && label !== undefined)
129
+ return { ...base, action: "waitFor", text: label };
130
+ const target = selector ? css(selector) : label ? { methods: [{ kind: "text", text: label }] } : refuse(`${raw.action} needs a selector or text`);
131
+ return raw.action === "click" ? { ...base, action: "click", target } : { ...base, action: "waitFor", target };
132
+ }
133
+ case "type":
134
+ return {
135
+ ...base,
136
+ action: "type",
137
+ target: needSelector(),
138
+ text: value ?? refuse("type needs a text value"),
139
+ ...raw.clear === false ? { clear: false } : {}
140
+ };
141
+ case "select":
142
+ return { ...base, action: "select", target: needSelector(), values: [value ?? refuse("select needs a value")] };
143
+ case "check":
144
+ return { ...base, action: "check", target: needSelector(), ...raw.checked === false ? { checked: false } : {} };
145
+ case "pressKey":
146
+ return { ...base, action: "pressKey", keys: [text(raw.key) ?? refuse("pressKey needs a key")] };
147
+ case "scroll":
148
+ return selector ? { ...base, action: "scroll", target: css(selector) } : { ...base, action: "scroll", to: raw.to === "top" ? "top" : "bottom" };
149
+ case "extract":
150
+ return { ...base, action: "extract", fields: convertFields(raw.fields, refuse) };
151
+ case "extractList": {
152
+ const item = text(raw.itemSelector) ?? refuse("extractList needs an itemSelector");
153
+ const maxItems = intIn(raw.maxItems, 1, MAX_LIST_ITEMS2);
154
+ const maxPages = intIn(raw.maxPages, 1, MAX_LIST_PAGES2);
155
+ const next = text(raw.paginateSelector);
156
+ return {
157
+ ...base,
158
+ action: "extractList",
159
+ item: css(item),
160
+ fields: convertFields(raw.fields, refuse),
161
+ ...maxItems === undefined ? {} : { maxItems },
162
+ ...next === undefined ? {} : { next: css(next) },
163
+ ...maxPages === undefined ? {} : { maxPages }
164
+ };
165
+ }
166
+ case "getPageText":
167
+ return { ...base, action: "getPageText" };
168
+ case "getPageHtml":
169
+ return { ...base, action: "getPageHtml" };
170
+ case "screenshot":
171
+ return { ...base, action: "screenshot" };
172
+ default:
173
+ return { ...base, action: "closeTab" };
174
+ }
175
+ }
176
+ function convertFields(value, refuse) {
177
+ if (!Array.isArray(value) || value.length === 0)
178
+ return refuse("needs at least one field");
179
+ return value.map((field, index) => {
180
+ if (!isRecord(field))
181
+ return refuse(`field ${index + 1} needs a name and a selector`);
182
+ const name = text(field.name);
183
+ const selector = text(field.selector);
184
+ if (!name || !selector)
185
+ return refuse(`field ${index + 1} needs a name and a selector`);
186
+ if (!NAME_PATTERN2.test(name)) {
187
+ return refuse(`field name "${name.slice(0, 64)}" must be letters, digits or _ and start with a letter or _`);
188
+ }
189
+ const attribute = text(field.attribute);
190
+ return {
191
+ name,
192
+ target: css(selector),
193
+ ...attribute === undefined ? {} : { attribute },
194
+ ...field.multiple === true ? { all: true } : {}
195
+ };
196
+ });
197
+ }
198
+ // src/script/adapters/to-browser-action.ts
199
+ class NotLowerable extends Error {
200
+ }
201
+ function stop() {
202
+ throw new NotLowerable;
203
+ }
204
+ function toBrowserActionSteps2(script, options = {}) {
205
+ try {
206
+ return lower(script, options);
207
+ } catch (error) {
208
+ if (error instanceof NotLowerable)
209
+ return null;
210
+ throw error;
211
+ }
212
+ }
213
+ function lower(script, options) {
214
+ if (script.cleanup || script.outputs?.length || script.variables?.length)
215
+ stop();
216
+ const settings = script.settings;
217
+ if (settings?.inputMethod && settings.inputMethod !== "auto")
218
+ stop();
219
+ if (settings?.firstWaitMs !== undefined || settings?.waitMs !== undefined)
220
+ stop();
221
+ if (settings?.screenshots === "everyStep")
222
+ stop();
223
+ if (script.steps.length > LEGACY_MAX_BROWSER_STEPS2)
224
+ stop();
225
+ const context = {
226
+ elements: script.elements ?? {},
227
+ inputs: options.inputs ?? {},
228
+ defaults: Object.fromEntries((script.inputs ?? []).map((input) => [input.name, input.default]))
229
+ };
230
+ const steps = script.steps.map((step) => lowerStep(step, context));
231
+ if (jsonByteLength2(steps) > LEGACY_MAX_STEPS_BYTES2)
232
+ stop();
233
+ return steps;
234
+ }
235
+ function lowerStep(step, context) {
236
+ if (step.disabled || step.breakpoint || step.verify || step.retry || step.onError === "continue")
237
+ stop();
238
+ if (step.timeoutMs !== undefined && step.timeoutMs > LEGACY_MAX_STEP_TIMEOUT_MS2)
239
+ stop();
240
+ if (step.screenshot === "always" || step.inputMethod && step.inputMethod !== "auto")
241
+ stop();
242
+ const common = {
243
+ ...step.saveAs === undefined ? {} : { name: step.saveAs },
244
+ ...step.timeoutMs === undefined ? {} : { timeoutMs: step.timeoutMs },
245
+ ...step.note === undefined ? {} : { note: step.note }
246
+ };
247
+ const selector = (ref) => cssOf(resolve(ref, context)) ?? stop();
248
+ const value = (expression) => literal(expression, context) ?? stop();
249
+ switch (step.action) {
250
+ case "navigate": {
251
+ if (step.waitUntil && step.waitUntil !== "load")
252
+ stop();
253
+ const url = value(step.url);
254
+ if (!/^https?:\/\//i.test(url))
255
+ stop();
256
+ return { action: "navigate", ...common, url };
257
+ }
258
+ case "click": {
259
+ if (step.button === "right")
260
+ stop();
261
+ return { action: "click", ...common, ...selectorOrText(resolve(step.target, context)) };
262
+ }
263
+ case "waitFor": {
264
+ if (step.urlContains !== undefined || step.milliseconds !== undefined)
265
+ stop();
266
+ if (step.state && step.state !== "visible")
267
+ stop();
268
+ if (step.target)
269
+ return { action: "waitFor", ...common, ...selectorOrText(resolve(step.target, context)) };
270
+ return { action: "waitFor", ...common, text: value(step.text) };
271
+ }
272
+ case "type": {
273
+ if (step.masked || step.pressEnter || step.delayMs !== undefined)
274
+ stop();
275
+ return {
276
+ action: "type",
277
+ ...common,
278
+ selector: selector(step.target),
279
+ value: value(step.text),
280
+ ...step.clear === false ? { clear: false } : {}
281
+ };
282
+ }
283
+ case "select": {
284
+ if (step.values.length !== 1)
285
+ stop();
286
+ return { action: "select", ...common, selector: selector(step.target), value: value(step.values[0]) };
287
+ }
288
+ case "check":
289
+ return { action: "check", ...common, selector: selector(step.target), checked: step.checked !== false };
290
+ case "pressKey": {
291
+ const [key] = step.keys;
292
+ if (step.keys.length !== 1 || step.target || key === undefined)
293
+ stop();
294
+ return { action: "pressKey", ...common, key };
295
+ }
296
+ case "scroll": {
297
+ if (step.dx !== undefined || step.dy !== undefined)
298
+ stop();
299
+ if (step.target)
300
+ return { action: "scroll", ...common, selector: selector(step.target) };
301
+ return { action: "scroll", ...common, ...step.to === "top" ? { to: "top" } : {} };
302
+ }
303
+ case "extract":
304
+ return { action: "extract", ...common, fields: step.fields.map((field) => lowerField(field, context)) };
305
+ case "extractList":
306
+ return {
307
+ action: "extractList",
308
+ ...common,
309
+ itemSelector: selector(step.item),
310
+ fields: step.fields.map((field) => lowerField(field, context)),
311
+ ...step.maxItems === undefined ? {} : { maxItems: step.maxItems },
312
+ ...step.next ? { paginateSelector: selector(step.next) } : {},
313
+ ...step.maxPages === undefined ? {} : { maxPages: step.maxPages }
314
+ };
315
+ case "screenshot":
316
+ if (step.target || step.fullPage)
317
+ stop();
318
+ return { action: "screenshot", ...common };
319
+ case "getPageText":
320
+ case "getPageHtml":
321
+ case "closeTab":
322
+ return { action: step.action, ...common };
323
+ default:
324
+ return stop();
325
+ }
326
+ }
327
+ function lowerField(field, context) {
328
+ if (field.attribute === "text" || field.attribute === "html" || field.attribute === "value")
329
+ stop();
330
+ return {
331
+ name: field.name,
332
+ selector: cssOf(resolve(field.target, context)) ?? stop(),
333
+ ...field.attribute === undefined ? {} : { attribute: field.attribute },
334
+ ...field.all ? { multiple: true } : {}
335
+ };
336
+ }
337
+ function resolve(ref, context) {
338
+ if (!ref)
339
+ return stop();
340
+ if ("element" in ref)
341
+ return context.elements[ref.element]?.target ?? stop();
342
+ return ref;
343
+ }
344
+ function cssOf(target) {
345
+ const [method] = target.methods;
346
+ if (target.frame || target.methods.length !== 1 || method?.enabled === false)
347
+ return;
348
+ return method?.kind === "css" ? method.selector : undefined;
349
+ }
350
+ function selectorOrText(target) {
351
+ const selector = cssOf(target);
352
+ if (selector !== undefined)
353
+ return { selector };
354
+ const [method] = target.methods;
355
+ if (target.frame || target.methods.length !== 1 || method?.kind !== "text" || method.enabled === false || method.exact === true || (method.nth ?? 0) !== 0) {
356
+ return stop();
357
+ }
358
+ return { text: method.text };
359
+ }
360
+ function literal(expression, context) {
361
+ if (typeof expression === "string")
362
+ return expression;
363
+ if (typeof expression === "number" || typeof expression === "boolean")
364
+ return String(expression);
365
+ if (expression !== null && typeof expression === "object" && "input" in expression && !expression.path) {
366
+ const supplied = context.inputs[expression.input];
367
+ if (typeof supplied === "string")
368
+ return supplied;
369
+ if (typeof supplied === "number" || typeof supplied === "boolean")
370
+ return String(supplied);
371
+ if (supplied === undefined)
372
+ return literal(context.defaults[expression.input], { ...context, defaults: {} });
373
+ }
374
+ return null;
375
+ }
376
+ // src/script/adapters/from-remote-browser.ts
377
+ var ACTIONS = new Set([
378
+ "navigate",
379
+ "click",
380
+ "type",
381
+ "select",
382
+ "press",
383
+ "waitFor",
384
+ "extract",
385
+ "screenshot",
386
+ "login"
387
+ ]);
388
+ var STEP_KEYS = {
389
+ navigate: ["url", "waitUntil"],
390
+ click: ["selector"],
391
+ type: ["selector", "text", "clear", "pressEnter"],
392
+ select: ["selector", "values"],
393
+ press: ["key"],
394
+ waitFor: ["selector", "state", "urlContains", "milliseconds"],
395
+ extract: ["fields"],
396
+ screenshot: ["fullPage", "selector"],
397
+ login: ["usernameSelector", "passwordSelector", "submitSelector", "successSelector"]
398
+ };
399
+ var WAIT_UNTIL = ["load", "domcontentloaded", "networkidle", "commit"];
400
+ var WAIT_STATES = ["visible", "hidden", "attached", "detached"];
401
+ function isRecord2(value) {
402
+ return typeof value === "object" && value !== null && !Array.isArray(value);
403
+ }
404
+ function given(value) {
405
+ return value !== undefined && value !== null && value !== "";
406
+ }
407
+ function oneOf(list, value) {
408
+ return list.find((item) => item === value);
409
+ }
410
+ function targetFromPlaywrightSelector2(raw, refuse) {
411
+ const selector = raw.trim();
412
+ if (!selector)
413
+ return refuse("the selector is empty");
414
+ if (selector.includes(">>"))
415
+ return refuse(`the selector "${selector.slice(0, 80)}" chains engines with >>`);
416
+ const engine = /^([a-zA-Z][\w-]*)=(.*)$/s.exec(selector);
417
+ if (selector.startsWith("//") || selector.startsWith("(//")) {
418
+ return { methods: [{ kind: "xpath", xpath: selector }] };
419
+ }
420
+ if (!engine)
421
+ return { methods: [{ kind: "css", selector }] };
422
+ const [, name = "", body = ""] = engine;
423
+ const value = body.trim();
424
+ if (!value)
425
+ return refuse(`the selector "${selector.slice(0, 80)}" is empty after ${name}=`);
426
+ const quoted = /^"(.*)"$/s.exec(value) ?? /^'(.*)'$/s.exec(value);
427
+ switch (name) {
428
+ case "css":
429
+ return { methods: [{ kind: "css", selector: value }] };
430
+ case "xpath":
431
+ return { methods: [{ kind: "xpath", xpath: value }] };
432
+ case "text":
433
+ return {
434
+ methods: [quoted ? { kind: "text", text: quoted[1] ?? "", exact: true } : { kind: "text", text: value }]
435
+ };
436
+ case "id":
437
+ return { methods: [{ kind: "css", selector: `[id=${JSON.stringify(quoted?.[1] ?? value)}]` }] };
438
+ case "data-testid":
439
+ return { methods: [{ kind: "testId", value: quoted?.[1] ?? value }] };
440
+ default:
441
+ return refuse(`the selector engine "${name}" has no UI script equivalent`);
442
+ }
443
+ }
444
+ function fromRemoteBrowserSteps2(steps, options = {}) {
445
+ const list = readStepList(steps, "Remote Browser steps");
446
+ const script = {
447
+ scriptVersion: 1,
448
+ ...options.name ? { name: options.name } : {},
449
+ steps: list.map((step, index) => convertStep2(step, index))
450
+ };
451
+ return parseUiScript2(script);
452
+ }
453
+ function bool(value, name, refuse) {
454
+ if (!given(value))
455
+ return;
456
+ if (typeof value === "boolean")
457
+ return value;
458
+ if (typeof value === "string" && /^(true|false)$/i.test(value.trim()))
459
+ return value.trim().toLowerCase() === "true";
460
+ return refuse(`'${name}' must be true or false`);
461
+ }
462
+ function convertStep2(raw, index) {
463
+ const where = `Step ${index + 1}`;
464
+ const refuse = (message) => {
465
+ throw new UiScriptError2("INVALID_SCRIPT", `${where}: ${message}`, String(index));
466
+ };
467
+ if (!isRecord2(raw) || typeof raw.action !== "string" || !ACTIONS.has(raw.action)) {
468
+ return refuse("has no known Remote Browser action");
469
+ }
470
+ const action = raw.action;
471
+ const unknown = Object.keys(raw).filter((key) => key !== "action" && key !== "name" && !(STEP_KEYS[action] ?? []).includes(key));
472
+ if (unknown.length > 0)
473
+ refuse(`(${action}) has unknown keys: ${unknown.sort().join(", ")}`);
474
+ const name = typeof raw.name === "string" && raw.name.trim() ? raw.name.trim() : undefined;
475
+ if (name !== undefined && !NAME_PATTERN2.test(name))
476
+ refuse(`the result name "${name.slice(0, 64)}" is not valid`);
477
+ const base = { id: `s${index + 1}`, ...name === undefined ? {} : { saveAs: name } };
478
+ const target = (key = "selector", required = true) => {
479
+ const value = raw[key];
480
+ if (!given(value))
481
+ return required ? refuse(`'${key}' is required`) : undefined;
482
+ if (typeof value !== "string")
483
+ return refuse(`'${key}' must be text`);
484
+ return targetFromPlaywrightSelector2(value, refuse);
485
+ };
486
+ const need = (key = "selector") => target(key, true) ?? refuse(`'${key}' is required`);
487
+ switch (action) {
488
+ case "navigate": {
489
+ if (typeof raw.url !== "string" || !raw.url.trim())
490
+ return refuse("'url' is required");
491
+ const waitUntil = given(raw.waitUntil) ? oneOf(WAIT_UNTIL, raw.waitUntil) : undefined;
492
+ if (given(raw.waitUntil) && !waitUntil)
493
+ refuse(`'waitUntil' must be one of ${WAIT_UNTIL.join(", ")}`);
494
+ return {
495
+ ...base,
496
+ action: "navigate",
497
+ url: raw.url,
498
+ ...waitUntil && waitUntil !== "load" ? { waitUntil } : {}
499
+ };
500
+ }
501
+ case "click":
502
+ return { ...base, action: "click", target: need() };
503
+ case "type": {
504
+ const text = typeof raw.text === "number" ? String(raw.text) : raw.text;
505
+ if (given(text) && typeof text !== "string")
506
+ refuse("'text' must be text");
507
+ const clear = bool(raw.clear, "clear", refuse);
508
+ const pressEnter = bool(raw.pressEnter, "pressEnter", refuse);
509
+ return {
510
+ ...base,
511
+ action: "type",
512
+ target: need(),
513
+ text: typeof text === "string" ? text : "",
514
+ ...clear === false ? { clear: false } : {},
515
+ ...pressEnter === true ? { pressEnter: true } : {}
516
+ };
517
+ }
518
+ case "select":
519
+ return { ...base, action: "select", target: need(), values: selectValues(raw.values, refuse) };
520
+ case "press": {
521
+ const key = typeof raw.key === "string" ? raw.key.trim() : "";
522
+ if (!/^(?:(?:Control|Shift|Alt|Meta)\+){0,3}[A-Za-z0-9]{1,16}$/.test(key)) {
523
+ refuse("'key' must be a key name such as Enter, Tab, Escape or Control+A");
524
+ }
525
+ return { ...base, action: "pressKey", keys: key.split("+") };
526
+ }
527
+ case "waitFor":
528
+ return convertWait(raw, base, refuse, target);
529
+ case "extract":
530
+ return { ...base, action: "extract", fields: convertFields2(raw.fields, refuse) };
531
+ case "screenshot": {
532
+ const fullPage = bool(raw.fullPage, "fullPage", refuse);
533
+ const shot = target("selector", false);
534
+ return {
535
+ ...base,
536
+ action: "screenshot",
537
+ ...shot ? { target: shot } : {},
538
+ ...fullPage === true ? { fullPage: true } : {}
539
+ };
540
+ }
541
+ default: {
542
+ const username = target("usernameSelector", false);
543
+ const password = target("passwordSelector", false);
544
+ const submit = target("submitSelector", false);
545
+ const success = target("successSelector", false);
546
+ return {
547
+ ...base,
548
+ action: "login",
549
+ ...username ? { username } : {},
550
+ ...password ? { password } : {},
551
+ ...submit ? { submit } : {},
552
+ ...success ? { success } : {}
553
+ };
554
+ }
555
+ }
556
+ }
557
+ function convertWait(raw, base, refuse, target) {
558
+ const present = ["selector", "urlContains", "milliseconds"].filter((key) => given(raw[key]));
559
+ if (present.length !== 1)
560
+ return refuse("give exactly one of 'selector', 'urlContains' or 'milliseconds'");
561
+ if (present[0] === "selector") {
562
+ const state = given(raw.state) ? oneOf(WAIT_STATES, raw.state) : undefined;
563
+ if (given(raw.state) && !state)
564
+ refuse(`'state' must be one of ${WAIT_STATES.join(", ")}`);
565
+ return {
566
+ ...base,
567
+ action: "waitFor",
568
+ target: target("selector", true) ?? refuse("'selector' is required"),
569
+ ...state && state !== "visible" ? { state } : {}
570
+ };
571
+ }
572
+ if (present[0] === "urlContains") {
573
+ if (typeof raw.urlContains !== "string")
574
+ return refuse("'urlContains' must be text");
575
+ return { ...base, action: "waitFor", urlContains: raw.urlContains };
576
+ }
577
+ const milliseconds = typeof raw.milliseconds === "string" ? Number(raw.milliseconds.trim()) : raw.milliseconds;
578
+ if (typeof milliseconds !== "number" || !Number.isInteger(milliseconds) || milliseconds < 1 || milliseconds > MAX_STEP_TIMEOUT_MS2) {
579
+ return refuse(`'milliseconds' must be a whole number between 1 and ${MAX_STEP_TIMEOUT_MS2}`);
580
+ }
581
+ return { ...base, action: "waitFor", milliseconds };
582
+ }
583
+ function selectValues(value, refuse) {
584
+ let list = value;
585
+ if (typeof value === "string") {
586
+ const text = value.trim();
587
+ if (text.startsWith("[")) {
588
+ try {
589
+ list = JSON.parse(text);
590
+ } catch {
591
+ return refuse("'values' is not valid JSON");
592
+ }
593
+ } else {
594
+ list = text.split(",").map((part) => part.trim()).filter(Boolean);
595
+ }
596
+ }
597
+ if (!Array.isArray(list) || list.length === 0)
598
+ return refuse("'values' is required");
599
+ return list.map((item) => typeof item === "string" || typeof item === "number" ? String(item) : refuse("'values' must be a list of values"));
600
+ }
601
+ function convertFields2(value, refuse) {
602
+ let fields = value;
603
+ if (typeof value === "string") {
604
+ try {
605
+ fields = JSON.parse(value);
606
+ } catch {
607
+ return refuse("'fields' is not valid JSON");
608
+ }
609
+ }
610
+ if (!isRecord2(fields) || Object.keys(fields).length === 0) {
611
+ return refuse("'fields' must be an object of {name: selector} or {name: {selector, attribute, all}}");
612
+ }
613
+ return Object.entries(fields).map(([name, spec]) => {
614
+ if (!NAME_PATTERN2.test(name))
615
+ return refuse(`field name '${name.slice(0, 64)}' is not valid`);
616
+ if (typeof spec === "string")
617
+ return { name, target: targetFromPlaywrightSelector2(spec, refuse), attribute: "text" };
618
+ if (!isRecord2(spec) || typeof spec.selector !== "string") {
619
+ return refuse(`'fields.${name}' must be a selector or an object with a selector`);
620
+ }
621
+ const extra = Object.keys(spec).filter((key) => !["selector", "attribute", "all"].includes(key));
622
+ if (extra.length > 0)
623
+ refuse(`'fields.${name}' has unknown keys: ${extra.sort().join(", ")}`);
624
+ const attribute = typeof spec.attribute === "string" && spec.attribute ? spec.attribute : "text";
625
+ const all = bool(spec.all, `fields.${name}.all`, refuse);
626
+ return {
627
+ name,
628
+ target: targetFromPlaywrightSelector2(spec.selector, refuse),
629
+ attribute,
630
+ ...all === true ? { all: true } : {}
631
+ };
632
+ });
633
+ }
634
+ // src/script/adapters/recording.ts
635
+ function roleTarget(target) {
636
+ const method = {
637
+ kind: "role",
638
+ role: target.role,
639
+ name: target.name,
640
+ nth: target.nth,
641
+ ...target.app === undefined ? {} : { app: target.app },
642
+ ...target.window === undefined ? {} : { window: target.window }
643
+ };
644
+ return { methods: [method] };
645
+ }
646
+ function fromRecording2(value) {
647
+ const recording = parseRecording2(value);
648
+ return parseUiScript2({ scriptVersion: 1, steps: recording.steps.map(fromRecordedStep) });
649
+ }
650
+ function fromRecordedStep(step) {
651
+ const base = {
652
+ id: step.id,
653
+ intent: step.intent,
654
+ ...step.screenshotRef === undefined ? {} : { screenshotRef: step.screenshotRef },
655
+ fingerprint: step.fingerprint
656
+ };
657
+ switch (step.action) {
658
+ case "click": {
659
+ const button = step.button === "right" ? { button: "right" } : {};
660
+ return step.count === 2 ? { ...base, action: "doubleClick", target: roleTarget(step.target), ...button } : { ...base, action: "click", target: roleTarget(step.target), ...button };
661
+ }
662
+ case "type":
663
+ return {
664
+ ...base,
665
+ action: "type",
666
+ ...step.target ? { target: roleTarget(step.target) } : {},
667
+ ...step.text === undefined ? {} : { text: step.text },
668
+ masked: step.masked
669
+ };
670
+ case "secret_fill":
671
+ return {
672
+ ...base,
673
+ action: "typeSecret",
674
+ target: roleTarget(step.target),
675
+ secretRef: step.secretRef,
676
+ expectedOrigin: step.expectedOrigin
677
+ };
678
+ case "key":
679
+ return { ...base, action: "pressKey", keys: step.keys };
680
+ case "scroll":
681
+ return {
682
+ ...base,
683
+ action: "scroll",
684
+ ...step.target ? { target: roleTarget(step.target) } : {},
685
+ dx: step.dx,
686
+ dy: step.dy
687
+ };
688
+ case "navigate":
689
+ return { ...base, action: "navigate", url: step.url };
690
+ default:
691
+ return {
692
+ ...base,
693
+ action: "focusWindow",
694
+ app: step.app,
695
+ ...step.title === undefined ? {} : { title: step.title }
696
+ };
697
+ }
698
+ }
699
+
700
+ class NotRecordable extends Error {
701
+ }
702
+ function stop2() {
703
+ throw new NotRecordable;
704
+ }
705
+ function toRecording2(script, fallbackIntent) {
706
+ try {
707
+ if (script.cleanup || script.outputs?.length || script.variables?.length || script.inputs?.length)
708
+ stop2();
709
+ if (script.settings && Object.values(script.settings).some((value) => value !== undefined))
710
+ stop2();
711
+ const recording = {
712
+ version: 1,
713
+ steps: script.steps.map((step) => toRecordedStep(step, fallbackIntent))
714
+ };
715
+ return parseRecording2(recording);
716
+ } catch (error) {
717
+ if (error instanceof NotRecordable || error instanceof RecordingError2)
718
+ return null;
719
+ throw error;
720
+ }
721
+ }
722
+ function recordedTarget(ref) {
723
+ const method = soleRoleMethod(ref) ?? stop2();
724
+ return {
725
+ ...method.app === undefined ? {} : { app: method.app },
726
+ ...method.window === undefined ? {} : { window: method.window },
727
+ role: method.role,
728
+ name: method.name,
729
+ nth: method.nth ?? 0
730
+ };
731
+ }
732
+ function toRecordedStep(step, fallbackIntent) {
733
+ if (step.disabled || step.breakpoint || step.verify || step.retry || step.saveAs !== undefined)
734
+ stop2();
735
+ if (step.onError === "continue" || step.note !== undefined || step.timeoutMs !== undefined)
736
+ stop2();
737
+ if (step.screenshot || step.inputMethod || step.safeToRepeat)
738
+ stop2();
739
+ const intent = step.intent ?? fallbackIntent?.(step) ?? stop2();
740
+ const base = {
741
+ id: step.id,
742
+ intent,
743
+ ...step.screenshotRef === undefined ? {} : { screenshotRef: step.screenshotRef }
744
+ };
745
+ const fingerprint = uiStepFingerprint2(step);
746
+ switch (step.action) {
747
+ case "click":
748
+ case "doubleClick":
749
+ return {
750
+ ...base,
751
+ fingerprint,
752
+ action: "click",
753
+ target: recordedTarget(step.target),
754
+ button: step.button ?? "left",
755
+ count: step.action === "doubleClick" ? 2 : 1
756
+ };
757
+ case "type":
758
+ if (step.clear === false || step.pressEnter || step.delayMs !== undefined)
759
+ stop2();
760
+ if (step.text !== undefined && typeof step.text !== "string")
761
+ stop2();
762
+ return {
763
+ ...base,
764
+ fingerprint,
765
+ action: "type",
766
+ ...step.target ? { target: recordedTarget(step.target) } : {},
767
+ ...step.text === undefined ? {} : { text: step.text },
768
+ masked: step.masked === true
769
+ };
770
+ case "typeSecret":
771
+ return {
772
+ ...base,
773
+ fingerprint,
774
+ action: "secret_fill",
775
+ target: recordedTarget(step.target),
776
+ secretRef: step.secretRef,
777
+ expectedOrigin: step.expectedOrigin ?? stop2()
778
+ };
779
+ case "pressKey":
780
+ if (step.target)
781
+ stop2();
782
+ return { ...base, fingerprint, action: "key", keys: step.keys };
783
+ case "scroll":
784
+ if (step.to || step.dx === undefined && step.dy === undefined)
785
+ stop2();
786
+ return {
787
+ ...base,
788
+ fingerprint,
789
+ action: "scroll",
790
+ ...step.target ? { target: recordedTarget(step.target) } : {},
791
+ dx: step.dx ?? 0,
792
+ dy: step.dy ?? 0
793
+ };
794
+ case "navigate":
795
+ if (typeof step.url !== "string" || step.waitUntil && step.waitUntil !== "load")
796
+ stop2();
797
+ return { ...base, fingerprint, action: "navigate", url: step.url };
798
+ case "focusWindow":
799
+ return {
800
+ ...base,
801
+ fingerprint,
802
+ action: "focus_window",
803
+ app: step.app,
804
+ ...step.title === undefined ? {} : { title: step.title }
805
+ };
806
+ default:
807
+ return stop2();
808
+ }
809
+ }
810
+ export { UI_SCRIPT_SCHEMA_HASH2, schemaHashOf2, UI_SCRIPT_SCHEMA_TITLE2, uiScriptJsonSchema2, BROWSER_STEP_ACTIONS2, fromBrowserActionSteps2, toBrowserActionSteps2, targetFromPlaywrightSelector2, fromRemoteBrowserSteps2, fromRecording2, toRecording2 };