@opentiny/next-sdk 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/agent/AgentModelProvider.ts +78 -81
  2. package/agent/type.ts +6 -9
  3. package/agent/utils/getAISDKTools.ts +0 -1
  4. package/agent/utils/getBuiltinMcpTools.ts +7 -7
  5. package/core.ts +0 -3
  6. package/dist/SimulatorMask-BHVXyogh-CARX3Rff.js +361 -0
  7. package/dist/agent/type.d.ts +4 -12
  8. package/dist/agent/utils/getBuiltinMcpTools.d.ts +3 -3
  9. package/dist/core.d.ts +0 -1
  10. package/dist/core.js +16 -17
  11. package/dist/index-R_HIbfUX.js +6604 -0
  12. package/dist/index.d.ts +11 -3
  13. package/dist/index.js +76 -4969
  14. package/dist/{initialize-builtin-WebMCP-HgObT902.js → initialize-builtin-WebMCP-JaoKwVlm.js} +1156 -1037
  15. package/dist/page-tools/a11y/build.d.ts +10 -0
  16. package/dist/page-tools/a11y/config.d.ts +96 -0
  17. package/dist/page-tools/a11y/constants.d.ts +11 -0
  18. package/dist/page-tools/a11y/search.d.ts +17 -0
  19. package/dist/page-tools/a11y/types.d.ts +95 -0
  20. package/dist/page-tools/a11y/utils.d.ts +55 -0
  21. package/dist/page-tools/a11y/vnode.d.ts +40 -0
  22. package/dist/page-tools/a11y-tree.d.ts +9 -99
  23. package/dist/page-tools/configs/console-cloud.d.ts +6 -0
  24. package/dist/page-tools/constants.d.ts +10 -0
  25. package/dist/page-tools/context.d.ts +40 -0
  26. package/dist/page-tools/handlers/browserState.d.ts +8 -0
  27. package/dist/page-tools/handlers/click.d.ts +8 -0
  28. package/dist/page-tools/handlers/executeJavascript.d.ts +8 -0
  29. package/dist/page-tools/handlers/fill.d.ts +8 -0
  30. package/dist/page-tools/handlers/scroll.d.ts +8 -0
  31. package/dist/page-tools/handlers/searchTree.d.ts +9 -0
  32. package/dist/page-tools/handlers/select.d.ts +8 -0
  33. package/dist/page-tools/page-agent-highlight/index.d.ts +21 -0
  34. package/dist/page-tools/page-agent-mask/SimulatorMask.d.ts +16 -0
  35. package/dist/page-tools/page-agent-mask/checkDarkMode.d.ts +5 -0
  36. package/dist/page-tools/page-agent-tool-event.d.ts +26 -0
  37. package/dist/page-tools/page-agent-tool.d.ts +3 -8
  38. package/dist/page-tools/schema.d.ts +44 -0
  39. package/dist/page-tools/tool-config.d.ts +50 -0
  40. package/dist/page-tools/utils/dom.d.ts +6 -0
  41. package/dist/page-tools/utils/scroll.d.ts +15 -0
  42. package/dist/runtime.d.ts +7 -0
  43. package/dist/runtime.js +732 -0
  44. package/dist/utils/builtinProxy.d.ts +1 -1
  45. package/dist/vitest.config.d.ts +2 -0
  46. package/index.ts +35 -5
  47. package/package.json +23 -29
  48. package/page-tools/a11y/build.ts +74 -0
  49. package/page-tools/a11y/config.ts +465 -0
  50. package/page-tools/a11y/constants.ts +131 -0
  51. package/page-tools/a11y/search.ts +127 -0
  52. package/page-tools/a11y/types.ts +105 -0
  53. package/page-tools/a11y/utils.ts +239 -0
  54. package/page-tools/a11y/vnode.ts +439 -0
  55. package/page-tools/a11y-tree.ts +9 -527
  56. package/page-tools/bridge.ts +23 -3
  57. package/page-tools/configs/console-cloud.ts +172 -0
  58. package/page-tools/constants.ts +12 -0
  59. package/page-tools/context.ts +50 -0
  60. package/page-tools/handlers/browserState.ts +12 -0
  61. package/page-tools/handlers/click.ts +30 -0
  62. package/page-tools/handlers/executeJavascript.ts +22 -0
  63. package/page-tools/handlers/fill.ts +65 -0
  64. package/page-tools/handlers/scroll.ts +66 -0
  65. package/page-tools/handlers/searchTree.ts +27 -0
  66. package/page-tools/handlers/select.ts +39 -0
  67. package/page-tools/page-agent-highlight/index.ts +245 -0
  68. package/page-tools/page-agent-mask/SimulatorMask.module.css +14 -0
  69. package/page-tools/page-agent-mask/SimulatorMask.ts +299 -0
  70. package/page-tools/page-agent-mask/checkDarkMode.ts +181 -0
  71. package/page-tools/page-agent-mask/cursor-border.svg +3 -0
  72. package/page-tools/page-agent-mask/cursor-fill.svg +5 -0
  73. package/page-tools/page-agent-mask/cursor.module.css +70 -0
  74. package/page-tools/page-agent-mask/hauwei.svg +25 -0
  75. package/page-tools/page-agent-prompt.md +34 -18
  76. package/page-tools/page-agent-tool-event.ts +113 -0
  77. package/page-tools/page-agent-tool.ts +146 -162
  78. package/page-tools/schema.ts +52 -0
  79. package/page-tools/tool-config.ts +100 -0
  80. package/page-tools/utils/dom.ts +158 -0
  81. package/page-tools/utils/scroll.ts +58 -0
  82. package/runtime.ts +44 -0
  83. package/test/page-tools/a11y/build.test.ts +638 -0
  84. package/test/page-tools/a11y/config.test.ts +370 -0
  85. package/test/page-tools/configs/console-cloud.test.ts +168 -0
  86. package/test/page-tools/page-agent-highlight.test.ts +110 -0
  87. package/test/page-tools/page-agent-tool-dispatch.test.ts +208 -0
  88. package/test/page-tools/page-agent-tool.test.ts +102 -0
  89. package/test/page-tools/tool-config.test.ts +112 -0
  90. package/test/page-tools/utils/dom.test.ts +122 -0
  91. package/utils/builtinProxy.ts +45 -13
  92. package/vite.config.runtime.ts +22 -0
  93. package/vite.config.ts +52 -8
  94. package/vitest.config.ts +10 -0
  95. package/McpSdk.ts +0 -14
  96. package/WebAgent.ts +0 -5
  97. package/WebMcp.ts +0 -26
  98. package/Zod.ts +0 -1
  99. package/dist/McpSdk.d.ts +0 -14
  100. package/dist/SimulatorMask-BHVXyogh-BFEGpD5S.js +0 -1048
  101. package/dist/SimulatorMask-BHVXyogh-CCYbrb84.js +0 -801
  102. package/dist/WebAgent.d.ts +0 -5
  103. package/dist/WebMcp.d.ts +0 -23
  104. package/dist/Zod.d.ts +0 -1
  105. package/dist/index.es.dev.js +0 -59017
  106. package/dist/index.es.js +0 -46795
  107. package/dist/index.umd.dev.js +0 -60355
  108. package/dist/index.umd.js +0 -1248
  109. package/dist/mcpsdk@1.25.3.dev.js +0 -22780
  110. package/dist/mcpsdk@1.25.3.es.dev.js +0 -22778
  111. package/dist/mcpsdk@1.25.3.es.js +0 -16960
  112. package/dist/mcpsdk@1.25.3.js +0 -48
  113. package/dist/transport/ExtensionClientTransport.d.ts +0 -24
  114. package/dist/transport/ExtensionContentServerTransport.d.ts +0 -39
  115. package/dist/transport/ExtensionPageServerTransport.d.ts +0 -36
  116. package/dist/transport/messages.d.ts +0 -9
  117. package/dist/vite.config.mcpSdk.d.ts +0 -2
  118. package/dist/vite.config.webAgent.d.ts +0 -2
  119. package/dist/vite.config.webMcp.d.ts +0 -2
  120. package/dist/vite.config.webMcpFull.d.ts +0 -2
  121. package/dist/vite.config.zod.d.ts +0 -2
  122. package/dist/webagent.dev.js +0 -49360
  123. package/dist/webagent.es.dev.js +0 -49071
  124. package/dist/webagent.es.js +0 -39219
  125. package/dist/webagent.js +0 -642
  126. package/dist/webmcp-full.dev.js +0 -31336
  127. package/dist/webmcp-full.es.dev.js +0 -30283
  128. package/dist/webmcp-full.es.js +0 -22889
  129. package/dist/webmcp-full.js +0 -645
  130. package/dist/webmcp.dev.js +0 -9572
  131. package/dist/webmcp.es.dev.js +0 -8518
  132. package/dist/webmcp.es.js +0 -6727
  133. package/dist/webmcp.js +0 -602
  134. package/dist/zod@3.25.76.dev.js +0 -4037
  135. package/dist/zod@3.25.76.es.dev.js +0 -4033
  136. package/dist/zod@3.25.76.es.js +0 -2945
  137. package/dist/zod@3.25.76.js +0 -1
  138. package/transport/ExtensionClientTransport.ts +0 -100
  139. package/transport/ExtensionContentServerTransport.ts +0 -162
  140. package/transport/ExtensionPageServerTransport.ts +0 -149
  141. package/transport/messages.ts +0 -63
  142. package/vite-build-tsc.ts +0 -63
  143. package/vite-env.d.ts +0 -10
  144. package/vite.config.mcpSdk.ts +0 -28
  145. package/vite.config.webAgent.ts +0 -19
  146. package/vite.config.webMcp.ts +0 -40
  147. package/vite.config.webMcpFull.ts +0 -19
  148. package/vite.config.zod.ts +0 -23
  149. /package/dist/{vite-build-tsc.d.ts → vite.config.runtime.d.ts} +0 -0
@@ -1,19 +1,19 @@
1
- import { MessageChannelServerTransport as St, createTransportPair as rn, MessageChannelClientTransport as xt, createSseProxy as nn, createSocketProxy as on, createStreamProxy as sn, sseOptions as an, streamOptions as ln, MessageChannelTransport as cn } from "@opentiny/next";
2
- import { McpServer as pr } from "@modelcontextprotocol/sdk/server/mcp.js";
3
- import { SetLevelRequestSchema as Ut, SubscribeRequestSchema as un, UnsubscribeRequestSchema as dn, ListResourcesRequestSchema as fn, RootsListChangedNotificationSchema as pn, CallToolResultSchema as hn, ElicitRequestSchema as mn, CreateMessageRequestSchema as gn, ListRootsRequestSchema as yn, ToolListChangedNotificationSchema as vn, PromptListChangedNotificationSchema as wn, ResourceListChangedNotificationSchema as bn, ResourceUpdatedNotificationSchema as _n, LoggingMessageNotificationSchema as Sn, JSONRPCMessageSchema as xn } from "@modelcontextprotocol/sdk/types.js";
4
- import { dynamicTool as hr, jsonSchema as mr, generateText as Lt, streamText as st, stepCountIs as Tn } from "ai";
5
- import { TypeValidationError as Ce, JSONParseError as De, InvalidArgumentError as Cn, AISDKError as qe } from "@ai-sdk/provider";
6
- import * as Dt from "zod/v4";
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 $n } from "@modelcontextprotocol/sdk/inMemory.js";
11
+ import { InMemoryTransport as En } from "@modelcontextprotocol/sdk/inMemory.js";
12
12
  import { createOpenAI as Pn } from "@ai-sdk/openai";
13
- import { createDeepSeek as En } from "@ai-sdk/deepseek";
14
- import { Client as gr } from "@modelcontextprotocol/sdk/client/index.js";
15
- import { WebSocketClientTransport as Rn } from "@modelcontextprotocol/sdk/client/websocket.js";
16
- class Ua {
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 Ba {
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 pr(t || n, r || { capabilities: o }), this.server.server.oninitialized = () => {
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 St(t), await this.transport.listen()), await this.server.connect(this.transport), this.transport;
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(un, t);
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(dn, t);
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(fn, t);
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(pn, t);
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 La = (e, t) => new St(e, t), Da = () => rn(), qa = (e) => e instanceof St, Ha = (e) => e instanceof pr, kn = (e) => {
216
- const t = () => typeof navigator > "u" ? null : navigator.modelContextTesting || null;
215
+ const Ga = (e, t) => new xt(e, t), Ka = () => on(), Ya = (e) => e instanceof xt, Xa = (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.listTools) {
240
- const l = (await s.listTools()).map((u) => {
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 d = new Error('Invalid params: "name" is required and params must be an object');
267
- throw d.code = -32602, d;
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, u = await s.executeTool(i, JSON.stringify(l || {})), c = u && typeof u == "object" && "content" in u ? u : { content: [{ type: "text", text: typeof u == "string" ? u : JSON.stringify(u) }] };
270
- await e.send({ jsonrpc: "2.0", id: n, result: c });
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 && await e.send({
282
- jsonrpc: "2.0",
283
- id: n,
284
- error: { code: s.code || -32e3, message: s.message || String(s) }
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 In {
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 gr(t || n, r || { capabilities: o }), this.client.onclose = () => {
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 nn(p) : s === "socket" ? await on(p) : await sn(p);
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 && kn(f.transport), f;
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 xt(r), await this.client.connect(d)), s === "sse") {
321
- const p = an(n, o);
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 Rn(new URL(`${r}?sessionId=${o}&token=${n}`)), d.sessionId = o, await this.client.connect(d)), s === "stream" || typeof d > "u") {
325
- const p = ln(n, o);
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, hn, r);
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(mn, t);
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(gn, t);
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(yn, t);
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(vn, t);
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(wn, t);
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(bn, t);
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(_n, t);
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(Sn, t);
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 || (On(this.transport) ? await this.transport.terminateSession() : this.transport && typeof this.transport.close == "function" && await this.transport.close());
534
+ t.persisted || (In(this.transport) ? await this.transport.terminateSession() : this.transport && typeof this.transport.close == "function" && await this.transport.close());
527
535
  }
528
536
  }
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
- }
603
- }
604
- }
605
- const Nn = () => typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
606
- const t = Math.random() * 16 | 0;
607
- return (e === "x" ? t : t & 3 | 8).toString(16);
608
- });
537
+ const Qa = (e, t) => new Xe(e, t), el = (e, t) => new Ye(e, t), tl = (e, t) => new St(e, t), rl = (e) => e instanceof Xe, In = (e) => e instanceof Ye, nl = (e) => e instanceof St, ol = (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, zn = 13, fe = 32;
543
+ const qt = 10, Mn = 13, fe = 32;
615
544
  function at(e) {
616
545
  }
617
- function Un(e) {
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 y(h) {
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 j = x(h);
631
- j !== "" && (i.push(j), l = j.length), T();
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, T();
565
+ i.push(h), l += h.length, S();
637
566
  return;
638
567
  }
639
568
  i.push(h);
640
- const m = i.join("");
569
+ const g = i.join("");
641
570
  i.length = 0, l = 0;
642
- const _ = x(m);
643
- _ !== "" && (i.push(_), l = _.length), T();
571
+ const _ = x(g);
572
+ _ !== "" && (i.push(_), l = _.length), S();
644
573
  }
645
- function T() {
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 m = 0;
582
+ let g = 0;
654
583
  if (h.indexOf("\r") === -1) {
655
584
  let _ = h.indexOf(`
656
- `, m);
585
+ `, g);
657
586
  for (; _ !== -1; ) {
658
- if (m === _) {
659
- p > 0 && t({ id: c, event: f, data: d }), c = void 0, d = "", p = 0, f = void 0, m = _ + 1, _ = h.indexOf(`
660
- `, m);
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 j = h.charCodeAt(m);
664
- if (Ht(h, m, j)) {
665
- const O = h.charCodeAt(m + 5) === fe ? m + 6 : m + 5, D = h.slice(O, _);
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: D }), c = void 0, d = "", f = void 0, m = _ + 2, _ = h.indexOf(`
668
- `, m);
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 ? D : `${d}
672
- ${D}`, p++;
673
- } else Ft(h, m, j) ? f = h.slice(
674
- h.charCodeAt(m + 6) === fe ? m + 7 : m + 6,
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, m, _);
677
- m = _ + 1, _ = h.indexOf(`
678
- `, m);
605
+ ) || void 0 : R(h, g, _);
606
+ g = _ + 1, _ = h.indexOf(`
607
+ `, g);
679
608
  }
680
- return h.slice(m);
609
+ return h.slice(g);
681
610
  }
682
- for (; m < h.length; ) {
683
- const _ = h.indexOf("\r", m), j = h.indexOf(`
684
- `, m);
685
- let O = -1;
686
- if (_ !== -1 && j !== -1 ? O = _ < j ? _ : j : _ !== -1 ? _ === h.length - 1 ? O = -1 : O = _ : j !== -1 && (O = j), O === -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, m, O), m = O + 1, h.charCodeAt(m - 1) === zn && h.charCodeAt(m) === qt && m++;
617
+ R(h, g, I), g = I + 1, h.charCodeAt(g - 1) === Mn && h.charCodeAt(g) === qt && g++;
689
618
  }
690
- return h.slice(m);
619
+ return h.slice(g);
691
620
  }
692
- function R(h, m, _) {
693
- if (m === _) {
694
- I();
621
+ function R(h, g, _) {
622
+ if (g === _) {
623
+ O();
695
624
  return;
696
625
  }
697
- const j = h.charCodeAt(m);
698
- if (Ht(h, m, j)) {
699
- const H = h.charCodeAt(m + 5) === fe ? m + 6 : m + 5, G = h.slice(H, _);
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, m, j)) {
705
- f = h.slice(h.charCodeAt(m + 6) === fe ? m + 7 : m + 6, _) || void 0;
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 (j === 105 && h.charCodeAt(m + 1) === 100 && h.charCodeAt(m + 2) === 58) {
709
- const H = h.slice(h.charCodeAt(m + 3) === fe ? m + 4 : m + 3, _);
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 (j === 58) {
642
+ if (N === 58) {
714
643
  if (o) {
715
- const H = h.slice(m, _);
716
- o(H.slice(h.charCodeAt(m + 1) === fe ? 2 : 1));
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 O = h.slice(m, _), D = O.indexOf(":");
721
- if (D === -1) {
722
- M(O, "", O);
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 = O.slice(0, D), Z = O.charCodeAt(D + 1) === fe ? 2 : 1, oe = O.slice(D + Z);
726
- M(K, oe, O);
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, m, _) {
657
+ function M(h, g, _) {
729
658
  switch (h) {
730
659
  case "event":
731
- f = m || void 0;
660
+ f = g || void 0;
732
661
  break;
733
662
  case "data":
734
- d = p === 0 ? m : `${d}
735
- ${m}`, p++;
663
+ d = p === 0 ? g : `${d}
664
+ ${g}`, p++;
736
665
  break;
737
666
  case "id":
738
- c = m.includes("\0") ? void 0 : m;
667
+ c = g.includes("\0") ? void 0 : g;
739
668
  break;
740
669
  case "retry":
741
- /^\d+$/.test(m) ? n(parseInt(m, 10)) : r(
742
- new it(`Invalid \`retry\` value: "${m}"`, {
670
+ /^\d+$/.test(g) ? n(parseInt(g, 10)) : r(
671
+ new it(`Invalid \`retry\` value: "${g}"`, {
743
672
  type: "invalid-retry",
744
- value: m,
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: m, line: _ }
682
+ { type: "unknown-field", field: h, value: g, line: _ }
754
683
  )
755
684
  );
756
685
  break;
757
686
  }
758
687
  }
759
- function I() {
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 z(h = {}) {
695
+ function j(h = {}) {
767
696
  if (h.consume && i.length > 0) {
768
- const m = i.join("");
769
- R(m, 0, m.length);
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: y, reset: z };
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 = Un({
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
- var Ln = ({
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 Cn({
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
- Ln();
826
- function yr(e = globalThis) {
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 Dn(e) {
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 vr(e, ...t) {
846
- const r = new Headers(Dn(e)), n = r.get("user-agent") || "";
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 Zt(e) {
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 wr(e) {
833
+ function br(e) {
876
834
  const { stackTraceLimit: t } = Error;
877
835
  try {
878
836
  Error.stackTraceLimit = 0;
879
837
  } catch {
880
- return Zt(e);
838
+ return Vt(e);
881
839
  }
882
840
  try {
883
- return Zt(e);
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
- ), Vt = {
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
- ...Vt,
887
+ ...Jt,
930
888
  name: e
931
889
  } : {
932
- ...Vt,
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 = N(e.type._def, {
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 br(e, t) {
972
- return N(e.type._def, t);
929
+ function _r(e, t) {
930
+ return z(e.type._def, t);
973
931
  }
974
- var Gn = (e, t) => N(e.innerType._def, t);
975
- function _r(e, t, r) {
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) => _r(e, t, o))
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
- ...N(e.innerType._def, t),
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" ? N(e.schema._def, t) : B();
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
- N(e.left._def, {
989
+ z(e.left._def, {
1032
990
  ...t,
1033
991
  currentPath: [...t.currentPath, "allOf", "0"]
1034
992
  }),
1035
- N(e.right._def, {
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: Jt(t, n),
1215
+ pattern: Wt(t, n),
1258
1216
  ...r && n.errorMessages && { errorMessage: { pattern: r } }
1259
- })) : e.pattern = Jt(t, n);
1217
+ })) : e.pattern = Wt(t, n);
1260
1218
  }
1261
- function Jt(e, t) {
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 xr(e, t) {
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 = N(e.valueType._def, {
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 } = br(
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 xr(e, t);
1359
- const r = N(e.keyType._def, {
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 = N(e.valueType._def, {
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) => N(n._def, {
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 = N(e.innerType._def, {
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 = N(l._def, {
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 N(e.catchall._def, {
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 N(e.innerType._def, t);
1553
- const n = N(e.innerType._def, {
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 N(e.in._def, t);
1518
+ return z(e.in._def, t);
1561
1519
  if (t.pipeStrategy === "output")
1562
- return N(e.out._def, t);
1563
- const r = N(e.in._def, {
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 = N(e.out._def, {
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 N(e.type._def, t);
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: N(e.valueType._def, {
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) => N(r._def, {
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: N(e.rest._def, {
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) => N(r._def, {
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 So() {
1578
+ function xo() {
1621
1579
  return {
1622
1580
  not: B()
1623
1581
  };
1624
1582
  }
1625
- function xo() {
1583
+ function So() {
1626
1584
  return B();
1627
1585
  }
1628
- var To = (e, t) => N(e.innerType._def, t), Co = (e, t, r) => {
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 _r(e, r);
1599
+ return xr(e, r);
1642
1600
  case k.ZodUndefined:
1643
- return So();
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 xr(e, r);
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 xo();
1641
+ return So();
1684
1642
  case k.ZodDefault:
1685
1643
  return Yn(e, r);
1686
1644
  case k.ZodBranded:
1687
- return br(e, r);
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 N(e, t, r = !1) {
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 = Po(o, t);
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" ? N(i(), t) : i;
1730
- if (l && Eo(e, t, l), t.postProcess) {
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 Po = (e, t) => {
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
- }, Eo = (e, t, r) => (e.description && (r.description = e.description), r), Ro = (e) => {
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 = N(
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 = N(
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 Ee(e, {
1771
+ function Pe(e, {
1814
1772
  validate: t
1815
1773
  } = {}) {
1816
1774
  return {
@@ -1823,19 +1781,29 @@ function Ee(e, {
1823
1781
  validate: t
1824
1782
  };
1825
1783
  }
1826
- function Io(e) {
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 Tr(e) {
1830
- return e == null ? Ee({ properties: {}, additionalProperties: !1 }) : Io(e) ? e : "~standard" in e ? e["~standard"].vendor === "zod" ? No(e) : Oo(e) : e();
1831
- }
1832
- function Oo(e) {
1833
- return Ee(
1834
- () => Tt(
1835
- e["~standard"].jsonSchema.input({
1836
- target: "draft-07"
1837
- })
1838
- ),
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" ? zo(e) : Ao(e) : e();
1793
+ }
1794
+ function Ao(e) {
1795
+ return Pe(
1796
+ () => {
1797
+ if (!Io(e))
1798
+ throw new Error(
1799
+ `Standard schema vendor '${e["~standard"].vendor}' does not support JSON Schema conversion.`
1800
+ );
1801
+ return Tt(
1802
+ e["~standard"].jsonSchema.input({
1803
+ target: "draft-07"
1804
+ })
1805
+ );
1806
+ },
1839
1807
  {
1840
1808
  validate: async (t) => {
1841
1809
  const r = await e["~standard"].validate(t);
@@ -1850,10 +1818,13 @@ function Oo(e) {
1850
1818
  }
1851
1819
  );
1852
1820
  }
1821
+ function Io(e) {
1822
+ return e["~standard"].jsonSchema != null;
1823
+ }
1853
1824
  function Mo(e, t) {
1854
1825
  var r;
1855
1826
  const n = (r = void 0) != null ? r : !1;
1856
- return Ee(
1827
+ return Pe(
1857
1828
  // defer json schema creation to avoid unnecessary computation when only validation is needed
1858
1829
  () => ko(e, {
1859
1830
  $refStrategy: n ? "root" : "none"
@@ -1866,13 +1837,13 @@ function Mo(e, t) {
1866
1837
  }
1867
1838
  );
1868
1839
  }
1869
- function Ao(e, t) {
1840
+ function jo(e, t) {
1870
1841
  var r;
1871
1842
  const n = (r = void 0) != null ? r : !1;
1872
- return Ee(
1843
+ return Pe(
1873
1844
  // defer json schema creation to avoid unnecessary computation when only validation is needed
1874
1845
  () => Tt(
1875
- Dt.toJSONSchema(e, {
1846
+ Lt.toJSONSchema(e, {
1876
1847
  target: "draft-7",
1877
1848
  io: "input",
1878
1849
  reused: n ? "ref" : "inline"
@@ -1880,19 +1851,19 @@ function Ao(e, t) {
1880
1851
  ),
1881
1852
  {
1882
1853
  validate: async (o) => {
1883
- const s = await Dt.safeParseAsync(e, o);
1854
+ const s = await Lt.safeParseAsync(e, o);
1884
1855
  return s.success ? { success: !0, value: s.data } : { success: !1, error: s.error };
1885
1856
  }
1886
1857
  }
1887
1858
  );
1888
1859
  }
1889
- function jo(e) {
1860
+ function No(e) {
1890
1861
  return "_zod" in e;
1891
1862
  }
1892
- function No(e, t) {
1893
- return jo(e) ? Ao(e) : Mo(e);
1863
+ function zo(e, t) {
1864
+ return No(e) ? jo(e) : Mo(e);
1894
1865
  }
1895
- async function zo({
1866
+ async function Uo({
1896
1867
  value: e,
1897
1868
  schema: t,
1898
1869
  context: r
@@ -1907,7 +1878,7 @@ async function Ct({
1907
1878
  schema: t,
1908
1879
  context: r
1909
1880
  }) {
1910
- const n = Tr(t);
1881
+ const n = Cr(t);
1911
1882
  try {
1912
1883
  if (n.validate == null)
1913
1884
  return { success: !0, value: e, rawValue: e };
@@ -1925,28 +1896,28 @@ async function Ct({
1925
1896
  };
1926
1897
  }
1927
1898
  }
1928
- async function Cr({
1899
+ async function $r({
1929
1900
  text: e,
1930
1901
  schema: t
1931
1902
  }) {
1932
1903
  try {
1933
- const r = wr(e);
1934
- return t == null ? r : zo({ value: r, schema: t });
1904
+ const r = br(e);
1905
+ return t == null ? r : Uo({ value: r, schema: t });
1935
1906
  } catch (r) {
1936
- throw De.isInstance(r) || Ce.isInstance(r) ? r : new De({ text: e, cause: r });
1907
+ throw Le.isInstance(r) || Ce.isInstance(r) ? r : new Le({ text: e, cause: r });
1937
1908
  }
1938
1909
  }
1939
- async function Uo({
1910
+ async function Do({
1940
1911
  text: e,
1941
1912
  schema: t
1942
1913
  }) {
1943
1914
  try {
1944
- const r = wr(e);
1915
+ const r = br(e);
1945
1916
  return t == null ? { success: !0, value: r, rawValue: r } : await Ct({ value: r, schema: t });
1946
1917
  } catch (r) {
1947
1918
  return {
1948
1919
  success: !1,
1949
- error: De.isInstance(r) ? r : new De({ text: e, cause: r }),
1920
+ error: Le.isInstance(r) ? r : new Le({ text: e, cause: r }),
1950
1921
  rawValue: void 0
1951
1922
  };
1952
1923
  }
@@ -1954,55 +1925,104 @@ async function Uo({
1954
1925
  function Lo(e) {
1955
1926
  return { ...e, type: "dynamic" };
1956
1927
  }
1928
+ var qo = ({
1929
+ maxRetries: e = 2,
1930
+ initialDelayInMs: t = 2e3,
1931
+ backoffFactor: r = 2,
1932
+ abortSignal: n,
1933
+ shouldRetry: o,
1934
+ getDelayInMs: s = ({ exponentialBackoffDelay: l }) => l,
1935
+ createRetryError: i = ({ message: l }) => new Error(l)
1936
+ }) => async (l) => Er(l, {
1937
+ maxRetries: e,
1938
+ delayInMs: t,
1939
+ backoffFactor: r,
1940
+ abortSignal: n,
1941
+ shouldRetry: o,
1942
+ getDelayInMs: s,
1943
+ createRetryError: i
1944
+ });
1945
+ async function Er(e, {
1946
+ maxRetries: t,
1947
+ delayInMs: r,
1948
+ backoffFactor: n,
1949
+ abortSignal: o,
1950
+ shouldRetry: s,
1951
+ getDelayInMs: i,
1952
+ createRetryError: l
1953
+ }, u = []) {
1954
+ try {
1955
+ return await e();
1956
+ } catch (c) {
1957
+ if (Dn(c) || t === 0)
1958
+ throw c;
1959
+ const d = Un(c), p = [...u, c], f = p.length;
1960
+ if (f > t)
1961
+ throw l({
1962
+ message: `Failed after ${f} attempts. Last error: ${d}`,
1963
+ reason: "maxRetriesExceeded",
1964
+ errors: p
1965
+ });
1966
+ if (await s(c) && f <= t)
1967
+ return await Nn(
1968
+ i({
1969
+ error: c,
1970
+ exponentialBackoffDelay: r
1971
+ }),
1972
+ { abortSignal: o }
1973
+ ), Er(
1974
+ e,
1975
+ {
1976
+ maxRetries: t,
1977
+ delayInMs: n * r,
1978
+ backoffFactor: n,
1979
+ abortSignal: o,
1980
+ shouldRetry: s,
1981
+ getDelayInMs: i,
1982
+ createRetryError: l
1983
+ },
1984
+ p
1985
+ );
1986
+ throw f === 1 ? c : l({
1987
+ message: `Failed after ${f} attempts with non-retryable error: '${d}'`,
1988
+ reason: "errorNotRetryable",
1989
+ errors: p
1990
+ });
1991
+ }
1992
+ }
1957
1993
  new TextDecoder();
1958
1994
  let $t;
1959
1995
  $t = globalThis.crypto;
1960
- async function Do(e) {
1996
+ async function Ho(e) {
1961
1997
  return (await $t).getRandomValues(new Uint8Array(e));
1962
1998
  }
1963
- async function qo(e) {
1999
+ async function Fo(e) {
1964
2000
  const t = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~", r = Math.pow(2, 8) - Math.pow(2, 8) % t.length;
1965
2001
  let n = "";
1966
2002
  for (; n.length < e; ) {
1967
- const o = await Do(e - n.length);
2003
+ const o = await Ho(e - n.length);
1968
2004
  for (const s of o)
1969
2005
  s < r && (n += t[s % t.length]);
1970
2006
  }
1971
2007
  return n;
1972
2008
  }
1973
- async function Ho(e) {
1974
- return await qo(e);
2009
+ async function Zo(e) {
2010
+ return await Fo(e);
1975
2011
  }
1976
- async function Fo(e) {
2012
+ async function Vo(e) {
1977
2013
  const t = await (await $t).subtle.digest("SHA-256", new TextEncoder().encode(e));
1978
2014
  return btoa(String.fromCharCode(...new Uint8Array(t))).replace(/\//g, "_").replace(/\+/g, "-").replace(/=/g, "");
1979
2015
  }
1980
- async function Zo(e) {
2016
+ async function Jo(e) {
1981
2017
  if (e || (e = 43), e < 43 || e > 128)
1982
2018
  throw `Expected a length between 43 and 128. Received ${e}.`;
1983
- const t = await Ho(e), r = await Fo(t);
2019
+ const t = await Zo(e), r = await Vo(t);
1984
2020
  return {
1985
2021
  code_verifier: t,
1986
2022
  code_challenge: r
1987
2023
  };
1988
2024
  }
1989
- var Vo = "AI_MCPClientError", $r = `vercel.ai.error.${Vo}`, Jo = Symbol.for($r), Wt, Bt, A = class extends (Bt = qe, Wt = Jo, Bt) {
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 = [
2025
+ var we = "2025-11-25", Wo = [
2006
2026
  we,
2007
2027
  "2025-06-18",
2008
2028
  "2025-03-26",
@@ -2016,7 +2036,7 @@ var Vo = "AI_MCPClientError", $r = `vercel.ai.error.${Vo}`, Jo = Symbol.for($r),
2016
2036
  }), ne = Re, Pr = a.object({
2017
2037
  method: a.string(),
2018
2038
  params: a.optional(Re)
2019
- }), Er = a.object({
2039
+ }), Rr = a.object({
2020
2040
  applyDefaults: a.optional(a.boolean())
2021
2041
  }).loose(), Ko = a.looseObject({
2022
2042
  experimental: a.optional(a.object({}).loose()),
@@ -2038,17 +2058,17 @@ var Vo = "AI_MCPClientError", $r = `vercel.ai.error.${Vo}`, Jo = Symbol.for($r),
2038
2058
  listChanged: a.optional(a.boolean())
2039
2059
  })
2040
2060
  ),
2041
- elicitation: a.optional(Er)
2061
+ elicitation: a.optional(Rr)
2042
2062
  });
2043
2063
  a.object({
2044
- elicitation: a.optional(Er)
2064
+ elicitation: a.optional(Rr)
2045
2065
  }).loose();
2046
2066
  var Yo = ne.extend({
2047
2067
  protocolVersion: a.string(),
2048
2068
  capabilities: Ko,
2049
2069
  serverInfo: Go,
2050
2070
  instructions: a.optional(a.string())
2051
- }), Pt = ne.extend({
2071
+ }), Et = ne.extend({
2052
2072
  nextCursor: a.optional(a.string())
2053
2073
  }), Xo = a.object({
2054
2074
  name: a.string(),
@@ -2071,12 +2091,12 @@ var Yo = ne.extend({
2071
2091
  }).loose()
2072
2092
  ),
2073
2093
  _meta: Bo
2074
- }).loose(), Qo = Pt.extend({
2094
+ }).loose(), Qo = Et.extend({
2075
2095
  tools: a.array(Xo)
2076
- }), Rr = a.object({
2096
+ }), kr = a.object({
2077
2097
  type: a.literal("text"),
2078
2098
  text: a.string()
2079
- }).loose(), kr = a.object({
2099
+ }).loose(), Or = a.object({
2080
2100
  type: a.literal("image"),
2081
2101
  data: a.base64(),
2082
2102
  mimeType: a.string()
@@ -2087,9 +2107,9 @@ var Yo = ne.extend({
2087
2107
  description: a.optional(a.string()),
2088
2108
  mimeType: a.optional(a.string()),
2089
2109
  size: a.optional(a.number())
2090
- }).loose(), ts = Pt.extend({
2110
+ }).loose(), ts = Et.extend({
2091
2111
  resources: a.array(es)
2092
- }), Ir = a.object({
2112
+ }), Ar = a.object({
2093
2113
  /**
2094
2114
  * The URI of this resource.
2095
2115
  */
@@ -2106,14 +2126,14 @@ var Yo = ne.extend({
2106
2126
  * The MIME type of this resource, if known.
2107
2127
  */
2108
2128
  mimeType: a.optional(a.string())
2109
- }).loose(), Or = Ir.extend({
2129
+ }).loose(), Ir = Ar.extend({
2110
2130
  text: a.string()
2111
- }), Mr = Ir.extend({
2131
+ }), Mr = Ar.extend({
2112
2132
  blob: a.base64()
2113
- }), Ar = a.object({
2133
+ }), jr = a.object({
2114
2134
  type: a.literal("resource"),
2115
- resource: a.union([Or, Mr])
2116
- }).loose(), jr = a.object({
2135
+ resource: a.union([Ir, Mr])
2136
+ }).loose(), Nr = a.object({
2117
2137
  type: a.literal("resource_link"),
2118
2138
  uri: a.string(),
2119
2139
  name: a.string(),
@@ -2122,10 +2142,10 @@ var Yo = ne.extend({
2122
2142
  }).loose(), rs = ne.extend({
2123
2143
  content: a.array(
2124
2144
  a.union([
2125
- Rr,
2126
2145
  kr,
2127
- Ar,
2128
- jr
2146
+ Or,
2147
+ jr,
2148
+ Nr
2129
2149
  ])
2130
2150
  ),
2131
2151
  /**
@@ -2147,7 +2167,7 @@ var Yo = ne.extend({
2147
2167
  resourceTemplates: a.array(ns)
2148
2168
  }), ss = ne.extend({
2149
2169
  contents: a.array(
2150
- a.union([Or, Mr])
2170
+ a.union([Ir, Mr])
2151
2171
  )
2152
2172
  }), is = a.object({
2153
2173
  type: a.literal("ref/prompt"),
@@ -2183,15 +2203,15 @@ var cs = ne.extend({
2183
2203
  title: a.optional(a.string()),
2184
2204
  description: a.optional(a.string()),
2185
2205
  arguments: a.optional(a.array(us))
2186
- }).loose(), fs = Pt.extend({
2206
+ }).loose(), fs = Et.extend({
2187
2207
  prompts: a.array(ds)
2188
2208
  }), ps = a.object({
2189
2209
  role: a.union([a.literal("user"), a.literal("assistant")]),
2190
2210
  content: a.union([
2191
- Rr,
2192
2211
  kr,
2193
- Ar,
2194
- jr
2212
+ Or,
2213
+ jr,
2214
+ Nr
2195
2215
  ])
2196
2216
  }).loose(), hs = ne.extend({
2197
2217
  description: a.optional(a.string()),
@@ -2199,7 +2219,7 @@ var cs = ne.extend({
2199
2219
  }), ms = Re.extend({
2200
2220
  message: a.string(),
2201
2221
  requestedSchema: a.unknown()
2202
- }), Gt = Pr.extend({
2222
+ }), Bt = Pr.extend({
2203
2223
  method: a.literal("elicitation/create"),
2204
2224
  params: ms
2205
2225
  }), gs = ne.extend({
@@ -2231,16 +2251,35 @@ var cs = ne.extend({
2231
2251
  method: a.string(),
2232
2252
  params: a.optional(Re)
2233
2253
  })
2234
- ).strict(), mt = a.union([
2254
+ ).strict(), _s = a.union([
2235
2255
  ys,
2236
2256
  bs,
2237
2257
  vs,
2238
2258
  ws
2239
2259
  ]);
2260
+ function mt(e) {
2261
+ return _s.parse(e);
2262
+ }
2240
2263
  async function gt(e) {
2241
- return mt.parse(await Cr({ text: e }));
2264
+ return mt(await $r({ text: e }));
2242
2265
  }
2243
- var Nr = typeof __PACKAGE_VERSION__ < "u" ? __PACKAGE_VERSION__ : "0.0.0-test", F = a.string().url().superRefine((e, t) => {
2266
+ var xs = "AI_MCPClientError", zr = `vercel.ai.error.${xs}`, Ss = Symbol.for(zr), Gt, Kt, A = class extends (Kt = qe, Gt = Ss, Kt) {
2267
+ constructor({
2268
+ name: e = "MCPClientError",
2269
+ message: t,
2270
+ cause: r,
2271
+ data: n,
2272
+ code: o,
2273
+ statusCode: s,
2274
+ url: i,
2275
+ responseBody: l
2276
+ }) {
2277
+ 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;
2278
+ }
2279
+ static isInstance(e) {
2280
+ return qe.hasMarker(e, zr);
2281
+ }
2282
+ }, Ur = typeof __PACKAGE_VERSION__ < "u" ? __PACKAGE_VERSION__ : "0.0.0-test", F = a.string().url().superRefine((e, t) => {
2244
2283
  if (!URL.canParse(e))
2245
2284
  return t.addIssue({
2246
2285
  code: a.ZodIssueCode.custom,
@@ -2253,7 +2292,7 @@ var Nr = typeof __PACKAGE_VERSION__ < "u" ? __PACKAGE_VERSION__ : "0.0.0-test",
2253
2292
  return t.protocol !== "javascript:" && t.protocol !== "data:" && t.protocol !== "vbscript:";
2254
2293
  },
2255
2294
  { message: "URL cannot use javascript:, data:, or vbscript: scheme" }
2256
- ), zr = a.object({
2295
+ ), Dr = a.object({
2257
2296
  access_token: a.string(),
2258
2297
  id_token: a.string().optional(),
2259
2298
  // Optional for OAuth 2.1, but necessary in OpenID Connect
@@ -2263,7 +2302,7 @@ var Nr = typeof __PACKAGE_VERSION__ < "u" ? __PACKAGE_VERSION__ : "0.0.0-test",
2263
2302
  refresh_token: a.string().optional(),
2264
2303
  authorization_server: F.optional(),
2265
2304
  token_endpoint: F.optional()
2266
- }).strip(), _s = a.object({
2305
+ }).strip(), Ts = a.object({
2267
2306
  resource: a.string().url(),
2268
2307
  authorization_servers: a.array(F).optional(),
2269
2308
  jwks_uri: a.string().url().optional(),
@@ -2278,7 +2317,7 @@ var Nr = typeof __PACKAGE_VERSION__ < "u" ? __PACKAGE_VERSION__ : "0.0.0-test",
2278
2317
  authorization_details_types_supported: a.array(a.string()).optional(),
2279
2318
  dpop_signing_alg_values_supported: a.array(a.string()).optional(),
2280
2319
  dpop_bound_access_tokens_required: a.boolean().optional()
2281
- }).passthrough(), Ur = a.object({
2320
+ }).passthrough(), Lr = a.object({
2282
2321
  issuer: a.string(),
2283
2322
  authorization_endpoint: F,
2284
2323
  token_endpoint: F,
@@ -2289,7 +2328,7 @@ var Nr = typeof __PACKAGE_VERSION__ < "u" ? __PACKAGE_VERSION__ : "0.0.0-test",
2289
2328
  code_challenge_methods_supported: a.array(a.string()),
2290
2329
  token_endpoint_auth_methods_supported: a.array(a.string()).optional(),
2291
2330
  token_endpoint_auth_signing_alg_values_supported: a.array(a.string()).optional()
2292
- }).passthrough(), Ss = a.object({
2331
+ }).passthrough(), Cs = a.object({
2293
2332
  issuer: a.string(),
2294
2333
  authorization_endpoint: F,
2295
2334
  token_endpoint: F,
@@ -2303,18 +2342,18 @@ var Nr = typeof __PACKAGE_VERSION__ < "u" ? __PACKAGE_VERSION__ : "0.0.0-test",
2303
2342
  id_token_signing_alg_values_supported: a.array(a.string()),
2304
2343
  claims_supported: a.array(a.string()).optional(),
2305
2344
  token_endpoint_auth_methods_supported: a.array(a.string()).optional()
2306
- }).passthrough(), xs = Ss.merge(
2307
- Ur.pick({
2345
+ }).passthrough(), $s = Cs.merge(
2346
+ Lr.pick({
2308
2347
  code_challenge_methods_supported: !0
2309
2348
  })
2310
- ), Ts = a.object({
2349
+ ), Es = a.object({
2311
2350
  client_id: a.string(),
2312
2351
  client_secret: a.string().optional(),
2313
2352
  client_id_issued_at: a.number().optional(),
2314
2353
  client_secret_expires_at: a.number().optional(),
2315
2354
  authorization_server: F.optional(),
2316
2355
  token_endpoint: F.optional()
2317
- }).strip(), Cs = a.object({
2356
+ }).strip(), Ps = a.object({
2318
2357
  redirect_uris: a.array(F),
2319
2358
  token_endpoint_auth_method: a.string().optional(),
2320
2359
  grant_types: a.array(a.string()).optional(),
@@ -2331,22 +2370,22 @@ var Nr = typeof __PACKAGE_VERSION__ < "u" ? __PACKAGE_VERSION__ : "0.0.0-test",
2331
2370
  software_id: a.string().optional(),
2332
2371
  software_version: a.string().optional(),
2333
2372
  software_statement: a.string().optional()
2334
- }).strip(), $s = a.object({
2373
+ }).strip(), Rs = a.object({
2335
2374
  error: a.string(),
2336
2375
  error_description: a.string().optional(),
2337
2376
  error_uri: a.string().optional()
2338
- }), Ps = Cs.merge(
2339
- Ts
2340
- ), Es = "AI_MCPClientOAuthError", Lr = `vercel.ai.error.${Es}`, Rs = Symbol.for(Lr), Kt, Yt, re = class extends (Yt = qe, Kt = Rs, Yt) {
2377
+ }), ks = Ps.merge(
2378
+ Es
2379
+ ), Os = "AI_MCPClientOAuthError", qr = `vercel.ai.error.${Os}`, As = Symbol.for(qr), Yt, Xt, re = class extends (Xt = qe, Yt = As, Xt) {
2341
2380
  constructor({
2342
2381
  name: e = "MCPClientOAuthError",
2343
2382
  message: t,
2344
2383
  cause: r
2345
2384
  }) {
2346
- super({ name: e, message: t, cause: r }), this[Kt] = !0;
2385
+ super({ name: e, message: t, cause: r }), this[Yt] = !0;
2347
2386
  }
2348
2387
  static isInstance(e) {
2349
- return qe.hasMarker(e, Lr);
2388
+ return qe.hasMarker(e, qr);
2350
2389
  }
2351
2390
  }, ge = class extends re {
2352
2391
  };
@@ -2360,21 +2399,21 @@ Fe.errorCode = "invalid_grant";
2360
2399
  var Ze = class extends re {
2361
2400
  };
2362
2401
  Ze.errorCode = "unauthorized_client";
2363
- var ks = {
2402
+ var Is = {
2364
2403
  [ge.errorCode]: ge,
2365
2404
  [He.errorCode]: He,
2366
2405
  [Fe.errorCode]: Fe,
2367
2406
  [Ze.errorCode]: Ze
2368
2407
  };
2369
- function Is(e) {
2408
+ function Ms(e) {
2370
2409
  const t = typeof e == "string" ? new URL(e) : new URL(e.href);
2371
2410
  return t.hash = "", t;
2372
2411
  }
2373
- function Et(e) {
2412
+ function Pt(e) {
2374
2413
  const t = e.href;
2375
2414
  return e.pathname === "/" && t.endsWith("/") ? t.slice(0, -1) : t;
2376
2415
  }
2377
- function Os({
2416
+ function js({
2378
2417
  requestedResource: e,
2379
2418
  configuredResource: t
2380
2419
  }) {
@@ -2392,7 +2431,7 @@ var Ve = class extends Error {
2392
2431
  function ye(e) {
2393
2432
  return new URL(e).href;
2394
2433
  }
2395
- function Ms(e, t) {
2434
+ function Ns(e, t) {
2396
2435
  return {
2397
2436
  authorizationServerUrl: ye(e),
2398
2437
  tokenEndpoint: ye(
@@ -2400,34 +2439,34 @@ function Ms(e, t) {
2400
2439
  )
2401
2440
  };
2402
2441
  }
2403
- function Xt(e, t) {
2442
+ function Qt(e, t) {
2404
2443
  return {
2405
2444
  ...e,
2406
2445
  authorization_server: t.authorizationServerUrl,
2407
2446
  token_endpoint: t.tokenEndpoint
2408
2447
  };
2409
2448
  }
2410
- function Dr(e, t) {
2449
+ function Hr(e, t) {
2411
2450
  return {
2412
2451
  ...e,
2413
2452
  authorization_server: t.authorizationServerUrl,
2414
2453
  token_endpoint: t.tokenEndpoint
2415
2454
  };
2416
2455
  }
2417
- function Qt(e) {
2456
+ function er(e) {
2418
2457
  if (!(!e?.authorization_server || !e.token_endpoint))
2419
2458
  return {
2420
2459
  authorizationServerUrl: ye(e.authorization_server),
2421
2460
  tokenEndpoint: ye(e.token_endpoint)
2422
2461
  };
2423
2462
  }
2424
- async function er({
2463
+ async function tr({
2425
2464
  provider: e,
2426
2465
  clientInformation: t,
2427
2466
  tokens: r
2428
2467
  }) {
2429
2468
  var n;
2430
- const o = Qt(r);
2469
+ const o = er(r);
2431
2470
  if (o)
2432
2471
  return o;
2433
2472
  const s = await ((n = e.authorizationServerInformation) == null ? void 0 : n.call(e));
@@ -2438,9 +2477,9 @@ async function er({
2438
2477
  tokenEndpoint: ye(
2439
2478
  s.tokenEndpoint
2440
2479
  )
2441
- } : Qt(t);
2480
+ } : er(t);
2442
2481
  }
2443
- async function As({
2482
+ async function zs({
2444
2483
  provider: e,
2445
2484
  clientInformation: t,
2446
2485
  authorizationServerInformation: r
@@ -2448,13 +2487,13 @@ async function As({
2448
2487
  return e.saveAuthorizationServerInformation ? (await e.saveAuthorizationServerInformation(
2449
2488
  r
2450
2489
  ), !0) : e.saveClientInformation ? (await e.saveClientInformation(
2451
- Dr(
2490
+ Hr(
2452
2491
  t,
2453
2492
  r
2454
2493
  )
2455
2494
  ), !0) : !1;
2456
2495
  }
2457
- function js(e, t) {
2496
+ function Us(e, t) {
2458
2497
  if (!t)
2459
2498
  return;
2460
2499
  const r = new URL(e).origin;
@@ -2463,7 +2502,7 @@ function js(e, t) {
2463
2502
  message: `OAuth protected resource metadata URL ${t.href} must have the same origin as the MCP server URL ${r}`
2464
2503
  });
2465
2504
  }
2466
- function tr({
2505
+ function rr({
2467
2506
  storedAuthorizationServerInformation: e,
2468
2507
  currentAuthorizationServerInformation: t
2469
2508
  }) {
@@ -2488,7 +2527,7 @@ function Je(e) {
2488
2527
  return;
2489
2528
  }
2490
2529
  }
2491
- function Ns(e, t = "", r = {}) {
2530
+ function Ds(e, t = "", r = {}) {
2492
2531
  return t.endsWith("/") && (t = t.slice(0, -1)), r.prependPathname ? `${t}/.well-known/${e}` : `/.well-known/${e}${t}`;
2493
2532
  }
2494
2533
  async function Rt(e, t, r = fetch) {
@@ -2500,33 +2539,33 @@ async function Rt(e, t, r = fetch) {
2500
2539
  throw n;
2501
2540
  }
2502
2541
  }
2503
- async function rr(e, t, r = fetch) {
2542
+ async function nr(e, t, r = fetch) {
2504
2543
  return await Rt(e, {
2505
2544
  "MCP-Protocol-Version": t
2506
2545
  }, r);
2507
2546
  }
2508
- function zs(e, t) {
2547
+ function Ls(e, t) {
2509
2548
  return !e || e.status >= 400 && e.status < 500 && t !== "/";
2510
2549
  }
2511
- async function Us(e, t, r, n) {
2550
+ async function qs(e, t, r, n) {
2512
2551
  var o, s;
2513
2552
  const i = new URL(e), l = (o = n?.protocolVersion) != null ? o : we;
2514
2553
  let u;
2515
2554
  if (n?.metadataUrl)
2516
2555
  u = new URL(n.metadataUrl);
2517
2556
  else {
2518
- const d = Ns(t, i.pathname);
2557
+ const d = Ds(t, i.pathname);
2519
2558
  u = new URL(d, (s = n?.metadataServerUrl) != null ? s : i), u.search = i.search;
2520
2559
  }
2521
- let c = await rr(u, l, r);
2522
- if (!n?.metadataUrl && zs(c, i.pathname)) {
2560
+ let c = await nr(u, l, r);
2561
+ if (!n?.metadataUrl && Ls(c, i.pathname)) {
2523
2562
  const d = new URL(`/.well-known/${t}`, i);
2524
- c = await rr(d, l, r);
2563
+ c = await nr(d, l, r);
2525
2564
  }
2526
2565
  return c;
2527
2566
  }
2528
- async function Ls(e, t, r = fetch) {
2529
- const n = await Us(
2567
+ async function Hs(e, t, r = fetch) {
2568
+ const n = await qs(
2530
2569
  e,
2531
2570
  "oauth-protected-resource",
2532
2571
  r,
@@ -2543,9 +2582,9 @@ async function Ls(e, t, r = fetch) {
2543
2582
  throw new Error(
2544
2583
  `HTTP ${n.status} trying to load well-known OAuth protected resource metadata.`
2545
2584
  );
2546
- return _s.parse(await n.json());
2585
+ return Ts.parse(await n.json());
2547
2586
  }
2548
- function Ds(e) {
2587
+ function Fs(e) {
2549
2588
  const t = typeof e == "string" ? new URL(e) : e, r = t.pathname !== "/", n = t.origin, o = [];
2550
2589
  if (!r)
2551
2590
  return o.push({
@@ -2581,18 +2620,18 @@ function Ds(e) {
2581
2620
  expectedIssuer: i
2582
2621
  }), o;
2583
2622
  }
2584
- function nr(e, t) {
2623
+ function or(e, t) {
2585
2624
  if (e.issuer !== t)
2586
2625
  throw new re({
2587
2626
  message: `OAuth authorization server metadata issuer ${e.issuer} does not match expected issuer ${t}`
2588
2627
  });
2589
2628
  }
2590
- async function qs(e, {
2629
+ async function Zs(e, {
2591
2630
  fetchFn: t = fetch,
2592
2631
  protocolVersion: r = we
2593
2632
  } = {}) {
2594
2633
  var n;
2595
- const o = { "MCP-Protocol-Version": r }, s = Ds(e);
2634
+ const o = { "MCP-Protocol-Version": r }, s = Fs(e);
2596
2635
  for (const { url: i, type: l, expectedIssuer: u } of s) {
2597
2636
  const c = await Rt(i, o, t);
2598
2637
  if (c) {
@@ -2604,13 +2643,13 @@ async function qs(e, {
2604
2643
  );
2605
2644
  }
2606
2645
  if (l === "oauth") {
2607
- const d = Ur.parse(await c.json());
2608
- return nr(d, u), d;
2646
+ const d = Lr.parse(await c.json());
2647
+ return or(d, u), d;
2609
2648
  } else {
2610
- const d = xs.parse(
2649
+ const d = $s.parse(
2611
2650
  await c.json()
2612
2651
  );
2613
- if (nr(d, u), !((n = d.code_challenge_methods_supported) != null && n.includes("S256")))
2652
+ if (or(d, u), !((n = d.code_challenge_methods_supported) != null && n.includes("S256")))
2614
2653
  throw new Error(
2615
2654
  `Incompatible OIDC provider at ${i}: does not support S256 code challenge method required by MCP specification`
2616
2655
  );
@@ -2619,7 +2658,7 @@ async function qs(e, {
2619
2658
  }
2620
2659
  }
2621
2660
  }
2622
- async function Hs(e, {
2661
+ async function Vs(e, {
2623
2662
  metadata: t,
2624
2663
  clientInformation: r,
2625
2664
  redirectUrl: n,
@@ -2640,36 +2679,36 @@ async function Hs(e, {
2640
2679
  );
2641
2680
  } else
2642
2681
  c = new URL("/authorize", e);
2643
- const d = await Zo(), p = d.code_verifier, f = d.code_challenge;
2682
+ const d = await Jo(), p = d.code_verifier, f = d.code_challenge;
2644
2683
  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
2684
  "code_challenge_method",
2646
2685
  u
2647
2686
  ), 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
2687
  "resource",
2649
- Et(i)
2688
+ Pt(i)
2650
2689
  ), { authorizationUrl: c, codeVerifier: p };
2651
2690
  }
2652
- function qr(e, t) {
2691
+ function Fr(e, t) {
2653
2692
  const r = e.client_secret !== void 0;
2654
2693
  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
2694
  }
2656
- function Hr(e, t, r, n) {
2695
+ function Zr(e, t, r, n) {
2657
2696
  const { client_id: o, client_secret: s } = t;
2658
2697
  switch (e) {
2659
2698
  case "client_secret_basic":
2660
- Fs(o, s, r);
2699
+ Js(o, s, r);
2661
2700
  return;
2662
2701
  case "client_secret_post":
2663
- Zs(o, s, n);
2702
+ Ws(o, s, n);
2664
2703
  return;
2665
2704
  case "none":
2666
- Vs(o, n);
2705
+ Bs(o, n);
2667
2706
  return;
2668
2707
  default:
2669
2708
  throw new Error(`Unsupported client authentication method: ${e}`);
2670
2709
  }
2671
2710
  }
2672
- function Fs(e, t, r) {
2711
+ function Js(e, t, r) {
2673
2712
  if (!t)
2674
2713
  throw new Error(
2675
2714
  "client_secret_basic authentication requires a client_secret"
@@ -2677,18 +2716,18 @@ function Fs(e, t, r) {
2677
2716
  const n = btoa(`${e}:${t}`);
2678
2717
  r.set("Authorization", `Basic ${n}`);
2679
2718
  }
2680
- function Zs(e, t, r) {
2719
+ function Ws(e, t, r) {
2681
2720
  r.set("client_id", e), t && r.set("client_secret", t);
2682
2721
  }
2683
- function Vs(e, t) {
2722
+ function Bs(e, t) {
2684
2723
  t.set("client_id", e);
2685
2724
  }
2686
2725
  async function kt(e) {
2687
2726
  const t = e instanceof Response ? e.status : void 0, r = e instanceof Response ? await e.text() : e;
2688
2727
  try {
2689
- const n = $s.parse(
2690
- await Cr({ text: r })
2691
- ), { error: o, error_description: s, error_uri: i } = n, l = ks[o] || ge;
2728
+ const n = Rs.parse(
2729
+ await $r({ text: r })
2730
+ ), { error: o, error_description: s, error_uri: i } = n, l = Is[o] || ge;
2692
2731
  return new l({
2693
2732
  message: s || "",
2694
2733
  cause: i
@@ -2698,7 +2737,7 @@ async function kt(e) {
2698
2737
  return new ge({ message: o });
2699
2738
  }
2700
2739
  }
2701
- async function Js(e, {
2740
+ async function Gs(e, {
2702
2741
  metadata: t,
2703
2742
  clientInformation: r,
2704
2743
  authorizationCode: n,
@@ -2731,23 +2770,23 @@ async function Js(e, {
2731
2770
  t
2732
2771
  );
2733
2772
  else {
2734
- const T = (c = t?.token_endpoint_auth_methods_supported) != null ? c : [], x = qr(
2773
+ const S = (c = t?.token_endpoint_auth_methods_supported) != null ? c : [], x = Fr(
2735
2774
  r,
2736
- T
2775
+ S
2737
2776
  );
2738
- Hr(x, r, f, v);
2777
+ Zr(x, r, f, v);
2739
2778
  }
2740
- i && v.set("resource", Et(i));
2741
- const y = await (u ?? fetch)(p, {
2779
+ i && v.set("resource", Pt(i));
2780
+ const m = await (u ?? fetch)(p, {
2742
2781
  method: "POST",
2743
2782
  headers: f,
2744
2783
  body: v
2745
2784
  });
2746
- if (!y.ok)
2747
- throw await kt(y);
2748
- return zr.parse(await y.json());
2785
+ if (!m.ok)
2786
+ throw await kt(m);
2787
+ return Dr.parse(await m.json());
2749
2788
  }
2750
- async function Ws(e, {
2789
+ async function Ks(e, {
2751
2790
  metadata: t,
2752
2791
  clientInformation: r,
2753
2792
  refreshToken: n,
@@ -2780,13 +2819,13 @@ async function Ws(e, {
2780
2819
  t
2781
2820
  );
2782
2821
  else {
2783
- const v = (l = t?.token_endpoint_auth_methods_supported) != null ? l : [], y = qr(
2822
+ const v = (l = t?.token_endpoint_auth_methods_supported) != null ? l : [], m = Fr(
2784
2823
  r,
2785
2824
  v
2786
2825
  );
2787
- Hr(y, r, d, p);
2826
+ Zr(m, r, d, p);
2788
2827
  }
2789
- o && p.set("resource", Et(o));
2828
+ o && p.set("resource", Pt(o));
2790
2829
  const f = await (i ?? fetch)(c, {
2791
2830
  method: "POST",
2792
2831
  headers: d,
@@ -2794,12 +2833,12 @@ async function Ws(e, {
2794
2833
  });
2795
2834
  if (!f.ok)
2796
2835
  throw await kt(f);
2797
- return zr.parse({
2836
+ return Dr.parse({
2798
2837
  refresh_token: n,
2799
2838
  ...await f.json()
2800
2839
  });
2801
2840
  }
2802
- async function Bs(e, {
2841
+ async function Ys(e, {
2803
2842
  metadata: t,
2804
2843
  clientMetadata: r,
2805
2844
  fetchFn: n
@@ -2822,7 +2861,7 @@ async function Bs(e, {
2822
2861
  });
2823
2862
  if (!s.ok)
2824
2863
  throw await kt(s);
2825
- return Ps.parse(await s.json());
2864
+ return ks.parse(await s.json());
2826
2865
  }
2827
2866
  async function yt(e, t) {
2828
2867
  var r, n;
@@ -2836,15 +2875,15 @@ async function yt(e, t) {
2836
2875
  throw o;
2837
2876
  }
2838
2877
  }
2839
- async function Gs(e, t, r) {
2840
- const n = Is(e);
2878
+ async function Xs(e, t, r) {
2879
+ const n = Ms(e);
2841
2880
  if (t.validateResourceURL)
2842
2881
  return await t.validateResourceURL(
2843
2882
  n,
2844
2883
  r?.resource
2845
2884
  );
2846
2885
  if (r) {
2847
- if (!Os({
2886
+ if (!js({
2848
2887
  requestedResource: n,
2849
2888
  configuredResource: r.resource
2850
2889
  }))
@@ -2864,9 +2903,9 @@ async function ut(e, {
2864
2903
  }) {
2865
2904
  var l, u;
2866
2905
  let c, d;
2867
- js(t, s);
2906
+ Us(t, s);
2868
2907
  try {
2869
- c = await Ls(
2908
+ c = await Hs(
2870
2909
  t,
2871
2910
  { resourceMetadataUrl: s },
2872
2911
  i
@@ -2874,7 +2913,7 @@ async function ut(e, {
2874
2913
  } catch {
2875
2914
  }
2876
2915
  d || (d = t);
2877
- const p = await Gs(
2916
+ const p = await Xs(
2878
2917
  t,
2879
2918
  e,
2880
2919
  c
@@ -2884,14 +2923,14 @@ async function ut(e, {
2884
2923
  t,
2885
2924
  d
2886
2925
  ));
2887
- const f = await qs(
2926
+ const f = await Zs(
2888
2927
  d,
2889
2928
  {
2890
2929
  fetchFn: i
2891
2930
  }
2892
- ), v = Ms(d, f);
2893
- let y = await Promise.resolve(e.clientInformation());
2894
- if (!y) {
2931
+ ), v = Ns(d, f);
2932
+ let m = await Promise.resolve(e.clientInformation());
2933
+ if (!m) {
2895
2934
  if (r !== void 0)
2896
2935
  throw new Error(
2897
2936
  "Existing OAuth client information is required when exchanging an authorization code"
@@ -2900,15 +2939,15 @@ async function ut(e, {
2900
2939
  throw new Error(
2901
2940
  "OAuth client information must be saveable for dynamic registration"
2902
2941
  );
2903
- const z = await Bs(d, {
2942
+ const j = await Ys(d, {
2904
2943
  metadata: f,
2905
2944
  clientMetadata: e.clientMetadata,
2906
2945
  fetchFn: i
2907
2946
  });
2908
- y = Dr(
2909
- z,
2947
+ m = Hr(
2948
+ j,
2910
2949
  v
2911
- ), await e.saveClientInformation(y);
2950
+ ), await e.saveClientInformation(m);
2912
2951
  }
2913
2952
  if (r !== void 0) {
2914
2953
  if (e.storedState) {
@@ -2918,21 +2957,21 @@ async function ut(e, {
2918
2957
  "OAuth state parameter mismatch - possible CSRF attack"
2919
2958
  );
2920
2959
  }
2921
- const z = await er({
2960
+ const j = await tr({
2922
2961
  provider: e,
2923
- clientInformation: y
2962
+ clientInformation: m
2924
2963
  });
2925
- if (!z)
2964
+ if (!j)
2926
2965
  throw new re({
2927
2966
  message: "Stored OAuth authorization server metadata is required when exchanging an authorization code"
2928
2967
  });
2929
- tr({
2930
- storedAuthorizationServerInformation: z,
2968
+ rr({
2969
+ storedAuthorizationServerInformation: j,
2931
2970
  currentAuthorizationServerInformation: v
2932
2971
  });
2933
- const h = await e.codeVerifier(), m = await Js(d, {
2972
+ const h = await e.codeVerifier(), g = await Gs(d, {
2934
2973
  metadata: f,
2935
- clientInformation: y,
2974
+ clientInformation: m,
2936
2975
  authorizationCode: r,
2937
2976
  codeVerifier: h,
2938
2977
  redirectUri: e.redirectUrl,
@@ -2941,35 +2980,35 @@ async function ut(e, {
2941
2980
  fetchFn: i
2942
2981
  });
2943
2982
  return await e.saveTokens(
2944
- Xt(
2945
- m,
2983
+ Qt(
2984
+ g,
2946
2985
  v
2947
2986
  )
2948
2987
  ), "AUTHORIZED";
2949
2988
  }
2950
- const T = await e.tokens();
2951
- if (T?.refresh_token) {
2952
- const z = await er({
2989
+ const S = await e.tokens();
2990
+ if (S?.refresh_token) {
2991
+ const j = await tr({
2953
2992
  provider: e,
2954
- clientInformation: y,
2955
- tokens: T
2993
+ clientInformation: m,
2994
+ tokens: S
2956
2995
  });
2957
- z ? tr({
2958
- storedAuthorizationServerInformation: z,
2996
+ j ? rr({
2997
+ storedAuthorizationServerInformation: j,
2959
2998
  currentAuthorizationServerInformation: v
2960
2999
  }) : await ((u = e.invalidateCredentials) == null ? void 0 : u.call(e, "tokens"));
2961
3000
  try {
2962
- if (z) {
2963
- const h = await Ws(d, {
3001
+ if (j) {
3002
+ const h = await Ks(d, {
2964
3003
  metadata: f,
2965
- clientInformation: y,
2966
- refreshToken: T.refresh_token,
3004
+ clientInformation: m,
3005
+ refreshToken: S.refresh_token,
2967
3006
  resource: p,
2968
3007
  addClientAuthentication: e.addClientAuthentication,
2969
3008
  fetchFn: i
2970
3009
  });
2971
3010
  return await e.saveTokens(
2972
- Xt(
3011
+ Qt(
2973
3012
  h,
2974
3013
  v
2975
3014
  )
@@ -2984,20 +3023,20 @@ async function ut(e, {
2984
3023
  }
2985
3024
  const x = e.state ? await e.state() : void 0;
2986
3025
  x && e.saveState && await e.saveState(x);
2987
- const { authorizationUrl: R, codeVerifier: M } = await Hs(
3026
+ const { authorizationUrl: R, codeVerifier: M } = await Vs(
2988
3027
  d,
2989
3028
  {
2990
3029
  metadata: f,
2991
- clientInformation: y,
3030
+ clientInformation: m,
2992
3031
  state: x,
2993
3032
  redirectUrl: e.redirectUrl,
2994
3033
  scope: o || e.clientMetadata.scope,
2995
3034
  resource: p
2996
3035
  }
2997
3036
  );
2998
- if (!await As({
3037
+ if (!await zs({
2999
3038
  provider: e,
3000
- clientInformation: y,
3039
+ clientInformation: m,
3001
3040
  authorizationServerInformation: v
3002
3041
  }))
3003
3042
  throw new re({
@@ -3005,10 +3044,10 @@ async function ut(e, {
3005
3044
  });
3006
3045
  return await e.saveCodeVerifier(M), await e.redirectToAuthorization(R), "REDIRECT";
3007
3046
  }
3008
- function Ks(e) {
3047
+ function Qs(e) {
3009
3048
  return e === void 0 || e === "message";
3010
3049
  }
3011
- var Ys = class {
3050
+ var ei = class {
3012
3051
  constructor({
3013
3052
  url: e,
3014
3053
  headers: t,
@@ -3032,10 +3071,10 @@ var Ys = class {
3032
3071
  const n = await this.authProvider.tokens();
3033
3072
  n?.access_token && (r.Authorization = `Bearer ${n.access_token}`);
3034
3073
  }
3035
- return vr(
3074
+ return wr(
3036
3075
  r,
3037
- `ai-sdk/${Nr}`,
3038
- yr()
3076
+ `ai-sdk/${Ur}`,
3077
+ vr()
3039
3078
  );
3040
3079
  }
3041
3080
  async start() {
@@ -3061,60 +3100,60 @@ var Ys = class {
3061
3100
  resourceMetadataUrl: this.resourceMetadataUrl,
3062
3101
  fetchFn: this.fetchFn
3063
3102
  }) !== "AUTHORIZED") {
3064
- const T = new Ve();
3065
- return (s = this.onerror) == null || s.call(this, T), t(T);
3103
+ const S = new Ve();
3104
+ return (s = this.onerror) == null || s.call(this, S), t(S);
3066
3105
  }
3067
- } catch (y) {
3068
- return (i = this.onerror) == null || i.call(this, y), t(y);
3106
+ } catch (m) {
3107
+ return (i = this.onerror) == null || i.call(this, m), t(m);
3069
3108
  }
3070
3109
  return r(!0);
3071
3110
  }
3072
3111
  if (!d.ok || !d.body) {
3073
- let y = `MCP SSE Transport Error: ${d.status} ${d.statusText}`;
3074
- d.status === 405 && (y += ". This server does not support SSE transport. Try using `http` transport instead");
3075
- const T = new A({
3076
- message: y
3112
+ let m = `MCP SSE Transport Error: ${d.status} ${d.statusText}`;
3113
+ d.status === 405 && (m += ". This server does not support SSE transport. Try using `http` transport instead");
3114
+ const S = new A({
3115
+ message: m
3077
3116
  });
3078
- return (l = this.onerror) == null || l.call(this, T), t(T);
3117
+ return (l = this.onerror) == null || l.call(this, S), t(S);
3079
3118
  }
3080
3119
  const f = d.body.pipeThrough(new TextDecoderStream()).pipeThrough(new ft()).getReader(), v = async () => {
3081
- var y, T, x, R, M;
3120
+ var m, S, x, R, M;
3082
3121
  try {
3083
3122
  for (; ; ) {
3084
- const { done: I, value: z } = await f.read();
3085
- if (I) {
3123
+ const { done: O, value: j } = await f.read();
3124
+ if (O) {
3086
3125
  if (this.connected)
3087
3126
  throw this.connected = !1, new A({
3088
3127
  message: "MCP SSE Transport Error: Connection closed unexpectedly"
3089
3128
  });
3090
3129
  return;
3091
3130
  }
3092
- const { event: h, data: m } = z;
3131
+ const { event: h, data: g } = j;
3093
3132
  if (h === "endpoint") {
3094
3133
  if (this.endpoint)
3095
3134
  continue;
3096
- const _ = new URL(m, this.url);
3135
+ const _ = new URL(g, this.url);
3097
3136
  if (_.origin !== this.url.origin)
3098
- throw this.connected = !1, this.endpoint = void 0, (y = this.sseConnection) == null || y.close(), (T = this.abortController) == null || T.abort(), new A({
3137
+ throw this.connected = !1, this.endpoint = void 0, (m = this.sseConnection) == null || m.close(), (S = this.abortController) == null || S.abort(), new A({
3099
3138
  message: `MCP SSE Transport Error: Endpoint origin does not match connection origin: ${_.origin}`
3100
3139
  });
3101
3140
  this.endpoint = _, this.connected = !0, e();
3102
- } else if (Ks(h))
3141
+ } else if (Qs(h))
3103
3142
  try {
3104
- const _ = await gt(m);
3143
+ const _ = await gt(g);
3105
3144
  (x = this.onmessage) == null || x.call(this, _);
3106
3145
  } catch (_) {
3107
- const j = new A({
3146
+ const N = new A({
3108
3147
  message: "MCP SSE Transport Error: Failed to parse message",
3109
3148
  cause: _
3110
3149
  });
3111
- (R = this.onerror) == null || R.call(this, j);
3150
+ (R = this.onerror) == null || R.call(this, N);
3112
3151
  }
3113
3152
  }
3114
- } catch (I) {
3115
- if (I instanceof Error && I.name === "AbortError")
3153
+ } catch (O) {
3154
+ if (O instanceof Error && O.name === "AbortError")
3116
3155
  return;
3117
- (M = this.onerror) == null || M.call(this, I), t(I);
3156
+ (M = this.onerror) == null || M.call(this, O), t(O);
3118
3157
  }
3119
3158
  };
3120
3159
  this.sseConnection = {
@@ -3183,10 +3222,10 @@ var Ys = class {
3183
3222
  await r();
3184
3223
  }
3185
3224
  };
3186
- function or(e) {
3225
+ function sr(e) {
3187
3226
  return e === void 0 || e === "message";
3188
3227
  }
3189
- var Xs = class {
3228
+ var ti = class {
3190
3229
  constructor({
3191
3230
  url: e,
3192
3231
  headers: t,
@@ -3215,10 +3254,10 @@ var Xs = class {
3215
3254
  const n = await this.authProvider.tokens();
3216
3255
  n?.access_token && (r.Authorization = `Bearer ${n.access_token}`);
3217
3256
  }
3218
- return vr(
3257
+ return wr(
3219
3258
  r,
3220
- `ai-sdk/${Nr}`,
3221
- yr()
3259
+ `ai-sdk/${Ur}`,
3260
+ vr()
3222
3261
  );
3223
3262
  }
3224
3263
  /**
@@ -3238,7 +3277,7 @@ var Xs = class {
3238
3277
  throw new A({
3239
3278
  message: "MCP HTTP Transport Error: Transport already started. Note: client.connect() calls start() automatically."
3240
3279
  });
3241
- this.abortController = new AbortController(), this.openInboundSse();
3280
+ this.abortController = new AbortController(), this.startInboundSse();
3242
3281
  }
3243
3282
  async close() {
3244
3283
  var e, t, r;
@@ -3283,50 +3322,51 @@ var Xs = class {
3283
3322
  return t(!0);
3284
3323
  }
3285
3324
  if (f.status === 202) {
3286
- this.inboundSseConnection || this.openInboundSse();
3325
+ this.inboundSseConnection || this.startInboundSse();
3287
3326
  return;
3288
3327
  }
3289
3328
  if (!f.ok) {
3290
3329
  const R = await f.text().catch(() => null);
3291
3330
  let M = `MCP HTTP Transport Error: POSTing to endpoint (HTTP ${f.status}): ${R}`;
3292
3331
  f.status === 404 && (M += ". This server does not support HTTP transport. Try using `sse` transport instead");
3293
- const I = new A({
3332
+ const O = new A({
3294
3333
  message: M,
3295
3334
  statusCode: f.status,
3296
3335
  url: this.url.href,
3297
3336
  responseBody: R ?? void 0
3298
3337
  });
3299
- throw (s = this.onerror) == null || s.call(this, I), I;
3338
+ throw (s = this.onerror) == null || s.call(this, O), O;
3300
3339
  }
3301
3340
  if (!("id" in e))
3302
3341
  return;
3303
- const T = f.headers.get("content-type") || "";
3304
- if (T.includes("application/json")) {
3305
- const R = await f.json(), M = Array.isArray(R) ? R.map((I) => mt.parse(I)) : [mt.parse(R)];
3306
- for (const I of M) (i = this.onmessage) == null || i.call(this, I);
3342
+ const S = f.headers.get("content-type") || "";
3343
+ if (S.includes("application/json")) {
3344
+ const R = await f.json(), M = Array.isArray(R) ? R.map((O) => mt(O)) : [mt(R)];
3345
+ for (const O of M)
3346
+ (i = this.onmessage) == null || i.call(this, O);
3307
3347
  return;
3308
3348
  }
3309
- if (T.includes("text/event-stream")) {
3349
+ if (S.includes("text/event-stream")) {
3310
3350
  if (!f.body) {
3311
- const z = new A({
3351
+ const j = new A({
3312
3352
  message: "MCP HTTP Transport Error: text/event-stream response without body",
3313
3353
  statusCode: f.status,
3314
3354
  url: this.url.href
3315
3355
  });
3316
- throw (l = this.onerror) == null || l.call(this, z), z;
3356
+ throw (l = this.onerror) == null || l.call(this, j), j;
3317
3357
  }
3318
3358
  const M = f.body.pipeThrough(new TextDecoderStream()).pipeThrough(new ft()).getReader();
3319
3359
  (async () => {
3320
- var z, h, m;
3360
+ var j, h, g;
3321
3361
  try {
3322
3362
  for (; ; ) {
3323
- const { done: _, value: j } = await M.read();
3363
+ const { done: _, value: N } = await M.read();
3324
3364
  if (_) return;
3325
- const { event: O, data: D } = j;
3326
- if (or(O))
3365
+ const { event: I, data: L } = N;
3366
+ if (sr(I))
3327
3367
  try {
3328
- const K = await gt(D);
3329
- (z = this.onmessage) == null || z.call(this, K);
3368
+ const K = await gt(L);
3369
+ (j = this.onmessage) == null || j.call(this, K);
3330
3370
  } catch (K) {
3331
3371
  const Z = new A({
3332
3372
  message: "MCP HTTP Transport Error: Failed to parse message",
@@ -3338,13 +3378,16 @@ var Xs = class {
3338
3378
  } catch (_) {
3339
3379
  if (_ instanceof Error && _.name === "AbortError")
3340
3380
  return;
3341
- (m = this.onerror) == null || m.call(this, _);
3381
+ (g = this.onerror) == null || g.call(this, _);
3342
3382
  }
3343
- })();
3383
+ })().catch((j) => {
3384
+ var h;
3385
+ j instanceof Error && j.name === "AbortError" || (h = this.onerror) == null || h.call(this, j);
3386
+ });
3344
3387
  return;
3345
3388
  }
3346
3389
  const x = new A({
3347
- message: `MCP HTTP Transport Error: Unexpected content type: ${T}`,
3390
+ message: `MCP HTTP Transport Error: Unexpected content type: ${S}`,
3348
3391
  statusCode: f.status,
3349
3392
  url: this.url.href
3350
3393
  });
@@ -3379,11 +3422,17 @@ var Xs = class {
3379
3422
  return;
3380
3423
  }
3381
3424
  const r = this.getNextReconnectionDelay(this.inboundReconnectAttempts);
3382
- this.inboundReconnectAttempts += 1, setTimeout(async () => {
3425
+ this.inboundReconnectAttempts += 1, setTimeout(() => {
3383
3426
  var n;
3384
- (n = this.abortController) != null && n.signal.aborted || await this.openInboundSse(!1, this.lastInboundEventId);
3427
+ (n = this.abortController) != null && n.signal.aborted || this.startInboundSse(!1, this.lastInboundEventId);
3385
3428
  }, r);
3386
3429
  }
3430
+ startInboundSse(e = !1, t) {
3431
+ this.openInboundSse(e, t).catch((r) => {
3432
+ var n;
3433
+ r instanceof Error && r.name === "AbortError" || (n = this.onerror) == null || n.call(this, r);
3434
+ });
3435
+ }
3387
3436
  // Open optional inbound SSE stream; best-effort and resumable
3388
3437
  async openInboundSse(e = !1, t) {
3389
3438
  var r, n, o, s, i, l;
@@ -3402,12 +3451,12 @@ var Xs = class {
3402
3451
  this.resourceMetadataUrl = Je(c);
3403
3452
  try {
3404
3453
  if (await this.authorizeOnce(this.resourceMetadataUrl) !== "AUTHORIZED") {
3405
- const T = new Ve();
3406
- (n = this.onerror) == null || n.call(this, T);
3454
+ const S = new Ve();
3455
+ (n = this.onerror) == null || n.call(this, S);
3407
3456
  return;
3408
3457
  }
3409
- } catch (y) {
3410
- (o = this.onerror) == null || o.call(this, y);
3458
+ } catch (m) {
3459
+ (o = this.onerror) == null || o.call(this, m);
3411
3460
  return;
3412
3461
  }
3413
3462
  return this.openInboundSse(!0, t);
@@ -3415,31 +3464,31 @@ var Xs = class {
3415
3464
  if (c.status === 405)
3416
3465
  return;
3417
3466
  if (!c.ok || !c.body) {
3418
- const y = new A({
3467
+ const m = new A({
3419
3468
  message: `MCP HTTP Transport Error: GET SSE failed: ${c.status} ${c.statusText}`,
3420
3469
  statusCode: c.status,
3421
3470
  url: this.url.href
3422
3471
  });
3423
- (s = this.onerror) == null || s.call(this, y);
3472
+ (s = this.onerror) == null || s.call(this, m);
3424
3473
  return;
3425
3474
  }
3426
3475
  const f = c.body.pipeThrough(new TextDecoderStream()).pipeThrough(new ft()).getReader(), v = async () => {
3427
- var y, T, x, R;
3476
+ var m, S, x, R;
3428
3477
  try {
3429
3478
  for (; ; ) {
3430
- const { done: M, value: I } = await f.read();
3479
+ const { done: M, value: O } = await f.read();
3431
3480
  if (M) return;
3432
- const { event: z, data: h, id: m } = I;
3433
- if (m && (this.lastInboundEventId = m), or(z))
3481
+ const { event: j, data: h, id: g } = O;
3482
+ if (g && (this.lastInboundEventId = g), sr(j))
3434
3483
  try {
3435
3484
  const _ = await gt(h);
3436
- (y = this.onmessage) == null || y.call(this, _);
3485
+ (m = this.onmessage) == null || m.call(this, _);
3437
3486
  } catch (_) {
3438
- const j = new A({
3487
+ const N = new A({
3439
3488
  message: "MCP HTTP Transport Error: Failed to parse message",
3440
3489
  cause: _
3441
3490
  });
3442
- (T = this.onerror) == null || T.call(this, j);
3491
+ (S = this.onerror) == null || S.call(this, N);
3443
3492
  }
3444
3493
  }
3445
3494
  } catch (M) {
@@ -3449,8 +3498,16 @@ var Xs = class {
3449
3498
  }
3450
3499
  };
3451
3500
  this.inboundSseConnection = {
3452
- close: () => f.cancel()
3453
- }, this.inboundReconnectAttempts = 0, v();
3501
+ close: () => {
3502
+ f.cancel().catch((m) => {
3503
+ var S;
3504
+ m instanceof Error && m.name === "AbortError" || (S = this.onerror) == null || S.call(this, m);
3505
+ });
3506
+ }
3507
+ }, this.inboundReconnectAttempts = 0, v().catch((m) => {
3508
+ var S, x;
3509
+ m instanceof Error && m.name === "AbortError" || ((S = this.onerror) == null || S.call(this, m), (x = this.abortController) != null && x.signal.aborted || this.scheduleInboundSseReconnection());
3510
+ });
3454
3511
  } catch (u) {
3455
3512
  if (u instanceof Error && u.name === "AbortError")
3456
3513
  return;
@@ -3458,23 +3515,61 @@ var Xs = class {
3458
3515
  }
3459
3516
  }
3460
3517
  };
3461
- function Qs(e) {
3518
+ function ri(e) {
3462
3519
  switch (e.type) {
3463
3520
  case "sse":
3464
- return new Ys(e);
3521
+ return new ei(e);
3465
3522
  case "http":
3466
- return new Xs(e);
3523
+ return new ti(e);
3467
3524
  default:
3468
3525
  throw new A({
3469
3526
  message: "Unsupported or invalid transport configuration. If you are using a custom transport, make sure it implements the MCPTransport interface."
3470
3527
  });
3471
3528
  }
3472
3529
  }
3473
- function ei(e) {
3530
+ function ni(e) {
3474
3531
  return "start" in e && typeof e.start == "function" && "send" in e && typeof e.send == "function" && "close" in e && typeof e.close == "function";
3475
3532
  }
3476
- var ti = "1.0.0";
3477
- function sr({
3533
+ var oi = "1.0.0", si = 0, ii = [
3534
+ "ConnectionRefused",
3535
+ "ConnectionClosed",
3536
+ "FailedToOpenSocket",
3537
+ "ECONNRESET",
3538
+ "ECONNREFUSED",
3539
+ "ETIMEDOUT",
3540
+ "EPIPE"
3541
+ ];
3542
+ function ai(e) {
3543
+ if (e != null && typeof e == "object" && "statusCode" in e && typeof e.statusCode == "number")
3544
+ return e.statusCode;
3545
+ }
3546
+ function li(e) {
3547
+ if (e != null && typeof e == "object" && "code" in e && typeof e.code == "string")
3548
+ return e.code;
3549
+ }
3550
+ function ci(e) {
3551
+ const t = ai(e);
3552
+ if (t != null)
3553
+ return t === 408 || t === 409 || t === 429 || t >= 500;
3554
+ if (A.isInstance(e) && e.code != null)
3555
+ return !1;
3556
+ const r = li(e);
3557
+ return r != null && ii.includes(r);
3558
+ }
3559
+ function ui(e) {
3560
+ if (e == null)
3561
+ return si;
3562
+ if (!Number.isInteger(e))
3563
+ throw new A({
3564
+ message: "maxRetries must be an integer"
3565
+ });
3566
+ if (e < 0)
3567
+ throw new A({
3568
+ message: "maxRetries must be >= 0"
3569
+ });
3570
+ return e;
3571
+ }
3572
+ function ir({
3478
3573
  output: e
3479
3574
  }) {
3480
3575
  const t = e;
@@ -3486,29 +3581,30 @@ function sr({
3486
3581
  } : { type: "text", text: JSON.stringify(n) }
3487
3582
  ) };
3488
3583
  }
3489
- async function ri(e) {
3490
- const t = new ni(e);
3584
+ async function di(e) {
3585
+ const t = new fi(e);
3491
3586
  return await t.init(), t;
3492
3587
  }
3493
- var ni = class {
3588
+ var fi = class {
3494
3589
  constructor({
3495
3590
  transport: e,
3496
3591
  name: t,
3497
3592
  clientName: r = t ?? "ai-sdk-mcp-client",
3498
- version: n = ti,
3593
+ version: n = oi,
3499
3594
  onUncaughtError: o,
3500
- capabilities: s
3595
+ maxRetries: s,
3596
+ capabilities: i
3501
3597
  }) {
3502
- this.requestMessageId = 0, this.responseHandlers = /* @__PURE__ */ new Map(), this.serverCapabilities = {}, this._serverInfo = { name: "", version: "" }, this.isClosed = !0, this.onUncaughtError = o, this.clientCapabilities = s ?? {}, ei(e) ? this.transport = e : this.transport = Qs(e), this.transport.onclose = () => this.onClose(), this.transport.onerror = (i) => this.onError(i), this.transport.onmessage = (i) => {
3503
- if ("method" in i) {
3504
- "id" in i ? this.onRequestMessage(i) : this.onError(
3598
+ this.requestMessageId = 0, this.responseHandlers = /* @__PURE__ */ new Map(), this.serverCapabilities = {}, this._serverInfo = { name: "", version: "" }, this.isClosed = !0, this.onUncaughtError = o, this.maxRetries = ui(s), this.clientCapabilities = i ?? {}, ni(e) ? this.transport = e : this.transport = ri(e), this.transport.onclose = () => this.onClose(), this.transport.onerror = (l) => this.onError(l), this.transport.onmessage = (l) => {
3599
+ if ("method" in l) {
3600
+ "id" in l ? this.onRequestMessage(l) : this.onError(
3505
3601
  new A({
3506
3602
  message: "Unsupported message type"
3507
3603
  })
3508
3604
  );
3509
3605
  return;
3510
3606
  }
3511
- this.onResponse(i);
3607
+ this.onResponse(l);
3512
3608
  }, this.clientInfo = {
3513
3609
  name: r,
3514
3610
  version: n
@@ -3611,30 +3707,36 @@ var ni = class {
3611
3707
  jsonrpc: "2.0",
3612
3708
  id: i
3613
3709
  }, u = () => {
3614
- this.responseHandlers.delete(i);
3710
+ o(
3711
+ new A({
3712
+ message: "Request was aborted",
3713
+ cause: s?.reason
3714
+ })
3715
+ );
3716
+ }, c = () => {
3717
+ this.responseHandlers.delete(i), s?.removeEventListener("abort", p);
3718
+ }, d = (f) => {
3719
+ c(), o(f);
3720
+ }, p = () => {
3721
+ c(), u();
3615
3722
  };
3616
- this.responseHandlers.set(i, (c) => {
3723
+ this.responseHandlers.set(i, (f) => {
3617
3724
  if (s?.aborted)
3618
- return o(
3619
- new A({
3620
- message: "Request was aborted",
3621
- cause: s.reason
3622
- })
3623
- );
3624
- if (c instanceof Error)
3625
- return o(c);
3725
+ return c(), u();
3726
+ if (f instanceof Error)
3727
+ return d(f);
3626
3728
  try {
3627
- const d = t.parse(c.result);
3628
- n(d);
3629
- } catch (d) {
3630
- const p = new A({
3729
+ const v = t.parse(f.result);
3730
+ c(), n(v);
3731
+ } catch (v) {
3732
+ const m = new A({
3631
3733
  message: "Failed to parse server response",
3632
- cause: d
3734
+ cause: v
3633
3735
  });
3634
- o(p);
3736
+ d(m);
3635
3737
  }
3636
- }), this.transport.send(l).catch((c) => {
3637
- u(), o(c);
3738
+ }), s?.addEventListener("abort", p, { once: !0 }), this.transport.send(l).catch((f) => {
3739
+ d(f);
3638
3740
  });
3639
3741
  });
3640
3742
  }
@@ -3648,18 +3750,38 @@ var ni = class {
3648
3750
  options: t
3649
3751
  });
3650
3752
  }
3753
+ async callToolWithRetry({
3754
+ options: e,
3755
+ execute: t
3756
+ }) {
3757
+ return this.maxRetries === 0 ? t() : qo({
3758
+ maxRetries: this.maxRetries,
3759
+ abortSignal: e?.abortSignal,
3760
+ shouldRetry: ci,
3761
+ createRetryError: ({ message: r, errors: n }) => new A({
3762
+ message: r,
3763
+ cause: n[n.length - 1]
3764
+ })
3765
+ })(t);
3766
+ }
3651
3767
  async callTool({
3652
3768
  name: e,
3653
3769
  args: t,
3654
3770
  options: r
3655
3771
  }) {
3656
3772
  try {
3657
- return this.request({
3658
- request: { method: "tools/call", params: { name: e, arguments: t } },
3659
- resultSchema: rs,
3660
- options: {
3661
- signal: r?.abortSignal
3662
- }
3773
+ return this.callToolWithRetry({
3774
+ options: r,
3775
+ execute: () => this.request({
3776
+ request: {
3777
+ method: "tools/call",
3778
+ params: { name: e, arguments: t }
3779
+ },
3780
+ resultSchema: rs,
3781
+ options: {
3782
+ signal: r?.abortSignal
3783
+ }
3784
+ })
3663
3785
  });
3664
3786
  } catch (n) {
3665
3787
  throw n;
@@ -3782,24 +3904,24 @@ var ni = class {
3782
3904
  const p = i ?? c?.title;
3783
3905
  if (t !== "automatic" && !Object.prototype.hasOwnProperty.call(t, s))
3784
3906
  continue;
3785
- const f = this, v = t !== "automatic" ? (r = t[s]) == null ? void 0 : r.outputSchema : void 0, y = async (x, R) => {
3907
+ const f = this, v = t !== "automatic" ? (r = t[s]) == null ? void 0 : r.outputSchema : void 0, m = async (x, R) => {
3786
3908
  var M;
3787
3909
  (M = R?.abortSignal) == null || M.throwIfAborted();
3788
- const I = await f.callTool({ name: s, args: x, options: R });
3789
- return I.isError ? I : v != null ? f.extractStructuredContent(I, v, s) : I;
3790
- }, T = t === "automatic" ? Lo({
3910
+ const O = await f.callTool({ name: s, args: x, options: R });
3911
+ return O.isError ? O : v != null ? f.extractStructuredContent(O, v, s) : O;
3912
+ }, S = t === "automatic" ? Lo({
3791
3913
  description: l,
3792
3914
  title: p,
3793
3915
  metadata: {
3794
3916
  clientName: this.clientInfo.name
3795
3917
  },
3796
- inputSchema: Ee({
3918
+ inputSchema: Pe({
3797
3919
  ...u,
3798
3920
  properties: (n = u.properties) != null ? n : {},
3799
3921
  additionalProperties: !1
3800
3922
  }),
3801
- execute: y,
3802
- toModelOutput: sr
3923
+ execute: m,
3924
+ toModelOutput: ir
3803
3925
  }) : {
3804
3926
  description: l,
3805
3927
  title: p,
@@ -3808,10 +3930,10 @@ var ni = class {
3808
3930
  },
3809
3931
  inputSchema: t[s].inputSchema,
3810
3932
  ...v != null ? { outputSchema: v } : {},
3811
- execute: y,
3812
- toModelOutput: sr
3933
+ execute: m,
3934
+ toModelOutput: ir
3813
3935
  };
3814
- o[s] = { ...T, _meta: d };
3936
+ o[s] = { ...S, _meta: d };
3815
3937
  }
3816
3938
  return o;
3817
3939
  }
@@ -3822,7 +3944,7 @@ var ni = class {
3822
3944
  if ("structuredContent" in e && e.structuredContent != null) {
3823
3945
  const n = await Ct({
3824
3946
  value: e.structuredContent,
3825
- schema: Tr(t)
3947
+ schema: Cr(t)
3826
3948
  });
3827
3949
  if (!n.success)
3828
3950
  throw new A({
@@ -3834,7 +3956,7 @@ var ni = class {
3834
3956
  if ("content" in e && Array.isArray(e.content)) {
3835
3957
  const n = e.content.find((o) => o.type === "text");
3836
3958
  if (n && "text" in n) {
3837
- const o = await Uo({
3959
+ const o = await Do({
3838
3960
  text: n.text,
3839
3961
  schema: t
3840
3962
  });
@@ -3884,7 +4006,7 @@ var ni = class {
3884
4006
  return this.completeInternal(e);
3885
4007
  }
3886
4008
  onElicitationRequest(e, t) {
3887
- if (e !== Gt)
4009
+ if (e !== Bt)
3888
4010
  throw new A({
3889
4011
  message: "Unsupported request schema. Only ElicitationRequestSchema is supported."
3890
4012
  });
@@ -3922,7 +4044,7 @@ var ni = class {
3922
4044
  });
3923
4045
  return;
3924
4046
  }
3925
- const t = Gt.safeParse({
4047
+ const t = Bt.safeParse({
3926
4048
  method: e.method,
3927
4049
  params: e.params
3928
4050
  });
@@ -3990,15 +4112,15 @@ var ni = class {
3990
4112
  );
3991
4113
  }
3992
4114
  };
3993
- const oi = async (e) => {
4115
+ const pi = async (e) => {
3994
4116
  const t = {};
3995
4117
  try {
3996
4118
  const r = await e.listTools();
3997
4119
  for (const { name: n, description: o, inputSchema: s } of r.tools) {
3998
4120
  const i = async (l, u) => e.callTool({ name: n, arguments: l }, { signal: u?.abortSignal });
3999
- t[n] = hr({
4121
+ t[n] = mr({
4000
4122
  description: o,
4001
- inputSchema: mr({
4123
+ inputSchema: gr({
4002
4124
  ...s,
4003
4125
  properties: s.properties ?? {},
4004
4126
  additionalProperties: !1
@@ -4010,7 +4132,7 @@ const oi = async (e) => {
4010
4132
  } catch (r) {
4011
4133
  throw r;
4012
4134
  }
4013
- }, si = async (e) => {
4135
+ }, hi = async (e) => {
4014
4136
  const t = {};
4015
4137
  if (!e)
4016
4138
  return t;
@@ -4035,19 +4157,19 @@ const oi = async (e) => {
4035
4157
  additionalProperties: !1,
4036
4158
  ...d
4037
4159
  };
4038
- t[l] = hr({
4160
+ t[l] = mr({
4039
4161
  description: u ?? "",
4040
- inputSchema: mr(p),
4162
+ inputSchema: gr(p),
4041
4163
  async execute(f) {
4042
4164
  if (!r.executeTool)
4043
- throw new Error("navigator.modelContextTesting.executeTool is not available");
4044
- return r.executeTool(l, JSON.stringify(f ?? {}));
4165
+ throw new Error("document.modelContext.executeTool is not available");
4166
+ return r.executeTool(i, JSON.stringify(f ?? {}));
4045
4167
  }
4046
4168
  });
4047
4169
  }
4048
4170
  return t;
4049
4171
  };
4050
- function ii(e) {
4172
+ function mi(e) {
4051
4173
  const t = Object.entries(e);
4052
4174
  if (t.length === 0)
4053
4175
  return "";
@@ -4097,7 +4219,7 @@ Thought: 用户想要获取今天的日期,我需要调用日期相关的工
4097
4219
  - 如果不需要调用工具,直接给出最终答案即可
4098
4220
  `, r;
4099
4221
  }
4100
- function ir(e, t) {
4222
+ function ar(e, t) {
4101
4223
  if (!e || typeof e != "string")
4102
4224
  return null;
4103
4225
  const r = e.match(/<tool_call>([\s\S]*?)<\/tool_call>/i);
@@ -4110,11 +4232,11 @@ function ir(e, t) {
4110
4232
  }
4111
4233
  return null;
4112
4234
  }
4113
- const ai = {
4235
+ const gi = {
4114
4236
  openai: Pn,
4115
- deepseek: En
4237
+ deepseek: Rn
4116
4238
  };
4117
- class Ya {
4239
+ class sl {
4118
4240
  constructor({ llmConfig: t, mcpServers: r }) {
4119
4241
  if (this.mcpServers = {}, this.mcpClients = {}, this.mcpTools = {}, this.ignoreToolnames = [], this.responseMessages = [], this.useReActMode = !1, !t)
4120
4242
  throw new Error("llmConfig is required to initialize AgentModelProvider");
@@ -4123,7 +4245,7 @@ class Ya {
4123
4245
  else if (t.providerType) {
4124
4246
  const n = t.providerType;
4125
4247
  let o;
4126
- typeof n == "string" ? o = ai[n] : o = n, this.llm = o({
4248
+ typeof n == "string" ? o = gi[n] : o = n, this.llm = o({
4127
4249
  apiKey: t.apiKey,
4128
4250
  baseURL: t.baseURL
4129
4251
  });
@@ -4138,7 +4260,7 @@ class Ya {
4138
4260
  if ("type" in t && t.type === "builtin") {
4139
4261
  const o = t.client;
4140
4262
  return {
4141
- tools: () => si(o),
4263
+ tools: () => hi(o),
4142
4264
  close: async () => {
4143
4265
  }
4144
4266
  };
@@ -4149,12 +4271,12 @@ class Ya {
4149
4271
  } else if ("type" in t && t.type === "sse") {
4150
4272
  const o = t, s = o.headers ? { headers: o.headers } : void 0;
4151
4273
  r = new Xe(new URL(o.url), { requestInit: s });
4152
- } else "type" in t && t.type === "extension" ? r = new jn(t.sessionId) : "transport" in t ? r = t.transport : r = t;
4274
+ } else "transport" in t ? r = t.transport : r = t;
4153
4275
  if (t.useAISdkClient ?? !1) {
4154
- const o = await ri({ transport: r });
4276
+ const o = await di({ transport: r });
4155
4277
  return o.__transport__ = r, o;
4156
4278
  } else {
4157
- const o = new In(
4279
+ const o = new An(
4158
4280
  { name: "mcp-web-client", version: "1.0.0" },
4159
4281
  { capabilities: { roots: { listChanged: !0 }, sampling: {}, elicitation: {} } }
4160
4282
  );
@@ -4168,7 +4290,7 @@ class Ya {
4168
4290
  async _closeOneClient(t) {
4169
4291
  try {
4170
4292
  const r = t.__transport__;
4171
- if (r && r instanceof $n || r && r instanceof cn)
4293
+ if (r && r instanceof En || r && r instanceof dn)
4172
4294
  return;
4173
4295
  await r?.terminateSession?.(), await r?.close?.(), await t?.close?.();
4174
4296
  } catch {
@@ -4191,7 +4313,7 @@ class Ya {
4191
4313
  if (!t)
4192
4314
  return null;
4193
4315
  try {
4194
- return typeof t.tools == "function" ? await t.tools() : await oi(t);
4316
+ return typeof t.tools == "function" ? await t.tools() : await pi(t);
4195
4317
  } catch (n) {
4196
4318
  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
4319
  }
@@ -4276,7 +4398,7 @@ class Ya {
4276
4398
  }
4277
4399
  /** 生成 ReAct 模式的系统提示词(包含工具描述) */
4278
4400
  _generateReActSystemPrompt(t, r, n) {
4279
- const o = ii(t);
4401
+ const o = mi(t);
4280
4402
  return n ? `${n}${o}` : `你是一个智能助手,可以通过调用工具来完成任务。
4281
4403
  ${o}`;
4282
4404
  }
@@ -4365,26 +4487,26 @@ ${o}`;
4365
4487
  const d = s.maxImages ?? 3;
4366
4488
  for (; c < o; ) {
4367
4489
  c++;
4368
- const f = this._buildMessagesForModel(l, u, d), { tools: v, ...y } = s, x = (await Lt({
4490
+ const f = this._buildMessagesForModel(l, u, d), { tools: v, ...m } = s, x = (await Dt({
4369
4491
  // @ts-ignore ProviderV2 是所有llm的父类,在每一个具体的llm类都有一个选择model的函数用法
4370
4492
  model: this.llm(n),
4371
4493
  messages: f,
4372
- ...y
4494
+ ...m
4373
4495
  })).text, R = { role: "assistant", content: x };
4374
4496
  u.push(R), i.push(R);
4375
- const M = ir(x, r);
4497
+ const M = ar(x, r);
4376
4498
  if (!M)
4377
4499
  return this.responseMessages = i, {
4378
4500
  text: x,
4379
4501
  response: { messages: i }
4380
4502
  };
4381
- const I = await this._executeReActToolCall(M.toolName, M.arguments, r), m = {
4503
+ const O = await this._executeReActToolCall(M.toolName, M.arguments, r), g = {
4382
4504
  role: "user",
4383
4505
  content: `<tool_response>
4384
- ${I.success ? JSON.stringify(I.result) : `工具执行失败 - ${I.error}`}
4506
+ ${O.success ? JSON.stringify(O.result) : `工具执行失败 - ${O.error}`}
4385
4507
  </tool_response>`
4386
4508
  };
4387
- u.push(m), i.push(m);
4509
+ u.push(g), i.push(g);
4388
4510
  }
4389
4511
  return this.responseMessages = i, {
4390
4512
  text: i[i.length - 2]?.content || "",
@@ -4402,59 +4524,59 @@ ${I.success ? JSON.stringify(I.result) : `工具执行失败 - ${I.error}`}
4402
4524
  fullStream: new ReadableStream({
4403
4525
  async start(f) {
4404
4526
  let v = [...t];
4405
- const y = t[0]?.role === "system" ? t[0] : null, T = y ? t.slice(1) : [...t];
4527
+ const m = t[0]?.role === "system" ? t[0] : null, S = m ? t.slice(1) : [...t];
4406
4528
  let x = 0, R = "";
4407
4529
  const M = s.maxImages ?? 3;
4408
4530
  f.enqueue({ type: "start" }), f.enqueue({ type: "start-step" });
4409
4531
  try {
4410
4532
  for (; x < o; ) {
4411
4533
  x++;
4412
- const I = i._buildMessagesForModel(y, T, M), { tools: z, ...h } = s;
4534
+ const O = i._buildMessagesForModel(m, S, M), { tools: j, ...h } = s;
4413
4535
  delete h.system, delete h.onFinish;
4414
- const m = await st({
4536
+ const g = await st({
4415
4537
  ...h,
4416
4538
  model: l,
4417
- messages: I
4539
+ messages: O
4418
4540
  });
4419
4541
  let _ = "";
4420
- for await (const q of m.fullStream)
4542
+ for await (const q of g.fullStream)
4421
4543
  q.type === "text-delta" ? (_ += q.text || "", f.enqueue({
4422
4544
  type: "text-delta",
4423
4545
  text: q.text
4424
4546
  })) : 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
4547
  R += _;
4426
- const j = { role: "assistant", content: R };
4427
- T.push(j), v.push(j);
4428
- const O = ir(R, r);
4429
- if (!O) {
4548
+ const N = { role: "assistant", content: R };
4549
+ S.push(N), v.push(N);
4550
+ const I = ar(R, r);
4551
+ if (!I) {
4430
4552
  f.enqueue({ type: "text-end" }), f.enqueue({ type: "finish-step" }), f.enqueue({ type: "finish" }), f.close(), i.responseMessages = v, u({ messages: v });
4431
4553
  return;
4432
4554
  }
4433
- if (O.toolName === "computer" && O.arguments?.action === "terminate") {
4555
+ if (I.toolName === "computer" && I.arguments?.action === "terminate") {
4434
4556
  f.enqueue({ type: "text-end" }), f.enqueue({ type: "finish-step" }), f.enqueue({ type: "finish" }), f.close(), i.responseMessages = v, u({ messages: v });
4435
4557
  return;
4436
4558
  }
4437
- const D = `react-${Date.now()}`;
4559
+ const L = `react-${Date.now()}`;
4438
4560
  f.enqueue({
4439
4561
  type: "tool-input-start",
4440
- id: D,
4441
- toolName: O.toolName
4562
+ id: L,
4563
+ toolName: I.toolName
4442
4564
  });
4443
- const K = JSON.stringify(O.arguments, null, 2);
4565
+ const K = JSON.stringify(I.arguments, null, 2);
4444
4566
  f.enqueue({
4445
4567
  type: "tool-input-delta",
4446
- id: D,
4568
+ id: L,
4447
4569
  delta: K
4448
4570
  }), f.enqueue({
4449
4571
  type: "tool-input-end",
4450
- id: D
4572
+ id: L
4451
4573
  }), f.enqueue({
4452
4574
  type: "tool-call",
4453
- toolCallId: D,
4454
- toolName: O.toolName,
4455
- input: O.arguments
4575
+ toolCallId: L,
4576
+ toolName: I.toolName,
4577
+ input: I.arguments
4456
4578
  });
4457
- const Z = await i._executeReActToolCall(O.toolName, O.arguments, r);
4579
+ const Z = await i._executeReActToolCall(I.toolName, I.arguments, r);
4458
4580
  let oe, H = Z.result;
4459
4581
  if (Z.success && Z.result && typeof Z.result == "object" && Z.result.screenshot) {
4460
4582
  oe = Z.result.screenshot;
@@ -4470,7 +4592,7 @@ ${G}
4470
4592
  oe && (q += `
4471
4593
  请检查截图以确认操作是否成功。如果成功,请继续下一步;如果失败,请重试。`), f.enqueue({
4472
4594
  type: "tool-result",
4473
- toolCallId: D,
4595
+ toolCallId: L,
4474
4596
  result: q
4475
4597
  });
4476
4598
  const le = oe ? {
@@ -4483,18 +4605,18 @@ ${G}
4483
4605
  role: "user",
4484
4606
  content: q
4485
4607
  };
4486
- T.push(le), v.push(le), R = "";
4608
+ S.push(le), v.push(le), R = "";
4487
4609
  } else
4488
4610
  G = `工具执行失败 - ${Z.error}`, f.enqueue({
4489
4611
  type: "tool-error",
4490
- toolCallId: D,
4491
- input: O.arguments,
4612
+ toolCallId: L,
4613
+ input: I.arguments,
4492
4614
  error: { message: G }
4493
4615
  });
4494
4616
  }
4495
4617
  f.enqueue({ type: "text-end" }), f.enqueue({ type: "finish-step" }), f.enqueue({ type: "finish" }), f.close(), i.responseMessages = v, u({ messages: v });
4496
- } catch (I) {
4497
- f.error(I), c(I);
4618
+ } catch (O) {
4619
+ f.error(O), c(O);
4498
4620
  }
4499
4621
  }
4500
4622
  }),
@@ -4509,22 +4631,22 @@ ${G}
4509
4631
  await this.initClientsAndTools();
4510
4632
  const s = o.tools || {}, i = this._tempMergeTools(s, !1), l = () => {
4511
4633
  const v = this._tempMergeTools(s, !1);
4512
- Object.entries(v).forEach(([y, T]) => {
4513
- i[y] = T;
4514
- }), Object.keys(i).forEach((y) => {
4515
- y in v || delete i[y];
4634
+ Object.entries(v).forEach(([m, S]) => {
4635
+ i[m] = S;
4636
+ }), Object.keys(i).forEach((m) => {
4637
+ m in v || delete i[m];
4516
4638
  });
4517
4639
  }, u = o.prepareStep, c = async (v) => {
4518
4640
  l();
4519
- const y = this._getActiveToolNames(i), T = typeof u == "function" ? await u(v) : void 0, x = T && typeof T == "object" ? T : {};
4641
+ const m = this._getActiveToolNames(i), S = typeof u == "function" ? await u(v) : void 0, x = S && typeof S == "object" ? S : {};
4520
4642
  return {
4521
4643
  ...x,
4522
- activeTools: Array.isArray(x.activeTools) ? x.activeTools.filter((R) => y.includes(R)) : y
4644
+ activeTools: Array.isArray(x.activeTools) ? x.activeTools.filter((R) => m.includes(R)) : m
4523
4645
  };
4524
4646
  }, d = {
4525
4647
  // @ts-ignore ProviderV2 是所有llm的父类, 在每一个具体的llm 类都有一个选择model的函数用法
4526
4648
  model: this.llm(r),
4527
- stopWhen: Tn(n),
4649
+ stopWhen: Cn(n),
4528
4650
  ...o,
4529
4651
  tools: i,
4530
4652
  prepareStep: c,
@@ -4539,28 +4661,31 @@ ${G}
4539
4661
  }
4540
4662
  const f = t(d);
4541
4663
  return f?.response?.then((v) => {
4542
- const y = v.messages?.[0];
4543
- p && y?.role !== "user" && this.responseMessages.push(p), this.responseMessages.push(...v.messages);
4664
+ const m = v.messages?.[0];
4665
+ p && m?.role !== "user" && this.responseMessages.push(p), this.responseMessages.push(...v.messages);
4544
4666
  }), f;
4545
4667
  }
4546
4668
  async chat(t) {
4547
- return this._chat(Lt, t);
4669
+ return this._chat(Dt, t);
4548
4670
  }
4549
4671
  async chatStream(t) {
4550
4672
  return this._chat(st, t);
4551
4673
  }
4552
4674
  }
4553
- const ae = () => typeof window < "u" && typeof navigator < "u", li = () => ae() && typeof document < "u";
4554
- let ie = null, We = null, ar = null, Le = 0;
4555
- const ci = "next-sdk-tool-body-glow";
4675
+ const yi = () => typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
4676
+ const t = Math.random() * 16 | 0;
4677
+ return (e === "x" ? t : t & 3 | 8).toString(16);
4678
+ }), ae = () => typeof window < "u" && typeof navigator < "u", vi = () => ae() && typeof document < "u";
4679
+ let ie = null, We = null, lr = null, De = 0;
4680
+ const wi = "next-sdk-tool-body-glow";
4556
4681
  function ke() {
4557
- return li();
4682
+ return vi();
4558
4683
  }
4559
- function ui() {
4560
- if (!ke() || ar) return;
4684
+ function bi() {
4685
+ if (!ke() || lr) return;
4561
4686
  const e = document.createElement("style");
4562
4687
  e.textContent = `
4563
- .${ci} {
4688
+ .${wi} {
4564
4689
  position: relative;
4565
4690
  }
4566
4691
 
@@ -4727,11 +4852,11 @@ function ui() {
4727
4852
  transform: scale(1) translateY(0);
4728
4853
  }
4729
4854
  }
4730
- `, document.head.appendChild(e), ar = e;
4855
+ `, document.head.appendChild(e), lr = e;
4731
4856
  }
4732
- function di() {
4857
+ function _i() {
4733
4858
  if (!ke() || ie) return;
4734
- ui();
4859
+ bi();
4735
4860
  const e = document.createElement("div");
4736
4861
  e.className = "next-sdk-tool-overlay";
4737
4862
  const t = document.createElement("div");
@@ -4753,10 +4878,10 @@ function di() {
4753
4878
  const c = document.createElement("div");
4754
4879
  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
4880
  }
4756
- function fi(e) {
4757
- ke() && (di(), !(!ie || !We) && (ie.classList.remove("next-sdk-tool-overlay--exit"), We.textContent = e.label));
4881
+ function xi(e) {
4882
+ ke() && (_i(), !(!ie || !We) && (ie.classList.remove("next-sdk-tool-overlay--exit"), We.textContent = e.label));
4758
4883
  }
4759
- function pi() {
4884
+ function Si() {
4760
4885
  if (!ie) return;
4761
4886
  ie.classList.add("next-sdk-tool-overlay--exit");
4762
4887
  const e = ie;
@@ -4766,42 +4891,42 @@ function pi() {
4766
4891
  };
4767
4892
  e.addEventListener("animationend", n), r = setTimeout(n, 500);
4768
4893
  }
4769
- function hi(e) {
4770
- ke() && (Le += 1, fi(e));
4894
+ function Ti(e) {
4895
+ ke() && (De += 1, xi(e));
4771
4896
  }
4772
- function mi() {
4773
- !ke() || Le <= 0 || (Le -= 1, Le === 0 && pi());
4897
+ function Ci() {
4898
+ !ke() || De <= 0 || (De -= 1, De === 0 && Si());
4774
4899
  }
4775
- function Fr(e, t, r) {
4900
+ function Vr(e, t, r) {
4776
4901
  if (!r) return;
4777
4902
  const n = t || e;
4778
4903
  return typeof r == "boolean" ? r ? { label: n } : void 0 : {
4779
4904
  label: r.label || n
4780
4905
  };
4781
4906
  }
4782
- const Zr = "next-sdk:tool-call", vt = "next-sdk:tool-response", ve = "next-sdk:tool-registered", Be = "next-sdk:tool-unregistered", gi = "next-sdk:remoter-ready", wt = /* @__PURE__ */ new Map(), $e = (e) => e.replace(/\/+$/, "") || "/", It = /* @__PURE__ */ new Set();
4783
- function yi() {
4784
- ae() && It.add({ win: window, origin: window.location.origin || "*" });
4907
+ const Jr = "next-sdk:tool-call", vt = "next-sdk:tool-response", ve = "next-sdk:tool-registered", Be = "next-sdk:tool-unregistered", $i = "next-sdk:remoter-ready", wt = /* @__PURE__ */ new Map(), $e = (e) => e.replace(/\/+$/, "") || "/", Ot = /* @__PURE__ */ new Set();
4908
+ function Ei() {
4909
+ ae() && Ot.add({ win: window, origin: window.location.origin || "*" });
4785
4910
  }
4786
- yi();
4911
+ Ei();
4787
4912
  function ce(e) {
4788
4913
  if (!ae()) return;
4789
4914
  const t = { type: e };
4790
- It.forEach(({ win: r, origin: n }) => {
4915
+ Ot.forEach(({ win: r, origin: n }) => {
4791
4916
  try {
4792
4917
  r.postMessage(t, n);
4793
4918
  } catch {
4794
4919
  }
4795
4920
  });
4796
4921
  }
4797
- function vi() {
4922
+ function Pi() {
4798
4923
  ae() && window.addEventListener("message", (e) => {
4799
- if (e.data?.type !== gi || !e.source || e.origin !== window.location.origin) return;
4924
+ if (e.data?.type !== $i || !e.source || e.origin !== window.location.origin) return;
4800
4925
  const t = e.source;
4801
- It.add({ win: t, origin: e.origin || "*" });
4926
+ Ot.add({ win: t, origin: e.origin || "*" });
4802
4927
  });
4803
4928
  }
4804
- vi();
4929
+ Pi();
4805
4930
  function dt(e) {
4806
4931
  if (!e) return;
4807
4932
  const t = e;
@@ -4810,20 +4935,20 @@ function dt(e) {
4810
4935
  } catch {
4811
4936
  }
4812
4937
  }
4813
- function lr(e, t) {
4938
+ function cr(e, t) {
4814
4939
  const r = wt.get(e);
4815
4940
  return !!r && r.has(t);
4816
4941
  }
4817
- let Pe = null;
4818
- function Xa(e) {
4819
- Pe = e;
4942
+ let Ee = null;
4943
+ function il(e) {
4944
+ Ee = e;
4820
4945
  }
4821
- function wi(e) {
4946
+ function Ri(e) {
4822
4947
  if (!ae()) return !1;
4823
4948
  const t = $e(e);
4824
4949
  return $e(window.location.pathname) === t;
4825
4950
  }
4826
- function bi(e) {
4951
+ function ki(e) {
4827
4952
  return ae() ? new Promise((t) => {
4828
4953
  let r = !1;
4829
4954
  const n = () => {
@@ -4834,7 +4959,7 @@ function bi(e) {
4834
4959
  window.addEventListener("message", o), setTimeout(n, e);
4835
4960
  }) : Promise.resolve();
4836
4961
  }
4837
- function Qa(e, t) {
4962
+ function al(e, t) {
4838
4963
  const r = t?.name ?? "navigate_to_page", n = t?.title ?? "页面跳转", o = t?.description ?? '当需要的工具在当前页面不可用时,使用此工具跳转到特定页面。例如:要查询订单时跳转到 "/orders",要创建价保时跳转到 "/price-protection"。', s = t?.timeoutMs ?? 5e3, i = {
4839
4964
  type: "object",
4840
4965
  properties: {
@@ -4851,7 +4976,7 @@ function Qa(e, t) {
4851
4976
  return {
4852
4977
  content: [{ type: "text", text: "当前环境不支持页面跳转(window 不存在)。" }]
4853
4978
  };
4854
- if (!Pe)
4979
+ if (!Ee)
4855
4980
  return {
4856
4981
  content: [
4857
4982
  {
@@ -4861,12 +4986,12 @@ function Qa(e, t) {
4861
4986
  ]
4862
4987
  };
4863
4988
  try {
4864
- if (wi(u))
4989
+ if (Ri(u))
4865
4990
  return {
4866
4991
  content: [{ type: "text", text: `当前已在页面:${u}。请继续你的下一步操作。` }]
4867
4992
  };
4868
- const c = bi(s);
4869
- return await Pe(u) !== !0 && (await c, await new Promise((p) => setTimeout(p, 500))), {
4993
+ const c = ki(s);
4994
+ return await Ee(u) !== !0 && (await c, await new Promise((p) => setTimeout(p, 500))), {
4870
4995
  content: [{ type: "text", text: `已成功跳转至页面:${u}。请继续你的下一步操作。` }]
4871
4996
  };
4872
4997
  } catch (c) {
@@ -4898,13 +5023,13 @@ function Qa(e, t) {
4898
5023
  );
4899
5024
  throw new Error("Failed to register navigate tool: invalid server instance.");
4900
5025
  }
4901
- function Vr(e, t, r = 3e4, n) {
5026
+ function Wr(e, t, r = 3e4, n) {
4902
5027
  return (o) => {
4903
- const s = Nn();
5028
+ const s = yi();
4904
5029
  return new Promise((i, l) => {
4905
5030
  let u, c;
4906
5031
  const d = () => {
4907
- clearTimeout(u), window.removeEventListener("message", p), c && window.removeEventListener("message", c), n && mi();
5032
+ clearTimeout(u), window.removeEventListener("message", p), c && window.removeEventListener("message", c), n && Ci();
4908
5033
  };
4909
5034
  u = setTimeout(() => {
4910
5035
  d(), l(new Error(`工具 [${e}] 调用超时 (${r}ms),请检查目标页面是否正确调用了 registerPageTool`));
@@ -4914,25 +5039,25 @@ function Vr(e, t, r = 3e4, n) {
4914
5039
  };
4915
5040
  window.addEventListener("message", p);
4916
5041
  const f = () => {
4917
- window.postMessage({ type: Zr, callId: s, toolName: e, route: t, input: o }, window.location.origin || "*");
5042
+ window.postMessage({ type: Jr, callId: s, toolName: e, route: t, input: o }, window.location.origin || "*");
4918
5043
  };
4919
5044
  let v = !1;
4920
- const y = () => {
5045
+ const m = () => {
4921
5046
  v || (v = !0, f());
4922
5047
  };
4923
5048
  (async () => {
4924
5049
  try {
4925
- if (n && hi(n), lr(t, e)) {
4926
- y();
5050
+ if (n && Ti(n), cr(t, e)) {
5051
+ m();
4927
5052
  return;
4928
5053
  }
4929
5054
  if (c = (x) => {
4930
- x.source !== window || x.data?.type !== ve || (window.removeEventListener("message", c), y());
4931
- }, window.addEventListener("message", c), Pe && await Pe(t) === !0) {
4932
- c && window.removeEventListener("message", c), y();
5055
+ x.source !== window || x.data?.type !== ve || (window.removeEventListener("message", c), m());
5056
+ }, window.addEventListener("message", c), Ee && await Ee(t) === !0) {
5057
+ c && window.removeEventListener("message", c), m();
4933
5058
  return;
4934
5059
  }
4935
- lr(t, e) && (window.removeEventListener("message", c), y());
5060
+ cr(t, e) && (window.removeEventListener("message", c), m());
4936
5061
  } catch (x) {
4937
5062
  d(), l(x instanceof Error ? x : new Error(String(x)));
4938
5063
  }
@@ -4940,7 +5065,7 @@ function Vr(e, t, r = 3e4, n) {
4940
5065
  });
4941
5066
  };
4942
5067
  }
4943
- function el(e) {
5068
+ function ll(e) {
4944
5069
  const t = /* @__PURE__ */ new Map(), r = (n, o, s = !1) => {
4945
5070
  const i = t.get(o), l = !!i;
4946
5071
  if (t.delete(o), i)
@@ -4959,15 +5084,15 @@ function el(e) {
4959
5084
  const R = c(i, l, u);
4960
5085
  return t.set(i, R), dt(n), ce(ve), R;
4961
5086
  }
4962
- const { route: d, timeout: p, invokeEffect: f } = u, v = $e(d), y = Fr(i, l?.title, f), T = Vr(i, v, p, y), x = c(i, l, T);
5087
+ 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
5088
  return t.set(i, x), dt(n), ce(ve), x;
4964
5089
  } : Reflect.get(n, o, s);
4965
5090
  }
4966
5091
  });
4967
5092
  }
4968
- function tl(e) {
5093
+ function cl(e) {
4969
5094
  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 !== Zr || !(i.data.toolName in r))
5095
+ if (i.source !== window || i.data?.type !== Jr || !(i.data.toolName in r))
4971
5096
  return;
4972
5097
  const { callId: l, toolName: u, input: c } = i.data;
4973
5098
  try {
@@ -4990,42 +5115,42 @@ function tl(e) {
4990
5115
  wt.delete(n), window.removeEventListener("message", s), ce(Be);
4991
5116
  };
4992
5117
  }
4993
- const xe = /* @__PURE__ */ new Map();
4994
- function _i() {
5118
+ const Se = /* @__PURE__ */ new Map();
5119
+ function Oi() {
4995
5120
  if (typeof document > "u") return;
4996
- const t = document.modelContext;
4997
- if (!t || t.__isNextSdkBridgeSetup) return;
4998
- ae() && (window.__nextSdkRegisteredTools = () => Array.from(xe.values()));
4999
- const r = t.registerTool?.bind(t), n = t.unregisterTool?.bind(t);
5000
- typeof r == "function" && (t.registerTool = (o, s) => {
5001
- const i = o.name, l = { ...o };
5002
- s?.signal && s.signal.addEventListener("abort", () => {
5003
- xe.delete(i), ce(Be);
5121
+ const e = document, t = typeof navigator < "u" ? navigator : void 0, r = e.modelContext || t?.modelContext;
5122
+ if (!r || r.__isNextSdkBridgeSetup) return;
5123
+ !e.modelContext && t?.modelContext && (e.modelContext = t.modelContext), ae() && (window.__nextSdkRegisteredTools = () => Array.from(Se.values()));
5124
+ const n = r.registerTool?.bind(r), o = r.unregisterTool?.bind(r);
5125
+ typeof n == "function" && (r.registerTool = (s, i) => {
5126
+ const l = s.name, u = { ...s };
5127
+ i?.signal && i.signal.addEventListener("abort", () => {
5128
+ Se.delete(l), ce(Be);
5004
5129
  });
5005
- const u = l.routeConfig && typeof l.routeConfig == "object" && "route" in l.routeConfig ? l.routeConfig : null;
5006
- if (u) {
5007
- const c = $e(u.route), d = Fr(i, l.title, u.invokeEffect), p = Vr(i, c, u.timeout, d);
5008
- l.execute = p, delete l.routeConfig;
5130
+ const c = u.routeConfig && typeof u.routeConfig == "object" && "route" in u.routeConfig ? u.routeConfig : null;
5131
+ if (c) {
5132
+ const d = $e(c.route), p = Vr(l, u.title, c.invokeEffect), f = Wr(l, d, c.timeout, p);
5133
+ u.execute = f, delete u.routeConfig;
5009
5134
  }
5010
- xe.set(i, {
5011
- name: i,
5012
- title: o.title,
5013
- description: o.description,
5014
- inputSchema: o.inputSchema
5135
+ Se.set(l, {
5136
+ name: l,
5137
+ title: s.title,
5138
+ description: s.description,
5139
+ inputSchema: s.inputSchema
5015
5140
  });
5016
5141
  try {
5017
- r(l, s), ce(ve);
5142
+ n(u, i), ce(ve);
5018
5143
  } catch {
5019
- xe.delete(i);
5144
+ Se.delete(l);
5020
5145
  }
5021
- }), t.unregisterTool = (o) => {
5146
+ }), r.unregisterTool = (s) => {
5022
5147
  try {
5023
- typeof n == "function" && n(o);
5148
+ typeof o == "function" && o(s);
5024
5149
  } catch {
5025
5150
  } finally {
5026
- xe.delete(o), ce(Be);
5151
+ Se.delete(s), ce(Be);
5027
5152
  }
5028
- }, t.__isNextSdkBridgeSetup = !0;
5153
+ }, r.__isNextSdkBridgeSetup = !0;
5029
5154
  }
5030
5155
  function Te(e, t) {
5031
5156
  const r = typeof e;
@@ -5056,24 +5181,24 @@ function Te(e, t) {
5056
5181
  return e === t;
5057
5182
  }
5058
5183
  function Q(e) {
5059
- return encodeURI(Si(e));
5184
+ return encodeURI(Ai(e));
5060
5185
  }
5061
- function Si(e) {
5186
+ function Ai(e) {
5062
5187
  return e.replace(/~/g, "~0").replace(/\//g, "~1");
5063
5188
  }
5064
- const xi = {
5189
+ const Ii = {
5065
5190
  prefixItems: !0,
5066
5191
  items: !0,
5067
5192
  allOf: !0,
5068
5193
  anyOf: !0,
5069
5194
  oneOf: !0
5070
- }, Ti = {
5195
+ }, Mi = {
5071
5196
  $defs: !0,
5072
5197
  definitions: !0,
5073
5198
  properties: !0,
5074
5199
  patternProperties: !0,
5075
5200
  dependentSchemas: !0
5076
- }, Ci = {
5201
+ }, ji = {
5077
5202
  id: !0,
5078
5203
  $id: !0,
5079
5204
  $ref: !0,
@@ -5101,8 +5226,8 @@ const xi = {
5101
5226
  maxProperties: !0,
5102
5227
  minProperties: !0
5103
5228
  };
5104
- let $i = 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");
5105
- function he(e, t = /* @__PURE__ */ Object.create(null), r = $i, n = "") {
5229
+ let Ni = 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");
5230
+ function he(e, t = /* @__PURE__ */ Object.create(null), r = Ni, n = "") {
5106
5231
  if (e && typeof e == "object" && !Array.isArray(e)) {
5107
5232
  const s = e.$id || e.id;
5108
5233
  if (s) {
@@ -5138,16 +5263,16 @@ function he(e, t = /* @__PURE__ */ Object.create(null), r = $i, n = "") {
5138
5263
  t[s.href] = e;
5139
5264
  }
5140
5265
  for (let s in e) {
5141
- if (Ci[s])
5266
+ if (ji[s])
5142
5267
  continue;
5143
5268
  const i = `${n}/${Q(s)}`, l = e[s];
5144
5269
  if (Array.isArray(l)) {
5145
- if (xi[s]) {
5270
+ if (Ii[s]) {
5146
5271
  const u = l.length;
5147
5272
  for (let c = 0; c < u; c++)
5148
5273
  he(l[c], t, r, `${i}/${c}`);
5149
5274
  }
5150
- } else if (Ti[s])
5275
+ } else if (Mi[s])
5151
5276
  for (let u in l)
5152
5277
  he(l[u], t, r, `${i}/${Q(u)}`);
5153
5278
  else
@@ -5155,63 +5280,63 @@ function he(e, t = /* @__PURE__ */ Object.create(null), r = $i, n = "") {
5155
5280
  }
5156
5281
  return t;
5157
5282
  }
5158
- const Pi = /^(\d\d\d\d)-(\d\d)-(\d\d)$/, Ei = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], Ri = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i, ki = /^(?=.{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, Ii = /^(?:[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, Oi = /^(?:(?:[^\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, Mi = /^(?:(?: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, Ai = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i, ji = /^(?:\/(?:[^~/]|~0|~1)*)*$/, Ni = /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i, zi = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/, Ui = (e) => {
5283
+ const zi = /^(\d\d\d\d)-(\d\d)-(\d\d)$/, Ui = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], Di = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i, Li = /^(?=.{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, qi = /^(?:[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, Hi = /^(?:(?:[^\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, Fi = /^(?:(?: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, Zi = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i, Vi = /^(?:\/(?:[^~/]|~0|~1)*)*$/, Ji = /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i, Wi = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/, Bi = (e) => {
5159
5284
  if (e[0] === '"')
5160
5285
  return !1;
5161
5286
  const [t, r, ...n] = e.split("@");
5162
5287
  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
- }, Li = /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/, Di = /^((([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, qi = (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));
5288
+ }, Gi = /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/, Ki = /^((([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, Yi = (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
5289
  function ee(e) {
5165
5290
  return e.test.bind(e);
5166
5291
  }
5167
- const cr = {
5168
- date: Jr,
5169
- time: Wr.bind(void 0, !1),
5170
- "date-time": Zi,
5171
- duration: qi,
5172
- uri: Wi,
5173
- "uri-reference": ee(Ii),
5174
- "uri-template": ee(Oi),
5175
- url: ee(Mi),
5176
- email: Ui,
5177
- hostname: ee(ki),
5178
- ipv4: ee(Li),
5179
- ipv6: ee(Di),
5180
- regex: Gi,
5181
- uuid: ee(Ai),
5182
- "json-pointer": ee(ji),
5183
- "json-pointer-uri-fragment": ee(Ni),
5184
- "relative-json-pointer": ee(zi)
5292
+ const ur = {
5293
+ date: Br,
5294
+ time: Gr.bind(void 0, !1),
5295
+ "date-time": ea,
5296
+ duration: Yi,
5297
+ uri: na,
5298
+ "uri-reference": ee(qi),
5299
+ "uri-template": ee(Hi),
5300
+ url: ee(Fi),
5301
+ email: Bi,
5302
+ hostname: ee(Li),
5303
+ ipv4: ee(Gi),
5304
+ ipv6: ee(Ki),
5305
+ regex: sa,
5306
+ uuid: ee(Zi),
5307
+ "json-pointer": ee(Vi),
5308
+ "json-pointer-uri-fragment": ee(Ji),
5309
+ "relative-json-pointer": ee(Wi)
5185
5310
  };
5186
- function Hi(e) {
5311
+ function Xi(e) {
5187
5312
  return e % 4 === 0 && (e % 100 !== 0 || e % 400 === 0);
5188
5313
  }
5189
- function Jr(e) {
5190
- const t = e.match(Pi);
5314
+ function Br(e) {
5315
+ const t = e.match(zi);
5191
5316
  if (!t)
5192
5317
  return !1;
5193
5318
  const r = +t[1], n = +t[2], o = +t[3];
5194
- return n >= 1 && n <= 12 && o >= 1 && o <= (n == 2 && Hi(r) ? 29 : Ei[n]);
5319
+ return n >= 1 && n <= 12 && o >= 1 && o <= (n == 2 && Xi(r) ? 29 : Ui[n]);
5195
5320
  }
5196
- function Wr(e, t) {
5197
- const r = t.match(Ri);
5321
+ function Gr(e, t) {
5322
+ const r = t.match(Di);
5198
5323
  if (!r)
5199
5324
  return !1;
5200
5325
  const n = +r[1], o = +r[2], s = +r[3], i = !!r[5];
5201
5326
  return (n <= 23 && o <= 59 && s <= 59 || n == 23 && o == 59 && s == 60) && (!e || i);
5202
5327
  }
5203
- const Fi = /t|\s/i;
5204
- function Zi(e) {
5205
- const t = e.split(Fi);
5206
- return t.length == 2 && Jr(t[0]) && Wr(!0, t[1]);
5328
+ const Qi = /t|\s/i;
5329
+ function ea(e) {
5330
+ const t = e.split(Qi);
5331
+ return t.length == 2 && Br(t[0]) && Gr(!0, t[1]);
5207
5332
  }
5208
- const Vi = /\/|:/, Ji = /^(?:[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;
5209
- function Wi(e) {
5210
- return Vi.test(e) && Ji.test(e);
5333
+ const ta = /\/|:/, ra = /^(?:[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;
5334
+ function na(e) {
5335
+ return ta.test(e) && ra.test(e);
5211
5336
  }
5212
- const Bi = /[^\\]\\Z/;
5213
- function Gi(e) {
5214
- if (Bi.test(e))
5337
+ const oa = /[^\\]\\Z/;
5338
+ function sa(e) {
5339
+ if (oa.test(e))
5215
5340
  return !1;
5216
5341
  try {
5217
5342
  return new RegExp(e, "u"), !0;
@@ -5219,13 +5344,13 @@ function Gi(e) {
5219
5344
  return !1;
5220
5345
  }
5221
5346
  }
5222
- function Ki(e) {
5347
+ function ia(e) {
5223
5348
  let t = 0, r = e.length, n = 0, o;
5224
5349
  for (; n < r; )
5225
5350
  t++, o = e.charCodeAt(n++), o >= 55296 && o <= 56319 && n < r && (o = e.charCodeAt(n), (o & 64512) == 56320 && n++);
5226
5351
  return t;
5227
5352
  }
5228
- function L(e, t, r = "2019-09", n = he(t), o = !0, s = null, i = "#", l = "#", u = /* @__PURE__ */ Object.create(null)) {
5353
+ function D(e, t, r = "2019-09", n = he(t), o = !0, s = null, i = "#", l = "#", u = /* @__PURE__ */ Object.create(null)) {
5229
5354
  if (t === !0)
5230
5355
  return { valid: !0, errors: [] };
5231
5356
  if (t === !1)
@@ -5254,68 +5379,68 @@ function L(e, t, r = "2019-09", n = he(t), o = !0, s = null, i = "#", l = "#", u
5254
5379
  default:
5255
5380
  throw new Error(`Instances of "${c}" type are not supported.`);
5256
5381
  }
5257
- const { $ref: p, $recursiveRef: f, $recursiveAnchor: v, type: y, const: T, enum: x, required: R, not: M, anyOf: I, allOf: z, oneOf: h, if: m, then: _, else: j, format: O, properties: D, patternProperties: K, additionalProperties: Z, unevaluatedProperties: oe, minProperties: H, maxProperties: G, propertyNames: q, dependentRequired: le, dependentSchemas: et, dependencies: tt, prefixItems: rt, items: be, additionalItems: Ot, unevaluatedItems: Mt, contains: At, minContains: se, maxContains: Ie, minItems: nt, maxItems: ot, uniqueItems: en, minimum: ue, maximum: de, exclusiveMinimum: _e, exclusiveMaximum: Se, multipleOf: Oe, minLength: Me, maxLength: Ae, pattern: jt, __absolute_ref__: je, __absolute_recursive_ref__: tn } = t, w = [];
5382
+ 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
5383
  if (v === !0 && s === null && (s = t), f === "#") {
5259
- const C = s === null ? n[tn] : s, S = `${l}/$recursiveRef`, E = L(e, s === null ? t : s, r, n, o, C, i, S, u);
5260
- E.valid || w.push({
5384
+ const C = s === null ? n[nn] : s, T = `${l}/$recursiveRef`, P = D(e, s === null ? t : s, r, n, o, C, i, T, u);
5385
+ P.valid || w.push({
5261
5386
  instanceLocation: i,
5262
5387
  keyword: "$recursiveRef",
5263
- keywordLocation: S,
5388
+ keywordLocation: T,
5264
5389
  error: "A subschema had errors."
5265
- }, ...E.errors);
5390
+ }, ...P.errors);
5266
5391
  }
5267
5392
  if (p !== void 0) {
5268
- const S = n[je || p];
5269
- if (S === void 0) {
5270
- let g = `Unresolved $ref "${p}".`;
5271
- throw je && je !== p && (g += ` Absolute URI "${je}".`), g += `
5393
+ const T = n[je || p];
5394
+ if (T === void 0) {
5395
+ let y = `Unresolved $ref "${p}".`;
5396
+ throw je && je !== p && (y += ` Absolute URI "${je}".`), y += `
5272
5397
  Known schemas:
5273
5398
  - ${Object.keys(n).join(`
5274
- - `)}`, new Error(g);
5399
+ - `)}`, new Error(y);
5275
5400
  }
5276
- const E = `${l}/$ref`, b = L(e, S, r, n, o, s, i, E, u);
5401
+ const P = `${l}/$ref`, b = D(e, T, r, n, o, s, i, P, u);
5277
5402
  if (b.valid || w.push({
5278
5403
  instanceLocation: i,
5279
5404
  keyword: "$ref",
5280
- keywordLocation: E,
5405
+ keywordLocation: P,
5281
5406
  error: "A subschema had errors."
5282
5407
  }, ...b.errors), r === "4" || r === "7")
5283
5408
  return { valid: w.length === 0, errors: w };
5284
5409
  }
5285
- if (Array.isArray(y)) {
5286
- let C = y.length, S = !1;
5287
- for (let E = 0; E < C; E++)
5288
- if (d === y[E] || y[E] === "integer" && d === "number" && e % 1 === 0 && e === e) {
5289
- S = !0;
5410
+ if (Array.isArray(m)) {
5411
+ let C = m.length, T = !1;
5412
+ for (let P = 0; P < C; P++)
5413
+ if (d === m[P] || m[P] === "integer" && d === "number" && e % 1 === 0 && e === e) {
5414
+ T = !0;
5290
5415
  break;
5291
5416
  }
5292
- S || w.push({
5417
+ T || w.push({
5293
5418
  instanceLocation: i,
5294
5419
  keyword: "type",
5295
5420
  keywordLocation: `${l}/type`,
5296
- error: `Instance type "${d}" is invalid. Expected "${y.join('", "')}".`
5421
+ error: `Instance type "${d}" is invalid. Expected "${m.join('", "')}".`
5297
5422
  });
5298
- } else y === "integer" ? (d !== "number" || e % 1 || e !== e) && w.push({
5423
+ } else m === "integer" ? (d !== "number" || e % 1 || e !== e) && w.push({
5299
5424
  instanceLocation: i,
5300
5425
  keyword: "type",
5301
5426
  keywordLocation: `${l}/type`,
5302
- error: `Instance type "${d}" is invalid. Expected "${y}".`
5303
- }) : y !== void 0 && d !== y && w.push({
5427
+ error: `Instance type "${d}" is invalid. Expected "${m}".`
5428
+ }) : m !== void 0 && d !== m && w.push({
5304
5429
  instanceLocation: i,
5305
5430
  keyword: "type",
5306
5431
  keywordLocation: `${l}/type`,
5307
- error: `Instance type "${d}" is invalid. Expected "${y}".`
5432
+ error: `Instance type "${d}" is invalid. Expected "${m}".`
5308
5433
  });
5309
- if (T !== void 0 && (d === "object" || d === "array" ? Te(e, T) || w.push({
5434
+ if (S !== void 0 && (d === "object" || d === "array" ? Te(e, S) || w.push({
5310
5435
  instanceLocation: i,
5311
5436
  keyword: "const",
5312
5437
  keywordLocation: `${l}/const`,
5313
- error: `Instance does not match ${JSON.stringify(T)}.`
5314
- }) : e !== T && w.push({
5438
+ error: `Instance does not match ${JSON.stringify(S)}.`
5439
+ }) : e !== S && w.push({
5315
5440
  instanceLocation: i,
5316
5441
  keyword: "const",
5317
5442
  keywordLocation: `${l}/const`,
5318
- error: `Instance does not match ${JSON.stringify(T)}.`
5443
+ error: `Instance does not match ${JSON.stringify(S)}.`
5319
5444
  })), x !== void 0 && (d === "object" || d === "array" ? x.some((C) => Te(e, C)) || w.push({
5320
5445
  instanceLocation: i,
5321
5446
  keyword: "enum",
@@ -5328,7 +5453,7 @@ Known schemas:
5328
5453
  error: `Instance does not match any of ${JSON.stringify(x)}.`
5329
5454
  })), M !== void 0) {
5330
5455
  const C = `${l}/not`;
5331
- L(e, M, r, n, o, s, i, C).valid && w.push({
5456
+ D(e, M, r, n, o, s, i, C).valid && w.push({
5332
5457
  instanceLocation: i,
5333
5458
  keyword: "not",
5334
5459
  keywordLocation: C,
@@ -5336,28 +5461,28 @@ Known schemas:
5336
5461
  });
5337
5462
  }
5338
5463
  let Ne = [];
5339
- if (I !== void 0) {
5340
- const C = `${l}/anyOf`, S = w.length;
5341
- let E = !1;
5342
- for (let b = 0; b < I.length; b++) {
5343
- const g = I[b], P = Object.create(u), $ = L(e, g, r, n, o, v === !0 ? s : null, i, `${C}/${b}`, P);
5344
- w.push(...$.errors), E = E || $.valid, $.valid && Ne.push(P);
5464
+ if (O !== void 0) {
5465
+ const C = `${l}/anyOf`, T = w.length;
5466
+ let P = !1;
5467
+ for (let b = 0; b < O.length; b++) {
5468
+ const y = O[b], E = Object.create(u), $ = D(e, y, r, n, o, v === !0 ? s : null, i, `${C}/${b}`, E);
5469
+ w.push(...$.errors), P = P || $.valid, $.valid && Ne.push(E);
5345
5470
  }
5346
- E ? w.length = S : w.splice(S, 0, {
5471
+ P ? w.length = T : w.splice(T, 0, {
5347
5472
  instanceLocation: i,
5348
5473
  keyword: "anyOf",
5349
5474
  keywordLocation: C,
5350
5475
  error: "Instance does not match any subschemas."
5351
5476
  });
5352
5477
  }
5353
- if (z !== void 0) {
5354
- const C = `${l}/allOf`, S = w.length;
5355
- let E = !0;
5356
- for (let b = 0; b < z.length; b++) {
5357
- const g = z[b], P = Object.create(u), $ = L(e, g, r, n, o, v === !0 ? s : null, i, `${C}/${b}`, P);
5358
- w.push(...$.errors), E = E && $.valid, $.valid && Ne.push(P);
5478
+ if (j !== void 0) {
5479
+ const C = `${l}/allOf`, T = w.length;
5480
+ let P = !0;
5481
+ for (let b = 0; b < j.length; b++) {
5482
+ const y = j[b], E = Object.create(u), $ = D(e, y, r, n, o, v === !0 ? s : null, i, `${C}/${b}`, E);
5483
+ w.push(...$.errors), P = P && $.valid, $.valid && Ne.push(E);
5359
5484
  }
5360
- E ? w.length = S : w.splice(S, 0, {
5485
+ P ? w.length = T : w.splice(T, 0, {
5361
5486
  instanceLocation: i,
5362
5487
  keyword: "allOf",
5363
5488
  keywordLocation: C,
@@ -5365,37 +5490,37 @@ Known schemas:
5365
5490
  });
5366
5491
  }
5367
5492
  if (h !== void 0) {
5368
- const C = `${l}/oneOf`, S = w.length, E = h.filter((b, g) => {
5369
- const P = Object.create(u), $ = L(e, b, r, n, o, v === !0 ? s : null, i, `${C}/${g}`, P);
5370
- return w.push(...$.errors), $.valid && Ne.push(P), $.valid;
5493
+ const C = `${l}/oneOf`, T = w.length, P = h.filter((b, y) => {
5494
+ const E = Object.create(u), $ = D(e, b, r, n, o, v === !0 ? s : null, i, `${C}/${y}`, E);
5495
+ return w.push(...$.errors), $.valid && Ne.push(E), $.valid;
5371
5496
  }).length;
5372
- E === 1 ? w.length = S : w.splice(S, 0, {
5497
+ P === 1 ? w.length = T : w.splice(T, 0, {
5373
5498
  instanceLocation: i,
5374
5499
  keyword: "oneOf",
5375
5500
  keywordLocation: C,
5376
- error: `Instance does not match exactly one subschema (${E} matches).`
5501
+ error: `Instance does not match exactly one subschema (${P} matches).`
5377
5502
  });
5378
5503
  }
5379
- if ((d === "object" || d === "array") && Object.assign(u, ...Ne), m !== void 0) {
5504
+ if ((d === "object" || d === "array") && Object.assign(u, ...Ne), g !== void 0) {
5380
5505
  const C = `${l}/if`;
5381
- if (L(e, m, r, n, o, s, i, C, u).valid) {
5506
+ if (D(e, g, r, n, o, s, i, C, u).valid) {
5382
5507
  if (_ !== void 0) {
5383
- const E = L(e, _, r, n, o, s, i, `${l}/then`, u);
5384
- E.valid || w.push({
5508
+ const P = D(e, _, r, n, o, s, i, `${l}/then`, u);
5509
+ P.valid || w.push({
5385
5510
  instanceLocation: i,
5386
5511
  keyword: "if",
5387
5512
  keywordLocation: C,
5388
5513
  error: 'Instance does not match "then" schema.'
5389
- }, ...E.errors);
5514
+ }, ...P.errors);
5390
5515
  }
5391
- } else if (j !== void 0) {
5392
- const E = L(e, j, r, n, o, s, i, `${l}/else`, u);
5393
- E.valid || w.push({
5516
+ } else if (N !== void 0) {
5517
+ const P = D(e, N, r, n, o, s, i, `${l}/else`, u);
5518
+ P.valid || w.push({
5394
5519
  instanceLocation: i,
5395
5520
  keyword: "if",
5396
5521
  keywordLocation: C,
5397
5522
  error: 'Instance does not match "else" schema.'
5398
- }, ...E.errors);
5523
+ }, ...P.errors);
5399
5524
  }
5400
5525
  }
5401
5526
  if (d === "object") {
@@ -5420,126 +5545,126 @@ Known schemas:
5420
5545
  error: `Instance does not have at least ${G} properties.`
5421
5546
  }), q !== void 0) {
5422
5547
  const b = `${l}/propertyNames`;
5423
- for (const g in e) {
5424
- const P = `${i}/${Q(g)}`, $ = L(g, q, r, n, o, s, P, b);
5548
+ for (const y in e) {
5549
+ const E = `${i}/${Q(y)}`, $ = D(y, q, r, n, o, s, E, b);
5425
5550
  $.valid || w.push({
5426
5551
  instanceLocation: i,
5427
5552
  keyword: "propertyNames",
5428
5553
  keywordLocation: b,
5429
- error: `Property name "${g}" does not match schema.`
5554
+ error: `Property name "${y}" does not match schema.`
5430
5555
  }, ...$.errors);
5431
5556
  }
5432
5557
  }
5433
5558
  if (le !== void 0) {
5434
5559
  const b = `${l}/dependantRequired`;
5435
- for (const g in le)
5436
- if (g in e) {
5437
- const P = le[g];
5438
- for (const $ of P)
5560
+ for (const y in le)
5561
+ if (y in e) {
5562
+ const E = le[y];
5563
+ for (const $ of E)
5439
5564
  $ in e || w.push({
5440
5565
  instanceLocation: i,
5441
5566
  keyword: "dependentRequired",
5442
5567
  keywordLocation: b,
5443
- error: `Instance has "${g}" but does not have "${$}".`
5568
+ error: `Instance has "${y}" but does not have "${$}".`
5444
5569
  });
5445
5570
  }
5446
5571
  }
5447
5572
  if (et !== void 0)
5448
5573
  for (const b in et) {
5449
- const g = `${l}/dependentSchemas`;
5574
+ const y = `${l}/dependentSchemas`;
5450
5575
  if (b in e) {
5451
- const P = L(e, et[b], r, n, o, s, i, `${g}/${Q(b)}`, u);
5452
- P.valid || w.push({
5576
+ const E = D(e, et[b], r, n, o, s, i, `${y}/${Q(b)}`, u);
5577
+ E.valid || w.push({
5453
5578
  instanceLocation: i,
5454
5579
  keyword: "dependentSchemas",
5455
- keywordLocation: g,
5580
+ keywordLocation: y,
5456
5581
  error: `Instance has "${b}" but does not match dependant schema.`
5457
- }, ...P.errors);
5582
+ }, ...E.errors);
5458
5583
  }
5459
5584
  }
5460
5585
  if (tt !== void 0) {
5461
5586
  const b = `${l}/dependencies`;
5462
- for (const g in tt)
5463
- if (g in e) {
5464
- const P = tt[g];
5465
- if (Array.isArray(P))
5466
- for (const $ of P)
5587
+ for (const y in tt)
5588
+ if (y in e) {
5589
+ const E = tt[y];
5590
+ if (Array.isArray(E))
5591
+ for (const $ of E)
5467
5592
  $ in e || w.push({
5468
5593
  instanceLocation: i,
5469
5594
  keyword: "dependencies",
5470
5595
  keywordLocation: b,
5471
- error: `Instance has "${g}" but does not have "${$}".`
5596
+ error: `Instance has "${y}" but does not have "${$}".`
5472
5597
  });
5473
5598
  else {
5474
- const $ = L(e, P, r, n, o, s, i, `${b}/${Q(g)}`);
5599
+ const $ = D(e, E, r, n, o, s, i, `${b}/${Q(y)}`);
5475
5600
  $.valid || w.push({
5476
5601
  instanceLocation: i,
5477
5602
  keyword: "dependencies",
5478
5603
  keywordLocation: b,
5479
- error: `Instance has "${g}" but does not match dependant schema.`
5604
+ error: `Instance has "${y}" but does not match dependant schema.`
5480
5605
  }, ...$.errors);
5481
5606
  }
5482
5607
  }
5483
5608
  }
5484
- const S = /* @__PURE__ */ Object.create(null);
5485
- let E = !1;
5486
- if (D !== void 0) {
5609
+ const T = /* @__PURE__ */ Object.create(null);
5610
+ let P = !1;
5611
+ if (L !== void 0) {
5487
5612
  const b = `${l}/properties`;
5488
- for (const g in D) {
5489
- if (!(g in e))
5613
+ for (const y in L) {
5614
+ if (!(y in e))
5490
5615
  continue;
5491
- const P = `${i}/${Q(g)}`, $ = L(e[g], D[g], r, n, o, s, P, `${b}/${Q(g)}`);
5616
+ const E = `${i}/${Q(y)}`, $ = D(e[y], L[y], r, n, o, s, E, `${b}/${Q(y)}`);
5492
5617
  if ($.valid)
5493
- u[g] = S[g] = !0;
5494
- else if (E = o, w.push({
5618
+ u[y] = T[y] = !0;
5619
+ else if (P = o, w.push({
5495
5620
  instanceLocation: i,
5496
5621
  keyword: "properties",
5497
5622
  keywordLocation: b,
5498
- error: `Property "${g}" does not match schema.`
5499
- }, ...$.errors), E)
5623
+ error: `Property "${y}" does not match schema.`
5624
+ }, ...$.errors), P)
5500
5625
  break;
5501
5626
  }
5502
5627
  }
5503
- if (!E && K !== void 0) {
5628
+ if (!P && K !== void 0) {
5504
5629
  const b = `${l}/patternProperties`;
5505
- for (const g in K) {
5506
- const P = new RegExp(g, "u"), $ = K[g];
5630
+ for (const y in K) {
5631
+ const E = new RegExp(y, "u"), $ = K[y];
5507
5632
  for (const W in e) {
5508
- if (!P.test(W))
5633
+ if (!E.test(W))
5509
5634
  continue;
5510
- const Nt = `${i}/${Q(W)}`, zt = L(e[W], $, r, n, o, s, Nt, `${b}/${Q(g)}`);
5511
- zt.valid ? u[W] = S[W] = !0 : (E = o, w.push({
5635
+ const Nt = `${i}/${Q(W)}`, zt = D(e[W], $, r, n, o, s, Nt, `${b}/${Q(y)}`);
5636
+ zt.valid ? u[W] = T[W] = !0 : (P = o, w.push({
5512
5637
  instanceLocation: i,
5513
5638
  keyword: "patternProperties",
5514
5639
  keywordLocation: b,
5515
- error: `Property "${W}" matches pattern "${g}" but does not match associated schema.`
5640
+ error: `Property "${W}" matches pattern "${y}" but does not match associated schema.`
5516
5641
  }, ...zt.errors));
5517
5642
  }
5518
5643
  }
5519
5644
  }
5520
- if (!E && Z !== void 0) {
5645
+ if (!P && Z !== void 0) {
5521
5646
  const b = `${l}/additionalProperties`;
5522
- for (const g in e) {
5523
- if (S[g])
5647
+ for (const y in e) {
5648
+ if (T[y])
5524
5649
  continue;
5525
- const P = `${i}/${Q(g)}`, $ = L(e[g], Z, r, n, o, s, P, b);
5526
- $.valid ? u[g] = !0 : (E = o, w.push({
5650
+ const E = `${i}/${Q(y)}`, $ = D(e[y], Z, r, n, o, s, E, b);
5651
+ $.valid ? u[y] = !0 : (P = o, w.push({
5527
5652
  instanceLocation: i,
5528
5653
  keyword: "additionalProperties",
5529
5654
  keywordLocation: b,
5530
- error: `Property "${g}" does not match additional properties schema.`
5655
+ error: `Property "${y}" does not match additional properties schema.`
5531
5656
  }, ...$.errors));
5532
5657
  }
5533
- } else if (!E && oe !== void 0) {
5658
+ } else if (!P && oe !== void 0) {
5534
5659
  const b = `${l}/unevaluatedProperties`;
5535
- for (const g in e)
5536
- if (!u[g]) {
5537
- const P = `${i}/${Q(g)}`, $ = L(e[g], oe, r, n, o, s, P, b);
5538
- $.valid ? u[g] = !0 : w.push({
5660
+ for (const y in e)
5661
+ if (!u[y]) {
5662
+ const E = `${i}/${Q(y)}`, $ = D(e[y], oe, r, n, o, s, E, b);
5663
+ $.valid ? u[y] = !0 : w.push({
5539
5664
  instanceLocation: i,
5540
5665
  keyword: "unevaluatedProperties",
5541
5666
  keywordLocation: b,
5542
- error: `Property "${g}" does not match unevaluated properties schema.`
5667
+ error: `Property "${y}" does not match unevaluated properties schema.`
5543
5668
  }, ...$.errors);
5544
5669
  }
5545
5670
  }
@@ -5556,59 +5681,59 @@ Known schemas:
5556
5681
  error: `Array has too few items (${e.length} < ${nt}).`
5557
5682
  });
5558
5683
  const C = e.length;
5559
- let S = 0, E = !1;
5684
+ let T = 0, P = !1;
5560
5685
  if (rt !== void 0) {
5561
- const b = `${l}/prefixItems`, g = Math.min(rt.length, C);
5562
- for (; S < g; S++) {
5563
- const P = L(e[S], rt[S], r, n, o, s, `${i}/${S}`, `${b}/${S}`);
5564
- if (u[S] = !0, !P.valid && (E = o, w.push({
5686
+ const b = `${l}/prefixItems`, y = Math.min(rt.length, C);
5687
+ for (; T < y; T++) {
5688
+ const E = D(e[T], rt[T], r, n, o, s, `${i}/${T}`, `${b}/${T}`);
5689
+ if (u[T] = !0, !E.valid && (P = o, w.push({
5565
5690
  instanceLocation: i,
5566
5691
  keyword: "prefixItems",
5567
5692
  keywordLocation: b,
5568
5693
  error: "Items did not match schema."
5569
- }, ...P.errors), E))
5694
+ }, ...E.errors), P))
5570
5695
  break;
5571
5696
  }
5572
5697
  }
5573
5698
  if (be !== void 0) {
5574
5699
  const b = `${l}/items`;
5575
5700
  if (Array.isArray(be)) {
5576
- const g = Math.min(be.length, C);
5577
- for (; S < g; S++) {
5578
- const P = L(e[S], be[S], r, n, o, s, `${i}/${S}`, `${b}/${S}`);
5579
- if (u[S] = !0, !P.valid && (E = o, w.push({
5701
+ const y = Math.min(be.length, C);
5702
+ for (; T < y; T++) {
5703
+ const E = D(e[T], be[T], r, n, o, s, `${i}/${T}`, `${b}/${T}`);
5704
+ if (u[T] = !0, !E.valid && (P = o, w.push({
5580
5705
  instanceLocation: i,
5581
5706
  keyword: "items",
5582
5707
  keywordLocation: b,
5583
5708
  error: "Items did not match schema."
5584
- }, ...P.errors), E))
5709
+ }, ...E.errors), P))
5585
5710
  break;
5586
5711
  }
5587
5712
  } else
5588
- for (; S < C; S++) {
5589
- const g = L(e[S], be, r, n, o, s, `${i}/${S}`, b);
5590
- if (u[S] = !0, !g.valid && (E = o, w.push({
5713
+ for (; T < C; T++) {
5714
+ const y = D(e[T], be, r, n, o, s, `${i}/${T}`, b);
5715
+ if (u[T] = !0, !y.valid && (P = o, w.push({
5591
5716
  instanceLocation: i,
5592
5717
  keyword: "items",
5593
5718
  keywordLocation: b,
5594
5719
  error: "Items did not match schema."
5595
- }, ...g.errors), E))
5720
+ }, ...y.errors), P))
5596
5721
  break;
5597
5722
  }
5598
- if (!E && Ot !== void 0) {
5599
- const g = `${l}/additionalItems`;
5600
- for (; S < C; S++) {
5601
- const P = L(e[S], Ot, r, n, o, s, `${i}/${S}`, g);
5602
- u[S] = !0, P.valid || (E = o, w.push({
5723
+ if (!P && At !== void 0) {
5724
+ const y = `${l}/additionalItems`;
5725
+ for (; T < C; T++) {
5726
+ const E = D(e[T], At, r, n, o, s, `${i}/${T}`, y);
5727
+ u[T] = !0, E.valid || (P = o, w.push({
5603
5728
  instanceLocation: i,
5604
5729
  keyword: "additionalItems",
5605
- keywordLocation: g,
5730
+ keywordLocation: y,
5606
5731
  error: "Items did not match additional items schema."
5607
- }, ...P.errors));
5732
+ }, ...E.errors));
5608
5733
  }
5609
5734
  }
5610
5735
  }
5611
- if (At !== void 0)
5736
+ if (Mt !== void 0)
5612
5737
  if (C === 0 && se === void 0)
5613
5738
  w.push({
5614
5739
  instanceLocation: i,
@@ -5624,51 +5749,51 @@ Known schemas:
5624
5749
  error: `Array has less items (${C}) than minContains (${se}).`
5625
5750
  });
5626
5751
  else {
5627
- const b = `${l}/contains`, g = w.length;
5628
- let P = 0;
5752
+ const b = `${l}/contains`, y = w.length;
5753
+ let E = 0;
5629
5754
  for (let $ = 0; $ < C; $++) {
5630
- const W = L(e[$], At, r, n, o, s, `${i}/${$}`, b);
5631
- W.valid ? (u[$] = !0, P++) : w.push(...W.errors);
5755
+ const W = D(e[$], Mt, r, n, o, s, `${i}/${$}`, b);
5756
+ W.valid ? (u[$] = !0, E++) : w.push(...W.errors);
5632
5757
  }
5633
- P >= (se || 0) && (w.length = g), se === void 0 && Ie === void 0 && P === 0 ? w.splice(g, 0, {
5758
+ E >= (se || 0) && (w.length = y), se === void 0 && Oe === void 0 && E === 0 ? w.splice(y, 0, {
5634
5759
  instanceLocation: i,
5635
5760
  keyword: "contains",
5636
5761
  keywordLocation: b,
5637
5762
  error: "Array does not contain item matching schema."
5638
- }) : se !== void 0 && P < se ? w.push({
5763
+ }) : se !== void 0 && E < se ? w.push({
5639
5764
  instanceLocation: i,
5640
5765
  keyword: "minContains",
5641
5766
  keywordLocation: `${l}/minContains`,
5642
- error: `Array must contain at least ${se} items matching schema. Only ${P} items were found.`
5643
- }) : Ie !== void 0 && P > Ie && w.push({
5767
+ error: `Array must contain at least ${se} items matching schema. Only ${E} items were found.`
5768
+ }) : Oe !== void 0 && E > Oe && w.push({
5644
5769
  instanceLocation: i,
5645
5770
  keyword: "maxContains",
5646
5771
  keywordLocation: `${l}/maxContains`,
5647
- error: `Array may contain at most ${Ie} items matching schema. ${P} items were found.`
5772
+ error: `Array may contain at most ${Oe} items matching schema. ${E} items were found.`
5648
5773
  });
5649
5774
  }
5650
- if (!E && Mt !== void 0) {
5775
+ if (!P && It !== void 0) {
5651
5776
  const b = `${l}/unevaluatedItems`;
5652
- for (S; S < C; S++) {
5653
- if (u[S])
5777
+ for (T; T < C; T++) {
5778
+ if (u[T])
5654
5779
  continue;
5655
- const g = L(e[S], Mt, r, n, o, s, `${i}/${S}`, b);
5656
- u[S] = !0, g.valid || w.push({
5780
+ const y = D(e[T], It, r, n, o, s, `${i}/${T}`, b);
5781
+ u[T] = !0, y.valid || w.push({
5657
5782
  instanceLocation: i,
5658
5783
  keyword: "unevaluatedItems",
5659
5784
  keywordLocation: b,
5660
5785
  error: "Items did not match unevaluated items schema."
5661
- }, ...g.errors);
5786
+ }, ...y.errors);
5662
5787
  }
5663
5788
  }
5664
- if (en)
5789
+ if (rn)
5665
5790
  for (let b = 0; b < C; b++) {
5666
- const g = e[b], P = typeof g == "object" && g !== null;
5791
+ const y = e[b], E = typeof y == "object" && y !== null;
5667
5792
  for (let $ = 0; $ < C; $++) {
5668
5793
  if (b === $)
5669
5794
  continue;
5670
5795
  const W = e[$];
5671
- (g === W || P && (typeof W == "object" && W !== null) && Te(g, W)) && (w.push({
5796
+ (y === W || E && (typeof W == "object" && W !== null) && Te(y, W)) && (w.push({
5672
5797
  instanceLocation: i,
5673
5798
  keyword: "uniqueItems",
5674
5799
  keywordLocation: `${l}/uniqueItems`,
@@ -5682,11 +5807,11 @@ Known schemas:
5682
5807
  keyword: "minimum",
5683
5808
  keywordLocation: `${l}/minimum`,
5684
5809
  error: `${e} is less than ${_e ? "or equal to " : ""} ${ue}.`
5685
- }), de !== void 0 && (Se === !0 && e >= de || e > de) && w.push({
5810
+ }), de !== void 0 && (xe === !0 && e >= de || e > de) && w.push({
5686
5811
  instanceLocation: i,
5687
5812
  keyword: "maximum",
5688
5813
  keywordLocation: `${l}/maximum`,
5689
- error: `${e} is greater than ${Se ? "or equal to " : ""} ${de}.`
5814
+ error: `${e} is greater than ${xe ? "or equal to " : ""} ${de}.`
5690
5815
  })) : (ue !== void 0 && e < ue && w.push({
5691
5816
  instanceLocation: i,
5692
5817
  keyword: "minimum",
@@ -5702,47 +5827,47 @@ Known schemas:
5702
5827
  keyword: "exclusiveMinimum",
5703
5828
  keywordLocation: `${l}/exclusiveMinimum`,
5704
5829
  error: `${e} is less than ${_e}.`
5705
- }), Se !== void 0 && e >= Se && w.push({
5830
+ }), xe !== void 0 && e >= xe && w.push({
5706
5831
  instanceLocation: i,
5707
5832
  keyword: "exclusiveMaximum",
5708
5833
  keywordLocation: `${l}/exclusiveMaximum`,
5709
- error: `${e} is greater than or equal to ${Se}.`
5710
- })), Oe !== void 0) {
5711
- const C = e % Oe;
5712
- Math.abs(0 - C) >= 11920929e-14 && Math.abs(Oe - C) >= 11920929e-14 && w.push({
5834
+ error: `${e} is greater than or equal to ${xe}.`
5835
+ })), Ae !== void 0) {
5836
+ const C = e % Ae;
5837
+ Math.abs(0 - C) >= 11920929e-14 && Math.abs(Ae - C) >= 11920929e-14 && w.push({
5713
5838
  instanceLocation: i,
5714
5839
  keyword: "multipleOf",
5715
5840
  keywordLocation: `${l}/multipleOf`,
5716
- error: `${e} is not a multiple of ${Oe}.`
5841
+ error: `${e} is not a multiple of ${Ae}.`
5717
5842
  });
5718
5843
  }
5719
5844
  } else if (d === "string") {
5720
- const C = Me === void 0 && Ae === void 0 ? 0 : Ki(e);
5721
- Me !== void 0 && C < Me && w.push({
5845
+ const C = Ie === void 0 && Me === void 0 ? 0 : ia(e);
5846
+ Ie !== void 0 && C < Ie && w.push({
5722
5847
  instanceLocation: i,
5723
5848
  keyword: "minLength",
5724
5849
  keywordLocation: `${l}/minLength`,
5725
- error: `String is too short (${C} < ${Me}).`
5726
- }), Ae !== void 0 && C > Ae && w.push({
5850
+ error: `String is too short (${C} < ${Ie}).`
5851
+ }), Me !== void 0 && C > Me && w.push({
5727
5852
  instanceLocation: i,
5728
5853
  keyword: "maxLength",
5729
5854
  keywordLocation: `${l}/maxLength`,
5730
- error: `String is too long (${C} > ${Ae}).`
5855
+ error: `String is too long (${C} > ${Me}).`
5731
5856
  }), jt !== void 0 && !new RegExp(jt, "u").test(e) && w.push({
5732
5857
  instanceLocation: i,
5733
5858
  keyword: "pattern",
5734
5859
  keywordLocation: `${l}/pattern`,
5735
5860
  error: "String does not match pattern."
5736
- }), O !== void 0 && cr[O] && !cr[O](e) && w.push({
5861
+ }), I !== void 0 && ur[I] && !ur[I](e) && w.push({
5737
5862
  instanceLocation: i,
5738
5863
  keyword: "format",
5739
5864
  keywordLocation: `${l}/format`,
5740
- error: `String does not match format "${O}".`
5865
+ error: `String does not match format "${I}".`
5741
5866
  });
5742
5867
  }
5743
5868
  return { valid: w.length === 0, errors: w };
5744
5869
  }
5745
- class Yi {
5870
+ class aa {
5746
5871
  schema;
5747
5872
  draft;
5748
5873
  shortCircuit;
@@ -5751,16 +5876,16 @@ class Yi {
5751
5876
  this.schema = t, this.draft = r, this.shortCircuit = n, this.lookup = he(t);
5752
5877
  }
5753
5878
  validate(t) {
5754
- return L(t, this.schema, this.draft, this.lookup, this.shortCircuit);
5879
+ return D(t, this.schema, this.draft, this.lookup, this.shortCircuit);
5755
5880
  }
5756
5881
  addSchema(t, r) {
5757
5882
  r && (t = { ...t, $id: r }), he(t, this.lookup);
5758
5883
  }
5759
5884
  }
5760
- const ur = "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 = {
5885
+ 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
5886
  type: "object",
5762
5887
  properties: {}
5763
- }, Xi = ["draft-2020-12", "draft-07"], Qi = "__isWebMCPPolyfill", Br = Symbol("standardValidator"), U = {
5888
+ }, la = ["draft-2020-12", "draft-07"], ca = "__isWebMCPPolyfill", Kr = Symbol("standardValidator"), U = {
5764
5889
  installed: !1,
5765
5890
  previousNavigatorModelContextDescriptor: void 0,
5766
5891
  previousNavigatorModelContextTestingDescriptor: void 0,
@@ -5769,7 +5894,7 @@ const ur = "Failed to parse input arguments", Ge = "Tool was executed but the in
5769
5894
  installedNavigatorModelContextTesting: !1,
5770
5895
  installedDocumentModelContext: !1
5771
5896
  };
5772
- var ea = class extends EventTarget {
5897
+ var ua = class extends EventTarget {
5773
5898
  tools = /* @__PURE__ */ new Map();
5774
5899
  testingShim = null;
5775
5900
  _ontoolchange = null;
@@ -5786,14 +5911,14 @@ var ea = class extends EventTarget {
5786
5911
  console.warn(`[WebMCPPolyfill] registerTool("${e?.name ?? "<unknown>"}") skipped: options.signal was already aborted.`);
5787
5912
  return;
5788
5913
  }
5789
- const n = la(e, this.tools);
5914
+ const n = va(e, this.tools);
5790
5915
  this.tools.set(n.name, n), this.notifyToolsChanged(), r && r.addEventListener("abort", () => {
5791
5916
  this.tools.delete(n.name) && this.notifyToolsChanged();
5792
5917
  }, { once: !0 });
5793
5918
  }
5794
5919
  unregisterTool(e) {
5795
5920
  this.warnUnregisterToolDeprecationOnce();
5796
- const t = na(e);
5921
+ const t = pa(e);
5797
5922
  this.tools.delete(t) && this.notifyToolsChanged();
5798
5923
  }
5799
5924
  getTools() {
@@ -5803,7 +5928,7 @@ var ea = class extends EventTarget {
5803
5928
  return this.executeToolByName(e.name, t, r, !1);
5804
5929
  }
5805
5930
  getTestingShim() {
5806
- return this.testingShim || (this.testingShim = new ta(this)), this.testingShim;
5931
+ return this.testingShim || (this.testingShim = new da(this)), this.testingShim;
5807
5932
  }
5808
5933
  /** @internal Used by PolyfillTestingShim */
5809
5934
  getToolInfos() {
@@ -5841,7 +5966,7 @@ var ea = class extends EventTarget {
5841
5966
  if (r?.signal?.aborted) throw te(bt);
5842
5967
  const o = this.tools.get(e);
5843
5968
  if (!o) throw te(`Tool not found: ${e}`);
5844
- const s = ra(t), i = await fa(s, o);
5969
+ const s = fa(t), i = await xa(s, o);
5845
5970
  if (i) throw te(i);
5846
5971
  let l = !0;
5847
5972
  const u = { requestUserInteraction: async (c) => {
@@ -5850,8 +5975,8 @@ var ea = class extends EventTarget {
5850
5975
  return c();
5851
5976
  } };
5852
5977
  try {
5853
- const c = o.execute(s, u), d = await ba(Promise.resolve(c), r?.signal);
5854
- if (n) return wa(ya(d));
5978
+ const c = o.execute(s, u), d = await ka(Promise.resolve(c), r?.signal);
5979
+ if (n) return Ra(Ea(d));
5855
5980
  const p = JSON.stringify(d);
5856
5981
  return p === void 0 ? null : p;
5857
5982
  } catch (c) {
@@ -5874,7 +5999,7 @@ var ea = class extends EventTarget {
5874
5999
  warnUnregisterToolDeprecationOnce() {
5875
6000
  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
6001
  }
5877
- }, ta = class extends EventTarget {
6002
+ }, da = class extends EventTarget {
5878
6003
  context;
5879
6004
  _ontoolchange = null;
5880
6005
  constructor(e) {
@@ -5922,17 +6047,17 @@ function te(e) {
5922
6047
  return t.name = "UnknownError", t;
5923
6048
  }
5924
6049
  }
5925
- function ra(e) {
6050
+ function fa(e) {
5926
6051
  let t;
5927
6052
  try {
5928
6053
  t = JSON.parse(e);
5929
6054
  } catch {
5930
- throw te(ur);
6055
+ throw te(dr);
5931
6056
  }
5932
- if (!t || typeof t != "object" || Array.isArray(t)) throw te(ur);
6057
+ if (!t || typeof t != "object" || Array.isArray(t)) throw te(dr);
5933
6058
  return t;
5934
6059
  }
5935
- function na(e) {
6060
+ function pa(e) {
5936
6061
  if (typeof e == "string") return e;
5937
6062
  if (V(e) && typeof e.name == "string") return e.name;
5938
6063
  throw new TypeError("Failed to execute 'unregisterTool' on 'ModelContext': parameter 1 must be a string or an object with a string name.");
@@ -5940,17 +6065,17 @@ function na(e) {
5940
6065
  function V(e) {
5941
6066
  return !!e && typeof e == "object" && !Array.isArray(e);
5942
6067
  }
5943
- function Gr(e) {
6068
+ function Yr(e) {
5944
6069
  if (!V(e)) return null;
5945
6070
  const t = e["~standard"];
5946
6071
  return V(t) ? t : null;
5947
6072
  }
5948
- function oa(e) {
5949
- const t = Gr(e);
6073
+ function ha(e) {
6074
+ const t = Yr(e);
5950
6075
  return !!(t && t.version === 1 && typeof t.validate == "function");
5951
6076
  }
5952
- function sa(e) {
5953
- const t = Gr(e);
6077
+ function ma(e) {
6078
+ const t = Yr(e);
5954
6079
  return !t || t.version !== 1 || !V(t.jsonSchema) ? !1 : typeof t.jsonSchema.input == "function";
5955
6080
  }
5956
6081
  function Ue(e) {
@@ -5959,21 +6084,21 @@ function Ue(e) {
5959
6084
  vendor: "@mcp-b/webmcp-polyfill-json-schema",
5960
6085
  validate(t) {
5961
6086
  if (!V(t)) return { issues: [{ message: "expected object arguments" }] };
5962
- const r = ca(t, e);
6087
+ const r = wa(t, e);
5963
6088
  return r ? { issues: [r] } : { value: t };
5964
6089
  }
5965
6090
  } };
5966
6091
  }
5967
- function ia(e) {
5968
- for (const t of Xi) try {
6092
+ function ga(e) {
6093
+ for (const t of la) try {
5969
6094
  const r = e["~standard"].jsonSchema.input({ target: t });
5970
- return Kr(r), r;
6095
+ return Xr(r), r;
5971
6096
  } catch (r) {
5972
6097
  console.warn(`[WebMCPPolyfill] Standard JSON Schema conversion failed for target "${t}":`, r);
5973
6098
  }
5974
6099
  throw new Error("Failed to convert Standard JSON Schema inputSchema to a JSON Schema object");
5975
6100
  }
5976
- function aa(e) {
6101
+ function ya(e) {
5977
6102
  if (e === void 0) {
5978
6103
  const r = ze;
5979
6104
  return {
@@ -5981,18 +6106,18 @@ function aa(e) {
5981
6106
  standardValidator: Ue(r)
5982
6107
  };
5983
6108
  }
5984
- if (sa(e)) {
5985
- const r = ia(e);
6109
+ if (ma(e)) {
6110
+ const r = ga(e);
5986
6111
  return {
5987
6112
  inputSchema: r,
5988
6113
  standardValidator: Ue(r)
5989
6114
  };
5990
6115
  }
5991
- if (oa(e)) return {
6116
+ if (ha(e)) return {
5992
6117
  inputSchema: ze,
5993
6118
  standardValidator: e
5994
6119
  };
5995
- if (Kr(e), Object.keys(e).length === 0) return {
6120
+ if (Xr(e), Object.keys(e).length === 0) return {
5996
6121
  inputSchema: ze,
5997
6122
  standardValidator: Ue(ze)
5998
6123
  };
@@ -6005,7 +6130,7 @@ function aa(e) {
6005
6130
  standardValidator: Ue(t)
6006
6131
  };
6007
6132
  }
6008
- function Kr(e) {
6133
+ function Xr(e) {
6009
6134
  if (!V(e)) throw new Error("inputSchema must be a JSON Schema object");
6010
6135
  me(e, "$");
6011
6136
  }
@@ -6054,13 +6179,13 @@ function me(e, t) {
6054
6179
  throw new Error(`Invalid JSON Schema at ${t}: schema must be JSON-serializable`);
6055
6180
  }
6056
6181
  }
6057
- function la(e, t) {
6182
+ function va(e, t) {
6058
6183
  if (!e || typeof e != "object") throw new TypeError("registerTool(tool) requires a tool object");
6059
6184
  if (typeof e.name != "string" || e.name.length === 0) throw new TypeError('Tool "name" must be a non-empty string');
6060
6185
  if (typeof e.description != "string" || e.description.length === 0) throw new TypeError('Tool "description" must be a non-empty string');
6061
6186
  if (typeof e.execute != "function") throw new TypeError('Tool "execute" must be a function');
6062
6187
  if (t.has(e.name)) throw new Error(`Tool already registered: ${e.name}`);
6063
- const r = aa(e.inputSchema), n = e.annotations, o = n ? {
6188
+ const r = ya(e.inputSchema), n = e.annotations, o = n ? {
6064
6189
  ...n,
6065
6190
  ...n.readOnlyHint === "true" ? { readOnlyHint: !0 } : n.readOnlyHint === "false" ? { readOnlyHint: !1 } : {},
6066
6191
  ...n.destructiveHint === "true" ? { destructiveHint: !0 } : n.destructiveHint === "false" ? { destructiveHint: !1 } : {},
@@ -6071,21 +6196,21 @@ function la(e, t) {
6071
6196
  ...e,
6072
6197
  ...o ? { annotations: o } : {},
6073
6198
  inputSchema: r.inputSchema,
6074
- [Br]: r.standardValidator
6199
+ [Kr]: r.standardValidator
6075
6200
  };
6076
6201
  }
6077
- function ca(e, t) {
6078
- const r = new Yi(t, "2020-12", !0).validate(e);
6202
+ function wa(e, t) {
6203
+ const r = new aa(t, "2020-12", !0).validate(e);
6079
6204
  if (r.valid) return null;
6080
6205
  const n = r.errors[r.errors.length - 1];
6081
6206
  return n ? { message: n.error } : { message: "Input validation failed" };
6082
6207
  }
6083
- function ua(e) {
6208
+ function ba(e) {
6084
6209
  if (!e || e.length === 0) return null;
6085
6210
  const t = e.map((r) => V(r) && "key" in r ? r.key : r).map((r) => String(r)).filter((r) => r.length > 0);
6086
6211
  return t.length === 0 ? null : t.join(".");
6087
6212
  }
6088
- async function da(e, t) {
6213
+ async function _a(e, t) {
6089
6214
  let r;
6090
6215
  try {
6091
6216
  r = await Promise.resolve(t["~standard"].validate(e));
@@ -6096,26 +6221,26 @@ async function da(e, t) {
6096
6221
  if (!r.issues || r.issues.length === 0) return null;
6097
6222
  const n = r.issues[0];
6098
6223
  if (!n) return "Input validation error";
6099
- const o = ua(n?.path);
6224
+ const o = ba(n?.path);
6100
6225
  return o ? `Input validation error: ${n.message} at ${o}` : `Input validation error: ${n.message}`;
6101
6226
  }
6102
- async function fa(e, t) {
6103
- return da(e, t[Br]);
6227
+ async function xa(e, t) {
6228
+ return _a(e, t[Kr]);
6104
6229
  }
6105
- function pa(e) {
6230
+ function Sa(e) {
6106
6231
  return V(e) && Array.isArray(e.content);
6107
6232
  }
6108
- function ha(e) {
6233
+ function Ta(e) {
6109
6234
  return e === null || typeof e == "string" || typeof e == "number" || typeof e == "boolean";
6110
6235
  }
6111
6236
  function _t(e) {
6112
- return ha(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;
6237
+ return Ta(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
6238
  }
6114
- function ma(e) {
6239
+ function Ca(e) {
6115
6240
  if (!(!V(e) || !_t(e)))
6116
6241
  return e;
6117
6242
  }
6118
- function ga(e) {
6243
+ function $a(e) {
6119
6244
  if (typeof e == "string") return e;
6120
6245
  try {
6121
6246
  return JSON.stringify(e) ?? String(e);
@@ -6123,24 +6248,24 @@ function ga(e) {
6123
6248
  return String(e);
6124
6249
  }
6125
6250
  }
6126
- function ya(e) {
6127
- if (pa(e)) return e;
6128
- const t = ma(e);
6251
+ function Ea(e) {
6252
+ if (Sa(e)) return e;
6253
+ const t = Ca(e);
6129
6254
  return {
6130
6255
  content: [{
6131
6256
  type: "text",
6132
- text: ga(e)
6257
+ text: $a(e)
6133
6258
  }],
6134
6259
  ...t ? { structuredContent: t } : {},
6135
6260
  isError: !1
6136
6261
  };
6137
6262
  }
6138
- function va(e) {
6263
+ function Pa(e) {
6139
6264
  for (const t of e.content ?? []) if (t.type === "text" && "text" in t && typeof t.text == "string") return t.text;
6140
6265
  return null;
6141
6266
  }
6142
- function wa(e) {
6143
- if (e.isError) throw te(va(e)?.replace(/^Error:\s*/i, "").trim() || Ge);
6267
+ function Ra(e) {
6268
+ if (e.isError) throw te(Pa(e)?.replace(/^Error:\s*/i, "").trim() || Ge);
6144
6269
  const t = e.metadata;
6145
6270
  if (t && typeof t == "object" && t.willNavigate) return null;
6146
6271
  try {
@@ -6149,7 +6274,7 @@ function wa(e) {
6149
6274
  throw te(Ge);
6150
6275
  }
6151
6276
  }
6152
- function ba(e, t) {
6277
+ function ka(e, t) {
6153
6278
  return t ? t.aborted ? Promise.reject(te(bt)) : new Promise((r, n) => {
6154
6279
  const o = () => {
6155
6280
  s(), n(te(bt));
@@ -6163,13 +6288,13 @@ function ba(e, t) {
6163
6288
  });
6164
6289
  }) : e;
6165
6290
  }
6166
- function Yr() {
6291
+ function Qr() {
6167
6292
  return typeof navigator < "u" ? navigator : null;
6168
6293
  }
6169
- function Xr() {
6294
+ function en() {
6170
6295
  return typeof document < "u" ? document : null;
6171
6296
  }
6172
- function _a(e, t, r) {
6297
+ function Oa(e, t, r) {
6173
6298
  Object.defineProperty(e, t, {
6174
6299
  configurable: !0,
6175
6300
  enumerable: !0,
@@ -6177,7 +6302,7 @@ function _a(e, t, r) {
6177
6302
  value: r
6178
6303
  });
6179
6304
  }
6180
- function dr(e, t) {
6305
+ function fr(e, t) {
6181
6306
  Object.defineProperty(e, "modelContext", {
6182
6307
  configurable: !0,
6183
6308
  enumerable: !0,
@@ -6186,7 +6311,7 @@ function dr(e, t) {
6186
6311
  });
6187
6312
  }
6188
6313
  let Ke = !1;
6189
- function Sa(e, t) {
6314
+ function Aa(e, t) {
6190
6315
  Object.defineProperty(e, "modelContext", {
6191
6316
  configurable: !0,
6192
6317
  enumerable: !0,
@@ -6195,24 +6320,24 @@ function Sa(e, t) {
6195
6320
  }
6196
6321
  });
6197
6322
  }
6198
- function Qr(e) {
6199
- const t = Yr(), r = Xr();
6323
+ function tn(e) {
6324
+ const t = Qr(), r = en();
6200
6325
  if (!t && !r || r?.modelContext) return;
6201
6326
  const o = t?.modelContext, s = !!o;
6202
- if (U.installed && xa(), r && o) {
6203
- U.previousDocumentModelContextDescriptor = Object.getOwnPropertyDescriptor(r, "modelContext"), dr(r, o), U.installedDocumentModelContext = !0, U.installed = !0;
6327
+ if (U.installed && Ia(), r && o) {
6328
+ U.previousDocumentModelContextDescriptor = Object.getOwnPropertyDescriptor(r, "modelContext"), fr(r, o), U.installedDocumentModelContext = !0, U.installed = !0;
6204
6329
  return;
6205
6330
  }
6206
6331
  if (s) return;
6207
- const i = new ea(), l = i;
6208
- if (l[Qi] = !0, r && (U.previousDocumentModelContextDescriptor = Object.getOwnPropertyDescriptor(r, "modelContext"), dr(r, l), U.installedDocumentModelContext = !0), t) {
6209
- U.previousNavigatorModelContextDescriptor = Object.getOwnPropertyDescriptor(t, "modelContext"), U.previousNavigatorModelContextTestingDescriptor = Object.getOwnPropertyDescriptor(t, "modelContextTesting"), Ke = !1, Sa(t, l), U.installedNavigatorModelContext = !0;
6332
+ const i = new ua(), l = i;
6333
+ if (l[ca] = !0, r && (U.previousDocumentModelContextDescriptor = Object.getOwnPropertyDescriptor(r, "modelContext"), fr(r, l), U.installedDocumentModelContext = !0), t) {
6334
+ U.previousNavigatorModelContextDescriptor = Object.getOwnPropertyDescriptor(t, "modelContext"), U.previousNavigatorModelContextTestingDescriptor = Object.getOwnPropertyDescriptor(t, "modelContextTesting"), Ke = !1, Aa(t, l), U.installedNavigatorModelContext = !0;
6210
6335
  const u = e?.installTestingShim ?? "if-missing", c = !!t.modelContextTesting;
6211
- (u === "always" || (u === !0 || u === "if-missing") && !c) && (_a(t, "modelContextTesting", i.getTestingShim()), U.installedNavigatorModelContextTesting = !0);
6336
+ (u === "always" || (u === !0 || u === "if-missing") && !c) && (Oa(t, "modelContextTesting", i.getTestingShim()), U.installedNavigatorModelContextTesting = !0);
6212
6337
  }
6213
6338
  U.installed = !0;
6214
6339
  }
6215
- function xa() {
6340
+ function Ia() {
6216
6341
  if (!U.installed) return;
6217
6342
  const e = (n, o, s) => {
6218
6343
  if (s) {
@@ -6220,60 +6345,54 @@ function xa() {
6220
6345
  return;
6221
6346
  }
6222
6347
  delete n[o];
6223
- }, t = Yr(), r = Xr();
6348
+ }, t = Qr(), r = en();
6224
6349
  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
6350
  }
6226
6351
  if (typeof window < "u" && typeof document < "u") {
6227
6352
  const e = window.__webMCPPolyfillOptions;
6228
6353
  if (e?.autoInitialize !== !1) try {
6229
- Qr(e);
6354
+ tn(e);
6230
6355
  } catch (t) {
6231
6356
  console.error("[WebMCPPolyfill] Auto-initialization failed:", t);
6232
6357
  }
6233
6358
  }
6234
- let fr = !1;
6235
- const rl = () => {
6359
+ let pr = !1;
6360
+ const ul = () => {
6236
6361
  if (ae())
6237
6362
  try {
6238
- if (fr) return;
6239
- Qr(), _i(), fr = !0;
6363
+ if (pr) return;
6364
+ tn(), Oi(), pr = !0;
6240
6365
  } catch (e) {
6241
6366
  console.warn("[next-sdk] 自动注入 modelContext polyfill 和桥接同步失败:", e);
6242
6367
  }
6243
6368
  };
6244
6369
  export {
6245
- Ya as A,
6246
- xa as B,
6247
- Qr as C,
6248
- V as D,
6249
- jn as E,
6250
- ca as F,
6370
+ sl as A,
6251
6371
  ve as M,
6252
- Ua as W,
6253
- Da as a,
6254
- qa as b,
6255
- La as c,
6256
- Ha as d,
6257
- In as e,
6258
- Fa as f,
6259
- oi as g,
6260
- Za as h,
6261
- rl as i,
6262
- Va as j,
6263
- Ja as k,
6264
- On as l,
6265
- Wa as m,
6266
- Ba as n,
6267
- Ka as o,
6268
- An as p,
6269
- Mn as q,
6270
- Nn as r,
6271
- Ga as s,
6272
- Be as t,
6273
- gi as u,
6274
- Xa as v,
6275
- Qa as w,
6276
- el as x,
6277
- tl as y,
6278
- _i as z
6372
+ Ba as W,
6373
+ Ka as a,
6374
+ Ya as b,
6375
+ Ga as c,
6376
+ Xa as d,
6377
+ An as e,
6378
+ Qa as f,
6379
+ pi as g,
6380
+ el as h,
6381
+ ul as i,
6382
+ tl as j,
6383
+ rl as k,
6384
+ In as l,
6385
+ nl as m,
6386
+ ol as n,
6387
+ Be as o,
6388
+ $i as p,
6389
+ cl as q,
6390
+ al as r,
6391
+ il as s,
6392
+ Oi as t,
6393
+ Ia as u,
6394
+ tn as v,
6395
+ ll as w,
6396
+ V as x,
6397
+ wa as y
6279
6398
  };