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
@@ -1,874 +1,10 @@
1
- import type { Locator, Page } from "playwright-core";
2
- import type { ToolRunContext } from "../lib/types.js";
3
- import type { BrowserConfig, RefEntry, ReplayStep, SelectorHint } from "./types.js";
4
- import { type RunRecord } from "./reports.js";
5
- /** 读取 PNG 文件头(IHDR)中的宽高,不解码像素(导出供测试)。 */
6
- export declare function pngSize(buf: Buffer): {
7
- width: number;
8
- height: number;
9
- };
10
- /** 按缩放比例换算 mask 矩形(导出供测试;与页内比对共用同一套坐标语义)。 */
11
- export declare function scaleRects(rects: {
12
- x: number;
13
- y: number;
14
- width: number;
15
- height: number;
16
- }[], scale: number): {
17
- x: number;
18
- y: number;
19
- width: number;
20
- height: number;
21
- }[];
22
- export declare function openTool(config: BrowserConfig, args: Record<string, any>): Promise<{
23
- url: string;
24
- title: string;
25
- status: string;
26
- }>;
27
- /**
28
- * 快照文本压缩(导出供测试):
29
- * - 去掉首尾空白行;
30
- * - 连续空白行折叠为 1 行;
31
- * - 连续重复的非空行(表格空单元格/占位行产生的噪音)折叠为「首行 + …(重复 N 行)」。
32
- * 只折叠完全相同的相邻行,不重排、不删改非重复内容。
33
- */
34
- export declare function compressText(text: string): string;
35
- /** 最长公共子串长度(小写比较;零依赖,导出供测试)。 */
36
- export declare function lcsScore(a: string, b: string): number;
37
- /** 零命中时按相似度挑 top5 候选(导出供测试)。 */
38
- export declare function topSuggestions(query: string, candidates: {
39
- role: string;
40
- name: string;
41
- }[], count?: number): {
42
- role: string;
43
- name: string;
44
- score: number;
45
- }[];
46
- /**
47
- * 为命中元素增量分配 ref:沿用既有注册表的编号继续(不与上次快照冲突),
48
- * 合并写回;返回带 ref 的命中列表(上限 maxRefs,超出标 truncated)。
49
- * 导出供测试(纯逻辑,不依赖浏览器)。
50
- */
51
- export declare function assignRefs(existing: Map<string, RefEntry>, matches: {
52
- role: string;
53
- name: string;
54
- selector: string;
55
- ancestors: string[];
56
- library?: string;
57
- component?: string;
58
- sourceFile?: string;
59
- formLabel?: string;
60
- }[], maxRefs: number): {
61
- withRefs: {
62
- ref: string;
63
- role: string;
64
- name: string;
65
- selector: string;
66
- ancestors: string[];
67
- library?: string;
68
- component?: string;
69
- sourceFile?: string;
70
- formLabel?: string;
71
- }[];
72
- merged: Map<string, RefEntry>;
73
- truncated: boolean;
74
- };
75
- /**
76
- * 语义元素定位:按名称(或 id/data-testid/组件名/源码文件)在可交互元素中查找,只返回命中的
77
- * ref + 区域上下文,不输出全量 aria 树 —— 大页面定位单个目标时 token 开销
78
- * 远小于 browser_snapshot { mode: "aria" }。返回的 ref 可直接用于
79
- * click/type/select/press。零命中不抛错,附最相近候选供二次定位。
80
- */
81
- export declare function findTool(config: BrowserConfig, args: Record<string, any>): Promise<{
82
- scanned: number;
83
- url: string;
84
- title: string;
85
- truncated?: true | undefined;
86
- suggestions?: {
87
- role: string;
88
- name: string;
89
- score: number;
90
- }[] | undefined;
91
- found: number;
92
- matches: {
93
- formLabel?: string | undefined;
94
- sourceFile?: string | undefined;
95
- component?: string | undefined;
96
- library?: string | undefined;
97
- ref: string;
98
- role: string;
99
- name: string;
100
- ancestors: string[];
101
- }[];
102
- }>;
103
- /**
104
- * 行级 diff:掐掉公共前缀/后缀,返回变化区。导出供测试。
105
- * 全等返回 { unchanged: true };否则 changedFrom 为新文本中变化区首行(1 起)。
106
- */
107
- export declare function diffLines(oldText: string, newText: string): {
108
- unchanged: boolean;
109
- changedFrom?: number;
110
- lines?: string[];
111
- removed?: number;
112
- };
113
- export declare function snapshotTool(config: BrowserConfig, args: Record<string, any>): Promise<{
114
- url: string;
115
- title: string;
116
- scope?: string | undefined;
117
- unchanged: boolean;
118
- contentVersion: number;
119
- } | {
120
- url: string;
121
- title: string;
122
- truncated: boolean;
123
- scope?: string | undefined;
124
- diff: boolean;
125
- contentVersion: number;
126
- changedFrom: number | undefined;
127
- removed: number | undefined;
128
- } | {
129
- url: string;
130
- title: string;
131
- truncated: boolean;
132
- scope?: string | undefined;
133
- stale?: boolean | undefined;
134
- contentVersion: number;
135
- }>;
136
- /**
137
- * 解析点击/输入目标为 Locator:selector 直译;ref 走注册表——
138
- * 先试快照时的 CSS 路径并校验 role/name 仍一致(防 ref 漂移误点),
139
- * 不一致则降级 getByRole(role, {name}),均失败报「ref 已失效」。
140
- */
141
- export declare function targetLocator(page: Page, args: Record<string, any>): Promise<Locator>;
142
- export declare function clickTool(config: BrowserConfig, args: Record<string, any>): Promise<{
143
- url: string;
144
- title: string;
145
- clicked: string;
146
- }>;
147
- export declare function typeTool(config: BrowserConfig, args: Record<string, any>): Promise<{
148
- url: string;
149
- title: string;
150
- typed: boolean;
151
- selector: string;
152
- submit: boolean;
153
- }>;
154
- export declare function pressTool(config: BrowserConfig, args: Record<string, any>): Promise<{
155
- url: string;
156
- title: string;
157
- pressed: string;
158
- }>;
159
- /** 给本身无超时的 Playwright 调用(evaluate/allTextContents)加有界保护,防页面主线程忙时无限挂起。 */
160
- export declare function withTimeout<T>(p: Promise<T>, ms: number, what: string): Promise<T>;
161
- /**
162
- * 下拉选择原语:原生 <select> 走 selectOption;组件库下拉(antd/element/listbox)
163
- * 走「点击触发框 → 等待可见选项 → 按文本点击」。找不到选项时抛出错误并附当前可见
164
- * 选项清单,agent 可直接据此修正,无需再手写 eval 探查。
165
- */
166
- export declare function selectTool(config: BrowserConfig, args: Record<string, any>): Promise<{
167
- url: string;
168
- title: string;
169
- selected: string;
170
- selector: string;
171
- }>;
172
- /**
173
- * 防御性解码 eval 脚本:模型/人工偶发把脚本 JSON.stringify 一次再传
174
- * (脚本以 \" 开头、换行变字面 \\n),回放/录制链路不纠错会导致语法错误。
175
- * 识别条件:字符串以引号包裹且含反斜杠转义,且 JSON.parse 结果仍是字符串。
176
- * 无法解析或语义不变场景原样返回(裸字符串字面量如 "hello" 不含转义,不受影响)。
177
- */
178
- export declare function unwrapDoubleEncodedScript(script: string): {
179
- script: string;
180
- unwrapped: boolean;
181
- };
182
- export declare function evalTool(config: BrowserConfig, args: Record<string, any>): Promise<{
183
- scriptUnwrapped?: boolean | undefined;
184
- result: unknown;
185
- }>;
186
- export declare function screenshotTool(config: BrowserConfig, args: Record<string, any>, exec?: ToolRunContext): Promise<{
187
- path: string;
188
- bytes: number;
189
- width: number;
190
- height: number;
191
- baseline: string;
192
- } | {
193
- path: string;
194
- bytes: number;
195
- width: number;
196
- height: number;
197
- baseline?: undefined;
198
- }>;
199
- export declare function waitTool(config: BrowserConfig, args: Record<string, any>): Promise<{
200
- url: string;
201
- title: string;
202
- waitedMs: number;
203
- }>;
204
- export declare function backTool(config: BrowserConfig): Promise<{
205
- url: string;
206
- title: string;
207
- }>;
208
- export declare function reloadTool(config: BrowserConfig): Promise<{
209
- url: string;
210
- title: string;
211
- }>;
212
- /** 一项诊断结果(ok=false 时附 advice 修复建议)。导出供测试。 */
213
- export interface DoctorCheck {
214
- name: string;
215
- ok: boolean;
216
- detail: string;
217
- advice?: string;
218
- }
219
- export declare function setDoctorProbe(fn: ((basePath: string) => Promise<{
220
- ok: boolean;
221
- detail: string;
222
- advice?: string;
223
- }>) | null): void;
224
- /** 目录可写性检查(mkdir + 写探针文件 + 删除)。导出供测试。 */
225
- export declare function checkWritableDir(dir: string): {
226
- ok: boolean;
227
- detail: string;
228
- };
229
- /** 可执行文件存在性检查(executablePath 显式配置用)。导出供测试。 */
230
- export declare function checkExecutable(path: string): DoctorCheck;
231
- /**
232
- * 命名隔离上下文:同一浏览器进程内独立 cookies/storage 的"标签组"。
233
- * 页注册进 profile 标签表(所有既有工具直接可用),context 只做归属记录:
234
- * list / new(name?, url?) / switch(激活该组的一页,没有则新开) / close(整组关闭)。
235
- * 持久模式(userDataDir)浏览器只有单一 context,不支持本工具(用 profiles 替代)。
236
- */
237
- export declare function contextTool(config: BrowserConfig, args: Record<string, any>): Promise<{
238
- contexts: {
239
- name: string;
240
- pages: number;
241
- active: boolean;
242
- createdAt: number;
243
- }[];
244
- profile: string;
245
- closed?: undefined;
246
- remainingTabs?: undefined;
247
- } | {
248
- url: string;
249
- title: string;
250
- navigated?: string | undefined;
251
- created: string;
252
- contexts?: undefined;
253
- profile?: undefined;
254
- closed?: undefined;
255
- remainingTabs?: undefined;
256
- } | {
257
- url: string;
258
- title: string;
259
- switched: string;
260
- contexts?: undefined;
261
- profile?: undefined;
262
- closed?: undefined;
263
- remainingTabs?: undefined;
264
- } | {
265
- url: string;
266
- title: string;
267
- switched: string;
268
- pages: number;
269
- contexts?: undefined;
270
- profile?: undefined;
271
- closed?: undefined;
272
- remainingTabs?: undefined;
273
- } | {
274
- closed: string;
275
- remainingTabs: number;
276
- contexts?: undefined;
277
- profile?: undefined;
278
- }>;
279
- /**
280
- * 操作预告高亮:agent 即将 click/type/select/press 的元素在页面上琥珀色描边
281
- * ~1.5 秒。异步不阻塞(fire-and-forget,任何失败静默),不影响操作时序。
282
- */
283
- export declare function previewHighlight(page: Page | null, selector: string, label: string): void;
284
- /** 一次性健康诊断:不启动浏览器,只做静态/本地检查。 */
285
- export declare function doctorTool(config: BrowserConfig, _args: Record<string, any>, exec?: ToolRunContext): Promise<{
286
- checks: DoctorCheck[];
287
- summary: {
288
- ok: boolean;
289
- passed: number;
290
- failed: number;
291
- };
292
- }>;
293
- export declare function statusTool(): Promise<{
294
- open: boolean;
295
- profile: string;
296
- channel: string;
297
- tabs: number;
298
- profiles: {
299
- name: string;
300
- open: boolean;
301
- tabs: number;
302
- channel: string;
303
- persistent: boolean;
304
- }[];
305
- } | {
306
- url: string;
307
- title: string;
308
- open: boolean;
309
- profile: string;
310
- channel: string;
311
- tabs: number;
312
- profiles: {
313
- name: string;
314
- open: boolean;
315
- tabs: number;
316
- channel: string;
317
- persistent: boolean;
318
- }[];
319
- }>;
320
- export declare function tabsTool(config: BrowserConfig, args: Record<string, any>): Promise<{
321
- action: any;
322
- tabs: {
323
- id: number;
324
- url: string;
325
- title: string;
326
- }[];
327
- activeId: number;
328
- tab?: undefined;
329
- } | {
330
- action: any;
331
- tab: {
332
- id: number;
333
- url: string;
334
- title: string;
335
- };
336
- tabs: {
337
- id: number;
338
- url: string;
339
- title: string;
340
- }[];
341
- activeId: number;
342
- }>;
343
- export declare function resolveTabId(args: Record<string, any>): number;
344
- export declare function downloadTool(config: BrowserConfig, args: Record<string, any>, exec?: ToolRunContext): Promise<{
345
- path: string;
346
- filename: string;
347
- url: string;
348
- bytes: number;
349
- }>;
350
- export declare function uploadTool(config: BrowserConfig, args: Record<string, any>, exec?: ToolRunContext): Promise<{
351
- url: string;
352
- title: string;
353
- uploaded: string;
354
- bytes: number;
355
- }>;
356
- export declare function cookiesTool(config: BrowserConfig, args: Record<string, any>): Promise<{
357
- cookies: {
358
- name: string;
359
- value: string;
360
- domain: string;
361
- path: string;
362
- httpOnly: boolean;
363
- secure: boolean;
364
- sameSite: "Strict" | "Lax" | "None";
365
- expires: number;
366
- }[];
367
- set?: undefined;
368
- name?: undefined;
369
- url?: undefined;
370
- cleared?: undefined;
371
- } | {
372
- set: boolean;
373
- name: string;
374
- url: any;
375
- cookies?: undefined;
376
- cleared?: undefined;
377
- } | {
378
- cleared: boolean;
379
- cookies?: undefined;
380
- set?: undefined;
381
- name?: undefined;
382
- url?: undefined;
383
- }>;
384
- export declare function formTool(config: BrowserConfig, args: Record<string, any>): Promise<{
385
- url: string;
386
- title: string;
387
- filled: ({
388
- selector: any;
389
- label?: undefined;
390
- } | {
391
- label: any;
392
- selector?: undefined;
393
- })[];
394
- submit: boolean;
395
- }>;
396
- export declare function formSaveTool(args: Record<string, any>): Promise<{
397
- saved: string;
398
- fields: number;
399
- }>;
400
- export declare function formsTool(args: Record<string, any>): Promise<{
401
- forms: {
402
- name: string;
403
- fields: number;
404
- preview: string;
405
- }[];
406
- deleted?: undefined;
407
- name?: undefined;
408
- } | {
409
- deleted: boolean;
410
- name: string;
411
- forms?: undefined;
412
- }>;
413
- export declare function profileTool(config: BrowserConfig, args: Record<string, any>): Promise<{
414
- current: string;
415
- profiles: {
416
- name: string;
417
- open: boolean;
418
- tabs: number;
419
- persistent: boolean;
420
- userDataDir: string;
421
- }[];
422
- }>;
423
- export declare function elementsTool(config: BrowserConfig, args: Record<string, any>): Promise<{
424
- count: number;
425
- elements: Record<string, unknown>[];
426
- dropdownOptions: string[];
427
- }>;
428
- export declare function closeTool(): Promise<{
429
- closed: boolean;
430
- }>;
431
- /**
432
- * 条件检查引擎(测试原语共用)。
433
- *
434
- * cond 支持四类(每类内部互斥,取第一个存在的字段):
435
- * { selector: "#btn", state: "visible|hidden|attached|detached" } 元素状态(默认 visible)
436
- * { url: "正则字符串" } 当前 URL 匹配
437
- * { text: "子串" } body 可见文本包含
438
- * { count: { selector, op: "eq|gt|gte|lt|lte", value: n } } 元素数量比较
439
- * { eval: "JS 表达式" } 表达式求值 truthy
440
- */
441
- export type TestCondition = Record<string, any>;
442
- /** 单次检查:返回 { ok, detail }。不抛错,失败时 detail 给出原因。 */
443
- export declare function checkOnce(page: Page, cond: TestCondition): Promise<{
444
- ok: boolean;
445
- detail?: string;
446
- }>;
447
- /** 轮询等待条件成立(intervalMs 步进),返回最后一次检查结果。 */
448
- export declare function pollCondition(page: Page, cond: TestCondition, timeoutMs: number, intervalMs?: number): Promise<{
449
- ok: boolean;
450
- detail?: string;
451
- }>;
452
- /** 通用显式等待:等待条件成立,超时抛错。 */
453
- export declare function waitForTool(config: BrowserConfig, args: Record<string, any>): Promise<{
454
- url: string;
455
- title: string;
456
- met: boolean;
457
- }>;
458
- /**
459
- * 等待人工登录完成(配合 headless:false 使用):agent 打开登录页后调用本工具,
460
- * 提示用户在浏览器窗口中完成登录(输入/扫码/双因素)。基于通用条件引擎:
461
- * successSelector / successUrl 指定完成条件,两者都不给则以 URL 跳转视为完成。
462
- * 超时返回 loggedIn:false(不抛错)。
463
- */
464
- export declare function waitForLoginTool(config: BrowserConfig, args: Record<string, any>): Promise<{
465
- url: string;
466
- title: string;
467
- loggedIn: boolean;
468
- }>;
469
- /**
470
- * 人工接管等待(通用版 wait_for_login):agent 把控制权交还给用户(验证码 /
471
- * 二次确认 / 人工复核等)。instruction 会显示在实时画面面板;完成条件三选一:
472
- * successSelector(元素出现)/ successUrl(URL 正则)/ 两者都不给则以
473
- * URL 变化或页面内容签名变化视为完成。轮询间隔 2 秒,超时返回 completed:false
474
- * (不抛错)。导出 runPauseOnPage 供测试注入 fake page。
475
- */
476
- export declare function runPauseOnPage(page: Page, args: Record<string, any>): Promise<{
477
- completed: boolean;
478
- waitedMs: number;
479
- detail: string;
480
- }>;
481
- /** 人工接管等待工具入口(缺 instruction 在启动浏览器前即校验,失败更快)。 */
482
- export declare function pauseForHumanTool(config: BrowserConfig, args: Record<string, any>): Promise<{
483
- url: string;
484
- title: string;
485
- completed: boolean;
486
- status: "completed" | "timedOut";
487
- instruction: string;
488
- detail: string;
489
- waitedMs: number;
490
- }>;
491
- /**
492
- * 敏感操作审批:agent 在执行提交/删除/支付类动作前调用,把审批请求推到实时
493
- * 画面面板,挂起等待用户点「允许/拒绝」。超时视为拒绝(fail-closed)。
494
- * 用户允许时返回 { decision: "allowed", ... };拒绝/超时**抛错**(消息含原因),
495
- * 使 live 调用与 replay/batch 步骤统一按失败处理,agent 不应继续敏感动作。
496
- * 决策通过 session.resolveConfirm(面板 POST)写入。
497
- */
498
- export declare function confirmTool(config: BrowserConfig, args: Record<string, any>): Promise<{
499
- decision: "allowed";
500
- id: string;
501
- reason: string;
502
- waitedMs: number;
503
- detail: string;
504
- }>;
505
- /** auto 模式默认敏感文本模式(提交/删除/支付类)。 */
506
- export declare const DEFAULT_SENSITIVE_PATTERNS: string[];
507
- /** auto 模式默认参与判定的工具(已决:只拦 browser_click,type 误报率高)。 */
508
- export declare const DEFAULT_SENSITIVE_TOOLS: string[];
509
- /** 敏感判定的元素描述(与 walker describeElement 字段子集对应)。 */
510
- export interface SensitiveDesc {
511
- role: string;
512
- name: string;
513
- text: string;
514
- id: string;
515
- testid: string;
516
- tag: string;
517
- }
518
- /**
519
- * 纯逻辑:元素描述命中了哪些敏感模式(role/name/text/id/testid/tag 拼接后
520
- * 子串匹配,大小写不敏感;空白模式忽略)。返回命中的模式列表(空 = 放行)。
521
- * 导出供测试。
522
- */
523
- export declare function sensitiveHits(desc: SensitiveDesc | null, patterns: string[]): string[];
524
- /**
525
- * auto 模式审批闸:命中敏感模式时经 confirmTool 弹审批等待用户决策,
526
- * 拒绝/超时抛错(调用方该步失败),允许则返回继续执行原工具。
527
- * 不满足前置条件(非 auto / 工具不在 sensitiveTools / 无模式 / 无活动页 /
528
- * 无目标 selector / 页内取描述失败)一律直接放行,由原工具自行处理错误。
529
- * page 参数仅供测试注入;缺省取当前活动页。
530
- */
531
- export declare function confirmGate(config: BrowserConfig, tool: string, args: Record<string, any>, page?: Page | null): Promise<void>;
532
- /** 断言:条件在 timeoutMs 内成立则通过,否则失败并自动截图存证据。visual 断言走像素比对。 */
533
- export declare function assertTool(config: BrowserConfig, args: Record<string, any>, exec?: ToolRunContext): Promise<{
534
- url: string;
535
- title: string;
536
- passed: boolean;
537
- visual: {
538
- baseline: string;
539
- diffRatio: number;
540
- diffPixels: number;
541
- };
542
- } | {
543
- url: string;
544
- title: string;
545
- passed: boolean;
546
- }>;
547
- /** 网络记录查询:list / failed / wait / clear。 */
548
- export declare function networkTool(args: Record<string, any>): Promise<{
549
- cleared: boolean;
550
- entries: never[];
551
- matched?: undefined;
552
- waitMs?: undefined;
553
- stats?: undefined;
554
- failed?: undefined;
555
- } | {
556
- matched: import("./session.js").NetworkEntry;
557
- waitMs: number;
558
- cleared?: undefined;
559
- entries?: undefined;
560
- stats?: undefined;
561
- failed?: undefined;
562
- } | {
563
- stats: {
564
- host: string;
565
- total: number;
566
- failed: number;
567
- avgMs: number | null;
568
- byStatus: Record<string, number>;
569
- }[];
570
- cleared?: undefined;
571
- entries?: undefined;
572
- matched?: undefined;
573
- waitMs?: undefined;
574
- failed?: undefined;
575
- } | {
576
- failed: import("./session.js").NetworkEntry[];
577
- cleared?: undefined;
578
- entries?: undefined;
579
- matched?: undefined;
580
- waitMs?: undefined;
581
- stats?: undefined;
582
- } | {
583
- entries: import("./session.js").NetworkEntry[];
584
- cleared?: undefined;
585
- matched?: undefined;
586
- waitMs?: undefined;
587
- stats?: undefined;
588
- failed?: undefined;
589
- }>;
590
- /** 使用 args.selector 定位的工具集合(自愈与录制指纹的作用范围)。 */
591
- export declare const SELECTOR_STEP_TOOLS: Set<string>;
592
- /**
593
- * 采集选择器指向元素的指纹(页内 evaluate;找不到元素返回 null)。
594
- * 指纹是回放自愈的降级候选来源:testid / role+name / text / id / tag+text。
595
- * F5 收敛:元素描述(role/name/text)改用 walker 单一来源
596
- * (describeElement),与 aria 快照/find/录制回声共用同一套语义;相比旧
597
- * 内联副本,role 推断更完整(slider/spinbutton/searchbox/heading 等),
598
- * name 补齐 labelledby/label[for]/title 兜底 —— 指纹只作自愈降级候选,
599
- * 语义增强只会让自愈命中率更高,不改变任何主链路行为。
600
- */
601
- export declare function captureSelectorHint(page: Page, selector: string): Promise<SelectorHint | null>;
602
- /** 由指纹生成自愈降级候选(按优先级排序;导出供测试)。 */
603
- export declare function healCandidates(hint: SelectorHint): {
604
- via: string;
605
- selector: string;
606
- }[];
607
- /** 录制管理:start / stop / save / list / delete。 */
608
- export declare function recordTool(args: Record<string, any>): Promise<{
609
- recording: boolean;
610
- hint: string;
611
- steps?: undefined;
612
- recordings?: undefined;
613
- deleted?: undefined;
614
- name?: undefined;
615
- } | {
616
- recording: boolean;
617
- steps: number;
618
- hint?: undefined;
619
- recordings?: undefined;
620
- deleted?: undefined;
621
- name?: undefined;
622
- } | {
623
- hint: string;
624
- warnings?: string[] | undefined;
625
- varsApplied?: number | undefined;
626
- skippedFailed?: number | undefined;
627
- stripped?: number | undefined;
628
- saved: string;
629
- steps: number;
630
- source: string;
631
- file: string;
632
- recording?: undefined;
633
- recordings?: undefined;
634
- deleted?: undefined;
635
- name?: undefined;
636
- } | {
637
- recordings: {
638
- name: string;
639
- steps: number;
640
- savedAt: number;
641
- preview: string;
642
- }[];
643
- recording?: undefined;
644
- hint?: undefined;
645
- steps?: undefined;
646
- deleted?: undefined;
647
- name?: undefined;
648
- } | {
649
- deleted: boolean;
650
- name: string;
651
- recording?: undefined;
652
- hint?: undefined;
653
- steps?: undefined;
654
- recordings?: undefined;
655
- }>;
656
- /** 回放选项(自愈开关与单次尝试超时,来自 config;retryFailed 为自动重试次数)。 */
657
- export interface ReplayOptions {
658
- healing?: boolean;
659
- healTimeoutMs?: number;
660
- /** F2:步骤失败(含自愈链耗尽)后自动重试的次数,步骤间 500ms×n 线性退避。 */
661
- retryFailed?: number;
662
- }
663
- /** 回放执行器(步骤 → 工具调用),由 register.ts 注入实现 map。支持选择器自愈。 */
664
- export declare function runReplay(steps: ReplayStep[], impls: Record<string, (args: any) => Promise<unknown>>, failFast: boolean, opts?: ReplayOptions): Promise<{
665
- total: number;
666
- passed: number;
667
- failed: number;
668
- healedCount: number;
669
- retries?: {
670
- attempted: number;
671
- recovered: number;
672
- };
673
- stoppedAt?: number;
674
- results: any[];
675
- }>;
676
- export interface ExtractField {
677
- name: string;
678
- selector: string;
679
- attr?: string;
680
- multiple?: boolean;
681
- fields?: ExtractField[];
682
- }
683
- /**
684
- * 把单页抽取结果规整为行数组:恰好一个顶层 multiple 字段时,其数组即行
685
- * (行内嵌套对象为行,标量包装成 { [name]: value });否则整页算一行。
686
- */
687
- export declare function rowsOfExtract(result: Record<string, any>, fields: ExtractField[]): Record<string, any>[];
688
- /** 工作区内落盘路径解析(拒绝穿越到工作区之外)。 */
689
- export declare function workspaceFilePath(cwd: string, file: string): string;
690
- /**
691
- * 规则化抽取:fields 定义抽取结构,next 选择器驱动翻页(maxPages 上限),
692
- * 行数超 maxRows 截断;format/file 控制序列化与落盘(json/csv/jsonl/markdown)。
693
- */
694
- /** suggest 采集的表格单元格信息(页内采集,纯函数消费)。 */
695
- export interface SuggestCell {
696
- text: string;
697
- href?: string;
698
- src?: string;
699
- }
700
- /** suggest 页内分析结果(自包含 injectWalker 注入采集)。 */
701
- export interface SuggestAnalysis {
702
- ok: boolean;
703
- /** table: 表格行模式;list: 重复卡片/列表项模式。 */
704
- kind?: "table" | "list";
705
- /** 行/卡片选择器(抽取 fields 顶层的 multiple selector)。 */
706
- rowSelector?: string;
707
- headerTexts?: string[];
708
- cells?: SuggestCell[];
709
- item?: SuggestCell;
710
- reason?: string;
711
- overview?: {
712
- links: number;
713
- images: number;
714
- buttons: number;
715
- headings: number;
716
- rows: number;
717
- textChars: number;
718
- };
719
- }
720
- /** 字段名净化:空白→下划线,限长 30,空回落 col_N。导出供测试。 */
721
- export declare function suggestFieldName(header: string | undefined, index: number): string;
722
- /**
723
- * 纯逻辑:由表头与首行单元格特征推断表格 fields(单元格文本/链接 href/图片 src)。
724
- * 返回可直接放进 rows.fields 的嵌套字段数组。导出供测试。
725
- */
726
- export declare function fieldsFromCells(headerTexts: string[], cells: SuggestCell[]): ExtractField[];
727
- /**
728
- * 纯逻辑:由首条卡片信息推断列表 fields(项文本/链接/图片)。
729
- * 文本取第一个子元素(项自身无法用 querySelector 自选)。导出供测试。
730
- */
731
- export declare function fieldsFromCard(item: SuggestCell): ExtractField[];
732
- /** 纯逻辑:由 fields 与单元格样本拼出首行样例(与抽取输出同构;按 td 序号对位)。导出供测试。 */
733
- export declare function sampleOfFields(fields: ExtractField[], cells: SuggestCell[]): Record<string, unknown>;
734
- /**
735
- * suggest 汇总(纯逻辑):由页内分析结果组装「可直接交给抽取模式」的顶层 fields
736
- * (单个 multiple rows 字段 + 行内嵌套字段)与样本。推断失败原样返回。导出供测试。
737
- */
738
- export declare function suggestWrap(analysis: SuggestAnalysis): {
739
- suggested: boolean;
740
- kind?: "table" | "list";
741
- rowSelector?: string;
742
- headerTexts?: string[];
743
- fields?: ExtractField[];
744
- sample?: Record<string, unknown>;
745
- reason?: string;
746
- overview?: SuggestAnalysis["overview"];
747
- };
748
- export declare function extractTool(config: BrowserConfig, args: Record<string, any>, exec?: ToolRunContext): Promise<{
749
- url: string;
750
- title: string;
751
- suggested: boolean;
752
- kind?: "table" | "list";
753
- rowSelector?: string;
754
- headerTexts?: string[];
755
- fields?: ExtractField[];
756
- sample?: Record<string, unknown>;
757
- reason?: string;
758
- overview?: SuggestAnalysis["overview"];
759
- action: string;
760
- } | {
761
- url: string;
762
- title: string;
763
- file?: string | undefined;
764
- bytes?: number | undefined;
765
- truncated: boolean;
766
- rows: Record<string, any>[];
767
- count: number;
768
- pages: number;
769
- format: string;
770
- }>;
771
- /**
772
- * 回归报告:list 列出最近运行,show 看单条详情,
773
- * export 聚合生成 Markdown/HTML 报告落盘工作区。
774
- */
775
- export declare function reportTool(config: BrowserConfig, args: Record<string, any>, exec?: ToolRunContext): Promise<{
776
- runs: {
777
- row?: number | undefined;
778
- runId: string;
779
- ts: number;
780
- kind: "replay" | "batch";
781
- source: string;
782
- total: number;
783
- passed: number;
784
- failed: number;
785
- healedCount: number;
786
- durationMs: number;
787
- }[];
788
- run?: undefined;
789
- file?: undefined;
790
- bytes?: undefined;
791
- format?: undefined;
792
- } | {
793
- run: RunRecord;
794
- runs?: undefined;
795
- file?: undefined;
796
- bytes?: undefined;
797
- format?: undefined;
798
- } | {
799
- file: string;
800
- bytes: number;
801
- runs: number;
802
- format: string;
803
- run?: undefined;
804
- }>;
805
- /**
806
- * 动作批处理:一次调用顺序执行多个浏览器步骤(内核复用 runReplay),
807
- * 减少「点击→等待→输入」类固定小序列的工具往返。步骤内禁止嵌套
808
- * batch/replay/record;批整体在操作轨迹里记为一条 browser_batch。
809
- */
810
- export declare function batchTool(args: Record<string, any>, impls: Record<string, (args: any) => Promise<unknown>>, config?: BrowserConfig): Promise<{
811
- summary: string;
812
- total: number;
813
- passed: number;
814
- failed: number;
815
- healedCount: number;
816
- retries?: {
817
- attempted: number;
818
- recovered: number;
819
- };
820
- stoppedAt?: number;
821
- results: any[];
822
- }>;
823
- /** 收集步骤中所有 {{var}} 占位符名(导出供测试)。 */
824
- export declare function findPlaceholders(steps: ReplayStep[]): string[];
825
- /**
826
- * 深拷贝步骤并替换字符串叶子里的 {{var}} 占位符(导出供测试)。
827
- * vars 缺失的占位符保留原样(由调用方先 findPlaceholders 校验)。
828
- */
829
- export declare function substituteVars(steps: ReplayStep[], vars: Record<string, unknown>): ReplayStep[];
830
- /**
831
- * 回放入口:name(已保存录制)或 steps(数组)二选一。
832
- * vars 注入 {{占位符}};data/dataFile 数据集模式逐行运行并聚合。
833
- */
834
- export declare function replayTool(args: Record<string, any>, impls: Record<string, (args: any) => Promise<unknown>>, config?: BrowserConfig, exec?: ToolRunContext): Promise<{
835
- source: string;
836
- rows: number;
837
- passedRows: number;
838
- failedRows: number;
839
- runs: any[];
840
- summary: string;
841
- } | {
842
- summary: string;
843
- total: number;
844
- passed: number;
845
- failed: number;
846
- healedCount: number;
847
- retries?: {
848
- attempted: number;
849
- recovered: number;
850
- };
851
- stoppedAt?: number;
852
- results: any[];
853
- source: string;
854
- rows?: undefined;
855
- passedRows?: undefined;
856
- failedRows?: undefined;
857
- runs?: undefined;
858
- }>;
859
- /** 重跑请求:source 为已保存录制名,retryOf 为被重跑的原 runId(记录用)。 */
860
- export interface RerunRequest {
861
- source: string;
862
- retryOf?: string;
863
- }
864
- type RerunHandler = (req: RerunRequest) => Promise<unknown>;
865
- /** registerTools 注册重跑入口(stepImpls 同路径);web-only 进程保持 null。 */
866
- export declare function setRerunHandler(fn: RerunHandler): void;
867
- /** 当前可用的重跑入口(null = 本进程没有 tools 服务,无法重跑)。 */
868
- export declare function getRerunHandler(): RerunHandler | null;
869
- /** 重跑是否正在执行(端点互斥;导出供测试)。 */
870
- export declare function rerunBusy(): boolean;
871
- /** 执行一次面板重跑(busy 检查 + 互斥标记;返回 replayTool 结果)。 */
872
- export declare function runPanelRerun(req: RerunRequest): Promise<unknown>;
873
- export {};
1
+ export * from "./tools/common.js";
2
+ export * from "./tools/navigation.js";
3
+ export * from "./tools/interaction.js";
4
+ export * from "./tools/inspection.js";
5
+ export * from "./tools/testing.js";
6
+ export * from "./tools/doctor.js";
7
+ export * from "./tools/collaboration.js";
8
+ export * from "./tools/extract.js";
9
+ export * from "./tools/recorder.js";
874
10
  //# sourceMappingURL=tools.d.ts.map