@xyd-js/ask-ai-edge 0.0.0-build-60554d1-20251028180454 → 0.0.0-build-c7bdbdb-20251129215505

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 (2) hide show
  1. package/dist/index.js +1993 -500
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -17666,9 +17666,6 @@ var postToApi = async ({
17666
17666
  function tool(tool2) {
17667
17667
  return tool2;
17668
17668
  }
17669
- function dynamicTool(tool2) {
17670
- return { ...tool2, type: "dynamic" };
17671
- }
17672
17669
  function createProviderDefinedToolFactory({
17673
17670
  id,
17674
17671
  name: name14,
@@ -19774,23 +19771,6 @@ var name53 = "AI_MCPClientError";
19774
19771
  var marker53 = `vercel.ai.error.${name53}`;
19775
19772
  var symbol53 = Symbol.for(marker53);
19776
19773
  var _a53;
19777
- var MCPClientError = class extends AISDKError {
19778
- constructor({
19779
- name: name17 = "MCPClientError",
19780
- message,
19781
- cause,
19782
- data,
19783
- code
19784
- }) {
19785
- super({ name: name17, message, cause });
19786
- this[_a53] = true;
19787
- this.data = data;
19788
- this.code = code;
19789
- }
19790
- static isInstance(error40) {
19791
- return AISDKError.hasMarker(error40, marker53);
19792
- }
19793
- };
19794
19774
  _a53 = symbol53;
19795
19775
  var name63 = "AI_NoImageGeneratedError";
19796
19776
  var marker63 = `vercel.ai.error.${name63}`;
@@ -24178,12 +24158,6 @@ var marker16 = `vercel.ai.error.${name162}`;
24178
24158
  var symbol16 = Symbol.for(marker16);
24179
24159
  var _a16;
24180
24160
  _a16 = symbol16;
24181
- var LATEST_PROTOCOL_VERSION = "2025-06-18";
24182
- var SUPPORTED_PROTOCOL_VERSIONS = [
24183
- LATEST_PROTOCOL_VERSION,
24184
- "2025-03-26",
24185
- "2024-11-05"
24186
- ];
24187
24161
  var ClientOrServerImplementationSchema = exports_external.looseObject({
24188
24162
  name: exports_external.string(),
24189
24163
  version: exports_external.string()
@@ -24290,52 +24264,1274 @@ var JSONRPCMessageSchema = exports_external.union([
24290
24264
  JSONRPCResponseSchema,
24291
24265
  JSONRPCErrorSchema
24292
24266
  ]);
24293
- var SseMCPTransport = class {
24294
- constructor({
24295
- url: url2,
24296
- headers
24297
- }) {
24298
- this.connected = false;
24299
- this.url = new URL(url2);
24300
- this.headers = headers;
24267
+ var uiMessagesSchema = lazyValidator(() => zodSchema(exports_external.array(exports_external.object({
24268
+ id: exports_external.string(),
24269
+ role: exports_external.enum(["system", "user", "assistant"]),
24270
+ metadata: exports_external.unknown().optional(),
24271
+ parts: exports_external.array(exports_external.union([
24272
+ exports_external.object({
24273
+ type: exports_external.literal("text"),
24274
+ text: exports_external.string(),
24275
+ state: exports_external.enum(["streaming", "done"]).optional(),
24276
+ providerMetadata: providerMetadataSchema.optional()
24277
+ }),
24278
+ exports_external.object({
24279
+ type: exports_external.literal("reasoning"),
24280
+ text: exports_external.string(),
24281
+ state: exports_external.enum(["streaming", "done"]).optional(),
24282
+ providerMetadata: providerMetadataSchema.optional()
24283
+ }),
24284
+ exports_external.object({
24285
+ type: exports_external.literal("source-url"),
24286
+ sourceId: exports_external.string(),
24287
+ url: exports_external.string(),
24288
+ title: exports_external.string().optional(),
24289
+ providerMetadata: providerMetadataSchema.optional()
24290
+ }),
24291
+ exports_external.object({
24292
+ type: exports_external.literal("source-document"),
24293
+ sourceId: exports_external.string(),
24294
+ mediaType: exports_external.string(),
24295
+ title: exports_external.string(),
24296
+ filename: exports_external.string().optional(),
24297
+ providerMetadata: providerMetadataSchema.optional()
24298
+ }),
24299
+ exports_external.object({
24300
+ type: exports_external.literal("file"),
24301
+ mediaType: exports_external.string(),
24302
+ filename: exports_external.string().optional(),
24303
+ url: exports_external.string(),
24304
+ providerMetadata: providerMetadataSchema.optional()
24305
+ }),
24306
+ exports_external.object({
24307
+ type: exports_external.literal("step-start")
24308
+ }),
24309
+ exports_external.object({
24310
+ type: exports_external.string().startsWith("data-"),
24311
+ id: exports_external.string().optional(),
24312
+ data: exports_external.unknown()
24313
+ }),
24314
+ exports_external.object({
24315
+ type: exports_external.literal("dynamic-tool"),
24316
+ toolName: exports_external.string(),
24317
+ toolCallId: exports_external.string(),
24318
+ state: exports_external.literal("input-streaming"),
24319
+ input: exports_external.unknown().optional(),
24320
+ output: exports_external.never().optional(),
24321
+ errorText: exports_external.never().optional()
24322
+ }),
24323
+ exports_external.object({
24324
+ type: exports_external.literal("dynamic-tool"),
24325
+ toolName: exports_external.string(),
24326
+ toolCallId: exports_external.string(),
24327
+ state: exports_external.literal("input-available"),
24328
+ input: exports_external.unknown(),
24329
+ output: exports_external.never().optional(),
24330
+ errorText: exports_external.never().optional(),
24331
+ callProviderMetadata: providerMetadataSchema.optional()
24332
+ }),
24333
+ exports_external.object({
24334
+ type: exports_external.literal("dynamic-tool"),
24335
+ toolName: exports_external.string(),
24336
+ toolCallId: exports_external.string(),
24337
+ state: exports_external.literal("output-available"),
24338
+ input: exports_external.unknown(),
24339
+ output: exports_external.unknown(),
24340
+ errorText: exports_external.never().optional(),
24341
+ callProviderMetadata: providerMetadataSchema.optional(),
24342
+ preliminary: exports_external.boolean().optional()
24343
+ }),
24344
+ exports_external.object({
24345
+ type: exports_external.literal("dynamic-tool"),
24346
+ toolName: exports_external.string(),
24347
+ toolCallId: exports_external.string(),
24348
+ state: exports_external.literal("output-error"),
24349
+ input: exports_external.unknown(),
24350
+ output: exports_external.never().optional(),
24351
+ errorText: exports_external.string(),
24352
+ callProviderMetadata: providerMetadataSchema.optional()
24353
+ }),
24354
+ exports_external.object({
24355
+ type: exports_external.string().startsWith("tool-"),
24356
+ toolCallId: exports_external.string(),
24357
+ state: exports_external.literal("input-streaming"),
24358
+ providerExecuted: exports_external.boolean().optional(),
24359
+ input: exports_external.unknown().optional(),
24360
+ output: exports_external.never().optional(),
24361
+ errorText: exports_external.never().optional(),
24362
+ approval: exports_external.never().optional()
24363
+ }),
24364
+ exports_external.object({
24365
+ type: exports_external.string().startsWith("tool-"),
24366
+ toolCallId: exports_external.string(),
24367
+ state: exports_external.literal("input-available"),
24368
+ providerExecuted: exports_external.boolean().optional(),
24369
+ input: exports_external.unknown(),
24370
+ output: exports_external.never().optional(),
24371
+ errorText: exports_external.never().optional(),
24372
+ callProviderMetadata: providerMetadataSchema.optional(),
24373
+ approval: exports_external.never().optional()
24374
+ }),
24375
+ exports_external.object({
24376
+ type: exports_external.string().startsWith("tool-"),
24377
+ toolCallId: exports_external.string(),
24378
+ state: exports_external.literal("approval-requested"),
24379
+ input: exports_external.unknown(),
24380
+ providerExecuted: exports_external.boolean().optional(),
24381
+ output: exports_external.never().optional(),
24382
+ errorText: exports_external.never().optional(),
24383
+ callProviderMetadata: providerMetadataSchema.optional(),
24384
+ approval: exports_external.object({
24385
+ id: exports_external.string(),
24386
+ approved: exports_external.never().optional(),
24387
+ reason: exports_external.never().optional()
24388
+ })
24389
+ }),
24390
+ exports_external.object({
24391
+ type: exports_external.string().startsWith("tool-"),
24392
+ toolCallId: exports_external.string(),
24393
+ state: exports_external.literal("approval-responded"),
24394
+ input: exports_external.unknown(),
24395
+ providerExecuted: exports_external.boolean().optional(),
24396
+ output: exports_external.never().optional(),
24397
+ errorText: exports_external.never().optional(),
24398
+ callProviderMetadata: providerMetadataSchema.optional(),
24399
+ approval: exports_external.object({
24400
+ id: exports_external.string(),
24401
+ approved: exports_external.boolean(),
24402
+ reason: exports_external.string().optional()
24403
+ })
24404
+ }),
24405
+ exports_external.object({
24406
+ type: exports_external.string().startsWith("tool-"),
24407
+ toolCallId: exports_external.string(),
24408
+ state: exports_external.literal("output-available"),
24409
+ providerExecuted: exports_external.boolean().optional(),
24410
+ input: exports_external.unknown(),
24411
+ output: exports_external.unknown(),
24412
+ errorText: exports_external.never().optional(),
24413
+ callProviderMetadata: providerMetadataSchema.optional(),
24414
+ preliminary: exports_external.boolean().optional(),
24415
+ approval: exports_external.object({
24416
+ id: exports_external.string(),
24417
+ approved: exports_external.literal(true),
24418
+ reason: exports_external.string().optional()
24419
+ }).optional()
24420
+ }),
24421
+ exports_external.object({
24422
+ type: exports_external.string().startsWith("tool-"),
24423
+ toolCallId: exports_external.string(),
24424
+ state: exports_external.literal("output-error"),
24425
+ providerExecuted: exports_external.boolean().optional(),
24426
+ input: exports_external.unknown(),
24427
+ output: exports_external.never().optional(),
24428
+ errorText: exports_external.string(),
24429
+ callProviderMetadata: providerMetadataSchema.optional(),
24430
+ approval: exports_external.object({
24431
+ id: exports_external.string(),
24432
+ approved: exports_external.literal(true),
24433
+ reason: exports_external.string().optional()
24434
+ }).optional()
24435
+ }),
24436
+ exports_external.object({
24437
+ type: exports_external.string().startsWith("tool-"),
24438
+ toolCallId: exports_external.string(),
24439
+ state: exports_external.literal("output-denied"),
24440
+ providerExecuted: exports_external.boolean().optional(),
24441
+ input: exports_external.unknown(),
24442
+ output: exports_external.never().optional(),
24443
+ errorText: exports_external.never().optional(),
24444
+ callProviderMetadata: providerMetadataSchema.optional(),
24445
+ approval: exports_external.object({
24446
+ id: exports_external.string(),
24447
+ approved: exports_external.literal(false),
24448
+ reason: exports_external.string().optional()
24449
+ })
24450
+ })
24451
+ ]))
24452
+ }))));
24453
+ // ../../node_modules/.pnpm/@ai-sdk+provider-utils@3.0.18_zod@3.25.76/node_modules/@ai-sdk/provider-utils/dist/index.mjs
24454
+ var createIdGenerator2 = ({
24455
+ prefix,
24456
+ size = 16,
24457
+ alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
24458
+ separator = "-"
24459
+ } = {}) => {
24460
+ const generator = () => {
24461
+ const alphabetLength = alphabet.length;
24462
+ const chars = new Array(size);
24463
+ for (let i = 0;i < size; i++) {
24464
+ chars[i] = alphabet[Math.random() * alphabetLength | 0];
24465
+ }
24466
+ return chars.join("");
24467
+ };
24468
+ if (prefix == null) {
24469
+ return generator;
24301
24470
  }
24302
- async start() {
24303
- return new Promise((resolve2, reject) => {
24304
- if (this.connected) {
24305
- return resolve2();
24306
- }
24307
- this.abortController = new AbortController;
24308
- const establishConnection = async () => {
24309
- var _a172, _b8, _c;
24310
- try {
24311
- const headers = withUserAgentSuffix({
24312
- ...this.headers,
24313
- Accept: "text/event-stream"
24314
- }, `ai-sdk/${VERSION3}`, getRuntimeEnvironmentUserAgent());
24315
- const response = await fetch(this.url.href, {
24316
- headers,
24317
- signal: (_a172 = this.abortController) == null ? undefined : _a172.signal
24318
- });
24319
- if (!response.ok || !response.body) {
24320
- const error40 = new MCPClientError({
24321
- message: `MCP SSE Transport Error: ${response.status} ${response.statusText}`
24322
- });
24323
- (_b8 = this.onerror) == null || _b8.call(this, error40);
24324
- return reject(error40);
24325
- }
24326
- const stream = response.body.pipeThrough(new TextDecoderStream).pipeThrough(new EventSourceParserStream);
24327
- const reader = stream.getReader();
24328
- const processEvents = async () => {
24329
- var _a18, _b22, _c2;
24330
- try {
24331
- while (true) {
24332
- const { done, value } = await reader.read();
24333
- if (done) {
24334
- if (this.connected) {
24335
- this.connected = false;
24336
- throw new MCPClientError({
24337
- message: "MCP SSE Transport Error: Connection closed unexpectedly"
24338
- });
24471
+ if (alphabet.includes(separator)) {
24472
+ throw new InvalidArgumentError({
24473
+ argument: "separator",
24474
+ message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
24475
+ });
24476
+ }
24477
+ return () => `${prefix}${separator}${generator()}`;
24478
+ };
24479
+ var generateId2 = createIdGenerator2();
24480
+ function getRuntimeEnvironmentUserAgent2(globalThisAny = globalThis) {
24481
+ var _a18, _b8, _c;
24482
+ if (globalThisAny.window) {
24483
+ return `runtime/browser`;
24484
+ }
24485
+ if ((_a18 = globalThisAny.navigator) == null ? undefined : _a18.userAgent) {
24486
+ return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
24487
+ }
24488
+ if ((_c = (_b8 = globalThisAny.process) == null ? undefined : _b8.versions) == null ? undefined : _c.node) {
24489
+ return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
24490
+ }
24491
+ if (globalThisAny.EdgeRuntime) {
24492
+ return `runtime/vercel-edge`;
24493
+ }
24494
+ return "runtime/unknown";
24495
+ }
24496
+ function normalizeHeaders(headers) {
24497
+ if (headers == null) {
24498
+ return {};
24499
+ }
24500
+ const normalized = {};
24501
+ if (headers instanceof Headers) {
24502
+ headers.forEach((value, key) => {
24503
+ normalized[key.toLowerCase()] = value;
24504
+ });
24505
+ } else {
24506
+ if (!Array.isArray(headers)) {
24507
+ headers = Object.entries(headers);
24508
+ }
24509
+ for (const [key, value] of headers) {
24510
+ if (value != null) {
24511
+ normalized[key.toLowerCase()] = value;
24512
+ }
24513
+ }
24514
+ }
24515
+ return normalized;
24516
+ }
24517
+ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
24518
+ const normalizedHeaders = new Headers(normalizeHeaders(headers));
24519
+ const currentUserAgentHeader = normalizedHeaders.get("user-agent") || "";
24520
+ normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
24521
+ return Object.fromEntries(normalizedHeaders.entries());
24522
+ }
24523
+ var validatorSymbol2 = Symbol.for("vercel.ai.validator");
24524
+ function tool2(tool22) {
24525
+ return tool22;
24526
+ }
24527
+ function dynamicTool(tool22) {
24528
+ return { ...tool22, type: "dynamic" };
24529
+ }
24530
+ var ignoreOverride2 = Symbol("Let zodToJsonSchema decide on which parser to use");
24531
+ var ALPHA_NUMERIC2 = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
24532
+ var schemaSymbol2 = Symbol.for("vercel.ai.schema");
24533
+ function jsonSchema2(jsonSchema22, {
24534
+ validate
24535
+ } = {}) {
24536
+ return {
24537
+ [schemaSymbol2]: true,
24538
+ _type: undefined,
24539
+ [validatorSymbol2]: true,
24540
+ get jsonSchema() {
24541
+ if (typeof jsonSchema22 === "function") {
24542
+ jsonSchema22 = jsonSchema22();
24543
+ }
24544
+ return jsonSchema22;
24545
+ },
24546
+ validate
24547
+ };
24548
+ }
24549
+
24550
+ // ../../node_modules/.pnpm/pkce-challenge@5.0.0/node_modules/pkce-challenge/dist/index.node.js
24551
+ var crypto;
24552
+ crypto = globalThis.crypto?.webcrypto ?? globalThis.crypto ?? import("node:crypto").then((m) => m.webcrypto);
24553
+ async function getRandomValues(size) {
24554
+ return (await crypto).getRandomValues(new Uint8Array(size));
24555
+ }
24556
+ async function random(size) {
24557
+ const mask = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~";
24558
+ let result = "";
24559
+ const randomUints = await getRandomValues(size);
24560
+ for (let i = 0;i < size; i++) {
24561
+ const randomIndex = randomUints[i] % mask.length;
24562
+ result += mask[randomIndex];
24563
+ }
24564
+ return result;
24565
+ }
24566
+ async function generateVerifier(length) {
24567
+ return await random(length);
24568
+ }
24569
+ async function generateChallenge(code_verifier) {
24570
+ const buffer = await (await crypto).subtle.digest("SHA-256", new TextEncoder().encode(code_verifier));
24571
+ return btoa(String.fromCharCode(...new Uint8Array(buffer))).replace(/\//g, "_").replace(/\+/g, "-").replace(/=/g, "");
24572
+ }
24573
+ async function pkceChallenge(length) {
24574
+ if (!length)
24575
+ length = 43;
24576
+ if (length < 43 || length > 128) {
24577
+ throw `Expected a length between 43 and 128. Received ${length}.`;
24578
+ }
24579
+ const verifier = await generateVerifier(length);
24580
+ const challenge = await generateChallenge(verifier);
24581
+ return {
24582
+ code_verifier: verifier,
24583
+ code_challenge: challenge
24584
+ };
24585
+ }
24586
+
24587
+ // ../../node_modules/.pnpm/@ai-sdk+mcp@0.0.11_zod@3.25.76/node_modules/@ai-sdk/mcp/dist/index.mjs
24588
+ var name17 = "AI_MCPClientError";
24589
+ var marker18 = `vercel.ai.error.${name17}`;
24590
+ var symbol19 = Symbol.for(marker18);
24591
+ var _a18;
24592
+ var _b8;
24593
+ var MCPClientError = class extends (_b8 = AISDKError, _a18 = symbol19, _b8) {
24594
+ constructor({
24595
+ name: name34 = "MCPClientError",
24596
+ message,
24597
+ cause,
24598
+ data,
24599
+ code
24600
+ }) {
24601
+ super({ name: name34, message, cause });
24602
+ this[_a18] = true;
24603
+ this.data = data;
24604
+ this.code = code;
24605
+ }
24606
+ static isInstance(error40) {
24607
+ return AISDKError.hasMarker(error40, marker18);
24608
+ }
24609
+ };
24610
+ var LATEST_PROTOCOL_VERSION = "2025-06-18";
24611
+ var SUPPORTED_PROTOCOL_VERSIONS = [
24612
+ LATEST_PROTOCOL_VERSION,
24613
+ "2025-03-26",
24614
+ "2024-11-05"
24615
+ ];
24616
+ var ClientOrServerImplementationSchema2 = exports_external.looseObject({
24617
+ name: exports_external.string(),
24618
+ version: exports_external.string()
24619
+ });
24620
+ var BaseParamsSchema2 = exports_external.looseObject({
24621
+ _meta: exports_external.optional(exports_external.object({}).loose())
24622
+ });
24623
+ var ResultSchema2 = BaseParamsSchema2;
24624
+ var RequestSchema2 = exports_external.object({
24625
+ method: exports_external.string(),
24626
+ params: exports_external.optional(BaseParamsSchema2)
24627
+ });
24628
+ var ElicitationCapabilitySchema = exports_external.object({
24629
+ applyDefaults: exports_external.optional(exports_external.boolean())
24630
+ }).loose();
24631
+ var ServerCapabilitiesSchema2 = exports_external.looseObject({
24632
+ experimental: exports_external.optional(exports_external.object({}).loose()),
24633
+ logging: exports_external.optional(exports_external.object({}).loose()),
24634
+ prompts: exports_external.optional(exports_external.looseObject({
24635
+ listChanged: exports_external.optional(exports_external.boolean())
24636
+ })),
24637
+ resources: exports_external.optional(exports_external.looseObject({
24638
+ subscribe: exports_external.optional(exports_external.boolean()),
24639
+ listChanged: exports_external.optional(exports_external.boolean())
24640
+ })),
24641
+ tools: exports_external.optional(exports_external.looseObject({
24642
+ listChanged: exports_external.optional(exports_external.boolean())
24643
+ })),
24644
+ elicitation: exports_external.optional(ElicitationCapabilitySchema)
24645
+ });
24646
+ var ClientCapabilitiesSchema = exports_external.object({
24647
+ elicitation: exports_external.optional(ElicitationCapabilitySchema)
24648
+ }).loose();
24649
+ var InitializeResultSchema2 = ResultSchema2.extend({
24650
+ protocolVersion: exports_external.string(),
24651
+ capabilities: ServerCapabilitiesSchema2,
24652
+ serverInfo: ClientOrServerImplementationSchema2,
24653
+ instructions: exports_external.optional(exports_external.string())
24654
+ });
24655
+ var PaginatedResultSchema2 = ResultSchema2.extend({
24656
+ nextCursor: exports_external.optional(exports_external.string())
24657
+ });
24658
+ var ToolSchema2 = exports_external.object({
24659
+ name: exports_external.string(),
24660
+ description: exports_external.optional(exports_external.string()),
24661
+ inputSchema: exports_external.object({
24662
+ type: exports_external.literal("object"),
24663
+ properties: exports_external.optional(exports_external.object({}).loose())
24664
+ }).loose()
24665
+ }).loose();
24666
+ var ListToolsResultSchema2 = PaginatedResultSchema2.extend({
24667
+ tools: exports_external.array(ToolSchema2)
24668
+ });
24669
+ var TextContentSchema2 = exports_external.object({
24670
+ type: exports_external.literal("text"),
24671
+ text: exports_external.string()
24672
+ }).loose();
24673
+ var ImageContentSchema2 = exports_external.object({
24674
+ type: exports_external.literal("image"),
24675
+ data: exports_external.base64(),
24676
+ mimeType: exports_external.string()
24677
+ }).loose();
24678
+ var ResourceSchema = exports_external.object({
24679
+ uri: exports_external.string(),
24680
+ name: exports_external.string(),
24681
+ title: exports_external.optional(exports_external.string()),
24682
+ description: exports_external.optional(exports_external.string()),
24683
+ mimeType: exports_external.optional(exports_external.string()),
24684
+ size: exports_external.optional(exports_external.number())
24685
+ }).loose();
24686
+ var ListResourcesResultSchema = PaginatedResultSchema2.extend({
24687
+ resources: exports_external.array(ResourceSchema)
24688
+ });
24689
+ var ResourceContentsSchema2 = exports_external.object({
24690
+ uri: exports_external.string(),
24691
+ name: exports_external.optional(exports_external.string()),
24692
+ title: exports_external.optional(exports_external.string()),
24693
+ mimeType: exports_external.optional(exports_external.string())
24694
+ }).loose();
24695
+ var TextResourceContentsSchema2 = ResourceContentsSchema2.extend({
24696
+ text: exports_external.string()
24697
+ });
24698
+ var BlobResourceContentsSchema2 = ResourceContentsSchema2.extend({
24699
+ blob: exports_external.base64()
24700
+ });
24701
+ var EmbeddedResourceSchema2 = exports_external.object({
24702
+ type: exports_external.literal("resource"),
24703
+ resource: exports_external.union([TextResourceContentsSchema2, BlobResourceContentsSchema2])
24704
+ }).loose();
24705
+ var CallToolResultSchema2 = ResultSchema2.extend({
24706
+ content: exports_external.array(exports_external.union([TextContentSchema2, ImageContentSchema2, EmbeddedResourceSchema2])),
24707
+ isError: exports_external.boolean().default(false).optional()
24708
+ }).or(ResultSchema2.extend({
24709
+ toolResult: exports_external.unknown()
24710
+ }));
24711
+ var ResourceTemplateSchema = exports_external.object({
24712
+ uriTemplate: exports_external.string(),
24713
+ name: exports_external.string(),
24714
+ title: exports_external.optional(exports_external.string()),
24715
+ description: exports_external.optional(exports_external.string()),
24716
+ mimeType: exports_external.optional(exports_external.string())
24717
+ }).loose();
24718
+ var ListResourceTemplatesResultSchema = ResultSchema2.extend({
24719
+ resourceTemplates: exports_external.array(ResourceTemplateSchema)
24720
+ });
24721
+ var ReadResourceResultSchema = ResultSchema2.extend({
24722
+ contents: exports_external.array(exports_external.union([TextResourceContentsSchema2, BlobResourceContentsSchema2]))
24723
+ });
24724
+ var PromptArgumentSchema = exports_external.object({
24725
+ name: exports_external.string(),
24726
+ description: exports_external.optional(exports_external.string()),
24727
+ required: exports_external.optional(exports_external.boolean())
24728
+ }).loose();
24729
+ var PromptSchema = exports_external.object({
24730
+ name: exports_external.string(),
24731
+ title: exports_external.optional(exports_external.string()),
24732
+ description: exports_external.optional(exports_external.string()),
24733
+ arguments: exports_external.optional(exports_external.array(PromptArgumentSchema))
24734
+ }).loose();
24735
+ var ListPromptsResultSchema = PaginatedResultSchema2.extend({
24736
+ prompts: exports_external.array(PromptSchema)
24737
+ });
24738
+ var PromptMessageSchema = exports_external.object({
24739
+ role: exports_external.union([exports_external.literal("user"), exports_external.literal("assistant")]),
24740
+ content: exports_external.union([
24741
+ TextContentSchema2,
24742
+ ImageContentSchema2,
24743
+ EmbeddedResourceSchema2
24744
+ ])
24745
+ }).loose();
24746
+ var GetPromptResultSchema = ResultSchema2.extend({
24747
+ description: exports_external.optional(exports_external.string()),
24748
+ messages: exports_external.array(PromptMessageSchema)
24749
+ });
24750
+ var ElicitationRequestParamsSchema = BaseParamsSchema2.extend({
24751
+ message: exports_external.string(),
24752
+ requestedSchema: exports_external.unknown()
24753
+ });
24754
+ var ElicitationRequestSchema = RequestSchema2.extend({
24755
+ method: exports_external.literal("elicitation/create"),
24756
+ params: ElicitationRequestParamsSchema
24757
+ });
24758
+ var ElicitResultSchema = ResultSchema2.extend({
24759
+ action: exports_external.union([
24760
+ exports_external.literal("accept"),
24761
+ exports_external.literal("decline"),
24762
+ exports_external.literal("cancel")
24763
+ ]),
24764
+ content: exports_external.optional(exports_external.record(exports_external.string(), exports_external.unknown()))
24765
+ });
24766
+ var JSONRPC_VERSION2 = "2.0";
24767
+ var JSONRPCRequestSchema2 = exports_external.object({
24768
+ jsonrpc: exports_external.literal(JSONRPC_VERSION2),
24769
+ id: exports_external.union([exports_external.string(), exports_external.number().int()])
24770
+ }).merge(RequestSchema2).strict();
24771
+ var JSONRPCResponseSchema2 = exports_external.object({
24772
+ jsonrpc: exports_external.literal(JSONRPC_VERSION2),
24773
+ id: exports_external.union([exports_external.string(), exports_external.number().int()]),
24774
+ result: ResultSchema2
24775
+ }).strict();
24776
+ var JSONRPCErrorSchema2 = exports_external.object({
24777
+ jsonrpc: exports_external.literal(JSONRPC_VERSION2),
24778
+ id: exports_external.union([exports_external.string(), exports_external.number().int()]),
24779
+ error: exports_external.object({
24780
+ code: exports_external.number().int(),
24781
+ message: exports_external.string(),
24782
+ data: exports_external.optional(exports_external.unknown())
24783
+ })
24784
+ }).strict();
24785
+ var JSONRPCNotificationSchema2 = exports_external.object({
24786
+ jsonrpc: exports_external.literal(JSONRPC_VERSION2)
24787
+ }).merge(exports_external.object({
24788
+ method: exports_external.string(),
24789
+ params: exports_external.optional(BaseParamsSchema2)
24790
+ })).strict();
24791
+ var JSONRPCMessageSchema2 = exports_external.union([
24792
+ JSONRPCRequestSchema2,
24793
+ JSONRPCNotificationSchema2,
24794
+ JSONRPCResponseSchema2,
24795
+ JSONRPCErrorSchema2
24796
+ ]);
24797
+ var VERSION4 = typeof __PACKAGE_VERSION__ !== "undefined" ? __PACKAGE_VERSION__ : "0.0.0-test";
24798
+ var OAuthTokensSchema = exports_external.object({
24799
+ access_token: exports_external.string(),
24800
+ id_token: exports_external.string().optional(),
24801
+ token_type: exports_external.string(),
24802
+ expires_in: exports_external.number().optional(),
24803
+ scope: exports_external.string().optional(),
24804
+ refresh_token: exports_external.string().optional()
24805
+ }).strip();
24806
+ var SafeUrlSchema = exports_external.string().url().superRefine((val, ctx) => {
24807
+ if (!URL.canParse(val)) {
24808
+ ctx.addIssue({
24809
+ code: exports_external.ZodIssueCode.custom,
24810
+ message: "URL must be parseable",
24811
+ fatal: true
24812
+ });
24813
+ return exports_external.NEVER;
24814
+ }
24815
+ }).refine((url2) => {
24816
+ const u = new URL(url2);
24817
+ return u.protocol !== "javascript:" && u.protocol !== "data:" && u.protocol !== "vbscript:";
24818
+ }, { message: "URL cannot use javascript:, data:, or vbscript: scheme" });
24819
+ var OAuthProtectedResourceMetadataSchema = exports_external.object({
24820
+ resource: exports_external.string().url(),
24821
+ authorization_servers: exports_external.array(SafeUrlSchema).optional(),
24822
+ jwks_uri: exports_external.string().url().optional(),
24823
+ scopes_supported: exports_external.array(exports_external.string()).optional(),
24824
+ bearer_methods_supported: exports_external.array(exports_external.string()).optional(),
24825
+ resource_signing_alg_values_supported: exports_external.array(exports_external.string()).optional(),
24826
+ resource_name: exports_external.string().optional(),
24827
+ resource_documentation: exports_external.string().optional(),
24828
+ resource_policy_uri: exports_external.string().url().optional(),
24829
+ resource_tos_uri: exports_external.string().url().optional(),
24830
+ tls_client_certificate_bound_access_tokens: exports_external.boolean().optional(),
24831
+ authorization_details_types_supported: exports_external.array(exports_external.string()).optional(),
24832
+ dpop_signing_alg_values_supported: exports_external.array(exports_external.string()).optional(),
24833
+ dpop_bound_access_tokens_required: exports_external.boolean().optional()
24834
+ }).passthrough();
24835
+ var OAuthMetadataSchema = exports_external.object({
24836
+ issuer: exports_external.string(),
24837
+ authorization_endpoint: SafeUrlSchema,
24838
+ token_endpoint: SafeUrlSchema,
24839
+ registration_endpoint: SafeUrlSchema.optional(),
24840
+ scopes_supported: exports_external.array(exports_external.string()).optional(),
24841
+ response_types_supported: exports_external.array(exports_external.string()),
24842
+ grant_types_supported: exports_external.array(exports_external.string()).optional(),
24843
+ code_challenge_methods_supported: exports_external.array(exports_external.string()),
24844
+ token_endpoint_auth_methods_supported: exports_external.array(exports_external.string()).optional(),
24845
+ token_endpoint_auth_signing_alg_values_supported: exports_external.array(exports_external.string()).optional()
24846
+ }).passthrough();
24847
+ var OpenIdProviderMetadataSchema = exports_external.object({
24848
+ issuer: exports_external.string(),
24849
+ authorization_endpoint: SafeUrlSchema,
24850
+ token_endpoint: SafeUrlSchema,
24851
+ userinfo_endpoint: SafeUrlSchema.optional(),
24852
+ jwks_uri: SafeUrlSchema,
24853
+ registration_endpoint: SafeUrlSchema.optional(),
24854
+ scopes_supported: exports_external.array(exports_external.string()).optional(),
24855
+ response_types_supported: exports_external.array(exports_external.string()),
24856
+ grant_types_supported: exports_external.array(exports_external.string()).optional(),
24857
+ subject_types_supported: exports_external.array(exports_external.string()),
24858
+ id_token_signing_alg_values_supported: exports_external.array(exports_external.string()),
24859
+ claims_supported: exports_external.array(exports_external.string()).optional(),
24860
+ token_endpoint_auth_methods_supported: exports_external.array(exports_external.string()).optional()
24861
+ }).passthrough();
24862
+ var OpenIdProviderDiscoveryMetadataSchema = OpenIdProviderMetadataSchema.merge(OAuthMetadataSchema.pick({
24863
+ code_challenge_methods_supported: true
24864
+ }));
24865
+ var OAuthClientInformationSchema = exports_external.object({
24866
+ client_id: exports_external.string(),
24867
+ client_secret: exports_external.string().optional(),
24868
+ client_id_issued_at: exports_external.number().optional(),
24869
+ client_secret_expires_at: exports_external.number().optional()
24870
+ }).strip();
24871
+ var OAuthClientMetadataSchema = exports_external.object({
24872
+ redirect_uris: exports_external.array(SafeUrlSchema),
24873
+ token_endpoint_auth_method: exports_external.string().optional(),
24874
+ grant_types: exports_external.array(exports_external.string()).optional(),
24875
+ response_types: exports_external.array(exports_external.string()).optional(),
24876
+ client_name: exports_external.string().optional(),
24877
+ client_uri: SafeUrlSchema.optional(),
24878
+ logo_uri: SafeUrlSchema.optional(),
24879
+ scope: exports_external.string().optional(),
24880
+ contacts: exports_external.array(exports_external.string()).optional(),
24881
+ tos_uri: SafeUrlSchema.optional(),
24882
+ policy_uri: exports_external.string().optional(),
24883
+ jwks_uri: SafeUrlSchema.optional(),
24884
+ jwks: exports_external.any().optional(),
24885
+ software_id: exports_external.string().optional(),
24886
+ software_version: exports_external.string().optional(),
24887
+ software_statement: exports_external.string().optional()
24888
+ }).strip();
24889
+ var OAuthErrorResponseSchema = exports_external.object({
24890
+ error: exports_external.string(),
24891
+ error_description: exports_external.string().optional(),
24892
+ error_uri: exports_external.string().optional()
24893
+ });
24894
+ var OAuthClientInformationFullSchema = OAuthClientMetadataSchema.merge(OAuthClientInformationSchema);
24895
+ var name24 = "AI_MCPClientOAuthError";
24896
+ var marker24 = `vercel.ai.error.${name24}`;
24897
+ var symbol24 = Symbol.for(marker24);
24898
+ var _a24;
24899
+ var _b22;
24900
+ var MCPClientOAuthError = class extends (_b22 = AISDKError, _a24 = symbol24, _b22) {
24901
+ constructor({
24902
+ name: name34 = "MCPClientOAuthError",
24903
+ message,
24904
+ cause
24905
+ }) {
24906
+ super({ name: name34, message, cause });
24907
+ this[_a24] = true;
24908
+ }
24909
+ static isInstance(error40) {
24910
+ return AISDKError.hasMarker(error40, marker24);
24911
+ }
24912
+ };
24913
+ var ServerError = class extends MCPClientOAuthError {
24914
+ };
24915
+ ServerError.errorCode = "server_error";
24916
+ var InvalidClientError = class extends MCPClientOAuthError {
24917
+ };
24918
+ InvalidClientError.errorCode = "invalid_client";
24919
+ var InvalidGrantError = class extends MCPClientOAuthError {
24920
+ };
24921
+ InvalidGrantError.errorCode = "invalid_grant";
24922
+ var UnauthorizedClientError = class extends MCPClientOAuthError {
24923
+ };
24924
+ UnauthorizedClientError.errorCode = "unauthorized_client";
24925
+ var OAUTH_ERRORS = {
24926
+ [ServerError.errorCode]: ServerError,
24927
+ [InvalidClientError.errorCode]: InvalidClientError,
24928
+ [InvalidGrantError.errorCode]: InvalidGrantError,
24929
+ [UnauthorizedClientError.errorCode]: UnauthorizedClientError
24930
+ };
24931
+ function resourceUrlFromServerUrl(url2) {
24932
+ const resourceURL = typeof url2 === "string" ? new URL(url2) : new URL(url2.href);
24933
+ resourceURL.hash = "";
24934
+ return resourceURL;
24935
+ }
24936
+ function checkResourceAllowed({
24937
+ requestedResource,
24938
+ configuredResource
24939
+ }) {
24940
+ const requested = typeof requestedResource === "string" ? new URL(requestedResource) : new URL(requestedResource.href);
24941
+ const configured = typeof configuredResource === "string" ? new URL(configuredResource) : new URL(configuredResource.href);
24942
+ if (requested.origin !== configured.origin) {
24943
+ return false;
24944
+ }
24945
+ if (requested.pathname.length < configured.pathname.length) {
24946
+ return false;
24947
+ }
24948
+ const requestedPath = requested.pathname.endsWith("/") ? requested.pathname : requested.pathname + "/";
24949
+ const configuredPath = configured.pathname.endsWith("/") ? configured.pathname : configured.pathname + "/";
24950
+ return requestedPath.startsWith(configuredPath);
24951
+ }
24952
+ var UnauthorizedError = class extends Error {
24953
+ constructor(message = "Unauthorized") {
24954
+ super(message);
24955
+ this.name = "UnauthorizedError";
24956
+ }
24957
+ };
24958
+ function extractResourceMetadataUrl(response) {
24959
+ var _a34;
24960
+ const header = (_a34 = response.headers.get("www-authenticate")) != null ? _a34 : response.headers.get("WWW-Authenticate");
24961
+ if (!header) {
24962
+ return;
24963
+ }
24964
+ const [type, scheme] = header.split(" ");
24965
+ if (type.toLowerCase() !== "bearer" || !scheme) {
24966
+ return;
24967
+ }
24968
+ const regex = /resource_metadata="([^"]*)"/;
24969
+ const match = header.match(regex);
24970
+ if (!match) {
24971
+ return;
24972
+ }
24973
+ try {
24974
+ return new URL(match[1]);
24975
+ } catch (e) {
24976
+ return;
24977
+ }
24978
+ }
24979
+ function buildWellKnownPath(wellKnownPrefix, pathname = "", options = {}) {
24980
+ if (pathname.endsWith("/")) {
24981
+ pathname = pathname.slice(0, -1);
24982
+ }
24983
+ return options.prependPathname ? `${pathname}/.well-known/${wellKnownPrefix}` : `/.well-known/${wellKnownPrefix}${pathname}`;
24984
+ }
24985
+ async function fetchWithCorsRetry(url2, headers, fetchFn = fetch) {
24986
+ try {
24987
+ return await fetchFn(url2, { headers });
24988
+ } catch (error40) {
24989
+ if (error40 instanceof TypeError) {
24990
+ if (headers) {
24991
+ return fetchWithCorsRetry(url2, undefined, fetchFn);
24992
+ } else {
24993
+ return;
24994
+ }
24995
+ }
24996
+ throw error40;
24997
+ }
24998
+ }
24999
+ async function tryMetadataDiscovery(url2, protocolVersion, fetchFn = fetch) {
25000
+ const headers = {
25001
+ "MCP-Protocol-Version": protocolVersion
25002
+ };
25003
+ return await fetchWithCorsRetry(url2, headers, fetchFn);
25004
+ }
25005
+ function shouldAttemptFallback(response, pathname) {
25006
+ return !response || response.status >= 400 && response.status < 500 && pathname !== "/";
25007
+ }
25008
+ async function discoverMetadataWithFallback(serverUrl, wellKnownType, fetchFn, opts) {
25009
+ var _a34, _b32;
25010
+ const issuer = new URL(serverUrl);
25011
+ const protocolVersion = (_a34 = opts == null ? undefined : opts.protocolVersion) != null ? _a34 : LATEST_PROTOCOL_VERSION;
25012
+ let url2;
25013
+ if (opts == null ? undefined : opts.metadataUrl) {
25014
+ url2 = new URL(opts.metadataUrl);
25015
+ } else {
25016
+ const wellKnownPath = buildWellKnownPath(wellKnownType, issuer.pathname);
25017
+ url2 = new URL(wellKnownPath, (_b32 = opts == null ? undefined : opts.metadataServerUrl) != null ? _b32 : issuer);
25018
+ url2.search = issuer.search;
25019
+ }
25020
+ let response = await tryMetadataDiscovery(url2, protocolVersion, fetchFn);
25021
+ if (!(opts == null ? undefined : opts.metadataUrl) && shouldAttemptFallback(response, issuer.pathname)) {
25022
+ const rootUrl = new URL(`/.well-known/${wellKnownType}`, issuer);
25023
+ response = await tryMetadataDiscovery(rootUrl, protocolVersion, fetchFn);
25024
+ }
25025
+ return response;
25026
+ }
25027
+ async function discoverOAuthProtectedResourceMetadata(serverUrl, opts, fetchFn = fetch) {
25028
+ const response = await discoverMetadataWithFallback(serverUrl, "oauth-protected-resource", fetchFn, {
25029
+ protocolVersion: opts == null ? undefined : opts.protocolVersion,
25030
+ metadataUrl: opts == null ? undefined : opts.resourceMetadataUrl
25031
+ });
25032
+ if (!response || response.status === 404) {
25033
+ throw new Error(`Resource server does not implement OAuth 2.0 Protected Resource Metadata.`);
25034
+ }
25035
+ if (!response.ok) {
25036
+ throw new Error(`HTTP ${response.status} trying to load well-known OAuth protected resource metadata.`);
25037
+ }
25038
+ return OAuthProtectedResourceMetadataSchema.parse(await response.json());
25039
+ }
25040
+ function buildDiscoveryUrls(authorizationServerUrl) {
25041
+ const url2 = typeof authorizationServerUrl === "string" ? new URL(authorizationServerUrl) : authorizationServerUrl;
25042
+ const hasPath = url2.pathname !== "/";
25043
+ const urlsToTry = [];
25044
+ if (!hasPath) {
25045
+ urlsToTry.push({
25046
+ url: new URL("/.well-known/oauth-authorization-server", url2.origin),
25047
+ type: "oauth"
25048
+ });
25049
+ urlsToTry.push({
25050
+ url: new URL("/.well-known/openid-configuration", url2.origin),
25051
+ type: "oidc"
25052
+ });
25053
+ return urlsToTry;
25054
+ }
25055
+ let pathname = url2.pathname;
25056
+ if (pathname.endsWith("/")) {
25057
+ pathname = pathname.slice(0, -1);
25058
+ }
25059
+ urlsToTry.push({
25060
+ url: new URL(`/.well-known/oauth-authorization-server${pathname}`, url2.origin),
25061
+ type: "oauth"
25062
+ });
25063
+ urlsToTry.push({
25064
+ url: new URL("/.well-known/oauth-authorization-server", url2.origin),
25065
+ type: "oauth"
25066
+ });
25067
+ urlsToTry.push({
25068
+ url: new URL(`/.well-known/openid-configuration${pathname}`, url2.origin),
25069
+ type: "oidc"
25070
+ });
25071
+ urlsToTry.push({
25072
+ url: new URL(`${pathname}/.well-known/openid-configuration`, url2.origin),
25073
+ type: "oidc"
25074
+ });
25075
+ return urlsToTry;
25076
+ }
25077
+ async function discoverAuthorizationServerMetadata(authorizationServerUrl, {
25078
+ fetchFn = fetch,
25079
+ protocolVersion = LATEST_PROTOCOL_VERSION
25080
+ } = {}) {
25081
+ var _a34;
25082
+ const headers = { "MCP-Protocol-Version": protocolVersion };
25083
+ const urlsToTry = buildDiscoveryUrls(authorizationServerUrl);
25084
+ for (const { url: endpointUrl, type } of urlsToTry) {
25085
+ const response = await fetchWithCorsRetry(endpointUrl, headers, fetchFn);
25086
+ if (!response) {
25087
+ continue;
25088
+ }
25089
+ if (!response.ok) {
25090
+ if (response.status >= 400 && response.status < 500) {
25091
+ continue;
25092
+ }
25093
+ throw new Error(`HTTP ${response.status} trying to load ${type === "oauth" ? "OAuth" : "OpenID provider"} metadata from ${endpointUrl}`);
25094
+ }
25095
+ if (type === "oauth") {
25096
+ return OAuthMetadataSchema.parse(await response.json());
25097
+ } else {
25098
+ const metadata = OpenIdProviderDiscoveryMetadataSchema.parse(await response.json());
25099
+ if (!((_a34 = metadata.code_challenge_methods_supported) == null ? undefined : _a34.includes("S256"))) {
25100
+ throw new Error(`Incompatible OIDC provider at ${endpointUrl}: does not support S256 code challenge method required by MCP specification`);
25101
+ }
25102
+ return metadata;
25103
+ }
25104
+ }
25105
+ return;
25106
+ }
25107
+ async function startAuthorization(authorizationServerUrl, {
25108
+ metadata,
25109
+ clientInformation,
25110
+ redirectUrl,
25111
+ scope,
25112
+ state,
25113
+ resource
25114
+ }) {
25115
+ const responseType = "code";
25116
+ const codeChallengeMethod = "S256";
25117
+ let authorizationUrl;
25118
+ if (metadata) {
25119
+ authorizationUrl = new URL(metadata.authorization_endpoint);
25120
+ if (!metadata.response_types_supported.includes(responseType)) {
25121
+ throw new Error(`Incompatible auth server: does not support response type ${responseType}`);
25122
+ }
25123
+ if (!metadata.code_challenge_methods_supported || !metadata.code_challenge_methods_supported.includes(codeChallengeMethod)) {
25124
+ throw new Error(`Incompatible auth server: does not support code challenge method ${codeChallengeMethod}`);
25125
+ }
25126
+ } else {
25127
+ authorizationUrl = new URL("/authorize", authorizationServerUrl);
25128
+ }
25129
+ const challenge = await pkceChallenge();
25130
+ const codeVerifier = challenge.code_verifier;
25131
+ const codeChallenge = challenge.code_challenge;
25132
+ authorizationUrl.searchParams.set("response_type", responseType);
25133
+ authorizationUrl.searchParams.set("client_id", clientInformation.client_id);
25134
+ authorizationUrl.searchParams.set("code_challenge", codeChallenge);
25135
+ authorizationUrl.searchParams.set("code_challenge_method", codeChallengeMethod);
25136
+ authorizationUrl.searchParams.set("redirect_uri", String(redirectUrl));
25137
+ if (state) {
25138
+ authorizationUrl.searchParams.set("state", state);
25139
+ }
25140
+ if (scope) {
25141
+ authorizationUrl.searchParams.set("scope", scope);
25142
+ }
25143
+ if (scope == null ? undefined : scope.includes("offline_access")) {
25144
+ authorizationUrl.searchParams.append("prompt", "consent");
25145
+ }
25146
+ if (resource) {
25147
+ authorizationUrl.searchParams.set("resource", resource.href);
25148
+ }
25149
+ return { authorizationUrl, codeVerifier };
25150
+ }
25151
+ function selectClientAuthMethod(clientInformation, supportedMethods) {
25152
+ const hasClientSecret = clientInformation.client_secret !== undefined;
25153
+ if (supportedMethods.length === 0) {
25154
+ return hasClientSecret ? "client_secret_post" : "none";
25155
+ }
25156
+ if (hasClientSecret && supportedMethods.includes("client_secret_basic")) {
25157
+ return "client_secret_basic";
25158
+ }
25159
+ if (hasClientSecret && supportedMethods.includes("client_secret_post")) {
25160
+ return "client_secret_post";
25161
+ }
25162
+ if (supportedMethods.includes("none")) {
25163
+ return "none";
25164
+ }
25165
+ return hasClientSecret ? "client_secret_post" : "none";
25166
+ }
25167
+ function applyClientAuthentication(method, clientInformation, headers, params) {
25168
+ const { client_id, client_secret } = clientInformation;
25169
+ switch (method) {
25170
+ case "client_secret_basic":
25171
+ applyBasicAuth(client_id, client_secret, headers);
25172
+ return;
25173
+ case "client_secret_post":
25174
+ applyPostAuth(client_id, client_secret, params);
25175
+ return;
25176
+ case "none":
25177
+ applyPublicAuth(client_id, params);
25178
+ return;
25179
+ default:
25180
+ throw new Error(`Unsupported client authentication method: ${method}`);
25181
+ }
25182
+ }
25183
+ function applyBasicAuth(clientId, clientSecret, headers) {
25184
+ if (!clientSecret) {
25185
+ throw new Error("client_secret_basic authentication requires a client_secret");
25186
+ }
25187
+ const credentials = btoa(`${clientId}:${clientSecret}`);
25188
+ headers.set("Authorization", `Basic ${credentials}`);
25189
+ }
25190
+ function applyPostAuth(clientId, clientSecret, params) {
25191
+ params.set("client_id", clientId);
25192
+ if (clientSecret) {
25193
+ params.set("client_secret", clientSecret);
25194
+ }
25195
+ }
25196
+ function applyPublicAuth(clientId, params) {
25197
+ params.set("client_id", clientId);
25198
+ }
25199
+ async function parseErrorResponse(input) {
25200
+ const statusCode = input instanceof Response ? input.status : undefined;
25201
+ const body = input instanceof Response ? await input.text() : input;
25202
+ try {
25203
+ const result = OAuthErrorResponseSchema.parse(JSON.parse(body));
25204
+ const { error: error40, error_description, error_uri } = result;
25205
+ const errorClass = OAUTH_ERRORS[error40] || ServerError;
25206
+ return new errorClass({
25207
+ message: error_description || "",
25208
+ cause: error_uri
25209
+ });
25210
+ } catch (error40) {
25211
+ const errorMessage = `${statusCode ? `HTTP ${statusCode}: ` : ""}Invalid OAuth error response: ${error40}. Raw body: ${body}`;
25212
+ return new ServerError({ message: errorMessage });
25213
+ }
25214
+ }
25215
+ async function exchangeAuthorization(authorizationServerUrl, {
25216
+ metadata,
25217
+ clientInformation,
25218
+ authorizationCode,
25219
+ codeVerifier,
25220
+ redirectUri,
25221
+ resource,
25222
+ addClientAuthentication,
25223
+ fetchFn
25224
+ }) {
25225
+ var _a34;
25226
+ const grantType = "authorization_code";
25227
+ const tokenUrl = (metadata == null ? undefined : metadata.token_endpoint) ? new URL(metadata.token_endpoint) : new URL("/token", authorizationServerUrl);
25228
+ if ((metadata == null ? undefined : metadata.grant_types_supported) && !metadata.grant_types_supported.includes(grantType)) {
25229
+ throw new Error(`Incompatible auth server: does not support grant type ${grantType}`);
25230
+ }
25231
+ const headers = new Headers({
25232
+ "Content-Type": "application/x-www-form-urlencoded",
25233
+ Accept: "application/json"
25234
+ });
25235
+ const params = new URLSearchParams({
25236
+ grant_type: grantType,
25237
+ code: authorizationCode,
25238
+ code_verifier: codeVerifier,
25239
+ redirect_uri: String(redirectUri)
25240
+ });
25241
+ if (addClientAuthentication) {
25242
+ addClientAuthentication(headers, params, authorizationServerUrl, metadata);
25243
+ } else {
25244
+ const supportedMethods = (_a34 = metadata == null ? undefined : metadata.token_endpoint_auth_methods_supported) != null ? _a34 : [];
25245
+ const authMethod = selectClientAuthMethod(clientInformation, supportedMethods);
25246
+ applyClientAuthentication(authMethod, clientInformation, headers, params);
25247
+ }
25248
+ if (resource) {
25249
+ params.set("resource", resource.href);
25250
+ }
25251
+ const response = await (fetchFn != null ? fetchFn : fetch)(tokenUrl, {
25252
+ method: "POST",
25253
+ headers,
25254
+ body: params
25255
+ });
25256
+ if (!response.ok) {
25257
+ throw await parseErrorResponse(response);
25258
+ }
25259
+ return OAuthTokensSchema.parse(await response.json());
25260
+ }
25261
+ async function refreshAuthorization(authorizationServerUrl, {
25262
+ metadata,
25263
+ clientInformation,
25264
+ refreshToken,
25265
+ resource,
25266
+ addClientAuthentication,
25267
+ fetchFn
25268
+ }) {
25269
+ var _a34;
25270
+ const grantType = "refresh_token";
25271
+ let tokenUrl;
25272
+ if (metadata) {
25273
+ tokenUrl = new URL(metadata.token_endpoint);
25274
+ if (metadata.grant_types_supported && !metadata.grant_types_supported.includes(grantType)) {
25275
+ throw new Error(`Incompatible auth server: does not support grant type ${grantType}`);
25276
+ }
25277
+ } else {
25278
+ tokenUrl = new URL("/token", authorizationServerUrl);
25279
+ }
25280
+ const headers = new Headers({
25281
+ "Content-Type": "application/x-www-form-urlencoded"
25282
+ });
25283
+ const params = new URLSearchParams({
25284
+ grant_type: grantType,
25285
+ refresh_token: refreshToken
25286
+ });
25287
+ if (addClientAuthentication) {
25288
+ addClientAuthentication(headers, params, authorizationServerUrl, metadata);
25289
+ } else {
25290
+ const supportedMethods = (_a34 = metadata == null ? undefined : metadata.token_endpoint_auth_methods_supported) != null ? _a34 : [];
25291
+ const authMethod = selectClientAuthMethod(clientInformation, supportedMethods);
25292
+ applyClientAuthentication(authMethod, clientInformation, headers, params);
25293
+ }
25294
+ if (resource) {
25295
+ params.set("resource", resource.href);
25296
+ }
25297
+ const response = await (fetchFn != null ? fetchFn : fetch)(tokenUrl, {
25298
+ method: "POST",
25299
+ headers,
25300
+ body: params
25301
+ });
25302
+ if (!response.ok) {
25303
+ throw await parseErrorResponse(response);
25304
+ }
25305
+ return OAuthTokensSchema.parse({
25306
+ refresh_token: refreshToken,
25307
+ ...await response.json()
25308
+ });
25309
+ }
25310
+ async function registerClient(authorizationServerUrl, {
25311
+ metadata,
25312
+ clientMetadata,
25313
+ fetchFn
25314
+ }) {
25315
+ let registrationUrl;
25316
+ if (metadata) {
25317
+ if (!metadata.registration_endpoint) {
25318
+ throw new Error("Incompatible auth server: does not support dynamic client registration");
25319
+ }
25320
+ registrationUrl = new URL(metadata.registration_endpoint);
25321
+ } else {
25322
+ registrationUrl = new URL("/register", authorizationServerUrl);
25323
+ }
25324
+ const response = await (fetchFn != null ? fetchFn : fetch)(registrationUrl, {
25325
+ method: "POST",
25326
+ headers: {
25327
+ "Content-Type": "application/json"
25328
+ },
25329
+ body: JSON.stringify(clientMetadata)
25330
+ });
25331
+ if (!response.ok) {
25332
+ throw await parseErrorResponse(response);
25333
+ }
25334
+ return OAuthClientInformationFullSchema.parse(await response.json());
25335
+ }
25336
+ async function auth(provider, options) {
25337
+ var _a34, _b32;
25338
+ try {
25339
+ return await authInternal(provider, options);
25340
+ } catch (error40) {
25341
+ if (error40 instanceof InvalidClientError || error40 instanceof UnauthorizedClientError) {
25342
+ await ((_a34 = provider.invalidateCredentials) == null ? undefined : _a34.call(provider, "all"));
25343
+ return await authInternal(provider, options);
25344
+ } else if (error40 instanceof InvalidGrantError) {
25345
+ await ((_b32 = provider.invalidateCredentials) == null ? undefined : _b32.call(provider, "tokens"));
25346
+ return await authInternal(provider, options);
25347
+ }
25348
+ throw error40;
25349
+ }
25350
+ }
25351
+ async function selectResourceURL(serverUrl, provider, resourceMetadata) {
25352
+ const defaultResource = resourceUrlFromServerUrl(serverUrl);
25353
+ if (provider.validateResourceURL) {
25354
+ return await provider.validateResourceURL(defaultResource, resourceMetadata == null ? undefined : resourceMetadata.resource);
25355
+ }
25356
+ if (!resourceMetadata) {
25357
+ return;
25358
+ }
25359
+ if (!checkResourceAllowed({
25360
+ requestedResource: defaultResource,
25361
+ configuredResource: resourceMetadata.resource
25362
+ })) {
25363
+ throw new Error(`Protected resource ${resourceMetadata.resource} does not match expected ${defaultResource} (or origin)`);
25364
+ }
25365
+ return new URL(resourceMetadata.resource);
25366
+ }
25367
+ async function authInternal(provider, {
25368
+ serverUrl,
25369
+ authorizationCode,
25370
+ scope,
25371
+ resourceMetadataUrl,
25372
+ fetchFn
25373
+ }) {
25374
+ let resourceMetadata;
25375
+ let authorizationServerUrl;
25376
+ try {
25377
+ resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl }, fetchFn);
25378
+ if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
25379
+ authorizationServerUrl = resourceMetadata.authorization_servers[0];
25380
+ }
25381
+ } catch (e) {}
25382
+ if (!authorizationServerUrl) {
25383
+ authorizationServerUrl = serverUrl;
25384
+ }
25385
+ const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
25386
+ const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, {
25387
+ fetchFn
25388
+ });
25389
+ let clientInformation = await Promise.resolve(provider.clientInformation());
25390
+ if (!clientInformation) {
25391
+ if (authorizationCode !== undefined) {
25392
+ throw new Error("Existing OAuth client information is required when exchanging an authorization code");
25393
+ }
25394
+ if (!provider.saveClientInformation) {
25395
+ throw new Error("OAuth client information must be saveable for dynamic registration");
25396
+ }
25397
+ const fullInformation = await registerClient(authorizationServerUrl, {
25398
+ metadata,
25399
+ clientMetadata: provider.clientMetadata,
25400
+ fetchFn
25401
+ });
25402
+ await provider.saveClientInformation(fullInformation);
25403
+ clientInformation = fullInformation;
25404
+ }
25405
+ if (authorizationCode !== undefined) {
25406
+ const codeVerifier2 = await provider.codeVerifier();
25407
+ const tokens2 = await exchangeAuthorization(authorizationServerUrl, {
25408
+ metadata,
25409
+ clientInformation,
25410
+ authorizationCode,
25411
+ codeVerifier: codeVerifier2,
25412
+ redirectUri: provider.redirectUrl,
25413
+ resource,
25414
+ addClientAuthentication: provider.addClientAuthentication,
25415
+ fetchFn
25416
+ });
25417
+ await provider.saveTokens(tokens2);
25418
+ return "AUTHORIZED";
25419
+ }
25420
+ const tokens = await provider.tokens();
25421
+ if (tokens == null ? undefined : tokens.refresh_token) {
25422
+ try {
25423
+ const newTokens = await refreshAuthorization(authorizationServerUrl, {
25424
+ metadata,
25425
+ clientInformation,
25426
+ refreshToken: tokens.refresh_token,
25427
+ resource,
25428
+ addClientAuthentication: provider.addClientAuthentication,
25429
+ fetchFn
25430
+ });
25431
+ await provider.saveTokens(newTokens);
25432
+ return "AUTHORIZED";
25433
+ } catch (error40) {
25434
+ if (!(error40 instanceof MCPClientOAuthError) || error40 instanceof ServerError) {} else {
25435
+ throw error40;
25436
+ }
25437
+ }
25438
+ }
25439
+ const state = provider.state ? await provider.state() : undefined;
25440
+ const { authorizationUrl, codeVerifier } = await startAuthorization(authorizationServerUrl, {
25441
+ metadata,
25442
+ clientInformation,
25443
+ state,
25444
+ redirectUrl: provider.redirectUrl,
25445
+ scope: scope || provider.clientMetadata.scope,
25446
+ resource
25447
+ });
25448
+ await provider.saveCodeVerifier(codeVerifier);
25449
+ await provider.redirectToAuthorization(authorizationUrl);
25450
+ return "REDIRECT";
25451
+ }
25452
+ var SseMCPTransport = class {
25453
+ constructor({
25454
+ url: url2,
25455
+ headers,
25456
+ authProvider
25457
+ }) {
25458
+ this.connected = false;
25459
+ this.url = new URL(url2);
25460
+ this.headers = headers;
25461
+ this.authProvider = authProvider;
25462
+ }
25463
+ async commonHeaders(base) {
25464
+ const headers = {
25465
+ ...this.headers,
25466
+ ...base,
25467
+ "mcp-protocol-version": LATEST_PROTOCOL_VERSION
25468
+ };
25469
+ if (this.authProvider) {
25470
+ const tokens = await this.authProvider.tokens();
25471
+ if (tokens == null ? undefined : tokens.access_token) {
25472
+ headers["Authorization"] = `Bearer ${tokens.access_token}`;
25473
+ }
25474
+ }
25475
+ return withUserAgentSuffix2(headers, `ai-sdk/${VERSION4}`, getRuntimeEnvironmentUserAgent2());
25476
+ }
25477
+ async start() {
25478
+ return new Promise((resolve2, reject) => {
25479
+ if (this.connected) {
25480
+ return resolve2();
25481
+ }
25482
+ this.abortController = new AbortController;
25483
+ const establishConnection = async (triedAuth = false) => {
25484
+ var _a34, _b32, _c, _d, _e;
25485
+ try {
25486
+ const headers = await this.commonHeaders({
25487
+ Accept: "text/event-stream"
25488
+ });
25489
+ const response = await fetch(this.url.href, {
25490
+ headers,
25491
+ signal: (_a34 = this.abortController) == null ? undefined : _a34.signal
25492
+ });
25493
+ if (response.status === 401 && this.authProvider && !triedAuth) {
25494
+ this.resourceMetadataUrl = extractResourceMetadataUrl(response);
25495
+ try {
25496
+ const result = await auth(this.authProvider, {
25497
+ serverUrl: this.url,
25498
+ resourceMetadataUrl: this.resourceMetadataUrl
25499
+ });
25500
+ if (result !== "AUTHORIZED") {
25501
+ const error40 = new UnauthorizedError;
25502
+ (_b32 = this.onerror) == null || _b32.call(this, error40);
25503
+ return reject(error40);
25504
+ }
25505
+ } catch (error40) {
25506
+ (_c = this.onerror) == null || _c.call(this, error40);
25507
+ return reject(error40);
25508
+ }
25509
+ return establishConnection(true);
25510
+ }
25511
+ if (!response.ok || !response.body) {
25512
+ let errorMessage = `MCP SSE Transport Error: ${response.status} ${response.statusText}`;
25513
+ if (response.status === 405) {
25514
+ errorMessage += ". This server does not support SSE transport. Try using `http` transport instead";
25515
+ }
25516
+ const error40 = new MCPClientError({
25517
+ message: errorMessage
25518
+ });
25519
+ (_d = this.onerror) == null || _d.call(this, error40);
25520
+ return reject(error40);
25521
+ }
25522
+ const stream = response.body.pipeThrough(new TextDecoderStream).pipeThrough(new EventSourceParserStream);
25523
+ const reader = stream.getReader();
25524
+ const processEvents = async () => {
25525
+ var _a44, _b42, _c2;
25526
+ try {
25527
+ while (true) {
25528
+ const { done, value } = await reader.read();
25529
+ if (done) {
25530
+ if (this.connected) {
25531
+ this.connected = false;
25532
+ throw new MCPClientError({
25533
+ message: "MCP SSE Transport Error: Connection closed unexpectedly"
25534
+ });
24339
25535
  }
24340
25536
  return;
24341
25537
  }
@@ -24351,14 +25547,14 @@ var SseMCPTransport = class {
24351
25547
  resolve2();
24352
25548
  } else if (event === "message") {
24353
25549
  try {
24354
- const message = JSONRPCMessageSchema.parse(JSON.parse(data));
24355
- (_a18 = this.onmessage) == null || _a18.call(this, message);
25550
+ const message = JSONRPCMessageSchema2.parse(JSON.parse(data));
25551
+ (_a44 = this.onmessage) == null || _a44.call(this, message);
24356
25552
  } catch (error40) {
24357
25553
  const e = new MCPClientError({
24358
25554
  message: "MCP SSE Transport Error: Failed to parse message",
24359
25555
  cause: error40
24360
25556
  });
24361
- (_b22 = this.onerror) == null || _b22.call(this, e);
25557
+ (_b42 = this.onerror) == null || _b42.call(this, e);
24362
25558
  }
24363
25559
  }
24364
25560
  }
@@ -24378,7 +25574,7 @@ var SseMCPTransport = class {
24378
25574
  if (error40 instanceof Error && error40.name === "AbortError") {
24379
25575
  return;
24380
25576
  }
24381
- (_c = this.onerror) == null || _c.call(this, error40);
25577
+ (_e = this.onerror) == null || _e.call(this, error40);
24382
25578
  reject(error40);
24383
25579
  }
24384
25580
  };
@@ -24386,52 +25582,377 @@ var SseMCPTransport = class {
24386
25582
  });
24387
25583
  }
24388
25584
  async close() {
24389
- var _a172, _b8, _c;
25585
+ var _a34, _b32, _c;
24390
25586
  this.connected = false;
24391
- (_a172 = this.sseConnection) == null || _a172.close();
24392
- (_b8 = this.abortController) == null || _b8.abort();
25587
+ (_a34 = this.sseConnection) == null || _a34.close();
25588
+ (_b32 = this.abortController) == null || _b32.abort();
24393
25589
  (_c = this.onclose) == null || _c.call(this);
24394
25590
  }
24395
25591
  async send(message) {
24396
- var _a172, _b8, _c;
24397
25592
  if (!this.endpoint || !this.connected) {
24398
25593
  throw new MCPClientError({
24399
25594
  message: "MCP SSE Transport Error: Not connected"
24400
25595
  });
24401
25596
  }
25597
+ const endpoint = this.endpoint;
25598
+ const attempt = async (triedAuth = false) => {
25599
+ var _a34, _b32, _c, _d, _e;
25600
+ try {
25601
+ const headers = await this.commonHeaders({
25602
+ "Content-Type": "application/json"
25603
+ });
25604
+ const init = {
25605
+ method: "POST",
25606
+ headers,
25607
+ body: JSON.stringify(message),
25608
+ signal: (_a34 = this.abortController) == null ? undefined : _a34.signal
25609
+ };
25610
+ const response = await fetch(endpoint, init);
25611
+ if (response.status === 401 && this.authProvider && !triedAuth) {
25612
+ this.resourceMetadataUrl = extractResourceMetadataUrl(response);
25613
+ try {
25614
+ const result = await auth(this.authProvider, {
25615
+ serverUrl: this.url,
25616
+ resourceMetadataUrl: this.resourceMetadataUrl
25617
+ });
25618
+ if (result !== "AUTHORIZED") {
25619
+ const error40 = new UnauthorizedError;
25620
+ (_b32 = this.onerror) == null || _b32.call(this, error40);
25621
+ return;
25622
+ }
25623
+ } catch (error40) {
25624
+ (_c = this.onerror) == null || _c.call(this, error40);
25625
+ return;
25626
+ }
25627
+ return attempt(true);
25628
+ }
25629
+ if (!response.ok) {
25630
+ const text2 = await response.text().catch(() => null);
25631
+ const error40 = new MCPClientError({
25632
+ message: `MCP SSE Transport Error: POSTing to endpoint (HTTP ${response.status}): ${text2}`
25633
+ });
25634
+ (_d = this.onerror) == null || _d.call(this, error40);
25635
+ return;
25636
+ }
25637
+ } catch (error40) {
25638
+ (_e = this.onerror) == null || _e.call(this, error40);
25639
+ return;
25640
+ }
25641
+ };
25642
+ await attempt();
25643
+ }
25644
+ };
25645
+ var HttpMCPTransport = class {
25646
+ constructor({
25647
+ url: url2,
25648
+ headers,
25649
+ authProvider
25650
+ }) {
25651
+ this.inboundReconnectAttempts = 0;
25652
+ this.reconnectionOptions = {
25653
+ initialReconnectionDelay: 1000,
25654
+ maxReconnectionDelay: 30000,
25655
+ reconnectionDelayGrowFactor: 1.5,
25656
+ maxRetries: 2
25657
+ };
25658
+ this.url = new URL(url2);
25659
+ this.headers = headers;
25660
+ this.authProvider = authProvider;
25661
+ }
25662
+ async commonHeaders(base) {
25663
+ const headers = {
25664
+ ...this.headers,
25665
+ ...base,
25666
+ "mcp-protocol-version": LATEST_PROTOCOL_VERSION
25667
+ };
25668
+ if (this.sessionId) {
25669
+ headers["mcp-session-id"] = this.sessionId;
25670
+ }
25671
+ if (this.authProvider) {
25672
+ const tokens = await this.authProvider.tokens();
25673
+ if (tokens == null ? undefined : tokens.access_token) {
25674
+ headers["Authorization"] = `Bearer ${tokens.access_token}`;
25675
+ }
25676
+ }
25677
+ return withUserAgentSuffix2(headers, `ai-sdk/${VERSION4}`, getRuntimeEnvironmentUserAgent2());
25678
+ }
25679
+ async start() {
25680
+ if (this.abortController) {
25681
+ throw new MCPClientError({
25682
+ message: "MCP HTTP Transport Error: Transport already started. Note: client.connect() calls start() automatically."
25683
+ });
25684
+ }
25685
+ this.abortController = new AbortController;
25686
+ this.openInboundSse();
25687
+ }
25688
+ async close() {
25689
+ var _a34, _b32, _c;
25690
+ (_a34 = this.inboundSseConnection) == null || _a34.close();
24402
25691
  try {
24403
- const headers = withUserAgentSuffix({
24404
- ...this.headers,
24405
- "Content-Type": "application/json"
24406
- }, `ai-sdk/${VERSION3}`, getRuntimeEnvironmentUserAgent());
24407
- const init = {
24408
- method: "POST",
25692
+ if (this.sessionId && this.abortController && !this.abortController.signal.aborted) {
25693
+ const headers = await this.commonHeaders({});
25694
+ await fetch(this.url, {
25695
+ method: "DELETE",
25696
+ headers,
25697
+ signal: this.abortController.signal
25698
+ }).catch(() => {
25699
+ return;
25700
+ });
25701
+ }
25702
+ } catch (e) {}
25703
+ (_b32 = this.abortController) == null || _b32.abort();
25704
+ (_c = this.onclose) == null || _c.call(this);
25705
+ }
25706
+ async send(message) {
25707
+ const attempt = async (triedAuth = false) => {
25708
+ var _a34, _b32, _c, _d, _e, _f, _g;
25709
+ try {
25710
+ const headers = await this.commonHeaders({
25711
+ "Content-Type": "application/json",
25712
+ Accept: "application/json, text/event-stream"
25713
+ });
25714
+ const init = {
25715
+ method: "POST",
25716
+ headers,
25717
+ body: JSON.stringify(message),
25718
+ signal: (_a34 = this.abortController) == null ? undefined : _a34.signal
25719
+ };
25720
+ const response = await fetch(this.url, init);
25721
+ const sessionId = response.headers.get("mcp-session-id");
25722
+ if (sessionId) {
25723
+ this.sessionId = sessionId;
25724
+ }
25725
+ if (response.status === 401 && this.authProvider && !triedAuth) {
25726
+ this.resourceMetadataUrl = extractResourceMetadataUrl(response);
25727
+ try {
25728
+ const result = await auth(this.authProvider, {
25729
+ serverUrl: this.url,
25730
+ resourceMetadataUrl: this.resourceMetadataUrl
25731
+ });
25732
+ if (result !== "AUTHORIZED") {
25733
+ const error210 = new UnauthorizedError;
25734
+ throw error210;
25735
+ }
25736
+ } catch (error210) {
25737
+ (_b32 = this.onerror) == null || _b32.call(this, error210);
25738
+ throw error210;
25739
+ }
25740
+ return attempt(true);
25741
+ }
25742
+ if (response.status === 202) {
25743
+ if (!this.inboundSseConnection) {
25744
+ this.openInboundSse();
25745
+ }
25746
+ return;
25747
+ }
25748
+ if (!response.ok) {
25749
+ const text2 = await response.text().catch(() => null);
25750
+ let errorMessage = `MCP HTTP Transport Error: POSTing to endpoint (HTTP ${response.status}): ${text2}`;
25751
+ if (response.status === 404) {
25752
+ errorMessage += ". This server does not support HTTP transport. Try using `sse` transport instead";
25753
+ }
25754
+ const error210 = new MCPClientError({
25755
+ message: errorMessage
25756
+ });
25757
+ (_c = this.onerror) == null || _c.call(this, error210);
25758
+ throw error210;
25759
+ }
25760
+ const contentType = response.headers.get("content-type") || "";
25761
+ if (contentType.includes("application/json")) {
25762
+ const data = await response.json();
25763
+ const messages = Array.isArray(data) ? data.map((m) => JSONRPCMessageSchema2.parse(m)) : [JSONRPCMessageSchema2.parse(data)];
25764
+ for (const m of messages)
25765
+ (_d = this.onmessage) == null || _d.call(this, m);
25766
+ return;
25767
+ }
25768
+ if (contentType.includes("text/event-stream")) {
25769
+ if (!response.body) {
25770
+ const error210 = new MCPClientError({
25771
+ message: "MCP HTTP Transport Error: text/event-stream response without body"
25772
+ });
25773
+ (_e = this.onerror) == null || _e.call(this, error210);
25774
+ throw error210;
25775
+ }
25776
+ const stream = response.body.pipeThrough(new TextDecoderStream).pipeThrough(new EventSourceParserStream);
25777
+ const reader = stream.getReader();
25778
+ const processEvents = async () => {
25779
+ var _a44, _b42, _c2;
25780
+ try {
25781
+ while (true) {
25782
+ const { done, value } = await reader.read();
25783
+ if (done)
25784
+ return;
25785
+ const { event, data } = value;
25786
+ if (event === "message") {
25787
+ try {
25788
+ const msg = JSONRPCMessageSchema2.parse(JSON.parse(data));
25789
+ (_a44 = this.onmessage) == null || _a44.call(this, msg);
25790
+ } catch (error210) {
25791
+ const e = new MCPClientError({
25792
+ message: "MCP HTTP Transport Error: Failed to parse message",
25793
+ cause: error210
25794
+ });
25795
+ (_b42 = this.onerror) == null || _b42.call(this, e);
25796
+ }
25797
+ }
25798
+ }
25799
+ } catch (error210) {
25800
+ if (error210 instanceof Error && error210.name === "AbortError") {
25801
+ return;
25802
+ }
25803
+ (_c2 = this.onerror) == null || _c2.call(this, error210);
25804
+ }
25805
+ };
25806
+ processEvents();
25807
+ return;
25808
+ }
25809
+ const error40 = new MCPClientError({
25810
+ message: `MCP HTTP Transport Error: Unexpected content type: ${contentType}`
25811
+ });
25812
+ (_f = this.onerror) == null || _f.call(this, error40);
25813
+ throw error40;
25814
+ } catch (error40) {
25815
+ (_g = this.onerror) == null || _g.call(this, error40);
25816
+ throw error40;
25817
+ }
25818
+ };
25819
+ await attempt();
25820
+ }
25821
+ getNextReconnectionDelay(attempt) {
25822
+ const {
25823
+ initialReconnectionDelay,
25824
+ reconnectionDelayGrowFactor,
25825
+ maxReconnectionDelay
25826
+ } = this.reconnectionOptions;
25827
+ return Math.min(initialReconnectionDelay * Math.pow(reconnectionDelayGrowFactor, attempt), maxReconnectionDelay);
25828
+ }
25829
+ scheduleInboundSseReconnection() {
25830
+ var _a34;
25831
+ const { maxRetries } = this.reconnectionOptions;
25832
+ if (maxRetries > 0 && this.inboundReconnectAttempts >= maxRetries) {
25833
+ (_a34 = this.onerror) == null || _a34.call(this, new MCPClientError({
25834
+ message: `MCP HTTP Transport Error: Maximum reconnection attempts (${maxRetries}) exceeded.`
25835
+ }));
25836
+ return;
25837
+ }
25838
+ const delay2 = this.getNextReconnectionDelay(this.inboundReconnectAttempts);
25839
+ this.inboundReconnectAttempts += 1;
25840
+ setTimeout(async () => {
25841
+ var _a44;
25842
+ if ((_a44 = this.abortController) == null ? undefined : _a44.signal.aborted)
25843
+ return;
25844
+ await this.openInboundSse(false, this.lastInboundEventId);
25845
+ }, delay2);
25846
+ }
25847
+ async openInboundSse(triedAuth = false, resumeToken) {
25848
+ var _a34, _b32, _c, _d, _e, _f;
25849
+ try {
25850
+ const headers = await this.commonHeaders({
25851
+ Accept: "text/event-stream"
25852
+ });
25853
+ if (resumeToken) {
25854
+ headers["last-event-id"] = resumeToken;
25855
+ }
25856
+ const response = await fetch(this.url.href, {
25857
+ method: "GET",
24409
25858
  headers,
24410
- body: JSON.stringify(message),
24411
- signal: (_a172 = this.abortController) == null ? undefined : _a172.signal
24412
- };
24413
- const response = await fetch(this.endpoint, init);
24414
- if (!response.ok) {
24415
- const text2 = await response.text().catch(() => null);
25859
+ signal: (_a34 = this.abortController) == null ? undefined : _a34.signal
25860
+ });
25861
+ const sessionId = response.headers.get("mcp-session-id");
25862
+ if (sessionId) {
25863
+ this.sessionId = sessionId;
25864
+ }
25865
+ if (response.status === 401 && this.authProvider && !triedAuth) {
25866
+ this.resourceMetadataUrl = extractResourceMetadataUrl(response);
25867
+ try {
25868
+ const result = await auth(this.authProvider, {
25869
+ serverUrl: this.url,
25870
+ resourceMetadataUrl: this.resourceMetadataUrl
25871
+ });
25872
+ if (result !== "AUTHORIZED") {
25873
+ const error40 = new UnauthorizedError;
25874
+ (_b32 = this.onerror) == null || _b32.call(this, error40);
25875
+ return;
25876
+ }
25877
+ } catch (error40) {
25878
+ (_c = this.onerror) == null || _c.call(this, error40);
25879
+ return;
25880
+ }
25881
+ return this.openInboundSse(true, resumeToken);
25882
+ }
25883
+ if (response.status === 405) {
25884
+ return;
25885
+ }
25886
+ if (!response.ok || !response.body) {
24416
25887
  const error40 = new MCPClientError({
24417
- message: `MCP SSE Transport Error: POSTing to endpoint (HTTP ${response.status}): ${text2}`
25888
+ message: `MCP HTTP Transport Error: GET SSE failed: ${response.status} ${response.statusText}`
24418
25889
  });
24419
- (_b8 = this.onerror) == null || _b8.call(this, error40);
25890
+ (_d = this.onerror) == null || _d.call(this, error40);
24420
25891
  return;
24421
25892
  }
25893
+ const stream = response.body.pipeThrough(new TextDecoderStream).pipeThrough(new EventSourceParserStream);
25894
+ const reader = stream.getReader();
25895
+ const processEvents = async () => {
25896
+ var _a44, _b42, _c2, _d2;
25897
+ try {
25898
+ while (true) {
25899
+ const { done, value } = await reader.read();
25900
+ if (done)
25901
+ return;
25902
+ const { event, data, id } = value;
25903
+ if (id) {
25904
+ this.lastInboundEventId = id;
25905
+ }
25906
+ if (event === "message") {
25907
+ try {
25908
+ const msg = JSONRPCMessageSchema2.parse(JSON.parse(data));
25909
+ (_a44 = this.onmessage) == null || _a44.call(this, msg);
25910
+ } catch (error40) {
25911
+ const e = new MCPClientError({
25912
+ message: "MCP HTTP Transport Error: Failed to parse message",
25913
+ cause: error40
25914
+ });
25915
+ (_b42 = this.onerror) == null || _b42.call(this, e);
25916
+ }
25917
+ }
25918
+ }
25919
+ } catch (error40) {
25920
+ if (error40 instanceof Error && error40.name === "AbortError") {
25921
+ return;
25922
+ }
25923
+ (_c2 = this.onerror) == null || _c2.call(this, error40);
25924
+ if (!((_d2 = this.abortController) == null ? undefined : _d2.signal.aborted)) {
25925
+ this.scheduleInboundSseReconnection();
25926
+ }
25927
+ }
25928
+ };
25929
+ this.inboundSseConnection = {
25930
+ close: () => reader.cancel()
25931
+ };
25932
+ this.inboundReconnectAttempts = 0;
25933
+ processEvents();
24422
25934
  } catch (error40) {
24423
- (_c = this.onerror) == null || _c.call(this, error40);
24424
- return;
25935
+ if (error40 instanceof Error && error40.name === "AbortError") {
25936
+ return;
25937
+ }
25938
+ (_e = this.onerror) == null || _e.call(this, error40);
25939
+ if (!((_f = this.abortController) == null ? undefined : _f.signal.aborted)) {
25940
+ this.scheduleInboundSseReconnection();
25941
+ }
24425
25942
  }
24426
25943
  }
24427
25944
  };
24428
25945
  function createMcpTransport(config2) {
24429
- if (config2.type !== "sse") {
24430
- throw new MCPClientError({
24431
- message: "Unsupported or invalid transport configuration. If you are using a custom transport, make sure it implements the MCPTransport interface."
24432
- });
25946
+ switch (config2.type) {
25947
+ case "sse":
25948
+ return new SseMCPTransport(config2);
25949
+ case "http":
25950
+ return new HttpMCPTransport(config2);
25951
+ default:
25952
+ throw new MCPClientError({
25953
+ message: "Unsupported or invalid transport configuration. If you are using a custom transport, make sure it implements the MCPTransport interface."
25954
+ });
24433
25955
  }
24434
- return new SseMCPTransport(config2);
24435
25956
  }
24436
25957
  function isCustomMcpTransport(transport) {
24437
25958
  return "start" in transport && typeof transport.start === "function" && "send" in transport && typeof transport.send === "function" && "close" in transport && typeof transport.close === "function";
@@ -24445,14 +25966,17 @@ async function createMCPClient(config2) {
24445
25966
  var DefaultMCPClient = class {
24446
25967
  constructor({
24447
25968
  transport: transportConfig,
24448
- name: name17 = "ai-sdk-mcp-client",
24449
- onUncaughtError
25969
+ name: name34 = "ai-sdk-mcp-client",
25970
+ version: version2 = CLIENT_VERSION,
25971
+ onUncaughtError,
25972
+ capabilities
24450
25973
  }) {
24451
25974
  this.requestMessageId = 0;
24452
25975
  this.responseHandlers = /* @__PURE__ */ new Map;
24453
25976
  this.serverCapabilities = {};
24454
25977
  this.isClosed = true;
24455
25978
  this.onUncaughtError = onUncaughtError;
25979
+ this.clientCapabilities = capabilities != null ? capabilities : {};
24456
25980
  if (isCustomMcpTransport(transportConfig)) {
24457
25981
  this.transport = transportConfig;
24458
25982
  } else {
@@ -24462,16 +25986,20 @@ var DefaultMCPClient = class {
24462
25986
  this.transport.onerror = (error40) => this.onError(error40);
24463
25987
  this.transport.onmessage = (message) => {
24464
25988
  if ("method" in message) {
24465
- this.onError(new MCPClientError({
24466
- message: "Unsupported message type"
24467
- }));
25989
+ if ("id" in message) {
25990
+ this.onRequestMessage(message);
25991
+ } else {
25992
+ this.onError(new MCPClientError({
25993
+ message: "Unsupported message type"
25994
+ }));
25995
+ }
24468
25996
  return;
24469
25997
  }
24470
25998
  this.onResponse(message);
24471
25999
  };
24472
26000
  this.clientInfo = {
24473
- name: name17,
24474
- version: CLIENT_VERSION
26001
+ name: name34,
26002
+ version: version2
24475
26003
  };
24476
26004
  }
24477
26005
  async init() {
@@ -24483,11 +26011,11 @@ var DefaultMCPClient = class {
24483
26011
  method: "initialize",
24484
26012
  params: {
24485
26013
  protocolVersion: LATEST_PROTOCOL_VERSION,
24486
- capabilities: {},
26014
+ capabilities: this.clientCapabilities,
24487
26015
  clientInfo: this.clientInfo
24488
26016
  }
24489
26017
  },
24490
- resultSchema: InitializeResultSchema
26018
+ resultSchema: InitializeResultSchema2
24491
26019
  });
24492
26020
  if (result === undefined) {
24493
26021
  throw new MCPClientError({
@@ -24510,10 +26038,10 @@ var DefaultMCPClient = class {
24510
26038
  }
24511
26039
  }
24512
26040
  async close() {
24513
- var _a172;
26041
+ var _a34;
24514
26042
  if (this.isClosed)
24515
26043
  return;
24516
- await ((_a172 = this.transport) == null ? undefined : _a172.close());
26044
+ await ((_a34 = this.transport) == null ? undefined : _a34.close());
24517
26045
  this.onClose();
24518
26046
  }
24519
26047
  assertCapability(method) {
@@ -24528,6 +26056,23 @@ var DefaultMCPClient = class {
24528
26056
  });
24529
26057
  }
24530
26058
  break;
26059
+ case "resources/list":
26060
+ case "resources/read":
26061
+ case "resources/templates/list":
26062
+ if (!this.serverCapabilities.resources) {
26063
+ throw new MCPClientError({
26064
+ message: `Server does not support resources`
26065
+ });
26066
+ }
26067
+ break;
26068
+ case "prompts/list":
26069
+ case "prompts/get":
26070
+ if (!this.serverCapabilities.prompts) {
26071
+ throw new MCPClientError({
26072
+ message: `Server does not support prompts`
26073
+ });
26074
+ }
26075
+ break;
24531
26076
  default:
24532
26077
  throw new MCPClientError({
24533
26078
  message: `Unsupported method: ${method}`
@@ -24591,7 +26136,7 @@ var DefaultMCPClient = class {
24591
26136
  try {
24592
26137
  return this.request({
24593
26138
  request: { method: "tools/list", params },
24594
- resultSchema: ListToolsResultSchema,
26139
+ resultSchema: ListToolsResultSchema2,
24595
26140
  options
24596
26141
  });
24597
26142
  } catch (error40) {
@@ -24599,14 +26144,14 @@ var DefaultMCPClient = class {
24599
26144
  }
24600
26145
  }
24601
26146
  async callTool({
24602
- name: name17,
26147
+ name: name34,
24603
26148
  args,
24604
26149
  options
24605
26150
  }) {
24606
26151
  try {
24607
26152
  return this.request({
24608
- request: { method: "tools/call", params: { name: name17, arguments: args } },
24609
- resultSchema: CallToolResultSchema,
26153
+ request: { method: "tools/call", params: { name: name34, arguments: args } },
26154
+ resultSchema: CallToolResultSchema2,
24610
26155
  options: {
24611
26156
  signal: options == null ? undefined : options.abortSignal
24612
26157
  }
@@ -24615,6 +26160,76 @@ var DefaultMCPClient = class {
24615
26160
  throw error40;
24616
26161
  }
24617
26162
  }
26163
+ async listResourcesInternal({
26164
+ params,
26165
+ options
26166
+ } = {}) {
26167
+ try {
26168
+ return this.request({
26169
+ request: { method: "resources/list", params },
26170
+ resultSchema: ListResourcesResultSchema,
26171
+ options
26172
+ });
26173
+ } catch (error40) {
26174
+ throw error40;
26175
+ }
26176
+ }
26177
+ async readResourceInternal({
26178
+ uri,
26179
+ options
26180
+ }) {
26181
+ try {
26182
+ return this.request({
26183
+ request: { method: "resources/read", params: { uri } },
26184
+ resultSchema: ReadResourceResultSchema,
26185
+ options
26186
+ });
26187
+ } catch (error40) {
26188
+ throw error40;
26189
+ }
26190
+ }
26191
+ async listResourceTemplatesInternal({
26192
+ options
26193
+ } = {}) {
26194
+ try {
26195
+ return this.request({
26196
+ request: { method: "resources/templates/list" },
26197
+ resultSchema: ListResourceTemplatesResultSchema,
26198
+ options
26199
+ });
26200
+ } catch (error40) {
26201
+ throw error40;
26202
+ }
26203
+ }
26204
+ async listPromptsInternal({
26205
+ params,
26206
+ options
26207
+ } = {}) {
26208
+ try {
26209
+ return this.request({
26210
+ request: { method: "prompts/list", params },
26211
+ resultSchema: ListPromptsResultSchema,
26212
+ options
26213
+ });
26214
+ } catch (error40) {
26215
+ throw error40;
26216
+ }
26217
+ }
26218
+ async getPromptInternal({
26219
+ name: name34,
26220
+ args,
26221
+ options
26222
+ }) {
26223
+ try {
26224
+ return this.request({
26225
+ request: { method: "prompts/get", params: { name: name34, arguments: args } },
26226
+ resultSchema: GetPromptResultSchema,
26227
+ options
26228
+ });
26229
+ } catch (error40) {
26230
+ throw error40;
26231
+ }
26232
+ }
24618
26233
  async notification(notification) {
24619
26234
  const jsonrpcNotification = {
24620
26235
  ...notification,
@@ -24625,38 +26240,139 @@ var DefaultMCPClient = class {
24625
26240
  async tools({
24626
26241
  schemas: schemas3 = "automatic"
24627
26242
  } = {}) {
24628
- var _a172;
26243
+ var _a34;
24629
26244
  const tools = {};
24630
26245
  try {
24631
- const listToolsResult = await this.listTools();
24632
- for (const { name: name17, description, inputSchema } of listToolsResult.tools) {
24633
- if (schemas3 !== "automatic" && !(name17 in schemas3)) {
24634
- continue;
24635
- }
24636
- const self = this;
24637
- const execute = async (args, options) => {
24638
- var _a18;
24639
- (_a18 = options == null ? undefined : options.abortSignal) == null || _a18.throwIfAborted();
24640
- return self.callTool({ name: name17, args, options });
24641
- };
24642
- const toolWithExecute = schemas3 === "automatic" ? dynamicTool({
24643
- description,
24644
- inputSchema: jsonSchema({
24645
- ...inputSchema,
24646
- properties: (_a172 = inputSchema.properties) != null ? _a172 : {},
24647
- additionalProperties: false
24648
- }),
24649
- execute
24650
- }) : tool({
24651
- description,
24652
- inputSchema: schemas3[name17].inputSchema,
24653
- execute
26246
+ const listToolsResult = await this.listTools();
26247
+ for (const { name: name34, description, inputSchema } of listToolsResult.tools) {
26248
+ if (schemas3 !== "automatic" && !(name34 in schemas3)) {
26249
+ continue;
26250
+ }
26251
+ const self = this;
26252
+ const execute = async (args, options) => {
26253
+ var _a44;
26254
+ (_a44 = options == null ? undefined : options.abortSignal) == null || _a44.throwIfAborted();
26255
+ return self.callTool({ name: name34, args, options });
26256
+ };
26257
+ const toolWithExecute = schemas3 === "automatic" ? dynamicTool({
26258
+ description,
26259
+ inputSchema: jsonSchema2({
26260
+ ...inputSchema,
26261
+ properties: (_a34 = inputSchema.properties) != null ? _a34 : {},
26262
+ additionalProperties: false
26263
+ }),
26264
+ execute
26265
+ }) : tool2({
26266
+ description,
26267
+ inputSchema: schemas3[name34].inputSchema,
26268
+ execute
26269
+ });
26270
+ tools[name34] = toolWithExecute;
26271
+ }
26272
+ return tools;
26273
+ } catch (error40) {
26274
+ throw error40;
26275
+ }
26276
+ }
26277
+ listResources({
26278
+ params,
26279
+ options
26280
+ } = {}) {
26281
+ return this.listResourcesInternal({ params, options });
26282
+ }
26283
+ readResource({
26284
+ uri,
26285
+ options
26286
+ }) {
26287
+ return this.readResourceInternal({ uri, options });
26288
+ }
26289
+ listResourceTemplates({
26290
+ options
26291
+ } = {}) {
26292
+ return this.listResourceTemplatesInternal({ options });
26293
+ }
26294
+ listPrompts({
26295
+ params,
26296
+ options
26297
+ } = {}) {
26298
+ return this.listPromptsInternal({ params, options });
26299
+ }
26300
+ getPrompt({
26301
+ name: name34,
26302
+ arguments: args,
26303
+ options
26304
+ }) {
26305
+ return this.getPromptInternal({ name: name34, args, options });
26306
+ }
26307
+ onElicitationRequest(schema, handler) {
26308
+ if (schema !== ElicitationRequestSchema) {
26309
+ throw new MCPClientError({
26310
+ message: "Unsupported request schema. Only ElicitationRequestSchema is supported."
26311
+ });
26312
+ }
26313
+ this.elicitationRequestHandler = handler;
26314
+ }
26315
+ async onRequestMessage(request) {
26316
+ try {
26317
+ if (request.method !== "elicitation/create") {
26318
+ await this.transport.send({
26319
+ jsonrpc: "2.0",
26320
+ id: request.id,
26321
+ error: {
26322
+ code: -32601,
26323
+ message: `Unsupported request method: ${request.method}`
26324
+ }
24654
26325
  });
24655
- tools[name17] = toolWithExecute;
26326
+ return;
26327
+ }
26328
+ if (!this.elicitationRequestHandler) {
26329
+ await this.transport.send({
26330
+ jsonrpc: "2.0",
26331
+ id: request.id,
26332
+ error: {
26333
+ code: -32601,
26334
+ message: "No elicitation handler registered on client"
26335
+ }
26336
+ });
26337
+ return;
26338
+ }
26339
+ const parsedRequest = ElicitationRequestSchema.safeParse({
26340
+ method: request.method,
26341
+ params: request.params
26342
+ });
26343
+ if (!parsedRequest.success) {
26344
+ await this.transport.send({
26345
+ jsonrpc: "2.0",
26346
+ id: request.id,
26347
+ error: {
26348
+ code: -32602,
26349
+ message: `Invalid elicitation request: ${parsedRequest.error.message}`,
26350
+ data: parsedRequest.error.issues
26351
+ }
26352
+ });
26353
+ return;
26354
+ }
26355
+ try {
26356
+ const result = await this.elicitationRequestHandler(parsedRequest.data);
26357
+ const validatedResult = ElicitResultSchema.parse(result);
26358
+ await this.transport.send({
26359
+ jsonrpc: "2.0",
26360
+ id: request.id,
26361
+ result: validatedResult
26362
+ });
26363
+ } catch (error40) {
26364
+ await this.transport.send({
26365
+ jsonrpc: "2.0",
26366
+ id: request.id,
26367
+ error: {
26368
+ code: -32603,
26369
+ message: error40 instanceof Error ? error40.message : "Failed to handle elicitation request"
26370
+ }
26371
+ });
26372
+ this.onError(error40);
24656
26373
  }
24657
- return tools;
24658
26374
  } catch (error40) {
24659
- throw error40;
26375
+ this.onError(error40);
24660
26376
  }
24661
26377
  }
24662
26378
  onClose() {
@@ -24693,192 +26409,6 @@ var DefaultMCPClient = class {
24693
26409
  }));
24694
26410
  }
24695
26411
  };
24696
- var uiMessagesSchema = lazyValidator(() => zodSchema(exports_external.array(exports_external.object({
24697
- id: exports_external.string(),
24698
- role: exports_external.enum(["system", "user", "assistant"]),
24699
- metadata: exports_external.unknown().optional(),
24700
- parts: exports_external.array(exports_external.union([
24701
- exports_external.object({
24702
- type: exports_external.literal("text"),
24703
- text: exports_external.string(),
24704
- state: exports_external.enum(["streaming", "done"]).optional(),
24705
- providerMetadata: providerMetadataSchema.optional()
24706
- }),
24707
- exports_external.object({
24708
- type: exports_external.literal("reasoning"),
24709
- text: exports_external.string(),
24710
- state: exports_external.enum(["streaming", "done"]).optional(),
24711
- providerMetadata: providerMetadataSchema.optional()
24712
- }),
24713
- exports_external.object({
24714
- type: exports_external.literal("source-url"),
24715
- sourceId: exports_external.string(),
24716
- url: exports_external.string(),
24717
- title: exports_external.string().optional(),
24718
- providerMetadata: providerMetadataSchema.optional()
24719
- }),
24720
- exports_external.object({
24721
- type: exports_external.literal("source-document"),
24722
- sourceId: exports_external.string(),
24723
- mediaType: exports_external.string(),
24724
- title: exports_external.string(),
24725
- filename: exports_external.string().optional(),
24726
- providerMetadata: providerMetadataSchema.optional()
24727
- }),
24728
- exports_external.object({
24729
- type: exports_external.literal("file"),
24730
- mediaType: exports_external.string(),
24731
- filename: exports_external.string().optional(),
24732
- url: exports_external.string(),
24733
- providerMetadata: providerMetadataSchema.optional()
24734
- }),
24735
- exports_external.object({
24736
- type: exports_external.literal("step-start")
24737
- }),
24738
- exports_external.object({
24739
- type: exports_external.string().startsWith("data-"),
24740
- id: exports_external.string().optional(),
24741
- data: exports_external.unknown()
24742
- }),
24743
- exports_external.object({
24744
- type: exports_external.literal("dynamic-tool"),
24745
- toolName: exports_external.string(),
24746
- toolCallId: exports_external.string(),
24747
- state: exports_external.literal("input-streaming"),
24748
- input: exports_external.unknown().optional(),
24749
- output: exports_external.never().optional(),
24750
- errorText: exports_external.never().optional()
24751
- }),
24752
- exports_external.object({
24753
- type: exports_external.literal("dynamic-tool"),
24754
- toolName: exports_external.string(),
24755
- toolCallId: exports_external.string(),
24756
- state: exports_external.literal("input-available"),
24757
- input: exports_external.unknown(),
24758
- output: exports_external.never().optional(),
24759
- errorText: exports_external.never().optional(),
24760
- callProviderMetadata: providerMetadataSchema.optional()
24761
- }),
24762
- exports_external.object({
24763
- type: exports_external.literal("dynamic-tool"),
24764
- toolName: exports_external.string(),
24765
- toolCallId: exports_external.string(),
24766
- state: exports_external.literal("output-available"),
24767
- input: exports_external.unknown(),
24768
- output: exports_external.unknown(),
24769
- errorText: exports_external.never().optional(),
24770
- callProviderMetadata: providerMetadataSchema.optional(),
24771
- preliminary: exports_external.boolean().optional()
24772
- }),
24773
- exports_external.object({
24774
- type: exports_external.literal("dynamic-tool"),
24775
- toolName: exports_external.string(),
24776
- toolCallId: exports_external.string(),
24777
- state: exports_external.literal("output-error"),
24778
- input: exports_external.unknown(),
24779
- output: exports_external.never().optional(),
24780
- errorText: exports_external.string(),
24781
- callProviderMetadata: providerMetadataSchema.optional()
24782
- }),
24783
- exports_external.object({
24784
- type: exports_external.string().startsWith("tool-"),
24785
- toolCallId: exports_external.string(),
24786
- state: exports_external.literal("input-streaming"),
24787
- providerExecuted: exports_external.boolean().optional(),
24788
- input: exports_external.unknown().optional(),
24789
- output: exports_external.never().optional(),
24790
- errorText: exports_external.never().optional(),
24791
- approval: exports_external.never().optional()
24792
- }),
24793
- exports_external.object({
24794
- type: exports_external.string().startsWith("tool-"),
24795
- toolCallId: exports_external.string(),
24796
- state: exports_external.literal("input-available"),
24797
- providerExecuted: exports_external.boolean().optional(),
24798
- input: exports_external.unknown(),
24799
- output: exports_external.never().optional(),
24800
- errorText: exports_external.never().optional(),
24801
- callProviderMetadata: providerMetadataSchema.optional(),
24802
- approval: exports_external.never().optional()
24803
- }),
24804
- exports_external.object({
24805
- type: exports_external.string().startsWith("tool-"),
24806
- toolCallId: exports_external.string(),
24807
- state: exports_external.literal("approval-requested"),
24808
- input: exports_external.unknown(),
24809
- providerExecuted: exports_external.boolean().optional(),
24810
- output: exports_external.never().optional(),
24811
- errorText: exports_external.never().optional(),
24812
- callProviderMetadata: providerMetadataSchema.optional(),
24813
- approval: exports_external.object({
24814
- id: exports_external.string(),
24815
- approved: exports_external.never().optional(),
24816
- reason: exports_external.never().optional()
24817
- })
24818
- }),
24819
- exports_external.object({
24820
- type: exports_external.string().startsWith("tool-"),
24821
- toolCallId: exports_external.string(),
24822
- state: exports_external.literal("approval-responded"),
24823
- input: exports_external.unknown(),
24824
- providerExecuted: exports_external.boolean().optional(),
24825
- output: exports_external.never().optional(),
24826
- errorText: exports_external.never().optional(),
24827
- callProviderMetadata: providerMetadataSchema.optional(),
24828
- approval: exports_external.object({
24829
- id: exports_external.string(),
24830
- approved: exports_external.boolean(),
24831
- reason: exports_external.string().optional()
24832
- })
24833
- }),
24834
- exports_external.object({
24835
- type: exports_external.string().startsWith("tool-"),
24836
- toolCallId: exports_external.string(),
24837
- state: exports_external.literal("output-available"),
24838
- providerExecuted: exports_external.boolean().optional(),
24839
- input: exports_external.unknown(),
24840
- output: exports_external.unknown(),
24841
- errorText: exports_external.never().optional(),
24842
- callProviderMetadata: providerMetadataSchema.optional(),
24843
- preliminary: exports_external.boolean().optional(),
24844
- approval: exports_external.object({
24845
- id: exports_external.string(),
24846
- approved: exports_external.literal(true),
24847
- reason: exports_external.string().optional()
24848
- }).optional()
24849
- }),
24850
- exports_external.object({
24851
- type: exports_external.string().startsWith("tool-"),
24852
- toolCallId: exports_external.string(),
24853
- state: exports_external.literal("output-error"),
24854
- providerExecuted: exports_external.boolean().optional(),
24855
- input: exports_external.unknown(),
24856
- output: exports_external.never().optional(),
24857
- errorText: exports_external.string(),
24858
- callProviderMetadata: providerMetadataSchema.optional(),
24859
- approval: exports_external.object({
24860
- id: exports_external.string(),
24861
- approved: exports_external.literal(true),
24862
- reason: exports_external.string().optional()
24863
- }).optional()
24864
- }),
24865
- exports_external.object({
24866
- type: exports_external.string().startsWith("tool-"),
24867
- toolCallId: exports_external.string(),
24868
- state: exports_external.literal("output-denied"),
24869
- providerExecuted: exports_external.boolean().optional(),
24870
- input: exports_external.unknown(),
24871
- output: exports_external.never().optional(),
24872
- errorText: exports_external.never().optional(),
24873
- callProviderMetadata: providerMetadataSchema.optional(),
24874
- approval: exports_external.object({
24875
- id: exports_external.string(),
24876
- approved: exports_external.literal(false),
24877
- reason: exports_external.string().optional()
24878
- })
24879
- })
24880
- ]))
24881
- }))));
24882
26412
 
24883
26413
  // ../xyd-ask-ai/dist/_rollupPluginBabelHelpers-B0vHBMb8.js
24884
26414
  function t(t2, r) {
@@ -25204,45 +26734,8 @@ function g(t2) {
25204
26734
  }, g(t2);
25205
26735
  }
25206
26736
 
25207
- // ../../node_modules/.pnpm/pkce-challenge@5.0.0/node_modules/pkce-challenge/dist/index.node.js
25208
- var crypto;
25209
- crypto = globalThis.crypto?.webcrypto ?? globalThis.crypto ?? import("node:crypto").then((m2) => m2.webcrypto);
25210
- async function getRandomValues(size) {
25211
- return (await crypto).getRandomValues(new Uint8Array(size));
25212
- }
25213
- async function random(size) {
25214
- const mask = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~";
25215
- let result = "";
25216
- const randomUints = await getRandomValues(size);
25217
- for (let i2 = 0;i2 < size; i2++) {
25218
- const randomIndex = randomUints[i2] % mask.length;
25219
- result += mask[randomIndex];
25220
- }
25221
- return result;
25222
- }
25223
- async function generateVerifier(length) {
25224
- return await random(length);
25225
- }
25226
- async function generateChallenge(code_verifier) {
25227
- const buffer = await (await crypto).subtle.digest("SHA-256", new TextEncoder().encode(code_verifier));
25228
- return btoa(String.fromCharCode(...new Uint8Array(buffer))).replace(/\//g, "_").replace(/\+/g, "-").replace(/=/g, "");
25229
- }
25230
- async function pkceChallenge(length) {
25231
- if (!length)
25232
- length = 43;
25233
- if (length < 43 || length > 128) {
25234
- throw `Expected a length between 43 and 128. Received ${length}.`;
25235
- }
25236
- const verifier = await generateVerifier(length);
25237
- const challenge = await generateChallenge(verifier);
25238
- return {
25239
- code_verifier: verifier,
25240
- code_challenge: challenge
25241
- };
25242
- }
25243
-
25244
26737
  // ../../node_modules/.pnpm/@ai-sdk+anthropic@2.0.30_zod@3.25.76/node_modules/@ai-sdk/anthropic/dist/index.mjs
25245
- var VERSION4 = "2.0.30";
26738
+ var VERSION5 = "2.0.30";
25246
26739
  var anthropicErrorDataSchema = lazySchema(() => zodSchema(exports_external.object({
25247
26740
  type: exports_external.literal("error"),
25248
26741
  error: exports_external.object({
@@ -25680,9 +27173,9 @@ var anthropicProviderOptions = exports_external.object({
25680
27173
  }).optional()
25681
27174
  });
25682
27175
  function getCacheControl(providerMetadata) {
25683
- var _a18;
27176
+ var _a19;
25684
27177
  const anthropic2 = providerMetadata == null ? undefined : providerMetadata.anthropic;
25685
- const cacheControlValue = (_a18 = anthropic2 == null ? undefined : anthropic2.cacheControl) != null ? _a18 : anthropic2 == null ? undefined : anthropic2.cache_control;
27178
+ const cacheControlValue = (_a19 = anthropic2 == null ? undefined : anthropic2.cacheControl) != null ? _a19 : anthropic2 == null ? undefined : anthropic2.cache_control;
25686
27179
  return cacheControlValue;
25687
27180
  }
25688
27181
  var textEditor_20250728ArgsSchema = lazySchema(() => zodSchema(exports_external.object({
@@ -25789,20 +27282,20 @@ async function prepareTools({
25789
27282
  return { tools: undefined, toolChoice: undefined, toolWarnings, betas };
25790
27283
  }
25791
27284
  const anthropicTools2 = [];
25792
- for (const tool2 of tools) {
25793
- switch (tool2.type) {
27285
+ for (const tool3 of tools) {
27286
+ switch (tool3.type) {
25794
27287
  case "function": {
25795
- const cacheControl = getCacheControl(tool2.providerOptions);
27288
+ const cacheControl = getCacheControl(tool3.providerOptions);
25796
27289
  anthropicTools2.push({
25797
- name: tool2.name,
25798
- description: tool2.description,
25799
- input_schema: tool2.inputSchema,
27290
+ name: tool3.name,
27291
+ description: tool3.description,
27292
+ input_schema: tool3.inputSchema,
25800
27293
  cache_control: cacheControl
25801
27294
  });
25802
27295
  break;
25803
27296
  }
25804
27297
  case "provider-defined": {
25805
- switch (tool2.id) {
27298
+ switch (tool3.id) {
25806
27299
  case "anthropic.code_execution_20250522": {
25807
27300
  betas.add("code-execution-2025-05-22");
25808
27301
  anthropicTools2.push({
@@ -25824,9 +27317,9 @@ async function prepareTools({
25824
27317
  anthropicTools2.push({
25825
27318
  name: "computer",
25826
27319
  type: "computer_20250124",
25827
- display_width_px: tool2.args.displayWidthPx,
25828
- display_height_px: tool2.args.displayHeightPx,
25829
- display_number: tool2.args.displayNumber
27320
+ display_width_px: tool3.args.displayWidthPx,
27321
+ display_height_px: tool3.args.displayHeightPx,
27322
+ display_number: tool3.args.displayNumber
25830
27323
  });
25831
27324
  break;
25832
27325
  }
@@ -25835,9 +27328,9 @@ async function prepareTools({
25835
27328
  anthropicTools2.push({
25836
27329
  name: "computer",
25837
27330
  type: "computer_20241022",
25838
- display_width_px: tool2.args.displayWidthPx,
25839
- display_height_px: tool2.args.displayHeightPx,
25840
- display_number: tool2.args.displayNumber
27331
+ display_width_px: tool3.args.displayWidthPx,
27332
+ display_height_px: tool3.args.displayHeightPx,
27333
+ display_number: tool3.args.displayNumber
25841
27334
  });
25842
27335
  break;
25843
27336
  }
@@ -25867,7 +27360,7 @@ async function prepareTools({
25867
27360
  }
25868
27361
  case "anthropic.text_editor_20250728": {
25869
27362
  const args = await validateTypes({
25870
- value: tool2.args,
27363
+ value: tool3.args,
25871
27364
  schema: textEditor_20250728ArgsSchema
25872
27365
  });
25873
27366
  anthropicTools2.push({
@@ -25904,7 +27397,7 @@ async function prepareTools({
25904
27397
  case "anthropic.web_fetch_20250910": {
25905
27398
  betas.add("web-fetch-2025-09-10");
25906
27399
  const args = await validateTypes({
25907
- value: tool2.args,
27400
+ value: tool3.args,
25908
27401
  schema: webFetch_20250910ArgsSchema
25909
27402
  });
25910
27403
  anthropicTools2.push({
@@ -25920,7 +27413,7 @@ async function prepareTools({
25920
27413
  }
25921
27414
  case "anthropic.web_search_20250305": {
25922
27415
  const args = await validateTypes({
25923
- value: tool2.args,
27416
+ value: tool3.args,
25924
27417
  schema: webSearch_20250305ArgsSchema
25925
27418
  });
25926
27419
  anthropicTools2.push({
@@ -25934,14 +27427,14 @@ async function prepareTools({
25934
27427
  break;
25935
27428
  }
25936
27429
  default: {
25937
- toolWarnings.push({ type: "unsupported-tool", tool: tool2 });
27430
+ toolWarnings.push({ type: "unsupported-tool", tool: tool3 });
25938
27431
  break;
25939
27432
  }
25940
27433
  }
25941
27434
  break;
25942
27435
  }
25943
27436
  default: {
25944
- toolWarnings.push({ type: "unsupported-tool", tool: tool2 });
27437
+ toolWarnings.push({ type: "unsupported-tool", tool: tool3 });
25945
27438
  break;
25946
27439
  }
25947
27440
  }
@@ -26111,19 +27604,19 @@ async function convertToAnthropicMessagesPrompt({
26111
27604
  sendReasoning,
26112
27605
  warnings
26113
27606
  }) {
26114
- var _a18, _b8, _c, _d, _e;
27607
+ var _a19, _b9, _c, _d, _e;
26115
27608
  const betas = /* @__PURE__ */ new Set;
26116
27609
  const blocks = groupIntoBlocks(prompt);
26117
27610
  let system = undefined;
26118
27611
  const messages = [];
26119
27612
  async function shouldEnableCitations(providerMetadata) {
26120
- var _a24, _b22;
27613
+ var _a25, _b23;
26121
27614
  const anthropicOptions = await parseProviderOptions({
26122
27615
  provider: "anthropic",
26123
27616
  providerOptions: providerMetadata,
26124
27617
  schema: anthropicFilePartProviderOptions
26125
27618
  });
26126
- return (_b22 = (_a24 = anthropicOptions == null ? undefined : anthropicOptions.citations) == null ? undefined : _a24.enabled) != null ? _b22 : false;
27619
+ return (_b23 = (_a25 = anthropicOptions == null ? undefined : anthropicOptions.citations) == null ? undefined : _a25.enabled) != null ? _b23 : false;
26127
27620
  }
26128
27621
  async function getDocumentMetadata(providerMetadata) {
26129
27622
  const anthropicOptions = await parseProviderOptions({
@@ -26163,7 +27656,7 @@ async function convertToAnthropicMessagesPrompt({
26163
27656
  for (let j2 = 0;j2 < content.length; j2++) {
26164
27657
  const part = content[j2];
26165
27658
  const isLastPart = j2 === content.length - 1;
26166
- const cacheControl = (_a18 = getCacheControl(part.providerOptions)) != null ? _a18 : isLastPart ? getCacheControl(message.providerOptions) : undefined;
27659
+ const cacheControl = (_a19 = getCacheControl(part.providerOptions)) != null ? _a19 : isLastPart ? getCacheControl(message.providerOptions) : undefined;
26167
27660
  switch (part.type) {
26168
27661
  case "text": {
26169
27662
  anthropicContent.push({
@@ -26201,7 +27694,7 @@ async function convertToAnthropicMessagesPrompt({
26201
27694
  media_type: "application/pdf",
26202
27695
  data: convertToBase64(part.data)
26203
27696
  },
26204
- title: (_b8 = metadata.title) != null ? _b8 : part.filename,
27697
+ title: (_b9 = metadata.title) != null ? _b9 : part.filename,
26205
27698
  ...metadata.context && { context: metadata.context },
26206
27699
  ...enableCitations && {
26207
27700
  citations: { enabled: true }
@@ -26614,7 +28107,7 @@ function mapAnthropicStopReason({
26614
28107
  }
26615
28108
  }
26616
28109
  function createCitationSource(citation, citationDocuments, generateId3) {
26617
- var _a18;
28110
+ var _a19;
26618
28111
  if (citation.type !== "page_location" && citation.type !== "char_location") {
26619
28112
  return;
26620
28113
  }
@@ -26627,7 +28120,7 @@ function createCitationSource(citation, citationDocuments, generateId3) {
26627
28120
  sourceType: "document",
26628
28121
  id: generateId3(),
26629
28122
  mediaType: documentInfo.mediaType,
26630
- title: (_a18 = citation.document_title) != null ? _a18 : documentInfo.title,
28123
+ title: (_a19 = citation.document_title) != null ? _a19 : documentInfo.title,
26631
28124
  filename: documentInfo.filename,
26632
28125
  providerMetadata: {
26633
28126
  anthropic: citation.type === "page_location" ? {
@@ -26645,10 +28138,10 @@ function createCitationSource(citation, citationDocuments, generateId3) {
26645
28138
  var AnthropicMessagesLanguageModel = class {
26646
28139
  constructor(modelId, config2) {
26647
28140
  this.specificationVersion = "v2";
26648
- var _a18;
28141
+ var _a19;
26649
28142
  this.modelId = modelId;
26650
28143
  this.config = config2;
26651
- this.generateId = (_a18 = config2.generateId) != null ? _a18 : generateId;
28144
+ this.generateId = (_a19 = config2.generateId) != null ? _a19 : generateId;
26652
28145
  }
26653
28146
  supportsUrl(url2) {
26654
28147
  return url2.protocol === "https:";
@@ -26657,8 +28150,8 @@ var AnthropicMessagesLanguageModel = class {
26657
28150
  return this.config.provider;
26658
28151
  }
26659
28152
  get supportedUrls() {
26660
- var _a18, _b8, _c;
26661
- return (_c = (_b8 = (_a18 = this.config).supportedUrls) == null ? undefined : _b8.call(_a18)) != null ? _c : {};
28153
+ var _a19, _b9, _c;
28154
+ return (_c = (_b9 = (_a19 = this.config).supportedUrls) == null ? undefined : _b9.call(_a19)) != null ? _c : {};
26662
28155
  }
26663
28156
  async getArgs({
26664
28157
  prompt,
@@ -26675,7 +28168,7 @@ var AnthropicMessagesLanguageModel = class {
26675
28168
  toolChoice,
26676
28169
  providerOptions
26677
28170
  }) {
26678
- var _a18, _b8, _c;
28171
+ var _a19, _b9, _c;
26679
28172
  const warnings = [];
26680
28173
  if (frequencyPenalty != null) {
26681
28174
  warnings.push({
@@ -26723,10 +28216,10 @@ var AnthropicMessagesLanguageModel = class {
26723
28216
  });
26724
28217
  const { prompt: messagesPrompt, betas: messagesBetas } = await convertToAnthropicMessagesPrompt({
26725
28218
  prompt,
26726
- sendReasoning: (_a18 = anthropicOptions == null ? undefined : anthropicOptions.sendReasoning) != null ? _a18 : true,
28219
+ sendReasoning: (_a19 = anthropicOptions == null ? undefined : anthropicOptions.sendReasoning) != null ? _a19 : true,
26727
28220
  warnings
26728
28221
  });
26729
- const isThinking = ((_b8 = anthropicOptions == null ? undefined : anthropicOptions.thinking) == null ? undefined : _b8.type) === "enabled";
28222
+ const isThinking = ((_b9 = anthropicOptions == null ? undefined : anthropicOptions.thinking) == null ? undefined : _b9.type) === "enabled";
26730
28223
  const thinkingBudget = (_c = anthropicOptions == null ? undefined : anthropicOptions.thinking) == null ? undefined : _c.budgetTokens;
26731
28224
  const baseArgs = {
26732
28225
  model: this.modelId,
@@ -26805,38 +28298,38 @@ var AnthropicMessagesLanguageModel = class {
26805
28298
  return combineHeaders(await resolve(this.config.headers), betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {}, headers);
26806
28299
  }
26807
28300
  buildRequestUrl(isStreaming) {
26808
- var _a18, _b8, _c;
26809
- return (_c = (_b8 = (_a18 = this.config).buildRequestUrl) == null ? undefined : _b8.call(_a18, this.config.baseURL, isStreaming)) != null ? _c : `${this.config.baseURL}/messages`;
28301
+ var _a19, _b9, _c;
28302
+ return (_c = (_b9 = (_a19 = this.config).buildRequestUrl) == null ? undefined : _b9.call(_a19, this.config.baseURL, isStreaming)) != null ? _c : `${this.config.baseURL}/messages`;
26810
28303
  }
26811
28304
  transformRequestBody(args) {
26812
- var _a18, _b8, _c;
26813
- return (_c = (_b8 = (_a18 = this.config).transformRequestBody) == null ? undefined : _b8.call(_a18, args)) != null ? _c : args;
28305
+ var _a19, _b9, _c;
28306
+ return (_c = (_b9 = (_a19 = this.config).transformRequestBody) == null ? undefined : _b9.call(_a19, args)) != null ? _c : args;
26814
28307
  }
26815
28308
  extractCitationDocuments(prompt) {
26816
28309
  const isCitationPart = (part) => {
26817
- var _a18, _b8;
28310
+ var _a19, _b9;
26818
28311
  if (part.type !== "file") {
26819
28312
  return false;
26820
28313
  }
26821
28314
  if (part.mediaType !== "application/pdf" && part.mediaType !== "text/plain") {
26822
28315
  return false;
26823
28316
  }
26824
- const anthropic2 = (_a18 = part.providerOptions) == null ? undefined : _a18.anthropic;
28317
+ const anthropic2 = (_a19 = part.providerOptions) == null ? undefined : _a19.anthropic;
26825
28318
  const citationsConfig = anthropic2 == null ? undefined : anthropic2.citations;
26826
- return (_b8 = citationsConfig == null ? undefined : citationsConfig.enabled) != null ? _b8 : false;
28319
+ return (_b9 = citationsConfig == null ? undefined : citationsConfig.enabled) != null ? _b9 : false;
26827
28320
  };
26828
28321
  return prompt.filter((message) => message.role === "user").flatMap((message) => message.content).filter(isCitationPart).map((part) => {
26829
- var _a18;
28322
+ var _a19;
26830
28323
  const filePart = part;
26831
28324
  return {
26832
- title: (_a18 = filePart.filename) != null ? _a18 : "Untitled Document",
28325
+ title: (_a19 = filePart.filename) != null ? _a19 : "Untitled Document",
26833
28326
  filename: filePart.filename,
26834
28327
  mediaType: filePart.mediaType
26835
28328
  };
26836
28329
  });
26837
28330
  }
26838
28331
  async doGenerate(options) {
26839
- var _a18, _b8, _c, _d, _e, _f;
28332
+ var _a19, _b9, _c, _d, _e, _f;
26840
28333
  const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
26841
28334
  const citationDocuments = this.extractCitationDocuments(options.prompt);
26842
28335
  const {
@@ -26970,11 +28463,11 @@ var AnthropicMessagesLanguageModel = class {
26970
28463
  toolCallId: part.tool_use_id,
26971
28464
  toolName: "web_search",
26972
28465
  result: part.content.map((result) => {
26973
- var _a24;
28466
+ var _a25;
26974
28467
  return {
26975
28468
  url: result.url,
26976
28469
  title: result.title,
26977
- pageAge: (_a24 = result.page_age) != null ? _a24 : null,
28470
+ pageAge: (_a25 = result.page_age) != null ? _a25 : null,
26978
28471
  encryptedContent: result.encrypted_content,
26979
28472
  type: result.type
26980
28473
  };
@@ -26990,7 +28483,7 @@ var AnthropicMessagesLanguageModel = class {
26990
28483
  title: result.title,
26991
28484
  providerMetadata: {
26992
28485
  anthropic: {
26993
- pageAge: (_a18 = result.page_age) != null ? _a18 : null
28486
+ pageAge: (_a19 = result.page_age) != null ? _a19 : null
26994
28487
  }
26995
28488
  }
26996
28489
  });
@@ -27062,7 +28555,7 @@ var AnthropicMessagesLanguageModel = class {
27062
28555
  inputTokens: response.usage.input_tokens,
27063
28556
  outputTokens: response.usage.output_tokens,
27064
28557
  totalTokens: response.usage.input_tokens + response.usage.output_tokens,
27065
- cachedInputTokens: (_b8 = response.usage.cache_read_input_tokens) != null ? _b8 : undefined
28558
+ cachedInputTokens: (_b9 = response.usage.cache_read_input_tokens) != null ? _b9 : undefined
27066
28559
  },
27067
28560
  request: { body: args },
27068
28561
  response: {
@@ -27112,7 +28605,7 @@ var AnthropicMessagesLanguageModel = class {
27112
28605
  controller.enqueue({ type: "stream-start", warnings });
27113
28606
  },
27114
28607
  transform(chunk, controller) {
27115
- var _a18, _b8, _c, _d, _e, _f, _g, _h;
28608
+ var _a19, _b9, _c, _d, _e, _f, _g, _h;
27116
28609
  if (options.includeRawChunks) {
27117
28610
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
27118
28611
  }
@@ -27245,11 +28738,11 @@ var AnthropicMessagesLanguageModel = class {
27245
28738
  toolCallId: part.tool_use_id,
27246
28739
  toolName: "web_search",
27247
28740
  result: part.content.map((result) => {
27248
- var _a24;
28741
+ var _a25;
27249
28742
  return {
27250
28743
  url: result.url,
27251
28744
  title: result.title,
27252
- pageAge: (_a24 = result.page_age) != null ? _a24 : null,
28745
+ pageAge: (_a25 = result.page_age) != null ? _a25 : null,
27253
28746
  encryptedContent: result.encrypted_content,
27254
28747
  type: result.type
27255
28748
  };
@@ -27265,7 +28758,7 @@ var AnthropicMessagesLanguageModel = class {
27265
28758
  title: result.title,
27266
28759
  providerMetadata: {
27267
28760
  anthropic: {
27268
- pageAge: (_a18 = result.page_age) != null ? _a18 : null
28761
+ pageAge: (_a19 = result.page_age) != null ? _a19 : null
27269
28762
  }
27270
28763
  }
27271
28764
  });
@@ -27458,7 +28951,7 @@ var AnthropicMessagesLanguageModel = class {
27458
28951
  }
27459
28952
  case "message_start": {
27460
28953
  usage.inputTokens = value.message.usage.input_tokens;
27461
- usage.cachedInputTokens = (_b8 = value.message.usage.cache_read_input_tokens) != null ? _b8 : undefined;
28954
+ usage.cachedInputTokens = (_b9 = value.message.usage.cache_read_input_tokens) != null ? _b9 : undefined;
27462
28955
  rawUsage = {
27463
28956
  ...value.message.usage
27464
28957
  };
@@ -27681,8 +29174,8 @@ var anthropicTools = {
27681
29174
  webSearch_20250305
27682
29175
  };
27683
29176
  function createAnthropic(options = {}) {
27684
- var _a18;
27685
- const baseURL = (_a18 = withoutTrailingSlash(options.baseURL)) != null ? _a18 : "https://api.anthropic.com/v1";
29177
+ var _a19;
29178
+ const baseURL = (_a19 = withoutTrailingSlash(options.baseURL)) != null ? _a19 : "https://api.anthropic.com/v1";
27686
29179
  const getHeaders = () => withUserAgentSuffix({
27687
29180
  "anthropic-version": "2023-06-01",
27688
29181
  "x-api-key": loadApiKey({
@@ -27691,15 +29184,15 @@ function createAnthropic(options = {}) {
27691
29184
  description: "Anthropic"
27692
29185
  }),
27693
29186
  ...options.headers
27694
- }, `ai-sdk/anthropic/${VERSION4}`);
29187
+ }, `ai-sdk/anthropic/${VERSION5}`);
27695
29188
  const createChatModel = (modelId) => {
27696
- var _a24;
29189
+ var _a25;
27697
29190
  return new AnthropicMessagesLanguageModel(modelId, {
27698
29191
  provider: "anthropic.messages",
27699
29192
  baseURL,
27700
29193
  headers: getHeaders,
27701
29194
  fetch: options.fetch,
27702
- generateId: (_a24 = options.generateId) != null ? _a24 : generateId,
29195
+ generateId: (_a25 = options.generateId) != null ? _a25 : generateId,
27703
29196
  supportedUrls: () => ({
27704
29197
  "image/*": [/^https?:\/\/.*$/]
27705
29198
  })
@@ -27778,7 +29271,7 @@ function convertToOpenAIChatMessages({
27778
29271
  messages.push({
27779
29272
  role: "user",
27780
29273
  content: content.map((part, index) => {
27781
- var _a18, _b8, _c;
29274
+ var _a19, _b9, _c;
27782
29275
  switch (part.type) {
27783
29276
  case "text": {
27784
29277
  return { type: "text", text: part.text };
@@ -27790,7 +29283,7 @@ function convertToOpenAIChatMessages({
27790
29283
  type: "image_url",
27791
29284
  image_url: {
27792
29285
  url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`,
27793
- detail: (_b8 = (_a18 = part.providerOptions) == null ? undefined : _a18.openai) == null ? undefined : _b8.imageDetail
29286
+ detail: (_b9 = (_a19 = part.providerOptions) == null ? undefined : _a19.openai) == null ? undefined : _b9.imageDetail
27794
29287
  }
27795
29288
  };
27796
29289
  } else if (part.mediaType.startsWith("audio/")) {
@@ -28070,21 +29563,21 @@ function prepareChatTools({
28070
29563
  return { tools: undefined, toolChoice: undefined, toolWarnings };
28071
29564
  }
28072
29565
  const openaiTools2 = [];
28073
- for (const tool2 of tools) {
28074
- switch (tool2.type) {
29566
+ for (const tool3 of tools) {
29567
+ switch (tool3.type) {
28075
29568
  case "function":
28076
29569
  openaiTools2.push({
28077
29570
  type: "function",
28078
29571
  function: {
28079
- name: tool2.name,
28080
- description: tool2.description,
28081
- parameters: tool2.inputSchema,
29572
+ name: tool3.name,
29573
+ description: tool3.description,
29574
+ parameters: tool3.inputSchema,
28082
29575
  strict: structuredOutputs ? strictJsonSchema : undefined
28083
29576
  }
28084
29577
  });
28085
29578
  break;
28086
29579
  default:
28087
- toolWarnings.push({ type: "unsupported-tool", tool: tool2 });
29580
+ toolWarnings.push({ type: "unsupported-tool", tool: tool3 });
28088
29581
  break;
28089
29582
  }
28090
29583
  }
@@ -28143,14 +29636,14 @@ var OpenAIChatLanguageModel = class {
28143
29636
  toolChoice,
28144
29637
  providerOptions
28145
29638
  }) {
28146
- var _a18, _b8, _c, _d;
29639
+ var _a19, _b9, _c, _d;
28147
29640
  const warnings = [];
28148
- const openaiOptions = (_a18 = await parseProviderOptions({
29641
+ const openaiOptions = (_a19 = await parseProviderOptions({
28149
29642
  provider: "openai",
28150
29643
  providerOptions,
28151
29644
  schema: openaiChatLanguageModelOptions
28152
- })) != null ? _a18 : {};
28153
- const structuredOutputs = (_b8 = openaiOptions.structuredOutputs) != null ? _b8 : true;
29645
+ })) != null ? _a19 : {};
29646
+ const structuredOutputs = (_b9 = openaiOptions.structuredOutputs) != null ? _b9 : true;
28154
29647
  if (topK != null) {
28155
29648
  warnings.push({
28156
29649
  type: "unsupported-setting",
@@ -28310,7 +29803,7 @@ var OpenAIChatLanguageModel = class {
28310
29803
  };
28311
29804
  }
28312
29805
  async doGenerate(options) {
28313
- var _a18, _b8, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
29806
+ var _a19, _b9, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
28314
29807
  const { args: body, warnings } = await this.getArgs(options);
28315
29808
  const {
28316
29809
  responseHeaders,
@@ -28334,10 +29827,10 @@ var OpenAIChatLanguageModel = class {
28334
29827
  if (text2 != null && text2.length > 0) {
28335
29828
  content.push({ type: "text", text: text2 });
28336
29829
  }
28337
- for (const toolCall of (_a18 = choice.message.tool_calls) != null ? _a18 : []) {
29830
+ for (const toolCall of (_a19 = choice.message.tool_calls) != null ? _a19 : []) {
28338
29831
  content.push({
28339
29832
  type: "tool-call",
28340
- toolCallId: (_b8 = toolCall.id) != null ? _b8 : generateId(),
29833
+ toolCallId: (_b9 = toolCall.id) != null ? _b9 : generateId(),
28341
29834
  toolName: toolCall.function.name,
28342
29835
  input: toolCall.function.arguments
28343
29836
  });
@@ -28420,7 +29913,7 @@ var OpenAIChatLanguageModel = class {
28420
29913
  controller.enqueue({ type: "stream-start", warnings });
28421
29914
  },
28422
29915
  transform(chunk, controller) {
28423
- var _a18, _b8, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
29916
+ var _a19, _b9, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
28424
29917
  if (options.includeRawChunks) {
28425
29918
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
28426
29919
  }
@@ -28443,8 +29936,8 @@ var OpenAIChatLanguageModel = class {
28443
29936
  });
28444
29937
  }
28445
29938
  if (value.usage != null) {
28446
- usage.inputTokens = (_a18 = value.usage.prompt_tokens) != null ? _a18 : undefined;
28447
- usage.outputTokens = (_b8 = value.usage.completion_tokens) != null ? _b8 : undefined;
29939
+ usage.inputTokens = (_a19 = value.usage.prompt_tokens) != null ? _a19 : undefined;
29940
+ usage.outputTokens = (_b9 = value.usage.completion_tokens) != null ? _b9 : undefined;
28448
29941
  usage.totalTokens = (_c = value.usage.total_tokens) != null ? _c : undefined;
28449
29942
  usage.reasoningTokens = (_e = (_d = value.usage.completion_tokens_details) == null ? undefined : _d.reasoning_tokens) != null ? _e : undefined;
28450
29943
  usage.cachedInputTokens = (_g = (_f = value.usage.prompt_tokens_details) == null ? undefined : _f.cached_tokens) != null ? _g : undefined;
@@ -28604,11 +30097,11 @@ function supportsPriorityProcessing(modelId) {
28604
30097
  return modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
28605
30098
  }
28606
30099
  function getSystemMessageMode(modelId) {
28607
- var _a18, _b8;
30100
+ var _a19, _b9;
28608
30101
  if (!isReasoningModel(modelId)) {
28609
30102
  return "system";
28610
30103
  }
28611
- return (_b8 = (_a18 = reasoningModels[modelId]) == null ? undefined : _a18.systemMessageMode) != null ? _b8 : "developer";
30104
+ return (_b9 = (_a19 = reasoningModels[modelId]) == null ? undefined : _a19.systemMessageMode) != null ? _b9 : "developer";
28612
30105
  }
28613
30106
  var reasoningModels = {
28614
30107
  "o1-mini": {
@@ -28869,7 +30362,7 @@ var OpenAICompletionLanguageModel = class {
28869
30362
  };
28870
30363
  }
28871
30364
  async doGenerate(options) {
28872
- var _a18, _b8, _c;
30365
+ var _a19, _b9, _c;
28873
30366
  const { args, warnings } = await this.getArgs(options);
28874
30367
  const {
28875
30368
  responseHeaders,
@@ -28895,8 +30388,8 @@ var OpenAICompletionLanguageModel = class {
28895
30388
  return {
28896
30389
  content: [{ type: "text", text: choice.text }],
28897
30390
  usage: {
28898
- inputTokens: (_a18 = response.usage) == null ? undefined : _a18.prompt_tokens,
28899
- outputTokens: (_b8 = response.usage) == null ? undefined : _b8.completion_tokens,
30391
+ inputTokens: (_a19 = response.usage) == null ? undefined : _a19.prompt_tokens,
30392
+ outputTokens: (_b9 = response.usage) == null ? undefined : _b9.completion_tokens,
28900
30393
  totalTokens: (_c = response.usage) == null ? undefined : _c.total_tokens
28901
30394
  },
28902
30395
  finishReason: mapOpenAIFinishReason2(choice.finish_reason),
@@ -29029,7 +30522,7 @@ var OpenAIEmbeddingModel = class {
29029
30522
  abortSignal,
29030
30523
  providerOptions
29031
30524
  }) {
29032
- var _a18;
30525
+ var _a19;
29033
30526
  if (values.length > this.maxEmbeddingsPerCall) {
29034
30527
  throw new TooManyEmbeddingValuesForCallError({
29035
30528
  provider: this.provider,
@@ -29038,11 +30531,11 @@ var OpenAIEmbeddingModel = class {
29038
30531
  values
29039
30532
  });
29040
30533
  }
29041
- const openaiOptions = (_a18 = await parseProviderOptions({
30534
+ const openaiOptions = (_a19 = await parseProviderOptions({
29042
30535
  provider: "openai",
29043
30536
  providerOptions,
29044
30537
  schema: openaiEmbeddingProviderOptions
29045
- })) != null ? _a18 : {};
30538
+ })) != null ? _a19 : {};
29046
30539
  const {
29047
30540
  responseHeaders,
29048
30541
  value: response,
@@ -29095,8 +30588,8 @@ var OpenAIImageModel = class {
29095
30588
  this.specificationVersion = "v2";
29096
30589
  }
29097
30590
  get maxImagesPerCall() {
29098
- var _a18;
29099
- return (_a18 = modelMaxImagesPerCall[this.modelId]) != null ? _a18 : 1;
30591
+ var _a19;
30592
+ return (_a19 = modelMaxImagesPerCall[this.modelId]) != null ? _a19 : 1;
29100
30593
  }
29101
30594
  get provider() {
29102
30595
  return this.config.provider;
@@ -29111,7 +30604,7 @@ var OpenAIImageModel = class {
29111
30604
  headers,
29112
30605
  abortSignal
29113
30606
  }) {
29114
- var _a18, _b8, _c, _d;
30607
+ var _a19, _b9, _c, _d;
29115
30608
  const warnings = [];
29116
30609
  if (aspectRatio != null) {
29117
30610
  warnings.push({
@@ -29123,7 +30616,7 @@ var OpenAIImageModel = class {
29123
30616
  if (seed != null) {
29124
30617
  warnings.push({ type: "unsupported-setting", setting: "seed" });
29125
30618
  }
29126
- const currentDate = (_c = (_b8 = (_a18 = this.config._internal) == null ? undefined : _a18.currentDate) == null ? undefined : _b8.call(_a18)) != null ? _c : /* @__PURE__ */ new Date;
30619
+ const currentDate = (_c = (_b9 = (_a19 = this.config._internal) == null ? undefined : _a19.currentDate) == null ? undefined : _b9.call(_a19)) != null ? _c : /* @__PURE__ */ new Date;
29127
30620
  const { value: response, responseHeaders } = await postJsonToApi({
29128
30621
  url: this.config.url({
29129
30622
  path: "/images/generations",
@@ -29355,7 +30848,7 @@ async function convertToOpenAIResponsesInput({
29355
30848
  store,
29356
30849
  hasLocalShellTool = false
29357
30850
  }) {
29358
- var _a18, _b8, _c, _d;
30851
+ var _a19, _b9, _c, _d;
29359
30852
  const input = [];
29360
30853
  const warnings = [];
29361
30854
  for (const { role, content } of prompt) {
@@ -29388,7 +30881,7 @@ async function convertToOpenAIResponsesInput({
29388
30881
  input.push({
29389
30882
  role: "user",
29390
30883
  content: content.map((part, index) => {
29391
- var _a24, _b22, _c2;
30884
+ var _a25, _b23, _c2;
29392
30885
  switch (part.type) {
29393
30886
  case "text": {
29394
30887
  return { type: "input_text", text: part.text };
@@ -29401,7 +30894,7 @@ async function convertToOpenAIResponsesInput({
29401
30894
  ...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
29402
30895
  image_url: `data:${mediaType};base64,${convertToBase64(part.data)}`
29403
30896
  },
29404
- detail: (_b22 = (_a24 = part.providerOptions) == null ? undefined : _a24.openai) == null ? undefined : _b22.imageDetail
30897
+ detail: (_b23 = (_a25 = part.providerOptions) == null ? undefined : _a25.openai) == null ? undefined : _b23.imageDetail
29405
30898
  };
29406
30899
  } else if (part.mediaType === "application/pdf") {
29407
30900
  if (part.data instanceof URL) {
@@ -29434,7 +30927,7 @@ async function convertToOpenAIResponsesInput({
29434
30927
  for (const part of content) {
29435
30928
  switch (part.type) {
29436
30929
  case "text": {
29437
- const id = (_b8 = (_a18 = part.providerOptions) == null ? undefined : _a18.openai) == null ? undefined : _b8.itemId;
30930
+ const id = (_b9 = (_a19 = part.providerOptions) == null ? undefined : _a19.openai) == null ? undefined : _b9.itemId;
29438
30931
  if (store && id != null) {
29439
30932
  input.push({ type: "item_reference", id });
29440
30933
  break;
@@ -30110,22 +31603,22 @@ async function prepareResponsesTools({
30110
31603
  return { tools: undefined, toolChoice: undefined, toolWarnings };
30111
31604
  }
30112
31605
  const openaiTools2 = [];
30113
- for (const tool2 of tools) {
30114
- switch (tool2.type) {
31606
+ for (const tool3 of tools) {
31607
+ switch (tool3.type) {
30115
31608
  case "function":
30116
31609
  openaiTools2.push({
30117
31610
  type: "function",
30118
- name: tool2.name,
30119
- description: tool2.description,
30120
- parameters: tool2.inputSchema,
31611
+ name: tool3.name,
31612
+ description: tool3.description,
31613
+ parameters: tool3.inputSchema,
30121
31614
  strict: strictJsonSchema
30122
31615
  });
30123
31616
  break;
30124
31617
  case "provider-defined": {
30125
- switch (tool2.id) {
31618
+ switch (tool3.id) {
30126
31619
  case "openai.file_search": {
30127
31620
  const args = await validateTypes({
30128
- value: tool2.args,
31621
+ value: tool3.args,
30129
31622
  schema: fileSearchArgsSchema
30130
31623
  });
30131
31624
  openaiTools2.push({
@@ -30148,7 +31641,7 @@ async function prepareResponsesTools({
30148
31641
  }
30149
31642
  case "openai.web_search_preview": {
30150
31643
  const args = await validateTypes({
30151
- value: tool2.args,
31644
+ value: tool3.args,
30152
31645
  schema: webSearchPreviewArgsSchema
30153
31646
  });
30154
31647
  openaiTools2.push({
@@ -30160,7 +31653,7 @@ async function prepareResponsesTools({
30160
31653
  }
30161
31654
  case "openai.web_search": {
30162
31655
  const args = await validateTypes({
30163
- value: tool2.args,
31656
+ value: tool3.args,
30164
31657
  schema: webSearchArgsSchema
30165
31658
  });
30166
31659
  openaiTools2.push({
@@ -30173,7 +31666,7 @@ async function prepareResponsesTools({
30173
31666
  }
30174
31667
  case "openai.code_interpreter": {
30175
31668
  const args = await validateTypes({
30176
- value: tool2.args,
31669
+ value: tool3.args,
30177
31670
  schema: codeInterpreterArgsSchema
30178
31671
  });
30179
31672
  openaiTools2.push({
@@ -30184,7 +31677,7 @@ async function prepareResponsesTools({
30184
31677
  }
30185
31678
  case "openai.image_generation": {
30186
31679
  const args = await validateTypes({
30187
- value: tool2.args,
31680
+ value: tool3.args,
30188
31681
  schema: imageGenerationArgsSchema
30189
31682
  });
30190
31683
  openaiTools2.push({
@@ -30208,7 +31701,7 @@ async function prepareResponsesTools({
30208
31701
  break;
30209
31702
  }
30210
31703
  default:
30211
- toolWarnings.push({ type: "unsupported-tool", tool: tool2 });
31704
+ toolWarnings.push({ type: "unsupported-tool", tool: tool3 });
30212
31705
  break;
30213
31706
  }
30214
31707
  }
@@ -30263,7 +31756,7 @@ var OpenAIResponsesLanguageModel = class {
30263
31756
  toolChoice,
30264
31757
  responseFormat
30265
31758
  }) {
30266
- var _a18, _b8, _c, _d;
31759
+ var _a19, _b9, _c, _d;
30267
31760
  const warnings = [];
30268
31761
  const modelConfig = getResponsesModelConfig(this.modelId);
30269
31762
  if (topK != null) {
@@ -30296,11 +31789,11 @@ var OpenAIResponsesLanguageModel = class {
30296
31789
  prompt,
30297
31790
  systemMessageMode: modelConfig.systemMessageMode,
30298
31791
  fileIdPrefixes: this.config.fileIdPrefixes,
30299
- store: (_a18 = openaiOptions == null ? undefined : openaiOptions.store) != null ? _a18 : true,
31792
+ store: (_a19 = openaiOptions == null ? undefined : openaiOptions.store) != null ? _a19 : true,
30300
31793
  hasLocalShellTool: hasOpenAITool("openai.local_shell")
30301
31794
  });
30302
31795
  warnings.push(...inputWarnings);
30303
- const strictJsonSchema = (_b8 = openaiOptions == null ? undefined : openaiOptions.strictJsonSchema) != null ? _b8 : false;
31796
+ const strictJsonSchema = (_b9 = openaiOptions == null ? undefined : openaiOptions.strictJsonSchema) != null ? _b9 : false;
30304
31797
  let include = openaiOptions == null ? undefined : openaiOptions.include;
30305
31798
  function addInclude(key) {
30306
31799
  if (include == null) {
@@ -30310,13 +31803,13 @@ var OpenAIResponsesLanguageModel = class {
30310
31803
  }
30311
31804
  }
30312
31805
  function hasOpenAITool(id) {
30313
- return (tools == null ? undefined : tools.find((tool2) => tool2.type === "provider-defined" && tool2.id === id)) != null;
31806
+ return (tools == null ? undefined : tools.find((tool3) => tool3.type === "provider-defined" && tool3.id === id)) != null;
30314
31807
  }
30315
31808
  const topLogprobs = typeof (openaiOptions == null ? undefined : openaiOptions.logprobs) === "number" ? openaiOptions == null ? undefined : openaiOptions.logprobs : (openaiOptions == null ? undefined : openaiOptions.logprobs) === true ? TOP_LOGPROBS_MAX : undefined;
30316
31809
  if (topLogprobs) {
30317
31810
  addInclude("message.output_text.logprobs");
30318
31811
  }
30319
- const webSearchToolName = (_c = tools == null ? undefined : tools.find((tool2) => tool2.type === "provider-defined" && (tool2.id === "openai.web_search" || tool2.id === "openai.web_search_preview"))) == null ? undefined : _c.name;
31812
+ const webSearchToolName = (_c = tools == null ? undefined : tools.find((tool3) => tool3.type === "provider-defined" && (tool3.id === "openai.web_search" || tool3.id === "openai.web_search_preview"))) == null ? undefined : _c.name;
30320
31813
  if (webSearchToolName) {
30321
31814
  addInclude("web_search_call.action.sources");
30322
31815
  }
@@ -30445,7 +31938,7 @@ var OpenAIResponsesLanguageModel = class {
30445
31938
  };
30446
31939
  }
30447
31940
  async doGenerate(options) {
30448
- var _a18, _b8, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
31941
+ var _a19, _b9, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
30449
31942
  const {
30450
31943
  args: body,
30451
31944
  warnings,
@@ -30495,7 +31988,7 @@ var OpenAIResponsesLanguageModel = class {
30495
31988
  providerMetadata: {
30496
31989
  openai: {
30497
31990
  itemId: part.id,
30498
- reasoningEncryptedContent: (_a18 = part.encrypted_content) != null ? _a18 : null
31991
+ reasoningEncryptedContent: (_a19 = part.encrypted_content) != null ? _a19 : null
30499
31992
  }
30500
31993
  }
30501
31994
  });
@@ -30539,7 +32032,7 @@ var OpenAIResponsesLanguageModel = class {
30539
32032
  }
30540
32033
  case "message": {
30541
32034
  for (const contentPart of part.content) {
30542
- if (((_c = (_b8 = options.providerOptions) == null ? undefined : _b8.openai) == null ? undefined : _c.logprobs) && contentPart.logprobs) {
32035
+ if (((_c = (_b9 = options.providerOptions) == null ? undefined : _b9.openai) == null ? undefined : _c.logprobs) && contentPart.logprobs) {
30543
32036
  logprobs.push(contentPart.logprobs);
30544
32037
  }
30545
32038
  content.push({
@@ -30751,7 +32244,7 @@ var OpenAIResponsesLanguageModel = class {
30751
32244
  controller.enqueue({ type: "stream-start", warnings });
30752
32245
  },
30753
32246
  transform(chunk, controller) {
30754
- var _a18, _b8, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
32247
+ var _a19, _b9, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
30755
32248
  if (options.includeRawChunks) {
30756
32249
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
30757
32250
  }
@@ -30861,7 +32354,7 @@ var OpenAIResponsesLanguageModel = class {
30861
32354
  providerMetadata: {
30862
32355
  openai: {
30863
32356
  itemId: value.item.id,
30864
- reasoningEncryptedContent: (_a18 = value.item.encrypted_content) != null ? _a18 : null
32357
+ reasoningEncryptedContent: (_a19 = value.item.encrypted_content) != null ? _a19 : null
30865
32358
  }
30866
32359
  }
30867
32360
  });
@@ -30925,7 +32418,7 @@ var OpenAIResponsesLanguageModel = class {
30925
32418
  toolName: "file_search",
30926
32419
  result: {
30927
32420
  queries: value.item.queries,
30928
- results: (_c = (_b8 = value.item.results) == null ? undefined : _b8.map((result) => ({
32421
+ results: (_c = (_b9 = value.item.results) == null ? undefined : _b9.map((result) => ({
30929
32422
  attributes: result.attributes,
30930
32423
  fileId: result.file_id,
30931
32424
  filename: result.filename,
@@ -31231,10 +32724,10 @@ function getResponsesModelConfig(modelId) {
31231
32724
  };
31232
32725
  }
31233
32726
  function mapWebSearchOutput(action) {
31234
- var _a18;
32727
+ var _a19;
31235
32728
  switch (action.type) {
31236
32729
  case "search":
31237
- return { action: { type: "search", query: (_a18 = action.query) != null ? _a18 : undefined } };
32730
+ return { action: { type: "search", query: (_a19 = action.query) != null ? _a19 : undefined } };
31238
32731
  case "open_page":
31239
32732
  return { action: { type: "openPage", url: action.url } };
31240
32733
  case "find":
@@ -31312,8 +32805,8 @@ var OpenAISpeechModel = class {
31312
32805
  };
31313
32806
  }
31314
32807
  async doGenerate(options) {
31315
- var _a18, _b8, _c;
31316
- const currentDate = (_c = (_b8 = (_a18 = this.config._internal) == null ? undefined : _a18.currentDate) == null ? undefined : _b8.call(_a18)) != null ? _c : /* @__PURE__ */ new Date;
32808
+ var _a19, _b9, _c;
32809
+ const currentDate = (_c = (_b9 = (_a19 = this.config._internal) == null ? undefined : _a19.currentDate) == null ? undefined : _b9.call(_a19)) != null ? _c : /* @__PURE__ */ new Date;
31317
32810
  const { requestBody, warnings } = await this.getArgs(options);
31318
32811
  const {
31319
32812
  value: audio,
@@ -31489,8 +32982,8 @@ var OpenAITranscriptionModel = class {
31489
32982
  };
31490
32983
  }
31491
32984
  async doGenerate(options) {
31492
- var _a18, _b8, _c, _d, _e, _f, _g, _h;
31493
- const currentDate = (_c = (_b8 = (_a18 = this.config._internal) == null ? undefined : _a18.currentDate) == null ? undefined : _b8.call(_a18)) != null ? _c : /* @__PURE__ */ new Date;
32985
+ var _a19, _b9, _c, _d, _e, _f, _g, _h;
32986
+ const currentDate = (_c = (_b9 = (_a19 = this.config._internal) == null ? undefined : _a19.currentDate) == null ? undefined : _b9.call(_a19)) != null ? _c : /* @__PURE__ */ new Date;
31494
32987
  const { formData, warnings } = await this.getArgs(options);
31495
32988
  const {
31496
32989
  value: response,
@@ -31532,14 +33025,14 @@ var OpenAITranscriptionModel = class {
31532
33025
  };
31533
33026
  }
31534
33027
  };
31535
- var VERSION5 = "2.0.52";
33028
+ var VERSION6 = "2.0.52";
31536
33029
  function createOpenAI(options = {}) {
31537
- var _a18, _b8;
31538
- const baseURL = (_a18 = withoutTrailingSlash(loadOptionalSetting({
33030
+ var _a19, _b9;
33031
+ const baseURL = (_a19 = withoutTrailingSlash(loadOptionalSetting({
31539
33032
  settingValue: options.baseURL,
31540
33033
  environmentVariableName: "OPENAI_BASE_URL"
31541
- }))) != null ? _a18 : "https://api.openai.com/v1";
31542
- const providerName = (_b8 = options.name) != null ? _b8 : "openai";
33034
+ }))) != null ? _a19 : "https://api.openai.com/v1";
33035
+ const providerName = (_b9 = options.name) != null ? _b9 : "openai";
31543
33036
  const getHeaders = () => withUserAgentSuffix({
31544
33037
  Authorization: `Bearer ${loadApiKey({
31545
33038
  apiKey: options.apiKey,
@@ -31549,7 +33042,7 @@ function createOpenAI(options = {}) {
31549
33042
  "OpenAI-Organization": options.organization,
31550
33043
  "OpenAI-Project": options.project,
31551
33044
  ...options.headers
31552
- }, `ai-sdk/openai/${VERSION5}`);
33045
+ }, `ai-sdk/openai/${VERSION6}`);
31553
33046
  const createChatModel = (modelId) => new OpenAIChatLanguageModel(modelId, {
31554
33047
  provider: `${providerName}.chat`,
31555
33048
  url: ({ path }) => `${baseURL}${path}`,
@@ -35231,29 +36724,29 @@ var ma = function() {
35231
36724
  var e3, t2, n2, r2, a2, o2, c2, l2;
35232
36725
  }();
35233
36726
  var ya;
35234
- var _a18;
36727
+ var _a19;
35235
36728
  var ga;
35236
36729
  async function ka(e3, a2, i2, s2, o2) {
35237
36730
  try {
35238
36731
  if (!ya) {
35239
- const n2 = new ma(new URL(e3 || "http://localhost:3000/mcp"));
35240
- ya = await createMCPClient({ transport: n2 });
36732
+ const t2 = new ma(new URL(e3 || "http://localhost:3000/mcp"));
36733
+ ya = await createMCPClient({ transport: t2 });
35241
36734
  }
35242
- if (!_a18)
36735
+ if (!_a19)
35243
36736
  switch (a2) {
35244
36737
  case "openai":
35245
36738
  const e4 = createOpenAI({ apiKey: s2 });
35246
- _a18 = e4(i2);
36739
+ _a19 = e4(i2);
35247
36740
  break;
35248
36741
  case "anthropic":
35249
36742
  const t2 = createAnthropic({ apiKey: s2 });
35250
- _a18 = t2(i2);
36743
+ _a19 = t2(i2);
35251
36744
  break;
35252
36745
  default:
35253
36746
  throw new Error("Invalid AI provider");
35254
36747
  }
35255
36748
  ga || (ga = await ya.tools());
35256
- return (await streamText({ model: _a18, tools: ga, stopWhen: stepCountIs(5), messages: [{ role: "user", content: [{ type: "text", text: o2 }] }] })).textStream;
36749
+ return (await streamText({ model: _a19, tools: ga, stopWhen: stepCountIs(5), messages: [{ role: "user", content: [{ type: "text", text: o2 }] }] })).textStream;
35257
36750
  } catch (e4) {
35258
36751
  throw console.error(e4), e4;
35259
36752
  }