@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.
Files changed (77) hide show
  1. package/agent/AgentModelProvider.ts +539 -21
  2. package/agent/type.ts +12 -6
  3. package/agent/utils/generateReActPrompt.ts +55 -0
  4. package/agent/utils/parseReActAction.ts +34 -0
  5. package/dist/McpSdk.d.ts +14 -0
  6. package/dist/WebAgent.d.ts +5 -0
  7. package/dist/WebMcp.d.ts +20 -0
  8. package/dist/WebMcpClient.d.ts +389 -1152
  9. package/dist/WebMcpServer.d.ts +79 -78
  10. package/dist/Zod.d.ts +1 -0
  11. package/dist/agent/AgentModelProvider.d.ts +40 -4
  12. package/dist/agent/type.d.ts +13 -3
  13. package/dist/agent/utils/generateReActPrompt.d.ts +9 -0
  14. package/dist/agent/utils/getAISDKTools.d.ts +1 -0
  15. package/dist/agent/utils/parseReActAction.d.ts +14 -0
  16. package/dist/index.d.ts +2 -1
  17. package/dist/index.es.dev.js +36351 -34349
  18. package/dist/index.es.js +28821 -25466
  19. package/dist/index.js +3880 -25
  20. package/dist/index.umd.dev.js +34228 -32226
  21. package/dist/index.umd.js +220 -128
  22. package/dist/mcpsdk@1.24.3.dev.js +22539 -0
  23. package/dist/mcpsdk@1.24.3.es.dev.js +22537 -0
  24. package/dist/mcpsdk@1.24.3.es.js +16781 -0
  25. package/dist/mcpsdk@1.24.3.js +43 -0
  26. package/dist/remoter/createRemoter.d.ts +9 -0
  27. package/dist/remoter/tooltips.d.ts +36 -0
  28. package/dist/script/utils.d.ts +1 -0
  29. package/dist/transport/ExtensionClientTransport.d.ts +3 -2
  30. package/dist/transport/ExtensionContentServerTransport.d.ts +3 -2
  31. package/dist/transport/ExtensionPageServerTransport.d.ts +4 -4
  32. package/dist/vite-build-tsc.d.ts +2 -0
  33. package/dist/vite.config.d.ts +2 -0
  34. package/dist/vite.config.mcpSdk.d.ts +2 -0
  35. package/dist/vite.config.webAgent.d.ts +2 -0
  36. package/dist/vite.config.webMcp.d.ts +2 -0
  37. package/dist/vite.config.webMcpFull.d.ts +2 -0
  38. package/dist/vite.config.zod.d.ts +2 -0
  39. package/dist/webagent.dev.js +24690 -20960
  40. package/dist/webagent.es.dev.js +24032 -20302
  41. package/dist/webagent.es.js +25326 -20723
  42. package/dist/webagent.js +209 -110
  43. package/dist/webmcp-full.dev.js +21225 -20021
  44. package/dist/webmcp-full.es.dev.js +21223 -20019
  45. package/dist/webmcp-full.es.js +16710 -14437
  46. package/dist/webmcp-full.js +42 -15
  47. package/dist/webmcp.dev.js +14 -22
  48. package/dist/webmcp.es.dev.js +12 -20
  49. package/dist/webmcp.es.js +172 -179
  50. package/dist/webmcp.js +1 -1
  51. package/dist/zod@3.25.76.dev.js +30 -32
  52. package/dist/zod@3.25.76.es.dev.js +28 -30
  53. package/dist/zod@3.25.76.es.js +143 -145
  54. package/dist/zod@3.25.76.js +1 -1
  55. package/package.json +11 -9
  56. package/remoter/createRemoter.ts +126 -71
  57. package/remoter/tooltips.ts +260 -0
  58. package/transport/ExtensionPageServerTransport.ts +2 -4
  59. package/tsconfig.json +5 -3
  60. package/vite-build-tsc.ts +60 -0
  61. package/vite-env.d.ts +5 -0
  62. package/dist/WebMcpClient.js +0 -363
  63. package/dist/WebMcpServer.js +0 -283
  64. package/dist/agent/AgentModelProvider.js +0 -293
  65. package/dist/agent/type.js +0 -1
  66. package/dist/agent/utils/getAISDKTools.js +0 -36
  67. package/dist/mcpsdk@1.17.0.dev.js +0 -21391
  68. package/dist/mcpsdk@1.17.0.es.dev.js +0 -21389
  69. package/dist/mcpsdk@1.17.0.es.js +0 -14505
  70. package/dist/mcpsdk@1.17.0.js +0 -16
  71. package/dist/remoter/QrCode.js +0 -55
  72. package/dist/remoter/createRemoter.js +0 -743
  73. package/dist/transport/ExtensionClientTransport.js +0 -81
  74. package/dist/transport/ExtensionContentServerTransport.js +0 -128
  75. package/dist/transport/ExtensionPageServerTransport.js +0 -118
  76. package/dist/transport/messages.js +0 -51
  77. package/dist/utils/uuid.js +0 -10
@@ -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 type { ToolCallback, RegisteredTool, PromptCallback, RegisteredPrompt, ResourceMetadata, ResourceTemplate, RegisteredResource, ReadResourceCallback, RegisteredResourceTemplate, ReadResourceTemplateCallback } from '@modelcontextprotocol/sdk/server/mcp.js';
6
- import type { Result, Request, Notification, Implementation, ToolAnnotations, ClientCapabilities, ElicitResult, ElicitRequest, ListRootsRequest, CreateMessageRequest, LoggingMessageNotification, ResourceUpdatedNotification } from '@modelcontextprotocol/sdk/types.js';
7
- import type { ZodRawShape, ZodTypeDef } from 'zod';
8
- import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
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?: import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough"> | undefined;
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<z.objectOutputType<{
109
- _meta: import("zod").ZodOptional<import("zod").ZodObject<{}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
110
- } & {
111
- model: import("zod").ZodString;
112
- stopReason: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodEnum<["endTurn", "stopSequence", "maxTokens"]>, import("zod").ZodString]>>;
113
- role: import("zod").ZodEnum<["user", "assistant"]>;
114
- content: import("zod").ZodDiscriminatedUnion<"type", [import("zod").ZodObject<{
115
- type: import("zod").ZodLiteral<"text">;
116
- text: import("zod").ZodString;
117
- _meta: import("zod").ZodOptional<import("zod").ZodObject<{}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
118
- }, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
119
- type: import("zod").ZodLiteral<"text">;
120
- text: import("zod").ZodString;
121
- _meta: import("zod").ZodOptional<import("zod").ZodObject<{}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
122
- }, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{
123
- type: import("zod").ZodLiteral<"text">;
124
- text: import("zod").ZodString;
125
- _meta: import("zod").ZodOptional<import("zod").ZodObject<{}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
126
- }, import("zod").ZodTypeAny, "passthrough">>, import("zod").ZodObject<{
127
- type: import("zod").ZodLiteral<"image">;
128
- data: import("zod").ZodEffects<import("zod").ZodString, string, string>;
129
- mimeType: import("zod").ZodString;
130
- _meta: import("zod").ZodOptional<import("zod").ZodObject<{}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
131
- }, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
132
- type: import("zod").ZodLiteral<"image">;
133
- data: import("zod").ZodEffects<import("zod").ZodString, string, string>;
134
- mimeType: import("zod").ZodString;
135
- _meta: import("zod").ZodOptional<import("zod").ZodObject<{}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
136
- }, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{
137
- type: import("zod").ZodLiteral<"image">;
138
- data: import("zod").ZodEffects<import("zod").ZodString, string, string>;
139
- mimeType: import("zod").ZodString;
140
- _meta: import("zod").ZodOptional<import("zod").ZodObject<{}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
141
- }, import("zod").ZodTypeAny, "passthrough">>, import("zod").ZodObject<{
142
- type: import("zod").ZodLiteral<"audio">;
143
- data: import("zod").ZodEffects<import("zod").ZodString, string, string>;
144
- mimeType: import("zod").ZodString;
145
- _meta: import("zod").ZodOptional<import("zod").ZodObject<{}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
146
- }, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
147
- type: import("zod").ZodLiteral<"audio">;
148
- data: import("zod").ZodEffects<import("zod").ZodString, string, string>;
149
- mimeType: import("zod").ZodString;
150
- _meta: import("zod").ZodOptional<import("zod").ZodObject<{}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
151
- }, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{
152
- type: import("zod").ZodLiteral<"audio">;
153
- data: import("zod").ZodEffects<import("zod").ZodString, string, string>;
154
- mimeType: import("zod").ZodString;
155
- _meta: import("zod").ZodOptional<import("zod").ZodObject<{}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
156
- }, import("zod").ZodTypeAny, "passthrough">>]>;
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<z.objectOutputType<{
166
- _meta: import("zod").ZodOptional<import("zod").ZodObject<{}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
167
- } & {
168
- roots: import("zod").ZodArray<import("zod").ZodObject<{
169
- uri: import("zod").ZodString;
170
- name: import("zod").ZodOptional<import("zod").ZodString>;
171
- _meta: import("zod").ZodOptional<import("zod").ZodObject<{}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
172
- }, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
173
- uri: import("zod").ZodString;
174
- name: import("zod").ZodOptional<import("zod").ZodString>;
175
- _meta: import("zod").ZodOptional<import("zod").ZodObject<{}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
176
- }, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{
177
- uri: import("zod").ZodString;
178
- name: import("zod").ZodOptional<import("zod").ZodString>;
179
- _meta: import("zod").ZodOptional<import("zod").ZodObject<{}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
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("@opentiny/next").MessageChannelTransport, import("@opentiny/next").MessageChannelTransport];
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 type { IAgentModelProviderOption, McpServerConfig } from './type';
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;
@@ -1,6 +1,7 @@
1
- export type { experimental_MCPClient as MCPClient } from 'ai';
2
- import type { ProviderV2 } from '@ai-sdk/provider';
3
- import type { MCPTransport } from 'ai';
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,9 @@
1
+ import { ToolSet } from 'ai';
2
+
3
+ /**
4
+ * 生成 ReAct 模式的工具描述提示词(统一使用 XML 格式)
5
+ * 将工具集合转换为 ReAct 格式的文本描述,用于添加到系统提示词中
6
+ * @param tools - 工具集合对象
7
+ * @returns 格式化的工具描述字符串
8
+ */
9
+ export declare function generateReActToolsPrompt(tools: ToolSet): string;
@@ -1,5 +1,6 @@
1
1
  import { ToolSet } from 'ai';
2
2
  import { WebMcpClient } from '../../WebMcpClient';
3
+
3
4
  /**
4
5
  * 快速从官方 mcp 或 WebMcpClient 这2种client中读取 tools 数组,并转换成 ai-sdk 的tool的对象格式。
5
6
  * @params client 一个已连接好的 WebMcpClient
@@ -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
@@ -1,4 +1,5 @@
1
- import Ajv from 'ajv';
1
+ import { default as Ajv } from 'ajv';
2
+
2
3
  export { Ajv };
3
4
  export { z } from 'zod';
4
5
  export { AuthClientProvider } from '@opentiny/next';