@opentiny/next-sdk 0.3.0-alpha.0 → 0.3.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 +11 -1
- package/agent/type.ts +22 -1
- package/agent/utils/getBuiltinMcpTools.ts +74 -0
- package/dist/{AgentModelProvider-BIOOEdcN.js → AgentModelProvider-D13Uqnne.js} +213 -178
- package/dist/agent/AgentModelProvider.d.ts +5 -2
- package/dist/agent/type.d.ts +23 -0
- package/dist/agent/utils/getBuiltinMcpTools.d.ts +12 -0
- package/dist/core.js +1 -1
- package/dist/index.es.dev.js +113 -478
- package/dist/index.es.js +9589 -9858
- package/dist/index.js +539 -853
- package/dist/index.umd.dev.js +113 -478
- package/dist/index.umd.js +66 -66
- package/dist/page-tools/bridge.d.ts +19 -43
- package/dist/webagent.dev.js +54 -1
- package/dist/webagent.es.dev.js +54 -1
- package/dist/webagent.es.js +1217 -1172
- package/dist/webagent.js +32 -32
- package/package.json +1 -1
- package/page-tools/bridge.ts +96 -614
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { MessageChannelServerTransport as ge, createTransportPair as
|
|
1
|
+
import { MessageChannelServerTransport as ge, createTransportPair as pt, MessageChannelClientTransport as ye, sseOptions as ht, streamOptions as mt, createSseProxy as ft, createSocketProxy as gt, createStreamProxy as yt, MessageChannelTransport as vt } from "@opentiny/next";
|
|
2
2
|
import { McpServer as qe } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
-
import { SetLevelRequestSchema as Te, SubscribeRequestSchema as
|
|
4
|
-
import { dynamicTool as
|
|
5
|
-
import { TypeValidationError as pe, JSONParseError as
|
|
6
|
-
import * as
|
|
3
|
+
import { SetLevelRequestSchema as Te, SubscribeRequestSchema as wt, UnsubscribeRequestSchema as _t, ListResourcesRequestSchema as bt, RootsListChangedNotificationSchema as St, CallToolResultSchema as Tt, ElicitRequestSchema as Pt, CreateMessageRequestSchema as Rt, ListRootsRequestSchema as Ct, ToolListChangedNotificationSchema as Mt, PromptListChangedNotificationSchema as Et, ResourceListChangedNotificationSchema as At, ResourceUpdatedNotificationSchema as kt, LoggingMessageNotificationSchema as Ot, JSONRPCMessageSchema as xt } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
import { dynamicTool as He, jsonSchema as Ze, generateText as Pe, streamText as ie, stepCountIs as It } from "ai";
|
|
5
|
+
import { TypeValidationError as pe, JSONParseError as Re, InvalidArgumentError as Lt, AISDKError as K } from "@ai-sdk/provider";
|
|
6
|
+
import * as Ce from "zod/v4";
|
|
7
7
|
import { z as o } from "zod/v4";
|
|
8
8
|
import { ZodFirstPartyTypeKind as w } from "zod/v3";
|
|
9
9
|
import { StreamableHTTPClientTransport as se } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
@@ -11,9 +11,9 @@ import { SSEClientTransport as ne } from "@modelcontextprotocol/sdk/client/sse.j
|
|
|
11
11
|
import { InMemoryTransport as Ut } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
12
12
|
import { createOpenAI as $t } from "@ai-sdk/openai";
|
|
13
13
|
import { createDeepSeek as jt } from "@ai-sdk/deepseek";
|
|
14
|
-
import { Client as
|
|
14
|
+
import { Client as De } from "@modelcontextprotocol/sdk/client/index.js";
|
|
15
15
|
import { WebSocketClientTransport as Nt } from "@modelcontextprotocol/sdk/client/websocket.js";
|
|
16
|
-
class
|
|
16
|
+
class bn {
|
|
17
17
|
constructor(e, r) {
|
|
18
18
|
const s = {
|
|
19
19
|
name: "web-mcp-server",
|
|
@@ -179,13 +179,13 @@ class _n {
|
|
|
179
179
|
* Registers a handler for the subscribe request.
|
|
180
180
|
*/
|
|
181
181
|
onSubscribe(e) {
|
|
182
|
-
this.server.server.setRequestHandler(
|
|
182
|
+
this.server.server.setRequestHandler(wt, e);
|
|
183
183
|
}
|
|
184
184
|
/**
|
|
185
185
|
* Registers a handler for the unsubscribe request.
|
|
186
186
|
*/
|
|
187
187
|
onUnsubscribe(e) {
|
|
188
|
-
this.server.server.setRequestHandler(
|
|
188
|
+
this.server.server.setRequestHandler(_t, e);
|
|
189
189
|
}
|
|
190
190
|
/**
|
|
191
191
|
* Registers a handler for the set log level request.
|
|
@@ -197,13 +197,13 @@ class _n {
|
|
|
197
197
|
* Registers a handler for the list tools request.
|
|
198
198
|
*/
|
|
199
199
|
onListResources(e) {
|
|
200
|
-
this.server.server.setRequestHandler(
|
|
200
|
+
this.server.server.setRequestHandler(bt, e);
|
|
201
201
|
}
|
|
202
202
|
/**
|
|
203
203
|
* Registers a handler for the roots list changed notification.
|
|
204
204
|
*/
|
|
205
205
|
onRootsListChanged(e) {
|
|
206
|
-
this.server.server.setNotificationHandler(
|
|
206
|
+
this.server.server.setNotificationHandler(St, e);
|
|
207
207
|
}
|
|
208
208
|
/**
|
|
209
209
|
* Close the transport for window.addEventListener('pagehide')
|
|
@@ -212,7 +212,7 @@ class _n {
|
|
|
212
212
|
e.persisted || this.transport && typeof this.transport.close == "function" && await this.transport.close();
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
|
-
const
|
|
215
|
+
const Sn = (t, e) => new ge(t, e), Tn = () => pt(), Pn = (t) => t instanceof ge, Rn = (t) => t instanceof qe;
|
|
216
216
|
class qt {
|
|
217
217
|
constructor(e, r) {
|
|
218
218
|
const s = {
|
|
@@ -223,7 +223,7 @@ class qt {
|
|
|
223
223
|
sampling: {},
|
|
224
224
|
elicitation: {}
|
|
225
225
|
};
|
|
226
|
-
this.client = new
|
|
226
|
+
this.client = new De(e || s, r || { capabilities: n }), this.client.onclose = () => {
|
|
227
227
|
this.onclose?.();
|
|
228
228
|
}, this.client.onerror = (a) => {
|
|
229
229
|
this.onerror?.(a);
|
|
@@ -240,7 +240,7 @@ class qt {
|
|
|
240
240
|
const p = { client: this.client, url: r, token: s, sessionId: n };
|
|
241
241
|
let g;
|
|
242
242
|
return await (async () => {
|
|
243
|
-
const { transport: m, sessionId: y } = a === "sse" ? await
|
|
243
|
+
const { transport: m, sessionId: y } = a === "sse" ? await ft(p) : a === "socket" ? await gt(p) : await yt(p);
|
|
244
244
|
m.onerror = async (h) => {
|
|
245
245
|
u?.(h);
|
|
246
246
|
}, g = { transport: m, sessionId: y };
|
|
@@ -249,11 +249,11 @@ class qt {
|
|
|
249
249
|
const l = new URL(r);
|
|
250
250
|
let c;
|
|
251
251
|
if (a === "channel" && (c = new ye(r), await this.client.connect(c)), a === "sse") {
|
|
252
|
-
const p =
|
|
252
|
+
const p = ht(s, n);
|
|
253
253
|
c = new ne(l, p), await this.client.connect(c);
|
|
254
254
|
}
|
|
255
255
|
if (a === "socket" && (c = new Nt(new URL(`${r}?sessionId=${n}&token=${s}`)), c.sessionId = n, await this.client.connect(c)), typeof c > "u") {
|
|
256
|
-
const p =
|
|
256
|
+
const p = mt(s, n);
|
|
257
257
|
c = new se(l, p), await this.client.connect(c);
|
|
258
258
|
}
|
|
259
259
|
return this.transport = c, { transport: this.transport, sessionId: this.transport.sessionId };
|
|
@@ -346,7 +346,7 @@ class qt {
|
|
|
346
346
|
* Calls a tool on the server with the given parameters.
|
|
347
347
|
*/
|
|
348
348
|
async callTool(e, r) {
|
|
349
|
-
return await this.client.callTool(e,
|
|
349
|
+
return await this.client.callTool(e, Tt, r);
|
|
350
350
|
}
|
|
351
351
|
/**
|
|
352
352
|
* Lists all tools available on the server.
|
|
@@ -406,49 +406,49 @@ class qt {
|
|
|
406
406
|
* Registers a handler for the elicitation request.
|
|
407
407
|
*/
|
|
408
408
|
onElicit(e) {
|
|
409
|
-
this.client.setRequestHandler(
|
|
409
|
+
this.client.setRequestHandler(Pt, e);
|
|
410
410
|
}
|
|
411
411
|
/**
|
|
412
412
|
* Registers a handler for the create LLM message request.
|
|
413
413
|
*/
|
|
414
414
|
onCreateMessage(e) {
|
|
415
|
-
this.client.setRequestHandler(
|
|
415
|
+
this.client.setRequestHandler(Rt, e);
|
|
416
416
|
}
|
|
417
417
|
/**
|
|
418
418
|
* Registers a handler for the list roots request.
|
|
419
419
|
*/
|
|
420
420
|
onListRoots(e) {
|
|
421
|
-
this.client.setRequestHandler(
|
|
421
|
+
this.client.setRequestHandler(Ct, e);
|
|
422
422
|
}
|
|
423
423
|
/**
|
|
424
424
|
* Registers a handler for the tool list changed notification.
|
|
425
425
|
*/
|
|
426
426
|
onToolListChanged(e) {
|
|
427
|
-
this.client.setNotificationHandler(
|
|
427
|
+
this.client.setNotificationHandler(Mt, e);
|
|
428
428
|
}
|
|
429
429
|
/**
|
|
430
430
|
* Registers a handler for the prompt list changed notification.
|
|
431
431
|
*/
|
|
432
432
|
onPromptListChanged(e) {
|
|
433
|
-
this.client.setNotificationHandler(
|
|
433
|
+
this.client.setNotificationHandler(Et, e);
|
|
434
434
|
}
|
|
435
435
|
/**
|
|
436
436
|
* Registers a handler for the resource list changed notification.
|
|
437
437
|
*/
|
|
438
438
|
onResourceListChanged(e) {
|
|
439
|
-
this.client.setNotificationHandler(
|
|
439
|
+
this.client.setNotificationHandler(At, e);
|
|
440
440
|
}
|
|
441
441
|
/**
|
|
442
442
|
* Registers a handler for the resource updated notification.
|
|
443
443
|
*/
|
|
444
444
|
onResourceUpdated(e) {
|
|
445
|
-
this.client.setNotificationHandler(
|
|
445
|
+
this.client.setNotificationHandler(kt, e);
|
|
446
446
|
}
|
|
447
447
|
/**
|
|
448
448
|
* Registers a handler for the logging message notification.
|
|
449
449
|
*/
|
|
450
450
|
onLoggingMessage(e) {
|
|
451
|
-
this.client.setNotificationHandler(
|
|
451
|
+
this.client.setNotificationHandler(Ot, e);
|
|
452
452
|
}
|
|
453
453
|
/**
|
|
454
454
|
* Close the transport for window.addEventListener('pagehide')
|
|
@@ -457,7 +457,7 @@ class qt {
|
|
|
457
457
|
e.persisted || (Ht(this.transport) ? await this.transport.terminateSession() : this.transport && typeof this.transport.close == "function" && await this.transport.close());
|
|
458
458
|
}
|
|
459
459
|
}
|
|
460
|
-
const Cn = (t, e) => new ne(t, e),
|
|
460
|
+
const Cn = (t, e) => new ne(t, e), Mn = (t, e) => new se(t, e), En = (t, e) => new ye(t, e), An = (t) => t instanceof ne, Ht = (t) => t instanceof se, kn = (t) => t instanceof ye, On = (t) => t instanceof De, xn = (t, e, r) => {
|
|
461
461
|
window.postMessage({ type: t, direction: r, data: e }, "*");
|
|
462
462
|
}, In = (t, e, r) => {
|
|
463
463
|
const s = async function(n) {
|
|
@@ -489,7 +489,7 @@ class zt {
|
|
|
489
489
|
(r) => {
|
|
490
490
|
try {
|
|
491
491
|
if (r.sessionId !== this.targetSessionId) return;
|
|
492
|
-
const s =
|
|
492
|
+
const s = xt.parse(r.mcpMessage);
|
|
493
493
|
this.onmessage?.(s);
|
|
494
494
|
} catch (s) {
|
|
495
495
|
console.log("【Client Transport】处理server消息错误:", s);
|
|
@@ -678,7 +678,7 @@ var Jt = ({
|
|
|
678
678
|
return () => `${t}${s}${n()}`;
|
|
679
679
|
};
|
|
680
680
|
Jt();
|
|
681
|
-
function
|
|
681
|
+
function ze(t = globalThis) {
|
|
682
682
|
var e, r, s;
|
|
683
683
|
return t.window ? "runtime/browser" : (e = t.navigator) != null && e.userAgent ? `runtime/${t.navigator.userAgent.toLowerCase()}` : (s = (r = t.process) == null ? void 0 : r.versions) != null && s.node ? `runtime/node.js/${t.process.version.substring(0)}` : t.EdgeRuntime ? "runtime/vercel-edge" : "runtime/unknown";
|
|
684
684
|
}
|
|
@@ -697,7 +697,7 @@ function Wt(t) {
|
|
|
697
697
|
}
|
|
698
698
|
return e;
|
|
699
699
|
}
|
|
700
|
-
function
|
|
700
|
+
function Fe(t, ...e) {
|
|
701
701
|
const r = new Headers(Wt(t)), s = r.get("user-agent") || "";
|
|
702
702
|
return r.set(
|
|
703
703
|
"user-agent",
|
|
@@ -823,15 +823,15 @@ function tr(t) {
|
|
|
823
823
|
function rr() {
|
|
824
824
|
return { type: "boolean" };
|
|
825
825
|
}
|
|
826
|
-
function
|
|
826
|
+
function Ve(t, e) {
|
|
827
827
|
return S(t.type._def, e);
|
|
828
828
|
}
|
|
829
829
|
var sr = (t, e) => S(t.innerType._def, e);
|
|
830
|
-
function
|
|
830
|
+
function Je(t, e, r) {
|
|
831
831
|
const s = r ?? e.dateStrategy;
|
|
832
832
|
if (Array.isArray(s))
|
|
833
833
|
return {
|
|
834
|
-
anyOf: s.map((n, a) =>
|
|
834
|
+
anyOf: s.map((n, a) => Je(t, e, n))
|
|
835
835
|
};
|
|
836
836
|
switch (s) {
|
|
837
837
|
case "string":
|
|
@@ -959,7 +959,7 @@ var le = void 0, L = {
|
|
|
959
959
|
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
960
960
|
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
961
961
|
};
|
|
962
|
-
function
|
|
962
|
+
function We(t, e) {
|
|
963
963
|
const r = {
|
|
964
964
|
type: "string"
|
|
965
965
|
};
|
|
@@ -981,7 +981,7 @@ function Ve(t, e) {
|
|
|
981
981
|
U(r, "idn-email", s.message, e);
|
|
982
982
|
break;
|
|
983
983
|
case "pattern:zod":
|
|
984
|
-
|
|
984
|
+
R(r, L.email, s.message, e);
|
|
985
985
|
break;
|
|
986
986
|
}
|
|
987
987
|
break;
|
|
@@ -992,16 +992,16 @@ function Ve(t, e) {
|
|
|
992
992
|
U(r, "uuid", s.message, e);
|
|
993
993
|
break;
|
|
994
994
|
case "regex":
|
|
995
|
-
|
|
995
|
+
R(r, s.regex, s.message, e);
|
|
996
996
|
break;
|
|
997
997
|
case "cuid":
|
|
998
|
-
|
|
998
|
+
R(r, L.cuid, s.message, e);
|
|
999
999
|
break;
|
|
1000
1000
|
case "cuid2":
|
|
1001
|
-
|
|
1001
|
+
R(r, L.cuid2, s.message, e);
|
|
1002
1002
|
break;
|
|
1003
1003
|
case "startsWith":
|
|
1004
|
-
|
|
1004
|
+
R(
|
|
1005
1005
|
r,
|
|
1006
1006
|
RegExp(`^${ue(s.value, e)}`),
|
|
1007
1007
|
s.message,
|
|
@@ -1009,7 +1009,7 @@ function Ve(t, e) {
|
|
|
1009
1009
|
);
|
|
1010
1010
|
break;
|
|
1011
1011
|
case "endsWith":
|
|
1012
|
-
|
|
1012
|
+
R(
|
|
1013
1013
|
r,
|
|
1014
1014
|
RegExp(`${ue(s.value, e)}$`),
|
|
1015
1015
|
s.message,
|
|
@@ -1032,7 +1032,7 @@ function Ve(t, e) {
|
|
|
1032
1032
|
r.minLength = typeof r.minLength == "number" ? Math.max(r.minLength, s.value) : s.value, r.maxLength = typeof r.maxLength == "number" ? Math.min(r.maxLength, s.value) : s.value;
|
|
1033
1033
|
break;
|
|
1034
1034
|
case "includes": {
|
|
1035
|
-
|
|
1035
|
+
R(
|
|
1036
1036
|
r,
|
|
1037
1037
|
RegExp(ue(s.value, e)),
|
|
1038
1038
|
s.message,
|
|
@@ -1045,20 +1045,20 @@ function Ve(t, e) {
|
|
|
1045
1045
|
break;
|
|
1046
1046
|
}
|
|
1047
1047
|
case "base64url":
|
|
1048
|
-
|
|
1048
|
+
R(r, L.base64url, s.message, e);
|
|
1049
1049
|
break;
|
|
1050
1050
|
case "jwt":
|
|
1051
|
-
|
|
1051
|
+
R(r, L.jwt, s.message, e);
|
|
1052
1052
|
break;
|
|
1053
1053
|
case "cidr": {
|
|
1054
|
-
s.version !== "v6" &&
|
|
1054
|
+
s.version !== "v6" && R(r, L.ipv4Cidr, s.message, e), s.version !== "v4" && R(r, L.ipv6Cidr, s.message, e);
|
|
1055
1055
|
break;
|
|
1056
1056
|
}
|
|
1057
1057
|
case "emoji":
|
|
1058
|
-
|
|
1058
|
+
R(r, L.emoji(), s.message, e);
|
|
1059
1059
|
break;
|
|
1060
1060
|
case "ulid": {
|
|
1061
|
-
|
|
1061
|
+
R(r, L.ulid, s.message, e);
|
|
1062
1062
|
break;
|
|
1063
1063
|
}
|
|
1064
1064
|
case "base64": {
|
|
@@ -1072,14 +1072,14 @@ function Ve(t, e) {
|
|
|
1072
1072
|
break;
|
|
1073
1073
|
}
|
|
1074
1074
|
case "pattern:zod": {
|
|
1075
|
-
|
|
1075
|
+
R(r, L.base64, s.message, e);
|
|
1076
1076
|
break;
|
|
1077
1077
|
}
|
|
1078
1078
|
}
|
|
1079
1079
|
break;
|
|
1080
1080
|
}
|
|
1081
1081
|
case "nanoid":
|
|
1082
|
-
|
|
1082
|
+
R(r, L.nanoid, s.message, e);
|
|
1083
1083
|
}
|
|
1084
1084
|
return r;
|
|
1085
1085
|
}
|
|
@@ -1104,7 +1104,7 @@ function U(t, e, r, s) {
|
|
|
1104
1104
|
...r && s.errorMessages && { errorMessage: { format: r } }
|
|
1105
1105
|
})) : t.format = e;
|
|
1106
1106
|
}
|
|
1107
|
-
function
|
|
1107
|
+
function R(t, e, r, s) {
|
|
1108
1108
|
var n;
|
|
1109
1109
|
t.pattern || (n = t.allOf) != null && n.some((a) => a.pattern) ? (t.allOf || (t.allOf = []), t.pattern && (t.allOf.push({
|
|
1110
1110
|
pattern: t.pattern
|
|
@@ -1172,7 +1172,7 @@ function ke(t, e) {
|
|
|
1172
1172
|
}
|
|
1173
1173
|
return a;
|
|
1174
1174
|
}
|
|
1175
|
-
function
|
|
1175
|
+
function Be(t, e) {
|
|
1176
1176
|
var r, s, n, a, i, u;
|
|
1177
1177
|
const l = {
|
|
1178
1178
|
type: "object",
|
|
@@ -1182,7 +1182,7 @@ function Je(t, e) {
|
|
|
1182
1182
|
})) != null ? r : e.allowedAdditionalProperties
|
|
1183
1183
|
};
|
|
1184
1184
|
if (((s = t.keyType) == null ? void 0 : s._def.typeName) === w.ZodString && ((n = t.keyType._def.checks) != null && n.length)) {
|
|
1185
|
-
const { type: c, ...p } =
|
|
1185
|
+
const { type: c, ...p } = We(t.keyType._def, e);
|
|
1186
1186
|
return {
|
|
1187
1187
|
...l,
|
|
1188
1188
|
propertyNames: p
|
|
@@ -1196,7 +1196,7 @@ function Je(t, e) {
|
|
|
1196
1196
|
}
|
|
1197
1197
|
};
|
|
1198
1198
|
if (((i = t.keyType) == null ? void 0 : i._def.typeName) === w.ZodBranded && t.keyType._def.type._def.typeName === w.ZodString && ((u = t.keyType._def.type._def.checks) != null && u.length)) {
|
|
1199
|
-
const { type: c, ...p } =
|
|
1199
|
+
const { type: c, ...p } = Ve(
|
|
1200
1200
|
t.keyType._def,
|
|
1201
1201
|
e
|
|
1202
1202
|
);
|
|
@@ -1210,7 +1210,7 @@ function Je(t, e) {
|
|
|
1210
1210
|
}
|
|
1211
1211
|
function hr(t, e) {
|
|
1212
1212
|
if (e.mapStrategy === "record")
|
|
1213
|
-
return
|
|
1213
|
+
return Be(t, e);
|
|
1214
1214
|
const r = S(t.keyType._def, {
|
|
1215
1215
|
...e,
|
|
1216
1216
|
currentPath: [...e.currentPath, "items", "items", "0"]
|
|
@@ -1410,7 +1410,7 @@ var Pr = (t, e) => {
|
|
|
1410
1410
|
currentPath: [...e.currentPath, "anyOf", "1"]
|
|
1411
1411
|
});
|
|
1412
1412
|
return s ? { anyOf: [{ not: E() }, s] } : E();
|
|
1413
|
-
},
|
|
1413
|
+
}, Rr = (t, e) => {
|
|
1414
1414
|
if (e.pipeStrategy === "input")
|
|
1415
1415
|
return S(t.in._def, e);
|
|
1416
1416
|
if (e.pipeStrategy === "output")
|
|
@@ -1426,7 +1426,7 @@ var Pr = (t, e) => {
|
|
|
1426
1426
|
allOf: [r, s].filter((n) => n !== void 0)
|
|
1427
1427
|
};
|
|
1428
1428
|
};
|
|
1429
|
-
function
|
|
1429
|
+
function Cr(t, e) {
|
|
1430
1430
|
return S(t.type._def, e);
|
|
1431
1431
|
}
|
|
1432
1432
|
function Mr(t, e) {
|
|
@@ -1480,10 +1480,10 @@ function Ar() {
|
|
|
1480
1480
|
function kr() {
|
|
1481
1481
|
return E();
|
|
1482
1482
|
}
|
|
1483
|
-
var Or = (t, e) => S(t.innerType._def, e),
|
|
1483
|
+
var Or = (t, e) => S(t.innerType._def, e), xr = (t, e, r) => {
|
|
1484
1484
|
switch (e) {
|
|
1485
1485
|
case w.ZodString:
|
|
1486
|
-
return
|
|
1486
|
+
return We(t, r);
|
|
1487
1487
|
case w.ZodNumber:
|
|
1488
1488
|
return _r(t);
|
|
1489
1489
|
case w.ZodObject:
|
|
@@ -1493,7 +1493,7 @@ var Or = (t, e) => S(t.innerType._def, e), Ir = (t, e, r) => {
|
|
|
1493
1493
|
case w.ZodBoolean:
|
|
1494
1494
|
return rr();
|
|
1495
1495
|
case w.ZodDate:
|
|
1496
|
-
return
|
|
1496
|
+
return Je(t, r);
|
|
1497
1497
|
case w.ZodUndefined:
|
|
1498
1498
|
return Ar();
|
|
1499
1499
|
case w.ZodNull:
|
|
@@ -1508,7 +1508,7 @@ var Or = (t, e) => S(t.innerType._def, e), Ir = (t, e, r) => {
|
|
|
1508
1508
|
case w.ZodTuple:
|
|
1509
1509
|
return Er(t, r);
|
|
1510
1510
|
case w.ZodRecord:
|
|
1511
|
-
return
|
|
1511
|
+
return Be(t, r);
|
|
1512
1512
|
case w.ZodLiteral:
|
|
1513
1513
|
return ur(t);
|
|
1514
1514
|
case w.ZodEnum:
|
|
@@ -1526,7 +1526,7 @@ var Or = (t, e) => S(t.innerType._def, e), Ir = (t, e, r) => {
|
|
|
1526
1526
|
case w.ZodLazy:
|
|
1527
1527
|
return () => t.getter()._def;
|
|
1528
1528
|
case w.ZodPromise:
|
|
1529
|
-
return
|
|
1529
|
+
return Cr(t, r);
|
|
1530
1530
|
case w.ZodNaN:
|
|
1531
1531
|
case w.ZodNever:
|
|
1532
1532
|
return fr();
|
|
@@ -1539,13 +1539,13 @@ var Or = (t, e) => S(t.innerType._def, e), Ir = (t, e, r) => {
|
|
|
1539
1539
|
case w.ZodDefault:
|
|
1540
1540
|
return or(t, r);
|
|
1541
1541
|
case w.ZodBranded:
|
|
1542
|
-
return
|
|
1542
|
+
return Ve(t, r);
|
|
1543
1543
|
case w.ZodReadonly:
|
|
1544
1544
|
return Or(t, r);
|
|
1545
1545
|
case w.ZodCatch:
|
|
1546
1546
|
return sr(t, r);
|
|
1547
1547
|
case w.ZodPipeline:
|
|
1548
|
-
return
|
|
1548
|
+
return Rr(t, r);
|
|
1549
1549
|
case w.ZodFunction:
|
|
1550
1550
|
case w.ZodVoid:
|
|
1551
1551
|
case w.ZodSymbol:
|
|
@@ -1554,7 +1554,7 @@ var Or = (t, e) => S(t.innerType._def, e), Ir = (t, e, r) => {
|
|
|
1554
1554
|
return /* @__PURE__ */ ((s) => {
|
|
1555
1555
|
})();
|
|
1556
1556
|
}
|
|
1557
|
-
},
|
|
1557
|
+
}, Ir = (t, e) => {
|
|
1558
1558
|
let r = 0;
|
|
1559
1559
|
for (; r < t.length && r < e.length && t[r] === e[r]; r++)
|
|
1560
1560
|
;
|
|
@@ -1581,7 +1581,7 @@ function S(t, e, r = !1) {
|
|
|
1581
1581
|
}
|
|
1582
1582
|
const a = { def: t, path: e.currentPath, jsonSchema: void 0 };
|
|
1583
1583
|
e.seen.set(t, a);
|
|
1584
|
-
const i =
|
|
1584
|
+
const i = xr(t, t.typeName, e), u = typeof i == "function" ? S(i(), e) : i;
|
|
1585
1585
|
if (u && Ur(t, e, u), e.postProcess) {
|
|
1586
1586
|
const l = e.postProcess(u, t, e);
|
|
1587
1587
|
return a.jsonSchema = u, l;
|
|
@@ -1593,7 +1593,7 @@ var Lr = (t, e) => {
|
|
|
1593
1593
|
case "root":
|
|
1594
1594
|
return { $ref: t.path.join("/") };
|
|
1595
1595
|
case "relative":
|
|
1596
|
-
return { $ref:
|
|
1596
|
+
return { $ref: Ir(e.currentPath, t.path) };
|
|
1597
1597
|
case "none":
|
|
1598
1598
|
case "seen":
|
|
1599
1599
|
return t.path.length < e.currentPath.length && t.path.every((r, s) => e.currentPath[s] === r) ? (console.warn(
|
|
@@ -1681,7 +1681,7 @@ function J(t, {
|
|
|
1681
1681
|
function Nr(t) {
|
|
1682
1682
|
return typeof t == "object" && t !== null && fe in t && t[fe] === !0 && "jsonSchema" in t && "validate" in t;
|
|
1683
1683
|
}
|
|
1684
|
-
function
|
|
1684
|
+
function Ge(t) {
|
|
1685
1685
|
return t == null ? J({ properties: {}, additionalProperties: !1 }) : Nr(t) ? t : "~standard" in t ? t["~standard"].vendor === "zod" ? zr(t) : qr(t) : t();
|
|
1686
1686
|
}
|
|
1687
1687
|
function qr(t) {
|
|
@@ -1727,7 +1727,7 @@ function Zr(t, e) {
|
|
|
1727
1727
|
return J(
|
|
1728
1728
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
1729
1729
|
() => ve(
|
|
1730
|
-
|
|
1730
|
+
Ce.toJSONSchema(t, {
|
|
1731
1731
|
target: "draft-7",
|
|
1732
1732
|
io: "input",
|
|
1733
1733
|
reused: s ? "ref" : "inline"
|
|
@@ -1735,7 +1735,7 @@ function Zr(t, e) {
|
|
|
1735
1735
|
),
|
|
1736
1736
|
{
|
|
1737
1737
|
validate: async (n) => {
|
|
1738
|
-
const a = await
|
|
1738
|
+
const a = await Ce.safeParseAsync(t, n);
|
|
1739
1739
|
return a.success ? { success: !0, value: a.data } : { success: !1, error: a.error };
|
|
1740
1740
|
}
|
|
1741
1741
|
}
|
|
@@ -1747,12 +1747,12 @@ function Dr(t) {
|
|
|
1747
1747
|
function zr(t, e) {
|
|
1748
1748
|
return Dr(t) ? Zr(t) : Hr(t);
|
|
1749
1749
|
}
|
|
1750
|
-
async function
|
|
1750
|
+
async function Ke({
|
|
1751
1751
|
value: t,
|
|
1752
1752
|
schema: e,
|
|
1753
1753
|
context: r
|
|
1754
1754
|
}) {
|
|
1755
|
-
const s =
|
|
1755
|
+
const s = Ge(e);
|
|
1756
1756
|
try {
|
|
1757
1757
|
if (s.validate == null)
|
|
1758
1758
|
return { success: !0, value: t, rawValue: t };
|
|
@@ -1776,11 +1776,11 @@ async function Fr({
|
|
|
1776
1776
|
}) {
|
|
1777
1777
|
try {
|
|
1778
1778
|
const r = Xt(t);
|
|
1779
|
-
return e == null ? { success: !0, value: r, rawValue: r } : await
|
|
1779
|
+
return e == null ? { success: !0, value: r, rawValue: r } : await Ke({ value: r, schema: e });
|
|
1780
1780
|
} catch (r) {
|
|
1781
1781
|
return {
|
|
1782
1782
|
success: !1,
|
|
1783
|
-
error:
|
|
1783
|
+
error: Re.isInstance(r) ? r : new Re({ text: t, cause: r }),
|
|
1784
1784
|
rawValue: void 0
|
|
1785
1785
|
};
|
|
1786
1786
|
}
|
|
@@ -1819,7 +1819,7 @@ async function Kr(t) {
|
|
|
1819
1819
|
code_challenge: r
|
|
1820
1820
|
};
|
|
1821
1821
|
}
|
|
1822
|
-
var Xr = "AI_MCPClientError",
|
|
1822
|
+
var Xr = "AI_MCPClientError", Xe = `vercel.ai.error.${Xr}`, Qr = Symbol.for(Xe), Oe, xe, _ = class extends (xe = K, Oe = Qr, xe) {
|
|
1823
1823
|
constructor({
|
|
1824
1824
|
name: t = "MCPClientError",
|
|
1825
1825
|
message: e,
|
|
@@ -1830,7 +1830,7 @@ var Xr = "AI_MCPClientError", Ge = `vercel.ai.error.${Xr}`, Qr = Symbol.for(Ge),
|
|
|
1830
1830
|
super({ name: t, message: e, cause: r }), this[Oe] = !0, this.data = s, this.code = n;
|
|
1831
1831
|
}
|
|
1832
1832
|
static isInstance(t) {
|
|
1833
|
-
return K.hasMarker(t,
|
|
1833
|
+
return K.hasMarker(t, Xe);
|
|
1834
1834
|
}
|
|
1835
1835
|
}, D = "2025-11-25", Yr = [
|
|
1836
1836
|
D,
|
|
@@ -1842,10 +1842,10 @@ var Xr = "AI_MCPClientError", Ge = `vercel.ai.error.${Xr}`, Qr = Symbol.for(Ge),
|
|
|
1842
1842
|
version: o.string()
|
|
1843
1843
|
}), oe = o.looseObject({
|
|
1844
1844
|
_meta: o.optional(o.object({}).loose())
|
|
1845
|
-
}), $ = oe,
|
|
1845
|
+
}), $ = oe, Qe = o.object({
|
|
1846
1846
|
method: o.string(),
|
|
1847
1847
|
params: o.optional(oe)
|
|
1848
|
-
}),
|
|
1848
|
+
}), Ye = o.object({
|
|
1849
1849
|
applyDefaults: o.optional(o.boolean())
|
|
1850
1850
|
}).loose(), rs = o.looseObject({
|
|
1851
1851
|
experimental: o.optional(o.object({}).loose()),
|
|
@@ -1866,10 +1866,10 @@ var Xr = "AI_MCPClientError", Ge = `vercel.ai.error.${Xr}`, Qr = Symbol.for(Ge),
|
|
|
1866
1866
|
listChanged: o.optional(o.boolean())
|
|
1867
1867
|
})
|
|
1868
1868
|
),
|
|
1869
|
-
elicitation: o.optional(
|
|
1869
|
+
elicitation: o.optional(Ye)
|
|
1870
1870
|
});
|
|
1871
1871
|
o.object({
|
|
1872
|
-
elicitation: o.optional(
|
|
1872
|
+
elicitation: o.optional(Ye)
|
|
1873
1873
|
}).loose();
|
|
1874
1874
|
var ss = $.extend({
|
|
1875
1875
|
protocolVersion: o.string(),
|
|
@@ -1901,10 +1901,10 @@ var ss = $.extend({
|
|
|
1901
1901
|
_meta: es
|
|
1902
1902
|
}).loose(), os = _e.extend({
|
|
1903
1903
|
tools: o.array(ns)
|
|
1904
|
-
}),
|
|
1904
|
+
}), et = o.object({
|
|
1905
1905
|
type: o.literal("text"),
|
|
1906
1906
|
text: o.string()
|
|
1907
|
-
}).loose(),
|
|
1907
|
+
}).loose(), tt = o.object({
|
|
1908
1908
|
type: o.literal("image"),
|
|
1909
1909
|
data: o.base64(),
|
|
1910
1910
|
mimeType: o.string()
|
|
@@ -1917,7 +1917,7 @@ var ss = $.extend({
|
|
|
1917
1917
|
size: o.optional(o.number())
|
|
1918
1918
|
}).loose(), is = _e.extend({
|
|
1919
1919
|
resources: o.array(as)
|
|
1920
|
-
}),
|
|
1920
|
+
}), rt = o.object({
|
|
1921
1921
|
/**
|
|
1922
1922
|
* The URI of this resource.
|
|
1923
1923
|
*/
|
|
@@ -1934,16 +1934,16 @@ var ss = $.extend({
|
|
|
1934
1934
|
* The MIME type of this resource, if known.
|
|
1935
1935
|
*/
|
|
1936
1936
|
mimeType: o.optional(o.string())
|
|
1937
|
-
}).loose(),
|
|
1937
|
+
}).loose(), st = rt.extend({
|
|
1938
1938
|
text: o.string()
|
|
1939
|
-
}),
|
|
1939
|
+
}), nt = rt.extend({
|
|
1940
1940
|
blob: o.base64()
|
|
1941
|
-
}),
|
|
1941
|
+
}), ot = o.object({
|
|
1942
1942
|
type: o.literal("resource"),
|
|
1943
|
-
resource: o.union([
|
|
1943
|
+
resource: o.union([st, nt])
|
|
1944
1944
|
}).loose(), cs = $.extend({
|
|
1945
1945
|
content: o.array(
|
|
1946
|
-
o.union([
|
|
1946
|
+
o.union([et, tt, ot])
|
|
1947
1947
|
),
|
|
1948
1948
|
/**
|
|
1949
1949
|
* @see https://modelcontextprotocol.io/specification/2025-06-18/server/tools#structured-content
|
|
@@ -1964,7 +1964,7 @@ var ss = $.extend({
|
|
|
1964
1964
|
resourceTemplates: o.array(ls)
|
|
1965
1965
|
}), ds = $.extend({
|
|
1966
1966
|
contents: o.array(
|
|
1967
|
-
o.union([
|
|
1967
|
+
o.union([st, nt])
|
|
1968
1968
|
)
|
|
1969
1969
|
}), ps = o.object({
|
|
1970
1970
|
name: o.string(),
|
|
@@ -1980,9 +1980,9 @@ var ss = $.extend({
|
|
|
1980
1980
|
}), fs = o.object({
|
|
1981
1981
|
role: o.union([o.literal("user"), o.literal("assistant")]),
|
|
1982
1982
|
content: o.union([
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1983
|
+
et,
|
|
1984
|
+
tt,
|
|
1985
|
+
ot
|
|
1986
1986
|
])
|
|
1987
1987
|
}).loose(), gs = $.extend({
|
|
1988
1988
|
description: o.optional(o.string()),
|
|
@@ -1990,7 +1990,7 @@ var ss = $.extend({
|
|
|
1990
1990
|
}), ys = oe.extend({
|
|
1991
1991
|
message: o.string(),
|
|
1992
1992
|
requestedSchema: o.unknown()
|
|
1993
|
-
}),
|
|
1993
|
+
}), Ie = Qe.extend({
|
|
1994
1994
|
method: o.literal("elicitation/create"),
|
|
1995
1995
|
params: ys
|
|
1996
1996
|
}), vs = $.extend({
|
|
@@ -2003,7 +2003,7 @@ var ss = $.extend({
|
|
|
2003
2003
|
}), ae = "2.0", ws = o.object({
|
|
2004
2004
|
jsonrpc: o.literal(ae),
|
|
2005
2005
|
id: o.union([o.string(), o.number().int()])
|
|
2006
|
-
}).merge(
|
|
2006
|
+
}).merge(Qe).strict(), _s = o.object({
|
|
2007
2007
|
jsonrpc: o.literal(ae),
|
|
2008
2008
|
id: o.union([o.string(), o.number().int()]),
|
|
2009
2009
|
result: $
|
|
@@ -2027,7 +2027,7 @@ var ss = $.extend({
|
|
|
2027
2027
|
Ss,
|
|
2028
2028
|
_s,
|
|
2029
2029
|
bs
|
|
2030
|
-
]),
|
|
2030
|
+
]), at = typeof __PACKAGE_VERSION__ < "u" ? __PACKAGE_VERSION__ : "0.0.0-test", it = o.object({
|
|
2031
2031
|
access_token: o.string(),
|
|
2032
2032
|
id_token: o.string().optional(),
|
|
2033
2033
|
// Optional for OAuth 2.1, but necessary in OpenID Connect
|
|
@@ -2035,7 +2035,7 @@ var ss = $.extend({
|
|
|
2035
2035
|
expires_in: o.number().optional(),
|
|
2036
2036
|
scope: o.string().optional(),
|
|
2037
2037
|
refresh_token: o.string().optional()
|
|
2038
|
-
}).strip(),
|
|
2038
|
+
}).strip(), C = o.string().url().superRefine((t, e) => {
|
|
2039
2039
|
if (!URL.canParse(t))
|
|
2040
2040
|
return e.addIssue({
|
|
2041
2041
|
code: o.ZodIssueCode.custom,
|
|
@@ -2050,7 +2050,7 @@ var ss = $.extend({
|
|
|
2050
2050
|
{ message: "URL cannot use javascript:, data:, or vbscript: scheme" }
|
|
2051
2051
|
), Ts = o.object({
|
|
2052
2052
|
resource: o.string().url(),
|
|
2053
|
-
authorization_servers: o.array(
|
|
2053
|
+
authorization_servers: o.array(C).optional(),
|
|
2054
2054
|
jwks_uri: o.string().url().optional(),
|
|
2055
2055
|
scopes_supported: o.array(o.string()).optional(),
|
|
2056
2056
|
bearer_methods_supported: o.array(o.string()).optional(),
|
|
@@ -2063,11 +2063,11 @@ var ss = $.extend({
|
|
|
2063
2063
|
authorization_details_types_supported: o.array(o.string()).optional(),
|
|
2064
2064
|
dpop_signing_alg_values_supported: o.array(o.string()).optional(),
|
|
2065
2065
|
dpop_bound_access_tokens_required: o.boolean().optional()
|
|
2066
|
-
}).passthrough(),
|
|
2066
|
+
}).passthrough(), ct = o.object({
|
|
2067
2067
|
issuer: o.string(),
|
|
2068
|
-
authorization_endpoint:
|
|
2069
|
-
token_endpoint:
|
|
2070
|
-
registration_endpoint:
|
|
2068
|
+
authorization_endpoint: C,
|
|
2069
|
+
token_endpoint: C,
|
|
2070
|
+
registration_endpoint: C.optional(),
|
|
2071
2071
|
scopes_supported: o.array(o.string()).optional(),
|
|
2072
2072
|
response_types_supported: o.array(o.string()),
|
|
2073
2073
|
grant_types_supported: o.array(o.string()).optional(),
|
|
@@ -2076,11 +2076,11 @@ var ss = $.extend({
|
|
|
2076
2076
|
token_endpoint_auth_signing_alg_values_supported: o.array(o.string()).optional()
|
|
2077
2077
|
}).passthrough(), Ps = o.object({
|
|
2078
2078
|
issuer: o.string(),
|
|
2079
|
-
authorization_endpoint:
|
|
2080
|
-
token_endpoint:
|
|
2081
|
-
userinfo_endpoint:
|
|
2082
|
-
jwks_uri:
|
|
2083
|
-
registration_endpoint:
|
|
2079
|
+
authorization_endpoint: C,
|
|
2080
|
+
token_endpoint: C,
|
|
2081
|
+
userinfo_endpoint: C.optional(),
|
|
2082
|
+
jwks_uri: C,
|
|
2083
|
+
registration_endpoint: C.optional(),
|
|
2084
2084
|
scopes_supported: o.array(o.string()).optional(),
|
|
2085
2085
|
response_types_supported: o.array(o.string()),
|
|
2086
2086
|
grant_types_supported: o.array(o.string()).optional(),
|
|
@@ -2088,28 +2088,28 @@ var ss = $.extend({
|
|
|
2088
2088
|
id_token_signing_alg_values_supported: o.array(o.string()),
|
|
2089
2089
|
claims_supported: o.array(o.string()).optional(),
|
|
2090
2090
|
token_endpoint_auth_methods_supported: o.array(o.string()).optional()
|
|
2091
|
-
}).passthrough(),
|
|
2092
|
-
|
|
2091
|
+
}).passthrough(), Rs = Ps.merge(
|
|
2092
|
+
ct.pick({
|
|
2093
2093
|
code_challenge_methods_supported: !0
|
|
2094
2094
|
})
|
|
2095
|
-
),
|
|
2095
|
+
), Cs = o.object({
|
|
2096
2096
|
client_id: o.string(),
|
|
2097
2097
|
client_secret: o.string().optional(),
|
|
2098
2098
|
client_id_issued_at: o.number().optional(),
|
|
2099
2099
|
client_secret_expires_at: o.number().optional()
|
|
2100
2100
|
}).strip(), Ms = o.object({
|
|
2101
|
-
redirect_uris: o.array(
|
|
2101
|
+
redirect_uris: o.array(C),
|
|
2102
2102
|
token_endpoint_auth_method: o.string().optional(),
|
|
2103
2103
|
grant_types: o.array(o.string()).optional(),
|
|
2104
2104
|
response_types: o.array(o.string()).optional(),
|
|
2105
2105
|
client_name: o.string().optional(),
|
|
2106
|
-
client_uri:
|
|
2107
|
-
logo_uri:
|
|
2106
|
+
client_uri: C.optional(),
|
|
2107
|
+
logo_uri: C.optional(),
|
|
2108
2108
|
scope: o.string().optional(),
|
|
2109
2109
|
contacts: o.array(o.string()).optional(),
|
|
2110
|
-
tos_uri:
|
|
2110
|
+
tos_uri: C.optional(),
|
|
2111
2111
|
policy_uri: o.string().optional(),
|
|
2112
|
-
jwks_uri:
|
|
2112
|
+
jwks_uri: C.optional(),
|
|
2113
2113
|
jwks: o.any().optional(),
|
|
2114
2114
|
software_id: o.string().optional(),
|
|
2115
2115
|
software_version: o.string().optional(),
|
|
@@ -2119,8 +2119,8 @@ var ss = $.extend({
|
|
|
2119
2119
|
error_description: o.string().optional(),
|
|
2120
2120
|
error_uri: o.string().optional()
|
|
2121
2121
|
}), As = Ms.merge(
|
|
2122
|
-
|
|
2123
|
-
), ks = "AI_MCPClientOAuthError",
|
|
2122
|
+
Cs
|
|
2123
|
+
), ks = "AI_MCPClientOAuthError", lt = `vercel.ai.error.${ks}`, Os = Symbol.for(lt), Le, Ue, W = class extends (Ue = K, Le = Os, Ue) {
|
|
2124
2124
|
constructor({
|
|
2125
2125
|
name: t = "MCPClientOAuthError",
|
|
2126
2126
|
message: e,
|
|
@@ -2129,7 +2129,7 @@ var ss = $.extend({
|
|
|
2129
2129
|
super({ name: t, message: e, cause: r }), this[Le] = !0;
|
|
2130
2130
|
}
|
|
2131
2131
|
static isInstance(t) {
|
|
2132
|
-
return K.hasMarker(t,
|
|
2132
|
+
return K.hasMarker(t, lt);
|
|
2133
2133
|
}
|
|
2134
2134
|
}, Z = class extends W {
|
|
2135
2135
|
};
|
|
@@ -2143,13 +2143,13 @@ Q.errorCode = "invalid_grant";
|
|
|
2143
2143
|
var Y = class extends W {
|
|
2144
2144
|
};
|
|
2145
2145
|
Y.errorCode = "unauthorized_client";
|
|
2146
|
-
var
|
|
2146
|
+
var xs = {
|
|
2147
2147
|
[Z.errorCode]: Z,
|
|
2148
2148
|
[X.errorCode]: X,
|
|
2149
2149
|
[Q.errorCode]: Q,
|
|
2150
2150
|
[Y.errorCode]: Y
|
|
2151
2151
|
};
|
|
2152
|
-
function
|
|
2152
|
+
function Is(t) {
|
|
2153
2153
|
const e = typeof t == "string" ? new URL(t) : new URL(t.href);
|
|
2154
2154
|
return e.hash = "", e;
|
|
2155
2155
|
}
|
|
@@ -2286,9 +2286,9 @@ async function Hs(t, {
|
|
|
2286
2286
|
);
|
|
2287
2287
|
}
|
|
2288
2288
|
if (u === "oauth")
|
|
2289
|
-
return
|
|
2289
|
+
return ct.parse(await l.json());
|
|
2290
2290
|
{
|
|
2291
|
-
const c =
|
|
2291
|
+
const c = Rs.parse(
|
|
2292
2292
|
await l.json()
|
|
2293
2293
|
);
|
|
2294
2294
|
if (!((s = c.code_challenge_methods_supported) != null && s.includes("S256")))
|
|
@@ -2327,11 +2327,11 @@ async function Zs(t, {
|
|
|
2327
2327
|
l
|
|
2328
2328
|
), c.searchParams.set("redirect_uri", String(s)), a && c.searchParams.set("state", a), n && c.searchParams.set("scope", n), n?.includes("offline_access") && c.searchParams.append("prompt", "consent"), i && c.searchParams.set("resource", i.href), { authorizationUrl: c, codeVerifier: g };
|
|
2329
2329
|
}
|
|
2330
|
-
function
|
|
2330
|
+
function ut(t, e) {
|
|
2331
2331
|
const r = t.client_secret !== void 0;
|
|
2332
2332
|
return e.length === 0 ? r ? "client_secret_post" : "none" : r && e.includes("client_secret_basic") ? "client_secret_basic" : r && e.includes("client_secret_post") ? "client_secret_post" : e.includes("none") ? "none" : r ? "client_secret_post" : "none";
|
|
2333
2333
|
}
|
|
2334
|
-
function
|
|
2334
|
+
function dt(t, e, r, s) {
|
|
2335
2335
|
const { client_id: n, client_secret: a } = e;
|
|
2336
2336
|
switch (t) {
|
|
2337
2337
|
case "client_secret_basic":
|
|
@@ -2364,7 +2364,7 @@ function Fs(t, e) {
|
|
|
2364
2364
|
async function Se(t) {
|
|
2365
2365
|
const e = t instanceof Response ? t.status : void 0, r = t instanceof Response ? await t.text() : t;
|
|
2366
2366
|
try {
|
|
2367
|
-
const s = Es.parse(JSON.parse(r)), { error: n, error_description: a, error_uri: i } = s, u =
|
|
2367
|
+
const s = Es.parse(JSON.parse(r)), { error: n, error_description: a, error_uri: i } = s, u = xs[n] || Z;
|
|
2368
2368
|
return new u({
|
|
2369
2369
|
message: a || "",
|
|
2370
2370
|
cause: i
|
|
@@ -2402,11 +2402,11 @@ async function Vs(t, {
|
|
|
2402
2402
|
if (u)
|
|
2403
2403
|
u(d, m, t, e);
|
|
2404
2404
|
else {
|
|
2405
|
-
const h = (c = e?.token_endpoint_auth_methods_supported) != null ? c : [], f =
|
|
2405
|
+
const h = (c = e?.token_endpoint_auth_methods_supported) != null ? c : [], f = ut(
|
|
2406
2406
|
r,
|
|
2407
2407
|
h
|
|
2408
2408
|
);
|
|
2409
|
-
|
|
2409
|
+
dt(f, r, d, m);
|
|
2410
2410
|
}
|
|
2411
2411
|
i && m.set("resource", i.href);
|
|
2412
2412
|
const y = await (l ?? fetch)(g, {
|
|
@@ -2416,7 +2416,7 @@ async function Vs(t, {
|
|
|
2416
2416
|
});
|
|
2417
2417
|
if (!y.ok)
|
|
2418
2418
|
throw await Se(y);
|
|
2419
|
-
return
|
|
2419
|
+
return it.parse(await y.json());
|
|
2420
2420
|
}
|
|
2421
2421
|
async function Js(t, {
|
|
2422
2422
|
metadata: e,
|
|
@@ -2446,11 +2446,11 @@ async function Js(t, {
|
|
|
2446
2446
|
if (a)
|
|
2447
2447
|
a(p, g, t, e);
|
|
2448
2448
|
else {
|
|
2449
|
-
const m = (u = e?.token_endpoint_auth_methods_supported) != null ? u : [], y =
|
|
2449
|
+
const m = (u = e?.token_endpoint_auth_methods_supported) != null ? u : [], y = ut(
|
|
2450
2450
|
r,
|
|
2451
2451
|
m
|
|
2452
2452
|
);
|
|
2453
|
-
|
|
2453
|
+
dt(y, r, p, g);
|
|
2454
2454
|
}
|
|
2455
2455
|
n && g.set("resource", n.href);
|
|
2456
2456
|
const d = await (i ?? fetch)(c, {
|
|
@@ -2460,7 +2460,7 @@ async function Js(t, {
|
|
|
2460
2460
|
});
|
|
2461
2461
|
if (!d.ok)
|
|
2462
2462
|
throw await Se(d);
|
|
2463
|
-
return
|
|
2463
|
+
return it.parse({
|
|
2464
2464
|
refresh_token: s,
|
|
2465
2465
|
...await d.json()
|
|
2466
2466
|
});
|
|
@@ -2503,7 +2503,7 @@ async function re(t, e) {
|
|
|
2503
2503
|
}
|
|
2504
2504
|
}
|
|
2505
2505
|
async function Bs(t, e, r) {
|
|
2506
|
-
const s =
|
|
2506
|
+
const s = Is(t);
|
|
2507
2507
|
if (e.validateResourceURL)
|
|
2508
2508
|
return await e.validateResourceURL(
|
|
2509
2509
|
s,
|
|
@@ -2637,10 +2637,10 @@ var Gs = class {
|
|
|
2637
2637
|
const r = await this.authProvider.tokens();
|
|
2638
2638
|
r?.access_token && (e.Authorization = `Bearer ${r.access_token}`);
|
|
2639
2639
|
}
|
|
2640
|
-
return
|
|
2640
|
+
return Fe(
|
|
2641
2641
|
e,
|
|
2642
|
-
`ai-sdk/${
|
|
2643
|
-
|
|
2642
|
+
`ai-sdk/${at}`,
|
|
2643
|
+
ze()
|
|
2644
2644
|
);
|
|
2645
2645
|
}
|
|
2646
2646
|
async start() {
|
|
@@ -2808,10 +2808,10 @@ var Gs = class {
|
|
|
2808
2808
|
const r = await this.authProvider.tokens();
|
|
2809
2809
|
r?.access_token && (e.Authorization = `Bearer ${r.access_token}`);
|
|
2810
2810
|
}
|
|
2811
|
-
return
|
|
2811
|
+
return Fe(
|
|
2812
2812
|
e,
|
|
2813
|
-
`ai-sdk/${
|
|
2814
|
-
|
|
2813
|
+
`ai-sdk/${at}`,
|
|
2814
|
+
ze()
|
|
2815
2815
|
);
|
|
2816
2816
|
}
|
|
2817
2817
|
async start() {
|
|
@@ -2901,17 +2901,17 @@ var Gs = class {
|
|
|
2901
2901
|
for (; ; ) {
|
|
2902
2902
|
const { done: O, value: H } = await b.read();
|
|
2903
2903
|
if (O) return;
|
|
2904
|
-
const { event:
|
|
2905
|
-
if (
|
|
2904
|
+
const { event: x, data: j } = H;
|
|
2905
|
+
if (x === "message")
|
|
2906
2906
|
try {
|
|
2907
2907
|
const z = V.parse(JSON.parse(j));
|
|
2908
2908
|
(A = this.onmessage) == null || A.call(this, z);
|
|
2909
2909
|
} catch (z) {
|
|
2910
|
-
const
|
|
2910
|
+
const I = new _({
|
|
2911
2911
|
message: "MCP HTTP Transport Error: Failed to parse message",
|
|
2912
2912
|
cause: z
|
|
2913
2913
|
});
|
|
2914
|
-
(M = this.onerror) == null || M.call(this,
|
|
2914
|
+
(M = this.onerror) == null || M.call(this, I);
|
|
2915
2915
|
}
|
|
2916
2916
|
}
|
|
2917
2917
|
} catch (O) {
|
|
@@ -3369,9 +3369,9 @@ var tn = class {
|
|
|
3369
3369
|
*/
|
|
3370
3370
|
async extractStructuredContent(t, e, r) {
|
|
3371
3371
|
if ("structuredContent" in t && t.structuredContent != null) {
|
|
3372
|
-
const s = await
|
|
3372
|
+
const s = await Ke({
|
|
3373
3373
|
value: t.structuredContent,
|
|
3374
|
-
schema:
|
|
3374
|
+
schema: Ge(e)
|
|
3375
3375
|
});
|
|
3376
3376
|
if (!s.success)
|
|
3377
3377
|
throw new _({
|
|
@@ -3430,7 +3430,7 @@ var tn = class {
|
|
|
3430
3430
|
return this.getPromptInternal({ name: t, args: e, options: r });
|
|
3431
3431
|
}
|
|
3432
3432
|
onElicitationRequest(t, e) {
|
|
3433
|
-
if (t !==
|
|
3433
|
+
if (t !== Ie)
|
|
3434
3434
|
throw new _({
|
|
3435
3435
|
message: "Unsupported request schema. Only ElicitationRequestSchema is supported."
|
|
3436
3436
|
});
|
|
@@ -3460,7 +3460,7 @@ var tn = class {
|
|
|
3460
3460
|
});
|
|
3461
3461
|
return;
|
|
3462
3462
|
}
|
|
3463
|
-
const e =
|
|
3463
|
+
const e = Ie.safeParse({
|
|
3464
3464
|
method: t.method,
|
|
3465
3465
|
params: t.params
|
|
3466
3466
|
});
|
|
@@ -3534,9 +3534,9 @@ const rn = async (t) => {
|
|
|
3534
3534
|
const r = await t.listTools();
|
|
3535
3535
|
for (const { name: s, description: n, inputSchema: a } of r.tools) {
|
|
3536
3536
|
const i = async (u, l) => t.callTool({ name: s, arguments: u }, { signal: l?.abortSignal });
|
|
3537
|
-
e[s] =
|
|
3537
|
+
e[s] = He({
|
|
3538
3538
|
description: n,
|
|
3539
|
-
inputSchema:
|
|
3539
|
+
inputSchema: Ze({
|
|
3540
3540
|
...a,
|
|
3541
3541
|
properties: a.properties ?? {},
|
|
3542
3542
|
additionalProperties: !1
|
|
@@ -3548,8 +3548,35 @@ const rn = async (t) => {
|
|
|
3548
3548
|
} catch (r) {
|
|
3549
3549
|
throw r;
|
|
3550
3550
|
}
|
|
3551
|
+
}, sn = async (t) => {
|
|
3552
|
+
const e = {};
|
|
3553
|
+
if (!t)
|
|
3554
|
+
return e;
|
|
3555
|
+
const r = t, s = r.listTools ?? r.getTools;
|
|
3556
|
+
if (!s)
|
|
3557
|
+
return e;
|
|
3558
|
+
const n = await s.call(r), a = Array.isArray(n) ? n : [];
|
|
3559
|
+
for (const i of a) {
|
|
3560
|
+
const { name: u, description: l, inputSchema: c = {} } = i, p = {
|
|
3561
|
+
type: "object",
|
|
3562
|
+
properties: c.properties ?? {},
|
|
3563
|
+
...c.required ? { required: c.required } : {},
|
|
3564
|
+
additionalProperties: !1,
|
|
3565
|
+
...c
|
|
3566
|
+
};
|
|
3567
|
+
e[u] = He({
|
|
3568
|
+
description: l ?? "",
|
|
3569
|
+
inputSchema: Ze(p),
|
|
3570
|
+
async execute(g) {
|
|
3571
|
+
if (!r.executeTool)
|
|
3572
|
+
throw new Error("navigator.modelContextTesting.executeTool is not available");
|
|
3573
|
+
return r.executeTool(u, JSON.stringify(g ?? {}));
|
|
3574
|
+
}
|
|
3575
|
+
});
|
|
3576
|
+
}
|
|
3577
|
+
return e;
|
|
3551
3578
|
};
|
|
3552
|
-
function
|
|
3579
|
+
function nn(t) {
|
|
3553
3580
|
const e = Object.entries(t);
|
|
3554
3581
|
if (e.length === 0)
|
|
3555
3582
|
return "";
|
|
@@ -3612,11 +3639,11 @@ function Ne(t, e) {
|
|
|
3612
3639
|
}
|
|
3613
3640
|
return null;
|
|
3614
3641
|
}
|
|
3615
|
-
const
|
|
3642
|
+
const on = {
|
|
3616
3643
|
openai: $t,
|
|
3617
3644
|
deepseek: jt
|
|
3618
3645
|
};
|
|
3619
|
-
class
|
|
3646
|
+
class Ln {
|
|
3620
3647
|
constructor({ llmConfig: e, mcpServers: r }) {
|
|
3621
3648
|
if (this.mcpServers = {}, this.mcpClients = {}, this.mcpTools = {}, this.ignoreToolnames = [], this.responseMessages = [], this.useReActMode = !1, !e)
|
|
3622
3649
|
throw new Error("llmConfig is required to initialize AgentModelProvider");
|
|
@@ -3625,7 +3652,7 @@ class xn {
|
|
|
3625
3652
|
else if (e.providerType) {
|
|
3626
3653
|
const s = e.providerType;
|
|
3627
3654
|
let n;
|
|
3628
|
-
typeof s == "string" ? n =
|
|
3655
|
+
typeof s == "string" ? n = on[s] : n = s, this.llm = n({
|
|
3629
3656
|
apiKey: e.apiKey,
|
|
3630
3657
|
baseURL: e.baseURL
|
|
3631
3658
|
});
|
|
@@ -3637,6 +3664,14 @@ class xn {
|
|
|
3637
3664
|
async _createOneClient(e) {
|
|
3638
3665
|
try {
|
|
3639
3666
|
let r;
|
|
3667
|
+
if ("type" in e && e.type === "builtin") {
|
|
3668
|
+
const n = e.client;
|
|
3669
|
+
return {
|
|
3670
|
+
tools: () => sn(n),
|
|
3671
|
+
close: async () => {
|
|
3672
|
+
}
|
|
3673
|
+
};
|
|
3674
|
+
}
|
|
3640
3675
|
if ("type" in e && e.type.toLocaleLowerCase() === "streamablehttp") {
|
|
3641
3676
|
const n = e, a = n.headers ? { headers: n.headers } : void 0;
|
|
3642
3677
|
r = new se(new URL(n.url), { requestInit: a });
|
|
@@ -3662,7 +3697,7 @@ class xn {
|
|
|
3662
3697
|
async _closeOneClient(e) {
|
|
3663
3698
|
try {
|
|
3664
3699
|
const r = e.__transport__;
|
|
3665
|
-
if (r && r instanceof Ut || r && r instanceof
|
|
3700
|
+
if (r && r instanceof Ut || r && r instanceof vt)
|
|
3666
3701
|
return;
|
|
3667
3702
|
await r?.terminateSession?.(), await r?.close?.(), await e?.close?.();
|
|
3668
3703
|
} catch {
|
|
@@ -3770,7 +3805,7 @@ class xn {
|
|
|
3770
3805
|
}
|
|
3771
3806
|
/** 生成 ReAct 模式的系统提示词(包含工具描述) */
|
|
3772
3807
|
_generateReActSystemPrompt(e, r, s) {
|
|
3773
|
-
const n =
|
|
3808
|
+
const n = nn(e);
|
|
3774
3809
|
return s ? `${s}${n}` : `你是一个智能助手,可以通过调用工具来完成任务。
|
|
3775
3810
|
${n}`;
|
|
3776
3811
|
}
|
|
@@ -3919,12 +3954,12 @@ ${T.success ? JSON.stringify(T.result) : `工具执行失败 - ${T.error}`}
|
|
|
3919
3954
|
v += O;
|
|
3920
3955
|
const H = { role: "assistant", content: v };
|
|
3921
3956
|
h.push(H), m.push(H);
|
|
3922
|
-
const
|
|
3923
|
-
if (!
|
|
3957
|
+
const x = Ne(v, r);
|
|
3958
|
+
if (!x) {
|
|
3924
3959
|
d.enqueue({ type: "text-end" }), d.enqueue({ type: "finish-step" }), d.enqueue({ type: "finish" }), d.close(), i.responseMessages = m, l({ messages: m });
|
|
3925
3960
|
return;
|
|
3926
3961
|
}
|
|
3927
|
-
if (
|
|
3962
|
+
if (x.toolName === "computer" && x.arguments?.action === "terminate") {
|
|
3928
3963
|
d.enqueue({ type: "text-end" }), d.enqueue({ type: "finish-step" }), d.enqueue({ type: "finish" }), d.close(), i.responseMessages = m, l({ messages: m });
|
|
3929
3964
|
return;
|
|
3930
3965
|
}
|
|
@@ -3932,9 +3967,9 @@ ${T.success ? JSON.stringify(T.result) : `工具执行失败 - ${T.error}`}
|
|
|
3932
3967
|
d.enqueue({
|
|
3933
3968
|
type: "tool-input-start",
|
|
3934
3969
|
id: j,
|
|
3935
|
-
toolName:
|
|
3970
|
+
toolName: x.toolName
|
|
3936
3971
|
});
|
|
3937
|
-
const z = JSON.stringify(
|
|
3972
|
+
const z = JSON.stringify(x.arguments, null, 2);
|
|
3938
3973
|
d.enqueue({
|
|
3939
3974
|
type: "tool-input-delta",
|
|
3940
3975
|
id: j,
|
|
@@ -3945,18 +3980,18 @@ ${T.success ? JSON.stringify(T.result) : `工具执行失败 - ${T.error}`}
|
|
|
3945
3980
|
}), d.enqueue({
|
|
3946
3981
|
type: "tool-call",
|
|
3947
3982
|
toolCallId: j,
|
|
3948
|
-
toolName:
|
|
3949
|
-
input:
|
|
3983
|
+
toolName: x.toolName,
|
|
3984
|
+
input: x.arguments
|
|
3950
3985
|
});
|
|
3951
|
-
const
|
|
3952
|
-
let B, N =
|
|
3953
|
-
if (
|
|
3954
|
-
B =
|
|
3955
|
-
const { screenshot: P, ...G } =
|
|
3986
|
+
const I = await i._executeReActToolCall(x.toolName, x.arguments, r);
|
|
3987
|
+
let B, N = I.result;
|
|
3988
|
+
if (I.success && I.result && typeof I.result == "object" && I.result.screenshot) {
|
|
3989
|
+
B = I.result.screenshot;
|
|
3990
|
+
const { screenshot: P, ...G } = I.result;
|
|
3956
3991
|
N = G;
|
|
3957
3992
|
}
|
|
3958
3993
|
let F = "";
|
|
3959
|
-
if (
|
|
3994
|
+
if (I.success) {
|
|
3960
3995
|
N && Array.isArray(N.content) && N.content.length > 0 && N.content[0].text ? F = N.content[0].text : F = JSON.stringify(N);
|
|
3961
3996
|
let P = `<tool_response>
|
|
3962
3997
|
${F}
|
|
@@ -3979,10 +4014,10 @@ ${F}
|
|
|
3979
4014
|
};
|
|
3980
4015
|
h.push(G), m.push(G), v = "";
|
|
3981
4016
|
} else
|
|
3982
|
-
F = `工具执行失败 - ${
|
|
4017
|
+
F = `工具执行失败 - ${I.error}`, d.enqueue({
|
|
3983
4018
|
type: "tool-error",
|
|
3984
4019
|
toolCallId: j,
|
|
3985
|
-
input:
|
|
4020
|
+
input: x.arguments,
|
|
3986
4021
|
error: { message: F }
|
|
3987
4022
|
});
|
|
3988
4023
|
}
|
|
@@ -4018,7 +4053,7 @@ ${F}
|
|
|
4018
4053
|
}, p = {
|
|
4019
4054
|
// @ts-ignore ProviderV2 是所有llm的父类, 在每一个具体的llm 类都有一个选择model的函数用法
|
|
4020
4055
|
model: this.llm(r),
|
|
4021
|
-
stopWhen:
|
|
4056
|
+
stopWhen: It(s),
|
|
4022
4057
|
...n,
|
|
4023
4058
|
tools: i,
|
|
4024
4059
|
prepareStep: c,
|
|
@@ -4045,24 +4080,24 @@ ${F}
|
|
|
4045
4080
|
}
|
|
4046
4081
|
}
|
|
4047
4082
|
export {
|
|
4048
|
-
|
|
4083
|
+
Ln as A,
|
|
4049
4084
|
zt as E,
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4085
|
+
bn as W,
|
|
4086
|
+
Tn as a,
|
|
4087
|
+
Rn as b,
|
|
4088
|
+
Sn as c,
|
|
4054
4089
|
qt as d,
|
|
4055
4090
|
Cn as e,
|
|
4056
|
-
|
|
4091
|
+
Mn as f,
|
|
4057
4092
|
rn as g,
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4093
|
+
En as h,
|
|
4094
|
+
Pn as i,
|
|
4095
|
+
An as j,
|
|
4061
4096
|
Ht as k,
|
|
4062
|
-
|
|
4063
|
-
|
|
4097
|
+
kn as l,
|
|
4098
|
+
On as m,
|
|
4064
4099
|
Dt as n,
|
|
4065
4100
|
In as o,
|
|
4066
4101
|
Zt as p,
|
|
4067
|
-
|
|
4102
|
+
xn as s
|
|
4068
4103
|
};
|