@opentiny/next-sdk 0.4.1 → 0.4.3

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 (90) hide show
  1. package/dist/{SimulatorMask-BHVXyogh-iNUb4dyF.js → SimulatorMask-BHVXyogh-CKmEDsYG.js} +1 -1
  2. package/dist/core.js +1 -1
  3. package/dist/{index-CXK8CcKq.js → index-CHMa2zG4.js} +1985 -1434
  4. package/dist/index.d.ts +11 -0
  5. package/dist/index.js +69 -50
  6. package/dist/{initialize-builtin-WebMCP-rALfqS-o.js → initialize-builtin-WebMCP-JaoKwVlm.js} +355 -346
  7. package/dist/page-tools/a11y/build.d.ts +3 -4
  8. package/dist/page-tools/a11y/config.d.ts +99 -0
  9. package/dist/page-tools/a11y/constants.d.ts +22 -0
  10. package/dist/page-tools/a11y/search.d.ts +1 -1
  11. package/dist/page-tools/a11y/types.d.ts +13 -22
  12. package/dist/page-tools/a11y/utils.d.ts +46 -11
  13. package/dist/page-tools/a11y/vnode.d.ts +14 -11
  14. package/dist/page-tools/a11y-tree.d.ts +1 -0
  15. package/dist/page-tools/configs/console-cloud.d.ts +6 -0
  16. package/dist/page-tools/constants.d.ts +7 -17
  17. package/dist/page-tools/context.d.ts +14 -0
  18. package/dist/page-tools/handlers/hover.d.ts +9 -0
  19. package/dist/page-tools/handlers/searchTree.d.ts +2 -1
  20. package/dist/page-tools/page-agent-highlight/index.d.ts +12 -0
  21. package/dist/page-tools/page-agent-mask/SimulatorMask.d.ts +2 -0
  22. package/dist/page-tools/page-agent-tool-event.d.ts +26 -0
  23. package/dist/page-tools/schema.d.ts +4 -3
  24. package/dist/page-tools/tool-config.d.ts +50 -0
  25. package/dist/page-tools/utils/dom.d.ts +8 -2
  26. package/dist/runtime.d.ts +4 -1
  27. package/dist/runtime.js +22 -187
  28. package/dist/vitest.config.d.ts +2 -0
  29. package/package.json +26 -16
  30. package/WebMcpClient.ts +0 -505
  31. package/WebMcpServer.ts +0 -447
  32. package/agent/AgentModelProvider.ts +0 -932
  33. package/agent/type.ts +0 -91
  34. package/agent/utils/generateReActPrompt.ts +0 -71
  35. package/agent/utils/getAISDKTools.ts +0 -34
  36. package/agent/utils/getBuiltinMcpTools.ts +0 -86
  37. package/agent/utils/parseReActAction.ts +0 -34
  38. package/core.ts +0 -26
  39. package/index.ts +0 -56
  40. package/page-tools/a11y/build.ts +0 -70
  41. package/page-tools/a11y/constants.ts +0 -110
  42. package/page-tools/a11y/search.ts +0 -129
  43. package/page-tools/a11y/types.ts +0 -108
  44. package/page-tools/a11y/utils.ts +0 -266
  45. package/page-tools/a11y/vnode.ts +0 -229
  46. package/page-tools/a11y-tree.ts +0 -13
  47. package/page-tools/bridge.ts +0 -702
  48. package/page-tools/constants.ts +0 -72
  49. package/page-tools/context.ts +0 -13
  50. package/page-tools/effects.ts +0 -345
  51. package/page-tools/handlers/browserState.ts +0 -12
  52. package/page-tools/handlers/click.ts +0 -26
  53. package/page-tools/handlers/executeJavascript.ts +0 -22
  54. package/page-tools/handlers/fill.ts +0 -60
  55. package/page-tools/handlers/scroll.ts +0 -66
  56. package/page-tools/handlers/searchTree.ts +0 -30
  57. package/page-tools/handlers/select.ts +0 -34
  58. package/page-tools/initialize-builtin-WebMCP.ts +0 -20
  59. package/page-tools/page-agent-highlight/index.ts +0 -198
  60. package/page-tools/page-agent-mask/SimulatorMask.module.css +0 -14
  61. package/page-tools/page-agent-mask/SimulatorMask.ts +0 -279
  62. package/page-tools/page-agent-mask/checkDarkMode.ts +0 -181
  63. package/page-tools/page-agent-mask/cursor-border.svg +0 -3
  64. package/page-tools/page-agent-mask/cursor-fill.svg +0 -5
  65. package/page-tools/page-agent-mask/cursor.module.css +0 -70
  66. package/page-tools/page-agent-prompt.md +0 -139
  67. package/page-tools/page-agent-tool.ts +0 -175
  68. package/page-tools/page-state-cache.ts +0 -78
  69. package/page-tools/schema.ts +0 -51
  70. package/page-tools/utils/dom.ts +0 -155
  71. package/page-tools/utils/scroll.ts +0 -58
  72. package/remoter/QrCode.ts +0 -54
  73. package/remoter/createRemoter.ts +0 -957
  74. package/remoter/svgs/chat.svg +0 -43
  75. package/remoter/svgs/icon-copy.svg +0 -25
  76. package/remoter/svgs/link.svg +0 -28
  77. package/remoter/svgs/logo.svg +0 -45
  78. package/remoter/svgs/qrcode.svg +0 -35
  79. package/remoter/svgs/scan.svg +0 -21
  80. package/remoter/tooltips.ts +0 -260
  81. package/runtime.html +0 -39
  82. package/runtime.ts +0 -13
  83. package/script/utils.ts +0 -26
  84. package/skills/index.ts +0 -287
  85. package/tsconfig.json +0 -16
  86. package/utils/builtinProxy.ts +0 -144
  87. package/utils/env.ts +0 -13
  88. package/utils/uuid.ts +0 -10
  89. package/vite.config.runtime.ts +0 -22
  90. package/vite.config.ts +0 -63
@@ -1,11 +1,10 @@
1
1
  import { A11yTreeOptions, A11yTreeResult } from './types';
2
+ import { A11yConfig } from './config';
2
3
 
3
4
  /**
4
5
  * 生成当前页面的语义化 ARIA YAML 树
5
6
  *
6
7
  * @param root 遍历起点,默认 document.body
7
- * @param blacklist 需要跳过的元素(用户自定义黑名单)
8
- * @param whitelist 需要识别为可交互的白名单元素列表
9
- * @param options 过滤选项
8
+ * @param config 统一无障碍配置(角色/状态规则、白/黑名单、自定义属性等)+ 树形状选项(pruneUnnamed/preserveRoles)
10
9
  */
11
- export declare function buildA11yTree(root?: Element, blacklist?: Element[], whitelist?: Element[], options?: A11yTreeOptions): A11yTreeResult;
10
+ export declare function buildA11yTree(root?: Element, config?: A11yConfig & A11yTreeOptions): A11yTreeResult;
@@ -0,0 +1,99 @@
1
+ /**
2
+ * a11y/config.ts
3
+ *
4
+ * 统一无障碍配置(A11yConfig):把角色推断、状态推断、白/黑名单、自定义属性、
5
+ * 弹窗选择器等配置项收敛为一个对象,并提供:
6
+ * 1. 声明式规则(roles/states)的合并与匹配逻辑
7
+ * 2. 底层的逐元素解析函数(resolveA11yRole/resolveA11yStates/resolveA11yInfo)
8
+ *
9
+ * 运行期读写 API 统一由 ../tool-config.ts 的 getPageAgentToolConfig/setPageAgentToolConfig 提供
10
+ * (a11yConfig 是其中一个字段),这里不再单独维护一套 get/set。
11
+ */
12
+ export interface A11yMatcher {
13
+ /**
14
+ * 标准 CSS 选择器。优先使用 selector,仅当选择器表达不了时再写 match。
15
+ * - **states**:用 `closest` 判断自身或祖先是否命中(适合 error/selected 等挂在容器上的状态)
16
+ * - **roles**:用 `matches` 仅判断自身是否命中(避免角色传染给子孙节点)
17
+ * 支持标签/属性/id/组合选择器,也支持字符串数组(任意一个命中即可)。
18
+ */
19
+ selector?: string | string[];
20
+ /** 自定义判断函数,优先级高于 selector,用于读取计算样式、组合条件等选择器表达不了的场景 */
21
+ match?: (el: Element) => boolean;
22
+ }
23
+ export type A11yStateName = 'checked' | 'selected' | 'pressed' | 'current' | 'expanded' | 'hasPopup' | 'disabled' | 'readonly' | 'required' | 'invalid' | 'busy' | 'error' | 'warning' | (string & {});
24
+ export interface A11yRoleRule extends A11yMatcher {
25
+ /** 命中后赋予的 ARIA 角色,如 'tab' | 'tabpanel' | 'switch' | 'treeitem' */
26
+ role: string;
27
+ /** 为 true 时覆盖元素已有的显式 role 属性,默认 false(不覆盖开发者显式设置) */
28
+ force?: boolean;
29
+ }
30
+ export interface A11yConfig {
31
+ /** 角色推断规则:用于弥补页面缺失的语义 role(如自定义 Tab 组件没有 role=tab) */
32
+ roles?: A11yRoleRule[];
33
+ /** 状态推断规则:key 为状态名,value 为一条或多条规则(命中任意一条即成立),与标准 aria-* 检测结果取"或" */
34
+ states?: Partial<Record<A11yStateName, A11yMatcher | A11yMatcher[]>>;
35
+ /** 白名单:强制识别为可交互元素并纳入无障碍树。支持 Element 引用或 CSS 选择器字符串(字符串每次动态解析,适配 SPA 重渲染) */
36
+ whitelist?: Array<Element | string>;
37
+ /** 黑名单:强制从无障碍树中排除,规则同上 */
38
+ blacklist?: Array<Element | string>;
39
+ /** 额外暴露的自定义 DOM 属性(作为 token 输出,如 [data-testid="xxx"]) */
40
+ exposedAttributes?: string[];
41
+ }
42
+ /** 单个元素解析出的完整无障碍信息 */
43
+ export interface A11yInfo {
44
+ role: string;
45
+ tokens: string[];
46
+ }
47
+ /** 标记已与默认值合并并规整过的配置,避免热路径上二次 merge 导致默认规则翻倍 */
48
+ declare const RESOLVED_A11Y_BRAND: unique symbol;
49
+ /**
50
+ * 合并/规整后的完整无障碍配置:与用户书写的 {@link A11yConfig} 的唯一区别是
51
+ * states 的每个状态名都统一规范化为数组(不再是 `A11yMatcher | A11yMatcher[]`)。
52
+ * resolveA11yInfo 内部与 getPageAgentToolConfig().a11yConfig 读取到的都是这个类型。
53
+ */
54
+ export interface ResolvedA11yConfig {
55
+ roles: A11yRoleRule[];
56
+ states: Partial<Record<A11yStateName, A11yMatcher[]>>;
57
+ whitelist: Array<Element | string>;
58
+ blacklist: Array<Element | string>;
59
+ exposedAttributes: string[];
60
+ readonly [RESOLVED_A11Y_BRAND]?: true;
61
+ }
62
+ /** 是否为 {@link mergeA11yConfig}/{@link mergeA11yConfigs} 产出的已规整配置 */
63
+ export declare function isResolvedA11yConfig(config?: A11yConfig | ResolvedA11yConfig | null): config is ResolvedA11yConfig;
64
+ /** 默认生效的无障碍配置:零配置即可覆盖 ARIA 标准 + 主流 UI 框架的常见错误/警告/选中态检测 */
65
+ export declare const DEFAULT_A11Y_CONFIG: ResolvedA11yConfig;
66
+ /**
67
+ * 从 roles 规则中提取指定角色的所有 CSS 选择器(展平为一维 string[])。
68
+ * 供 DOM 检测函数(detectPageDialog / getVisibleTooltipElements)复用:
69
+ * 这些函数需要选择器字符串做 deepQuerySelectorAll,而非 matches 判断。
70
+ */
71
+ export declare function getSelectorsForRole(roles: A11yRoleRule[], targetRole: string): string[];
72
+ /** 从状态规则中提取纯 CSS 选择器列表(忽略只有 match 函数、没有 selector 的规则;数组 selector 会被展开),供页面级选择器扫描场景复用 */
73
+ export declare function extractSelectors(rules?: A11yMatcher | A11yMatcher[]): string[];
74
+ /** 合并两份 A11yConfig:数组类字段拼接(additive,不丢失 base 中已有的规则),states 按 key 独立合并 */
75
+ export declare function mergeA11yConfigs(base: A11yConfig, patch: A11yConfig): ResolvedA11yConfig;
76
+ /**
77
+ * 将用户配置与默认配置合并(additive),得到最终生效的完整配置。
78
+ * 若入参已是 {@link ResolvedA11yConfig},直接返回(幂等,避免默认规则被再次拼接)。
79
+ */
80
+ export declare function mergeA11yConfig(user?: A11yConfig | ResolvedA11yConfig): ResolvedA11yConfig;
81
+ /**
82
+ * 保证拿到已与默认值合并的配置:已规整则原样返回(同引用,零开销),否则与默认配置合并。
83
+ * buildA11yTree / resolveA11yInfo 热路径应优先走此函数,避免对运行期配置反复 merge。
84
+ */
85
+ export declare function ensureResolvedA11yConfig(config?: A11yConfig | ResolvedA11yConfig): ResolvedA11yConfig;
86
+ /** 恒等函数,仅用于书写配置时获得 TS 类型提示/校验(风格对齐 defineConfig) */
87
+ export declare function defineA11yConfig(config: A11yConfig): A11yConfig;
88
+ export declare function resolveA11yRole(el: Element, config?: A11yConfig | ResolvedA11yConfig): string;
89
+ export declare function resolveA11yStates(el: Element, config?: A11yConfig | ResolvedA11yConfig): string[];
90
+ /**
91
+ * 统一入口(供用户直接调用的底层函数):读取配置 -> 依据 roles/states 规则计算出该元素的
92
+ * 完整无障碍信息(角色 + 状态 token)。buildA11yTree 内部对每个 DOM 节点也是调用这一个函数,
93
+ * 是声明式规则与树生成结果之间唯一的桥接点;用户也可以直接调用它来调试/复用同一套解析逻辑。
94
+ *
95
+ * 若传入已是 {@link ResolvedA11yConfig}(如 getPageAgentToolConfig().a11yConfig),则跳过合并,
96
+ * 避免在整树遍历时对每个节点重复 array spread / 默认规则翻倍。
97
+ */
98
+ export declare function resolveA11yInfo(el: Element, config?: A11yConfig | ResolvedA11yConfig): A11yInfo;
99
+ export {};
@@ -5,5 +5,27 @@
5
5
  */
6
6
  export declare const DEFAULT_ERROR_SELECTORS: string[];
7
7
  export declare const DEFAULT_WARNING_SELECTORS: string[];
8
+ /** 模态弹窗默认选择器:ARIA 标准 + 主流 UI 框架(唯一来源,顶层 constants.ts 从此处重新导出) */
9
+ export declare const DEFAULT_DIALOG_SELECTORS: string[];
10
+ /** 可见 tooltip / 浮层提示默认选择器:ARIA 标准 + 主流 UI 框架(唯一来源,顶层 constants.ts 从此处重新导出) */
11
+ export declare const DEFAULT_TOOLTIP_SELECTORS: string[];
8
12
  export declare const TAG_ROLE_MAP: Record<string, string>;
13
+ /**
14
+ * 框架级 role 覆盖规则
15
+ *
16
+ * 当元素没有显式 role 属性时,按 CSS 选择器匹配框架特有 class 模式,
17
+ * 推断出符合 ARIA 语义的 role,使无障碍树能正确识别非标准 UI 组件。
18
+ *
19
+ * 优先级:显式 role 属性 > 框架 role 覆盖 > 标签隐式映射 > generic
20
+ *
21
+ * 注意:框架特有规则(如 Tiny3 Tabs、tp-helptip)应放在各框架预设配置中
22
+ *(如 configs/console-cloud.ts),此处仅保留通用规则。
23
+ */
24
+ export interface RoleOverride {
25
+ /** CSS 选择器,匹配则应用该 role */
26
+ selector: string;
27
+ /** 覆盖后的 ARIA 角色 */
28
+ role: string;
29
+ }
30
+ export declare const DEFAULT_ROLE_OVERRIDES: RoleOverride[];
9
31
  export declare const INPUT_TYPE_ROLE: Record<string, string>;
@@ -14,4 +14,4 @@ import { SearchA11yTreeOptions, SearchA11yTreeResult } from './types';
14
14
  * searchA11yTree('提交') // 找名称含"提交"的节点
15
15
  * searchA11yTree('#3') // 找 ref #3
16
16
  */
17
- export declare function searchA11yTree(query: string, root?: Element, blacklist?: Element[], whitelist?: Element[], options?: SearchA11yTreeOptions): SearchA11yTreeResult;
17
+ export declare function searchA11yTree(query: string, root?: Element, options?: SearchA11yTreeOptions): SearchA11yTreeResult;
@@ -1,8 +1,5 @@
1
- /**
2
- * a11y/types.ts
3
- *
4
- * 定义无障碍树模块(A11y Tree)的核心接口和类型。
5
- */
1
+ import { A11yConfig } from './config';
2
+
6
3
  /** ref 索引 → HTMLElement 映射,供 click/fill/select 操作使用 */
7
4
  export type RefMap = Map<number, HTMLElement>;
8
5
  /** 内部中间态节点,与 DOM 解耦,便于剪枝和序列化 */
@@ -20,8 +17,12 @@ export interface VNode {
20
17
  /** 包含的子节点列表 */
21
18
  children: VNode[];
22
19
  }
23
- /** 构建无障碍树时的配置选项 */
24
- export interface A11yTreeOptions {
20
+ /**
21
+ * 构建无障碍树时的配置选项。
22
+ * 继承统一的 A11yConfig(角色/状态规则、白/黑名单、自定义暴露属性、弹窗选择器),
23
+ * 并额外提供两个控制树"形状"(而非无障碍语义)的选项。
24
+ */
25
+ export interface A11yTreeOptions extends A11yConfig {
25
26
  /**
26
27
  * 是否启用剪枝:无 ref 且无 accessible name 的节点透明穿透
27
28
  * 默认 true(推荐)
@@ -32,21 +33,11 @@ export interface A11yTreeOptions {
32
33
  * 例如:['table', 'row'] 用于保留表格结构
33
34
  */
34
35
  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[];
36
+ }
37
+ /** 序列化 YAML 树时实际用到的形状选项(与无障碍语义解析无关,独立于 A11yConfig) */
38
+ export interface A11yTreeShapeOptions {
39
+ pruneUnnamed: boolean;
40
+ preserveRoles: string[];
50
41
  }
51
42
  /** 构建无障碍树的返回结果 */
52
43
  export interface A11yTreeResult {
@@ -1,25 +1,46 @@
1
+ import { ResolvedA11yConfig } from './config';
2
+
3
+ export declare function isNonContentElement(el: Element): boolean;
1
4
  /**
2
- * a11y/utils.ts
5
+ * 判断元素是否"自身"呈现 cursor:pointer(而非从祖先继承而来)。
3
6
  *
4
- * 存放生成无障碍树时的通用工具函数:节点解析、状态获取、角色推断及纯文本兜底等。
7
+ * 背景:CSS 的 `cursor` 属性会向子孙继承。可点击容器(如 <a>、自定义卡片 .card-wrapper)
8
+ * 一旦设置 cursor:pointer,其内部所有子孙的 computed cursor 都会变成 pointer。
9
+ * 若仅凭「computed cursor === pointer」判定交互性,会让容器的可点击性"传染"给全部子孙,
10
+ * 产生大量误报 ref(父容器 cursor:pointer 泛滥到每个子节点)。
11
+ *
12
+ * 业界主流 DOM 提取器(如 browser-use 的 doesElementHaveInteractivePointer)同样以
13
+ * cursor:pointer 作为可点击性的核心兜底信号,并通过与父元素对比来定位真正的可点击"边界元素"。
14
+ * 因此这里的判定为:元素自身 computed cursor 为 pointer,且其父元素不是 pointer —— 说明
15
+ * 该元素(或命中它的 CSS 规则)主动声明了指针手势,是真正意义上的可点击目标。
16
+ *
17
+ * 无父元素(如 shadow host 边界、游离节点)时,没有可继承来源,视为自身声明。
5
18
  */
19
+ export declare function hasOwnPointerCursor(el: Element): boolean;
6
20
  /**
7
- * 获取元素的 ARIA 角色
8
- * 优先级:显式 role 属性 > 标签隐式角色 > 'generic'
21
+ * 收集页面中"仅在 :hover/:focus/:active 等交互态下声明 cursor:pointer"的元素集合。
22
+ *
23
+ * 背景(华为云控制台实测):大量可点击卡片(如 `.container-wrapper .shadow:hover{cursor:pointer}`)
24
+ * 只在鼠标悬停时才显示手势,静止态 `getComputedStyle(el).cursor` 读到的是 `auto`,
25
+ * 因此仅凭 computed cursor 的判定(含业界 getComputedStyle 方案)会漏判这类元素。
26
+ * 这里通过扫描样式表把这类"交互态手势"补齐,作为可点击性的兜底信号。
27
+ *
28
+ * 每次构建树只调用一次(O(规则数) 扫描 + 一次合并查询),避免逐元素扫描样式表。
9
29
  */
10
- export declare function inferRole(el: Element): string;
30
+ export declare function collectHoverPointerElements(root: Element): Set<Element>;
31
+ /** 判断元素是否应被跳过(不可见、非内容或在黑名单中) */
32
+ export declare function isHidden(el: Element): boolean;
11
33
  /**
12
- * 收集节点的 ARIA 状态 token
13
- * 格式:[checked] [selected] [disabled] [hasPopup] [cursor=pointer] [value="..."]
34
+ * 收集元素自身或子孙节点的 title,用作图标按钮等无文本节点的名字兜底。
35
+ * 云控制台常见模式:可点击容器无 aria-label,title 挂在内部 span 上。
14
36
  */
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;
37
+ export declare function collectTitleLabel(el: Element): string;
18
38
  /**
19
39
  * 收集子孙节点的文本内容,用作无障碍名字的兜底。
20
40
  * 当普通计算无法提取文本时,遍历后代并拼接可见文本。
41
+ * @param config 已规整的无障碍配置;传入后角色判断会尊重页面自定义 roles 规则
21
42
  */
22
- export declare function collectDescendantText(el: Element): string;
43
+ export declare function collectDescendantText(el: Element, config?: ResolvedA11yConfig): string;
23
44
  /**
24
45
  * 获取元素在 composed tree(组合树)中的有效子元素
25
46
  *
@@ -32,3 +53,17 @@ export declare function collectDescendantText(el: Element): string;
32
53
  * 无 shadowRoot 时直接遍历 light DOM children。
33
54
  */
34
55
  export declare function getComposedChildren(el: Element): Element[];
56
+ /**
57
+ * 提取元素的 tooltip / 帮助提示文本
58
+ *
59
+ * 按以下优先级查找(返回首个非空结果):
60
+ * 1. title 属性
61
+ * 2. aria-describedby 引用的元素文本
62
+ * 3. data-tooltip / data-tips 自定义属性
63
+ * 4. 框架级 tooltip 内容(如 Tiny3 tp-helptip 内的 .tp-helptip-label 文本)
64
+ * 4b. 框架级 overflow 指令(Tiny3 tioverflow / Angular Material matTooltip)
65
+ *
66
+ * 即使 tooltip 容器被隐藏(display:none / opacity:0),也提取其文本内容,
67
+ * 让 AI 无需 hover 即可获取帮助信息。
68
+ */
69
+ export declare function extractTooltipText(el: Element): string;
@@ -1,21 +1,19 @@
1
- import { VNode, RefMap, A11yTreeOptions } from './types';
1
+ import { VNode, RefMap, A11yTreeShapeOptions } from './types';
2
+ import { ResolvedA11yConfig } from './config';
2
3
 
3
4
  /**
4
5
  * 递归将 DOM 元素转换为 VNode 中间表示
5
6
  * @param el 当前 DOM 元素
6
7
  * @param refCounter 引用计数器(使用对象引用避免全局可变状态)
7
8
  * @param refMap ref 索引 → 元素映射
8
- * @param blacklistSet 用户自定义黑名单
9
- * @param whitelistSet 用户自定义白名单
10
- * @param exposedAttributes 需要暴露的自定义属性
11
- * @param errorSelectors 错误选择器
12
- * @param warningSelectors 警告选择器
9
+ * @param blacklistSet 已解析的黑名单元素集合
10
+ * @param whitelistSet 已解析的白名单元素集合
11
+ * @param config 已与默认值合并的统一无障碍配置
12
+ * @param hoverPointerSet 只在 :hover/:focus/:active 下声明 cursor:pointer 的元素集合(静止态读不到手势,靠样式表扫描兜底)
13
13
  */
14
14
  export declare function buildVNode(el: Element, refCounter: {
15
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;
16
+ }, refMap: RefMap, blacklistSet: Set<Element>, whitelistSet: Set<Element>, config: ResolvedA11yConfig, hoverPointerSet?: Set<Element>): VNode | null;
19
17
  /**
20
18
  * 判断 VNode 子树是否包含任何有价值的节点(有 ref 或有 accessible name)
21
19
  * 用于过滤空容器子树,避免输出无内容的嵌套层级
@@ -29,9 +27,14 @@ export declare function hasValue(vnode: VNode): boolean;
29
27
  * - 去掉 generic/list/listitem 等纯布局噪音(无 name 时穿透)
30
28
  * - 保留有 name 的 listitem(有 name 时保留,兼顾内容理解场景)
31
29
  */
32
- export declare function shouldPassThrough(vnode: VNode, opts: Required<A11yTreeOptions>): boolean;
30
+ export declare function shouldPassThrough(vnode: VNode, opts: A11yTreeShapeOptions): boolean;
33
31
  /**
34
32
  * 将 VNode 序列化为 YAML 行数组
35
33
  * 穿透节点时,子节点在当前 depth 平铺输出(不增加缩进层级)
34
+ *
35
+ * 文本折叠规则(Static-Lift + Interactive-Keep,保字优先):
36
+ * 1. 子树全静态 → 省略子节点,文字保留在父节点
37
+ * 2. 混合子树 → 静态文案上提到父 name(成功才省略静态子节点);交互分支递归保留;
38
+ * 禁止把交互文案并入父 name;上提失败则静态子节点独立输出,绝不丢字
36
39
  */
37
- export declare function serializeVNode(vnode: VNode, depth: number, opts: Required<A11yTreeOptions>): string[];
40
+ export declare function serializeVNode(vnode: VNode, depth: number, opts: A11yTreeShapeOptions): string[];
@@ -6,6 +6,7 @@
6
6
  */
7
7
  export * from './a11y/types';
8
8
  export * from './a11y/constants';
9
+ export * from './a11y/config';
9
10
  export * from './a11y/utils';
10
11
  export * from './a11y/vnode';
11
12
  export * from './a11y/build';
@@ -0,0 +1,6 @@
1
+ import { PageAgentToolOptions } from '../tool-config';
2
+
3
+ /** 云控制台 page-agent-tool 预设配置 */
4
+ export declare const consoleCloudPageAgentToolOptions: PageAgentToolOptions;
5
+ /** 判断当前页面是否应使用云控制台(consoleCloud)预设 */
6
+ export declare function isConsoleCloudHost(hostname?: string): boolean;
@@ -1,22 +1,12 @@
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
- }
1
+ /** 校验错误/弹窗/tooltip 默认选择器:ARIA 标准 + 主流 UI 框架(唯一来源为 a11y/constants.ts,此处重新导出保持旧路径可用) */
2
+ export { DEFAULT_ERROR_SELECTORS, DEFAULT_DIALOG_SELECTORS, DEFAULT_TOOLTIP_SELECTORS } from './a11y/constants';
3
+ /** 框架级 role 覆盖规则:为非标准 UI 组件推断 ARIA 角色(已纳入 DEFAULT_A11Y_CONFIG.roles,此处重新导出保持旧路径可用) */
4
+ export { DEFAULT_ROLE_OVERRIDES, type RoleOverride } from './a11y/constants';
5
+ /** registerPageAgentTool(options) 的入参类型,定义见 tool-config.ts(与运行期 setPageAgentToolConfig 的补丁类型一致) */
6
+ export type { PageAgentToolOptions } from './tool-config';
11
7
  declare global {
12
8
  interface Window {
13
- __webmcpcli_interactiveWhitelist?: Element[];
14
- __webmcpcli_interactiveBlacklist?: Element[];
15
- __webmcpcli_exposedAttributes?: string[];
9
+ /** 指定网站可覆盖该函数,在每次 getBrowserState 之前调用,常用于配合 setPageAgentToolConfig 动态调整当前页面的配置 */
16
10
  __webmcpcli_beforeGetBrowserState?: (() => void) | null;
17
- /** 校验错误元素 CSS 选择器列表(覆盖默认,用于检测页面可见的校验错误) */
18
- __webmcpcli_errorSelectors?: string[];
19
- /** 模态弹窗元素 CSS 选择器列表(覆盖默认,用于检测阻塞交互的弹窗) */
20
- __webmcpcli_dialogSelectors?: string[];
21
11
  }
22
12
  }
@@ -2,6 +2,19 @@ import { PageController } from '@page-agent/page-controller';
2
2
  import { PageStateCache } from './page-state-cache';
3
3
  import { RefMap } from './a11y-tree';
4
4
 
5
+ export type PageAgentToolContentResult = {
6
+ content: Array<{
7
+ type: 'text';
8
+ text: string;
9
+ }>;
10
+ };
11
+ export type PageAgentToolErrorResult = PageAgentToolContentResult & {
12
+ isError: true;
13
+ error: string;
14
+ };
15
+ /** 将额外字段合并进 browserState JSON,保持整段可反序列化 */
16
+ export declare function withStateFields(stateText: string, extra: Record<string, unknown>): string;
17
+ export declare function createActionErrorResult(message: string, buildBrowserStateResponse: ActionContext['buildBrowserStateResponse']): Promise<PageAgentToolErrorResult>;
5
18
  export interface ActionContext {
6
19
  pageController: PageController;
7
20
  stateCache: PageStateCache;
@@ -25,4 +38,5 @@ export interface ActionContext {
25
38
  text: string;
26
39
  }>;
27
40
  }>;
41
+ actionError: (msg: string) => Promise<PageAgentToolErrorResult>;
28
42
  }
@@ -0,0 +1,9 @@
1
+ import { ActionContext } from '../context';
2
+ import { PageAgentToolInput } from '../schema';
3
+
4
+ export declare function handleHover(args: PageAgentToolInput, ctx: ActionContext): Promise<{
5
+ content: Array<{
6
+ type: "text";
7
+ text: string;
8
+ }>;
9
+ }>;
@@ -1,6 +1,7 @@
1
1
  import { ActionContext } from '../context';
2
+ import { PageAgentToolInput } from '../schema';
2
3
 
3
- export declare function handleSearchTree(args: any, ctx: ActionContext): Promise<{
4
+ export declare function handleSearchTree(args: PageAgentToolInput, ctx: ActionContext): Promise<{
4
5
  content: Array<{
5
6
  type: "text";
6
7
  text: string;
@@ -2,6 +2,18 @@ import { RefMap } from '../a11y-tree';
2
2
 
3
3
  export declare const HIGHLIGHT_CONTAINER_ID = "webmcpcli-highlight-container";
4
4
  export declare const HIGHLIGHT_CONTAINER_STYLE_ID = "webmcpcli-highlight-container-style";
5
+ export type HighlightRect = {
6
+ top: number;
7
+ left: number;
8
+ width: number;
9
+ height: number;
10
+ };
11
+ /**
12
+ * 解析高亮矩形。
13
+ * Tiny3 `ti-icon` / `tp-icon` 字形常画在 ::before 上,宿主 getBoundingClientRect 宽或高为 0,
14
+ * 旧逻辑直接跳过导致帮助中心关闭/全屏等图标有 ref 却不高亮。
15
+ */
16
+ export declare function resolveHighlightRect(el: HTMLElement): HighlightRect | null;
5
17
  export declare const highlight: (refMap: RefMap, parentIframe?: HTMLIFrameElement | null) => void;
6
18
  /** 移除高亮, 可反复调用 */
7
19
  export declare const unhighlight: () => void;
@@ -11,4 +11,6 @@ export declare class SimulatorMask extends EventTarget {
11
11
  show(): void;
12
12
  hide(): void;
13
13
  dispose(): void;
14
+ borderElement(targetElement: HTMLElement): void;
15
+ removeBorderElement(): void;
14
16
  }
@@ -0,0 +1,26 @@
1
+ import { PageAgentToolInput, PageAgentToolRawInput } from './schema';
2
+ import { PageController } from '@page-agent/page-controller';
3
+
4
+ export declare const PAGE_AGENT_TOOL_CALL_EVENT = "page-agent-tool-call";
5
+ export declare const PAGE_AGENT_TOOL_RESULT_EVENT = "page-agent-tool-result";
6
+ export declare const PAGE_AGENT_CHAT_END_EVENT = "page-agent-chat-end";
7
+ export type PageAgentToolCallEventDetail = {
8
+ data?: PageAgentToolRawInput;
9
+ requestId: string;
10
+ };
11
+ export type PageAgentToolResultEventDetail = {
12
+ data: {
13
+ success: boolean;
14
+ result?: unknown;
15
+ error?: string;
16
+ };
17
+ requestId: string;
18
+ };
19
+ type ExecutePageAgentTool = (data: PageAgentToolInput) => Promise<unknown>;
20
+ declare global {
21
+ interface Window {
22
+ __nextSdkPageAgentToolEventCleanup?: () => void;
23
+ }
24
+ }
25
+ export declare function setupPageAgentToolEventBridge(executePageAgentTool: ExecutePageAgentTool, pageController: PageController): void;
26
+ export {};
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
 
3
3
  export declare const inputSchema: z.ZodObject<{
4
- action: z.ZodEnum<["browserState", "click", "fill", "select", "scroll", "executeJavascript", "searchTree"]>;
4
+ action: z.ZodEnum<["browserState", "click", "fill", "select", "scroll", "executeJavascript", "searchTree", "hover"]>;
5
5
  index: z.ZodOptional<z.ZodNumber>;
6
6
  text: z.ZodOptional<z.ZodString>;
7
7
  down: z.ZodOptional<z.ZodBoolean>;
@@ -14,7 +14,7 @@ export declare const inputSchema: z.ZodObject<{
14
14
  maxMatches: z.ZodDefault<z.ZodNumber>;
15
15
  responseMode: z.ZodDefault<z.ZodOptional<z.ZodEnum<["full", "diff", "both"]>>>;
16
16
  }, "strip", z.ZodTypeAny, {
17
- action: "fill" | "click" | "select" | "scroll" | "browserState" | "executeJavascript" | "searchTree";
17
+ action: "fill" | "hover" | "click" | "select" | "scroll" | "browserState" | "executeJavascript" | "searchTree";
18
18
  contextLines: number;
19
19
  maxMatches: number;
20
20
  responseMode: "full" | "diff" | "both";
@@ -27,7 +27,7 @@ export declare const inputSchema: z.ZodObject<{
27
27
  pixels?: number | undefined;
28
28
  query?: string | undefined;
29
29
  }, {
30
- action: "fill" | "click" | "select" | "scroll" | "browserState" | "executeJavascript" | "searchTree";
30
+ action: "fill" | "hover" | "click" | "select" | "scroll" | "browserState" | "executeJavascript" | "searchTree";
31
31
  text?: string | undefined;
32
32
  right?: boolean | undefined;
33
33
  script?: string | undefined;
@@ -41,3 +41,4 @@ export declare const inputSchema: z.ZodObject<{
41
41
  responseMode?: "full" | "diff" | "both" | undefined;
42
42
  }>;
43
43
  export type PageAgentToolInput = z.infer<typeof inputSchema>;
44
+ export type PageAgentToolRawInput = z.input<typeof inputSchema>;
@@ -0,0 +1,50 @@
1
+ import { A11yConfig, ResolvedA11yConfig } from './a11y/config';
2
+
3
+ export interface PageAgentToolConfig {
4
+ /** 是否启用元素高亮 */
5
+ enableHighlight: boolean;
6
+ /** 是否在工具调用后移除遮罩, 默认值为 true 移除 */
7
+ removeMaskAfterToolCall?: boolean;
8
+ /**
9
+ * 统一无障碍配置:按角色(roles)、状态(states:selected/disabled/error/warning 等)自定义规则,
10
+ * 以及白名单/黑名单/自定义暴露属性/弹窗选择器。已与默认配置合并(数组类字段是拼接结果)。
11
+ */
12
+ a11yConfig: ResolvedA11yConfig;
13
+ }
14
+ /**
15
+ * 用于初始化(registerPageAgentTool 的入参)或运行期 setPageAgentToolConfig 的补丁对象:
16
+ * enableHighlight 为覆盖式更新;a11yConfig 为拼接式合并(数组类字段追加,不丢已有规则,语义见 a11y/config.ts)。
17
+ */
18
+ export interface PageAgentToolConfigPatch {
19
+ /** 是否启用元素高亮 */
20
+ enableHighlight?: boolean;
21
+ /** 是否在工具调用后移除遮罩, 默认值为 true 移除 */
22
+ removeMaskAfterToolCall?: boolean;
23
+ /** 是否在工具调用后移除遮罩 */
24
+ /** 统一无障碍配置,会与当前生效的 a11yConfig 按数组拼接合并 */
25
+ a11yConfig?: A11yConfig;
26
+ }
27
+ /** registerPageAgentTool(options) 的入参类型,与运行期补丁 {@link PageAgentToolConfigPatch} 完全一致 */
28
+ export type PageAgentToolOptions = PageAgentToolConfigPatch;
29
+ /** 默认生效的完整工具配置 */
30
+ export declare const DEFAULT_PAGE_AGENT_TOOL_CONFIG: PageAgentToolConfig;
31
+ declare global {
32
+ interface Window {
33
+ /** 运行期唯一生效的 page-agent-tool 完整配置(已与默认值合并),可通过 getPageAgentToolConfig/setPageAgentToolConfig 读写 */
34
+ __webmcpcli_toolConfig?: PageAgentToolConfig;
35
+ }
36
+ }
37
+ /** 读取当前生效的完整工具配置(已与默认值合并)。未初始化时返回默认配置 */
38
+ export declare function getPageAgentToolConfig(): PageAgentToolConfig;
39
+ /**
40
+ * 更新当前生效配置。
41
+ * - patch 为对象时:enableHighlight 覆盖式更新;a11yConfig 与当前配置按数组拼接合并(不丢已有规则)
42
+ * - patch 为函数时:入参为当前生效配置,返回值直接与默认配置合并(而不是再与 current 相加)。
43
+ * 这样函数体内可以对 current.a11yConfig 做任意过滤/裁剪(如按条件"移除"某条旧规则),
44
+ * 返回值即为最终生效的配置,不会因为再与 current 相加而让被过滤掉的旧规则"复活"
45
+ * - options.mode = 'replace' 时(仅影响对象类型的 patch):不与"当前生效配置"合并,而是与默认配置重新合并
46
+ * 返回合并后的最新完整配置,并写回运行期存储供 buildBrowserStateResponse/buildA11yTree 等读取。
47
+ */
48
+ export declare function setPageAgentToolConfig(patch: PageAgentToolConfigPatch | ((current: PageAgentToolConfig) => PageAgentToolConfigPatch), options?: {
49
+ mode?: 'merge' | 'replace';
50
+ }): PageAgentToolConfig;
@@ -2,5 +2,11 @@ export declare function isInShadowDom(el: Element): boolean;
2
2
  export declare function dispatchComposedEvents(el: Element, ...types: string[]): void;
3
3
  export declare function deepQuerySelectorAll(selector: string, root?: Document | Element | ShadowRoot): Element[];
4
4
  export declare function waitForDomSettled(timeout?: number, settleTime?: number): Promise<void>;
5
- export declare function detectPageDialog(): string;
6
- export declare function detectValidationErrors(): string;
5
+ /** 页面级模态弹窗检测结果 */
6
+ export interface DetectedDialog {
7
+ text: string;
8
+ buttons: string[];
9
+ }
10
+ export declare function detectPageDialog(): DetectedDialog[];
11
+ export declare function detectValidationErrors(): string[];
12
+ export declare function detectVisibleTooltips(): string[];
package/dist/runtime.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import { initializeBuiltinWebMCP } from './page-tools/initialize-builtin-WebMCP';
2
2
  import { registerPageAgentTool } from './page-tools/page-agent-tool';
3
+ import { getPageAgentToolConfig, setPageAgentToolConfig } from './page-tools/tool-config';
4
+ import { defineA11yConfig } from './page-tools/a11y/config';
5
+ import { consoleCloudPageAgentToolOptions, isConsoleCloudHost } from './page-tools/configs/console-cloud';
3
6
 
4
- export { initializeBuiltinWebMCP, registerPageAgentTool };
7
+ export { initializeBuiltinWebMCP, registerPageAgentTool, getPageAgentToolConfig, setPageAgentToolConfig, defineA11yConfig, consoleCloudPageAgentToolOptions, isConsoleCloudHost, };