@opentiny/next-sdk 0.3.0-alpha.0 → 0.3.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/WebMcpClient.ts +7 -1
- package/agent/AgentModelProvider.ts +11 -1
- package/agent/type.ts +22 -1
- package/agent/utils/getBuiltinMcpTools.ts +86 -0
- package/dist/{AgentModelProvider-BIOOEdcN.js → AgentModelProvider-BnMj6YSC.js} +820 -706
- package/dist/WebMcpClient.d.ts +15 -8
- 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.d.ts +2 -0
- package/dist/index.es.dev.js +1872 -691
- package/dist/index.es.js +10777 -9902
- package/dist/index.js +1665 -917
- package/dist/index.umd.dev.js +1872 -691
- package/dist/index.umd.js +55 -52
- package/dist/page-tools/bridge.d.ts +15 -86
- package/dist/utils/builtinProxy.d.ts +7 -0
- package/dist/utils/env.d.ts +8 -0
- package/dist/webagent.dev.js +164 -9
- package/dist/webagent.es.dev.js +164 -9
- package/dist/webagent.es.js +3067 -2940
- package/dist/webagent.js +35 -35
- package/dist/webmcp-full.dev.js +79 -1
- package/dist/webmcp-full.es.dev.js +79 -1
- package/dist/webmcp-full.es.js +377 -314
- package/dist/webmcp-full.js +7 -7
- package/dist/webmcp.dev.js +79 -1
- package/dist/webmcp.es.dev.js +79 -1
- package/dist/webmcp.es.js +323 -260
- package/dist/webmcp.js +1 -1
- package/index.ts +17 -0
- package/package.json +2 -1
- package/page-tools/bridge.ts +168 -821
- package/page-tools/effects.ts +3 -1
- package/utils/builtinProxy.ts +90 -0
- package/utils/env.ts +13 -0
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { MessageChannelServerTransport as ge, createTransportPair as
|
|
2
|
-
import { McpServer as
|
|
3
|
-
import { SetLevelRequestSchema as
|
|
4
|
-
import { dynamicTool as
|
|
5
|
-
import { TypeValidationError as pe, JSONParseError as
|
|
6
|
-
import * as
|
|
1
|
+
import { MessageChannelServerTransport as ge, createTransportPair as ht, MessageChannelClientTransport as ye, sseOptions as mt, streamOptions as ft, createSseProxy as gt, createSocketProxy as yt, createStreamProxy as vt, MessageChannelTransport as wt } from "@opentiny/next";
|
|
2
|
+
import { McpServer as He } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { SetLevelRequestSchema as Ce, SubscribeRequestSchema as _t, UnsubscribeRequestSchema as bt, ListResourcesRequestSchema as St, RootsListChangedNotificationSchema as Tt, CallToolResultSchema as Ct, ElicitRequestSchema as Pt, CreateMessageRequestSchema as Rt, ListRootsRequestSchema as Mt, ToolListChangedNotificationSchema as Et, PromptListChangedNotificationSchema as At, ResourceListChangedNotificationSchema as kt, ResourceUpdatedNotificationSchema as Ot, LoggingMessageNotificationSchema as xt, JSONRPCMessageSchema as It } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
import { dynamicTool as Ze, jsonSchema as De, generateText as Pe, streamText as ie, stepCountIs as Lt } from "ai";
|
|
5
|
+
import { TypeValidationError as pe, JSONParseError as Re, InvalidArgumentError as jt, AISDKError as K } from "@ai-sdk/provider";
|
|
6
|
+
import * as Me 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";
|
|
10
10
|
import { SSEClientTransport as ne } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
11
11
|
import { InMemoryTransport as Ut } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
12
12
|
import { createOpenAI as $t } from "@ai-sdk/openai";
|
|
13
|
-
import { createDeepSeek as
|
|
14
|
-
import { Client as
|
|
15
|
-
import { WebSocketClientTransport as
|
|
16
|
-
class
|
|
13
|
+
import { createDeepSeek as Nt } from "@ai-sdk/deepseek";
|
|
14
|
+
import { Client as ze } from "@modelcontextprotocol/sdk/client/index.js";
|
|
15
|
+
import { WebSocketClientTransport as qt } from "@modelcontextprotocol/sdk/client/websocket.js";
|
|
16
|
+
class Tn {
|
|
17
17
|
constructor(e, r) {
|
|
18
18
|
const s = {
|
|
19
19
|
name: "web-mcp-server",
|
|
@@ -25,13 +25,13 @@ class _n {
|
|
|
25
25
|
completions: {},
|
|
26
26
|
logging: {}
|
|
27
27
|
};
|
|
28
|
-
this.server = new
|
|
28
|
+
this.server = new He(e || s, r || { capabilities: n }), this.server.server.oninitialized = () => {
|
|
29
29
|
this.oninitialized?.();
|
|
30
30
|
}, this.server.server.onclose = () => {
|
|
31
31
|
this.onclose?.();
|
|
32
32
|
}, this.server.server.onerror = (a) => {
|
|
33
33
|
this.onerror?.(a);
|
|
34
|
-
}, this.server.server.setRequestHandler(
|
|
34
|
+
}, this.server.server.setRequestHandler(Ce, async () => ({}));
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Connects the server to a transport via the specified option.
|
|
@@ -179,31 +179,31 @@ 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(_t, 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(bt, e);
|
|
189
189
|
}
|
|
190
190
|
/**
|
|
191
191
|
* Registers a handler for the set log level request.
|
|
192
192
|
*/
|
|
193
193
|
onSetLogLevel(e) {
|
|
194
|
-
this.server.server.setRequestHandler(
|
|
194
|
+
this.server.server.setRequestHandler(Ce, e);
|
|
195
195
|
}
|
|
196
196
|
/**
|
|
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(St, 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(Tt, e);
|
|
207
207
|
}
|
|
208
208
|
/**
|
|
209
209
|
* Close the transport for window.addEventListener('pagehide')
|
|
@@ -212,8 +212,71 @@ class _n {
|
|
|
212
212
|
e.persisted || this.transport && typeof this.transport.close == "function" && await this.transport.close();
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
|
-
const
|
|
216
|
-
|
|
215
|
+
const Cn = (t, e) => new ge(t, e), Pn = () => ht(), Rn = (t) => t instanceof ge, Mn = (t) => t instanceof He, Ht = (t) => {
|
|
216
|
+
t.onmessage = async (e) => {
|
|
217
|
+
if (!e || typeof e != "object") return;
|
|
218
|
+
const r = e.id;
|
|
219
|
+
try {
|
|
220
|
+
if (e.method === "initialize")
|
|
221
|
+
await t.send({
|
|
222
|
+
jsonrpc: "2.0",
|
|
223
|
+
id: r,
|
|
224
|
+
result: {
|
|
225
|
+
protocolVersion: "2024-11-05",
|
|
226
|
+
capabilities: { tools: {} },
|
|
227
|
+
serverInfo: { name: "browser-builtin-webmcp-proxy", version: "1.0.0" }
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
else if (e.method !== "notifications/initialized")
|
|
231
|
+
if (e.method === "ping" || e.method === "custom_ping")
|
|
232
|
+
await t.send({ jsonrpc: "2.0", id: r, result: {} });
|
|
233
|
+
else if (e.method === "tools/list") {
|
|
234
|
+
const s = typeof navigator < "u" ? navigator.modelContextTesting || navigator.modelContext : null;
|
|
235
|
+
if (s && s.listTools) {
|
|
236
|
+
const a = (await s.listTools()).map((i) => {
|
|
237
|
+
let c = {};
|
|
238
|
+
if (typeof i.inputSchema == "string")
|
|
239
|
+
try {
|
|
240
|
+
c = JSON.parse(i.inputSchema);
|
|
241
|
+
} catch (u) {
|
|
242
|
+
console.error("Failed to parse inputSchema:", u);
|
|
243
|
+
}
|
|
244
|
+
else typeof i.inputSchema == "object" && i.inputSchema !== null && (c = i.inputSchema);
|
|
245
|
+
return {
|
|
246
|
+
name: i.name,
|
|
247
|
+
description: i.description || "",
|
|
248
|
+
inputSchema: {
|
|
249
|
+
type: "object",
|
|
250
|
+
properties: c.properties || {},
|
|
251
|
+
required: c.required || []
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
});
|
|
255
|
+
await t.send({ jsonrpc: "2.0", id: r, result: { tools: a } });
|
|
256
|
+
} else
|
|
257
|
+
await t.send({ jsonrpc: "2.0", id: r, result: { tools: [] } });
|
|
258
|
+
} else if (e.method === "tools/call") {
|
|
259
|
+
const s = typeof navigator < "u" ? navigator.modelContextTesting || navigator.modelContext : null;
|
|
260
|
+
if (s && s.executeTool) {
|
|
261
|
+
const { name: n, arguments: a } = e.params, i = await s.executeTool(n, JSON.stringify(a || {})), c = i && typeof i == "object" && "content" in i ? i : { content: [{ type: "text", text: typeof i == "string" ? i : JSON.stringify(i) }] };
|
|
262
|
+
await t.send({ jsonrpc: "2.0", id: r, result: c });
|
|
263
|
+
} else
|
|
264
|
+
await t.send({
|
|
265
|
+
jsonrpc: "2.0",
|
|
266
|
+
id: r,
|
|
267
|
+
error: { code: -32601, message: "Browser built-in WebMCP not available" }
|
|
268
|
+
});
|
|
269
|
+
} else r !== void 0 && await t.send({
|
|
270
|
+
jsonrpc: "2.0",
|
|
271
|
+
id: r,
|
|
272
|
+
error: { code: -32601, message: `Method not found: ${e.method}` }
|
|
273
|
+
});
|
|
274
|
+
} catch (s) {
|
|
275
|
+
r !== void 0 && await t.send({ jsonrpc: "2.0", id: r, error: { code: -32e3, message: s.message || String(s) } });
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
class Zt {
|
|
217
280
|
constructor(e, r) {
|
|
218
281
|
const s = {
|
|
219
282
|
name: "web-mcp-client",
|
|
@@ -223,7 +286,7 @@ class qt {
|
|
|
223
286
|
sampling: {},
|
|
224
287
|
elicitation: {}
|
|
225
288
|
};
|
|
226
|
-
this.client = new
|
|
289
|
+
this.client = new ze(e || s, r || { capabilities: n }), this.client.onclose = () => {
|
|
227
290
|
this.onclose?.();
|
|
228
291
|
}, this.client.onerror = (a) => {
|
|
229
292
|
this.onerror?.(a);
|
|
@@ -235,28 +298,28 @@ class qt {
|
|
|
235
298
|
async connect(e) {
|
|
236
299
|
if (typeof e.start == "function")
|
|
237
300
|
return this.transport = e, this.transport.onclose = void 0, this.transport.onerror = void 0, this.transport.onmessage = void 0, await this.client.connect(this.transport), { transport: this.transport, sessionId: this.transport.sessionId };
|
|
238
|
-
const { url: r, token: s, sessionId: n, type: a, agent: i, onError: u } = e;
|
|
301
|
+
const { url: r, token: s, sessionId: n, type: a, agent: i, builtin: c, onError: u } = e;
|
|
239
302
|
if (i === !0) {
|
|
240
|
-
const
|
|
241
|
-
let
|
|
303
|
+
const m = { client: this.client, url: r, token: s, sessionId: n };
|
|
304
|
+
let d;
|
|
242
305
|
return await (async () => {
|
|
243
|
-
const { transport:
|
|
244
|
-
|
|
245
|
-
u?.(
|
|
246
|
-
},
|
|
247
|
-
})(),
|
|
306
|
+
const { transport: y, sessionId: h } = a === "sse" ? await gt(m) : a === "socket" ? await yt(m) : await vt(m);
|
|
307
|
+
y.onerror = async (f) => {
|
|
308
|
+
u?.(f);
|
|
309
|
+
}, c === !0 && Ht(y), d = { transport: y, sessionId: h };
|
|
310
|
+
})(), d;
|
|
248
311
|
}
|
|
249
312
|
const l = new URL(r);
|
|
250
|
-
let
|
|
251
|
-
if (a === "channel" && (
|
|
252
|
-
const
|
|
253
|
-
|
|
313
|
+
let p;
|
|
314
|
+
if (a === "channel" && (p = new ye(r), await this.client.connect(p)), a === "sse") {
|
|
315
|
+
const m = mt(s, n);
|
|
316
|
+
p = new ne(l, m), await this.client.connect(p);
|
|
254
317
|
}
|
|
255
|
-
if (a === "socket" && (
|
|
256
|
-
const
|
|
257
|
-
|
|
318
|
+
if (a === "socket" && (p = new qt(new URL(`${r}?sessionId=${n}&token=${s}`)), p.sessionId = n, await this.client.connect(p)), typeof p > "u") {
|
|
319
|
+
const m = ft(s, n);
|
|
320
|
+
p = new se(l, m), await this.client.connect(p);
|
|
258
321
|
}
|
|
259
|
-
return this.transport =
|
|
322
|
+
return this.transport = p, { transport: this.transport, sessionId: this.transport.sessionId };
|
|
260
323
|
}
|
|
261
324
|
/**
|
|
262
325
|
* Closes the connection.
|
|
@@ -346,7 +409,7 @@ class qt {
|
|
|
346
409
|
* Calls a tool on the server with the given parameters.
|
|
347
410
|
*/
|
|
348
411
|
async callTool(e, r) {
|
|
349
|
-
return await this.client.callTool(e,
|
|
412
|
+
return await this.client.callTool(e, Ct, r);
|
|
350
413
|
}
|
|
351
414
|
/**
|
|
352
415
|
* Lists all tools available on the server.
|
|
@@ -406,65 +469,65 @@ class qt {
|
|
|
406
469
|
* Registers a handler for the elicitation request.
|
|
407
470
|
*/
|
|
408
471
|
onElicit(e) {
|
|
409
|
-
this.client.setRequestHandler(
|
|
472
|
+
this.client.setRequestHandler(Pt, e);
|
|
410
473
|
}
|
|
411
474
|
/**
|
|
412
475
|
* Registers a handler for the create LLM message request.
|
|
413
476
|
*/
|
|
414
477
|
onCreateMessage(e) {
|
|
415
|
-
this.client.setRequestHandler(
|
|
478
|
+
this.client.setRequestHandler(Rt, e);
|
|
416
479
|
}
|
|
417
480
|
/**
|
|
418
481
|
* Registers a handler for the list roots request.
|
|
419
482
|
*/
|
|
420
483
|
onListRoots(e) {
|
|
421
|
-
this.client.setRequestHandler(
|
|
484
|
+
this.client.setRequestHandler(Mt, e);
|
|
422
485
|
}
|
|
423
486
|
/**
|
|
424
487
|
* Registers a handler for the tool list changed notification.
|
|
425
488
|
*/
|
|
426
489
|
onToolListChanged(e) {
|
|
427
|
-
this.client.setNotificationHandler(
|
|
490
|
+
this.client.setNotificationHandler(Et, e);
|
|
428
491
|
}
|
|
429
492
|
/**
|
|
430
493
|
* Registers a handler for the prompt list changed notification.
|
|
431
494
|
*/
|
|
432
495
|
onPromptListChanged(e) {
|
|
433
|
-
this.client.setNotificationHandler(
|
|
496
|
+
this.client.setNotificationHandler(At, e);
|
|
434
497
|
}
|
|
435
498
|
/**
|
|
436
499
|
* Registers a handler for the resource list changed notification.
|
|
437
500
|
*/
|
|
438
501
|
onResourceListChanged(e) {
|
|
439
|
-
this.client.setNotificationHandler(
|
|
502
|
+
this.client.setNotificationHandler(kt, e);
|
|
440
503
|
}
|
|
441
504
|
/**
|
|
442
505
|
* Registers a handler for the resource updated notification.
|
|
443
506
|
*/
|
|
444
507
|
onResourceUpdated(e) {
|
|
445
|
-
this.client.setNotificationHandler(
|
|
508
|
+
this.client.setNotificationHandler(Ot, e);
|
|
446
509
|
}
|
|
447
510
|
/**
|
|
448
511
|
* Registers a handler for the logging message notification.
|
|
449
512
|
*/
|
|
450
513
|
onLoggingMessage(e) {
|
|
451
|
-
this.client.setNotificationHandler(
|
|
514
|
+
this.client.setNotificationHandler(xt, e);
|
|
452
515
|
}
|
|
453
516
|
/**
|
|
454
517
|
* Close the transport for window.addEventListener('pagehide')
|
|
455
518
|
*/
|
|
456
519
|
async onPagehide(e) {
|
|
457
|
-
e.persisted || (
|
|
520
|
+
e.persisted || (Dt(this.transport) ? await this.transport.terminateSession() : this.transport && typeof this.transport.close == "function" && await this.transport.close());
|
|
458
521
|
}
|
|
459
522
|
}
|
|
460
|
-
const
|
|
523
|
+
const En = (t, e) => new ne(t, e), An = (t, e) => new se(t, e), kn = (t, e) => new ye(t, e), On = (t) => t instanceof ne, Dt = (t) => t instanceof se, xn = (t) => t instanceof ye, In = (t) => t instanceof ze, Ln = (t, e, r) => {
|
|
461
524
|
window.postMessage({ type: t, direction: r, data: e }, "*");
|
|
462
|
-
},
|
|
525
|
+
}, jn = (t, e, r) => {
|
|
463
526
|
const s = async function(n) {
|
|
464
527
|
n.source === window && n.data.type === t && n.data.direction === r && await e(n.data.data);
|
|
465
528
|
};
|
|
466
529
|
return window.addEventListener("message", s), () => window.removeEventListener("message", s);
|
|
467
|
-
},
|
|
530
|
+
}, zt = (t, e, r) => {
|
|
468
531
|
if (r.endsWith("content"))
|
|
469
532
|
chrome.tabs.query({}, (s) => {
|
|
470
533
|
s.forEach((n) => {
|
|
@@ -473,23 +536,23 @@ const Cn = (t, e) => new ne(t, e), Rn = (t, e) => new se(t, e), Mn = (t, e) => n
|
|
|
473
536
|
});
|
|
474
537
|
else
|
|
475
538
|
return chrome.runtime.sendMessage({ direction: r, type: t, data: e });
|
|
476
|
-
},
|
|
477
|
-
const n = (a, i,
|
|
539
|
+
}, Ft = (t, e, r, s) => {
|
|
540
|
+
const n = (a, i, c) => {
|
|
478
541
|
if (a.type === t && a.direction === r && (!s || s && a.tabId === s)) {
|
|
479
|
-
const { data:
|
|
480
|
-
e(
|
|
542
|
+
const { data: u } = a;
|
|
543
|
+
e(u, i, c), c(i);
|
|
481
544
|
}
|
|
482
545
|
};
|
|
483
546
|
return chrome.runtime.onMessage.addListener(n), () => chrome.runtime.onMessage.removeListener(n);
|
|
484
547
|
};
|
|
485
|
-
class
|
|
548
|
+
class Vt {
|
|
486
549
|
constructor(e) {
|
|
487
|
-
this._isStarted = !1, this._isClosed = !1, this.targetSessionId = e, this._messageListener =
|
|
550
|
+
this._isStarted = !1, this._isClosed = !1, this.targetSessionId = e, this._messageListener = Ft(
|
|
488
551
|
"mcp-server-to-client",
|
|
489
552
|
(r) => {
|
|
490
553
|
try {
|
|
491
554
|
if (r.sessionId !== this.targetSessionId) return;
|
|
492
|
-
const s =
|
|
555
|
+
const s = It.parse(r.mcpMessage);
|
|
493
556
|
this.onmessage?.(s);
|
|
494
557
|
} catch (s) {
|
|
495
558
|
console.log("【Client Transport】处理server消息错误:", s);
|
|
@@ -517,7 +580,7 @@ class zt {
|
|
|
517
580
|
const n = chrome.sessionRegistry.get(this.targetSessionId);
|
|
518
581
|
n && n.tabIds.length > 0 && (s = n.tabIds[n.tabIds.length - 1]);
|
|
519
582
|
}
|
|
520
|
-
s == null && (s = await chrome.runtime.sendMessage({ type: "get-session-tab-id", sessionId: this.targetSessionId })), this._throwError(() => s == null, `【Client Transport】后台未找到活动的tabId用于${this.targetSessionId}`),
|
|
583
|
+
s == null && (s = await chrome.runtime.sendMessage({ type: "get-session-tab-id", sessionId: this.targetSessionId })), this._throwError(() => s == null, `【Client Transport】后台未找到活动的tabId用于${this.targetSessionId}`), zt(
|
|
521
584
|
"mcp-client-to-server",
|
|
522
585
|
{ sessionId: this.targetSessionId, tabId: s, mcpMessage: e },
|
|
523
586
|
"bg->content"
|
|
@@ -533,29 +596,29 @@ class zt {
|
|
|
533
596
|
}
|
|
534
597
|
}
|
|
535
598
|
}
|
|
536
|
-
class
|
|
599
|
+
class Ee extends Error {
|
|
537
600
|
constructor(e, r) {
|
|
538
601
|
super(e), this.name = "ParseError", this.type = r.type, this.field = r.field, this.value = r.value, this.line = r.line;
|
|
539
602
|
}
|
|
540
603
|
}
|
|
541
604
|
function ce(t) {
|
|
542
605
|
}
|
|
543
|
-
function
|
|
606
|
+
function Jt(t) {
|
|
544
607
|
if (typeof t == "function")
|
|
545
608
|
throw new TypeError(
|
|
546
609
|
"`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
|
|
547
610
|
);
|
|
548
611
|
const { onEvent: e = ce, onError: r = ce, onRetry: s = ce, onComment: n } = t;
|
|
549
|
-
let a = "", i = !0,
|
|
612
|
+
let a = "", i = !0, c, u = "", l = "";
|
|
550
613
|
function p(h) {
|
|
551
|
-
const f = i ? h.replace(/^\xEF\xBB\xBF/, "") : h, [v, b] =
|
|
614
|
+
const f = i ? h.replace(/^\xEF\xBB\xBF/, "") : h, [v, b] = Wt(`${a}${f}`);
|
|
552
615
|
for (const T of v)
|
|
553
|
-
|
|
616
|
+
m(T);
|
|
554
617
|
a = b, i = !1;
|
|
555
618
|
}
|
|
556
|
-
function
|
|
619
|
+
function m(h) {
|
|
557
620
|
if (h === "") {
|
|
558
|
-
|
|
621
|
+
g();
|
|
559
622
|
return;
|
|
560
623
|
}
|
|
561
624
|
if (h.startsWith(":")) {
|
|
@@ -573,18 +636,18 @@ function Ft(t) {
|
|
|
573
636
|
function d(h, f, v) {
|
|
574
637
|
switch (h) {
|
|
575
638
|
case "event":
|
|
576
|
-
|
|
639
|
+
l = f;
|
|
577
640
|
break;
|
|
578
641
|
case "data":
|
|
579
|
-
|
|
642
|
+
u = `${u}${f}
|
|
580
643
|
`;
|
|
581
644
|
break;
|
|
582
645
|
case "id":
|
|
583
|
-
|
|
646
|
+
c = f.includes("\0") ? void 0 : f;
|
|
584
647
|
break;
|
|
585
648
|
case "retry":
|
|
586
649
|
/^\d+$/.test(f) ? s(parseInt(f, 10)) : r(
|
|
587
|
-
new
|
|
650
|
+
new Ee(`Invalid \`retry\` value: "${f}"`, {
|
|
588
651
|
type: "invalid-retry",
|
|
589
652
|
value: f,
|
|
590
653
|
line: v
|
|
@@ -593,7 +656,7 @@ function Ft(t) {
|
|
|
593
656
|
break;
|
|
594
657
|
default:
|
|
595
658
|
r(
|
|
596
|
-
new
|
|
659
|
+
new Ee(
|
|
597
660
|
`Unknown field "${h.length > 20 ? `${h.slice(0, 20)}…` : h}"`,
|
|
598
661
|
{ type: "unknown-field", field: h, value: f, line: v }
|
|
599
662
|
)
|
|
@@ -601,22 +664,22 @@ function Ft(t) {
|
|
|
601
664
|
break;
|
|
602
665
|
}
|
|
603
666
|
}
|
|
604
|
-
function
|
|
605
|
-
|
|
606
|
-
id:
|
|
607
|
-
event:
|
|
667
|
+
function g() {
|
|
668
|
+
u.length > 0 && e({
|
|
669
|
+
id: c,
|
|
670
|
+
event: l || void 0,
|
|
608
671
|
// If the data buffer's last character is a U+000A LINE FEED (LF) character,
|
|
609
672
|
// then remove the last character from the data buffer.
|
|
610
|
-
data:
|
|
611
|
-
`) ?
|
|
612
|
-
}),
|
|
673
|
+
data: u.endsWith(`
|
|
674
|
+
`) ? u.slice(0, -1) : u
|
|
675
|
+
}), c = void 0, u = "", l = "";
|
|
613
676
|
}
|
|
614
677
|
function y(h = {}) {
|
|
615
|
-
a && h.consume &&
|
|
678
|
+
a && h.consume && m(a), i = !0, c = void 0, u = "", l = "", a = "";
|
|
616
679
|
}
|
|
617
680
|
return { feed: p, reset: y };
|
|
618
681
|
}
|
|
619
|
-
function
|
|
682
|
+
function Wt(t) {
|
|
620
683
|
const e = [];
|
|
621
684
|
let r = "", s = 0;
|
|
622
685
|
for (; s < t.length; ) {
|
|
@@ -627,8 +690,8 @@ function Vt(t) {
|
|
|
627
690
|
r = t.slice(s);
|
|
628
691
|
break;
|
|
629
692
|
} else {
|
|
630
|
-
const
|
|
631
|
-
e.push(
|
|
693
|
+
const c = t.slice(s, i);
|
|
694
|
+
e.push(c), s = i + 1, t[s - 1] === "\r" && t[s] === `
|
|
632
695
|
` && s++;
|
|
633
696
|
}
|
|
634
697
|
}
|
|
@@ -639,7 +702,7 @@ class he extends TransformStream {
|
|
|
639
702
|
let n;
|
|
640
703
|
super({
|
|
641
704
|
start(a) {
|
|
642
|
-
n =
|
|
705
|
+
n = Jt({
|
|
643
706
|
onEvent: (i) => {
|
|
644
707
|
a.enqueue(i);
|
|
645
708
|
},
|
|
@@ -656,7 +719,7 @@ class he extends TransformStream {
|
|
|
656
719
|
});
|
|
657
720
|
}
|
|
658
721
|
}
|
|
659
|
-
var
|
|
722
|
+
var Bt = ({
|
|
660
723
|
prefix: t,
|
|
661
724
|
size: e = 16,
|
|
662
725
|
alphabet: r = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
@@ -664,25 +727,25 @@ var Jt = ({
|
|
|
664
727
|
} = {}) => {
|
|
665
728
|
const n = () => {
|
|
666
729
|
const a = r.length, i = new Array(e);
|
|
667
|
-
for (let
|
|
668
|
-
i[
|
|
730
|
+
for (let c = 0; c < e; c++)
|
|
731
|
+
i[c] = r[Math.random() * a | 0];
|
|
669
732
|
return i.join("");
|
|
670
733
|
};
|
|
671
734
|
if (t == null)
|
|
672
735
|
return n;
|
|
673
736
|
if (r.includes(s))
|
|
674
|
-
throw new
|
|
737
|
+
throw new jt({
|
|
675
738
|
argument: "separator",
|
|
676
739
|
message: `The separator "${s}" must not be part of the alphabet "${r}".`
|
|
677
740
|
});
|
|
678
741
|
return () => `${t}${s}${n()}`;
|
|
679
742
|
};
|
|
680
|
-
|
|
681
|
-
function
|
|
743
|
+
Bt();
|
|
744
|
+
function Fe(t = globalThis) {
|
|
682
745
|
var e, r, s;
|
|
683
746
|
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
747
|
}
|
|
685
|
-
function
|
|
748
|
+
function Gt(t) {
|
|
686
749
|
if (t == null)
|
|
687
750
|
return {};
|
|
688
751
|
const e = {};
|
|
@@ -697,19 +760,19 @@ function Wt(t) {
|
|
|
697
760
|
}
|
|
698
761
|
return e;
|
|
699
762
|
}
|
|
700
|
-
function
|
|
701
|
-
const r = new Headers(
|
|
763
|
+
function Ve(t, ...e) {
|
|
764
|
+
const r = new Headers(Gt(t)), s = r.get("user-agent") || "";
|
|
702
765
|
return r.set(
|
|
703
766
|
"user-agent",
|
|
704
767
|
[s, ...e].filter(Boolean).join(" ")
|
|
705
768
|
), Object.fromEntries(r.entries());
|
|
706
769
|
}
|
|
707
|
-
var
|
|
708
|
-
function
|
|
770
|
+
var Kt = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/, Xt = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
771
|
+
function Ae(t) {
|
|
709
772
|
const e = JSON.parse(t);
|
|
710
|
-
return e === null || typeof e != "object" ||
|
|
773
|
+
return e === null || typeof e != "object" || Kt.test(t) === !1 && Xt.test(t) === !1 ? e : Qt(e);
|
|
711
774
|
}
|
|
712
|
-
function
|
|
775
|
+
function Qt(t) {
|
|
713
776
|
let e = [t];
|
|
714
777
|
for (; e.length; ) {
|
|
715
778
|
const r = e;
|
|
@@ -727,15 +790,15 @@ function Kt(t) {
|
|
|
727
790
|
}
|
|
728
791
|
return t;
|
|
729
792
|
}
|
|
730
|
-
function
|
|
793
|
+
function Yt(t) {
|
|
731
794
|
const { stackTraceLimit: e } = Error;
|
|
732
795
|
try {
|
|
733
796
|
Error.stackTraceLimit = 0;
|
|
734
797
|
} catch {
|
|
735
|
-
return
|
|
798
|
+
return Ae(t);
|
|
736
799
|
}
|
|
737
800
|
try {
|
|
738
|
-
return
|
|
801
|
+
return Ae(t);
|
|
739
802
|
} finally {
|
|
740
803
|
Error.stackTraceLimit = e;
|
|
741
804
|
}
|
|
@@ -758,9 +821,9 @@ function ve(t) {
|
|
|
758
821
|
function q(t) {
|
|
759
822
|
return typeof t == "boolean" ? t : ve(t);
|
|
760
823
|
}
|
|
761
|
-
var
|
|
824
|
+
var er = /* @__PURE__ */ Symbol(
|
|
762
825
|
"Let zodToJsonSchema decide on which parser to use"
|
|
763
|
-
),
|
|
826
|
+
), ke = {
|
|
764
827
|
name: void 0,
|
|
765
828
|
$refStrategy: "root",
|
|
766
829
|
basePath: ["#"],
|
|
@@ -780,17 +843,17 @@ var Qt = /* @__PURE__ */ Symbol(
|
|
|
780
843
|
emailStrategy: "format:email",
|
|
781
844
|
base64Strategy: "contentEncoding:base64",
|
|
782
845
|
nameStrategy: "ref"
|
|
783
|
-
},
|
|
784
|
-
...
|
|
846
|
+
}, tr = (t) => typeof t == "string" ? {
|
|
847
|
+
...ke,
|
|
785
848
|
name: t
|
|
786
849
|
} : {
|
|
787
|
-
...
|
|
850
|
+
...ke,
|
|
788
851
|
...t
|
|
789
852
|
};
|
|
790
853
|
function E() {
|
|
791
854
|
return {};
|
|
792
855
|
}
|
|
793
|
-
function
|
|
856
|
+
function rr(t, e) {
|
|
794
857
|
var r, s, n;
|
|
795
858
|
const a = {
|
|
796
859
|
type: "array"
|
|
@@ -800,7 +863,7 @@ function er(t, e) {
|
|
|
800
863
|
currentPath: [...e.currentPath, "items"]
|
|
801
864
|
})), t.minLength && (a.minItems = t.minLength.value), t.maxLength && (a.maxItems = t.maxLength.value), t.exactLength && (a.minItems = t.exactLength.value, a.maxItems = t.exactLength.value), a;
|
|
802
865
|
}
|
|
803
|
-
function
|
|
866
|
+
function sr(t) {
|
|
804
867
|
const e = {
|
|
805
868
|
type: "integer",
|
|
806
869
|
format: "int64"
|
|
@@ -820,18 +883,18 @@ function tr(t) {
|
|
|
820
883
|
}
|
|
821
884
|
return e;
|
|
822
885
|
}
|
|
823
|
-
function
|
|
886
|
+
function nr() {
|
|
824
887
|
return { type: "boolean" };
|
|
825
888
|
}
|
|
826
|
-
function
|
|
889
|
+
function Je(t, e) {
|
|
827
890
|
return S(t.type._def, e);
|
|
828
891
|
}
|
|
829
|
-
var
|
|
830
|
-
function
|
|
892
|
+
var or = (t, e) => S(t.innerType._def, e);
|
|
893
|
+
function We(t, e, r) {
|
|
831
894
|
const s = r ?? e.dateStrategy;
|
|
832
895
|
if (Array.isArray(s))
|
|
833
896
|
return {
|
|
834
|
-
anyOf: s.map((n, a) =>
|
|
897
|
+
anyOf: s.map((n, a) => We(t, e, n))
|
|
835
898
|
};
|
|
836
899
|
switch (s) {
|
|
837
900
|
case "string":
|
|
@@ -846,10 +909,10 @@ function Fe(t, e, r) {
|
|
|
846
909
|
format: "date"
|
|
847
910
|
};
|
|
848
911
|
case "integer":
|
|
849
|
-
return
|
|
912
|
+
return ar(t);
|
|
850
913
|
}
|
|
851
914
|
}
|
|
852
|
-
var
|
|
915
|
+
var ar = (t) => {
|
|
853
916
|
const e = {
|
|
854
917
|
type: "integer",
|
|
855
918
|
format: "unix-time"
|
|
@@ -865,23 +928,23 @@ var nr = (t) => {
|
|
|
865
928
|
}
|
|
866
929
|
return e;
|
|
867
930
|
};
|
|
868
|
-
function
|
|
931
|
+
function ir(t, e) {
|
|
869
932
|
return {
|
|
870
933
|
...S(t.innerType._def, e),
|
|
871
934
|
default: t.defaultValue()
|
|
872
935
|
};
|
|
873
936
|
}
|
|
874
|
-
function
|
|
937
|
+
function cr(t, e) {
|
|
875
938
|
return e.effectStrategy === "input" ? S(t.schema._def, e) : E();
|
|
876
939
|
}
|
|
877
|
-
function
|
|
940
|
+
function lr(t) {
|
|
878
941
|
return {
|
|
879
942
|
type: "string",
|
|
880
943
|
enum: Array.from(t.values)
|
|
881
944
|
};
|
|
882
945
|
}
|
|
883
|
-
var
|
|
884
|
-
function
|
|
946
|
+
var ur = (t) => "type" in t && t.type === "string" ? !1 : "allOf" in t;
|
|
947
|
+
function dr(t, e) {
|
|
885
948
|
const r = [
|
|
886
949
|
S(t.left._def, {
|
|
887
950
|
...e,
|
|
@@ -893,19 +956,19 @@ function lr(t, e) {
|
|
|
893
956
|
})
|
|
894
957
|
].filter((n) => !!n), s = [];
|
|
895
958
|
return r.forEach((n) => {
|
|
896
|
-
if (
|
|
959
|
+
if (ur(n))
|
|
897
960
|
s.push(...n.allOf);
|
|
898
961
|
else {
|
|
899
962
|
let a = n;
|
|
900
963
|
if ("additionalProperties" in n && n.additionalProperties === !1) {
|
|
901
|
-
const { additionalProperties: i, ...
|
|
902
|
-
a =
|
|
964
|
+
const { additionalProperties: i, ...c } = n;
|
|
965
|
+
a = c;
|
|
903
966
|
}
|
|
904
967
|
s.push(a);
|
|
905
968
|
}
|
|
906
969
|
}), s.length ? { allOf: s } : void 0;
|
|
907
970
|
}
|
|
908
|
-
function
|
|
971
|
+
function pr(t) {
|
|
909
972
|
const e = typeof t.value;
|
|
910
973
|
return e !== "bigint" && e !== "number" && e !== "boolean" && e !== "string" ? {
|
|
911
974
|
type: Array.isArray(t.value) ? "array" : "object"
|
|
@@ -959,7 +1022,7 @@ var le = void 0, L = {
|
|
|
959
1022
|
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
960
1023
|
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
961
1024
|
};
|
|
962
|
-
function
|
|
1025
|
+
function Be(t, e) {
|
|
963
1026
|
const r = {
|
|
964
1027
|
type: "string"
|
|
965
1028
|
};
|
|
@@ -975,33 +1038,33 @@ function Ve(t, e) {
|
|
|
975
1038
|
case "email":
|
|
976
1039
|
switch (e.emailStrategy) {
|
|
977
1040
|
case "format:email":
|
|
978
|
-
|
|
1041
|
+
j(r, "email", s.message, e);
|
|
979
1042
|
break;
|
|
980
1043
|
case "format:idn-email":
|
|
981
|
-
|
|
1044
|
+
j(r, "idn-email", s.message, e);
|
|
982
1045
|
break;
|
|
983
1046
|
case "pattern:zod":
|
|
984
|
-
|
|
1047
|
+
P(r, L.email, s.message, e);
|
|
985
1048
|
break;
|
|
986
1049
|
}
|
|
987
1050
|
break;
|
|
988
1051
|
case "url":
|
|
989
|
-
|
|
1052
|
+
j(r, "uri", s.message, e);
|
|
990
1053
|
break;
|
|
991
1054
|
case "uuid":
|
|
992
|
-
|
|
1055
|
+
j(r, "uuid", s.message, e);
|
|
993
1056
|
break;
|
|
994
1057
|
case "regex":
|
|
995
|
-
|
|
1058
|
+
P(r, s.regex, s.message, e);
|
|
996
1059
|
break;
|
|
997
1060
|
case "cuid":
|
|
998
|
-
|
|
1061
|
+
P(r, L.cuid, s.message, e);
|
|
999
1062
|
break;
|
|
1000
1063
|
case "cuid2":
|
|
1001
|
-
|
|
1064
|
+
P(r, L.cuid2, s.message, e);
|
|
1002
1065
|
break;
|
|
1003
1066
|
case "startsWith":
|
|
1004
|
-
|
|
1067
|
+
P(
|
|
1005
1068
|
r,
|
|
1006
1069
|
RegExp(`^${ue(s.value, e)}`),
|
|
1007
1070
|
s.message,
|
|
@@ -1009,7 +1072,7 @@ function Ve(t, e) {
|
|
|
1009
1072
|
);
|
|
1010
1073
|
break;
|
|
1011
1074
|
case "endsWith":
|
|
1012
|
-
|
|
1075
|
+
P(
|
|
1013
1076
|
r,
|
|
1014
1077
|
RegExp(`${ue(s.value, e)}$`),
|
|
1015
1078
|
s.message,
|
|
@@ -1017,22 +1080,22 @@ function Ve(t, e) {
|
|
|
1017
1080
|
);
|
|
1018
1081
|
break;
|
|
1019
1082
|
case "datetime":
|
|
1020
|
-
|
|
1083
|
+
j(r, "date-time", s.message, e);
|
|
1021
1084
|
break;
|
|
1022
1085
|
case "date":
|
|
1023
|
-
|
|
1086
|
+
j(r, "date", s.message, e);
|
|
1024
1087
|
break;
|
|
1025
1088
|
case "time":
|
|
1026
|
-
|
|
1089
|
+
j(r, "time", s.message, e);
|
|
1027
1090
|
break;
|
|
1028
1091
|
case "duration":
|
|
1029
|
-
|
|
1092
|
+
j(r, "duration", s.message, e);
|
|
1030
1093
|
break;
|
|
1031
1094
|
case "length":
|
|
1032
1095
|
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
1096
|
break;
|
|
1034
1097
|
case "includes": {
|
|
1035
|
-
|
|
1098
|
+
P(
|
|
1036
1099
|
r,
|
|
1037
1100
|
RegExp(ue(s.value, e)),
|
|
1038
1101
|
s.message,
|
|
@@ -1041,30 +1104,30 @@ function Ve(t, e) {
|
|
|
1041
1104
|
break;
|
|
1042
1105
|
}
|
|
1043
1106
|
case "ip": {
|
|
1044
|
-
s.version !== "v6" &&
|
|
1107
|
+
s.version !== "v6" && j(r, "ipv4", s.message, e), s.version !== "v4" && j(r, "ipv6", s.message, e);
|
|
1045
1108
|
break;
|
|
1046
1109
|
}
|
|
1047
1110
|
case "base64url":
|
|
1048
|
-
|
|
1111
|
+
P(r, L.base64url, s.message, e);
|
|
1049
1112
|
break;
|
|
1050
1113
|
case "jwt":
|
|
1051
|
-
|
|
1114
|
+
P(r, L.jwt, s.message, e);
|
|
1052
1115
|
break;
|
|
1053
1116
|
case "cidr": {
|
|
1054
|
-
s.version !== "v6" &&
|
|
1117
|
+
s.version !== "v6" && P(r, L.ipv4Cidr, s.message, e), s.version !== "v4" && P(r, L.ipv6Cidr, s.message, e);
|
|
1055
1118
|
break;
|
|
1056
1119
|
}
|
|
1057
1120
|
case "emoji":
|
|
1058
|
-
|
|
1121
|
+
P(r, L.emoji(), s.message, e);
|
|
1059
1122
|
break;
|
|
1060
1123
|
case "ulid": {
|
|
1061
|
-
|
|
1124
|
+
P(r, L.ulid, s.message, e);
|
|
1062
1125
|
break;
|
|
1063
1126
|
}
|
|
1064
1127
|
case "base64": {
|
|
1065
1128
|
switch (e.base64Strategy) {
|
|
1066
1129
|
case "format:binary": {
|
|
1067
|
-
|
|
1130
|
+
j(r, "binary", s.message, e);
|
|
1068
1131
|
break;
|
|
1069
1132
|
}
|
|
1070
1133
|
case "contentEncoding:base64": {
|
|
@@ -1072,30 +1135,30 @@ function Ve(t, e) {
|
|
|
1072
1135
|
break;
|
|
1073
1136
|
}
|
|
1074
1137
|
case "pattern:zod": {
|
|
1075
|
-
|
|
1138
|
+
P(r, L.base64, s.message, e);
|
|
1076
1139
|
break;
|
|
1077
1140
|
}
|
|
1078
1141
|
}
|
|
1079
1142
|
break;
|
|
1080
1143
|
}
|
|
1081
1144
|
case "nanoid":
|
|
1082
|
-
|
|
1145
|
+
P(r, L.nanoid, s.message, e);
|
|
1083
1146
|
}
|
|
1084
1147
|
return r;
|
|
1085
1148
|
}
|
|
1086
1149
|
function ue(t, e) {
|
|
1087
|
-
return e.patternStrategy === "escape" ?
|
|
1150
|
+
return e.patternStrategy === "escape" ? mr(t) : t;
|
|
1088
1151
|
}
|
|
1089
|
-
var
|
|
1152
|
+
var hr = new Set(
|
|
1090
1153
|
"ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789"
|
|
1091
1154
|
);
|
|
1092
|
-
function
|
|
1155
|
+
function mr(t) {
|
|
1093
1156
|
let e = "";
|
|
1094
1157
|
for (let r = 0; r < t.length; r++)
|
|
1095
|
-
|
|
1158
|
+
hr.has(t[r]) || (e += "\\"), e += t[r];
|
|
1096
1159
|
return e;
|
|
1097
1160
|
}
|
|
1098
|
-
function
|
|
1161
|
+
function j(t, e, r, s) {
|
|
1099
1162
|
var n;
|
|
1100
1163
|
t.format || (n = t.anyOf) != null && n.some((a) => a.format) ? (t.anyOf || (t.anyOf = []), t.format && (t.anyOf.push({
|
|
1101
1164
|
format: t.format
|
|
@@ -1104,16 +1167,16 @@ function U(t, e, r, s) {
|
|
|
1104
1167
|
...r && s.errorMessages && { errorMessage: { format: r } }
|
|
1105
1168
|
})) : t.format = e;
|
|
1106
1169
|
}
|
|
1107
|
-
function
|
|
1170
|
+
function P(t, e, r, s) {
|
|
1108
1171
|
var n;
|
|
1109
1172
|
t.pattern || (n = t.allOf) != null && n.some((a) => a.pattern) ? (t.allOf || (t.allOf = []), t.pattern && (t.allOf.push({
|
|
1110
1173
|
pattern: t.pattern
|
|
1111
1174
|
}), delete t.pattern), t.allOf.push({
|
|
1112
|
-
pattern:
|
|
1175
|
+
pattern: Oe(e, s),
|
|
1113
1176
|
...r && s.errorMessages && { errorMessage: { pattern: r } }
|
|
1114
|
-
})) : t.pattern =
|
|
1177
|
+
})) : t.pattern = Oe(e, s);
|
|
1115
1178
|
}
|
|
1116
|
-
function
|
|
1179
|
+
function Oe(t, e) {
|
|
1117
1180
|
var r;
|
|
1118
1181
|
if (!e.applyRegexFlags || !t.flags)
|
|
1119
1182
|
return t.source;
|
|
@@ -1125,41 +1188,41 @@ function ke(t, e) {
|
|
|
1125
1188
|
s: t.flags.includes("s")
|
|
1126
1189
|
// `.` matches newlines
|
|
1127
1190
|
}, n = s.i ? t.source.toLowerCase() : t.source;
|
|
1128
|
-
let a = "", i = !1,
|
|
1129
|
-
for (let
|
|
1191
|
+
let a = "", i = !1, c = !1, u = !1;
|
|
1192
|
+
for (let l = 0; l < n.length; l++) {
|
|
1130
1193
|
if (i) {
|
|
1131
|
-
a += n[
|
|
1194
|
+
a += n[l], i = !1;
|
|
1132
1195
|
continue;
|
|
1133
1196
|
}
|
|
1134
1197
|
if (s.i) {
|
|
1135
|
-
if (
|
|
1136
|
-
if (n[
|
|
1137
|
-
|
|
1198
|
+
if (c) {
|
|
1199
|
+
if (n[l].match(/[a-z]/)) {
|
|
1200
|
+
u ? (a += n[l], a += `${n[l - 2]}-${n[l]}`.toUpperCase(), u = !1) : n[l + 1] === "-" && ((r = n[l + 2]) != null && r.match(/[a-z]/)) ? (a += n[l], u = !0) : a += `${n[l]}${n[l].toUpperCase()}`;
|
|
1138
1201
|
continue;
|
|
1139
1202
|
}
|
|
1140
|
-
} else if (n[
|
|
1141
|
-
a += `[${n[
|
|
1203
|
+
} else if (n[l].match(/[a-z]/)) {
|
|
1204
|
+
a += `[${n[l]}${n[l].toUpperCase()}]`;
|
|
1142
1205
|
continue;
|
|
1143
1206
|
}
|
|
1144
1207
|
}
|
|
1145
1208
|
if (s.m) {
|
|
1146
|
-
if (n[
|
|
1209
|
+
if (n[l] === "^") {
|
|
1147
1210
|
a += `(^|(?<=[\r
|
|
1148
1211
|
]))`;
|
|
1149
1212
|
continue;
|
|
1150
|
-
} else if (n[
|
|
1213
|
+
} else if (n[l] === "$") {
|
|
1151
1214
|
a += `($|(?=[\r
|
|
1152
1215
|
]))`;
|
|
1153
1216
|
continue;
|
|
1154
1217
|
}
|
|
1155
1218
|
}
|
|
1156
|
-
if (s.s && n[
|
|
1157
|
-
a +=
|
|
1158
|
-
` : `[${n[
|
|
1219
|
+
if (s.s && n[l] === ".") {
|
|
1220
|
+
a += c ? `${n[l]}\r
|
|
1221
|
+
` : `[${n[l]}\r
|
|
1159
1222
|
]`;
|
|
1160
1223
|
continue;
|
|
1161
1224
|
}
|
|
1162
|
-
a += n[
|
|
1225
|
+
a += n[l], n[l] === "\\" ? i = !0 : c && n[l] === "]" ? c = !1 : !c && n[l] === "[" && (c = !0);
|
|
1163
1226
|
}
|
|
1164
1227
|
try {
|
|
1165
1228
|
new RegExp(a);
|
|
@@ -1172,9 +1235,9 @@ function ke(t, e) {
|
|
|
1172
1235
|
}
|
|
1173
1236
|
return a;
|
|
1174
1237
|
}
|
|
1175
|
-
function
|
|
1176
|
-
var r, s, n, a, i,
|
|
1177
|
-
const
|
|
1238
|
+
function Ge(t, e) {
|
|
1239
|
+
var r, s, n, a, i, c;
|
|
1240
|
+
const u = {
|
|
1178
1241
|
type: "object",
|
|
1179
1242
|
additionalProperties: (r = S(t.valueType._def, {
|
|
1180
1243
|
...e,
|
|
@@ -1182,35 +1245,35 @@ function Je(t, e) {
|
|
|
1182
1245
|
})) != null ? r : e.allowedAdditionalProperties
|
|
1183
1246
|
};
|
|
1184
1247
|
if (((s = t.keyType) == null ? void 0 : s._def.typeName) === w.ZodString && ((n = t.keyType._def.checks) != null && n.length)) {
|
|
1185
|
-
const { type:
|
|
1248
|
+
const { type: l, ...p } = Be(t.keyType._def, e);
|
|
1186
1249
|
return {
|
|
1187
|
-
...
|
|
1250
|
+
...u,
|
|
1188
1251
|
propertyNames: p
|
|
1189
1252
|
};
|
|
1190
1253
|
} else {
|
|
1191
1254
|
if (((a = t.keyType) == null ? void 0 : a._def.typeName) === w.ZodEnum)
|
|
1192
1255
|
return {
|
|
1193
|
-
...
|
|
1256
|
+
...u,
|
|
1194
1257
|
propertyNames: {
|
|
1195
1258
|
enum: t.keyType._def.values
|
|
1196
1259
|
}
|
|
1197
1260
|
};
|
|
1198
|
-
if (((i = t.keyType) == null ? void 0 : i._def.typeName) === w.ZodBranded && t.keyType._def.type._def.typeName === w.ZodString && ((
|
|
1199
|
-
const { type:
|
|
1261
|
+
if (((i = t.keyType) == null ? void 0 : i._def.typeName) === w.ZodBranded && t.keyType._def.type._def.typeName === w.ZodString && ((c = t.keyType._def.type._def.checks) != null && c.length)) {
|
|
1262
|
+
const { type: l, ...p } = Je(
|
|
1200
1263
|
t.keyType._def,
|
|
1201
1264
|
e
|
|
1202
1265
|
);
|
|
1203
1266
|
return {
|
|
1204
|
-
...
|
|
1267
|
+
...u,
|
|
1205
1268
|
propertyNames: p
|
|
1206
1269
|
};
|
|
1207
1270
|
}
|
|
1208
1271
|
}
|
|
1209
|
-
return
|
|
1272
|
+
return u;
|
|
1210
1273
|
}
|
|
1211
|
-
function
|
|
1274
|
+
function fr(t, e) {
|
|
1212
1275
|
if (e.mapStrategy === "record")
|
|
1213
|
-
return
|
|
1276
|
+
return Ge(t, e);
|
|
1214
1277
|
const r = S(t.keyType._def, {
|
|
1215
1278
|
...e,
|
|
1216
1279
|
currentPath: [...e.currentPath, "items", "items", "0"]
|
|
@@ -1229,7 +1292,7 @@ function hr(t, e) {
|
|
|
1229
1292
|
}
|
|
1230
1293
|
};
|
|
1231
1294
|
}
|
|
1232
|
-
function
|
|
1295
|
+
function gr(t) {
|
|
1233
1296
|
const e = t.values, s = Object.keys(t.values).filter((a) => typeof e[e[a]] != "number").map((a) => e[a]), n = Array.from(
|
|
1234
1297
|
new Set(s.map((a) => typeof a))
|
|
1235
1298
|
);
|
|
@@ -1238,10 +1301,10 @@ function mr(t) {
|
|
|
1238
1301
|
enum: s
|
|
1239
1302
|
};
|
|
1240
1303
|
}
|
|
1241
|
-
function
|
|
1304
|
+
function yr() {
|
|
1242
1305
|
return { not: E() };
|
|
1243
1306
|
}
|
|
1244
|
-
function
|
|
1307
|
+
function vr() {
|
|
1245
1308
|
return {
|
|
1246
1309
|
type: "null"
|
|
1247
1310
|
};
|
|
@@ -1253,7 +1316,7 @@ var me = {
|
|
|
1253
1316
|
ZodBoolean: "boolean",
|
|
1254
1317
|
ZodNull: "null"
|
|
1255
1318
|
};
|
|
1256
|
-
function
|
|
1319
|
+
function wr(t, e) {
|
|
1257
1320
|
const r = t.options instanceof Map ? Array.from(t.options.values()) : t.options;
|
|
1258
1321
|
if (r.every(
|
|
1259
1322
|
(s) => s._def.typeName in me && (!s._def.checks || !s._def.checks.length)
|
|
@@ -1288,7 +1351,7 @@ function yr(t, e) {
|
|
|
1288
1351
|
[]
|
|
1289
1352
|
);
|
|
1290
1353
|
if (s.length === r.length) {
|
|
1291
|
-
const n = s.filter((a, i,
|
|
1354
|
+
const n = s.filter((a, i, c) => c.indexOf(a) === i);
|
|
1292
1355
|
return {
|
|
1293
1356
|
type: n.length > 1 ? n : n[0],
|
|
1294
1357
|
enum: r.reduce(
|
|
@@ -1308,9 +1371,9 @@ function yr(t, e) {
|
|
|
1308
1371
|
[]
|
|
1309
1372
|
)
|
|
1310
1373
|
};
|
|
1311
|
-
return
|
|
1374
|
+
return _r(t, e);
|
|
1312
1375
|
}
|
|
1313
|
-
var
|
|
1376
|
+
var _r = (t, e) => {
|
|
1314
1377
|
const r = (t.options instanceof Map ? Array.from(t.options.values()) : t.options).map(
|
|
1315
1378
|
(s, n) => S(s._def, {
|
|
1316
1379
|
...e,
|
|
@@ -1321,7 +1384,7 @@ var vr = (t, e) => {
|
|
|
1321
1384
|
);
|
|
1322
1385
|
return r.length ? { anyOf: r } : void 0;
|
|
1323
1386
|
};
|
|
1324
|
-
function
|
|
1387
|
+
function br(t, e) {
|
|
1325
1388
|
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(
|
|
1326
1389
|
t.innerType._def.typeName
|
|
1327
1390
|
) && (!t.innerType._def.checks || !t.innerType._def.checks.length))
|
|
@@ -1337,7 +1400,7 @@ function wr(t, e) {
|
|
|
1337
1400
|
});
|
|
1338
1401
|
return r && { anyOf: [r, { type: "null" }] };
|
|
1339
1402
|
}
|
|
1340
|
-
function
|
|
1403
|
+
function Sr(t) {
|
|
1341
1404
|
const e = {
|
|
1342
1405
|
type: "number"
|
|
1343
1406
|
};
|
|
@@ -1359,27 +1422,27 @@ function _r(t) {
|
|
|
1359
1422
|
}
|
|
1360
1423
|
return e;
|
|
1361
1424
|
}
|
|
1362
|
-
function
|
|
1425
|
+
function Tr(t, e) {
|
|
1363
1426
|
const r = {
|
|
1364
1427
|
type: "object",
|
|
1365
1428
|
properties: {}
|
|
1366
1429
|
}, s = [], n = t.shape();
|
|
1367
1430
|
for (const i in n) {
|
|
1368
|
-
let
|
|
1369
|
-
if (
|
|
1431
|
+
let c = n[i];
|
|
1432
|
+
if (c === void 0 || c._def === void 0)
|
|
1370
1433
|
continue;
|
|
1371
|
-
const
|
|
1434
|
+
const u = Pr(c), l = S(c._def, {
|
|
1372
1435
|
...e,
|
|
1373
1436
|
currentPath: [...e.currentPath, "properties", i],
|
|
1374
1437
|
propertyPath: [...e.currentPath, "properties", i]
|
|
1375
1438
|
});
|
|
1376
|
-
|
|
1439
|
+
l !== void 0 && (r.properties[i] = l, u || s.push(i));
|
|
1377
1440
|
}
|
|
1378
1441
|
s.length && (r.required = s);
|
|
1379
|
-
const a =
|
|
1442
|
+
const a = Cr(t, e);
|
|
1380
1443
|
return a !== void 0 && (r.additionalProperties = a), r;
|
|
1381
1444
|
}
|
|
1382
|
-
function
|
|
1445
|
+
function Cr(t, e) {
|
|
1383
1446
|
if (t.catchall._def.typeName !== "ZodNever")
|
|
1384
1447
|
return S(t.catchall._def, {
|
|
1385
1448
|
...e,
|
|
@@ -1394,14 +1457,14 @@ function Sr(t, e) {
|
|
|
1394
1457
|
return e.removeAdditionalStrategy === "strict" ? e.allowedAdditionalProperties : e.rejectedAdditionalProperties;
|
|
1395
1458
|
}
|
|
1396
1459
|
}
|
|
1397
|
-
function
|
|
1460
|
+
function Pr(t) {
|
|
1398
1461
|
try {
|
|
1399
1462
|
return t.isOptional();
|
|
1400
1463
|
} catch {
|
|
1401
1464
|
return !0;
|
|
1402
1465
|
}
|
|
1403
1466
|
}
|
|
1404
|
-
var
|
|
1467
|
+
var Rr = (t, e) => {
|
|
1405
1468
|
var r;
|
|
1406
1469
|
if (e.currentPath.toString() === ((r = e.propertyPath) == null ? void 0 : r.toString()))
|
|
1407
1470
|
return S(t.innerType._def, e);
|
|
@@ -1410,7 +1473,7 @@ var Pr = (t, e) => {
|
|
|
1410
1473
|
currentPath: [...e.currentPath, "anyOf", "1"]
|
|
1411
1474
|
});
|
|
1412
1475
|
return s ? { anyOf: [{ not: E() }, s] } : E();
|
|
1413
|
-
},
|
|
1476
|
+
}, Mr = (t, e) => {
|
|
1414
1477
|
if (e.pipeStrategy === "input")
|
|
1415
1478
|
return S(t.in._def, e);
|
|
1416
1479
|
if (e.pipeStrategy === "output")
|
|
@@ -1426,10 +1489,10 @@ var Pr = (t, e) => {
|
|
|
1426
1489
|
allOf: [r, s].filter((n) => n !== void 0)
|
|
1427
1490
|
};
|
|
1428
1491
|
};
|
|
1429
|
-
function
|
|
1492
|
+
function Er(t, e) {
|
|
1430
1493
|
return S(t.type._def, e);
|
|
1431
1494
|
}
|
|
1432
|
-
function
|
|
1495
|
+
function Ar(t, e) {
|
|
1433
1496
|
const s = {
|
|
1434
1497
|
type: "array",
|
|
1435
1498
|
uniqueItems: !0,
|
|
@@ -1440,7 +1503,7 @@ function Mr(t, e) {
|
|
|
1440
1503
|
};
|
|
1441
1504
|
return t.minSize && (s.minItems = t.minSize.value), t.maxSize && (s.maxItems = t.maxSize.value), s;
|
|
1442
1505
|
}
|
|
1443
|
-
function
|
|
1506
|
+
function kr(t, e) {
|
|
1444
1507
|
return t.rest ? {
|
|
1445
1508
|
type: "array",
|
|
1446
1509
|
minItems: t.items.length,
|
|
@@ -1472,80 +1535,80 @@ function Er(t, e) {
|
|
|
1472
1535
|
)
|
|
1473
1536
|
};
|
|
1474
1537
|
}
|
|
1475
|
-
function
|
|
1538
|
+
function Or() {
|
|
1476
1539
|
return {
|
|
1477
1540
|
not: E()
|
|
1478
1541
|
};
|
|
1479
1542
|
}
|
|
1480
|
-
function
|
|
1543
|
+
function xr() {
|
|
1481
1544
|
return E();
|
|
1482
1545
|
}
|
|
1483
|
-
var
|
|
1546
|
+
var Ir = (t, e) => S(t.innerType._def, e), Lr = (t, e, r) => {
|
|
1484
1547
|
switch (e) {
|
|
1485
1548
|
case w.ZodString:
|
|
1486
|
-
return
|
|
1549
|
+
return Be(t, r);
|
|
1487
1550
|
case w.ZodNumber:
|
|
1488
|
-
return
|
|
1551
|
+
return Sr(t);
|
|
1489
1552
|
case w.ZodObject:
|
|
1490
|
-
return
|
|
1553
|
+
return Tr(t, r);
|
|
1491
1554
|
case w.ZodBigInt:
|
|
1492
|
-
return
|
|
1555
|
+
return sr(t);
|
|
1493
1556
|
case w.ZodBoolean:
|
|
1494
|
-
return
|
|
1557
|
+
return nr();
|
|
1495
1558
|
case w.ZodDate:
|
|
1496
|
-
return
|
|
1559
|
+
return We(t, r);
|
|
1497
1560
|
case w.ZodUndefined:
|
|
1498
|
-
return
|
|
1561
|
+
return Or();
|
|
1499
1562
|
case w.ZodNull:
|
|
1500
|
-
return
|
|
1563
|
+
return vr();
|
|
1501
1564
|
case w.ZodArray:
|
|
1502
|
-
return
|
|
1565
|
+
return rr(t, r);
|
|
1503
1566
|
case w.ZodUnion:
|
|
1504
1567
|
case w.ZodDiscriminatedUnion:
|
|
1505
|
-
return
|
|
1568
|
+
return wr(t, r);
|
|
1506
1569
|
case w.ZodIntersection:
|
|
1507
|
-
return
|
|
1570
|
+
return dr(t, r);
|
|
1508
1571
|
case w.ZodTuple:
|
|
1509
|
-
return
|
|
1572
|
+
return kr(t, r);
|
|
1510
1573
|
case w.ZodRecord:
|
|
1511
|
-
return
|
|
1574
|
+
return Ge(t, r);
|
|
1512
1575
|
case w.ZodLiteral:
|
|
1513
|
-
return
|
|
1576
|
+
return pr(t);
|
|
1514
1577
|
case w.ZodEnum:
|
|
1515
|
-
return
|
|
1578
|
+
return lr(t);
|
|
1516
1579
|
case w.ZodNativeEnum:
|
|
1517
|
-
return
|
|
1580
|
+
return gr(t);
|
|
1518
1581
|
case w.ZodNullable:
|
|
1519
|
-
return
|
|
1582
|
+
return br(t, r);
|
|
1520
1583
|
case w.ZodOptional:
|
|
1521
|
-
return
|
|
1584
|
+
return Rr(t, r);
|
|
1522
1585
|
case w.ZodMap:
|
|
1523
|
-
return
|
|
1586
|
+
return fr(t, r);
|
|
1524
1587
|
case w.ZodSet:
|
|
1525
|
-
return
|
|
1588
|
+
return Ar(t, r);
|
|
1526
1589
|
case w.ZodLazy:
|
|
1527
1590
|
return () => t.getter()._def;
|
|
1528
1591
|
case w.ZodPromise:
|
|
1529
|
-
return
|
|
1592
|
+
return Er(t, r);
|
|
1530
1593
|
case w.ZodNaN:
|
|
1531
1594
|
case w.ZodNever:
|
|
1532
|
-
return
|
|
1595
|
+
return yr();
|
|
1533
1596
|
case w.ZodEffects:
|
|
1534
|
-
return
|
|
1597
|
+
return cr(t, r);
|
|
1535
1598
|
case w.ZodAny:
|
|
1536
1599
|
return E();
|
|
1537
1600
|
case w.ZodUnknown:
|
|
1538
|
-
return
|
|
1601
|
+
return xr();
|
|
1539
1602
|
case w.ZodDefault:
|
|
1540
|
-
return
|
|
1603
|
+
return ir(t, r);
|
|
1541
1604
|
case w.ZodBranded:
|
|
1542
|
-
return
|
|
1605
|
+
return Je(t, r);
|
|
1543
1606
|
case w.ZodReadonly:
|
|
1544
|
-
return
|
|
1607
|
+
return Ir(t, r);
|
|
1545
1608
|
case w.ZodCatch:
|
|
1546
|
-
return
|
|
1609
|
+
return or(t, r);
|
|
1547
1610
|
case w.ZodPipeline:
|
|
1548
|
-
return
|
|
1611
|
+
return Mr(t, r);
|
|
1549
1612
|
case w.ZodFunction:
|
|
1550
1613
|
case w.ZodVoid:
|
|
1551
1614
|
case w.ZodSymbol:
|
|
@@ -1554,7 +1617,7 @@ var Or = (t, e) => S(t.innerType._def, e), Ir = (t, e, r) => {
|
|
|
1554
1617
|
return /* @__PURE__ */ ((s) => {
|
|
1555
1618
|
})();
|
|
1556
1619
|
}
|
|
1557
|
-
},
|
|
1620
|
+
}, jr = (t, e) => {
|
|
1558
1621
|
let r = 0;
|
|
1559
1622
|
for (; r < t.length && r < e.length && t[r] === e[r]; r++)
|
|
1560
1623
|
;
|
|
@@ -1564,36 +1627,36 @@ function S(t, e, r = !1) {
|
|
|
1564
1627
|
var s;
|
|
1565
1628
|
const n = e.seen.get(t);
|
|
1566
1629
|
if (e.override) {
|
|
1567
|
-
const
|
|
1630
|
+
const u = (s = e.override) == null ? void 0 : s.call(
|
|
1568
1631
|
e,
|
|
1569
1632
|
t,
|
|
1570
1633
|
e,
|
|
1571
1634
|
n,
|
|
1572
1635
|
r
|
|
1573
1636
|
);
|
|
1574
|
-
if (
|
|
1575
|
-
return
|
|
1637
|
+
if (u !== er)
|
|
1638
|
+
return u;
|
|
1576
1639
|
}
|
|
1577
1640
|
if (n && !r) {
|
|
1578
|
-
const
|
|
1579
|
-
if (
|
|
1580
|
-
return
|
|
1641
|
+
const u = Ur(n, e);
|
|
1642
|
+
if (u !== void 0)
|
|
1643
|
+
return u;
|
|
1581
1644
|
}
|
|
1582
1645
|
const a = { def: t, path: e.currentPath, jsonSchema: void 0 };
|
|
1583
1646
|
e.seen.set(t, a);
|
|
1584
|
-
const i =
|
|
1585
|
-
if (
|
|
1586
|
-
const
|
|
1587
|
-
return a.jsonSchema =
|
|
1647
|
+
const i = Lr(t, t.typeName, e), c = typeof i == "function" ? S(i(), e) : i;
|
|
1648
|
+
if (c && $r(t, e, c), e.postProcess) {
|
|
1649
|
+
const u = e.postProcess(c, t, e);
|
|
1650
|
+
return a.jsonSchema = c, u;
|
|
1588
1651
|
}
|
|
1589
|
-
return a.jsonSchema =
|
|
1652
|
+
return a.jsonSchema = c, c;
|
|
1590
1653
|
}
|
|
1591
|
-
var
|
|
1654
|
+
var Ur = (t, e) => {
|
|
1592
1655
|
switch (e.$refStrategy) {
|
|
1593
1656
|
case "root":
|
|
1594
1657
|
return { $ref: t.path.join("/") };
|
|
1595
1658
|
case "relative":
|
|
1596
|
-
return { $ref:
|
|
1659
|
+
return { $ref: jr(e.currentPath, t.path) };
|
|
1597
1660
|
case "none":
|
|
1598
1661
|
case "seen":
|
|
1599
1662
|
return t.path.length < e.currentPath.length && t.path.every((r, s) => e.currentPath[s] === r) ? (console.warn(
|
|
@@ -1602,8 +1665,8 @@ var Lr = (t, e) => {
|
|
|
1602
1665
|
)}! Defaulting to any`
|
|
1603
1666
|
), E()) : e.$refStrategy === "seen" ? E() : void 0;
|
|
1604
1667
|
}
|
|
1605
|
-
},
|
|
1606
|
-
const e =
|
|
1668
|
+
}, $r = (t, e, r) => (t.description && (r.description = t.description), r), Nr = (t) => {
|
|
1669
|
+
const e = tr(t), r = e.name !== void 0 ? [...e.basePath, e.definitionPath, e.name] : e.basePath;
|
|
1607
1670
|
return {
|
|
1608
1671
|
...e,
|
|
1609
1672
|
currentPath: r,
|
|
@@ -1620,16 +1683,16 @@ var Lr = (t, e) => {
|
|
|
1620
1683
|
])
|
|
1621
1684
|
)
|
|
1622
1685
|
};
|
|
1623
|
-
},
|
|
1686
|
+
}, qr = (t, e) => {
|
|
1624
1687
|
var r;
|
|
1625
|
-
const s =
|
|
1688
|
+
const s = Nr(e);
|
|
1626
1689
|
let n = typeof e == "object" && e.definitions ? Object.entries(e.definitions).reduce(
|
|
1627
|
-
(
|
|
1690
|
+
(l, [p, m]) => {
|
|
1628
1691
|
var d;
|
|
1629
1692
|
return {
|
|
1630
|
-
...
|
|
1693
|
+
...l,
|
|
1631
1694
|
[p]: (d = S(
|
|
1632
|
-
|
|
1695
|
+
m._def,
|
|
1633
1696
|
{
|
|
1634
1697
|
...s,
|
|
1635
1698
|
currentPath: [...s.basePath, s.definitionPath, p]
|
|
@@ -1647,9 +1710,9 @@ var Lr = (t, e) => {
|
|
|
1647
1710
|
currentPath: [...s.basePath, s.definitionPath, a]
|
|
1648
1711
|
},
|
|
1649
1712
|
!1
|
|
1650
|
-
)) != null ? r : E(),
|
|
1651
|
-
|
|
1652
|
-
const
|
|
1713
|
+
)) != null ? r : E(), c = typeof e == "object" && e.name !== void 0 && e.nameStrategy === "title" ? e.name : void 0;
|
|
1714
|
+
c !== void 0 && (i.title = c);
|
|
1715
|
+
const u = a === void 0 ? n ? {
|
|
1653
1716
|
...i,
|
|
1654
1717
|
[s.definitionPath]: n
|
|
1655
1718
|
} : i : {
|
|
@@ -1663,7 +1726,7 @@ var Lr = (t, e) => {
|
|
|
1663
1726
|
[a]: i
|
|
1664
1727
|
}
|
|
1665
1728
|
};
|
|
1666
|
-
return
|
|
1729
|
+
return u.$schema = "http://json-schema.org/draft-07/schema#", u;
|
|
1667
1730
|
}, fe = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
1668
1731
|
function J(t, {
|
|
1669
1732
|
validate: e
|
|
@@ -1678,13 +1741,13 @@ function J(t, {
|
|
|
1678
1741
|
validate: e
|
|
1679
1742
|
};
|
|
1680
1743
|
}
|
|
1681
|
-
function
|
|
1744
|
+
function Hr(t) {
|
|
1682
1745
|
return typeof t == "object" && t !== null && fe in t && t[fe] === !0 && "jsonSchema" in t && "validate" in t;
|
|
1683
1746
|
}
|
|
1684
|
-
function
|
|
1685
|
-
return t == null ? J({ properties: {}, additionalProperties: !1 }) :
|
|
1747
|
+
function Ke(t) {
|
|
1748
|
+
return t == null ? J({ properties: {}, additionalProperties: !1 }) : Hr(t) ? t : "~standard" in t ? t["~standard"].vendor === "zod" ? Vr(t) : Zr(t) : t();
|
|
1686
1749
|
}
|
|
1687
|
-
function
|
|
1750
|
+
function Zr(t) {
|
|
1688
1751
|
return J(
|
|
1689
1752
|
() => ve(
|
|
1690
1753
|
t["~standard"].jsonSchema.input({
|
|
@@ -1705,12 +1768,12 @@ function qr(t) {
|
|
|
1705
1768
|
}
|
|
1706
1769
|
);
|
|
1707
1770
|
}
|
|
1708
|
-
function
|
|
1771
|
+
function Dr(t, e) {
|
|
1709
1772
|
var r;
|
|
1710
1773
|
const s = (r = void 0) != null ? r : !1;
|
|
1711
1774
|
return J(
|
|
1712
1775
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
1713
|
-
() =>
|
|
1776
|
+
() => qr(t, {
|
|
1714
1777
|
$refStrategy: s ? "root" : "none"
|
|
1715
1778
|
}),
|
|
1716
1779
|
{
|
|
@@ -1721,13 +1784,13 @@ function Hr(t, e) {
|
|
|
1721
1784
|
}
|
|
1722
1785
|
);
|
|
1723
1786
|
}
|
|
1724
|
-
function
|
|
1787
|
+
function zr(t, e) {
|
|
1725
1788
|
var r;
|
|
1726
1789
|
const s = (r = void 0) != null ? r : !1;
|
|
1727
1790
|
return J(
|
|
1728
1791
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
1729
1792
|
() => ve(
|
|
1730
|
-
|
|
1793
|
+
Me.toJSONSchema(t, {
|
|
1731
1794
|
target: "draft-7",
|
|
1732
1795
|
io: "input",
|
|
1733
1796
|
reused: s ? "ref" : "inline"
|
|
@@ -1735,24 +1798,24 @@ function Zr(t, e) {
|
|
|
1735
1798
|
),
|
|
1736
1799
|
{
|
|
1737
1800
|
validate: async (n) => {
|
|
1738
|
-
const a = await
|
|
1801
|
+
const a = await Me.safeParseAsync(t, n);
|
|
1739
1802
|
return a.success ? { success: !0, value: a.data } : { success: !1, error: a.error };
|
|
1740
1803
|
}
|
|
1741
1804
|
}
|
|
1742
1805
|
);
|
|
1743
1806
|
}
|
|
1744
|
-
function
|
|
1807
|
+
function Fr(t) {
|
|
1745
1808
|
return "_zod" in t;
|
|
1746
1809
|
}
|
|
1747
|
-
function
|
|
1748
|
-
return
|
|
1810
|
+
function Vr(t, e) {
|
|
1811
|
+
return Fr(t) ? zr(t) : Dr(t);
|
|
1749
1812
|
}
|
|
1750
|
-
async function
|
|
1813
|
+
async function Xe({
|
|
1751
1814
|
value: t,
|
|
1752
1815
|
schema: e,
|
|
1753
1816
|
context: r
|
|
1754
1817
|
}) {
|
|
1755
|
-
const s =
|
|
1818
|
+
const s = Ke(e);
|
|
1756
1819
|
try {
|
|
1757
1820
|
if (s.validate == null)
|
|
1758
1821
|
return { success: !0, value: t, rawValue: t };
|
|
@@ -1770,56 +1833,56 @@ async function Be({
|
|
|
1770
1833
|
};
|
|
1771
1834
|
}
|
|
1772
1835
|
}
|
|
1773
|
-
async function
|
|
1836
|
+
async function Jr({
|
|
1774
1837
|
text: t,
|
|
1775
1838
|
schema: e
|
|
1776
1839
|
}) {
|
|
1777
1840
|
try {
|
|
1778
|
-
const r =
|
|
1779
|
-
return e == null ? { success: !0, value: r, rawValue: r } : await
|
|
1841
|
+
const r = Yt(t);
|
|
1842
|
+
return e == null ? { success: !0, value: r, rawValue: r } : await Xe({ value: r, schema: e });
|
|
1780
1843
|
} catch (r) {
|
|
1781
1844
|
return {
|
|
1782
1845
|
success: !1,
|
|
1783
|
-
error:
|
|
1846
|
+
error: Re.isInstance(r) ? r : new Re({ text: t, cause: r }),
|
|
1784
1847
|
rawValue: void 0
|
|
1785
1848
|
};
|
|
1786
1849
|
}
|
|
1787
1850
|
}
|
|
1788
|
-
function
|
|
1851
|
+
function Wr(t) {
|
|
1789
1852
|
return { ...t, type: "dynamic" };
|
|
1790
1853
|
}
|
|
1791
1854
|
let we;
|
|
1792
1855
|
we = globalThis.crypto;
|
|
1793
|
-
async function
|
|
1856
|
+
async function Br(t) {
|
|
1794
1857
|
return (await we).getRandomValues(new Uint8Array(t));
|
|
1795
1858
|
}
|
|
1796
|
-
async function
|
|
1859
|
+
async function Gr(t) {
|
|
1797
1860
|
const e = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~", r = Math.pow(2, 8) - Math.pow(2, 8) % e.length;
|
|
1798
1861
|
let s = "";
|
|
1799
1862
|
for (; s.length < t; ) {
|
|
1800
|
-
const n = await
|
|
1863
|
+
const n = await Br(t - s.length);
|
|
1801
1864
|
for (const a of n)
|
|
1802
1865
|
a < r && (s += e[a % e.length]);
|
|
1803
1866
|
}
|
|
1804
1867
|
return s;
|
|
1805
1868
|
}
|
|
1806
|
-
async function
|
|
1807
|
-
return await
|
|
1869
|
+
async function Kr(t) {
|
|
1870
|
+
return await Gr(t);
|
|
1808
1871
|
}
|
|
1809
|
-
async function
|
|
1872
|
+
async function Xr(t) {
|
|
1810
1873
|
const e = await (await we).subtle.digest("SHA-256", new TextEncoder().encode(t));
|
|
1811
1874
|
return btoa(String.fromCharCode(...new Uint8Array(e))).replace(/\//g, "_").replace(/\+/g, "-").replace(/=/g, "");
|
|
1812
1875
|
}
|
|
1813
|
-
async function
|
|
1876
|
+
async function Qr(t) {
|
|
1814
1877
|
if (t || (t = 43), t < 43 || t > 128)
|
|
1815
1878
|
throw `Expected a length between 43 and 128. Received ${t}.`;
|
|
1816
|
-
const e = await
|
|
1879
|
+
const e = await Kr(t), r = await Xr(e);
|
|
1817
1880
|
return {
|
|
1818
1881
|
code_verifier: e,
|
|
1819
1882
|
code_challenge: r
|
|
1820
1883
|
};
|
|
1821
1884
|
}
|
|
1822
|
-
var
|
|
1885
|
+
var Yr = "AI_MCPClientError", Qe = `vercel.ai.error.${Yr}`, es = Symbol.for(Qe), xe, Ie, _ = class extends (Ie = K, xe = es, Ie) {
|
|
1823
1886
|
constructor({
|
|
1824
1887
|
name: t = "MCPClientError",
|
|
1825
1888
|
message: e,
|
|
@@ -1827,27 +1890,27 @@ var Xr = "AI_MCPClientError", Ge = `vercel.ai.error.${Xr}`, Qr = Symbol.for(Ge),
|
|
|
1827
1890
|
data: s,
|
|
1828
1891
|
code: n
|
|
1829
1892
|
}) {
|
|
1830
|
-
super({ name: t, message: e, cause: r }), this[
|
|
1893
|
+
super({ name: t, message: e, cause: r }), this[xe] = !0, this.data = s, this.code = n;
|
|
1831
1894
|
}
|
|
1832
1895
|
static isInstance(t) {
|
|
1833
|
-
return K.hasMarker(t,
|
|
1896
|
+
return K.hasMarker(t, Qe);
|
|
1834
1897
|
}
|
|
1835
|
-
}, D = "2025-11-25",
|
|
1898
|
+
}, D = "2025-11-25", ts = [
|
|
1836
1899
|
D,
|
|
1837
1900
|
"2025-06-18",
|
|
1838
1901
|
"2025-03-26",
|
|
1839
1902
|
"2024-11-05"
|
|
1840
|
-
],
|
|
1903
|
+
], rs = o.optional(o.record(o.string(), o.unknown())), ss = o.looseObject({
|
|
1841
1904
|
name: o.string(),
|
|
1842
1905
|
version: o.string()
|
|
1843
1906
|
}), oe = o.looseObject({
|
|
1844
1907
|
_meta: o.optional(o.object({}).loose())
|
|
1845
|
-
}),
|
|
1908
|
+
}), U = oe, Ye = o.object({
|
|
1846
1909
|
method: o.string(),
|
|
1847
1910
|
params: o.optional(oe)
|
|
1848
|
-
}),
|
|
1911
|
+
}), et = o.object({
|
|
1849
1912
|
applyDefaults: o.optional(o.boolean())
|
|
1850
|
-
}).loose(),
|
|
1913
|
+
}).loose(), ns = o.looseObject({
|
|
1851
1914
|
experimental: o.optional(o.object({}).loose()),
|
|
1852
1915
|
logging: o.optional(o.object({}).loose()),
|
|
1853
1916
|
prompts: o.optional(
|
|
@@ -1866,19 +1929,19 @@ var Xr = "AI_MCPClientError", Ge = `vercel.ai.error.${Xr}`, Qr = Symbol.for(Ge),
|
|
|
1866
1929
|
listChanged: o.optional(o.boolean())
|
|
1867
1930
|
})
|
|
1868
1931
|
),
|
|
1869
|
-
elicitation: o.optional(
|
|
1932
|
+
elicitation: o.optional(et)
|
|
1870
1933
|
});
|
|
1871
1934
|
o.object({
|
|
1872
|
-
elicitation: o.optional(
|
|
1935
|
+
elicitation: o.optional(et)
|
|
1873
1936
|
}).loose();
|
|
1874
|
-
var
|
|
1937
|
+
var os = U.extend({
|
|
1875
1938
|
protocolVersion: o.string(),
|
|
1876
|
-
capabilities:
|
|
1877
|
-
serverInfo:
|
|
1939
|
+
capabilities: ns,
|
|
1940
|
+
serverInfo: ss,
|
|
1878
1941
|
instructions: o.optional(o.string())
|
|
1879
|
-
}), _e =
|
|
1942
|
+
}), _e = U.extend({
|
|
1880
1943
|
nextCursor: o.optional(o.string())
|
|
1881
|
-
}),
|
|
1944
|
+
}), as = o.object({
|
|
1882
1945
|
name: o.string(),
|
|
1883
1946
|
/**
|
|
1884
1947
|
* @see https://modelcontextprotocol.io/specification/2025-11-25/server/tools#tool
|
|
@@ -1898,26 +1961,26 @@ var ss = $.extend({
|
|
|
1898
1961
|
title: o.optional(o.string())
|
|
1899
1962
|
}).loose()
|
|
1900
1963
|
),
|
|
1901
|
-
_meta:
|
|
1902
|
-
}).loose(),
|
|
1903
|
-
tools: o.array(
|
|
1904
|
-
}),
|
|
1964
|
+
_meta: rs
|
|
1965
|
+
}).loose(), is = _e.extend({
|
|
1966
|
+
tools: o.array(as)
|
|
1967
|
+
}), tt = o.object({
|
|
1905
1968
|
type: o.literal("text"),
|
|
1906
1969
|
text: o.string()
|
|
1907
|
-
}).loose(),
|
|
1970
|
+
}).loose(), rt = o.object({
|
|
1908
1971
|
type: o.literal("image"),
|
|
1909
1972
|
data: o.base64(),
|
|
1910
1973
|
mimeType: o.string()
|
|
1911
|
-
}).loose(),
|
|
1974
|
+
}).loose(), cs = o.object({
|
|
1912
1975
|
uri: o.string(),
|
|
1913
1976
|
name: o.string(),
|
|
1914
1977
|
title: o.optional(o.string()),
|
|
1915
1978
|
description: o.optional(o.string()),
|
|
1916
1979
|
mimeType: o.optional(o.string()),
|
|
1917
1980
|
size: o.optional(o.number())
|
|
1918
|
-
}).loose(),
|
|
1919
|
-
resources: o.array(
|
|
1920
|
-
}),
|
|
1981
|
+
}).loose(), ls = _e.extend({
|
|
1982
|
+
resources: o.array(cs)
|
|
1983
|
+
}), st = o.object({
|
|
1921
1984
|
/**
|
|
1922
1985
|
* The URI of this resource.
|
|
1923
1986
|
*/
|
|
@@ -1934,16 +1997,16 @@ var ss = $.extend({
|
|
|
1934
1997
|
* The MIME type of this resource, if known.
|
|
1935
1998
|
*/
|
|
1936
1999
|
mimeType: o.optional(o.string())
|
|
1937
|
-
}).loose(),
|
|
2000
|
+
}).loose(), nt = st.extend({
|
|
1938
2001
|
text: o.string()
|
|
1939
|
-
}),
|
|
2002
|
+
}), ot = st.extend({
|
|
1940
2003
|
blob: o.base64()
|
|
1941
|
-
}),
|
|
2004
|
+
}), at = o.object({
|
|
1942
2005
|
type: o.literal("resource"),
|
|
1943
|
-
resource: o.union([
|
|
1944
|
-
}).loose(),
|
|
2006
|
+
resource: o.union([nt, ot])
|
|
2007
|
+
}).loose(), us = U.extend({
|
|
1945
2008
|
content: o.array(
|
|
1946
|
-
o.union([
|
|
2009
|
+
o.union([tt, rt, at])
|
|
1947
2010
|
),
|
|
1948
2011
|
/**
|
|
1949
2012
|
* @see https://modelcontextprotocol.io/specification/2025-06-18/server/tools#structured-content
|
|
@@ -1951,63 +2014,63 @@ var ss = $.extend({
|
|
|
1951
2014
|
structuredContent: o.optional(o.unknown()),
|
|
1952
2015
|
isError: o.boolean().default(!1).optional()
|
|
1953
2016
|
}).or(
|
|
1954
|
-
|
|
2017
|
+
U.extend({
|
|
1955
2018
|
toolResult: o.unknown()
|
|
1956
2019
|
})
|
|
1957
|
-
),
|
|
2020
|
+
), ds = o.object({
|
|
1958
2021
|
uriTemplate: o.string(),
|
|
1959
2022
|
name: o.string(),
|
|
1960
2023
|
title: o.optional(o.string()),
|
|
1961
2024
|
description: o.optional(o.string()),
|
|
1962
2025
|
mimeType: o.optional(o.string())
|
|
1963
|
-
}).loose(),
|
|
1964
|
-
resourceTemplates: o.array(
|
|
1965
|
-
}),
|
|
2026
|
+
}).loose(), ps = U.extend({
|
|
2027
|
+
resourceTemplates: o.array(ds)
|
|
2028
|
+
}), hs = U.extend({
|
|
1966
2029
|
contents: o.array(
|
|
1967
|
-
o.union([
|
|
2030
|
+
o.union([nt, ot])
|
|
1968
2031
|
)
|
|
1969
|
-
}),
|
|
2032
|
+
}), ms = o.object({
|
|
1970
2033
|
name: o.string(),
|
|
1971
2034
|
description: o.optional(o.string()),
|
|
1972
2035
|
required: o.optional(o.boolean())
|
|
1973
|
-
}).loose(),
|
|
2036
|
+
}).loose(), fs = o.object({
|
|
1974
2037
|
name: o.string(),
|
|
1975
2038
|
title: o.optional(o.string()),
|
|
1976
2039
|
description: o.optional(o.string()),
|
|
1977
|
-
arguments: o.optional(o.array(
|
|
1978
|
-
}).loose(),
|
|
1979
|
-
prompts: o.array(
|
|
1980
|
-
}),
|
|
2040
|
+
arguments: o.optional(o.array(ms))
|
|
2041
|
+
}).loose(), gs = _e.extend({
|
|
2042
|
+
prompts: o.array(fs)
|
|
2043
|
+
}), ys = o.object({
|
|
1981
2044
|
role: o.union([o.literal("user"), o.literal("assistant")]),
|
|
1982
2045
|
content: o.union([
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
2046
|
+
tt,
|
|
2047
|
+
rt,
|
|
2048
|
+
at
|
|
1986
2049
|
])
|
|
1987
|
-
}).loose(),
|
|
2050
|
+
}).loose(), vs = U.extend({
|
|
1988
2051
|
description: o.optional(o.string()),
|
|
1989
|
-
messages: o.array(
|
|
1990
|
-
}),
|
|
2052
|
+
messages: o.array(ys)
|
|
2053
|
+
}), ws = oe.extend({
|
|
1991
2054
|
message: o.string(),
|
|
1992
2055
|
requestedSchema: o.unknown()
|
|
1993
|
-
}),
|
|
2056
|
+
}), Le = Ye.extend({
|
|
1994
2057
|
method: o.literal("elicitation/create"),
|
|
1995
|
-
params:
|
|
1996
|
-
}),
|
|
2058
|
+
params: ws
|
|
2059
|
+
}), _s = U.extend({
|
|
1997
2060
|
action: o.union([
|
|
1998
2061
|
o.literal("accept"),
|
|
1999
2062
|
o.literal("decline"),
|
|
2000
2063
|
o.literal("cancel")
|
|
2001
2064
|
]),
|
|
2002
2065
|
content: o.optional(o.record(o.string(), o.unknown()))
|
|
2003
|
-
}), ae = "2.0",
|
|
2066
|
+
}), ae = "2.0", bs = o.object({
|
|
2004
2067
|
jsonrpc: o.literal(ae),
|
|
2005
2068
|
id: o.union([o.string(), o.number().int()])
|
|
2006
|
-
}).merge(
|
|
2069
|
+
}).merge(Ye).strict(), Ss = o.object({
|
|
2007
2070
|
jsonrpc: o.literal(ae),
|
|
2008
2071
|
id: o.union([o.string(), o.number().int()]),
|
|
2009
|
-
result:
|
|
2010
|
-
}).strict(),
|
|
2072
|
+
result: U
|
|
2073
|
+
}).strict(), Ts = o.object({
|
|
2011
2074
|
jsonrpc: o.literal(ae),
|
|
2012
2075
|
id: o.union([o.string(), o.number().int()]),
|
|
2013
2076
|
error: o.object({
|
|
@@ -2015,7 +2078,7 @@ var ss = $.extend({
|
|
|
2015
2078
|
message: o.string(),
|
|
2016
2079
|
data: o.optional(o.unknown())
|
|
2017
2080
|
})
|
|
2018
|
-
}).strict(),
|
|
2081
|
+
}).strict(), Cs = o.object({
|
|
2019
2082
|
jsonrpc: o.literal(ae)
|
|
2020
2083
|
}).merge(
|
|
2021
2084
|
o.object({
|
|
@@ -2023,11 +2086,11 @@ var ss = $.extend({
|
|
|
2023
2086
|
params: o.optional(oe)
|
|
2024
2087
|
})
|
|
2025
2088
|
).strict(), V = o.union([
|
|
2026
|
-
|
|
2089
|
+
bs,
|
|
2090
|
+
Cs,
|
|
2027
2091
|
Ss,
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
]), nt = typeof __PACKAGE_VERSION__ < "u" ? __PACKAGE_VERSION__ : "0.0.0-test", ot = o.object({
|
|
2092
|
+
Ts
|
|
2093
|
+
]), it = typeof __PACKAGE_VERSION__ < "u" ? __PACKAGE_VERSION__ : "0.0.0-test", ct = o.object({
|
|
2031
2094
|
access_token: o.string(),
|
|
2032
2095
|
id_token: o.string().optional(),
|
|
2033
2096
|
// Optional for OAuth 2.1, but necessary in OpenID Connect
|
|
@@ -2048,7 +2111,7 @@ var ss = $.extend({
|
|
|
2048
2111
|
return e.protocol !== "javascript:" && e.protocol !== "data:" && e.protocol !== "vbscript:";
|
|
2049
2112
|
},
|
|
2050
2113
|
{ message: "URL cannot use javascript:, data:, or vbscript: scheme" }
|
|
2051
|
-
),
|
|
2114
|
+
), Ps = o.object({
|
|
2052
2115
|
resource: o.string().url(),
|
|
2053
2116
|
authorization_servers: o.array(R).optional(),
|
|
2054
2117
|
jwks_uri: o.string().url().optional(),
|
|
@@ -2063,7 +2126,7 @@ var ss = $.extend({
|
|
|
2063
2126
|
authorization_details_types_supported: o.array(o.string()).optional(),
|
|
2064
2127
|
dpop_signing_alg_values_supported: o.array(o.string()).optional(),
|
|
2065
2128
|
dpop_bound_access_tokens_required: o.boolean().optional()
|
|
2066
|
-
}).passthrough(),
|
|
2129
|
+
}).passthrough(), lt = o.object({
|
|
2067
2130
|
issuer: o.string(),
|
|
2068
2131
|
authorization_endpoint: R,
|
|
2069
2132
|
token_endpoint: R,
|
|
@@ -2074,7 +2137,7 @@ var ss = $.extend({
|
|
|
2074
2137
|
code_challenge_methods_supported: o.array(o.string()),
|
|
2075
2138
|
token_endpoint_auth_methods_supported: o.array(o.string()).optional(),
|
|
2076
2139
|
token_endpoint_auth_signing_alg_values_supported: o.array(o.string()).optional()
|
|
2077
|
-
}).passthrough(),
|
|
2140
|
+
}).passthrough(), Rs = o.object({
|
|
2078
2141
|
issuer: o.string(),
|
|
2079
2142
|
authorization_endpoint: R,
|
|
2080
2143
|
token_endpoint: R,
|
|
@@ -2088,16 +2151,16 @@ var ss = $.extend({
|
|
|
2088
2151
|
id_token_signing_alg_values_supported: o.array(o.string()),
|
|
2089
2152
|
claims_supported: o.array(o.string()).optional(),
|
|
2090
2153
|
token_endpoint_auth_methods_supported: o.array(o.string()).optional()
|
|
2091
|
-
}).passthrough(),
|
|
2092
|
-
|
|
2154
|
+
}).passthrough(), Ms = Rs.merge(
|
|
2155
|
+
lt.pick({
|
|
2093
2156
|
code_challenge_methods_supported: !0
|
|
2094
2157
|
})
|
|
2095
|
-
),
|
|
2158
|
+
), Es = o.object({
|
|
2096
2159
|
client_id: o.string(),
|
|
2097
2160
|
client_secret: o.string().optional(),
|
|
2098
2161
|
client_id_issued_at: o.number().optional(),
|
|
2099
2162
|
client_secret_expires_at: o.number().optional()
|
|
2100
|
-
}).strip(),
|
|
2163
|
+
}).strip(), As = o.object({
|
|
2101
2164
|
redirect_uris: o.array(R),
|
|
2102
2165
|
token_endpoint_auth_method: o.string().optional(),
|
|
2103
2166
|
grant_types: o.array(o.string()).optional(),
|
|
@@ -2114,22 +2177,22 @@ var ss = $.extend({
|
|
|
2114
2177
|
software_id: o.string().optional(),
|
|
2115
2178
|
software_version: o.string().optional(),
|
|
2116
2179
|
software_statement: o.string().optional()
|
|
2117
|
-
}).strip(),
|
|
2180
|
+
}).strip(), ks = o.object({
|
|
2118
2181
|
error: o.string(),
|
|
2119
2182
|
error_description: o.string().optional(),
|
|
2120
2183
|
error_uri: o.string().optional()
|
|
2121
|
-
}),
|
|
2122
|
-
|
|
2123
|
-
),
|
|
2184
|
+
}), Os = As.merge(
|
|
2185
|
+
Es
|
|
2186
|
+
), xs = "AI_MCPClientOAuthError", ut = `vercel.ai.error.${xs}`, Is = Symbol.for(ut), je, Ue, W = class extends (Ue = K, je = Is, Ue) {
|
|
2124
2187
|
constructor({
|
|
2125
2188
|
name: t = "MCPClientOAuthError",
|
|
2126
2189
|
message: e,
|
|
2127
2190
|
cause: r
|
|
2128
2191
|
}) {
|
|
2129
|
-
super({ name: t, message: e, cause: r }), this[
|
|
2192
|
+
super({ name: t, message: e, cause: r }), this[je] = !0;
|
|
2130
2193
|
}
|
|
2131
2194
|
static isInstance(t) {
|
|
2132
|
-
return K.hasMarker(t,
|
|
2195
|
+
return K.hasMarker(t, ut);
|
|
2133
2196
|
}
|
|
2134
2197
|
}, Z = class extends W {
|
|
2135
2198
|
};
|
|
@@ -2143,17 +2206,21 @@ Q.errorCode = "invalid_grant";
|
|
|
2143
2206
|
var Y = class extends W {
|
|
2144
2207
|
};
|
|
2145
2208
|
Y.errorCode = "unauthorized_client";
|
|
2146
|
-
var
|
|
2209
|
+
var Ls = {
|
|
2147
2210
|
[Z.errorCode]: Z,
|
|
2148
2211
|
[X.errorCode]: X,
|
|
2149
2212
|
[Q.errorCode]: Q,
|
|
2150
2213
|
[Y.errorCode]: Y
|
|
2151
2214
|
};
|
|
2152
|
-
function
|
|
2215
|
+
function js(t) {
|
|
2153
2216
|
const e = typeof t == "string" ? new URL(t) : new URL(t.href);
|
|
2154
2217
|
return e.hash = "", e;
|
|
2155
2218
|
}
|
|
2156
|
-
function
|
|
2219
|
+
function be(t) {
|
|
2220
|
+
const e = t.href;
|
|
2221
|
+
return t.pathname === "/" && e.endsWith("/") ? e.slice(0, -1) : e;
|
|
2222
|
+
}
|
|
2223
|
+
function Us({
|
|
2157
2224
|
requestedResource: t,
|
|
2158
2225
|
configuredResource: e
|
|
2159
2226
|
}) {
|
|
@@ -2184,45 +2251,45 @@ function te(t) {
|
|
|
2184
2251
|
return;
|
|
2185
2252
|
}
|
|
2186
2253
|
}
|
|
2187
|
-
function
|
|
2254
|
+
function $s(t, e = "", r = {}) {
|
|
2188
2255
|
return e.endsWith("/") && (e = e.slice(0, -1)), r.prependPathname ? `${e}/.well-known/${t}` : `/.well-known/${t}${e}`;
|
|
2189
2256
|
}
|
|
2190
|
-
async function
|
|
2257
|
+
async function Se(t, e, r = fetch) {
|
|
2191
2258
|
try {
|
|
2192
2259
|
return await r(t, { headers: e });
|
|
2193
2260
|
} catch (s) {
|
|
2194
2261
|
if (s instanceof TypeError)
|
|
2195
|
-
return e ?
|
|
2262
|
+
return e ? Se(t, void 0, r) : void 0;
|
|
2196
2263
|
throw s;
|
|
2197
2264
|
}
|
|
2198
2265
|
}
|
|
2199
2266
|
async function $e(t, e, r = fetch) {
|
|
2200
|
-
return await
|
|
2267
|
+
return await Se(t, {
|
|
2201
2268
|
"MCP-Protocol-Version": e
|
|
2202
2269
|
}, r);
|
|
2203
2270
|
}
|
|
2204
|
-
function
|
|
2271
|
+
function Ns(t, e) {
|
|
2205
2272
|
return !t || t.status >= 400 && t.status < 500 && e !== "/";
|
|
2206
2273
|
}
|
|
2207
|
-
async function
|
|
2274
|
+
async function qs(t, e, r, s) {
|
|
2208
2275
|
var n, a;
|
|
2209
|
-
const i = new URL(t),
|
|
2210
|
-
let
|
|
2276
|
+
const i = new URL(t), c = (n = s?.protocolVersion) != null ? n : D;
|
|
2277
|
+
let u;
|
|
2211
2278
|
if (s?.metadataUrl)
|
|
2212
|
-
|
|
2279
|
+
u = new URL(s.metadataUrl);
|
|
2213
2280
|
else {
|
|
2214
|
-
const p =
|
|
2215
|
-
|
|
2281
|
+
const p = $s(e, i.pathname);
|
|
2282
|
+
u = new URL(p, (a = s?.metadataServerUrl) != null ? a : i), u.search = i.search;
|
|
2216
2283
|
}
|
|
2217
|
-
let
|
|
2218
|
-
if (!s?.metadataUrl &&
|
|
2284
|
+
let l = await $e(u, c, r);
|
|
2285
|
+
if (!s?.metadataUrl && Ns(l, i.pathname)) {
|
|
2219
2286
|
const p = new URL(`/.well-known/${e}`, i);
|
|
2220
|
-
|
|
2287
|
+
l = await $e(p, c, r);
|
|
2221
2288
|
}
|
|
2222
|
-
return
|
|
2289
|
+
return l;
|
|
2223
2290
|
}
|
|
2224
|
-
async function
|
|
2225
|
-
const s = await
|
|
2291
|
+
async function Hs(t, e, r = fetch) {
|
|
2292
|
+
const s = await qs(
|
|
2226
2293
|
t,
|
|
2227
2294
|
"oauth-protected-resource",
|
|
2228
2295
|
r,
|
|
@@ -2239,9 +2306,9 @@ async function Ns(t, e, r = fetch) {
|
|
|
2239
2306
|
throw new Error(
|
|
2240
2307
|
`HTTP ${s.status} trying to load well-known OAuth protected resource metadata.`
|
|
2241
2308
|
);
|
|
2242
|
-
return
|
|
2309
|
+
return Ps.parse(await s.json());
|
|
2243
2310
|
}
|
|
2244
|
-
function
|
|
2311
|
+
function Zs(t) {
|
|
2245
2312
|
const e = typeof t == "string" ? new URL(t) : t, r = e.pathname !== "/", s = [];
|
|
2246
2313
|
if (!r)
|
|
2247
2314
|
return s.push({
|
|
@@ -2269,38 +2336,38 @@ function qs(t) {
|
|
|
2269
2336
|
type: "oidc"
|
|
2270
2337
|
}), s;
|
|
2271
2338
|
}
|
|
2272
|
-
async function
|
|
2339
|
+
async function Ds(t, {
|
|
2273
2340
|
fetchFn: e = fetch,
|
|
2274
2341
|
protocolVersion: r = D
|
|
2275
2342
|
} = {}) {
|
|
2276
2343
|
var s;
|
|
2277
|
-
const n = { "MCP-Protocol-Version": r }, a =
|
|
2278
|
-
for (const { url: i, type:
|
|
2279
|
-
const
|
|
2280
|
-
if (
|
|
2281
|
-
if (!
|
|
2282
|
-
if (
|
|
2344
|
+
const n = { "MCP-Protocol-Version": r }, a = Zs(t);
|
|
2345
|
+
for (const { url: i, type: c } of a) {
|
|
2346
|
+
const u = await Se(i, n, e);
|
|
2347
|
+
if (u) {
|
|
2348
|
+
if (!u.ok) {
|
|
2349
|
+
if (u.status >= 400 && u.status < 500)
|
|
2283
2350
|
continue;
|
|
2284
2351
|
throw new Error(
|
|
2285
|
-
`HTTP ${
|
|
2352
|
+
`HTTP ${u.status} trying to load ${c === "oauth" ? "OAuth" : "OpenID provider"} metadata from ${i}`
|
|
2286
2353
|
);
|
|
2287
2354
|
}
|
|
2288
|
-
if (
|
|
2289
|
-
return
|
|
2355
|
+
if (c === "oauth")
|
|
2356
|
+
return lt.parse(await u.json());
|
|
2290
2357
|
{
|
|
2291
|
-
const
|
|
2292
|
-
await
|
|
2358
|
+
const l = Ms.parse(
|
|
2359
|
+
await u.json()
|
|
2293
2360
|
);
|
|
2294
|
-
if (!((s =
|
|
2361
|
+
if (!((s = l.code_challenge_methods_supported) != null && s.includes("S256")))
|
|
2295
2362
|
throw new Error(
|
|
2296
2363
|
`Incompatible OIDC provider at ${i}: does not support S256 code challenge method required by MCP specification`
|
|
2297
2364
|
);
|
|
2298
|
-
return
|
|
2365
|
+
return l;
|
|
2299
2366
|
}
|
|
2300
2367
|
}
|
|
2301
2368
|
}
|
|
2302
2369
|
}
|
|
2303
|
-
async function
|
|
2370
|
+
async function zs(t, {
|
|
2304
2371
|
metadata: e,
|
|
2305
2372
|
clientInformation: r,
|
|
2306
2373
|
redirectUrl: s,
|
|
@@ -2308,46 +2375,49 @@ async function Zs(t, {
|
|
|
2308
2375
|
state: a,
|
|
2309
2376
|
resource: i
|
|
2310
2377
|
}) {
|
|
2311
|
-
const
|
|
2312
|
-
let
|
|
2378
|
+
const c = "code", u = "S256";
|
|
2379
|
+
let l;
|
|
2313
2380
|
if (e) {
|
|
2314
|
-
if (
|
|
2381
|
+
if (l = new URL(e.authorization_endpoint), !e.response_types_supported.includes(c))
|
|
2315
2382
|
throw new Error(
|
|
2316
|
-
`Incompatible auth server: does not support response type ${
|
|
2383
|
+
`Incompatible auth server: does not support response type ${c}`
|
|
2317
2384
|
);
|
|
2318
|
-
if (!e.code_challenge_methods_supported || !e.code_challenge_methods_supported.includes(
|
|
2385
|
+
if (!e.code_challenge_methods_supported || !e.code_challenge_methods_supported.includes(u))
|
|
2319
2386
|
throw new Error(
|
|
2320
|
-
`Incompatible auth server: does not support code challenge method ${
|
|
2387
|
+
`Incompatible auth server: does not support code challenge method ${u}`
|
|
2321
2388
|
);
|
|
2322
2389
|
} else
|
|
2323
|
-
|
|
2324
|
-
const p = await
|
|
2325
|
-
return
|
|
2390
|
+
l = new URL("/authorize", t);
|
|
2391
|
+
const p = await Qr(), m = p.code_verifier, d = p.code_challenge;
|
|
2392
|
+
return l.searchParams.set("response_type", c), l.searchParams.set("client_id", r.client_id), l.searchParams.set("code_challenge", d), l.searchParams.set(
|
|
2326
2393
|
"code_challenge_method",
|
|
2327
|
-
|
|
2328
|
-
),
|
|
2394
|
+
u
|
|
2395
|
+
), l.searchParams.set("redirect_uri", String(s)), a && l.searchParams.set("state", a), n && l.searchParams.set("scope", n), n?.includes("offline_access") && l.searchParams.append("prompt", "consent"), i && l.searchParams.set(
|
|
2396
|
+
"resource",
|
|
2397
|
+
be(i)
|
|
2398
|
+
), { authorizationUrl: l, codeVerifier: m };
|
|
2329
2399
|
}
|
|
2330
|
-
function
|
|
2400
|
+
function dt(t, e) {
|
|
2331
2401
|
const r = t.client_secret !== void 0;
|
|
2332
2402
|
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
2403
|
}
|
|
2334
|
-
function
|
|
2404
|
+
function pt(t, e, r, s) {
|
|
2335
2405
|
const { client_id: n, client_secret: a } = e;
|
|
2336
2406
|
switch (t) {
|
|
2337
2407
|
case "client_secret_basic":
|
|
2338
|
-
|
|
2408
|
+
Fs(n, a, r);
|
|
2339
2409
|
return;
|
|
2340
2410
|
case "client_secret_post":
|
|
2341
|
-
|
|
2411
|
+
Vs(n, a, s);
|
|
2342
2412
|
return;
|
|
2343
2413
|
case "none":
|
|
2344
|
-
|
|
2414
|
+
Js(n, s);
|
|
2345
2415
|
return;
|
|
2346
2416
|
default:
|
|
2347
2417
|
throw new Error(`Unsupported client authentication method: ${t}`);
|
|
2348
2418
|
}
|
|
2349
2419
|
}
|
|
2350
|
-
function
|
|
2420
|
+
function Fs(t, e, r) {
|
|
2351
2421
|
if (!e)
|
|
2352
2422
|
throw new Error(
|
|
2353
2423
|
"client_secret_basic authentication requires a client_secret"
|
|
@@ -2355,17 +2425,17 @@ function Ds(t, e, r) {
|
|
|
2355
2425
|
const s = btoa(`${t}:${e}`);
|
|
2356
2426
|
r.set("Authorization", `Basic ${s}`);
|
|
2357
2427
|
}
|
|
2358
|
-
function
|
|
2428
|
+
function Vs(t, e, r) {
|
|
2359
2429
|
r.set("client_id", t), e && r.set("client_secret", e);
|
|
2360
2430
|
}
|
|
2361
|
-
function
|
|
2431
|
+
function Js(t, e) {
|
|
2362
2432
|
e.set("client_id", t);
|
|
2363
2433
|
}
|
|
2364
|
-
async function
|
|
2434
|
+
async function Te(t) {
|
|
2365
2435
|
const e = t instanceof Response ? t.status : void 0, r = t instanceof Response ? await t.text() : t;
|
|
2366
2436
|
try {
|
|
2367
|
-
const s =
|
|
2368
|
-
return new
|
|
2437
|
+
const s = ks.parse(JSON.parse(r)), { error: n, error_description: a, error_uri: i } = s, c = Ls[n] || Z;
|
|
2438
|
+
return new c({
|
|
2369
2439
|
message: a || "",
|
|
2370
2440
|
cause: i
|
|
2371
2441
|
});
|
|
@@ -2374,18 +2444,18 @@ async function Se(t) {
|
|
|
2374
2444
|
return new Z({ message: n });
|
|
2375
2445
|
}
|
|
2376
2446
|
}
|
|
2377
|
-
async function
|
|
2447
|
+
async function Ws(t, {
|
|
2378
2448
|
metadata: e,
|
|
2379
2449
|
clientInformation: r,
|
|
2380
2450
|
authorizationCode: s,
|
|
2381
2451
|
codeVerifier: n,
|
|
2382
2452
|
redirectUri: a,
|
|
2383
2453
|
resource: i,
|
|
2384
|
-
addClientAuthentication:
|
|
2385
|
-
fetchFn:
|
|
2454
|
+
addClientAuthentication: c,
|
|
2455
|
+
fetchFn: u
|
|
2386
2456
|
}) {
|
|
2387
|
-
var
|
|
2388
|
-
const p = "authorization_code",
|
|
2457
|
+
var l;
|
|
2458
|
+
const p = "authorization_code", m = e?.token_endpoint ? new URL(e.token_endpoint) : new URL("/token", t);
|
|
2389
2459
|
if (e?.grant_types_supported && !e.grant_types_supported.includes(p))
|
|
2390
2460
|
throw new Error(
|
|
2391
2461
|
`Incompatible auth server: does not support grant type ${p}`
|
|
@@ -2393,32 +2463,32 @@ async function Vs(t, {
|
|
|
2393
2463
|
const d = new Headers({
|
|
2394
2464
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
2395
2465
|
Accept: "application/json"
|
|
2396
|
-
}),
|
|
2466
|
+
}), g = new URLSearchParams({
|
|
2397
2467
|
grant_type: p,
|
|
2398
2468
|
code: s,
|
|
2399
2469
|
code_verifier: n,
|
|
2400
2470
|
redirect_uri: String(a)
|
|
2401
2471
|
});
|
|
2402
|
-
if (
|
|
2403
|
-
|
|
2472
|
+
if (c)
|
|
2473
|
+
c(d, g, t, e);
|
|
2404
2474
|
else {
|
|
2405
|
-
const h = (
|
|
2475
|
+
const h = (l = e?.token_endpoint_auth_methods_supported) != null ? l : [], f = dt(
|
|
2406
2476
|
r,
|
|
2407
2477
|
h
|
|
2408
2478
|
);
|
|
2409
|
-
|
|
2479
|
+
pt(f, r, d, g);
|
|
2410
2480
|
}
|
|
2411
|
-
i &&
|
|
2412
|
-
const y = await (
|
|
2481
|
+
i && g.set("resource", be(i));
|
|
2482
|
+
const y = await (u ?? fetch)(m, {
|
|
2413
2483
|
method: "POST",
|
|
2414
2484
|
headers: d,
|
|
2415
|
-
body:
|
|
2485
|
+
body: g
|
|
2416
2486
|
});
|
|
2417
2487
|
if (!y.ok)
|
|
2418
|
-
throw await
|
|
2419
|
-
return
|
|
2488
|
+
throw await Te(y);
|
|
2489
|
+
return ct.parse(await y.json());
|
|
2420
2490
|
}
|
|
2421
|
-
async function
|
|
2491
|
+
async function Bs(t, {
|
|
2422
2492
|
metadata: e,
|
|
2423
2493
|
clientInformation: r,
|
|
2424
2494
|
refreshToken: s,
|
|
@@ -2426,46 +2496,46 @@ async function Js(t, {
|
|
|
2426
2496
|
addClientAuthentication: a,
|
|
2427
2497
|
fetchFn: i
|
|
2428
2498
|
}) {
|
|
2429
|
-
var
|
|
2430
|
-
const
|
|
2431
|
-
let
|
|
2499
|
+
var c;
|
|
2500
|
+
const u = "refresh_token";
|
|
2501
|
+
let l;
|
|
2432
2502
|
if (e) {
|
|
2433
|
-
if (
|
|
2503
|
+
if (l = new URL(e.token_endpoint), e.grant_types_supported && !e.grant_types_supported.includes(u))
|
|
2434
2504
|
throw new Error(
|
|
2435
|
-
`Incompatible auth server: does not support grant type ${
|
|
2505
|
+
`Incompatible auth server: does not support grant type ${u}`
|
|
2436
2506
|
);
|
|
2437
2507
|
} else
|
|
2438
|
-
|
|
2508
|
+
l = new URL("/token", t);
|
|
2439
2509
|
const p = new Headers({
|
|
2440
2510
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
2441
2511
|
Accept: "application/json"
|
|
2442
|
-
}),
|
|
2443
|
-
grant_type:
|
|
2512
|
+
}), m = new URLSearchParams({
|
|
2513
|
+
grant_type: u,
|
|
2444
2514
|
refresh_token: s
|
|
2445
2515
|
});
|
|
2446
2516
|
if (a)
|
|
2447
|
-
a(p,
|
|
2517
|
+
a(p, m, t, e);
|
|
2448
2518
|
else {
|
|
2449
|
-
const
|
|
2519
|
+
const g = (c = e?.token_endpoint_auth_methods_supported) != null ? c : [], y = dt(
|
|
2450
2520
|
r,
|
|
2451
|
-
|
|
2521
|
+
g
|
|
2452
2522
|
);
|
|
2453
|
-
|
|
2523
|
+
pt(y, r, p, m);
|
|
2454
2524
|
}
|
|
2455
|
-
n &&
|
|
2456
|
-
const d = await (i ?? fetch)(
|
|
2525
|
+
n && m.set("resource", be(n));
|
|
2526
|
+
const d = await (i ?? fetch)(l, {
|
|
2457
2527
|
method: "POST",
|
|
2458
2528
|
headers: p,
|
|
2459
|
-
body:
|
|
2529
|
+
body: m
|
|
2460
2530
|
});
|
|
2461
2531
|
if (!d.ok)
|
|
2462
|
-
throw await
|
|
2463
|
-
return
|
|
2532
|
+
throw await Te(d);
|
|
2533
|
+
return ct.parse({
|
|
2464
2534
|
refresh_token: s,
|
|
2465
2535
|
...await d.json()
|
|
2466
2536
|
});
|
|
2467
2537
|
}
|
|
2468
|
-
async function
|
|
2538
|
+
async function Gs(t, {
|
|
2469
2539
|
metadata: e,
|
|
2470
2540
|
clientMetadata: r,
|
|
2471
2541
|
fetchFn: s
|
|
@@ -2487,8 +2557,8 @@ async function Ws(t, {
|
|
|
2487
2557
|
body: JSON.stringify(r)
|
|
2488
2558
|
});
|
|
2489
2559
|
if (!a.ok)
|
|
2490
|
-
throw await
|
|
2491
|
-
return
|
|
2560
|
+
throw await Te(a);
|
|
2561
|
+
return Os.parse(await a.json());
|
|
2492
2562
|
}
|
|
2493
2563
|
async function re(t, e) {
|
|
2494
2564
|
var r, s;
|
|
@@ -2502,15 +2572,15 @@ async function re(t, e) {
|
|
|
2502
2572
|
throw n;
|
|
2503
2573
|
}
|
|
2504
2574
|
}
|
|
2505
|
-
async function
|
|
2506
|
-
const s =
|
|
2575
|
+
async function Ks(t, e, r) {
|
|
2576
|
+
const s = js(t);
|
|
2507
2577
|
if (e.validateResourceURL)
|
|
2508
2578
|
return await e.validateResourceURL(
|
|
2509
2579
|
s,
|
|
2510
2580
|
r?.resource
|
|
2511
2581
|
);
|
|
2512
2582
|
if (r) {
|
|
2513
|
-
if (!
|
|
2583
|
+
if (!Us({
|
|
2514
2584
|
requestedResource: s,
|
|
2515
2585
|
configuredResource: r.resource
|
|
2516
2586
|
}))
|
|
@@ -2528,28 +2598,28 @@ async function de(t, {
|
|
|
2528
2598
|
resourceMetadataUrl: a,
|
|
2529
2599
|
fetchFn: i
|
|
2530
2600
|
}) {
|
|
2531
|
-
let
|
|
2601
|
+
let c, u;
|
|
2532
2602
|
try {
|
|
2533
|
-
|
|
2603
|
+
c = await Hs(
|
|
2534
2604
|
e,
|
|
2535
2605
|
{ resourceMetadataUrl: a },
|
|
2536
2606
|
i
|
|
2537
|
-
),
|
|
2607
|
+
), c.authorization_servers && c.authorization_servers.length > 0 && (u = c.authorization_servers[0]);
|
|
2538
2608
|
} catch {
|
|
2539
2609
|
}
|
|
2540
|
-
|
|
2541
|
-
const
|
|
2610
|
+
u || (u = e);
|
|
2611
|
+
const l = await Ks(
|
|
2542
2612
|
e,
|
|
2543
2613
|
t,
|
|
2544
|
-
|
|
2545
|
-
), p = await
|
|
2546
|
-
|
|
2614
|
+
c
|
|
2615
|
+
), p = await Ds(
|
|
2616
|
+
u,
|
|
2547
2617
|
{
|
|
2548
2618
|
fetchFn: i
|
|
2549
2619
|
}
|
|
2550
2620
|
);
|
|
2551
|
-
let
|
|
2552
|
-
if (!
|
|
2621
|
+
let m = await Promise.resolve(t.clientInformation());
|
|
2622
|
+
if (!m) {
|
|
2553
2623
|
if (r !== void 0)
|
|
2554
2624
|
throw new Error(
|
|
2555
2625
|
"Existing OAuth client information is required when exchanging an authorization code"
|
|
@@ -2558,12 +2628,12 @@ async function de(t, {
|
|
|
2558
2628
|
throw new Error(
|
|
2559
2629
|
"OAuth client information must be saveable for dynamic registration"
|
|
2560
2630
|
);
|
|
2561
|
-
const f = await
|
|
2631
|
+
const f = await Gs(u, {
|
|
2562
2632
|
metadata: p,
|
|
2563
2633
|
clientMetadata: t.clientMetadata,
|
|
2564
2634
|
fetchFn: i
|
|
2565
2635
|
});
|
|
2566
|
-
await t.saveClientInformation(f),
|
|
2636
|
+
await t.saveClientInformation(f), m = f;
|
|
2567
2637
|
}
|
|
2568
2638
|
if (r !== void 0) {
|
|
2569
2639
|
if (t.storedState) {
|
|
@@ -2573,13 +2643,13 @@ async function de(t, {
|
|
|
2573
2643
|
"OAuth state parameter mismatch - possible CSRF attack"
|
|
2574
2644
|
);
|
|
2575
2645
|
}
|
|
2576
|
-
const f = await t.codeVerifier(), v = await
|
|
2646
|
+
const f = await t.codeVerifier(), v = await Ws(u, {
|
|
2577
2647
|
metadata: p,
|
|
2578
|
-
clientInformation:
|
|
2648
|
+
clientInformation: m,
|
|
2579
2649
|
authorizationCode: r,
|
|
2580
2650
|
codeVerifier: f,
|
|
2581
2651
|
redirectUri: t.redirectUrl,
|
|
2582
|
-
resource:
|
|
2652
|
+
resource: l,
|
|
2583
2653
|
addClientAuthentication: t.addClientAuthentication,
|
|
2584
2654
|
fetchFn: i
|
|
2585
2655
|
});
|
|
@@ -2588,11 +2658,11 @@ async function de(t, {
|
|
|
2588
2658
|
const d = await t.tokens();
|
|
2589
2659
|
if (d?.refresh_token)
|
|
2590
2660
|
try {
|
|
2591
|
-
const f = await
|
|
2661
|
+
const f = await Bs(u, {
|
|
2592
2662
|
metadata: p,
|
|
2593
|
-
clientInformation:
|
|
2663
|
+
clientInformation: m,
|
|
2594
2664
|
refreshToken: d.refresh_token,
|
|
2595
|
-
resource:
|
|
2665
|
+
resource: l,
|
|
2596
2666
|
addClientAuthentication: t.addClientAuthentication,
|
|
2597
2667
|
fetchFn: i
|
|
2598
2668
|
});
|
|
@@ -2603,22 +2673,22 @@ async function de(t, {
|
|
|
2603
2673
|
!(!(f instanceof W) || f instanceof Z)
|
|
2604
2674
|
) throw f;
|
|
2605
2675
|
}
|
|
2606
|
-
const
|
|
2607
|
-
|
|
2608
|
-
const { authorizationUrl: y, codeVerifier: h } = await
|
|
2609
|
-
|
|
2676
|
+
const g = t.state ? await t.state() : void 0;
|
|
2677
|
+
g && t.saveState && await t.saveState(g);
|
|
2678
|
+
const { authorizationUrl: y, codeVerifier: h } = await zs(
|
|
2679
|
+
u,
|
|
2610
2680
|
{
|
|
2611
2681
|
metadata: p,
|
|
2612
|
-
clientInformation:
|
|
2613
|
-
state:
|
|
2682
|
+
clientInformation: m,
|
|
2683
|
+
state: g,
|
|
2614
2684
|
redirectUrl: t.redirectUrl,
|
|
2615
2685
|
scope: n || t.clientMetadata.scope,
|
|
2616
|
-
resource:
|
|
2686
|
+
resource: l
|
|
2617
2687
|
}
|
|
2618
2688
|
);
|
|
2619
2689
|
return await t.saveCodeVerifier(h), await t.redirectToAuthorization(y), "REDIRECT";
|
|
2620
2690
|
}
|
|
2621
|
-
var
|
|
2691
|
+
var Xs = class {
|
|
2622
2692
|
constructor({
|
|
2623
2693
|
url: t,
|
|
2624
2694
|
headers: e,
|
|
@@ -2637,10 +2707,10 @@ var Gs = class {
|
|
|
2637
2707
|
const r = await this.authProvider.tokens();
|
|
2638
2708
|
r?.access_token && (e.Authorization = `Bearer ${r.access_token}`);
|
|
2639
2709
|
}
|
|
2640
|
-
return
|
|
2710
|
+
return Ve(
|
|
2641
2711
|
e,
|
|
2642
|
-
`ai-sdk/${
|
|
2643
|
-
|
|
2712
|
+
`ai-sdk/${it}`,
|
|
2713
|
+
Fe()
|
|
2644
2714
|
);
|
|
2645
2715
|
}
|
|
2646
2716
|
async start() {
|
|
@@ -2649,12 +2719,12 @@ var Gs = class {
|
|
|
2649
2719
|
return t();
|
|
2650
2720
|
this.abortController = new AbortController();
|
|
2651
2721
|
const r = async (s = !1) => {
|
|
2652
|
-
var n, a, i,
|
|
2722
|
+
var n, a, i, c, u;
|
|
2653
2723
|
try {
|
|
2654
|
-
const
|
|
2724
|
+
const l = await this.commonHeaders({
|
|
2655
2725
|
Accept: "text/event-stream"
|
|
2656
2726
|
}), p = await fetch(this.url.href, {
|
|
2657
|
-
headers:
|
|
2727
|
+
headers: l,
|
|
2658
2728
|
signal: (n = this.abortController) == null ? void 0 : n.signal,
|
|
2659
2729
|
redirect: this.redirectMode
|
|
2660
2730
|
});
|
|
@@ -2679,9 +2749,9 @@ var Gs = class {
|
|
|
2679
2749
|
const h = new _({
|
|
2680
2750
|
message: y
|
|
2681
2751
|
});
|
|
2682
|
-
return (
|
|
2752
|
+
return (c = this.onerror) == null || c.call(this, h), e(h);
|
|
2683
2753
|
}
|
|
2684
|
-
const d = p.body.pipeThrough(new TextDecoderStream()).pipeThrough(new he()).getReader(),
|
|
2754
|
+
const d = p.body.pipeThrough(new TextDecoderStream()).pipeThrough(new he()).getReader(), g = async () => {
|
|
2685
2755
|
var y, h, f;
|
|
2686
2756
|
try {
|
|
2687
2757
|
for (; ; ) {
|
|
@@ -2722,11 +2792,11 @@ var Gs = class {
|
|
|
2722
2792
|
};
|
|
2723
2793
|
this.sseConnection = {
|
|
2724
2794
|
close: () => d.cancel()
|
|
2725
|
-
},
|
|
2726
|
-
} catch (
|
|
2727
|
-
if (
|
|
2795
|
+
}, g();
|
|
2796
|
+
} catch (l) {
|
|
2797
|
+
if (l instanceof Error && l.name === "AbortError")
|
|
2728
2798
|
return;
|
|
2729
|
-
(
|
|
2799
|
+
(u = this.onerror) == null || u.call(this, l), e(l);
|
|
2730
2800
|
}
|
|
2731
2801
|
};
|
|
2732
2802
|
r();
|
|
@@ -2742,7 +2812,7 @@ var Gs = class {
|
|
|
2742
2812
|
message: "MCP SSE Transport Error: Not connected"
|
|
2743
2813
|
});
|
|
2744
2814
|
const e = this.endpoint, r = async (s = !1) => {
|
|
2745
|
-
var n, a, i,
|
|
2815
|
+
var n, a, i, c, u;
|
|
2746
2816
|
try {
|
|
2747
2817
|
const p = {
|
|
2748
2818
|
method: "POST",
|
|
@@ -2752,16 +2822,16 @@ var Gs = class {
|
|
|
2752
2822
|
body: JSON.stringify(t),
|
|
2753
2823
|
signal: (n = this.abortController) == null ? void 0 : n.signal,
|
|
2754
2824
|
redirect: this.redirectMode
|
|
2755
|
-
},
|
|
2756
|
-
if (
|
|
2757
|
-
this.resourceMetadataUrl = te(
|
|
2825
|
+
}, m = await fetch(e, p);
|
|
2826
|
+
if (m.status === 401 && this.authProvider && !s) {
|
|
2827
|
+
this.resourceMetadataUrl = te(m);
|
|
2758
2828
|
try {
|
|
2759
2829
|
if (await re(this.authProvider, {
|
|
2760
2830
|
serverUrl: this.url,
|
|
2761
2831
|
resourceMetadataUrl: this.resourceMetadataUrl
|
|
2762
2832
|
}) !== "AUTHORIZED") {
|
|
2763
|
-
const
|
|
2764
|
-
(a = this.onerror) == null || a.call(this,
|
|
2833
|
+
const g = new ee();
|
|
2834
|
+
(a = this.onerror) == null || a.call(this, g);
|
|
2765
2835
|
return;
|
|
2766
2836
|
}
|
|
2767
2837
|
} catch (d) {
|
|
@@ -2770,21 +2840,21 @@ var Gs = class {
|
|
|
2770
2840
|
}
|
|
2771
2841
|
return r(!0);
|
|
2772
2842
|
}
|
|
2773
|
-
if (!
|
|
2774
|
-
const d = await
|
|
2775
|
-
message: `MCP SSE Transport Error: POSTing to endpoint (HTTP ${
|
|
2843
|
+
if (!m.ok) {
|
|
2844
|
+
const d = await m.text().catch(() => null), g = new _({
|
|
2845
|
+
message: `MCP SSE Transport Error: POSTing to endpoint (HTTP ${m.status}): ${d}`
|
|
2776
2846
|
});
|
|
2777
|
-
(
|
|
2847
|
+
(c = this.onerror) == null || c.call(this, g);
|
|
2778
2848
|
return;
|
|
2779
2849
|
}
|
|
2780
|
-
} catch (
|
|
2781
|
-
(
|
|
2850
|
+
} catch (l) {
|
|
2851
|
+
(u = this.onerror) == null || u.call(this, l);
|
|
2782
2852
|
return;
|
|
2783
2853
|
}
|
|
2784
2854
|
};
|
|
2785
2855
|
await r();
|
|
2786
2856
|
}
|
|
2787
|
-
},
|
|
2857
|
+
}, Qs = class {
|
|
2788
2858
|
constructor({
|
|
2789
2859
|
url: t,
|
|
2790
2860
|
headers: e,
|
|
@@ -2808,10 +2878,10 @@ var Gs = class {
|
|
|
2808
2878
|
const r = await this.authProvider.tokens();
|
|
2809
2879
|
r?.access_token && (e.Authorization = `Bearer ${r.access_token}`);
|
|
2810
2880
|
}
|
|
2811
|
-
return
|
|
2881
|
+
return Ve(
|
|
2812
2882
|
e,
|
|
2813
|
-
`ai-sdk/${
|
|
2814
|
-
|
|
2883
|
+
`ai-sdk/${it}`,
|
|
2884
|
+
Fe()
|
|
2815
2885
|
);
|
|
2816
2886
|
}
|
|
2817
2887
|
async start() {
|
|
@@ -2841,9 +2911,9 @@ var Gs = class {
|
|
|
2841
2911
|
}
|
|
2842
2912
|
async send(t) {
|
|
2843
2913
|
const e = async (r = !1) => {
|
|
2844
|
-
var s, n, a, i, u, l
|
|
2914
|
+
var s, n, a, i, c, u, l;
|
|
2845
2915
|
try {
|
|
2846
|
-
const
|
|
2916
|
+
const m = {
|
|
2847
2917
|
method: "POST",
|
|
2848
2918
|
headers: await this.commonHeaders({
|
|
2849
2919
|
"Content-Type": "application/json",
|
|
@@ -2852,8 +2922,8 @@ var Gs = class {
|
|
|
2852
2922
|
body: JSON.stringify(t),
|
|
2853
2923
|
signal: (s = this.abortController) == null ? void 0 : s.signal,
|
|
2854
2924
|
redirect: this.redirectMode
|
|
2855
|
-
}, d = await fetch(this.url,
|
|
2856
|
-
if (
|
|
2925
|
+
}, d = await fetch(this.url, m), g = d.headers.get("mcp-session-id");
|
|
2926
|
+
if (g && (this.sessionId = g), d.status === 401 && this.authProvider && !r) {
|
|
2857
2927
|
this.resourceMetadataUrl = te(d);
|
|
2858
2928
|
try {
|
|
2859
2929
|
if (await re(this.authProvider, {
|
|
@@ -2892,7 +2962,7 @@ var Gs = class {
|
|
|
2892
2962
|
const A = new _({
|
|
2893
2963
|
message: "MCP HTTP Transport Error: text/event-stream response without body"
|
|
2894
2964
|
});
|
|
2895
|
-
throw (
|
|
2965
|
+
throw (c = this.onerror) == null || c.call(this, A), A;
|
|
2896
2966
|
}
|
|
2897
2967
|
const b = d.body.pipeThrough(new TextDecoderStream()).pipeThrough(new he()).getReader();
|
|
2898
2968
|
(async () => {
|
|
@@ -2901,17 +2971,17 @@ var Gs = class {
|
|
|
2901
2971
|
for (; ; ) {
|
|
2902
2972
|
const { done: O, value: H } = await b.read();
|
|
2903
2973
|
if (O) return;
|
|
2904
|
-
const { event:
|
|
2905
|
-
if (
|
|
2974
|
+
const { event: x, data: $ } = H;
|
|
2975
|
+
if (x === "message")
|
|
2906
2976
|
try {
|
|
2907
|
-
const z = V.parse(JSON.parse(
|
|
2977
|
+
const z = V.parse(JSON.parse($));
|
|
2908
2978
|
(A = this.onmessage) == null || A.call(this, z);
|
|
2909
2979
|
} catch (z) {
|
|
2910
|
-
const
|
|
2980
|
+
const I = new _({
|
|
2911
2981
|
message: "MCP HTTP Transport Error: Failed to parse message",
|
|
2912
2982
|
cause: z
|
|
2913
2983
|
});
|
|
2914
|
-
(M = this.onerror) == null || M.call(this,
|
|
2984
|
+
(M = this.onerror) == null || M.call(this, I);
|
|
2915
2985
|
}
|
|
2916
2986
|
}
|
|
2917
2987
|
} catch (O) {
|
|
@@ -2925,9 +2995,9 @@ var Gs = class {
|
|
|
2925
2995
|
const f = new _({
|
|
2926
2996
|
message: `MCP HTTP Transport Error: Unexpected content type: ${h}`
|
|
2927
2997
|
});
|
|
2928
|
-
throw (
|
|
2998
|
+
throw (u = this.onerror) == null || u.call(this, f), f;
|
|
2929
2999
|
} catch (p) {
|
|
2930
|
-
throw (
|
|
3000
|
+
throw (l = this.onerror) == null || l.call(this, p), p;
|
|
2931
3001
|
}
|
|
2932
3002
|
};
|
|
2933
3003
|
await e();
|
|
@@ -2963,20 +3033,20 @@ var Gs = class {
|
|
|
2963
3033
|
}
|
|
2964
3034
|
// Open optional inbound SSE stream; best-effort and resumable
|
|
2965
3035
|
async openInboundSse(t = !1, e) {
|
|
2966
|
-
var r, s, n, a, i,
|
|
3036
|
+
var r, s, n, a, i, c;
|
|
2967
3037
|
try {
|
|
2968
|
-
const
|
|
3038
|
+
const u = await this.commonHeaders({
|
|
2969
3039
|
Accept: "text/event-stream"
|
|
2970
3040
|
});
|
|
2971
|
-
e && (
|
|
2972
|
-
const
|
|
3041
|
+
e && (u["last-event-id"] = e);
|
|
3042
|
+
const l = await fetch(this.url.href, {
|
|
2973
3043
|
method: "GET",
|
|
2974
|
-
headers:
|
|
3044
|
+
headers: u,
|
|
2975
3045
|
signal: (r = this.abortController) == null ? void 0 : r.signal,
|
|
2976
3046
|
redirect: this.redirectMode
|
|
2977
|
-
}), p =
|
|
2978
|
-
if (p && (this.sessionId = p),
|
|
2979
|
-
this.resourceMetadataUrl = te(
|
|
3047
|
+
}), p = l.headers.get("mcp-session-id");
|
|
3048
|
+
if (p && (this.sessionId = p), l.status === 401 && this.authProvider && !t) {
|
|
3049
|
+
this.resourceMetadataUrl = te(l);
|
|
2980
3050
|
try {
|
|
2981
3051
|
if (await re(this.authProvider, {
|
|
2982
3052
|
serverUrl: this.url,
|
|
@@ -2992,16 +3062,16 @@ var Gs = class {
|
|
|
2992
3062
|
}
|
|
2993
3063
|
return this.openInboundSse(!0, e);
|
|
2994
3064
|
}
|
|
2995
|
-
if (
|
|
3065
|
+
if (l.status === 405)
|
|
2996
3066
|
return;
|
|
2997
|
-
if (!
|
|
3067
|
+
if (!l.ok || !l.body) {
|
|
2998
3068
|
const y = new _({
|
|
2999
|
-
message: `MCP HTTP Transport Error: GET SSE failed: ${
|
|
3069
|
+
message: `MCP HTTP Transport Error: GET SSE failed: ${l.status} ${l.statusText}`
|
|
3000
3070
|
});
|
|
3001
3071
|
(a = this.onerror) == null || a.call(this, y);
|
|
3002
3072
|
return;
|
|
3003
3073
|
}
|
|
3004
|
-
const d =
|
|
3074
|
+
const d = l.body.pipeThrough(new TextDecoderStream()).pipeThrough(new he()).getReader(), g = async () => {
|
|
3005
3075
|
var y, h, f, v;
|
|
3006
3076
|
try {
|
|
3007
3077
|
for (; ; ) {
|
|
@@ -3028,31 +3098,31 @@ var Gs = class {
|
|
|
3028
3098
|
};
|
|
3029
3099
|
this.inboundSseConnection = {
|
|
3030
3100
|
close: () => d.cancel()
|
|
3031
|
-
}, this.inboundReconnectAttempts = 0,
|
|
3032
|
-
} catch (
|
|
3033
|
-
if (
|
|
3101
|
+
}, this.inboundReconnectAttempts = 0, g();
|
|
3102
|
+
} catch (u) {
|
|
3103
|
+
if (u instanceof Error && u.name === "AbortError")
|
|
3034
3104
|
return;
|
|
3035
|
-
(i = this.onerror) == null || i.call(this,
|
|
3105
|
+
(i = this.onerror) == null || i.call(this, u), (c = this.abortController) != null && c.signal.aborted || this.scheduleInboundSseReconnection();
|
|
3036
3106
|
}
|
|
3037
3107
|
}
|
|
3038
3108
|
};
|
|
3039
|
-
function
|
|
3109
|
+
function Ys(t) {
|
|
3040
3110
|
switch (t.type) {
|
|
3041
3111
|
case "sse":
|
|
3042
|
-
return new
|
|
3112
|
+
return new Xs(t);
|
|
3043
3113
|
case "http":
|
|
3044
|
-
return new
|
|
3114
|
+
return new Qs(t);
|
|
3045
3115
|
default:
|
|
3046
3116
|
throw new _({
|
|
3047
3117
|
message: "Unsupported or invalid transport configuration. If you are using a custom transport, make sure it implements the MCPTransport interface."
|
|
3048
3118
|
});
|
|
3049
3119
|
}
|
|
3050
3120
|
}
|
|
3051
|
-
function
|
|
3121
|
+
function en(t) {
|
|
3052
3122
|
return "start" in t && typeof t.start == "function" && "send" in t && typeof t.send == "function" && "close" in t && typeof t.close == "function";
|
|
3053
3123
|
}
|
|
3054
|
-
var
|
|
3055
|
-
function
|
|
3124
|
+
var tn = "1.0.0";
|
|
3125
|
+
function Ne({
|
|
3056
3126
|
output: t
|
|
3057
3127
|
}) {
|
|
3058
3128
|
const e = t;
|
|
@@ -3064,19 +3134,19 @@ function je({
|
|
|
3064
3134
|
} : { type: "text", text: JSON.stringify(s) }
|
|
3065
3135
|
) };
|
|
3066
3136
|
}
|
|
3067
|
-
async function
|
|
3068
|
-
const e = new
|
|
3137
|
+
async function rn(t) {
|
|
3138
|
+
const e = new sn(t);
|
|
3069
3139
|
return await e.init(), e;
|
|
3070
3140
|
}
|
|
3071
|
-
var
|
|
3141
|
+
var sn = class {
|
|
3072
3142
|
constructor({
|
|
3073
3143
|
transport: t,
|
|
3074
3144
|
name: e = "ai-sdk-mcp-client",
|
|
3075
|
-
version: r =
|
|
3145
|
+
version: r = tn,
|
|
3076
3146
|
onUncaughtError: s,
|
|
3077
3147
|
capabilities: n
|
|
3078
3148
|
}) {
|
|
3079
|
-
this.requestMessageId = 0, this.responseHandlers = /* @__PURE__ */ new Map(), this.serverCapabilities = {}, this.isClosed = !0, this.onUncaughtError = s, this.clientCapabilities = n ?? {},
|
|
3149
|
+
this.requestMessageId = 0, this.responseHandlers = /* @__PURE__ */ new Map(), this.serverCapabilities = {}, this.isClosed = !0, this.onUncaughtError = s, this.clientCapabilities = n ?? {}, en(t) ? this.transport = t : this.transport = Ys(t), this.transport.onclose = () => this.onClose(), this.transport.onerror = (a) => this.onError(a), this.transport.onmessage = (a) => {
|
|
3080
3150
|
if ("method" in a) {
|
|
3081
3151
|
"id" in a ? this.onRequestMessage(a) : this.onError(
|
|
3082
3152
|
new _({
|
|
@@ -3103,13 +3173,13 @@ var tn = class {
|
|
|
3103
3173
|
clientInfo: this.clientInfo
|
|
3104
3174
|
}
|
|
3105
3175
|
},
|
|
3106
|
-
resultSchema:
|
|
3176
|
+
resultSchema: os
|
|
3107
3177
|
});
|
|
3108
3178
|
if (t === void 0)
|
|
3109
3179
|
throw new _({
|
|
3110
3180
|
message: "Server sent invalid initialize result"
|
|
3111
3181
|
});
|
|
3112
|
-
if (!
|
|
3182
|
+
if (!ts.includes(t.protocolVersion))
|
|
3113
3183
|
throw new _({
|
|
3114
3184
|
message: `Server's protocol version is not supported: ${t.protocolVersion}`
|
|
3115
3185
|
});
|
|
@@ -3171,14 +3241,14 @@ var tn = class {
|
|
|
3171
3241
|
this.assertCapability(t.method);
|
|
3172
3242
|
const a = r?.signal;
|
|
3173
3243
|
a?.throwIfAborted();
|
|
3174
|
-
const i = this.requestMessageId++,
|
|
3244
|
+
const i = this.requestMessageId++, c = {
|
|
3175
3245
|
...t,
|
|
3176
3246
|
jsonrpc: "2.0",
|
|
3177
3247
|
id: i
|
|
3178
|
-
},
|
|
3248
|
+
}, u = () => {
|
|
3179
3249
|
this.responseHandlers.delete(i);
|
|
3180
3250
|
};
|
|
3181
|
-
this.responseHandlers.set(i, (
|
|
3251
|
+
this.responseHandlers.set(i, (l) => {
|
|
3182
3252
|
if (a?.aborted)
|
|
3183
3253
|
return n(
|
|
3184
3254
|
new _({
|
|
@@ -3186,20 +3256,20 @@ var tn = class {
|
|
|
3186
3256
|
cause: a.reason
|
|
3187
3257
|
})
|
|
3188
3258
|
);
|
|
3189
|
-
if (
|
|
3190
|
-
return n(
|
|
3259
|
+
if (l instanceof Error)
|
|
3260
|
+
return n(l);
|
|
3191
3261
|
try {
|
|
3192
|
-
const p = e.parse(
|
|
3262
|
+
const p = e.parse(l.result);
|
|
3193
3263
|
s(p);
|
|
3194
3264
|
} catch (p) {
|
|
3195
|
-
const
|
|
3265
|
+
const m = new _({
|
|
3196
3266
|
message: "Failed to parse server response",
|
|
3197
3267
|
cause: p
|
|
3198
3268
|
});
|
|
3199
|
-
n(
|
|
3269
|
+
n(m);
|
|
3200
3270
|
}
|
|
3201
|
-
}), this.transport.send(
|
|
3202
|
-
|
|
3271
|
+
}), this.transport.send(c).catch((l) => {
|
|
3272
|
+
u(), n(l);
|
|
3203
3273
|
});
|
|
3204
3274
|
});
|
|
3205
3275
|
}
|
|
@@ -3209,7 +3279,7 @@ var tn = class {
|
|
|
3209
3279
|
} = {}) {
|
|
3210
3280
|
return this.request({
|
|
3211
3281
|
request: { method: "tools/list", params: t },
|
|
3212
|
-
resultSchema:
|
|
3282
|
+
resultSchema: is,
|
|
3213
3283
|
options: e
|
|
3214
3284
|
});
|
|
3215
3285
|
}
|
|
@@ -3221,7 +3291,7 @@ var tn = class {
|
|
|
3221
3291
|
try {
|
|
3222
3292
|
return this.request({
|
|
3223
3293
|
request: { method: "tools/call", params: { name: t, arguments: e } },
|
|
3224
|
-
resultSchema:
|
|
3294
|
+
resultSchema: us,
|
|
3225
3295
|
options: {
|
|
3226
3296
|
signal: r?.abortSignal
|
|
3227
3297
|
}
|
|
@@ -3237,7 +3307,7 @@ var tn = class {
|
|
|
3237
3307
|
try {
|
|
3238
3308
|
return this.request({
|
|
3239
3309
|
request: { method: "resources/list", params: t },
|
|
3240
|
-
resultSchema:
|
|
3310
|
+
resultSchema: ls,
|
|
3241
3311
|
options: e
|
|
3242
3312
|
});
|
|
3243
3313
|
} catch (r) {
|
|
@@ -3251,7 +3321,7 @@ var tn = class {
|
|
|
3251
3321
|
try {
|
|
3252
3322
|
return this.request({
|
|
3253
3323
|
request: { method: "resources/read", params: { uri: t } },
|
|
3254
|
-
resultSchema:
|
|
3324
|
+
resultSchema: hs,
|
|
3255
3325
|
options: e
|
|
3256
3326
|
});
|
|
3257
3327
|
} catch (r) {
|
|
@@ -3264,7 +3334,7 @@ var tn = class {
|
|
|
3264
3334
|
try {
|
|
3265
3335
|
return this.request({
|
|
3266
3336
|
request: { method: "resources/templates/list" },
|
|
3267
|
-
resultSchema:
|
|
3337
|
+
resultSchema: ps,
|
|
3268
3338
|
options: t
|
|
3269
3339
|
});
|
|
3270
3340
|
} catch (e) {
|
|
@@ -3278,7 +3348,7 @@ var tn = class {
|
|
|
3278
3348
|
try {
|
|
3279
3349
|
return this.request({
|
|
3280
3350
|
request: { method: "prompts/list", params: t },
|
|
3281
|
-
resultSchema:
|
|
3351
|
+
resultSchema: gs,
|
|
3282
3352
|
options: e
|
|
3283
3353
|
});
|
|
3284
3354
|
} catch (r) {
|
|
@@ -3293,7 +3363,7 @@ var tn = class {
|
|
|
3293
3363
|
try {
|
|
3294
3364
|
return this.request({
|
|
3295
3365
|
request: { method: "prompts/get", params: { name: t, arguments: e } },
|
|
3296
|
-
resultSchema:
|
|
3366
|
+
resultSchema: vs,
|
|
3297
3367
|
options: r
|
|
3298
3368
|
});
|
|
3299
3369
|
} catch (s) {
|
|
@@ -3329,36 +3399,36 @@ var tn = class {
|
|
|
3329
3399
|
for (const {
|
|
3330
3400
|
name: a,
|
|
3331
3401
|
title: i,
|
|
3332
|
-
description:
|
|
3333
|
-
inputSchema:
|
|
3334
|
-
annotations:
|
|
3402
|
+
description: c,
|
|
3403
|
+
inputSchema: u,
|
|
3404
|
+
annotations: l,
|
|
3335
3405
|
_meta: p
|
|
3336
3406
|
} of t.tools) {
|
|
3337
|
-
const
|
|
3407
|
+
const m = i ?? l?.title;
|
|
3338
3408
|
if (e !== "automatic" && !(a in e))
|
|
3339
3409
|
continue;
|
|
3340
|
-
const d = this,
|
|
3410
|
+
const d = this, g = e !== "automatic" ? (r = e[a]) == null ? void 0 : r.outputSchema : void 0, y = async (f, v) => {
|
|
3341
3411
|
var b;
|
|
3342
3412
|
(b = v?.abortSignal) == null || b.throwIfAborted();
|
|
3343
3413
|
const T = await d.callTool({ name: a, args: f, options: v });
|
|
3344
|
-
return
|
|
3345
|
-
}, h = e === "automatic" ?
|
|
3346
|
-
description:
|
|
3347
|
-
title:
|
|
3414
|
+
return g != null ? d.extractStructuredContent(T, g, a) : T;
|
|
3415
|
+
}, h = e === "automatic" ? Wr({
|
|
3416
|
+
description: c,
|
|
3417
|
+
title: m,
|
|
3348
3418
|
inputSchema: J({
|
|
3349
|
-
...
|
|
3350
|
-
properties: (s =
|
|
3419
|
+
...u,
|
|
3420
|
+
properties: (s = u.properties) != null ? s : {},
|
|
3351
3421
|
additionalProperties: !1
|
|
3352
3422
|
}),
|
|
3353
3423
|
execute: y,
|
|
3354
|
-
toModelOutput:
|
|
3424
|
+
toModelOutput: Ne
|
|
3355
3425
|
}) : {
|
|
3356
|
-
description:
|
|
3357
|
-
title:
|
|
3426
|
+
description: c,
|
|
3427
|
+
title: m,
|
|
3358
3428
|
inputSchema: e[a].inputSchema,
|
|
3359
|
-
...
|
|
3429
|
+
...g != null ? { outputSchema: g } : {},
|
|
3360
3430
|
execute: y,
|
|
3361
|
-
toModelOutput:
|
|
3431
|
+
toModelOutput: Ne
|
|
3362
3432
|
};
|
|
3363
3433
|
n[a] = { ...h, _meta: p };
|
|
3364
3434
|
}
|
|
@@ -3369,9 +3439,9 @@ var tn = class {
|
|
|
3369
3439
|
*/
|
|
3370
3440
|
async extractStructuredContent(t, e, r) {
|
|
3371
3441
|
if ("structuredContent" in t && t.structuredContent != null) {
|
|
3372
|
-
const s = await
|
|
3442
|
+
const s = await Xe({
|
|
3373
3443
|
value: t.structuredContent,
|
|
3374
|
-
schema:
|
|
3444
|
+
schema: Ke(e)
|
|
3375
3445
|
});
|
|
3376
3446
|
if (!s.success)
|
|
3377
3447
|
throw new _({
|
|
@@ -3383,7 +3453,7 @@ var tn = class {
|
|
|
3383
3453
|
if ("content" in t && Array.isArray(t.content)) {
|
|
3384
3454
|
const s = t.content.find((n) => n.type === "text");
|
|
3385
3455
|
if (s && "text" in s) {
|
|
3386
|
-
const n = await
|
|
3456
|
+
const n = await Jr({
|
|
3387
3457
|
text: s.text,
|
|
3388
3458
|
schema: e
|
|
3389
3459
|
});
|
|
@@ -3430,7 +3500,7 @@ var tn = class {
|
|
|
3430
3500
|
return this.getPromptInternal({ name: t, args: e, options: r });
|
|
3431
3501
|
}
|
|
3432
3502
|
onElicitationRequest(t, e) {
|
|
3433
|
-
if (t !==
|
|
3503
|
+
if (t !== Le)
|
|
3434
3504
|
throw new _({
|
|
3435
3505
|
message: "Unsupported request schema. Only ElicitationRequestSchema is supported."
|
|
3436
3506
|
});
|
|
@@ -3460,7 +3530,7 @@ var tn = class {
|
|
|
3460
3530
|
});
|
|
3461
3531
|
return;
|
|
3462
3532
|
}
|
|
3463
|
-
const e =
|
|
3533
|
+
const e = Le.safeParse({
|
|
3464
3534
|
method: t.method,
|
|
3465
3535
|
params: t.params
|
|
3466
3536
|
});
|
|
@@ -3477,7 +3547,7 @@ var tn = class {
|
|
|
3477
3547
|
return;
|
|
3478
3548
|
}
|
|
3479
3549
|
try {
|
|
3480
|
-
const r = await this.elicitationRequestHandler(e.data), s =
|
|
3550
|
+
const r = await this.elicitationRequestHandler(e.data), s = _s.parse(r);
|
|
3481
3551
|
await this.transport.send({
|
|
3482
3552
|
jsonrpc: "2.0",
|
|
3483
3553
|
id: t.id,
|
|
@@ -3528,15 +3598,15 @@ var tn = class {
|
|
|
3528
3598
|
);
|
|
3529
3599
|
}
|
|
3530
3600
|
};
|
|
3531
|
-
const
|
|
3601
|
+
const nn = async (t) => {
|
|
3532
3602
|
const e = {};
|
|
3533
3603
|
try {
|
|
3534
3604
|
const r = await t.listTools();
|
|
3535
3605
|
for (const { name: s, description: n, inputSchema: a } of r.tools) {
|
|
3536
|
-
const i = async (
|
|
3537
|
-
e[s] =
|
|
3606
|
+
const i = async (c, u) => t.callTool({ name: s, arguments: c }, { signal: u?.abortSignal });
|
|
3607
|
+
e[s] = Ze({
|
|
3538
3608
|
description: n,
|
|
3539
|
-
inputSchema:
|
|
3609
|
+
inputSchema: De({
|
|
3540
3610
|
...a,
|
|
3541
3611
|
properties: a.properties ?? {},
|
|
3542
3612
|
additionalProperties: !1
|
|
@@ -3548,8 +3618,44 @@ const rn = async (t) => {
|
|
|
3548
3618
|
} catch (r) {
|
|
3549
3619
|
throw r;
|
|
3550
3620
|
}
|
|
3621
|
+
}, on = async (t) => {
|
|
3622
|
+
const e = {};
|
|
3623
|
+
if (!t)
|
|
3624
|
+
return e;
|
|
3625
|
+
const r = t, s = r.listTools ?? r.getTools;
|
|
3626
|
+
if (!s)
|
|
3627
|
+
return e;
|
|
3628
|
+
const n = await s.call(r), a = Array.isArray(n) ? n : [];
|
|
3629
|
+
for (const i of a) {
|
|
3630
|
+
const { name: c, description: u } = i, l = i.inputSchema;
|
|
3631
|
+
let p = {};
|
|
3632
|
+
if (typeof l == "string")
|
|
3633
|
+
try {
|
|
3634
|
+
p = JSON.parse(l);
|
|
3635
|
+
} catch (d) {
|
|
3636
|
+
console.error("Failed to parse inputSchema in getBuiltinMcpTools:", d);
|
|
3637
|
+
}
|
|
3638
|
+
else typeof l == "object" && l !== null && (p = l);
|
|
3639
|
+
const m = {
|
|
3640
|
+
type: "object",
|
|
3641
|
+
properties: p.properties ?? {},
|
|
3642
|
+
...p.required ? { required: p.required } : {},
|
|
3643
|
+
additionalProperties: !1,
|
|
3644
|
+
...p
|
|
3645
|
+
};
|
|
3646
|
+
e[c] = Ze({
|
|
3647
|
+
description: u ?? "",
|
|
3648
|
+
inputSchema: De(m),
|
|
3649
|
+
async execute(d) {
|
|
3650
|
+
if (!r.executeTool)
|
|
3651
|
+
throw new Error("navigator.modelContextTesting.executeTool is not available");
|
|
3652
|
+
return r.executeTool(c, JSON.stringify(d ?? {}));
|
|
3653
|
+
}
|
|
3654
|
+
});
|
|
3655
|
+
}
|
|
3656
|
+
return e;
|
|
3551
3657
|
};
|
|
3552
|
-
function
|
|
3658
|
+
function an(t) {
|
|
3553
3659
|
const e = Object.entries(t);
|
|
3554
3660
|
if (e.length === 0)
|
|
3555
3661
|
return "";
|
|
@@ -3561,11 +3667,11 @@ function sn(t) {
|
|
|
3561
3667
|
<tools>
|
|
3562
3668
|
`;
|
|
3563
3669
|
return e.forEach(([s, n]) => {
|
|
3564
|
-
const a = n, i = a.description || "无描述",
|
|
3670
|
+
const a = n, i = a.description || "无描述", c = a.parameters || a.inputSchema || {};
|
|
3565
3671
|
r += `${JSON.stringify({
|
|
3566
3672
|
name: s,
|
|
3567
3673
|
description: i,
|
|
3568
|
-
parameters:
|
|
3674
|
+
parameters: c
|
|
3569
3675
|
}, null, 2)}
|
|
3570
3676
|
`;
|
|
3571
3677
|
}), r += `
|
|
@@ -3599,7 +3705,7 @@ Thought: 用户想要获取今天的日期,我需要调用日期相关的工
|
|
|
3599
3705
|
- 如果不需要调用工具,直接给出最终答案即可
|
|
3600
3706
|
`, r;
|
|
3601
3707
|
}
|
|
3602
|
-
function
|
|
3708
|
+
function qe(t, e) {
|
|
3603
3709
|
if (!t || typeof t != "string")
|
|
3604
3710
|
return null;
|
|
3605
3711
|
const r = t.match(/<tool_call>([\s\S]*?)<\/tool_call>/i);
|
|
@@ -3612,11 +3718,11 @@ function Ne(t, e) {
|
|
|
3612
3718
|
}
|
|
3613
3719
|
return null;
|
|
3614
3720
|
}
|
|
3615
|
-
const
|
|
3721
|
+
const cn = {
|
|
3616
3722
|
openai: $t,
|
|
3617
|
-
deepseek:
|
|
3723
|
+
deepseek: Nt
|
|
3618
3724
|
};
|
|
3619
|
-
class
|
|
3725
|
+
class Un {
|
|
3620
3726
|
constructor({ llmConfig: e, mcpServers: r }) {
|
|
3621
3727
|
if (this.mcpServers = {}, this.mcpClients = {}, this.mcpTools = {}, this.ignoreToolnames = [], this.responseMessages = [], this.useReActMode = !1, !e)
|
|
3622
3728
|
throw new Error("llmConfig is required to initialize AgentModelProvider");
|
|
@@ -3625,7 +3731,7 @@ class xn {
|
|
|
3625
3731
|
else if (e.providerType) {
|
|
3626
3732
|
const s = e.providerType;
|
|
3627
3733
|
let n;
|
|
3628
|
-
typeof s == "string" ? n =
|
|
3734
|
+
typeof s == "string" ? n = cn[s] : n = s, this.llm = n({
|
|
3629
3735
|
apiKey: e.apiKey,
|
|
3630
3736
|
baseURL: e.baseURL
|
|
3631
3737
|
});
|
|
@@ -3637,18 +3743,26 @@ class xn {
|
|
|
3637
3743
|
async _createOneClient(e) {
|
|
3638
3744
|
try {
|
|
3639
3745
|
let r;
|
|
3746
|
+
if ("type" in e && e.type === "builtin") {
|
|
3747
|
+
const n = e.client;
|
|
3748
|
+
return {
|
|
3749
|
+
tools: () => on(n),
|
|
3750
|
+
close: async () => {
|
|
3751
|
+
}
|
|
3752
|
+
};
|
|
3753
|
+
}
|
|
3640
3754
|
if ("type" in e && e.type.toLocaleLowerCase() === "streamablehttp") {
|
|
3641
3755
|
const n = e, a = n.headers ? { headers: n.headers } : void 0;
|
|
3642
3756
|
r = new se(new URL(n.url), { requestInit: a });
|
|
3643
3757
|
} else if ("type" in e && e.type === "sse") {
|
|
3644
3758
|
const n = e, a = n.headers ? { headers: n.headers } : void 0;
|
|
3645
3759
|
r = new ne(new URL(n.url), { requestInit: a });
|
|
3646
|
-
} else "type" in e && e.type === "extension" ? r = new
|
|
3760
|
+
} else "type" in e && e.type === "extension" ? r = new Vt(e.sessionId) : "transport" in e ? r = e.transport : r = e;
|
|
3647
3761
|
if (e.useAISdkClient ?? !1) {
|
|
3648
|
-
const n = await
|
|
3762
|
+
const n = await rn({ transport: r });
|
|
3649
3763
|
return n.__transport__ = r, n;
|
|
3650
3764
|
} else {
|
|
3651
|
-
const n = new
|
|
3765
|
+
const n = new Zt(
|
|
3652
3766
|
{ name: "mcp-web-client", version: "1.0.0" },
|
|
3653
3767
|
{ capabilities: { roots: { listChanged: !0 }, sampling: {}, elicitation: {} } }
|
|
3654
3768
|
);
|
|
@@ -3662,7 +3776,7 @@ class xn {
|
|
|
3662
3776
|
async _closeOneClient(e) {
|
|
3663
3777
|
try {
|
|
3664
3778
|
const r = e.__transport__;
|
|
3665
|
-
if (r && r instanceof Ut || r && r instanceof
|
|
3779
|
+
if (r && r instanceof Ut || r && r instanceof wt)
|
|
3666
3780
|
return;
|
|
3667
3781
|
await r?.terminateSession?.(), await r?.close?.(), await e?.close?.();
|
|
3668
3782
|
} catch {
|
|
@@ -3685,7 +3799,7 @@ class xn {
|
|
|
3685
3799
|
if (!e)
|
|
3686
3800
|
return null;
|
|
3687
3801
|
try {
|
|
3688
|
-
return typeof e.tools == "function" ? await e.tools() : await
|
|
3802
|
+
return typeof e.tools == "function" ? await e.tools() : await nn(e);
|
|
3689
3803
|
} catch (s) {
|
|
3690
3804
|
return this.onError && this.onError(s?.message || `Failed to query tools for ${r}`, s), console.error(`Failed to query tools for ${r}`, s), null;
|
|
3691
3805
|
}
|
|
@@ -3770,7 +3884,7 @@ class xn {
|
|
|
3770
3884
|
}
|
|
3771
3885
|
/** 生成 ReAct 模式的系统提示词(包含工具描述) */
|
|
3772
3886
|
_generateReActSystemPrompt(e, r, s) {
|
|
3773
|
-
const n =
|
|
3887
|
+
const n = an(e);
|
|
3774
3888
|
return s ? `${s}${n}` : `你是一个智能助手,可以通过调用工具来完成任务。
|
|
3775
3889
|
${n}`;
|
|
3776
3890
|
}
|
|
@@ -3794,10 +3908,10 @@ ${n}`;
|
|
|
3794
3908
|
const a = this._tempMergeTools(n.tools);
|
|
3795
3909
|
if (Object.keys(a).length === 0)
|
|
3796
3910
|
return this._chat(e, { model: r, maxSteps: s, ...n });
|
|
3797
|
-
let
|
|
3798
|
-
n.message && !n.messages ?
|
|
3799
|
-
const
|
|
3800
|
-
return e === ie ? this._chatReActStream(
|
|
3911
|
+
let c = [];
|
|
3912
|
+
n.message && !n.messages ? c.push({ role: "user", content: n.message }) : n.messages ? c = [...n.messages] : c = [...this.responseMessages];
|
|
3913
|
+
const u = typeof r == "string" ? r : r?.modelId || "default-model", p = { role: "system", content: this._generateReActSystemPrompt(a, u, n.system) }, m = c[0]?.role === "system" ? c : [p, ...c];
|
|
3914
|
+
return e === ie ? this._chatReActStream(m, a, u, s, n) : this._chatReActNonStream(m, a, u, s, n);
|
|
3801
3915
|
}
|
|
3802
3916
|
/**
|
|
3803
3917
|
* 检查消息内容是否包含图片
|
|
@@ -3837,36 +3951,36 @@ ${n}`;
|
|
|
3837
3951
|
e && n.push(e);
|
|
3838
3952
|
let a = 0;
|
|
3839
3953
|
const i = [];
|
|
3840
|
-
for (let
|
|
3841
|
-
const
|
|
3842
|
-
if (this._messageHasImage(
|
|
3954
|
+
for (let c = r.length - 1; c >= 0; c--) {
|
|
3955
|
+
const u = r[c];
|
|
3956
|
+
if (this._messageHasImage(u.content))
|
|
3843
3957
|
if (a < s)
|
|
3844
|
-
i.unshift(
|
|
3958
|
+
i.unshift(u), a++;
|
|
3845
3959
|
else {
|
|
3846
|
-
const p = this._removeImageFromMessage(
|
|
3960
|
+
const p = this._removeImageFromMessage(u);
|
|
3847
3961
|
p && i.unshift(p);
|
|
3848
3962
|
}
|
|
3849
3963
|
else
|
|
3850
|
-
i.unshift(
|
|
3964
|
+
i.unshift(u);
|
|
3851
3965
|
}
|
|
3852
3966
|
return n.push(...i), n;
|
|
3853
3967
|
}
|
|
3854
3968
|
/** ReAct 模式非流式对话 */
|
|
3855
3969
|
async _chatReActNonStream(e, r, s, n, a) {
|
|
3856
3970
|
let i = [...e];
|
|
3857
|
-
const
|
|
3858
|
-
let
|
|
3971
|
+
const c = e[0]?.role === "system" ? e[0] : null, u = c ? e.slice(1) : e;
|
|
3972
|
+
let l = 0;
|
|
3859
3973
|
const p = a.maxImages ?? 3;
|
|
3860
|
-
for (;
|
|
3861
|
-
|
|
3862
|
-
const d = this._buildMessagesForModel(
|
|
3974
|
+
for (; l < n; ) {
|
|
3975
|
+
l++;
|
|
3976
|
+
const d = this._buildMessagesForModel(c, u, p), { tools: g, ...y } = a, f = (await Pe({
|
|
3863
3977
|
// @ts-ignore ProviderV2 是所有llm的父类,在每一个具体的llm类都有一个选择model的函数用法
|
|
3864
3978
|
model: this.llm(s),
|
|
3865
3979
|
messages: d,
|
|
3866
3980
|
...y
|
|
3867
3981
|
})).text, v = { role: "assistant", content: f };
|
|
3868
|
-
|
|
3869
|
-
const b =
|
|
3982
|
+
u.push(v), i.push(v);
|
|
3983
|
+
const b = qe(f, r);
|
|
3870
3984
|
if (!b)
|
|
3871
3985
|
return this.responseMessages = i, {
|
|
3872
3986
|
text: f,
|
|
@@ -3878,7 +3992,7 @@ ${n}`;
|
|
|
3878
3992
|
${T.success ? JSON.stringify(T.result) : `工具执行失败 - ${T.error}`}
|
|
3879
3993
|
</tool_response>`
|
|
3880
3994
|
};
|
|
3881
|
-
|
|
3995
|
+
u.push(k), i.push(k);
|
|
3882
3996
|
}
|
|
3883
3997
|
return this.responseMessages = i, {
|
|
3884
3998
|
text: i[i.length - 2]?.content || "",
|
|
@@ -3887,15 +4001,15 @@ ${T.success ? JSON.stringify(T.result) : `工具执行失败 - ${T.error}`}
|
|
|
3887
4001
|
}
|
|
3888
4002
|
/** ReAct 模式流式对话 */
|
|
3889
4003
|
_chatReActStream(e, r, s, n, a) {
|
|
3890
|
-
const i = this,
|
|
3891
|
-
let
|
|
3892
|
-
const p = new Promise((d,
|
|
3893
|
-
|
|
4004
|
+
const i = this, c = this.llm(s);
|
|
4005
|
+
let u, l;
|
|
4006
|
+
const p = new Promise((d, g) => {
|
|
4007
|
+
u = d, l = g;
|
|
3894
4008
|
});
|
|
3895
4009
|
return {
|
|
3896
4010
|
fullStream: new ReadableStream({
|
|
3897
4011
|
async start(d) {
|
|
3898
|
-
let
|
|
4012
|
+
let g = [...e];
|
|
3899
4013
|
const y = e[0]?.role === "system" ? e[0] : null, h = y ? e.slice(1) : [...e];
|
|
3900
4014
|
let f = 0, v = "";
|
|
3901
4015
|
const b = a.maxImages ?? 3;
|
|
@@ -3907,88 +4021,88 @@ ${T.success ? JSON.stringify(T.result) : `工具执行失败 - ${T.error}`}
|
|
|
3907
4021
|
delete M.system, delete M.onFinish;
|
|
3908
4022
|
const k = await ie({
|
|
3909
4023
|
...M,
|
|
3910
|
-
model:
|
|
4024
|
+
model: c,
|
|
3911
4025
|
messages: T
|
|
3912
4026
|
});
|
|
3913
4027
|
let O = "";
|
|
3914
|
-
for await (const
|
|
3915
|
-
|
|
4028
|
+
for await (const C of k.fullStream)
|
|
4029
|
+
C.type === "text-delta" ? (O += C.text || "", d.enqueue({
|
|
3916
4030
|
type: "text-delta",
|
|
3917
|
-
text:
|
|
3918
|
-
})) :
|
|
4031
|
+
text: C.text
|
|
4032
|
+
})) : C.type === "text-start" ? d.enqueue({ type: "text-start" }) : C.type === "text-end" || C.type === "finish-step" || C.type === "finish" || C.type === "start" || C.type === "start-step" || d.enqueue(C);
|
|
3919
4033
|
v += O;
|
|
3920
4034
|
const H = { role: "assistant", content: v };
|
|
3921
|
-
h.push(H),
|
|
3922
|
-
const
|
|
3923
|
-
if (!
|
|
3924
|
-
d.enqueue({ type: "text-end" }), d.enqueue({ type: "finish-step" }), d.enqueue({ type: "finish" }), d.close(), i.responseMessages =
|
|
4035
|
+
h.push(H), g.push(H);
|
|
4036
|
+
const x = qe(v, r);
|
|
4037
|
+
if (!x) {
|
|
4038
|
+
d.enqueue({ type: "text-end" }), d.enqueue({ type: "finish-step" }), d.enqueue({ type: "finish" }), d.close(), i.responseMessages = g, u({ messages: g });
|
|
3925
4039
|
return;
|
|
3926
4040
|
}
|
|
3927
|
-
if (
|
|
3928
|
-
d.enqueue({ type: "text-end" }), d.enqueue({ type: "finish-step" }), d.enqueue({ type: "finish" }), d.close(), i.responseMessages =
|
|
4041
|
+
if (x.toolName === "computer" && x.arguments?.action === "terminate") {
|
|
4042
|
+
d.enqueue({ type: "text-end" }), d.enqueue({ type: "finish-step" }), d.enqueue({ type: "finish" }), d.close(), i.responseMessages = g, u({ messages: g });
|
|
3929
4043
|
return;
|
|
3930
4044
|
}
|
|
3931
|
-
const
|
|
4045
|
+
const $ = `react-${Date.now()}`;
|
|
3932
4046
|
d.enqueue({
|
|
3933
4047
|
type: "tool-input-start",
|
|
3934
|
-
id:
|
|
3935
|
-
toolName:
|
|
4048
|
+
id: $,
|
|
4049
|
+
toolName: x.toolName
|
|
3936
4050
|
});
|
|
3937
|
-
const z = JSON.stringify(
|
|
4051
|
+
const z = JSON.stringify(x.arguments, null, 2);
|
|
3938
4052
|
d.enqueue({
|
|
3939
4053
|
type: "tool-input-delta",
|
|
3940
|
-
id:
|
|
4054
|
+
id: $,
|
|
3941
4055
|
delta: z
|
|
3942
4056
|
}), d.enqueue({
|
|
3943
4057
|
type: "tool-input-end",
|
|
3944
|
-
id:
|
|
4058
|
+
id: $
|
|
3945
4059
|
}), d.enqueue({
|
|
3946
4060
|
type: "tool-call",
|
|
3947
|
-
toolCallId:
|
|
3948
|
-
toolName:
|
|
3949
|
-
input:
|
|
4061
|
+
toolCallId: $,
|
|
4062
|
+
toolName: x.toolName,
|
|
4063
|
+
input: x.arguments
|
|
3950
4064
|
});
|
|
3951
|
-
const
|
|
3952
|
-
let B, N =
|
|
3953
|
-
if (
|
|
3954
|
-
B =
|
|
3955
|
-
const { screenshot:
|
|
4065
|
+
const I = await i._executeReActToolCall(x.toolName, x.arguments, r);
|
|
4066
|
+
let B, N = I.result;
|
|
4067
|
+
if (I.success && I.result && typeof I.result == "object" && I.result.screenshot) {
|
|
4068
|
+
B = I.result.screenshot;
|
|
4069
|
+
const { screenshot: C, ...G } = I.result;
|
|
3956
4070
|
N = G;
|
|
3957
4071
|
}
|
|
3958
4072
|
let F = "";
|
|
3959
|
-
if (
|
|
4073
|
+
if (I.success) {
|
|
3960
4074
|
N && Array.isArray(N.content) && N.content.length > 0 && N.content[0].text ? F = N.content[0].text : F = JSON.stringify(N);
|
|
3961
|
-
let
|
|
4075
|
+
let C = `<tool_response>
|
|
3962
4076
|
${F}
|
|
3963
4077
|
</tool_response>`;
|
|
3964
|
-
B && (
|
|
4078
|
+
B && (C += `
|
|
3965
4079
|
请检查截图以确认操作是否成功。如果成功,请继续下一步;如果失败,请重试。`), d.enqueue({
|
|
3966
4080
|
type: "tool-result",
|
|
3967
|
-
toolCallId:
|
|
3968
|
-
result:
|
|
4081
|
+
toolCallId: $,
|
|
4082
|
+
result: C
|
|
3969
4083
|
});
|
|
3970
4084
|
const G = B ? {
|
|
3971
4085
|
role: "user",
|
|
3972
4086
|
content: [
|
|
3973
|
-
{ type: "text", text:
|
|
4087
|
+
{ type: "text", text: C },
|
|
3974
4088
|
{ type: "image", image: B }
|
|
3975
4089
|
]
|
|
3976
4090
|
} : {
|
|
3977
4091
|
role: "user",
|
|
3978
|
-
content:
|
|
4092
|
+
content: C
|
|
3979
4093
|
};
|
|
3980
|
-
h.push(G),
|
|
4094
|
+
h.push(G), g.push(G), v = "";
|
|
3981
4095
|
} else
|
|
3982
|
-
F = `工具执行失败 - ${
|
|
4096
|
+
F = `工具执行失败 - ${I.error}`, d.enqueue({
|
|
3983
4097
|
type: "tool-error",
|
|
3984
|
-
toolCallId:
|
|
3985
|
-
input:
|
|
4098
|
+
toolCallId: $,
|
|
4099
|
+
input: x.arguments,
|
|
3986
4100
|
error: { message: F }
|
|
3987
4101
|
});
|
|
3988
4102
|
}
|
|
3989
|
-
d.enqueue({ type: "text-end" }), d.enqueue({ type: "finish-step" }), d.enqueue({ type: "finish" }), d.close(), i.responseMessages =
|
|
4103
|
+
d.enqueue({ type: "text-end" }), d.enqueue({ type: "finish-step" }), d.enqueue({ type: "finish" }), d.close(), i.responseMessages = g, u({ messages: g });
|
|
3990
4104
|
} catch (T) {
|
|
3991
|
-
d.error(T),
|
|
4105
|
+
d.error(T), l(T);
|
|
3992
4106
|
}
|
|
3993
4107
|
}
|
|
3994
4108
|
}),
|
|
@@ -4001,16 +4115,16 @@ ${F}
|
|
|
4001
4115
|
if (!this.llm)
|
|
4002
4116
|
throw new Error("LLM is not initialized");
|
|
4003
4117
|
await this.initClientsAndTools();
|
|
4004
|
-
const a = n.tools || {}, i = this._tempMergeTools(a, !1),
|
|
4005
|
-
const
|
|
4006
|
-
Object.entries(
|
|
4118
|
+
const a = n.tools || {}, i = this._tempMergeTools(a, !1), c = () => {
|
|
4119
|
+
const g = this._tempMergeTools(a, !1);
|
|
4120
|
+
Object.entries(g).forEach(([y, h]) => {
|
|
4007
4121
|
i[y] = h;
|
|
4008
4122
|
}), Object.keys(i).forEach((y) => {
|
|
4009
|
-
y in
|
|
4123
|
+
y in g || delete i[y];
|
|
4010
4124
|
});
|
|
4011
|
-
},
|
|
4012
|
-
|
|
4013
|
-
const y = this._getActiveToolNames(i), h = typeof
|
|
4125
|
+
}, u = n.prepareStep, l = async (g) => {
|
|
4126
|
+
c();
|
|
4127
|
+
const y = this._getActiveToolNames(i), h = typeof u == "function" ? await u(g) : void 0, f = h && typeof h == "object" ? h : {};
|
|
4014
4128
|
return {
|
|
4015
4129
|
...f,
|
|
4016
4130
|
activeTools: Array.isArray(f.activeTools) ? f.activeTools.filter((v) => y.includes(v)) : y
|
|
@@ -4018,23 +4132,23 @@ ${F}
|
|
|
4018
4132
|
}, p = {
|
|
4019
4133
|
// @ts-ignore ProviderV2 是所有llm的父类, 在每一个具体的llm 类都有一个选择model的函数用法
|
|
4020
4134
|
model: this.llm(r),
|
|
4021
|
-
stopWhen:
|
|
4135
|
+
stopWhen: Lt(s),
|
|
4022
4136
|
...n,
|
|
4023
4137
|
tools: i,
|
|
4024
|
-
prepareStep:
|
|
4138
|
+
prepareStep: l,
|
|
4025
4139
|
activeTools: this._getActiveToolNames(i)
|
|
4026
4140
|
};
|
|
4027
|
-
let
|
|
4141
|
+
let m = null;
|
|
4028
4142
|
if (n.message && !n.messages)
|
|
4029
|
-
|
|
4143
|
+
m = { role: "user", content: n.message }, this.responseMessages.push(m), p.messages = [...this.responseMessages];
|
|
4030
4144
|
else if (n.messages && n.messages.length > 0) {
|
|
4031
|
-
const
|
|
4032
|
-
|
|
4145
|
+
const g = n.messages[n.messages.length - 1];
|
|
4146
|
+
g.role === "user" && (m = g);
|
|
4033
4147
|
}
|
|
4034
4148
|
const d = e(p);
|
|
4035
|
-
return d?.response?.then((
|
|
4036
|
-
const y =
|
|
4037
|
-
|
|
4149
|
+
return d?.response?.then((g) => {
|
|
4150
|
+
const y = g.messages?.[0];
|
|
4151
|
+
m && y?.role !== "user" && this.responseMessages.push(m), this.responseMessages.push(...g.messages);
|
|
4038
4152
|
}), d;
|
|
4039
4153
|
}
|
|
4040
4154
|
async chat(e) {
|
|
@@ -4045,24 +4159,24 @@ ${F}
|
|
|
4045
4159
|
}
|
|
4046
4160
|
}
|
|
4047
4161
|
export {
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4162
|
+
Un as A,
|
|
4163
|
+
Vt as E,
|
|
4164
|
+
Tn as W,
|
|
4165
|
+
Pn as a,
|
|
4166
|
+
Mn as b,
|
|
4167
|
+
Cn as c,
|
|
4168
|
+
Zt as d,
|
|
4169
|
+
En as e,
|
|
4170
|
+
An as f,
|
|
4171
|
+
nn as g,
|
|
4172
|
+
kn as h,
|
|
4173
|
+
Rn as i,
|
|
4174
|
+
On as j,
|
|
4175
|
+
Dt as k,
|
|
4176
|
+
xn as l,
|
|
4177
|
+
In as m,
|
|
4178
|
+
Ft as n,
|
|
4179
|
+
jn as o,
|
|
4180
|
+
zt as p,
|
|
4181
|
+
Ln as s
|
|
4068
4182
|
};
|