@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.
- package/README.md +71 -5
- package/dist/analyze/analyze.d.ts +19 -0
- package/dist/analyze/context.d.ts +40 -0
- package/dist/analyze/index.d.ts +10 -0
- package/dist/analyze/messages.d.ts +39 -0
- package/dist/analyze/rules/fixed-wait.d.ts +6 -0
- package/dist/analyze/rules/hardware-input.d.ts +2 -0
- package/dist/analyze/rules/index.d.ts +3 -0
- package/dist/analyze/rules/inline-target.d.ts +2 -0
- package/dist/analyze/rules/masked-value.d.ts +8 -0
- package/dist/analyze/rules/no-cleanup.d.ts +2 -0
- package/dist/analyze/rules/plain-text-secret.d.ts +2 -0
- package/dist/analyze/rules/rule.d.ts +15 -0
- package/dist/analyze/rules/secret-origin.d.ts +7 -0
- package/dist/analyze/rules/sensitive-screenshot.d.ts +2 -0
- package/dist/analyze/rules/single-method-target.d.ts +2 -0
- package/dist/analyze/rules/unknown-variable.d.ts +2 -0
- package/dist/analyze/rules/unused-value.d.ts +2 -0
- package/dist/analyze/sensitive.d.ts +14 -0
- package/dist/analyze/types.d.ts +66 -0
- package/dist/analyze.d.ts +2 -0
- package/dist/analyze.js +26 -0
- package/dist/dom-runtime.iife.js +1 -1
- package/dist/dom-runtime.js +27 -532
- package/dist/drivers/dom-driver.d.ts +44 -0
- package/dist/drivers/index.d.ts +7 -0
- package/dist/drivers/snapshot-driver.d.ts +59 -0
- package/dist/drivers.d.ts +2 -0
- package/dist/drivers.js +172 -0
- package/dist/index-21hvbvx1.js +340 -0
- package/dist/{index-q1b0j9yr.js → index-5k26keah.js} +58 -592
- package/dist/index-77pcz6n3.js +303 -0
- package/dist/index-8w0f6rsz.js +402 -0
- package/dist/index-9s5nphx0.js +99 -0
- package/dist/index-c88tvyj1.js +743 -0
- package/dist/index-ct2xctrq.js +229 -0
- package/dist/index-g7724awk.js +224 -0
- package/dist/index-gvavb597.js +195 -0
- package/dist/index-r2a9rftv.js +1740 -0
- package/dist/index-s7qdecev.js +489 -0
- package/dist/index-vg8r40y7.js +220 -0
- package/dist/index-xner4tgb.js +810 -0
- package/dist/index-ycs2bz1a.js +589 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +163 -49
- package/dist/interpret/compile.d.ts +58 -0
- package/dist/interpret/driver.d.ts +171 -0
- package/dist/interpret/errors.d.ts +194 -0
- package/dist/interpret/events.d.ts +73 -0
- package/dist/interpret/expr.d.ts +35 -0
- package/dist/interpret/index.d.ts +13 -0
- package/dist/interpret/run.d.ts +77 -0
- package/dist/interpret.d.ts +2 -0
- package/dist/interpret.js +84 -0
- package/dist/script/adapters/browser-action-contract.d.ts +5 -2
- package/dist/script/limits.d.ts +2 -0
- package/dist/script.js +60 -50
- package/dist/target/index.d.ts +1 -1
- package/dist/target/resolve.d.ts +18 -1
- package/dist/target.js +23 -19
- package/dist/testing/fake-web-driver.d.ts +28 -0
- package/dist/testing/index.d.ts +3 -2
- package/dist/testing.js +55 -0
- package/package.json +15 -3
- package/dist/index-zwrxw3zp.js +0 -1988
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import {
|
|
2
|
+
sha256Hex2
|
|
3
|
+
} from "./index-cs6acyjn.js";
|
|
4
|
+
import {
|
|
5
|
+
NAME_PATTERN2,
|
|
6
|
+
STEP_ID_PATTERN2,
|
|
7
|
+
ELEMENT_KEY_PATTERN2,
|
|
8
|
+
uiTargetSchema2,
|
|
9
|
+
withFingerprint2,
|
|
10
|
+
UiScriptError2,
|
|
11
|
+
parseUiScript2
|
|
12
|
+
} from "./index-c88tvyj1.js";
|
|
13
|
+
import {
|
|
14
|
+
UiRunError2
|
|
15
|
+
} from "./index-vg8r40y7.js";
|
|
16
|
+
import {
|
|
17
|
+
requiredCapabilities2,
|
|
18
|
+
missingCapabilities2
|
|
19
|
+
} from "./index-9s5nphx0.js";
|
|
20
|
+
import {
|
|
21
|
+
walkSteps2
|
|
22
|
+
} from "./index-g7724awk.js";
|
|
23
|
+
// src/interpret/compile.ts
|
|
24
|
+
var MAX_CALL_DEPTH2 = 4;
|
|
25
|
+
var COMPILED_NAME_PREFIX2 = "__c";
|
|
26
|
+
function invalid(message, detail) {
|
|
27
|
+
throw new UiRunError2("INVALID_SCRIPT", message, detail);
|
|
28
|
+
}
|
|
29
|
+
function parsedTarget(value, key) {
|
|
30
|
+
const parsed = uiTargetSchema2.safeParse(value);
|
|
31
|
+
if (!parsed.success)
|
|
32
|
+
invalid(`The resolved target of element "${key}" is not a valid UI target`, { key });
|
|
33
|
+
return parsed.data;
|
|
34
|
+
}
|
|
35
|
+
function applyPins2(script, resolved) {
|
|
36
|
+
if (!script.elements)
|
|
37
|
+
return script;
|
|
38
|
+
const byKey = new Map(resolved.map((element) => [element.key, element]));
|
|
39
|
+
const elements = {};
|
|
40
|
+
for (const [key, pin] of Object.entries(script.elements)) {
|
|
41
|
+
const found = byKey.get(key);
|
|
42
|
+
if (!found)
|
|
43
|
+
invalid(`The element "${key}" was not resolved`, { key });
|
|
44
|
+
if (found.elementId !== pin.elementId || found.version !== pin.version) {
|
|
45
|
+
invalid(`The element "${key}" was resolved to a different element or version`, { key });
|
|
46
|
+
}
|
|
47
|
+
elements[key] = {
|
|
48
|
+
...pin,
|
|
49
|
+
...pin.name === undefined && found.name ? { name: found.name.slice(0, 512) } : {},
|
|
50
|
+
target: parsedTarget(found.target, key)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return { ...script, elements };
|
|
54
|
+
}
|
|
55
|
+
function stripBreakpoints2(script) {
|
|
56
|
+
const strip = (steps) => steps.map((step) => {
|
|
57
|
+
const copy = { ...step };
|
|
58
|
+
delete copy.breakpoint;
|
|
59
|
+
return mapBlocks(copy, strip);
|
|
60
|
+
});
|
|
61
|
+
return { ...script, steps: strip(script.steps), ...script.cleanup ? { cleanup: strip(script.cleanup) } : {} };
|
|
62
|
+
}
|
|
63
|
+
function mapBlocks(step, map) {
|
|
64
|
+
switch (step.action) {
|
|
65
|
+
case "if":
|
|
66
|
+
return { ...step, then: map(step.then), ...step.else ? { else: map(step.else) } : {} };
|
|
67
|
+
case "forEach":
|
|
68
|
+
case "while":
|
|
69
|
+
case "retryScope":
|
|
70
|
+
return { ...step, steps: map(step.steps) };
|
|
71
|
+
default:
|
|
72
|
+
return step;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function prefixed(prefix, name) {
|
|
76
|
+
const full = `${prefix}${name}`;
|
|
77
|
+
return NAME_PATTERN2.test(full) ? full : `${prefix}${sha256Hex2(name).slice(0, 12)}`;
|
|
78
|
+
}
|
|
79
|
+
function prefixedKey(prefix, key) {
|
|
80
|
+
const full = `${prefix}${key}`;
|
|
81
|
+
return ELEMENT_KEY_PATTERN2.test(full) ? full : `${prefix}${sha256Hex2(key).slice(0, 12)}`;
|
|
82
|
+
}
|
|
83
|
+
function renameExpression(expression, renames) {
|
|
84
|
+
if (expression === null || typeof expression !== "object")
|
|
85
|
+
return expression;
|
|
86
|
+
if ("input" in expression) {
|
|
87
|
+
return { var: renames.argument(expression.input), ...expression.path ? { path: expression.path } : {} };
|
|
88
|
+
}
|
|
89
|
+
if ("var" in expression) {
|
|
90
|
+
return { var: renames.variable(expression.var), ...expression.path ? { path: expression.path } : {} };
|
|
91
|
+
}
|
|
92
|
+
if ("list" in expression)
|
|
93
|
+
return { list: expression.list.map((item) => renameExpression(item, renames)) };
|
|
94
|
+
if ("object" in expression) {
|
|
95
|
+
return {
|
|
96
|
+
object: Object.fromEntries(Object.entries(expression.object).map(([key, item]) => [key, renameExpression(item, renames)]))
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return { op: expression.op, args: expression.args.map((arg) => renameExpression(arg, renames)) };
|
|
100
|
+
}
|
|
101
|
+
function renameRef(ref, renames) {
|
|
102
|
+
if (ref && "element" in ref)
|
|
103
|
+
return { element: renames.element(ref.element) };
|
|
104
|
+
return ref;
|
|
105
|
+
}
|
|
106
|
+
function renameVerify(verify, renames) {
|
|
107
|
+
if (!verify)
|
|
108
|
+
return;
|
|
109
|
+
switch (verify.kind) {
|
|
110
|
+
case "elementVisible":
|
|
111
|
+
case "elementGone":
|
|
112
|
+
return { ...verify, target: renameRef(verify.target, renames) };
|
|
113
|
+
case "valueEquals":
|
|
114
|
+
return {
|
|
115
|
+
...verify,
|
|
116
|
+
target: renameRef(verify.target, renames),
|
|
117
|
+
value: renameExpression(verify.value, renames)
|
|
118
|
+
};
|
|
119
|
+
case "urlContains":
|
|
120
|
+
return { ...verify, value: renameExpression(verify.value, renames) };
|
|
121
|
+
case "textPresent":
|
|
122
|
+
return { ...verify, text: renameExpression(verify.text, renames) };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
var expr = (value, renames) => value === undefined ? undefined : renameExpression(value, renames);
|
|
126
|
+
function renameStep(step, renames) {
|
|
127
|
+
const common = {
|
|
128
|
+
id: renames.stepId(step.id),
|
|
129
|
+
...step.saveAs === undefined ? {} : { saveAs: renames.variable(step.saveAs) },
|
|
130
|
+
...step.verify ? { verify: renameVerify(step.verify, renames) } : {}
|
|
131
|
+
};
|
|
132
|
+
const children = (steps) => steps.map((child) => renameStep(child, renames));
|
|
133
|
+
const fields = (list) => list.map((field) => ({ ...field, target: renameRef(field.target, renames) }));
|
|
134
|
+
let renamed;
|
|
135
|
+
switch (step.action) {
|
|
136
|
+
case "navigate":
|
|
137
|
+
renamed = { ...step, ...common, url: renameExpression(step.url, renames) };
|
|
138
|
+
break;
|
|
139
|
+
case "type":
|
|
140
|
+
renamed = {
|
|
141
|
+
...step,
|
|
142
|
+
...common,
|
|
143
|
+
...step.target ? { target: renameRef(step.target, renames) } : {},
|
|
144
|
+
...step.text === undefined ? {} : { text: renameExpression(step.text, renames) }
|
|
145
|
+
};
|
|
146
|
+
break;
|
|
147
|
+
case "select":
|
|
148
|
+
renamed = {
|
|
149
|
+
...step,
|
|
150
|
+
...common,
|
|
151
|
+
target: renameRef(step.target, renames),
|
|
152
|
+
values: step.values.map((value) => renameExpression(value, renames))
|
|
153
|
+
};
|
|
154
|
+
break;
|
|
155
|
+
case "waitFor":
|
|
156
|
+
renamed = {
|
|
157
|
+
...step,
|
|
158
|
+
...common,
|
|
159
|
+
...step.target ? { target: renameRef(step.target, renames) } : {},
|
|
160
|
+
...step.text === undefined ? {} : { text: expr(step.text, renames) },
|
|
161
|
+
...step.urlContains === undefined ? {} : { urlContains: expr(step.urlContains, renames) }
|
|
162
|
+
};
|
|
163
|
+
break;
|
|
164
|
+
case "extract":
|
|
165
|
+
renamed = { ...step, ...common, fields: fields(step.fields) };
|
|
166
|
+
break;
|
|
167
|
+
case "extractList":
|
|
168
|
+
renamed = {
|
|
169
|
+
...step,
|
|
170
|
+
...common,
|
|
171
|
+
item: renameRef(step.item, renames),
|
|
172
|
+
fields: fields(step.fields),
|
|
173
|
+
...step.next ? { next: renameRef(step.next, renames) } : {}
|
|
174
|
+
};
|
|
175
|
+
break;
|
|
176
|
+
case "login":
|
|
177
|
+
renamed = {
|
|
178
|
+
...step,
|
|
179
|
+
...common,
|
|
180
|
+
...step.username ? { username: renameRef(step.username, renames) } : {},
|
|
181
|
+
...step.password ? { password: renameRef(step.password, renames) } : {},
|
|
182
|
+
...step.submit ? { submit: renameRef(step.submit, renames) } : {},
|
|
183
|
+
...step.success ? { success: renameRef(step.success, renames) } : {}
|
|
184
|
+
};
|
|
185
|
+
break;
|
|
186
|
+
case "if":
|
|
187
|
+
renamed = {
|
|
188
|
+
...step,
|
|
189
|
+
...common,
|
|
190
|
+
...step.condition === undefined ? {} : { condition: expr(step.condition, renames) },
|
|
191
|
+
...step.elementExists ? { elementExists: renameRef(step.elementExists, renames) } : {},
|
|
192
|
+
then: children(step.then),
|
|
193
|
+
...step.else ? { else: children(step.else) } : {}
|
|
194
|
+
};
|
|
195
|
+
break;
|
|
196
|
+
case "while":
|
|
197
|
+
renamed = {
|
|
198
|
+
...step,
|
|
199
|
+
...common,
|
|
200
|
+
...step.condition === undefined ? {} : { condition: expr(step.condition, renames) },
|
|
201
|
+
...step.elementExists ? { elementExists: renameRef(step.elementExists, renames) } : {},
|
|
202
|
+
steps: children(step.steps)
|
|
203
|
+
};
|
|
204
|
+
break;
|
|
205
|
+
case "forEach":
|
|
206
|
+
renamed = {
|
|
207
|
+
...step,
|
|
208
|
+
...common,
|
|
209
|
+
...step.in === undefined ? {} : { in: expr(step.in, renames) },
|
|
210
|
+
...step.elements ? { elements: renameRef(step.elements, renames) } : {},
|
|
211
|
+
as: renames.variable(step.as),
|
|
212
|
+
...step.index === undefined ? {} : { index: renames.variable(step.index) },
|
|
213
|
+
steps: children(step.steps)
|
|
214
|
+
};
|
|
215
|
+
break;
|
|
216
|
+
case "retryScope":
|
|
217
|
+
renamed = { ...step, ...common, steps: children(step.steps) };
|
|
218
|
+
break;
|
|
219
|
+
case "set":
|
|
220
|
+
renamed = { ...step, ...common, name: renames.variable(step.name), value: renameExpression(step.value, renames) };
|
|
221
|
+
break;
|
|
222
|
+
case "log":
|
|
223
|
+
renamed = { ...step, ...common, message: renameExpression(step.message, renames) };
|
|
224
|
+
break;
|
|
225
|
+
case "call":
|
|
226
|
+
renamed = {
|
|
227
|
+
...step,
|
|
228
|
+
...common,
|
|
229
|
+
...step.args ? {
|
|
230
|
+
args: Object.fromEntries(Object.entries(step.args).map(([name, value]) => [name, renameExpression(value, renames)]))
|
|
231
|
+
} : {}
|
|
232
|
+
};
|
|
233
|
+
break;
|
|
234
|
+
default:
|
|
235
|
+
renamed = "target" in step && step.target ? { ...step, ...common, target: renameRef(step.target, renames) } : { ...step, ...common };
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
return step.fingerprint === undefined ? renamed : withFingerprint2(renamed);
|
|
239
|
+
}
|
|
240
|
+
function assertNoReservedNames(script) {
|
|
241
|
+
const reserved = (name) => name !== undefined && name.startsWith(COMPILED_NAME_PREFIX2);
|
|
242
|
+
const names = [
|
|
243
|
+
...(script.inputs ?? []).map((input) => input.name),
|
|
244
|
+
...(script.variables ?? []).map((variable) => variable.name),
|
|
245
|
+
...Object.keys(script.elements ?? {})
|
|
246
|
+
];
|
|
247
|
+
for (const { step } of walkSteps2(script)) {
|
|
248
|
+
names.push(step.saveAs ?? "");
|
|
249
|
+
if (step.action === "set")
|
|
250
|
+
names.push(step.name);
|
|
251
|
+
if (step.action === "forEach")
|
|
252
|
+
names.push(step.as, step.index ?? "");
|
|
253
|
+
}
|
|
254
|
+
const clash = names.find(reserved);
|
|
255
|
+
if (clash !== undefined) {
|
|
256
|
+
invalid(`The name "${clash}" starts with "${COMPILED_NAME_PREFIX2}", which is reserved for inlined shared sequences`);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function inlineCalls2(script, sequences) {
|
|
260
|
+
const hasCall = Array.from(walkSteps2(script)).some(({ step }) => step.action === "call");
|
|
261
|
+
if (!hasCall)
|
|
262
|
+
return { script, calls: [] };
|
|
263
|
+
assertNoReservedNames(script);
|
|
264
|
+
const bySequence = new Map(sequences.map((sequence) => [`${sequence.sequenceId}@${sequence.version}`, sequence]));
|
|
265
|
+
const usedIds = new Set(Array.from(walkSteps2(script)).map(({ step }) => step.id));
|
|
266
|
+
const elements = { ...script.elements };
|
|
267
|
+
const calls = [];
|
|
268
|
+
let counter = 0;
|
|
269
|
+
const uniqueId = (wanted) => {
|
|
270
|
+
let id = STEP_ID_PATTERN2.test(wanted) ? wanted : `s-${sha256Hex2(wanted).slice(0, 12)}`;
|
|
271
|
+
for (let n = 2;usedIds.has(id); n += 1)
|
|
272
|
+
id = `s-${sha256Hex2(`${wanted}#${n}`).slice(0, 12)}`;
|
|
273
|
+
usedIds.add(id);
|
|
274
|
+
return id;
|
|
275
|
+
};
|
|
276
|
+
const inlineList = (steps, stack) => steps.map((step) => step.action === "call" ? inlineOne(step, stack) : mapBlocks(step, (children) => inlineList(children, stack)));
|
|
277
|
+
const inlineOne = (call, stack) => {
|
|
278
|
+
const ref = `${call.sequenceId}@${call.version}`;
|
|
279
|
+
if (stack.includes(ref))
|
|
280
|
+
invalid(`The shared sequence ${ref} calls itself`, { sequenceId: call.sequenceId });
|
|
281
|
+
if (stack.length >= MAX_CALL_DEPTH2) {
|
|
282
|
+
invalid(`Shared sequences call each other at most ${MAX_CALL_DEPTH2} deep`, { sequenceId: call.sequenceId });
|
|
283
|
+
}
|
|
284
|
+
const sequence = bySequence.get(ref);
|
|
285
|
+
if (!sequence)
|
|
286
|
+
invalid(`The shared sequence ${ref} was not resolved`, { sequenceId: call.sequenceId });
|
|
287
|
+
counter += 1;
|
|
288
|
+
const prefix = `${COMPILED_NAME_PREFIX2}${counter}_`;
|
|
289
|
+
const elementKeys = new Map;
|
|
290
|
+
for (const element of sequence.elements) {
|
|
291
|
+
const key = prefixedKey(prefix, element.key);
|
|
292
|
+
elementKeys.set(element.key, key);
|
|
293
|
+
elements[key] = {
|
|
294
|
+
elementId: element.elementId,
|
|
295
|
+
version: element.version,
|
|
296
|
+
...element.name ? { name: element.name.slice(0, 512) } : {},
|
|
297
|
+
target: parsedTarget(element.target, element.key)
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
const declared = new Map(sequence.arguments.map((argument) => [argument.name, argument]));
|
|
301
|
+
const renames = {
|
|
302
|
+
variable: (name) => prefixed(`${prefix}v_`, name),
|
|
303
|
+
argument: (name) => {
|
|
304
|
+
if (!declared.has(name))
|
|
305
|
+
invalid(`The shared sequence ${ref} reads an argument "${name}" it does not declare`);
|
|
306
|
+
return prefixed(`${prefix}a_`, name);
|
|
307
|
+
},
|
|
308
|
+
element: (key) => {
|
|
309
|
+
const mapped = elementKeys.get(key);
|
|
310
|
+
if (mapped === undefined)
|
|
311
|
+
invalid(`The shared sequence ${ref} uses an element "${key}" it does not pin`, { key });
|
|
312
|
+
return mapped;
|
|
313
|
+
},
|
|
314
|
+
stepId: (id) => uniqueId(`${call.id}-${id}`)
|
|
315
|
+
};
|
|
316
|
+
for (const name of Object.keys(call.args ?? {})) {
|
|
317
|
+
if (!declared.has(name))
|
|
318
|
+
invalid(`Step ${call.id} passes an argument "${name}" the sequence does not declare`);
|
|
319
|
+
}
|
|
320
|
+
const argumentSteps = sequence.arguments.map((argument) => {
|
|
321
|
+
const given = call.args?.[argument.name];
|
|
322
|
+
if (given === undefined && argument.default === undefined && argument.required === true) {
|
|
323
|
+
invalid(`Step ${call.id} does not pass the required argument "${argument.name}"`);
|
|
324
|
+
}
|
|
325
|
+
const value = given !== undefined ? given : argument.default !== undefined ? renameExpression(argument.default, renames) : null;
|
|
326
|
+
return {
|
|
327
|
+
id: uniqueId(`${call.id}-arg-${argument.name}`),
|
|
328
|
+
action: "set",
|
|
329
|
+
name: renames.argument(argument.name),
|
|
330
|
+
value
|
|
331
|
+
};
|
|
332
|
+
});
|
|
333
|
+
const body = inlineList(sequence.steps.map((step) => renameStep(step, renames)), [...stack, ref]);
|
|
334
|
+
const outputSteps = call.saveAs === undefined ? [] : [
|
|
335
|
+
{
|
|
336
|
+
id: uniqueId(`${call.id}-out`),
|
|
337
|
+
action: "set",
|
|
338
|
+
name: call.saveAs,
|
|
339
|
+
value: {
|
|
340
|
+
object: Object.fromEntries(sequence.outputs.map((output) => [output.name, renameExpression(output.value, renames)]))
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
];
|
|
344
|
+
calls.push({ stepId: call.id, sequenceId: call.sequenceId, version: call.version });
|
|
345
|
+
return {
|
|
346
|
+
id: call.id,
|
|
347
|
+
action: "retryScope",
|
|
348
|
+
attempts: 1,
|
|
349
|
+
...call.intent === undefined ? {} : { intent: call.intent },
|
|
350
|
+
...call.note === undefined ? {} : { note: call.note },
|
|
351
|
+
...call.disabled === undefined ? {} : { disabled: call.disabled },
|
|
352
|
+
...call.breakpoint === undefined ? {} : { breakpoint: call.breakpoint },
|
|
353
|
+
...call.retry === undefined ? {} : { retry: call.retry },
|
|
354
|
+
...call.onError === undefined ? {} : { onError: call.onError },
|
|
355
|
+
...call.safeToRepeat === undefined ? {} : { safeToRepeat: call.safeToRepeat },
|
|
356
|
+
...call.saveAs === undefined ? {} : { saveAs: call.saveAs },
|
|
357
|
+
steps: [...argumentSteps, ...body, ...outputSteps]
|
|
358
|
+
};
|
|
359
|
+
};
|
|
360
|
+
const steps = inlineList(script.steps, []);
|
|
361
|
+
const cleanup = script.cleanup ? inlineList(script.cleanup, []) : undefined;
|
|
362
|
+
return {
|
|
363
|
+
script: {
|
|
364
|
+
...script,
|
|
365
|
+
...Object.keys(elements).length > 0 ? { elements } : {},
|
|
366
|
+
steps,
|
|
367
|
+
...cleanup ? { cleanup } : {}
|
|
368
|
+
},
|
|
369
|
+
calls
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
function parseOrThrow(value, resolved) {
|
|
373
|
+
try {
|
|
374
|
+
return parseUiScript2(value, { resolved });
|
|
375
|
+
} catch (error) {
|
|
376
|
+
if (error instanceof UiScriptError2) {
|
|
377
|
+
throw new UiRunError2("INVALID_SCRIPT", error.message, {
|
|
378
|
+
engineCode: error.code,
|
|
379
|
+
...error.path === undefined ? {} : { path: error.path }
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
throw error;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
function compileUiScript2(value, options = {}) {
|
|
386
|
+
const parsed = parseOrThrow(value, false);
|
|
387
|
+
const pinned = applyPins2(parsed, options.elements ?? []);
|
|
388
|
+
const { script: inlined, calls } = inlineCalls2(pinned, options.sequences ?? []);
|
|
389
|
+
const stripped = options.mode === "test" ? inlined : stripBreakpoints2(inlined);
|
|
390
|
+
const script = parseOrThrow(stripped, true);
|
|
391
|
+
const required = requiredCapabilities2(script);
|
|
392
|
+
if (options.capabilities) {
|
|
393
|
+
const missing = missingCapabilities2(script, options.capabilities);
|
|
394
|
+
if (missing.length > 0) {
|
|
395
|
+
throw new UiRunError2("UNSUPPORTED_ON_DESK", `The desk cannot run this script: it lacks ${missing.join(", ")}`, {
|
|
396
|
+
missing
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return { script, requiredCapabilities: required, calls };
|
|
401
|
+
}
|
|
402
|
+
export { MAX_CALL_DEPTH2, COMPILED_NAME_PREFIX2, applyPins2, stripBreakpoints2, inlineCalls2, compileUiScript2 };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UI_TARGET_METHOD_KINDS2,
|
|
3
|
+
UI_STEP_ACTIONS2,
|
|
4
|
+
walkSteps2,
|
|
5
|
+
stepTargets2
|
|
6
|
+
} from "./index-g7724awk.js";
|
|
7
|
+
|
|
8
|
+
// src/script/limits.ts
|
|
9
|
+
var UI_SCRIPT_VERSION2 = 1;
|
|
10
|
+
var MAX_SCRIPT_STEPS2 = 500;
|
|
11
|
+
var MAX_SCRIPT_BYTES2 = 1024 * 1024;
|
|
12
|
+
var MAX_FLOW_DEPTH2 = 8;
|
|
13
|
+
var MAX_EXPRESSION_DEPTH2 = 16;
|
|
14
|
+
var MAX_EXPRESSION_ITEMS2 = 1000;
|
|
15
|
+
var MAX_OPERATOR_ARGS2 = 16;
|
|
16
|
+
var MAX_SCRIPT_INPUTS2 = 100;
|
|
17
|
+
var MAX_SCRIPT_OUTPUTS2 = 100;
|
|
18
|
+
var MAX_SCRIPT_VARIABLES2 = 100;
|
|
19
|
+
var MAX_SCRIPT_ELEMENTS2 = 500;
|
|
20
|
+
var MAX_TARGET_METHODS2 = 8;
|
|
21
|
+
var MAX_FRAME_DEPTH2 = 8;
|
|
22
|
+
var MAX_EXTRACT_FIELDS2 = 50;
|
|
23
|
+
var MAX_LIST_ITEMS2 = 5000;
|
|
24
|
+
var MAX_LIST_PAGES2 = 50;
|
|
25
|
+
var MAX_LOOP_ITERATIONS2 = 1e4;
|
|
26
|
+
var MAX_RETRY_ATTEMPTS2 = 10;
|
|
27
|
+
var MAX_STEP_TIMEOUT_MS2 = 600000;
|
|
28
|
+
var MAX_DELAY_MS2 = 60000;
|
|
29
|
+
var MAX_KEYS2 = 8;
|
|
30
|
+
var MAX_SELECT_VALUES2 = 50;
|
|
31
|
+
var MAX_SELECTOR_LENGTH2 = 500;
|
|
32
|
+
var MAX_URL_LENGTH2 = 4096;
|
|
33
|
+
var MAX_LABEL_LENGTH2 = 512;
|
|
34
|
+
var MAX_TEXT_LENGTH2 = 1e4;
|
|
35
|
+
var MAX_INTENT_LENGTH2 = 500;
|
|
36
|
+
var MAX_NAME_LENGTH2 = 64;
|
|
37
|
+
var LEGACY_MAX_BROWSER_STEPS2 = 100;
|
|
38
|
+
var LEGACY_MAX_STEPS_BYTES2 = 256 * 1024;
|
|
39
|
+
var LEGACY_MAX_STEP_TIMEOUT_MS2 = 60000;
|
|
40
|
+
function jsonByteLength2(value) {
|
|
41
|
+
return new TextEncoder().encode(JSON.stringify(value) ?? "").length;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/script/capabilities.ts
|
|
45
|
+
var CAPABILITY_IDS2 = [
|
|
46
|
+
"script:1",
|
|
47
|
+
...UI_STEP_ACTIONS2.map((action) => `action:${action}`),
|
|
48
|
+
...UI_TARGET_METHOD_KINDS2.map((kind) => `target:${kind}`),
|
|
49
|
+
"target:frame",
|
|
50
|
+
"step:verify",
|
|
51
|
+
"step:retry",
|
|
52
|
+
"step:breakpoint",
|
|
53
|
+
"input:direct",
|
|
54
|
+
"input:hardware"
|
|
55
|
+
].sort();
|
|
56
|
+
var SCRIPT_CAPABILITY2 = "script:1";
|
|
57
|
+
function targetCapabilities(target, into) {
|
|
58
|
+
for (const method of target.methods)
|
|
59
|
+
if (method.enabled !== false)
|
|
60
|
+
into.add(`target:${method.kind}`);
|
|
61
|
+
if (target.frame)
|
|
62
|
+
into.add("target:frame");
|
|
63
|
+
}
|
|
64
|
+
function requiredCapabilities2(script) {
|
|
65
|
+
const required = new Set([SCRIPT_CAPABILITY2]);
|
|
66
|
+
const elements = script.elements ?? {};
|
|
67
|
+
const inputMethods = [script.settings?.inputMethod];
|
|
68
|
+
const skipped = [];
|
|
69
|
+
for (const { step, path } of walkSteps2(script)) {
|
|
70
|
+
if (step.disabled === true)
|
|
71
|
+
skipped.push(`${path}.`);
|
|
72
|
+
if (step.disabled === true || skipped.some((prefix) => path.startsWith(prefix)))
|
|
73
|
+
continue;
|
|
74
|
+
required.add(`action:${step.action}`);
|
|
75
|
+
for (const [, ref] of stepTargets2(step)) {
|
|
76
|
+
const target = "element" in ref ? elements[ref.element]?.target : ref;
|
|
77
|
+
if (target)
|
|
78
|
+
targetCapabilities(target, required);
|
|
79
|
+
}
|
|
80
|
+
if (step.verify)
|
|
81
|
+
required.add("step:verify");
|
|
82
|
+
if (step.retry)
|
|
83
|
+
required.add("step:retry");
|
|
84
|
+
if (step.breakpoint === true)
|
|
85
|
+
required.add("step:breakpoint");
|
|
86
|
+
inputMethods.push(step.inputMethod);
|
|
87
|
+
}
|
|
88
|
+
for (const method of inputMethods) {
|
|
89
|
+
if (method === "direct" || method === "hardware")
|
|
90
|
+
required.add(`input:${method}`);
|
|
91
|
+
}
|
|
92
|
+
return [...required].sort();
|
|
93
|
+
}
|
|
94
|
+
function missingCapabilities2(script, supported) {
|
|
95
|
+
const have = new Set(supported);
|
|
96
|
+
return requiredCapabilities2(script).filter((id) => !have.has(id));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { UI_SCRIPT_VERSION2, MAX_SCRIPT_STEPS2, MAX_SCRIPT_BYTES2, MAX_FLOW_DEPTH2, MAX_EXPRESSION_DEPTH2, MAX_EXPRESSION_ITEMS2, MAX_OPERATOR_ARGS2, MAX_SCRIPT_INPUTS2, MAX_SCRIPT_OUTPUTS2, MAX_SCRIPT_VARIABLES2, MAX_SCRIPT_ELEMENTS2, MAX_TARGET_METHODS2, MAX_FRAME_DEPTH2, MAX_EXTRACT_FIELDS2, MAX_LIST_ITEMS2, MAX_LIST_PAGES2, MAX_LOOP_ITERATIONS2, MAX_RETRY_ATTEMPTS2, MAX_STEP_TIMEOUT_MS2, MAX_DELAY_MS2, MAX_KEYS2, MAX_SELECT_VALUES2, MAX_SELECTOR_LENGTH2, MAX_URL_LENGTH2, MAX_LABEL_LENGTH2, MAX_TEXT_LENGTH2, MAX_INTENT_LENGTH2, MAX_NAME_LENGTH2, LEGACY_MAX_BROWSER_STEPS2, LEGACY_MAX_STEPS_BYTES2, LEGACY_MAX_STEP_TIMEOUT_MS2, jsonByteLength2, CAPABILITY_IDS2, SCRIPT_CAPABILITY2, requiredCapabilities2, missingCapabilities2 };
|