@burdenoff/ui-engine 2026.1204.1 → 2026.1204.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 +20 -2
- package/dist/analyze/analyze.d.ts +10 -0
- package/dist/analyze/context.d.ts +25 -9
- package/dist/analyze/index.d.ts +3 -2
- package/dist/analyze/messages.d.ts +2 -0
- package/dist/analyze/rules/run-command-from-variable.d.ts +2 -0
- package/dist/analyze/rules/single-method-image-target.d.ts +7 -0
- package/dist/analyze/sensitive.d.ts +2 -2
- package/dist/analyze/types.d.ts +6 -2
- package/dist/analyze.js +4 -2
- package/dist/desk.d.ts +13 -0
- package/dist/desk.js +29 -0
- package/dist/dom-runtime.iife.js +1 -1
- package/dist/dom-runtime.js +2 -2
- package/dist/drivers/desk-backend.d.ts +40 -0
- package/dist/drivers/desk-driver.d.ts +41 -0
- package/dist/drivers/desk-errors.d.ts +19 -0
- package/dist/drivers/desk-tree.d.ts +28 -0
- package/dist/drivers/desk-wire.d.ts +237 -0
- package/dist/drivers/index.d.ts +3 -1
- package/dist/drivers.js +10 -7
- package/dist/heal.js +5 -5
- package/dist/index-0ps53dhe.js +85 -0
- package/dist/{index-ptrmf779.js → index-2q0hh6we.js} +3 -3
- package/dist/index-552x2bnm.js +56 -0
- package/dist/index-6m0chbhq.js +64 -0
- package/dist/{index-dwp10g62.js → index-7gfzv5n8.js} +96 -53
- package/dist/{index-gvavb597.js → index-93hfbk5c.js} +10 -0
- package/dist/index-a8s39bse.js +920 -0
- package/dist/index-b5a306v7.js +43 -0
- package/dist/index-bx4bsvg0.js +458 -0
- package/dist/{index-9xgz8dxt.js → index-cc49ykn5.js} +4 -4
- package/dist/{index-vpm1gnmy.js → index-e557vzdd.js} +219 -34
- package/dist/{index-vnv9tp11.js → index-e7pgqd60.js} +2 -2
- package/dist/index-hdq3y007.js +246 -0
- package/dist/{index-zagmp5ya.js → index-n3nfhjrj.js} +2 -2
- package/dist/{index-wnch00m6.js → index-nmsg2wze.js} +2 -2
- package/dist/{index-zhbwhdya.js → index-q2jbva7c.js} +5 -3
- package/dist/{index-n7ah1jn7.js → index-rbem2yms.js} +16 -243
- package/dist/{index-mhv6a02p.js → index-reef7e8m.js} +1 -1
- package/dist/{index-3r2y0mnc.js → index-wdbn4xjc.js} +5 -5
- package/dist/{index-8eb4xd1j.js → index-x8fc4r4h.js} +101 -426
- package/dist/{index-0tfzfxx9.js → index-yhzykhdj.js} +1 -43
- package/dist/{index-t55wvhvh.js → index-z2v8prer.js} +1 -61
- package/dist/{index-5pv673wd.js → index-zj3zhbac.js} +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +79 -31
- package/dist/interpret/driver.d.ts +109 -18
- package/dist/interpret/events.d.ts +5 -2
- package/dist/interpret/index.d.ts +4 -3
- package/dist/interpret/run.d.ts +28 -1
- package/dist/interpret.js +16 -9
- package/dist/script/adapters/recording-desktop.d.ts +52 -0
- package/dist/script/describe.d.ts +7 -2
- package/dist/script/desk-roles.d.ts +33 -0
- package/dist/script/desktop-capabilities.d.ts +7 -2
- package/dist/script/desktop-schema.d.ts +2 -0
- package/dist/script/index.d.ts +3 -1
- package/dist/script.js +35 -19
- package/dist/target/types.d.ts +10 -4
- package/dist/target.js +20 -16
- package/dist/testing.js +5 -3
- package/package.json +7 -3
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
uiTargetSchema2,
|
|
3
|
+
MAX_DESK_FILE_BYTES2,
|
|
4
|
+
DEFAULT_DESK_FILE_BYTES2,
|
|
5
|
+
MAX_DESK_SET_VALUE2,
|
|
3
6
|
UiScriptError2,
|
|
4
|
-
parseUiScript2
|
|
5
|
-
|
|
7
|
+
parseUiScript2,
|
|
8
|
+
parseDesktopUiScript2
|
|
9
|
+
} from "./index-zj3zhbac.js";
|
|
6
10
|
import {
|
|
7
11
|
UI_CONSEQUENCES2,
|
|
8
12
|
parseHealMode2,
|
|
@@ -10,7 +14,7 @@ import {
|
|
|
10
14
|
usablePopupHandlers2,
|
|
11
15
|
matchesUrlPattern2,
|
|
12
16
|
verifyHealCandidate2
|
|
13
|
-
} from "./index-
|
|
17
|
+
} from "./index-2q0hh6we.js";
|
|
14
18
|
import {
|
|
15
19
|
isActingStep,
|
|
16
20
|
classifyConsequence2,
|
|
@@ -18,18 +22,23 @@ import {
|
|
|
18
22
|
HEALABLE_ACTIONS2,
|
|
19
23
|
MAX_POPUP_HANDLERS_PER_STEP2,
|
|
20
24
|
POPUP_HANDLER_STEP_WAIT_MS2
|
|
21
|
-
} from "./index-
|
|
25
|
+
} from "./index-7gfzv5n8.js";
|
|
26
|
+
import {
|
|
27
|
+
realClock2
|
|
28
|
+
} from "./index-b5a306v7.js";
|
|
22
29
|
import {
|
|
23
30
|
isUiErrorCode2,
|
|
24
31
|
isRetryableInScript2,
|
|
25
32
|
UiRunError2,
|
|
26
|
-
UiDriverError2
|
|
27
|
-
|
|
28
|
-
} from "./index-0tfzfxx9.js";
|
|
33
|
+
UiDriverError2
|
|
34
|
+
} from "./index-yhzykhdj.js";
|
|
29
35
|
import {
|
|
30
36
|
describeTarget2,
|
|
31
37
|
describeStep2
|
|
32
|
-
} from "./index-
|
|
38
|
+
} from "./index-93hfbk5c.js";
|
|
39
|
+
import {
|
|
40
|
+
checkDesktopScriptForDesk2
|
|
41
|
+
} from "./index-bx4bsvg0.js";
|
|
33
42
|
import {
|
|
34
43
|
missingCapabilities2
|
|
35
44
|
} from "./index-zpxk3fzd.js";
|
|
@@ -41,14 +50,16 @@ import {
|
|
|
41
50
|
isSnapshotPath2,
|
|
42
51
|
indexSnapshot2,
|
|
43
52
|
maskSnapshot2
|
|
44
|
-
} from "./index-
|
|
53
|
+
} from "./index-q2jbva7c.js";
|
|
45
54
|
import {
|
|
46
55
|
MAX_TYPED_TEXT2
|
|
47
|
-
} from "./index-
|
|
56
|
+
} from "./index-e7pgqd60.js";
|
|
48
57
|
import {
|
|
49
|
-
containsText2,
|
|
50
58
|
snapshotUrl2
|
|
51
|
-
} from "./index-
|
|
59
|
+
} from "./index-6m0chbhq.js";
|
|
60
|
+
import {
|
|
61
|
+
containsText2
|
|
62
|
+
} from "./index-z2v8prer.js";
|
|
52
63
|
import {
|
|
53
64
|
redactCredentials2
|
|
54
65
|
} from "./index-mgztm37r.js";
|
|
@@ -519,7 +530,15 @@ function healFailureCode(code) {
|
|
|
519
530
|
function isConsequence(value) {
|
|
520
531
|
return typeof value === "string" && UI_CONSEQUENCES2.some((consequence) => consequence === value);
|
|
521
532
|
}
|
|
522
|
-
var FLOW_ACTIONS = new Set([
|
|
533
|
+
var FLOW_ACTIONS = new Set([
|
|
534
|
+
"if",
|
|
535
|
+
"forEach",
|
|
536
|
+
"while",
|
|
537
|
+
"retryScope",
|
|
538
|
+
"set",
|
|
539
|
+
"log",
|
|
540
|
+
"call"
|
|
541
|
+
]);
|
|
523
542
|
function clipMessage(text) {
|
|
524
543
|
return redactCredentials2(text).slice(0, MAX_EVENT_MESSAGE2);
|
|
525
544
|
}
|
|
@@ -596,16 +615,28 @@ function typeMatches(type, value) {
|
|
|
596
615
|
async function runUiScript2(script, driver, options = {}) {
|
|
597
616
|
return new Interpreter(driver, options).run(script);
|
|
598
617
|
}
|
|
618
|
+
var DEFAULT_COMMAND_TIMEOUT_MS2 = 60000;
|
|
619
|
+
async function runDesktopUiScript2(script, driver, options = {}) {
|
|
620
|
+
return new Interpreter(driver, options, driver).run(script);
|
|
621
|
+
}
|
|
622
|
+
function webStep(step) {
|
|
623
|
+
return step;
|
|
624
|
+
}
|
|
625
|
+
function webTarget(target) {
|
|
626
|
+
return target;
|
|
627
|
+
}
|
|
599
628
|
|
|
600
629
|
class Interpreter {
|
|
601
630
|
driver;
|
|
602
631
|
options;
|
|
632
|
+
desk;
|
|
603
633
|
clock;
|
|
604
634
|
emitter;
|
|
605
635
|
startedAt;
|
|
606
636
|
pollMs;
|
|
607
637
|
test;
|
|
608
638
|
script;
|
|
639
|
+
webScript;
|
|
609
640
|
inputs = {};
|
|
610
641
|
variables = new Map;
|
|
611
642
|
results = {};
|
|
@@ -628,9 +659,10 @@ class Interpreter {
|
|
|
628
659
|
popupHandlers = [];
|
|
629
660
|
popupRejections = [];
|
|
630
661
|
inRepair = false;
|
|
631
|
-
constructor(driver, options) {
|
|
662
|
+
constructor(driver, options, desk) {
|
|
632
663
|
this.driver = driver;
|
|
633
664
|
this.options = options;
|
|
665
|
+
this.desk = desk;
|
|
634
666
|
this.clock = driver.clock ?? realClock2;
|
|
635
667
|
this.startedAt = this.clock.now();
|
|
636
668
|
const maxEvents = Math.min(MAX_EVENTS_LIMIT2, Math.max(1, Math.floor(options.maxEvents ?? DEFAULT_MAX_EVENTS2)));
|
|
@@ -760,7 +792,15 @@ class Interpreter {
|
|
|
760
792
|
}
|
|
761
793
|
preflight(input) {
|
|
762
794
|
try {
|
|
763
|
-
this.
|
|
795
|
+
if (this.desk) {
|
|
796
|
+
const script = parseDesktopUiScript2(input, { resolved: true });
|
|
797
|
+
this.checkDesk(this.desk, script);
|
|
798
|
+
this.script = script;
|
|
799
|
+
} else {
|
|
800
|
+
const script = parseUiScript2(input, { resolved: true });
|
|
801
|
+
this.script = script;
|
|
802
|
+
this.webScript = script;
|
|
803
|
+
}
|
|
764
804
|
} catch (error) {
|
|
765
805
|
if (error instanceof UiScriptError2) {
|
|
766
806
|
throw new UiRunError2("INVALID_SCRIPT", error.message, {
|
|
@@ -770,7 +810,7 @@ class Interpreter {
|
|
|
770
810
|
}
|
|
771
811
|
throw error;
|
|
772
812
|
}
|
|
773
|
-
const missing = missingCapabilities2(this.
|
|
813
|
+
const missing = this.webScript ? missingCapabilities2(this.webScript, this.driver.capabilities) : [];
|
|
774
814
|
const needed = this.test ? missing : missing.filter((id) => id !== "step:breakpoint");
|
|
775
815
|
if (needed.length > 0) {
|
|
776
816
|
throw new UiRunError2("UNSUPPORTED_ON_DESK", `The desk cannot run this script: it lacks ${needed.join(", ")}`, {
|
|
@@ -792,8 +832,9 @@ class Interpreter {
|
|
|
792
832
|
}
|
|
793
833
|
}
|
|
794
834
|
this.checkRange();
|
|
795
|
-
this.
|
|
796
|
-
|
|
835
|
+
if (!this.desk)
|
|
836
|
+
this.bindOverrides();
|
|
837
|
+
if (!this.desk && this.options.popupHandlers && this.options.popupHandlers.length > 0) {
|
|
797
838
|
const usable = usablePopupHandlers2(this.options.popupHandlers);
|
|
798
839
|
this.popupHandlers = usable.handlers;
|
|
799
840
|
this.popupRejections = usable.rejected;
|
|
@@ -803,6 +844,22 @@ class Interpreter {
|
|
|
803
844
|
this.variables.set(variable.name, variable.initial === undefined ? null : this.evaluateOrInvalid(variable.initial, `variables.${variable.name}`));
|
|
804
845
|
}
|
|
805
846
|
}
|
|
847
|
+
checkDesk(desk, script) {
|
|
848
|
+
let capabilities;
|
|
849
|
+
try {
|
|
850
|
+
capabilities = desk.deskCapabilities();
|
|
851
|
+
} catch {
|
|
852
|
+
throw new UiRunError2("DESK_UNAVAILABLE", "The desk did not report its capabilities");
|
|
853
|
+
}
|
|
854
|
+
const check = checkDesktopScriptForDesk2(script, capabilities, {
|
|
855
|
+
...this.options.allowShell === undefined ? {} : { allowShell: this.options.allowShell },
|
|
856
|
+
...this.options.schemaHash === undefined ? {} : { schemaHash: this.options.schemaHash }
|
|
857
|
+
});
|
|
858
|
+
if (check.ok)
|
|
859
|
+
return;
|
|
860
|
+
const listed = check.code === "UNSUPPORTED_ON_DESK" ? { shortfalls: check.shortfalls.slice(0, 20) } : { steps: check.steps.slice(0, 20) };
|
|
861
|
+
throw new UiRunError2(check.code, check.message, listed);
|
|
862
|
+
}
|
|
806
863
|
bindOverrides() {
|
|
807
864
|
const overrides = this.options.targetOverrides;
|
|
808
865
|
if (!overrides)
|
|
@@ -813,7 +870,7 @@ class Interpreter {
|
|
|
813
870
|
for (const [stepId, value] of Object.entries(overrides)) {
|
|
814
871
|
const step = steps.get(stepId);
|
|
815
872
|
const parsed = uiTargetSchema2.safeParse(value);
|
|
816
|
-
if (!step || !HEALABLE_ACTIONS2.has(step.action) || !this.primaryRef(step) || !parsed.success) {
|
|
873
|
+
if (!step || !HEALABLE_ACTIONS2.has(webStep(step).action) || !this.primaryRef(step) || !parsed.success) {
|
|
817
874
|
throw new UiRunError2("INVALID_SCRIPT", "A target override names no step it can apply to, or is not a valid target", {
|
|
818
875
|
targetOverride: stepId.slice(0, 64)
|
|
819
876
|
});
|
|
@@ -933,7 +990,11 @@ class Interpreter {
|
|
|
933
990
|
stepId: step.id,
|
|
934
991
|
action: step.action,
|
|
935
992
|
attempt,
|
|
936
|
-
...this.options.signal && !this.inCleanup ? { signal: this.options.signal } : {}
|
|
993
|
+
...this.options.signal && !this.inCleanup ? { signal: this.options.signal } : {},
|
|
994
|
+
...this.desk ? {
|
|
995
|
+
inputMethod: step.inputMethod ?? this.script.settings?.inputMethod ?? "auto",
|
|
996
|
+
...step.timeoutMs === undefined ? {} : { timeoutMs: step.timeoutMs }
|
|
997
|
+
} : {}
|
|
937
998
|
};
|
|
938
999
|
}
|
|
939
1000
|
async emit(draft) {
|
|
@@ -1185,10 +1246,10 @@ class Interpreter {
|
|
|
1185
1246
|
};
|
|
1186
1247
|
}
|
|
1187
1248
|
canRepair(step, path, failure) {
|
|
1188
|
-
if (this.inRepair || this.driver.replay || failure.stepPath !== path || !failure.primary)
|
|
1249
|
+
if (this.desk || this.inRepair || this.driver.replay || failure.stepPath !== path || !failure.primary)
|
|
1189
1250
|
return false;
|
|
1190
1251
|
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);
|
|
1252
|
+
const heal = this.options.onTargetNotFound !== undefined && HEAL_CODES.has(failure.code) && HEALABLE_ACTIONS2.has(webStep(step).action);
|
|
1192
1253
|
return popups || heal;
|
|
1193
1254
|
}
|
|
1194
1255
|
async repair(step, path, attempt, failure) {
|
|
@@ -1325,13 +1386,14 @@ class Interpreter {
|
|
|
1325
1386
|
});
|
|
1326
1387
|
});
|
|
1327
1388
|
}
|
|
1328
|
-
async heal(
|
|
1389
|
+
async heal(runStep, path, attempt, failure) {
|
|
1390
|
+
const step = webStep(runStep);
|
|
1329
1391
|
const hook = this.options.onTargetNotFound;
|
|
1330
|
-
const ref =
|
|
1392
|
+
const ref = "target" in step ? step.target : undefined;
|
|
1331
1393
|
if (!hook || !ref || !HEALABLE_ACTIONS2.has(step.action) || this.healTried.has(step.id))
|
|
1332
1394
|
return { failure };
|
|
1333
1395
|
this.healTried.add(step.id);
|
|
1334
|
-
const failedTarget = this.stepTarget(step, ref);
|
|
1396
|
+
const failedTarget = webTarget(this.stepTarget(step, ref));
|
|
1335
1397
|
const context = this.context(step, path, attempt);
|
|
1336
1398
|
let snapshot = null;
|
|
1337
1399
|
let url = "";
|
|
@@ -1345,7 +1407,7 @@ class Interpreter {
|
|
|
1345
1407
|
if (!snapshot)
|
|
1346
1408
|
return { failure: this.withHeal(failure, { outcome: "unavailable", reason: "NO_SNAPSHOT" }) };
|
|
1347
1409
|
const masked = maskSnapshot2(snapshot, { maskedPaths: this.options.healing?.maskedPaths ?? [] });
|
|
1348
|
-
const elements = this.
|
|
1410
|
+
const elements = this.webScript?.elements ?? {};
|
|
1349
1411
|
const element = "element" in ref ? elements[ref.element] : undefined;
|
|
1350
1412
|
const request = {
|
|
1351
1413
|
stepPath: path,
|
|
@@ -1793,11 +1855,35 @@ class Interpreter {
|
|
|
1793
1855
|
this.freshScreen = true;
|
|
1794
1856
|
return {};
|
|
1795
1857
|
}
|
|
1796
|
-
case "focusWindow":
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1858
|
+
case "focusWindow": {
|
|
1859
|
+
const desk = this.desk;
|
|
1860
|
+
if (!desk) {
|
|
1861
|
+
return this.fail(step, path, {
|
|
1862
|
+
code: "UNSUPPORTED_ON_DESK",
|
|
1863
|
+
message: "A web desk cannot focus a desktop window"
|
|
1864
|
+
});
|
|
1865
|
+
}
|
|
1866
|
+
await this.call(step, path, () => desk.focusWindow(step.app, step.title, context()));
|
|
1867
|
+
this.freshScreen = true;
|
|
1868
|
+
return {};
|
|
1869
|
+
}
|
|
1870
|
+
case "openApp":
|
|
1871
|
+
case "closeApp":
|
|
1872
|
+
case "windowState":
|
|
1873
|
+
case "listWindows":
|
|
1874
|
+
case "invoke":
|
|
1875
|
+
case "setValue":
|
|
1876
|
+
case "toggle":
|
|
1877
|
+
case "expand":
|
|
1878
|
+
case "get":
|
|
1879
|
+
case "runCommand":
|
|
1880
|
+
case "fileRead":
|
|
1881
|
+
case "fileWrite":
|
|
1882
|
+
case "fileCopy":
|
|
1883
|
+
case "fileList":
|
|
1884
|
+
case "fileDelete":
|
|
1885
|
+
case "releaseRobot":
|
|
1886
|
+
return this.performDesktop(step, path, attempt);
|
|
1801
1887
|
case "if": {
|
|
1802
1888
|
if (enteringForRange) {
|
|
1803
1889
|
const inElse = this.options.startAt?.startsWith(`${path}.else.`) === true;
|
|
@@ -1884,6 +1970,100 @@ class Interpreter {
|
|
|
1884
1970
|
});
|
|
1885
1971
|
}
|
|
1886
1972
|
}
|
|
1973
|
+
async performDesktop(step, path, attempt) {
|
|
1974
|
+
const desk = this.desk;
|
|
1975
|
+
if (!desk)
|
|
1976
|
+
return this.fail(step, path, { code: "UNSUPPORTED_ON_DESK", message: "A web desk cannot run desktop steps" });
|
|
1977
|
+
const context = () => this.context(step, path, attempt);
|
|
1978
|
+
const pattern = (ref, action) => this.onTarget(step, path, attempt, ref, (target, ctx) => desk.pattern(target, action, ctx));
|
|
1979
|
+
switch (step.action) {
|
|
1980
|
+
case "openApp": {
|
|
1981
|
+
const args = step.args?.map((arg) => this.text(step, path, arg));
|
|
1982
|
+
const windows = await this.call(step, path, () => desk.openApp(step.app, {
|
|
1983
|
+
...args === undefined ? {} : { args },
|
|
1984
|
+
...step.waitForTitle === undefined ? {} : { waitForTitle: step.waitForTitle }
|
|
1985
|
+
}, context()));
|
|
1986
|
+
this.freshScreen = true;
|
|
1987
|
+
return { value: toUiValue2(windows) };
|
|
1988
|
+
}
|
|
1989
|
+
case "closeApp":
|
|
1990
|
+
await this.call(step, path, () => desk.closeApp(step.app, step.title, context()));
|
|
1991
|
+
this.freshScreen = true;
|
|
1992
|
+
return {};
|
|
1993
|
+
case "windowState": {
|
|
1994
|
+
const windows = await this.call(step, path, () => desk.windowState(step.app, step.title, step.state, context()));
|
|
1995
|
+
return { value: toUiValue2(windows) };
|
|
1996
|
+
}
|
|
1997
|
+
case "listWindows": {
|
|
1998
|
+
const windows = await this.call(step, path, () => desk.listWindows(step.app, context()));
|
|
1999
|
+
return { value: toUiValue2(windows) };
|
|
2000
|
+
}
|
|
2001
|
+
case "invoke":
|
|
2002
|
+
return pattern(step.target, { kind: "invoke" });
|
|
2003
|
+
case "setValue": {
|
|
2004
|
+
const value = this.text(step, path, step.value);
|
|
2005
|
+
if (value.length > MAX_DESK_SET_VALUE2) {
|
|
2006
|
+
this.fail(step, path, {
|
|
2007
|
+
code: "ACTION_FAILED",
|
|
2008
|
+
message: `A set value step sets at most ${MAX_DESK_SET_VALUE2} characters`,
|
|
2009
|
+
detail: { problem: "INVALID_ACTION" }
|
|
2010
|
+
});
|
|
2011
|
+
}
|
|
2012
|
+
const outcome = await pattern(step.target, { kind: "setValue", value });
|
|
2013
|
+
return outcome.resolvedBy ? { resolvedBy: outcome.resolvedBy } : {};
|
|
2014
|
+
}
|
|
2015
|
+
case "toggle":
|
|
2016
|
+
return pattern(step.target, { kind: "toggle", ...step.state === undefined ? {} : { state: step.state } });
|
|
2017
|
+
case "expand":
|
|
2018
|
+
return pattern(step.target, { kind: "expand", ...step.state === undefined ? {} : { state: step.state } });
|
|
2019
|
+
case "get":
|
|
2020
|
+
return pattern(step.target, {
|
|
2021
|
+
kind: "get",
|
|
2022
|
+
what: step.what,
|
|
2023
|
+
...step.attributes === undefined ? {} : { attributes: step.attributes }
|
|
2024
|
+
});
|
|
2025
|
+
case "runCommand": {
|
|
2026
|
+
const command = this.text(step, path, step.command);
|
|
2027
|
+
const timeoutMs = step.timeoutMs ?? DEFAULT_COMMAND_TIMEOUT_MS2;
|
|
2028
|
+
const output = await this.call(step, path, () => desk.runCommand(command, { timeoutMs, ...step.cwd === undefined ? {} : { cwd: step.cwd } }, context()));
|
|
2029
|
+
return { value: String(output).slice(0, MAX_PAGE_TEXT2) };
|
|
2030
|
+
}
|
|
2031
|
+
case "fileRead": {
|
|
2032
|
+
const filePath = this.text(step, path, step.path);
|
|
2033
|
+
const maxBytes = step.maxBytes ?? DEFAULT_DESK_FILE_BYTES2;
|
|
2034
|
+
const content = await this.call(step, path, () => desk.readFile(filePath, maxBytes, context()));
|
|
2035
|
+
return { value: String(content) };
|
|
2036
|
+
}
|
|
2037
|
+
case "fileWrite": {
|
|
2038
|
+
const filePath = this.text(step, path, step.path);
|
|
2039
|
+
const content = this.text(step, path, step.content);
|
|
2040
|
+
await this.call(step, path, () => desk.writeFile(filePath, content, context()));
|
|
2041
|
+
return {};
|
|
2042
|
+
}
|
|
2043
|
+
case "fileCopy": {
|
|
2044
|
+
const from = this.text(step, path, step.from);
|
|
2045
|
+
const to = this.text(step, path, step.to);
|
|
2046
|
+
const content = String(await this.call(step, path, () => desk.readFile(from, MAX_DESK_FILE_BYTES2, context())));
|
|
2047
|
+
if (new TextEncoder().encode(content).byteLength > MAX_DESK_FILE_BYTES2 - 4) {
|
|
2048
|
+
this.fail(step, path, {
|
|
2049
|
+
code: "ACTION_FAILED",
|
|
2050
|
+
message: `A copy step copies text files under ${MAX_DESK_FILE_BYTES2 / (1024 * 1024)} MiB`,
|
|
2051
|
+
detail: { problem: "FILE_TOO_LARGE" }
|
|
2052
|
+
});
|
|
2053
|
+
}
|
|
2054
|
+
await this.call(step, path, () => desk.writeFile(to, content, context()));
|
|
2055
|
+
return {};
|
|
2056
|
+
}
|
|
2057
|
+
case "fileList":
|
|
2058
|
+
case "fileDelete":
|
|
2059
|
+
return this.fail(step, path, {
|
|
2060
|
+
code: "UNSUPPORTED_ON_DESK",
|
|
2061
|
+
message: `Desk contract v3 has no action for ${step.action}`
|
|
2062
|
+
});
|
|
2063
|
+
default:
|
|
2064
|
+
return {};
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
1887
2067
|
async typeText(step, path, attempt) {
|
|
1888
2068
|
if (step.text === undefined)
|
|
1889
2069
|
return {};
|
|
@@ -2090,11 +2270,16 @@ class Interpreter {
|
|
|
2090
2270
|
return {};
|
|
2091
2271
|
}
|
|
2092
2272
|
const wanted = this.text(step, path, step.text);
|
|
2093
|
-
const present = await this.waitUntil(step, path, this.waitFor(step),
|
|
2273
|
+
const present = await this.waitUntil(step, path, this.waitFor(step), (context) => this.showsText(wanted, context), attempt);
|
|
2094
2274
|
if (!present)
|
|
2095
2275
|
this.fail(step, path, { code: "WAIT_TIMEOUT", message: "The text did not appear within the wait" });
|
|
2096
2276
|
return {};
|
|
2097
2277
|
}
|
|
2278
|
+
async showsText(text, context) {
|
|
2279
|
+
if (this.desk)
|
|
2280
|
+
return this.desk.containsText(text, context);
|
|
2281
|
+
return containsText2(await this.driver.pageText(context), text);
|
|
2282
|
+
}
|
|
2098
2283
|
async waitUntil(step, path, waitMs, condition, attempt) {
|
|
2099
2284
|
const context = this.context(step, path, attempt);
|
|
2100
2285
|
const start = this.clock.now();
|
|
@@ -2123,7 +2308,7 @@ class Interpreter {
|
|
|
2123
2308
|
case "urlContains":
|
|
2124
2309
|
return (await this.driver.currentUrl(context)).includes(this.text(step, path, verify.value));
|
|
2125
2310
|
case "textPresent":
|
|
2126
|
-
return
|
|
2311
|
+
return this.showsText(this.text(step, path, verify.text), context);
|
|
2127
2312
|
case "valueEquals": {
|
|
2128
2313
|
const read = await this.driver.read(this.targetOf(verify.target), { kind: "value" }, context);
|
|
2129
2314
|
if (!read.ok)
|
|
@@ -2144,4 +2329,4 @@ class Interpreter {
|
|
|
2144
2329
|
}
|
|
2145
2330
|
}
|
|
2146
2331
|
|
|
2147
|
-
export { MAX_VALUE_TEXT2, MAX_VALUE_ITEMS2, toUiValue2, readPath2, truthy2, valuesEqual2, toText2, toNumber2, evaluateExpression2, UI_RUN_EVENT_KINDS2, DEFAULT_MAX_EVENTS2, MAX_STEP_LOG_ENTRIES2, MAX_EVENT_MESSAGE2, DEFAULT_FIRST_WAIT_MS2, DEFAULT_WAIT_MS2, DEFAULT_RETRY_DELAY_MS2, DEFAULT_POLL_INTERVAL_MS2, MAX_EVENTS_LIMIT2, MAX_PAGE_TEXT2, DEFAULT_LIST_ITEMS2, runUiScript2 };
|
|
2332
|
+
export { MAX_VALUE_TEXT2, MAX_VALUE_ITEMS2, toUiValue2, readPath2, truthy2, valuesEqual2, toText2, toNumber2, evaluateExpression2, UI_RUN_EVENT_KINDS2, DEFAULT_MAX_EVENTS2, MAX_STEP_LOG_ENTRIES2, MAX_EVENT_MESSAGE2, DEFAULT_FIRST_WAIT_MS2, DEFAULT_WAIT_MS2, DEFAULT_RETRY_DELAY_MS2, DEFAULT_POLL_INTERVAL_MS2, MAX_EVENTS_LIMIT2, MAX_PAGE_TEXT2, DEFAULT_LIST_ITEMS2, runUiScript2, DEFAULT_COMMAND_TIMEOUT_MS2, runDesktopUiScript2 };
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
parentAcrossShadow2,
|
|
4
4
|
isElementEnabled2,
|
|
5
5
|
isSensitiveElement2
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-reef7e8m.js";
|
|
7
7
|
import {
|
|
8
8
|
sameText2
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-z2v8prer.js";
|
|
10
10
|
|
|
11
11
|
// src/dom-runtime/actions.ts
|
|
12
12
|
var MAX_READ_TEXT2 = 65536;
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import {
|
|
2
|
+
roleOf2,
|
|
3
|
+
accessibleName2,
|
|
4
|
+
visibleText2,
|
|
5
|
+
matchesRoleAndName2,
|
|
6
|
+
isElementVisible2,
|
|
7
|
+
elementRect2,
|
|
8
|
+
elementsUnder2
|
|
9
|
+
} from "./index-reef7e8m.js";
|
|
10
|
+
import {
|
|
11
|
+
MAX_COMPARED_TEXT2,
|
|
12
|
+
normaliseText2,
|
|
13
|
+
sameText2,
|
|
14
|
+
containsText2,
|
|
15
|
+
textSimilarity2
|
|
16
|
+
} from "./index-z2v8prer.js";
|
|
17
|
+
|
|
18
|
+
// src/target/types.ts
|
|
19
|
+
var WEB_TARGET_ERROR_CODES2 = ["ELEMENT_NOT_FOUND", "ELEMENT_AMBIGUOUS", "ELEMENT_NOT_INTERACTABLE"];
|
|
20
|
+
var MAX_CANDIDATES2 = 5;
|
|
21
|
+
var MAX_CANDIDATE_NAME2 = 200;
|
|
22
|
+
|
|
23
|
+
// src/target/methods.ts
|
|
24
|
+
var DEFAULT_FUZZY_THRESHOLD2 = 0.8;
|
|
25
|
+
var FUZZY_MARGIN2 = 0.05;
|
|
26
|
+
var ANCHOR_MARGIN_PX2 = 4;
|
|
27
|
+
var MAX_XPATH_RESULTS2 = 1000;
|
|
28
|
+
var EDGE_SLACK_PX = 2;
|
|
29
|
+
var INTERACTIVE_ROLES2 = new Set([
|
|
30
|
+
"button",
|
|
31
|
+
"checkbox",
|
|
32
|
+
"combobox",
|
|
33
|
+
"link",
|
|
34
|
+
"listbox",
|
|
35
|
+
"menuitem",
|
|
36
|
+
"menuitemcheckbox",
|
|
37
|
+
"menuitemradio",
|
|
38
|
+
"option",
|
|
39
|
+
"radio",
|
|
40
|
+
"searchbox",
|
|
41
|
+
"slider",
|
|
42
|
+
"spinbutton",
|
|
43
|
+
"switch",
|
|
44
|
+
"tab",
|
|
45
|
+
"textbox",
|
|
46
|
+
"treeitem"
|
|
47
|
+
]);
|
|
48
|
+
var ATTRIBUTE_NAME = /^[A-Za-z_][\w:.-]{0,127}$/;
|
|
49
|
+
function documentOf(root) {
|
|
50
|
+
return root.nodeType === 9 ? root : root.ownerDocument;
|
|
51
|
+
}
|
|
52
|
+
function matchRole(method, context) {
|
|
53
|
+
const elements = elementsUnder2(context.root).filter((element) => matchesRoleAndName2(element, method.role, method.name, context.probe));
|
|
54
|
+
return { kind: "list", elements, ...method.nth !== undefined ? { nth: method.nth } : {} };
|
|
55
|
+
}
|
|
56
|
+
function matchCss(selector, context) {
|
|
57
|
+
try {
|
|
58
|
+
return { kind: "list", elements: Array.from(context.root.querySelectorAll(selector)) };
|
|
59
|
+
} catch {
|
|
60
|
+
return { kind: "invalid" };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function matchTestId(method, context) {
|
|
64
|
+
const attribute = method.attribute ?? "data-testid";
|
|
65
|
+
if (!ATTRIBUTE_NAME.test(attribute))
|
|
66
|
+
return { kind: "invalid" };
|
|
67
|
+
const elements = elementsUnder2(context.root).filter((element) => element.getAttribute(attribute) === method.value);
|
|
68
|
+
return { kind: "list", elements };
|
|
69
|
+
}
|
|
70
|
+
function isUnder(root, node) {
|
|
71
|
+
if (root.nodeType === 9)
|
|
72
|
+
return node.ownerDocument === root && node.getRootNode() === root;
|
|
73
|
+
return root === node || root.contains(node);
|
|
74
|
+
}
|
|
75
|
+
function matchXPath(method, context) {
|
|
76
|
+
const document = documentOf(context.root);
|
|
77
|
+
if (typeof document.evaluate !== "function")
|
|
78
|
+
return { kind: "unsupported" };
|
|
79
|
+
let result;
|
|
80
|
+
try {
|
|
81
|
+
result = document.evaluate(method.xpath, context.root, null, 7, null);
|
|
82
|
+
} catch {
|
|
83
|
+
return { kind: "invalid" };
|
|
84
|
+
}
|
|
85
|
+
const elements = [];
|
|
86
|
+
const length = Math.min(result.snapshotLength, MAX_XPATH_RESULTS2);
|
|
87
|
+
for (let index = 0;index < length; index += 1) {
|
|
88
|
+
const node = result.snapshotItem(index);
|
|
89
|
+
if (node && node.nodeType === 1 && isUnder(context.root, node))
|
|
90
|
+
elements.push(node);
|
|
91
|
+
}
|
|
92
|
+
return { kind: "list", elements, ...result.snapshotLength > MAX_XPATH_RESULTS2 ? { overflow: true } : {} };
|
|
93
|
+
}
|
|
94
|
+
function lengthAllows(name, wantedLength, threshold) {
|
|
95
|
+
const length = Math.min(normaliseText2(name).length, MAX_COMPARED_TEXT2);
|
|
96
|
+
const longest = Math.max(length, wantedLength);
|
|
97
|
+
return longest > 0 && Math.abs(length - wantedLength) <= (1 - threshold) * longest;
|
|
98
|
+
}
|
|
99
|
+
function matchFuzzy(method, context) {
|
|
100
|
+
const threshold = Math.min(1, Math.max(0.5, method.threshold ?? DEFAULT_FUZZY_THRESHOLD2));
|
|
101
|
+
const wantedRole = method.role?.trim().toLowerCase();
|
|
102
|
+
const wantedLength = Math.min(normaliseText2(method.name).length, MAX_COMPARED_TEXT2);
|
|
103
|
+
const scored = [];
|
|
104
|
+
for (const element of elementsUnder2(context.root)) {
|
|
105
|
+
const role = roleOf2(element);
|
|
106
|
+
if (wantedRole ? role !== wantedRole : role === "")
|
|
107
|
+
continue;
|
|
108
|
+
const name = accessibleName2(element, context.probe);
|
|
109
|
+
if (!lengthAllows(name, wantedLength, threshold))
|
|
110
|
+
continue;
|
|
111
|
+
const score = textSimilarity2(name, method.name);
|
|
112
|
+
if (score >= threshold)
|
|
113
|
+
scored.push({ element, score });
|
|
114
|
+
}
|
|
115
|
+
return { kind: "ranked", scored, margin: FUZZY_MARGIN2 };
|
|
116
|
+
}
|
|
117
|
+
function innermostByText(context, matches) {
|
|
118
|
+
const hits = elementsUnder2(context.root).filter((element) => matches(visibleText2(element, context.probe)));
|
|
119
|
+
const keep = context.keep ?? (() => true);
|
|
120
|
+
const innerHits = hits.filter(keep);
|
|
121
|
+
return hits.filter((element) => !innerHits.some((inner) => inner !== element && element.contains(inner)));
|
|
122
|
+
}
|
|
123
|
+
function matchText(method, context) {
|
|
124
|
+
const test = method.exact ? (text) => sameText2(text, method.text) : (text) => containsText2(text, method.text);
|
|
125
|
+
if (normaliseText2(method.text).length === 0)
|
|
126
|
+
return { kind: "list", elements: [] };
|
|
127
|
+
return {
|
|
128
|
+
kind: "list",
|
|
129
|
+
elements: innermostByText(context, test),
|
|
130
|
+
...method.nth !== undefined ? { nth: method.nth } : {}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function labelText(text) {
|
|
134
|
+
return normaliseText2(text).replace(/[\s:*]+$/u, "");
|
|
135
|
+
}
|
|
136
|
+
function anchorElements(anchor, context) {
|
|
137
|
+
const found = anchor.kind === "role" ? elementsUnder2(context.root).filter((element) => matchesRoleAndName2(element, anchor.role, anchor.name, context.probe)) : innermostByText(context, (text) => labelText(text) === labelText(anchor.text) && labelText(text) !== "");
|
|
138
|
+
return found.filter((element) => isElementVisible2(element, context.probe));
|
|
139
|
+
}
|
|
140
|
+
function candidateElements(method, context, anchors) {
|
|
141
|
+
const wantedRole = method.role?.trim().toLowerCase();
|
|
142
|
+
return elementsUnder2(context.root).filter((element) => {
|
|
143
|
+
const role = roleOf2(element);
|
|
144
|
+
if (wantedRole ? role !== wantedRole : !INTERACTIVE_ROLES2.has(role))
|
|
145
|
+
return false;
|
|
146
|
+
return !anchors.some((anchor) => anchor === element || element.contains(anchor));
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
var HEADING_TAGS = new Set(["h1", "h2", "h3", "h4", "h5", "h6", "legend", "caption", "figcaption", "summary", "dt"]);
|
|
150
|
+
function isHeadingLike(element) {
|
|
151
|
+
return HEADING_TAGS.has(element.localName) || roleOf2(element) === "heading";
|
|
152
|
+
}
|
|
153
|
+
function headingOf(anchor) {
|
|
154
|
+
for (let current = anchor;current; current = current.parentElement) {
|
|
155
|
+
if (isHeadingLike(current))
|
|
156
|
+
return current;
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
function matchInside(method, context, anchors) {
|
|
161
|
+
const candidates = candidateElements(method, context, anchors);
|
|
162
|
+
const inside = new Set;
|
|
163
|
+
for (const anchor of anchors) {
|
|
164
|
+
const heading = headingOf(anchor);
|
|
165
|
+
const container = heading?.parentElement ?? anchor;
|
|
166
|
+
for (const candidate of candidates)
|
|
167
|
+
if (container.contains(candidate))
|
|
168
|
+
inside.add(candidate);
|
|
169
|
+
}
|
|
170
|
+
return { kind: "list", elements: candidates.filter((candidate) => inside.has(candidate)) };
|
|
171
|
+
}
|
|
172
|
+
function overlaps(aStart, aEnd, bStart, bEnd) {
|
|
173
|
+
return aStart < bEnd && bStart < aEnd;
|
|
174
|
+
}
|
|
175
|
+
function relationDistance2(relation, anchor, element) {
|
|
176
|
+
const aRight = anchor.x + anchor.width;
|
|
177
|
+
const aBottom = anchor.y + anchor.height;
|
|
178
|
+
const eRight = element.x + element.width;
|
|
179
|
+
const eBottom = element.y + element.height;
|
|
180
|
+
const sameRow = overlaps(anchor.y, aBottom, element.y, eBottom);
|
|
181
|
+
const sameColumn = overlaps(anchor.x, aRight, element.x, eRight);
|
|
182
|
+
switch (relation) {
|
|
183
|
+
case "rightOf":
|
|
184
|
+
return sameRow && element.x >= aRight - EDGE_SLACK_PX ? Math.max(0, element.x - aRight) : null;
|
|
185
|
+
case "leftOf":
|
|
186
|
+
return sameRow && eRight <= anchor.x + EDGE_SLACK_PX ? Math.max(0, anchor.x - eRight) : null;
|
|
187
|
+
case "below":
|
|
188
|
+
return sameColumn && element.y >= aBottom - EDGE_SLACK_PX ? Math.max(0, element.y - aBottom) : null;
|
|
189
|
+
case "above":
|
|
190
|
+
return sameColumn && eBottom <= anchor.y + EDGE_SLACK_PX ? Math.max(0, anchor.y - eBottom) : null;
|
|
191
|
+
case "sameRow":
|
|
192
|
+
return sameRow ? Math.abs(element.x + element.width / 2 - (anchor.x + anchor.width / 2)) : null;
|
|
193
|
+
default:
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function hasArea(rect) {
|
|
198
|
+
return rect.width > 0 && rect.height > 0;
|
|
199
|
+
}
|
|
200
|
+
function matchAnchor(method, context) {
|
|
201
|
+
const anchors = anchorElements(method.anchor, context);
|
|
202
|
+
if (anchors.length === 0)
|
|
203
|
+
return { kind: "list", elements: [] };
|
|
204
|
+
if (method.relation === "inside")
|
|
205
|
+
return matchInside(method, context, anchors);
|
|
206
|
+
const anchorRects = anchors.map((anchor) => elementRect2(anchor, context.probe)).filter(hasArea);
|
|
207
|
+
if (anchorRects.length === 0)
|
|
208
|
+
return { kind: "unsupported" };
|
|
209
|
+
const scored = [];
|
|
210
|
+
for (const element of candidateElements(method, context, anchors)) {
|
|
211
|
+
const rect = elementRect2(element, context.probe);
|
|
212
|
+
if (!hasArea(rect))
|
|
213
|
+
continue;
|
|
214
|
+
let best = null;
|
|
215
|
+
for (const anchorRect of anchorRects) {
|
|
216
|
+
const distance = relationDistance2(method.relation, anchorRect, rect);
|
|
217
|
+
if (distance !== null && (best === null || distance < best))
|
|
218
|
+
best = distance;
|
|
219
|
+
}
|
|
220
|
+
if (best !== null)
|
|
221
|
+
scored.push({ element, score: -best });
|
|
222
|
+
}
|
|
223
|
+
return { kind: "ranked", scored, margin: ANCHOR_MARGIN_PX2 };
|
|
224
|
+
}
|
|
225
|
+
function matchMethod2(method, context) {
|
|
226
|
+
switch (method.kind) {
|
|
227
|
+
case "role":
|
|
228
|
+
return matchRole(method, context);
|
|
229
|
+
case "css":
|
|
230
|
+
return matchCss(method.selector, context);
|
|
231
|
+
case "testId":
|
|
232
|
+
return matchTestId(method, context);
|
|
233
|
+
case "xpath":
|
|
234
|
+
return matchXPath(method, context);
|
|
235
|
+
case "fuzzy":
|
|
236
|
+
return matchFuzzy(method, context);
|
|
237
|
+
case "anchor":
|
|
238
|
+
return matchAnchor(method, context);
|
|
239
|
+
case "text":
|
|
240
|
+
return matchText(method, context);
|
|
241
|
+
default:
|
|
242
|
+
return { kind: "unsupported" };
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export { WEB_TARGET_ERROR_CODES2, MAX_CANDIDATES2, MAX_CANDIDATE_NAME2, DEFAULT_FUZZY_THRESHOLD2, FUZZY_MARGIN2, ANCHOR_MARGIN_PX2, MAX_XPATH_RESULTS2, INTERACTIVE_ROLES2, isHeadingLike, relationDistance2, matchMethod2 };
|