@opentiny/next-sdk 0.3.1 → 0.3.3-alpha.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 (54) hide show
  1. package/WebMcp.ts +6 -0
  2. package/WebMcpClient.ts +16 -21
  3. package/agent/type.ts +93 -69
  4. package/core.ts +1 -0
  5. package/dist/SimulatorMask-BHVXyogh-BFEGpD5S.js +1048 -0
  6. package/dist/SimulatorMask-BHVXyogh-CCYbrb84.js +801 -0
  7. package/dist/WebMcp.d.ts +3 -0
  8. package/dist/WebMcpClient.d.ts +7 -13
  9. package/dist/agent/type.d.ts +10 -0
  10. package/dist/core.d.ts +1 -0
  11. package/dist/core.js +16 -15
  12. package/dist/index.d.ts +3 -2
  13. package/dist/index.es.dev.js +8384 -2700
  14. package/dist/index.es.js +21608 -16893
  15. package/dist/index.js +4033 -1850
  16. package/dist/index.umd.dev.js +9739 -3110
  17. package/dist/index.umd.js +500 -66
  18. package/dist/initialize-builtin-WebMCP-HgObT902.js +6279 -0
  19. package/dist/mcpsdk@1.25.3.dev.js +253 -94
  20. package/dist/mcpsdk@1.25.3.es.dev.js +253 -94
  21. package/dist/mcpsdk@1.25.3.es.js +5689 -5531
  22. package/dist/mcpsdk@1.25.3.js +32 -27
  23. package/dist/page-tools/a11y-tree.d.ts +103 -0
  24. package/dist/page-tools/bridge.d.ts +0 -6
  25. package/dist/page-tools/initialize-builtin-WebMCP.d.ts +1 -0
  26. package/dist/page-tools/page-agent-tool.d.ts +9 -0
  27. package/dist/page-tools/page-state-cache.d.ts +36 -0
  28. package/dist/skills/index.d.ts +7 -12
  29. package/dist/webagent.dev.js +3772 -1919
  30. package/dist/webagent.es.dev.js +3528 -1571
  31. package/dist/webagent.es.js +16380 -14585
  32. package/dist/webagent.js +74 -66
  33. package/dist/webmcp-full.dev.js +7670 -747
  34. package/dist/webmcp-full.es.dev.js +6482 -608
  35. package/dist/webmcp-full.es.js +12180 -7618
  36. package/dist/webmcp-full.js +631 -29
  37. package/dist/webmcp.dev.js +8047 -53
  38. package/dist/webmcp.es.dev.js +6977 -31
  39. package/dist/webmcp.es.js +6187 -860
  40. package/dist/webmcp.js +602 -1
  41. package/index.ts +2 -15
  42. package/package.json +11 -4
  43. package/page-tools/a11y-tree.ts +532 -0
  44. package/page-tools/bridge.ts +48 -14
  45. package/page-tools/initialize-builtin-WebMCP.ts +20 -0
  46. package/page-tools/page-agent-prompt.md +123 -0
  47. package/page-tools/page-agent-tool.ts +223 -0
  48. package/page-tools/page-state-cache.ts +78 -0
  49. package/remoter/createRemoter.ts +2 -1
  50. package/remoter/svgs/logo.svg +45 -0
  51. package/skills/index.ts +50 -31
  52. package/utils/builtinProxy.ts +42 -20
  53. package/vite-env.d.ts +5 -0
  54. package/dist/AgentModelProvider-BnMj6YSC.js +0 -4182
@@ -0,0 +1,103 @@
1
+ /**
2
+ * a11y-tree.ts
3
+ *
4
+ * 浏览器内语义化 ARIA 树生成器(重构版)
5
+ *
6
+ * 核心改进:
7
+ * 1. 两阶段处理:buildVNode(构建中间树)→ serializeVNode(剪枝序列化)
8
+ * 2. 统一剪枝规则:无 ref 且无 accessible name → 透明穿透(跳过本节点,保留子节点)
9
+ * - 兼顾操作场景(去掉 generic/list/listitem 噪音)
10
+ * - 兼顾内容理解场景(有 name 的 listitem 等节点保留)
11
+ * 3. 修复全局可变状态:refCounter 改为局部对象,消除并发调用隐患
12
+ *
13
+ * 依赖:
14
+ * - dom-accessibility-api: W3C AccName 规范 JS 实现(计算 accessible name)
15
+ * - tabbable: 可交互/可聚焦元素检测(工业级,处理所有边界情况)
16
+ */
17
+ /** ref 索引 → HTMLElement 映射,供 click/fill/select 操作使用 */
18
+ export type RefMap = Map<number, HTMLElement>;
19
+ export interface A11yTreeOptions {
20
+ /**
21
+ * 是否启用剪枝:无 ref 且无 accessible name 的节点透明穿透
22
+ * 默认 true(推荐)
23
+ */
24
+ pruneUnnamed?: boolean;
25
+ /**
26
+ * 强制保留的角色列表,即使无 name 也不穿透(优先级最高)
27
+ * 例如:['table', 'row'] 用于保留表格结构
28
+ */
29
+ preserveRoles?: string[];
30
+ }
31
+ export interface A11yTreeResult {
32
+ /** 语义化 YAML 文本(供 AI 阅读和 Diff 计算) */
33
+ yaml: string;
34
+ /** ref 索引 → HTMLElement 映射(供后续操作使用) */
35
+ refMap: RefMap;
36
+ /** 可交互元素总数 */
37
+ interactiveCount: number;
38
+ /** 原始行数组(不含 yaml 代码块包裹),供搜索使用 */
39
+ lines: string[];
40
+ }
41
+ /** 关键词搜索选项 */
42
+ export interface SearchA11yTreeOptions extends A11yTreeOptions {
43
+ /**
44
+ * 每个匹配行前后保留的上下文行数(类似 grep -C N)
45
+ * 默认 2
46
+ */
47
+ contextLines?: number;
48
+ /**
49
+ * 是否大小写不敏感,默认 true
50
+ */
51
+ caseInsensitive?: boolean;
52
+ /**
53
+ * 最大返回匹配分组数(防止命中过多撑爆上下文),默认 20
54
+ */
55
+ maxMatches?: number;
56
+ }
57
+ /** 单个匹配分组 */
58
+ export interface A11ySearchMatch {
59
+ /** 主命中行行号(1-based) */
60
+ lineNumber: number;
61
+ /** 主命中行内容 */
62
+ line: string;
63
+ /** 含上下文的行列表(带行号) */
64
+ context: Array<{
65
+ lineNumber: number;
66
+ line: string;
67
+ }>;
68
+ }
69
+ /** searchA11yTree 返回值 */
70
+ export interface SearchA11yTreeResult {
71
+ /** 格式化后可直接发给 LLM 的文本 */
72
+ text: string;
73
+ /** 结构化匹配列表 */
74
+ matches: A11ySearchMatch[];
75
+ /** 无障碍树总行数 */
76
+ totalLines: number;
77
+ /** 原始命中行数(去重前) */
78
+ matchCount: number;
79
+ }
80
+ /**
81
+ * 生成当前页面的语义化 ARIA YAML 树
82
+ *
83
+ * @param root 遍历起点,默认 document.body
84
+ * @param blacklist 需要跳过的元素(用户自定义黑名单)
85
+ * @param whitelist 需要识别为可交互的白名单元素列表
86
+ * @param options 过滤选项
87
+ */
88
+ export declare function buildA11yTree(root?: Element, blacklist?: Element[], whitelist?: Element[], options?: A11yTreeOptions): A11yTreeResult;
89
+ /**
90
+ * 在无障碍树中按关键词搜索,返回带行号的匹配结果和上下文
91
+ *
92
+ * 支持的搜索维度(均对同一个 query 字符串做包含匹配):
93
+ * - role:如 `button`、`link`、`heading`
94
+ * - accessible name:节点的语义化名称(引号内文本)
95
+ * - state token:如 `checked`、`disabled`、`expanded`
96
+ * - ref 索引:如 `#5`
97
+ *
98
+ * @example
99
+ * searchA11yTree('button') // 找全部按钮
100
+ * searchA11yTree('提交') // 找名称含"提交"的节点
101
+ * searchA11yTree('#3') // 找 ref #3
102
+ */
103
+ export declare function searchA11yTree(query: string, root?: Element, blacklist?: Element[], whitelist?: Element[], options?: SearchA11yTreeOptions): SearchA11yTreeResult;
@@ -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 @@
1
+ export declare const initializeBuiltinWebMCP: () => void;
@@ -0,0 +1,9 @@
1
+ declare global {
2
+ interface Window {
3
+ __webmcpcli_interactiveWhitelist?: Element[];
4
+ __webmcpcli_interactiveBlacklist?: Element[];
5
+ __webmcpcli_beforeGetBrowserState?: (() => void) | null;
6
+ }
7
+ }
8
+ /** 在浏览器页面中注册 page-agent-tool, 用于页面的内容获取和操作,页面的动效 */
9
+ export declare function registerPageAgentTool(): 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
+ }
@@ -15,41 +15,36 @@ export interface SkillMeta {
15
15
  /**
16
16
  * 从主 SKILL.md 的 YAML front matter 中用正则提取 name、description
17
17
  */
18
- export declare function parseSkillFrontMatter(content: string): {
18
+ export declare function parseSkillFrontMatter(content: string | (() => Promise<string>)): Promise<{
19
19
  name: string;
20
20
  description: string;
21
- } | null;
21
+ } | null>;
22
22
  /**
23
23
  * 获取所有「主 SKILL.md」的路径(一级子目录下的 SKILL.md)
24
24
  * - 对传入的 modules 先做 normalize,兼容任意 import.meta.glob 写法
25
25
  */
26
- export declare function getMainSkillPaths(modules: Record<string, string>): string[];
26
+ export declare function getMainSkillPaths(modules: Record<string, string | (() => Promise<string>)>): Promise<string[]>;
27
27
  /**
28
28
  * 获取所有技能的概况列表(name、description、path),用于 systemPrompt 或列表展示
29
29
  * - 内部统一对 modules 做 normalize,避免调用方关心路径细节
30
30
  */
31
- export declare function getSkillOverviews(modules: Record<string, string>): SkillMeta[];
31
+ export declare function getSkillOverviews(modules: Record<string, string | (() => Promise<string>)>): Promise<SkillMeta[]>;
32
32
  /**
33
33
  * 格式化为大模型 systemPrompt 可用的技能说明文本
34
34
  * @param skills 不传则需由调用方传入从 getSkillOverviews 得到的结果
35
35
  */
36
36
  export declare function formatSkillsForSystemPrompt(skills: SkillMeta[]): string;
37
- /**
38
- * 获取所有已加载的技能文件路径(含主 SKILL.md 与 reference 下的 .md/.json/.xml 等)
39
- * - 对 modules 做 normalize 后再返回 key 列表
40
- */
41
- export declare function getSkillMdPaths(modules: Record<string, string>): string[];
42
37
  /**
43
38
  * 根据相对路径获取某个技能文档的原始内容(支持 .md、.json、.xml 等文本格式)
44
39
  * - 自动对 modules 做 normalize,再按 path 查找
45
40
  */
46
- export declare function getSkillMdContent(modules: Record<string, string>, path: string): string | undefined;
41
+ export declare function getSkillMdContent(modules: Record<string, string | (() => Promise<string>)>, path: string): Promise<string | undefined>;
47
42
  /**
48
43
  * 根据技能 name 查找其主 SKILL.md 的路径
49
44
  * 支持匹配目录名(如 ecommerce)或 SKILL.md 内 frontmatter 定义的 name
50
45
  * - 依赖 getMainSkillPaths,内部已做 normalize
51
46
  */
52
- export declare function getMainSkillPathByName(modules: Record<string, string>, name: string): string | undefined;
47
+ export declare function getMainSkillPathByName(modules: Record<string, string | (() => Promise<string>)>, name: string): Promise<string | undefined>;
53
48
  /** AI SDK Tool 类型,用于 extraTools 合并,不写死泛型避免与 ai 包版本强绑定 */
54
49
  export type SkillToolsSet = Record<string, any>;
55
50
  /**
@@ -57,4 +52,4 @@ export type SkillToolsSet = Record<string, any>;
57
52
  * - get_skill_content: 按技能名或路径获取完整文档内容,便于大模型自动识别并加载技能
58
53
  * remoter 可将返回的 tools 合并进 extraTools 注入 agent
59
54
  */
60
- export declare function createSkillTools(modules: Record<string, string>): SkillToolsSet;
55
+ export declare function createSkillTools(modules: Record<string, string | (() => Promise<string>)>): SkillToolsSet;