@opentiny/next-sdk 0.1.14 → 0.1.15-beta.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.
- package/agent/AgentModelProvider.ts +539 -21
- package/agent/type.ts +12 -6
- package/agent/utils/generateReActPrompt.ts +55 -0
- package/agent/utils/parseReActAction.ts +34 -0
- package/dist/McpSdk.d.ts +14 -0
- package/dist/WebAgent.d.ts +5 -0
- package/dist/WebMcp.d.ts +20 -0
- package/dist/WebMcpClient.d.ts +389 -1152
- package/dist/WebMcpServer.d.ts +79 -78
- package/dist/Zod.d.ts +1 -0
- package/dist/agent/AgentModelProvider.d.ts +40 -4
- package/dist/agent/type.d.ts +13 -3
- package/dist/agent/utils/generateReActPrompt.d.ts +9 -0
- package/dist/agent/utils/getAISDKTools.d.ts +1 -0
- package/dist/agent/utils/parseReActAction.d.ts +14 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.es.dev.js +36351 -34349
- package/dist/index.es.js +28821 -25466
- package/dist/index.js +3880 -25
- package/dist/index.umd.dev.js +34228 -32226
- package/dist/index.umd.js +220 -128
- package/dist/mcpsdk@1.24.3.dev.js +22539 -0
- package/dist/mcpsdk@1.24.3.es.dev.js +22537 -0
- package/dist/mcpsdk@1.24.3.es.js +16781 -0
- package/dist/mcpsdk@1.24.3.js +43 -0
- package/dist/remoter/createRemoter.d.ts +9 -0
- package/dist/remoter/tooltips.d.ts +36 -0
- package/dist/script/utils.d.ts +1 -0
- package/dist/transport/ExtensionClientTransport.d.ts +3 -2
- package/dist/transport/ExtensionContentServerTransport.d.ts +3 -2
- package/dist/transport/ExtensionPageServerTransport.d.ts +4 -4
- package/dist/vite-build-tsc.d.ts +2 -0
- package/dist/vite.config.d.ts +2 -0
- package/dist/vite.config.mcpSdk.d.ts +2 -0
- package/dist/vite.config.webAgent.d.ts +2 -0
- package/dist/vite.config.webMcp.d.ts +2 -0
- package/dist/vite.config.webMcpFull.d.ts +2 -0
- package/dist/vite.config.zod.d.ts +2 -0
- package/dist/webagent.dev.js +24690 -20960
- package/dist/webagent.es.dev.js +24032 -20302
- package/dist/webagent.es.js +25326 -20723
- package/dist/webagent.js +209 -110
- package/dist/webmcp-full.dev.js +21225 -20021
- package/dist/webmcp-full.es.dev.js +21223 -20019
- package/dist/webmcp-full.es.js +16710 -14437
- package/dist/webmcp-full.js +42 -15
- package/dist/webmcp.dev.js +14 -22
- package/dist/webmcp.es.dev.js +12 -20
- package/dist/webmcp.es.js +172 -179
- package/dist/webmcp.js +1 -1
- package/dist/zod@3.25.76.dev.js +30 -32
- package/dist/zod@3.25.76.es.dev.js +28 -30
- package/dist/zod@3.25.76.es.js +143 -145
- package/dist/zod@3.25.76.js +1 -1
- package/package.json +11 -9
- package/remoter/createRemoter.ts +126 -71
- package/remoter/tooltips.ts +260 -0
- package/transport/ExtensionPageServerTransport.ts +2 -4
- package/tsconfig.json +5 -3
- package/vite-build-tsc.ts +60 -0
- package/vite-env.d.ts +5 -0
- package/dist/WebMcpClient.js +0 -363
- package/dist/WebMcpServer.js +0 -283
- package/dist/agent/AgentModelProvider.js +0 -293
- package/dist/agent/type.js +0 -1
- package/dist/agent/utils/getAISDKTools.js +0 -36
- package/dist/mcpsdk@1.17.0.dev.js +0 -21391
- package/dist/mcpsdk@1.17.0.es.dev.js +0 -21389
- package/dist/mcpsdk@1.17.0.es.js +0 -14505
- package/dist/mcpsdk@1.17.0.js +0 -16
- package/dist/remoter/QrCode.js +0 -55
- package/dist/remoter/createRemoter.js +0 -743
- package/dist/transport/ExtensionClientTransport.js +0 -81
- package/dist/transport/ExtensionContentServerTransport.js +0 -128
- package/dist/transport/ExtensionPageServerTransport.js +0 -118
- package/dist/transport/messages.js +0 -51
- package/dist/utils/uuid.js +0 -10
package/dist/WebMcpServer.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { MessageChannelServerTransport } from '@opentiny/next';
|
|
2
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
-
import { z, ZodObject, ZodLiteral, ZodType, ZodOptional } from 'zod';
|
|
4
|
-
import { SetLevelRequestSchema, SubscribeRequestSchema, UnsubscribeRequestSchema, ListResourcesRequestSchema, RootsListChangedNotificationSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
import type { ServerOptions } from '@modelcontextprotocol/sdk/server/index.js';
|
|
10
|
-
import type { RequestOptions, NotificationOptions, RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
2
|
+
import { McpServer, ToolCallback, RegisteredTool, PromptCallback, RegisteredPrompt, ResourceMetadata, ResourceTemplate, RegisteredResource, ReadResourceCallback, RegisteredResourceTemplate, ReadResourceTemplateCallback } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
import { z, ZodObject, ZodLiteral, ZodType, ZodOptional, ZodRawShape, ZodTypeDef } from 'zod';
|
|
4
|
+
import { SetLevelRequestSchema, SubscribeRequestSchema, UnsubscribeRequestSchema, ListResourcesRequestSchema, RootsListChangedNotificationSchema, Result, Request, Notification, Implementation, ToolAnnotations, ClientCapabilities, ElicitResult, ElicitRequest, ListRootsRequest, CreateMessageRequest, LoggingMessageNotification, ResourceUpdatedNotification } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
+
import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
6
|
+
import { ServerOptions } from '@modelcontextprotocol/sdk/server/index.js';
|
|
7
|
+
import { RequestOptions, NotificationOptions, RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
8
|
+
|
|
11
9
|
type PromptArgsRawShape = {
|
|
12
10
|
[k: string]: ZodType<string, ZodTypeDef, string> | ZodOptional<ZodType<string, ZodTypeDef, string>>;
|
|
13
11
|
};
|
|
@@ -100,61 +98,66 @@ export declare class WebMcpServer {
|
|
|
100
98
|
* Sends a ping to the client to check if it is still connected.
|
|
101
99
|
*/
|
|
102
100
|
ping(): Promise<{
|
|
103
|
-
_meta?:
|
|
101
|
+
_meta?: {
|
|
102
|
+
[x: string]: unknown;
|
|
103
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
104
|
+
[x: string]: unknown;
|
|
105
|
+
taskId: string;
|
|
106
|
+
} | undefined;
|
|
107
|
+
} | undefined;
|
|
104
108
|
}>;
|
|
105
109
|
/**
|
|
106
110
|
* Creates a LLM message to be sent to the client.
|
|
107
111
|
*/
|
|
108
|
-
createMessage(params: CreateMessageRequest['params'], options?: RequestOptions): Promise<
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}, z.ZodTypeAny, "passthrough">>;
|
|
112
|
+
createMessage(params: CreateMessageRequest['params'], options?: RequestOptions): Promise<{
|
|
113
|
+
[x: string]: unknown;
|
|
114
|
+
model: string;
|
|
115
|
+
role: "user" | "assistant";
|
|
116
|
+
content: {
|
|
117
|
+
type: "text";
|
|
118
|
+
text: string;
|
|
119
|
+
annotations?: {
|
|
120
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
121
|
+
priority?: number | undefined;
|
|
122
|
+
lastModified?: string | undefined;
|
|
123
|
+
} | undefined;
|
|
124
|
+
_meta?: {
|
|
125
|
+
[x: string]: unknown;
|
|
126
|
+
} | undefined;
|
|
127
|
+
} | {
|
|
128
|
+
type: "image";
|
|
129
|
+
data: string;
|
|
130
|
+
mimeType: string;
|
|
131
|
+
annotations?: {
|
|
132
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
133
|
+
priority?: number | undefined;
|
|
134
|
+
lastModified?: string | undefined;
|
|
135
|
+
} | undefined;
|
|
136
|
+
_meta?: {
|
|
137
|
+
[x: string]: unknown;
|
|
138
|
+
} | undefined;
|
|
139
|
+
} | {
|
|
140
|
+
type: "audio";
|
|
141
|
+
data: string;
|
|
142
|
+
mimeType: string;
|
|
143
|
+
annotations?: {
|
|
144
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
145
|
+
priority?: number | undefined;
|
|
146
|
+
lastModified?: string | undefined;
|
|
147
|
+
} | undefined;
|
|
148
|
+
_meta?: {
|
|
149
|
+
[x: string]: unknown;
|
|
150
|
+
} | undefined;
|
|
151
|
+
};
|
|
152
|
+
_meta?: {
|
|
153
|
+
[x: string]: unknown;
|
|
154
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
155
|
+
[x: string]: unknown;
|
|
156
|
+
taskId: string;
|
|
157
|
+
} | undefined;
|
|
158
|
+
} | undefined;
|
|
159
|
+
stopReason?: string | undefined;
|
|
160
|
+
}>;
|
|
158
161
|
/**
|
|
159
162
|
* Elicits input from the client, such as a prompt or resource.
|
|
160
163
|
*/
|
|
@@ -162,23 +165,21 @@ export declare class WebMcpServer {
|
|
|
162
165
|
/**
|
|
163
166
|
* Lists the root resources available to the client.
|
|
164
167
|
*/
|
|
165
|
-
listRoots(params?: ListRootsRequest['params'], options?: RequestOptions): Promise<
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}, import("zod").ZodTypeAny, "passthrough">>, "many">;
|
|
181
|
-
}, z.ZodTypeAny, "passthrough">>;
|
|
168
|
+
listRoots(params?: ListRootsRequest['params'], options?: RequestOptions): Promise<{
|
|
169
|
+
[x: string]: unknown;
|
|
170
|
+
roots: {
|
|
171
|
+
uri: string;
|
|
172
|
+
name?: string | undefined;
|
|
173
|
+
_meta?: Record<string, unknown> | undefined;
|
|
174
|
+
}[];
|
|
175
|
+
_meta?: {
|
|
176
|
+
[x: string]: unknown;
|
|
177
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
178
|
+
[x: string]: unknown;
|
|
179
|
+
taskId: string;
|
|
180
|
+
} | undefined;
|
|
181
|
+
} | undefined;
|
|
182
|
+
}>;
|
|
182
183
|
/**
|
|
183
184
|
* Sends a logging message to the client.
|
|
184
185
|
*/
|
|
@@ -253,7 +254,7 @@ export declare const createMessageChannelServerTransport: (endpoint: string, glo
|
|
|
253
254
|
/**
|
|
254
255
|
* Creates a pair of transports for communication between a server and client using MessageChannel.
|
|
255
256
|
*/
|
|
256
|
-
export declare const createMessageChannelPairTransport: () => [import(
|
|
257
|
+
export declare const createMessageChannelPairTransport: () => [import('@opentiny/next').MessageChannelTransport, import('@opentiny/next').MessageChannelTransport];
|
|
257
258
|
/**
|
|
258
259
|
* Checks if the transport is a MessageChannelServerTransport.
|
|
259
260
|
*/
|
package/dist/Zod.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { z } from 'zod';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { streamText, generateText } from 'ai';
|
|
2
|
-
import
|
|
2
|
+
import { IAgentModelProviderOption, McpServerConfig } from './type';
|
|
3
3
|
import { ProviderV2 } from '@ai-sdk/provider';
|
|
4
|
-
import { OpenAIProvider } from '@ai-sdk/openai';
|
|
5
|
-
import { createOpenAI } from '@ai-sdk/openai';
|
|
4
|
+
import { OpenAIProvider, createOpenAI } from '@ai-sdk/openai';
|
|
6
5
|
import { createDeepSeek } from '@ai-sdk/deepseek';
|
|
7
6
|
import { WebMcpClient } from '../WebMcpClient';
|
|
7
|
+
|
|
8
8
|
export declare const AIProviderFactories: {
|
|
9
9
|
openai: typeof createOpenAI;
|
|
10
10
|
deepseek: typeof createDeepSeek;
|
|
@@ -32,6 +32,8 @@ export declare class AgentModelProvider {
|
|
|
32
32
|
onClientDisconnected?: (serverName: string, reason?: string) => void;
|
|
33
33
|
/** 缓存 ai-sdk response 中的 多轮会话的上下文 */
|
|
34
34
|
messages: any[];
|
|
35
|
+
/** 是否使用 ReAct 模式(通过提示词而非 function calling 进行工具调用) */
|
|
36
|
+
useReActMode: boolean;
|
|
35
37
|
constructor({ llmConfig, mcpServers }: IAgentModelProviderOption);
|
|
36
38
|
/** 创建一个 ai-sdk的 mcpClient, 创建失败则返回 null */
|
|
37
39
|
private _createOneClient;
|
|
@@ -39,6 +41,8 @@ export declare class AgentModelProvider {
|
|
|
39
41
|
private _closeOneClient;
|
|
40
42
|
/** 创建所有 mcpClients */
|
|
41
43
|
private _createMpcClients;
|
|
44
|
+
/** 兼容两种 client 类型的 tools 获取方法 */
|
|
45
|
+
private _getClientTools;
|
|
42
46
|
/** 查询所有 mcpClients 的 tools, 失败则保存为null */
|
|
43
47
|
private _createMpcTools;
|
|
44
48
|
/** 关闭所有的 clients */
|
|
@@ -48,11 +52,43 @@ export declare class AgentModelProvider {
|
|
|
48
52
|
/** 全量更新所有的 mcpServers */
|
|
49
53
|
updateMcpServers(mcpServers?: Record<string, McpServerConfig>): Promise<void>;
|
|
50
54
|
/** 插入一个新的mcpServer,如果已经存在则返回false */
|
|
51
|
-
insertMcpServer(serverName: string, mcpServer: McpServerConfig): Promise<false | WebMcpClient | null>;
|
|
55
|
+
insertMcpServer(serverName: string, mcpServer: McpServerConfig): Promise<false | WebMcpClient | import('@ai-sdk/mcp').experimental_MCPClient | null>;
|
|
52
56
|
/** 通过服务器名称删除mcpServer: mcpServers mcpClients mcpTools ignoreToolnames */
|
|
53
57
|
removeMcpServer(serverName: string): Promise<void>;
|
|
54
58
|
/** 创建临时允许调用的tools集合 */
|
|
55
59
|
private _tempMergeTools;
|
|
60
|
+
/** 生成 ReAct 模式的系统提示词(包含工具描述) */
|
|
61
|
+
private _generateReActSystemPrompt;
|
|
62
|
+
/** 执行 ReAct 模式下的工具调用 */
|
|
63
|
+
private _executeReActToolCall;
|
|
64
|
+
/** ReAct 模式的对话实现 */
|
|
65
|
+
private _chatReAct;
|
|
66
|
+
/**
|
|
67
|
+
* 检查消息内容是否包含图片
|
|
68
|
+
* @param content 消息内容
|
|
69
|
+
* @returns 是否包含图片
|
|
70
|
+
*/
|
|
71
|
+
private _messageHasImage;
|
|
72
|
+
/**
|
|
73
|
+
* 从消息中移除图片,但保留文本内容
|
|
74
|
+
* @param message 原始消息
|
|
75
|
+
* @returns 移除图片后的消息(如果只有图片没有文本,返回 null)
|
|
76
|
+
*/
|
|
77
|
+
private _removeImageFromMessage;
|
|
78
|
+
/**
|
|
79
|
+
* 构建用于模型调用的消息列表(magentic-ui 风格)
|
|
80
|
+
* 策略:保留所有文本消息,仅限制图片数量(类似 magentic-ui 的 maybe_remove_old_screenshots)
|
|
81
|
+
*
|
|
82
|
+
* @param systemMessage 系统提示词
|
|
83
|
+
* @param allMessages 所有消息历史(包括初始消息和后续对话)
|
|
84
|
+
* @param maxImages 最多保留的图片数量(默认3张)
|
|
85
|
+
* @returns 构建好的消息列表
|
|
86
|
+
*/
|
|
87
|
+
private _buildMessagesForModel;
|
|
88
|
+
/** ReAct 模式非流式对话 */
|
|
89
|
+
private _chatReActNonStream;
|
|
90
|
+
/** ReAct 模式流式对话 */
|
|
91
|
+
private _chatReActStream;
|
|
56
92
|
private _chat;
|
|
57
93
|
chat(options: Parameters<typeof generateText>[0] & {
|
|
58
94
|
maxSteps?: number;
|
package/dist/agent/type.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { ProviderV2 } from '@ai-sdk/provider';
|
|
2
|
+
import { experimental_MCPClientConfig as MCPClientConfig } from '@ai-sdk/mcp';
|
|
3
|
+
|
|
4
|
+
export type MCPTransport = MCPClientConfig['transport'];
|
|
4
5
|
type ProviderFactory = 'openai' | 'deepseek' | ((options: any) => ProviderV2);
|
|
5
6
|
type LlmFactoryConfig = {
|
|
6
7
|
/** API密钥 */
|
|
@@ -11,6 +12,8 @@ type LlmFactoryConfig = {
|
|
|
11
12
|
providerType: ProviderFactory;
|
|
12
13
|
/** 互斥:当使用 providerType 分支时不允许传入 llm */
|
|
13
14
|
llm?: never;
|
|
15
|
+
/** 是否使用 ReAct 模式(通过提示词而非 function calling 进行工具调用),默认为 false */
|
|
16
|
+
useReActMode?: boolean;
|
|
14
17
|
};
|
|
15
18
|
type LlmInstanceConfig = {
|
|
16
19
|
/** 自定义 Provider 实例,优先级最高 */
|
|
@@ -19,6 +22,8 @@ type LlmInstanceConfig = {
|
|
|
19
22
|
apiKey?: never;
|
|
20
23
|
baseURL?: never;
|
|
21
24
|
providerType?: never;
|
|
25
|
+
/** 是否使用 ReAct 模式(通过提示词而非 function calling 进行工具调用),默认为 false */
|
|
26
|
+
useReActMode?: boolean;
|
|
22
27
|
};
|
|
23
28
|
/** 代理模型提供器的大语言配置对象, 通过 XOR 表达二选一 */
|
|
24
29
|
export type IAgentModelProviderLlmConfig = LlmFactoryConfig | LlmInstanceConfig;
|
|
@@ -26,15 +31,19 @@ export type IAgentModelProviderLlmConfig = LlmFactoryConfig | LlmInstanceConfig;
|
|
|
26
31
|
export type McpServerConfig = {
|
|
27
32
|
type: 'streamableHttp';
|
|
28
33
|
url: string;
|
|
34
|
+
useAISdkClient?: boolean;
|
|
29
35
|
} | {
|
|
30
36
|
type: 'sse';
|
|
31
37
|
url: string;
|
|
38
|
+
useAISdkClient?: boolean;
|
|
32
39
|
} | {
|
|
33
40
|
type: 'extension';
|
|
34
41
|
url: string;
|
|
35
42
|
sessionId: string;
|
|
43
|
+
useAISdkClient?: boolean;
|
|
36
44
|
} | {
|
|
37
45
|
transport: MCPTransport;
|
|
46
|
+
useAISdkClient?: boolean;
|
|
38
47
|
};
|
|
39
48
|
/** */
|
|
40
49
|
export interface IAgentModelProviderOption {
|
|
@@ -43,3 +52,4 @@ export interface IAgentModelProviderOption {
|
|
|
43
52
|
/** Mcp Server的配置对象的集合,键为服务器名称,值为配置对象 */
|
|
44
53
|
mcpServers?: Record<string, McpServerConfig>;
|
|
45
54
|
}
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ToolSet } from 'ai';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 解析 ReAct 格式的工具调用
|
|
5
|
+
* 从模型输出文本中提取工具名称和参数
|
|
6
|
+
* 现在统一使用 XML 格式(<call> 标签),同时保留对其他格式的兼容性支持
|
|
7
|
+
* @param text - 模型输出的文本
|
|
8
|
+
* @param availableTools - 可用的工具集合,用于验证工具名称
|
|
9
|
+
* @returns 解析出的工具调用信息,如果未找到则返回 null
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseReActAction(text: string, availableTools: ToolSet): {
|
|
12
|
+
toolName: string;
|
|
13
|
+
arguments: any;
|
|
14
|
+
} | null;
|
package/dist/index.d.ts
CHANGED