@opentiny/next-sdk 0.2.6 → 0.2.8
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/agent/AgentModelProvider.ts +22 -10
- package/agent/utils/generateReActPrompt.ts +36 -20
- package/dist/agent/AgentModelProvider.d.ts +3 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.es.dev.js +1138 -116
- package/dist/index.es.js +15866 -15040
- package/dist/index.js +2574 -2150
- package/dist/index.umd.dev.js +1138 -116
- package/dist/index.umd.js +254 -84
- package/dist/page-tools/bridge.d.ts +101 -0
- package/dist/page-tools/effects.d.ts +36 -0
- package/dist/remoter/createRemoter.d.ts +7 -5
- package/dist/skills/index.d.ts +7 -1
- package/dist/webagent.dev.js +586 -99
- package/dist/webagent.es.dev.js +586 -99
- package/dist/webagent.es.js +10799 -10378
- package/dist/webagent.js +76 -74
- package/index.ts +3 -0
- package/package.json +1 -1
- package/page-tools/bridge.ts +382 -0
- package/page-tools/effects.ts +343 -0
- package/remoter/createRemoter.ts +37 -16
- package/skills/index.ts +146 -19
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { ZodRawShape } from 'zod';
|
|
2
|
+
import { RegisteredTool } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
import { ToolAnnotations } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
+
import { WebMcpServer } from '../WebMcpServer';
|
|
5
|
+
import { ToolInvokeEffectConfig } from './effects';
|
|
6
|
+
|
|
7
|
+
/** 页面卸载广播,供 pageToolsOnDemand 模式监听 */
|
|
8
|
+
export declare const MSG_PAGE_LEAVE = "next-sdk:page-leave";
|
|
9
|
+
/** iframe 内 Remoter 就绪后向父窗口发送,父窗口回传 route-state-initial */
|
|
10
|
+
export declare const MSG_REMOTER_READY = "next-sdk:remoter-ready";
|
|
11
|
+
/** 父窗口向 iframe Remoter 回传的初始路由状态(toolRouteMap + activeRoutes) */
|
|
12
|
+
export declare const MSG_ROUTE_STATE_INITIAL = "next-sdk:route-state-initial";
|
|
13
|
+
/**
|
|
14
|
+
* 获取通过 withPageTools + RouteConfig 注册的全部工具路由映射。
|
|
15
|
+
* 返回的是内部 Map 的只读快照,可安全遍历。
|
|
16
|
+
* @returns toolName → route 的只读 Map
|
|
17
|
+
*/
|
|
18
|
+
export declare function getToolRouteMap(): ReadonlyMap<string, string>;
|
|
19
|
+
/**
|
|
20
|
+
* 获取当前已激活(已挂载)的路由集合。
|
|
21
|
+
* 即调用了 registerPageTool 且尚未执行 cleanup 的页面路由。
|
|
22
|
+
* @returns 当前激活路由的 Set 快照
|
|
23
|
+
*/
|
|
24
|
+
export declare function getActiveRoutes(): Set<string>;
|
|
25
|
+
/**
|
|
26
|
+
* 注册应用的导航函数,通常在应用入口(如 main.ts)调用一次。
|
|
27
|
+
* @param fn 导航函数,接收路由路径并执行跳转(如 router.push)
|
|
28
|
+
*/
|
|
29
|
+
export declare function setNavigator(fn: (route: string) => void | Promise<void>): void;
|
|
30
|
+
/**
|
|
31
|
+
* registerTool 第三个参数的路由配置对象类型。
|
|
32
|
+
* 当传入此类型时,工具调用会自动跳转到 route 对应的页面并通过消息通信执行。
|
|
33
|
+
*/
|
|
34
|
+
export type RouteConfig = {
|
|
35
|
+
/** 目标路由路径,如 '/comprehensive' */
|
|
36
|
+
route: string;
|
|
37
|
+
/** 等待页面响应的超时时间(ms),默认 30000 */
|
|
38
|
+
timeout?: number;
|
|
39
|
+
/**
|
|
40
|
+
* 是否在调用该工具时启用页面级调用提示效果。
|
|
41
|
+
*
|
|
42
|
+
* - false / 未配置:不启用任何额外效果(保持现有行为)
|
|
43
|
+
* - true:使用默认提示文案(优先取工具标题,其次为工具名)
|
|
44
|
+
* - 对象:可自定义提示文案
|
|
45
|
+
*/
|
|
46
|
+
invokeEffect?: boolean | ToolInvokeEffectConfig;
|
|
47
|
+
};
|
|
48
|
+
export type { ToolInvokeEffectConfig };
|
|
49
|
+
/**
|
|
50
|
+
* PageAwareServer 的 registerTool 配置对象类型,与 WebMcpServer.registerTool 保持一致。
|
|
51
|
+
*/
|
|
52
|
+
type RegisterToolConfig<InputArgs extends ZodRawShape, OutputArgs extends ZodRawShape> = {
|
|
53
|
+
title?: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
inputSchema?: InputArgs;
|
|
56
|
+
outputSchema?: OutputArgs;
|
|
57
|
+
annotations?: ToolAnnotations;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* 包装 WebMcpServer 后的类型:registerTool 第三个参数额外支持 RouteConfig。
|
|
61
|
+
* 泛型签名与 WebMcpServer.registerTool 对齐,保持完整的类型推导能力。
|
|
62
|
+
* 原有的回调函数写法完全兼容,无需改动。
|
|
63
|
+
*/
|
|
64
|
+
export type PageAwareServer = Omit<WebMcpServer, 'registerTool'> & {
|
|
65
|
+
registerTool<InputArgs extends ZodRawShape, OutputArgs extends ZodRawShape>(name: string, config: RegisterToolConfig<InputArgs, OutputArgs>, handlerOrRoute: ((...args: any[]) => any) | RouteConfig): RegisteredTool;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* 包装 WebMcpServer,使 registerTool 第三个参数支持 RouteConfig。
|
|
69
|
+
*
|
|
70
|
+
* - 第三个参数为**回调函数**:与原始 registerTool 完全一致,直接透传
|
|
71
|
+
* - 第三个参数为 **RouteConfig 对象**:自动生成转发 handler,工具调用时
|
|
72
|
+
* 先导航到目标路由,再通过 postMessage 与页面通信
|
|
73
|
+
*/
|
|
74
|
+
export declare function withPageTools(server: WebMcpServer): PageAwareServer;
|
|
75
|
+
/**
|
|
76
|
+
* 在目标页面激活工具处理器(框架无关的纯 JS 函数)。
|
|
77
|
+
*
|
|
78
|
+
* 调用后立即:
|
|
79
|
+
* - 将路由注册到 activePages(标记页面已激活)
|
|
80
|
+
* - 添加 message 监听,处理来自 buildPageHandler 的工具调用
|
|
81
|
+
* - 广播 page-ready 信号,通知正在等待导航完成的工具
|
|
82
|
+
*
|
|
83
|
+
* 返回 cleanup 函数,页面销毁时调用。
|
|
84
|
+
*/
|
|
85
|
+
export declare function registerPageTool(options: {
|
|
86
|
+
/**
|
|
87
|
+
* 目标路由路径,与 RouteConfig.route 保持一致。
|
|
88
|
+
* 省略时自动读取 window.location.pathname。
|
|
89
|
+
* 当页面路由与 pathname 不一致时(如 hash 路由、子路径前缀等),需手动传入。
|
|
90
|
+
*/
|
|
91
|
+
route?: string;
|
|
92
|
+
/**
|
|
93
|
+
* 工具名 → 处理函数的映射表。
|
|
94
|
+
*
|
|
95
|
+
* 此处 handler 的 input 参数类型保留 any:
|
|
96
|
+
* 若改为 unknown,TypeScript 函数参数逆变规则会导致用户的具名解构写法
|
|
97
|
+
*(如 `async ({ productId }: { productId: string }) => ...`)无法通过类型检查,
|
|
98
|
+
* 破坏现有调用方代码的开发体验。运行时输入由 MCP inputSchema 保证类型安全。
|
|
99
|
+
*/
|
|
100
|
+
handlers: Record<string, (input: any) => Promise<any>>;
|
|
101
|
+
}): () => void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* page-tools/effects - 页面工具调用提示效果模块(框架无关)
|
|
3
|
+
*
|
|
4
|
+
* 作用:
|
|
5
|
+
* - 在调用通过 withPageTools 注册的页面工具时,显示页面级的调用状态提示
|
|
6
|
+
* - 以左下角小 tip 形式展示“当前正在调用的工具”文案,尽量不打扰用户操作
|
|
7
|
+
* - 纯 DOM + CSS 实现,不依赖 Vue/React 等框架
|
|
8
|
+
*/
|
|
9
|
+
export type ToolInvokeEffectConfig = {
|
|
10
|
+
/**
|
|
11
|
+
* 自定义提示文案,默认使用“工具标题 || 工具名称”
|
|
12
|
+
* 例如:"正在为你整理订单数据"
|
|
13
|
+
*/
|
|
14
|
+
label?: string;
|
|
15
|
+
};
|
|
16
|
+
type RuntimeEffectConfig = {
|
|
17
|
+
label: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* 在页面上显示工具调用提示效果。
|
|
21
|
+
* - 若当前已有其他工具在执行,仅更新文案,不重复创建 DOM
|
|
22
|
+
* - 会增加 activeCount 计数,需配对调用 hideToolInvokeEffect
|
|
23
|
+
*/
|
|
24
|
+
export declare function showToolInvokeEffect(config: RuntimeEffectConfig): void;
|
|
25
|
+
/**
|
|
26
|
+
* 隐藏工具调用提示效果。
|
|
27
|
+
* - 使用引用计数:只有当所有调用结束后才真正移除 Overlay
|
|
28
|
+
*/
|
|
29
|
+
export declare function hideToolInvokeEffect(): void;
|
|
30
|
+
/**
|
|
31
|
+
* 将 RouteConfig 中的 invokeEffect 配置编译成运行时效果配置。
|
|
32
|
+
* - boolean / undefined:关闭或开启默认文案
|
|
33
|
+
* - 对象:允许自定义 label
|
|
34
|
+
*/
|
|
35
|
+
export declare function resolveRuntimeEffectConfig(toolName: string, toolTitle: string | undefined, value: boolean | ToolInvokeEffectConfig | undefined): RuntimeEffectConfig | undefined;
|
|
36
|
+
export {};
|
|
@@ -25,8 +25,8 @@ export interface FloatingBlockOptions {
|
|
|
25
25
|
onShowAIChat?: () => void;
|
|
26
26
|
/** 遥控端页面地址,默认为: https://ai.opentiny.design/next-remoter */
|
|
27
27
|
qrCodeUrl?: string;
|
|
28
|
-
/** 被遥控页面的 sessionId
|
|
29
|
-
sessionId
|
|
28
|
+
/** 被遥控页面的 sessionId;无 sessionId 时仅显示「打开对话框」菜单,不显示二维码、识别码、遥控器链接 */
|
|
29
|
+
sessionId?: string;
|
|
30
30
|
/** 菜单项配置 */
|
|
31
31
|
menuItems?: MenuItemConfig[];
|
|
32
32
|
/** 遥控端页面地址,默认为: https://chat.opentiny.design */
|
|
@@ -48,9 +48,9 @@ declare class FloatingBlock {
|
|
|
48
48
|
private getImageUrl;
|
|
49
49
|
private renderItem;
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
51
|
+
* 合并菜单项配置。
|
|
52
|
+
* - 有 sessionId:使用默认菜单 + 用户配置(可定制每一项的 show/text/icon 等)
|
|
53
|
+
* - 无 sessionId:不渲染任何下拉菜单,仅保留点击浮标打开对话框的能力
|
|
54
54
|
*/
|
|
55
55
|
private mergeMenuItems;
|
|
56
56
|
private init;
|
|
@@ -74,6 +74,8 @@ declare class FloatingBlock {
|
|
|
74
74
|
private hideModal;
|
|
75
75
|
private addStyles;
|
|
76
76
|
destroy(): void;
|
|
77
|
+
hide(): void;
|
|
78
|
+
show(): void;
|
|
77
79
|
}
|
|
78
80
|
export declare const createRemoter: (options?: FloatingBlockOptions) => FloatingBlock;
|
|
79
81
|
export {};
|
package/dist/skills/index.d.ts
CHANGED
|
@@ -21,10 +21,12 @@ export declare function parseSkillFrontMatter(content: string): {
|
|
|
21
21
|
} | null;
|
|
22
22
|
/**
|
|
23
23
|
* 获取所有「主 SKILL.md」的路径(一级子目录下的 SKILL.md)
|
|
24
|
+
* - 对传入的 modules 先做 normalize,兼容任意 import.meta.glob 写法
|
|
24
25
|
*/
|
|
25
26
|
export declare function getMainSkillPaths(modules: Record<string, string>): string[];
|
|
26
27
|
/**
|
|
27
28
|
* 获取所有技能的概况列表(name、description、path),用于 systemPrompt 或列表展示
|
|
29
|
+
* - 内部统一对 modules 做 normalize,避免调用方关心路径细节
|
|
28
30
|
*/
|
|
29
31
|
export declare function getSkillOverviews(modules: Record<string, string>): SkillMeta[];
|
|
30
32
|
/**
|
|
@@ -34,14 +36,18 @@ export declare function getSkillOverviews(modules: Record<string, string>): Skil
|
|
|
34
36
|
export declare function formatSkillsForSystemPrompt(skills: SkillMeta[]): string;
|
|
35
37
|
/**
|
|
36
38
|
* 获取所有已加载的技能文件路径(含主 SKILL.md 与 reference 下的 .md/.json/.xml 等)
|
|
39
|
+
* - 对 modules 做 normalize 后再返回 key 列表
|
|
37
40
|
*/
|
|
38
41
|
export declare function getSkillMdPaths(modules: Record<string, string>): string[];
|
|
39
42
|
/**
|
|
40
43
|
* 根据相对路径获取某个技能文档的原始内容(支持 .md、.json、.xml 等文本格式)
|
|
44
|
+
* - 自动对 modules 做 normalize,再按 path 查找
|
|
41
45
|
*/
|
|
42
46
|
export declare function getSkillMdContent(modules: Record<string, string>, path: string): string | undefined;
|
|
43
47
|
/**
|
|
44
|
-
* 根据技能 name 查找其主 SKILL.md
|
|
48
|
+
* 根据技能 name 查找其主 SKILL.md 的路径
|
|
49
|
+
* 支持匹配目录名(如 ecommerce)或 SKILL.md 内 frontmatter 定义的 name
|
|
50
|
+
* - 依赖 getMainSkillPaths,内部已做 normalize
|
|
45
51
|
*/
|
|
46
52
|
export declare function getMainSkillPathByName(modules: Record<string, string>, name: string): string | undefined;
|
|
47
53
|
/** AI SDK Tool 类型,用于 extraTools 合并,不写死泛型避免与 ai 包版本强绑定 */
|