@opentiny/next-sdk 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent/AgentModelProvider.ts +78 -81
- package/agent/type.ts +6 -9
- package/agent/utils/getAISDKTools.ts +0 -1
- package/agent/utils/getBuiltinMcpTools.ts +7 -7
- package/core.ts +0 -3
- package/dist/SimulatorMask-BHVXyogh-iNUb4dyF.js +361 -0
- package/dist/agent/type.d.ts +4 -12
- package/dist/agent/utils/getBuiltinMcpTools.d.ts +3 -3
- package/dist/core.d.ts +0 -1
- package/dist/core.js +16 -17
- package/dist/index-CXK8CcKq.js +6076 -0
- package/dist/index.d.ts +0 -3
- package/dist/index.js +57 -4969
- package/dist/{initialize-builtin-WebMCP-HgObT902.js → initialize-builtin-WebMCP-rALfqS-o.js} +1166 -1056
- package/dist/page-tools/a11y/build.d.ts +11 -0
- package/dist/page-tools/a11y/constants.d.ts +9 -0
- package/dist/page-tools/a11y/search.d.ts +17 -0
- package/dist/page-tools/a11y/types.d.ts +104 -0
- package/dist/page-tools/a11y/utils.d.ts +34 -0
- package/dist/page-tools/a11y/vnode.d.ts +37 -0
- package/dist/page-tools/a11y-tree.d.ts +8 -99
- package/dist/page-tools/constants.d.ts +22 -0
- package/dist/page-tools/context.d.ts +28 -0
- package/dist/page-tools/handlers/browserState.d.ts +8 -0
- package/dist/page-tools/handlers/click.d.ts +8 -0
- package/dist/page-tools/handlers/executeJavascript.d.ts +8 -0
- package/dist/page-tools/handlers/fill.d.ts +8 -0
- package/dist/page-tools/handlers/scroll.d.ts +8 -0
- package/dist/page-tools/handlers/searchTree.d.ts +8 -0
- package/dist/page-tools/handlers/select.d.ts +8 -0
- package/dist/page-tools/page-agent-highlight/index.d.ts +9 -0
- package/dist/page-tools/page-agent-mask/SimulatorMask.d.ts +14 -0
- package/dist/page-tools/page-agent-mask/checkDarkMode.d.ts +5 -0
- package/dist/page-tools/page-agent-tool.d.ts +3 -8
- package/dist/page-tools/schema.d.ts +43 -0
- package/dist/page-tools/utils/dom.d.ts +6 -0
- package/dist/page-tools/utils/scroll.d.ts +15 -0
- package/dist/runtime.d.ts +4 -0
- package/dist/runtime.js +744 -0
- package/dist/utils/builtinProxy.d.ts +1 -1
- package/index.ts +0 -5
- package/package.json +6 -17
- package/page-tools/a11y/build.ts +70 -0
- package/page-tools/a11y/constants.ts +110 -0
- package/page-tools/a11y/search.ts +129 -0
- package/page-tools/a11y/types.ts +108 -0
- package/page-tools/a11y/utils.ts +266 -0
- package/page-tools/a11y/vnode.ts +229 -0
- package/page-tools/a11y-tree.ts +8 -527
- package/page-tools/bridge.ts +1 -1
- package/page-tools/constants.ts +72 -0
- package/page-tools/context.ts +13 -0
- package/page-tools/handlers/browserState.ts +12 -0
- package/page-tools/handlers/click.ts +26 -0
- package/page-tools/handlers/executeJavascript.ts +22 -0
- package/page-tools/handlers/fill.ts +60 -0
- package/page-tools/handlers/scroll.ts +66 -0
- package/page-tools/handlers/searchTree.ts +30 -0
- package/page-tools/handlers/select.ts +34 -0
- package/page-tools/page-agent-highlight/index.ts +198 -0
- package/page-tools/page-agent-mask/SimulatorMask.module.css +14 -0
- package/page-tools/page-agent-mask/SimulatorMask.ts +279 -0
- package/page-tools/page-agent-mask/checkDarkMode.ts +181 -0
- package/page-tools/page-agent-mask/cursor-border.svg +3 -0
- package/page-tools/page-agent-mask/cursor-fill.svg +5 -0
- package/page-tools/page-agent-mask/cursor.module.css +70 -0
- package/page-tools/page-agent-prompt.md +34 -18
- package/page-tools/page-agent-tool.ts +104 -152
- package/page-tools/schema.ts +51 -0
- package/page-tools/utils/dom.ts +155 -0
- package/page-tools/utils/scroll.ts +58 -0
- package/runtime.ts +13 -0
- package/utils/builtinProxy.ts +45 -13
- package/vite.config.runtime.ts +22 -0
- package/vite.config.ts +52 -8
- package/McpSdk.ts +0 -14
- package/WebAgent.ts +0 -5
- package/WebMcp.ts +0 -26
- package/Zod.ts +0 -1
- package/dist/McpSdk.d.ts +0 -14
- package/dist/SimulatorMask-BHVXyogh-BFEGpD5S.js +0 -1048
- package/dist/SimulatorMask-BHVXyogh-CCYbrb84.js +0 -801
- package/dist/WebAgent.d.ts +0 -5
- package/dist/WebMcp.d.ts +0 -23
- package/dist/Zod.d.ts +0 -1
- package/dist/index.es.dev.js +0 -59017
- package/dist/index.es.js +0 -46795
- package/dist/index.umd.dev.js +0 -60355
- package/dist/index.umd.js +0 -1248
- package/dist/mcpsdk@1.25.3.dev.js +0 -22780
- package/dist/mcpsdk@1.25.3.es.dev.js +0 -22778
- package/dist/mcpsdk@1.25.3.es.js +0 -16960
- package/dist/mcpsdk@1.25.3.js +0 -48
- package/dist/transport/ExtensionClientTransport.d.ts +0 -24
- package/dist/transport/ExtensionContentServerTransport.d.ts +0 -39
- package/dist/transport/ExtensionPageServerTransport.d.ts +0 -36
- package/dist/transport/messages.d.ts +0 -9
- package/dist/vite.config.mcpSdk.d.ts +0 -2
- package/dist/vite.config.webAgent.d.ts +0 -2
- package/dist/vite.config.webMcp.d.ts +0 -2
- package/dist/vite.config.webMcpFull.d.ts +0 -2
- package/dist/vite.config.zod.d.ts +0 -2
- package/dist/webagent.dev.js +0 -49360
- package/dist/webagent.es.dev.js +0 -49071
- package/dist/webagent.es.js +0 -39219
- package/dist/webagent.js +0 -642
- package/dist/webmcp-full.dev.js +0 -31336
- package/dist/webmcp-full.es.dev.js +0 -30283
- package/dist/webmcp-full.es.js +0 -22889
- package/dist/webmcp-full.js +0 -645
- package/dist/webmcp.dev.js +0 -9572
- package/dist/webmcp.es.dev.js +0 -8518
- package/dist/webmcp.es.js +0 -6727
- package/dist/webmcp.js +0 -602
- package/dist/zod@3.25.76.dev.js +0 -4037
- package/dist/zod@3.25.76.es.dev.js +0 -4033
- package/dist/zod@3.25.76.es.js +0 -2945
- package/dist/zod@3.25.76.js +0 -1
- package/transport/ExtensionClientTransport.ts +0 -100
- package/transport/ExtensionContentServerTransport.ts +0 -162
- package/transport/ExtensionPageServerTransport.ts +0 -149
- package/transport/messages.ts +0 -63
- package/vite-build-tsc.ts +0 -63
- package/vite-env.d.ts +0 -10
- package/vite.config.mcpSdk.ts +0 -28
- package/vite.config.webAgent.ts +0 -19
- package/vite.config.webMcp.ts +0 -40
- package/vite.config.webMcpFull.ts +0 -19
- package/vite.config.zod.ts +0 -23
- /package/dist/{vite-build-tsc.d.ts → vite.config.runtime.d.ts} +0 -0
package/dist/{initialize-builtin-WebMCP-HgObT902.js → initialize-builtin-WebMCP-rALfqS-o.js}
RENAMED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { MessageChannelServerTransport as
|
|
2
|
-
import { McpServer as
|
|
3
|
-
import { SetLevelRequestSchema as Ut, SubscribeRequestSchema as
|
|
4
|
-
import { dynamicTool as
|
|
5
|
-
import { TypeValidationError as Ce, JSONParseError as
|
|
6
|
-
import * as
|
|
1
|
+
import { MessageChannelServerTransport as xt, createTransportPair as on, MessageChannelClientTransport as St, createSseProxy as sn, createSocketProxy as an, createStreamProxy as ln, sseOptions as cn, streamOptions as un, MessageChannelTransport as dn } from "@opentiny/next";
|
|
2
|
+
import { McpServer as hr } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { SetLevelRequestSchema as Ut, SubscribeRequestSchema as fn, UnsubscribeRequestSchema as pn, ListResourcesRequestSchema as hn, RootsListChangedNotificationSchema as mn, CallToolResultSchema as gn, ElicitRequestSchema as yn, CreateMessageRequestSchema as vn, ListRootsRequestSchema as wn, ToolListChangedNotificationSchema as bn, PromptListChangedNotificationSchema as _n, ResourceListChangedNotificationSchema as xn, ResourceUpdatedNotificationSchema as Sn, LoggingMessageNotificationSchema as Tn } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
import { dynamicTool as mr, jsonSchema as gr, generateText as Dt, streamText as st, stepCountIs as Cn } from "ai";
|
|
5
|
+
import { TypeValidationError as Ce, JSONParseError as Le, InvalidArgumentError as $n, AISDKError as qe } from "@ai-sdk/provider";
|
|
6
|
+
import * as Lt from "zod/v4";
|
|
7
7
|
import { z as a } from "zod/v4";
|
|
8
8
|
import { ZodFirstPartyTypeKind as k } from "zod/v3";
|
|
9
9
|
import { StreamableHTTPClientTransport as Ye } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
10
10
|
import { SSEClientTransport as Xe } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
11
|
-
import { InMemoryTransport as
|
|
11
|
+
import { InMemoryTransport as En } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
12
12
|
import { createOpenAI as Pn } from "@ai-sdk/openai";
|
|
13
|
-
import { createDeepSeek as
|
|
14
|
-
import { Client as
|
|
15
|
-
import { WebSocketClientTransport as
|
|
16
|
-
class
|
|
13
|
+
import { createDeepSeek as Rn } from "@ai-sdk/deepseek";
|
|
14
|
+
import { Client as yr } from "@modelcontextprotocol/sdk/client/index.js";
|
|
15
|
+
import { WebSocketClientTransport as kn } from "@modelcontextprotocol/sdk/client/websocket.js";
|
|
16
|
+
class Wa {
|
|
17
17
|
constructor(t, r) {
|
|
18
18
|
const n = {
|
|
19
19
|
name: "web-mcp-server",
|
|
@@ -25,7 +25,7 @@ class Ua {
|
|
|
25
25
|
completions: {},
|
|
26
26
|
logging: {}
|
|
27
27
|
};
|
|
28
|
-
this.server = new
|
|
28
|
+
this.server = new hr(t || n, r || { capabilities: o }), this.server.server.oninitialized = () => {
|
|
29
29
|
this.oninitialized?.();
|
|
30
30
|
}, this.server.server.onclose = () => {
|
|
31
31
|
this.onclose?.();
|
|
@@ -37,7 +37,7 @@ class Ua {
|
|
|
37
37
|
* Connects the server to a transport via the specified option.
|
|
38
38
|
*/
|
|
39
39
|
async connect(t) {
|
|
40
|
-
return typeof t.start == "function" ? (this.transport = t, this.transport.onclose = void 0, this.transport.onerror = void 0, this.transport.onmessage = void 0) : (this.transport = new
|
|
40
|
+
return typeof t.start == "function" ? (this.transport = t, this.transport.onclose = void 0, this.transport.onerror = void 0, this.transport.onmessage = void 0) : (this.transport = new xt(t), await this.transport.listen()), await this.server.connect(this.transport), this.transport;
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
* Closes the connection.
|
|
@@ -179,13 +179,13 @@ class Ua {
|
|
|
179
179
|
* Registers a handler for the subscribe request.
|
|
180
180
|
*/
|
|
181
181
|
onSubscribe(t) {
|
|
182
|
-
this.server.server.setRequestHandler(
|
|
182
|
+
this.server.server.setRequestHandler(fn, t);
|
|
183
183
|
}
|
|
184
184
|
/**
|
|
185
185
|
* Registers a handler for the unsubscribe request.
|
|
186
186
|
*/
|
|
187
187
|
onUnsubscribe(t) {
|
|
188
|
-
this.server.server.setRequestHandler(
|
|
188
|
+
this.server.server.setRequestHandler(pn, t);
|
|
189
189
|
}
|
|
190
190
|
/**
|
|
191
191
|
* Registers a handler for the set log level request.
|
|
@@ -197,13 +197,13 @@ class Ua {
|
|
|
197
197
|
* Registers a handler for the list tools request.
|
|
198
198
|
*/
|
|
199
199
|
onListResources(t) {
|
|
200
|
-
this.server.server.setRequestHandler(
|
|
200
|
+
this.server.server.setRequestHandler(hn, t);
|
|
201
201
|
}
|
|
202
202
|
/**
|
|
203
203
|
* Registers a handler for the roots list changed notification.
|
|
204
204
|
*/
|
|
205
205
|
onRootsListChanged(t) {
|
|
206
|
-
this.server.server.setNotificationHandler(
|
|
206
|
+
this.server.server.setNotificationHandler(mn, t);
|
|
207
207
|
}
|
|
208
208
|
/**
|
|
209
209
|
* Close the transport for window.addEventListener('pagehide')
|
|
@@ -212,8 +212,11 @@ class Ua {
|
|
|
212
212
|
t.persisted || this.transport && typeof this.transport.close == "function" && await this.transport.close();
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
|
-
const
|
|
216
|
-
const t = () =>
|
|
215
|
+
const Ba = (e, t) => new xt(e, t), Ga = () => on(), Ka = (e) => e instanceof xt, Ya = (e) => e instanceof hr, On = (e) => {
|
|
216
|
+
const t = () => {
|
|
217
|
+
let r = null;
|
|
218
|
+
return typeof document < "u" && (r = r || document.modelContext), typeof navigator < "u" && (r = r || navigator.modelContext), r = r || globalThis.modelContext, r || null;
|
|
219
|
+
};
|
|
217
220
|
e.onmessage = async (r) => {
|
|
218
221
|
if (!r || typeof r != "object") return;
|
|
219
222
|
const n = r.id, o = r.method;
|
|
@@ -236,8 +239,8 @@ const La = (e, t) => new St(e, t), Da = () => rn(), qa = (e) => e instanceof St,
|
|
|
236
239
|
await e.send({ jsonrpc: "2.0", id: n, result: {} });
|
|
237
240
|
else if (o === "tools/list") {
|
|
238
241
|
const s = t();
|
|
239
|
-
if (s && s.
|
|
240
|
-
const l = (await s.
|
|
242
|
+
if (s && s.getTools) {
|
|
243
|
+
const l = (await s.getTools()).map((u) => {
|
|
241
244
|
let c = {};
|
|
242
245
|
if (typeof u.inputSchema == "string")
|
|
243
246
|
try {
|
|
@@ -263,11 +266,13 @@ const La = (e, t) => new St(e, t), Da = () => rn(), qa = (e) => e instanceof St,
|
|
|
263
266
|
const s = t();
|
|
264
267
|
if (s && s.executeTool) {
|
|
265
268
|
if (!r.params || typeof r.params != "object" || !r.params.name) {
|
|
266
|
-
const
|
|
267
|
-
throw
|
|
269
|
+
const f = new Error('Invalid params: "name" is required and params must be an object');
|
|
270
|
+
throw f.code = -32602, f;
|
|
268
271
|
}
|
|
269
|
-
const { name: i, arguments: l } = r.params,
|
|
270
|
-
|
|
272
|
+
const { name: i, arguments: l } = r.params, c = (await (s.getTools ? s.getTools() : [])).find((f) => f.name === i);
|
|
273
|
+
if (!c) throw new Error(`Tool ${i} not found`);
|
|
274
|
+
const d = await s.executeTool(c, JSON.stringify(l || {})), p = d && typeof d == "object" && "content" in d ? d : { content: [{ type: "text", text: typeof d == "string" ? d : JSON.stringify(d) }] };
|
|
275
|
+
await e.send({ jsonrpc: "2.0", id: n, result: p });
|
|
271
276
|
} else {
|
|
272
277
|
const i = new Error("executeTool not implemented in Browser built-in WebMCP");
|
|
273
278
|
throw i.code = -32601, i;
|
|
@@ -278,15 +283,18 @@ const La = (e, t) => new St(e, t), Da = () => rn(), qa = (e) => e instanceof St,
|
|
|
278
283
|
error: { code: -32601, message: `Method not found: ${o}` }
|
|
279
284
|
});
|
|
280
285
|
} catch (s) {
|
|
281
|
-
n !== void 0
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
+
if (n !== void 0) {
|
|
287
|
+
const i = s;
|
|
288
|
+
await e.send({
|
|
289
|
+
jsonrpc: "2.0",
|
|
290
|
+
id: n,
|
|
291
|
+
error: { code: i.code || -32e3, message: i.message || String(s) }
|
|
292
|
+
});
|
|
293
|
+
}
|
|
286
294
|
}
|
|
287
295
|
};
|
|
288
296
|
};
|
|
289
|
-
class
|
|
297
|
+
class An {
|
|
290
298
|
constructor(t, r) {
|
|
291
299
|
const n = {
|
|
292
300
|
name: "web-mcp-client",
|
|
@@ -296,7 +304,7 @@ class In {
|
|
|
296
304
|
sampling: {},
|
|
297
305
|
elicitation: {}
|
|
298
306
|
};
|
|
299
|
-
this.client = new
|
|
307
|
+
this.client = new yr(t || n, r || { capabilities: o }), this.client.onclose = () => {
|
|
300
308
|
this.onclose?.();
|
|
301
309
|
}, this.client.onerror = (s) => {
|
|
302
310
|
this.onerror?.(s);
|
|
@@ -310,19 +318,19 @@ class In {
|
|
|
310
318
|
return this.transport = t, 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 };
|
|
311
319
|
const { url: r, token: n, sessionId: o, type: s, agent: i, builtin: l, onError: u } = t;
|
|
312
320
|
if (i) {
|
|
313
|
-
const p = { client: this.client, url: r, token: n, sessionId: o }, f = s === "sse" ? await
|
|
321
|
+
const p = { client: this.client, url: r, token: n, sessionId: o }, f = s === "sse" ? await sn(p) : s === "socket" ? await an(p) : await ln(p);
|
|
314
322
|
return f.transport.onerror = async (v) => {
|
|
315
323
|
u?.(v);
|
|
316
|
-
}, l &&
|
|
324
|
+
}, l && On(f.transport), f;
|
|
317
325
|
}
|
|
318
326
|
const c = new URL(r);
|
|
319
327
|
let d;
|
|
320
|
-
if (s === "channel" && (d = new
|
|
321
|
-
const p =
|
|
328
|
+
if (s === "channel" && (d = new St(r), await this.client.connect(d)), s === "sse") {
|
|
329
|
+
const p = cn(n, o);
|
|
322
330
|
d = new Xe(c, p), await this.client.connect(d);
|
|
323
331
|
}
|
|
324
|
-
if (s === "socket" && (d = new
|
|
325
|
-
const p =
|
|
332
|
+
if (s === "socket" && (d = new kn(new URL(`${r}?sessionId=${o}&token=${n}`)), d.sessionId = o, await this.client.connect(d)), s === "stream" || typeof d > "u") {
|
|
333
|
+
const p = un(n, o);
|
|
326
334
|
d = new Ye(c, p), await this.client.connect(d);
|
|
327
335
|
}
|
|
328
336
|
return this.transport = d, { transport: this.transport, sessionId: this.transport.sessionId };
|
|
@@ -415,7 +423,7 @@ class In {
|
|
|
415
423
|
* Calls a tool on the server with the given parameters.
|
|
416
424
|
*/
|
|
417
425
|
async callTool(t, r) {
|
|
418
|
-
return await this.client.callTool(t,
|
|
426
|
+
return await this.client.callTool(t, gn, r);
|
|
419
427
|
}
|
|
420
428
|
/**
|
|
421
429
|
* Lists all tools available on the server.
|
|
@@ -475,174 +483,95 @@ class In {
|
|
|
475
483
|
* Registers a handler for the elicitation request.
|
|
476
484
|
*/
|
|
477
485
|
onElicit(t) {
|
|
478
|
-
this.client.setRequestHandler(
|
|
486
|
+
this.client.setRequestHandler(yn, t);
|
|
479
487
|
}
|
|
480
488
|
/**
|
|
481
489
|
* Registers a handler for the create LLM message request.
|
|
482
490
|
*/
|
|
483
491
|
onCreateMessage(t) {
|
|
484
|
-
this.client.setRequestHandler(
|
|
492
|
+
this.client.setRequestHandler(vn, t);
|
|
485
493
|
}
|
|
486
494
|
/**
|
|
487
495
|
* Registers a handler for the list roots request.
|
|
488
496
|
*/
|
|
489
497
|
onListRoots(t) {
|
|
490
|
-
this.client.setRequestHandler(
|
|
498
|
+
this.client.setRequestHandler(wn, t);
|
|
491
499
|
}
|
|
492
500
|
/**
|
|
493
501
|
* Registers a handler for the tool list changed notification.
|
|
494
502
|
*/
|
|
495
503
|
onToolListChanged(t) {
|
|
496
|
-
this.client.setNotificationHandler(
|
|
504
|
+
this.client.setNotificationHandler(bn, t);
|
|
497
505
|
}
|
|
498
506
|
/**
|
|
499
507
|
* Registers a handler for the prompt list changed notification.
|
|
500
508
|
*/
|
|
501
509
|
onPromptListChanged(t) {
|
|
502
|
-
this.client.setNotificationHandler(
|
|
510
|
+
this.client.setNotificationHandler(_n, t);
|
|
503
511
|
}
|
|
504
512
|
/**
|
|
505
513
|
* Registers a handler for the resource list changed notification.
|
|
506
514
|
*/
|
|
507
515
|
onResourceListChanged(t) {
|
|
508
|
-
this.client.setNotificationHandler(
|
|
516
|
+
this.client.setNotificationHandler(xn, t);
|
|
509
517
|
}
|
|
510
518
|
/**
|
|
511
519
|
* Registers a handler for the resource updated notification.
|
|
512
520
|
*/
|
|
513
521
|
onResourceUpdated(t) {
|
|
514
|
-
this.client.setNotificationHandler(
|
|
522
|
+
this.client.setNotificationHandler(Sn, t);
|
|
515
523
|
}
|
|
516
524
|
/**
|
|
517
525
|
* Registers a handler for the logging message notification.
|
|
518
526
|
*/
|
|
519
527
|
onLoggingMessage(t) {
|
|
520
|
-
this.client.setNotificationHandler(
|
|
528
|
+
this.client.setNotificationHandler(Tn, t);
|
|
521
529
|
}
|
|
522
530
|
/**
|
|
523
531
|
* Close the transport for window.addEventListener('pagehide')
|
|
524
532
|
*/
|
|
525
533
|
async onPagehide(t) {
|
|
526
|
-
t.persisted || (
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
const Fa = (e, t) => new Xe(e, t), Za = (e, t) => new Ye(e, t), Va = (e, t) => new xt(e, t), Ja = (e) => e instanceof Xe, On = (e) => e instanceof Ye, Wa = (e) => e instanceof xt, Ba = (e) => e instanceof gr, Ga = (e, t, r) => {
|
|
530
|
-
window.postMessage({ type: e, direction: r, data: t }, "*");
|
|
531
|
-
}, Ka = (e, t, r) => {
|
|
532
|
-
const n = async function(o) {
|
|
533
|
-
o.source === window && o.data.type === e && o.data.direction === r && await t(o.data.data);
|
|
534
|
-
};
|
|
535
|
-
return window.addEventListener("message", n), () => window.removeEventListener("message", n);
|
|
536
|
-
}, Mn = (e, t, r) => {
|
|
537
|
-
if (r.endsWith("content"))
|
|
538
|
-
chrome.tabs.query({}, (n) => {
|
|
539
|
-
n.forEach((o) => {
|
|
540
|
-
chrome.tabs.sendMessage(o.id, { type: e, data: t, direction: r, tabId: o.id });
|
|
541
|
-
});
|
|
542
|
-
});
|
|
543
|
-
else
|
|
544
|
-
return chrome.runtime.sendMessage({ direction: r, type: e, data: t });
|
|
545
|
-
}, An = (e, t, r, n) => {
|
|
546
|
-
const o = (s, i, l) => {
|
|
547
|
-
if (s.type === e && s.direction === r && (!n || n && s.tabId === n)) {
|
|
548
|
-
const { data: u } = s;
|
|
549
|
-
t(u, i, l), l(i);
|
|
550
|
-
}
|
|
551
|
-
};
|
|
552
|
-
return chrome.runtime.onMessage.addListener(o), () => chrome.runtime.onMessage.removeListener(o);
|
|
553
|
-
};
|
|
554
|
-
class jn {
|
|
555
|
-
constructor(t) {
|
|
556
|
-
this._isStarted = !1, this._isClosed = !1, this.targetSessionId = t, this._messageListener = An(
|
|
557
|
-
"mcp-server-to-client",
|
|
558
|
-
(r) => {
|
|
559
|
-
try {
|
|
560
|
-
if (r.sessionId !== this.targetSessionId) return;
|
|
561
|
-
const n = xn.parse(r.mcpMessage);
|
|
562
|
-
this.onmessage?.(n);
|
|
563
|
-
} catch (n) {
|
|
564
|
-
console.log("【Client Transport】处理server消息错误:", n);
|
|
565
|
-
}
|
|
566
|
-
},
|
|
567
|
-
"content->bg"
|
|
568
|
-
);
|
|
569
|
-
}
|
|
570
|
-
// 是否已关闭
|
|
571
|
-
_throwError(t, r) {
|
|
572
|
-
if (t()) {
|
|
573
|
-
const n = new Error(r);
|
|
574
|
-
throw console.log(r, n), this.onerror && this.onerror(n), n;
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
/** 启动 transport,开始监听消息 */
|
|
578
|
-
async start() {
|
|
579
|
-
this._throwError(() => this._isClosed, "【Client Transport】 未启动,无法重新启动"), this._isStarted = !0;
|
|
580
|
-
}
|
|
581
|
-
/** 发送消息到 MCP Server */
|
|
582
|
-
async send(t, r) {
|
|
583
|
-
this._throwError(() => !this._isStarted, "【Client Transport】 未启动,无法发送消息"), this._throwError(() => this._isClosed, "【Client Transport】 已关闭,无法发送消息");
|
|
584
|
-
let n;
|
|
585
|
-
if (chrome.sessionRegistry) {
|
|
586
|
-
const o = chrome.sessionRegistry.get(this.targetSessionId);
|
|
587
|
-
o && o.tabIds.length > 0 && (n = o.tabIds[o.tabIds.length - 1]);
|
|
588
|
-
}
|
|
589
|
-
n == null && (n = await chrome.runtime.sendMessage({ type: "get-session-tab-id", sessionId: this.targetSessionId })), this._throwError(() => n == null, `【Client Transport】后台未找到活动的tabId用于${this.targetSessionId}`), Mn(
|
|
590
|
-
"mcp-client-to-server",
|
|
591
|
-
{ sessionId: this.targetSessionId, tabId: n, mcpMessage: t },
|
|
592
|
-
"bg->content"
|
|
593
|
-
);
|
|
594
|
-
}
|
|
595
|
-
/** 关闭 transport */
|
|
596
|
-
async close() {
|
|
597
|
-
if (!this._isClosed)
|
|
598
|
-
try {
|
|
599
|
-
this._isClosed = !0, this._isStarted = !1, this._messageListener && this._messageListener(), this.onclose && this.onclose();
|
|
600
|
-
} catch {
|
|
601
|
-
this._throwError(() => !0, "【Client Transport】 关闭时发生错误");
|
|
602
|
-
}
|
|
534
|
+
t.persisted || (In(this.transport) ? await this.transport.terminateSession() : this.transport && typeof this.transport.close == "function" && await this.transport.close());
|
|
603
535
|
}
|
|
604
536
|
}
|
|
605
|
-
const
|
|
606
|
-
const t = Math.random() * 16 | 0;
|
|
607
|
-
return (e === "x" ? t : t & 3 | 8).toString(16);
|
|
608
|
-
});
|
|
537
|
+
const Xa = (e, t) => new Xe(e, t), Qa = (e, t) => new Ye(e, t), el = (e, t) => new St(e, t), tl = (e) => e instanceof Xe, In = (e) => e instanceof Ye, rl = (e) => e instanceof St, nl = (e) => e instanceof yr;
|
|
609
538
|
class it extends Error {
|
|
610
539
|
constructor(t, r) {
|
|
611
540
|
super(t), this.name = "ParseError", this.type = r.type, this.field = r.field, this.value = r.value, this.line = r.line;
|
|
612
541
|
}
|
|
613
542
|
}
|
|
614
|
-
const qt = 10,
|
|
543
|
+
const qt = 10, Mn = 13, fe = 32;
|
|
615
544
|
function at(e) {
|
|
616
545
|
}
|
|
617
|
-
function
|
|
546
|
+
function jn(e) {
|
|
618
547
|
if (typeof e == "function")
|
|
619
548
|
throw new TypeError(
|
|
620
549
|
"`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?"
|
|
621
550
|
);
|
|
622
551
|
const { onEvent: t = at, onError: r = at, onRetry: n = at, onComment: o, maxBufferSize: s } = e, i = [];
|
|
623
552
|
let l = 0, u = !0, c, d = "", p = 0, f, v = !1;
|
|
624
|
-
function
|
|
553
|
+
function m(h) {
|
|
625
554
|
if (v)
|
|
626
555
|
throw new Error(
|
|
627
556
|
"Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing."
|
|
628
557
|
);
|
|
629
558
|
if (u && (u = !1, h.charCodeAt(0) === 239 && h.charCodeAt(1) === 187 && h.charCodeAt(2) === 191 && (h = h.slice(3))), i.length === 0) {
|
|
630
|
-
const
|
|
631
|
-
|
|
559
|
+
const N = x(h);
|
|
560
|
+
N !== "" && (i.push(N), l = N.length), S();
|
|
632
561
|
return;
|
|
633
562
|
}
|
|
634
563
|
if (h.indexOf(`
|
|
635
564
|
`) === -1 && h.indexOf("\r") === -1) {
|
|
636
|
-
i.push(h), l += h.length,
|
|
565
|
+
i.push(h), l += h.length, S();
|
|
637
566
|
return;
|
|
638
567
|
}
|
|
639
568
|
i.push(h);
|
|
640
|
-
const
|
|
569
|
+
const g = i.join("");
|
|
641
570
|
i.length = 0, l = 0;
|
|
642
|
-
const _ = x(
|
|
643
|
-
_ !== "" && (i.push(_), l = _.length),
|
|
571
|
+
const _ = x(g);
|
|
572
|
+
_ !== "" && (i.push(_), l = _.length), S();
|
|
644
573
|
}
|
|
645
|
-
function
|
|
574
|
+
function S() {
|
|
646
575
|
s !== void 0 && (l + d.length <= s || (v = !0, i.length = 0, l = 0, c = void 0, d = "", p = 0, f = void 0, r(
|
|
647
576
|
new it(`Buffered data exceeded max buffer size of ${s} characters`, {
|
|
648
577
|
type: "max-buffer-size-exceeded"
|
|
@@ -650,98 +579,98 @@ function Un(e) {
|
|
|
650
579
|
)));
|
|
651
580
|
}
|
|
652
581
|
function x(h) {
|
|
653
|
-
let
|
|
582
|
+
let g = 0;
|
|
654
583
|
if (h.indexOf("\r") === -1) {
|
|
655
584
|
let _ = h.indexOf(`
|
|
656
|
-
`,
|
|
585
|
+
`, g);
|
|
657
586
|
for (; _ !== -1; ) {
|
|
658
|
-
if (
|
|
659
|
-
p > 0 && t({ id: c, event: f, data: d }), c = void 0, d = "", p = 0, f = void 0,
|
|
660
|
-
`,
|
|
587
|
+
if (g === _) {
|
|
588
|
+
p > 0 && t({ id: c, event: f, data: d }), c = void 0, d = "", p = 0, f = void 0, g = _ + 1, _ = h.indexOf(`
|
|
589
|
+
`, g);
|
|
661
590
|
continue;
|
|
662
591
|
}
|
|
663
|
-
const
|
|
664
|
-
if (Ht(h,
|
|
665
|
-
const
|
|
592
|
+
const N = h.charCodeAt(g);
|
|
593
|
+
if (Ht(h, g, N)) {
|
|
594
|
+
const I = h.charCodeAt(g + 5) === fe ? g + 6 : g + 5, L = h.slice(I, _);
|
|
666
595
|
if (p === 0 && h.charCodeAt(_ + 1) === qt) {
|
|
667
|
-
t({ id: c, event: f, data:
|
|
668
|
-
`,
|
|
596
|
+
t({ id: c, event: f, data: L }), c = void 0, d = "", f = void 0, g = _ + 2, _ = h.indexOf(`
|
|
597
|
+
`, g);
|
|
669
598
|
continue;
|
|
670
599
|
}
|
|
671
|
-
d = p === 0 ?
|
|
672
|
-
${
|
|
673
|
-
} else Ft(h,
|
|
674
|
-
h.charCodeAt(
|
|
600
|
+
d = p === 0 ? L : `${d}
|
|
601
|
+
${L}`, p++;
|
|
602
|
+
} else Ft(h, g, N) ? f = h.slice(
|
|
603
|
+
h.charCodeAt(g + 6) === fe ? g + 7 : g + 6,
|
|
675
604
|
_
|
|
676
|
-
) || void 0 : R(h,
|
|
677
|
-
|
|
678
|
-
`,
|
|
605
|
+
) || void 0 : R(h, g, _);
|
|
606
|
+
g = _ + 1, _ = h.indexOf(`
|
|
607
|
+
`, g);
|
|
679
608
|
}
|
|
680
|
-
return h.slice(
|
|
609
|
+
return h.slice(g);
|
|
681
610
|
}
|
|
682
|
-
for (;
|
|
683
|
-
const _ = h.indexOf("\r",
|
|
684
|
-
`,
|
|
685
|
-
let
|
|
686
|
-
if (_ !== -1 &&
|
|
611
|
+
for (; g < h.length; ) {
|
|
612
|
+
const _ = h.indexOf("\r", g), N = h.indexOf(`
|
|
613
|
+
`, g);
|
|
614
|
+
let I = -1;
|
|
615
|
+
if (_ !== -1 && N !== -1 ? I = _ < N ? _ : N : _ !== -1 ? _ === h.length - 1 ? I = -1 : I = _ : N !== -1 && (I = N), I === -1)
|
|
687
616
|
break;
|
|
688
|
-
R(h,
|
|
617
|
+
R(h, g, I), g = I + 1, h.charCodeAt(g - 1) === Mn && h.charCodeAt(g) === qt && g++;
|
|
689
618
|
}
|
|
690
|
-
return h.slice(
|
|
619
|
+
return h.slice(g);
|
|
691
620
|
}
|
|
692
|
-
function R(h,
|
|
693
|
-
if (
|
|
694
|
-
|
|
621
|
+
function R(h, g, _) {
|
|
622
|
+
if (g === _) {
|
|
623
|
+
O();
|
|
695
624
|
return;
|
|
696
625
|
}
|
|
697
|
-
const
|
|
698
|
-
if (Ht(h,
|
|
699
|
-
const H = h.charCodeAt(
|
|
626
|
+
const N = h.charCodeAt(g);
|
|
627
|
+
if (Ht(h, g, N)) {
|
|
628
|
+
const H = h.charCodeAt(g + 5) === fe ? g + 6 : g + 5, G = h.slice(H, _);
|
|
700
629
|
d = p === 0 ? G : `${d}
|
|
701
630
|
${G}`, p++;
|
|
702
631
|
return;
|
|
703
632
|
}
|
|
704
|
-
if (Ft(h,
|
|
705
|
-
f = h.slice(h.charCodeAt(
|
|
633
|
+
if (Ft(h, g, N)) {
|
|
634
|
+
f = h.slice(h.charCodeAt(g + 6) === fe ? g + 7 : g + 6, _) || void 0;
|
|
706
635
|
return;
|
|
707
636
|
}
|
|
708
|
-
if (
|
|
709
|
-
const H = h.slice(h.charCodeAt(
|
|
637
|
+
if (N === 105 && h.charCodeAt(g + 1) === 100 && h.charCodeAt(g + 2) === 58) {
|
|
638
|
+
const H = h.slice(h.charCodeAt(g + 3) === fe ? g + 4 : g + 3, _);
|
|
710
639
|
c = H.includes("\0") ? void 0 : H;
|
|
711
640
|
return;
|
|
712
641
|
}
|
|
713
|
-
if (
|
|
642
|
+
if (N === 58) {
|
|
714
643
|
if (o) {
|
|
715
|
-
const H = h.slice(
|
|
716
|
-
o(H.slice(h.charCodeAt(
|
|
644
|
+
const H = h.slice(g, _);
|
|
645
|
+
o(H.slice(h.charCodeAt(g + 1) === fe ? 2 : 1));
|
|
717
646
|
}
|
|
718
647
|
return;
|
|
719
648
|
}
|
|
720
|
-
const
|
|
721
|
-
if (
|
|
722
|
-
M(
|
|
649
|
+
const I = h.slice(g, _), L = I.indexOf(":");
|
|
650
|
+
if (L === -1) {
|
|
651
|
+
M(I, "", I);
|
|
723
652
|
return;
|
|
724
653
|
}
|
|
725
|
-
const K =
|
|
726
|
-
M(K, oe,
|
|
654
|
+
const K = I.slice(0, L), Z = I.charCodeAt(L + 1) === fe ? 2 : 1, oe = I.slice(L + Z);
|
|
655
|
+
M(K, oe, I);
|
|
727
656
|
}
|
|
728
|
-
function M(h,
|
|
657
|
+
function M(h, g, _) {
|
|
729
658
|
switch (h) {
|
|
730
659
|
case "event":
|
|
731
|
-
f =
|
|
660
|
+
f = g || void 0;
|
|
732
661
|
break;
|
|
733
662
|
case "data":
|
|
734
|
-
d = p === 0 ?
|
|
735
|
-
${
|
|
663
|
+
d = p === 0 ? g : `${d}
|
|
664
|
+
${g}`, p++;
|
|
736
665
|
break;
|
|
737
666
|
case "id":
|
|
738
|
-
c =
|
|
667
|
+
c = g.includes("\0") ? void 0 : g;
|
|
739
668
|
break;
|
|
740
669
|
case "retry":
|
|
741
|
-
/^\d+$/.test(
|
|
742
|
-
new it(`Invalid \`retry\` value: "${
|
|
670
|
+
/^\d+$/.test(g) ? n(parseInt(g, 10)) : r(
|
|
671
|
+
new it(`Invalid \`retry\` value: "${g}"`, {
|
|
743
672
|
type: "invalid-retry",
|
|
744
|
-
value:
|
|
673
|
+
value: g,
|
|
745
674
|
line: _
|
|
746
675
|
})
|
|
747
676
|
);
|
|
@@ -750,27 +679,27 @@ ${m}`, p++;
|
|
|
750
679
|
r(
|
|
751
680
|
new it(
|
|
752
681
|
`Unknown field "${h.length > 20 ? `${h.slice(0, 20)}…` : h}"`,
|
|
753
|
-
{ type: "unknown-field", field: h, value:
|
|
682
|
+
{ type: "unknown-field", field: h, value: g, line: _ }
|
|
754
683
|
)
|
|
755
684
|
);
|
|
756
685
|
break;
|
|
757
686
|
}
|
|
758
687
|
}
|
|
759
|
-
function
|
|
688
|
+
function O() {
|
|
760
689
|
p > 0 && t({
|
|
761
690
|
id: c,
|
|
762
691
|
event: f,
|
|
763
692
|
data: d
|
|
764
693
|
}), c = void 0, d = "", p = 0, f = void 0;
|
|
765
694
|
}
|
|
766
|
-
function
|
|
695
|
+
function j(h = {}) {
|
|
767
696
|
if (h.consume && i.length > 0) {
|
|
768
|
-
const
|
|
769
|
-
R(
|
|
697
|
+
const g = i.join("");
|
|
698
|
+
R(g, 0, g.length);
|
|
770
699
|
}
|
|
771
700
|
u = !0, c = void 0, d = "", p = 0, f = void 0, i.length = 0, l = 0, v = !1;
|
|
772
701
|
}
|
|
773
|
-
return { feed:
|
|
702
|
+
return { feed: m, reset: j };
|
|
774
703
|
}
|
|
775
704
|
function Ht(e, t, r) {
|
|
776
705
|
return r === 100 && e.charCodeAt(t + 1) === 97 && e.charCodeAt(t + 2) === 116 && e.charCodeAt(t + 3) === 97 && e.charCodeAt(t + 4) === 58;
|
|
@@ -783,7 +712,7 @@ class ft extends TransformStream {
|
|
|
783
712
|
let s;
|
|
784
713
|
super({
|
|
785
714
|
start(i) {
|
|
786
|
-
s =
|
|
715
|
+
s = jn({
|
|
787
716
|
onEvent: (l) => {
|
|
788
717
|
i.enqueue(l);
|
|
789
718
|
},
|
|
@@ -801,7 +730,29 @@ class ft extends TransformStream {
|
|
|
801
730
|
});
|
|
802
731
|
}
|
|
803
732
|
}
|
|
804
|
-
|
|
733
|
+
async function Nn(e, t) {
|
|
734
|
+
if (e == null)
|
|
735
|
+
return Promise.resolve();
|
|
736
|
+
const r = t?.abortSignal;
|
|
737
|
+
return new Promise((n, o) => {
|
|
738
|
+
if (r?.aborted) {
|
|
739
|
+
o(Zt());
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
const s = setTimeout(() => {
|
|
743
|
+
i(), n();
|
|
744
|
+
}, e), i = () => {
|
|
745
|
+
clearTimeout(s), r?.removeEventListener("abort", l);
|
|
746
|
+
}, l = () => {
|
|
747
|
+
i(), o(Zt());
|
|
748
|
+
};
|
|
749
|
+
r?.addEventListener("abort", l);
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
function Zt() {
|
|
753
|
+
return new DOMException("Delay was aborted", "AbortError");
|
|
754
|
+
}
|
|
755
|
+
var zn = ({
|
|
805
756
|
prefix: e,
|
|
806
757
|
size: t = 16,
|
|
807
758
|
alphabet: r = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
|
|
@@ -816,18 +767,25 @@ var Ln = ({
|
|
|
816
767
|
if (e == null)
|
|
817
768
|
return o;
|
|
818
769
|
if (r.includes(n))
|
|
819
|
-
throw new
|
|
770
|
+
throw new $n({
|
|
820
771
|
argument: "separator",
|
|
821
772
|
message: `The separator "${n}" must not be part of the alphabet "${r}".`
|
|
822
773
|
});
|
|
823
774
|
return () => `${e}${n}${o()}`;
|
|
824
775
|
};
|
|
825
|
-
|
|
826
|
-
function
|
|
776
|
+
zn();
|
|
777
|
+
function Un(e) {
|
|
778
|
+
return e == null ? "unknown error" : typeof e == "string" ? e : e instanceof Error ? e.message : JSON.stringify(e);
|
|
779
|
+
}
|
|
780
|
+
function Dn(e) {
|
|
781
|
+
return (e instanceof Error || e instanceof DOMException) && (e.name === "AbortError" || e.name === "ResponseAborted" || // Next.js
|
|
782
|
+
e.name === "TimeoutError");
|
|
783
|
+
}
|
|
784
|
+
function vr(e = globalThis) {
|
|
827
785
|
var t, r, n;
|
|
828
786
|
return e.window ? "runtime/browser" : (t = e.navigator) != null && t.userAgent ? `runtime/${e.navigator.userAgent.toLowerCase()}` : (n = (r = e.process) == null ? void 0 : r.versions) != null && n.node ? `runtime/node.js/${e.process.version.substring(0)}` : e.EdgeRuntime ? "runtime/vercel-edge" : "runtime/unknown";
|
|
829
787
|
}
|
|
830
|
-
function
|
|
788
|
+
function Ln(e) {
|
|
831
789
|
if (e == null)
|
|
832
790
|
return {};
|
|
833
791
|
const t = {};
|
|
@@ -842,15 +800,15 @@ function Dn(e) {
|
|
|
842
800
|
}
|
|
843
801
|
return t;
|
|
844
802
|
}
|
|
845
|
-
function
|
|
846
|
-
const r = new Headers(
|
|
803
|
+
function wr(e, ...t) {
|
|
804
|
+
const r = new Headers(Ln(e)), n = r.get("user-agent") || "";
|
|
847
805
|
return r.set(
|
|
848
806
|
"user-agent",
|
|
849
807
|
[n, ...t].filter(Boolean).join(" ")
|
|
850
808
|
), Object.fromEntries(r.entries());
|
|
851
809
|
}
|
|
852
810
|
var qn = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/, Hn = /"(?: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*:/;
|
|
853
|
-
function
|
|
811
|
+
function Vt(e) {
|
|
854
812
|
const t = JSON.parse(e);
|
|
855
813
|
return t === null || typeof t != "object" || qn.test(e) === !1 && Hn.test(e) === !1 ? t : Fn(t);
|
|
856
814
|
}
|
|
@@ -872,15 +830,15 @@ function Fn(e) {
|
|
|
872
830
|
}
|
|
873
831
|
return e;
|
|
874
832
|
}
|
|
875
|
-
function
|
|
833
|
+
function br(e) {
|
|
876
834
|
const { stackTraceLimit: t } = Error;
|
|
877
835
|
try {
|
|
878
836
|
Error.stackTraceLimit = 0;
|
|
879
837
|
} catch {
|
|
880
|
-
return
|
|
838
|
+
return Vt(e);
|
|
881
839
|
}
|
|
882
840
|
try {
|
|
883
|
-
return
|
|
841
|
+
return Vt(e);
|
|
884
842
|
} finally {
|
|
885
843
|
Error.stackTraceLimit = t;
|
|
886
844
|
}
|
|
@@ -905,7 +863,7 @@ function pe(e) {
|
|
|
905
863
|
}
|
|
906
864
|
var Zn = /* @__PURE__ */ Symbol(
|
|
907
865
|
"Let zodToJsonSchema decide on which parser to use"
|
|
908
|
-
),
|
|
866
|
+
), Jt = {
|
|
909
867
|
name: void 0,
|
|
910
868
|
$refStrategy: "root",
|
|
911
869
|
basePath: ["#"],
|
|
@@ -926,10 +884,10 @@ var Zn = /* @__PURE__ */ Symbol(
|
|
|
926
884
|
base64Strategy: "contentEncoding:base64",
|
|
927
885
|
nameStrategy: "ref"
|
|
928
886
|
}, Vn = (e) => typeof e == "string" ? {
|
|
929
|
-
...
|
|
887
|
+
...Jt,
|
|
930
888
|
name: e
|
|
931
889
|
} : {
|
|
932
|
-
...
|
|
890
|
+
...Jt,
|
|
933
891
|
...e
|
|
934
892
|
};
|
|
935
893
|
function B() {
|
|
@@ -940,7 +898,7 @@ function Jn(e, t) {
|
|
|
940
898
|
const s = {
|
|
941
899
|
type: "array"
|
|
942
900
|
};
|
|
943
|
-
return (r = e.type) != null && r._def && ((o = (n = e.type) == null ? void 0 : n._def) == null ? void 0 : o.typeName) !== k.ZodAny && (s.items =
|
|
901
|
+
return (r = e.type) != null && r._def && ((o = (n = e.type) == null ? void 0 : n._def) == null ? void 0 : o.typeName) !== k.ZodAny && (s.items = z(e.type._def, {
|
|
944
902
|
...t,
|
|
945
903
|
currentPath: [...t.currentPath, "items"]
|
|
946
904
|
})), e.minLength && (s.minItems = e.minLength.value), e.maxLength && (s.maxItems = e.maxLength.value), e.exactLength && (s.minItems = e.exactLength.value, s.maxItems = e.exactLength.value), s;
|
|
@@ -968,15 +926,15 @@ function Wn(e) {
|
|
|
968
926
|
function Bn() {
|
|
969
927
|
return { type: "boolean" };
|
|
970
928
|
}
|
|
971
|
-
function
|
|
972
|
-
return
|
|
929
|
+
function _r(e, t) {
|
|
930
|
+
return z(e.type._def, t);
|
|
973
931
|
}
|
|
974
|
-
var Gn = (e, t) =>
|
|
975
|
-
function
|
|
932
|
+
var Gn = (e, t) => z(e.innerType._def, t);
|
|
933
|
+
function xr(e, t, r) {
|
|
976
934
|
const n = r ?? t.dateStrategy;
|
|
977
935
|
if (Array.isArray(n))
|
|
978
936
|
return {
|
|
979
|
-
anyOf: n.map((o, s) =>
|
|
937
|
+
anyOf: n.map((o, s) => xr(e, t, o))
|
|
980
938
|
};
|
|
981
939
|
switch (n) {
|
|
982
940
|
case "string":
|
|
@@ -1012,12 +970,12 @@ var Kn = (e) => {
|
|
|
1012
970
|
};
|
|
1013
971
|
function Yn(e, t) {
|
|
1014
972
|
return {
|
|
1015
|
-
...
|
|
973
|
+
...z(e.innerType._def, t),
|
|
1016
974
|
default: e.defaultValue()
|
|
1017
975
|
};
|
|
1018
976
|
}
|
|
1019
977
|
function Xn(e, t) {
|
|
1020
|
-
return t.effectStrategy === "input" ?
|
|
978
|
+
return t.effectStrategy === "input" ? z(e.schema._def, t) : B();
|
|
1021
979
|
}
|
|
1022
980
|
function Qn(e) {
|
|
1023
981
|
return {
|
|
@@ -1028,11 +986,11 @@ function Qn(e) {
|
|
|
1028
986
|
var eo = (e) => "type" in e && e.type === "string" ? !1 : "allOf" in e;
|
|
1029
987
|
function to(e, t) {
|
|
1030
988
|
const r = [
|
|
1031
|
-
|
|
989
|
+
z(e.left._def, {
|
|
1032
990
|
...t,
|
|
1033
991
|
currentPath: [...t.currentPath, "allOf", "0"]
|
|
1034
992
|
}),
|
|
1035
|
-
|
|
993
|
+
z(e.right._def, {
|
|
1036
994
|
...t,
|
|
1037
995
|
currentPath: [...t.currentPath, "allOf", "1"]
|
|
1038
996
|
})
|
|
@@ -1254,11 +1212,11 @@ function J(e, t, r, n) {
|
|
|
1254
1212
|
e.pattern || (o = e.allOf) != null && o.some((s) => s.pattern) ? (e.allOf || (e.allOf = []), e.pattern && (e.allOf.push({
|
|
1255
1213
|
pattern: e.pattern
|
|
1256
1214
|
}), delete e.pattern), e.allOf.push({
|
|
1257
|
-
pattern:
|
|
1215
|
+
pattern: Wt(t, n),
|
|
1258
1216
|
...r && n.errorMessages && { errorMessage: { pattern: r } }
|
|
1259
|
-
})) : e.pattern =
|
|
1217
|
+
})) : e.pattern = Wt(t, n);
|
|
1260
1218
|
}
|
|
1261
|
-
function
|
|
1219
|
+
function Wt(e, t) {
|
|
1262
1220
|
var r;
|
|
1263
1221
|
if (!t.applyRegexFlags || !e.flags)
|
|
1264
1222
|
return e.source;
|
|
@@ -1317,11 +1275,11 @@ function Jt(e, t) {
|
|
|
1317
1275
|
}
|
|
1318
1276
|
return s;
|
|
1319
1277
|
}
|
|
1320
|
-
function
|
|
1278
|
+
function Tr(e, t) {
|
|
1321
1279
|
var r, n, o, s, i, l;
|
|
1322
1280
|
const u = {
|
|
1323
1281
|
type: "object",
|
|
1324
|
-
additionalProperties: (r =
|
|
1282
|
+
additionalProperties: (r = z(e.valueType._def, {
|
|
1325
1283
|
...t,
|
|
1326
1284
|
currentPath: [...t.currentPath, "additionalProperties"]
|
|
1327
1285
|
})) != null ? r : t.allowedAdditionalProperties
|
|
@@ -1341,7 +1299,7 @@ function xr(e, t) {
|
|
|
1341
1299
|
}
|
|
1342
1300
|
};
|
|
1343
1301
|
if (((i = e.keyType) == null ? void 0 : i._def.typeName) === k.ZodBranded && e.keyType._def.type._def.typeName === k.ZodString && ((l = e.keyType._def.type._def.checks) != null && l.length)) {
|
|
1344
|
-
const { type: c, ...d } =
|
|
1302
|
+
const { type: c, ...d } = _r(
|
|
1345
1303
|
e.keyType._def,
|
|
1346
1304
|
t
|
|
1347
1305
|
);
|
|
@@ -1355,11 +1313,11 @@ function xr(e, t) {
|
|
|
1355
1313
|
}
|
|
1356
1314
|
function so(e, t) {
|
|
1357
1315
|
if (t.mapStrategy === "record")
|
|
1358
|
-
return
|
|
1359
|
-
const r =
|
|
1316
|
+
return Tr(e, t);
|
|
1317
|
+
const r = z(e.keyType._def, {
|
|
1360
1318
|
...t,
|
|
1361
1319
|
currentPath: [...t.currentPath, "items", "items", "0"]
|
|
1362
|
-
}) || B(), n =
|
|
1320
|
+
}) || B(), n = z(e.valueType._def, {
|
|
1363
1321
|
...t,
|
|
1364
1322
|
currentPath: [...t.currentPath, "items", "items", "1"]
|
|
1365
1323
|
}) || B();
|
|
@@ -1457,7 +1415,7 @@ function co(e, t) {
|
|
|
1457
1415
|
}
|
|
1458
1416
|
var uo = (e, t) => {
|
|
1459
1417
|
const r = (e.options instanceof Map ? Array.from(e.options.values()) : e.options).map(
|
|
1460
|
-
(n, o) =>
|
|
1418
|
+
(n, o) => z(n._def, {
|
|
1461
1419
|
...t,
|
|
1462
1420
|
currentPath: [...t.currentPath, "anyOf", `${o}`]
|
|
1463
1421
|
})
|
|
@@ -1476,7 +1434,7 @@ function fo(e, t) {
|
|
|
1476
1434
|
"null"
|
|
1477
1435
|
]
|
|
1478
1436
|
};
|
|
1479
|
-
const r =
|
|
1437
|
+
const r = z(e.innerType._def, {
|
|
1480
1438
|
...t,
|
|
1481
1439
|
currentPath: [...t.currentPath, "anyOf", "0"]
|
|
1482
1440
|
});
|
|
@@ -1513,7 +1471,7 @@ function ho(e, t) {
|
|
|
1513
1471
|
let l = o[i];
|
|
1514
1472
|
if (l === void 0 || l._def === void 0)
|
|
1515
1473
|
continue;
|
|
1516
|
-
const u = go(l), c =
|
|
1474
|
+
const u = go(l), c = z(l._def, {
|
|
1517
1475
|
...t,
|
|
1518
1476
|
currentPath: [...t.currentPath, "properties", i],
|
|
1519
1477
|
propertyPath: [...t.currentPath, "properties", i]
|
|
@@ -1526,7 +1484,7 @@ function ho(e, t) {
|
|
|
1526
1484
|
}
|
|
1527
1485
|
function mo(e, t) {
|
|
1528
1486
|
if (e.catchall._def.typeName !== "ZodNever")
|
|
1529
|
-
return
|
|
1487
|
+
return z(e.catchall._def, {
|
|
1530
1488
|
...t,
|
|
1531
1489
|
currentPath: [...t.currentPath, "additionalProperties"]
|
|
1532
1490
|
});
|
|
@@ -1549,21 +1507,21 @@ function go(e) {
|
|
|
1549
1507
|
var yo = (e, t) => {
|
|
1550
1508
|
var r;
|
|
1551
1509
|
if (t.currentPath.toString() === ((r = t.propertyPath) == null ? void 0 : r.toString()))
|
|
1552
|
-
return
|
|
1553
|
-
const n =
|
|
1510
|
+
return z(e.innerType._def, t);
|
|
1511
|
+
const n = z(e.innerType._def, {
|
|
1554
1512
|
...t,
|
|
1555
1513
|
currentPath: [...t.currentPath, "anyOf", "1"]
|
|
1556
1514
|
});
|
|
1557
1515
|
return n ? { anyOf: [{ not: B() }, n] } : B();
|
|
1558
1516
|
}, vo = (e, t) => {
|
|
1559
1517
|
if (t.pipeStrategy === "input")
|
|
1560
|
-
return
|
|
1518
|
+
return z(e.in._def, t);
|
|
1561
1519
|
if (t.pipeStrategy === "output")
|
|
1562
|
-
return
|
|
1563
|
-
const r =
|
|
1520
|
+
return z(e.out._def, t);
|
|
1521
|
+
const r = z(e.in._def, {
|
|
1564
1522
|
...t,
|
|
1565
1523
|
currentPath: [...t.currentPath, "allOf", "0"]
|
|
1566
|
-
}), n =
|
|
1524
|
+
}), n = z(e.out._def, {
|
|
1567
1525
|
...t,
|
|
1568
1526
|
currentPath: [...t.currentPath, "allOf", r ? "1" : "0"]
|
|
1569
1527
|
});
|
|
@@ -1572,13 +1530,13 @@ var yo = (e, t) => {
|
|
|
1572
1530
|
};
|
|
1573
1531
|
};
|
|
1574
1532
|
function wo(e, t) {
|
|
1575
|
-
return
|
|
1533
|
+
return z(e.type._def, t);
|
|
1576
1534
|
}
|
|
1577
1535
|
function bo(e, t) {
|
|
1578
1536
|
const n = {
|
|
1579
1537
|
type: "array",
|
|
1580
1538
|
uniqueItems: !0,
|
|
1581
|
-
items:
|
|
1539
|
+
items: z(e.valueType._def, {
|
|
1582
1540
|
...t,
|
|
1583
1541
|
currentPath: [...t.currentPath, "items"]
|
|
1584
1542
|
})
|
|
@@ -1590,7 +1548,7 @@ function _o(e, t) {
|
|
|
1590
1548
|
type: "array",
|
|
1591
1549
|
minItems: e.items.length,
|
|
1592
1550
|
items: e.items.map(
|
|
1593
|
-
(r, n) =>
|
|
1551
|
+
(r, n) => z(r._def, {
|
|
1594
1552
|
...t,
|
|
1595
1553
|
currentPath: [...t.currentPath, "items", `${n}`]
|
|
1596
1554
|
})
|
|
@@ -1598,7 +1556,7 @@ function _o(e, t) {
|
|
|
1598
1556
|
(r, n) => n === void 0 ? r : [...r, n],
|
|
1599
1557
|
[]
|
|
1600
1558
|
),
|
|
1601
|
-
additionalItems:
|
|
1559
|
+
additionalItems: z(e.rest._def, {
|
|
1602
1560
|
...t,
|
|
1603
1561
|
currentPath: [...t.currentPath, "additionalItems"]
|
|
1604
1562
|
})
|
|
@@ -1607,7 +1565,7 @@ function _o(e, t) {
|
|
|
1607
1565
|
minItems: e.items.length,
|
|
1608
1566
|
maxItems: e.items.length,
|
|
1609
1567
|
items: e.items.map(
|
|
1610
|
-
(r, n) =>
|
|
1568
|
+
(r, n) => z(r._def, {
|
|
1611
1569
|
...t,
|
|
1612
1570
|
currentPath: [...t.currentPath, "items", `${n}`]
|
|
1613
1571
|
})
|
|
@@ -1617,15 +1575,15 @@ function _o(e, t) {
|
|
|
1617
1575
|
)
|
|
1618
1576
|
};
|
|
1619
1577
|
}
|
|
1620
|
-
function
|
|
1578
|
+
function xo() {
|
|
1621
1579
|
return {
|
|
1622
1580
|
not: B()
|
|
1623
1581
|
};
|
|
1624
1582
|
}
|
|
1625
|
-
function
|
|
1583
|
+
function So() {
|
|
1626
1584
|
return B();
|
|
1627
1585
|
}
|
|
1628
|
-
var To = (e, t) =>
|
|
1586
|
+
var To = (e, t) => z(e.innerType._def, t), Co = (e, t, r) => {
|
|
1629
1587
|
switch (t) {
|
|
1630
1588
|
case k.ZodString:
|
|
1631
1589
|
return Sr(e, r);
|
|
@@ -1638,9 +1596,9 @@ var To = (e, t) => N(e.innerType._def, t), Co = (e, t, r) => {
|
|
|
1638
1596
|
case k.ZodBoolean:
|
|
1639
1597
|
return Bn();
|
|
1640
1598
|
case k.ZodDate:
|
|
1641
|
-
return
|
|
1599
|
+
return xr(e, r);
|
|
1642
1600
|
case k.ZodUndefined:
|
|
1643
|
-
return
|
|
1601
|
+
return xo();
|
|
1644
1602
|
case k.ZodNull:
|
|
1645
1603
|
return lo();
|
|
1646
1604
|
case k.ZodArray:
|
|
@@ -1653,7 +1611,7 @@ var To = (e, t) => N(e.innerType._def, t), Co = (e, t, r) => {
|
|
|
1653
1611
|
case k.ZodTuple:
|
|
1654
1612
|
return _o(e, r);
|
|
1655
1613
|
case k.ZodRecord:
|
|
1656
|
-
return
|
|
1614
|
+
return Tr(e, r);
|
|
1657
1615
|
case k.ZodLiteral:
|
|
1658
1616
|
return ro(e);
|
|
1659
1617
|
case k.ZodEnum:
|
|
@@ -1680,11 +1638,11 @@ var To = (e, t) => N(e.innerType._def, t), Co = (e, t, r) => {
|
|
|
1680
1638
|
case k.ZodAny:
|
|
1681
1639
|
return B();
|
|
1682
1640
|
case k.ZodUnknown:
|
|
1683
|
-
return
|
|
1641
|
+
return So();
|
|
1684
1642
|
case k.ZodDefault:
|
|
1685
1643
|
return Yn(e, r);
|
|
1686
1644
|
case k.ZodBranded:
|
|
1687
|
-
return
|
|
1645
|
+
return _r(e, r);
|
|
1688
1646
|
case k.ZodReadonly:
|
|
1689
1647
|
return To(e, r);
|
|
1690
1648
|
case k.ZodCatch:
|
|
@@ -1705,7 +1663,7 @@ var To = (e, t) => N(e.innerType._def, t), Co = (e, t, r) => {
|
|
|
1705
1663
|
;
|
|
1706
1664
|
return [(e.length - r).toString(), ...t.slice(r)].join("/");
|
|
1707
1665
|
};
|
|
1708
|
-
function
|
|
1666
|
+
function z(e, t, r = !1) {
|
|
1709
1667
|
var n;
|
|
1710
1668
|
const o = t.seen.get(e);
|
|
1711
1669
|
if (t.override) {
|
|
@@ -1720,20 +1678,20 @@ function N(e, t, r = !1) {
|
|
|
1720
1678
|
return u;
|
|
1721
1679
|
}
|
|
1722
1680
|
if (o && !r) {
|
|
1723
|
-
const u =
|
|
1681
|
+
const u = Eo(o, t);
|
|
1724
1682
|
if (u !== void 0)
|
|
1725
1683
|
return u;
|
|
1726
1684
|
}
|
|
1727
1685
|
const s = { def: e, path: t.currentPath, jsonSchema: void 0 };
|
|
1728
1686
|
t.seen.set(e, s);
|
|
1729
|
-
const i = Co(e, e.typeName, t), l = typeof i == "function" ?
|
|
1730
|
-
if (l &&
|
|
1687
|
+
const i = Co(e, e.typeName, t), l = typeof i == "function" ? z(i(), t) : i;
|
|
1688
|
+
if (l && Po(e, t, l), t.postProcess) {
|
|
1731
1689
|
const u = t.postProcess(l, e, t);
|
|
1732
1690
|
return s.jsonSchema = l, u;
|
|
1733
1691
|
}
|
|
1734
1692
|
return s.jsonSchema = l, l;
|
|
1735
1693
|
}
|
|
1736
|
-
var
|
|
1694
|
+
var Eo = (e, t) => {
|
|
1737
1695
|
switch (t.$refStrategy) {
|
|
1738
1696
|
case "root":
|
|
1739
1697
|
return { $ref: e.path.join("/") };
|
|
@@ -1747,7 +1705,7 @@ var Po = (e, t) => {
|
|
|
1747
1705
|
)}! Defaulting to any`
|
|
1748
1706
|
), B()) : t.$refStrategy === "seen" ? B() : void 0;
|
|
1749
1707
|
}
|
|
1750
|
-
},
|
|
1708
|
+
}, Po = (e, t, r) => (e.description && (r.description = e.description), r), Ro = (e) => {
|
|
1751
1709
|
const t = Vn(e), r = t.name !== void 0 ? [...t.basePath, t.definitionPath, t.name] : t.basePath;
|
|
1752
1710
|
return {
|
|
1753
1711
|
...t,
|
|
@@ -1773,7 +1731,7 @@ var Po = (e, t) => {
|
|
|
1773
1731
|
var f;
|
|
1774
1732
|
return {
|
|
1775
1733
|
...c,
|
|
1776
|
-
[d]: (f =
|
|
1734
|
+
[d]: (f = z(
|
|
1777
1735
|
p._def,
|
|
1778
1736
|
{
|
|
1779
1737
|
...n,
|
|
@@ -1785,7 +1743,7 @@ var Po = (e, t) => {
|
|
|
1785
1743
|
},
|
|
1786
1744
|
{}
|
|
1787
1745
|
) : void 0;
|
|
1788
|
-
const s = typeof t == "string" ? t : t?.nameStrategy === "title" ? void 0 : t?.name, i = (r =
|
|
1746
|
+
const s = typeof t == "string" ? t : t?.nameStrategy === "title" ? void 0 : t?.name, i = (r = z(
|
|
1789
1747
|
e._def,
|
|
1790
1748
|
s === void 0 ? n : {
|
|
1791
1749
|
...n,
|
|
@@ -1810,7 +1768,7 @@ var Po = (e, t) => {
|
|
|
1810
1768
|
};
|
|
1811
1769
|
return u.$schema = "http://json-schema.org/draft-07/schema#", u;
|
|
1812
1770
|
}, ht = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
1813
|
-
function
|
|
1771
|
+
function Pe(e, {
|
|
1814
1772
|
validate: t
|
|
1815
1773
|
} = {}) {
|
|
1816
1774
|
return {
|
|
@@ -1823,14 +1781,18 @@ function Ee(e, {
|
|
|
1823
1781
|
validate: t
|
|
1824
1782
|
};
|
|
1825
1783
|
}
|
|
1826
|
-
function
|
|
1784
|
+
function Oo(e) {
|
|
1827
1785
|
return typeof e == "object" && e !== null && ht in e && e[ht] === !0 && "jsonSchema" in e && "validate" in e;
|
|
1828
1786
|
}
|
|
1829
|
-
function
|
|
1830
|
-
return e == null ?
|
|
1787
|
+
function Cr(e) {
|
|
1788
|
+
return e == null ? Pe({
|
|
1789
|
+
type: "object",
|
|
1790
|
+
properties: {},
|
|
1791
|
+
additionalProperties: !1
|
|
1792
|
+
}) : Oo(e) ? e : "~standard" in e ? e["~standard"].vendor === "zod" ? No(e) : Ao(e) : e();
|
|
1831
1793
|
}
|
|
1832
|
-
function
|
|
1833
|
-
return
|
|
1794
|
+
function Ao(e) {
|
|
1795
|
+
return Pe(
|
|
1834
1796
|
() => Tt(
|
|
1835
1797
|
e["~standard"].jsonSchema.input({
|
|
1836
1798
|
target: "draft-07"
|
|
@@ -1850,10 +1812,10 @@ function Oo(e) {
|
|
|
1850
1812
|
}
|
|
1851
1813
|
);
|
|
1852
1814
|
}
|
|
1853
|
-
function
|
|
1815
|
+
function Io(e, t) {
|
|
1854
1816
|
var r;
|
|
1855
1817
|
const n = (r = void 0) != null ? r : !1;
|
|
1856
|
-
return
|
|
1818
|
+
return Pe(
|
|
1857
1819
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
1858
1820
|
() => ko(e, {
|
|
1859
1821
|
$refStrategy: n ? "root" : "none"
|
|
@@ -1866,13 +1828,13 @@ function Mo(e, t) {
|
|
|
1866
1828
|
}
|
|
1867
1829
|
);
|
|
1868
1830
|
}
|
|
1869
|
-
function
|
|
1831
|
+
function Mo(e, t) {
|
|
1870
1832
|
var r;
|
|
1871
1833
|
const n = (r = void 0) != null ? r : !1;
|
|
1872
|
-
return
|
|
1834
|
+
return Pe(
|
|
1873
1835
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
1874
1836
|
() => Tt(
|
|
1875
|
-
|
|
1837
|
+
Lt.toJSONSchema(e, {
|
|
1876
1838
|
target: "draft-7",
|
|
1877
1839
|
io: "input",
|
|
1878
1840
|
reused: n ? "ref" : "inline"
|
|
@@ -1880,7 +1842,7 @@ function Ao(e, t) {
|
|
|
1880
1842
|
),
|
|
1881
1843
|
{
|
|
1882
1844
|
validate: async (o) => {
|
|
1883
|
-
const s = await
|
|
1845
|
+
const s = await Lt.safeParseAsync(e, o);
|
|
1884
1846
|
return s.success ? { success: !0, value: s.data } : { success: !1, error: s.error };
|
|
1885
1847
|
}
|
|
1886
1848
|
}
|
|
@@ -1890,7 +1852,7 @@ function jo(e) {
|
|
|
1890
1852
|
return "_zod" in e;
|
|
1891
1853
|
}
|
|
1892
1854
|
function No(e, t) {
|
|
1893
|
-
return jo(e) ?
|
|
1855
|
+
return jo(e) ? Mo(e) : Io(e);
|
|
1894
1856
|
}
|
|
1895
1857
|
async function zo({
|
|
1896
1858
|
value: e,
|
|
@@ -1907,7 +1869,7 @@ async function Ct({
|
|
|
1907
1869
|
schema: t,
|
|
1908
1870
|
context: r
|
|
1909
1871
|
}) {
|
|
1910
|
-
const n =
|
|
1872
|
+
const n = Cr(t);
|
|
1911
1873
|
try {
|
|
1912
1874
|
if (n.validate == null)
|
|
1913
1875
|
return { success: !0, value: e, rawValue: e };
|
|
@@ -1925,15 +1887,15 @@ async function Ct({
|
|
|
1925
1887
|
};
|
|
1926
1888
|
}
|
|
1927
1889
|
}
|
|
1928
|
-
async function
|
|
1890
|
+
async function $r({
|
|
1929
1891
|
text: e,
|
|
1930
1892
|
schema: t
|
|
1931
1893
|
}) {
|
|
1932
1894
|
try {
|
|
1933
|
-
const r =
|
|
1895
|
+
const r = br(e);
|
|
1934
1896
|
return t == null ? r : zo({ value: r, schema: t });
|
|
1935
1897
|
} catch (r) {
|
|
1936
|
-
throw
|
|
1898
|
+
throw Le.isInstance(r) || Ce.isInstance(r) ? r : new Le({ text: e, cause: r });
|
|
1937
1899
|
}
|
|
1938
1900
|
}
|
|
1939
1901
|
async function Uo({
|
|
@@ -1941,73 +1903,122 @@ async function Uo({
|
|
|
1941
1903
|
schema: t
|
|
1942
1904
|
}) {
|
|
1943
1905
|
try {
|
|
1944
|
-
const r =
|
|
1906
|
+
const r = br(e);
|
|
1945
1907
|
return t == null ? { success: !0, value: r, rawValue: r } : await Ct({ value: r, schema: t });
|
|
1946
1908
|
} catch (r) {
|
|
1947
1909
|
return {
|
|
1948
1910
|
success: !1,
|
|
1949
|
-
error:
|
|
1911
|
+
error: Le.isInstance(r) ? r : new Le({ text: e, cause: r }),
|
|
1950
1912
|
rawValue: void 0
|
|
1951
1913
|
};
|
|
1952
1914
|
}
|
|
1953
1915
|
}
|
|
1954
|
-
function
|
|
1916
|
+
function Do(e) {
|
|
1955
1917
|
return { ...e, type: "dynamic" };
|
|
1956
1918
|
}
|
|
1919
|
+
var Lo = ({
|
|
1920
|
+
maxRetries: e = 2,
|
|
1921
|
+
initialDelayInMs: t = 2e3,
|
|
1922
|
+
backoffFactor: r = 2,
|
|
1923
|
+
abortSignal: n,
|
|
1924
|
+
shouldRetry: o,
|
|
1925
|
+
getDelayInMs: s = ({ exponentialBackoffDelay: l }) => l,
|
|
1926
|
+
createRetryError: i = ({ message: l }) => new Error(l)
|
|
1927
|
+
}) => async (l) => Er(l, {
|
|
1928
|
+
maxRetries: e,
|
|
1929
|
+
delayInMs: t,
|
|
1930
|
+
backoffFactor: r,
|
|
1931
|
+
abortSignal: n,
|
|
1932
|
+
shouldRetry: o,
|
|
1933
|
+
getDelayInMs: s,
|
|
1934
|
+
createRetryError: i
|
|
1935
|
+
});
|
|
1936
|
+
async function Er(e, {
|
|
1937
|
+
maxRetries: t,
|
|
1938
|
+
delayInMs: r,
|
|
1939
|
+
backoffFactor: n,
|
|
1940
|
+
abortSignal: o,
|
|
1941
|
+
shouldRetry: s,
|
|
1942
|
+
getDelayInMs: i,
|
|
1943
|
+
createRetryError: l
|
|
1944
|
+
}, u = []) {
|
|
1945
|
+
try {
|
|
1946
|
+
return await e();
|
|
1947
|
+
} catch (c) {
|
|
1948
|
+
if (Dn(c) || t === 0)
|
|
1949
|
+
throw c;
|
|
1950
|
+
const d = Un(c), p = [...u, c], f = p.length;
|
|
1951
|
+
if (f > t)
|
|
1952
|
+
throw l({
|
|
1953
|
+
message: `Failed after ${f} attempts. Last error: ${d}`,
|
|
1954
|
+
reason: "maxRetriesExceeded",
|
|
1955
|
+
errors: p
|
|
1956
|
+
});
|
|
1957
|
+
if (await s(c) && f <= t)
|
|
1958
|
+
return await Nn(
|
|
1959
|
+
i({
|
|
1960
|
+
error: c,
|
|
1961
|
+
exponentialBackoffDelay: r
|
|
1962
|
+
}),
|
|
1963
|
+
{ abortSignal: o }
|
|
1964
|
+
), Er(
|
|
1965
|
+
e,
|
|
1966
|
+
{
|
|
1967
|
+
maxRetries: t,
|
|
1968
|
+
delayInMs: n * r,
|
|
1969
|
+
backoffFactor: n,
|
|
1970
|
+
abortSignal: o,
|
|
1971
|
+
shouldRetry: s,
|
|
1972
|
+
getDelayInMs: i,
|
|
1973
|
+
createRetryError: l
|
|
1974
|
+
},
|
|
1975
|
+
p
|
|
1976
|
+
);
|
|
1977
|
+
throw f === 1 ? c : l({
|
|
1978
|
+
message: `Failed after ${f} attempts with non-retryable error: '${d}'`,
|
|
1979
|
+
reason: "errorNotRetryable",
|
|
1980
|
+
errors: p
|
|
1981
|
+
});
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1957
1984
|
new TextDecoder();
|
|
1958
1985
|
let $t;
|
|
1959
1986
|
$t = globalThis.crypto;
|
|
1960
|
-
async function
|
|
1987
|
+
async function qo(e) {
|
|
1961
1988
|
return (await $t).getRandomValues(new Uint8Array(e));
|
|
1962
1989
|
}
|
|
1963
|
-
async function
|
|
1990
|
+
async function Ho(e) {
|
|
1964
1991
|
const t = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~", r = Math.pow(2, 8) - Math.pow(2, 8) % t.length;
|
|
1965
1992
|
let n = "";
|
|
1966
1993
|
for (; n.length < e; ) {
|
|
1967
|
-
const o = await
|
|
1994
|
+
const o = await qo(e - n.length);
|
|
1968
1995
|
for (const s of o)
|
|
1969
1996
|
s < r && (n += t[s % t.length]);
|
|
1970
1997
|
}
|
|
1971
1998
|
return n;
|
|
1972
1999
|
}
|
|
1973
|
-
async function Ho(e) {
|
|
1974
|
-
return await qo(e);
|
|
1975
|
-
}
|
|
1976
2000
|
async function Fo(e) {
|
|
2001
|
+
return await Ho(e);
|
|
2002
|
+
}
|
|
2003
|
+
async function Zo(e) {
|
|
1977
2004
|
const t = await (await $t).subtle.digest("SHA-256", new TextEncoder().encode(e));
|
|
1978
2005
|
return btoa(String.fromCharCode(...new Uint8Array(t))).replace(/\//g, "_").replace(/\+/g, "-").replace(/=/g, "");
|
|
1979
2006
|
}
|
|
1980
|
-
async function
|
|
2007
|
+
async function Vo(e) {
|
|
1981
2008
|
if (e || (e = 43), e < 43 || e > 128)
|
|
1982
2009
|
throw `Expected a length between 43 and 128. Received ${e}.`;
|
|
1983
|
-
const t = await
|
|
2010
|
+
const t = await Fo(e), r = await Zo(t);
|
|
1984
2011
|
return {
|
|
1985
2012
|
code_verifier: t,
|
|
1986
2013
|
code_challenge: r
|
|
1987
2014
|
};
|
|
1988
2015
|
}
|
|
1989
|
-
var
|
|
1990
|
-
constructor({
|
|
1991
|
-
name: e = "MCPClientError",
|
|
1992
|
-
message: t,
|
|
1993
|
-
cause: r,
|
|
1994
|
-
data: n,
|
|
1995
|
-
code: o,
|
|
1996
|
-
statusCode: s,
|
|
1997
|
-
url: i,
|
|
1998
|
-
responseBody: l
|
|
1999
|
-
}) {
|
|
2000
|
-
super({ name: e, message: t, cause: r }), this[Wt] = !0, this.data = n, this.code = o, this.statusCode = s, this.url = i, this.responseBody = l;
|
|
2001
|
-
}
|
|
2002
|
-
static isInstance(e) {
|
|
2003
|
-
return qe.hasMarker(e, $r);
|
|
2004
|
-
}
|
|
2005
|
-
}, we = "2025-11-25", Wo = [
|
|
2016
|
+
var we = "2025-11-25", Jo = [
|
|
2006
2017
|
we,
|
|
2007
2018
|
"2025-06-18",
|
|
2008
2019
|
"2025-03-26",
|
|
2009
2020
|
"2024-11-05"
|
|
2010
|
-
],
|
|
2021
|
+
], Wo = a.optional(a.record(a.string(), a.unknown())), Bo = a.looseObject({
|
|
2011
2022
|
name: a.string(),
|
|
2012
2023
|
version: a.string(),
|
|
2013
2024
|
title: a.optional(a.string())
|
|
@@ -2016,9 +2027,9 @@ var Vo = "AI_MCPClientError", $r = `vercel.ai.error.${Vo}`, Jo = Symbol.for($r),
|
|
|
2016
2027
|
}), ne = Re, Pr = a.object({
|
|
2017
2028
|
method: a.string(),
|
|
2018
2029
|
params: a.optional(Re)
|
|
2019
|
-
}),
|
|
2030
|
+
}), Rr = a.object({
|
|
2020
2031
|
applyDefaults: a.optional(a.boolean())
|
|
2021
|
-
}).loose(),
|
|
2032
|
+
}).loose(), Go = a.looseObject({
|
|
2022
2033
|
experimental: a.optional(a.object({}).loose()),
|
|
2023
2034
|
logging: a.optional(a.object({}).loose()),
|
|
2024
2035
|
completions: a.optional(a.object({}).loose()),
|
|
@@ -2038,19 +2049,19 @@ var Vo = "AI_MCPClientError", $r = `vercel.ai.error.${Vo}`, Jo = Symbol.for($r),
|
|
|
2038
2049
|
listChanged: a.optional(a.boolean())
|
|
2039
2050
|
})
|
|
2040
2051
|
),
|
|
2041
|
-
elicitation: a.optional(
|
|
2052
|
+
elicitation: a.optional(Rr)
|
|
2042
2053
|
});
|
|
2043
2054
|
a.object({
|
|
2044
|
-
elicitation: a.optional(
|
|
2055
|
+
elicitation: a.optional(Rr)
|
|
2045
2056
|
}).loose();
|
|
2046
|
-
var
|
|
2057
|
+
var Ko = ne.extend({
|
|
2047
2058
|
protocolVersion: a.string(),
|
|
2048
|
-
capabilities:
|
|
2049
|
-
serverInfo:
|
|
2059
|
+
capabilities: Go,
|
|
2060
|
+
serverInfo: Bo,
|
|
2050
2061
|
instructions: a.optional(a.string())
|
|
2051
|
-
}),
|
|
2062
|
+
}), Et = ne.extend({
|
|
2052
2063
|
nextCursor: a.optional(a.string())
|
|
2053
|
-
}),
|
|
2064
|
+
}), Yo = a.object({
|
|
2054
2065
|
name: a.string(),
|
|
2055
2066
|
/**
|
|
2056
2067
|
* @see https://modelcontextprotocol.io/specification/2025-11-25/server/tools#tool
|
|
@@ -2070,26 +2081,26 @@ var Yo = ne.extend({
|
|
|
2070
2081
|
title: a.optional(a.string())
|
|
2071
2082
|
}).loose()
|
|
2072
2083
|
),
|
|
2073
|
-
_meta:
|
|
2074
|
-
}).loose(),
|
|
2075
|
-
tools: a.array(
|
|
2076
|
-
}),
|
|
2084
|
+
_meta: Wo
|
|
2085
|
+
}).loose(), Xo = Et.extend({
|
|
2086
|
+
tools: a.array(Yo)
|
|
2087
|
+
}), kr = a.object({
|
|
2077
2088
|
type: a.literal("text"),
|
|
2078
2089
|
text: a.string()
|
|
2079
|
-
}).loose(),
|
|
2090
|
+
}).loose(), Or = a.object({
|
|
2080
2091
|
type: a.literal("image"),
|
|
2081
2092
|
data: a.base64(),
|
|
2082
2093
|
mimeType: a.string()
|
|
2083
|
-
}).loose(),
|
|
2094
|
+
}).loose(), Qo = a.object({
|
|
2084
2095
|
uri: a.string(),
|
|
2085
2096
|
name: a.string(),
|
|
2086
2097
|
title: a.optional(a.string()),
|
|
2087
2098
|
description: a.optional(a.string()),
|
|
2088
2099
|
mimeType: a.optional(a.string()),
|
|
2089
2100
|
size: a.optional(a.number())
|
|
2090
|
-
}).loose(),
|
|
2091
|
-
resources: a.array(
|
|
2092
|
-
}),
|
|
2101
|
+
}).loose(), es = Et.extend({
|
|
2102
|
+
resources: a.array(Qo)
|
|
2103
|
+
}), Ar = a.object({
|
|
2093
2104
|
/**
|
|
2094
2105
|
* The URI of this resource.
|
|
2095
2106
|
*/
|
|
@@ -2106,26 +2117,26 @@ var Yo = ne.extend({
|
|
|
2106
2117
|
* The MIME type of this resource, if known.
|
|
2107
2118
|
*/
|
|
2108
2119
|
mimeType: a.optional(a.string())
|
|
2109
|
-
}).loose(),
|
|
2120
|
+
}).loose(), Ir = Ar.extend({
|
|
2110
2121
|
text: a.string()
|
|
2111
|
-
}), Mr =
|
|
2122
|
+
}), Mr = Ar.extend({
|
|
2112
2123
|
blob: a.base64()
|
|
2113
|
-
}),
|
|
2124
|
+
}), jr = a.object({
|
|
2114
2125
|
type: a.literal("resource"),
|
|
2115
|
-
resource: a.union([
|
|
2116
|
-
}).loose(),
|
|
2126
|
+
resource: a.union([Ir, Mr])
|
|
2127
|
+
}).loose(), Nr = a.object({
|
|
2117
2128
|
type: a.literal("resource_link"),
|
|
2118
2129
|
uri: a.string(),
|
|
2119
2130
|
name: a.string(),
|
|
2120
2131
|
description: a.optional(a.string()),
|
|
2121
2132
|
mimeType: a.optional(a.string())
|
|
2122
|
-
}).loose(),
|
|
2133
|
+
}).loose(), ts = ne.extend({
|
|
2123
2134
|
content: a.array(
|
|
2124
2135
|
a.union([
|
|
2125
|
-
Rr,
|
|
2126
2136
|
kr,
|
|
2127
|
-
|
|
2128
|
-
jr
|
|
2137
|
+
Or,
|
|
2138
|
+
jr,
|
|
2139
|
+
Nr
|
|
2129
2140
|
])
|
|
2130
2141
|
),
|
|
2131
2142
|
/**
|
|
@@ -2137,86 +2148,86 @@ var Yo = ne.extend({
|
|
|
2137
2148
|
ne.extend({
|
|
2138
2149
|
toolResult: a.unknown()
|
|
2139
2150
|
})
|
|
2140
|
-
),
|
|
2151
|
+
), rs = a.object({
|
|
2141
2152
|
uriTemplate: a.string(),
|
|
2142
2153
|
name: a.string(),
|
|
2143
2154
|
title: a.optional(a.string()),
|
|
2144
2155
|
description: a.optional(a.string()),
|
|
2145
2156
|
mimeType: a.optional(a.string())
|
|
2146
|
-
}).loose(),
|
|
2147
|
-
resourceTemplates: a.array(
|
|
2148
|
-
}),
|
|
2157
|
+
}).loose(), ns = ne.extend({
|
|
2158
|
+
resourceTemplates: a.array(rs)
|
|
2159
|
+
}), os = ne.extend({
|
|
2149
2160
|
contents: a.array(
|
|
2150
|
-
a.union([
|
|
2161
|
+
a.union([Ir, Mr])
|
|
2151
2162
|
)
|
|
2152
|
-
}),
|
|
2163
|
+
}), ss = a.object({
|
|
2153
2164
|
type: a.literal("ref/prompt"),
|
|
2154
2165
|
name: a.string()
|
|
2155
|
-
}).loose(),
|
|
2166
|
+
}).loose(), is = a.object({
|
|
2156
2167
|
type: a.literal("ref/resource"),
|
|
2157
2168
|
uri: a.string()
|
|
2158
|
-
}).loose(),
|
|
2169
|
+
}).loose(), as = a.object({
|
|
2159
2170
|
name: a.string(),
|
|
2160
2171
|
value: a.string()
|
|
2161
2172
|
}).loose();
|
|
2162
2173
|
Re.extend({
|
|
2163
|
-
ref: a.union([
|
|
2164
|
-
argument:
|
|
2174
|
+
ref: a.union([ss, is]),
|
|
2175
|
+
argument: as,
|
|
2165
2176
|
context: a.optional(
|
|
2166
2177
|
a.object({
|
|
2167
2178
|
arguments: a.record(a.string(), a.string())
|
|
2168
2179
|
}).loose()
|
|
2169
2180
|
)
|
|
2170
2181
|
});
|
|
2171
|
-
var
|
|
2182
|
+
var ls = ne.extend({
|
|
2172
2183
|
completion: a.object({
|
|
2173
2184
|
values: a.array(a.string()).max(100),
|
|
2174
2185
|
total: a.optional(a.number().int()),
|
|
2175
2186
|
hasMore: a.optional(a.boolean())
|
|
2176
2187
|
}).loose()
|
|
2177
|
-
}),
|
|
2188
|
+
}), cs = a.object({
|
|
2178
2189
|
name: a.string(),
|
|
2179
2190
|
description: a.optional(a.string()),
|
|
2180
2191
|
required: a.optional(a.boolean())
|
|
2181
|
-
}).loose(),
|
|
2192
|
+
}).loose(), us = a.object({
|
|
2182
2193
|
name: a.string(),
|
|
2183
2194
|
title: a.optional(a.string()),
|
|
2184
2195
|
description: a.optional(a.string()),
|
|
2185
|
-
arguments: a.optional(a.array(
|
|
2186
|
-
}).loose(),
|
|
2187
|
-
prompts: a.array(
|
|
2188
|
-
}),
|
|
2196
|
+
arguments: a.optional(a.array(cs))
|
|
2197
|
+
}).loose(), ds = Et.extend({
|
|
2198
|
+
prompts: a.array(us)
|
|
2199
|
+
}), fs = a.object({
|
|
2189
2200
|
role: a.union([a.literal("user"), a.literal("assistant")]),
|
|
2190
2201
|
content: a.union([
|
|
2191
|
-
Rr,
|
|
2192
2202
|
kr,
|
|
2193
|
-
|
|
2194
|
-
jr
|
|
2203
|
+
Or,
|
|
2204
|
+
jr,
|
|
2205
|
+
Nr
|
|
2195
2206
|
])
|
|
2196
|
-
}).loose(),
|
|
2207
|
+
}).loose(), ps = ne.extend({
|
|
2197
2208
|
description: a.optional(a.string()),
|
|
2198
|
-
messages: a.array(
|
|
2199
|
-
}),
|
|
2209
|
+
messages: a.array(fs)
|
|
2210
|
+
}), hs = Re.extend({
|
|
2200
2211
|
message: a.string(),
|
|
2201
2212
|
requestedSchema: a.unknown()
|
|
2202
|
-
}),
|
|
2213
|
+
}), Bt = Pr.extend({
|
|
2203
2214
|
method: a.literal("elicitation/create"),
|
|
2204
|
-
params:
|
|
2205
|
-
}),
|
|
2215
|
+
params: hs
|
|
2216
|
+
}), ms = ne.extend({
|
|
2206
2217
|
action: a.union([
|
|
2207
2218
|
a.literal("accept"),
|
|
2208
2219
|
a.literal("decline"),
|
|
2209
2220
|
a.literal("cancel")
|
|
2210
2221
|
]),
|
|
2211
2222
|
content: a.optional(a.record(a.string(), a.unknown()))
|
|
2212
|
-
}), Qe = "2.0",
|
|
2223
|
+
}), Qe = "2.0", gs = a.object({
|
|
2213
2224
|
jsonrpc: a.literal(Qe),
|
|
2214
2225
|
id: a.union([a.string(), a.number().int()])
|
|
2215
|
-
}).merge(Pr).strict(),
|
|
2226
|
+
}).merge(Pr).strict(), ys = a.object({
|
|
2216
2227
|
jsonrpc: a.literal(Qe),
|
|
2217
2228
|
id: a.union([a.string(), a.number().int()]),
|
|
2218
2229
|
result: ne
|
|
2219
|
-
}).strict(),
|
|
2230
|
+
}).strict(), vs = a.object({
|
|
2220
2231
|
jsonrpc: a.literal(Qe),
|
|
2221
2232
|
id: a.union([a.string(), a.number().int()]),
|
|
2222
2233
|
error: a.object({
|
|
@@ -2224,23 +2235,42 @@ var cs = ne.extend({
|
|
|
2224
2235
|
message: a.string(),
|
|
2225
2236
|
data: a.optional(a.unknown())
|
|
2226
2237
|
})
|
|
2227
|
-
}).strict(),
|
|
2238
|
+
}).strict(), ws = a.object({
|
|
2228
2239
|
jsonrpc: a.literal(Qe)
|
|
2229
2240
|
}).merge(
|
|
2230
2241
|
a.object({
|
|
2231
2242
|
method: a.string(),
|
|
2232
2243
|
params: a.optional(Re)
|
|
2233
2244
|
})
|
|
2234
|
-
).strict(),
|
|
2245
|
+
).strict(), bs = a.union([
|
|
2246
|
+
gs,
|
|
2247
|
+
ws,
|
|
2235
2248
|
ys,
|
|
2236
|
-
|
|
2237
|
-
vs,
|
|
2238
|
-
ws
|
|
2249
|
+
vs
|
|
2239
2250
|
]);
|
|
2251
|
+
function mt(e) {
|
|
2252
|
+
return bs.parse(e);
|
|
2253
|
+
}
|
|
2240
2254
|
async function gt(e) {
|
|
2241
|
-
return mt
|
|
2255
|
+
return mt(await $r({ text: e }));
|
|
2242
2256
|
}
|
|
2243
|
-
var
|
|
2257
|
+
var _s = "AI_MCPClientError", zr = `vercel.ai.error.${_s}`, xs = Symbol.for(zr), Gt, Kt, A = class extends (Kt = qe, Gt = xs, Kt) {
|
|
2258
|
+
constructor({
|
|
2259
|
+
name: e = "MCPClientError",
|
|
2260
|
+
message: t,
|
|
2261
|
+
cause: r,
|
|
2262
|
+
data: n,
|
|
2263
|
+
code: o,
|
|
2264
|
+
statusCode: s,
|
|
2265
|
+
url: i,
|
|
2266
|
+
responseBody: l
|
|
2267
|
+
}) {
|
|
2268
|
+
super({ name: e, message: t, cause: r }), this[Gt] = !0, this.data = n, this.code = o, this.statusCode = s, this.url = i, this.responseBody = l;
|
|
2269
|
+
}
|
|
2270
|
+
static isInstance(e) {
|
|
2271
|
+
return qe.hasMarker(e, zr);
|
|
2272
|
+
}
|
|
2273
|
+
}, Ur = typeof __PACKAGE_VERSION__ < "u" ? __PACKAGE_VERSION__ : "0.0.0-test", F = a.string().url().superRefine((e, t) => {
|
|
2244
2274
|
if (!URL.canParse(e))
|
|
2245
2275
|
return t.addIssue({
|
|
2246
2276
|
code: a.ZodIssueCode.custom,
|
|
@@ -2253,7 +2283,7 @@ var Nr = typeof __PACKAGE_VERSION__ < "u" ? __PACKAGE_VERSION__ : "0.0.0-test",
|
|
|
2253
2283
|
return t.protocol !== "javascript:" && t.protocol !== "data:" && t.protocol !== "vbscript:";
|
|
2254
2284
|
},
|
|
2255
2285
|
{ message: "URL cannot use javascript:, data:, or vbscript: scheme" }
|
|
2256
|
-
),
|
|
2286
|
+
), Dr = a.object({
|
|
2257
2287
|
access_token: a.string(),
|
|
2258
2288
|
id_token: a.string().optional(),
|
|
2259
2289
|
// Optional for OAuth 2.1, but necessary in OpenID Connect
|
|
@@ -2263,7 +2293,7 @@ var Nr = typeof __PACKAGE_VERSION__ < "u" ? __PACKAGE_VERSION__ : "0.0.0-test",
|
|
|
2263
2293
|
refresh_token: a.string().optional(),
|
|
2264
2294
|
authorization_server: F.optional(),
|
|
2265
2295
|
token_endpoint: F.optional()
|
|
2266
|
-
}).strip(),
|
|
2296
|
+
}).strip(), Ss = a.object({
|
|
2267
2297
|
resource: a.string().url(),
|
|
2268
2298
|
authorization_servers: a.array(F).optional(),
|
|
2269
2299
|
jwks_uri: a.string().url().optional(),
|
|
@@ -2278,7 +2308,7 @@ var Nr = typeof __PACKAGE_VERSION__ < "u" ? __PACKAGE_VERSION__ : "0.0.0-test",
|
|
|
2278
2308
|
authorization_details_types_supported: a.array(a.string()).optional(),
|
|
2279
2309
|
dpop_signing_alg_values_supported: a.array(a.string()).optional(),
|
|
2280
2310
|
dpop_bound_access_tokens_required: a.boolean().optional()
|
|
2281
|
-
}).passthrough(),
|
|
2311
|
+
}).passthrough(), Lr = a.object({
|
|
2282
2312
|
issuer: a.string(),
|
|
2283
2313
|
authorization_endpoint: F,
|
|
2284
2314
|
token_endpoint: F,
|
|
@@ -2289,7 +2319,7 @@ var Nr = typeof __PACKAGE_VERSION__ < "u" ? __PACKAGE_VERSION__ : "0.0.0-test",
|
|
|
2289
2319
|
code_challenge_methods_supported: a.array(a.string()),
|
|
2290
2320
|
token_endpoint_auth_methods_supported: a.array(a.string()).optional(),
|
|
2291
2321
|
token_endpoint_auth_signing_alg_values_supported: a.array(a.string()).optional()
|
|
2292
|
-
}).passthrough(),
|
|
2322
|
+
}).passthrough(), Ts = a.object({
|
|
2293
2323
|
issuer: a.string(),
|
|
2294
2324
|
authorization_endpoint: F,
|
|
2295
2325
|
token_endpoint: F,
|
|
@@ -2303,18 +2333,18 @@ var Nr = typeof __PACKAGE_VERSION__ < "u" ? __PACKAGE_VERSION__ : "0.0.0-test",
|
|
|
2303
2333
|
id_token_signing_alg_values_supported: a.array(a.string()),
|
|
2304
2334
|
claims_supported: a.array(a.string()).optional(),
|
|
2305
2335
|
token_endpoint_auth_methods_supported: a.array(a.string()).optional()
|
|
2306
|
-
}).passthrough(),
|
|
2307
|
-
|
|
2336
|
+
}).passthrough(), Cs = Ts.merge(
|
|
2337
|
+
Lr.pick({
|
|
2308
2338
|
code_challenge_methods_supported: !0
|
|
2309
2339
|
})
|
|
2310
|
-
),
|
|
2340
|
+
), $s = a.object({
|
|
2311
2341
|
client_id: a.string(),
|
|
2312
2342
|
client_secret: a.string().optional(),
|
|
2313
2343
|
client_id_issued_at: a.number().optional(),
|
|
2314
2344
|
client_secret_expires_at: a.number().optional(),
|
|
2315
2345
|
authorization_server: F.optional(),
|
|
2316
2346
|
token_endpoint: F.optional()
|
|
2317
|
-
}).strip(),
|
|
2347
|
+
}).strip(), Es = a.object({
|
|
2318
2348
|
redirect_uris: a.array(F),
|
|
2319
2349
|
token_endpoint_auth_method: a.string().optional(),
|
|
2320
2350
|
grant_types: a.array(a.string()).optional(),
|
|
@@ -2331,22 +2361,22 @@ var Nr = typeof __PACKAGE_VERSION__ < "u" ? __PACKAGE_VERSION__ : "0.0.0-test",
|
|
|
2331
2361
|
software_id: a.string().optional(),
|
|
2332
2362
|
software_version: a.string().optional(),
|
|
2333
2363
|
software_statement: a.string().optional()
|
|
2334
|
-
}).strip(),
|
|
2364
|
+
}).strip(), Ps = a.object({
|
|
2335
2365
|
error: a.string(),
|
|
2336
2366
|
error_description: a.string().optional(),
|
|
2337
2367
|
error_uri: a.string().optional()
|
|
2338
|
-
}),
|
|
2339
|
-
|
|
2340
|
-
),
|
|
2368
|
+
}), Rs = Es.merge(
|
|
2369
|
+
$s
|
|
2370
|
+
), ks = "AI_MCPClientOAuthError", qr = `vercel.ai.error.${ks}`, Os = Symbol.for(qr), Yt, Xt, re = class extends (Xt = qe, Yt = Os, Xt) {
|
|
2341
2371
|
constructor({
|
|
2342
2372
|
name: e = "MCPClientOAuthError",
|
|
2343
2373
|
message: t,
|
|
2344
2374
|
cause: r
|
|
2345
2375
|
}) {
|
|
2346
|
-
super({ name: e, message: t, cause: r }), this[
|
|
2376
|
+
super({ name: e, message: t, cause: r }), this[Yt] = !0;
|
|
2347
2377
|
}
|
|
2348
2378
|
static isInstance(e) {
|
|
2349
|
-
return qe.hasMarker(e,
|
|
2379
|
+
return qe.hasMarker(e, qr);
|
|
2350
2380
|
}
|
|
2351
2381
|
}, ge = class extends re {
|
|
2352
2382
|
};
|
|
@@ -2360,7 +2390,7 @@ Fe.errorCode = "invalid_grant";
|
|
|
2360
2390
|
var Ze = class extends re {
|
|
2361
2391
|
};
|
|
2362
2392
|
Ze.errorCode = "unauthorized_client";
|
|
2363
|
-
var
|
|
2393
|
+
var As = {
|
|
2364
2394
|
[ge.errorCode]: ge,
|
|
2365
2395
|
[He.errorCode]: He,
|
|
2366
2396
|
[Fe.errorCode]: Fe,
|
|
@@ -2370,11 +2400,11 @@ function Is(e) {
|
|
|
2370
2400
|
const t = typeof e == "string" ? new URL(e) : new URL(e.href);
|
|
2371
2401
|
return t.hash = "", t;
|
|
2372
2402
|
}
|
|
2373
|
-
function
|
|
2403
|
+
function Pt(e) {
|
|
2374
2404
|
const t = e.href;
|
|
2375
2405
|
return e.pathname === "/" && t.endsWith("/") ? t.slice(0, -1) : t;
|
|
2376
2406
|
}
|
|
2377
|
-
function
|
|
2407
|
+
function Ms({
|
|
2378
2408
|
requestedResource: e,
|
|
2379
2409
|
configuredResource: t
|
|
2380
2410
|
}) {
|
|
@@ -2392,7 +2422,7 @@ var Ve = class extends Error {
|
|
|
2392
2422
|
function ye(e) {
|
|
2393
2423
|
return new URL(e).href;
|
|
2394
2424
|
}
|
|
2395
|
-
function
|
|
2425
|
+
function js(e, t) {
|
|
2396
2426
|
return {
|
|
2397
2427
|
authorizationServerUrl: ye(e),
|
|
2398
2428
|
tokenEndpoint: ye(
|
|
@@ -2400,34 +2430,34 @@ function Ms(e, t) {
|
|
|
2400
2430
|
)
|
|
2401
2431
|
};
|
|
2402
2432
|
}
|
|
2403
|
-
function
|
|
2433
|
+
function Qt(e, t) {
|
|
2404
2434
|
return {
|
|
2405
2435
|
...e,
|
|
2406
2436
|
authorization_server: t.authorizationServerUrl,
|
|
2407
2437
|
token_endpoint: t.tokenEndpoint
|
|
2408
2438
|
};
|
|
2409
2439
|
}
|
|
2410
|
-
function
|
|
2440
|
+
function Hr(e, t) {
|
|
2411
2441
|
return {
|
|
2412
2442
|
...e,
|
|
2413
2443
|
authorization_server: t.authorizationServerUrl,
|
|
2414
2444
|
token_endpoint: t.tokenEndpoint
|
|
2415
2445
|
};
|
|
2416
2446
|
}
|
|
2417
|
-
function
|
|
2447
|
+
function er(e) {
|
|
2418
2448
|
if (!(!e?.authorization_server || !e.token_endpoint))
|
|
2419
2449
|
return {
|
|
2420
2450
|
authorizationServerUrl: ye(e.authorization_server),
|
|
2421
2451
|
tokenEndpoint: ye(e.token_endpoint)
|
|
2422
2452
|
};
|
|
2423
2453
|
}
|
|
2424
|
-
async function
|
|
2454
|
+
async function tr({
|
|
2425
2455
|
provider: e,
|
|
2426
2456
|
clientInformation: t,
|
|
2427
2457
|
tokens: r
|
|
2428
2458
|
}) {
|
|
2429
2459
|
var n;
|
|
2430
|
-
const o =
|
|
2460
|
+
const o = er(r);
|
|
2431
2461
|
if (o)
|
|
2432
2462
|
return o;
|
|
2433
2463
|
const s = await ((n = e.authorizationServerInformation) == null ? void 0 : n.call(e));
|
|
@@ -2438,9 +2468,9 @@ async function er({
|
|
|
2438
2468
|
tokenEndpoint: ye(
|
|
2439
2469
|
s.tokenEndpoint
|
|
2440
2470
|
)
|
|
2441
|
-
} :
|
|
2471
|
+
} : er(t);
|
|
2442
2472
|
}
|
|
2443
|
-
async function
|
|
2473
|
+
async function Ns({
|
|
2444
2474
|
provider: e,
|
|
2445
2475
|
clientInformation: t,
|
|
2446
2476
|
authorizationServerInformation: r
|
|
@@ -2448,13 +2478,13 @@ async function As({
|
|
|
2448
2478
|
return e.saveAuthorizationServerInformation ? (await e.saveAuthorizationServerInformation(
|
|
2449
2479
|
r
|
|
2450
2480
|
), !0) : e.saveClientInformation ? (await e.saveClientInformation(
|
|
2451
|
-
|
|
2481
|
+
Hr(
|
|
2452
2482
|
t,
|
|
2453
2483
|
r
|
|
2454
2484
|
)
|
|
2455
2485
|
), !0) : !1;
|
|
2456
2486
|
}
|
|
2457
|
-
function
|
|
2487
|
+
function zs(e, t) {
|
|
2458
2488
|
if (!t)
|
|
2459
2489
|
return;
|
|
2460
2490
|
const r = new URL(e).origin;
|
|
@@ -2463,7 +2493,7 @@ function js(e, t) {
|
|
|
2463
2493
|
message: `OAuth protected resource metadata URL ${t.href} must have the same origin as the MCP server URL ${r}`
|
|
2464
2494
|
});
|
|
2465
2495
|
}
|
|
2466
|
-
function
|
|
2496
|
+
function rr({
|
|
2467
2497
|
storedAuthorizationServerInformation: e,
|
|
2468
2498
|
currentAuthorizationServerInformation: t
|
|
2469
2499
|
}) {
|
|
@@ -2488,7 +2518,7 @@ function Je(e) {
|
|
|
2488
2518
|
return;
|
|
2489
2519
|
}
|
|
2490
2520
|
}
|
|
2491
|
-
function
|
|
2521
|
+
function Us(e, t = "", r = {}) {
|
|
2492
2522
|
return t.endsWith("/") && (t = t.slice(0, -1)), r.prependPathname ? `${t}/.well-known/${e}` : `/.well-known/${e}${t}`;
|
|
2493
2523
|
}
|
|
2494
2524
|
async function Rt(e, t, r = fetch) {
|
|
@@ -2500,33 +2530,33 @@ async function Rt(e, t, r = fetch) {
|
|
|
2500
2530
|
throw n;
|
|
2501
2531
|
}
|
|
2502
2532
|
}
|
|
2503
|
-
async function
|
|
2533
|
+
async function nr(e, t, r = fetch) {
|
|
2504
2534
|
return await Rt(e, {
|
|
2505
2535
|
"MCP-Protocol-Version": t
|
|
2506
2536
|
}, r);
|
|
2507
2537
|
}
|
|
2508
|
-
function
|
|
2538
|
+
function Ds(e, t) {
|
|
2509
2539
|
return !e || e.status >= 400 && e.status < 500 && t !== "/";
|
|
2510
2540
|
}
|
|
2511
|
-
async function
|
|
2541
|
+
async function Ls(e, t, r, n) {
|
|
2512
2542
|
var o, s;
|
|
2513
2543
|
const i = new URL(e), l = (o = n?.protocolVersion) != null ? o : we;
|
|
2514
2544
|
let u;
|
|
2515
2545
|
if (n?.metadataUrl)
|
|
2516
2546
|
u = new URL(n.metadataUrl);
|
|
2517
2547
|
else {
|
|
2518
|
-
const d =
|
|
2548
|
+
const d = Us(t, i.pathname);
|
|
2519
2549
|
u = new URL(d, (s = n?.metadataServerUrl) != null ? s : i), u.search = i.search;
|
|
2520
2550
|
}
|
|
2521
|
-
let c = await
|
|
2522
|
-
if (!n?.metadataUrl &&
|
|
2551
|
+
let c = await nr(u, l, r);
|
|
2552
|
+
if (!n?.metadataUrl && Ds(c, i.pathname)) {
|
|
2523
2553
|
const d = new URL(`/.well-known/${t}`, i);
|
|
2524
|
-
c = await
|
|
2554
|
+
c = await nr(d, l, r);
|
|
2525
2555
|
}
|
|
2526
2556
|
return c;
|
|
2527
2557
|
}
|
|
2528
|
-
async function
|
|
2529
|
-
const n = await
|
|
2558
|
+
async function qs(e, t, r = fetch) {
|
|
2559
|
+
const n = await Ls(
|
|
2530
2560
|
e,
|
|
2531
2561
|
"oauth-protected-resource",
|
|
2532
2562
|
r,
|
|
@@ -2543,9 +2573,9 @@ async function Ls(e, t, r = fetch) {
|
|
|
2543
2573
|
throw new Error(
|
|
2544
2574
|
`HTTP ${n.status} trying to load well-known OAuth protected resource metadata.`
|
|
2545
2575
|
);
|
|
2546
|
-
return
|
|
2576
|
+
return Ss.parse(await n.json());
|
|
2547
2577
|
}
|
|
2548
|
-
function
|
|
2578
|
+
function Hs(e) {
|
|
2549
2579
|
const t = typeof e == "string" ? new URL(e) : e, r = t.pathname !== "/", n = t.origin, o = [];
|
|
2550
2580
|
if (!r)
|
|
2551
2581
|
return o.push({
|
|
@@ -2581,18 +2611,18 @@ function Ds(e) {
|
|
|
2581
2611
|
expectedIssuer: i
|
|
2582
2612
|
}), o;
|
|
2583
2613
|
}
|
|
2584
|
-
function
|
|
2614
|
+
function or(e, t) {
|
|
2585
2615
|
if (e.issuer !== t)
|
|
2586
2616
|
throw new re({
|
|
2587
2617
|
message: `OAuth authorization server metadata issuer ${e.issuer} does not match expected issuer ${t}`
|
|
2588
2618
|
});
|
|
2589
2619
|
}
|
|
2590
|
-
async function
|
|
2620
|
+
async function Fs(e, {
|
|
2591
2621
|
fetchFn: t = fetch,
|
|
2592
2622
|
protocolVersion: r = we
|
|
2593
2623
|
} = {}) {
|
|
2594
2624
|
var n;
|
|
2595
|
-
const o = { "MCP-Protocol-Version": r }, s =
|
|
2625
|
+
const o = { "MCP-Protocol-Version": r }, s = Hs(e);
|
|
2596
2626
|
for (const { url: i, type: l, expectedIssuer: u } of s) {
|
|
2597
2627
|
const c = await Rt(i, o, t);
|
|
2598
2628
|
if (c) {
|
|
@@ -2604,13 +2634,13 @@ async function qs(e, {
|
|
|
2604
2634
|
);
|
|
2605
2635
|
}
|
|
2606
2636
|
if (l === "oauth") {
|
|
2607
|
-
const d =
|
|
2608
|
-
return
|
|
2637
|
+
const d = Lr.parse(await c.json());
|
|
2638
|
+
return or(d, u), d;
|
|
2609
2639
|
} else {
|
|
2610
|
-
const d =
|
|
2640
|
+
const d = Cs.parse(
|
|
2611
2641
|
await c.json()
|
|
2612
2642
|
);
|
|
2613
|
-
if (
|
|
2643
|
+
if (or(d, u), !((n = d.code_challenge_methods_supported) != null && n.includes("S256")))
|
|
2614
2644
|
throw new Error(
|
|
2615
2645
|
`Incompatible OIDC provider at ${i}: does not support S256 code challenge method required by MCP specification`
|
|
2616
2646
|
);
|
|
@@ -2619,7 +2649,7 @@ async function qs(e, {
|
|
|
2619
2649
|
}
|
|
2620
2650
|
}
|
|
2621
2651
|
}
|
|
2622
|
-
async function
|
|
2652
|
+
async function Zs(e, {
|
|
2623
2653
|
metadata: t,
|
|
2624
2654
|
clientInformation: r,
|
|
2625
2655
|
redirectUrl: n,
|
|
@@ -2640,36 +2670,36 @@ async function Hs(e, {
|
|
|
2640
2670
|
);
|
|
2641
2671
|
} else
|
|
2642
2672
|
c = new URL("/authorize", e);
|
|
2643
|
-
const d = await
|
|
2673
|
+
const d = await Vo(), p = d.code_verifier, f = d.code_challenge;
|
|
2644
2674
|
return c.searchParams.set("response_type", l), c.searchParams.set("client_id", r.client_id), c.searchParams.set("code_challenge", f), c.searchParams.set(
|
|
2645
2675
|
"code_challenge_method",
|
|
2646
2676
|
u
|
|
2647
2677
|
), c.searchParams.set("redirect_uri", String(n)), s && c.searchParams.set("state", s), o && c.searchParams.set("scope", o), o?.includes("offline_access") && c.searchParams.append("prompt", "consent"), i && c.searchParams.set(
|
|
2648
2678
|
"resource",
|
|
2649
|
-
|
|
2679
|
+
Pt(i)
|
|
2650
2680
|
), { authorizationUrl: c, codeVerifier: p };
|
|
2651
2681
|
}
|
|
2652
|
-
function
|
|
2682
|
+
function Fr(e, t) {
|
|
2653
2683
|
const r = e.client_secret !== void 0;
|
|
2654
2684
|
return t.length === 0 ? r ? "client_secret_post" : "none" : r && t.includes("client_secret_basic") ? "client_secret_basic" : r && t.includes("client_secret_post") ? "client_secret_post" : t.includes("none") ? "none" : r ? "client_secret_post" : "none";
|
|
2655
2685
|
}
|
|
2656
|
-
function
|
|
2686
|
+
function Zr(e, t, r, n) {
|
|
2657
2687
|
const { client_id: o, client_secret: s } = t;
|
|
2658
2688
|
switch (e) {
|
|
2659
2689
|
case "client_secret_basic":
|
|
2660
|
-
|
|
2690
|
+
Vs(o, s, r);
|
|
2661
2691
|
return;
|
|
2662
2692
|
case "client_secret_post":
|
|
2663
|
-
|
|
2693
|
+
Js(o, s, n);
|
|
2664
2694
|
return;
|
|
2665
2695
|
case "none":
|
|
2666
|
-
|
|
2696
|
+
Ws(o, n);
|
|
2667
2697
|
return;
|
|
2668
2698
|
default:
|
|
2669
2699
|
throw new Error(`Unsupported client authentication method: ${e}`);
|
|
2670
2700
|
}
|
|
2671
2701
|
}
|
|
2672
|
-
function
|
|
2702
|
+
function Vs(e, t, r) {
|
|
2673
2703
|
if (!t)
|
|
2674
2704
|
throw new Error(
|
|
2675
2705
|
"client_secret_basic authentication requires a client_secret"
|
|
@@ -2677,18 +2707,18 @@ function Fs(e, t, r) {
|
|
|
2677
2707
|
const n = btoa(`${e}:${t}`);
|
|
2678
2708
|
r.set("Authorization", `Basic ${n}`);
|
|
2679
2709
|
}
|
|
2680
|
-
function
|
|
2710
|
+
function Js(e, t, r) {
|
|
2681
2711
|
r.set("client_id", e), t && r.set("client_secret", t);
|
|
2682
2712
|
}
|
|
2683
|
-
function
|
|
2713
|
+
function Ws(e, t) {
|
|
2684
2714
|
t.set("client_id", e);
|
|
2685
2715
|
}
|
|
2686
2716
|
async function kt(e) {
|
|
2687
2717
|
const t = e instanceof Response ? e.status : void 0, r = e instanceof Response ? await e.text() : e;
|
|
2688
2718
|
try {
|
|
2689
|
-
const n =
|
|
2690
|
-
await
|
|
2691
|
-
), { error: o, error_description: s, error_uri: i } = n, l =
|
|
2719
|
+
const n = Ps.parse(
|
|
2720
|
+
await $r({ text: r })
|
|
2721
|
+
), { error: o, error_description: s, error_uri: i } = n, l = As[o] || ge;
|
|
2692
2722
|
return new l({
|
|
2693
2723
|
message: s || "",
|
|
2694
2724
|
cause: i
|
|
@@ -2698,7 +2728,7 @@ async function kt(e) {
|
|
|
2698
2728
|
return new ge({ message: o });
|
|
2699
2729
|
}
|
|
2700
2730
|
}
|
|
2701
|
-
async function
|
|
2731
|
+
async function Bs(e, {
|
|
2702
2732
|
metadata: t,
|
|
2703
2733
|
clientInformation: r,
|
|
2704
2734
|
authorizationCode: n,
|
|
@@ -2731,23 +2761,23 @@ async function Js(e, {
|
|
|
2731
2761
|
t
|
|
2732
2762
|
);
|
|
2733
2763
|
else {
|
|
2734
|
-
const
|
|
2764
|
+
const S = (c = t?.token_endpoint_auth_methods_supported) != null ? c : [], x = Fr(
|
|
2735
2765
|
r,
|
|
2736
|
-
|
|
2766
|
+
S
|
|
2737
2767
|
);
|
|
2738
|
-
|
|
2768
|
+
Zr(x, r, f, v);
|
|
2739
2769
|
}
|
|
2740
|
-
i && v.set("resource",
|
|
2741
|
-
const
|
|
2770
|
+
i && v.set("resource", Pt(i));
|
|
2771
|
+
const m = await (u ?? fetch)(p, {
|
|
2742
2772
|
method: "POST",
|
|
2743
2773
|
headers: f,
|
|
2744
2774
|
body: v
|
|
2745
2775
|
});
|
|
2746
|
-
if (!
|
|
2747
|
-
throw await kt(
|
|
2748
|
-
return
|
|
2776
|
+
if (!m.ok)
|
|
2777
|
+
throw await kt(m);
|
|
2778
|
+
return Dr.parse(await m.json());
|
|
2749
2779
|
}
|
|
2750
|
-
async function
|
|
2780
|
+
async function Gs(e, {
|
|
2751
2781
|
metadata: t,
|
|
2752
2782
|
clientInformation: r,
|
|
2753
2783
|
refreshToken: n,
|
|
@@ -2780,13 +2810,13 @@ async function Ws(e, {
|
|
|
2780
2810
|
t
|
|
2781
2811
|
);
|
|
2782
2812
|
else {
|
|
2783
|
-
const v = (l = t?.token_endpoint_auth_methods_supported) != null ? l : [],
|
|
2813
|
+
const v = (l = t?.token_endpoint_auth_methods_supported) != null ? l : [], m = Fr(
|
|
2784
2814
|
r,
|
|
2785
2815
|
v
|
|
2786
2816
|
);
|
|
2787
|
-
|
|
2817
|
+
Zr(m, r, d, p);
|
|
2788
2818
|
}
|
|
2789
|
-
o && p.set("resource",
|
|
2819
|
+
o && p.set("resource", Pt(o));
|
|
2790
2820
|
const f = await (i ?? fetch)(c, {
|
|
2791
2821
|
method: "POST",
|
|
2792
2822
|
headers: d,
|
|
@@ -2794,12 +2824,12 @@ async function Ws(e, {
|
|
|
2794
2824
|
});
|
|
2795
2825
|
if (!f.ok)
|
|
2796
2826
|
throw await kt(f);
|
|
2797
|
-
return
|
|
2827
|
+
return Dr.parse({
|
|
2798
2828
|
refresh_token: n,
|
|
2799
2829
|
...await f.json()
|
|
2800
2830
|
});
|
|
2801
2831
|
}
|
|
2802
|
-
async function
|
|
2832
|
+
async function Ks(e, {
|
|
2803
2833
|
metadata: t,
|
|
2804
2834
|
clientMetadata: r,
|
|
2805
2835
|
fetchFn: n
|
|
@@ -2822,7 +2852,7 @@ async function Bs(e, {
|
|
|
2822
2852
|
});
|
|
2823
2853
|
if (!s.ok)
|
|
2824
2854
|
throw await kt(s);
|
|
2825
|
-
return
|
|
2855
|
+
return Rs.parse(await s.json());
|
|
2826
2856
|
}
|
|
2827
2857
|
async function yt(e, t) {
|
|
2828
2858
|
var r, n;
|
|
@@ -2836,7 +2866,7 @@ async function yt(e, t) {
|
|
|
2836
2866
|
throw o;
|
|
2837
2867
|
}
|
|
2838
2868
|
}
|
|
2839
|
-
async function
|
|
2869
|
+
async function Ys(e, t, r) {
|
|
2840
2870
|
const n = Is(e);
|
|
2841
2871
|
if (t.validateResourceURL)
|
|
2842
2872
|
return await t.validateResourceURL(
|
|
@@ -2844,7 +2874,7 @@ async function Gs(e, t, r) {
|
|
|
2844
2874
|
r?.resource
|
|
2845
2875
|
);
|
|
2846
2876
|
if (r) {
|
|
2847
|
-
if (!
|
|
2877
|
+
if (!Ms({
|
|
2848
2878
|
requestedResource: n,
|
|
2849
2879
|
configuredResource: r.resource
|
|
2850
2880
|
}))
|
|
@@ -2864,9 +2894,9 @@ async function ut(e, {
|
|
|
2864
2894
|
}) {
|
|
2865
2895
|
var l, u;
|
|
2866
2896
|
let c, d;
|
|
2867
|
-
|
|
2897
|
+
zs(t, s);
|
|
2868
2898
|
try {
|
|
2869
|
-
c = await
|
|
2899
|
+
c = await qs(
|
|
2870
2900
|
t,
|
|
2871
2901
|
{ resourceMetadataUrl: s },
|
|
2872
2902
|
i
|
|
@@ -2874,7 +2904,7 @@ async function ut(e, {
|
|
|
2874
2904
|
} catch {
|
|
2875
2905
|
}
|
|
2876
2906
|
d || (d = t);
|
|
2877
|
-
const p = await
|
|
2907
|
+
const p = await Ys(
|
|
2878
2908
|
t,
|
|
2879
2909
|
e,
|
|
2880
2910
|
c
|
|
@@ -2884,14 +2914,14 @@ async function ut(e, {
|
|
|
2884
2914
|
t,
|
|
2885
2915
|
d
|
|
2886
2916
|
));
|
|
2887
|
-
const f = await
|
|
2917
|
+
const f = await Fs(
|
|
2888
2918
|
d,
|
|
2889
2919
|
{
|
|
2890
2920
|
fetchFn: i
|
|
2891
2921
|
}
|
|
2892
|
-
), v =
|
|
2893
|
-
let
|
|
2894
|
-
if (!
|
|
2922
|
+
), v = js(d, f);
|
|
2923
|
+
let m = await Promise.resolve(e.clientInformation());
|
|
2924
|
+
if (!m) {
|
|
2895
2925
|
if (r !== void 0)
|
|
2896
2926
|
throw new Error(
|
|
2897
2927
|
"Existing OAuth client information is required when exchanging an authorization code"
|
|
@@ -2900,15 +2930,15 @@ async function ut(e, {
|
|
|
2900
2930
|
throw new Error(
|
|
2901
2931
|
"OAuth client information must be saveable for dynamic registration"
|
|
2902
2932
|
);
|
|
2903
|
-
const
|
|
2933
|
+
const j = await Ks(d, {
|
|
2904
2934
|
metadata: f,
|
|
2905
2935
|
clientMetadata: e.clientMetadata,
|
|
2906
2936
|
fetchFn: i
|
|
2907
2937
|
});
|
|
2908
|
-
|
|
2909
|
-
|
|
2938
|
+
m = Hr(
|
|
2939
|
+
j,
|
|
2910
2940
|
v
|
|
2911
|
-
), await e.saveClientInformation(
|
|
2941
|
+
), await e.saveClientInformation(m);
|
|
2912
2942
|
}
|
|
2913
2943
|
if (r !== void 0) {
|
|
2914
2944
|
if (e.storedState) {
|
|
@@ -2918,21 +2948,21 @@ async function ut(e, {
|
|
|
2918
2948
|
"OAuth state parameter mismatch - possible CSRF attack"
|
|
2919
2949
|
);
|
|
2920
2950
|
}
|
|
2921
|
-
const
|
|
2951
|
+
const j = await tr({
|
|
2922
2952
|
provider: e,
|
|
2923
|
-
clientInformation:
|
|
2953
|
+
clientInformation: m
|
|
2924
2954
|
});
|
|
2925
|
-
if (!
|
|
2955
|
+
if (!j)
|
|
2926
2956
|
throw new re({
|
|
2927
2957
|
message: "Stored OAuth authorization server metadata is required when exchanging an authorization code"
|
|
2928
2958
|
});
|
|
2929
|
-
|
|
2930
|
-
storedAuthorizationServerInformation:
|
|
2959
|
+
rr({
|
|
2960
|
+
storedAuthorizationServerInformation: j,
|
|
2931
2961
|
currentAuthorizationServerInformation: v
|
|
2932
2962
|
});
|
|
2933
|
-
const h = await e.codeVerifier(),
|
|
2963
|
+
const h = await e.codeVerifier(), g = await Bs(d, {
|
|
2934
2964
|
metadata: f,
|
|
2935
|
-
clientInformation:
|
|
2965
|
+
clientInformation: m,
|
|
2936
2966
|
authorizationCode: r,
|
|
2937
2967
|
codeVerifier: h,
|
|
2938
2968
|
redirectUri: e.redirectUrl,
|
|
@@ -2941,35 +2971,35 @@ async function ut(e, {
|
|
|
2941
2971
|
fetchFn: i
|
|
2942
2972
|
});
|
|
2943
2973
|
return await e.saveTokens(
|
|
2944
|
-
|
|
2945
|
-
|
|
2974
|
+
Qt(
|
|
2975
|
+
g,
|
|
2946
2976
|
v
|
|
2947
2977
|
)
|
|
2948
2978
|
), "AUTHORIZED";
|
|
2949
2979
|
}
|
|
2950
|
-
const
|
|
2951
|
-
if (
|
|
2952
|
-
const
|
|
2980
|
+
const S = await e.tokens();
|
|
2981
|
+
if (S?.refresh_token) {
|
|
2982
|
+
const j = await tr({
|
|
2953
2983
|
provider: e,
|
|
2954
|
-
clientInformation:
|
|
2955
|
-
tokens:
|
|
2984
|
+
clientInformation: m,
|
|
2985
|
+
tokens: S
|
|
2956
2986
|
});
|
|
2957
|
-
|
|
2958
|
-
storedAuthorizationServerInformation:
|
|
2987
|
+
j ? rr({
|
|
2988
|
+
storedAuthorizationServerInformation: j,
|
|
2959
2989
|
currentAuthorizationServerInformation: v
|
|
2960
2990
|
}) : await ((u = e.invalidateCredentials) == null ? void 0 : u.call(e, "tokens"));
|
|
2961
2991
|
try {
|
|
2962
|
-
if (
|
|
2963
|
-
const h = await
|
|
2992
|
+
if (j) {
|
|
2993
|
+
const h = await Gs(d, {
|
|
2964
2994
|
metadata: f,
|
|
2965
|
-
clientInformation:
|
|
2966
|
-
refreshToken:
|
|
2995
|
+
clientInformation: m,
|
|
2996
|
+
refreshToken: S.refresh_token,
|
|
2967
2997
|
resource: p,
|
|
2968
2998
|
addClientAuthentication: e.addClientAuthentication,
|
|
2969
2999
|
fetchFn: i
|
|
2970
3000
|
});
|
|
2971
3001
|
return await e.saveTokens(
|
|
2972
|
-
|
|
3002
|
+
Qt(
|
|
2973
3003
|
h,
|
|
2974
3004
|
v
|
|
2975
3005
|
)
|
|
@@ -2984,20 +3014,20 @@ async function ut(e, {
|
|
|
2984
3014
|
}
|
|
2985
3015
|
const x = e.state ? await e.state() : void 0;
|
|
2986
3016
|
x && e.saveState && await e.saveState(x);
|
|
2987
|
-
const { authorizationUrl: R, codeVerifier: M } = await
|
|
3017
|
+
const { authorizationUrl: R, codeVerifier: M } = await Zs(
|
|
2988
3018
|
d,
|
|
2989
3019
|
{
|
|
2990
3020
|
metadata: f,
|
|
2991
|
-
clientInformation:
|
|
3021
|
+
clientInformation: m,
|
|
2992
3022
|
state: x,
|
|
2993
3023
|
redirectUrl: e.redirectUrl,
|
|
2994
3024
|
scope: o || e.clientMetadata.scope,
|
|
2995
3025
|
resource: p
|
|
2996
3026
|
}
|
|
2997
3027
|
);
|
|
2998
|
-
if (!await
|
|
3028
|
+
if (!await Ns({
|
|
2999
3029
|
provider: e,
|
|
3000
|
-
clientInformation:
|
|
3030
|
+
clientInformation: m,
|
|
3001
3031
|
authorizationServerInformation: v
|
|
3002
3032
|
}))
|
|
3003
3033
|
throw new re({
|
|
@@ -3005,10 +3035,10 @@ async function ut(e, {
|
|
|
3005
3035
|
});
|
|
3006
3036
|
return await e.saveCodeVerifier(M), await e.redirectToAuthorization(R), "REDIRECT";
|
|
3007
3037
|
}
|
|
3008
|
-
function
|
|
3038
|
+
function Xs(e) {
|
|
3009
3039
|
return e === void 0 || e === "message";
|
|
3010
3040
|
}
|
|
3011
|
-
var
|
|
3041
|
+
var Qs = class {
|
|
3012
3042
|
constructor({
|
|
3013
3043
|
url: e,
|
|
3014
3044
|
headers: t,
|
|
@@ -3032,10 +3062,10 @@ var Ys = class {
|
|
|
3032
3062
|
const n = await this.authProvider.tokens();
|
|
3033
3063
|
n?.access_token && (r.Authorization = `Bearer ${n.access_token}`);
|
|
3034
3064
|
}
|
|
3035
|
-
return
|
|
3065
|
+
return wr(
|
|
3036
3066
|
r,
|
|
3037
|
-
`ai-sdk/${
|
|
3038
|
-
|
|
3067
|
+
`ai-sdk/${Ur}`,
|
|
3068
|
+
vr()
|
|
3039
3069
|
);
|
|
3040
3070
|
}
|
|
3041
3071
|
async start() {
|
|
@@ -3061,60 +3091,60 @@ var Ys = class {
|
|
|
3061
3091
|
resourceMetadataUrl: this.resourceMetadataUrl,
|
|
3062
3092
|
fetchFn: this.fetchFn
|
|
3063
3093
|
}) !== "AUTHORIZED") {
|
|
3064
|
-
const
|
|
3065
|
-
return (s = this.onerror) == null || s.call(this,
|
|
3094
|
+
const S = new Ve();
|
|
3095
|
+
return (s = this.onerror) == null || s.call(this, S), t(S);
|
|
3066
3096
|
}
|
|
3067
|
-
} catch (
|
|
3068
|
-
return (i = this.onerror) == null || i.call(this,
|
|
3097
|
+
} catch (m) {
|
|
3098
|
+
return (i = this.onerror) == null || i.call(this, m), t(m);
|
|
3069
3099
|
}
|
|
3070
3100
|
return r(!0);
|
|
3071
3101
|
}
|
|
3072
3102
|
if (!d.ok || !d.body) {
|
|
3073
|
-
let
|
|
3074
|
-
d.status === 405 && (
|
|
3075
|
-
const
|
|
3076
|
-
message:
|
|
3103
|
+
let m = `MCP SSE Transport Error: ${d.status} ${d.statusText}`;
|
|
3104
|
+
d.status === 405 && (m += ". This server does not support SSE transport. Try using `http` transport instead");
|
|
3105
|
+
const S = new A({
|
|
3106
|
+
message: m
|
|
3077
3107
|
});
|
|
3078
|
-
return (l = this.onerror) == null || l.call(this,
|
|
3108
|
+
return (l = this.onerror) == null || l.call(this, S), t(S);
|
|
3079
3109
|
}
|
|
3080
3110
|
const f = d.body.pipeThrough(new TextDecoderStream()).pipeThrough(new ft()).getReader(), v = async () => {
|
|
3081
|
-
var
|
|
3111
|
+
var m, S, x, R, M;
|
|
3082
3112
|
try {
|
|
3083
3113
|
for (; ; ) {
|
|
3084
|
-
const { done:
|
|
3085
|
-
if (
|
|
3114
|
+
const { done: O, value: j } = await f.read();
|
|
3115
|
+
if (O) {
|
|
3086
3116
|
if (this.connected)
|
|
3087
3117
|
throw this.connected = !1, new A({
|
|
3088
3118
|
message: "MCP SSE Transport Error: Connection closed unexpectedly"
|
|
3089
3119
|
});
|
|
3090
3120
|
return;
|
|
3091
3121
|
}
|
|
3092
|
-
const { event: h, data:
|
|
3122
|
+
const { event: h, data: g } = j;
|
|
3093
3123
|
if (h === "endpoint") {
|
|
3094
3124
|
if (this.endpoint)
|
|
3095
3125
|
continue;
|
|
3096
|
-
const _ = new URL(
|
|
3126
|
+
const _ = new URL(g, this.url);
|
|
3097
3127
|
if (_.origin !== this.url.origin)
|
|
3098
|
-
throw this.connected = !1, this.endpoint = void 0, (
|
|
3128
|
+
throw this.connected = !1, this.endpoint = void 0, (m = this.sseConnection) == null || m.close(), (S = this.abortController) == null || S.abort(), new A({
|
|
3099
3129
|
message: `MCP SSE Transport Error: Endpoint origin does not match connection origin: ${_.origin}`
|
|
3100
3130
|
});
|
|
3101
3131
|
this.endpoint = _, this.connected = !0, e();
|
|
3102
|
-
} else if (
|
|
3132
|
+
} else if (Xs(h))
|
|
3103
3133
|
try {
|
|
3104
|
-
const _ = await gt(
|
|
3134
|
+
const _ = await gt(g);
|
|
3105
3135
|
(x = this.onmessage) == null || x.call(this, _);
|
|
3106
3136
|
} catch (_) {
|
|
3107
|
-
const
|
|
3137
|
+
const N = new A({
|
|
3108
3138
|
message: "MCP SSE Transport Error: Failed to parse message",
|
|
3109
3139
|
cause: _
|
|
3110
3140
|
});
|
|
3111
|
-
(R = this.onerror) == null || R.call(this,
|
|
3141
|
+
(R = this.onerror) == null || R.call(this, N);
|
|
3112
3142
|
}
|
|
3113
3143
|
}
|
|
3114
|
-
} catch (
|
|
3115
|
-
if (
|
|
3144
|
+
} catch (O) {
|
|
3145
|
+
if (O instanceof Error && O.name === "AbortError")
|
|
3116
3146
|
return;
|
|
3117
|
-
(M = this.onerror) == null || M.call(this,
|
|
3147
|
+
(M = this.onerror) == null || M.call(this, O), t(O);
|
|
3118
3148
|
}
|
|
3119
3149
|
};
|
|
3120
3150
|
this.sseConnection = {
|
|
@@ -3183,10 +3213,10 @@ var Ys = class {
|
|
|
3183
3213
|
await r();
|
|
3184
3214
|
}
|
|
3185
3215
|
};
|
|
3186
|
-
function
|
|
3216
|
+
function sr(e) {
|
|
3187
3217
|
return e === void 0 || e === "message";
|
|
3188
3218
|
}
|
|
3189
|
-
var
|
|
3219
|
+
var ei = class {
|
|
3190
3220
|
constructor({
|
|
3191
3221
|
url: e,
|
|
3192
3222
|
headers: t,
|
|
@@ -3215,10 +3245,10 @@ var Xs = class {
|
|
|
3215
3245
|
const n = await this.authProvider.tokens();
|
|
3216
3246
|
n?.access_token && (r.Authorization = `Bearer ${n.access_token}`);
|
|
3217
3247
|
}
|
|
3218
|
-
return
|
|
3248
|
+
return wr(
|
|
3219
3249
|
r,
|
|
3220
|
-
`ai-sdk/${
|
|
3221
|
-
|
|
3250
|
+
`ai-sdk/${Ur}`,
|
|
3251
|
+
vr()
|
|
3222
3252
|
);
|
|
3223
3253
|
}
|
|
3224
3254
|
/**
|
|
@@ -3238,7 +3268,7 @@ var Xs = class {
|
|
|
3238
3268
|
throw new A({
|
|
3239
3269
|
message: "MCP HTTP Transport Error: Transport already started. Note: client.connect() calls start() automatically."
|
|
3240
3270
|
});
|
|
3241
|
-
this.abortController = new AbortController(), this.
|
|
3271
|
+
this.abortController = new AbortController(), this.startInboundSse();
|
|
3242
3272
|
}
|
|
3243
3273
|
async close() {
|
|
3244
3274
|
var e, t, r;
|
|
@@ -3283,50 +3313,51 @@ var Xs = class {
|
|
|
3283
3313
|
return t(!0);
|
|
3284
3314
|
}
|
|
3285
3315
|
if (f.status === 202) {
|
|
3286
|
-
this.inboundSseConnection || this.
|
|
3316
|
+
this.inboundSseConnection || this.startInboundSse();
|
|
3287
3317
|
return;
|
|
3288
3318
|
}
|
|
3289
3319
|
if (!f.ok) {
|
|
3290
3320
|
const R = await f.text().catch(() => null);
|
|
3291
3321
|
let M = `MCP HTTP Transport Error: POSTing to endpoint (HTTP ${f.status}): ${R}`;
|
|
3292
3322
|
f.status === 404 && (M += ". This server does not support HTTP transport. Try using `sse` transport instead");
|
|
3293
|
-
const
|
|
3323
|
+
const O = new A({
|
|
3294
3324
|
message: M,
|
|
3295
3325
|
statusCode: f.status,
|
|
3296
3326
|
url: this.url.href,
|
|
3297
3327
|
responseBody: R ?? void 0
|
|
3298
3328
|
});
|
|
3299
|
-
throw (s = this.onerror) == null || s.call(this,
|
|
3329
|
+
throw (s = this.onerror) == null || s.call(this, O), O;
|
|
3300
3330
|
}
|
|
3301
3331
|
if (!("id" in e))
|
|
3302
3332
|
return;
|
|
3303
|
-
const
|
|
3304
|
-
if (
|
|
3305
|
-
const R = await f.json(), M = Array.isArray(R) ? R.map((
|
|
3306
|
-
for (const
|
|
3333
|
+
const S = f.headers.get("content-type") || "";
|
|
3334
|
+
if (S.includes("application/json")) {
|
|
3335
|
+
const R = await f.json(), M = Array.isArray(R) ? R.map((O) => mt(O)) : [mt(R)];
|
|
3336
|
+
for (const O of M)
|
|
3337
|
+
(i = this.onmessage) == null || i.call(this, O);
|
|
3307
3338
|
return;
|
|
3308
3339
|
}
|
|
3309
|
-
if (
|
|
3340
|
+
if (S.includes("text/event-stream")) {
|
|
3310
3341
|
if (!f.body) {
|
|
3311
|
-
const
|
|
3342
|
+
const j = new A({
|
|
3312
3343
|
message: "MCP HTTP Transport Error: text/event-stream response without body",
|
|
3313
3344
|
statusCode: f.status,
|
|
3314
3345
|
url: this.url.href
|
|
3315
3346
|
});
|
|
3316
|
-
throw (l = this.onerror) == null || l.call(this,
|
|
3347
|
+
throw (l = this.onerror) == null || l.call(this, j), j;
|
|
3317
3348
|
}
|
|
3318
3349
|
const M = f.body.pipeThrough(new TextDecoderStream()).pipeThrough(new ft()).getReader();
|
|
3319
3350
|
(async () => {
|
|
3320
|
-
var
|
|
3351
|
+
var j, h, g;
|
|
3321
3352
|
try {
|
|
3322
3353
|
for (; ; ) {
|
|
3323
|
-
const { done: _, value:
|
|
3354
|
+
const { done: _, value: N } = await M.read();
|
|
3324
3355
|
if (_) return;
|
|
3325
|
-
const { event:
|
|
3326
|
-
if (
|
|
3356
|
+
const { event: I, data: L } = N;
|
|
3357
|
+
if (sr(I))
|
|
3327
3358
|
try {
|
|
3328
|
-
const K = await gt(
|
|
3329
|
-
(
|
|
3359
|
+
const K = await gt(L);
|
|
3360
|
+
(j = this.onmessage) == null || j.call(this, K);
|
|
3330
3361
|
} catch (K) {
|
|
3331
3362
|
const Z = new A({
|
|
3332
3363
|
message: "MCP HTTP Transport Error: Failed to parse message",
|
|
@@ -3338,13 +3369,16 @@ var Xs = class {
|
|
|
3338
3369
|
} catch (_) {
|
|
3339
3370
|
if (_ instanceof Error && _.name === "AbortError")
|
|
3340
3371
|
return;
|
|
3341
|
-
(
|
|
3372
|
+
(g = this.onerror) == null || g.call(this, _);
|
|
3342
3373
|
}
|
|
3343
|
-
})()
|
|
3374
|
+
})().catch((j) => {
|
|
3375
|
+
var h;
|
|
3376
|
+
j instanceof Error && j.name === "AbortError" || (h = this.onerror) == null || h.call(this, j);
|
|
3377
|
+
});
|
|
3344
3378
|
return;
|
|
3345
3379
|
}
|
|
3346
3380
|
const x = new A({
|
|
3347
|
-
message: `MCP HTTP Transport Error: Unexpected content type: ${
|
|
3381
|
+
message: `MCP HTTP Transport Error: Unexpected content type: ${S}`,
|
|
3348
3382
|
statusCode: f.status,
|
|
3349
3383
|
url: this.url.href
|
|
3350
3384
|
});
|
|
@@ -3379,11 +3413,17 @@ var Xs = class {
|
|
|
3379
3413
|
return;
|
|
3380
3414
|
}
|
|
3381
3415
|
const r = this.getNextReconnectionDelay(this.inboundReconnectAttempts);
|
|
3382
|
-
this.inboundReconnectAttempts += 1, setTimeout(
|
|
3416
|
+
this.inboundReconnectAttempts += 1, setTimeout(() => {
|
|
3383
3417
|
var n;
|
|
3384
|
-
(n = this.abortController) != null && n.signal.aborted ||
|
|
3418
|
+
(n = this.abortController) != null && n.signal.aborted || this.startInboundSse(!1, this.lastInboundEventId);
|
|
3385
3419
|
}, r);
|
|
3386
3420
|
}
|
|
3421
|
+
startInboundSse(e = !1, t) {
|
|
3422
|
+
this.openInboundSse(e, t).catch((r) => {
|
|
3423
|
+
var n;
|
|
3424
|
+
r instanceof Error && r.name === "AbortError" || (n = this.onerror) == null || n.call(this, r);
|
|
3425
|
+
});
|
|
3426
|
+
}
|
|
3387
3427
|
// Open optional inbound SSE stream; best-effort and resumable
|
|
3388
3428
|
async openInboundSse(e = !1, t) {
|
|
3389
3429
|
var r, n, o, s, i, l;
|
|
@@ -3402,12 +3442,12 @@ var Xs = class {
|
|
|
3402
3442
|
this.resourceMetadataUrl = Je(c);
|
|
3403
3443
|
try {
|
|
3404
3444
|
if (await this.authorizeOnce(this.resourceMetadataUrl) !== "AUTHORIZED") {
|
|
3405
|
-
const
|
|
3406
|
-
(n = this.onerror) == null || n.call(this,
|
|
3445
|
+
const S = new Ve();
|
|
3446
|
+
(n = this.onerror) == null || n.call(this, S);
|
|
3407
3447
|
return;
|
|
3408
3448
|
}
|
|
3409
|
-
} catch (
|
|
3410
|
-
(o = this.onerror) == null || o.call(this,
|
|
3449
|
+
} catch (m) {
|
|
3450
|
+
(o = this.onerror) == null || o.call(this, m);
|
|
3411
3451
|
return;
|
|
3412
3452
|
}
|
|
3413
3453
|
return this.openInboundSse(!0, t);
|
|
@@ -3415,31 +3455,31 @@ var Xs = class {
|
|
|
3415
3455
|
if (c.status === 405)
|
|
3416
3456
|
return;
|
|
3417
3457
|
if (!c.ok || !c.body) {
|
|
3418
|
-
const
|
|
3458
|
+
const m = new A({
|
|
3419
3459
|
message: `MCP HTTP Transport Error: GET SSE failed: ${c.status} ${c.statusText}`,
|
|
3420
3460
|
statusCode: c.status,
|
|
3421
3461
|
url: this.url.href
|
|
3422
3462
|
});
|
|
3423
|
-
(s = this.onerror) == null || s.call(this,
|
|
3463
|
+
(s = this.onerror) == null || s.call(this, m);
|
|
3424
3464
|
return;
|
|
3425
3465
|
}
|
|
3426
3466
|
const f = c.body.pipeThrough(new TextDecoderStream()).pipeThrough(new ft()).getReader(), v = async () => {
|
|
3427
|
-
var
|
|
3467
|
+
var m, S, x, R;
|
|
3428
3468
|
try {
|
|
3429
3469
|
for (; ; ) {
|
|
3430
|
-
const { done: M, value:
|
|
3470
|
+
const { done: M, value: O } = await f.read();
|
|
3431
3471
|
if (M) return;
|
|
3432
|
-
const { event:
|
|
3433
|
-
if (
|
|
3472
|
+
const { event: j, data: h, id: g } = O;
|
|
3473
|
+
if (g && (this.lastInboundEventId = g), sr(j))
|
|
3434
3474
|
try {
|
|
3435
3475
|
const _ = await gt(h);
|
|
3436
|
-
(
|
|
3476
|
+
(m = this.onmessage) == null || m.call(this, _);
|
|
3437
3477
|
} catch (_) {
|
|
3438
|
-
const
|
|
3478
|
+
const N = new A({
|
|
3439
3479
|
message: "MCP HTTP Transport Error: Failed to parse message",
|
|
3440
3480
|
cause: _
|
|
3441
3481
|
});
|
|
3442
|
-
(
|
|
3482
|
+
(S = this.onerror) == null || S.call(this, N);
|
|
3443
3483
|
}
|
|
3444
3484
|
}
|
|
3445
3485
|
} catch (M) {
|
|
@@ -3449,8 +3489,16 @@ var Xs = class {
|
|
|
3449
3489
|
}
|
|
3450
3490
|
};
|
|
3451
3491
|
this.inboundSseConnection = {
|
|
3452
|
-
close: () =>
|
|
3453
|
-
|
|
3492
|
+
close: () => {
|
|
3493
|
+
f.cancel().catch((m) => {
|
|
3494
|
+
var S;
|
|
3495
|
+
m instanceof Error && m.name === "AbortError" || (S = this.onerror) == null || S.call(this, m);
|
|
3496
|
+
});
|
|
3497
|
+
}
|
|
3498
|
+
}, this.inboundReconnectAttempts = 0, v().catch((m) => {
|
|
3499
|
+
var S, x;
|
|
3500
|
+
m instanceof Error && m.name === "AbortError" || ((S = this.onerror) == null || S.call(this, m), (x = this.abortController) != null && x.signal.aborted || this.scheduleInboundSseReconnection());
|
|
3501
|
+
});
|
|
3454
3502
|
} catch (u) {
|
|
3455
3503
|
if (u instanceof Error && u.name === "AbortError")
|
|
3456
3504
|
return;
|
|
@@ -3458,23 +3506,61 @@ var Xs = class {
|
|
|
3458
3506
|
}
|
|
3459
3507
|
}
|
|
3460
3508
|
};
|
|
3461
|
-
function
|
|
3509
|
+
function ti(e) {
|
|
3462
3510
|
switch (e.type) {
|
|
3463
3511
|
case "sse":
|
|
3464
|
-
return new
|
|
3512
|
+
return new Qs(e);
|
|
3465
3513
|
case "http":
|
|
3466
|
-
return new
|
|
3514
|
+
return new ei(e);
|
|
3467
3515
|
default:
|
|
3468
3516
|
throw new A({
|
|
3469
3517
|
message: "Unsupported or invalid transport configuration. If you are using a custom transport, make sure it implements the MCPTransport interface."
|
|
3470
3518
|
});
|
|
3471
3519
|
}
|
|
3472
3520
|
}
|
|
3473
|
-
function
|
|
3521
|
+
function ri(e) {
|
|
3474
3522
|
return "start" in e && typeof e.start == "function" && "send" in e && typeof e.send == "function" && "close" in e && typeof e.close == "function";
|
|
3475
3523
|
}
|
|
3476
|
-
var
|
|
3477
|
-
|
|
3524
|
+
var ni = "1.0.0", oi = 0, si = [
|
|
3525
|
+
"ConnectionRefused",
|
|
3526
|
+
"ConnectionClosed",
|
|
3527
|
+
"FailedToOpenSocket",
|
|
3528
|
+
"ECONNRESET",
|
|
3529
|
+
"ECONNREFUSED",
|
|
3530
|
+
"ETIMEDOUT",
|
|
3531
|
+
"EPIPE"
|
|
3532
|
+
];
|
|
3533
|
+
function ii(e) {
|
|
3534
|
+
if (e != null && typeof e == "object" && "statusCode" in e && typeof e.statusCode == "number")
|
|
3535
|
+
return e.statusCode;
|
|
3536
|
+
}
|
|
3537
|
+
function ai(e) {
|
|
3538
|
+
if (e != null && typeof e == "object" && "code" in e && typeof e.code == "string")
|
|
3539
|
+
return e.code;
|
|
3540
|
+
}
|
|
3541
|
+
function li(e) {
|
|
3542
|
+
const t = ii(e);
|
|
3543
|
+
if (t != null)
|
|
3544
|
+
return t === 408 || t === 409 || t === 429 || t >= 500;
|
|
3545
|
+
if (A.isInstance(e) && e.code != null)
|
|
3546
|
+
return !1;
|
|
3547
|
+
const r = ai(e);
|
|
3548
|
+
return r != null && si.includes(r);
|
|
3549
|
+
}
|
|
3550
|
+
function ci(e) {
|
|
3551
|
+
if (e == null)
|
|
3552
|
+
return oi;
|
|
3553
|
+
if (!Number.isInteger(e))
|
|
3554
|
+
throw new A({
|
|
3555
|
+
message: "maxRetries must be an integer"
|
|
3556
|
+
});
|
|
3557
|
+
if (e < 0)
|
|
3558
|
+
throw new A({
|
|
3559
|
+
message: "maxRetries must be >= 0"
|
|
3560
|
+
});
|
|
3561
|
+
return e;
|
|
3562
|
+
}
|
|
3563
|
+
function ir({
|
|
3478
3564
|
output: e
|
|
3479
3565
|
}) {
|
|
3480
3566
|
const t = e;
|
|
@@ -3486,29 +3572,30 @@ function sr({
|
|
|
3486
3572
|
} : { type: "text", text: JSON.stringify(n) }
|
|
3487
3573
|
) };
|
|
3488
3574
|
}
|
|
3489
|
-
async function
|
|
3490
|
-
const t = new
|
|
3575
|
+
async function ui(e) {
|
|
3576
|
+
const t = new di(e);
|
|
3491
3577
|
return await t.init(), t;
|
|
3492
3578
|
}
|
|
3493
|
-
var
|
|
3579
|
+
var di = class {
|
|
3494
3580
|
constructor({
|
|
3495
3581
|
transport: e,
|
|
3496
3582
|
name: t,
|
|
3497
3583
|
clientName: r = t ?? "ai-sdk-mcp-client",
|
|
3498
|
-
version: n =
|
|
3584
|
+
version: n = ni,
|
|
3499
3585
|
onUncaughtError: o,
|
|
3500
|
-
|
|
3586
|
+
maxRetries: s,
|
|
3587
|
+
capabilities: i
|
|
3501
3588
|
}) {
|
|
3502
|
-
this.requestMessageId = 0, this.responseHandlers = /* @__PURE__ */ new Map(), this.serverCapabilities = {}, this._serverInfo = { name: "", version: "" }, this.isClosed = !0, this.onUncaughtError = o, this.
|
|
3503
|
-
if ("method" in
|
|
3504
|
-
"id" in
|
|
3589
|
+
this.requestMessageId = 0, this.responseHandlers = /* @__PURE__ */ new Map(), this.serverCapabilities = {}, this._serverInfo = { name: "", version: "" }, this.isClosed = !0, this.onUncaughtError = o, this.maxRetries = ci(s), this.clientCapabilities = i ?? {}, ri(e) ? this.transport = e : this.transport = ti(e), this.transport.onclose = () => this.onClose(), this.transport.onerror = (l) => this.onError(l), this.transport.onmessage = (l) => {
|
|
3590
|
+
if ("method" in l) {
|
|
3591
|
+
"id" in l ? this.onRequestMessage(l) : this.onError(
|
|
3505
3592
|
new A({
|
|
3506
3593
|
message: "Unsupported message type"
|
|
3507
3594
|
})
|
|
3508
3595
|
);
|
|
3509
3596
|
return;
|
|
3510
3597
|
}
|
|
3511
|
-
this.onResponse(
|
|
3598
|
+
this.onResponse(l);
|
|
3512
3599
|
}, this.clientInfo = {
|
|
3513
3600
|
name: r,
|
|
3514
3601
|
version: n
|
|
@@ -3532,13 +3619,13 @@ var ni = class {
|
|
|
3532
3619
|
clientInfo: this.clientInfo
|
|
3533
3620
|
}
|
|
3534
3621
|
},
|
|
3535
|
-
resultSchema:
|
|
3622
|
+
resultSchema: Ko
|
|
3536
3623
|
});
|
|
3537
3624
|
if (e === void 0)
|
|
3538
3625
|
throw new A({
|
|
3539
3626
|
message: "Server sent invalid initialize result"
|
|
3540
3627
|
});
|
|
3541
|
-
if (!
|
|
3628
|
+
if (!Jo.includes(e.protocolVersion))
|
|
3542
3629
|
throw new A({
|
|
3543
3630
|
message: `Server's protocol version is not supported: ${e.protocolVersion}`
|
|
3544
3631
|
});
|
|
@@ -3611,30 +3698,36 @@ var ni = class {
|
|
|
3611
3698
|
jsonrpc: "2.0",
|
|
3612
3699
|
id: i
|
|
3613
3700
|
}, u = () => {
|
|
3614
|
-
|
|
3701
|
+
o(
|
|
3702
|
+
new A({
|
|
3703
|
+
message: "Request was aborted",
|
|
3704
|
+
cause: s?.reason
|
|
3705
|
+
})
|
|
3706
|
+
);
|
|
3707
|
+
}, c = () => {
|
|
3708
|
+
this.responseHandlers.delete(i), s?.removeEventListener("abort", p);
|
|
3709
|
+
}, d = (f) => {
|
|
3710
|
+
c(), o(f);
|
|
3711
|
+
}, p = () => {
|
|
3712
|
+
c(), u();
|
|
3615
3713
|
};
|
|
3616
|
-
this.responseHandlers.set(i, (
|
|
3714
|
+
this.responseHandlers.set(i, (f) => {
|
|
3617
3715
|
if (s?.aborted)
|
|
3618
|
-
return
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
cause: s.reason
|
|
3622
|
-
})
|
|
3623
|
-
);
|
|
3624
|
-
if (c instanceof Error)
|
|
3625
|
-
return o(c);
|
|
3716
|
+
return c(), u();
|
|
3717
|
+
if (f instanceof Error)
|
|
3718
|
+
return d(f);
|
|
3626
3719
|
try {
|
|
3627
|
-
const
|
|
3628
|
-
n(
|
|
3629
|
-
} catch (
|
|
3630
|
-
const
|
|
3720
|
+
const v = t.parse(f.result);
|
|
3721
|
+
c(), n(v);
|
|
3722
|
+
} catch (v) {
|
|
3723
|
+
const m = new A({
|
|
3631
3724
|
message: "Failed to parse server response",
|
|
3632
|
-
cause:
|
|
3725
|
+
cause: v
|
|
3633
3726
|
});
|
|
3634
|
-
|
|
3727
|
+
d(m);
|
|
3635
3728
|
}
|
|
3636
|
-
}), this.transport.send(l).catch((
|
|
3637
|
-
|
|
3729
|
+
}), s?.addEventListener("abort", p, { once: !0 }), this.transport.send(l).catch((f) => {
|
|
3730
|
+
d(f);
|
|
3638
3731
|
});
|
|
3639
3732
|
});
|
|
3640
3733
|
}
|
|
@@ -3644,22 +3737,42 @@ var ni = class {
|
|
|
3644
3737
|
} = {}) {
|
|
3645
3738
|
return this.request({
|
|
3646
3739
|
request: { method: "tools/list", params: e },
|
|
3647
|
-
resultSchema:
|
|
3740
|
+
resultSchema: Xo,
|
|
3648
3741
|
options: t
|
|
3649
3742
|
});
|
|
3650
3743
|
}
|
|
3744
|
+
async callToolWithRetry({
|
|
3745
|
+
options: e,
|
|
3746
|
+
execute: t
|
|
3747
|
+
}) {
|
|
3748
|
+
return this.maxRetries === 0 ? t() : Lo({
|
|
3749
|
+
maxRetries: this.maxRetries,
|
|
3750
|
+
abortSignal: e?.abortSignal,
|
|
3751
|
+
shouldRetry: li,
|
|
3752
|
+
createRetryError: ({ message: r, errors: n }) => new A({
|
|
3753
|
+
message: r,
|
|
3754
|
+
cause: n[n.length - 1]
|
|
3755
|
+
})
|
|
3756
|
+
})(t);
|
|
3757
|
+
}
|
|
3651
3758
|
async callTool({
|
|
3652
3759
|
name: e,
|
|
3653
3760
|
args: t,
|
|
3654
3761
|
options: r
|
|
3655
3762
|
}) {
|
|
3656
3763
|
try {
|
|
3657
|
-
return this.
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3764
|
+
return this.callToolWithRetry({
|
|
3765
|
+
options: r,
|
|
3766
|
+
execute: () => this.request({
|
|
3767
|
+
request: {
|
|
3768
|
+
method: "tools/call",
|
|
3769
|
+
params: { name: e, arguments: t }
|
|
3770
|
+
},
|
|
3771
|
+
resultSchema: ts,
|
|
3772
|
+
options: {
|
|
3773
|
+
signal: r?.abortSignal
|
|
3774
|
+
}
|
|
3775
|
+
})
|
|
3663
3776
|
});
|
|
3664
3777
|
} catch (n) {
|
|
3665
3778
|
throw n;
|
|
@@ -3672,7 +3785,7 @@ var ni = class {
|
|
|
3672
3785
|
try {
|
|
3673
3786
|
return this.request({
|
|
3674
3787
|
request: { method: "resources/list", params: e },
|
|
3675
|
-
resultSchema:
|
|
3788
|
+
resultSchema: es,
|
|
3676
3789
|
options: t
|
|
3677
3790
|
});
|
|
3678
3791
|
} catch (r) {
|
|
@@ -3686,7 +3799,7 @@ var ni = class {
|
|
|
3686
3799
|
try {
|
|
3687
3800
|
return this.request({
|
|
3688
3801
|
request: { method: "resources/read", params: { uri: e } },
|
|
3689
|
-
resultSchema:
|
|
3802
|
+
resultSchema: os,
|
|
3690
3803
|
options: t
|
|
3691
3804
|
});
|
|
3692
3805
|
} catch (r) {
|
|
@@ -3699,7 +3812,7 @@ var ni = class {
|
|
|
3699
3812
|
try {
|
|
3700
3813
|
return this.request({
|
|
3701
3814
|
request: { method: "resources/templates/list" },
|
|
3702
|
-
resultSchema:
|
|
3815
|
+
resultSchema: ns,
|
|
3703
3816
|
options: e
|
|
3704
3817
|
});
|
|
3705
3818
|
} catch (t) {
|
|
@@ -3713,7 +3826,7 @@ var ni = class {
|
|
|
3713
3826
|
try {
|
|
3714
3827
|
return this.request({
|
|
3715
3828
|
request: { method: "prompts/list", params: e },
|
|
3716
|
-
resultSchema:
|
|
3829
|
+
resultSchema: ds,
|
|
3717
3830
|
options: t
|
|
3718
3831
|
});
|
|
3719
3832
|
} catch (r) {
|
|
@@ -3728,7 +3841,7 @@ var ni = class {
|
|
|
3728
3841
|
try {
|
|
3729
3842
|
return this.request({
|
|
3730
3843
|
request: { method: "prompts/get", params: { name: e, arguments: t } },
|
|
3731
|
-
resultSchema:
|
|
3844
|
+
resultSchema: ps,
|
|
3732
3845
|
options: r
|
|
3733
3846
|
});
|
|
3734
3847
|
} catch (n) {
|
|
@@ -3741,7 +3854,7 @@ var ni = class {
|
|
|
3741
3854
|
}) {
|
|
3742
3855
|
return this.request({
|
|
3743
3856
|
request: { method: "completion/complete", params: t },
|
|
3744
|
-
resultSchema:
|
|
3857
|
+
resultSchema: ls,
|
|
3745
3858
|
options: e
|
|
3746
3859
|
});
|
|
3747
3860
|
}
|
|
@@ -3782,24 +3895,24 @@ var ni = class {
|
|
|
3782
3895
|
const p = i ?? c?.title;
|
|
3783
3896
|
if (t !== "automatic" && !Object.prototype.hasOwnProperty.call(t, s))
|
|
3784
3897
|
continue;
|
|
3785
|
-
const f = this, v = t !== "automatic" ? (r = t[s]) == null ? void 0 : r.outputSchema : void 0,
|
|
3898
|
+
const f = this, v = t !== "automatic" ? (r = t[s]) == null ? void 0 : r.outputSchema : void 0, m = async (x, R) => {
|
|
3786
3899
|
var M;
|
|
3787
3900
|
(M = R?.abortSignal) == null || M.throwIfAborted();
|
|
3788
|
-
const
|
|
3789
|
-
return
|
|
3790
|
-
},
|
|
3901
|
+
const O = await f.callTool({ name: s, args: x, options: R });
|
|
3902
|
+
return O.isError ? O : v != null ? f.extractStructuredContent(O, v, s) : O;
|
|
3903
|
+
}, S = t === "automatic" ? Do({
|
|
3791
3904
|
description: l,
|
|
3792
3905
|
title: p,
|
|
3793
3906
|
metadata: {
|
|
3794
3907
|
clientName: this.clientInfo.name
|
|
3795
3908
|
},
|
|
3796
|
-
inputSchema:
|
|
3909
|
+
inputSchema: Pe({
|
|
3797
3910
|
...u,
|
|
3798
3911
|
properties: (n = u.properties) != null ? n : {},
|
|
3799
3912
|
additionalProperties: !1
|
|
3800
3913
|
}),
|
|
3801
|
-
execute:
|
|
3802
|
-
toModelOutput:
|
|
3914
|
+
execute: m,
|
|
3915
|
+
toModelOutput: ir
|
|
3803
3916
|
}) : {
|
|
3804
3917
|
description: l,
|
|
3805
3918
|
title: p,
|
|
@@ -3808,10 +3921,10 @@ var ni = class {
|
|
|
3808
3921
|
},
|
|
3809
3922
|
inputSchema: t[s].inputSchema,
|
|
3810
3923
|
...v != null ? { outputSchema: v } : {},
|
|
3811
|
-
execute:
|
|
3812
|
-
toModelOutput:
|
|
3924
|
+
execute: m,
|
|
3925
|
+
toModelOutput: ir
|
|
3813
3926
|
};
|
|
3814
|
-
o[s] = { ...
|
|
3927
|
+
o[s] = { ...S, _meta: d };
|
|
3815
3928
|
}
|
|
3816
3929
|
return o;
|
|
3817
3930
|
}
|
|
@@ -3822,7 +3935,7 @@ var ni = class {
|
|
|
3822
3935
|
if ("structuredContent" in e && e.structuredContent != null) {
|
|
3823
3936
|
const n = await Ct({
|
|
3824
3937
|
value: e.structuredContent,
|
|
3825
|
-
schema:
|
|
3938
|
+
schema: Cr(t)
|
|
3826
3939
|
});
|
|
3827
3940
|
if (!n.success)
|
|
3828
3941
|
throw new A({
|
|
@@ -3884,7 +3997,7 @@ var ni = class {
|
|
|
3884
3997
|
return this.completeInternal(e);
|
|
3885
3998
|
}
|
|
3886
3999
|
onElicitationRequest(e, t) {
|
|
3887
|
-
if (e !==
|
|
4000
|
+
if (e !== Bt)
|
|
3888
4001
|
throw new A({
|
|
3889
4002
|
message: "Unsupported request schema. Only ElicitationRequestSchema is supported."
|
|
3890
4003
|
});
|
|
@@ -3922,7 +4035,7 @@ var ni = class {
|
|
|
3922
4035
|
});
|
|
3923
4036
|
return;
|
|
3924
4037
|
}
|
|
3925
|
-
const t =
|
|
4038
|
+
const t = Bt.safeParse({
|
|
3926
4039
|
method: e.method,
|
|
3927
4040
|
params: e.params
|
|
3928
4041
|
});
|
|
@@ -3939,7 +4052,7 @@ var ni = class {
|
|
|
3939
4052
|
return;
|
|
3940
4053
|
}
|
|
3941
4054
|
try {
|
|
3942
|
-
const r = await this.elicitationRequestHandler(t.data), n =
|
|
4055
|
+
const r = await this.elicitationRequestHandler(t.data), n = ms.parse(r);
|
|
3943
4056
|
await this.transport.send({
|
|
3944
4057
|
jsonrpc: "2.0",
|
|
3945
4058
|
id: e.id,
|
|
@@ -3990,15 +4103,15 @@ var ni = class {
|
|
|
3990
4103
|
);
|
|
3991
4104
|
}
|
|
3992
4105
|
};
|
|
3993
|
-
const
|
|
4106
|
+
const fi = async (e) => {
|
|
3994
4107
|
const t = {};
|
|
3995
4108
|
try {
|
|
3996
4109
|
const r = await e.listTools();
|
|
3997
4110
|
for (const { name: n, description: o, inputSchema: s } of r.tools) {
|
|
3998
4111
|
const i = async (l, u) => e.callTool({ name: n, arguments: l }, { signal: u?.abortSignal });
|
|
3999
|
-
t[n] =
|
|
4112
|
+
t[n] = mr({
|
|
4000
4113
|
description: o,
|
|
4001
|
-
inputSchema:
|
|
4114
|
+
inputSchema: gr({
|
|
4002
4115
|
...s,
|
|
4003
4116
|
properties: s.properties ?? {},
|
|
4004
4117
|
additionalProperties: !1
|
|
@@ -4010,7 +4123,7 @@ const oi = async (e) => {
|
|
|
4010
4123
|
} catch (r) {
|
|
4011
4124
|
throw r;
|
|
4012
4125
|
}
|
|
4013
|
-
},
|
|
4126
|
+
}, pi = async (e) => {
|
|
4014
4127
|
const t = {};
|
|
4015
4128
|
if (!e)
|
|
4016
4129
|
return t;
|
|
@@ -4035,19 +4148,19 @@ const oi = async (e) => {
|
|
|
4035
4148
|
additionalProperties: !1,
|
|
4036
4149
|
...d
|
|
4037
4150
|
};
|
|
4038
|
-
t[l] =
|
|
4151
|
+
t[l] = mr({
|
|
4039
4152
|
description: u ?? "",
|
|
4040
|
-
inputSchema:
|
|
4153
|
+
inputSchema: gr(p),
|
|
4041
4154
|
async execute(f) {
|
|
4042
4155
|
if (!r.executeTool)
|
|
4043
|
-
throw new Error("
|
|
4044
|
-
return r.executeTool(
|
|
4156
|
+
throw new Error("document.modelContext.executeTool is not available");
|
|
4157
|
+
return r.executeTool(i, JSON.stringify(f ?? {}));
|
|
4045
4158
|
}
|
|
4046
4159
|
});
|
|
4047
4160
|
}
|
|
4048
4161
|
return t;
|
|
4049
4162
|
};
|
|
4050
|
-
function
|
|
4163
|
+
function hi(e) {
|
|
4051
4164
|
const t = Object.entries(e);
|
|
4052
4165
|
if (t.length === 0)
|
|
4053
4166
|
return "";
|
|
@@ -4097,7 +4210,7 @@ Thought: 用户想要获取今天的日期,我需要调用日期相关的工
|
|
|
4097
4210
|
- 如果不需要调用工具,直接给出最终答案即可
|
|
4098
4211
|
`, r;
|
|
4099
4212
|
}
|
|
4100
|
-
function
|
|
4213
|
+
function ar(e, t) {
|
|
4101
4214
|
if (!e || typeof e != "string")
|
|
4102
4215
|
return null;
|
|
4103
4216
|
const r = e.match(/<tool_call>([\s\S]*?)<\/tool_call>/i);
|
|
@@ -4110,11 +4223,11 @@ function ir(e, t) {
|
|
|
4110
4223
|
}
|
|
4111
4224
|
return null;
|
|
4112
4225
|
}
|
|
4113
|
-
const
|
|
4226
|
+
const mi = {
|
|
4114
4227
|
openai: Pn,
|
|
4115
|
-
deepseek:
|
|
4228
|
+
deepseek: Rn
|
|
4116
4229
|
};
|
|
4117
|
-
class
|
|
4230
|
+
class ol {
|
|
4118
4231
|
constructor({ llmConfig: t, mcpServers: r }) {
|
|
4119
4232
|
if (this.mcpServers = {}, this.mcpClients = {}, this.mcpTools = {}, this.ignoreToolnames = [], this.responseMessages = [], this.useReActMode = !1, !t)
|
|
4120
4233
|
throw new Error("llmConfig is required to initialize AgentModelProvider");
|
|
@@ -4123,7 +4236,7 @@ class Ya {
|
|
|
4123
4236
|
else if (t.providerType) {
|
|
4124
4237
|
const n = t.providerType;
|
|
4125
4238
|
let o;
|
|
4126
|
-
typeof n == "string" ? o =
|
|
4239
|
+
typeof n == "string" ? o = mi[n] : o = n, this.llm = o({
|
|
4127
4240
|
apiKey: t.apiKey,
|
|
4128
4241
|
baseURL: t.baseURL
|
|
4129
4242
|
});
|
|
@@ -4138,7 +4251,7 @@ class Ya {
|
|
|
4138
4251
|
if ("type" in t && t.type === "builtin") {
|
|
4139
4252
|
const o = t.client;
|
|
4140
4253
|
return {
|
|
4141
|
-
tools: () =>
|
|
4254
|
+
tools: () => pi(o),
|
|
4142
4255
|
close: async () => {
|
|
4143
4256
|
}
|
|
4144
4257
|
};
|
|
@@ -4149,12 +4262,12 @@ class Ya {
|
|
|
4149
4262
|
} else if ("type" in t && t.type === "sse") {
|
|
4150
4263
|
const o = t, s = o.headers ? { headers: o.headers } : void 0;
|
|
4151
4264
|
r = new Xe(new URL(o.url), { requestInit: s });
|
|
4152
|
-
} else "
|
|
4265
|
+
} else "transport" in t ? r = t.transport : r = t;
|
|
4153
4266
|
if (t.useAISdkClient ?? !1) {
|
|
4154
|
-
const o = await
|
|
4267
|
+
const o = await ui({ transport: r });
|
|
4155
4268
|
return o.__transport__ = r, o;
|
|
4156
4269
|
} else {
|
|
4157
|
-
const o = new
|
|
4270
|
+
const o = new An(
|
|
4158
4271
|
{ name: "mcp-web-client", version: "1.0.0" },
|
|
4159
4272
|
{ capabilities: { roots: { listChanged: !0 }, sampling: {}, elicitation: {} } }
|
|
4160
4273
|
);
|
|
@@ -4168,7 +4281,7 @@ class Ya {
|
|
|
4168
4281
|
async _closeOneClient(t) {
|
|
4169
4282
|
try {
|
|
4170
4283
|
const r = t.__transport__;
|
|
4171
|
-
if (r && r instanceof
|
|
4284
|
+
if (r && r instanceof En || r && r instanceof dn)
|
|
4172
4285
|
return;
|
|
4173
4286
|
await r?.terminateSession?.(), await r?.close?.(), await t?.close?.();
|
|
4174
4287
|
} catch {
|
|
@@ -4191,7 +4304,7 @@ class Ya {
|
|
|
4191
4304
|
if (!t)
|
|
4192
4305
|
return null;
|
|
4193
4306
|
try {
|
|
4194
|
-
return typeof t.tools == "function" ? await t.tools() : await
|
|
4307
|
+
return typeof t.tools == "function" ? await t.tools() : await fi(t);
|
|
4195
4308
|
} catch (n) {
|
|
4196
4309
|
return this.onError && this.onError(n?.message || `Failed to query tools for ${r}`, n), console.error(`Failed to query tools for ${r}`, n), null;
|
|
4197
4310
|
}
|
|
@@ -4276,7 +4389,7 @@ class Ya {
|
|
|
4276
4389
|
}
|
|
4277
4390
|
/** 生成 ReAct 模式的系统提示词(包含工具描述) */
|
|
4278
4391
|
_generateReActSystemPrompt(t, r, n) {
|
|
4279
|
-
const o =
|
|
4392
|
+
const o = hi(t);
|
|
4280
4393
|
return n ? `${n}${o}` : `你是一个智能助手,可以通过调用工具来完成任务。
|
|
4281
4394
|
${o}`;
|
|
4282
4395
|
}
|
|
@@ -4365,26 +4478,26 @@ ${o}`;
|
|
|
4365
4478
|
const d = s.maxImages ?? 3;
|
|
4366
4479
|
for (; c < o; ) {
|
|
4367
4480
|
c++;
|
|
4368
|
-
const f = this._buildMessagesForModel(l, u, d), { tools: v, ...
|
|
4481
|
+
const f = this._buildMessagesForModel(l, u, d), { tools: v, ...m } = s, x = (await Dt({
|
|
4369
4482
|
// @ts-ignore ProviderV2 是所有llm的父类,在每一个具体的llm类都有一个选择model的函数用法
|
|
4370
4483
|
model: this.llm(n),
|
|
4371
4484
|
messages: f,
|
|
4372
|
-
...
|
|
4485
|
+
...m
|
|
4373
4486
|
})).text, R = { role: "assistant", content: x };
|
|
4374
4487
|
u.push(R), i.push(R);
|
|
4375
|
-
const M =
|
|
4488
|
+
const M = ar(x, r);
|
|
4376
4489
|
if (!M)
|
|
4377
4490
|
return this.responseMessages = i, {
|
|
4378
4491
|
text: x,
|
|
4379
4492
|
response: { messages: i }
|
|
4380
4493
|
};
|
|
4381
|
-
const
|
|
4494
|
+
const O = await this._executeReActToolCall(M.toolName, M.arguments, r), g = {
|
|
4382
4495
|
role: "user",
|
|
4383
4496
|
content: `<tool_response>
|
|
4384
|
-
${
|
|
4497
|
+
${O.success ? JSON.stringify(O.result) : `工具执行失败 - ${O.error}`}
|
|
4385
4498
|
</tool_response>`
|
|
4386
4499
|
};
|
|
4387
|
-
u.push(
|
|
4500
|
+
u.push(g), i.push(g);
|
|
4388
4501
|
}
|
|
4389
4502
|
return this.responseMessages = i, {
|
|
4390
4503
|
text: i[i.length - 2]?.content || "",
|
|
@@ -4402,59 +4515,59 @@ ${I.success ? JSON.stringify(I.result) : `工具执行失败 - ${I.error}`}
|
|
|
4402
4515
|
fullStream: new ReadableStream({
|
|
4403
4516
|
async start(f) {
|
|
4404
4517
|
let v = [...t];
|
|
4405
|
-
const
|
|
4518
|
+
const m = t[0]?.role === "system" ? t[0] : null, S = m ? t.slice(1) : [...t];
|
|
4406
4519
|
let x = 0, R = "";
|
|
4407
4520
|
const M = s.maxImages ?? 3;
|
|
4408
4521
|
f.enqueue({ type: "start" }), f.enqueue({ type: "start-step" });
|
|
4409
4522
|
try {
|
|
4410
4523
|
for (; x < o; ) {
|
|
4411
4524
|
x++;
|
|
4412
|
-
const
|
|
4525
|
+
const O = i._buildMessagesForModel(m, S, M), { tools: j, ...h } = s;
|
|
4413
4526
|
delete h.system, delete h.onFinish;
|
|
4414
|
-
const
|
|
4527
|
+
const g = await st({
|
|
4415
4528
|
...h,
|
|
4416
4529
|
model: l,
|
|
4417
|
-
messages:
|
|
4530
|
+
messages: O
|
|
4418
4531
|
});
|
|
4419
4532
|
let _ = "";
|
|
4420
|
-
for await (const q of
|
|
4533
|
+
for await (const q of g.fullStream)
|
|
4421
4534
|
q.type === "text-delta" ? (_ += q.text || "", f.enqueue({
|
|
4422
4535
|
type: "text-delta",
|
|
4423
4536
|
text: q.text
|
|
4424
4537
|
})) : q.type === "text-start" ? f.enqueue({ type: "text-start" }) : q.type === "text-end" || q.type === "finish-step" || q.type === "finish" || q.type === "start" || q.type === "start-step" || f.enqueue(q);
|
|
4425
4538
|
R += _;
|
|
4426
|
-
const
|
|
4427
|
-
|
|
4428
|
-
const
|
|
4429
|
-
if (!
|
|
4539
|
+
const N = { role: "assistant", content: R };
|
|
4540
|
+
S.push(N), v.push(N);
|
|
4541
|
+
const I = ar(R, r);
|
|
4542
|
+
if (!I) {
|
|
4430
4543
|
f.enqueue({ type: "text-end" }), f.enqueue({ type: "finish-step" }), f.enqueue({ type: "finish" }), f.close(), i.responseMessages = v, u({ messages: v });
|
|
4431
4544
|
return;
|
|
4432
4545
|
}
|
|
4433
|
-
if (
|
|
4546
|
+
if (I.toolName === "computer" && I.arguments?.action === "terminate") {
|
|
4434
4547
|
f.enqueue({ type: "text-end" }), f.enqueue({ type: "finish-step" }), f.enqueue({ type: "finish" }), f.close(), i.responseMessages = v, u({ messages: v });
|
|
4435
4548
|
return;
|
|
4436
4549
|
}
|
|
4437
|
-
const
|
|
4550
|
+
const L = `react-${Date.now()}`;
|
|
4438
4551
|
f.enqueue({
|
|
4439
4552
|
type: "tool-input-start",
|
|
4440
|
-
id:
|
|
4441
|
-
toolName:
|
|
4553
|
+
id: L,
|
|
4554
|
+
toolName: I.toolName
|
|
4442
4555
|
});
|
|
4443
|
-
const K = JSON.stringify(
|
|
4556
|
+
const K = JSON.stringify(I.arguments, null, 2);
|
|
4444
4557
|
f.enqueue({
|
|
4445
4558
|
type: "tool-input-delta",
|
|
4446
|
-
id:
|
|
4559
|
+
id: L,
|
|
4447
4560
|
delta: K
|
|
4448
4561
|
}), f.enqueue({
|
|
4449
4562
|
type: "tool-input-end",
|
|
4450
|
-
id:
|
|
4563
|
+
id: L
|
|
4451
4564
|
}), f.enqueue({
|
|
4452
4565
|
type: "tool-call",
|
|
4453
|
-
toolCallId:
|
|
4454
|
-
toolName:
|
|
4455
|
-
input:
|
|
4566
|
+
toolCallId: L,
|
|
4567
|
+
toolName: I.toolName,
|
|
4568
|
+
input: I.arguments
|
|
4456
4569
|
});
|
|
4457
|
-
const Z = await i._executeReActToolCall(
|
|
4570
|
+
const Z = await i._executeReActToolCall(I.toolName, I.arguments, r);
|
|
4458
4571
|
let oe, H = Z.result;
|
|
4459
4572
|
if (Z.success && Z.result && typeof Z.result == "object" && Z.result.screenshot) {
|
|
4460
4573
|
oe = Z.result.screenshot;
|
|
@@ -4470,7 +4583,7 @@ ${G}
|
|
|
4470
4583
|
oe && (q += `
|
|
4471
4584
|
请检查截图以确认操作是否成功。如果成功,请继续下一步;如果失败,请重试。`), f.enqueue({
|
|
4472
4585
|
type: "tool-result",
|
|
4473
|
-
toolCallId:
|
|
4586
|
+
toolCallId: L,
|
|
4474
4587
|
result: q
|
|
4475
4588
|
});
|
|
4476
4589
|
const le = oe ? {
|
|
@@ -4483,18 +4596,18 @@ ${G}
|
|
|
4483
4596
|
role: "user",
|
|
4484
4597
|
content: q
|
|
4485
4598
|
};
|
|
4486
|
-
|
|
4599
|
+
S.push(le), v.push(le), R = "";
|
|
4487
4600
|
} else
|
|
4488
4601
|
G = `工具执行失败 - ${Z.error}`, f.enqueue({
|
|
4489
4602
|
type: "tool-error",
|
|
4490
|
-
toolCallId:
|
|
4491
|
-
input:
|
|
4603
|
+
toolCallId: L,
|
|
4604
|
+
input: I.arguments,
|
|
4492
4605
|
error: { message: G }
|
|
4493
4606
|
});
|
|
4494
4607
|
}
|
|
4495
4608
|
f.enqueue({ type: "text-end" }), f.enqueue({ type: "finish-step" }), f.enqueue({ type: "finish" }), f.close(), i.responseMessages = v, u({ messages: v });
|
|
4496
|
-
} catch (
|
|
4497
|
-
f.error(
|
|
4609
|
+
} catch (O) {
|
|
4610
|
+
f.error(O), c(O);
|
|
4498
4611
|
}
|
|
4499
4612
|
}
|
|
4500
4613
|
}),
|
|
@@ -4509,22 +4622,22 @@ ${G}
|
|
|
4509
4622
|
await this.initClientsAndTools();
|
|
4510
4623
|
const s = o.tools || {}, i = this._tempMergeTools(s, !1), l = () => {
|
|
4511
4624
|
const v = this._tempMergeTools(s, !1);
|
|
4512
|
-
Object.entries(v).forEach(([
|
|
4513
|
-
i[
|
|
4514
|
-
}), Object.keys(i).forEach((
|
|
4515
|
-
|
|
4625
|
+
Object.entries(v).forEach(([m, S]) => {
|
|
4626
|
+
i[m] = S;
|
|
4627
|
+
}), Object.keys(i).forEach((m) => {
|
|
4628
|
+
m in v || delete i[m];
|
|
4516
4629
|
});
|
|
4517
4630
|
}, u = o.prepareStep, c = async (v) => {
|
|
4518
4631
|
l();
|
|
4519
|
-
const
|
|
4632
|
+
const m = this._getActiveToolNames(i), S = typeof u == "function" ? await u(v) : void 0, x = S && typeof S == "object" ? S : {};
|
|
4520
4633
|
return {
|
|
4521
4634
|
...x,
|
|
4522
|
-
activeTools: Array.isArray(x.activeTools) ? x.activeTools.filter((R) =>
|
|
4635
|
+
activeTools: Array.isArray(x.activeTools) ? x.activeTools.filter((R) => m.includes(R)) : m
|
|
4523
4636
|
};
|
|
4524
4637
|
}, d = {
|
|
4525
4638
|
// @ts-ignore ProviderV2 是所有llm的父类, 在每一个具体的llm 类都有一个选择model的函数用法
|
|
4526
4639
|
model: this.llm(r),
|
|
4527
|
-
stopWhen:
|
|
4640
|
+
stopWhen: Cn(n),
|
|
4528
4641
|
...o,
|
|
4529
4642
|
tools: i,
|
|
4530
4643
|
prepareStep: c,
|
|
@@ -4539,28 +4652,31 @@ ${G}
|
|
|
4539
4652
|
}
|
|
4540
4653
|
const f = t(d);
|
|
4541
4654
|
return f?.response?.then((v) => {
|
|
4542
|
-
const
|
|
4543
|
-
p &&
|
|
4655
|
+
const m = v.messages?.[0];
|
|
4656
|
+
p && m?.role !== "user" && this.responseMessages.push(p), this.responseMessages.push(...v.messages);
|
|
4544
4657
|
}), f;
|
|
4545
4658
|
}
|
|
4546
4659
|
async chat(t) {
|
|
4547
|
-
return this._chat(
|
|
4660
|
+
return this._chat(Dt, t);
|
|
4548
4661
|
}
|
|
4549
4662
|
async chatStream(t) {
|
|
4550
4663
|
return this._chat(st, t);
|
|
4551
4664
|
}
|
|
4552
4665
|
}
|
|
4553
|
-
const
|
|
4554
|
-
|
|
4555
|
-
|
|
4666
|
+
const gi = () => typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
|
|
4667
|
+
const t = Math.random() * 16 | 0;
|
|
4668
|
+
return (e === "x" ? t : t & 3 | 8).toString(16);
|
|
4669
|
+
}), ae = () => typeof window < "u" && typeof navigator < "u", yi = () => ae() && typeof document < "u";
|
|
4670
|
+
let ie = null, We = null, lr = null, De = 0;
|
|
4671
|
+
const vi = "next-sdk-tool-body-glow";
|
|
4556
4672
|
function ke() {
|
|
4557
|
-
return
|
|
4673
|
+
return yi();
|
|
4558
4674
|
}
|
|
4559
|
-
function
|
|
4560
|
-
if (!ke() ||
|
|
4675
|
+
function wi() {
|
|
4676
|
+
if (!ke() || lr) return;
|
|
4561
4677
|
const e = document.createElement("style");
|
|
4562
4678
|
e.textContent = `
|
|
4563
|
-
.${
|
|
4679
|
+
.${vi} {
|
|
4564
4680
|
position: relative;
|
|
4565
4681
|
}
|
|
4566
4682
|
|
|
@@ -4727,11 +4843,11 @@ function ui() {
|
|
|
4727
4843
|
transform: scale(1) translateY(0);
|
|
4728
4844
|
}
|
|
4729
4845
|
}
|
|
4730
|
-
`, document.head.appendChild(e),
|
|
4846
|
+
`, document.head.appendChild(e), lr = e;
|
|
4731
4847
|
}
|
|
4732
|
-
function
|
|
4848
|
+
function bi() {
|
|
4733
4849
|
if (!ke() || ie) return;
|
|
4734
|
-
|
|
4850
|
+
wi();
|
|
4735
4851
|
const e = document.createElement("div");
|
|
4736
4852
|
e.className = "next-sdk-tool-overlay";
|
|
4737
4853
|
const t = document.createElement("div");
|
|
@@ -4753,10 +4869,10 @@ function di() {
|
|
|
4753
4869
|
const c = document.createElement("div");
|
|
4754
4870
|
c.className = "next-sdk-tool-overlay__label", l.prepend(u), i.appendChild(l), i.appendChild(c), n.appendChild(o), n.appendChild(s), r.appendChild(n), r.appendChild(i), e.appendChild(t), e.appendChild(r), document.body.appendChild(e), ie = e, We = c;
|
|
4755
4871
|
}
|
|
4756
|
-
function
|
|
4757
|
-
ke() && (
|
|
4872
|
+
function _i(e) {
|
|
4873
|
+
ke() && (bi(), !(!ie || !We) && (ie.classList.remove("next-sdk-tool-overlay--exit"), We.textContent = e.label));
|
|
4758
4874
|
}
|
|
4759
|
-
function
|
|
4875
|
+
function xi() {
|
|
4760
4876
|
if (!ie) return;
|
|
4761
4877
|
ie.classList.add("next-sdk-tool-overlay--exit");
|
|
4762
4878
|
const e = ie;
|
|
@@ -4766,42 +4882,42 @@ function pi() {
|
|
|
4766
4882
|
};
|
|
4767
4883
|
e.addEventListener("animationend", n), r = setTimeout(n, 500);
|
|
4768
4884
|
}
|
|
4769
|
-
function
|
|
4770
|
-
ke() && (
|
|
4885
|
+
function Si(e) {
|
|
4886
|
+
ke() && (De += 1, _i(e));
|
|
4771
4887
|
}
|
|
4772
|
-
function
|
|
4773
|
-
!ke() ||
|
|
4888
|
+
function Ti() {
|
|
4889
|
+
!ke() || De <= 0 || (De -= 1, De === 0 && xi());
|
|
4774
4890
|
}
|
|
4775
|
-
function
|
|
4891
|
+
function Vr(e, t, r) {
|
|
4776
4892
|
if (!r) return;
|
|
4777
4893
|
const n = t || e;
|
|
4778
4894
|
return typeof r == "boolean" ? r ? { label: n } : void 0 : {
|
|
4779
4895
|
label: r.label || n
|
|
4780
4896
|
};
|
|
4781
4897
|
}
|
|
4782
|
-
const
|
|
4783
|
-
function
|
|
4784
|
-
ae() &&
|
|
4898
|
+
const Jr = "next-sdk:tool-call", vt = "next-sdk:tool-response", ve = "next-sdk:tool-registered", Be = "next-sdk:tool-unregistered", Ci = "next-sdk:remoter-ready", wt = /* @__PURE__ */ new Map(), $e = (e) => e.replace(/\/+$/, "") || "/", Ot = /* @__PURE__ */ new Set();
|
|
4899
|
+
function $i() {
|
|
4900
|
+
ae() && Ot.add({ win: window, origin: window.location.origin || "*" });
|
|
4785
4901
|
}
|
|
4786
|
-
|
|
4902
|
+
$i();
|
|
4787
4903
|
function ce(e) {
|
|
4788
4904
|
if (!ae()) return;
|
|
4789
4905
|
const t = { type: e };
|
|
4790
|
-
|
|
4906
|
+
Ot.forEach(({ win: r, origin: n }) => {
|
|
4791
4907
|
try {
|
|
4792
4908
|
r.postMessage(t, n);
|
|
4793
4909
|
} catch {
|
|
4794
4910
|
}
|
|
4795
4911
|
});
|
|
4796
4912
|
}
|
|
4797
|
-
function
|
|
4913
|
+
function Ei() {
|
|
4798
4914
|
ae() && window.addEventListener("message", (e) => {
|
|
4799
|
-
if (e.data?.type !==
|
|
4915
|
+
if (e.data?.type !== Ci || !e.source || e.origin !== window.location.origin) return;
|
|
4800
4916
|
const t = e.source;
|
|
4801
|
-
|
|
4917
|
+
Ot.add({ win: t, origin: e.origin || "*" });
|
|
4802
4918
|
});
|
|
4803
4919
|
}
|
|
4804
|
-
|
|
4920
|
+
Ei();
|
|
4805
4921
|
function dt(e) {
|
|
4806
4922
|
if (!e) return;
|
|
4807
4923
|
const t = e;
|
|
@@ -4810,20 +4926,20 @@ function dt(e) {
|
|
|
4810
4926
|
} catch {
|
|
4811
4927
|
}
|
|
4812
4928
|
}
|
|
4813
|
-
function
|
|
4929
|
+
function cr(e, t) {
|
|
4814
4930
|
const r = wt.get(e);
|
|
4815
4931
|
return !!r && r.has(t);
|
|
4816
4932
|
}
|
|
4817
|
-
let
|
|
4818
|
-
function
|
|
4819
|
-
|
|
4933
|
+
let Ee = null;
|
|
4934
|
+
function sl(e) {
|
|
4935
|
+
Ee = e;
|
|
4820
4936
|
}
|
|
4821
|
-
function
|
|
4937
|
+
function Pi(e) {
|
|
4822
4938
|
if (!ae()) return !1;
|
|
4823
4939
|
const t = $e(e);
|
|
4824
4940
|
return $e(window.location.pathname) === t;
|
|
4825
4941
|
}
|
|
4826
|
-
function
|
|
4942
|
+
function Ri(e) {
|
|
4827
4943
|
return ae() ? new Promise((t) => {
|
|
4828
4944
|
let r = !1;
|
|
4829
4945
|
const n = () => {
|
|
@@ -4834,7 +4950,7 @@ function bi(e) {
|
|
|
4834
4950
|
window.addEventListener("message", o), setTimeout(n, e);
|
|
4835
4951
|
}) : Promise.resolve();
|
|
4836
4952
|
}
|
|
4837
|
-
function
|
|
4953
|
+
function il(e, t) {
|
|
4838
4954
|
const r = t?.name ?? "navigate_to_page", n = t?.title ?? "页面跳转", o = t?.description ?? '当需要的工具在当前页面不可用时,使用此工具跳转到特定页面。例如:要查询订单时跳转到 "/orders",要创建价保时跳转到 "/price-protection"。', s = t?.timeoutMs ?? 5e3, i = {
|
|
4839
4955
|
type: "object",
|
|
4840
4956
|
properties: {
|
|
@@ -4851,7 +4967,7 @@ function Qa(e, t) {
|
|
|
4851
4967
|
return {
|
|
4852
4968
|
content: [{ type: "text", text: "当前环境不支持页面跳转(window 不存在)。" }]
|
|
4853
4969
|
};
|
|
4854
|
-
if (!
|
|
4970
|
+
if (!Ee)
|
|
4855
4971
|
return {
|
|
4856
4972
|
content: [
|
|
4857
4973
|
{
|
|
@@ -4861,12 +4977,12 @@ function Qa(e, t) {
|
|
|
4861
4977
|
]
|
|
4862
4978
|
};
|
|
4863
4979
|
try {
|
|
4864
|
-
if (
|
|
4980
|
+
if (Pi(u))
|
|
4865
4981
|
return {
|
|
4866
4982
|
content: [{ type: "text", text: `当前已在页面:${u}。请继续你的下一步操作。` }]
|
|
4867
4983
|
};
|
|
4868
|
-
const c =
|
|
4869
|
-
return await
|
|
4984
|
+
const c = Ri(s);
|
|
4985
|
+
return await Ee(u) !== !0 && (await c, await new Promise((p) => setTimeout(p, 500))), {
|
|
4870
4986
|
content: [{ type: "text", text: `已成功跳转至页面:${u}。请继续你的下一步操作。` }]
|
|
4871
4987
|
};
|
|
4872
4988
|
} catch (c) {
|
|
@@ -4898,13 +5014,13 @@ function Qa(e, t) {
|
|
|
4898
5014
|
);
|
|
4899
5015
|
throw new Error("Failed to register navigate tool: invalid server instance.");
|
|
4900
5016
|
}
|
|
4901
|
-
function
|
|
5017
|
+
function Wr(e, t, r = 3e4, n) {
|
|
4902
5018
|
return (o) => {
|
|
4903
|
-
const s =
|
|
5019
|
+
const s = gi();
|
|
4904
5020
|
return new Promise((i, l) => {
|
|
4905
5021
|
let u, c;
|
|
4906
5022
|
const d = () => {
|
|
4907
|
-
clearTimeout(u), window.removeEventListener("message", p), c && window.removeEventListener("message", c), n &&
|
|
5023
|
+
clearTimeout(u), window.removeEventListener("message", p), c && window.removeEventListener("message", c), n && Ti();
|
|
4908
5024
|
};
|
|
4909
5025
|
u = setTimeout(() => {
|
|
4910
5026
|
d(), l(new Error(`工具 [${e}] 调用超时 (${r}ms),请检查目标页面是否正确调用了 registerPageTool`));
|
|
@@ -4914,25 +5030,25 @@ function Vr(e, t, r = 3e4, n) {
|
|
|
4914
5030
|
};
|
|
4915
5031
|
window.addEventListener("message", p);
|
|
4916
5032
|
const f = () => {
|
|
4917
|
-
window.postMessage({ type:
|
|
5033
|
+
window.postMessage({ type: Jr, callId: s, toolName: e, route: t, input: o }, window.location.origin || "*");
|
|
4918
5034
|
};
|
|
4919
5035
|
let v = !1;
|
|
4920
|
-
const
|
|
5036
|
+
const m = () => {
|
|
4921
5037
|
v || (v = !0, f());
|
|
4922
5038
|
};
|
|
4923
5039
|
(async () => {
|
|
4924
5040
|
try {
|
|
4925
|
-
if (n &&
|
|
4926
|
-
|
|
5041
|
+
if (n && Si(n), cr(t, e)) {
|
|
5042
|
+
m();
|
|
4927
5043
|
return;
|
|
4928
5044
|
}
|
|
4929
5045
|
if (c = (x) => {
|
|
4930
|
-
x.source !== window || x.data?.type !== ve || (window.removeEventListener("message", c),
|
|
4931
|
-
}, window.addEventListener("message", c),
|
|
4932
|
-
c && window.removeEventListener("message", c),
|
|
5046
|
+
x.source !== window || x.data?.type !== ve || (window.removeEventListener("message", c), m());
|
|
5047
|
+
}, window.addEventListener("message", c), Ee && await Ee(t) === !0) {
|
|
5048
|
+
c && window.removeEventListener("message", c), m();
|
|
4933
5049
|
return;
|
|
4934
5050
|
}
|
|
4935
|
-
|
|
5051
|
+
cr(t, e) && (window.removeEventListener("message", c), m());
|
|
4936
5052
|
} catch (x) {
|
|
4937
5053
|
d(), l(x instanceof Error ? x : new Error(String(x)));
|
|
4938
5054
|
}
|
|
@@ -4940,7 +5056,7 @@ function Vr(e, t, r = 3e4, n) {
|
|
|
4940
5056
|
});
|
|
4941
5057
|
};
|
|
4942
5058
|
}
|
|
4943
|
-
function
|
|
5059
|
+
function al(e) {
|
|
4944
5060
|
const t = /* @__PURE__ */ new Map(), r = (n, o, s = !1) => {
|
|
4945
5061
|
const i = t.get(o), l = !!i;
|
|
4946
5062
|
if (t.delete(o), i)
|
|
@@ -4959,15 +5075,15 @@ function el(e) {
|
|
|
4959
5075
|
const R = c(i, l, u);
|
|
4960
5076
|
return t.set(i, R), dt(n), ce(ve), R;
|
|
4961
5077
|
}
|
|
4962
|
-
const { route: d, timeout: p, invokeEffect: f } = u, v = $e(d),
|
|
5078
|
+
const { route: d, timeout: p, invokeEffect: f } = u, v = $e(d), m = Vr(i, l?.title, f), S = Wr(i, v, p, m), x = c(i, l, S);
|
|
4963
5079
|
return t.set(i, x), dt(n), ce(ve), x;
|
|
4964
5080
|
} : Reflect.get(n, o, s);
|
|
4965
5081
|
}
|
|
4966
5082
|
});
|
|
4967
5083
|
}
|
|
4968
|
-
function
|
|
5084
|
+
function ll(e) {
|
|
4969
5085
|
const { route: t, handlers: r } = e, n = $e(t ?? window.location.pathname), o = Object.keys(r), s = async (i) => {
|
|
4970
|
-
if (i.source !== window || i.data?.type !==
|
|
5086
|
+
if (i.source !== window || i.data?.type !== Jr || !(i.data.toolName in r))
|
|
4971
5087
|
return;
|
|
4972
5088
|
const { callId: l, toolName: u, input: c } = i.data;
|
|
4973
5089
|
try {
|
|
@@ -4990,24 +5106,24 @@ function tl(e) {
|
|
|
4990
5106
|
wt.delete(n), window.removeEventListener("message", s), ce(Be);
|
|
4991
5107
|
};
|
|
4992
5108
|
}
|
|
4993
|
-
const
|
|
4994
|
-
function
|
|
5109
|
+
const Se = /* @__PURE__ */ new Map();
|
|
5110
|
+
function ki() {
|
|
4995
5111
|
if (typeof document > "u") return;
|
|
4996
5112
|
const t = document.modelContext;
|
|
4997
5113
|
if (!t || t.__isNextSdkBridgeSetup) return;
|
|
4998
|
-
ae() && (window.__nextSdkRegisteredTools = () => Array.from(
|
|
5114
|
+
ae() && (window.__nextSdkRegisteredTools = () => Array.from(Se.values()));
|
|
4999
5115
|
const r = t.registerTool?.bind(t), n = t.unregisterTool?.bind(t);
|
|
5000
5116
|
typeof r == "function" && (t.registerTool = (o, s) => {
|
|
5001
5117
|
const i = o.name, l = { ...o };
|
|
5002
5118
|
s?.signal && s.signal.addEventListener("abort", () => {
|
|
5003
|
-
|
|
5119
|
+
Se.delete(i), ce(Be);
|
|
5004
5120
|
});
|
|
5005
5121
|
const u = l.routeConfig && typeof l.routeConfig == "object" && "route" in l.routeConfig ? l.routeConfig : null;
|
|
5006
5122
|
if (u) {
|
|
5007
|
-
const c = $e(u.route), d =
|
|
5123
|
+
const c = $e(u.route), d = Vr(i, l.title, u.invokeEffect), p = Wr(i, c, u.timeout, d);
|
|
5008
5124
|
l.execute = p, delete l.routeConfig;
|
|
5009
5125
|
}
|
|
5010
|
-
|
|
5126
|
+
Se.set(i, {
|
|
5011
5127
|
name: i,
|
|
5012
5128
|
title: o.title,
|
|
5013
5129
|
description: o.description,
|
|
@@ -5016,14 +5132,14 @@ function _i() {
|
|
|
5016
5132
|
try {
|
|
5017
5133
|
r(l, s), ce(ve);
|
|
5018
5134
|
} catch {
|
|
5019
|
-
|
|
5135
|
+
Se.delete(i);
|
|
5020
5136
|
}
|
|
5021
5137
|
}), t.unregisterTool = (o) => {
|
|
5022
5138
|
try {
|
|
5023
5139
|
typeof n == "function" && n(o);
|
|
5024
5140
|
} catch {
|
|
5025
5141
|
} finally {
|
|
5026
|
-
|
|
5142
|
+
Se.delete(o), ce(Be);
|
|
5027
5143
|
}
|
|
5028
5144
|
}, t.__isNextSdkBridgeSetup = !0;
|
|
5029
5145
|
}
|
|
@@ -5056,24 +5172,24 @@ function Te(e, t) {
|
|
|
5056
5172
|
return e === t;
|
|
5057
5173
|
}
|
|
5058
5174
|
function Q(e) {
|
|
5059
|
-
return encodeURI(
|
|
5175
|
+
return encodeURI(Oi(e));
|
|
5060
5176
|
}
|
|
5061
|
-
function
|
|
5177
|
+
function Oi(e) {
|
|
5062
5178
|
return e.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
5063
5179
|
}
|
|
5064
|
-
const
|
|
5180
|
+
const Ai = {
|
|
5065
5181
|
prefixItems: !0,
|
|
5066
5182
|
items: !0,
|
|
5067
5183
|
allOf: !0,
|
|
5068
5184
|
anyOf: !0,
|
|
5069
5185
|
oneOf: !0
|
|
5070
|
-
},
|
|
5186
|
+
}, Ii = {
|
|
5071
5187
|
$defs: !0,
|
|
5072
5188
|
definitions: !0,
|
|
5073
5189
|
properties: !0,
|
|
5074
5190
|
patternProperties: !0,
|
|
5075
5191
|
dependentSchemas: !0
|
|
5076
|
-
},
|
|
5192
|
+
}, Mi = {
|
|
5077
5193
|
id: !0,
|
|
5078
5194
|
$id: !0,
|
|
5079
5195
|
$ref: !0,
|
|
@@ -5101,8 +5217,8 @@ const xi = {
|
|
|
5101
5217
|
maxProperties: !0,
|
|
5102
5218
|
minProperties: !0
|
|
5103
5219
|
};
|
|
5104
|
-
let
|
|
5105
|
-
function he(e, t = /* @__PURE__ */ Object.create(null), r =
|
|
5220
|
+
let ji = typeof self < "u" && self.location && self.location.origin !== "null" ? new URL(self.location.origin + self.location.pathname + location.search) : new URL("https://github.com/cfworker");
|
|
5221
|
+
function he(e, t = /* @__PURE__ */ Object.create(null), r = ji, n = "") {
|
|
5106
5222
|
if (e && typeof e == "object" && !Array.isArray(e)) {
|
|
5107
5223
|
const s = e.$id || e.id;
|
|
5108
5224
|
if (s) {
|
|
@@ -5138,16 +5254,16 @@ function he(e, t = /* @__PURE__ */ Object.create(null), r = $i, n = "") {
|
|
|
5138
5254
|
t[s.href] = e;
|
|
5139
5255
|
}
|
|
5140
5256
|
for (let s in e) {
|
|
5141
|
-
if (
|
|
5257
|
+
if (Mi[s])
|
|
5142
5258
|
continue;
|
|
5143
5259
|
const i = `${n}/${Q(s)}`, l = e[s];
|
|
5144
5260
|
if (Array.isArray(l)) {
|
|
5145
|
-
if (
|
|
5261
|
+
if (Ai[s]) {
|
|
5146
5262
|
const u = l.length;
|
|
5147
5263
|
for (let c = 0; c < u; c++)
|
|
5148
5264
|
he(l[c], t, r, `${i}/${c}`);
|
|
5149
5265
|
}
|
|
5150
|
-
} else if (
|
|
5266
|
+
} else if (Ii[s])
|
|
5151
5267
|
for (let u in l)
|
|
5152
5268
|
he(l[u], t, r, `${i}/${Q(u)}`);
|
|
5153
5269
|
else
|
|
@@ -5155,63 +5271,63 @@ function he(e, t = /* @__PURE__ */ Object.create(null), r = $i, n = "") {
|
|
|
5155
5271
|
}
|
|
5156
5272
|
return t;
|
|
5157
5273
|
}
|
|
5158
|
-
const
|
|
5274
|
+
const Ni = /^(\d\d\d\d)-(\d\d)-(\d\d)$/, zi = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], Ui = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i, Di = /^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i, Li = /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i, qi = /^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i, Hi = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)(?:\.(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu, Fi = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i, Zi = /^(?:\/(?:[^~/]|~0|~1)*)*$/, Vi = /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i, Ji = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/, Wi = (e) => {
|
|
5159
5275
|
if (e[0] === '"')
|
|
5160
5276
|
return !1;
|
|
5161
5277
|
const [t, r, ...n] = e.split("@");
|
|
5162
5278
|
return !t || !r || n.length !== 0 || t.length > 64 || r.length > 253 || t[0] === "." || t.endsWith(".") || t.includes("..") || !/^[a-z0-9.-]+$/i.test(r) || !/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+$/i.test(t) ? !1 : r.split(".").every((o) => /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/i.test(o));
|
|
5163
|
-
},
|
|
5279
|
+
}, Bi = /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/, Gi = /^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i, Ki = (e) => e.length > 1 && e.length < 80 && (/^P\d+([.,]\d+)?W$/.test(e) || /^P[\dYMDTHS]*(\d[.,]\d+)?[YMDHS]$/.test(e) && /^P([.,\d]+Y)?([.,\d]+M)?([.,\d]+D)?(T([.,\d]+H)?([.,\d]+M)?([.,\d]+S)?)?$/.test(e));
|
|
5164
5280
|
function ee(e) {
|
|
5165
5281
|
return e.test.bind(e);
|
|
5166
5282
|
}
|
|
5167
|
-
const
|
|
5168
|
-
date:
|
|
5169
|
-
time:
|
|
5170
|
-
"date-time":
|
|
5171
|
-
duration:
|
|
5172
|
-
uri:
|
|
5173
|
-
"uri-reference": ee(
|
|
5174
|
-
"uri-template": ee(
|
|
5175
|
-
url: ee(
|
|
5176
|
-
email:
|
|
5177
|
-
hostname: ee(
|
|
5178
|
-
ipv4: ee(
|
|
5179
|
-
ipv6: ee(
|
|
5180
|
-
regex:
|
|
5181
|
-
uuid: ee(
|
|
5182
|
-
"json-pointer": ee(
|
|
5183
|
-
"json-pointer-uri-fragment": ee(
|
|
5184
|
-
"relative-json-pointer": ee(
|
|
5283
|
+
const ur = {
|
|
5284
|
+
date: Br,
|
|
5285
|
+
time: Gr.bind(void 0, !1),
|
|
5286
|
+
"date-time": Qi,
|
|
5287
|
+
duration: Ki,
|
|
5288
|
+
uri: ra,
|
|
5289
|
+
"uri-reference": ee(Li),
|
|
5290
|
+
"uri-template": ee(qi),
|
|
5291
|
+
url: ee(Hi),
|
|
5292
|
+
email: Wi,
|
|
5293
|
+
hostname: ee(Di),
|
|
5294
|
+
ipv4: ee(Bi),
|
|
5295
|
+
ipv6: ee(Gi),
|
|
5296
|
+
regex: oa,
|
|
5297
|
+
uuid: ee(Fi),
|
|
5298
|
+
"json-pointer": ee(Zi),
|
|
5299
|
+
"json-pointer-uri-fragment": ee(Vi),
|
|
5300
|
+
"relative-json-pointer": ee(Ji)
|
|
5185
5301
|
};
|
|
5186
|
-
function
|
|
5302
|
+
function Yi(e) {
|
|
5187
5303
|
return e % 4 === 0 && (e % 100 !== 0 || e % 400 === 0);
|
|
5188
5304
|
}
|
|
5189
|
-
function
|
|
5190
|
-
const t = e.match(
|
|
5305
|
+
function Br(e) {
|
|
5306
|
+
const t = e.match(Ni);
|
|
5191
5307
|
if (!t)
|
|
5192
5308
|
return !1;
|
|
5193
5309
|
const r = +t[1], n = +t[2], o = +t[3];
|
|
5194
|
-
return n >= 1 && n <= 12 && o >= 1 && o <= (n == 2 &&
|
|
5310
|
+
return n >= 1 && n <= 12 && o >= 1 && o <= (n == 2 && Yi(r) ? 29 : zi[n]);
|
|
5195
5311
|
}
|
|
5196
|
-
function
|
|
5197
|
-
const r = t.match(
|
|
5312
|
+
function Gr(e, t) {
|
|
5313
|
+
const r = t.match(Ui);
|
|
5198
5314
|
if (!r)
|
|
5199
5315
|
return !1;
|
|
5200
5316
|
const n = +r[1], o = +r[2], s = +r[3], i = !!r[5];
|
|
5201
5317
|
return (n <= 23 && o <= 59 && s <= 59 || n == 23 && o == 59 && s == 60) && (!e || i);
|
|
5202
5318
|
}
|
|
5203
|
-
const
|
|
5204
|
-
function
|
|
5205
|
-
const t = e.split(
|
|
5206
|
-
return t.length == 2 &&
|
|
5319
|
+
const Xi = /t|\s/i;
|
|
5320
|
+
function Qi(e) {
|
|
5321
|
+
const t = e.split(Xi);
|
|
5322
|
+
return t.length == 2 && Br(t[0]) && Gr(!0, t[1]);
|
|
5207
5323
|
}
|
|
5208
|
-
const
|
|
5209
|
-
function
|
|
5210
|
-
return
|
|
5324
|
+
const ea = /\/|:/, ta = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
|
5325
|
+
function ra(e) {
|
|
5326
|
+
return ea.test(e) && ta.test(e);
|
|
5211
5327
|
}
|
|
5212
|
-
const
|
|
5213
|
-
function
|
|
5214
|
-
if (
|
|
5328
|
+
const na = /[^\\]\\Z/;
|
|
5329
|
+
function oa(e) {
|
|
5330
|
+
if (na.test(e))
|
|
5215
5331
|
return !1;
|
|
5216
5332
|
try {
|
|
5217
5333
|
return new RegExp(e, "u"), !0;
|
|
@@ -5219,13 +5335,13 @@ function Gi(e) {
|
|
|
5219
5335
|
return !1;
|
|
5220
5336
|
}
|
|
5221
5337
|
}
|
|
5222
|
-
function
|
|
5338
|
+
function sa(e) {
|
|
5223
5339
|
let t = 0, r = e.length, n = 0, o;
|
|
5224
5340
|
for (; n < r; )
|
|
5225
5341
|
t++, o = e.charCodeAt(n++), o >= 55296 && o <= 56319 && n < r && (o = e.charCodeAt(n), (o & 64512) == 56320 && n++);
|
|
5226
5342
|
return t;
|
|
5227
5343
|
}
|
|
5228
|
-
function
|
|
5344
|
+
function D(e, t, r = "2019-09", n = he(t), o = !0, s = null, i = "#", l = "#", u = /* @__PURE__ */ Object.create(null)) {
|
|
5229
5345
|
if (t === !0)
|
|
5230
5346
|
return { valid: !0, errors: [] };
|
|
5231
5347
|
if (t === !1)
|
|
@@ -5254,68 +5370,68 @@ function L(e, t, r = "2019-09", n = he(t), o = !0, s = null, i = "#", l = "#", u
|
|
|
5254
5370
|
default:
|
|
5255
5371
|
throw new Error(`Instances of "${c}" type are not supported.`);
|
|
5256
5372
|
}
|
|
5257
|
-
const { $ref: p, $recursiveRef: f, $recursiveAnchor: v, type:
|
|
5373
|
+
const { $ref: p, $recursiveRef: f, $recursiveAnchor: v, type: m, const: S, enum: x, required: R, not: M, anyOf: O, allOf: j, oneOf: h, if: g, then: _, else: N, format: I, properties: L, patternProperties: K, additionalProperties: Z, unevaluatedProperties: oe, minProperties: H, maxProperties: G, propertyNames: q, dependentRequired: le, dependentSchemas: et, dependencies: tt, prefixItems: rt, items: be, additionalItems: At, unevaluatedItems: It, contains: Mt, minContains: se, maxContains: Oe, minItems: nt, maxItems: ot, uniqueItems: rn, minimum: ue, maximum: de, exclusiveMinimum: _e, exclusiveMaximum: xe, multipleOf: Ae, minLength: Ie, maxLength: Me, pattern: jt, __absolute_ref__: je, __absolute_recursive_ref__: nn } = t, w = [];
|
|
5258
5374
|
if (v === !0 && s === null && (s = t), f === "#") {
|
|
5259
|
-
const C = s === null ? n[
|
|
5260
|
-
|
|
5375
|
+
const C = s === null ? n[nn] : s, T = `${l}/$recursiveRef`, P = D(e, s === null ? t : s, r, n, o, C, i, T, u);
|
|
5376
|
+
P.valid || w.push({
|
|
5261
5377
|
instanceLocation: i,
|
|
5262
5378
|
keyword: "$recursiveRef",
|
|
5263
|
-
keywordLocation:
|
|
5379
|
+
keywordLocation: T,
|
|
5264
5380
|
error: "A subschema had errors."
|
|
5265
|
-
}, ...
|
|
5381
|
+
}, ...P.errors);
|
|
5266
5382
|
}
|
|
5267
5383
|
if (p !== void 0) {
|
|
5268
|
-
const
|
|
5269
|
-
if (
|
|
5270
|
-
let
|
|
5271
|
-
throw je && je !== p && (
|
|
5384
|
+
const T = n[je || p];
|
|
5385
|
+
if (T === void 0) {
|
|
5386
|
+
let y = `Unresolved $ref "${p}".`;
|
|
5387
|
+
throw je && je !== p && (y += ` Absolute URI "${je}".`), y += `
|
|
5272
5388
|
Known schemas:
|
|
5273
5389
|
- ${Object.keys(n).join(`
|
|
5274
|
-
- `)}`, new Error(
|
|
5390
|
+
- `)}`, new Error(y);
|
|
5275
5391
|
}
|
|
5276
|
-
const
|
|
5392
|
+
const P = `${l}/$ref`, b = D(e, T, r, n, o, s, i, P, u);
|
|
5277
5393
|
if (b.valid || w.push({
|
|
5278
5394
|
instanceLocation: i,
|
|
5279
5395
|
keyword: "$ref",
|
|
5280
|
-
keywordLocation:
|
|
5396
|
+
keywordLocation: P,
|
|
5281
5397
|
error: "A subschema had errors."
|
|
5282
5398
|
}, ...b.errors), r === "4" || r === "7")
|
|
5283
5399
|
return { valid: w.length === 0, errors: w };
|
|
5284
5400
|
}
|
|
5285
|
-
if (Array.isArray(
|
|
5286
|
-
let C =
|
|
5287
|
-
for (let
|
|
5288
|
-
if (d ===
|
|
5289
|
-
|
|
5401
|
+
if (Array.isArray(m)) {
|
|
5402
|
+
let C = m.length, T = !1;
|
|
5403
|
+
for (let P = 0; P < C; P++)
|
|
5404
|
+
if (d === m[P] || m[P] === "integer" && d === "number" && e % 1 === 0 && e === e) {
|
|
5405
|
+
T = !0;
|
|
5290
5406
|
break;
|
|
5291
5407
|
}
|
|
5292
|
-
|
|
5408
|
+
T || w.push({
|
|
5293
5409
|
instanceLocation: i,
|
|
5294
5410
|
keyword: "type",
|
|
5295
5411
|
keywordLocation: `${l}/type`,
|
|
5296
|
-
error: `Instance type "${d}" is invalid. Expected "${
|
|
5412
|
+
error: `Instance type "${d}" is invalid. Expected "${m.join('", "')}".`
|
|
5297
5413
|
});
|
|
5298
|
-
} else
|
|
5414
|
+
} else m === "integer" ? (d !== "number" || e % 1 || e !== e) && w.push({
|
|
5299
5415
|
instanceLocation: i,
|
|
5300
5416
|
keyword: "type",
|
|
5301
5417
|
keywordLocation: `${l}/type`,
|
|
5302
|
-
error: `Instance type "${d}" is invalid. Expected "${
|
|
5303
|
-
}) :
|
|
5418
|
+
error: `Instance type "${d}" is invalid. Expected "${m}".`
|
|
5419
|
+
}) : m !== void 0 && d !== m && w.push({
|
|
5304
5420
|
instanceLocation: i,
|
|
5305
5421
|
keyword: "type",
|
|
5306
5422
|
keywordLocation: `${l}/type`,
|
|
5307
|
-
error: `Instance type "${d}" is invalid. Expected "${
|
|
5423
|
+
error: `Instance type "${d}" is invalid. Expected "${m}".`
|
|
5308
5424
|
});
|
|
5309
|
-
if (
|
|
5425
|
+
if (S !== void 0 && (d === "object" || d === "array" ? Te(e, S) || w.push({
|
|
5310
5426
|
instanceLocation: i,
|
|
5311
5427
|
keyword: "const",
|
|
5312
5428
|
keywordLocation: `${l}/const`,
|
|
5313
|
-
error: `Instance does not match ${JSON.stringify(
|
|
5314
|
-
}) : e !==
|
|
5429
|
+
error: `Instance does not match ${JSON.stringify(S)}.`
|
|
5430
|
+
}) : e !== S && w.push({
|
|
5315
5431
|
instanceLocation: i,
|
|
5316
5432
|
keyword: "const",
|
|
5317
5433
|
keywordLocation: `${l}/const`,
|
|
5318
|
-
error: `Instance does not match ${JSON.stringify(
|
|
5434
|
+
error: `Instance does not match ${JSON.stringify(S)}.`
|
|
5319
5435
|
})), x !== void 0 && (d === "object" || d === "array" ? x.some((C) => Te(e, C)) || w.push({
|
|
5320
5436
|
instanceLocation: i,
|
|
5321
5437
|
keyword: "enum",
|
|
@@ -5328,7 +5444,7 @@ Known schemas:
|
|
|
5328
5444
|
error: `Instance does not match any of ${JSON.stringify(x)}.`
|
|
5329
5445
|
})), M !== void 0) {
|
|
5330
5446
|
const C = `${l}/not`;
|
|
5331
|
-
|
|
5447
|
+
D(e, M, r, n, o, s, i, C).valid && w.push({
|
|
5332
5448
|
instanceLocation: i,
|
|
5333
5449
|
keyword: "not",
|
|
5334
5450
|
keywordLocation: C,
|
|
@@ -5336,28 +5452,28 @@ Known schemas:
|
|
|
5336
5452
|
});
|
|
5337
5453
|
}
|
|
5338
5454
|
let Ne = [];
|
|
5339
|
-
if (
|
|
5340
|
-
const C = `${l}/anyOf`,
|
|
5341
|
-
let
|
|
5342
|
-
for (let b = 0; b <
|
|
5343
|
-
const
|
|
5344
|
-
w.push(...$.errors),
|
|
5455
|
+
if (O !== void 0) {
|
|
5456
|
+
const C = `${l}/anyOf`, T = w.length;
|
|
5457
|
+
let P = !1;
|
|
5458
|
+
for (let b = 0; b < O.length; b++) {
|
|
5459
|
+
const y = O[b], E = Object.create(u), $ = D(e, y, r, n, o, v === !0 ? s : null, i, `${C}/${b}`, E);
|
|
5460
|
+
w.push(...$.errors), P = P || $.valid, $.valid && Ne.push(E);
|
|
5345
5461
|
}
|
|
5346
|
-
|
|
5462
|
+
P ? w.length = T : w.splice(T, 0, {
|
|
5347
5463
|
instanceLocation: i,
|
|
5348
5464
|
keyword: "anyOf",
|
|
5349
5465
|
keywordLocation: C,
|
|
5350
5466
|
error: "Instance does not match any subschemas."
|
|
5351
5467
|
});
|
|
5352
5468
|
}
|
|
5353
|
-
if (
|
|
5354
|
-
const C = `${l}/allOf`,
|
|
5355
|
-
let
|
|
5356
|
-
for (let b = 0; b <
|
|
5357
|
-
const
|
|
5358
|
-
w.push(...$.errors),
|
|
5469
|
+
if (j !== void 0) {
|
|
5470
|
+
const C = `${l}/allOf`, T = w.length;
|
|
5471
|
+
let P = !0;
|
|
5472
|
+
for (let b = 0; b < j.length; b++) {
|
|
5473
|
+
const y = j[b], E = Object.create(u), $ = D(e, y, r, n, o, v === !0 ? s : null, i, `${C}/${b}`, E);
|
|
5474
|
+
w.push(...$.errors), P = P && $.valid, $.valid && Ne.push(E);
|
|
5359
5475
|
}
|
|
5360
|
-
|
|
5476
|
+
P ? w.length = T : w.splice(T, 0, {
|
|
5361
5477
|
instanceLocation: i,
|
|
5362
5478
|
keyword: "allOf",
|
|
5363
5479
|
keywordLocation: C,
|
|
@@ -5365,37 +5481,37 @@ Known schemas:
|
|
|
5365
5481
|
});
|
|
5366
5482
|
}
|
|
5367
5483
|
if (h !== void 0) {
|
|
5368
|
-
const C = `${l}/oneOf`,
|
|
5369
|
-
const
|
|
5370
|
-
return w.push(...$.errors), $.valid && Ne.push(
|
|
5484
|
+
const C = `${l}/oneOf`, T = w.length, P = h.filter((b, y) => {
|
|
5485
|
+
const E = Object.create(u), $ = D(e, b, r, n, o, v === !0 ? s : null, i, `${C}/${y}`, E);
|
|
5486
|
+
return w.push(...$.errors), $.valid && Ne.push(E), $.valid;
|
|
5371
5487
|
}).length;
|
|
5372
|
-
|
|
5488
|
+
P === 1 ? w.length = T : w.splice(T, 0, {
|
|
5373
5489
|
instanceLocation: i,
|
|
5374
5490
|
keyword: "oneOf",
|
|
5375
5491
|
keywordLocation: C,
|
|
5376
|
-
error: `Instance does not match exactly one subschema (${
|
|
5492
|
+
error: `Instance does not match exactly one subschema (${P} matches).`
|
|
5377
5493
|
});
|
|
5378
5494
|
}
|
|
5379
|
-
if ((d === "object" || d === "array") && Object.assign(u, ...Ne),
|
|
5495
|
+
if ((d === "object" || d === "array") && Object.assign(u, ...Ne), g !== void 0) {
|
|
5380
5496
|
const C = `${l}/if`;
|
|
5381
|
-
if (
|
|
5497
|
+
if (D(e, g, r, n, o, s, i, C, u).valid) {
|
|
5382
5498
|
if (_ !== void 0) {
|
|
5383
|
-
const
|
|
5384
|
-
|
|
5499
|
+
const P = D(e, _, r, n, o, s, i, `${l}/then`, u);
|
|
5500
|
+
P.valid || w.push({
|
|
5385
5501
|
instanceLocation: i,
|
|
5386
5502
|
keyword: "if",
|
|
5387
5503
|
keywordLocation: C,
|
|
5388
5504
|
error: 'Instance does not match "then" schema.'
|
|
5389
|
-
}, ...
|
|
5505
|
+
}, ...P.errors);
|
|
5390
5506
|
}
|
|
5391
|
-
} else if (
|
|
5392
|
-
const
|
|
5393
|
-
|
|
5507
|
+
} else if (N !== void 0) {
|
|
5508
|
+
const P = D(e, N, r, n, o, s, i, `${l}/else`, u);
|
|
5509
|
+
P.valid || w.push({
|
|
5394
5510
|
instanceLocation: i,
|
|
5395
5511
|
keyword: "if",
|
|
5396
5512
|
keywordLocation: C,
|
|
5397
5513
|
error: 'Instance does not match "else" schema.'
|
|
5398
|
-
}, ...
|
|
5514
|
+
}, ...P.errors);
|
|
5399
5515
|
}
|
|
5400
5516
|
}
|
|
5401
5517
|
if (d === "object") {
|
|
@@ -5420,126 +5536,126 @@ Known schemas:
|
|
|
5420
5536
|
error: `Instance does not have at least ${G} properties.`
|
|
5421
5537
|
}), q !== void 0) {
|
|
5422
5538
|
const b = `${l}/propertyNames`;
|
|
5423
|
-
for (const
|
|
5424
|
-
const
|
|
5539
|
+
for (const y in e) {
|
|
5540
|
+
const E = `${i}/${Q(y)}`, $ = D(y, q, r, n, o, s, E, b);
|
|
5425
5541
|
$.valid || w.push({
|
|
5426
5542
|
instanceLocation: i,
|
|
5427
5543
|
keyword: "propertyNames",
|
|
5428
5544
|
keywordLocation: b,
|
|
5429
|
-
error: `Property name "${
|
|
5545
|
+
error: `Property name "${y}" does not match schema.`
|
|
5430
5546
|
}, ...$.errors);
|
|
5431
5547
|
}
|
|
5432
5548
|
}
|
|
5433
5549
|
if (le !== void 0) {
|
|
5434
5550
|
const b = `${l}/dependantRequired`;
|
|
5435
|
-
for (const
|
|
5436
|
-
if (
|
|
5437
|
-
const
|
|
5438
|
-
for (const $ of
|
|
5551
|
+
for (const y in le)
|
|
5552
|
+
if (y in e) {
|
|
5553
|
+
const E = le[y];
|
|
5554
|
+
for (const $ of E)
|
|
5439
5555
|
$ in e || w.push({
|
|
5440
5556
|
instanceLocation: i,
|
|
5441
5557
|
keyword: "dependentRequired",
|
|
5442
5558
|
keywordLocation: b,
|
|
5443
|
-
error: `Instance has "${
|
|
5559
|
+
error: `Instance has "${y}" but does not have "${$}".`
|
|
5444
5560
|
});
|
|
5445
5561
|
}
|
|
5446
5562
|
}
|
|
5447
5563
|
if (et !== void 0)
|
|
5448
5564
|
for (const b in et) {
|
|
5449
|
-
const
|
|
5565
|
+
const y = `${l}/dependentSchemas`;
|
|
5450
5566
|
if (b in e) {
|
|
5451
|
-
const
|
|
5452
|
-
|
|
5567
|
+
const E = D(e, et[b], r, n, o, s, i, `${y}/${Q(b)}`, u);
|
|
5568
|
+
E.valid || w.push({
|
|
5453
5569
|
instanceLocation: i,
|
|
5454
5570
|
keyword: "dependentSchemas",
|
|
5455
|
-
keywordLocation:
|
|
5571
|
+
keywordLocation: y,
|
|
5456
5572
|
error: `Instance has "${b}" but does not match dependant schema.`
|
|
5457
|
-
}, ...
|
|
5573
|
+
}, ...E.errors);
|
|
5458
5574
|
}
|
|
5459
5575
|
}
|
|
5460
5576
|
if (tt !== void 0) {
|
|
5461
5577
|
const b = `${l}/dependencies`;
|
|
5462
|
-
for (const
|
|
5463
|
-
if (
|
|
5464
|
-
const
|
|
5465
|
-
if (Array.isArray(
|
|
5466
|
-
for (const $ of
|
|
5578
|
+
for (const y in tt)
|
|
5579
|
+
if (y in e) {
|
|
5580
|
+
const E = tt[y];
|
|
5581
|
+
if (Array.isArray(E))
|
|
5582
|
+
for (const $ of E)
|
|
5467
5583
|
$ in e || w.push({
|
|
5468
5584
|
instanceLocation: i,
|
|
5469
5585
|
keyword: "dependencies",
|
|
5470
5586
|
keywordLocation: b,
|
|
5471
|
-
error: `Instance has "${
|
|
5587
|
+
error: `Instance has "${y}" but does not have "${$}".`
|
|
5472
5588
|
});
|
|
5473
5589
|
else {
|
|
5474
|
-
const $ =
|
|
5590
|
+
const $ = D(e, E, r, n, o, s, i, `${b}/${Q(y)}`);
|
|
5475
5591
|
$.valid || w.push({
|
|
5476
5592
|
instanceLocation: i,
|
|
5477
5593
|
keyword: "dependencies",
|
|
5478
5594
|
keywordLocation: b,
|
|
5479
|
-
error: `Instance has "${
|
|
5595
|
+
error: `Instance has "${y}" but does not match dependant schema.`
|
|
5480
5596
|
}, ...$.errors);
|
|
5481
5597
|
}
|
|
5482
5598
|
}
|
|
5483
5599
|
}
|
|
5484
|
-
const
|
|
5485
|
-
let
|
|
5486
|
-
if (
|
|
5600
|
+
const T = /* @__PURE__ */ Object.create(null);
|
|
5601
|
+
let P = !1;
|
|
5602
|
+
if (L !== void 0) {
|
|
5487
5603
|
const b = `${l}/properties`;
|
|
5488
|
-
for (const
|
|
5489
|
-
if (!(
|
|
5604
|
+
for (const y in L) {
|
|
5605
|
+
if (!(y in e))
|
|
5490
5606
|
continue;
|
|
5491
|
-
const
|
|
5607
|
+
const E = `${i}/${Q(y)}`, $ = D(e[y], L[y], r, n, o, s, E, `${b}/${Q(y)}`);
|
|
5492
5608
|
if ($.valid)
|
|
5493
|
-
u[
|
|
5494
|
-
else if (
|
|
5609
|
+
u[y] = T[y] = !0;
|
|
5610
|
+
else if (P = o, w.push({
|
|
5495
5611
|
instanceLocation: i,
|
|
5496
5612
|
keyword: "properties",
|
|
5497
5613
|
keywordLocation: b,
|
|
5498
|
-
error: `Property "${
|
|
5499
|
-
}, ...$.errors),
|
|
5614
|
+
error: `Property "${y}" does not match schema.`
|
|
5615
|
+
}, ...$.errors), P)
|
|
5500
5616
|
break;
|
|
5501
5617
|
}
|
|
5502
5618
|
}
|
|
5503
|
-
if (!
|
|
5619
|
+
if (!P && K !== void 0) {
|
|
5504
5620
|
const b = `${l}/patternProperties`;
|
|
5505
|
-
for (const
|
|
5506
|
-
const
|
|
5621
|
+
for (const y in K) {
|
|
5622
|
+
const E = new RegExp(y, "u"), $ = K[y];
|
|
5507
5623
|
for (const W in e) {
|
|
5508
|
-
if (!
|
|
5624
|
+
if (!E.test(W))
|
|
5509
5625
|
continue;
|
|
5510
|
-
const Nt = `${i}/${Q(W)}`, zt =
|
|
5511
|
-
zt.valid ? u[W] =
|
|
5626
|
+
const Nt = `${i}/${Q(W)}`, zt = D(e[W], $, r, n, o, s, Nt, `${b}/${Q(y)}`);
|
|
5627
|
+
zt.valid ? u[W] = T[W] = !0 : (P = o, w.push({
|
|
5512
5628
|
instanceLocation: i,
|
|
5513
5629
|
keyword: "patternProperties",
|
|
5514
5630
|
keywordLocation: b,
|
|
5515
|
-
error: `Property "${W}" matches pattern "${
|
|
5631
|
+
error: `Property "${W}" matches pattern "${y}" but does not match associated schema.`
|
|
5516
5632
|
}, ...zt.errors));
|
|
5517
5633
|
}
|
|
5518
5634
|
}
|
|
5519
5635
|
}
|
|
5520
|
-
if (!
|
|
5636
|
+
if (!P && Z !== void 0) {
|
|
5521
5637
|
const b = `${l}/additionalProperties`;
|
|
5522
|
-
for (const
|
|
5523
|
-
if (
|
|
5638
|
+
for (const y in e) {
|
|
5639
|
+
if (T[y])
|
|
5524
5640
|
continue;
|
|
5525
|
-
const
|
|
5526
|
-
$.valid ? u[
|
|
5641
|
+
const E = `${i}/${Q(y)}`, $ = D(e[y], Z, r, n, o, s, E, b);
|
|
5642
|
+
$.valid ? u[y] = !0 : (P = o, w.push({
|
|
5527
5643
|
instanceLocation: i,
|
|
5528
5644
|
keyword: "additionalProperties",
|
|
5529
5645
|
keywordLocation: b,
|
|
5530
|
-
error: `Property "${
|
|
5646
|
+
error: `Property "${y}" does not match additional properties schema.`
|
|
5531
5647
|
}, ...$.errors));
|
|
5532
5648
|
}
|
|
5533
|
-
} else if (!
|
|
5649
|
+
} else if (!P && oe !== void 0) {
|
|
5534
5650
|
const b = `${l}/unevaluatedProperties`;
|
|
5535
|
-
for (const
|
|
5536
|
-
if (!u[
|
|
5537
|
-
const
|
|
5538
|
-
$.valid ? u[
|
|
5651
|
+
for (const y in e)
|
|
5652
|
+
if (!u[y]) {
|
|
5653
|
+
const E = `${i}/${Q(y)}`, $ = D(e[y], oe, r, n, o, s, E, b);
|
|
5654
|
+
$.valid ? u[y] = !0 : w.push({
|
|
5539
5655
|
instanceLocation: i,
|
|
5540
5656
|
keyword: "unevaluatedProperties",
|
|
5541
5657
|
keywordLocation: b,
|
|
5542
|
-
error: `Property "${
|
|
5658
|
+
error: `Property "${y}" does not match unevaluated properties schema.`
|
|
5543
5659
|
}, ...$.errors);
|
|
5544
5660
|
}
|
|
5545
5661
|
}
|
|
@@ -5556,59 +5672,59 @@ Known schemas:
|
|
|
5556
5672
|
error: `Array has too few items (${e.length} < ${nt}).`
|
|
5557
5673
|
});
|
|
5558
5674
|
const C = e.length;
|
|
5559
|
-
let
|
|
5675
|
+
let T = 0, P = !1;
|
|
5560
5676
|
if (rt !== void 0) {
|
|
5561
|
-
const b = `${l}/prefixItems`,
|
|
5562
|
-
for (;
|
|
5563
|
-
const
|
|
5564
|
-
if (u[
|
|
5677
|
+
const b = `${l}/prefixItems`, y = Math.min(rt.length, C);
|
|
5678
|
+
for (; T < y; T++) {
|
|
5679
|
+
const E = D(e[T], rt[T], r, n, o, s, `${i}/${T}`, `${b}/${T}`);
|
|
5680
|
+
if (u[T] = !0, !E.valid && (P = o, w.push({
|
|
5565
5681
|
instanceLocation: i,
|
|
5566
5682
|
keyword: "prefixItems",
|
|
5567
5683
|
keywordLocation: b,
|
|
5568
5684
|
error: "Items did not match schema."
|
|
5569
|
-
}, ...
|
|
5685
|
+
}, ...E.errors), P))
|
|
5570
5686
|
break;
|
|
5571
5687
|
}
|
|
5572
5688
|
}
|
|
5573
5689
|
if (be !== void 0) {
|
|
5574
5690
|
const b = `${l}/items`;
|
|
5575
5691
|
if (Array.isArray(be)) {
|
|
5576
|
-
const
|
|
5577
|
-
for (;
|
|
5578
|
-
const
|
|
5579
|
-
if (u[
|
|
5692
|
+
const y = Math.min(be.length, C);
|
|
5693
|
+
for (; T < y; T++) {
|
|
5694
|
+
const E = D(e[T], be[T], r, n, o, s, `${i}/${T}`, `${b}/${T}`);
|
|
5695
|
+
if (u[T] = !0, !E.valid && (P = o, w.push({
|
|
5580
5696
|
instanceLocation: i,
|
|
5581
5697
|
keyword: "items",
|
|
5582
5698
|
keywordLocation: b,
|
|
5583
5699
|
error: "Items did not match schema."
|
|
5584
|
-
}, ...
|
|
5700
|
+
}, ...E.errors), P))
|
|
5585
5701
|
break;
|
|
5586
5702
|
}
|
|
5587
5703
|
} else
|
|
5588
|
-
for (;
|
|
5589
|
-
const
|
|
5590
|
-
if (u[
|
|
5704
|
+
for (; T < C; T++) {
|
|
5705
|
+
const y = D(e[T], be, r, n, o, s, `${i}/${T}`, b);
|
|
5706
|
+
if (u[T] = !0, !y.valid && (P = o, w.push({
|
|
5591
5707
|
instanceLocation: i,
|
|
5592
5708
|
keyword: "items",
|
|
5593
5709
|
keywordLocation: b,
|
|
5594
5710
|
error: "Items did not match schema."
|
|
5595
|
-
}, ...
|
|
5711
|
+
}, ...y.errors), P))
|
|
5596
5712
|
break;
|
|
5597
5713
|
}
|
|
5598
|
-
if (!
|
|
5599
|
-
const
|
|
5600
|
-
for (;
|
|
5601
|
-
const
|
|
5602
|
-
u[
|
|
5714
|
+
if (!P && At !== void 0) {
|
|
5715
|
+
const y = `${l}/additionalItems`;
|
|
5716
|
+
for (; T < C; T++) {
|
|
5717
|
+
const E = D(e[T], At, r, n, o, s, `${i}/${T}`, y);
|
|
5718
|
+
u[T] = !0, E.valid || (P = o, w.push({
|
|
5603
5719
|
instanceLocation: i,
|
|
5604
5720
|
keyword: "additionalItems",
|
|
5605
|
-
keywordLocation:
|
|
5721
|
+
keywordLocation: y,
|
|
5606
5722
|
error: "Items did not match additional items schema."
|
|
5607
|
-
}, ...
|
|
5723
|
+
}, ...E.errors));
|
|
5608
5724
|
}
|
|
5609
5725
|
}
|
|
5610
5726
|
}
|
|
5611
|
-
if (
|
|
5727
|
+
if (Mt !== void 0)
|
|
5612
5728
|
if (C === 0 && se === void 0)
|
|
5613
5729
|
w.push({
|
|
5614
5730
|
instanceLocation: i,
|
|
@@ -5624,51 +5740,51 @@ Known schemas:
|
|
|
5624
5740
|
error: `Array has less items (${C}) than minContains (${se}).`
|
|
5625
5741
|
});
|
|
5626
5742
|
else {
|
|
5627
|
-
const b = `${l}/contains`,
|
|
5628
|
-
let
|
|
5743
|
+
const b = `${l}/contains`, y = w.length;
|
|
5744
|
+
let E = 0;
|
|
5629
5745
|
for (let $ = 0; $ < C; $++) {
|
|
5630
|
-
const W =
|
|
5631
|
-
W.valid ? (u[$] = !0,
|
|
5746
|
+
const W = D(e[$], Mt, r, n, o, s, `${i}/${$}`, b);
|
|
5747
|
+
W.valid ? (u[$] = !0, E++) : w.push(...W.errors);
|
|
5632
5748
|
}
|
|
5633
|
-
|
|
5749
|
+
E >= (se || 0) && (w.length = y), se === void 0 && Oe === void 0 && E === 0 ? w.splice(y, 0, {
|
|
5634
5750
|
instanceLocation: i,
|
|
5635
5751
|
keyword: "contains",
|
|
5636
5752
|
keywordLocation: b,
|
|
5637
5753
|
error: "Array does not contain item matching schema."
|
|
5638
|
-
}) : se !== void 0 &&
|
|
5754
|
+
}) : se !== void 0 && E < se ? w.push({
|
|
5639
5755
|
instanceLocation: i,
|
|
5640
5756
|
keyword: "minContains",
|
|
5641
5757
|
keywordLocation: `${l}/minContains`,
|
|
5642
|
-
error: `Array must contain at least ${se} items matching schema. Only ${
|
|
5643
|
-
}) :
|
|
5758
|
+
error: `Array must contain at least ${se} items matching schema. Only ${E} items were found.`
|
|
5759
|
+
}) : Oe !== void 0 && E > Oe && w.push({
|
|
5644
5760
|
instanceLocation: i,
|
|
5645
5761
|
keyword: "maxContains",
|
|
5646
5762
|
keywordLocation: `${l}/maxContains`,
|
|
5647
|
-
error: `Array may contain at most ${
|
|
5763
|
+
error: `Array may contain at most ${Oe} items matching schema. ${E} items were found.`
|
|
5648
5764
|
});
|
|
5649
5765
|
}
|
|
5650
|
-
if (!
|
|
5766
|
+
if (!P && It !== void 0) {
|
|
5651
5767
|
const b = `${l}/unevaluatedItems`;
|
|
5652
|
-
for (
|
|
5653
|
-
if (u[
|
|
5768
|
+
for (T; T < C; T++) {
|
|
5769
|
+
if (u[T])
|
|
5654
5770
|
continue;
|
|
5655
|
-
const
|
|
5656
|
-
u[
|
|
5771
|
+
const y = D(e[T], It, r, n, o, s, `${i}/${T}`, b);
|
|
5772
|
+
u[T] = !0, y.valid || w.push({
|
|
5657
5773
|
instanceLocation: i,
|
|
5658
5774
|
keyword: "unevaluatedItems",
|
|
5659
5775
|
keywordLocation: b,
|
|
5660
5776
|
error: "Items did not match unevaluated items schema."
|
|
5661
|
-
}, ...
|
|
5777
|
+
}, ...y.errors);
|
|
5662
5778
|
}
|
|
5663
5779
|
}
|
|
5664
|
-
if (
|
|
5780
|
+
if (rn)
|
|
5665
5781
|
for (let b = 0; b < C; b++) {
|
|
5666
|
-
const
|
|
5782
|
+
const y = e[b], E = typeof y == "object" && y !== null;
|
|
5667
5783
|
for (let $ = 0; $ < C; $++) {
|
|
5668
5784
|
if (b === $)
|
|
5669
5785
|
continue;
|
|
5670
5786
|
const W = e[$];
|
|
5671
|
-
(
|
|
5787
|
+
(y === W || E && (typeof W == "object" && W !== null) && Te(y, W)) && (w.push({
|
|
5672
5788
|
instanceLocation: i,
|
|
5673
5789
|
keyword: "uniqueItems",
|
|
5674
5790
|
keywordLocation: `${l}/uniqueItems`,
|
|
@@ -5682,11 +5798,11 @@ Known schemas:
|
|
|
5682
5798
|
keyword: "minimum",
|
|
5683
5799
|
keywordLocation: `${l}/minimum`,
|
|
5684
5800
|
error: `${e} is less than ${_e ? "or equal to " : ""} ${ue}.`
|
|
5685
|
-
}), de !== void 0 && (
|
|
5801
|
+
}), de !== void 0 && (xe === !0 && e >= de || e > de) && w.push({
|
|
5686
5802
|
instanceLocation: i,
|
|
5687
5803
|
keyword: "maximum",
|
|
5688
5804
|
keywordLocation: `${l}/maximum`,
|
|
5689
|
-
error: `${e} is greater than ${
|
|
5805
|
+
error: `${e} is greater than ${xe ? "or equal to " : ""} ${de}.`
|
|
5690
5806
|
})) : (ue !== void 0 && e < ue && w.push({
|
|
5691
5807
|
instanceLocation: i,
|
|
5692
5808
|
keyword: "minimum",
|
|
@@ -5702,47 +5818,47 @@ Known schemas:
|
|
|
5702
5818
|
keyword: "exclusiveMinimum",
|
|
5703
5819
|
keywordLocation: `${l}/exclusiveMinimum`,
|
|
5704
5820
|
error: `${e} is less than ${_e}.`
|
|
5705
|
-
}),
|
|
5821
|
+
}), xe !== void 0 && e >= xe && w.push({
|
|
5706
5822
|
instanceLocation: i,
|
|
5707
5823
|
keyword: "exclusiveMaximum",
|
|
5708
5824
|
keywordLocation: `${l}/exclusiveMaximum`,
|
|
5709
|
-
error: `${e} is greater than or equal to ${
|
|
5710
|
-
})),
|
|
5711
|
-
const C = e %
|
|
5712
|
-
Math.abs(0 - C) >= 11920929e-14 && Math.abs(
|
|
5825
|
+
error: `${e} is greater than or equal to ${xe}.`
|
|
5826
|
+
})), Ae !== void 0) {
|
|
5827
|
+
const C = e % Ae;
|
|
5828
|
+
Math.abs(0 - C) >= 11920929e-14 && Math.abs(Ae - C) >= 11920929e-14 && w.push({
|
|
5713
5829
|
instanceLocation: i,
|
|
5714
5830
|
keyword: "multipleOf",
|
|
5715
5831
|
keywordLocation: `${l}/multipleOf`,
|
|
5716
|
-
error: `${e} is not a multiple of ${
|
|
5832
|
+
error: `${e} is not a multiple of ${Ae}.`
|
|
5717
5833
|
});
|
|
5718
5834
|
}
|
|
5719
5835
|
} else if (d === "string") {
|
|
5720
|
-
const C =
|
|
5721
|
-
|
|
5836
|
+
const C = Ie === void 0 && Me === void 0 ? 0 : sa(e);
|
|
5837
|
+
Ie !== void 0 && C < Ie && w.push({
|
|
5722
5838
|
instanceLocation: i,
|
|
5723
5839
|
keyword: "minLength",
|
|
5724
5840
|
keywordLocation: `${l}/minLength`,
|
|
5725
|
-
error: `String is too short (${C} < ${
|
|
5726
|
-
}),
|
|
5841
|
+
error: `String is too short (${C} < ${Ie}).`
|
|
5842
|
+
}), Me !== void 0 && C > Me && w.push({
|
|
5727
5843
|
instanceLocation: i,
|
|
5728
5844
|
keyword: "maxLength",
|
|
5729
5845
|
keywordLocation: `${l}/maxLength`,
|
|
5730
|
-
error: `String is too long (${C} > ${
|
|
5846
|
+
error: `String is too long (${C} > ${Me}).`
|
|
5731
5847
|
}), jt !== void 0 && !new RegExp(jt, "u").test(e) && w.push({
|
|
5732
5848
|
instanceLocation: i,
|
|
5733
5849
|
keyword: "pattern",
|
|
5734
5850
|
keywordLocation: `${l}/pattern`,
|
|
5735
5851
|
error: "String does not match pattern."
|
|
5736
|
-
}),
|
|
5852
|
+
}), I !== void 0 && ur[I] && !ur[I](e) && w.push({
|
|
5737
5853
|
instanceLocation: i,
|
|
5738
5854
|
keyword: "format",
|
|
5739
5855
|
keywordLocation: `${l}/format`,
|
|
5740
|
-
error: `String does not match format "${
|
|
5856
|
+
error: `String does not match format "${I}".`
|
|
5741
5857
|
});
|
|
5742
5858
|
}
|
|
5743
5859
|
return { valid: w.length === 0, errors: w };
|
|
5744
5860
|
}
|
|
5745
|
-
class
|
|
5861
|
+
class ia {
|
|
5746
5862
|
schema;
|
|
5747
5863
|
draft;
|
|
5748
5864
|
shortCircuit;
|
|
@@ -5751,16 +5867,16 @@ class Yi {
|
|
|
5751
5867
|
this.schema = t, this.draft = r, this.shortCircuit = n, this.lookup = he(t);
|
|
5752
5868
|
}
|
|
5753
5869
|
validate(t) {
|
|
5754
|
-
return
|
|
5870
|
+
return D(t, this.schema, this.draft, this.lookup, this.shortCircuit);
|
|
5755
5871
|
}
|
|
5756
5872
|
addSchema(t, r) {
|
|
5757
5873
|
r && (t = { ...t, $id: r }), he(t, this.lookup);
|
|
5758
5874
|
}
|
|
5759
5875
|
}
|
|
5760
|
-
const
|
|
5876
|
+
const dr = "Failed to parse input arguments", Ge = "Tool was executed but the invocation failed. For example, the script function threw an error", bt = "Tool was cancelled", ze = {
|
|
5761
5877
|
type: "object",
|
|
5762
5878
|
properties: {}
|
|
5763
|
-
},
|
|
5879
|
+
}, aa = ["draft-2020-12", "draft-07"], la = "__isWebMCPPolyfill", Kr = Symbol("standardValidator"), U = {
|
|
5764
5880
|
installed: !1,
|
|
5765
5881
|
previousNavigatorModelContextDescriptor: void 0,
|
|
5766
5882
|
previousNavigatorModelContextTestingDescriptor: void 0,
|
|
@@ -5769,7 +5885,7 @@ const ur = "Failed to parse input arguments", Ge = "Tool was executed but the in
|
|
|
5769
5885
|
installedNavigatorModelContextTesting: !1,
|
|
5770
5886
|
installedDocumentModelContext: !1
|
|
5771
5887
|
};
|
|
5772
|
-
var
|
|
5888
|
+
var ca = class extends EventTarget {
|
|
5773
5889
|
tools = /* @__PURE__ */ new Map();
|
|
5774
5890
|
testingShim = null;
|
|
5775
5891
|
_ontoolchange = null;
|
|
@@ -5786,14 +5902,14 @@ var ea = class extends EventTarget {
|
|
|
5786
5902
|
console.warn(`[WebMCPPolyfill] registerTool("${e?.name ?? "<unknown>"}") skipped: options.signal was already aborted.`);
|
|
5787
5903
|
return;
|
|
5788
5904
|
}
|
|
5789
|
-
const n =
|
|
5905
|
+
const n = ya(e, this.tools);
|
|
5790
5906
|
this.tools.set(n.name, n), this.notifyToolsChanged(), r && r.addEventListener("abort", () => {
|
|
5791
5907
|
this.tools.delete(n.name) && this.notifyToolsChanged();
|
|
5792
5908
|
}, { once: !0 });
|
|
5793
5909
|
}
|
|
5794
5910
|
unregisterTool(e) {
|
|
5795
5911
|
this.warnUnregisterToolDeprecationOnce();
|
|
5796
|
-
const t =
|
|
5912
|
+
const t = fa(e);
|
|
5797
5913
|
this.tools.delete(t) && this.notifyToolsChanged();
|
|
5798
5914
|
}
|
|
5799
5915
|
getTools() {
|
|
@@ -5803,7 +5919,7 @@ var ea = class extends EventTarget {
|
|
|
5803
5919
|
return this.executeToolByName(e.name, t, r, !1);
|
|
5804
5920
|
}
|
|
5805
5921
|
getTestingShim() {
|
|
5806
|
-
return this.testingShim || (this.testingShim = new
|
|
5922
|
+
return this.testingShim || (this.testingShim = new ua(this)), this.testingShim;
|
|
5807
5923
|
}
|
|
5808
5924
|
/** @internal Used by PolyfillTestingShim */
|
|
5809
5925
|
getToolInfos() {
|
|
@@ -5841,7 +5957,7 @@ var ea = class extends EventTarget {
|
|
|
5841
5957
|
if (r?.signal?.aborted) throw te(bt);
|
|
5842
5958
|
const o = this.tools.get(e);
|
|
5843
5959
|
if (!o) throw te(`Tool not found: ${e}`);
|
|
5844
|
-
const s =
|
|
5960
|
+
const s = da(t), i = await _a(s, o);
|
|
5845
5961
|
if (i) throw te(i);
|
|
5846
5962
|
let l = !0;
|
|
5847
5963
|
const u = { requestUserInteraction: async (c) => {
|
|
@@ -5850,8 +5966,8 @@ var ea = class extends EventTarget {
|
|
|
5850
5966
|
return c();
|
|
5851
5967
|
} };
|
|
5852
5968
|
try {
|
|
5853
|
-
const c = o.execute(s, u), d = await
|
|
5854
|
-
if (n) return
|
|
5969
|
+
const c = o.execute(s, u), d = await Ra(Promise.resolve(c), r?.signal);
|
|
5970
|
+
if (n) return Pa($a(d));
|
|
5855
5971
|
const p = JSON.stringify(d);
|
|
5856
5972
|
return p === void 0 ? null : p;
|
|
5857
5973
|
} catch (c) {
|
|
@@ -5874,7 +5990,7 @@ var ea = class extends EventTarget {
|
|
|
5874
5990
|
warnUnregisterToolDeprecationOnce() {
|
|
5875
5991
|
this.unregisterToolDeprecationWarned || (this.unregisterToolDeprecationWarned = !0, console.warn("[WebMCPPolyfill] navigator.modelContext.unregisterTool() is deprecated. The April 23, 2026 WebMCP draft removed it in favor of registerTool(tool, { signal }) — pass an AbortSignal and abort it to unregister."));
|
|
5876
5992
|
}
|
|
5877
|
-
},
|
|
5993
|
+
}, ua = class extends EventTarget {
|
|
5878
5994
|
context;
|
|
5879
5995
|
_ontoolchange = null;
|
|
5880
5996
|
constructor(e) {
|
|
@@ -5922,17 +6038,17 @@ function te(e) {
|
|
|
5922
6038
|
return t.name = "UnknownError", t;
|
|
5923
6039
|
}
|
|
5924
6040
|
}
|
|
5925
|
-
function
|
|
6041
|
+
function da(e) {
|
|
5926
6042
|
let t;
|
|
5927
6043
|
try {
|
|
5928
6044
|
t = JSON.parse(e);
|
|
5929
6045
|
} catch {
|
|
5930
|
-
throw te(
|
|
6046
|
+
throw te(dr);
|
|
5931
6047
|
}
|
|
5932
|
-
if (!t || typeof t != "object" || Array.isArray(t)) throw te(
|
|
6048
|
+
if (!t || typeof t != "object" || Array.isArray(t)) throw te(dr);
|
|
5933
6049
|
return t;
|
|
5934
6050
|
}
|
|
5935
|
-
function
|
|
6051
|
+
function fa(e) {
|
|
5936
6052
|
if (typeof e == "string") return e;
|
|
5937
6053
|
if (V(e) && typeof e.name == "string") return e.name;
|
|
5938
6054
|
throw new TypeError("Failed to execute 'unregisterTool' on 'ModelContext': parameter 1 must be a string or an object with a string name.");
|
|
@@ -5940,17 +6056,17 @@ function na(e) {
|
|
|
5940
6056
|
function V(e) {
|
|
5941
6057
|
return !!e && typeof e == "object" && !Array.isArray(e);
|
|
5942
6058
|
}
|
|
5943
|
-
function
|
|
6059
|
+
function Yr(e) {
|
|
5944
6060
|
if (!V(e)) return null;
|
|
5945
6061
|
const t = e["~standard"];
|
|
5946
6062
|
return V(t) ? t : null;
|
|
5947
6063
|
}
|
|
5948
|
-
function
|
|
5949
|
-
const t =
|
|
6064
|
+
function pa(e) {
|
|
6065
|
+
const t = Yr(e);
|
|
5950
6066
|
return !!(t && t.version === 1 && typeof t.validate == "function");
|
|
5951
6067
|
}
|
|
5952
|
-
function
|
|
5953
|
-
const t =
|
|
6068
|
+
function ha(e) {
|
|
6069
|
+
const t = Yr(e);
|
|
5954
6070
|
return !t || t.version !== 1 || !V(t.jsonSchema) ? !1 : typeof t.jsonSchema.input == "function";
|
|
5955
6071
|
}
|
|
5956
6072
|
function Ue(e) {
|
|
@@ -5959,21 +6075,21 @@ function Ue(e) {
|
|
|
5959
6075
|
vendor: "@mcp-b/webmcp-polyfill-json-schema",
|
|
5960
6076
|
validate(t) {
|
|
5961
6077
|
if (!V(t)) return { issues: [{ message: "expected object arguments" }] };
|
|
5962
|
-
const r =
|
|
6078
|
+
const r = va(t, e);
|
|
5963
6079
|
return r ? { issues: [r] } : { value: t };
|
|
5964
6080
|
}
|
|
5965
6081
|
} };
|
|
5966
6082
|
}
|
|
5967
|
-
function
|
|
5968
|
-
for (const t of
|
|
6083
|
+
function ma(e) {
|
|
6084
|
+
for (const t of aa) try {
|
|
5969
6085
|
const r = e["~standard"].jsonSchema.input({ target: t });
|
|
5970
|
-
return
|
|
6086
|
+
return Xr(r), r;
|
|
5971
6087
|
} catch (r) {
|
|
5972
6088
|
console.warn(`[WebMCPPolyfill] Standard JSON Schema conversion failed for target "${t}":`, r);
|
|
5973
6089
|
}
|
|
5974
6090
|
throw new Error("Failed to convert Standard JSON Schema inputSchema to a JSON Schema object");
|
|
5975
6091
|
}
|
|
5976
|
-
function
|
|
6092
|
+
function ga(e) {
|
|
5977
6093
|
if (e === void 0) {
|
|
5978
6094
|
const r = ze;
|
|
5979
6095
|
return {
|
|
@@ -5981,18 +6097,18 @@ function aa(e) {
|
|
|
5981
6097
|
standardValidator: Ue(r)
|
|
5982
6098
|
};
|
|
5983
6099
|
}
|
|
5984
|
-
if (
|
|
5985
|
-
const r =
|
|
6100
|
+
if (ha(e)) {
|
|
6101
|
+
const r = ma(e);
|
|
5986
6102
|
return {
|
|
5987
6103
|
inputSchema: r,
|
|
5988
6104
|
standardValidator: Ue(r)
|
|
5989
6105
|
};
|
|
5990
6106
|
}
|
|
5991
|
-
if (
|
|
6107
|
+
if (pa(e)) return {
|
|
5992
6108
|
inputSchema: ze,
|
|
5993
6109
|
standardValidator: e
|
|
5994
6110
|
};
|
|
5995
|
-
if (
|
|
6111
|
+
if (Xr(e), Object.keys(e).length === 0) return {
|
|
5996
6112
|
inputSchema: ze,
|
|
5997
6113
|
standardValidator: Ue(ze)
|
|
5998
6114
|
};
|
|
@@ -6005,7 +6121,7 @@ function aa(e) {
|
|
|
6005
6121
|
standardValidator: Ue(t)
|
|
6006
6122
|
};
|
|
6007
6123
|
}
|
|
6008
|
-
function
|
|
6124
|
+
function Xr(e) {
|
|
6009
6125
|
if (!V(e)) throw new Error("inputSchema must be a JSON Schema object");
|
|
6010
6126
|
me(e, "$");
|
|
6011
6127
|
}
|
|
@@ -6054,13 +6170,13 @@ function me(e, t) {
|
|
|
6054
6170
|
throw new Error(`Invalid JSON Schema at ${t}: schema must be JSON-serializable`);
|
|
6055
6171
|
}
|
|
6056
6172
|
}
|
|
6057
|
-
function
|
|
6173
|
+
function ya(e, t) {
|
|
6058
6174
|
if (!e || typeof e != "object") throw new TypeError("registerTool(tool) requires a tool object");
|
|
6059
6175
|
if (typeof e.name != "string" || e.name.length === 0) throw new TypeError('Tool "name" must be a non-empty string');
|
|
6060
6176
|
if (typeof e.description != "string" || e.description.length === 0) throw new TypeError('Tool "description" must be a non-empty string');
|
|
6061
6177
|
if (typeof e.execute != "function") throw new TypeError('Tool "execute" must be a function');
|
|
6062
6178
|
if (t.has(e.name)) throw new Error(`Tool already registered: ${e.name}`);
|
|
6063
|
-
const r =
|
|
6179
|
+
const r = ga(e.inputSchema), n = e.annotations, o = n ? {
|
|
6064
6180
|
...n,
|
|
6065
6181
|
...n.readOnlyHint === "true" ? { readOnlyHint: !0 } : n.readOnlyHint === "false" ? { readOnlyHint: !1 } : {},
|
|
6066
6182
|
...n.destructiveHint === "true" ? { destructiveHint: !0 } : n.destructiveHint === "false" ? { destructiveHint: !1 } : {},
|
|
@@ -6071,21 +6187,21 @@ function la(e, t) {
|
|
|
6071
6187
|
...e,
|
|
6072
6188
|
...o ? { annotations: o } : {},
|
|
6073
6189
|
inputSchema: r.inputSchema,
|
|
6074
|
-
[
|
|
6190
|
+
[Kr]: r.standardValidator
|
|
6075
6191
|
};
|
|
6076
6192
|
}
|
|
6077
|
-
function
|
|
6078
|
-
const r = new
|
|
6193
|
+
function va(e, t) {
|
|
6194
|
+
const r = new ia(t, "2020-12", !0).validate(e);
|
|
6079
6195
|
if (r.valid) return null;
|
|
6080
6196
|
const n = r.errors[r.errors.length - 1];
|
|
6081
6197
|
return n ? { message: n.error } : { message: "Input validation failed" };
|
|
6082
6198
|
}
|
|
6083
|
-
function
|
|
6199
|
+
function wa(e) {
|
|
6084
6200
|
if (!e || e.length === 0) return null;
|
|
6085
6201
|
const t = e.map((r) => V(r) && "key" in r ? r.key : r).map((r) => String(r)).filter((r) => r.length > 0);
|
|
6086
6202
|
return t.length === 0 ? null : t.join(".");
|
|
6087
6203
|
}
|
|
6088
|
-
async function
|
|
6204
|
+
async function ba(e, t) {
|
|
6089
6205
|
let r;
|
|
6090
6206
|
try {
|
|
6091
6207
|
r = await Promise.resolve(t["~standard"].validate(e));
|
|
@@ -6096,26 +6212,26 @@ async function da(e, t) {
|
|
|
6096
6212
|
if (!r.issues || r.issues.length === 0) return null;
|
|
6097
6213
|
const n = r.issues[0];
|
|
6098
6214
|
if (!n) return "Input validation error";
|
|
6099
|
-
const o =
|
|
6215
|
+
const o = wa(n?.path);
|
|
6100
6216
|
return o ? `Input validation error: ${n.message} at ${o}` : `Input validation error: ${n.message}`;
|
|
6101
6217
|
}
|
|
6102
|
-
async function
|
|
6103
|
-
return
|
|
6218
|
+
async function _a(e, t) {
|
|
6219
|
+
return ba(e, t[Kr]);
|
|
6104
6220
|
}
|
|
6105
|
-
function
|
|
6221
|
+
function xa(e) {
|
|
6106
6222
|
return V(e) && Array.isArray(e.content);
|
|
6107
6223
|
}
|
|
6108
|
-
function
|
|
6224
|
+
function Sa(e) {
|
|
6109
6225
|
return e === null || typeof e == "string" || typeof e == "number" || typeof e == "boolean";
|
|
6110
6226
|
}
|
|
6111
6227
|
function _t(e) {
|
|
6112
|
-
return
|
|
6228
|
+
return Sa(e) ? Number.isFinite(e) || typeof e != "number" : Array.isArray(e) ? e.every((t) => _t(t)) : V(e) ? Object.values(e).every((t) => _t(t)) : !1;
|
|
6113
6229
|
}
|
|
6114
|
-
function
|
|
6230
|
+
function Ta(e) {
|
|
6115
6231
|
if (!(!V(e) || !_t(e)))
|
|
6116
6232
|
return e;
|
|
6117
6233
|
}
|
|
6118
|
-
function
|
|
6234
|
+
function Ca(e) {
|
|
6119
6235
|
if (typeof e == "string") return e;
|
|
6120
6236
|
try {
|
|
6121
6237
|
return JSON.stringify(e) ?? String(e);
|
|
@@ -6123,24 +6239,24 @@ function ga(e) {
|
|
|
6123
6239
|
return String(e);
|
|
6124
6240
|
}
|
|
6125
6241
|
}
|
|
6126
|
-
function
|
|
6127
|
-
if (
|
|
6128
|
-
const t =
|
|
6242
|
+
function $a(e) {
|
|
6243
|
+
if (xa(e)) return e;
|
|
6244
|
+
const t = Ta(e);
|
|
6129
6245
|
return {
|
|
6130
6246
|
content: [{
|
|
6131
6247
|
type: "text",
|
|
6132
|
-
text:
|
|
6248
|
+
text: Ca(e)
|
|
6133
6249
|
}],
|
|
6134
6250
|
...t ? { structuredContent: t } : {},
|
|
6135
6251
|
isError: !1
|
|
6136
6252
|
};
|
|
6137
6253
|
}
|
|
6138
|
-
function
|
|
6254
|
+
function Ea(e) {
|
|
6139
6255
|
for (const t of e.content ?? []) if (t.type === "text" && "text" in t && typeof t.text == "string") return t.text;
|
|
6140
6256
|
return null;
|
|
6141
6257
|
}
|
|
6142
|
-
function
|
|
6143
|
-
if (e.isError) throw te(
|
|
6258
|
+
function Pa(e) {
|
|
6259
|
+
if (e.isError) throw te(Ea(e)?.replace(/^Error:\s*/i, "").trim() || Ge);
|
|
6144
6260
|
const t = e.metadata;
|
|
6145
6261
|
if (t && typeof t == "object" && t.willNavigate) return null;
|
|
6146
6262
|
try {
|
|
@@ -6149,7 +6265,7 @@ function wa(e) {
|
|
|
6149
6265
|
throw te(Ge);
|
|
6150
6266
|
}
|
|
6151
6267
|
}
|
|
6152
|
-
function
|
|
6268
|
+
function Ra(e, t) {
|
|
6153
6269
|
return t ? t.aborted ? Promise.reject(te(bt)) : new Promise((r, n) => {
|
|
6154
6270
|
const o = () => {
|
|
6155
6271
|
s(), n(te(bt));
|
|
@@ -6163,13 +6279,13 @@ function ba(e, t) {
|
|
|
6163
6279
|
});
|
|
6164
6280
|
}) : e;
|
|
6165
6281
|
}
|
|
6166
|
-
function
|
|
6282
|
+
function Qr() {
|
|
6167
6283
|
return typeof navigator < "u" ? navigator : null;
|
|
6168
6284
|
}
|
|
6169
|
-
function
|
|
6285
|
+
function en() {
|
|
6170
6286
|
return typeof document < "u" ? document : null;
|
|
6171
6287
|
}
|
|
6172
|
-
function
|
|
6288
|
+
function ka(e, t, r) {
|
|
6173
6289
|
Object.defineProperty(e, t, {
|
|
6174
6290
|
configurable: !0,
|
|
6175
6291
|
enumerable: !0,
|
|
@@ -6177,7 +6293,7 @@ function _a(e, t, r) {
|
|
|
6177
6293
|
value: r
|
|
6178
6294
|
});
|
|
6179
6295
|
}
|
|
6180
|
-
function
|
|
6296
|
+
function fr(e, t) {
|
|
6181
6297
|
Object.defineProperty(e, "modelContext", {
|
|
6182
6298
|
configurable: !0,
|
|
6183
6299
|
enumerable: !0,
|
|
@@ -6186,7 +6302,7 @@ function dr(e, t) {
|
|
|
6186
6302
|
});
|
|
6187
6303
|
}
|
|
6188
6304
|
let Ke = !1;
|
|
6189
|
-
function
|
|
6305
|
+
function Oa(e, t) {
|
|
6190
6306
|
Object.defineProperty(e, "modelContext", {
|
|
6191
6307
|
configurable: !0,
|
|
6192
6308
|
enumerable: !0,
|
|
@@ -6195,24 +6311,24 @@ function Sa(e, t) {
|
|
|
6195
6311
|
}
|
|
6196
6312
|
});
|
|
6197
6313
|
}
|
|
6198
|
-
function
|
|
6199
|
-
const t =
|
|
6314
|
+
function tn(e) {
|
|
6315
|
+
const t = Qr(), r = en();
|
|
6200
6316
|
if (!t && !r || r?.modelContext) return;
|
|
6201
6317
|
const o = t?.modelContext, s = !!o;
|
|
6202
|
-
if (U.installed &&
|
|
6203
|
-
U.previousDocumentModelContextDescriptor = Object.getOwnPropertyDescriptor(r, "modelContext"),
|
|
6318
|
+
if (U.installed && Aa(), r && o) {
|
|
6319
|
+
U.previousDocumentModelContextDescriptor = Object.getOwnPropertyDescriptor(r, "modelContext"), fr(r, o), U.installedDocumentModelContext = !0, U.installed = !0;
|
|
6204
6320
|
return;
|
|
6205
6321
|
}
|
|
6206
6322
|
if (s) return;
|
|
6207
|
-
const i = new
|
|
6208
|
-
if (l[
|
|
6209
|
-
U.previousNavigatorModelContextDescriptor = Object.getOwnPropertyDescriptor(t, "modelContext"), U.previousNavigatorModelContextTestingDescriptor = Object.getOwnPropertyDescriptor(t, "modelContextTesting"), Ke = !1,
|
|
6323
|
+
const i = new ca(), l = i;
|
|
6324
|
+
if (l[la] = !0, r && (U.previousDocumentModelContextDescriptor = Object.getOwnPropertyDescriptor(r, "modelContext"), fr(r, l), U.installedDocumentModelContext = !0), t) {
|
|
6325
|
+
U.previousNavigatorModelContextDescriptor = Object.getOwnPropertyDescriptor(t, "modelContext"), U.previousNavigatorModelContextTestingDescriptor = Object.getOwnPropertyDescriptor(t, "modelContextTesting"), Ke = !1, Oa(t, l), U.installedNavigatorModelContext = !0;
|
|
6210
6326
|
const u = e?.installTestingShim ?? "if-missing", c = !!t.modelContextTesting;
|
|
6211
|
-
(u === "always" || (u === !0 || u === "if-missing") && !c) && (
|
|
6327
|
+
(u === "always" || (u === !0 || u === "if-missing") && !c) && (ka(t, "modelContextTesting", i.getTestingShim()), U.installedNavigatorModelContextTesting = !0);
|
|
6212
6328
|
}
|
|
6213
6329
|
U.installed = !0;
|
|
6214
6330
|
}
|
|
6215
|
-
function
|
|
6331
|
+
function Aa() {
|
|
6216
6332
|
if (!U.installed) return;
|
|
6217
6333
|
const e = (n, o, s) => {
|
|
6218
6334
|
if (s) {
|
|
@@ -6220,60 +6336,54 @@ function xa() {
|
|
|
6220
6336
|
return;
|
|
6221
6337
|
}
|
|
6222
6338
|
delete n[o];
|
|
6223
|
-
}, t =
|
|
6339
|
+
}, t = Qr(), r = en();
|
|
6224
6340
|
r && U.installedDocumentModelContext && e(r, "modelContext", U.previousDocumentModelContextDescriptor), t && U.installedNavigatorModelContext && e(t, "modelContext", U.previousNavigatorModelContextDescriptor), t && U.installedNavigatorModelContextTesting && e(t, "modelContextTesting", U.previousNavigatorModelContextTestingDescriptor), U.installed = !1, U.previousDocumentModelContextDescriptor = void 0, U.previousNavigatorModelContextDescriptor = void 0, U.previousNavigatorModelContextTestingDescriptor = void 0, U.installedDocumentModelContext = !1, U.installedNavigatorModelContext = !1, U.installedNavigatorModelContextTesting = !1, Ke = !1;
|
|
6225
6341
|
}
|
|
6226
6342
|
if (typeof window < "u" && typeof document < "u") {
|
|
6227
6343
|
const e = window.__webMCPPolyfillOptions;
|
|
6228
6344
|
if (e?.autoInitialize !== !1) try {
|
|
6229
|
-
|
|
6345
|
+
tn(e);
|
|
6230
6346
|
} catch (t) {
|
|
6231
6347
|
console.error("[WebMCPPolyfill] Auto-initialization failed:", t);
|
|
6232
6348
|
}
|
|
6233
6349
|
}
|
|
6234
|
-
let
|
|
6235
|
-
const
|
|
6350
|
+
let pr = !1;
|
|
6351
|
+
const cl = () => {
|
|
6236
6352
|
if (ae())
|
|
6237
6353
|
try {
|
|
6238
|
-
if (
|
|
6239
|
-
|
|
6354
|
+
if (pr) return;
|
|
6355
|
+
tn(), ki(), pr = !0;
|
|
6240
6356
|
} catch (e) {
|
|
6241
6357
|
console.warn("[next-sdk] 自动注入 modelContext polyfill 和桥接同步失败:", e);
|
|
6242
6358
|
}
|
|
6243
6359
|
};
|
|
6244
6360
|
export {
|
|
6245
|
-
|
|
6246
|
-
xa as B,
|
|
6247
|
-
Qr as C,
|
|
6248
|
-
V as D,
|
|
6249
|
-
jn as E,
|
|
6250
|
-
ca as F,
|
|
6361
|
+
ol as A,
|
|
6251
6362
|
ve as M,
|
|
6252
|
-
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
|
|
6256
|
-
|
|
6257
|
-
|
|
6258
|
-
|
|
6259
|
-
|
|
6260
|
-
|
|
6261
|
-
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
|
|
6278
|
-
_i as z
|
|
6363
|
+
Wa as W,
|
|
6364
|
+
Ga as a,
|
|
6365
|
+
Ka as b,
|
|
6366
|
+
Ba as c,
|
|
6367
|
+
Ya as d,
|
|
6368
|
+
An as e,
|
|
6369
|
+
Xa as f,
|
|
6370
|
+
fi as g,
|
|
6371
|
+
Qa as h,
|
|
6372
|
+
cl as i,
|
|
6373
|
+
el as j,
|
|
6374
|
+
tl as k,
|
|
6375
|
+
In as l,
|
|
6376
|
+
rl as m,
|
|
6377
|
+
nl as n,
|
|
6378
|
+
Be as o,
|
|
6379
|
+
Ci as p,
|
|
6380
|
+
ll as q,
|
|
6381
|
+
il as r,
|
|
6382
|
+
sl as s,
|
|
6383
|
+
ki as t,
|
|
6384
|
+
Aa as u,
|
|
6385
|
+
tn as v,
|
|
6386
|
+
al as w,
|
|
6387
|
+
V as x,
|
|
6388
|
+
va as y
|
|
6279
6389
|
};
|