@mastra/server 1.84.0-alpha.3 → 1.84.0-alpha.4

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 (140) hide show
  1. package/dist/_types/@mastra_schema-compat@1.4.0/dist/_types/@internal_ai-sdk-v5@0.0.96/dist/index.d.ts +61 -2
  2. package/dist/_types/@mastra_schema-compat@1.4.0/dist/_types/@internal_ai-v6@0.0.96/dist/index.d.ts +9 -1
  3. package/dist/{a2a-CY85JalK.js → a2a-By6Kef65.js} +2 -2
  4. package/dist/{a2a-CY85JalK.js.map → a2a-By6Kef65.js.map} +1 -1
  5. package/dist/{a2a-Bz7vRGfF.cjs → a2a-CCYYdrZ1.cjs} +2 -2
  6. package/dist/{a2a-Bz7vRGfF.cjs.map → a2a-CCYYdrZ1.cjs.map} +1 -1
  7. package/dist/{agent-builder-DHqHFO5d.cjs → agent-builder-2Ogqa9-3.cjs} +3 -3
  8. package/dist/{agent-builder-DHqHFO5d.cjs.map → agent-builder-2Ogqa9-3.cjs.map} +1 -1
  9. package/dist/{agent-builder-D9rubwk0.js → agent-builder-Dc6cRAxh.js} +3 -3
  10. package/dist/{agent-builder-D9rubwk0.js.map → agent-builder-Dc6cRAxh.js.map} +1 -1
  11. package/dist/{agents-BgaBbcwb.cjs → agents-2HNpgTlJ.cjs} +7 -2
  12. package/dist/agents-2HNpgTlJ.cjs.map +1 -0
  13. package/dist/{agents-BjlUjmb1.js → agents-CEgQ1Sj5.js} +7 -2
  14. package/dist/agents-CEgQ1Sj5.js.map +1 -0
  15. package/dist/{api-schema-manifest-AltoM-cn.cjs → api-schema-manifest-BdpqONHU.cjs} +2 -2
  16. package/dist/{api-schema-manifest-AltoM-cn.cjs.map → api-schema-manifest-BdpqONHU.cjs.map} +1 -1
  17. package/dist/{api-schema-manifest-D1A2zfm3.js → api-schema-manifest-CAXT81dM.js} +2 -2
  18. package/dist/{api-schema-manifest-D1A2zfm3.js.map → api-schema-manifest-CAXT81dM.js.map} +1 -1
  19. package/dist/{catalogue-BW2a1gu4.cjs → catalogue-Cnb2A1bK.cjs} +8 -8
  20. package/dist/{catalogue-BW2a1gu4.cjs.map → catalogue-Cnb2A1bK.cjs.map} +1 -1
  21. package/dist/{catalogue-DPLsw3zE.js → catalogue-CpTFH24l.js} +8 -8
  22. package/dist/{catalogue-DPLsw3zE.js.map → catalogue-CpTFH24l.js.map} +1 -1
  23. package/dist/{conversations-DYqwqCWH.js → conversations-C9yLrQnn.js} +2 -2
  24. package/dist/{conversations-DYqwqCWH.js.map → conversations-C9yLrQnn.js.map} +1 -1
  25. package/dist/{conversations-Bvk5VVVJ.cjs → conversations-Cqyw1vjS.cjs} +2 -2
  26. package/dist/{conversations-Bvk5VVVJ.cjs.map → conversations-Cqyw1vjS.cjs.map} +1 -1
  27. package/dist/{dist-D2zyg15_.cjs → dist-BgMRdBmR.cjs} +759 -265
  28. package/dist/dist-BgMRdBmR.cjs.map +1 -0
  29. package/dist/{dist-CMgUx8hS.js → dist-BoE65ceB.js} +759 -266
  30. package/dist/dist-BoE65ceB.js.map +1 -0
  31. package/dist/{dist-ToffHjwd.cjs → dist-D4zWd2g_.cjs} +1 -1
  32. package/dist/dist-DLdEfrDl.js +1 -0
  33. package/dist/docs/SKILL.md +1 -1
  34. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  35. package/dist/docs/references/docs-server-mcp.md +2 -2
  36. package/dist/docs/references/reference-server-builtin-mcp-tools.md +13 -13
  37. package/dist/{editor-builder-CGM0scw2.js → editor-builder-Dd10fik0.js} +2 -2
  38. package/dist/{editor-builder-CGM0scw2.js.map → editor-builder-Dd10fik0.js.map} +1 -1
  39. package/dist/{editor-builder-SP_ledm3.cjs → editor-builder-apReuKyj.cjs} +2 -2
  40. package/dist/{editor-builder-SP_ledm3.cjs.map → editor-builder-apReuKyj.cjs.map} +1 -1
  41. package/dist/{memory-0jB2EOKx.js → memory-DS2tEXzG.js} +29 -23
  42. package/dist/memory-DS2tEXzG.js.map +1 -0
  43. package/dist/{memory-Dd7TpDfi.cjs → memory-HiP-vUvS.cjs} +28 -22
  44. package/dist/memory-HiP-vUvS.cjs.map +1 -0
  45. package/dist/{plans-BemJO4-7.js → plans-ByaTWRem.js} +2 -2
  46. package/dist/{plans-BemJO4-7.js.map → plans-ByaTWRem.js.map} +1 -1
  47. package/dist/{plans-CffjV2_6.cjs → plans-CE83TVnK.cjs} +2 -2
  48. package/dist/{plans-CffjV2_6.cjs.map → plans-CE83TVnK.cjs.map} +1 -1
  49. package/dist/{probe-image-size-CxVMV0gk.js → probe-image-size-Bu_nsmG7.js} +2 -2
  50. package/dist/{probe-image-size-CxVMV0gk.js.map → probe-image-size-Bu_nsmG7.js.map} +1 -1
  51. package/dist/{probe-image-size--ACsCqf-.cjs → probe-image-size-CIvA48eX.cjs} +2 -2
  52. package/dist/{probe-image-size--ACsCqf-.cjs.map → probe-image-size-CIvA48eX.cjs.map} +1 -1
  53. package/dist/{responses-D0mb5ubj.cjs → responses-3F7qAgFF.cjs} +2 -2
  54. package/dist/{responses-D0mb5ubj.cjs.map → responses-3F7qAgFF.cjs.map} +1 -1
  55. package/dist/{responses-BofWEQYg.js → responses-kWHiEbrl.js} +2 -2
  56. package/dist/{responses-BofWEQYg.js.map → responses-kWHiEbrl.js.map} +1 -1
  57. package/dist/{routes-CH5SQLu2.js → routes-8_3X8t-L.js} +14 -14
  58. package/dist/{routes-CH5SQLu2.js.map → routes-8_3X8t-L.js.map} +1 -1
  59. package/dist/{routes-bWCQflz5.cjs → routes-C76k7FKk.cjs} +14 -14
  60. package/dist/{routes-bWCQflz5.cjs.map → routes-C76k7FKk.cjs.map} +1 -1
  61. package/dist/{scores-CVssMyoQ.js → scores-B6h7rEBJ.js} +2 -2
  62. package/dist/{scores-CVssMyoQ.js.map → scores-B6h7rEBJ.js.map} +1 -1
  63. package/dist/{scores-0MyV08tL.cjs → scores-BuAYv1Gi.cjs} +2 -2
  64. package/dist/{scores-0MyV08tL.cjs.map → scores-BuAYv1Gi.cjs.map} +1 -1
  65. package/dist/server/handlers/a2a.cjs +1 -1
  66. package/dist/server/handlers/a2a.js +1 -1
  67. package/dist/server/handlers/agent-builder.cjs +1 -1
  68. package/dist/server/handlers/agent-builder.js +1 -1
  69. package/dist/server/handlers/agents.cjs +1 -1
  70. package/dist/server/handlers/agents.d.ts.map +1 -1
  71. package/dist/server/handlers/agents.js +1 -1
  72. package/dist/server/handlers/conversations.cjs +1 -1
  73. package/dist/server/handlers/conversations.js +1 -1
  74. package/dist/server/handlers/editor-builder.cjs +1 -1
  75. package/dist/server/handlers/editor-builder.js +1 -1
  76. package/dist/server/handlers/favorites-enrichment.cjs +1 -1
  77. package/dist/server/handlers/favorites-enrichment.js +1 -1
  78. package/dist/server/handlers/gateway-memory-client.cjs +26 -4
  79. package/dist/server/handlers/gateway-memory-client.cjs.map +1 -1
  80. package/dist/server/handlers/gateway-memory-client.d.ts +14 -2
  81. package/dist/server/handlers/gateway-memory-client.d.ts.map +1 -1
  82. package/dist/server/handlers/gateway-memory-client.js +26 -5
  83. package/dist/server/handlers/gateway-memory-client.js.map +1 -1
  84. package/dist/server/handlers/memory.cjs +1 -1
  85. package/dist/server/handlers/memory.d.ts.map +1 -1
  86. package/dist/server/handlers/memory.js +1 -1
  87. package/dist/server/handlers/plans.cjs +1 -1
  88. package/dist/server/handlers/plans.js +1 -1
  89. package/dist/server/handlers/responses.cjs +1 -1
  90. package/dist/server/handlers/responses.js +1 -1
  91. package/dist/server/handlers/scores.cjs +1 -1
  92. package/dist/server/handlers/scores.js +1 -1
  93. package/dist/server/handlers/stored-agent-favorites.cjs +1 -1
  94. package/dist/server/handlers/stored-agent-favorites.js +1 -1
  95. package/dist/server/handlers/stored-agents.cjs +1 -1
  96. package/dist/server/handlers/stored-agents.js +1 -1
  97. package/dist/server/handlers/stored-skill-favorites.cjs +1 -1
  98. package/dist/server/handlers/stored-skill-favorites.js +1 -1
  99. package/dist/server/handlers/stored-skills.cjs +1 -1
  100. package/dist/server/handlers/stored-skills.js +1 -1
  101. package/dist/server/handlers/system.cjs +1 -1
  102. package/dist/server/handlers/system.js +1 -1
  103. package/dist/server/handlers/tools.cjs +1 -1
  104. package/dist/server/handlers/tools.js +1 -1
  105. package/dist/server/handlers/voice.cjs +1 -1
  106. package/dist/server/handlers/voice.js +1 -1
  107. package/dist/server/handlers/workflows.cjs +1 -1
  108. package/dist/server/handlers/workflows.d.ts +2 -0
  109. package/dist/server/handlers/workflows.d.ts.map +1 -1
  110. package/dist/server/handlers/workflows.js +1 -1
  111. package/dist/server/handlers.cjs +11 -11
  112. package/dist/server/handlers.js +11 -11
  113. package/dist/server/server-adapter/index.cjs +2 -2
  114. package/dist/server/server-adapter/index.js +2 -2
  115. package/dist/server/server-adapter/routes/workflows.d.ts +2 -0
  116. package/dist/server/server-adapter/routes/workflows.d.ts.map +1 -1
  117. package/dist/{server-adapter-B3kR1OJs.js → server-adapter-BCeL96pF.js} +2 -2
  118. package/dist/{server-adapter-B3kR1OJs.js.map → server-adapter-BCeL96pF.js.map} +1 -1
  119. package/dist/{server-adapter-SLljXCyr.cjs → server-adapter-BhDR1wnp.cjs} +2 -2
  120. package/dist/{server-adapter-SLljXCyr.cjs.map → server-adapter-BhDR1wnp.cjs.map} +1 -1
  121. package/dist/{tools-oHRh4msa.js → tools-BuFpB7Lk.js} +2 -2
  122. package/dist/{tools-oHRh4msa.js.map → tools-BuFpB7Lk.js.map} +1 -1
  123. package/dist/{tools-CawMeeZg.cjs → tools-C_6yXAww.cjs} +2 -2
  124. package/dist/{tools-CawMeeZg.cjs.map → tools-C_6yXAww.cjs.map} +1 -1
  125. package/dist/{voice-Dk0O5mVD.cjs → voice-ByiFiTmK.cjs} +2 -2
  126. package/dist/{voice-Dk0O5mVD.cjs.map → voice-ByiFiTmK.cjs.map} +1 -1
  127. package/dist/{voice-C6bAqs79.js → voice-DOV0tU_V.js} +2 -2
  128. package/dist/{voice-C6bAqs79.js.map → voice-DOV0tU_V.js.map} +1 -1
  129. package/dist/{workflows-B-QJ0Tnv.js → workflows-9Q28sHTz.js} +5 -3
  130. package/dist/{workflows-B-QJ0Tnv.js.map → workflows-9Q28sHTz.js.map} +1 -1
  131. package/dist/{workflows-CwkEHIKW.cjs → workflows-DhmriYvN.cjs} +5 -3
  132. package/dist/{workflows-CwkEHIKW.cjs.map → workflows-DhmriYvN.cjs.map} +1 -1
  133. package/package.json +5 -5
  134. package/dist/agents-BgaBbcwb.cjs.map +0 -1
  135. package/dist/agents-BjlUjmb1.js.map +0 -1
  136. package/dist/dist-CMgUx8hS.js.map +0 -1
  137. package/dist/dist-D2zyg15_.cjs.map +0 -1
  138. package/dist/dist-HNpJc8bT.js +0 -1
  139. package/dist/memory-0jB2EOKx.js.map +0 -1
  140. package/dist/memory-Dd7TpDfi.cjs.map +0 -1
@@ -26,7 +26,8 @@ import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } fr
26
26
  import { tmpdir } from "os";
27
27
  import { basename, dirname, extname, isAbsolute, join, relative, resolve } from "path";
28
28
  import { createHash } from "crypto";
29
- import { toJSONSchema as toJSONSchema$1 } from "zod/v4/core";
29
+ import { config, toJSONSchema as toJSONSchema$1 } from "zod/v4/core";
30
+ import en from "zod/v4/locales/en.js";
30
31
  import { channel, tracingChannel } from "diagnostics_channel";
31
32
  import { AsyncLocalStorage, AsyncResource } from "async_hooks";
32
33
  import { exec, execFile, spawn } from "child_process";
@@ -8654,7 +8655,7 @@ function splitLines(text) {
8654
8655
  else result.push(result.pop().slice(0, -1));
8655
8656
  return result;
8656
8657
  }
8657
- // ../memory/dist/src-Xhctgeae.js
8658
+ // ../memory/dist/src-BkElV36S.js
8658
8659
  var __defProp$3 = Object.defineProperty;
8659
8660
  var __exportAll = (all, no_symbols) => {
8660
8661
  let target = {};
@@ -11407,8 +11408,8 @@ var UnsupportedModelVersionError$3 = class extends AISDKError$3 {
11407
11408
  }
11408
11409
  };
11409
11410
  var name$21 = "AI_InvalidArgumentError";
11410
- var marker$10 = `vercel.ai.error.${name$21}`;
11411
- var symbol$12 = Symbol.for(marker$10);
11411
+ var marker$20 = `vercel.ai.error.${name$21}`;
11412
+ var symbol$24 = Symbol.for(marker$20);
11412
11413
  var _a$6;
11413
11414
  var InvalidArgumentError$6 = class extends AISDKError$3 {
11414
11415
  constructor({ parameter, value, message }) {
@@ -11421,10 +11422,10 @@ var InvalidArgumentError$6 = class extends AISDKError$3 {
11421
11422
  this.value = value;
11422
11423
  }
11423
11424
  static isInstance(error) {
11424
- return AISDKError$3.hasMarker(error, marker$10);
11425
+ return AISDKError$3.hasMarker(error, marker$20);
11425
11426
  }
11426
11427
  };
11427
- _a$6 = symbol$12;
11428
+ _a$6 = symbol$24;
11428
11429
  var name2$6 = "AI_RetryError";
11429
11430
  var marker2$6 = `vercel.ai.error.${name2$6}`;
11430
11431
  var symbol2$6 = Symbol.for(marker2$6);
@@ -12314,11 +12315,11 @@ function trimStartOfStream() {
12314
12315
  return text2;
12315
12316
  };
12316
12317
  }
12317
- var marker$1$16 = "vercel.ai.error";
12318
- var symbol$1$17 = Symbol.for(marker$1$16);
12318
+ var marker$1$11 = "vercel.ai.error";
12319
+ var symbol$1$21 = Symbol.for(marker$1$11);
12319
12320
  var _a$1$2;
12320
12321
  var _b$1$4;
12321
- var AISDKError$2 = class _AISDKError extends (_b$1$4 = Error, _a$1$2 = symbol$1$17, _b$1$4) {
12322
+ var AISDKError$2 = class _AISDKError extends (_b$1$4 = Error, _a$1$2 = symbol$1$21, _b$1$4) {
12322
12323
  /**
12323
12324
  * Creates an AI SDK Error.
12324
12325
  *
@@ -12339,22 +12340,22 @@ var AISDKError$2 = class _AISDKError extends (_b$1$4 = Error, _a$1$2 = symbol$1$
12339
12340
  * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
12340
12341
  */
12341
12342
  static isInstance(error) {
12342
- return _AISDKError.hasMarker(error, marker$1$16);
12343
+ return _AISDKError.hasMarker(error, marker$1$11);
12343
12344
  }
12344
12345
  static hasMarker(error, marker15) {
12345
12346
  const markerSymbol = Symbol.for(marker15);
12346
12347
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
12347
12348
  }
12348
12349
  };
12349
- var name$1$15 = "AI_APICallError";
12350
- var marker2$5 = `vercel.ai.error.${name$1$15}`;
12350
+ var name$1$19 = "AI_APICallError";
12351
+ var marker2$5 = `vercel.ai.error.${name$1$19}`;
12351
12352
  var symbol2$5 = Symbol.for(marker2$5);
12352
12353
  var _a2$5;
12353
12354
  var _b2$3;
12354
12355
  var APICallError$2 = class extends (_b2$3 = AISDKError$2, _a2$5 = symbol2$5, _b2$3) {
12355
12356
  constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
12356
12357
  super({
12357
- name: name$1$15,
12358
+ name: name$1$19,
12358
12359
  message,
12359
12360
  cause
12360
12361
  });
@@ -12693,15 +12694,15 @@ function createAbortError$2() {
12693
12694
  function extractResponseHeaders$2(response) {
12694
12695
  return Object.fromEntries([...response.headers]);
12695
12696
  }
12696
- var name$15 = "AI_DownloadError";
12697
- var marker$20 = `vercel.ai.error.${name$15}`;
12698
- var symbol$24 = Symbol.for(marker$20);
12697
+ var name$20 = "AI_DownloadError";
12698
+ var marker$17 = `vercel.ai.error.${name$20}`;
12699
+ var symbol$22 = Symbol.for(marker$17);
12699
12700
  var _a$5;
12700
12701
  var _b$5;
12701
- var DownloadError$2 = class extends (_b$5 = AISDKError$2, _a$5 = symbol$24, _b$5) {
12702
+ var DownloadError$2 = class extends (_b$5 = AISDKError$2, _a$5 = symbol$22, _b$5) {
12702
12703
  constructor({ url, statusCode, statusText, cause, message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}` }) {
12703
12704
  super({
12704
- name: name$15,
12705
+ name: name$20,
12705
12706
  message,
12706
12707
  cause
12707
12708
  });
@@ -12711,7 +12712,7 @@ var DownloadError$2 = class extends (_b$5 = AISDKError$2, _a$5 = symbol$24, _b$5
12711
12712
  this.statusText = statusText;
12712
12713
  }
12713
12714
  static isInstance(error) {
12714
- return AISDKError$2.hasMarker(error, marker$20);
12715
+ return AISDKError$2.hasMarker(error, marker$17);
12715
12716
  }
12716
12717
  };
12717
12718
  var EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL$2 = /* @__PURE__ */ Symbol.for("vercel.ai.embeddingModel.maxInputBytesPerCall");
@@ -12721,6 +12722,247 @@ async function cancelResponseBody$2(response) {
12721
12722
  await ((_a2 = response.body) == null ? void 0 : _a2.cancel());
12722
12723
  } catch (e) {}
12723
12724
  }
12725
+ function isBrowserRuntime$2(globalThisAny = globalThis) {
12726
+ return globalThisAny.window != null;
12727
+ }
12728
+ function isSameOrigin$2(url, baseUrl) {
12729
+ try {
12730
+ return new URL(url).origin === new URL(baseUrl).origin;
12731
+ } catch (e) {
12732
+ return false;
12733
+ }
12734
+ }
12735
+ function validateDownloadUrl$2(url) {
12736
+ let parsed;
12737
+ try {
12738
+ parsed = new URL(url);
12739
+ } catch (e) {
12740
+ throw new DownloadError$2({
12741
+ url,
12742
+ message: `Invalid URL: ${url}`
12743
+ });
12744
+ }
12745
+ if (parsed.protocol === "data:") return;
12746
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new DownloadError$2({
12747
+ url,
12748
+ message: `URL scheme must be http, https, or data, got ${parsed.protocol}`
12749
+ });
12750
+ const hostname = parsed.hostname.toLowerCase().replace(/\.+$/, "");
12751
+ if (!hostname) throw new DownloadError$2({
12752
+ url,
12753
+ message: `URL must have a hostname`
12754
+ });
12755
+ if (hostname === "localhost" || hostname.endsWith(".local") || hostname.endsWith(".localhost") || hostname.endsWith(".internal")) throw new DownloadError$2({
12756
+ url,
12757
+ message: `URL with hostname ${hostname} is not allowed`
12758
+ });
12759
+ if (hostname.startsWith("[") && hostname.endsWith("]")) {
12760
+ if (isPrivateIPv6$2(hostname.slice(1, -1))) throw new DownloadError$2({
12761
+ url,
12762
+ message: `URL with IPv6 address ${hostname} is not allowed`
12763
+ });
12764
+ return;
12765
+ }
12766
+ if (isIPv4$2(hostname)) {
12767
+ if (isPrivateIPv4$2(hostname)) throw new DownloadError$2({
12768
+ url,
12769
+ message: `URL with IP address ${hostname} is not allowed`
12770
+ });
12771
+ }
12772
+ }
12773
+ function validateDownloadAddress$1({ address, family, hostname }) {
12774
+ if (family === 4 ? !isIPv4$2(address) || isPrivateIPv4$2(address) : family === 6 ? isPrivateIPv6$2(address) : true) throw new DownloadError$2({
12775
+ url: hostname,
12776
+ message: `Hostname ${hostname} resolved to disallowed IP address ${address}`
12777
+ });
12778
+ }
12779
+ function isIPv4$2(hostname) {
12780
+ const parts = hostname.split(".");
12781
+ if (parts.length !== 4) return false;
12782
+ return parts.every((part) => {
12783
+ const num = Number(part);
12784
+ return Number.isInteger(num) && num >= 0 && num <= 255 && String(num) === part;
12785
+ });
12786
+ }
12787
+ function isPrivateIPv4$2(ip) {
12788
+ const [a, b, c] = ip.split(".").map(Number);
12789
+ if (a === 0) return true;
12790
+ if (a === 10) return true;
12791
+ if (a === 100 && b >= 64 && b <= 127) return true;
12792
+ if (a === 127) return true;
12793
+ if (a === 169 && b === 254) return true;
12794
+ if (a === 172 && b >= 16 && b <= 31) return true;
12795
+ if (a === 192 && b === 0 && c === 0) return true;
12796
+ if (a === 192 && b === 168) return true;
12797
+ if (a === 198 && (b === 18 || b === 19)) return true;
12798
+ if (a >= 240) return true;
12799
+ return false;
12800
+ }
12801
+ function parseIPv6$2(ip) {
12802
+ let address = ip.toLowerCase();
12803
+ const zoneIndex = address.indexOf("%");
12804
+ if (zoneIndex !== -1) address = address.slice(0, zoneIndex);
12805
+ const halves = address.split("::");
12806
+ if (halves.length > 2) return null;
12807
+ const toGroups = (segment) => {
12808
+ if (segment === "") return [];
12809
+ const groups = [];
12810
+ const parts = segment.split(":");
12811
+ for (let i = 0; i < parts.length; i++) {
12812
+ const part = parts[i];
12813
+ if (part.includes(".")) {
12814
+ if (i !== parts.length - 1 || !isIPv4$2(part)) return null;
12815
+ const [a, b, c, d] = part.split(".").map(Number);
12816
+ groups.push(a << 8 | b, c << 8 | d);
12817
+ continue;
12818
+ }
12819
+ if (!/^[0-9a-f]{1,4}$/.test(part)) return null;
12820
+ groups.push(parseInt(part, 16));
12821
+ }
12822
+ return groups;
12823
+ };
12824
+ const head = toGroups(halves[0]);
12825
+ if (head === null) return null;
12826
+ if (halves.length === 2) {
12827
+ const tail = toGroups(halves[1]);
12828
+ if (tail === null) return null;
12829
+ const fill = 8 - head.length - tail.length;
12830
+ if (fill < 0) return null;
12831
+ return [
12832
+ ...head,
12833
+ ...new Array(fill).fill(0),
12834
+ ...tail
12835
+ ];
12836
+ }
12837
+ return head.length === 8 ? head : null;
12838
+ }
12839
+ function isPrivateIPv6$2(ip) {
12840
+ const groups = parseIPv6$2(ip);
12841
+ if (groups === null) return true;
12842
+ const topZero = (count) => groups.slice(0, count).every((group) => group === 0);
12843
+ if (topZero(7) && (groups[7] === 0 || groups[7] === 1)) return true;
12844
+ if ((groups[0] & 65024) === 64512) return true;
12845
+ if ((groups[0] & 65472) === 65152) return true;
12846
+ if ((groups[0] & 65472) === 65216) return true;
12847
+ if ((groups[0] & 65280) === 65280) return true;
12848
+ if (topZero(6) || topZero(5) && groups[5] === 65535 || topZero(4) && groups[4] === 65535 && groups[5] === 0 || groups[0] === 100 && groups[1] === 65435 && groups[2] === 0 && groups[3] === 0 && groups[4] === 0 && groups[5] === 0 || groups[0] === 100 && groups[1] === 65435 && groups[2] === 1) return isPrivateIPv4$2(`${groups[6] >> 8 & 255}.${groups[6] & 255}.${groups[7] >> 8 & 255}.${groups[7] & 255}`);
12849
+ return false;
12850
+ }
12851
+ function createSafeLookup$1(lookup) {
12852
+ return ((hostname, options, callback) => {
12853
+ lookup(hostname, {
12854
+ ...options,
12855
+ all: true
12856
+ }, (error, addresses) => {
12857
+ if (error) {
12858
+ callback(error);
12859
+ return;
12860
+ }
12861
+ try {
12862
+ const [firstAddress] = addresses;
12863
+ if (firstAddress == null) throw new Error(`Hostname ${hostname} did not resolve to an address`);
12864
+ for (const { address, family } of addresses) validateDownloadAddress$1({
12865
+ address,
12866
+ family,
12867
+ hostname
12868
+ });
12869
+ if (options.all === true) callback(null, addresses);
12870
+ else callback(null, firstAddress.address, firstAddress.family);
12871
+ } catch (error2) {
12872
+ callback(error2 instanceof Error ? error2 : new Error(String(error2)));
12873
+ }
12874
+ });
12875
+ });
12876
+ }
12877
+ var safeNodeFetchPromise$1;
12878
+ function isNodeRuntime$2() {
12879
+ var _a2, _b2, _c;
12880
+ const runtimeProcess = globalThis.process;
12881
+ return ((_a2 = runtimeProcess == null ? void 0 : runtimeProcess.release) == null ? void 0 : _a2.name) === "node" && ((_b2 = runtimeProcess.versions) == null ? void 0 : _b2.bun) == null && ((_c = runtimeProcess.versions) == null ? void 0 : _c.deno) == null && runtimeProcess.title !== "workerd" && globalThis.EdgeRuntime == null;
12882
+ }
12883
+ async function getDefaultDownloadFetch$1() {
12884
+ if (!isNodeRuntime$2()) return globalThis.fetch;
12885
+ return safeNodeFetchPromise$1 != null ? safeNodeFetchPromise$1 : safeNodeFetchPromise$1 = createSafeNodeFetch$1();
12886
+ }
12887
+ async function createSafeNodeFetch$1() {
12888
+ const [module, { lookup }] = await Promise.all([loadNodeModule$1("node:module"), loadNodeModule$1("node:dns")]);
12889
+ const { Agent, fetch } = module.createRequire(getCurrentModulePath$1())("undici");
12890
+ const dispatcher = new Agent({ connect: { lookup: createSafeLookup$1(lookup) } });
12891
+ return ((input, init) => fetch(input, {
12892
+ ...init,
12893
+ dispatcher
12894
+ }));
12895
+ }
12896
+ async function loadNodeModule$1(id) {
12897
+ var _a2;
12898
+ const processWithBuiltins = globalThis.process;
12899
+ const builtinModule = (_a2 = processWithBuiltins == null ? void 0 : processWithBuiltins.getBuiltinModule) == null ? void 0 : _a2.call(processWithBuiltins, id);
12900
+ return builtinModule == null ? await importNodeModule(id) : builtinModule;
12901
+ }
12902
+ function importNodeModule(id) {
12903
+ return import(id);
12904
+ }
12905
+ function getCurrentModulePath$1() {
12906
+ const originalPrepareStackTrace = Error.prepareStackTrace;
12907
+ try {
12908
+ Error.prepareStackTrace = (_error, callSites) => callSites;
12909
+ const error = /* @__PURE__ */ new Error("Capture current module path");
12910
+ Error.captureStackTrace(error, getCurrentModulePath$1);
12911
+ const [caller] = error.stack;
12912
+ const fileName = caller == null ? void 0 : caller.getFileName();
12913
+ if (fileName == null) throw new Error("Unable to determine the current module path");
12914
+ return fileName;
12915
+ } finally {
12916
+ Error.prepareStackTrace = originalPrepareStackTrace;
12917
+ }
12918
+ }
12919
+ var MAX_DOWNLOAD_REDIRECTS$2 = 10;
12920
+ async function getValidatedFetch$1(customFetch) {
12921
+ return customFetch == null || customFetch === globalThis.fetch ? await getDefaultDownloadFetch$1() : customFetch;
12922
+ }
12923
+ async function fetchWithValidatedRedirects$2({ url, headers, abortSignal, maxRedirects = MAX_DOWNLOAD_REDIRECTS$2, fetch: customFetch, trustedOrigin }) {
12924
+ var _a2;
12925
+ let currentHeaders = headers === void 0 ? void 0 : new Headers(headers);
12926
+ const perHopInit = (redirect) => ({
12927
+ signal: abortSignal,
12928
+ redirect,
12929
+ ...currentHeaders === void 0 ? {} : { headers: new Headers(currentHeaders) }
12930
+ });
12931
+ let currentUrl = url;
12932
+ for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
12933
+ const isTrustedHop = trustedOrigin !== void 0 && isSameOrigin$2(currentUrl, trustedOrigin);
12934
+ if (!isTrustedHop) validateDownloadUrl$2(currentUrl);
12935
+ const fetch = isTrustedHop && customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getValidatedFetch$1(customFetch);
12936
+ const response = await fetch(currentUrl, perHopInit("manual"));
12937
+ if (response.type === "opaqueredirect") {
12938
+ if (!isBrowserRuntime$2()) throw new DownloadError$2({
12939
+ url,
12940
+ message: `Redirect from ${currentUrl} could not be validated and was blocked`
12941
+ });
12942
+ return await fetch(currentUrl, perHopInit("follow"));
12943
+ }
12944
+ const location = (_a2 = response.headers) == null ? void 0 : _a2.get("location");
12945
+ if (response.status >= 300 && response.status < 400 && location) {
12946
+ cancelResponseBody$2(response);
12947
+ const nextUrl = new URL(location, currentUrl).toString();
12948
+ if (new URL(currentUrl).protocol === "https:" && new URL(nextUrl).protocol === "http:") throw new DownloadError$2({
12949
+ url,
12950
+ message: "Redirect from HTTPS to HTTP was blocked"
12951
+ });
12952
+ if (currentHeaders !== void 0 && !isSameOrigin$2(nextUrl, currentUrl)) {
12953
+ const userAgent = currentHeaders.get("user-agent");
12954
+ currentHeaders = new Headers(userAgent == null ? void 0 : { "user-agent": userAgent });
12955
+ }
12956
+ currentUrl = nextUrl;
12957
+ continue;
12958
+ }
12959
+ return response;
12960
+ }
12961
+ throw new DownloadError$2({
12962
+ url,
12963
+ message: `Too many redirects (max ${maxRedirects})`
12964
+ });
12965
+ }
12724
12966
  var DEFAULT_MAX_DOWNLOAD_SIZE$2 = 2147483648;
12725
12967
  async function readResponseWithSizeLimit$2({ response, url, maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE$2 }) {
12726
12968
  const contentLength = response.headers.get("content-length");
@@ -12874,13 +13116,21 @@ function withUserAgentSuffix$2(headers, ...userAgentSuffixParts) {
12874
13116
  normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
12875
13117
  return Object.fromEntries(normalizedHeaders.entries());
12876
13118
  }
12877
- var VERSION$8 = "3.0.44";
13119
+ var VERSION$8 = "3.0.46";
12878
13120
  var getOriginalFetch$3 = () => globalThis.fetch;
12879
- var getFromApi$2 = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch = getOriginalFetch$3() }) => {
13121
+ var getFromApi$2 = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, validateUrl, credentialedOrigin, trustedOrigin }) => {
12880
13122
  try {
12881
- const response = await fetch(url, {
13123
+ const requestFetch = fetch != null ? fetch : getOriginalFetch$3();
13124
+ const requestHeaders = withUserAgentSuffix$2(credentialedOrigin !== void 0 && !isSameOrigin$2(url, credentialedOrigin) ? {} : headers, `ai-sdk/provider-utils/${VERSION$8}`, getRuntimeEnvironmentUserAgent$2());
13125
+ const response = validateUrl ? await fetchWithValidatedRedirects$2({
13126
+ url,
13127
+ headers: requestHeaders,
13128
+ abortSignal,
13129
+ fetch,
13130
+ trustedOrigin
13131
+ }) : await requestFetch(url, {
12882
13132
  method: "GET",
12883
- headers: withUserAgentSuffix$2(headers, `ai-sdk/provider-utils/${VERSION$8}`, getRuntimeEnvironmentUserAgent$2()),
13133
+ headers: requestHeaders,
12884
13134
  signal: abortSignal
12885
13135
  });
12886
13136
  const responseHeaders = extractResponseHeaders$2(response);
@@ -14322,10 +14572,10 @@ async function getVercelOidcToken$2() {
14322
14572
  if (process.env.VERCEL_OIDC_TOKEN) return process.env.VERCEL_OIDC_TOKEN ?? "";
14323
14573
  throw new Error("@vercel/oidc is not available in the vendored @internal AI packages. Provide an API key instead.");
14324
14574
  }
14325
- var symbol$15 = Symbol.for("vercel.ai.gateway.error");
14575
+ var symbol$21 = Symbol.for("vercel.ai.gateway.error");
14326
14576
  var _a$4;
14327
14577
  var _b$3;
14328
- var GatewayError$2 = class _GatewayError extends (_b$3 = Error, _a$4 = symbol$15, _b$3) {
14578
+ var GatewayError$2 = class _GatewayError extends (_b$3 = Error, _a$4 = symbol$21, _b$3) {
14329
14579
  constructor({ message, statusCode = 500, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500) }) {
14330
14580
  super(message);
14331
14581
  this[_a$4] = true;
@@ -14342,11 +14592,11 @@ var GatewayError$2 = class _GatewayError extends (_b$3 = Error, _a$4 = symbol$15
14342
14592
  return _GatewayError.hasMarker(error);
14343
14593
  }
14344
14594
  static hasMarker(error) {
14345
- return typeof error === "object" && error !== null && symbol$15 in error && error[symbol$15] === true;
14595
+ return typeof error === "object" && error !== null && symbol$21 in error && error[symbol$21] === true;
14346
14596
  }
14347
14597
  };
14348
- var name$10 = "GatewayAuthenticationError";
14349
- var marker2$4 = `vercel.ai.gateway.error.${name$10}`;
14598
+ var name$19 = "GatewayAuthenticationError";
14599
+ var marker2$4 = `vercel.ai.gateway.error.${name$19}`;
14350
14600
  var symbol2$4 = Symbol.for(marker2$4);
14351
14601
  var _a2$4;
14352
14602
  var _b2$2;
@@ -14358,7 +14608,7 @@ var GatewayAuthenticationError$2 = class _GatewayAuthenticationError extends (_b
14358
14608
  cause
14359
14609
  });
14360
14610
  this[_a2$4] = true;
14361
- this.name = name$10;
14611
+ this.name = name$19;
14362
14612
  this.type = "authentication_error";
14363
14613
  }
14364
14614
  static isInstance(error) {
@@ -17234,11 +17484,11 @@ var object$2 = ({ schema: inputSchema }) => {
17234
17484
  }
17235
17485
  };
17236
17486
  };
17237
- var marker$1$14 = "vercel.ai.error";
17238
- var symbol$1$15 = Symbol.for(marker$1$14);
17487
+ var marker$1$10 = "vercel.ai.error";
17488
+ var symbol$1$13 = Symbol.for(marker$1$10);
17239
17489
  var _a$1$1;
17240
17490
  var _b$1$1;
17241
- var AISDKError$1 = class _AISDKError extends (_b$1$1 = Error, _a$1$1 = symbol$1$15, _b$1$1) {
17491
+ var AISDKError$1 = class _AISDKError extends (_b$1$1 = Error, _a$1$1 = symbol$1$13, _b$1$1) {
17242
17492
  /**
17243
17493
  * Creates an AI SDK Error.
17244
17494
  *
@@ -17259,22 +17509,22 @@ var AISDKError$1 = class _AISDKError extends (_b$1$1 = Error, _a$1$1 = symbol$1$
17259
17509
  * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
17260
17510
  */
17261
17511
  static isInstance(error) {
17262
- return _AISDKError.hasMarker(error, marker$1$14);
17512
+ return _AISDKError.hasMarker(error, marker$1$10);
17263
17513
  }
17264
17514
  static hasMarker(error, marker15) {
17265
17515
  const markerSymbol = Symbol.for(marker15);
17266
17516
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
17267
17517
  }
17268
17518
  };
17269
- var name$1$14 = "AI_APICallError";
17270
- var marker2$2 = `vercel.ai.error.${name$1$14}`;
17519
+ var name$1$10 = "AI_APICallError";
17520
+ var marker2$2 = `vercel.ai.error.${name$1$10}`;
17271
17521
  var symbol2$2 = Symbol.for(marker2$2);
17272
17522
  var _a2$2;
17273
17523
  var _b2$1;
17274
17524
  var APICallError$1 = class extends (_b2$1 = AISDKError$1, _a2$2 = symbol2$2, _b2$1) {
17275
17525
  constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
17276
17526
  super({
17277
- name: name$1$14,
17527
+ name: name$1$10,
17278
17528
  message,
17279
17529
  cause
17280
17530
  });
@@ -17657,15 +17907,15 @@ async function cancelResponseBody$1(response) {
17657
17907
  await ((_a2 = response.body) == null ? void 0 : _a2.cancel());
17658
17908
  } catch (e) {}
17659
17909
  }
17660
- var name$19 = "AI_DownloadError";
17661
- var marker$15 = `vercel.ai.error.${name$19}`;
17662
- var symbol$21 = Symbol.for(marker$15);
17910
+ var name$14 = "AI_DownloadError";
17911
+ var marker$13 = `vercel.ai.error.${name$14}`;
17912
+ var symbol$17 = Symbol.for(marker$13);
17663
17913
  var _a$2;
17664
17914
  var _b$2;
17665
- var DownloadError$1 = class extends (_b$2 = AISDKError$1, _a$2 = symbol$21, _b$2) {
17915
+ var DownloadError$1 = class extends (_b$2 = AISDKError$1, _a$2 = symbol$17, _b$2) {
17666
17916
  constructor({ url, statusCode, statusText, cause, message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}` }) {
17667
17917
  super({
17668
- name: name$19,
17918
+ name: name$14,
17669
17919
  message,
17670
17920
  cause
17671
17921
  });
@@ -17675,7 +17925,7 @@ var DownloadError$1 = class extends (_b$2 = AISDKError$1, _a$2 = symbol$21, _b$2
17675
17925
  this.statusText = statusText;
17676
17926
  }
17677
17927
  static isInstance(error) {
17678
- return AISDKError$1.hasMarker(error, marker$15);
17928
+ return AISDKError$1.hasMarker(error, marker$13);
17679
17929
  }
17680
17930
  };
17681
17931
  function isBrowserRuntime$1(globalThisAny = globalThis) {
@@ -17726,7 +17976,7 @@ function validateDownloadUrl$1(url) {
17726
17976
  });
17727
17977
  }
17728
17978
  }
17729
- function validateDownloadAddress$1({ address, family, hostname }) {
17979
+ function validateDownloadAddress({ address, family, hostname }) {
17730
17980
  if (family === 4 ? !isIPv4$1(address) || isPrivateIPv4$1(address) : family === 6 ? isPrivateIPv6$1(address) : true) throw new DownloadError$1({
17731
17981
  url: hostname,
17732
17982
  message: `Hostname ${hostname} resolved to disallowed IP address ${address}`
@@ -17804,7 +18054,7 @@ function isPrivateIPv6$1(ip) {
17804
18054
  if (topZero(6) || topZero(5) && groups[5] === 65535 || topZero(4) && groups[4] === 65535 && groups[5] === 0 || groups[0] === 100 && groups[1] === 65435 && groups[2] === 0 && groups[3] === 0 && groups[4] === 0 && groups[5] === 0 || groups[0] === 100 && groups[1] === 65435 && groups[2] === 1) return isPrivateIPv4$1(`${groups[6] >> 8 & 255}.${groups[6] & 255}.${groups[7] >> 8 & 255}.${groups[7] & 255}`);
17805
18055
  return false;
17806
18056
  }
17807
- function createSafeLookup$1(lookup) {
18057
+ function createSafeLookup(lookup) {
17808
18058
  return ((hostname, options, callback) => {
17809
18059
  lookup(hostname, {
17810
18060
  ...options,
@@ -17817,7 +18067,7 @@ function createSafeLookup$1(lookup) {
17817
18067
  try {
17818
18068
  const [firstAddress] = addresses;
17819
18069
  if (firstAddress == null) throw new Error(`Hostname ${hostname} did not resolve to an address`);
17820
- for (const { address, family } of addresses) validateDownloadAddress$1({
18070
+ for (const { address, family } of addresses) validateDownloadAddress({
17821
18071
  address,
17822
18072
  family,
17823
18073
  hostname
@@ -17830,20 +18080,20 @@ function createSafeLookup$1(lookup) {
17830
18080
  });
17831
18081
  });
17832
18082
  }
17833
- var safeNodeFetchPromise$1;
17834
- function isNodeRuntime$2() {
18083
+ var safeNodeFetchPromise;
18084
+ function isNodeRuntime$1() {
17835
18085
  var _a2, _b2, _c;
17836
18086
  const runtimeProcess = globalThis.process;
17837
18087
  return ((_a2 = runtimeProcess == null ? void 0 : runtimeProcess.release) == null ? void 0 : _a2.name) === "node" && ((_b2 = runtimeProcess.versions) == null ? void 0 : _b2.bun) == null && ((_c = runtimeProcess.versions) == null ? void 0 : _c.deno) == null && runtimeProcess.title !== "workerd" && globalThis.EdgeRuntime == null;
17838
18088
  }
17839
- async function getDefaultDownloadFetch$1() {
17840
- if (!isNodeRuntime$2()) return globalThis.fetch;
17841
- return safeNodeFetchPromise$1 != null ? safeNodeFetchPromise$1 : safeNodeFetchPromise$1 = createSafeNodeFetch$1();
18089
+ async function getDefaultDownloadFetch() {
18090
+ if (!isNodeRuntime$1()) return globalThis.fetch;
18091
+ return safeNodeFetchPromise != null ? safeNodeFetchPromise : safeNodeFetchPromise = createSafeNodeFetch();
17842
18092
  }
17843
- async function createSafeNodeFetch$1() {
18093
+ async function createSafeNodeFetch() {
17844
18094
  const [module, { lookup }] = await Promise.all([loadNodeModule("node:module"), loadNodeModule("node:dns")]);
17845
- const { Agent, fetch } = module.createRequire(getCurrentModulePath$1())("undici");
17846
- const dispatcher = new Agent({ connect: { lookup: createSafeLookup$1(lookup) } });
18095
+ const { Agent, fetch } = module.createRequire(getCurrentModulePath())("undici");
18096
+ const dispatcher = new Agent({ connect: { lookup: createSafeLookup(lookup) } });
17847
18097
  return ((input, init) => fetch(input, {
17848
18098
  ...init,
17849
18099
  dispatcher
@@ -17856,12 +18106,12 @@ async function loadNodeModule(id) {
17856
18106
  if (builtinModule == null) throw new Error(`Node.js built-in module ${id} is unavailable`);
17857
18107
  return builtinModule;
17858
18108
  }
17859
- function getCurrentModulePath$1() {
18109
+ function getCurrentModulePath() {
17860
18110
  const originalPrepareStackTrace = Error.prepareStackTrace;
17861
18111
  try {
17862
18112
  Error.prepareStackTrace = (_error, callSites) => callSites;
17863
18113
  const error = /* @__PURE__ */ new Error("Capture current module path");
17864
- Error.captureStackTrace(error, getCurrentModulePath$1);
18114
+ Error.captureStackTrace(error, getCurrentModulePath);
17865
18115
  const [caller] = error.stack;
17866
18116
  const fileName = caller == null ? void 0 : caller.getFileName();
17867
18117
  if (fileName == null) throw new Error("Unable to determine the current module path");
@@ -17905,8 +18155,8 @@ var REDIRECT_STATUS_CODES$1 = /* @__PURE__ */ new Set([
17905
18155
  307,
17906
18156
  308
17907
18157
  ]);
17908
- async function getValidatedFetch$1(customFetch) {
17909
- return customFetch == null || customFetch === globalThis.fetch ? await getDefaultDownloadFetch$1() : customFetch;
18158
+ async function getValidatedFetch(customFetch) {
18159
+ return customFetch == null || customFetch === globalThis.fetch ? await getDefaultDownloadFetch() : customFetch;
17910
18160
  }
17911
18161
  async function fetchWithValidatedRedirects$1({ url, headers, abortSignal, maxRedirects = MAX_DOWNLOAD_REDIRECTS$1, fetch: customFetch, trustedOrigin }) {
17912
18162
  var _a2;
@@ -17923,7 +18173,7 @@ async function fetchWithValidatedRedirects$1({ url, headers, abortSignal, maxRed
17923
18173
  for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
17924
18174
  const isTrustedHop = trustedOrigin !== void 0 && isSameOrigin$1(currentUrl, trustedOrigin);
17925
18175
  if (!isTrustedHop) validateDownloadUrl$1(currentUrl);
17926
- const fetch = isTrustedHop && customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getValidatedFetch$1(customFetch);
18176
+ const fetch = isTrustedHop && customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getValidatedFetch(customFetch);
17927
18177
  const response = await fetch(currentUrl, perHopInit("manual"));
17928
18178
  if (response.type === "opaqueredirect") {
17929
18179
  if (!isBrowserRuntime$1()) throw new DownloadError$1({
@@ -17936,6 +18186,10 @@ async function fetchWithValidatedRedirects$1({ url, headers, abortSignal, maxRed
17936
18186
  if (REDIRECT_STATUS_CODES$1.has(response.status) && location) {
17937
18187
  cancelResponseBody$1(response);
17938
18188
  const nextUrl = new URL(location, currentUrl).toString();
18189
+ if (new URL(currentUrl).protocol === "https:" && new URL(nextUrl).protocol === "http:") throw new DownloadError$1({
18190
+ url,
18191
+ message: "Redirect from HTTPS to HTTP was blocked"
18192
+ });
17939
18193
  if (currentHeaders !== void 0 && !isSameOrigin$1(nextUrl, currentUrl)) {
17940
18194
  const userAgent = currentHeaders.get("user-agent");
17941
18195
  currentHeaders = new Headers(userAgent == null ? void 0 : { "user-agent": userAgent });
@@ -18105,7 +18359,7 @@ function withUserAgentSuffix$1(headers, ...userAgentSuffixParts) {
18105
18359
  normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
18106
18360
  return Object.fromEntries(normalizedHeaders.entries());
18107
18361
  }
18108
- var VERSION$5 = "4.0.64";
18362
+ var VERSION$5 = "4.0.66";
18109
18363
  var getOriginalFetch$1 = () => globalThis.fetch;
18110
18364
  var getFromApi$1 = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, validateUrl, credentialedOrigin, trustedOrigin }) => {
18111
18365
  try {
@@ -19588,10 +19842,10 @@ async function getVercelOidcToken$1() {
19588
19842
  if (process.env.VERCEL_OIDC_TOKEN) return process.env.VERCEL_OIDC_TOKEN ?? "";
19589
19843
  throw new Error("@vercel/oidc is not available in the vendored @internal AI packages. Provide an API key instead.");
19590
19844
  }
19591
- var symbol$20 = Symbol.for("vercel.ai.gateway.error");
19845
+ var symbol$14 = Symbol.for("vercel.ai.gateway.error");
19592
19846
  var _a$1$3;
19593
19847
  var _b;
19594
- var GatewayError$1 = class _GatewayError extends (_b = Error, _a$1$3 = symbol$20, _b) {
19848
+ var GatewayError$1 = class _GatewayError extends (_b = Error, _a$1$3 = symbol$14, _b) {
19595
19849
  constructor({ message, statusCode = 500, cause, generationId, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500) }) {
19596
19850
  super(generationId ? `${message} [${generationId}]` : message);
19597
19851
  this[_a$1$3] = true;
@@ -19609,11 +19863,11 @@ var GatewayError$1 = class _GatewayError extends (_b = Error, _a$1$3 = symbol$20
19609
19863
  return _GatewayError.hasMarker(error);
19610
19864
  }
19611
19865
  static hasMarker(error) {
19612
- return typeof error === "object" && error !== null && symbol$20 in error && error[symbol$20] === true;
19866
+ return typeof error === "object" && error !== null && symbol$14 in error && error[symbol$14] === true;
19613
19867
  }
19614
19868
  };
19615
- var name$18 = "GatewayAuthenticationError";
19616
- var marker2$1 = `vercel.ai.gateway.error.${name$18}`;
19869
+ var name$13 = "GatewayAuthenticationError";
19870
+ var marker2$1 = `vercel.ai.gateway.error.${name$13}`;
19617
19871
  var symbol2$1 = Symbol.for(marker2$1);
19618
19872
  var _a2$1;
19619
19873
  var _b2;
@@ -19626,7 +19880,7 @@ var GatewayAuthenticationError$1 = class _GatewayAuthenticationError extends (_b
19626
19880
  generationId
19627
19881
  });
19628
19882
  this[_a2$1] = true;
19629
- this.name = name$18;
19883
+ this.name = name$13;
19630
19884
  this.type = "authentication_error";
19631
19885
  }
19632
19886
  static isInstance(error) {
@@ -22554,14 +22808,14 @@ var __export$3 = (target, all) => {
22554
22808
  enumerable: true
22555
22809
  });
22556
22810
  };
22557
- var name$12 = "AI_InvalidArgumentError";
22558
- var marker$12 = `vercel.ai.error.${name$12}`;
22559
- var symbol$19 = Symbol.for(marker$12);
22811
+ var name$10 = "AI_InvalidArgumentError";
22812
+ var marker$10 = `vercel.ai.error.${name$10}`;
22813
+ var symbol$13 = Symbol.for(marker$10);
22560
22814
  var _a;
22561
22815
  var InvalidArgumentError$2 = class extends AISDKError$1 {
22562
22816
  constructor({ parameter, value, message }) {
22563
22817
  super({
22564
- name: name$12,
22818
+ name: name$10,
22565
22819
  message: `Invalid argument for parameter ${parameter}: ${message}`
22566
22820
  });
22567
22821
  this[_a] = true;
@@ -22569,10 +22823,10 @@ var InvalidArgumentError$2 = class extends AISDKError$1 {
22569
22823
  this.value = value;
22570
22824
  }
22571
22825
  static isInstance(error) {
22572
- return AISDKError$1.hasMarker(error, marker$12);
22826
+ return AISDKError$1.hasMarker(error, marker$10);
22573
22827
  }
22574
22828
  };
22575
- _a = symbol$19;
22829
+ _a = symbol$13;
22576
22830
  var name9 = "AI_NoObjectGeneratedError";
22577
22831
  var marker9 = `vercel.ai.error.${name9}`;
22578
22832
  var symbol9 = Symbol.for(marker9);
@@ -23908,8 +24162,8 @@ createIdGenerator$1({
23908
24162
  * Symbol used for identifying AI SDK Error instances.
23909
24163
  * Enables checking if an error is an instance of AISDKError across package versions.
23910
24164
  */
23911
- const marker$16 = "vercel.ai.error";
23912
- const symbol$16 = Symbol.for(marker$16);
24165
+ const marker$18 = "vercel.ai.error";
24166
+ const symbol$18 = Symbol.for(marker$18);
23913
24167
  /**
23914
24168
  * Custom error class for AI SDK related errors.
23915
24169
  * @extends Error
@@ -23925,7 +24179,7 @@ var AISDKError$4 = class AISDKError extends Error {
23925
24179
  */
23926
24180
  constructor({ name, message, cause }) {
23927
24181
  super(message);
23928
- this[symbol$16] = true;
24182
+ this[symbol$18] = true;
23929
24183
  this.name = name;
23930
24184
  this.cause = cause;
23931
24185
  }
@@ -23935,24 +24189,24 @@ var AISDKError$4 = class AISDKError extends Error {
23935
24189
  * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
23936
24190
  */
23937
24191
  static isInstance(error) {
23938
- return AISDKError.hasMarker(error, marker$16);
24192
+ return AISDKError.hasMarker(error, marker$18);
23939
24193
  }
23940
24194
  static hasMarker(error, marker) {
23941
24195
  const markerSymbol = Symbol.for(marker);
23942
24196
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
23943
24197
  }
23944
24198
  };
23945
- const name$14 = "AI_APICallError";
23946
- const marker$14 = `vercel.ai.error.${name$14}`;
23947
- const symbol$14 = Symbol.for(marker$14);
24199
+ const name$16 = "AI_APICallError";
24200
+ const marker$16 = `vercel.ai.error.${name$16}`;
24201
+ const symbol$16 = Symbol.for(marker$16);
23948
24202
  var APICallError = class extends AISDKError$4 {
23949
24203
  constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
23950
24204
  super({
23951
- name: name$14,
24205
+ name: name$16,
23952
24206
  message,
23953
24207
  cause
23954
24208
  });
23955
- this[symbol$14] = true;
24209
+ this[symbol$16] = true;
23956
24210
  this.url = url;
23957
24211
  this.requestBodyValues = requestBodyValues;
23958
24212
  this.statusCode = statusCode;
@@ -23962,22 +24216,22 @@ var APICallError = class extends AISDKError$4 {
23962
24216
  this.data = data;
23963
24217
  }
23964
24218
  static isInstance(error) {
23965
- return AISDKError$4.hasMarker(error, marker$14);
24219
+ return AISDKError$4.hasMarker(error, marker$16);
23966
24220
  }
23967
24221
  };
23968
- const name$13 = "AI_EmptyResponseBodyError";
23969
- const marker$13 = `vercel.ai.error.${name$13}`;
23970
- const symbol$13 = Symbol.for(marker$13);
24222
+ const name$15 = "AI_EmptyResponseBodyError";
24223
+ const marker$15 = `vercel.ai.error.${name$15}`;
24224
+ const symbol$15 = Symbol.for(marker$15);
23971
24225
  var EmptyResponseBodyError = class extends AISDKError$4 {
23972
24226
  constructor({ message = "Empty response body" } = {}) {
23973
24227
  super({
23974
- name: name$13,
24228
+ name: name$15,
23975
24229
  message
23976
24230
  });
23977
- this[symbol$13] = true;
24231
+ this[symbol$15] = true;
23978
24232
  }
23979
24233
  static isInstance(error) {
23980
- return AISDKError$4.hasMarker(error, marker$13);
24234
+ return AISDKError$4.hasMarker(error, marker$15);
23981
24235
  }
23982
24236
  };
23983
24237
  function getErrorMessage(error) {
@@ -24105,20 +24359,20 @@ var TypeValidationError$4 = class TypeValidationError extends AISDKError$4 {
24105
24359
  });
24106
24360
  }
24107
24361
  };
24108
- const name$16 = "AI_UnsupportedFunctionalityError";
24109
- const marker$17 = `vercel.ai.error.${name$16}`;
24110
- const symbol$17 = Symbol.for(marker$17);
24362
+ const name$18 = "AI_UnsupportedFunctionalityError";
24363
+ const marker$19 = `vercel.ai.error.${name$18}`;
24364
+ const symbol$19 = Symbol.for(marker$19);
24111
24365
  var UnsupportedFunctionalityError = class extends AISDKError$4 {
24112
24366
  constructor({ functionality, message = `'${functionality}' functionality not supported.` }) {
24113
24367
  super({
24114
- name: name$16,
24368
+ name: name$18,
24115
24369
  message
24116
24370
  });
24117
- this[symbol$17] = true;
24371
+ this[symbol$19] = true;
24118
24372
  this.functionality = functionality;
24119
24373
  }
24120
24374
  static isInstance(error) {
24121
- return AISDKError$4.hasMarker(error, marker$17);
24375
+ return AISDKError$4.hasMarker(error, marker$19);
24122
24376
  }
24123
24377
  };
24124
24378
  var ParseError = class extends Error {
@@ -24604,7 +24858,7 @@ function handleFetchError({ error, url, requestBodyValues }) {
24604
24858
  }
24605
24859
  return error;
24606
24860
  }
24607
- const VERSION$2 = "5.0.74";
24861
+ const VERSION$2 = "5.0.81";
24608
24862
  /**
24609
24863
  * Normalizes different header inputs into a plain record with lower-case keys.
24610
24864
  * Entries with `undefined` or `null` values are removed.
@@ -24707,11 +24961,54 @@ function isSameOrigin(url, baseUrl) {
24707
24961
  }
24708
24962
  }
24709
24963
  /**
24964
+ * Request headers stripped before fetching an untrusted URL: host/virtual-host
24965
+ * routing, proxy/origin spoofing, cloud-metadata, cookies, and hop-by-hop
24966
+ * transport headers (RFC 7230 §6.1).
24967
+ *
24968
+ * `Authorization` and other credential-bearing caller headers (e.g. `x-key`)
24969
+ * are intentionally not listed because trusted provider requests may need
24970
+ * them. `fetchUntrustedUrl` separately restricts an untrusted first hop to an
24971
+ * explicit allowlist of non-credential request metadata. Both it and
24972
+ * `fetchWithValidatedRedirects` drop all caller headers except the user-agent
24973
+ * on a cross-origin redirect.
24974
+ */
24975
+ const BLOCKED_REQUEST_HEADERS = [
24976
+ "connection",
24977
+ "keep-alive",
24978
+ "te",
24979
+ "trailer",
24980
+ "transfer-encoding",
24981
+ "upgrade",
24982
+ "host",
24983
+ "forwarded",
24984
+ "proxy-authorization",
24985
+ "via",
24986
+ "x-forwarded-for",
24987
+ "x-forwarded-host",
24988
+ "x-forwarded-proto",
24989
+ "x-real-ip",
24990
+ "metadata",
24991
+ "metadata-flavor",
24992
+ "x-aws-ec2-metadata-token",
24993
+ "x-metadata-token",
24994
+ "cookie",
24995
+ "set-cookie"
24996
+ ];
24997
+ /**
24998
+ * Returns a fresh `Headers` built from `input` with {@link BLOCKED_REQUEST_HEADERS}
24999
+ * removed. The input is never mutated.
25000
+ */
25001
+ function sanitizeRequestHeaders(input) {
25002
+ const headers = new Headers(input);
25003
+ for (const name of BLOCKED_REQUEST_HEADERS) headers.delete(name);
25004
+ return headers;
25005
+ }
25006
+ /**
24710
25007
  * Validates that a URL is safe to download from, blocking private/internal addresses
24711
25008
  * to prevent SSRF attacks.
24712
25009
  *
24713
- * Note: this function performs string/literal-IP checks only. The Node.js
24714
- * download fetch additionally validates and pins DNS results at connect time.
25010
+ * This function performs string/literal-IP checks only. DNS validation must
25011
+ * be provided by the fetch transport or network egress controls.
24715
25012
  *
24716
25013
  * @param url - The URL string to validate.
24717
25014
  * @throws DownloadError if the URL is unsafe.
@@ -24754,16 +25051,6 @@ function validateDownloadUrl(url) {
24754
25051
  });
24755
25052
  }
24756
25053
  }
24757
- /**
24758
- * Validates an address returned by DNS before it is used to open a socket.
24759
- * This is intentionally not exported from the package entry point.
24760
- */
24761
- function validateDownloadAddress({ address, family, hostname }) {
24762
- if (family === 4 ? !isIPv4(address) || isPrivateIPv4(address) : family === 6 ? isPrivateIPv6(address) : true) throw new DownloadError({
24763
- url: hostname,
24764
- message: `Hostname ${hostname} resolved to disallowed IP address ${address}`
24765
- });
24766
- }
24767
25054
  function isIPv4(hostname) {
24768
25055
  const parts = hostname.split(".");
24769
25056
  if (parts.length !== 4) return false;
@@ -24847,119 +25134,6 @@ function isPrivateIPv6(ip) {
24847
25134
  if (topZero(6) || topZero(5) && groups[5] === 65535 || topZero(4) && groups[4] === 65535 && groups[5] === 0 || groups[0] === 100 && groups[1] === 65435 && groups[2] === 0 && groups[3] === 0 && groups[4] === 0 && groups[5] === 0 || groups[0] === 100 && groups[1] === 65435 && groups[2] === 1) return isPrivateIPv4(`${groups[6] >> 8 & 255}.${groups[6] & 255}.${groups[7] >> 8 & 255}.${groups[7] & 255}`);
24848
25135
  return false;
24849
25136
  }
24850
- /**
24851
- * Creates a DNS lookup hook that validates every returned address before
24852
- * returning the callback shape requested by the HTTP connector. Because
24853
- * resolution and validation happen inside the connector, the socket is pinned
24854
- * to the validated result and DNS rebinding cannot introduce a second lookup.
24855
- */
24856
- function createSafeLookup(lookup) {
24857
- return ((hostname, options, callback) => {
24858
- lookup(hostname, {
24859
- ...options,
24860
- all: true
24861
- }, (error, addresses) => {
24862
- if (error) {
24863
- callback(error);
24864
- return;
24865
- }
24866
- try {
24867
- const [firstAddress] = addresses;
24868
- if (firstAddress == null) throw new Error(`Hostname ${hostname} did not resolve to an address`);
24869
- for (const { address, family } of addresses) validateDownloadAddress({
24870
- address,
24871
- family,
24872
- hostname
24873
- });
24874
- if (options.all === true) callback(null, addresses);
24875
- else callback(null, firstAddress.address, firstAddress.family);
24876
- } catch (error) {
24877
- callback(error instanceof Error ? error : new Error(String(error)));
24878
- }
24879
- });
24880
- });
24881
- }
24882
- let safeNodeFetchPromise;
24883
- function isNodeRuntime$1() {
24884
- const runtimeProcess = globalThis.process;
24885
- return runtimeProcess?.release?.name === "node" && runtimeProcess.versions?.bun == null && runtimeProcess.versions?.deno == null && runtimeProcess.title !== "workerd" && globalThis.EdgeRuntime == null;
24886
- }
24887
- async function getDefaultDownloadFetch() {
24888
- if (!isNodeRuntime$1()) return globalThis.fetch;
24889
- return safeNodeFetchPromise ??= Promise.resolve().then(createSafeNodeFetch);
24890
- }
24891
- function createSafeNodeFetch() {
24892
- const module = loadBuiltinModule$1("node:module");
24893
- const { lookup } = loadBuiltinModule$1("node:dns");
24894
- const { Agent, fetch } = module.createRequire(getCurrentModulePath())("undici");
24895
- const dispatcher = new Agent({ connect: { lookup: createSafeLookup(lookup) } });
24896
- return ((input, init) => fetch(input, {
24897
- ...init,
24898
- dispatcher
24899
- }));
24900
- }
24901
- function loadBuiltinModule$1(id) {
24902
- const builtinModule = globalThis.process?.getBuiltinModule?.(id);
24903
- if (builtinModule == null) throw new Error(`Node.js built-in module ${id} is unavailable`);
24904
- return builtinModule;
24905
- }
24906
- function getCurrentModulePath() {
24907
- const originalPrepareStackTrace = Error.prepareStackTrace;
24908
- try {
24909
- Error.prepareStackTrace = (_error, callSites) => callSites;
24910
- const error = /* @__PURE__ */ new Error("Capture current module path");
24911
- Error.captureStackTrace(error, getCurrentModulePath);
24912
- const [caller] = error.stack;
24913
- const fileName = caller?.getFileName();
24914
- if (fileName == null) throw new Error("Unable to determine the current module path");
24915
- return fileName;
24916
- } finally {
24917
- Error.prepareStackTrace = originalPrepareStackTrace;
24918
- }
24919
- }
24920
- /**
24921
- * Request headers stripped before fetching an untrusted URL: host/virtual-host
24922
- * routing, proxy/origin spoofing, cloud-metadata, cookies, and hop-by-hop
24923
- * transport headers (RFC 7230 §6.1).
24924
- *
24925
- * `Authorization` and other credential-bearing caller headers (e.g. `x-key`)
24926
- * are intentionally not listed because trusted provider requests may need
24927
- * them. `fetchUntrustedUrl` separately restricts an untrusted first hop to an
24928
- * explicit allowlist of non-credential request metadata. Both it and
24929
- * `fetchWithValidatedRedirects` drop all caller headers except the user-agent
24930
- * on a cross-origin redirect.
24931
- */
24932
- const BLOCKED_REQUEST_HEADERS = [
24933
- "connection",
24934
- "keep-alive",
24935
- "te",
24936
- "trailer",
24937
- "transfer-encoding",
24938
- "upgrade",
24939
- "host",
24940
- "forwarded",
24941
- "proxy-authorization",
24942
- "via",
24943
- "x-forwarded-for",
24944
- "x-forwarded-host",
24945
- "x-forwarded-proto",
24946
- "x-real-ip",
24947
- "metadata",
24948
- "metadata-flavor",
24949
- "x-aws-ec2-metadata-token",
24950
- "x-metadata-token",
24951
- "cookie",
24952
- "set-cookie"
24953
- ];
24954
- /**
24955
- * Returns a fresh `Headers` built from `input` with {@link BLOCKED_REQUEST_HEADERS}
24956
- * removed. The input is never mutated.
24957
- */
24958
- function sanitizeRequestHeaders(input) {
24959
- const headers = new Headers(input);
24960
- for (const name of BLOCKED_REQUEST_HEADERS) headers.delete(name);
24961
- return headers;
24962
- }
24963
25137
  const MAX_DOWNLOAD_REDIRECTS = 10;
24964
25138
  const REDIRECT_STATUS_CODES = /* @__PURE__ */ new Set([
24965
25139
  301,
@@ -24968,9 +25142,6 @@ const REDIRECT_STATUS_CODES = /* @__PURE__ */ new Set([
24968
25142
  307,
24969
25143
  308
24970
25144
  ]);
24971
- async function getValidatedFetch(customFetch) {
24972
- return customFetch == null || customFetch === globalThis.fetch ? await getDefaultDownloadFetch() : customFetch;
24973
- }
24974
25145
  /**
24975
25146
  * Fetches a URL while enforcing the download guard on every hop.
24976
25147
  *
@@ -24980,6 +25151,9 @@ async function getValidatedFetch(customFetch) {
24980
25151
  * target (e.g. an internal address) before we ever see its URL, defeating the
24981
25152
  * guard.
24982
25153
  *
25154
+ * Manually followed redirects from HTTPS to HTTP are rejected before requesting
25155
+ * the target.
25156
+ *
24983
25157
  * Request headers are also protected: {@link sanitizeRequestHeaders} strips
24984
25158
  * proxy/metadata/cookie/hop-by-hop headers before the first request, and all
24985
25159
  * caller headers except `User-Agent` are dropped on a cross-origin redirect.
@@ -25009,11 +25183,8 @@ async function getValidatedFetch(customFetch) {
25009
25183
  * The returned response is the final (non-redirect) response. The caller is
25010
25184
  * responsible for checking `response.ok` and reading the body.
25011
25185
  *
25012
- * On Node.js, the default fetch resolves every hostname through a validating
25013
- * lookup hook and passes those exact addresses to the connector, preventing
25014
- * hostname-to-private-IP and DNS-rebinding bypasses. An injected fetch is
25015
- * responsible for equivalent connect-time validation. Other runtimes should
25016
- * constrain egress at the network layer when handling untrusted URLs.
25186
+ * URL validation does not resolve DNS. Use guarded-fetch on Node.js
25187
+ * for connection-time DNS validation, or enforce network egress restrictions.
25017
25188
  *
25018
25189
  * @throws DownloadError if a hop is unsafe, the redirect limit is exceeded, or
25019
25190
  * a redirect cannot be validated on a non-browser runtime.
@@ -25030,9 +25201,8 @@ async function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedir
25030
25201
  };
25031
25202
  let currentUrl = url;
25032
25203
  for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
25033
- const isTrustedHop = trustedOrigin !== void 0 && isSameOrigin(currentUrl, trustedOrigin);
25034
- if (!isTrustedHop) validateDownloadUrl(currentUrl);
25035
- const fetch = isTrustedHop && customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getValidatedFetch(customFetch);
25204
+ if (!(trustedOrigin !== void 0 && isSameOrigin(currentUrl, trustedOrigin))) validateDownloadUrl(currentUrl);
25205
+ const fetch = customFetch ?? globalThis.fetch;
25036
25206
  const response = await fetch(currentUrl, perHopInit("manual"));
25037
25207
  if (response.type === "opaqueredirect") {
25038
25208
  if (!isBrowserRuntime()) throw new DownloadError({
@@ -25045,6 +25215,10 @@ async function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedir
25045
25215
  if (REDIRECT_STATUS_CODES.has(response.status) && location) {
25046
25216
  cancelResponseBody(response);
25047
25217
  const nextUrl = new URL(location, currentUrl).toString();
25218
+ if (new URL(currentUrl).protocol === "https:" && new URL(nextUrl).protocol === "http:") throw new DownloadError({
25219
+ url,
25220
+ message: "Redirect from HTTPS to HTTP was blocked"
25221
+ });
25048
25222
  if (currentHeaders !== void 0 && !isSameOrigin(nextUrl, currentUrl)) {
25049
25223
  const userAgent = currentHeaders.get("user-agent");
25050
25224
  currentHeaders = new Headers(userAgent == null ? void 0 : { "user-agent": userAgent });
@@ -25081,10 +25255,13 @@ const DEFAULT_MAX_DOWNLOAD_SIZE = 2147483648;
25081
25255
  * @param response - The fetch Response to read.
25082
25256
  * @param url - The URL being downloaded (used in error messages).
25083
25257
  * @param maxBytes - Maximum allowed bytes. Defaults to DEFAULT_MAX_DOWNLOAD_SIZE.
25258
+ * @param onChunk - Optional. Receives each chunk instead of the chunks being
25259
+ * collected, so the body is not held in memory, and the returned array is empty.
25260
+ * The chunk may be a view on a larger buffer, copy what you keep.
25084
25261
  * @returns A Uint8Array containing the response body.
25085
25262
  * @throws DownloadError if the response exceeds maxBytes.
25086
25263
  */
25087
- async function readResponseWithSizeLimit({ response, url, maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE }) {
25264
+ async function readResponseWithSizeLimit({ response, url, maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE, onChunk }) {
25088
25265
  const contentLength = response.headers.get("content-length");
25089
25266
  if (contentLength != null) {
25090
25267
  const length = parseInt(contentLength, 10);
@@ -25110,6 +25287,10 @@ async function readResponseWithSizeLimit({ response, url, maxBytes = DEFAULT_MAX
25110
25287
  url,
25111
25288
  message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes.`
25112
25289
  });
25290
+ if (onChunk != null) {
25291
+ onChunk(value);
25292
+ continue;
25293
+ }
25113
25294
  chunks.push(value.byteLength < value.buffer.byteLength ? new Uint8Array(value) : value);
25114
25295
  }
25115
25296
  } finally {
@@ -25119,7 +25300,7 @@ async function readResponseWithSizeLimit({ response, url, maxBytes = DEFAULT_MAX
25119
25300
  reader.releaseLock();
25120
25301
  }
25121
25302
  }
25122
- const result = new Uint8Array(totalBytes);
25303
+ const result = new Uint8Array(onChunk != null ? 0 : totalBytes);
25123
25304
  let offset = 0;
25124
25305
  for (const chunk of chunks) {
25125
25306
  result.set(chunk, offset);
@@ -26284,6 +26465,7 @@ function zod3Schema$3(zodSchema, options) {
26284
26465
  } });
26285
26466
  }
26286
26467
  function zod4Schema$3(zodSchema, options) {
26468
+ if (!config().localeError) config(en());
26287
26469
  const useReferences = options?.useReferences ?? false;
26288
26470
  return jsonSchema$4(() => addAdditionalPropertiesToJsonSchema$3(toJSONSchema$1(zodSchema, {
26289
26471
  target: "draft-7",
@@ -26515,12 +26697,27 @@ const postToApi = async ({ url, headers = {}, body, successfulResponseHandler, f
26515
26697
  function tool(tool) {
26516
26698
  return tool;
26517
26699
  }
26518
- function createProviderExecutedToolFactory({ id, inputSchema, outputSchema, supportsDeferredResults }) {
26700
+ const telemetryRedaction = Symbol.for("vercel.ai.telemetry.redact");
26701
+ /**
26702
+ * Attach a provider-owned telemetry view without changing the original value.
26703
+ * The annotation is not serialized or included in enumerable application data.
26704
+ * Keep the annotated object when forwarding tool arguments or provider metadata.
26705
+ */
26706
+ function withTelemetryRedaction(value, redact) {
26707
+ return Object.create(Object.getPrototypeOf(value), {
26708
+ ...Object.getOwnPropertyDescriptors(value),
26709
+ [telemetryRedaction]: {
26710
+ value: redact,
26711
+ configurable: true
26712
+ }
26713
+ });
26714
+ }
26715
+ function createProviderExecutedToolFactory({ id, inputSchema, outputSchema, supportsDeferredResults, redactArgs }) {
26519
26716
  return ({ onInputStart, onInputDelta, onInputAvailable, ...args }) => tool({
26520
26717
  type: "provider",
26521
26718
  isProviderExecuted: true,
26522
26719
  id,
26523
- args,
26720
+ args: redactArgs == null ? args : withTelemetryRedaction(args, redactArgs),
26524
26721
  inputSchema,
26525
26722
  outputSchema,
26526
26723
  onInputStart,
@@ -26586,6 +26783,286 @@ async function retryWithExponentialBackoffInternal(f, { maxRetries, delayInMs, b
26586
26783
  });
26587
26784
  }
26588
26785
  }
26786
+ /**
26787
+ * Streaming extraction of large base64 strings from a JSON response body.
26788
+ *
26789
+ * A JSON response that carries an image or a file is mostly one very long
26790
+ * base64 string. The regular pipeline (collect chunks, concatenate, decode to
26791
+ * text, `JSON.parse`, decode base64) holds about four copies of that string at
26792
+ * once. The scanner reads the body chunk by chunk instead: strings at the
26793
+ * configured paths are decoded to bytes while they stream in, and the text that
26794
+ * is handed to `JSON.parse` (the "skeleton") holds a short placeholder in their
26795
+ * place.
26796
+ *
26797
+ * - The skeleton is the original body except for the extracted strings, so
26798
+ * `secureJsonParse` still sees every key (a base64 string cannot contain a
26799
+ * quote, so it cannot hide one).
26800
+ * - A string is extracted only if it is canonical standard-alphabet base64
26801
+ * (length divisible by 4, `=` only as the final padding, zero trailing bits,
26802
+ * no escape sequences or whitespace). The bytes are then exactly what `atob`
26803
+ * gives for it. Everything else stays a string. What was decoded before a
26804
+ * string turned out not to qualify is encoded back, which gives the original
26805
+ * characters.
26806
+ */
26807
+ /** Strings that decode to fewer bytes stay strings. */
26808
+ const DEFAULT_BINARY_FIELD_MIN_BYTES = 65536;
26809
+ const QUOTE = 34;
26810
+ const BACKSLASH = 92;
26811
+ const EQUALS = 61;
26812
+ const COMMA = 44;
26813
+ const COLON = 58;
26814
+ const LEFT_BRACE = 123;
26815
+ const RIGHT_BRACE = 125;
26816
+ const LEFT_BRACKET = 91;
26817
+ const RIGHT_BRACKET = 93;
26818
+ const OUTSIDE = 0;
26819
+ const KEY = 1;
26820
+ const SKIP = 2;
26821
+ const BLOB = 3;
26822
+ /**
26823
+ * Compiles paths such as `images[*]` or `content[*].data.data`: plain object
26824
+ * keys (letters, digits, `_` and `-`) joined by `.`, and `[*]` for every
26825
+ * element of an array. Keys are compared with the raw bytes of the key in the
26826
+ * body, so a key written with an escape sequence never matches.
26827
+ */
26828
+ function compileBinaryFieldPaths(paths) {
26829
+ const root = /* @__PURE__ */ new Map();
26830
+ for (const path of paths) {
26831
+ if (!/^(?:[\w-]+|\[\*])(?:\.[\w-]+|\[\*])*$/.test(path)) throw new InvalidArgumentError$1({
26832
+ argument: "experimental_binaryFields",
26833
+ message: `Invalid binary field path "${path}"`
26834
+ });
26835
+ let node = root;
26836
+ for (const segment of path.match(/\[\*]|[\w-]+/g)) {
26837
+ const edges = segment === "[*]" ? [null] : new TextEncoder().encode(`${segment}"`);
26838
+ for (const edge of edges) {
26839
+ let next = node.get(edge);
26840
+ if (next === void 0) node.set(edge, next = /* @__PURE__ */ new Map());
26841
+ node = next;
26842
+ }
26843
+ }
26844
+ node.set(true, node);
26845
+ }
26846
+ return root;
26847
+ }
26848
+ function join$1(parts, length) {
26849
+ const bytes = new Uint8Array(length);
26850
+ let at = 0;
26851
+ for (const part of parts) {
26852
+ bytes.set(part, at);
26853
+ at += part.length;
26854
+ }
26855
+ return bytes;
26856
+ }
26857
+ function createJsonBinaryFieldScanner(paths, minBytes = DEFAULT_BINARY_FIELD_MIN_BYTES) {
26858
+ const sextet = (/* @__PURE__ */ new Uint8Array(256)).fill(64);
26859
+ for (let index = 0; index < 64; index++) sextet["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(index)] = index;
26860
+ const encoder = new TextEncoder();
26861
+ const pieces = [];
26862
+ let piece = /* @__PURE__ */ new Uint8Array(65536);
26863
+ let pieceLength = 0;
26864
+ let size = 0;
26865
+ const binaries = /* @__PURE__ */ new Map();
26866
+ const frames = [];
26867
+ let skipped = 0;
26868
+ let mode = OUTSIDE;
26869
+ let escaped = false;
26870
+ let last = 0;
26871
+ let key;
26872
+ let segments = [];
26873
+ let segment = /* @__PURE__ */ new Uint8Array(0);
26874
+ let at = 0;
26875
+ let total = 0;
26876
+ let bits = 0;
26877
+ let chars = 0;
26878
+ let padding = 0;
26879
+ const add = (bytes) => {
26880
+ for (let offset = 0; offset < bytes.length;) {
26881
+ const length = Math.min(piece.length - pieceLength, bytes.length - offset);
26882
+ piece.set(bytes.subarray(offset, offset + length), pieceLength);
26883
+ pieceLength += length;
26884
+ offset += length;
26885
+ size += length;
26886
+ if (pieceLength === piece.length) {
26887
+ pieces.push(piece);
26888
+ piece = /* @__PURE__ */ new Uint8Array(65536);
26889
+ pieceLength = 0;
26890
+ }
26891
+ }
26892
+ };
26893
+ const emit = (chunk, start, end) => add(chunk.subarray(start, end));
26894
+ const reset = () => {
26895
+ segments = [];
26896
+ segment = /* @__PURE__ */ new Uint8Array(0);
26897
+ at = 0;
26898
+ total = 0;
26899
+ bits = 0;
26900
+ chars = 0;
26901
+ padding = 0;
26902
+ };
26903
+ const grow = () => {
26904
+ if (at > 0) segments.push(segment.subarray(0, at));
26905
+ segment = new Uint8Array(Math.min(Math.max(total, 4096), 4 << 20));
26906
+ at = 0;
26907
+ };
26908
+ const rest = () => bits << (4 - chars) * 6;
26909
+ const restore = () => {
26910
+ for (const part of [...segments, segment.subarray(0, at)]) add(encoder.encode(convertUint8ArrayToBase64(part)));
26911
+ const group = rest();
26912
+ add(encoder.encode(convertUint8ArrayToBase64(Uint8Array.of(group >> 16, group >> 8, group)).slice(0, chars) + "=".repeat(padding)));
26913
+ reset();
26914
+ };
26915
+ const closeBlob = () => {
26916
+ mode = OUTSIDE;
26917
+ const tail = chars && chars - 1;
26918
+ if (padding === (4 - chars) % 4 && !(bits & (1 << (4 - chars) * 2) - 1) && total + tail >= minBytes) {
26919
+ const group = rest();
26920
+ const bytes = join$1([...segments, segment.subarray(0, at)], total + tail);
26921
+ for (let index = 0; index < tail; index++) bytes[total + index] = group >> 16 - 8 * index;
26922
+ const placeholder = `[binary data: ${bytes.length} bytes; ref ${crypto.getRandomValues(/* @__PURE__ */ new Uint32Array(2)).join("-")}]`;
26923
+ binaries.set(placeholder, bytes);
26924
+ add(encoder.encode(placeholder));
26925
+ reset();
26926
+ } else restore();
26927
+ };
26928
+ const push = (chunk) => {
26929
+ let from = 0;
26930
+ const { length } = chunk;
26931
+ for (let index = 0; index < length; index++) {
26932
+ let byte = chunk[index];
26933
+ if (mode === BLOB) {
26934
+ if (padding === 0) {
26935
+ let pending = bits;
26936
+ let count = chars;
26937
+ for (let value; index < length && (value = sextet[chunk[index]]) < 64; index++) {
26938
+ pending = pending << 6 | value;
26939
+ if (++count === 4) {
26940
+ if (at + 3 > segment.length) grow();
26941
+ segment[at++] = pending >> 16;
26942
+ segment[at++] = pending >> 8;
26943
+ segment[at++] = pending;
26944
+ total += 3;
26945
+ pending = 0;
26946
+ count = 0;
26947
+ }
26948
+ }
26949
+ bits = pending;
26950
+ chars = count;
26951
+ }
26952
+ if (index >= length) break;
26953
+ byte = chunk[index];
26954
+ if (byte === QUOTE) {
26955
+ closeBlob();
26956
+ from = index;
26957
+ } else if (byte === EQUALS && chars > 1 && padding < 4 - chars) padding++;
26958
+ else {
26959
+ restore();
26960
+ mode = SKIP;
26961
+ from = index--;
26962
+ }
26963
+ } else if (mode !== OUTSIDE) {
26964
+ if (mode === KEY) key = key?.get(byte);
26965
+ if (escaped) escaped = false;
26966
+ else if (byte === BACKSLASH) escaped = true;
26967
+ else if (byte === QUOTE) {
26968
+ if (mode === KEY) frames.at(-1).next = key;
26969
+ mode = OUTSIDE;
26970
+ }
26971
+ } else if (byte === QUOTE) {
26972
+ const frame = frames.at(-1);
26973
+ if (skipped > 0) mode = SKIP;
26974
+ else if (frame?.keys && (last === LEFT_BRACE || last === COMMA)) {
26975
+ mode = KEY;
26976
+ key = frame.keys;
26977
+ } else if ((frame ? frame.next : paths)?.get(true)) {
26978
+ mode = BLOB;
26979
+ emit(chunk, from, index + 1);
26980
+ } else mode = SKIP;
26981
+ } else if (byte === LEFT_BRACE || byte === LEFT_BRACKET) {
26982
+ last = byte;
26983
+ const frame = frames.at(-1);
26984
+ const node = skipped > 0 ? void 0 : frame ? frame.next : paths;
26985
+ const items = node?.get(null);
26986
+ if (byte === LEFT_BRACE && node) frames.push({ keys: node });
26987
+ else if (byte === LEFT_BRACKET && items) frames.push({
26988
+ keys: null,
26989
+ next: items
26990
+ });
26991
+ else skipped++;
26992
+ } else if (byte === RIGHT_BRACE || byte === RIGHT_BRACKET) {
26993
+ if (skipped > 0) skipped--;
26994
+ else frames.pop();
26995
+ } else if (byte === COMMA || byte === COLON) last = byte;
26996
+ }
26997
+ if (mode !== BLOB) emit(chunk, from, length);
26998
+ };
26999
+ const finish = () => {
27000
+ if (mode === BLOB) restore();
27001
+ return {
27002
+ text: new TextDecoder().decode(join$1([...pieces, piece.subarray(0, pieceLength)], size)),
27003
+ binaries
27004
+ };
27005
+ };
27006
+ return {
27007
+ push,
27008
+ finish
27009
+ };
27010
+ }
27011
+ /**
27012
+ * Replaces the placeholders in a parsed value with the bytes they stand for.
27013
+ * Objects and arrays are copied, the parsed value is not modified. A
27014
+ * placeholder holds a random number, so a string that equals one is ours.
27015
+ */
27016
+ function replaceBinaryFieldPlaceholders(value, binaries) {
27017
+ if (typeof value === "string") return binaries.get(value) ?? value;
27018
+ if (Array.isArray(value)) return value.map((item) => replaceBinaryFieldPlaceholders(item, binaries));
27019
+ if (value != null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([name, item]) => [name, replaceBinaryFieldPlaceholders(item, binaries)]));
27020
+ return value;
27021
+ }
27022
+ /**
27023
+ * Makes `JSON.stringify` give the placeholder for each of the arrays, instead
27024
+ * of `{"0":…,"1":…}` with an entry for every byte: 24 MiB of bytes would
27025
+ * become a string of more than 300 MB. That is what a validator, or the code
27026
+ * that reports its issues, does with a value it puts into an error message.
27027
+ * The property is not enumerable, so the arrays look the same otherwise.
27028
+ * Returns the function that removes it again.
27029
+ */
27030
+ function maskBinariesInJson(binaries) {
27031
+ for (const [placeholder, bytes] of binaries) Object.defineProperty(bytes, "toJSON", {
27032
+ value: () => placeholder,
27033
+ configurable: true
27034
+ });
27035
+ return () => {
27036
+ for (const bytes of binaries.values()) Reflect.deleteProperty(bytes, "toJSON");
27037
+ };
27038
+ }
27039
+ /**
27040
+ * Wraps a schema so that it validates the extracted bytes in place of their
27041
+ * placeholders. The value parsed from the skeleton, and the value of the
27042
+ * validation error of the response, keep the placeholders: reporting an error
27043
+ * never prints the bytes.
27044
+ *
27045
+ * The errors of the schema itself may hold the bytes: a Standard Schema
27046
+ * validator wraps the value it was given into an error, and the issues it
27047
+ * reports may carry the offending input. So that their messages do not grow
27048
+ * with the image, the arrays stringify as their placeholders, and keep doing
27049
+ * so as long as an error can refer to them. When the validation succeeds the
27050
+ * arrays are plain again, for whoever receives them.
27051
+ */
27052
+ function withBinaryFields(schema, binaries) {
27053
+ if (binaries.size === 0) return schema;
27054
+ const actualSchema = asSchema$4(schema);
27055
+ return jsonSchema$4({}, { validate: async (value) => {
27056
+ const replaced = replaceBinaryFieldPlaceholders(value, binaries);
27057
+ const unmask = maskBinariesInJson(binaries);
27058
+ const result = actualSchema.validate ? await actualSchema.validate(replaced) : {
27059
+ success: true,
27060
+ value: replaced
27061
+ };
27062
+ if (result.success) unmask();
27063
+ return result;
27064
+ } });
27065
+ }
26589
27066
  const textDecoder = new TextDecoder();
26590
27067
  const DEFAULT_MAX_JSON_LINE_BYTES = 67108864;
26591
27068
  function wrapResponseBodyStream({ stream, url, requestBodyValues, statusCode, responseHeaders }) {
@@ -26708,29 +27185,45 @@ const createEventSourceResponseHandler = (chunkSchema) => async ({ response, url
26708
27185
  })
26709
27186
  };
26710
27187
  };
26711
- const createJsonResponseHandler = (responseSchema) => async ({ response, url, requestBodyValues }) => {
26712
- const responseBody = await readResponseBodyAsText({
26713
- response,
26714
- url
26715
- });
26716
- const parsedResult = await safeParseJSON$4({
26717
- text: responseBody,
26718
- schema: responseSchema
26719
- });
26720
- const responseHeaders = extractResponseHeaders(response);
26721
- if (!parsedResult.success) throw new APICallError({
26722
- message: "Invalid JSON response",
26723
- cause: parsedResult.error,
26724
- statusCode: response.status,
26725
- responseHeaders,
26726
- responseBody,
26727
- url,
26728
- requestBodyValues
26729
- });
26730
- return {
26731
- responseHeaders,
26732
- value: parsedResult.value,
26733
- rawValue: parsedResult.rawValue
27188
+ const createJsonResponseHandler = (responseSchema, { experimental_binaryFields } = {}) => {
27189
+ const binaryFieldPaths = experimental_binaryFields?.length ? compileBinaryFieldPaths(experimental_binaryFields) : void 0;
27190
+ return async ({ response, url, requestBodyValues }) => {
27191
+ let responseBody;
27192
+ let schema = responseSchema;
27193
+ if (binaryFieldPaths == null) responseBody = await readResponseBodyAsText({
27194
+ response,
27195
+ url
27196
+ });
27197
+ else {
27198
+ const scanner = createJsonBinaryFieldScanner(binaryFieldPaths);
27199
+ await readResponseWithSizeLimit({
27200
+ response,
27201
+ url,
27202
+ onChunk: scanner.push
27203
+ });
27204
+ const scanned = scanner.finish();
27205
+ responseBody = scanned.text;
27206
+ schema = withBinaryFields(responseSchema, scanned.binaries);
27207
+ }
27208
+ const parsedResult = await safeParseJSON$4({
27209
+ text: responseBody,
27210
+ schema
27211
+ });
27212
+ const responseHeaders = extractResponseHeaders(response);
27213
+ if (!parsedResult.success) throw new APICallError({
27214
+ message: "Invalid JSON response",
27215
+ cause: parsedResult.error,
27216
+ statusCode: response.status,
27217
+ responseHeaders,
27218
+ responseBody,
27219
+ url,
27220
+ requestBodyValues
27221
+ });
27222
+ return {
27223
+ responseHeaders,
27224
+ value: parsedResult.value,
27225
+ rawValue: parsedResult.rawValue
27226
+ };
26734
27227
  };
26735
27228
  };
26736
27229
  const createJsonLinesResponseHandler = (responseSchema, { maxLineBytes = DEFAULT_MAX_JSON_LINE_BYTES } = {}) => {
@@ -26814,20 +27307,20 @@ function isJSONSerializable(value) {
26814
27307
  if (Object.getPrototypeOf(value) === Object.prototype) return Object.values(value).every(isJSONSerializable);
26815
27308
  return false;
26816
27309
  }
26817
- const name$17 = "AI_SerializationError";
26818
- const marker$18 = `vercel.ai.error.${name$17}`;
26819
- const symbol$18 = Symbol.for(marker$18);
27310
+ const name$12 = "AI_SerializationError";
27311
+ const marker$12 = `vercel.ai.error.${name$12}`;
27312
+ const symbol$12 = Symbol.for(marker$12);
26820
27313
  var SerializationError = class extends AISDKError$4 {
26821
27314
  constructor({ message = "Failed to serialize value.", cause } = {}) {
26822
27315
  super({
26823
- name: name$17,
27316
+ name: name$12,
26824
27317
  message,
26825
27318
  cause
26826
27319
  });
26827
- this[symbol$18] = true;
27320
+ this[symbol$12] = true;
26828
27321
  }
26829
27322
  static isInstance(error) {
26830
- return AISDKError$4.hasMarker(error, marker$18);
27323
+ return AISDKError$4.hasMarker(error, marker$12);
26831
27324
  }
26832
27325
  };
26833
27326
  /**
@@ -36785,7 +37278,7 @@ async function resolveImageDimensionsAsync(part) {
36785
37278
  const url = resolveHttpAssetUrl(getObjectValue(part, "image") ?? getObjectValue(part, "data"));
36786
37279
  if (!url) return existing;
36787
37280
  try {
36788
- const probeImageSize = (await import("./probe-image-size-CxVMV0gk.js").then((m) => /* @__PURE__ */ __toESM$1(m.default, 1))).default;
37281
+ const probeImageSize = (await import("./probe-image-size-Bu_nsmG7.js").then((m) => /* @__PURE__ */ __toESM$1(m.default, 1))).default;
36789
37282
  const probed = await probeImageSize(url, {
36790
37283
  open_timeout: REMOTE_IMAGE_PROBE_TIMEOUT_MS,
36791
37284
  response_timeout: REMOTE_IMAGE_PROBE_TIMEOUT_MS,
@@ -52104,7 +52597,7 @@ const createModelInstance = async (provider, modelId, version = "v2") => {
52104
52597
  try {
52105
52598
  const providerFn = version === `v1` ? { v1: {
52106
52599
  openai: async () => {
52107
- const { openai } = await import("./dist-HNpJc8bT.js");
52600
+ const { openai } = await import("./dist-DLdEfrDl.js");
52108
52601
  return openai(modelId);
52109
52602
  },
52110
52603
  anthropic: async () => {
@@ -59860,4 +60353,4 @@ function createAgentBuilderWorkflows() {
59860
60353
  }
59861
60354
  export { require_tiff as a, require_png as c, createAgentBuilderWorkflows, require_gif as d, require_bmp as f, require_webp as i, require_jpeg as l, require_utils as m, openai as n, require_svg as o, require_avif as p, require_sync as r, require_psd as s, createOpenAI as t, require_ico as u };
59862
60355
 
59863
- //# sourceMappingURL=dist-CMgUx8hS.js.map
60356
+ //# sourceMappingURL=dist-BoE65ceB.js.map