@opentiny/next-sdk 0.1.13 → 0.1.14-alpha.0
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 +49 -20
- package/agent/type.ts +4 -4
- 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 +250 -1488
- package/dist/WebMcpServer.d.ts +190 -78
- package/dist/Zod.d.ts +1 -0
- package/dist/agent/AgentModelProvider.d.ts +6 -4
- package/dist/agent/type.d.ts +6 -2
- package/dist/agent/utils/getAISDKTools.d.ts +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.es.dev.js +23743 -25868
- package/dist/index.es.js +24524 -24312
- package/dist/index.js +1789 -25
- package/dist/index.umd.dev.js +23845 -25970
- package/dist/index.umd.js +185 -129
- package/dist/{mcpsdk@1.20.1.dev.js → mcpsdk@1.23.0.dev.js} +13535 -14184
- package/dist/{mcpsdk@1.20.1.es.dev.js → mcpsdk@1.23.0.es.dev.js} +13563 -14212
- package/dist/mcpsdk@1.23.0.es.js +15584 -0
- package/dist/mcpsdk@1.23.0.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 +3 -2
- 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 +18803 -18836
- package/dist/webagent.es.dev.js +17726 -17759
- package/dist/webagent.es.js +22571 -20829
- package/dist/webagent.js +172 -109
- package/dist/webmcp-full.dev.js +14463 -15009
- package/dist/webmcp-full.es.dev.js +14471 -15017
- package/dist/webmcp-full.es.js +13391 -12365
- package/dist/webmcp-full.js +43 -16
- package/package.json +3 -2
- package/remoter/createRemoter.ts +126 -71
- package/remoter/tooltips.ts +260 -0
- 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.20.1.es.js +0 -14600
- package/dist/mcpsdk@1.20.1.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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { streamText, stepCountIs, generateText, StreamTextResult } from 'ai'
|
|
2
|
-
import { experimental_MCPClientConfig as MCPClientConfig } from 'ai'
|
|
2
|
+
import { experimental_MCPClientConfig as MCPClientConfig, experimental_createMCPClient as createMCPClient } from 'ai'
|
|
3
3
|
import type { ToolSet } from 'ai'
|
|
4
4
|
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'
|
|
5
5
|
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js'
|
|
@@ -85,16 +85,28 @@ export class AgentModelProvider {
|
|
|
85
85
|
transport = serverConfig as MCPClientConfig['transport']
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
{ capabilities: { roots: { listChanged: true }, sampling: {}, elicitation: {} } }
|
|
91
|
-
)
|
|
92
|
-
await client.connect(transport)
|
|
88
|
+
// 根据 useAISdkClient 配置决定使用哪种 client 创建方式
|
|
89
|
+
const useAISdkClient = serverConfig.useAISdkClient ?? false
|
|
93
90
|
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
if (useAISdkClient) {
|
|
92
|
+
// 使用 ai-sdk 的 createMCPClient
|
|
93
|
+
const client = await createMCPClient({ transport: transport as MCPClientConfig['transport'] })
|
|
94
|
+
//@ts-ignore
|
|
95
|
+
client['__transport__'] = transport
|
|
96
|
+
return client
|
|
97
|
+
} else {
|
|
98
|
+
// 使用 WebMcpClient
|
|
99
|
+
const client = new WebMcpClient(
|
|
100
|
+
{ name: 'mcp-web-client', version: '1.0.0' },
|
|
101
|
+
{ capabilities: { roots: { listChanged: true }, sampling: {}, elicitation: {} } }
|
|
102
|
+
)
|
|
103
|
+
await client.connect(transport)
|
|
104
|
+
|
|
105
|
+
//@ts-ignore
|
|
106
|
+
client['__transport__'] = transport
|
|
96
107
|
|
|
97
|
-
|
|
108
|
+
return client
|
|
109
|
+
}
|
|
98
110
|
} catch (error: unknown) {
|
|
99
111
|
if (this.onError) {
|
|
100
112
|
this.onError((error as Error)?.message || `Failed to create MCP client`, error)
|
|
@@ -138,21 +150,37 @@ export class AgentModelProvider {
|
|
|
138
150
|
this.mcpClients[serverName] = client
|
|
139
151
|
})
|
|
140
152
|
}
|
|
153
|
+
/** 兼容两种 client 类型的 tools 获取方法 */
|
|
154
|
+
private async _getClientTools(client: any, serverName: string): Promise<ToolSet | null> {
|
|
155
|
+
if (!client) {
|
|
156
|
+
return null
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
try {
|
|
160
|
+
// 判断是否为 ai-sdk 的 client(有 tools 方法)
|
|
161
|
+
if (typeof client.tools === 'function') {
|
|
162
|
+
// ai-sdk 的 client,直接调用 tools() 方法
|
|
163
|
+
return await client.tools()
|
|
164
|
+
} else {
|
|
165
|
+
// WebMcpClient,使用 getAISDKTools 函数
|
|
166
|
+
return await getAISDKTools(client)
|
|
167
|
+
}
|
|
168
|
+
} catch (error: unknown) {
|
|
169
|
+
if (this.onError) {
|
|
170
|
+
this.onError((error as Error)?.message || `Failed to query tools for ${serverName}`, error)
|
|
171
|
+
}
|
|
172
|
+
console.error(`Failed to query tools for ${serverName}`, error)
|
|
173
|
+
return null
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
141
177
|
/** 查询所有 mcpClients 的 tools, 失败则保存为null */
|
|
142
178
|
private async _createMpcTools() {
|
|
143
179
|
const clientEntries = Object.entries(this.mcpClients)
|
|
144
180
|
const tools = await Promise.all(
|
|
145
181
|
clientEntries.map(async ([serverName, client]) => {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return { serverName, tools: result }
|
|
149
|
-
} catch (error: unknown) {
|
|
150
|
-
if (this.onError) {
|
|
151
|
-
this.onError((error as Error)?.message || `Failed to query tools`, error)
|
|
152
|
-
}
|
|
153
|
-
console.error(`Failed to query tools`, error)
|
|
154
|
-
return { serverName, tools: null }
|
|
155
|
-
}
|
|
182
|
+
const result = await this._getClientTools(client, serverName)
|
|
183
|
+
return { serverName, tools: result }
|
|
156
184
|
})
|
|
157
185
|
)
|
|
158
186
|
// 将结果存储到对象中,使用 serverName 作为键
|
|
@@ -206,7 +234,8 @@ export class AgentModelProvider {
|
|
|
206
234
|
return null
|
|
207
235
|
}
|
|
208
236
|
this.mcpClients[serverName] = client
|
|
209
|
-
|
|
237
|
+
// 使用兼容的工具获取方法
|
|
238
|
+
const tools = await this._getClientTools(client, serverName)
|
|
210
239
|
// 工具列表可能为 null,统一兜底为空对象,确保类型安全
|
|
211
240
|
this.mcpTools[serverName] = tools && typeof tools === 'object' ? (tools as Record<string, any>) : {}
|
|
212
241
|
this.mcpServers[serverName] = mcpServer
|
package/agent/type.ts
CHANGED
|
@@ -29,10 +29,10 @@ export type IAgentModelProviderLlmConfig = LlmFactoryConfig | LlmInstanceConfig
|
|
|
29
29
|
|
|
30
30
|
/** Mcp Server的配置对象 */
|
|
31
31
|
export type McpServerConfig =
|
|
32
|
-
| { type: 'streamableHttp'; url: string }
|
|
33
|
-
| { type: 'sse'; url: string }
|
|
34
|
-
| { type: 'extension'; url: string; sessionId: string }
|
|
35
|
-
| { transport: MCPTransport }
|
|
32
|
+
| { type: 'streamableHttp'; url: string; useAISdkClient?: boolean }
|
|
33
|
+
| { type: 'sse'; url: string; useAISdkClient?: boolean }
|
|
34
|
+
| { type: 'extension'; url: string; sessionId: string; useAISdkClient?: boolean }
|
|
35
|
+
| { transport: MCPTransport; useAISdkClient?: boolean }
|
|
36
36
|
|
|
37
37
|
/** */
|
|
38
38
|
export interface IAgentModelProviderOption {
|
package/dist/McpSdk.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { default as Ajv } from 'ajv';
|
|
2
|
+
|
|
3
|
+
export { Ajv };
|
|
4
|
+
export * from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
+
export * from '@modelcontextprotocol/sdk/shared/uriTemplate.js';
|
|
6
|
+
export * from '@modelcontextprotocol/sdk/server/completable.js';
|
|
7
|
+
export * from '@modelcontextprotocol/sdk/shared/metadataUtils.js';
|
|
8
|
+
export * from '@modelcontextprotocol/sdk/client/index.js';
|
|
9
|
+
export * from '@modelcontextprotocol/sdk/client/auth.js';
|
|
10
|
+
export * from '@modelcontextprotocol/sdk/client/sse.js';
|
|
11
|
+
export * from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
12
|
+
export * from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
13
|
+
export * from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
14
|
+
export * from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { AgentModelProvider } from './agent/AgentModelProvider';
|
|
2
|
+
export { createRemoter } from './remoter/createRemoter';
|
|
3
|
+
export { getAISDKTools } from './agent/utils/getAISDKTools';
|
|
4
|
+
export { QrCode, type QrCodeOption } from './remoter/QrCode';
|
|
5
|
+
export type * from './agent/type';
|
package/dist/WebMcp.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { default as Ajv } from 'ajv';
|
|
2
|
+
|
|
3
|
+
export * from './WebMcpServer';
|
|
4
|
+
export * from './WebMcpClient';
|
|
5
|
+
export { Ajv };
|
|
6
|
+
export { z } from 'zod';
|
|
7
|
+
export { AuthClientProvider } from '@opentiny/next';
|
|
8
|
+
export { ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
9
|
+
export { UriTemplate } from '@modelcontextprotocol/sdk/shared/uriTemplate.js';
|
|
10
|
+
export { completable } from '@modelcontextprotocol/sdk/server/completable.js';
|
|
11
|
+
export { getDisplayName } from '@modelcontextprotocol/sdk/shared/metadataUtils.js';
|
|
12
|
+
export type * from 'zod';
|
|
13
|
+
export type * from '@opentiny/next';
|
|
14
|
+
export type * from '@modelcontextprotocol/sdk/types.js';
|
|
15
|
+
export type * from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
16
|
+
export type * from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
17
|
+
export type * from '@modelcontextprotocol/sdk/client/sse.js';
|
|
18
|
+
export type * from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
19
|
+
export type * from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
20
|
+
export * from './transport/ExtensionPageServerTransport';
|