@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.
- package/dist/{SimulatorMask-BHVXyogh-iNUb4dyF.js → SimulatorMask-BHVXyogh-CKmEDsYG.js} +1 -1
- package/dist/core.js +1 -1
- package/dist/{index-CXK8CcKq.js → index-CHMa2zG4.js} +1985 -1434
- 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 +99 -0
- package/dist/page-tools/a11y/constants.d.ts +22 -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 +46 -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 +7 -17
- package/dist/page-tools/context.d.ts +14 -0
- package/dist/page-tools/handlers/hover.d.ts +9 -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 +4 -3
- package/dist/page-tools/tool-config.d.ts +50 -0
- package/dist/page-tools/utils/dom.d.ts +8 -2
- package/dist/runtime.d.ts +4 -1
- package/dist/runtime.js +22 -187
- package/dist/vitest.config.d.ts +2 -0
- package/package.json +26 -16
- package/WebMcpClient.ts +0 -505
- package/WebMcpServer.ts +0 -447
- package/agent/AgentModelProvider.ts +0 -932
- package/agent/type.ts +0 -91
- package/agent/utils/generateReActPrompt.ts +0 -71
- package/agent/utils/getAISDKTools.ts +0 -34
- package/agent/utils/getBuiltinMcpTools.ts +0 -86
- package/agent/utils/parseReActAction.ts +0 -34
- package/core.ts +0 -26
- package/index.ts +0 -56
- package/page-tools/a11y/build.ts +0 -70
- package/page-tools/a11y/constants.ts +0 -110
- package/page-tools/a11y/search.ts +0 -129
- package/page-tools/a11y/types.ts +0 -108
- package/page-tools/a11y/utils.ts +0 -266
- package/page-tools/a11y/vnode.ts +0 -229
- package/page-tools/a11y-tree.ts +0 -13
- package/page-tools/bridge.ts +0 -702
- package/page-tools/constants.ts +0 -72
- package/page-tools/context.ts +0 -13
- package/page-tools/effects.ts +0 -345
- package/page-tools/handlers/browserState.ts +0 -12
- package/page-tools/handlers/click.ts +0 -26
- package/page-tools/handlers/executeJavascript.ts +0 -22
- package/page-tools/handlers/fill.ts +0 -60
- package/page-tools/handlers/scroll.ts +0 -66
- package/page-tools/handlers/searchTree.ts +0 -30
- package/page-tools/handlers/select.ts +0 -34
- package/page-tools/initialize-builtin-WebMCP.ts +0 -20
- package/page-tools/page-agent-highlight/index.ts +0 -198
- package/page-tools/page-agent-mask/SimulatorMask.module.css +0 -14
- package/page-tools/page-agent-mask/SimulatorMask.ts +0 -279
- package/page-tools/page-agent-mask/checkDarkMode.ts +0 -181
- package/page-tools/page-agent-mask/cursor-border.svg +0 -3
- package/page-tools/page-agent-mask/cursor-fill.svg +0 -5
- package/page-tools/page-agent-mask/cursor.module.css +0 -70
- package/page-tools/page-agent-prompt.md +0 -139
- package/page-tools/page-agent-tool.ts +0 -175
- package/page-tools/page-state-cache.ts +0 -78
- package/page-tools/schema.ts +0 -51
- package/page-tools/utils/dom.ts +0 -155
- package/page-tools/utils/scroll.ts +0 -58
- package/remoter/QrCode.ts +0 -54
- package/remoter/createRemoter.ts +0 -957
- package/remoter/svgs/chat.svg +0 -43
- package/remoter/svgs/icon-copy.svg +0 -25
- package/remoter/svgs/link.svg +0 -28
- package/remoter/svgs/logo.svg +0 -45
- package/remoter/svgs/qrcode.svg +0 -35
- package/remoter/svgs/scan.svg +0 -21
- package/remoter/tooltips.ts +0 -260
- package/runtime.html +0 -39
- package/runtime.ts +0 -13
- package/script/utils.ts +0 -26
- package/skills/index.ts +0 -287
- package/tsconfig.json +0 -16
- package/utils/builtinProxy.ts +0 -144
- package/utils/env.ts +0 -13
- package/utils/uuid.ts +0 -10
- package/vite.config.runtime.ts +0 -22
- package/vite.config.ts +0 -63
package/agent/type.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import type { ProviderV2 } from '@ai-sdk/provider'
|
|
2
|
-
import type { MCPClientConfig } from '@ai-sdk/mcp'
|
|
3
|
-
|
|
4
|
-
// 从 MCPClientConfig 中提取 transport 类型
|
|
5
|
-
export type MCPTransport = MCPClientConfig['transport']
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 浏览器内置 WebMCP 测试 API 接口 (如 document.modelContext)
|
|
9
|
-
*/
|
|
10
|
-
export interface BuiltinMcpClient {
|
|
11
|
-
listTools?: () => Promise<any[]>
|
|
12
|
-
getTools?: () => Promise<any[]>
|
|
13
|
-
executeTool: (tool: any, input: string) => Promise<any>
|
|
14
|
-
registerTool?: (config: { name: string; execute: (input: any) => Promise<any> | any; [key: string]: any }) => void
|
|
15
|
-
unregisterTool?: (name: string) => void
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type ProviderFactory = 'openai' | 'deepseek' | ((options: any) => ProviderV2)
|
|
19
|
-
|
|
20
|
-
type LlmFactoryConfig = {
|
|
21
|
-
/** API密钥 */
|
|
22
|
-
apiKey: string
|
|
23
|
-
/** API基础URL */
|
|
24
|
-
baseURL: string
|
|
25
|
-
/** 内置或自定义 Provider 工厂函数 */
|
|
26
|
-
providerType: ProviderFactory
|
|
27
|
-
/** 互斥:当使用 providerType 分支时不允许传入 llm */
|
|
28
|
-
llm?: never
|
|
29
|
-
/** 是否使用 ReAct 模式(通过提示词而非 function calling 进行工具调用),默认为 false */
|
|
30
|
-
useReActMode?: boolean
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
type LlmInstanceConfig = {
|
|
34
|
-
/** 自定义 Provider 实例,优先级最高 */
|
|
35
|
-
llm: ProviderV2
|
|
36
|
-
/** 互斥:当传入 llm 实例时不需要 apiKey/baseURL/providerType */
|
|
37
|
-
apiKey?: never
|
|
38
|
-
baseURL?: never
|
|
39
|
-
providerType?: never
|
|
40
|
-
/** 是否使用 ReAct 模式(通过提示词而非 function calling 进行工具调用),默认为 false */
|
|
41
|
-
useReActMode?: boolean
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** 代理模型提供器的大语言配置对象, 通过 XOR 表达二选一 */
|
|
45
|
-
export type IAgentModelProviderLlmConfig = LlmFactoryConfig | LlmInstanceConfig
|
|
46
|
-
|
|
47
|
-
/** Mcp Server的配置对象 */
|
|
48
|
-
export type McpServerConfig =
|
|
49
|
-
| {
|
|
50
|
-
type: 'streamableHttp'
|
|
51
|
-
url: string
|
|
52
|
-
useAISdkClient?: boolean
|
|
53
|
-
headers?: Record<string, string>
|
|
54
|
-
name?: string
|
|
55
|
-
description?: string
|
|
56
|
-
}
|
|
57
|
-
| {
|
|
58
|
-
type: 'sse'
|
|
59
|
-
url: string
|
|
60
|
-
useAISdkClient?: boolean
|
|
61
|
-
headers?: Record<string, string>
|
|
62
|
-
name?: string
|
|
63
|
-
description?: string
|
|
64
|
-
}
|
|
65
|
-
| {
|
|
66
|
-
type: 'local'
|
|
67
|
-
transport: MCPTransport
|
|
68
|
-
useAISdkClient?: boolean
|
|
69
|
-
name?: string
|
|
70
|
-
description?: string
|
|
71
|
-
}
|
|
72
|
-
| {
|
|
73
|
-
/**
|
|
74
|
-
* 浏览器内置 WebMCP 类型。
|
|
75
|
-
* 将 `document.modelContext` 作为 MCP 工具数据源,
|
|
76
|
-
* 通过 `getBuiltinMcpTools` 适配为 ai-sdk 可调用的 ToolSet。
|
|
77
|
-
*/
|
|
78
|
-
type: 'builtin'
|
|
79
|
-
/** 传入 `document.modelContext` 对象 */
|
|
80
|
-
client: BuiltinMcpClient
|
|
81
|
-
name?: string
|
|
82
|
-
description?: string
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** */
|
|
86
|
-
export interface IAgentModelProviderOption {
|
|
87
|
-
/** 代理模型提供器的大语言配置对象 */
|
|
88
|
-
llmConfig: IAgentModelProviderLlmConfig
|
|
89
|
-
/** Mcp Server的配置对象的集合,键为服务器名称,值为配置对象 */
|
|
90
|
-
mcpServers?: Record<string, McpServerConfig>
|
|
91
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { ToolSet } from 'ai'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 生成 ReAct 模式的工具描述提示词(统一使用 XML 格式)
|
|
5
|
-
* 将工具集合转换为 ReAct 格式的文本描述,用于添加到系统提示词中
|
|
6
|
-
* @param tools - 工具集合对象
|
|
7
|
-
* @returns 格式化的工具描述字符串
|
|
8
|
-
*/
|
|
9
|
-
export function generateReActToolsPrompt(tools: ToolSet): string {
|
|
10
|
-
const toolEntries = Object.entries(tools)
|
|
11
|
-
|
|
12
|
-
// 如果没有工具,返回空字符串
|
|
13
|
-
if (toolEntries.length === 0) {
|
|
14
|
-
return ''
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
let prompt = `
|
|
18
|
-
# 工具调用
|
|
19
|
-
|
|
20
|
-
你可以根据需要调用以下工具:
|
|
21
|
-
|
|
22
|
-
<tools>
|
|
23
|
-
`
|
|
24
|
-
|
|
25
|
-
// 遍历所有工具,生成工具描述
|
|
26
|
-
toolEntries.forEach(([toolName, tool]) => {
|
|
27
|
-
const toolInfo = tool as any
|
|
28
|
-
const description = toolInfo.description || '无描述'
|
|
29
|
-
const schema = toolInfo.parameters || toolInfo.inputSchema || {}
|
|
30
|
-
|
|
31
|
-
// 构造类似 OpenAI function 的格式但放在 XML 中
|
|
32
|
-
const toolJson = {
|
|
33
|
-
name: toolName,
|
|
34
|
-
description: description,
|
|
35
|
-
parameters: schema
|
|
36
|
-
}
|
|
37
|
-
prompt += `${JSON.stringify(toolJson, null, 2)}\n`
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
prompt += `
|
|
41
|
-
</tools>
|
|
42
|
-
|
|
43
|
-
## 工具调用格式
|
|
44
|
-
|
|
45
|
-
要调用工具,请使用以下 XML 格式:
|
|
46
|
-
Thought: [你的思考过程]
|
|
47
|
-
<tool_call>
|
|
48
|
-
{"name": "toolName", "arguments": {"arg1": "value1"}}
|
|
49
|
-
</tool_call>
|
|
50
|
-
|
|
51
|
-
工具执行后,你将收到 <tool_response> 格式的结果。你可以继续思考或调用其他工具。
|
|
52
|
-
|
|
53
|
-
## 使用示例
|
|
54
|
-
|
|
55
|
-
如果用户要求"获取今天的日期",你可以这样调用工具:
|
|
56
|
-
Thought: 用户想要获取今天的日期,我需要调用日期相关的工具。
|
|
57
|
-
<tool_call>{"name": "get-today", "arguments": {}}</tool_call>
|
|
58
|
-
|
|
59
|
-
然后等待工具返回结果(Observation),再根据结果给出最终答案。
|
|
60
|
-
|
|
61
|
-
## 任务完成
|
|
62
|
-
|
|
63
|
-
当任务完成或无法继续时,直接给出最终答案即可。
|
|
64
|
-
|
|
65
|
-
**重要提示**:
|
|
66
|
-
- 必须严格按照 XML 格式调用工具
|
|
67
|
-
- arguments 必须是有效的 JSON 格式
|
|
68
|
-
- 如果不需要调用工具,直接给出最终答案即可
|
|
69
|
-
`
|
|
70
|
-
return prompt
|
|
71
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { dynamicTool, jsonSchema, Tool, ToolExecutionOptions, ToolSet } from 'ai'
|
|
2
|
-
import { WebMcpClient } from '../../WebMcpClient'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 快速从官方 mcp 或 WebMcpClient 这2种client中读取 tools 数组,并转换成 ai-sdk 的tool的对象格式。
|
|
6
|
-
* @params client 一个已连接好的 WebMcpClient
|
|
7
|
-
* @returns ai-sdk的dynamicTool对象。
|
|
8
|
-
*/
|
|
9
|
-
export const getAISDKTools = async (client: WebMcpClient): Promise<ToolSet> => {
|
|
10
|
-
const tools: Record<string, Tool> = {}
|
|
11
|
-
|
|
12
|
-
try {
|
|
13
|
-
const listToolsResult = await client.listTools()
|
|
14
|
-
for (const { name, description, inputSchema } of listToolsResult.tools) {
|
|
15
|
-
const execute = async (args: any, options: ToolExecutionOptions): Promise<any> => {
|
|
16
|
-
return client.callTool({ name, arguments: args }, { signal: options?.abortSignal })
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
tools[name] = dynamicTool({
|
|
20
|
-
description,
|
|
21
|
-
inputSchema: jsonSchema({
|
|
22
|
-
...inputSchema,
|
|
23
|
-
properties: (inputSchema.properties as Record<string, any>) ?? {},
|
|
24
|
-
additionalProperties: false
|
|
25
|
-
}),
|
|
26
|
-
execute
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return tools
|
|
31
|
-
} catch (error) {
|
|
32
|
-
throw error
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { dynamicTool, jsonSchema, Tool, ToolSet } from 'ai'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 浏览器内置 WebMCP 测试 API 的工具描述格式(Chrome document.modelContext)
|
|
5
|
-
*/
|
|
6
|
-
type BuiltinToolDescriptor = {
|
|
7
|
-
name: string
|
|
8
|
-
description?: string
|
|
9
|
-
inputSchema?: {
|
|
10
|
-
type?: string
|
|
11
|
-
properties?: Record<string, unknown>
|
|
12
|
-
required?: string[]
|
|
13
|
-
[key: string]: unknown
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
type BuiltinModelContextTesting = {
|
|
18
|
-
listTools?: () => Promise<BuiltinToolDescriptor[]>
|
|
19
|
-
getTools?: () => Promise<BuiltinToolDescriptor[]>
|
|
20
|
-
executeTool?: (tool: { name: string }, input: string) => Promise<unknown>
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 将浏览器内置 WebMCP 的 `document.modelContext` 适配为 ai-sdk 的 ToolSet。
|
|
25
|
-
*
|
|
26
|
-
* 类似 getAISDKTools,但数据源是浏览器原生 API 而非 MCP client。
|
|
27
|
-
* 工具执行时通过 `executeTool(toolObj, JSON.stringify(args))` 代理给浏览器。
|
|
28
|
-
*
|
|
29
|
-
* @param client - `document.modelContext` 对象
|
|
30
|
-
* @returns ai-sdk 格式的 ToolSet,可直接传入 streamText/generateText 的 tools 参数
|
|
31
|
-
*/
|
|
32
|
-
export const getBuiltinMcpTools = async (client: object | undefined | null): Promise<ToolSet> => {
|
|
33
|
-
const tools: Record<string, Tool> = {}
|
|
34
|
-
if (!client) {
|
|
35
|
-
return tools
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const testing = client as BuiltinModelContextTesting
|
|
39
|
-
|
|
40
|
-
// 优先使用 listTools,降级到 getTools
|
|
41
|
-
const listFn = testing.listTools ?? testing.getTools
|
|
42
|
-
if (!listFn) {
|
|
43
|
-
return tools
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const rawList = await listFn.call(testing)
|
|
47
|
-
const list = Array.isArray(rawList) ? (rawList as BuiltinToolDescriptor[]) : []
|
|
48
|
-
|
|
49
|
-
for (const descriptor of list) {
|
|
50
|
-
const { name, description } = descriptor
|
|
51
|
-
const rawInputSchema = descriptor.inputSchema
|
|
52
|
-
let schemaObj: Record<string, any> = {}
|
|
53
|
-
|
|
54
|
-
if (typeof rawInputSchema === 'string') {
|
|
55
|
-
try {
|
|
56
|
-
schemaObj = JSON.parse(rawInputSchema)
|
|
57
|
-
} catch (e) {
|
|
58
|
-
console.error('Failed to parse inputSchema in getBuiltinMcpTools:', e)
|
|
59
|
-
}
|
|
60
|
-
} else if (typeof rawInputSchema === 'object' && rawInputSchema !== null) {
|
|
61
|
-
schemaObj = rawInputSchema as Record<string, any>
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// 规范化 inputSchema:补全 properties/additionalProperties 字段
|
|
65
|
-
const normalizedSchema = {
|
|
66
|
-
type: 'object' as const,
|
|
67
|
-
properties: (schemaObj.properties ?? {}) as Record<string, unknown>,
|
|
68
|
-
...(schemaObj.required ? { required: schemaObj.required } : {}),
|
|
69
|
-
additionalProperties: false,
|
|
70
|
-
...schemaObj
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
tools[name] = dynamicTool({
|
|
74
|
-
description: description ?? '',
|
|
75
|
-
inputSchema: jsonSchema(normalizedSchema as Parameters<typeof jsonSchema>[0]),
|
|
76
|
-
async execute(args) {
|
|
77
|
-
if (!testing.executeTool) {
|
|
78
|
-
throw new Error(`document.modelContext.executeTool is not available`)
|
|
79
|
-
}
|
|
80
|
-
return testing.executeTool(descriptor, JSON.stringify(args ?? {}))
|
|
81
|
-
}
|
|
82
|
-
})
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return tools
|
|
86
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { ToolSet } from 'ai'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 解析 ReAct 格式的工具调用
|
|
5
|
-
* 从模型输出文本中提取工具名称和参数
|
|
6
|
-
* 现在统一使用 XML 格式(<call> 标签),同时保留对其他格式的兼容性支持
|
|
7
|
-
* @param text - 模型输出的文本
|
|
8
|
-
* @param availableTools - 可用的工具集合,用于验证工具名称
|
|
9
|
-
* @returns 解析出的工具调用信息,如果未找到则返回 null
|
|
10
|
-
*/
|
|
11
|
-
export function parseReActAction(text: string, availableTools: ToolSet): { toolName: string; arguments: any } | null {
|
|
12
|
-
if (!text || typeof text !== 'string') {
|
|
13
|
-
return null
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// XML 格式 <tool_call>
|
|
17
|
-
const toolCallMatchLegacy = text.match(/<tool_call>([\s\S]*?)<\/tool_call>/i)
|
|
18
|
-
if (toolCallMatchLegacy) {
|
|
19
|
-
try {
|
|
20
|
-
const jsonContent = toolCallMatchLegacy[1].trim()
|
|
21
|
-
const parsed = JSON.parse(jsonContent)
|
|
22
|
-
const toolName = parsed.name || parsed.action || parsed.tool
|
|
23
|
-
const args = parsed.arguments || parsed.args || parsed.input || {}
|
|
24
|
-
|
|
25
|
-
if (toolName && availableTools[toolName]) {
|
|
26
|
-
return { toolName, arguments: args }
|
|
27
|
-
}
|
|
28
|
-
} catch {
|
|
29
|
-
// 解析失败,继续尝试其他方法
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return null
|
|
34
|
-
}
|
package/core.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// 核心导出,仅包含无 DOM 依赖(Node.js / Service Worker 安全)的内容
|
|
2
|
-
import Ajv from 'ajv'
|
|
3
|
-
export { Ajv }
|
|
4
|
-
export { z } from 'zod'
|
|
5
|
-
export { AuthClientProvider } from '@opentiny/next'
|
|
6
|
-
export { ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
7
|
-
export { UriTemplate } from '@modelcontextprotocol/sdk/shared/uriTemplate.js'
|
|
8
|
-
export { completable } from '@modelcontextprotocol/sdk/server/completable.js'
|
|
9
|
-
export { getDisplayName } from '@modelcontextprotocol/sdk/shared/metadataUtils.js'
|
|
10
|
-
export { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js'
|
|
11
|
-
export type * from 'zod'
|
|
12
|
-
export type * from '@opentiny/next'
|
|
13
|
-
export type * from '@modelcontextprotocol/sdk/types.js'
|
|
14
|
-
export type * from '@modelcontextprotocol/sdk/shared/protocol.js'
|
|
15
|
-
export type * from '@modelcontextprotocol/sdk/shared/transport.js'
|
|
16
|
-
export type * from '@modelcontextprotocol/sdk/client/sse.js'
|
|
17
|
-
export type * from '@modelcontextprotocol/sdk/client/streamableHttp.js'
|
|
18
|
-
export type * from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
19
|
-
|
|
20
|
-
export * from './WebMcpServer'
|
|
21
|
-
export * from './WebMcpClient'
|
|
22
|
-
|
|
23
|
-
export { AgentModelProvider } from './agent/AgentModelProvider'
|
|
24
|
-
export { getAISDKTools } from './agent/utils/getAISDKTools'
|
|
25
|
-
export type * from './agent/type'
|
|
26
|
-
export { initializeBuiltinWebMCP } from './page-tools/initialize-builtin-WebMCP'
|
package/index.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
// 从相关包中,导出一些常用变量,方便用户导入
|
|
2
|
-
import Ajv from 'ajv'
|
|
3
|
-
export { Ajv }
|
|
4
|
-
export { z } from 'zod'
|
|
5
|
-
export { AuthClientProvider } from '@opentiny/next'
|
|
6
|
-
export { ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
7
|
-
export { UriTemplate } from '@modelcontextprotocol/sdk/shared/uriTemplate.js'
|
|
8
|
-
export { completable } from '@modelcontextprotocol/sdk/server/completable.js'
|
|
9
|
-
export { getDisplayName } from '@modelcontextprotocol/sdk/shared/metadataUtils.js'
|
|
10
|
-
export { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js'
|
|
11
|
-
export type * from 'zod'
|
|
12
|
-
export type * from '@opentiny/next'
|
|
13
|
-
export type * from '@modelcontextprotocol/sdk/types.js'
|
|
14
|
-
export type * from '@modelcontextprotocol/sdk/shared/protocol.js'
|
|
15
|
-
export type * from '@modelcontextprotocol/sdk/shared/transport.js'
|
|
16
|
-
export type * from '@modelcontextprotocol/sdk/client/sse.js'
|
|
17
|
-
export type * from '@modelcontextprotocol/sdk/client/streamableHttp.js'
|
|
18
|
-
export type * from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
19
|
-
|
|
20
|
-
// 2大核心模块
|
|
21
|
-
export * from './WebMcpServer'
|
|
22
|
-
export * from './WebMcpClient'
|
|
23
|
-
|
|
24
|
-
// 快速创建一个悬浮图标和菜单,是扫码和聊天框的入口
|
|
25
|
-
export * from './remoter/createRemoter'
|
|
26
|
-
|
|
27
|
-
// 一个通用的ai-sdk的agent封装
|
|
28
|
-
export { AgentModelProvider } from './agent/AgentModelProvider'
|
|
29
|
-
|
|
30
|
-
// 快速 从官方 mcp 或 WebMcpClient 这2种client中, 抽取成 ai-sdk 所需要的 tool的对象
|
|
31
|
-
export { getAISDKTools } from './agent/utils/getAISDKTools'
|
|
32
|
-
|
|
33
|
-
// 方便的二维码类
|
|
34
|
-
export { QrCode, type QrCodeOption } from './remoter/QrCode'
|
|
35
|
-
export type * from './agent/type'
|
|
36
|
-
|
|
37
|
-
// Web MCP 页面工具桥接:工具调用自动导航 + 页面消息通信
|
|
38
|
-
export * from './page-tools/bridge'
|
|
39
|
-
|
|
40
|
-
// Web 端 Skill 公共能力:解析 skill 文档、生成 systemPrompt、内置 list_skills / get_skill_content 工具
|
|
41
|
-
export {
|
|
42
|
-
getSkillOverviews,
|
|
43
|
-
formatSkillsForSystemPrompt,
|
|
44
|
-
getSkillMdContent,
|
|
45
|
-
getMainSkillPaths,
|
|
46
|
-
getMainSkillPathByName,
|
|
47
|
-
parseSkillFrontMatter,
|
|
48
|
-
createSkillTools,
|
|
49
|
-
type SkillMeta,
|
|
50
|
-
type SkillToolsSet
|
|
51
|
-
} from './skills/index'
|
|
52
|
-
|
|
53
|
-
export * from '@mcp-b/webmcp-polyfill'
|
|
54
|
-
|
|
55
|
-
export { initializeBuiltinWebMCP } from './page-tools/initialize-builtin-WebMCP'
|
|
56
|
-
export { registerPageAgentTool } from './page-tools/page-agent-tool'
|
package/page-tools/a11y/build.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* a11y/build.ts
|
|
3
|
-
*
|
|
4
|
-
* 暴露生成整棵无障碍树的主逻辑方法。
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { A11yTreeOptions, A11yTreeResult, RefMap } from './types'
|
|
8
|
-
import { DEFAULT_ERROR_SELECTORS, DEFAULT_WARNING_SELECTORS } from './constants'
|
|
9
|
-
import { buildVNode, serializeVNode } from './vnode'
|
|
10
|
-
import { getComposedChildren } from './utils'
|
|
11
|
-
import { HIGHLIGHT_CONTAINER_ID } from '../page-agent-highlight'
|
|
12
|
-
|
|
13
|
-
const DEFAULT_OPTIONS: Required<A11yTreeOptions> = {
|
|
14
|
-
pruneUnnamed: true,
|
|
15
|
-
preserveRoles: [],
|
|
16
|
-
exposedAttributes: [],
|
|
17
|
-
errorSelectors: DEFAULT_ERROR_SELECTORS,
|
|
18
|
-
warningSelectors: DEFAULT_WARNING_SELECTORS
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* 生成当前页面的语义化 ARIA YAML 树
|
|
23
|
-
*
|
|
24
|
-
* @param root 遍历起点,默认 document.body
|
|
25
|
-
* @param blacklist 需要跳过的元素(用户自定义黑名单)
|
|
26
|
-
* @param whitelist 需要识别为可交互的白名单元素列表
|
|
27
|
-
* @param options 过滤选项
|
|
28
|
-
*/
|
|
29
|
-
export function buildA11yTree(
|
|
30
|
-
root: Element = document.body,
|
|
31
|
-
blacklist: Element[] = [],
|
|
32
|
-
whitelist: Element[] = [],
|
|
33
|
-
options?: A11yTreeOptions
|
|
34
|
-
): A11yTreeResult {
|
|
35
|
-
const opts: Required<A11yTreeOptions> = { ...DEFAULT_OPTIONS, ...options }
|
|
36
|
-
// 使用对象引用避免全局可变状态,消除并发调用隐患
|
|
37
|
-
const refCounter = { value: 0 }
|
|
38
|
-
const refMap: RefMap = new Map()
|
|
39
|
-
const blacklistSet = new Set(blacklist)
|
|
40
|
-
const whitelistSet = new Set(whitelist)
|
|
41
|
-
const lines: string[] = []
|
|
42
|
-
|
|
43
|
-
// 永远过滤高亮容器
|
|
44
|
-
blacklistSet.add(document.getElementById(HIGHLIGHT_CONTAINER_ID)!)
|
|
45
|
-
|
|
46
|
-
for (const child of getComposedChildren(root)) {
|
|
47
|
-
const vnode = buildVNode(
|
|
48
|
-
child,
|
|
49
|
-
refCounter,
|
|
50
|
-
refMap,
|
|
51
|
-
blacklistSet,
|
|
52
|
-
whitelistSet,
|
|
53
|
-
opts.exposedAttributes,
|
|
54
|
-
opts.errorSelectors,
|
|
55
|
-
opts.warningSelectors
|
|
56
|
-
)
|
|
57
|
-
if (vnode) {
|
|
58
|
-
lines.push(...serializeVNode(vnode, 0, opts))
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const yaml = '```yaml\n' + lines.join('\n') + '\n```'
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
yaml,
|
|
66
|
-
refMap,
|
|
67
|
-
interactiveCount: refMap.size,
|
|
68
|
-
lines
|
|
69
|
-
}
|
|
70
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* a11y/constants.ts
|
|
3
|
-
*
|
|
4
|
-
* 存放无障碍树依赖的静态常量配置、默认选择器及角色映射表。
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
// ─── 默认校验错误/警告选择器(ARIA 标准 + 主流 UI 框架) ──────────────────
|
|
8
|
-
|
|
9
|
-
export const DEFAULT_ERROR_SELECTORS = [
|
|
10
|
-
'[role="alert"]', '[aria-invalid="true"]',
|
|
11
|
-
'.ti3-unifyvalid-error', '.ti3-error', '.ti-error',
|
|
12
|
-
'.lego-text-error', '.lego-error',
|
|
13
|
-
'.el-form-item__error',
|
|
14
|
-
'.ant-form-item-explain-error',
|
|
15
|
-
'.is-invalid', '.invalid-feedback',
|
|
16
|
-
'.ng-invalid',
|
|
17
|
-
'.error-msg', '.error-message', '.error-text',
|
|
18
|
-
'.field-error', '.form-error',
|
|
19
|
-
'.is-error', '.has-error',
|
|
20
|
-
'.validate-error', '.valid-error',
|
|
21
|
-
]
|
|
22
|
-
|
|
23
|
-
export const DEFAULT_WARNING_SELECTORS = [
|
|
24
|
-
'.ti3-warning', '.ti-warning', '.lego-text-warning',
|
|
25
|
-
'.warning-msg', '.warning-text', '.is-warning', '.has-warning',
|
|
26
|
-
]
|
|
27
|
-
|
|
28
|
-
// ─── ARIA 隐式角色静态映射表(覆盖页面 95%+ 的常用标签)───────────────────────
|
|
29
|
-
|
|
30
|
-
export const TAG_ROLE_MAP: Record<string, string> = {
|
|
31
|
-
a: 'link',
|
|
32
|
-
article: 'article',
|
|
33
|
-
aside: 'complementary',
|
|
34
|
-
button: 'button',
|
|
35
|
-
caption: 'caption',
|
|
36
|
-
cell: 'cell',
|
|
37
|
-
checkbox: 'checkbox',
|
|
38
|
-
code: 'code',
|
|
39
|
-
columnheader: 'columnheader',
|
|
40
|
-
combobox: 'combobox',
|
|
41
|
-
datalist: 'listbox',
|
|
42
|
-
dd: 'definition',
|
|
43
|
-
details: 'group',
|
|
44
|
-
dialog: 'dialog',
|
|
45
|
-
dt: 'term',
|
|
46
|
-
em: 'emphasis',
|
|
47
|
-
fieldset: 'group',
|
|
48
|
-
figure: 'figure',
|
|
49
|
-
footer: 'contentinfo',
|
|
50
|
-
form: 'form',
|
|
51
|
-
h1: 'heading',
|
|
52
|
-
h2: 'heading',
|
|
53
|
-
h3: 'heading',
|
|
54
|
-
h4: 'heading',
|
|
55
|
-
h5: 'heading',
|
|
56
|
-
h6: 'heading',
|
|
57
|
-
header: 'banner',
|
|
58
|
-
hr: 'separator',
|
|
59
|
-
img: 'img',
|
|
60
|
-
input: 'textbox', // 默认,具体 type 下面会覆盖
|
|
61
|
-
li: 'listitem',
|
|
62
|
-
link: 'link',
|
|
63
|
-
main: 'main',
|
|
64
|
-
mark: 'mark',
|
|
65
|
-
math: 'math',
|
|
66
|
-
menu: 'list',
|
|
67
|
-
menuitem: 'menuitem',
|
|
68
|
-
meter: 'meter',
|
|
69
|
-
nav: 'navigation',
|
|
70
|
-
ol: 'list',
|
|
71
|
-
option: 'option',
|
|
72
|
-
output: 'status',
|
|
73
|
-
p: 'paragraph',
|
|
74
|
-
progress: 'progressbar',
|
|
75
|
-
rowheader: 'rowheader',
|
|
76
|
-
search: 'search',
|
|
77
|
-
section: 'region',
|
|
78
|
-
select: 'listbox',
|
|
79
|
-
strong: 'strong',
|
|
80
|
-
summary: 'button',
|
|
81
|
-
table: 'table',
|
|
82
|
-
tbody: 'rowgroup',
|
|
83
|
-
td: 'cell',
|
|
84
|
-
textarea: 'textbox',
|
|
85
|
-
tfoot: 'rowgroup',
|
|
86
|
-
th: 'columnheader',
|
|
87
|
-
thead: 'rowgroup',
|
|
88
|
-
time: 'time',
|
|
89
|
-
tr: 'row',
|
|
90
|
-
ul: 'list',
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// input[type=*] 的角色覆盖
|
|
94
|
-
export const INPUT_TYPE_ROLE: Record<string, string> = {
|
|
95
|
-
button: 'button',
|
|
96
|
-
checkbox: 'checkbox',
|
|
97
|
-
color: 'textbox',
|
|
98
|
-
email: 'textbox',
|
|
99
|
-
file: 'textbox',
|
|
100
|
-
image: 'button',
|
|
101
|
-
number: 'spinbutton',
|
|
102
|
-
radio: 'radio',
|
|
103
|
-
range: 'slider',
|
|
104
|
-
reset: 'button',
|
|
105
|
-
search: 'searchbox',
|
|
106
|
-
submit: 'button',
|
|
107
|
-
tel: 'textbox',
|
|
108
|
-
text: 'textbox',
|
|
109
|
-
url: 'textbox',
|
|
110
|
-
}
|