dsh-browser-view 0.4.1 → 0.7.0

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.
Files changed (86) hide show
  1. package/README.md +14 -10
  2. package/lib/client.js +1 -1
  3. package/lib/index.js +7776 -5392
  4. package/lib/types/browser/adapters/antd.d.ts +14 -0
  5. package/lib/types/browser/adapters/archetypes.d.ts +93 -0
  6. package/lib/types/browser/adapters/dom.d.ts +6 -0
  7. package/lib/types/browser/adapters/element.d.ts +5 -0
  8. package/lib/types/browser/adapters/engine.d.ts +51 -0
  9. package/lib/types/browser/adapters/generic.d.ts +5 -0
  10. package/lib/types/browser/adapters/index.d.ts +10 -0
  11. package/lib/types/browser/adapters/modules/drag.d.ts +3 -0
  12. package/lib/types/browser/adapters/modules/editor.d.ts +3 -0
  13. package/lib/types/browser/adapters/modules/hierarchy.d.ts +3 -0
  14. package/lib/types/browser/adapters/modules/temporal.d.ts +3 -0
  15. package/lib/types/browser/adapters/modules/transfer.d.ts +3 -0
  16. package/lib/types/browser/adapters/modules/virtual.d.ts +4 -0
  17. package/lib/types/browser/adapters/quiescence.d.ts +3 -0
  18. package/lib/types/browser/adapters/registry.d.ts +64 -0
  19. package/lib/types/browser/adapters/select.d.ts +15 -0
  20. package/lib/types/browser/adapters/types.d.ts +134 -0
  21. package/lib/types/browser/codegen/playwright.d.ts +10 -0
  22. package/lib/types/browser/definitions/collaboration.d.ts +4 -0
  23. package/lib/types/browser/definitions/doctor.d.ts +4 -0
  24. package/lib/types/browser/definitions/extract.d.ts +4 -0
  25. package/lib/types/browser/definitions/inspection.d.ts +4 -0
  26. package/lib/types/browser/definitions/interaction.d.ts +4 -0
  27. package/lib/types/browser/definitions/navigation.d.ts +4 -0
  28. package/lib/types/browser/definitions/recorder.d.ts +4 -0
  29. package/lib/types/browser/definitions/testing.d.ts +4 -0
  30. package/lib/types/browser/policy/engine.d.ts +26 -0
  31. package/lib/types/browser/policy/types.d.ts +36 -0
  32. package/lib/types/browser/primitives/dialog.d.ts +12 -0
  33. package/lib/types/browser/primitives/dom.d.ts +43 -0
  34. package/lib/types/browser/primitives/drag.d.ts +3 -0
  35. package/lib/types/browser/primitives/editor.d.ts +3 -0
  36. package/lib/types/browser/primitives/form.d.ts +7 -0
  37. package/lib/types/browser/primitives/hierarchy.d.ts +3 -0
  38. package/lib/types/browser/primitives/index.d.ts +12 -0
  39. package/lib/types/browser/primitives/select.d.ts +7 -0
  40. package/lib/types/browser/primitives/temporal.d.ts +3 -0
  41. package/lib/types/browser/primitives/transfer.d.ts +3 -0
  42. package/lib/types/browser/primitives/types.d.ts +48 -0
  43. package/lib/types/browser/primitives/virtual.d.ts +4 -0
  44. package/lib/types/browser/reports.d.ts +0 -2
  45. package/lib/types/browser/session/cache.d.ts +103 -0
  46. package/lib/types/browser/session/collaboration.d.ts +53 -0
  47. package/lib/types/browser/session/recorder.d.ts +62 -0
  48. package/lib/types/browser/session/screencast.d.ts +37 -0
  49. package/lib/types/browser/session/screenshot.d.ts +17 -0
  50. package/lib/types/browser/session/semantic.d.ts +94 -0
  51. package/lib/types/browser/session/target.d.ts +16 -0
  52. package/lib/types/browser/session/tracer.d.ts +56 -0
  53. package/lib/types/browser/session.d.ts +7 -140
  54. package/lib/types/browser/stealth/keyboard.d.ts +13 -0
  55. package/lib/types/browser/stealth/mouse.d.ts +28 -0
  56. package/lib/types/browser/tools/collaboration.d.ts +73 -0
  57. package/lib/types/browser/tools/common.d.ts +67 -0
  58. package/lib/types/browser/tools/doctor.d.ts +31 -0
  59. package/lib/types/browser/tools/extract.d.ts +92 -0
  60. package/lib/types/browser/tools/inspection.d.ts +93 -0
  61. package/lib/types/browser/tools/interaction.d.ts +148 -0
  62. package/lib/types/browser/tools/navigation.d.ts +126 -0
  63. package/lib/types/browser/tools/recorder.d.ts +236 -0
  64. package/lib/types/browser/tools/testing.d.ts +94 -0
  65. package/lib/types/browser/tools.d.ts +9 -873
  66. package/lib/types/browser/types.d.ts +70 -7
  67. package/lib/types/browser/walker.d.ts +3 -12
  68. package/lib/types/client/api.d.ts +24 -0
  69. package/lib/types/client/components/ConfirmCard.d.ts +20 -0
  70. package/lib/types/client/components/FloatingOverlay.d.ts +10 -0
  71. package/lib/types/client/components/FloatingPanel.d.ts +40 -0
  72. package/lib/types/client/components/InspectionModal.d.ts +51 -0
  73. package/lib/types/client/components/SettingsSection.d.ts +5 -0
  74. package/lib/types/client/components/styles.d.ts +18 -0
  75. package/lib/types/client/hooks/useBrowserStatus.d.ts +11 -0
  76. package/lib/types/client/hooks/useConfirmPolling.d.ts +6 -0
  77. package/lib/types/client/hooks/usePickPolling.d.ts +5 -0
  78. package/lib/types/client/hooks/useRecordings.d.ts +9 -0
  79. package/lib/types/client/index.d.ts +7 -10
  80. package/lib/types/client/theme.d.ts +7 -0
  81. package/lib/types/client/types.d.ts +74 -0
  82. package/lib/types/lib/config.d.ts +0 -2
  83. package/lib/types/lib/http.d.ts +0 -2
  84. package/lib/types/lib/types.d.ts +1 -0
  85. package/package.json +13 -3
  86. package/lib/types/embed.d.ts +0 -7
@@ -0,0 +1,3 @@
1
+ import type { Locator, Page } from "playwright-core";
2
+ export declare function selectPathHelper(page: Page, trigger: string | Locator, path: string[]): Promise<boolean>;
3
+ //# sourceMappingURL=hierarchy.d.ts.map
@@ -0,0 +1,12 @@
1
+ export * from "./types.js";
2
+ export * from "./dom.js";
3
+ export * from "./dialog.js";
4
+ export * from "./select.js";
5
+ export * from "./virtual.js";
6
+ export * from "./editor.js";
7
+ export * from "./form.js";
8
+ export * from "./transfer.js";
9
+ export * from "./drag.js";
10
+ export * from "./hierarchy.js";
11
+ export * from "./temporal.js";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,7 @@
1
+ import type { SelectContext, SelectResult } from "./types.js";
2
+ /**
3
+ * 通用下拉选择原语
4
+ * 适用于原生 HTML <select> 及各类通过 Portal 挂载在 body 根节点的非标合成下拉组件
5
+ */
6
+ export declare function executeUniversalSelect(ctx: SelectContext): Promise<SelectResult>;
7
+ //# sourceMappingURL=select.d.ts.map
@@ -0,0 +1,3 @@
1
+ import type { Locator, Page } from "playwright-core";
2
+ export declare function fillDateRangeHelper(page: Page, container: string | Locator, dateValue: string | [string, string]): Promise<boolean>;
3
+ //# sourceMappingURL=temporal.d.ts.map
@@ -0,0 +1,3 @@
1
+ import type { Page } from "playwright-core";
2
+ export declare function transferItemsHelper(page: Page, selector: string, arg3: string | string[], arg4?: string | string[]): Promise<boolean>;
3
+ //# sourceMappingURL=transfer.d.ts.map
@@ -0,0 +1,48 @@
1
+ import type { Locator, Page } from "playwright-core";
2
+ /** 下拉选择上下文 */
3
+ export interface SelectContext {
4
+ page: Page;
5
+ target: Locator;
6
+ want: string;
7
+ label?: string;
8
+ exact?: boolean;
9
+ clear?: boolean;
10
+ timeout?: number;
11
+ }
12
+ /** 下拉选择执行结果 */
13
+ export interface SelectResult {
14
+ selected: string;
15
+ }
16
+ /** 表单填充条目 */
17
+ export interface FormFieldItem {
18
+ key: string;
19
+ value: any;
20
+ }
21
+ /** 表单填充汇总结果 */
22
+ export interface FormFillResult {
23
+ filled: string[];
24
+ skipped: string[];
25
+ errors: Record<string, string>;
26
+ submitted?: boolean;
27
+ }
28
+ /** 页面稳态等待选项 */
29
+ export interface QuiescenceOptions {
30
+ /** 连续无 DOM 变更的静默时间(ms),默认 80ms */
31
+ quietMs?: number;
32
+ /** 最大等待超时(ms),默认 2500ms */
33
+ maxTimeoutMs?: number;
34
+ /** 检查的根节点选择器,默认 document.body */
35
+ scope?: string;
36
+ }
37
+ /** 虚拟长列表与表格抽取选项 */
38
+ export interface VirtualExtractOptions {
39
+ /** 虚拟滚动的容器 CSS 选择器 */
40
+ scope?: string;
41
+ /** 待抽取的字段与对应列选择器字典,如 { id: ".col-id", name: ".col-name" } */
42
+ fields: Record<string, string>;
43
+ /** 最大抓取行数,默认 1000 */
44
+ maxRows?: number;
45
+ /** 每次滚动步进像素,默认 350 */
46
+ stepPixels?: number;
47
+ }
48
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,4 @@
1
+ import type { Page } from "playwright-core";
2
+ import type { VirtualExtractOptions } from "./types.js";
3
+ export declare function extractVirtualListHelper(page: Page, options: VirtualExtractOptions): Promise<Record<string, any>[]>;
4
+ //# sourceMappingURL=virtual.d.ts.map
@@ -30,8 +30,6 @@ export interface RunRecord {
30
30
  retryOf?: string;
31
31
  results: RunStepResult[];
32
32
  }
33
- /** 报告存储目录($DSH_HOME/.dsh-browser/reports)。 */
34
- export declare function reportsDir(): string;
35
33
  /** 生成 runId:YYYYMMDD-HHmmss-随机4位。 */
36
34
  export declare function makeRunId(ts: number): string;
37
35
  /** 追加一条运行记录;超限时截断旧行(原子替换)。 */
@@ -0,0 +1,103 @@
1
+ import type { Page } from "playwright-core";
2
+ import type { MarkEntry, RefEntry } from "../types.js";
3
+ /** 页面当前导航代际(0 = 尚未导航/未标记)。 */
4
+ export declare function pageNavSeq(page: Page): number;
5
+ /** 推进导航代际并返回新值;旧代际的 ref 全部标记为疑似过期。 */
6
+ export declare function bumpPageNav(page: Page): number;
7
+ export declare function noteReanchorAttempt(page: Page): void;
8
+ /** 当前代际是否已尝试过重锚定。 */
9
+ export declare function reanchorAttempted(page: Page): boolean;
10
+ /**
11
+ * 重锚定纯逻辑:按指纹把旧 ref 表映射到导航后的新扫描结果上。
12
+ * 匹配规则:role 相等 && 去-空白 name 相等(其次同 role 内 LCS ≥ 0.6 的名称
13
+ * 漂移);同指纹多命中按组内注册顺序 zip(稳定)。命中的 ref **沿用原编号**,
14
+ * 更新 selector/rect/scroll/navSeq;未命中的删除。
15
+ * 导出供测试。
16
+ */
17
+ export declare function remapRefs(oldRefs: Map<string, RefEntry>, fresh: {
18
+ role: string;
19
+ name: string;
20
+ selector: string;
21
+ rect?: {
22
+ x: number;
23
+ y: number;
24
+ w: number;
25
+ h: number;
26
+ };
27
+ scroll?: {
28
+ x: number;
29
+ y: number;
30
+ };
31
+ }[], seq: number): {
32
+ merged: Map<string, RefEntry>;
33
+ remapped: number;
34
+ dropped: number;
35
+ drifted: number;
36
+ };
37
+ /** 记录一次 aria 快照分配的 ref(整表替换)。 */
38
+ export declare function setPageRefs(page: Page, refs: Map<string, RefEntry>): void;
39
+ /** 查询某个 ref 的定位信息;未注册返回 undefined。 */
40
+ export declare function pageRef(page: Page, ref: string): RefEntry | undefined;
41
+ /** 清空页面的 ref 表(导航/新快照时调用)。 */
42
+ export declare function clearPageRefs(page: Page): void;
43
+ /** 取页面当前完整 ref 表(browser_find 增量续号合并用;无则空 Map)。 */
44
+ export declare function pageRefsOf(page: Page): Map<string, RefEntry>;
45
+ /**
46
+ * 为命中元素增量分配 ref:沿用既有注册表的编号继续(不与上次快照冲突),
47
+ * 合并写回;返回带 ref 的命中列表(上限 maxRefs,超出标 truncated)。
48
+ * 纯逻辑不依赖浏览器;findTool 与语义定位(semantic.ts)共用。
49
+ */
50
+ export declare function assignRefs(existing: Map<string, RefEntry>, matches: {
51
+ role: string;
52
+ name: string;
53
+ selector: string;
54
+ ancestors?: string[];
55
+ }[], maxRefs: number, navSeq?: number): {
56
+ withRefs: {
57
+ ref: string;
58
+ role: string;
59
+ name: string;
60
+ selector: string;
61
+ ancestors?: string[];
62
+ }[];
63
+ merged: Map<string, RefEntry>;
64
+ truncated: boolean;
65
+ };
66
+ /** 记录一次 SoM 截图的标徽表(整表替换)。 */
67
+ export declare function setPageMarks(page: Page, marks: Map<number, MarkEntry>): void;
68
+ /** 查询某个标徽的定位信息;未注册返回 undefined。 */
69
+ export declare function pageMark(page: Page, id: number): MarkEntry | undefined;
70
+ /** 清空页面的标徽表(导航时调用)。 */
71
+ export declare function clearPageMarks(page: Page): void;
72
+ /** 一个历史版本的快照内容(text/aria 两种模式共用同一条版本序列)。 */
73
+ export interface SnapshotEntry {
74
+ version: number;
75
+ text: string;
76
+ aria: string;
77
+ }
78
+ /**
79
+ * F3 增量快照历史:per-page 环形数组保存最近 K 个版本(K = snapshotHistory,
80
+ * 默认 5,上限 20;text 模式 ≤20KB/版本 → 内存上界 ≈100KB/page)。
81
+ * 任意 since ∈ [latest-K+1, latest] 都能 diff;更旧版本回落全量标 stale。
82
+ */
83
+ export interface SnapshotCache {
84
+ /** 最新版本号(单调递增,不因环形淘汰回退)。 */
85
+ version: number;
86
+ /** 最近 K 个版本,按 version 升序;长度 ≤ K。 */
87
+ history: SnapshotEntry[];
88
+ }
89
+ export declare function snapshotCacheOf(page: Page): SnapshotCache | undefined;
90
+ export declare function setSnapshotCache(page: Page, cache: SnapshotCache): void;
91
+ /** 环形容量钳制(1..20,非法值回落默认 5)。导出供测试。 */
92
+ export declare function snapshotCapacity(k: unknown): number;
93
+ /**
94
+ * 追加一个新版本并淘汰超限的最旧版本(纯逻辑,导出供测试)。
95
+ * cache 为 undefined 时从 version 1 开始;返回新缓存(不修改入参)。
96
+ */
97
+ export declare function pushSnapshotVersion(cache: SnapshotCache | undefined, content: {
98
+ text: string;
99
+ aria: string;
100
+ }, capacity: unknown): SnapshotCache;
101
+ /** 按版本号取历史条目;不在环形窗口内(更旧/未知)返回 undefined。 */
102
+ export declare function snapshotVersionEntry(cache: SnapshotCache | undefined, version: number): SnapshotEntry | undefined;
103
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1,53 @@
1
+ export declare function setPauseInstruction(instruction: string): void;
2
+ export declare function clearPauseInstruction(): void;
3
+ export declare function currentPause(): {
4
+ instruction: string;
5
+ startedAt: number;
6
+ } | null;
7
+ /** 一次待审批的敏感操作(browser_confirm 等待期间供面板展示与提交决策)。 */
8
+ export interface PendingConfirm {
9
+ id: string;
10
+ reason: string;
11
+ tool?: string;
12
+ args?: Record<string, any>;
13
+ startedAt: number;
14
+ decision?: "allowed" | "denied";
15
+ }
16
+ export declare function setPendingConfirm(entry: PendingConfirm): void;
17
+ export declare function getPendingConfirm(): PendingConfirm | null;
18
+ export declare function clearPendingConfirm(): void;
19
+ /** 面板提交审批决策;id 不匹配(已被新审批取代/超时清理)时返回 false。 */
20
+ export declare function resolveConfirm(id: string, decision: "allowed" | "denied"): boolean;
21
+ /** 一次待点选的教学请求(browser_pick_element 等待期间供面板展示与提交)。 */
22
+ export interface PendingPick {
23
+ id: string;
24
+ instruction: string;
25
+ startedAt: number;
26
+ /** 建立等待时快照的推流帧视口 CSS 尺寸(CDP metadata);坐标换算基准。 */
27
+ deviceWidth?: number;
28
+ deviceHeight?: number;
29
+ /** 面板提交的点选结果(截图位图像素坐标 + 截图尺寸)。 */
30
+ pick?: {
31
+ x: number;
32
+ y: number;
33
+ imgW: number;
34
+ imgH: number;
35
+ };
36
+ }
37
+ export declare function setPendingPick(entry: PendingPick): void;
38
+ export declare function getPendingPick(): PendingPick | null;
39
+ export declare function clearPendingPick(): void;
40
+ /** 面板提交点选坐标;id 不匹配(已被新请求取代/超时清理)时返回 false。 */
41
+ export declare function resolvePick(id: string, pick: {
42
+ x: number;
43
+ y: number;
44
+ imgW: number;
45
+ imgH: number;
46
+ }): boolean;
47
+ /** live 工具调用开始(register 包装层调用)。 */
48
+ export declare function noteToolStart(): void;
49
+ /** live 工具调用结束(成功/失败都算结束)。 */
50
+ export declare function noteToolEnd(): void;
51
+ /** 当前在途的 live 工具调用数(0 = agent 空闲)。 */
52
+ export declare function activeToolCalls(): number;
53
+ //# sourceMappingURL=collaboration.d.ts.map
@@ -0,0 +1,62 @@
1
+ import type { ReplayStep, SelectorHint } from "../types.js";
2
+ /** 已保存的录制脚本:name → 步骤数组。 */
3
+ export declare const savedRecordings: Map<string, {
4
+ steps: ReplayStep[];
5
+ savedAt: number;
6
+ }>;
7
+ /** 一次工具调用的记录(操作轨迹 / 录制 / 回放共用)。 */
8
+ export interface TestCall {
9
+ tool: string;
10
+ args: Record<string, any>;
11
+ ok: boolean;
12
+ ms: number;
13
+ ts: number;
14
+ error?: string;
15
+ /** 录制时采集的选择器指纹(回放自愈用;register 包装层异步补齐)。 */
16
+ meta?: {
17
+ hint?: SelectorHint;
18
+ source?: "human";
19
+ };
20
+ /** source: "human" 表示这条来自用户在浏览器中的手动操作(混合录制)。 */
21
+ source?: "human";
22
+ }
23
+ export declare function isRecording(): boolean;
24
+ export declare function startRecording(): void;
25
+ export declare function stopRecording(): TestCall[];
26
+ /** 最近一次完整录制(start→stop)的 buffer;从未录制过返回 null。 */
27
+ export declare function lastRecordingOf(): TestCall[] | null;
28
+ /** 操作轨迹追加(同时写入录制 buffer,排除 record/replay 自身)。返回存入的调用对象(供调用方补 meta)。 */
29
+ export declare function recordCall(call: TestCall): TestCall;
30
+ /** 操作轨迹(按时间倒序,最新在前)。 */
31
+ export declare function testLogOf(): TestCall[];
32
+ export declare function clearTestLog(): void;
33
+ /** window 上的回传 binding 名(须为合法 JS 标识符)。 */
34
+ export declare const HUMAN_BINDING = "__dshBrowserHumanEvent";
35
+ /** agent 即将/刚刚执行了 DOM 操作(register 包装层调用);1.5s 内的页内事件视为工具回声。 */
36
+ export declare function noteAgentAction(): void;
37
+ /** 导出供测试:距上次 agent 操作是否在去重窗口内。 */
38
+ export declare function agentActionRecent(now?: number, windowMs?: number): boolean;
39
+ /**
40
+ * 页内人工操作事件 → 录制步骤(纯函数,导出供测试)。
41
+ * payload 由 installHumanRecorder 生成:{ kind, selector, value?, testid?, role?, name?, id?, text?, tag? }。
42
+ * 无法映射(缺 selector / 未知 kind / 空输入)返回 null。
43
+ */
44
+ export declare function humanEventToStep(payload: unknown): {
45
+ tool: string;
46
+ args: Record<string, any>;
47
+ meta: {
48
+ hint: SelectorHint;
49
+ source: "human";
50
+ };
51
+ } | null;
52
+ /** binding 回调入站口:仅录制中生效;去重窗口内(agent 工具回声)丢弃。 */
53
+ export declare function handleHumanEvent(payload: unknown): void;
54
+ /**
55
+ * 页内注入的人工操作监听(addInitScript 序列化;每次导航自动重装)。
56
+ * 监听常驻但 node 侧只在录制中生效,关闭录制等价于"移除"。
57
+ * 只上报可交互元素上的 click 与表单控件的 change,避免逐键噪音。
58
+ * F5 收敛:cssPath 等元素描述来自 walker.ts 单一来源(构建期拼装注入),
59
+ * 不再持有内联副本;payload 字段语义与 v0.3 完全一致。
60
+ */
61
+ export declare const installHumanRecorder: (payload: unknown) => void;
62
+ //# sourceMappingURL=recorder.d.ts.map
@@ -0,0 +1,37 @@
1
+ import type { Page } from "playwright-core";
2
+ export interface ScreencastFrame {
3
+ /** 原始 JPEG 图像 Buffer */
4
+ buffer: Buffer;
5
+ /** Base64 编码字符串 */
6
+ base64: string;
7
+ /** CDP 帧元数据 (如 deviceWidth, deviceHeight, pageScaleFactor 等) */
8
+ metadata: Record<string, any>;
9
+ timestamp: number;
10
+ }
11
+ export type FrameListener = (frame: ScreencastFrame) => void;
12
+ declare class ScreencastManager {
13
+ private cdp;
14
+ private currentPage;
15
+ private listeners;
16
+ private isStarting;
17
+ private lastFrame;
18
+ /**
19
+ * 注册帧监听器。返回注销函数。
20
+ * 当第一个监听器加入时自动激活 CDP Screencast;
21
+ * 当所有监听器离开时自动注销并停止 CDP,实现零空载开销。
22
+ */
23
+ subscribe(listener: FrameListener): () => void;
24
+ get subscriberCount(): number;
25
+ getLastFrame(): ScreencastFrame | null;
26
+ /**
27
+ * 启动 CDP Screencast
28
+ */
29
+ start(targetPage?: Page | null): Promise<boolean>;
30
+ /**
31
+ * 停止 CDP Screencast,静默释放资源
32
+ */
33
+ stop(): Promise<void>;
34
+ }
35
+ export declare const screencastManager: ScreencastManager;
36
+ export {};
37
+ //# sourceMappingURL=screencast.d.ts.map
@@ -0,0 +1,17 @@
1
+ /** 记录最近一次截图目录(截图工具调用时写入)。 */
2
+ export declare function noteScreenshotDir(dir: string): void;
3
+ /** 定时清扫入口:若已知截图目录则按当前配置清理。 */
4
+ export declare function sweepScreenshotDir(opts: {
5
+ maxAgeDays?: number;
6
+ maxCount?: number;
7
+ }): number;
8
+ /**
9
+ * 清理截图目录里的 .png 文件:按修改时间保留最新的 maxCount 个,
10
+ * 并删除超过 maxAgeDays 天的旧文件。只处理目录直属文件,不递归;
11
+ * 单个文件删除失败(被占用等)静默跳过。返回删除数量。
12
+ */
13
+ export declare function cleanupScreenshots(dir: string, opts: {
14
+ maxAgeDays?: number;
15
+ maxCount?: number;
16
+ }): number;
17
+ //# sourceMappingURL=screenshot.d.ts.map
@@ -0,0 +1,94 @@
1
+ import type { Page } from "playwright-core";
2
+ import type { TargetResolution } from "../types.js";
3
+ /** 页内扫描命中的元素(带打分与上下文)。 */
4
+ export interface SemanticMatch {
5
+ role: string;
6
+ name: string;
7
+ selector: string;
8
+ text: string;
9
+ visible: boolean;
10
+ inDialog: boolean;
11
+ /** 命中得分:name 命中权重 3 / testid·id 2 / text·role 1,多 token 求和;传统子串命中加基础分。 */
12
+ score: number;
13
+ ancestors: string[];
14
+ }
15
+ /** 语义未命中时返回的最相近候选。 */
16
+ export interface SemanticCandidate {
17
+ role: string;
18
+ name: string;
19
+ selector: string;
20
+ score: number;
21
+ }
22
+ /** 语义未命中结果(与 TargetResolution 用 "candidates" 字段区分)。 */
23
+ export interface SemanticMiss {
24
+ what: string;
25
+ candidates: SemanticCandidate[];
26
+ }
27
+ /**
28
+ * 页内语义扫描:按 query 打分收集可交互元素(弹窗内优先、可见优先、高分优先)。
29
+ * 匹配语义与 browser_find 完全一致(去空白归一化支持 antd「确 定」分词);
30
+ * 多 token(空格/中英混排拆分)按 AND 命中 —— 单 token 行为与旧子串匹配等价。
31
+ */
32
+ export declare const scanInteractive: (payload: {
33
+ query: string;
34
+ exact: boolean;
35
+ scope: string;
36
+ limit: number;
37
+ dialogSelector?: string;
38
+ }) => {
39
+ matches: SemanticMatch[];
40
+ candidates: {
41
+ role: string;
42
+ name: string;
43
+ selector: string;
44
+ }[];
45
+ scanned: number;
46
+ };
47
+ /**
48
+ * 语义未命中时候选排序(纯逻辑,导出供测试):按与 query 的最长公共子串
49
+ * 打分取 top5,阈值与 topSuggestions 一致(短 query ≥1,长 query ≥2)。
50
+ */
51
+ export declare function semanticMissCandidates(query: string, candidates: {
52
+ role: string;
53
+ name: string;
54
+ selector: string;
55
+ }[], count?: number): SemanticCandidate[];
56
+ /** 语义未命中的错误消息(候选表内嵌,agent 不必再跑一轮 find)。 */
57
+ export declare function semanticMissMessage(miss: SemanticMiss): string;
58
+ /**
59
+ * 意图语义定位:what → 打分扫描 → 命中注册成正式 ref 并返回标准
60
+ * TargetResolution(含 matchedCount/visibleCount,与 selector 路径无缝衔接);
61
+ * 零命中返回 SemanticMiss(候选由调用方决定呈现方式)。
62
+ */
63
+ export declare function resolveSemanticTarget(page: Page, what: string, opts?: {
64
+ exact?: boolean;
65
+ scope?: string;
66
+ limit?: number;
67
+ maxRefs?: number;
68
+ }): Promise<TargetResolution | SemanticMiss>;
69
+ /**
70
+ * 全量可交互元素扫描(SPA ref 重锚定的数据源):返回页面(或 scope 内)全部
71
+ * 可见可交互元素的 role/name/selector(视口内附 rect/scroll),与 aria 快照
72
+ * 同一 walker 语义。上限 300 条,超出截断(超大页面重锚定按命中部分处理)。
73
+ */
74
+ export declare const scanAllInteractive: (payload: {
75
+ scope?: string;
76
+ }) => {
77
+ elements: {
78
+ role: string;
79
+ name: string;
80
+ selector: string;
81
+ rect?: {
82
+ x: number;
83
+ y: number;
84
+ w: number;
85
+ h: number;
86
+ };
87
+ scroll?: {
88
+ x: number;
89
+ y: number;
90
+ };
91
+ }[];
92
+ truncated: boolean;
93
+ };
94
+ //# sourceMappingURL=semantic.d.ts.map
@@ -0,0 +1,16 @@
1
+ import type { Locator, Page } from "playwright-core";
2
+ import type { TargetResolution } from "../types.js";
3
+ /**
4
+ * 构造对字符间/词间任意空白不敏感的匹配正则。
5
+ * 处理中英文混排、单字间隔、Tab、换行以及 &nbsp; 等特殊空白字符。
6
+ */
7
+ export declare function buildFlexibleTextPattern(text: string): RegExp;
8
+ /**
9
+ * 统一解析目标元素:
10
+ * 自动识别 selector 或 ref;若 ref 标记位于子 Frame,自动绑定到对应子 Frame 上下文。
11
+ * 具备路径防漂移校验与 getByRole 自愈降级能力。
12
+ */
13
+ export declare function resolveTargetLocator(page: Page, args: Record<string, any>): Promise<TargetResolution>;
14
+ /** 兼容旧版签名的目标定位快捷方式 */
15
+ export declare function targetLocator(page: Page, args: Record<string, any>): Promise<Locator>;
16
+ //# sourceMappingURL=target.d.ts.map
@@ -0,0 +1,56 @@
1
+ import type { Page } from "playwright-core";
2
+ export interface ConsoleLogEntry {
3
+ type: string;
4
+ text: string;
5
+ timestamp: number;
6
+ stepId?: string;
7
+ }
8
+ export interface FailedRequestEntry {
9
+ url: string;
10
+ method: string;
11
+ status?: number;
12
+ error?: string;
13
+ timestamp: number;
14
+ stepId?: string;
15
+ }
16
+ export interface StepTraceEntry {
17
+ stepId: string;
18
+ stepIndex: number;
19
+ tool: string;
20
+ args?: Record<string, any>;
21
+ url: string;
22
+ startedAt: number;
23
+ durationMs: number;
24
+ success: boolean;
25
+ error?: string;
26
+ consoleLogs: ConsoleLogEntry[];
27
+ failedRequests: FailedRequestEntry[];
28
+ thumbnail?: string;
29
+ /** 定位失败遥测(M6):失败阶段 + 页面特征,随 /timeline 透出,为按真实流量优化提供数据。 */
30
+ locationFailure?: {
31
+ phase: "zeroMatch" | "ambiguous" | "dialogOverlay" | "staleRef" | "coordinateMiss";
32
+ candidates: number;
33
+ dialogActive: boolean;
34
+ hasShadow: boolean;
35
+ };
36
+ }
37
+ declare class SessionTracer {
38
+ private consoleLogsByProfile;
39
+ private failedRequestsByProfile;
40
+ private tracesByProfile;
41
+ private activeStepByProfile;
42
+ private stepCounter;
43
+ /** 记录 Console 输出 */
44
+ recordConsole(profile: string, entry: ConsoleLogEntry): void;
45
+ /** 记录失败网络请求 (4xx/5xx 或网络断裂) */
46
+ recordFailedRequest(profile: string, entry: FailedRequestEntry): void;
47
+ /** 步骤开始 */
48
+ startStep(profile: string, tool: string, args?: Record<string, any>, page?: Page | null): string;
49
+ /** 步骤结束并归档 */
50
+ endStep(profile: string, success: boolean, error?: string, page?: Page | null, locationFailure?: StepTraceEntry["locationFailure"]): Promise<StepTraceEntry | null>;
51
+ getTraces(profile: string): StepTraceEntry[];
52
+ clear(profile?: string): void;
53
+ }
54
+ export declare const sessionTracer: SessionTracer;
55
+ export {};
56
+ //# sourceMappingURL=tracer.d.ts.map