@burdenoff/ui-engine 0.0.0-stage → 2026.1127.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/LICENSE +25 -0
- package/README.md +97 -2
- package/dist/capture.d.ts +118 -0
- package/dist/capture.js +14 -0
- package/dist/index-3v887c75.js +52 -0
- package/dist/index-c6pmt2rg.js +213 -0
- package/dist/index-n5amgh31.js +210 -0
- package/dist/index-phd8yhyg.js +224 -0
- package/dist/index-tqffkt91.js +1986 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +234 -0
- package/dist/recording.d.ts +214 -0
- package/dist/recording.js +28 -0
- package/dist/redact-credentials.d.ts +39 -0
- package/dist/replay.d.ts +144 -0
- package/dist/replay.js +20 -0
- package/dist/resolve.d.ts +43 -0
- package/dist/resolve.js +10 -0
- package/dist/script/adapters/browser-action-contract.d.ts +22 -0
- package/dist/script/adapters/from-browser-action.d.ts +7 -0
- package/dist/script/adapters/from-remote-browser.d.ts +7 -0
- package/dist/script/adapters/recording.d.ts +25 -0
- package/dist/script/adapters/to-browser-action.d.ts +8 -0
- package/dist/script/canonical.d.ts +6 -0
- package/dist/script/capabilities.d.ts +29 -0
- package/dist/script/describe.d.ts +83 -0
- package/dist/script/fingerprint.d.ts +9 -0
- package/dist/script/hash.d.ts +3 -0
- package/dist/script/index.d.ts +22 -0
- package/dist/script/json-schema.d.ts +4 -0
- package/dist/script/limits.d.ts +61 -0
- package/dist/script/parse.d.ts +31 -0
- package/dist/script/schema.d.ts +87 -0
- package/dist/script/types.d.ts +489 -0
- package/dist/script/walk.d.ts +29 -0
- package/dist/script.d.ts +2 -0
- package/dist/script.js +175 -0
- package/package.json +101 -4
- package/schema/ui-script-v1.schema.json +8199 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-resolve a saved step's target on the current screen (BOFF-16214).
|
|
3
|
+
*
|
|
4
|
+
* Copied from wspace-botmanor-svc `src/modules/stewards/teach/resolve.ts` at
|
|
5
|
+
* 6558d8b (BOFF-16873). One change: `readSnapshotNodes` also reads the
|
|
6
|
+
* `{ elements }` list that the browser desk (`vibe-plugin-desk-browser`
|
|
7
|
+
* `PageSnapshot`) returns. The Stewards copy reads only an array or `.nodes`,
|
|
8
|
+
* so against the real browser desk every targeted step finds 0 nodes.
|
|
9
|
+
*
|
|
10
|
+
* A desk snapshot (contract 2 `snapshot`) is an accessibility tree flattened to
|
|
11
|
+
* nodes with a ref, a role and a label; desktop desks add the app and window.
|
|
12
|
+
* A recorded target matches a node when its role and label are equal (case and
|
|
13
|
+
* whitespace aside) and, when the recording names them, the app and window are
|
|
14
|
+
* equal too. With several equal matches, the recorded `nth` picks one.
|
|
15
|
+
*
|
|
16
|
+
* No match, or fewer matches than `nth` needs, means the screen changed: the
|
|
17
|
+
* step falls back to the model. There is no fuzzy matching on purpose: a
|
|
18
|
+
* replayed click on the wrong element is worse than one model call.
|
|
19
|
+
*
|
|
20
|
+
* Snapshot content is untrusted page data. It is only compared here; it never
|
|
21
|
+
* becomes an instruction.
|
|
22
|
+
*/
|
|
23
|
+
import type { RecordedTarget } from './recording.js';
|
|
24
|
+
export interface SnapshotNode {
|
|
25
|
+
ref: string;
|
|
26
|
+
role: string;
|
|
27
|
+
name: string;
|
|
28
|
+
app?: string;
|
|
29
|
+
window?: string;
|
|
30
|
+
}
|
|
31
|
+
/** Most nodes kept from one snapshot (they are stored in the run checkpoint). */
|
|
32
|
+
export declare const MAX_SNAPSHOT_NODES = 2000;
|
|
33
|
+
/** The nodes of a desk snapshot, read leniently: anything that is not a node is skipped. */
|
|
34
|
+
export declare function readSnapshotNodes(snapshot: unknown): SnapshotNode[];
|
|
35
|
+
export type ResolveOutcome = {
|
|
36
|
+
resolved: true;
|
|
37
|
+
ref: string;
|
|
38
|
+
} | {
|
|
39
|
+
resolved: false;
|
|
40
|
+
reason: 'no-snapshot' | 'not-found' | 'fewer-matches';
|
|
41
|
+
};
|
|
42
|
+
/** The ref of the recorded target on this screen, or why it cannot be found. */
|
|
43
|
+
export declare function resolveTarget(target: RecordedTarget, nodes: readonly SnapshotNode[] | null): ResolveOutcome;
|
package/dist/resolve.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The legacy Run in Browser step contract, mirrored from wspace-workflow-svc
|
|
3
|
+
* `src/modules/runs/services/browser/browser-contract.ts` (the 14 actions, at
|
|
4
|
+
* most 100 steps, at most 256 KB) and fluidgrids-workers
|
|
5
|
+
* `src/internalnodes/services/browser-action.ts` (each action's fields).
|
|
6
|
+
* `tests/fixtures/browser-contract.json` pins the service's list, so a change
|
|
7
|
+
* there fails this package's tests until the mirror follows.
|
|
8
|
+
*/
|
|
9
|
+
/** The step actions a 0.3.0 extension runs, in the order the service lists them. */
|
|
10
|
+
export declare const BROWSER_STEP_ACTIONS: readonly ["navigate", "waitFor", "click", "type", "select", "check", "pressKey", "scroll", "extract", "extractList", "getPageText", "getPageHtml", "screenshot", "closeTab"];
|
|
11
|
+
export type BrowserStepAction = (typeof BROWSER_STEP_ACTIONS)[number];
|
|
12
|
+
/** A legacy Run in Browser step: `{ action, name?, ...params }`. */
|
|
13
|
+
export type BrowserActionStep = Record<string, unknown> & {
|
|
14
|
+
action: BrowserStepAction;
|
|
15
|
+
};
|
|
16
|
+
/** A legacy extract field. */
|
|
17
|
+
export interface BrowserActionField {
|
|
18
|
+
name: string;
|
|
19
|
+
selector: string;
|
|
20
|
+
attribute?: string;
|
|
21
|
+
multiple?: boolean;
|
|
22
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { UiScript } from '../types.js';
|
|
2
|
+
/** Read the steps parameter: an array, or the JSON text the builder's form saved. */
|
|
3
|
+
export declare function readStepList(value: unknown, what: string): unknown[];
|
|
4
|
+
/** Convert a Run in Browser step list to a UI script. Throws `UiScriptError` naming the step at fault. */
|
|
5
|
+
export declare function fromBrowserActionSteps(steps: unknown, options?: {
|
|
6
|
+
name?: string;
|
|
7
|
+
}): UiScript;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { UiScript, UiTarget } from '../types.js';
|
|
2
|
+
/** A Playwright selector as a v1 target; throws through `refuse` when it has no equivalent. */
|
|
3
|
+
export declare function targetFromPlaywrightSelector(raw: string, refuse: (message: string) => never): UiTarget;
|
|
4
|
+
/** Convert a Remote Browser step list to a UI script. Throws `UiScriptError` naming the step at fault. */
|
|
5
|
+
export declare function fromRemoteBrowserSteps(steps: unknown, options?: {
|
|
6
|
+
name?: string;
|
|
7
|
+
}): UiScript;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stewards saved-step recordings (version 1) to and from UI scripts
|
|
3
|
+
* (spec 18 section 6, rule 1: every valid recording maps onto a script
|
|
4
|
+
* without loss).
|
|
5
|
+
*
|
|
6
|
+
* `fromRecording` keeps every field: step ids, intents, masked screenshots,
|
|
7
|
+
* masked typing, secret references and fingerprints (the strict role method
|
|
8
|
+
* is fingerprinted exactly as Stewards does). `toRecording` gives the same
|
|
9
|
+
* recording back, and returns null for a script a recording cannot express
|
|
10
|
+
* (web-only actions, flow steps, other target methods, expressions).
|
|
11
|
+
*/
|
|
12
|
+
import { type Recording } from '../../recording.js';
|
|
13
|
+
import type { UiScript, UiStep } from '../types.js';
|
|
14
|
+
/** A Stewards recording as a UI script. The recording is validated first (`parseRecording`). */
|
|
15
|
+
export declare function fromRecording(value: unknown): UiScript;
|
|
16
|
+
/**
|
|
17
|
+
* The Stewards recording a script corresponds to, or null when the script
|
|
18
|
+
* uses something a recording cannot express: v1-only actions, options or
|
|
19
|
+
* script settings, or more than the recording format allows (200 steps,
|
|
20
|
+
* 4,000-character text). A step without an intent gets
|
|
21
|
+
* `fallbackIntent(step)` (for example the step's `describeStep` fallback),
|
|
22
|
+
* since every saved step needs one. The script's name and application are
|
|
23
|
+
* descriptive and are not carried. The result passes `parseRecording`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function toRecording(script: UiScript, fallbackIntent?: (step: UiStep) => string): Recording | null;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { UiScript } from '../types.js';
|
|
2
|
+
import type { BrowserActionStep } from './browser-action-contract.js';
|
|
3
|
+
export interface LowerOptions {
|
|
4
|
+
/** Input values supplied at dispatch, used for `{ input }` references. */
|
|
5
|
+
inputs?: Readonly<Record<string, unknown>>;
|
|
6
|
+
}
|
|
7
|
+
/** The Run in Browser steps for a script, or null when the script does not fit the legacy contract. */
|
|
8
|
+
export declare function toBrowserActionSteps(script: UiScript, options?: LowerOptions): BrowserActionStep[] | null;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical JSON: object keys sorted (by UTF-16 code unit), no whitespace,
|
|
3
|
+
* array order kept. Two values that are equal as JSON data serialise to the
|
|
4
|
+
* same text, which is what the schema hash and the fingerprints hash.
|
|
5
|
+
*/
|
|
6
|
+
export declare function canonicalJson(value: unknown): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capabilities: what a desk must support to run a script (spec 03 section
|
|
3
|
+
* 5.2). A desk (the extension, the remote-browser executor, later a robot)
|
|
4
|
+
* announces the capability ids it supports; the service hands a script only
|
|
5
|
+
* to a desk whose capabilities cover `requiredCapabilities(script)`, and the
|
|
6
|
+
* compiler refuses a script a desk cannot run with `UNSUPPORTED_ON_DESK`
|
|
7
|
+
* before any step runs.
|
|
8
|
+
*
|
|
9
|
+
* Ids:
|
|
10
|
+
* - `script:1`: reads UI script v1 (always required);
|
|
11
|
+
* - `action:<action>`: runs that step action, flow actions included;
|
|
12
|
+
* - `target:<kind>`: resolves that target method;
|
|
13
|
+
* - `target:frame`: follows a target's frame and shadow-root chain;
|
|
14
|
+
* - `step:verify`, `step:retry`, `step:breakpoint`: the matching step options;
|
|
15
|
+
* - `input:direct`, `input:hardware`: an explicit input method.
|
|
16
|
+
*/
|
|
17
|
+
import { type UiScript } from './types.js';
|
|
18
|
+
/** Every capability id of v1, sorted. */
|
|
19
|
+
export declare const CAPABILITY_IDS: readonly string[];
|
|
20
|
+
/** The capability every script requires: reading UI script v1. */
|
|
21
|
+
export declare const SCRIPT_CAPABILITY = "script:1";
|
|
22
|
+
/**
|
|
23
|
+
* The sorted capability ids a desk needs to run the script. Disabled steps
|
|
24
|
+
* and disabled target methods need nothing. A step that names a pinned
|
|
25
|
+
* element needs what the element's target uses, when the script carries it.
|
|
26
|
+
*/
|
|
27
|
+
export declare function requiredCapabilities(script: UiScript): string[];
|
|
28
|
+
/** The required capabilities a desk lacks, sorted; empty when the desk can run the script. */
|
|
29
|
+
export declare function missingCapabilities(script: UiScript, supported: Iterable<string>): string[];
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-line descriptions of steps for the editor, the recording review and the
|
|
3
|
+
* run view (plan P0-04, P1-12, P1-14).
|
|
4
|
+
*
|
|
5
|
+
* `describeStep` returns a message key under `fluidgrids.uiScript.step.*`,
|
|
6
|
+
* its variables, and an English fallback. The front end translates the key
|
|
7
|
+
* with `tr(key, vars)` so `i18n:extract` sees it; non-UI consumers (logs,
|
|
8
|
+
* Stewards intents) use the fallback. `UI_SCRIPT_STEP_MESSAGES` holds the
|
|
9
|
+
* English template of every key, with `{{name}}` placeholders.
|
|
10
|
+
*/
|
|
11
|
+
import type { UiExpression, UiScriptElement, UiStep, UiTargetRef } from './types.js';
|
|
12
|
+
/** The prefix of every step message key. */
|
|
13
|
+
export declare const UI_SCRIPT_STEP_KEY_PREFIX = "fluidgrids.uiScript.step.";
|
|
14
|
+
/** English templates of every step message, by name; the key is the prefix plus the name. */
|
|
15
|
+
export declare const UI_SCRIPT_STEP_MESSAGES: {
|
|
16
|
+
readonly navigate: "Go to {{url}}";
|
|
17
|
+
readonly goBack: "Go back";
|
|
18
|
+
readonly reload: "Reload the page";
|
|
19
|
+
readonly closeTab: "Close the tab";
|
|
20
|
+
readonly click: "Click {{target}}";
|
|
21
|
+
readonly rightClick: "Right-click {{target}}";
|
|
22
|
+
readonly doubleClick: "Double-click {{target}}";
|
|
23
|
+
readonly rightDoubleClick: "Right double-click {{target}}";
|
|
24
|
+
readonly hover: "Point at {{target}}";
|
|
25
|
+
readonly type: "Type {{value}} into {{target}}";
|
|
26
|
+
readonly typeFocused: "Type {{value}}";
|
|
27
|
+
readonly typeMasked: "Type a hidden value into {{target}}";
|
|
28
|
+
readonly typeMaskedFocused: "Type a hidden value";
|
|
29
|
+
readonly typeSecret: "Type a secret into {{target}}";
|
|
30
|
+
readonly clear: "Clear {{target}}";
|
|
31
|
+
readonly select: "Choose {{value}} in {{target}}";
|
|
32
|
+
readonly check: "Tick {{target}}";
|
|
33
|
+
readonly uncheck: "Untick {{target}}";
|
|
34
|
+
readonly pressKey: "Press {{keys}}";
|
|
35
|
+
readonly scrollTop: "Scroll to the top";
|
|
36
|
+
readonly scrollBottom: "Scroll to the bottom";
|
|
37
|
+
readonly scrollTo: "Scroll to {{target}}";
|
|
38
|
+
readonly scrollBy: "Scroll by {{dx}}, {{dy}}";
|
|
39
|
+
readonly scrollInside: "Scroll {{target}} by {{dx}}, {{dy}}";
|
|
40
|
+
readonly waitFor: "Wait for {{target}}";
|
|
41
|
+
readonly waitForGone: "Wait for {{target}} to go away";
|
|
42
|
+
readonly waitForText: "Wait for the text {{value}}";
|
|
43
|
+
readonly waitForUrl: "Wait for the address to contain {{value}}";
|
|
44
|
+
readonly waitForTime: "Wait {{milliseconds}} ms";
|
|
45
|
+
readonly extract: "Read {{fields}}";
|
|
46
|
+
readonly extractList: "Read each {{target}}";
|
|
47
|
+
readonly getText: "Read the text of {{target}}";
|
|
48
|
+
readonly getValue: "Read the value of {{target}}";
|
|
49
|
+
readonly getAttribute: "Read {{attribute}} of {{target}}";
|
|
50
|
+
readonly elementExists: "Check whether {{target}} is there";
|
|
51
|
+
readonly getPageText: "Read the page text";
|
|
52
|
+
readonly getPageHtml: "Read the page HTML";
|
|
53
|
+
readonly screenshot: "Take a screenshot";
|
|
54
|
+
readonly screenshotOf: "Take a screenshot of {{target}}";
|
|
55
|
+
readonly login: "Sign in";
|
|
56
|
+
readonly focusWindow: "Switch to {{app}}";
|
|
57
|
+
readonly if: "If {{condition}}";
|
|
58
|
+
readonly ifElement: "If {{target}} is there";
|
|
59
|
+
readonly forEach: "For each item in {{value}}";
|
|
60
|
+
readonly forEachElement: "For each {{target}}";
|
|
61
|
+
readonly while: "While {{condition}}, at most {{max}} times";
|
|
62
|
+
readonly whileElement: "While {{target}} is there, at most {{max}} times";
|
|
63
|
+
readonly retryScope: "Try up to {{attempts}} times";
|
|
64
|
+
readonly set: "Set {{name}} to {{value}}";
|
|
65
|
+
readonly log: "Log {{value}}";
|
|
66
|
+
readonly call: "Run the shared sequence {{sequence}}";
|
|
67
|
+
};
|
|
68
|
+
export type UiScriptStepMessageName = keyof typeof UI_SCRIPT_STEP_MESSAGES;
|
|
69
|
+
export type UiScriptStepMessageKey = `fluidgrids.uiScript.step.${UiScriptStepMessageName}`;
|
|
70
|
+
/** The full message key of a message name. */
|
|
71
|
+
export declare function stepMessageKey(name: UiScriptStepMessageName): UiScriptStepMessageKey;
|
|
72
|
+
export interface StepDescription {
|
|
73
|
+
key: UiScriptStepMessageKey;
|
|
74
|
+
vars: Record<string, string | number>;
|
|
75
|
+
/** The English sentence, for consumers that do not translate. */
|
|
76
|
+
fallback: string;
|
|
77
|
+
}
|
|
78
|
+
/** How a target reads in a sentence: the element's name, else what its first enabled method looks for. */
|
|
79
|
+
export declare function describeTarget(ref: UiTargetRef | undefined, elements?: Readonly<Record<string, UiScriptElement>>): string;
|
|
80
|
+
/** How a value reads in a sentence: literals quoted, inputs and variables as [name], anything else as …. */
|
|
81
|
+
export declare function describeExpression(expression: UiExpression | undefined): string;
|
|
82
|
+
/** The description of one step. `elements` are the script's pinned elements, for their names. */
|
|
83
|
+
export declare function describeStep(step: UiStep, elements?: Readonly<Record<string, UiScriptElement>>): StepDescription;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { UiRoleMethod, UiStep, UiStepAction, UiTargetRef } from './types.js';
|
|
2
|
+
/** The Stewards saved-step action each recordable script action corresponds to. */
|
|
3
|
+
export declare const RECORDING_ACTION_OF: Partial<Record<UiStepAction, string>>;
|
|
4
|
+
/** The single accessibility method of an inline target, when that is all the target holds. */
|
|
5
|
+
export declare function soleRoleMethod(ref: UiTargetRef | undefined): UiRoleMethod | undefined;
|
|
6
|
+
/** The fingerprint of a step (lower-case hex sha256). */
|
|
7
|
+
export declare function uiStepFingerprint(step: UiStep): string;
|
|
8
|
+
/** The step with its fingerprint set. Call it after editing a step's target. */
|
|
9
|
+
export declare function withFingerprint<S extends UiStep>(step: S): S;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const UI_SCRIPT_SCHEMA_HASH = "e6860649ad1cba906fb704ce4b62b3ea4380203e6628c809571602f4d0947884";
|
|
2
|
+
/** The schema hash of a JSON Schema document (the same function the constant was computed with). */
|
|
3
|
+
export declare function schemaHashOf(jsonSchema: unknown): string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UI script v1 (plan P0-04): the contract every RPA component shares. See
|
|
3
|
+
* `types.ts` for the format, `parse.ts` for validation, `capabilities.ts` for
|
|
4
|
+
* what a desk must support, `adapters/` for the conversions from and to the
|
|
5
|
+
* existing step vocabularies, and `describe.ts` for step descriptions.
|
|
6
|
+
*/
|
|
7
|
+
export * from './types.js';
|
|
8
|
+
export * from './limits.js';
|
|
9
|
+
export { ELEMENT_KEY_PATTERN, NAME_PATTERN, STEP_ID_PATTERN, uiExpressionSchema, uiScriptRegistry, uiScriptSchema, uiStepSchema, uiTargetMethodSchema, uiTargetRefSchema, uiTargetSchema, } from './schema.js';
|
|
10
|
+
export { type ParseUiScriptOptions, UI_EXPRESSION_ARITY, UiScriptError, type UiScriptErrorCode, parseUiScript, safeParseUiScript, } from './parse.js';
|
|
11
|
+
export { RECORDING_ACTION_OF, uiStepFingerprint, withFingerprint } from './fingerprint.js';
|
|
12
|
+
export { canonicalJson } from './canonical.js';
|
|
13
|
+
export { UI_SCRIPT_SCHEMA_HASH, schemaHashOf } from './hash.js';
|
|
14
|
+
export { UI_SCRIPT_SCHEMA_TITLE, uiScriptJsonSchema } from './json-schema.js';
|
|
15
|
+
export { CAPABILITY_IDS, SCRIPT_CAPABILITY, missingCapabilities, requiredCapabilities } from './capabilities.js';
|
|
16
|
+
export { type WalkedStep, childBlocks, countSteps, stepAtPath, stepExpressions, stepTargets, visitExpression, walkSteps, } from './walk.js';
|
|
17
|
+
export { type StepDescription, UI_SCRIPT_STEP_KEY_PREFIX, UI_SCRIPT_STEP_MESSAGES, type UiScriptStepMessageKey, type UiScriptStepMessageName, describeExpression, describeStep, describeTarget, stepMessageKey, } from './describe.js';
|
|
18
|
+
export { BROWSER_STEP_ACTIONS, type BrowserActionField, type BrowserActionStep, type BrowserStepAction, } from './adapters/browser-action-contract.js';
|
|
19
|
+
export { fromBrowserActionSteps } from './adapters/from-browser-action.js';
|
|
20
|
+
export { type LowerOptions, toBrowserActionSteps } from './adapters/to-browser-action.js';
|
|
21
|
+
export { fromRemoteBrowserSteps, targetFromPlaywrightSelector } from './adapters/from-remote-browser.js';
|
|
22
|
+
export { fromRecording, toRecording } from './adapters/recording.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The title the committed JSON Schema carries. */
|
|
2
|
+
export declare const UI_SCRIPT_SCHEMA_TITLE = "FluidGrids UI script v1";
|
|
3
|
+
/** The JSON Schema (draft 2020-12) of UI script v1, as accepted on input. */
|
|
4
|
+
export declare function uiScriptJsonSchema(): Record<string, unknown>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Limits of a UI script v1 (spec 12 section 8, plan P0-04).
|
|
3
|
+
*
|
|
4
|
+
* The schema enforces the per-field limits; `parseUiScript` enforces the
|
|
5
|
+
* whole-script ones (total step count, nesting depth, serialised size).
|
|
6
|
+
* Each limit is a constant so the service, the workers, the extension and the
|
|
7
|
+
* builder refuse the same scripts.
|
|
8
|
+
*/
|
|
9
|
+
/** The only UI script version this engine reads and writes. */
|
|
10
|
+
export declare const UI_SCRIPT_VERSION = 1;
|
|
11
|
+
/** Steps in one script, counting every nested step and the clean-up block. */
|
|
12
|
+
export declare const MAX_SCRIPT_STEPS = 500;
|
|
13
|
+
/** The script serialised as UTF-8 JSON, at most (1 MiB). */
|
|
14
|
+
export declare const MAX_SCRIPT_BYTES: number;
|
|
15
|
+
/** Flow blocks (if, for each, while, retry scope) nested inside each other, at most. */
|
|
16
|
+
export declare const MAX_FLOW_DEPTH = 8;
|
|
17
|
+
/** Nesting of one expression, at most. */
|
|
18
|
+
export declare const MAX_EXPRESSION_DEPTH = 16;
|
|
19
|
+
/** Items in one list literal of an expression, at most. */
|
|
20
|
+
export declare const MAX_EXPRESSION_ITEMS = 1000;
|
|
21
|
+
/** Arguments of one operator, at most (each operator's own arity is in `UI_EXPRESSION_ARITY`). */
|
|
22
|
+
export declare const MAX_OPERATOR_ARGS = 16;
|
|
23
|
+
/** Inputs, outputs and variables a script declares, each at most. */
|
|
24
|
+
export declare const MAX_SCRIPT_INPUTS = 100;
|
|
25
|
+
export declare const MAX_SCRIPT_OUTPUTS = 100;
|
|
26
|
+
export declare const MAX_SCRIPT_VARIABLES = 100;
|
|
27
|
+
/** Library elements a script pins, at most. */
|
|
28
|
+
export declare const MAX_SCRIPT_ELEMENTS = 500;
|
|
29
|
+
/** Methods in one target, at most. */
|
|
30
|
+
export declare const MAX_TARGET_METHODS = 8;
|
|
31
|
+
/** Frames and shadow roots in a target's frame chain, at most. */
|
|
32
|
+
export declare const MAX_FRAME_DEPTH = 8;
|
|
33
|
+
/** Fields of one extract or extract list step, at most. */
|
|
34
|
+
export declare const MAX_EXTRACT_FIELDS = 50;
|
|
35
|
+
/** Items an extract list step may return and pages it may follow. */
|
|
36
|
+
export declare const MAX_LIST_ITEMS = 5000;
|
|
37
|
+
export declare const MAX_LIST_PAGES = 50;
|
|
38
|
+
/** Iterations of a for each or while block, at most. */
|
|
39
|
+
export declare const MAX_LOOP_ITERATIONS = 10000;
|
|
40
|
+
/** Attempts of a step retry or a retry scope, at most. */
|
|
41
|
+
export declare const MAX_RETRY_ATTEMPTS = 10;
|
|
42
|
+
/** Longest wait one step may set (10 minutes). */
|
|
43
|
+
export declare const MAX_STEP_TIMEOUT_MS = 600000;
|
|
44
|
+
/** Longest delay between retries and between typed characters. */
|
|
45
|
+
export declare const MAX_DELAY_MS = 60000;
|
|
46
|
+
/** Keys pressed together in one press keys step, at most. */
|
|
47
|
+
export declare const MAX_KEYS = 8;
|
|
48
|
+
/** Values one select step may choose, at most. */
|
|
49
|
+
export declare const MAX_SELECT_VALUES = 50;
|
|
50
|
+
/** Text limits. */
|
|
51
|
+
export declare const MAX_SELECTOR_LENGTH = 500;
|
|
52
|
+
export declare const MAX_URL_LENGTH = 4096;
|
|
53
|
+
export declare const MAX_LABEL_LENGTH = 512;
|
|
54
|
+
export declare const MAX_TEXT_LENGTH = 10000;
|
|
55
|
+
export declare const MAX_INTENT_LENGTH = 500;
|
|
56
|
+
export declare const MAX_NAME_LENGTH = 64;
|
|
57
|
+
/** The legacy Run in Browser contract a lowered script must fit (wspace-workflow-svc `browser-contract.ts`). */
|
|
58
|
+
export declare const LEGACY_MAX_BROWSER_STEPS = 100;
|
|
59
|
+
export declare const LEGACY_MAX_STEPS_BYTES: number;
|
|
60
|
+
/** UTF-8 byte length of a value serialised as JSON (browser safe, no Buffer). */
|
|
61
|
+
export declare function jsonByteLength(value: unknown): number;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { UiExpressionOp, UiScript } from './types.js';
|
|
2
|
+
export type UiScriptErrorCode = 'INVALID_SCRIPT' | 'SCRIPT_TOO_LARGE' | 'TOO_MANY_STEPS' | 'DUPLICATE_STEP_ID' | 'UNKNOWN_ELEMENT' | 'UNKNOWN_INPUT' | 'FINGERPRINT_MISMATCH' | 'CREDENTIAL_IN_SCRIPT' | 'UNRESOLVED';
|
|
3
|
+
/** A script that cannot be used. `path` names the step (see `walk.ts`) or the field at fault. */
|
|
4
|
+
export declare class UiScriptError extends Error {
|
|
5
|
+
readonly code: UiScriptErrorCode;
|
|
6
|
+
readonly path?: string | undefined;
|
|
7
|
+
constructor(code: UiScriptErrorCode, message: string, path?: string | undefined);
|
|
8
|
+
}
|
|
9
|
+
export interface ParseUiScriptOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The script is compiled for a desk: every pinned element carries its
|
|
12
|
+
* target and no `call` step is left (the worker has inlined them).
|
|
13
|
+
* Refused with `UNRESOLVED` otherwise.
|
|
14
|
+
*/
|
|
15
|
+
resolved?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** Arguments each operator takes: [fewest, most]. */
|
|
18
|
+
export declare const UI_EXPRESSION_ARITY: Readonly<Record<UiExpressionOp, readonly [number, number]>>;
|
|
19
|
+
/**
|
|
20
|
+
* Parse a stored script (an object, or its JSON text) and check it. Returns
|
|
21
|
+
* the script unchanged; throws `UiScriptError`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseUiScript(value: unknown, options?: ParseUiScriptOptions): UiScript;
|
|
24
|
+
/** `parseUiScript` without throwing. */
|
|
25
|
+
export declare function safeParseUiScript(value: unknown, options?: ParseUiScriptOptions): {
|
|
26
|
+
success: true;
|
|
27
|
+
script: UiScript;
|
|
28
|
+
} | {
|
|
29
|
+
success: false;
|
|
30
|
+
error: UiScriptError;
|
|
31
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The zod schema of UI script v1. It checks the shape and the per-field
|
|
3
|
+
* limits; `parse.ts` adds the checks a schema cannot express (unique step ids,
|
|
4
|
+
* element references, total step count, nesting, size, fingerprints and
|
|
5
|
+
* credentials).
|
|
6
|
+
*
|
|
7
|
+
* No field has a zod default and no field is transformed, so a parsed script
|
|
8
|
+
* is exactly the stored one and serialises back unchanged. The JSON Schema in
|
|
9
|
+
* `schema/ui-script-v1.schema.json` is generated from this file
|
|
10
|
+
* (`json-schema.ts`) and its hash is `UI_SCRIPT_SCHEMA_HASH` (`hash.ts`).
|
|
11
|
+
*
|
|
12
|
+
* The recursive parts (expressions, steps) carry ids in a registry that
|
|
13
|
+
* belongs to this module, never zod's global registry, so two copies of the
|
|
14
|
+
* engine in one bundle do not collide.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
import { type UiExpression, type UiScript, type UiStep, type UiTarget, type UiTargetRef } from './types.js';
|
|
18
|
+
/** Ids of the named parts of the schema, used as `$defs` names in the JSON Schema. */
|
|
19
|
+
export declare const uiScriptRegistry: z.core.$ZodRegistry<{
|
|
20
|
+
id: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
}, z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
|
|
23
|
+
/** Variable, input, output and field names: an identifier. */
|
|
24
|
+
export declare const NAME_PATTERN: RegExp;
|
|
25
|
+
/** Step ids (the Stewards saved-step id rule). */
|
|
26
|
+
export declare const STEP_ID_PATTERN: RegExp;
|
|
27
|
+
/** Element keys inside a script. */
|
|
28
|
+
export declare const ELEMENT_KEY_PATTERN: RegExp;
|
|
29
|
+
export declare const uiExpressionSchema: z.ZodType<UiExpression>;
|
|
30
|
+
export declare const uiTargetMethodSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
31
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
32
|
+
kind: z.ZodLiteral<"role">;
|
|
33
|
+
role: z.ZodString;
|
|
34
|
+
name: z.ZodString;
|
|
35
|
+
nth: z.ZodOptional<z.ZodInt>;
|
|
36
|
+
app: z.ZodOptional<z.ZodString>;
|
|
37
|
+
window: z.ZodOptional<z.ZodString>;
|
|
38
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
39
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
40
|
+
kind: z.ZodLiteral<"css">;
|
|
41
|
+
selector: z.ZodString;
|
|
42
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
43
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
44
|
+
kind: z.ZodLiteral<"testId">;
|
|
45
|
+
value: z.ZodString;
|
|
46
|
+
attribute: z.ZodOptional<z.ZodString>;
|
|
47
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
48
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
49
|
+
kind: z.ZodLiteral<"xpath">;
|
|
50
|
+
xpath: z.ZodString;
|
|
51
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
52
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
53
|
+
kind: z.ZodLiteral<"fuzzy">;
|
|
54
|
+
role: z.ZodOptional<z.ZodString>;
|
|
55
|
+
name: z.ZodString;
|
|
56
|
+
threshold: z.ZodOptional<z.ZodNumber>;
|
|
57
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
58
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
59
|
+
kind: z.ZodLiteral<"anchor">;
|
|
60
|
+
anchor: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
61
|
+
kind: z.ZodLiteral<"text">;
|
|
62
|
+
text: z.ZodString;
|
|
63
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
64
|
+
kind: z.ZodLiteral<"role">;
|
|
65
|
+
role: z.ZodString;
|
|
66
|
+
name: z.ZodString;
|
|
67
|
+
}, z.core.$strict>], "kind">;
|
|
68
|
+
relation: z.ZodEnum<{
|
|
69
|
+
leftOf: "leftOf";
|
|
70
|
+
rightOf: "rightOf";
|
|
71
|
+
above: "above";
|
|
72
|
+
below: "below";
|
|
73
|
+
inside: "inside";
|
|
74
|
+
sameRow: "sameRow";
|
|
75
|
+
}>;
|
|
76
|
+
role: z.ZodOptional<z.ZodString>;
|
|
77
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
78
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
79
|
+
kind: z.ZodLiteral<"text">;
|
|
80
|
+
text: z.ZodString;
|
|
81
|
+
exact: z.ZodOptional<z.ZodBoolean>;
|
|
82
|
+
nth: z.ZodOptional<z.ZodInt>;
|
|
83
|
+
}, z.core.$strict>], "kind">;
|
|
84
|
+
export declare const uiTargetSchema: z.ZodType<UiTarget>;
|
|
85
|
+
export declare const uiTargetRefSchema: z.ZodType<UiTargetRef>;
|
|
86
|
+
export declare const uiStepSchema: z.ZodType<UiStep>;
|
|
87
|
+
export declare const uiScriptSchema: z.ZodType<UiScript>;
|