@sedum-dev/core 0.1.0-alpha.4 → 0.1.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -413,6 +413,29 @@ var SedumPageScript = (() => {
413
413
  }
414
414
  if (kbdText && kbdText === shown) addPart("keyboard shortcut");
415
415
  return parts.join(", ");
416
+ }, countBadgeKind = function(node, count) {
417
+ const tokens = [];
418
+ let control = null;
419
+ for (let current = node, depth = 0; current && current !== document.body && depth < 4; current = composedParent(current), depth++) {
420
+ tokens.push(
421
+ ...[
422
+ current.getAttribute("class") ?? "",
423
+ current.id,
424
+ current.getAttribute("data-test") ?? "",
425
+ current.getAttribute("data-testid") ?? ""
426
+ ].join(" ").toLocaleLowerCase().split(/\s+/).map((token) => token.replace(/[_:#/.]+/g, "-")).filter(Boolean)
427
+ );
428
+ if (interactive(current)) {
429
+ control = current;
430
+ break;
431
+ }
432
+ }
433
+ if (!control) return "";
434
+ if (publicText(control, true).replace(/\s+/g, "") !== count) return "";
435
+ const kind = ICON_KINDS.find(
436
+ ([pattern]) => tokens.some((token) => pattern.test(token))
437
+ );
438
+ return kind?.[1] ?? "";
416
439
  }, clippedAway = function(element) {
417
440
  const box = element.getBoundingClientRect();
418
441
  const x = box.left + box.width / 2;
@@ -901,8 +924,10 @@ var SedumPageScript = (() => {
901
924
  continue;
902
925
  }
903
926
  if (!parent || !visible(parent) || excludedTextAncestor(parent)) continue;
904
- const part = (node.textContent ?? "").replace(/\s+/g, " ").trim();
905
- if (!part) continue;
927
+ const text = (node.textContent ?? "").replace(/\s+/g, " ").trim();
928
+ if (!text) continue;
929
+ const kind = /^\d{1,4}\+?$/.test(text) ? countBadgeKind(parent, text) : "";
930
+ const part = kind ? `${kind} icon badge: ${text}` : text;
906
931
  size += Array.from(part).length + (pieces.length ? 1 : 0);
907
932
  if (size > DIGEST_LIMIT)
908
933
  return {
@@ -1025,7 +1050,7 @@ var SedumPageScript = (() => {
1025
1050
  return { actionable: false, reason: "stale" };
1026
1051
  return hitTest() ?? { actionable: false, reason: "not_actionable" };
1027
1052
  };
1028
- observe2 = observe, composedParent2 = composedParent, allElements2 = allElements, flatTextNodes2 = flatTextNodes, deepElementFromPoint2 = deepElementFromPoint, deepContains2 = deepContains, version2 = version, same2 = same, clearRefs2 = clearRefs, visible2 = visible, modal2 = modal, excludedTextAncestor2 = excludedTextAncestor, publicText2 = publicText, referencedLabelText2 = referencedLabelText, label2 = label, nearbyText2 = nearbyText, mediaName2 = mediaName, hostLabel2 = hostLabel, iconName2 = iconName, describedText2 = describedText, rowLabel2 = rowLabel, candidateName2 = candidateName, hintWords2 = hintWords, addsWords2 = addsWords, siteRootLink2 = siteRootLink, nameHint2 = nameHint, clippedAway2 = clippedAway, ariaHiddenOnly2 = ariaHiddenOnly, isToggle2 = isToggle, transparentToggle2 = transparentToggle, toggleLabel2 = toggleLabel, pointerTarget2 = pointerTarget, landmarkOf2 = landmarkOf, landmarkRoot2 = landmarkRoot, locationOf2 = locationOf, shortText2 = shortText, containerTitle2 = containerTitle, sectionOf2 = sectionOf, boundedName2 = boundedName, role2 = role, interactive2 = interactive, readable2 = readable, editable2 = editable, disabled2 = disabled, path2 = path, inArticleBody2 = inArticleBody, itemContext2 = itemContext, peers2 = peers, scan2 = scan, collect2 = collect, selectOnly2 = selectOnly, selectedText2 = selectedText, digest2 = digest, refElement2 = refElement, fillElement2 = fillElement, readTarget2 = readTarget, aim2 = aim;
1053
+ observe2 = observe, composedParent2 = composedParent, allElements2 = allElements, flatTextNodes2 = flatTextNodes, deepElementFromPoint2 = deepElementFromPoint, deepContains2 = deepContains, version2 = version, same2 = same, clearRefs2 = clearRefs, visible2 = visible, modal2 = modal, excludedTextAncestor2 = excludedTextAncestor, publicText2 = publicText, referencedLabelText2 = referencedLabelText, label2 = label, nearbyText2 = nearbyText, mediaName2 = mediaName, hostLabel2 = hostLabel, iconName2 = iconName, describedText2 = describedText, rowLabel2 = rowLabel, candidateName2 = candidateName, hintWords2 = hintWords, addsWords2 = addsWords, siteRootLink2 = siteRootLink, nameHint2 = nameHint, countBadgeKind2 = countBadgeKind, clippedAway2 = clippedAway, ariaHiddenOnly2 = ariaHiddenOnly, isToggle2 = isToggle, transparentToggle2 = transparentToggle, toggleLabel2 = toggleLabel, pointerTarget2 = pointerTarget, landmarkOf2 = landmarkOf, landmarkRoot2 = landmarkRoot, locationOf2 = locationOf, shortText2 = shortText, containerTitle2 = containerTitle, sectionOf2 = sectionOf, boundedName2 = boundedName, role2 = role, interactive2 = interactive, readable2 = readable, editable2 = editable, disabled2 = disabled, path2 = path, inArticleBody2 = inArticleBody, itemContext2 = itemContext, peers2 = peers, scan2 = scan, collect2 = collect, selectOnly2 = selectOnly, selectedText2 = selectedText, digest2 = digest, refElement2 = refElement, fillElement2 = fillElement, readTarget2 = readTarget, aim2 = aim;
1029
1054
  const documentId = Array.from(crypto.getRandomValues(new Uint32Array(4))).map((part) => part.toString(16)).join("-");
1030
1055
  let revision = 0;
1031
1056
  let route = location.href;
@@ -1190,6 +1215,7 @@ var SedumPageScript = (() => {
1190
1215
  var addsWords2;
1191
1216
  var siteRootLink2;
1192
1217
  var nameHint2;
1218
+ var countBadgeKind2;
1193
1219
  var clippedAway2;
1194
1220
  var ariaHiddenOnly2;
1195
1221
  var isToggle2;
@@ -39,7 +39,8 @@
39
39
  "type": "string",
40
40
  "enum": [
41
41
  "low_confidence",
42
- "contradiction"
42
+ "contradiction",
43
+ "flaky"
43
44
  ]
44
45
  }
45
46
  },
@@ -142,6 +143,29 @@
142
143
  "type": "integer",
143
144
  "exclusiveMinimum": 0,
144
145
  "maximum": 9007199254740991
146
+ },
147
+ "vision": {
148
+ "type": "object",
149
+ "properties": {
150
+ "model": {
151
+ "type": "string",
152
+ "minLength": 1,
153
+ "maxLength": 200
154
+ },
155
+ "key": {
156
+ "type": "string",
157
+ "enum": [
158
+ "accepted",
159
+ "rejected",
160
+ "unreachable"
161
+ ]
162
+ }
163
+ },
164
+ "required": [
165
+ "model",
166
+ "key"
167
+ ],
168
+ "additionalProperties": false
145
169
  }
146
170
  },
147
171
  "required": [
@@ -441,7 +465,8 @@
441
465
  "type": "string",
442
466
  "enum": [
443
467
  "low_confidence",
444
- "contradiction"
468
+ "contradiction",
469
+ "flaky"
445
470
  ]
446
471
  }
447
472
  },
@@ -494,7 +519,8 @@
494
519
  "type": "string",
495
520
  "enum": [
496
521
  "low_confidence",
497
- "contradiction"
522
+ "contradiction",
523
+ "flaky"
498
524
  ]
499
525
  }
500
526
  },
@@ -610,6 +636,14 @@
610
636
  "type": "string",
611
637
  "maxLength": 512
612
638
  },
639
+ "group": {
640
+ "maxItems": 16,
641
+ "type": "array",
642
+ "items": {
643
+ "type": "string",
644
+ "maxLength": 120
645
+ }
646
+ },
613
647
  "sourceStack": {
614
648
  "minItems": 1,
615
649
  "type": "array",
@@ -0,0 +1,212 @@
1
+ import { Page, BrowserContext } from 'playwright-core';
2
+ import 'playwright/test';
3
+
4
+ /** Source positions come from YAML nodes, never from searching the source text. */
5
+ interface FlowSource {
6
+ readonly file: string;
7
+ readonly line: number;
8
+ readonly col: number;
9
+ }
10
+ interface FlowDiagnostic {
11
+ readonly severity: "error" | "warning";
12
+ readonly code: string;
13
+ readonly source: FlowSource;
14
+ readonly message: string;
15
+ readonly fix: string;
16
+ }
17
+ type FlowScalar = string | number | boolean | null;
18
+ interface DeclaredDataValue {
19
+ readonly value: FlowScalar;
20
+ readonly source: FlowSource;
21
+ }
22
+ interface FlowToken {
23
+ readonly kind: "placeholder" | "quoted";
24
+ readonly start: number;
25
+ readonly end: number;
26
+ readonly text: string;
27
+ readonly key?: string;
28
+ }
29
+ interface SentenceStep {
30
+ readonly kind: "sentence";
31
+ readonly phase: "before" | "steps" | "after";
32
+ readonly text: string;
33
+ readonly tokens: readonly FlowToken[];
34
+ readonly source: FlowSource;
35
+ /** SED-29 adds module call sites before the sentence source. */
36
+ readonly sourceStack?: readonly FlowSource[];
37
+ }
38
+ interface ModuleBinding {
39
+ readonly value: FlowScalar;
40
+ readonly source: FlowSource;
41
+ }
42
+ interface ModuleStep {
43
+ readonly kind: "module";
44
+ readonly phase: "before" | "steps" | "after";
45
+ readonly use: string;
46
+ readonly with: Readonly<Record<string, FlowScalar>>;
47
+ readonly withSources: Readonly<Record<string, FlowSource>>;
48
+ readonly source: FlowSource;
49
+ /** SED-29 adds each resolved module source after this call site. */
50
+ readonly sourceStack: readonly FlowSource[];
51
+ /** Present only after the complete module graph has been resolved. */
52
+ readonly resolved?: ResolvedModuleCall;
53
+ }
54
+ interface ResolvedModuleCall {
55
+ readonly id: string;
56
+ readonly file: string;
57
+ readonly parameters: readonly string[];
58
+ readonly bindings: Readonly<Record<string, ModuleBinding>>;
59
+ readonly steps: readonly FlowStep[];
60
+ }
61
+ type FlowStep = SentenceStep | ModuleStep;
62
+ interface FlowDefinition {
63
+ readonly version: 1;
64
+ readonly file: string;
65
+ readonly identity: string;
66
+ readonly explicitId?: string;
67
+ readonly idSource?: FlowSource;
68
+ readonly description?: string;
69
+ readonly url?: string;
70
+ /** Position of the `url` value, for entry-URL diagnostics. */
71
+ readonly urlSource?: FlowSource;
72
+ readonly tags: readonly string[];
73
+ readonly meta: Readonly<Record<string, unknown>>;
74
+ readonly data: Readonly<Record<string, DeclaredDataValue>>;
75
+ readonly before: readonly FlowStep[];
76
+ readonly steps: readonly FlowStep[];
77
+ readonly after: readonly FlowStep[];
78
+ readonly goal?: {
79
+ readonly text: string;
80
+ readonly source: FlowSource;
81
+ readonly verify: string;
82
+ readonly verifySource: FlowSource;
83
+ };
84
+ }
85
+ interface ModuleDefinition {
86
+ readonly file: string;
87
+ readonly source: FlowSource;
88
+ readonly parameters: readonly string[];
89
+ readonly steps: readonly FlowStep[];
90
+ }
91
+ interface ParsedModuleResult {
92
+ readonly value?: ModuleDefinition;
93
+ readonly diagnostics: readonly FlowDiagnostic[];
94
+ }
95
+ /** A format-only result cannot be mistaken for full validation. */
96
+ interface FormatCoverage {
97
+ readonly format: "passed" | "failed";
98
+ readonly steps: "not_checked";
99
+ readonly modules: "not_needed" | "not_checked";
100
+ }
101
+ interface ParsedFlowResult {
102
+ readonly value?: FlowDefinition;
103
+ /** Parsed steps retained only for collecting later errors; never executable. */
104
+ readonly candidate?: FlowDefinition;
105
+ readonly diagnostics: readonly FlowDiagnostic[];
106
+ readonly coverage: FullValidationCoverage;
107
+ }
108
+ interface ValidationInput {
109
+ readonly source: string;
110
+ readonly path: string;
111
+ }
112
+ interface FlowValidationResult {
113
+ readonly files: readonly ParsedFlowResult[];
114
+ readonly diagnostics: readonly FlowDiagnostic[];
115
+ readonly coverage: FormatCoverage;
116
+ }
117
+ /** SED-28/29/37 may only mark checks complete after actually performing them. */
118
+ interface FullValidationCoverage {
119
+ readonly format: "passed" | "failed";
120
+ readonly steps: "not_checked" | "checked" | "incomplete";
121
+ readonly modules: "not_needed" | "not_checked" | "checked" | "incomplete";
122
+ }
123
+ declare function isFullyValidated(coverage: FullValidationCoverage, diagnostics: readonly FlowDiagnostic[]): boolean;
124
+ declare function formatFlowDiagnostic(diagnostic: FlowDiagnostic): string;
125
+
126
+ declare const SECRET: unique symbol;
127
+ /** A value typed into the page but never shown to a model or a report. */
128
+ interface SecretValue {
129
+ readonly [SECRET]: () => string;
130
+ }
131
+ /** Mark a value as sensitive: it is typed, but redacted from reports and model input. */
132
+ declare function secret(value: string): SecretValue;
133
+ declare function isSecret(value: unknown): value is SecretValue;
134
+ /** @internal The runner reads a secret's text only to type it. */
135
+ declare function revealSecret(value: SecretValue): string;
136
+ type AiValue = string | number | boolean | SecretValue;
137
+ /** Values for `{{name}}` placeholders; keep them out of the sentence text. */
138
+ type AiValues = Readonly<Record<string, AiValue>>;
139
+ /** Anything with a zod-style `parse`, such as `z.coerce.number()`. */
140
+ interface Parser<T> {
141
+ parse(input: unknown): T;
142
+ }
143
+ interface Ai {
144
+ /** Run one plain-English step, exactly as a YAML step sentence. */
145
+ (sentence: string, values?: AiValues): Promise<void>;
146
+ /** Run several steps in order; they share one values object. */
147
+ (sentences: readonly string[], values?: AiValues): Promise<void>;
148
+ /** Name a block of steps; every step inside is reported under the name. */
149
+ group<T>(name: string, body: () => Promise<T> | T): Promise<T>;
150
+ group(name: string, sentences: readonly string[], values?: AiValues): Promise<void>;
151
+ /** Read the text of the element a description refers to. */
152
+ extract(description: string): Promise<string>;
153
+ extract<T>(description: string, parser: Parser<T>): Promise<T>;
154
+ }
155
+ interface TestInfo {
156
+ readonly id: string;
157
+ readonly title: string;
158
+ readonly file: string;
159
+ readonly tags: readonly string[];
160
+ /** 1 for the first attempt, 2 for the first retry, and so on. */
161
+ readonly attempt: number;
162
+ }
163
+ interface TestContext {
164
+ /** The Playwright page the AI steps run on. */
165
+ readonly page: Page;
166
+ readonly context: BrowserContext;
167
+ readonly ai: Ai;
168
+ /** Configured variables and environment, as `sedum run` resolves them. */
169
+ readonly env: Readonly<Record<string, string | undefined>>;
170
+ readonly testInfo: TestInfo;
171
+ }
172
+ interface TestOptions {
173
+ /** Stable identity; defaults to `<file>#<title>`. */
174
+ readonly id?: string;
175
+ /** Entry URL, absolute or relative to `baseUrl`. Omit to start on a blank page. */
176
+ readonly url?: string;
177
+ readonly tags?: readonly string[];
178
+ }
179
+ type TestBody = (context: TestContext) => Promise<void> | void;
180
+ interface ScriptRegistration {
181
+ readonly title: string;
182
+ readonly options: TestOptions;
183
+ readonly body: TestBody;
184
+ /**
185
+ * The innermost stack frame in a `*.test.ts` file when `test()` ran, so a
186
+ * test declared through a helper belongs to the test file that called it.
187
+ * Otherwise the direct caller's frame.
188
+ */
189
+ readonly callSite: string | undefined;
190
+ }
191
+ interface Registry {
192
+ pending: ScriptRegistration[];
193
+ }
194
+ /** @internal */
195
+ declare function scriptRegistry(): Registry;
196
+ /** Declare a test. `sedum run` discovers every `test()` in a `*.test.ts` file. */
197
+ declare function test(title: string, body: TestBody): void;
198
+ declare function test(title: string, options: TestOptions, body: TestBody): void;
199
+ /** One stack frame, as `file:line:col`, parsed from V8's text. */
200
+ declare function parseFrame(frame: string): FlowSource | undefined;
201
+ /**
202
+ * One spelling per file, for comparing paths from stack frames. On Windows a
203
+ * frame may use forward slashes, a long name for a short one (RUNNER~1 in a
204
+ * temp dir), or another drive-letter case.
205
+ */
206
+ declare function pathKey(file: string): string;
207
+ /** Whether a stack frame's path names `file`. */
208
+ declare function samePath(a: string, b: string): boolean;
209
+ /** The innermost stack frame inside `file`, for reporting where a step was written. */
210
+ declare function sourceInFile(stack: string | undefined, file: string): FlowSource | undefined;
211
+
212
+ export { type AiValues as A, scriptRegistry as B, secret as C, type DeclaredDataValue as D, sourceInFile as E, type FlowSource as F, test as G, type ModuleBinding as M, type ParsedFlowResult as P, type ResolvedModuleCall as R, type SentenceStep as S, type TestBody as T, type ValidationInput as V, type FlowToken as a, type FlowScalar as b, type FlowDiagnostic as c, type FlowDefinition as d, type ParsedModuleResult as e, type FlowValidationResult as f, type ModuleStep as g, type FullValidationCoverage as h, type ScriptRegistration as i, type Ai as j, type AiValue as k, type FlowStep as l, type FormatCoverage as m, type ModuleDefinition as n, type Parser as o, type SecretValue as p, type TestContext as q, type TestInfo as r, type TestOptions as s, formatFlowDiagnostic as t, isFullyValidated as u, isSecret as v, parseFrame as w, pathKey as x, revealSecret as y, samePath as z };
@@ -0,0 +1,3 @@
1
+ export { j as Ai, k as AiValue, A as AiValues, o as Parser, p as SecretValue, T as TestBody, q as TestContext, r as TestInfo, s as TestOptions, C as secret, G as test } from './script-api-D3if59MQ.js';
2
+ export { expect } from 'playwright/test';
3
+ export { BrowserContext, Locator, Page } from 'playwright-core';
@@ -0,0 +1,12 @@
1
+ import {
2
+ secret,
3
+ test
4
+ } from "./chunk-C32TDS2U.js";
5
+
6
+ // src/script-api.ts
7
+ import { expect } from "playwright/test";
8
+ export {
9
+ expect,
10
+ secret,
11
+ test
12
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sedum-dev/core",
3
- "version": "0.1.0-alpha.4",
3
+ "version": "0.1.0-alpha.5",
4
4
  "repository": "https://github.com/sedum-dev/sedum",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -14,6 +14,10 @@
14
14
  "types": "./dist/index.d.ts",
15
15
  "import": "./dist/index.js"
16
16
  },
17
+ "./script": {
18
+ "types": "./dist/script-api.d.ts",
19
+ "import": "./dist/script-api.js"
20
+ },
17
21
  "./page-script.js": "./dist/page-script/index.global.js",
18
22
  "./run-result.schema.json": "./dist/run-result.schema.json"
19
23
  },
@@ -21,6 +25,8 @@
21
25
  "dist"
22
26
  ],
23
27
  "dependencies": {
28
+ "jiti": "2.7.0",
29
+ "playwright": "1.63.0",
24
30
  "playwright-core": "1.63.0",
25
31
  "sharp": "0.35.5",
26
32
  "yaml": "2.9.1",
@@ -30,7 +36,7 @@
30
36
  "@hegeldev/hegel": "0.4.7"
31
37
  },
32
38
  "scripts": {
33
- "build": "tsup src/index.ts --format esm --dts --clean --out-dir dist && node scripts/write-run-result-schema.mjs && tsup src/page-script/index.ts --format iife --platform browser --global-name SedumPageScript --out-dir dist/page-script",
39
+ "build": "tsup src/index.ts src/script-api.ts --format esm --dts --clean --out-dir dist && node scripts/write-run-result-schema.mjs && tsup src/page-script/index.ts --format iife --platform browser --global-name SedumPageScript --out-dir dist/page-script",
34
40
  "typecheck": "tsc --noEmit"
35
41
  }
36
42
  }