@opentiny/next-sdk 0.4.0 → 0.4.1

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 (130) hide show
  1. package/agent/AgentModelProvider.ts +78 -81
  2. package/agent/type.ts +6 -9
  3. package/agent/utils/getAISDKTools.ts +0 -1
  4. package/agent/utils/getBuiltinMcpTools.ts +7 -7
  5. package/core.ts +0 -3
  6. package/dist/SimulatorMask-BHVXyogh-iNUb4dyF.js +361 -0
  7. package/dist/agent/type.d.ts +4 -12
  8. package/dist/agent/utils/getBuiltinMcpTools.d.ts +3 -3
  9. package/dist/core.d.ts +0 -1
  10. package/dist/core.js +16 -17
  11. package/dist/index-CXK8CcKq.js +6076 -0
  12. package/dist/index.d.ts +0 -3
  13. package/dist/index.js +57 -4969
  14. package/dist/{initialize-builtin-WebMCP-HgObT902.js → initialize-builtin-WebMCP-rALfqS-o.js} +1166 -1056
  15. package/dist/page-tools/a11y/build.d.ts +11 -0
  16. package/dist/page-tools/a11y/constants.d.ts +9 -0
  17. package/dist/page-tools/a11y/search.d.ts +17 -0
  18. package/dist/page-tools/a11y/types.d.ts +104 -0
  19. package/dist/page-tools/a11y/utils.d.ts +34 -0
  20. package/dist/page-tools/a11y/vnode.d.ts +37 -0
  21. package/dist/page-tools/a11y-tree.d.ts +8 -99
  22. package/dist/page-tools/constants.d.ts +22 -0
  23. package/dist/page-tools/context.d.ts +28 -0
  24. package/dist/page-tools/handlers/browserState.d.ts +8 -0
  25. package/dist/page-tools/handlers/click.d.ts +8 -0
  26. package/dist/page-tools/handlers/executeJavascript.d.ts +8 -0
  27. package/dist/page-tools/handlers/fill.d.ts +8 -0
  28. package/dist/page-tools/handlers/scroll.d.ts +8 -0
  29. package/dist/page-tools/handlers/searchTree.d.ts +8 -0
  30. package/dist/page-tools/handlers/select.d.ts +8 -0
  31. package/dist/page-tools/page-agent-highlight/index.d.ts +9 -0
  32. package/dist/page-tools/page-agent-mask/SimulatorMask.d.ts +14 -0
  33. package/dist/page-tools/page-agent-mask/checkDarkMode.d.ts +5 -0
  34. package/dist/page-tools/page-agent-tool.d.ts +3 -8
  35. package/dist/page-tools/schema.d.ts +43 -0
  36. package/dist/page-tools/utils/dom.d.ts +6 -0
  37. package/dist/page-tools/utils/scroll.d.ts +15 -0
  38. package/dist/runtime.d.ts +4 -0
  39. package/dist/runtime.js +744 -0
  40. package/dist/utils/builtinProxy.d.ts +1 -1
  41. package/index.ts +0 -5
  42. package/package.json +6 -17
  43. package/page-tools/a11y/build.ts +70 -0
  44. package/page-tools/a11y/constants.ts +110 -0
  45. package/page-tools/a11y/search.ts +129 -0
  46. package/page-tools/a11y/types.ts +108 -0
  47. package/page-tools/a11y/utils.ts +266 -0
  48. package/page-tools/a11y/vnode.ts +229 -0
  49. package/page-tools/a11y-tree.ts +8 -527
  50. package/page-tools/bridge.ts +1 -1
  51. package/page-tools/constants.ts +72 -0
  52. package/page-tools/context.ts +13 -0
  53. package/page-tools/handlers/browserState.ts +12 -0
  54. package/page-tools/handlers/click.ts +26 -0
  55. package/page-tools/handlers/executeJavascript.ts +22 -0
  56. package/page-tools/handlers/fill.ts +60 -0
  57. package/page-tools/handlers/scroll.ts +66 -0
  58. package/page-tools/handlers/searchTree.ts +30 -0
  59. package/page-tools/handlers/select.ts +34 -0
  60. package/page-tools/page-agent-highlight/index.ts +198 -0
  61. package/page-tools/page-agent-mask/SimulatorMask.module.css +14 -0
  62. package/page-tools/page-agent-mask/SimulatorMask.ts +279 -0
  63. package/page-tools/page-agent-mask/checkDarkMode.ts +181 -0
  64. package/page-tools/page-agent-mask/cursor-border.svg +3 -0
  65. package/page-tools/page-agent-mask/cursor-fill.svg +5 -0
  66. package/page-tools/page-agent-mask/cursor.module.css +70 -0
  67. package/page-tools/page-agent-prompt.md +34 -18
  68. package/page-tools/page-agent-tool.ts +104 -152
  69. package/page-tools/schema.ts +51 -0
  70. package/page-tools/utils/dom.ts +155 -0
  71. package/page-tools/utils/scroll.ts +58 -0
  72. package/runtime.ts +13 -0
  73. package/utils/builtinProxy.ts +45 -13
  74. package/vite.config.runtime.ts +22 -0
  75. package/vite.config.ts +52 -8
  76. package/McpSdk.ts +0 -14
  77. package/WebAgent.ts +0 -5
  78. package/WebMcp.ts +0 -26
  79. package/Zod.ts +0 -1
  80. package/dist/McpSdk.d.ts +0 -14
  81. package/dist/SimulatorMask-BHVXyogh-BFEGpD5S.js +0 -1048
  82. package/dist/SimulatorMask-BHVXyogh-CCYbrb84.js +0 -801
  83. package/dist/WebAgent.d.ts +0 -5
  84. package/dist/WebMcp.d.ts +0 -23
  85. package/dist/Zod.d.ts +0 -1
  86. package/dist/index.es.dev.js +0 -59017
  87. package/dist/index.es.js +0 -46795
  88. package/dist/index.umd.dev.js +0 -60355
  89. package/dist/index.umd.js +0 -1248
  90. package/dist/mcpsdk@1.25.3.dev.js +0 -22780
  91. package/dist/mcpsdk@1.25.3.es.dev.js +0 -22778
  92. package/dist/mcpsdk@1.25.3.es.js +0 -16960
  93. package/dist/mcpsdk@1.25.3.js +0 -48
  94. package/dist/transport/ExtensionClientTransport.d.ts +0 -24
  95. package/dist/transport/ExtensionContentServerTransport.d.ts +0 -39
  96. package/dist/transport/ExtensionPageServerTransport.d.ts +0 -36
  97. package/dist/transport/messages.d.ts +0 -9
  98. package/dist/vite.config.mcpSdk.d.ts +0 -2
  99. package/dist/vite.config.webAgent.d.ts +0 -2
  100. package/dist/vite.config.webMcp.d.ts +0 -2
  101. package/dist/vite.config.webMcpFull.d.ts +0 -2
  102. package/dist/vite.config.zod.d.ts +0 -2
  103. package/dist/webagent.dev.js +0 -49360
  104. package/dist/webagent.es.dev.js +0 -49071
  105. package/dist/webagent.es.js +0 -39219
  106. package/dist/webagent.js +0 -642
  107. package/dist/webmcp-full.dev.js +0 -31336
  108. package/dist/webmcp-full.es.dev.js +0 -30283
  109. package/dist/webmcp-full.es.js +0 -22889
  110. package/dist/webmcp-full.js +0 -645
  111. package/dist/webmcp.dev.js +0 -9572
  112. package/dist/webmcp.es.dev.js +0 -8518
  113. package/dist/webmcp.es.js +0 -6727
  114. package/dist/webmcp.js +0 -602
  115. package/dist/zod@3.25.76.dev.js +0 -4037
  116. package/dist/zod@3.25.76.es.dev.js +0 -4033
  117. package/dist/zod@3.25.76.es.js +0 -2945
  118. package/dist/zod@3.25.76.js +0 -1
  119. package/transport/ExtensionClientTransport.ts +0 -100
  120. package/transport/ExtensionContentServerTransport.ts +0 -162
  121. package/transport/ExtensionPageServerTransport.ts +0 -149
  122. package/transport/messages.ts +0 -63
  123. package/vite-build-tsc.ts +0 -63
  124. package/vite-env.d.ts +0 -10
  125. package/vite.config.mcpSdk.ts +0 -28
  126. package/vite.config.webAgent.ts +0 -19
  127. package/vite.config.webMcp.ts +0 -40
  128. package/vite.config.webMcpFull.ts +0 -19
  129. package/vite.config.zod.ts +0 -23
  130. /package/dist/{vite-build-tsc.d.ts → vite.config.runtime.d.ts} +0 -0
@@ -0,0 +1,11 @@
1
+ import { A11yTreeOptions, A11yTreeResult } from './types';
2
+
3
+ /**
4
+ * 生成当前页面的语义化 ARIA YAML 树
5
+ *
6
+ * @param root 遍历起点,默认 document.body
7
+ * @param blacklist 需要跳过的元素(用户自定义黑名单)
8
+ * @param whitelist 需要识别为可交互的白名单元素列表
9
+ * @param options 过滤选项
10
+ */
11
+ export declare function buildA11yTree(root?: Element, blacklist?: Element[], whitelist?: Element[], options?: A11yTreeOptions): A11yTreeResult;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * a11y/constants.ts
3
+ *
4
+ * 存放无障碍树依赖的静态常量配置、默认选择器及角色映射表。
5
+ */
6
+ export declare const DEFAULT_ERROR_SELECTORS: string[];
7
+ export declare const DEFAULT_WARNING_SELECTORS: string[];
8
+ export declare const TAG_ROLE_MAP: Record<string, string>;
9
+ export declare const INPUT_TYPE_ROLE: Record<string, string>;
@@ -0,0 +1,17 @@
1
+ import { SearchA11yTreeOptions, SearchA11yTreeResult } from './types';
2
+
3
+ /**
4
+ * 在无障碍树中按关键词搜索,返回带行号的匹配结果和上下文
5
+ *
6
+ * 支持的搜索维度(均对同一个 query 字符串做包含匹配):
7
+ * - role:如 `button`、`link`、`heading`
8
+ * - accessible name:节点的语义化名称(引号内文本)
9
+ * - state token:如 `checked`、`disabled`、`expanded`
10
+ * - ref 索引:如 `#5`
11
+ *
12
+ * @example
13
+ * searchA11yTree('button') // 找全部按钮
14
+ * searchA11yTree('提交') // 找名称含"提交"的节点
15
+ * searchA11yTree('#3') // 找 ref #3
16
+ */
17
+ export declare function searchA11yTree(query: string, root?: Element, blacklist?: Element[], whitelist?: Element[], options?: SearchA11yTreeOptions): SearchA11yTreeResult;
@@ -0,0 +1,104 @@
1
+ /**
2
+ * a11y/types.ts
3
+ *
4
+ * 定义无障碍树模块(A11y Tree)的核心接口和类型。
5
+ */
6
+ /** ref 索引 → HTMLElement 映射,供 click/fill/select 操作使用 */
7
+ export type RefMap = Map<number, HTMLElement>;
8
+ /** 内部中间态节点,与 DOM 解耦,便于剪枝和序列化 */
9
+ export interface VNode {
10
+ /** 节点的 ARIA 角色 (如 'button', 'link', 'textbox') */
11
+ role: string;
12
+ /** W3C AccName 算法计算出的语义化名称 */
13
+ name: string;
14
+ /** 元素相关的状态和属性标记 (如 'checked', 'disabled', 'value="xxx"') */
15
+ tokens: string[];
16
+ /** 只有交互节点才有 ref (内部索引,用于标识可在其上执行交互动作的元素) */
17
+ ref?: number;
18
+ /** 关联的 DOM 元素实例 */
19
+ el: HTMLElement;
20
+ /** 包含的子节点列表 */
21
+ children: VNode[];
22
+ }
23
+ /** 构建无障碍树时的配置选项 */
24
+ export interface A11yTreeOptions {
25
+ /**
26
+ * 是否启用剪枝:无 ref 且无 accessible name 的节点透明穿透
27
+ * 默认 true(推荐)
28
+ */
29
+ pruneUnnamed?: boolean;
30
+ /**
31
+ * 强制保留的角色列表,即使无 name 也不穿透(优先级最高)
32
+ * 例如:['table', 'row'] 用于保留表格结构
33
+ */
34
+ preserveRoles?: string[];
35
+ /**
36
+ * 允许在无障碍树节点中作为 token 额外输出的 DOM 属性白名单
37
+ * 包含这些属性的节点会被自动视为需要暴露/交互的节点(分配 ref 并保留),
38
+ * 且属性及其值会显示在节点的 token 列表中,如 [cf-uba="cloudShell"]
39
+ */
40
+ exposedAttributes?: string[];
41
+ /**
42
+ * 校验错误元素 CSS 选择器(逗号分隔或选择器数组),用于在 token 中标记 [error]
43
+ * 默认覆盖 ARIA 标准 + 主流 UI 框架
44
+ */
45
+ errorSelectors?: string | string[];
46
+ /**
47
+ * 校验警告元素 CSS 选择器(逗号分隔或选择器数组)
48
+ */
49
+ warningSelectors?: string | string[];
50
+ }
51
+ /** 构建无障碍树的返回结果 */
52
+ export interface A11yTreeResult {
53
+ /** 语义化 YAML 文本(供 AI 阅读和 Diff 计算) */
54
+ yaml: string;
55
+ /** ref 索引 → HTMLElement 映射(供后续操作使用) */
56
+ refMap: RefMap;
57
+ /** 可交互元素总数 */
58
+ interactiveCount: number;
59
+ /** 原始行数组(不含 yaml 代码块包裹),供搜索使用 */
60
+ lines: string[];
61
+ }
62
+ /** 关键词搜索选项 */
63
+ export interface SearchA11yTreeOptions extends A11yTreeOptions {
64
+ /**
65
+ * 每个匹配行前后保留的上下文行数(类似 grep -C N)
66
+ * 默认 2
67
+ */
68
+ contextLines?: number;
69
+ /**
70
+ * 是否大小写不敏感,默认 true
71
+ */
72
+ caseInsensitive?: boolean;
73
+ /**
74
+ * 最大返回匹配分组数(防止命中过多撑爆上下文),默认 20
75
+ */
76
+ maxMatches?: number;
77
+ }
78
+ /** 单个搜索匹配的分组结构 */
79
+ export interface A11ySearchMatch {
80
+ /** 主命中行行号(1-based) */
81
+ lineNumber: number;
82
+ /** 主命中行内容 */
83
+ line: string;
84
+ /** 含上下文的行列表(带行号) */
85
+ context: Array<{
86
+ lineNumber: number;
87
+ line: string;
88
+ }>;
89
+ }
90
+ /** searchA11yTree 函数的返回结果 */
91
+ export interface SearchA11yTreeResult {
92
+ /** 格式化后可直接发给 LLM 的文本 */
93
+ text: string;
94
+ /** 结构化匹配列表 */
95
+ matches: A11ySearchMatch[];
96
+ /** 无障碍树总行数 */
97
+ totalLines: number;
98
+ /** 原始命中行数(去重前) */
99
+ matchCount: number;
100
+ /** 返回搜索时的 ref 映射 */
101
+ refMap: RefMap;
102
+ /** 返回搜索时的 yaml 状态,用于更新缓存 */
103
+ yaml: string;
104
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * a11y/utils.ts
3
+ *
4
+ * 存放生成无障碍树时的通用工具函数:节点解析、状态获取、角色推断及纯文本兜底等。
5
+ */
6
+ /**
7
+ * 获取元素的 ARIA 角色
8
+ * 优先级:显式 role 属性 > 标签隐式角色 > 'generic'
9
+ */
10
+ export declare function inferRole(el: Element): string;
11
+ /**
12
+ * 收集节点的 ARIA 状态 token
13
+ * 格式:[checked] [selected] [disabled] [hasPopup] [cursor=pointer] [value="..."]
14
+ */
15
+ export declare function getStateTokens(el: Element, exposedAttributes?: string[], errorSelectors?: string | string[], warningSelectors?: string | string[]): string[];
16
+ /** 判断元素是否应被跳过(不可见或在黑名单中) */
17
+ export declare function isHidden(el: Element): boolean;
18
+ /**
19
+ * 收集子孙节点的文本内容,用作无障碍名字的兜底。
20
+ * 当普通计算无法提取文本时,遍历后代并拼接可见文本。
21
+ */
22
+ export declare function collectDescendantText(el: Element): string;
23
+ /**
24
+ * 获取元素在 composed tree(组合树)中的有效子元素
25
+ *
26
+ * Shadow DOM 场景下,简单拼接 el.children + el.shadowRoot.children 不符合浏览器
27
+ * 实际渲染和无障碍树使用的组合树语义:slotted 节点应出现在 <slot> 的位置而非
28
+ * host 下,<slot> 本身不应作为噪音节点出现,未被任何 slot 接收的 light children
29
+ * 在组合树中不可见。
30
+ *
31
+ * 因此:有 shadowRoot 时遍历 shadow tree,遇到 <slot> 用 assignedElements 替换;
32
+ * 无 shadowRoot 时直接遍历 light DOM children。
33
+ */
34
+ export declare function getComposedChildren(el: Element): Element[];
@@ -0,0 +1,37 @@
1
+ import { VNode, RefMap, A11yTreeOptions } from './types';
2
+
3
+ /**
4
+ * 递归将 DOM 元素转换为 VNode 中间表示
5
+ * @param el 当前 DOM 元素
6
+ * @param refCounter 引用计数器(使用对象引用避免全局可变状态)
7
+ * @param refMap ref 索引 → 元素映射
8
+ * @param blacklistSet 用户自定义黑名单
9
+ * @param whitelistSet 用户自定义白名单
10
+ * @param exposedAttributes 需要暴露的自定义属性
11
+ * @param errorSelectors 错误选择器
12
+ * @param warningSelectors 警告选择器
13
+ */
14
+ export declare function buildVNode(el: Element, refCounter: {
15
+ value: number;
16
+ }, refMap: RefMap, blacklistSet: Set<Element>, whitelistSet: Set<Element>, exposedAttributes?: string[], errorSelectors?: string | string[], warningSelectors?: string | string[],
17
+ /** 祖先节点是否已是可交互节点(已分配 ref)。为 true 时,纯 CSS 继承的 cursor=pointer 不再额外分配 ref */
18
+ ancestorIsInteractive?: boolean): VNode | null;
19
+ /**
20
+ * 判断 VNode 子树是否包含任何有价值的节点(有 ref 或有 accessible name)
21
+ * 用于过滤空容器子树,避免输出无内容的嵌套层级
22
+ */
23
+ export declare function hasValue(vnode: VNode): boolean;
24
+ /**
25
+ * 判断节点是否需要透明穿透(跳过本节点但保留子节点)
26
+ *
27
+ * 统一规则:无 ref(非交互)且无 accessible name → 穿透
28
+ * 这样可以同时:
29
+ * - 去掉 generic/list/listitem 等纯布局噪音(无 name 时穿透)
30
+ * - 保留有 name 的 listitem(有 name 时保留,兼顾内容理解场景)
31
+ */
32
+ export declare function shouldPassThrough(vnode: VNode, opts: Required<A11yTreeOptions>): boolean;
33
+ /**
34
+ * 将 VNode 序列化为 YAML 行数组
35
+ * 穿透节点时,子节点在当前 depth 平铺输出(不增加缩进层级)
36
+ */
37
+ export declare function serializeVNode(vnode: VNode, depth: number, opts: Required<A11yTreeOptions>): string[];
@@ -1,103 +1,12 @@
1
1
  /**
2
2
  * a11y-tree.ts
3
3
  *
4
- * 浏览器内语义化 ARIA 树生成器(重构版)
5
- *
6
- * 核心改进:
7
- * 1. 两阶段处理:buildVNode(构建中间树)→ serializeVNode(剪枝序列化)
8
- * 2. 统一剪枝规则:无 ref 且无 accessible name → 透明穿透(跳过本节点,保留子节点)
9
- * - 兼顾操作场景(去掉 generic/list/listitem 噪音)
10
- * - 兼顾内容理解场景(有 name 的 listitem 等节点保留)
11
- * 3. 修复全局可变状态:refCounter 改为局部对象,消除并发调用隐患
12
- *
13
- * 依赖:
14
- * - dom-accessibility-api: W3C AccName 规范 JS 实现(计算 accessible name)
15
- * - tabbable: 可交互/可聚焦元素检测(工业级,处理所有边界情况)
16
- */
17
- /** ref 索引 → HTMLElement 映射,供 click/fill/select 操作使用 */
18
- export type RefMap = Map<number, HTMLElement>;
19
- export interface A11yTreeOptions {
20
- /**
21
- * 是否启用剪枝:无 ref 且无 accessible name 的节点透明穿透
22
- * 默认 true(推荐)
23
- */
24
- pruneUnnamed?: boolean;
25
- /**
26
- * 强制保留的角色列表,即使无 name 也不穿透(优先级最高)
27
- * 例如:['table', 'row'] 用于保留表格结构
28
- */
29
- preserveRoles?: string[];
30
- }
31
- export interface A11yTreeResult {
32
- /** 语义化 YAML 文本(供 AI 阅读和 Diff 计算) */
33
- yaml: string;
34
- /** ref 索引 → HTMLElement 映射(供后续操作使用) */
35
- refMap: RefMap;
36
- /** 可交互元素总数 */
37
- interactiveCount: number;
38
- /** 原始行数组(不含 yaml 代码块包裹),供搜索使用 */
39
- lines: string[];
40
- }
41
- /** 关键词搜索选项 */
42
- export interface SearchA11yTreeOptions extends A11yTreeOptions {
43
- /**
44
- * 每个匹配行前后保留的上下文行数(类似 grep -C N)
45
- * 默认 2
46
- */
47
- contextLines?: number;
48
- /**
49
- * 是否大小写不敏感,默认 true
50
- */
51
- caseInsensitive?: boolean;
52
- /**
53
- * 最大返回匹配分组数(防止命中过多撑爆上下文),默认 20
54
- */
55
- maxMatches?: number;
56
- }
57
- /** 单个匹配分组 */
58
- export interface A11ySearchMatch {
59
- /** 主命中行行号(1-based) */
60
- lineNumber: number;
61
- /** 主命中行内容 */
62
- line: string;
63
- /** 含上下文的行列表(带行号) */
64
- context: Array<{
65
- lineNumber: number;
66
- line: string;
67
- }>;
68
- }
69
- /** searchA11yTree 返回值 */
70
- export interface SearchA11yTreeResult {
71
- /** 格式化后可直接发给 LLM 的文本 */
72
- text: string;
73
- /** 结构化匹配列表 */
74
- matches: A11ySearchMatch[];
75
- /** 无障碍树总行数 */
76
- totalLines: number;
77
- /** 原始命中行数(去重前) */
78
- matchCount: number;
79
- }
80
- /**
81
- * 生成当前页面的语义化 ARIA YAML 树
82
- *
83
- * @param root 遍历起点,默认 document.body
84
- * @param blacklist 需要跳过的元素(用户自定义黑名单)
85
- * @param whitelist 需要识别为可交互的白名单元素列表
86
- * @param options 过滤选项
87
- */
88
- export declare function buildA11yTree(root?: Element, blacklist?: Element[], whitelist?: Element[], options?: A11yTreeOptions): A11yTreeResult;
89
- /**
90
- * 在无障碍树中按关键词搜索,返回带行号的匹配结果和上下文
91
- *
92
- * 支持的搜索维度(均对同一个 query 字符串做包含匹配):
93
- * - role:如 `button`、`link`、`heading`
94
- * - accessible name:节点的语义化名称(引号内文本)
95
- * - state token:如 `checked`、`disabled`、`expanded`
96
- * - ref 索引:如 `#5`
97
- *
98
- * @example
99
- * searchA11yTree('button') // 找全部按钮
100
- * searchA11yTree('提交') // 找名称含"提交"的节点
101
- * searchA11yTree('#3') // 找 ref #3
4
+ * 此文件为 A11y Tree 模块的汇总出口,
5
+ * 方便外部直接从 './a11y-tree' 引入相关类型及方法,而无需调整现有的引用路径。
102
6
  */
103
- export declare function searchA11yTree(query: string, root?: Element, blacklist?: Element[], whitelist?: Element[], options?: SearchA11yTreeOptions): SearchA11yTreeResult;
7
+ export * from './a11y/types';
8
+ export * from './a11y/constants';
9
+ export * from './a11y/utils';
10
+ export * from './a11y/vnode';
11
+ export * from './a11y/build';
12
+ export * from './a11y/search';
@@ -0,0 +1,22 @@
1
+ /** 校验错误默认选择器:ARIA 标准 + 主流 UI 框架 */
2
+ export declare const DEFAULT_ERROR_SELECTORS: string[];
3
+ /** 模态弹窗默认选择器:ARIA 标准 + 主流 UI 框架 */
4
+ export declare const DEFAULT_DIALOG_SELECTORS: string[];
5
+ export interface PageAgentToolOptions {
6
+ /** 允许在无障碍树节点中额外暴露的 DOM 属性白名单 */
7
+ exposedAttributes?: string[];
8
+ /** 是否启用元素高亮 */
9
+ enableHighlight?: boolean;
10
+ }
11
+ declare global {
12
+ interface Window {
13
+ __webmcpcli_interactiveWhitelist?: Element[];
14
+ __webmcpcli_interactiveBlacklist?: Element[];
15
+ __webmcpcli_exposedAttributes?: string[];
16
+ __webmcpcli_beforeGetBrowserState?: (() => void) | null;
17
+ /** 校验错误元素 CSS 选择器列表(覆盖默认,用于检测页面可见的校验错误) */
18
+ __webmcpcli_errorSelectors?: string[];
19
+ /** 模态弹窗元素 CSS 选择器列表(覆盖默认,用于检测阻塞交互的弹窗) */
20
+ __webmcpcli_dialogSelectors?: string[];
21
+ }
22
+ }
@@ -0,0 +1,28 @@
1
+ import { PageController } from '@page-agent/page-controller';
2
+ import { PageStateCache } from './page-state-cache';
3
+ import { RefMap } from './a11y-tree';
4
+
5
+ export interface ActionContext {
6
+ pageController: PageController;
7
+ stateCache: PageStateCache;
8
+ getRefMap: () => RefMap;
9
+ setRefMap: (map: RefMap) => void;
10
+ buildBrowserStateResponse: (mode?: 'full' | 'diff' | 'both') => Promise<{
11
+ content: Array<{
12
+ type: 'text';
13
+ text: string;
14
+ }>;
15
+ }>;
16
+ refreshOnStaleRef: (action: string, index: number) => Promise<{
17
+ content: Array<{
18
+ type: 'text';
19
+ text: string;
20
+ }>;
21
+ }>;
22
+ errContent: (msg: string) => Promise<{
23
+ content: Array<{
24
+ type: 'text';
25
+ text: string;
26
+ }>;
27
+ }>;
28
+ }
@@ -0,0 +1,8 @@
1
+ import { ActionContext } from '../context';
2
+
3
+ export declare function handleBrowserState(args: any, ctx: ActionContext): Promise<{
4
+ content: Array<{
5
+ type: "text";
6
+ text: string;
7
+ }>;
8
+ }>;
@@ -0,0 +1,8 @@
1
+ import { ActionContext } from '../context';
2
+
3
+ export declare function handleClick(args: any, ctx: ActionContext): Promise<{
4
+ content: Array<{
5
+ type: "text";
6
+ text: string;
7
+ }>;
8
+ }>;
@@ -0,0 +1,8 @@
1
+ import { ActionContext } from '../context';
2
+
3
+ export declare function handleExecuteJavascript(args: any, ctx: ActionContext): Promise<{
4
+ content: Array<{
5
+ type: "text";
6
+ text: string;
7
+ }>;
8
+ }>;
@@ -0,0 +1,8 @@
1
+ import { ActionContext } from '../context';
2
+
3
+ export declare function handleFill(args: any, ctx: ActionContext): Promise<{
4
+ content: Array<{
5
+ type: "text";
6
+ text: string;
7
+ }>;
8
+ }>;
@@ -0,0 +1,8 @@
1
+ import { ActionContext } from '../context';
2
+
3
+ export declare function handleScroll(args: any, ctx: ActionContext): Promise<{
4
+ content: Array<{
5
+ type: "text";
6
+ text: string;
7
+ }>;
8
+ }>;
@@ -0,0 +1,8 @@
1
+ import { ActionContext } from '../context';
2
+
3
+ export declare function handleSearchTree(args: any, ctx: ActionContext): Promise<{
4
+ content: Array<{
5
+ type: "text";
6
+ text: string;
7
+ }>;
8
+ }>;
@@ -0,0 +1,8 @@
1
+ import { ActionContext } from '../context';
2
+
3
+ export declare function handleSelect(args: any, ctx: ActionContext): Promise<{
4
+ content: Array<{
5
+ type: "text";
6
+ text: string;
7
+ }>;
8
+ }>;
@@ -0,0 +1,9 @@
1
+ import { RefMap } from '../a11y-tree';
2
+
3
+ export declare const HIGHLIGHT_CONTAINER_ID = "webmcpcli-highlight-container";
4
+ export declare const HIGHLIGHT_CONTAINER_STYLE_ID = "webmcpcli-highlight-container-style";
5
+ export declare const highlight: (refMap: RefMap, parentIframe?: HTMLIFrameElement | null) => void;
6
+ /** 移除高亮, 可反复调用 */
7
+ export declare const unhighlight: () => void;
8
+ /** 全局监听变化,随时准备移除高亮, 可反复调用 */
9
+ export declare const globalRemoveListener: () => void;
@@ -0,0 +1,14 @@
1
+ import { Motion } from 'ai-motion';
2
+
3
+ export declare class SimulatorMask extends EventTarget {
4
+ #private;
5
+ shown: boolean;
6
+ wrapper: HTMLDivElement;
7
+ motion: Motion | null;
8
+ constructor();
9
+ setCursorPosition(x: number, y: number): void;
10
+ triggerClickAnimation(): void;
11
+ show(): void;
12
+ hide(): void;
13
+ dispose(): void;
14
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * A comprehensive function to determine if the page is currently in a dark theme.
3
+ * Heuristic check. Only work for common patterns. Return false by default.
4
+ */
5
+ export declare function isPageDark(): boolean;
@@ -1,9 +1,4 @@
1
- declare global {
2
- interface Window {
3
- __webmcpcli_interactiveWhitelist?: Element[];
4
- __webmcpcli_interactiveBlacklist?: Element[];
5
- __webmcpcli_beforeGetBrowserState?: (() => void) | null;
6
- }
7
- }
1
+ import { PageAgentToolOptions } from './constants';
2
+
8
3
  /** 在浏览器页面中注册 page-agent-tool, 用于页面的内容获取和操作,页面的动效 */
9
- export declare function registerPageAgentTool(): void;
4
+ export declare function registerPageAgentTool(options?: PageAgentToolOptions): void;
@@ -0,0 +1,43 @@
1
+ import { z } from 'zod';
2
+
3
+ export declare const inputSchema: z.ZodObject<{
4
+ action: z.ZodEnum<["browserState", "click", "fill", "select", "scroll", "executeJavascript", "searchTree"]>;
5
+ index: z.ZodOptional<z.ZodNumber>;
6
+ text: z.ZodOptional<z.ZodString>;
7
+ down: z.ZodOptional<z.ZodBoolean>;
8
+ right: z.ZodOptional<z.ZodBoolean>;
9
+ numPages: z.ZodOptional<z.ZodNumber>;
10
+ pixels: z.ZodOptional<z.ZodNumber>;
11
+ script: z.ZodOptional<z.ZodString>;
12
+ query: z.ZodOptional<z.ZodString>;
13
+ contextLines: z.ZodDefault<z.ZodNumber>;
14
+ maxMatches: z.ZodDefault<z.ZodNumber>;
15
+ responseMode: z.ZodDefault<z.ZodOptional<z.ZodEnum<["full", "diff", "both"]>>>;
16
+ }, "strip", z.ZodTypeAny, {
17
+ action: "fill" | "click" | "select" | "scroll" | "browserState" | "executeJavascript" | "searchTree";
18
+ contextLines: number;
19
+ maxMatches: number;
20
+ responseMode: "full" | "diff" | "both";
21
+ text?: string | undefined;
22
+ right?: boolean | undefined;
23
+ script?: string | undefined;
24
+ index?: number | undefined;
25
+ down?: boolean | undefined;
26
+ numPages?: number | undefined;
27
+ pixels?: number | undefined;
28
+ query?: string | undefined;
29
+ }, {
30
+ action: "fill" | "click" | "select" | "scroll" | "browserState" | "executeJavascript" | "searchTree";
31
+ text?: string | undefined;
32
+ right?: boolean | undefined;
33
+ script?: string | undefined;
34
+ contextLines?: number | undefined;
35
+ maxMatches?: number | undefined;
36
+ index?: number | undefined;
37
+ down?: boolean | undefined;
38
+ numPages?: number | undefined;
39
+ pixels?: number | undefined;
40
+ query?: string | undefined;
41
+ responseMode?: "full" | "diff" | "both" | undefined;
42
+ }>;
43
+ export type PageAgentToolInput = z.infer<typeof inputSchema>;
@@ -0,0 +1,6 @@
1
+ export declare function isInShadowDom(el: Element): boolean;
2
+ export declare function dispatchComposedEvents(el: Element, ...types: string[]): void;
3
+ export declare function deepQuerySelectorAll(selector: string, root?: Document | Element | ShadowRoot): Element[];
4
+ export declare function waitForDomSettled(timeout?: number, settleTime?: number): Promise<void>;
5
+ export declare function detectPageDialog(): string;
6
+ export declare function detectValidationErrors(): string;
@@ -0,0 +1,15 @@
1
+ export declare function getScrollInfo(target?: Window | Element): {
2
+ scrollY: number;
3
+ scrollX: number;
4
+ pixelsAbove: number;
5
+ pixelsBelow: number;
6
+ pixelsLeft: number;
7
+ pixelsRight: number;
8
+ pagesAbove: number;
9
+ pagesBelow: number;
10
+ atTop: boolean;
11
+ atBottom: boolean;
12
+ atLeft: boolean;
13
+ atRight: boolean;
14
+ };
15
+ export declare function waitForScrollEnd(target: Window | Element, timeout?: number): Promise<void>;
@@ -0,0 +1,4 @@
1
+ import { initializeBuiltinWebMCP } from './page-tools/initialize-builtin-WebMCP';
2
+ import { registerPageAgentTool } from './page-tools/page-agent-tool';
3
+
4
+ export { initializeBuiltinWebMCP, registerPageAgentTool };