@opentiny/next-sdk 0.3.3 → 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 (134) 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 +1 -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 +1 -1
  10. package/dist/core.js +18 -18
  11. package/dist/index-CXK8CcKq.js +6076 -0
  12. package/dist/index.d.ts +2 -4
  13. package/dist/index.js +57 -2783
  14. package/dist/initialize-builtin-WebMCP-rALfqS-o.js +6389 -0
  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 +12 -0
  22. package/dist/page-tools/bridge.d.ts +0 -6
  23. package/dist/page-tools/constants.d.ts +22 -0
  24. package/dist/page-tools/context.d.ts +28 -0
  25. package/dist/page-tools/handlers/browserState.d.ts +8 -0
  26. package/dist/page-tools/handlers/click.d.ts +8 -0
  27. package/dist/page-tools/handlers/executeJavascript.d.ts +8 -0
  28. package/dist/page-tools/handlers/fill.d.ts +8 -0
  29. package/dist/page-tools/handlers/scroll.d.ts +8 -0
  30. package/dist/page-tools/handlers/searchTree.d.ts +8 -0
  31. package/dist/page-tools/handlers/select.d.ts +8 -0
  32. package/dist/page-tools/initialize-builtin-WebMCP.d.ts +1 -0
  33. package/dist/page-tools/page-agent-highlight/index.d.ts +9 -0
  34. package/dist/page-tools/page-agent-mask/SimulatorMask.d.ts +14 -0
  35. package/dist/page-tools/page-agent-mask/checkDarkMode.d.ts +5 -0
  36. package/dist/page-tools/page-agent-tool.d.ts +4 -0
  37. package/dist/page-tools/page-state-cache.d.ts +36 -0
  38. package/dist/page-tools/schema.d.ts +43 -0
  39. package/dist/page-tools/utils/dom.d.ts +6 -0
  40. package/dist/page-tools/utils/scroll.d.ts +15 -0
  41. package/dist/runtime.d.ts +4 -0
  42. package/dist/runtime.js +744 -0
  43. package/dist/utils/builtinProxy.d.ts +1 -1
  44. package/index.ts +2 -19
  45. package/package.json +14 -18
  46. package/page-tools/a11y/build.ts +70 -0
  47. package/page-tools/a11y/constants.ts +110 -0
  48. package/page-tools/a11y/search.ts +129 -0
  49. package/page-tools/a11y/types.ts +108 -0
  50. package/page-tools/a11y/utils.ts +266 -0
  51. package/page-tools/a11y/vnode.ts +229 -0
  52. package/page-tools/a11y-tree.ts +13 -0
  53. package/page-tools/bridge.ts +49 -15
  54. package/page-tools/constants.ts +72 -0
  55. package/page-tools/context.ts +13 -0
  56. package/page-tools/handlers/browserState.ts +12 -0
  57. package/page-tools/handlers/click.ts +26 -0
  58. package/page-tools/handlers/executeJavascript.ts +22 -0
  59. package/page-tools/handlers/fill.ts +60 -0
  60. package/page-tools/handlers/scroll.ts +66 -0
  61. package/page-tools/handlers/searchTree.ts +30 -0
  62. package/page-tools/handlers/select.ts +34 -0
  63. package/page-tools/initialize-builtin-WebMCP.ts +20 -0
  64. package/page-tools/page-agent-highlight/index.ts +198 -0
  65. package/page-tools/page-agent-mask/SimulatorMask.module.css +14 -0
  66. package/page-tools/page-agent-mask/SimulatorMask.ts +279 -0
  67. package/page-tools/page-agent-mask/checkDarkMode.ts +181 -0
  68. package/page-tools/page-agent-mask/cursor-border.svg +3 -0
  69. package/page-tools/page-agent-mask/cursor-fill.svg +5 -0
  70. package/page-tools/page-agent-mask/cursor.module.css +70 -0
  71. package/page-tools/page-agent-prompt.md +139 -0
  72. package/page-tools/page-agent-tool.ts +175 -0
  73. package/page-tools/page-state-cache.ts +78 -0
  74. package/page-tools/schema.ts +51 -0
  75. package/page-tools/utils/dom.ts +155 -0
  76. package/page-tools/utils/scroll.ts +58 -0
  77. package/runtime.ts +13 -0
  78. package/utils/builtinProxy.ts +45 -13
  79. package/vite.config.runtime.ts +22 -0
  80. package/vite.config.ts +52 -8
  81. package/McpSdk.ts +0 -14
  82. package/WebAgent.ts +0 -5
  83. package/WebMcp.ts +0 -20
  84. package/Zod.ts +0 -1
  85. package/dist/AgentModelProvider-CwqOT28f.js +0 -4198
  86. package/dist/McpSdk.d.ts +0 -14
  87. package/dist/WebAgent.d.ts +0 -5
  88. package/dist/WebMcp.d.ts +0 -20
  89. package/dist/Zod.d.ts +0 -1
  90. package/dist/index.es.dev.js +0 -53427
  91. package/dist/index.es.js +0 -42147
  92. package/dist/index.umd.dev.js +0 -53820
  93. package/dist/index.umd.js +0 -814
  94. package/dist/mcpsdk@1.25.3.dev.js +0 -22621
  95. package/dist/mcpsdk@1.25.3.es.dev.js +0 -22619
  96. package/dist/mcpsdk@1.25.3.es.js +0 -16802
  97. package/dist/mcpsdk@1.25.3.js +0 -43
  98. package/dist/transport/ExtensionClientTransport.d.ts +0 -24
  99. package/dist/transport/ExtensionContentServerTransport.d.ts +0 -39
  100. package/dist/transport/ExtensionPageServerTransport.d.ts +0 -36
  101. package/dist/transport/messages.d.ts +0 -9
  102. package/dist/vite.config.mcpSdk.d.ts +0 -2
  103. package/dist/vite.config.webAgent.d.ts +0 -2
  104. package/dist/vite.config.webMcp.d.ts +0 -2
  105. package/dist/vite.config.webMcpFull.d.ts +0 -2
  106. package/dist/vite.config.zod.d.ts +0 -2
  107. package/dist/webagent.dev.js +0 -47597
  108. package/dist/webagent.es.dev.js +0 -47204
  109. package/dist/webagent.es.js +0 -37494
  110. package/dist/webagent.js +0 -634
  111. package/dist/webmcp-full.dev.js +0 -24430
  112. package/dist/webmcp-full.es.dev.js +0 -24426
  113. package/dist/webmcp-full.es.js +0 -18333
  114. package/dist/webmcp-full.js +0 -43
  115. package/dist/webmcp.dev.js +0 -1595
  116. package/dist/webmcp.es.dev.js +0 -1589
  117. package/dist/webmcp.es.js +0 -1406
  118. package/dist/webmcp.js +0 -1
  119. package/dist/zod@3.25.76.dev.js +0 -4037
  120. package/dist/zod@3.25.76.es.dev.js +0 -4033
  121. package/dist/zod@3.25.76.es.js +0 -2945
  122. package/dist/zod@3.25.76.js +0 -1
  123. package/transport/ExtensionClientTransport.ts +0 -100
  124. package/transport/ExtensionContentServerTransport.ts +0 -162
  125. package/transport/ExtensionPageServerTransport.ts +0 -149
  126. package/transport/messages.ts +0 -63
  127. package/vite-build-tsc.ts +0 -63
  128. package/vite-env.d.ts +0 -5
  129. package/vite.config.mcpSdk.ts +0 -28
  130. package/vite.config.webAgent.ts +0 -19
  131. package/vite.config.webMcp.ts +0 -40
  132. package/vite.config.webMcpFull.ts +0 -19
  133. package/vite.config.zod.ts +0 -23
  134. /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[];
@@ -0,0 +1,12 @@
1
+ /**
2
+ * a11y-tree.ts
3
+ *
4
+ * 此文件为 A11y Tree 模块的汇总出口,
5
+ * 方便外部直接从 './a11y-tree' 引入相关类型及方法,而无需调整现有的引用路径。
6
+ */
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';
@@ -131,10 +131,4 @@ export type RegisterPageToolByHandlersOptions = {
131
131
  handlers: PageToolHandlers;
132
132
  };
133
133
  export declare function registerPageTool(options: RegisterPageToolByHandlersOptions): () => void;
134
- /**
135
- * 建立浏览器原生或 polyfill 与 next-sdk 页面工具桥接的联系。
136
- * 若用户或第三方库直接操作 navigator.modelContext 进行工具注册,
137
- * 我们通过此函数进行拦截劫持,并同步到 next-sdk 的握手线路 (MSG_TOOL_REGISTERED / MSG_TOOL_UNREGISTERED),
138
- * 从而保证无论浏览器是否原生支持,均能正常完成 WebMCP 握手交互。
139
- */
140
134
  export declare function setupModelContextBridge(): void;
@@ -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 @@
1
+ export declare const initializeBuiltinWebMCP: () => void;
@@ -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;
@@ -0,0 +1,4 @@
1
+ import { PageAgentToolOptions } from './constants';
2
+
3
+ /** 在浏览器页面中注册 page-agent-tool, 用于页面的内容获取和操作,页面的动效 */
4
+ export declare function registerPageAgentTool(options?: PageAgentToolOptions): void;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * page-state-cache.ts
3
+ *
4
+ * 页面状态 Diff 缓存模块
5
+ * - 缓存上一次 buildA11yTree 生成的 YAML 文本
6
+ * - 每次操作后计算 diff,只返回 +/- 变化行,大幅节省 Token
7
+ */
8
+ export interface PageSnapshot {
9
+ url: string;
10
+ yaml: string;
11
+ }
12
+ export interface DiffResult {
13
+ /** 是否为全量刷新(首次加载或 URL 变化) */
14
+ isFullRefresh: boolean;
15
+ /** 上一次的 URL(用于拼接 URL 变化提示) */
16
+ prevUrl: string;
17
+ /** 新增行数 */
18
+ addedLines: number;
19
+ /** 删除行数 */
20
+ removedLines: number;
21
+ /** 只含 +/- 行的 diff 文本(不含相同行,节省 Token) */
22
+ diffText: string;
23
+ }
24
+ export declare class PageStateCache {
25
+ private prev;
26
+ /** URL 变化或首次调用时,需要全量输出 */
27
+ isFullRefresh(currentUrl: string): boolean;
28
+ /**
29
+ * 更新缓存并返回 diff 结果
30
+ * @param url 当前页面 URL
31
+ * @param yaml 当前 YAML 树文本
32
+ */
33
+ update(url: string, yaml: string): DiffResult;
34
+ /** 强制清空缓存(页面刷新 / 手动重置场景) */
35
+ invalidate(): void;
36
+ }
@@ -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 };