@opentiny/next-sdk 0.4.1 → 0.4.2
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.
- package/dist/{SimulatorMask-BHVXyogh-iNUb4dyF.js → SimulatorMask-BHVXyogh-CARX3Rff.js} +1 -1
- package/dist/core.js +1 -1
- package/dist/{index-CXK8CcKq.js → index-R_HIbfUX.js} +1698 -1170
- package/dist/index.d.ts +11 -0
- package/dist/index.js +69 -50
- package/dist/{initialize-builtin-WebMCP-rALfqS-o.js → initialize-builtin-WebMCP-JaoKwVlm.js} +355 -346
- package/dist/page-tools/a11y/build.d.ts +3 -4
- package/dist/page-tools/a11y/config.d.ts +96 -0
- package/dist/page-tools/a11y/constants.d.ts +2 -0
- package/dist/page-tools/a11y/search.d.ts +1 -1
- package/dist/page-tools/a11y/types.d.ts +13 -22
- package/dist/page-tools/a11y/utils.d.ts +32 -11
- package/dist/page-tools/a11y/vnode.d.ts +14 -11
- package/dist/page-tools/a11y-tree.d.ts +1 -0
- package/dist/page-tools/configs/console-cloud.d.ts +6 -0
- package/dist/page-tools/constants.d.ts +5 -17
- package/dist/page-tools/context.d.ts +12 -0
- package/dist/page-tools/handlers/searchTree.d.ts +2 -1
- package/dist/page-tools/page-agent-highlight/index.d.ts +12 -0
- package/dist/page-tools/page-agent-mask/SimulatorMask.d.ts +2 -0
- package/dist/page-tools/page-agent-tool-event.d.ts +26 -0
- package/dist/page-tools/schema.d.ts +1 -0
- package/dist/page-tools/tool-config.d.ts +50 -0
- package/dist/runtime.d.ts +4 -1
- package/dist/runtime.js +37 -49
- package/dist/vitest.config.d.ts +2 -0
- package/index.ts +35 -0
- package/package.json +21 -16
- package/page-tools/a11y/build.ts +38 -34
- package/page-tools/a11y/config.ts +465 -0
- package/page-tools/a11y/constants.ts +21 -0
- package/page-tools/a11y/search.ts +1 -3
- package/page-tools/a11y/types.ts +14 -17
- package/page-tools/a11y/utils.ts +129 -156
- package/page-tools/a11y/vnode.ts +277 -67
- package/page-tools/a11y-tree.ts +1 -0
- package/page-tools/bridge.ts +22 -2
- package/page-tools/configs/console-cloud.ts +172 -0
- package/page-tools/constants.ts +5 -65
- package/page-tools/context.ts +38 -1
- package/page-tools/handlers/click.ts +6 -2
- package/page-tools/handlers/fill.ts +10 -5
- package/page-tools/handlers/searchTree.ts +7 -10
- package/page-tools/handlers/select.ts +10 -5
- package/page-tools/page-agent-highlight/index.ts +66 -19
- package/page-tools/page-agent-mask/SimulatorMask.ts +42 -22
- package/page-tools/page-agent-mask/hauwei.svg +25 -0
- package/page-tools/page-agent-prompt.md +1 -1
- package/page-tools/page-agent-tool-event.ts +113 -0
- package/page-tools/page-agent-tool.ts +85 -53
- package/page-tools/schema.ts +1 -0
- package/page-tools/tool-config.ts +100 -0
- package/page-tools/utils/dom.ts +6 -3
- package/runtime.ts +37 -6
- package/test/page-tools/a11y/build.test.ts +638 -0
- package/test/page-tools/a11y/config.test.ts +370 -0
- package/test/page-tools/configs/console-cloud.test.ts +168 -0
- package/test/page-tools/page-agent-highlight.test.ts +110 -0
- package/test/page-tools/page-agent-tool-dispatch.test.ts +208 -0
- package/test/page-tools/page-agent-tool.test.ts +102 -0
- package/test/page-tools/tool-config.test.ts +112 -0
- package/test/page-tools/utils/dom.test.ts +122 -0
- package/vite.config.runtime.ts +1 -1
- package/vitest.config.ts +10 -0
|
@@ -6,11 +6,13 @@ import { buildA11yTree, type RefMap } from './a11y-tree'
|
|
|
6
6
|
import { PageStateCache } from './page-state-cache'
|
|
7
7
|
import { SimulatorMask } from './page-agent-mask/SimulatorMask'
|
|
8
8
|
import { highlight, unhighlight, globalRemoveListener } from './page-agent-highlight'
|
|
9
|
+
import { setupPageAgentToolEventBridge } from './page-agent-tool-event'
|
|
9
10
|
|
|
10
|
-
import {
|
|
11
|
+
import type { PageAgentToolOptions } from './constants'
|
|
11
12
|
import { inputSchema, type PageAgentToolInput } from './schema'
|
|
12
|
-
import type
|
|
13
|
+
import { createActionErrorResult, type ActionContext } from './context'
|
|
13
14
|
import { detectPageDialog, detectValidationErrors } from './utils/dom'
|
|
15
|
+
import { getPageAgentToolConfig, setPageAgentToolConfig } from './tool-config'
|
|
14
16
|
|
|
15
17
|
import { handleBrowserState } from './handlers/browserState'
|
|
16
18
|
import { handleClick } from './handlers/click'
|
|
@@ -24,19 +26,12 @@ import { handleSearchTree } from './handlers/searchTree'
|
|
|
24
26
|
export function registerPageAgentTool(options: PageAgentToolOptions = {}) {
|
|
25
27
|
initializeBuiltinWebMCP()
|
|
26
28
|
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
29
|
+
// 完整工具配置(顶层选项 enableHighlight + 统一无障碍配置 a11yConfig):与默认配置合并后
|
|
30
|
+
// 得到运行期唯一生效的配置(存于 window.__webmcpcli_toolConfig),后续可通过
|
|
31
|
+
// setPageAgentToolConfig 在运行期继续修改(追加式合并/函数式过滤/整体替换)
|
|
32
|
+
setPageAgentToolConfig(options, { mode: 'replace' })
|
|
31
33
|
|
|
32
|
-
window.
|
|
33
|
-
window.__webmcpcli_interactiveBlacklist = window.__webmcpcli_interactiveBlacklist || [] // 黑名单,反之
|
|
34
|
-
window.__webmcpcli_exposedAttributes = window.__webmcpcli_exposedAttributes || options?.exposedAttributes || [] // 额外暴露的自定义属性白名单
|
|
35
|
-
window.__webmcpcli_beforeGetBrowserState = window.__webmcpcli_beforeGetBrowserState || null // 指定网站覆盖该函数,用于设置当前网站的黑白名单
|
|
36
|
-
// 校验错误选择器:默认覆盖 ARIA 标准 + 主流框架,网站可通过 window.__webmcpcli_errorSelectors 覆盖
|
|
37
|
-
window.__webmcpcli_errorSelectors = window.__webmcpcli_errorSelectors || DEFAULT_ERROR_SELECTORS
|
|
38
|
-
// 模态弹窗选择器:同上
|
|
39
|
-
window.__webmcpcli_dialogSelectors = window.__webmcpcli_dialogSelectors || DEFAULT_DIALOG_SELECTORS
|
|
34
|
+
window.__webmcpcli_beforeGetBrowserState = window.__webmcpcli_beforeGetBrowserState || null // 指定网站覆盖该函数,可在其中调用 setPageAgentToolConfig 动态调整当前页面的配置
|
|
40
35
|
|
|
41
36
|
// 保留 PageController ,先关闭内置mask, 再手工绑定当前项目的mask类
|
|
42
37
|
const pageController = new PageController({ enableMask: false })
|
|
@@ -55,10 +50,15 @@ export function registerPageAgentTool(options: PageAgentToolOptions = {}) {
|
|
|
55
50
|
|
|
56
51
|
// ─── 辅助:构建错误响应 ───────────────────────────────────────────────────
|
|
57
52
|
async function errContent(msg: string) {
|
|
58
|
-
await pageController.hideMask()
|
|
59
53
|
return { content: [{ type: 'text' as const, text: msg }] }
|
|
60
54
|
}
|
|
61
55
|
|
|
56
|
+
async function actionError(msg: string) {
|
|
57
|
+
const result = await createActionErrorResult(msg, buildBrowserStateResponse)
|
|
58
|
+
options.removeMaskAfterToolCall && (await pageController.hideMask())
|
|
59
|
+
return result
|
|
60
|
+
}
|
|
61
|
+
|
|
62
62
|
// AI 使用过期 ref 时,自动重建 A11y 树并返回全量状态,
|
|
63
63
|
// 避免 AI 额外往返调用 browserState,减少操作轮次
|
|
64
64
|
async function refreshOnStaleRef(action: string, index: number) {
|
|
@@ -76,20 +76,12 @@ export function registerPageAgentTool(options: PageAgentToolOptions = {}) {
|
|
|
76
76
|
const url = window.location.href
|
|
77
77
|
const title = document.title
|
|
78
78
|
|
|
79
|
-
//
|
|
80
|
-
const
|
|
81
|
-
const whitelist = (window.__webmcpcli_interactiveWhitelist ?? []) as Element[]
|
|
82
|
-
const exposedAttributes = (window.__webmcpcli_exposedAttributes ?? []) as string[]
|
|
83
|
-
|
|
84
|
-
// 生成语义化 ARIA YAML 树 + 刷新 refMap
|
|
85
|
-
const { yaml, refMap } = buildA11yTree(document.body, blacklist, whitelist, {
|
|
86
|
-
exposedAttributes,
|
|
87
|
-
errorSelectors: (window.__webmcpcli_errorSelectors ?? DEFAULT_ERROR_SELECTORS).join(', ')
|
|
88
|
-
})
|
|
79
|
+
// 生成语义化 ARIA YAML 树 + 刷新 refMap(统一读取运行期生效的配置,支持 setPageAgentToolConfig 动态修改)
|
|
80
|
+
const { yaml, refMap } = buildA11yTree(document.body, getPageAgentToolConfig().a11yConfig)
|
|
89
81
|
currentRefMap = refMap
|
|
90
82
|
|
|
91
|
-
//
|
|
92
|
-
if (
|
|
83
|
+
// 高亮交互元素,且增加全局移除高亮的监听(读取运行期生效的配置,支持 setPageAgentToolConfig 动态修改)
|
|
84
|
+
if (getPageAgentToolConfig().enableHighlight) {
|
|
93
85
|
highlight(refMap)
|
|
94
86
|
globalRemoveListener()
|
|
95
87
|
}
|
|
@@ -97,8 +89,6 @@ export function registerPageAgentTool(options: PageAgentToolOptions = {}) {
|
|
|
97
89
|
// 计算 Diff
|
|
98
90
|
const diff = stateCache.update(url, yaml)
|
|
99
91
|
|
|
100
|
-
await pageController.hideMask()
|
|
101
|
-
|
|
102
92
|
// 检测页面弹窗/遮罩层(确认框、提示框等),让 AI 优先处理
|
|
103
93
|
const dialogAlert = detectPageDialog()
|
|
104
94
|
// 检测表单校验错误,提醒 AI 优先修复
|
|
@@ -134,7 +124,68 @@ export function registerPageAgentTool(options: PageAgentToolOptions = {}) {
|
|
|
134
124
|
},
|
|
135
125
|
buildBrowserStateResponse,
|
|
136
126
|
refreshOnStaleRef,
|
|
137
|
-
errContent
|
|
127
|
+
errContent,
|
|
128
|
+
actionError
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function executePageAgentTool(args: PageAgentToolInput) {
|
|
132
|
+
try {
|
|
133
|
+
let ret: any
|
|
134
|
+
|
|
135
|
+
switch (args.action) {
|
|
136
|
+
case 'browserState':
|
|
137
|
+
ret = await handleBrowserState(args, actionContext)
|
|
138
|
+
break
|
|
139
|
+
case 'click':
|
|
140
|
+
await pageController.showMask()
|
|
141
|
+
pageController.mask.borderElement(currentRefMap.get(args.index))
|
|
142
|
+
ret = await handleClick(args, actionContext)
|
|
143
|
+
pageController.mask.removeBorderElement()
|
|
144
|
+
options.removeMaskAfterToolCall && (await pageController.hideMask())
|
|
145
|
+
break
|
|
146
|
+
case 'fill':
|
|
147
|
+
await pageController.showMask()
|
|
148
|
+
pageController.mask.borderElement(currentRefMap.get(args.index))
|
|
149
|
+
ret = await handleFill(args, actionContext)
|
|
150
|
+
pageController.mask.removeBorderElement()
|
|
151
|
+
options.removeMaskAfterToolCall && (await pageController.hideMask())
|
|
152
|
+
break
|
|
153
|
+
case 'select':
|
|
154
|
+
await pageController.showMask()
|
|
155
|
+
pageController.mask.borderElement(currentRefMap.get(args.index))
|
|
156
|
+
ret = await handleSelect(args, actionContext)
|
|
157
|
+
pageController.mask.removeBorderElement()
|
|
158
|
+
options.removeMaskAfterToolCall && (await pageController.hideMask())
|
|
159
|
+
break
|
|
160
|
+
case 'scroll':
|
|
161
|
+
await pageController.showMask()
|
|
162
|
+
ret = await handleScroll(args, actionContext)
|
|
163
|
+
options.removeMaskAfterToolCall && (await pageController.hideMask())
|
|
164
|
+
break
|
|
165
|
+
case 'executeJavascript':
|
|
166
|
+
ret = await handleExecuteJavascript(args, actionContext)
|
|
167
|
+
break
|
|
168
|
+
case 'searchTree':
|
|
169
|
+
ret = await handleSearchTree(args, actionContext)
|
|
170
|
+
break
|
|
171
|
+
default:
|
|
172
|
+
ret = { content: [{ type: 'text' as const, text: `未知操作: ${args.action}` }] }
|
|
173
|
+
}
|
|
174
|
+
return ret
|
|
175
|
+
} catch (error) {
|
|
176
|
+
const actionNames = {
|
|
177
|
+
click: '点击',
|
|
178
|
+
fill: '填写',
|
|
179
|
+
select: '选择'
|
|
180
|
+
} as const
|
|
181
|
+
if (args.action in actionNames) {
|
|
182
|
+
return actionError(
|
|
183
|
+
`${actionNames[args.action as keyof typeof actionNames]}执行异常: ${error instanceof Error ? error.message : String(error)}`
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
options.removeMaskAfterToolCall && (await pageController.hideMask())
|
|
187
|
+
throw error
|
|
188
|
+
}
|
|
138
189
|
}
|
|
139
190
|
|
|
140
191
|
// ─── 工具注册(名称与 inputSchema 与原版完全一致)────────────────────────
|
|
@@ -144,32 +195,13 @@ export function registerPageAgentTool(options: PageAgentToolOptions = {}) {
|
|
|
144
195
|
// @ts-ignore
|
|
145
196
|
inputSchema: zodToJsonSchema(inputSchema) as any,
|
|
146
197
|
async execute(args: PageAgentToolInput) {
|
|
147
|
-
await pageController.showMask()
|
|
148
198
|
try {
|
|
149
|
-
|
|
150
|
-
case 'browserState':
|
|
151
|
-
return await handleBrowserState(args, actionContext)
|
|
152
|
-
case 'click':
|
|
153
|
-
return await handleClick(args, actionContext)
|
|
154
|
-
case 'fill':
|
|
155
|
-
return await handleFill(args, actionContext)
|
|
156
|
-
case 'select':
|
|
157
|
-
return await handleSelect(args, actionContext)
|
|
158
|
-
case 'scroll':
|
|
159
|
-
return await handleScroll(args, actionContext)
|
|
160
|
-
case 'executeJavascript':
|
|
161
|
-
return await handleExecuteJavascript(args, actionContext)
|
|
162
|
-
case 'searchTree':
|
|
163
|
-
return await handleSearchTree(args, actionContext)
|
|
164
|
-
default:
|
|
165
|
-
await pageController.hideMask()
|
|
166
|
-
// @ts-ignore
|
|
167
|
-
return { content: [{ type: 'text', text: `未知操作: ${args.action}` }] }
|
|
168
|
-
}
|
|
199
|
+
return executePageAgentTool(args)
|
|
169
200
|
} catch (error) {
|
|
170
|
-
|
|
171
|
-
return { content: [{ type: 'text', text: `异常: ${String(error)}` }] }
|
|
201
|
+
return { content: [{ type: 'text' as const, text: `异常: ${String(error)}` }] }
|
|
172
202
|
}
|
|
173
203
|
}
|
|
174
204
|
})
|
|
205
|
+
|
|
206
|
+
setupPageAgentToolEventBridge(executePageAgentTool, pageController)
|
|
175
207
|
}
|
package/page-tools/schema.ts
CHANGED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tool-config.ts
|
|
3
|
+
*
|
|
4
|
+
* registerPageAgentTool 的完整运行期配置:顶层选项(enableHighlight 等)+ 统一无障碍配置(a11yConfig)。
|
|
5
|
+
* 两者合并到同一个配置对象里,提供唯一一套运行期读写 API(getPageAgentToolConfig/setPageAgentToolConfig):
|
|
6
|
+
* 注册时初始化一次,之后可随时读取/修改,无需分别记住两套 get/set 函数。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { A11yConfig, ResolvedA11yConfig } from './a11y/config'
|
|
10
|
+
import { DEFAULT_A11Y_CONFIG, mergeA11yConfig, mergeA11yConfigs } from './a11y/config'
|
|
11
|
+
|
|
12
|
+
export interface PageAgentToolConfig {
|
|
13
|
+
/** 是否启用元素高亮 */
|
|
14
|
+
enableHighlight: boolean
|
|
15
|
+
/** 是否在工具调用后移除遮罩, 默认值为 true 移除 */
|
|
16
|
+
removeMaskAfterToolCall?: boolean
|
|
17
|
+
/**
|
|
18
|
+
* 统一无障碍配置:按角色(roles)、状态(states:selected/disabled/error/warning 等)自定义规则,
|
|
19
|
+
* 以及白名单/黑名单/自定义暴露属性/弹窗选择器。已与默认配置合并(数组类字段是拼接结果)。
|
|
20
|
+
*/
|
|
21
|
+
a11yConfig: ResolvedA11yConfig
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 用于初始化(registerPageAgentTool 的入参)或运行期 setPageAgentToolConfig 的补丁对象:
|
|
26
|
+
* enableHighlight 为覆盖式更新;a11yConfig 为拼接式合并(数组类字段追加,不丢已有规则,语义见 a11y/config.ts)。
|
|
27
|
+
*/
|
|
28
|
+
export interface PageAgentToolConfigPatch {
|
|
29
|
+
/** 是否启用元素高亮 */
|
|
30
|
+
enableHighlight?: boolean
|
|
31
|
+
/** 是否在工具调用后移除遮罩, 默认值为 true 移除 */
|
|
32
|
+
removeMaskAfterToolCall?: boolean
|
|
33
|
+
/** 是否在工具调用后移除遮罩 */
|
|
34
|
+
/** 统一无障碍配置,会与当前生效的 a11yConfig 按数组拼接合并 */
|
|
35
|
+
a11yConfig?: A11yConfig
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** registerPageAgentTool(options) 的入参类型,与运行期补丁 {@link PageAgentToolConfigPatch} 完全一致 */
|
|
39
|
+
export type PageAgentToolOptions = PageAgentToolConfigPatch
|
|
40
|
+
|
|
41
|
+
/** 默认生效的完整工具配置 */
|
|
42
|
+
export const DEFAULT_PAGE_AGENT_TOOL_CONFIG: PageAgentToolConfig = {
|
|
43
|
+
enableHighlight: false,
|
|
44
|
+
removeMaskAfterToolCall: true,
|
|
45
|
+
a11yConfig: DEFAULT_A11Y_CONFIG
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
declare global {
|
|
49
|
+
interface Window {
|
|
50
|
+
/** 运行期唯一生效的 page-agent-tool 完整配置(已与默认值合并),可通过 getPageAgentToolConfig/setPageAgentToolConfig 读写 */
|
|
51
|
+
__webmcpcli_toolConfig?: PageAgentToolConfig
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 读取当前生效的完整工具配置(已与默认值合并)。未初始化时返回默认配置 */
|
|
56
|
+
export function getPageAgentToolConfig(): PageAgentToolConfig {
|
|
57
|
+
if (typeof window !== 'undefined' && window.__webmcpcli_toolConfig) {
|
|
58
|
+
return window.__webmcpcli_toolConfig
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
enableHighlight: DEFAULT_PAGE_AGENT_TOOL_CONFIG.enableHighlight,
|
|
62
|
+
removeMaskAfterToolCall: DEFAULT_PAGE_AGENT_TOOL_CONFIG.removeMaskAfterToolCall,
|
|
63
|
+
a11yConfig: mergeA11yConfig()
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function resolvePatch(patch: PageAgentToolConfigPatch, base: PageAgentToolConfig): PageAgentToolConfig {
|
|
68
|
+
return {
|
|
69
|
+
enableHighlight: patch.enableHighlight ?? base.enableHighlight,
|
|
70
|
+
removeMaskAfterToolCall: patch.removeMaskAfterToolCall ?? base.removeMaskAfterToolCall,
|
|
71
|
+
a11yConfig: mergeA11yConfigs(base.a11yConfig, patch.a11yConfig ?? {})
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 更新当前生效配置。
|
|
77
|
+
* - patch 为对象时:enableHighlight 覆盖式更新;a11yConfig 与当前配置按数组拼接合并(不丢已有规则)
|
|
78
|
+
* - patch 为函数时:入参为当前生效配置,返回值直接与默认配置合并(而不是再与 current 相加)。
|
|
79
|
+
* 这样函数体内可以对 current.a11yConfig 做任意过滤/裁剪(如按条件"移除"某条旧规则),
|
|
80
|
+
* 返回值即为最终生效的配置,不会因为再与 current 相加而让被过滤掉的旧规则"复活"
|
|
81
|
+
* - options.mode = 'replace' 时(仅影响对象类型的 patch):不与"当前生效配置"合并,而是与默认配置重新合并
|
|
82
|
+
* 返回合并后的最新完整配置,并写回运行期存储供 buildBrowserStateResponse/buildA11yTree 等读取。
|
|
83
|
+
*/
|
|
84
|
+
export function setPageAgentToolConfig(
|
|
85
|
+
patch: PageAgentToolConfigPatch | ((current: PageAgentToolConfig) => PageAgentToolConfigPatch),
|
|
86
|
+
options?: { mode?: 'merge' | 'replace' }
|
|
87
|
+
): PageAgentToolConfig {
|
|
88
|
+
const mode = options?.mode ?? 'merge'
|
|
89
|
+
const current = getPageAgentToolConfig()
|
|
90
|
+
|
|
91
|
+
const next =
|
|
92
|
+
typeof patch === 'function'
|
|
93
|
+
? resolvePatch(patch(current), DEFAULT_PAGE_AGENT_TOOL_CONFIG)
|
|
94
|
+
: resolvePatch(patch, mode === 'replace' ? DEFAULT_PAGE_AGENT_TOOL_CONFIG : current)
|
|
95
|
+
|
|
96
|
+
if (typeof window !== 'undefined') {
|
|
97
|
+
window.__webmcpcli_toolConfig = next
|
|
98
|
+
}
|
|
99
|
+
return next
|
|
100
|
+
}
|
package/page-tools/utils/dom.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { extractSelectors } from '../a11y/config'
|
|
2
|
+
import { getPageAgentToolConfig } from '../tool-config'
|
|
2
3
|
|
|
3
4
|
// ─── 辅助:Shadow DOM 事件穿透 ───────────────────────────────────────────
|
|
4
5
|
// 外部包 inputTextElement/selectOptionElement 派发的合成事件 composed:false,
|
|
@@ -69,7 +70,8 @@ export function detectPageDialog(): string {
|
|
|
69
70
|
const seen = new Set<Element>()
|
|
70
71
|
const dialogs: string[] = []
|
|
71
72
|
// 仅匹配明确的模态弹窗选择器,避免宽泛子串匹配误报
|
|
72
|
-
|
|
73
|
+
// 统一取 getPageAgentToolConfig().a11yConfig.dialogSelectors(已含默认值 + 用户配置)
|
|
74
|
+
const selectors = getPageAgentToolConfig().a11yConfig.dialogSelectors
|
|
73
75
|
|
|
74
76
|
for (const selector of selectors) {
|
|
75
77
|
try {
|
|
@@ -125,7 +127,8 @@ export function detectValidationErrors(): string {
|
|
|
125
127
|
const seen = new Set<Element>()
|
|
126
128
|
const errors: string[] = []
|
|
127
129
|
// 校验错误选择器:ARIA 标准 + 主流 UI 框架(可配置)
|
|
128
|
-
|
|
130
|
+
// 统一取 getPageAgentToolConfig().a11yConfig.states.error(已含默认值 + 用户配置)
|
|
131
|
+
const selectors = extractSelectors(getPageAgentToolConfig().a11yConfig.states.error)
|
|
129
132
|
|
|
130
133
|
for (const selector of selectors) {
|
|
131
134
|
try {
|
package/runtime.ts
CHANGED
|
@@ -1,13 +1,44 @@
|
|
|
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 {
|
|
6
|
+
consoleCloudPageAgentToolOptions,
|
|
7
|
+
isConsoleCloudHost,
|
|
8
|
+
} from './page-tools/configs/console-cloud'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* runtime IIFE 仅挂载可调用 API,不自动 registerPageAgentTool。
|
|
12
|
+
* 调用方需自行传入 enableHighlight / a11yConfig 等选项后再注册,例如:
|
|
13
|
+
* registerPageAgentTool({ enableHighlight: true, a11yConfig: { exposedAttributes: ['cf-uba'] } })
|
|
14
|
+
* registerPageAgentTool(consoleCloudPageAgentToolOptions)
|
|
15
|
+
*/
|
|
16
|
+
const runtimeApi = {
|
|
17
|
+
initializeBuiltinWebMCP,
|
|
18
|
+
registerPageAgentTool,
|
|
19
|
+
getPageAgentToolConfig,
|
|
20
|
+
setPageAgentToolConfig,
|
|
21
|
+
defineA11yConfig,
|
|
22
|
+
consoleCloudPageAgentToolOptions,
|
|
23
|
+
isConsoleCloudHost,
|
|
24
|
+
}
|
|
3
25
|
|
|
4
26
|
if (typeof window !== 'undefined') {
|
|
5
|
-
|
|
6
|
-
;(window as any).registerPageAgentTool = registerPageAgentTool
|
|
27
|
+
Object.assign(window, runtimeApi)
|
|
7
28
|
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
29
|
+
// 之前版本存在 WebMCP.registerPageAgentTool,当前先临时兼容,后续再移除
|
|
30
|
+
if (!(window as any).WebMCP) {
|
|
31
|
+
;(window as any).WebMCP = {}
|
|
32
|
+
}
|
|
33
|
+
Object.assign((window as any).WebMCP, runtimeApi)
|
|
11
34
|
}
|
|
12
35
|
|
|
13
|
-
export {
|
|
36
|
+
export {
|
|
37
|
+
initializeBuiltinWebMCP,
|
|
38
|
+
registerPageAgentTool,
|
|
39
|
+
getPageAgentToolConfig,
|
|
40
|
+
setPageAgentToolConfig,
|
|
41
|
+
defineA11yConfig,
|
|
42
|
+
consoleCloudPageAgentToolOptions,
|
|
43
|
+
isConsoleCloudHost,
|
|
44
|
+
}
|