@burdenoff/ui-engine 2026.1127.5 → 2026.1129.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -4
- package/dist/analyze/messages.d.ts +7 -0
- package/dist/analyze/rules/heal-consequential.d.ts +2 -0
- package/dist/analyze/rules/popup-handler-loop.d.ts +2 -0
- package/dist/analyze/types.d.ts +24 -1
- package/dist/analyze.js +1 -1
- package/dist/dom-runtime.iife.js +1 -1
- package/dist/dom-runtime.js +2 -2
- package/dist/drivers.js +9 -7
- package/dist/heal/answer.d.ts +26 -0
- package/dist/heal/consequence.d.ts +74 -0
- package/dist/heal/index.d.ts +19 -0
- package/dist/heal/modes.d.ts +25 -0
- package/dist/heal/popup-limits.d.ts +11 -0
- package/dist/heal/popup.d.ts +48 -0
- package/dist/heal/question.d.ts +41 -0
- package/dist/heal/target-from-node.d.ts +9 -0
- package/dist/heal/types.d.ts +134 -0
- package/dist/heal/verify-rules.d.ts +19 -0
- package/dist/heal/verify.d.ts +52 -0
- package/dist/heal.d.ts +2 -0
- package/dist/heal.js +106 -0
- package/dist/index-20bbwwc9.js +37 -0
- package/dist/{index-xner4tgb.js → index-5cffktzd.js} +481 -3
- package/dist/index-6h7ah1dw.js +328 -0
- package/dist/{index-8w0f6rsz.js → index-6kva2gvd.js} +3 -3
- package/dist/{index-ct2xctrq.js → index-70vm0qz8.js} +2 -2
- package/dist/{index-21hvbvx1.js → index-8w31tpfq.js} +21 -8
- package/dist/{index-r2a9rftv.js → index-eff47v1g.js} +424 -17
- package/dist/{index-9s5nphx0.js → index-hw5npwsv.js} +1 -37
- package/dist/{index-ycs2bz1a.js → index-mhv6a02p.js} +11 -166
- package/dist/index-p5823rpv.js +0 -0
- package/dist/{index-5k26keah.js → index-qg9yfr7r.js} +16 -67
- package/dist/{index-c88tvyj1.js → index-qmv3ar39.js} +1 -1
- package/dist/index-t55wvhvh.js +229 -0
- package/dist/{index-77pcz6n3.js → index-vnv9tp11.js} +4 -2
- package/dist/index-w9jc25y9.js +306 -0
- package/dist/{index-s7qdecev.js → index-xdtanv9b.js} +358 -4
- package/dist/{index-vg8r40y7.js → index-yc0jgph6.js} +7 -0
- package/dist/index-zhbwhdya.js +407 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +142 -24
- package/dist/interpret/driver.d.ts +14 -0
- package/dist/interpret/errors.d.ts +11 -2
- package/dist/interpret/events.d.ts +4 -0
- package/dist/interpret/run.d.ts +33 -0
- package/dist/interpret.js +5 -4
- package/dist/script/adapters/from-computer-use.d.ts +124 -0
- package/dist/script/index.d.ts +1 -0
- package/dist/script.js +28 -9
- package/dist/target/index.d.ts +2 -0
- package/dist/target/roles.d.ts +11 -0
- package/dist/target/snapshot-mask.d.ts +49 -0
- package/dist/target/snapshot-tree.d.ts +65 -0
- package/dist/target/snapshot-url.d.ts +6 -0
- package/dist/target/snapshot.d.ts +1 -6
- package/dist/target.js +55 -13
- package/dist/testing.js +2 -2
- package/package.json +7 -3
|
@@ -1,27 +1,54 @@
|
|
|
1
1
|
import {
|
|
2
|
+
uiTargetSchema2,
|
|
2
3
|
UiScriptError2,
|
|
3
4
|
parseUiScript2
|
|
4
|
-
} from "./index-
|
|
5
|
+
} from "./index-qmv3ar39.js";
|
|
6
|
+
import {
|
|
7
|
+
UI_CONSEQUENCES2,
|
|
8
|
+
parseHealMode2,
|
|
9
|
+
decideHeal2,
|
|
10
|
+
usablePopupHandlers2,
|
|
11
|
+
matchesUrlPattern2,
|
|
12
|
+
verifyHealCandidate2
|
|
13
|
+
} from "./index-w9jc25y9.js";
|
|
14
|
+
import {
|
|
15
|
+
isActingStep,
|
|
16
|
+
classifyConsequence2,
|
|
17
|
+
elementInfoFromTarget2,
|
|
18
|
+
HEALABLE_ACTIONS2,
|
|
19
|
+
MAX_POPUP_HANDLERS_PER_STEP2,
|
|
20
|
+
POPUP_HANDLER_STEP_WAIT_MS2
|
|
21
|
+
} from "./index-xdtanv9b.js";
|
|
5
22
|
import {
|
|
6
23
|
isUiErrorCode2,
|
|
7
24
|
isRetryableInScript2,
|
|
8
25
|
UiRunError2,
|
|
9
26
|
UiDriverError2,
|
|
10
27
|
realClock2
|
|
11
|
-
} from "./index-
|
|
28
|
+
} from "./index-yc0jgph6.js";
|
|
29
|
+
import {
|
|
30
|
+
describeTarget2,
|
|
31
|
+
describeStep2
|
|
32
|
+
} from "./index-gvavb597.js";
|
|
12
33
|
import {
|
|
13
34
|
missingCapabilities2
|
|
14
|
-
} from "./index-
|
|
35
|
+
} from "./index-hw5npwsv.js";
|
|
15
36
|
import {
|
|
16
37
|
walkSteps2,
|
|
17
38
|
stepTargets2
|
|
18
39
|
} from "./index-g7724awk.js";
|
|
40
|
+
import {
|
|
41
|
+
isSnapshotPath2,
|
|
42
|
+
indexSnapshot2,
|
|
43
|
+
maskSnapshot2
|
|
44
|
+
} from "./index-zhbwhdya.js";
|
|
19
45
|
import {
|
|
20
46
|
MAX_TYPED_TEXT2
|
|
21
|
-
} from "./index-
|
|
47
|
+
} from "./index-vnv9tp11.js";
|
|
22
48
|
import {
|
|
23
|
-
containsText2
|
|
24
|
-
|
|
49
|
+
containsText2,
|
|
50
|
+
snapshotUrl2
|
|
51
|
+
} from "./index-t55wvhvh.js";
|
|
25
52
|
import {
|
|
26
53
|
redactCredentials2
|
|
27
54
|
} from "./index-mgztm37r.js";
|
|
@@ -465,14 +492,33 @@ class StepFailure extends Error {
|
|
|
465
492
|
stepPath;
|
|
466
493
|
stepId;
|
|
467
494
|
detail;
|
|
468
|
-
|
|
495
|
+
primary;
|
|
496
|
+
heal;
|
|
497
|
+
constructor(code, message, stepPath, stepId, detail, primary = false, heal) {
|
|
469
498
|
super(message);
|
|
470
499
|
this.code = code;
|
|
471
500
|
this.stepPath = stepPath;
|
|
472
501
|
this.stepId = stepId;
|
|
473
502
|
this.detail = detail;
|
|
503
|
+
this.primary = primary;
|
|
504
|
+
this.heal = heal;
|
|
474
505
|
}
|
|
475
506
|
}
|
|
507
|
+
var POPUP_CODES = new Set(["ELEMENT_NOT_FOUND", "ELEMENT_NOT_INTERACTABLE"]);
|
|
508
|
+
var HEAL_CODES = new Set(["ELEMENT_NOT_FOUND", "ELEMENT_AMBIGUOUS"]);
|
|
509
|
+
function boundedHandlerStep(step) {
|
|
510
|
+
const timeoutMs = Math.min(step.timeoutMs ?? POPUP_HANDLER_STEP_WAIT_MS2, POPUP_HANDLER_STEP_WAIT_MS2);
|
|
511
|
+
if (step.action === "waitFor" && step.milliseconds !== undefined) {
|
|
512
|
+
return { ...step, timeoutMs, milliseconds: Math.min(step.milliseconds, POPUP_HANDLER_STEP_WAIT_MS2) };
|
|
513
|
+
}
|
|
514
|
+
return { ...step, timeoutMs };
|
|
515
|
+
}
|
|
516
|
+
function healFailureCode(code) {
|
|
517
|
+
return code === "ELEMENT_AMBIGUOUS" ? "ELEMENT_AMBIGUOUS" : "ELEMENT_NOT_FOUND";
|
|
518
|
+
}
|
|
519
|
+
function isConsequence(value) {
|
|
520
|
+
return typeof value === "string" && UI_CONSEQUENCES2.some((consequence) => consequence === value);
|
|
521
|
+
}
|
|
476
522
|
var FLOW_ACTIONS = new Set(["if", "forEach", "while", "retryScope", "set", "log", "call"]);
|
|
477
523
|
function clipMessage(text) {
|
|
478
524
|
return redactCredentials2(text).slice(0, MAX_EVENT_MESSAGE2);
|
|
@@ -574,6 +620,14 @@ class Interpreter {
|
|
|
574
620
|
ending = false;
|
|
575
621
|
inCleanup = false;
|
|
576
622
|
iterations = [];
|
|
623
|
+
overrides = new Map;
|
|
624
|
+
healed = new Map;
|
|
625
|
+
healTried = new Set;
|
|
626
|
+
healedSteps = new Set;
|
|
627
|
+
popupsHandled = 0;
|
|
628
|
+
popupHandlers = [];
|
|
629
|
+
popupRejections = [];
|
|
630
|
+
inRepair = false;
|
|
577
631
|
constructor(driver, options) {
|
|
578
632
|
this.driver = driver;
|
|
579
633
|
this.options = options;
|
|
@@ -595,6 +649,13 @@ class Interpreter {
|
|
|
595
649
|
const failure = error instanceof UiRunError2 ? error : new UiRunError2("INVALID_SCRIPT", "The UI script could not be read");
|
|
596
650
|
return this.finish("failed", { code: failure.code, family: failure.family, message: failure.message }, failure.detail);
|
|
597
651
|
}
|
|
652
|
+
if (this.popupRejections.length > 0) {
|
|
653
|
+
await this.emit({
|
|
654
|
+
kind: "LOG",
|
|
655
|
+
message: `${this.popupRejections.length} pop-up handler(s) were not used: they are not valid or could loop`,
|
|
656
|
+
detail: { level: "warn", popupHandlersRejected: this.popupRejections }
|
|
657
|
+
});
|
|
658
|
+
}
|
|
598
659
|
let status = "succeeded";
|
|
599
660
|
let failure;
|
|
600
661
|
let failureDetailValue;
|
|
@@ -661,7 +722,8 @@ class Interpreter {
|
|
|
661
722
|
family: known.family,
|
|
662
723
|
message: error.message,
|
|
663
724
|
stepPath: error.stepPath,
|
|
664
|
-
stepId: error.stepId
|
|
725
|
+
stepId: error.stepId,
|
|
726
|
+
...error.heal ? { heal: error.heal } : {}
|
|
665
727
|
};
|
|
666
728
|
}
|
|
667
729
|
async finish(status, failure, detail, outputs = {}) {
|
|
@@ -692,7 +754,8 @@ class Interpreter {
|
|
|
692
754
|
dropped: this.emitter.droppedCount,
|
|
693
755
|
truncated: this.emitter.isTruncated
|
|
694
756
|
},
|
|
695
|
-
durationMs
|
|
757
|
+
durationMs,
|
|
758
|
+
...this.healedSteps.size > 0 || this.popupsHandled > 0 ? { repairs: { healed: this.healedSteps.size, popupsHandled: this.popupsHandled } } : {}
|
|
696
759
|
};
|
|
697
760
|
}
|
|
698
761
|
preflight(input) {
|
|
@@ -729,11 +792,35 @@ class Interpreter {
|
|
|
729
792
|
}
|
|
730
793
|
}
|
|
731
794
|
this.checkRange();
|
|
795
|
+
this.bindOverrides();
|
|
796
|
+
if (this.options.popupHandlers && this.options.popupHandlers.length > 0) {
|
|
797
|
+
const usable = usablePopupHandlers2(this.options.popupHandlers);
|
|
798
|
+
this.popupHandlers = usable.handlers;
|
|
799
|
+
this.popupRejections = usable.rejected;
|
|
800
|
+
}
|
|
732
801
|
this.bindInputs();
|
|
733
802
|
for (const variable of this.script.variables ?? []) {
|
|
734
803
|
this.variables.set(variable.name, variable.initial === undefined ? null : this.evaluateOrInvalid(variable.initial, `variables.${variable.name}`));
|
|
735
804
|
}
|
|
736
805
|
}
|
|
806
|
+
bindOverrides() {
|
|
807
|
+
const overrides = this.options.targetOverrides;
|
|
808
|
+
if (!overrides)
|
|
809
|
+
return;
|
|
810
|
+
const steps = new Map;
|
|
811
|
+
for (const { step } of walkSteps2(this.script))
|
|
812
|
+
steps.set(step.id, step);
|
|
813
|
+
for (const [stepId, value] of Object.entries(overrides)) {
|
|
814
|
+
const step = steps.get(stepId);
|
|
815
|
+
const parsed = uiTargetSchema2.safeParse(value);
|
|
816
|
+
if (!step || !HEALABLE_ACTIONS2.has(step.action) || !this.primaryRef(step) || !parsed.success) {
|
|
817
|
+
throw new UiRunError2("INVALID_SCRIPT", "A target override names no step it can apply to, or is not a valid target", {
|
|
818
|
+
targetOverride: stepId.slice(0, 64)
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
this.overrides.set(stepId, parsed.data);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
737
824
|
evaluateOrInvalid(expression, where) {
|
|
738
825
|
try {
|
|
739
826
|
return evaluateExpression2(expression, this.scope);
|
|
@@ -1002,6 +1089,16 @@ class Interpreter {
|
|
|
1002
1089
|
await this.sleep(step.retry?.delayMs ?? DEFAULT_RETRY_DELAY_MS2);
|
|
1003
1090
|
}
|
|
1004
1091
|
}
|
|
1092
|
+
let repaired = {};
|
|
1093
|
+
if (failure && this.canRepair(step, path, failure)) {
|
|
1094
|
+
const result = await this.repair(step, path, tried, failure);
|
|
1095
|
+
if ("outcome" in result) {
|
|
1096
|
+
outcome = result.outcome;
|
|
1097
|
+
repaired = result.info;
|
|
1098
|
+
failure = undefined;
|
|
1099
|
+
} else
|
|
1100
|
+
failure = result.failure;
|
|
1101
|
+
}
|
|
1005
1102
|
const durationMs = Math.max(0, this.clock.now() - began);
|
|
1006
1103
|
const elementId = this.elementIdOf(step);
|
|
1007
1104
|
if (failure) {
|
|
@@ -1032,7 +1129,7 @@ class Interpreter {
|
|
|
1032
1129
|
...screenshotFileId ? { screenshotFileId } : {},
|
|
1033
1130
|
error: failure.code
|
|
1034
1131
|
});
|
|
1035
|
-
if (step.onError === "continue") {
|
|
1132
|
+
if (step.onError === "continue" && failure.code !== "HEAL_APPROVAL_REQUIRED") {
|
|
1036
1133
|
if (step.saveAs !== undefined)
|
|
1037
1134
|
this.store(step.saveAs, null);
|
|
1038
1135
|
this.endIfStopAfter(path);
|
|
@@ -1051,8 +1148,9 @@ class Interpreter {
|
|
|
1051
1148
|
durationMs,
|
|
1052
1149
|
...outcome?.resolvedBy ? { resolvedBy: outcome.resolvedBy } : {},
|
|
1053
1150
|
...screenshotFileId ? { screenshotFileId } : {},
|
|
1054
|
-
detail: this.iterationDetail()
|
|
1151
|
+
detail: { ...this.iterationDetail(), ...this.repairDetail(step, repaired) }
|
|
1055
1152
|
});
|
|
1153
|
+
const healed = this.healed.has(step.id) && this.primaryRef(step) !== undefined;
|
|
1056
1154
|
this.log({
|
|
1057
1155
|
path,
|
|
1058
1156
|
stepId: step.id,
|
|
@@ -1061,7 +1159,9 @@ class Interpreter {
|
|
|
1061
1159
|
durationMs,
|
|
1062
1160
|
...outcome?.resolvedBy ? { method: outcome.resolvedBy } : {},
|
|
1063
1161
|
...elementId ? { elementId } : {},
|
|
1064
|
-
...screenshotFileId ? { screenshotFileId } : {}
|
|
1162
|
+
...screenshotFileId ? { screenshotFileId } : {},
|
|
1163
|
+
...healed ? { healed: true } : {},
|
|
1164
|
+
...repaired.popupHandlerId ? { popupHandlerId: repaired.popupHandlerId } : {}
|
|
1065
1165
|
});
|
|
1066
1166
|
if (!FLOW_ACTIONS.has(step.action)) {
|
|
1067
1167
|
this.lastCompleted = path;
|
|
@@ -1069,6 +1169,301 @@ class Interpreter {
|
|
|
1069
1169
|
}
|
|
1070
1170
|
this.endIfStopAfter(path);
|
|
1071
1171
|
}
|
|
1172
|
+
repairDetail(step, repaired) {
|
|
1173
|
+
const healed = this.primaryRef(step) ? this.healed.get(step.id) : undefined;
|
|
1174
|
+
const overridden = !healed && this.overrides.has(step.id);
|
|
1175
|
+
return {
|
|
1176
|
+
...healed ? {
|
|
1177
|
+
healed: {
|
|
1178
|
+
method: "model",
|
|
1179
|
+
nodePath: healed.nodePath,
|
|
1180
|
+
...healed.proposalId ? { proposalId: healed.proposalId } : {}
|
|
1181
|
+
}
|
|
1182
|
+
} : {},
|
|
1183
|
+
...repaired.popupHandlerId ? { popupHandlerId: repaired.popupHandlerId } : {},
|
|
1184
|
+
...overridden ? { targetOverride: true } : {}
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
canRepair(step, path, failure) {
|
|
1188
|
+
if (this.inRepair || this.driver.replay || failure.stepPath !== path || !failure.primary)
|
|
1189
|
+
return false;
|
|
1190
|
+
const popups = this.popupHandlers.length > 0 && POPUP_CODES.has(failure.code);
|
|
1191
|
+
const heal = this.options.onTargetNotFound !== undefined && HEAL_CODES.has(failure.code) && HEALABLE_ACTIONS2.has(step.action);
|
|
1192
|
+
return popups || heal;
|
|
1193
|
+
}
|
|
1194
|
+
async repair(step, path, attempt, failure) {
|
|
1195
|
+
let current = failure;
|
|
1196
|
+
if (this.popupHandlers.length > 0 && POPUP_CODES.has(current.code)) {
|
|
1197
|
+
const tried = new Set;
|
|
1198
|
+
for (let used = 0;used < MAX_POPUP_HANDLERS_PER_STEP2; used += 1) {
|
|
1199
|
+
const handler = await this.findPopupHandler(step, path, attempt, tried);
|
|
1200
|
+
if (!handler)
|
|
1201
|
+
break;
|
|
1202
|
+
tried.add(handler.id);
|
|
1203
|
+
if (!await this.runPopupHandler(handler, step, path))
|
|
1204
|
+
continue;
|
|
1205
|
+
try {
|
|
1206
|
+
const outcome = await this.attemptStep(step, path, attempt + 1, false);
|
|
1207
|
+
this.popupsHandled += 1;
|
|
1208
|
+
return { outcome, info: { popupHandlerId: handler.id } };
|
|
1209
|
+
} catch (error) {
|
|
1210
|
+
if (!(error instanceof StepFailure))
|
|
1211
|
+
throw error;
|
|
1212
|
+
current = error;
|
|
1213
|
+
if (current.stepPath !== path || !current.primary || !POPUP_CODES.has(current.code))
|
|
1214
|
+
break;
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
if (HEAL_CODES.has(current.code) && current.stepPath === path && current.primary) {
|
|
1219
|
+
return this.heal(step, path, attempt, current);
|
|
1220
|
+
}
|
|
1221
|
+
return { failure: current };
|
|
1222
|
+
}
|
|
1223
|
+
async findPopupHandler(step, path, attempt, tried) {
|
|
1224
|
+
const context = this.context(step, path, attempt);
|
|
1225
|
+
let url;
|
|
1226
|
+
for (const handler of this.popupHandlers) {
|
|
1227
|
+
this.checkCancelled();
|
|
1228
|
+
if (tried.has(handler.id))
|
|
1229
|
+
continue;
|
|
1230
|
+
try {
|
|
1231
|
+
if (handler.match.urlPattern !== undefined) {
|
|
1232
|
+
url ??= await this.driver.currentUrl(context);
|
|
1233
|
+
if (!matchesUrlPattern2(url, handler.match.urlPattern))
|
|
1234
|
+
continue;
|
|
1235
|
+
}
|
|
1236
|
+
const resolution = await this.driver.resolve(handler.match.target, { state: "visible" }, context);
|
|
1237
|
+
if (resolution.status === "found")
|
|
1238
|
+
return handler;
|
|
1239
|
+
} catch {
|
|
1240
|
+
if (this.options.signal?.aborted && !this.inCleanup)
|
|
1241
|
+
throw new StopSignal("cancelled");
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1246
|
+
async runPopupHandler(handler, step, path) {
|
|
1247
|
+
this.inRepair = true;
|
|
1248
|
+
try {
|
|
1249
|
+
for (const [index, handlerStep] of handler.steps.entries()) {
|
|
1250
|
+
if (handlerStep.disabled === true)
|
|
1251
|
+
continue;
|
|
1252
|
+
const bounded = boundedHandlerStep(handlerStep);
|
|
1253
|
+
await this.perform(bounded, `${path}.popup.${index}`, 1, false);
|
|
1254
|
+
}
|
|
1255
|
+
} catch (error) {
|
|
1256
|
+
if (!(error instanceof StepFailure))
|
|
1257
|
+
throw error;
|
|
1258
|
+
await this.emit({
|
|
1259
|
+
kind: "LOG",
|
|
1260
|
+
stepPath: path,
|
|
1261
|
+
stepId: step.id,
|
|
1262
|
+
action: step.action,
|
|
1263
|
+
errorCode: error.code,
|
|
1264
|
+
message: clipMessage(`The pop-up handler ${handler.id} did not finish`),
|
|
1265
|
+
detail: { level: "warn", popupHandlerId: handler.id }
|
|
1266
|
+
});
|
|
1267
|
+
return false;
|
|
1268
|
+
} finally {
|
|
1269
|
+
this.inRepair = false;
|
|
1270
|
+
}
|
|
1271
|
+
await this.emit({
|
|
1272
|
+
kind: "LOG",
|
|
1273
|
+
stepPath: path,
|
|
1274
|
+
stepId: step.id,
|
|
1275
|
+
action: step.action,
|
|
1276
|
+
message: clipMessage(`The pop-up handler ${handler.id} ran`),
|
|
1277
|
+
detail: { level: "info", popupHandlerId: handler.id }
|
|
1278
|
+
});
|
|
1279
|
+
return true;
|
|
1280
|
+
}
|
|
1281
|
+
withHeal(failure, heal) {
|
|
1282
|
+
return new StepFailure(failure.code, failure.message, failure.stepPath, failure.stepId, { ...failure.detail ?? {}, heal }, failure.primary, heal);
|
|
1283
|
+
}
|
|
1284
|
+
checkedAnswer(answer, snapshot) {
|
|
1285
|
+
if (answer === null || typeof answer !== "object" || !("kind" in answer)) {
|
|
1286
|
+
return { kind: "unavailable", reason: "INVALID_ANSWER" };
|
|
1287
|
+
}
|
|
1288
|
+
if (answer.kind === "not_present")
|
|
1289
|
+
return { kind: "not_present" };
|
|
1290
|
+
if (answer.kind !== "candidate" || !("candidate" in answer)) {
|
|
1291
|
+
const reason = "reason" in answer && typeof answer.reason === "string" ? answer.reason.slice(0, 64) : "UNAVAILABLE";
|
|
1292
|
+
return { kind: "unavailable", reason };
|
|
1293
|
+
}
|
|
1294
|
+
const candidate = answer.candidate;
|
|
1295
|
+
if (candidate === null || typeof candidate !== "object")
|
|
1296
|
+
return { kind: "unavailable", reason: "INVALID_ANSWER" };
|
|
1297
|
+
const nodePath = "nodePath" in candidate ? candidate.nodePath : undefined;
|
|
1298
|
+
const target = uiTargetSchema2.safeParse("proposedTarget" in candidate ? candidate.proposedTarget : undefined);
|
|
1299
|
+
const confidence = "confidence" in candidate ? candidate.confidence : undefined;
|
|
1300
|
+
if (!isSnapshotPath2(nodePath) || !target.success)
|
|
1301
|
+
return { kind: "unavailable", reason: "INVALID_ANSWER" };
|
|
1302
|
+
if (!indexSnapshot2(snapshot).byPath.has(nodePath))
|
|
1303
|
+
return { kind: "unavailable", reason: "INVALID_ANSWER" };
|
|
1304
|
+
const usableConfidence = typeof confidence === "number" && Number.isFinite(confidence) && confidence >= 0 && confidence <= 1;
|
|
1305
|
+
return {
|
|
1306
|
+
kind: "candidate",
|
|
1307
|
+
candidate: { nodePath, proposedTarget: target.data, ...usableConfidence ? { confidence } : {} }
|
|
1308
|
+
};
|
|
1309
|
+
}
|
|
1310
|
+
async askHeal(hook, request) {
|
|
1311
|
+
const signal = this.inCleanup ? undefined : this.options.signal;
|
|
1312
|
+
if (!signal)
|
|
1313
|
+
return hook(request, {});
|
|
1314
|
+
if (signal.aborted)
|
|
1315
|
+
throw new StopSignal("cancelled");
|
|
1316
|
+
return new Promise((resolve, reject) => {
|
|
1317
|
+
const onAbort = () => reject(new StopSignal("cancelled"));
|
|
1318
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
1319
|
+
hook(request, { signal }).then((result) => {
|
|
1320
|
+
signal.removeEventListener("abort", onAbort);
|
|
1321
|
+
resolve(result);
|
|
1322
|
+
}, (error) => {
|
|
1323
|
+
signal.removeEventListener("abort", onAbort);
|
|
1324
|
+
reject(error instanceof Error ? error : new Error("The heal hook failed"));
|
|
1325
|
+
});
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1328
|
+
async heal(step, path, attempt, failure) {
|
|
1329
|
+
const hook = this.options.onTargetNotFound;
|
|
1330
|
+
const ref = this.primaryRef(step);
|
|
1331
|
+
if (!hook || !ref || !HEALABLE_ACTIONS2.has(step.action) || this.healTried.has(step.id))
|
|
1332
|
+
return { failure };
|
|
1333
|
+
this.healTried.add(step.id);
|
|
1334
|
+
const failedTarget = this.stepTarget(step, ref);
|
|
1335
|
+
const context = this.context(step, path, attempt);
|
|
1336
|
+
let snapshot = null;
|
|
1337
|
+
let url = "";
|
|
1338
|
+
try {
|
|
1339
|
+
snapshot = await this.driver.treeSnapshot?.(context) ?? null;
|
|
1340
|
+
url = await this.driver.currentUrl(context);
|
|
1341
|
+
} catch {
|
|
1342
|
+
if (this.options.signal?.aborted && !this.inCleanup)
|
|
1343
|
+
throw new StopSignal("cancelled");
|
|
1344
|
+
}
|
|
1345
|
+
if (!snapshot)
|
|
1346
|
+
return { failure: this.withHeal(failure, { outcome: "unavailable", reason: "NO_SNAPSHOT" }) };
|
|
1347
|
+
const masked = maskSnapshot2(snapshot, { maskedPaths: this.options.healing?.maskedPaths ?? [] });
|
|
1348
|
+
const elements = this.script.elements ?? {};
|
|
1349
|
+
const element = "element" in ref ? elements[ref.element] : undefined;
|
|
1350
|
+
const request = {
|
|
1351
|
+
stepPath: path,
|
|
1352
|
+
stepId: step.id,
|
|
1353
|
+
stepSentence: describeStep2(step, elements).fallback,
|
|
1354
|
+
action: step.action,
|
|
1355
|
+
..."element" in ref ? {
|
|
1356
|
+
elementRef: {
|
|
1357
|
+
element: ref.element,
|
|
1358
|
+
...element ? { elementId: element.elementId, version: element.version } : {}
|
|
1359
|
+
}
|
|
1360
|
+
} : {},
|
|
1361
|
+
target: failedTarget,
|
|
1362
|
+
description: describeTarget2(ref, elements),
|
|
1363
|
+
failureCode: healFailureCode(failure.code),
|
|
1364
|
+
url: snapshotUrl2(url) ?? "",
|
|
1365
|
+
snapshot: masked.snapshot,
|
|
1366
|
+
maskedPaths: masked.maskedPaths,
|
|
1367
|
+
screenshotMask: masked.screenshotMask
|
|
1368
|
+
};
|
|
1369
|
+
let result;
|
|
1370
|
+
try {
|
|
1371
|
+
result = await this.askHeal(hook, request);
|
|
1372
|
+
} catch (error) {
|
|
1373
|
+
if (error instanceof StopSignal)
|
|
1374
|
+
throw error;
|
|
1375
|
+
return { failure: this.withHeal(failure, { outcome: "unavailable", reason: "HOOK_FAILED" }) };
|
|
1376
|
+
}
|
|
1377
|
+
if (result === null || typeof result !== "object") {
|
|
1378
|
+
return { failure: this.withHeal(failure, { outcome: "unavailable", reason: "HOOK_FAILED" }) };
|
|
1379
|
+
}
|
|
1380
|
+
const mode = parseHealMode2(result.mode) ?? "off";
|
|
1381
|
+
if (mode === "off")
|
|
1382
|
+
return { failure };
|
|
1383
|
+
await this.emit({
|
|
1384
|
+
kind: "LOG",
|
|
1385
|
+
stepPath: path,
|
|
1386
|
+
stepId: step.id,
|
|
1387
|
+
action: step.action,
|
|
1388
|
+
errorCode: failure.code,
|
|
1389
|
+
message: "The target was not found; healing was asked for a repaired target",
|
|
1390
|
+
detail: { level: "info", healRequested: true, mode }
|
|
1391
|
+
});
|
|
1392
|
+
const proposalId = typeof result.proposalId === "string" && result.proposalId.length > 0 && result.proposalId.length <= 128 ? result.proposalId : undefined;
|
|
1393
|
+
const withProposal = proposalId ? { proposalId } : {};
|
|
1394
|
+
const answer = this.checkedAnswer(result.answer, masked.snapshot);
|
|
1395
|
+
if (answer.kind === "not_present") {
|
|
1396
|
+
return { failure: this.withHeal(failure, { outcome: "not_present", mode, ...withProposal }) };
|
|
1397
|
+
}
|
|
1398
|
+
if (answer.kind === "unavailable") {
|
|
1399
|
+
return {
|
|
1400
|
+
failure: this.withHeal(failure, { outcome: "unavailable", mode, reason: answer.reason, ...withProposal })
|
|
1401
|
+
};
|
|
1402
|
+
}
|
|
1403
|
+
const candidate = answer.candidate;
|
|
1404
|
+
const check = await verifyHealCandidate2(this.driver, candidate, step, {
|
|
1405
|
+
snapshot: masked.snapshot,
|
|
1406
|
+
failedTarget,
|
|
1407
|
+
stepContext: context
|
|
1408
|
+
});
|
|
1409
|
+
if (!check.ok) {
|
|
1410
|
+
return {
|
|
1411
|
+
failure: this.withHeal(failure, {
|
|
1412
|
+
outcome: "check_failed",
|
|
1413
|
+
mode,
|
|
1414
|
+
candidate,
|
|
1415
|
+
reason: check.reason,
|
|
1416
|
+
...withProposal
|
|
1417
|
+
})
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1420
|
+
const classified = {
|
|
1421
|
+
action: step.action,
|
|
1422
|
+
...step.action === "type" && step.pressEnter === true ? { pressEnter: true } : {}
|
|
1423
|
+
};
|
|
1424
|
+
const keywords = this.options.healing?.keywords;
|
|
1425
|
+
const verdict = classifyConsequence2(check.element, classified, keywords);
|
|
1426
|
+
const intended = classifyConsequence2(elementInfoFromTarget2(failedTarget, element?.name), classified, keywords);
|
|
1427
|
+
const consequence = verdict.consequence ?? intended.consequence ?? (isConsequence(result.consequence) ? result.consequence : undefined);
|
|
1428
|
+
const unreadable = isActingStep(classified) && (check.sensitive || check.element.name?.trim() === "");
|
|
1429
|
+
const alwaysAsk = result.alwaysAsk === true || verdict.keyword !== null || intended.keyword !== null || unreadable || (this.options.healing?.alwaysAskStepIds ?? []).includes(step.id);
|
|
1430
|
+
const decision = decideHeal2(mode, { consequence: consequence ?? null, alwaysAsk }) ?? "stop_suggest";
|
|
1431
|
+
const report = {
|
|
1432
|
+
outcome: decision === "continue" ? "healed" : decision === "ask" ? "approval_required" : "suggested",
|
|
1433
|
+
mode,
|
|
1434
|
+
decision,
|
|
1435
|
+
candidate,
|
|
1436
|
+
...withProposal,
|
|
1437
|
+
...consequence ? { consequence } : {},
|
|
1438
|
+
...alwaysAsk ? { alwaysAsk: true } : {}
|
|
1439
|
+
};
|
|
1440
|
+
if (decision === "stop_suggest")
|
|
1441
|
+
return { failure: this.withHeal(failure, report) };
|
|
1442
|
+
if (decision === "ask") {
|
|
1443
|
+
return {
|
|
1444
|
+
failure: new StepFailure("HEAL_APPROVAL_REQUIRED", "A person must approve the repaired target before the step runs", path, step.id, { ...failure.detail ?? {}, originalCode: failure.code, heal: report }, true, report)
|
|
1445
|
+
};
|
|
1446
|
+
}
|
|
1447
|
+
this.healed.set(step.id, { target: candidate.proposedTarget, nodePath: candidate.nodePath, ...withProposal });
|
|
1448
|
+
try {
|
|
1449
|
+
const outcome = await this.attemptStep(step, path, attempt + 1, false);
|
|
1450
|
+
this.healedSteps.add(step.id);
|
|
1451
|
+
return { outcome, info: {} };
|
|
1452
|
+
} catch (error) {
|
|
1453
|
+
if (!(error instanceof StepFailure))
|
|
1454
|
+
throw error;
|
|
1455
|
+
this.healed.delete(step.id);
|
|
1456
|
+
return {
|
|
1457
|
+
failure: this.withHeal(error, {
|
|
1458
|
+
...report,
|
|
1459
|
+
outcome: "check_failed",
|
|
1460
|
+
reason: "STEP_FAILED",
|
|
1461
|
+
stepFailureCode: error.code,
|
|
1462
|
+
attempted: true
|
|
1463
|
+
})
|
|
1464
|
+
};
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1072
1467
|
endIfStopAfter(path) {
|
|
1073
1468
|
if (this.started && this.options.stopAfter === path)
|
|
1074
1469
|
throw new StopSignal("rangeEnd");
|
|
@@ -1110,7 +1505,7 @@ class Interpreter {
|
|
|
1110
1505
|
return outcome;
|
|
1111
1506
|
}
|
|
1112
1507
|
fail(step, path, failure) {
|
|
1113
|
-
throw new StepFailure(failure.code, failure.message, path, step.id, failure.detail);
|
|
1508
|
+
throw new StepFailure(failure.code, failure.message, path, step.id, failure.detail, failure.primary === true);
|
|
1114
1509
|
}
|
|
1115
1510
|
evaluate(step, path, expression) {
|
|
1116
1511
|
try {
|
|
@@ -1128,6 +1523,17 @@ class Interpreter {
|
|
|
1128
1523
|
targetOf(ref) {
|
|
1129
1524
|
return "element" in ref ? this.script.elements?.[ref.element]?.target ?? { methods: [] } : ref;
|
|
1130
1525
|
}
|
|
1526
|
+
primaryRef(step) {
|
|
1527
|
+
return "target" in step ? step.target : undefined;
|
|
1528
|
+
}
|
|
1529
|
+
stepTarget(step, ref) {
|
|
1530
|
+
if (!this.inRepair && ref === this.primaryRef(step)) {
|
|
1531
|
+
const replaced = this.healed.get(step.id)?.target ?? this.overrides.get(step.id);
|
|
1532
|
+
if (replaced)
|
|
1533
|
+
return replaced;
|
|
1534
|
+
}
|
|
1535
|
+
return this.targetOf(ref);
|
|
1536
|
+
}
|
|
1131
1537
|
waitFor(step) {
|
|
1132
1538
|
const settings = this.script.settings;
|
|
1133
1539
|
if (step.timeoutMs !== undefined) {
|
|
@@ -1169,7 +1575,7 @@ class Interpreter {
|
|
|
1169
1575
|
}
|
|
1170
1576
|
}
|
|
1171
1577
|
async onTarget(step, path, attempt, ref, run, waitMs = this.waitFor(step)) {
|
|
1172
|
-
const target = this.
|
|
1578
|
+
const target = this.stepTarget(step, ref);
|
|
1173
1579
|
const context = this.context(step, path, attempt);
|
|
1174
1580
|
const { result, waitedMs } = await this.poll(step, path, waitMs, () => run(target, context));
|
|
1175
1581
|
if (!result.ok) {
|
|
@@ -1177,7 +1583,8 @@ class Interpreter {
|
|
|
1177
1583
|
this.fail(step, path, {
|
|
1178
1584
|
code,
|
|
1179
1585
|
message: FAILURE_MESSAGES[code] ?? "The step failed",
|
|
1180
|
-
detail: failureDetail(result, waitedMs)
|
|
1586
|
+
detail: failureDetail(result, waitedMs),
|
|
1587
|
+
primary: !this.inRepair && ref === this.primaryRef(step)
|
|
1181
1588
|
});
|
|
1182
1589
|
}
|
|
1183
1590
|
return {
|
|
@@ -1503,7 +1910,7 @@ class Interpreter {
|
|
|
1503
1910
|
outcome = await this.act(step, path, attempt, step.target, { kind: "type", text, append: step.clear === false });
|
|
1504
1911
|
}
|
|
1505
1912
|
if (step.pressEnter === true) {
|
|
1506
|
-
const target = step.target ? this.
|
|
1913
|
+
const target = step.target ? this.stepTarget(step, step.target) : null;
|
|
1507
1914
|
const context = this.context(step, path, attempt);
|
|
1508
1915
|
const result = await this.call(step, path, () => this.driver.pressKeys(target, ["Enter"], context));
|
|
1509
1916
|
if (!result.ok) {
|
|
@@ -1663,7 +2070,7 @@ class Interpreter {
|
|
|
1663
2070
|
}
|
|
1664
2071
|
if (this.driver.replay)
|
|
1665
2072
|
return {};
|
|
1666
|
-
const target = this.
|
|
2073
|
+
const target = this.stepTarget(step, step.target);
|
|
1667
2074
|
const resolveState = state === "hidden" ? "visible" : "attached";
|
|
1668
2075
|
const gone = await this.waitUntil(step, path, this.waitFor(step), async (context) => {
|
|
1669
2076
|
const resolution = await this.driver.resolve(target, { state: resolveState }, context);
|
|
@@ -5,42 +5,6 @@ import {
|
|
|
5
5
|
stepTargets2
|
|
6
6
|
} from "./index-g7724awk.js";
|
|
7
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
8
|
// src/script/capabilities.ts
|
|
45
9
|
var CAPABILITY_IDS2 = [
|
|
46
10
|
"script:1",
|
|
@@ -96,4 +60,4 @@ function missingCapabilities2(script, supported) {
|
|
|
96
60
|
return requiredCapabilities2(script).filter((id) => !have.has(id));
|
|
97
61
|
}
|
|
98
62
|
|
|
99
|
-
export {
|
|
63
|
+
export { CAPABILITY_IDS2, SCRIPT_CAPABILITY2, requiredCapabilities2, missingCapabilities2 };
|