@burdenoff/ui-engine 2026.1127.2 → 2026.1127.4
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 +74 -4
- package/dist/capture.js +3 -2
- package/dist/dom-runtime/actions.d.ts +65 -0
- package/dist/dom-runtime/iife.d.ts +1 -0
- package/dist/dom-runtime/index.d.ts +7 -0
- package/dist/dom-runtime/runtime.d.ts +79 -0
- package/dist/dom-runtime.d.ts +2 -0
- package/dist/dom-runtime.iife.js +1 -0
- package/dist/dom-runtime.js +30 -0
- 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 +170 -0
- package/dist/{index-n5amgh31.js → index-2kgsgn1c.js} +1 -1
- package/dist/index-3f1j8386.js +334 -0
- package/dist/index-3jymbm5t.js +315 -0
- package/dist/index-5k26keah.js +815 -0
- package/dist/index-77pcz6n3.js +303 -0
- package/dist/index-895kscx3.js +741 -0
- package/dist/{index-phd8yhyg.js → index-bnvmt4wf.js} +7 -5
- package/dist/{index-c6pmt2rg.js → index-cs6acyjn.js} +6 -59
- package/dist/index-ct2xctrq.js +229 -0
- package/dist/index-h88y5qgv.js +400 -0
- package/dist/index-mgztm37r.js +57 -0
- package/dist/{index-tqffkt91.js → index-pm13mvvc.js} +26 -1009
- package/dist/index-vg8r40y7.js +220 -0
- package/dist/index-ycs2bz1a.js +589 -0
- package/dist/index-zzhysbkj.js +1731 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +130 -42
- 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/recording.js +1 -1
- package/dist/replay.js +2 -2
- package/dist/script/adapters/browser-action-contract.d.ts +5 -2
- package/dist/script/limits.d.ts +2 -0
- package/dist/script.js +44 -38
- package/dist/target/aria.d.ts +31 -0
- package/dist/target/dom.d.ts +35 -0
- package/dist/target/index.d.ts +13 -0
- package/dist/target/markers.d.ts +18 -0
- package/dist/target/methods.d.ts +52 -0
- package/dist/target/resolve.d.ts +63 -0
- package/dist/target/snapshot.d.ts +57 -0
- package/dist/target/text.d.ts +23 -0
- package/dist/target/types.d.ts +88 -0
- package/dist/target.d.ts +2 -0
- package/dist/target.js +96 -0
- package/dist/testing/fake-web-driver.d.ts +28 -0
- package/dist/testing/fixtures/ambiguous.d.ts +7 -0
- package/dist/testing/fixtures/iframe.d.ts +6 -0
- package/dist/testing/fixtures/index.d.ts +26 -0
- package/dist/testing/fixtures/invoices-v2.d.ts +8 -0
- package/dist/testing/fixtures/invoices-v3.d.ts +7 -0
- package/dist/testing/fixtures/invoices.d.ts +6 -0
- package/dist/testing/fixtures/login.d.ts +6 -0
- package/dist/testing/fixtures/shadow.d.ts +7 -0
- package/dist/testing/index.d.ts +7 -0
- package/dist/testing/mount.d.ts +18 -0
- package/dist/testing.d.ts +2 -0
- package/dist/testing.js +379 -0
- package/package.json +29 -5
|
@@ -1,969 +1,38 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
uiScriptRegistry2,
|
|
3
|
+
NAME_PATTERN2,
|
|
4
|
+
uiScriptSchema2,
|
|
5
|
+
canonicalJson2,
|
|
6
|
+
soleRoleMethod,
|
|
7
|
+
uiStepFingerprint2,
|
|
8
|
+
UiScriptError2,
|
|
9
|
+
parseUiScript2
|
|
10
|
+
} from "./index-895kscx3.js";
|
|
11
|
+
import {
|
|
4
12
|
sha256Hex2,
|
|
5
|
-
targetFingerprint2,
|
|
6
13
|
RecordingError2,
|
|
7
14
|
parseRecording2
|
|
8
|
-
} from "./index-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"or",
|
|
20
|
-
"not",
|
|
21
|
-
"add",
|
|
22
|
-
"sub",
|
|
23
|
-
"mul",
|
|
24
|
-
"div",
|
|
25
|
-
"mod",
|
|
26
|
-
"neg",
|
|
27
|
-
"abs",
|
|
28
|
-
"round",
|
|
29
|
-
"min",
|
|
30
|
-
"max",
|
|
31
|
-
"concat",
|
|
32
|
-
"contains",
|
|
33
|
-
"startsWith",
|
|
34
|
-
"endsWith",
|
|
35
|
-
"lower",
|
|
36
|
-
"upper",
|
|
37
|
-
"trim",
|
|
38
|
-
"replace",
|
|
39
|
-
"split",
|
|
40
|
-
"join",
|
|
41
|
-
"length",
|
|
42
|
-
"toNumber",
|
|
43
|
-
"toText",
|
|
44
|
-
"toBoolean",
|
|
45
|
-
"isEmpty",
|
|
46
|
-
"coalesce",
|
|
47
|
-
"if",
|
|
48
|
-
"get",
|
|
49
|
-
"now",
|
|
50
|
-
"formatDate",
|
|
51
|
-
"addDays"
|
|
52
|
-
];
|
|
53
|
-
var UI_ANCHOR_RELATIONS2 = ["leftOf", "rightOf", "above", "below", "inside", "sameRow"];
|
|
54
|
-
var UI_TARGET_METHOD_KINDS2 = ["role", "css", "testId", "xpath", "fuzzy", "anchor", "text"];
|
|
55
|
-
var UI_WEB_ACTIONS2 = [
|
|
56
|
-
"navigate",
|
|
57
|
-
"goBack",
|
|
58
|
-
"reload",
|
|
59
|
-
"closeTab",
|
|
60
|
-
"click",
|
|
61
|
-
"doubleClick",
|
|
62
|
-
"hover",
|
|
63
|
-
"type",
|
|
64
|
-
"typeSecret",
|
|
65
|
-
"clear",
|
|
66
|
-
"select",
|
|
67
|
-
"check",
|
|
68
|
-
"pressKey",
|
|
69
|
-
"scroll",
|
|
70
|
-
"waitFor",
|
|
71
|
-
"extract",
|
|
72
|
-
"extractList",
|
|
73
|
-
"getText",
|
|
74
|
-
"getValue",
|
|
75
|
-
"getAttribute",
|
|
76
|
-
"elementExists",
|
|
77
|
-
"getPageText",
|
|
78
|
-
"getPageHtml",
|
|
79
|
-
"screenshot",
|
|
80
|
-
"login"
|
|
81
|
-
];
|
|
82
|
-
var UI_DESKTOP_ACTIONS2 = ["focusWindow"];
|
|
83
|
-
var UI_FLOW_ACTIONS2 = [
|
|
84
|
-
"if",
|
|
85
|
-
"forEach",
|
|
86
|
-
"while",
|
|
87
|
-
"retryScope",
|
|
88
|
-
"set",
|
|
89
|
-
"log",
|
|
90
|
-
"call"
|
|
91
|
-
];
|
|
92
|
-
var UI_STEP_ACTIONS2 = [...UI_WEB_ACTIONS2, ...UI_DESKTOP_ACTIONS2, ...UI_FLOW_ACTIONS2];
|
|
93
|
-
var UI_VALUE_TYPES2 = ["text", "number", "boolean", "list", "object", "any"];
|
|
94
|
-
// src/script/limits.ts
|
|
95
|
-
var UI_SCRIPT_VERSION2 = 1;
|
|
96
|
-
var MAX_SCRIPT_STEPS2 = 500;
|
|
97
|
-
var MAX_SCRIPT_BYTES2 = 1024 * 1024;
|
|
98
|
-
var MAX_FLOW_DEPTH2 = 8;
|
|
99
|
-
var MAX_EXPRESSION_DEPTH2 = 16;
|
|
100
|
-
var MAX_EXPRESSION_ITEMS2 = 1000;
|
|
101
|
-
var MAX_OPERATOR_ARGS2 = 16;
|
|
102
|
-
var MAX_SCRIPT_INPUTS2 = 100;
|
|
103
|
-
var MAX_SCRIPT_OUTPUTS2 = 100;
|
|
104
|
-
var MAX_SCRIPT_VARIABLES2 = 100;
|
|
105
|
-
var MAX_SCRIPT_ELEMENTS2 = 500;
|
|
106
|
-
var MAX_TARGET_METHODS2 = 8;
|
|
107
|
-
var MAX_FRAME_DEPTH2 = 8;
|
|
108
|
-
var MAX_EXTRACT_FIELDS2 = 50;
|
|
109
|
-
var MAX_LIST_ITEMS2 = 5000;
|
|
110
|
-
var MAX_LIST_PAGES2 = 50;
|
|
111
|
-
var MAX_LOOP_ITERATIONS2 = 1e4;
|
|
112
|
-
var MAX_RETRY_ATTEMPTS2 = 10;
|
|
113
|
-
var MAX_STEP_TIMEOUT_MS2 = 600000;
|
|
114
|
-
var MAX_DELAY_MS2 = 60000;
|
|
115
|
-
var MAX_KEYS2 = 8;
|
|
116
|
-
var MAX_SELECT_VALUES2 = 50;
|
|
117
|
-
var MAX_SELECTOR_LENGTH2 = 500;
|
|
118
|
-
var MAX_URL_LENGTH2 = 4096;
|
|
119
|
-
var MAX_LABEL_LENGTH2 = 512;
|
|
120
|
-
var MAX_TEXT_LENGTH2 = 1e4;
|
|
121
|
-
var MAX_INTENT_LENGTH2 = 500;
|
|
122
|
-
var MAX_NAME_LENGTH2 = 64;
|
|
123
|
-
var LEGACY_MAX_BROWSER_STEPS2 = 100;
|
|
124
|
-
var LEGACY_MAX_STEPS_BYTES2 = 256 * 1024;
|
|
125
|
-
function jsonByteLength2(value) {
|
|
126
|
-
return new TextEncoder().encode(JSON.stringify(value) ?? "").length;
|
|
127
|
-
}
|
|
128
|
-
// src/script/schema.ts
|
|
129
|
-
import { z } from "zod";
|
|
130
|
-
var uiScriptRegistry2 = z.registry();
|
|
131
|
-
var NAME_PATTERN2 = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/;
|
|
132
|
-
var STEP_ID_PATTERN2 = /^[A-Za-z0-9_-]{1,64}$/;
|
|
133
|
-
var ELEMENT_KEY_PATTERN2 = /^[A-Za-z_][A-Za-z0-9_-]{0,63}$/;
|
|
134
|
-
var STORAGE_KEY_PATTERN = /^[A-Za-z0-9][A-Za-z0-9:/._-]{0,511}$/;
|
|
135
|
-
var SECRET_REF_PATTERN = /^[A-Za-z0-9][A-Za-z0-9:/._#-]{0,254}$/;
|
|
136
|
-
var ATTRIBUTE_PATTERN = /^[A-Za-z_:][A-Za-z0-9_.:-]{0,63}$/;
|
|
137
|
-
var name = z.string().regex(NAME_PATTERN2);
|
|
138
|
-
var label = z.string().min(1).max(MAX_LABEL_LENGTH2);
|
|
139
|
-
var selector = z.string().min(1).max(MAX_SELECTOR_LENGTH2);
|
|
140
|
-
var ms = z.int().min(0).max(MAX_STEP_TIMEOUT_MS2);
|
|
141
|
-
var delay = z.int().min(0).max(MAX_DELAY_MS2);
|
|
142
|
-
var valueType = z.enum(UI_VALUE_TYPES2);
|
|
143
|
-
var valuePath = z.array(z.union([z.string().min(1).max(MAX_NAME_LENGTH2), z.int().min(0)])).min(1).max(MAX_EXPRESSION_DEPTH2);
|
|
144
|
-
var uiExpressionSchema2 = z.lazy(() => z.union([
|
|
145
|
-
z.string().max(MAX_TEXT_LENGTH2),
|
|
146
|
-
z.number(),
|
|
147
|
-
z.boolean(),
|
|
148
|
-
z.null(),
|
|
149
|
-
z.strictObject({ input: name, path: valuePath.optional() }),
|
|
150
|
-
z.strictObject({ var: name, path: valuePath.optional() }),
|
|
151
|
-
z.strictObject({ list: z.array(uiExpressionSchema2).max(MAX_EXPRESSION_ITEMS2) }),
|
|
152
|
-
z.strictObject({ object: z.record(name, uiExpressionSchema2) }),
|
|
153
|
-
z.strictObject({ op: z.enum(UI_EXPRESSION_OPS2), args: z.array(uiExpressionSchema2).max(MAX_OPERATOR_ARGS2) })
|
|
154
|
-
])).register(uiScriptRegistry2, { id: "UiExpression" });
|
|
155
|
-
var enabled = { enabled: z.boolean().optional() };
|
|
156
|
-
var anchorSchema = z.discriminatedUnion("kind", [
|
|
157
|
-
z.strictObject({ kind: z.literal("text"), text: label }),
|
|
158
|
-
z.strictObject({ kind: z.literal("role"), role: label, name: label })
|
|
159
|
-
]);
|
|
160
|
-
var uiTargetMethodSchema2 = z.discriminatedUnion("kind", [
|
|
161
|
-
z.strictObject({
|
|
162
|
-
kind: z.literal("role"),
|
|
163
|
-
role: label,
|
|
164
|
-
name: label,
|
|
165
|
-
nth: z.int().min(0).max(50).optional(),
|
|
166
|
-
app: label.optional(),
|
|
167
|
-
window: label.optional(),
|
|
168
|
-
...enabled
|
|
169
|
-
}),
|
|
170
|
-
z.strictObject({ kind: z.literal("css"), selector, ...enabled }),
|
|
171
|
-
z.strictObject({
|
|
172
|
-
kind: z.literal("testId"),
|
|
173
|
-
value: label,
|
|
174
|
-
attribute: z.string().regex(ATTRIBUTE_PATTERN).optional(),
|
|
175
|
-
...enabled
|
|
176
|
-
}),
|
|
177
|
-
z.strictObject({ kind: z.literal("xpath"), xpath: selector, ...enabled }),
|
|
178
|
-
z.strictObject({
|
|
179
|
-
kind: z.literal("fuzzy"),
|
|
180
|
-
role: label.optional(),
|
|
181
|
-
name: label,
|
|
182
|
-
threshold: z.number().min(0.5).max(1).optional(),
|
|
183
|
-
...enabled
|
|
184
|
-
}),
|
|
185
|
-
z.strictObject({
|
|
186
|
-
kind: z.literal("anchor"),
|
|
187
|
-
anchor: anchorSchema,
|
|
188
|
-
relation: z.enum(UI_ANCHOR_RELATIONS2),
|
|
189
|
-
role: label.optional(),
|
|
190
|
-
...enabled
|
|
191
|
-
}),
|
|
192
|
-
z.strictObject({
|
|
193
|
-
kind: z.literal("text"),
|
|
194
|
-
text: label,
|
|
195
|
-
exact: z.boolean().optional(),
|
|
196
|
-
nth: z.int().min(0).max(50).optional(),
|
|
197
|
-
...enabled
|
|
198
|
-
})
|
|
199
|
-
]).register(uiScriptRegistry2, { id: "UiTargetMethod" });
|
|
200
|
-
var uiTargetSchema2 = z.strictObject({
|
|
201
|
-
methods: z.array(uiTargetMethodSchema2).min(1).max(MAX_TARGET_METHODS2),
|
|
202
|
-
frame: z.array(selector).min(1).max(MAX_FRAME_DEPTH2).optional()
|
|
203
|
-
}).register(uiScriptRegistry2, { id: "UiTarget" });
|
|
204
|
-
var uiTargetRefSchema2 = z.union([uiTargetSchema2, z.strictObject({ element: z.string().regex(ELEMENT_KEY_PATTERN2) })]).register(uiScriptRegistry2, { id: "UiTargetRef" });
|
|
205
|
-
var verifyTimeout = { timeoutMs: ms.optional() };
|
|
206
|
-
var verifySchema = z.discriminatedUnion("kind", [
|
|
207
|
-
z.strictObject({ kind: z.literal("elementVisible"), target: uiTargetRefSchema2, ...verifyTimeout }),
|
|
208
|
-
z.strictObject({ kind: z.literal("elementGone"), target: uiTargetRefSchema2, ...verifyTimeout }),
|
|
209
|
-
z.strictObject({ kind: z.literal("urlContains"), value: uiExpressionSchema2, ...verifyTimeout }),
|
|
210
|
-
z.strictObject({ kind: z.literal("textPresent"), text: uiExpressionSchema2, ...verifyTimeout }),
|
|
211
|
-
z.strictObject({
|
|
212
|
-
kind: z.literal("valueEquals"),
|
|
213
|
-
target: uiTargetRefSchema2,
|
|
214
|
-
value: uiExpressionSchema2,
|
|
215
|
-
...verifyTimeout
|
|
216
|
-
})
|
|
217
|
-
]);
|
|
218
|
-
var base = {
|
|
219
|
-
id: z.string().regex(STEP_ID_PATTERN2),
|
|
220
|
-
intent: z.string().min(1).max(MAX_INTENT_LENGTH2).optional(),
|
|
221
|
-
note: z.string().min(1).max(MAX_INTENT_LENGTH2).optional(),
|
|
222
|
-
saveAs: name.optional(),
|
|
223
|
-
disabled: z.boolean().optional(),
|
|
224
|
-
breakpoint: z.boolean().optional(),
|
|
225
|
-
timeoutMs: ms.optional(),
|
|
226
|
-
retry: z.strictObject({ attempts: z.int().min(1).max(MAX_RETRY_ATTEMPTS2), delayMs: delay.optional() }).optional(),
|
|
227
|
-
onError: z.enum(["fail", "continue"]).optional(),
|
|
228
|
-
verify: verifySchema.optional(),
|
|
229
|
-
screenshot: z.enum(["never", "onFailure", "always"]).optional(),
|
|
230
|
-
inputMethod: z.enum(["auto", "direct", "hardware"]).optional(),
|
|
231
|
-
safeToRepeat: z.boolean().optional(),
|
|
232
|
-
screenshotRef: z.string().regex(STORAGE_KEY_PATTERN).optional(),
|
|
233
|
-
fingerprint: z.string().regex(/^[0-9a-f]{64}$/).optional()
|
|
234
|
-
};
|
|
235
|
-
var target = uiTargetRefSchema2;
|
|
236
|
-
var steps = () => z.array(uiStepSchema2).min(1).max(MAX_SCRIPT_STEPS2);
|
|
237
|
-
var fieldSchema = z.strictObject({
|
|
238
|
-
name,
|
|
239
|
-
target,
|
|
240
|
-
attribute: z.string().regex(ATTRIBUTE_PATTERN).optional(),
|
|
241
|
-
all: z.boolean().optional()
|
|
242
|
-
});
|
|
243
|
-
var fields = z.array(fieldSchema).min(1).max(MAX_EXTRACT_FIELDS2);
|
|
244
|
-
var condition = { condition: uiExpressionSchema2.optional(), elementExists: target.optional() };
|
|
245
|
-
var uiStepSchema2 = z.lazy(() => z.discriminatedUnion("action", [
|
|
246
|
-
z.strictObject({
|
|
247
|
-
...base,
|
|
248
|
-
action: z.literal("navigate"),
|
|
249
|
-
url: uiExpressionSchema2,
|
|
250
|
-
waitUntil: z.enum(["load", "domcontentloaded", "networkidle", "commit"]).optional()
|
|
251
|
-
}),
|
|
252
|
-
z.strictObject({ ...base, action: z.literal("goBack") }),
|
|
253
|
-
z.strictObject({ ...base, action: z.literal("reload") }),
|
|
254
|
-
z.strictObject({ ...base, action: z.literal("closeTab") }),
|
|
255
|
-
z.strictObject({ ...base, action: z.literal("click"), target, button: z.enum(["left", "right"]).optional() }),
|
|
256
|
-
z.strictObject({
|
|
257
|
-
...base,
|
|
258
|
-
action: z.literal("doubleClick"),
|
|
259
|
-
target,
|
|
260
|
-
button: z.enum(["left", "right"]).optional()
|
|
261
|
-
}),
|
|
262
|
-
z.strictObject({ ...base, action: z.literal("hover"), target }),
|
|
263
|
-
z.strictObject({
|
|
264
|
-
...base,
|
|
265
|
-
action: z.literal("type"),
|
|
266
|
-
target: target.optional(),
|
|
267
|
-
text: uiExpressionSchema2.optional(),
|
|
268
|
-
masked: z.boolean().optional(),
|
|
269
|
-
clear: z.boolean().optional(),
|
|
270
|
-
pressEnter: z.boolean().optional(),
|
|
271
|
-
delayMs: delay.optional()
|
|
272
|
-
}),
|
|
273
|
-
z.strictObject({
|
|
274
|
-
...base,
|
|
275
|
-
action: z.literal("typeSecret"),
|
|
276
|
-
target,
|
|
277
|
-
secretRef: z.string().regex(SECRET_REF_PATTERN),
|
|
278
|
-
expectedOrigin: z.url({ protocol: /^https?$/ }).max(MAX_URL_LENGTH2).optional()
|
|
279
|
-
}),
|
|
280
|
-
z.strictObject({ ...base, action: z.literal("clear"), target }),
|
|
281
|
-
z.strictObject({
|
|
282
|
-
...base,
|
|
283
|
-
action: z.literal("select"),
|
|
284
|
-
target,
|
|
285
|
-
values: z.array(uiExpressionSchema2).min(1).max(MAX_SELECT_VALUES2)
|
|
286
|
-
}),
|
|
287
|
-
z.strictObject({ ...base, action: z.literal("check"), target, checked: z.boolean().optional() }),
|
|
288
|
-
z.strictObject({
|
|
289
|
-
...base,
|
|
290
|
-
action: z.literal("pressKey"),
|
|
291
|
-
keys: z.array(z.string().min(1).max(32)).min(1).max(MAX_KEYS2),
|
|
292
|
-
target: target.optional()
|
|
293
|
-
}),
|
|
294
|
-
z.strictObject({
|
|
295
|
-
...base,
|
|
296
|
-
action: z.literal("scroll"),
|
|
297
|
-
target: target.optional(),
|
|
298
|
-
dx: z.int().min(-1e4).max(1e4).optional(),
|
|
299
|
-
dy: z.int().min(-1e4).max(1e4).optional(),
|
|
300
|
-
to: z.enum(["top", "bottom"]).optional()
|
|
301
|
-
}),
|
|
302
|
-
z.strictObject({
|
|
303
|
-
...base,
|
|
304
|
-
action: z.literal("waitFor"),
|
|
305
|
-
target: target.optional(),
|
|
306
|
-
text: uiExpressionSchema2.optional(),
|
|
307
|
-
urlContains: uiExpressionSchema2.optional(),
|
|
308
|
-
milliseconds: z.int().min(1).max(MAX_STEP_TIMEOUT_MS2).optional(),
|
|
309
|
-
state: z.enum(["visible", "hidden", "attached", "detached"]).optional()
|
|
310
|
-
}),
|
|
311
|
-
z.strictObject({ ...base, action: z.literal("extract"), fields }),
|
|
312
|
-
z.strictObject({
|
|
313
|
-
...base,
|
|
314
|
-
action: z.literal("extractList"),
|
|
315
|
-
item: target,
|
|
316
|
-
fields,
|
|
317
|
-
maxItems: z.int().min(1).max(MAX_LIST_ITEMS2).optional(),
|
|
318
|
-
next: target.optional(),
|
|
319
|
-
maxPages: z.int().min(1).max(MAX_LIST_PAGES2).optional()
|
|
320
|
-
}),
|
|
321
|
-
z.strictObject({ ...base, action: z.literal("getText"), target }),
|
|
322
|
-
z.strictObject({ ...base, action: z.literal("getValue"), target }),
|
|
323
|
-
z.strictObject({
|
|
324
|
-
...base,
|
|
325
|
-
action: z.literal("getAttribute"),
|
|
326
|
-
target,
|
|
327
|
-
attribute: z.string().regex(ATTRIBUTE_PATTERN)
|
|
328
|
-
}),
|
|
329
|
-
z.strictObject({ ...base, action: z.literal("elementExists"), target }),
|
|
330
|
-
z.strictObject({ ...base, action: z.literal("getPageText") }),
|
|
331
|
-
z.strictObject({ ...base, action: z.literal("getPageHtml") }),
|
|
332
|
-
z.strictObject({
|
|
333
|
-
...base,
|
|
334
|
-
action: z.literal("screenshot"),
|
|
335
|
-
target: target.optional(),
|
|
336
|
-
fullPage: z.boolean().optional()
|
|
337
|
-
}),
|
|
338
|
-
z.strictObject({
|
|
339
|
-
...base,
|
|
340
|
-
action: z.literal("login"),
|
|
341
|
-
username: target.optional(),
|
|
342
|
-
password: target.optional(),
|
|
343
|
-
submit: target.optional(),
|
|
344
|
-
success: target.optional()
|
|
345
|
-
}),
|
|
346
|
-
z.strictObject({ ...base, action: z.literal("focusWindow"), app: label, title: label.optional() }),
|
|
347
|
-
z.strictObject({ ...base, action: z.literal("if"), ...condition, then: steps(), else: steps().optional() }),
|
|
348
|
-
z.strictObject({
|
|
349
|
-
...base,
|
|
350
|
-
action: z.literal("forEach"),
|
|
351
|
-
in: uiExpressionSchema2.optional(),
|
|
352
|
-
elements: target.optional(),
|
|
353
|
-
as: name,
|
|
354
|
-
index: name.optional(),
|
|
355
|
-
max: z.int().min(1).max(MAX_LOOP_ITERATIONS2).optional(),
|
|
356
|
-
steps: steps()
|
|
357
|
-
}),
|
|
358
|
-
z.strictObject({
|
|
359
|
-
...base,
|
|
360
|
-
action: z.literal("while"),
|
|
361
|
-
...condition,
|
|
362
|
-
maxIterations: z.int().min(1).max(MAX_LOOP_ITERATIONS2),
|
|
363
|
-
steps: steps()
|
|
364
|
-
}),
|
|
365
|
-
z.strictObject({
|
|
366
|
-
...base,
|
|
367
|
-
action: z.literal("retryScope"),
|
|
368
|
-
attempts: z.int().min(1).max(MAX_RETRY_ATTEMPTS2),
|
|
369
|
-
delayMs: delay.optional(),
|
|
370
|
-
steps: steps()
|
|
371
|
-
}),
|
|
372
|
-
z.strictObject({ ...base, action: z.literal("set"), name, value: uiExpressionSchema2 }),
|
|
373
|
-
z.strictObject({
|
|
374
|
-
...base,
|
|
375
|
-
action: z.literal("log"),
|
|
376
|
-
level: z.enum(["debug", "info", "warn", "error"]).optional(),
|
|
377
|
-
message: uiExpressionSchema2
|
|
378
|
-
}),
|
|
379
|
-
z.strictObject({
|
|
380
|
-
...base,
|
|
381
|
-
action: z.literal("call"),
|
|
382
|
-
sequenceId: z.string().min(1).max(MAX_NAME_LENGTH2),
|
|
383
|
-
version: z.int().min(1),
|
|
384
|
-
args: z.record(name, uiExpressionSchema2).optional()
|
|
385
|
-
})
|
|
386
|
-
])).register(uiScriptRegistry2, { id: "UiStep" });
|
|
387
|
-
var description = z.string().min(1).max(MAX_INTENT_LENGTH2).optional();
|
|
388
|
-
var uiScriptSchema2 = z.strictObject({
|
|
389
|
-
scriptVersion: z.literal(UI_SCRIPT_VERSION2),
|
|
390
|
-
name: label.optional(),
|
|
391
|
-
application: z.strictObject({ name: label.optional(), urlPattern: z.string().min(1).max(MAX_URL_LENGTH2).optional() }).optional(),
|
|
392
|
-
settings: z.strictObject({
|
|
393
|
-
firstWaitMs: ms.optional(),
|
|
394
|
-
waitMs: ms.optional(),
|
|
395
|
-
screenshots: z.enum(["never", "onFailure", "everyStep"]).optional(),
|
|
396
|
-
inputMethod: z.enum(["auto", "direct", "hardware"]).optional()
|
|
397
|
-
}).optional(),
|
|
398
|
-
inputs: z.array(z.strictObject({
|
|
399
|
-
name,
|
|
400
|
-
type: valueType.optional(),
|
|
401
|
-
required: z.boolean().optional(),
|
|
402
|
-
default: uiExpressionSchema2.optional(),
|
|
403
|
-
description
|
|
404
|
-
})).max(MAX_SCRIPT_INPUTS2).optional(),
|
|
405
|
-
outputs: z.array(z.strictObject({ name, type: valueType.optional(), value: uiExpressionSchema2, description })).max(MAX_SCRIPT_OUTPUTS2).optional(),
|
|
406
|
-
variables: z.array(z.strictObject({ name, type: valueType.optional(), initial: uiExpressionSchema2.optional() })).max(MAX_SCRIPT_VARIABLES2).optional(),
|
|
407
|
-
elements: z.record(z.string().regex(ELEMENT_KEY_PATTERN2), z.strictObject({
|
|
408
|
-
elementId: z.string().min(1).max(MAX_NAME_LENGTH2),
|
|
409
|
-
version: z.int().min(1),
|
|
410
|
-
name: label.optional(),
|
|
411
|
-
target: uiTargetSchema2.optional()
|
|
412
|
-
})).optional(),
|
|
413
|
-
steps: steps(),
|
|
414
|
-
cleanup: steps().optional()
|
|
415
|
-
});
|
|
416
|
-
// src/script/canonical.ts
|
|
417
|
-
function canonicalJson2(value) {
|
|
418
|
-
return JSON.stringify(canonicalValue(value)) ?? "null";
|
|
419
|
-
}
|
|
420
|
-
function canonicalValue(value) {
|
|
421
|
-
if (Array.isArray(value))
|
|
422
|
-
return value.map(canonicalValue);
|
|
423
|
-
if (value !== null && typeof value === "object") {
|
|
424
|
-
const out = {};
|
|
425
|
-
for (const key of Object.keys(value).sort()) {
|
|
426
|
-
const item = Reflect.get(value, key);
|
|
427
|
-
if (item !== undefined)
|
|
428
|
-
out[key] = canonicalValue(item);
|
|
429
|
-
}
|
|
430
|
-
return out;
|
|
431
|
-
}
|
|
432
|
-
return value;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
// src/script/walk.ts
|
|
436
|
-
function childBlocks2(step) {
|
|
437
|
-
switch (step.action) {
|
|
438
|
-
case "if":
|
|
439
|
-
return step.else ? [
|
|
440
|
-
["then", step.then],
|
|
441
|
-
["else", step.else]
|
|
442
|
-
] : [["then", step.then]];
|
|
443
|
-
case "forEach":
|
|
444
|
-
case "while":
|
|
445
|
-
case "retryScope":
|
|
446
|
-
return [["steps", step.steps]];
|
|
447
|
-
default:
|
|
448
|
-
return [];
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
function* walkList(steps, prefix, depth) {
|
|
452
|
-
for (const [index, step] of steps.entries()) {
|
|
453
|
-
const path = prefix ? `${prefix}.${index}` : String(index);
|
|
454
|
-
yield { step, path, depth };
|
|
455
|
-
for (const [block, children] of childBlocks2(step)) {
|
|
456
|
-
yield* walkList(children, `${path}.${block}`, depth + 1);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
function* walkSteps2(script) {
|
|
461
|
-
yield* walkList(script.steps, "", 0);
|
|
462
|
-
if (script.cleanup)
|
|
463
|
-
yield* walkList(script.cleanup, "cleanup", 0);
|
|
464
|
-
}
|
|
465
|
-
function countSteps2(script) {
|
|
466
|
-
return Array.from(walkSteps2(script)).length;
|
|
467
|
-
}
|
|
468
|
-
function stepAtPath2(script, path) {
|
|
469
|
-
for (const walked of walkSteps2(script))
|
|
470
|
-
if (walked.path === path)
|
|
471
|
-
return walked.step;
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
function stepTargets2(step) {
|
|
475
|
-
const found = [];
|
|
476
|
-
const add = (field, ref) => {
|
|
477
|
-
if (ref)
|
|
478
|
-
found.push([field, ref]);
|
|
479
|
-
};
|
|
480
|
-
if ("target" in step)
|
|
481
|
-
add("target", step.target);
|
|
482
|
-
switch (step.action) {
|
|
483
|
-
case "extract":
|
|
484
|
-
step.fields.forEach((field, index) => add(`fields.${index}.target`, field.target));
|
|
485
|
-
break;
|
|
486
|
-
case "extractList":
|
|
487
|
-
add("item", step.item);
|
|
488
|
-
add("next", step.next);
|
|
489
|
-
step.fields.forEach((field, index) => add(`fields.${index}.target`, field.target));
|
|
490
|
-
break;
|
|
491
|
-
case "login":
|
|
492
|
-
add("username", step.username);
|
|
493
|
-
add("password", step.password);
|
|
494
|
-
add("submit", step.submit);
|
|
495
|
-
add("success", step.success);
|
|
496
|
-
break;
|
|
497
|
-
case "if":
|
|
498
|
-
case "while":
|
|
499
|
-
add("elementExists", step.elementExists);
|
|
500
|
-
break;
|
|
501
|
-
case "forEach":
|
|
502
|
-
add("elements", step.elements);
|
|
503
|
-
break;
|
|
504
|
-
default:
|
|
505
|
-
break;
|
|
506
|
-
}
|
|
507
|
-
if (step.verify && "target" in step.verify)
|
|
508
|
-
add("verify.target", step.verify.target);
|
|
509
|
-
return found;
|
|
510
|
-
}
|
|
511
|
-
function stepExpressions2(step) {
|
|
512
|
-
const found = [];
|
|
513
|
-
const add = (field, value) => {
|
|
514
|
-
if (value !== undefined)
|
|
515
|
-
found.push([field, value]);
|
|
516
|
-
};
|
|
517
|
-
switch (step.action) {
|
|
518
|
-
case "navigate":
|
|
519
|
-
add("url", step.url);
|
|
520
|
-
break;
|
|
521
|
-
case "type":
|
|
522
|
-
add("text", step.text);
|
|
523
|
-
break;
|
|
524
|
-
case "select":
|
|
525
|
-
step.values.forEach((value, index) => add(`values.${index}`, value));
|
|
526
|
-
break;
|
|
527
|
-
case "waitFor":
|
|
528
|
-
add("text", step.text);
|
|
529
|
-
add("urlContains", step.urlContains);
|
|
530
|
-
break;
|
|
531
|
-
case "if":
|
|
532
|
-
case "while":
|
|
533
|
-
add("condition", step.condition);
|
|
534
|
-
break;
|
|
535
|
-
case "forEach":
|
|
536
|
-
add("in", step.in);
|
|
537
|
-
break;
|
|
538
|
-
case "set":
|
|
539
|
-
add("value", step.value);
|
|
540
|
-
break;
|
|
541
|
-
case "log":
|
|
542
|
-
add("message", step.message);
|
|
543
|
-
break;
|
|
544
|
-
case "call":
|
|
545
|
-
for (const [arg, value] of Object.entries(step.args ?? {}))
|
|
546
|
-
add(`args.${arg}`, value);
|
|
547
|
-
break;
|
|
548
|
-
default:
|
|
549
|
-
break;
|
|
550
|
-
}
|
|
551
|
-
const verify = step.verify;
|
|
552
|
-
if (verify?.kind === "urlContains" || verify?.kind === "valueEquals")
|
|
553
|
-
add("verify.value", verify.value);
|
|
554
|
-
if (verify?.kind === "textPresent")
|
|
555
|
-
add("verify.text", verify.text);
|
|
556
|
-
return found;
|
|
557
|
-
}
|
|
558
|
-
function visitExpression2(expression, visit, depth = 1) {
|
|
559
|
-
visit(expression, depth);
|
|
560
|
-
if (expression === null || typeof expression !== "object")
|
|
561
|
-
return;
|
|
562
|
-
if ("list" in expression)
|
|
563
|
-
for (const item of expression.list)
|
|
564
|
-
visitExpression2(item, visit, depth + 1);
|
|
565
|
-
else if ("object" in expression)
|
|
566
|
-
for (const item of Object.values(expression.object))
|
|
567
|
-
visitExpression2(item, visit, depth + 1);
|
|
568
|
-
else if ("op" in expression)
|
|
569
|
-
for (const arg of expression.args)
|
|
570
|
-
visitExpression2(arg, visit, depth + 1);
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
// src/script/fingerprint.ts
|
|
574
|
-
var RECORDING_ACTION_OF2 = {
|
|
575
|
-
click: "click",
|
|
576
|
-
doubleClick: "click",
|
|
577
|
-
type: "type",
|
|
578
|
-
typeSecret: "secret_fill",
|
|
579
|
-
pressKey: "key",
|
|
580
|
-
scroll: "scroll",
|
|
581
|
-
navigate: "navigate",
|
|
582
|
-
focusWindow: "focus_window"
|
|
583
|
-
};
|
|
584
|
-
function soleRoleMethod(ref) {
|
|
585
|
-
if (!ref || "element" in ref || ref.frame || ref.methods.length !== 1)
|
|
586
|
-
return;
|
|
587
|
-
const [method] = ref.methods;
|
|
588
|
-
return method?.kind === "role" && method.enabled !== false ? method : undefined;
|
|
589
|
-
}
|
|
590
|
-
function stepTarget(step) {
|
|
591
|
-
return "target" in step ? step.target : undefined;
|
|
592
|
-
}
|
|
593
|
-
function uiStepFingerprint2(step) {
|
|
594
|
-
const target = stepTarget(step);
|
|
595
|
-
const recordingAction = RECORDING_ACTION_OF2[step.action];
|
|
596
|
-
const url = step.action === "navigate" ? step.url : undefined;
|
|
597
|
-
const app = step.action === "focusWindow" ? step.app : undefined;
|
|
598
|
-
const title = step.action === "focusWindow" ? step.title : undefined;
|
|
599
|
-
const role = soleRoleMethod(target);
|
|
600
|
-
const targets = stepTargets2(step);
|
|
601
|
-
const onlyOwnTarget = targets.every(([field]) => field === "target");
|
|
602
|
-
if (recordingAction && onlyOwnTarget && (target === undefined || role) && (url === undefined || typeof url === "string")) {
|
|
603
|
-
return targetFingerprint2({
|
|
604
|
-
action: recordingAction,
|
|
605
|
-
...role ? {
|
|
606
|
-
target: {
|
|
607
|
-
role: role.role,
|
|
608
|
-
name: role.name,
|
|
609
|
-
nth: role.nth ?? 0,
|
|
610
|
-
...role.app === undefined ? {} : { app: role.app },
|
|
611
|
-
...role.window === undefined ? {} : { window: role.window }
|
|
612
|
-
}
|
|
613
|
-
} : {},
|
|
614
|
-
...url === undefined ? {} : { url },
|
|
615
|
-
...app === undefined ? {} : { app },
|
|
616
|
-
...title === undefined ? {} : { title }
|
|
617
|
-
});
|
|
618
|
-
}
|
|
619
|
-
return sha256Hex2(canonicalJson2(["ui-script/1", step.action, targets, url ?? null, app ?? null, title ?? null]));
|
|
620
|
-
}
|
|
621
|
-
function withFingerprint2(step) {
|
|
622
|
-
return { ...step, fingerprint: uiStepFingerprint2(step) };
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
// src/script/parse.ts
|
|
626
|
-
class UiScriptError2 extends Error {
|
|
627
|
-
code;
|
|
628
|
-
path;
|
|
629
|
-
constructor(code, message, path) {
|
|
630
|
-
super(message);
|
|
631
|
-
this.code = code;
|
|
632
|
-
this.path = path;
|
|
633
|
-
this.name = "UiScriptError";
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
var UI_EXPRESSION_ARITY2 = {
|
|
637
|
-
eq: [2, 2],
|
|
638
|
-
ne: [2, 2],
|
|
639
|
-
lt: [2, 2],
|
|
640
|
-
le: [2, 2],
|
|
641
|
-
gt: [2, 2],
|
|
642
|
-
ge: [2, 2],
|
|
643
|
-
and: [2, 16],
|
|
644
|
-
or: [2, 16],
|
|
645
|
-
not: [1, 1],
|
|
646
|
-
add: [2, 16],
|
|
647
|
-
sub: [2, 2],
|
|
648
|
-
mul: [2, 16],
|
|
649
|
-
div: [2, 2],
|
|
650
|
-
mod: [2, 2],
|
|
651
|
-
neg: [1, 1],
|
|
652
|
-
abs: [1, 1],
|
|
653
|
-
round: [1, 2],
|
|
654
|
-
min: [1, 16],
|
|
655
|
-
max: [1, 16],
|
|
656
|
-
concat: [1, 16],
|
|
657
|
-
contains: [2, 2],
|
|
658
|
-
startsWith: [2, 2],
|
|
659
|
-
endsWith: [2, 2],
|
|
660
|
-
lower: [1, 1],
|
|
661
|
-
upper: [1, 1],
|
|
662
|
-
trim: [1, 1],
|
|
663
|
-
replace: [3, 3],
|
|
664
|
-
split: [2, 2],
|
|
665
|
-
join: [1, 2],
|
|
666
|
-
length: [1, 1],
|
|
667
|
-
toNumber: [1, 1],
|
|
668
|
-
toText: [1, 1],
|
|
669
|
-
toBoolean: [1, 1],
|
|
670
|
-
isEmpty: [1, 1],
|
|
671
|
-
coalesce: [1, 16],
|
|
672
|
-
if: [3, 3],
|
|
673
|
-
get: [2, 2],
|
|
674
|
-
now: [0, 0],
|
|
675
|
-
formatDate: [1, 2],
|
|
676
|
-
addDays: [2, 2]
|
|
677
|
-
};
|
|
678
|
-
function parseUiScript2(value, options = {}) {
|
|
679
|
-
const raw = readJson(value);
|
|
680
|
-
const parsed = uiScriptSchema2.safeParse(raw);
|
|
681
|
-
if (!parsed.success) {
|
|
682
|
-
const issue = parsed.error.issues[0];
|
|
683
|
-
const where = issue?.path.map(String).join(".") ?? "";
|
|
684
|
-
throw new UiScriptError2("INVALID_SCRIPT", `The UI script is not valid at ${where || "the top"}: ${issue?.message ?? "unknown problem"}`, where || undefined);
|
|
685
|
-
}
|
|
686
|
-
checkScript(parsed.data, options);
|
|
687
|
-
return parsed.data;
|
|
688
|
-
}
|
|
689
|
-
function safeParseUiScript2(value, options = {}) {
|
|
690
|
-
try {
|
|
691
|
-
return { success: true, script: parseUiScript2(value, options) };
|
|
692
|
-
} catch (error) {
|
|
693
|
-
if (error instanceof UiScriptError2)
|
|
694
|
-
return { success: false, error };
|
|
695
|
-
throw error;
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
function readJson(value) {
|
|
699
|
-
let raw = value;
|
|
700
|
-
if (typeof value === "string") {
|
|
701
|
-
if (new TextEncoder().encode(value).length > MAX_SCRIPT_BYTES2)
|
|
702
|
-
tooLarge();
|
|
703
|
-
try {
|
|
704
|
-
raw = JSON.parse(value);
|
|
705
|
-
} catch {
|
|
706
|
-
throw new UiScriptError2("INVALID_SCRIPT", "The UI script is not valid JSON");
|
|
707
|
-
}
|
|
708
|
-
} else if (jsonByteLength2(value) > MAX_SCRIPT_BYTES2) {
|
|
709
|
-
tooLarge();
|
|
710
|
-
}
|
|
711
|
-
if (jsonDepth(raw) > MAX_JSON_DEPTH) {
|
|
712
|
-
throw new UiScriptError2("INVALID_SCRIPT", `The UI script is nested deeper than ${MAX_JSON_DEPTH} levels`);
|
|
713
|
-
}
|
|
714
|
-
return raw;
|
|
715
|
-
}
|
|
716
|
-
var MAX_JSON_DEPTH = 256;
|
|
717
|
-
function jsonDepth(value) {
|
|
718
|
-
let deepest = 0;
|
|
719
|
-
const stack = [[value, 1]];
|
|
720
|
-
while (stack.length > 0) {
|
|
721
|
-
const [item, depth] = stack.pop() ?? [null, 0];
|
|
722
|
-
if (item === null || typeof item !== "object")
|
|
723
|
-
continue;
|
|
724
|
-
deepest = Math.max(deepest, depth);
|
|
725
|
-
if (deepest > MAX_JSON_DEPTH)
|
|
726
|
-
return deepest;
|
|
727
|
-
for (const child of Object.values(item))
|
|
728
|
-
stack.push([child, depth + 1]);
|
|
729
|
-
}
|
|
730
|
-
return deepest;
|
|
731
|
-
}
|
|
732
|
-
function tooLarge() {
|
|
733
|
-
throw new UiScriptError2("SCRIPT_TOO_LARGE", `The UI script is larger than ${MAX_SCRIPT_BYTES2} bytes`);
|
|
734
|
-
}
|
|
735
|
-
function checkScript(script, options) {
|
|
736
|
-
const elements = script.elements ?? {};
|
|
737
|
-
if (Object.keys(elements).length > MAX_SCRIPT_ELEMENTS2) {
|
|
738
|
-
throw new UiScriptError2("INVALID_SCRIPT", `A UI script pins at most ${MAX_SCRIPT_ELEMENTS2} elements`, "elements");
|
|
739
|
-
}
|
|
740
|
-
const inputs = uniqueNames(script.inputs, "inputs");
|
|
741
|
-
uniqueNames(script.outputs, "outputs");
|
|
742
|
-
uniqueNames(script.variables, "variables");
|
|
743
|
-
const checkExpression = (expression, where) => {
|
|
744
|
-
visitExpression2(expression, (node, depth) => {
|
|
745
|
-
if (depth > MAX_EXPRESSION_DEPTH2) {
|
|
746
|
-
throw new UiScriptError2("INVALID_SCRIPT", `An expression is nested deeper than ${MAX_EXPRESSION_DEPTH2}`, where);
|
|
747
|
-
}
|
|
748
|
-
if (typeof node === "string" && containsCredential(node)) {
|
|
749
|
-
throw new UiScriptError2("CREDENTIAL_IN_SCRIPT", "The UI script holds a credential in a value", where);
|
|
750
|
-
}
|
|
751
|
-
if (node === null || typeof node !== "object")
|
|
752
|
-
return;
|
|
753
|
-
if ("input" in node && !inputs.has(node.input)) {
|
|
754
|
-
throw new UiScriptError2("UNKNOWN_INPUT", `The input "${node.input}" is not declared`, where);
|
|
755
|
-
}
|
|
756
|
-
if ("op" in node) {
|
|
757
|
-
const [fewest, most] = UI_EXPRESSION_ARITY2[node.op];
|
|
758
|
-
if (node.args.length < fewest || node.args.length > most) {
|
|
759
|
-
throw new UiScriptError2("INVALID_SCRIPT", `The operator "${node.op}" takes ${fewest === most ? fewest : `${fewest} to ${most}`} arguments`, where);
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
});
|
|
763
|
-
};
|
|
764
|
-
script.inputs?.forEach((input, index) => {
|
|
765
|
-
if (input.default !== undefined)
|
|
766
|
-
checkExpression(input.default, `inputs.${index}.default`);
|
|
767
|
-
});
|
|
768
|
-
script.outputs?.forEach((output, index) => checkExpression(output.value, `outputs.${index}.value`));
|
|
769
|
-
script.variables?.forEach((variable, index) => {
|
|
770
|
-
if (variable.initial !== undefined)
|
|
771
|
-
checkExpression(variable.initial, `variables.${index}.initial`);
|
|
772
|
-
});
|
|
773
|
-
checkScriptText(script);
|
|
774
|
-
if (options.resolved) {
|
|
775
|
-
for (const [key, element] of Object.entries(elements)) {
|
|
776
|
-
if (!element.target) {
|
|
777
|
-
throw new UiScriptError2("UNRESOLVED", `The element "${key}" has no target`, `elements.${key}`);
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
const ids = new Set;
|
|
782
|
-
let count = 0;
|
|
783
|
-
for (const { step, path, depth } of walkSteps2(script)) {
|
|
784
|
-
count += 1;
|
|
785
|
-
if (count > MAX_SCRIPT_STEPS2) {
|
|
786
|
-
throw new UiScriptError2("TOO_MANY_STEPS", `A UI script has at most ${MAX_SCRIPT_STEPS2} steps`, path);
|
|
787
|
-
}
|
|
788
|
-
if (depth > MAX_FLOW_DEPTH2) {
|
|
789
|
-
throw new UiScriptError2("INVALID_SCRIPT", `Flow blocks nest at most ${MAX_FLOW_DEPTH2} deep`, path);
|
|
790
|
-
}
|
|
791
|
-
if (ids.has(step.id)) {
|
|
792
|
-
throw new UiScriptError2("DUPLICATE_STEP_ID", `Step id ${step.id} is used twice`, path);
|
|
793
|
-
}
|
|
794
|
-
ids.add(step.id);
|
|
795
|
-
if (options.resolved && step.action === "call") {
|
|
796
|
-
throw new UiScriptError2("UNRESOLVED", `Step ${step.id} calls a shared sequence that was not inlined`, path);
|
|
797
|
-
}
|
|
798
|
-
checkStepShape(step, path);
|
|
799
|
-
for (const [field, ref] of stepTargets2(step)) {
|
|
800
|
-
if ("element" in ref && !Object.hasOwn(elements, ref.element)) {
|
|
801
|
-
throw new UiScriptError2("UNKNOWN_ELEMENT", `Step ${step.id} uses the element "${ref.element}", which the script does not pin`, `${path}.${field}`);
|
|
802
|
-
}
|
|
803
|
-
if (!("element" in ref))
|
|
804
|
-
refuseCredentialText(targetText(ref), `${path}.${field}`);
|
|
805
|
-
}
|
|
806
|
-
for (const [field, expression] of stepExpressions2(step))
|
|
807
|
-
checkExpression(expression, `${path}.${field}`);
|
|
808
|
-
checkStepText(step, path);
|
|
809
|
-
if (step.fingerprint !== undefined && step.fingerprint !== uiStepFingerprint2(step)) {
|
|
810
|
-
throw new UiScriptError2("FINGERPRINT_MISMATCH", `Step ${step.id} was changed after it was recorded`, path);
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
function uniqueNames(list, where) {
|
|
815
|
-
const names = new Set;
|
|
816
|
-
list?.forEach(({ name }, index) => {
|
|
817
|
-
if (names.has(name)) {
|
|
818
|
-
throw new UiScriptError2("INVALID_SCRIPT", `The name "${name}" is declared twice`, `${where}.${index}`);
|
|
819
|
-
}
|
|
820
|
-
names.add(name);
|
|
821
|
-
});
|
|
822
|
-
return names;
|
|
823
|
-
}
|
|
824
|
-
function exactlyOne(step, path, fields) {
|
|
825
|
-
const given = Object.entries(fields).filter(([, value]) => value !== undefined);
|
|
826
|
-
if (given.length !== 1) {
|
|
827
|
-
throw new UiScriptError2("INVALID_SCRIPT", `Step ${step.id} (${step.action}) needs exactly one of ${Object.keys(fields).join(", ")}`, path);
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
function checkStepShape(step, path) {
|
|
831
|
-
const refuse = (message) => {
|
|
832
|
-
throw new UiScriptError2("INVALID_SCRIPT", `Step ${step.id} (${step.action}): ${message}`, path);
|
|
833
|
-
};
|
|
834
|
-
switch (step.action) {
|
|
835
|
-
case "navigate":
|
|
836
|
-
if (typeof step.url === "string" && !isHttpUrl(step.url))
|
|
837
|
-
refuse("the URL must be an absolute http(s) URL");
|
|
838
|
-
break;
|
|
839
|
-
case "waitFor":
|
|
840
|
-
exactlyOne(step, path, {
|
|
841
|
-
target: step.target,
|
|
842
|
-
text: step.text,
|
|
843
|
-
urlContains: step.urlContains,
|
|
844
|
-
milliseconds: step.milliseconds
|
|
845
|
-
});
|
|
846
|
-
if (step.state !== undefined && step.target === undefined)
|
|
847
|
-
refuse("state needs a target");
|
|
848
|
-
break;
|
|
849
|
-
case "if":
|
|
850
|
-
case "while":
|
|
851
|
-
exactlyOne(step, path, { condition: step.condition, elementExists: step.elementExists });
|
|
852
|
-
break;
|
|
853
|
-
case "forEach":
|
|
854
|
-
exactlyOne(step, path, { in: step.in, elements: step.elements });
|
|
855
|
-
if (step.index !== undefined && step.index === step.as)
|
|
856
|
-
refuse("the item and the index need different names");
|
|
857
|
-
break;
|
|
858
|
-
case "type":
|
|
859
|
-
if (step.masked === true && step.text !== undefined)
|
|
860
|
-
refuse("a masked step carries no text");
|
|
861
|
-
break;
|
|
862
|
-
case "scroll":
|
|
863
|
-
if (step.to !== undefined && (step.target !== undefined || step.dx !== undefined || step.dy !== undefined)) {
|
|
864
|
-
refuse("to scrolls the page and cannot be combined with a target or an offset");
|
|
865
|
-
}
|
|
866
|
-
break;
|
|
867
|
-
default:
|
|
868
|
-
break;
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
function isHttpUrl(text) {
|
|
872
|
-
if (text.length > MAX_URL_LENGTH2)
|
|
873
|
-
return false;
|
|
874
|
-
try {
|
|
875
|
-
const url = new URL(text);
|
|
876
|
-
return url.protocol === "http:" || url.protocol === "https:";
|
|
877
|
-
} catch {
|
|
878
|
-
return false;
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
function targetText(target) {
|
|
882
|
-
const texts = [...target.frame ?? []];
|
|
883
|
-
for (const method of target.methods) {
|
|
884
|
-
switch (method.kind) {
|
|
885
|
-
case "role":
|
|
886
|
-
texts.push(method.role, method.name, method.app, method.window);
|
|
887
|
-
break;
|
|
888
|
-
case "css":
|
|
889
|
-
texts.push(method.selector);
|
|
890
|
-
break;
|
|
891
|
-
case "testId":
|
|
892
|
-
texts.push(method.value, method.attribute);
|
|
893
|
-
break;
|
|
894
|
-
case "xpath":
|
|
895
|
-
texts.push(method.xpath);
|
|
896
|
-
break;
|
|
897
|
-
case "fuzzy":
|
|
898
|
-
texts.push(method.role, method.name);
|
|
899
|
-
break;
|
|
900
|
-
case "anchor":
|
|
901
|
-
texts.push(method.role, method.anchor.kind === "text" ? method.anchor.text : method.anchor.name);
|
|
902
|
-
if (method.anchor.kind === "role")
|
|
903
|
-
texts.push(method.anchor.role);
|
|
904
|
-
break;
|
|
905
|
-
default:
|
|
906
|
-
texts.push(method.text);
|
|
907
|
-
break;
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
return texts.filter((text) => text !== undefined);
|
|
911
|
-
}
|
|
912
|
-
function refuseCredentialText(texts, where) {
|
|
913
|
-
if (texts.some((text) => containsCredential(text))) {
|
|
914
|
-
throw new UiScriptError2("CREDENTIAL_IN_SCRIPT", "The UI script holds a credential in a stored text", where);
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
function checkScriptText(script) {
|
|
918
|
-
refuseCredentialText([script.name, script.application?.name, script.application?.urlPattern].filter((text) => text !== undefined), "name");
|
|
919
|
-
for (const [list, where] of [
|
|
920
|
-
[script.inputs, "inputs"],
|
|
921
|
-
[script.outputs, "outputs"]
|
|
922
|
-
]) {
|
|
923
|
-
list?.forEach((item, index) => {
|
|
924
|
-
if (item.description !== undefined)
|
|
925
|
-
refuseCredentialText([item.description], `${where}.${index}.description`);
|
|
926
|
-
});
|
|
927
|
-
}
|
|
928
|
-
for (const [key, element] of Object.entries(script.elements ?? {})) {
|
|
929
|
-
refuseCredentialText([element.name, ...element.target ? targetText(element.target) : []].filter((text) => text !== undefined), `elements.${key}`);
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
function checkStepText(step, path) {
|
|
933
|
-
if (step.action === "focusWindow") {
|
|
934
|
-
refuseCredentialText(step.title === undefined ? [step.app] : [step.app, step.title], path);
|
|
935
|
-
}
|
|
936
|
-
for (const [field, text] of [
|
|
937
|
-
["intent", step.intent],
|
|
938
|
-
["note", step.note]
|
|
939
|
-
]) {
|
|
940
|
-
if (text !== undefined && containsCredential(text)) {
|
|
941
|
-
throw new UiScriptError2("CREDENTIAL_IN_SCRIPT", `Step ${step.id} holds a credential in its ${field}`, path);
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
if (step.action === "navigate" && typeof step.url === "string") {
|
|
945
|
-
let userInfo = false;
|
|
946
|
-
try {
|
|
947
|
-
const url = new URL(step.url);
|
|
948
|
-
userInfo = Boolean(url.username || url.password);
|
|
949
|
-
} catch {
|
|
950
|
-
userInfo = false;
|
|
951
|
-
}
|
|
952
|
-
if (userInfo || containsCredentialInUrl(step.url)) {
|
|
953
|
-
throw new UiScriptError2("CREDENTIAL_IN_SCRIPT", `Step ${step.id} holds a credential in its URL`, `${path}.url`);
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
}
|
|
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-3jymbm5t.js";
|
|
957
26
|
// src/script/hash.ts
|
|
958
27
|
var UI_SCRIPT_SCHEMA_HASH2 = "e6860649ad1cba906fb704ce4b62b3ea4380203e6628c809571602f4d0947884";
|
|
959
28
|
function schemaHashOf2(jsonSchema) {
|
|
960
29
|
return sha256Hex2(canonicalJson2(jsonSchema));
|
|
961
30
|
}
|
|
962
31
|
// src/script/json-schema.ts
|
|
963
|
-
import { z
|
|
32
|
+
import { z } from "zod";
|
|
964
33
|
var UI_SCRIPT_SCHEMA_TITLE2 = "FluidGrids UI script v1";
|
|
965
34
|
function uiScriptJsonSchema2() {
|
|
966
|
-
const generated =
|
|
35
|
+
const generated = z.toJSONSchema(uiScriptSchema2, {
|
|
967
36
|
target: "draft-2020-12",
|
|
968
37
|
io: "input",
|
|
969
38
|
unrepresentable: "throw",
|
|
@@ -972,60 +41,6 @@ function uiScriptJsonSchema2() {
|
|
|
972
41
|
const { $schema, ...rest } = generated;
|
|
973
42
|
return { $schema, title: UI_SCRIPT_SCHEMA_TITLE2, ...rest };
|
|
974
43
|
}
|
|
975
|
-
// src/script/capabilities.ts
|
|
976
|
-
var CAPABILITY_IDS2 = [
|
|
977
|
-
"script:1",
|
|
978
|
-
...UI_STEP_ACTIONS2.map((action) => `action:${action}`),
|
|
979
|
-
...UI_TARGET_METHOD_KINDS2.map((kind) => `target:${kind}`),
|
|
980
|
-
"target:frame",
|
|
981
|
-
"step:verify",
|
|
982
|
-
"step:retry",
|
|
983
|
-
"step:breakpoint",
|
|
984
|
-
"input:direct",
|
|
985
|
-
"input:hardware"
|
|
986
|
-
].sort();
|
|
987
|
-
var SCRIPT_CAPABILITY2 = "script:1";
|
|
988
|
-
function targetCapabilities(target, into) {
|
|
989
|
-
for (const method of target.methods)
|
|
990
|
-
if (method.enabled !== false)
|
|
991
|
-
into.add(`target:${method.kind}`);
|
|
992
|
-
if (target.frame)
|
|
993
|
-
into.add("target:frame");
|
|
994
|
-
}
|
|
995
|
-
function requiredCapabilities2(script) {
|
|
996
|
-
const required = new Set([SCRIPT_CAPABILITY2]);
|
|
997
|
-
const elements = script.elements ?? {};
|
|
998
|
-
const inputMethods = [script.settings?.inputMethod];
|
|
999
|
-
const skipped = [];
|
|
1000
|
-
for (const { step, path } of walkSteps2(script)) {
|
|
1001
|
-
if (step.disabled === true)
|
|
1002
|
-
skipped.push(`${path}.`);
|
|
1003
|
-
if (step.disabled === true || skipped.some((prefix) => path.startsWith(prefix)))
|
|
1004
|
-
continue;
|
|
1005
|
-
required.add(`action:${step.action}`);
|
|
1006
|
-
for (const [, ref] of stepTargets2(step)) {
|
|
1007
|
-
const target = "element" in ref ? elements[ref.element]?.target : ref;
|
|
1008
|
-
if (target)
|
|
1009
|
-
targetCapabilities(target, required);
|
|
1010
|
-
}
|
|
1011
|
-
if (step.verify)
|
|
1012
|
-
required.add("step:verify");
|
|
1013
|
-
if (step.retry)
|
|
1014
|
-
required.add("step:retry");
|
|
1015
|
-
if (step.breakpoint === true)
|
|
1016
|
-
required.add("step:breakpoint");
|
|
1017
|
-
inputMethods.push(step.inputMethod);
|
|
1018
|
-
}
|
|
1019
|
-
for (const method of inputMethods) {
|
|
1020
|
-
if (method === "direct" || method === "hardware")
|
|
1021
|
-
required.add(`input:${method}`);
|
|
1022
|
-
}
|
|
1023
|
-
return [...required].sort();
|
|
1024
|
-
}
|
|
1025
|
-
function missingCapabilities2(script, supported) {
|
|
1026
|
-
const have = new Set(supported);
|
|
1027
|
-
return requiredCapabilities2(script).filter((id) => !have.has(id));
|
|
1028
|
-
}
|
|
1029
44
|
// src/script/describe.ts
|
|
1030
45
|
var UI_SCRIPT_STEP_KEY_PREFIX2 = "fluidgrids.uiScript.step.";
|
|
1031
46
|
var UI_SCRIPT_STEP_MESSAGES2 = {
|
|
@@ -1413,6 +428,8 @@ function lower(script, options) {
|
|
|
1413
428
|
function lowerStep(step, context) {
|
|
1414
429
|
if (step.disabled || step.breakpoint || step.verify || step.retry || step.onError === "continue")
|
|
1415
430
|
stop();
|
|
431
|
+
if (step.timeoutMs !== undefined && step.timeoutMs > LEGACY_MAX_STEP_TIMEOUT_MS2)
|
|
432
|
+
stop();
|
|
1416
433
|
if (step.screenshot === "always" || step.inputMethod && step.inputMethod !== "auto")
|
|
1417
434
|
stop();
|
|
1418
435
|
const common = {
|
|
@@ -1983,4 +1000,4 @@ function toRecordedStep(step, fallbackIntent) {
|
|
|
1983
1000
|
return stop2();
|
|
1984
1001
|
}
|
|
1985
1002
|
}
|
|
1986
|
-
export {
|
|
1003
|
+
export { UI_SCRIPT_SCHEMA_HASH2, schemaHashOf2, UI_SCRIPT_SCHEMA_TITLE2, uiScriptJsonSchema2, UI_SCRIPT_STEP_KEY_PREFIX2, UI_SCRIPT_STEP_MESSAGES2, stepMessageKey2, describeTarget2, describeExpression2, describeStep2, BROWSER_STEP_ACTIONS2, fromBrowserActionSteps2, toBrowserActionSteps2, targetFromPlaywrightSelector2, fromRemoteBrowserSteps2, fromRecording2, toRecording2 };
|