@mastra/memory 1.41.2-alpha.2 → 1.41.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,6 +33,8 @@ let zod = require("zod");
33
33
  let zod_v4 = require("zod/v4");
34
34
  zod_v4 = __toESM$1(zod_v4, 1);
35
35
  let zod_v4_core = require("zod/v4/core");
36
+ let zod_v4_locales_en_js = require("zod/v4/locales/en.js");
37
+ zod_v4_locales_en_js = __toESM$1(zod_v4_locales_en_js, 1);
36
38
  let _mastra_core_agent = require("@mastra/core/agent");
37
39
  let _mastra_core_error = require("@mastra/core/error");
38
40
  let _mastra_core_features = require("@mastra/core/features");
@@ -2803,8 +2805,8 @@ var UnsupportedModelVersionError$3 = class extends AISDKError$3 {
2803
2805
  }
2804
2806
  };
2805
2807
  var name$21 = "AI_InvalidArgumentError";
2806
- var marker$10 = `vercel.ai.error.${name$21}`;
2807
- var symbol$12 = Symbol.for(marker$10);
2808
+ var marker$20 = `vercel.ai.error.${name$21}`;
2809
+ var symbol$24 = Symbol.for(marker$20);
2808
2810
  var _a$6;
2809
2811
  var InvalidArgumentError$6 = class extends AISDKError$3 {
2810
2812
  constructor({ parameter, value, message }) {
@@ -2817,10 +2819,10 @@ var InvalidArgumentError$6 = class extends AISDKError$3 {
2817
2819
  this.value = value;
2818
2820
  }
2819
2821
  static isInstance(error) {
2820
- return AISDKError$3.hasMarker(error, marker$10);
2822
+ return AISDKError$3.hasMarker(error, marker$20);
2821
2823
  }
2822
2824
  };
2823
- _a$6 = symbol$12;
2825
+ _a$6 = symbol$24;
2824
2826
  var name2$6 = "AI_RetryError";
2825
2827
  var marker2$6 = `vercel.ai.error.${name2$6}`;
2826
2828
  var symbol2$6 = Symbol.for(marker2$6);
@@ -3710,12 +3712,12 @@ function trimStartOfStream() {
3710
3712
  return text2;
3711
3713
  };
3712
3714
  }
3713
- // ../_vendored/ai_v5/dist/dist-BESblyT5.js
3714
- var marker$1$16 = "vercel.ai.error";
3715
- var symbol$1$17 = Symbol.for(marker$1$16);
3715
+ // ../_vendored/ai_v5/dist/dist-DIfsHMRS.js
3716
+ var marker$1$11 = "vercel.ai.error";
3717
+ var symbol$1$21 = Symbol.for(marker$1$11);
3716
3718
  var _a$1$2;
3717
3719
  var _b$1$4;
3718
- var AISDKError$2 = class _AISDKError extends (_b$1$4 = Error, _a$1$2 = symbol$1$17, _b$1$4) {
3720
+ var AISDKError$2 = class _AISDKError extends (_b$1$4 = Error, _a$1$2 = symbol$1$21, _b$1$4) {
3719
3721
  /**
3720
3722
  * Creates an AI SDK Error.
3721
3723
  *
@@ -3736,22 +3738,22 @@ var AISDKError$2 = class _AISDKError extends (_b$1$4 = Error, _a$1$2 = symbol$1$
3736
3738
  * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
3737
3739
  */
3738
3740
  static isInstance(error) {
3739
- return _AISDKError.hasMarker(error, marker$1$16);
3741
+ return _AISDKError.hasMarker(error, marker$1$11);
3740
3742
  }
3741
3743
  static hasMarker(error, marker15) {
3742
3744
  const markerSymbol = Symbol.for(marker15);
3743
3745
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
3744
3746
  }
3745
3747
  };
3746
- var name$1$15 = "AI_APICallError";
3747
- var marker2$5 = `vercel.ai.error.${name$1$15}`;
3748
+ var name$1$19 = "AI_APICallError";
3749
+ var marker2$5 = `vercel.ai.error.${name$1$19}`;
3748
3750
  var symbol2$5 = Symbol.for(marker2$5);
3749
3751
  var _a2$5;
3750
3752
  var _b2$3;
3751
3753
  var APICallError$2 = class extends (_b2$3 = AISDKError$2, _a2$5 = symbol2$5, _b2$3) {
3752
3754
  constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
3753
3755
  super({
3754
- name: name$1$15,
3756
+ name: name$1$19,
3755
3757
  message,
3756
3758
  cause
3757
3759
  });
@@ -4090,15 +4092,15 @@ function createAbortError$2() {
4090
4092
  function extractResponseHeaders$2(response) {
4091
4093
  return Object.fromEntries([...response.headers]);
4092
4094
  }
4093
- var name$15 = "AI_DownloadError";
4094
- var marker$20 = `vercel.ai.error.${name$15}`;
4095
- var symbol$24 = Symbol.for(marker$20);
4095
+ var name$20 = "AI_DownloadError";
4096
+ var marker$17 = `vercel.ai.error.${name$20}`;
4097
+ var symbol$22 = Symbol.for(marker$17);
4096
4098
  var _a$5;
4097
4099
  var _b$5;
4098
- var DownloadError$2 = class extends (_b$5 = AISDKError$2, _a$5 = symbol$24, _b$5) {
4100
+ var DownloadError$2 = class extends (_b$5 = AISDKError$2, _a$5 = symbol$22, _b$5) {
4099
4101
  constructor({ url, statusCode, statusText, cause, message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}` }) {
4100
4102
  super({
4101
- name: name$15,
4103
+ name: name$20,
4102
4104
  message,
4103
4105
  cause
4104
4106
  });
@@ -4108,7 +4110,7 @@ var DownloadError$2 = class extends (_b$5 = AISDKError$2, _a$5 = symbol$24, _b$5
4108
4110
  this.statusText = statusText;
4109
4111
  }
4110
4112
  static isInstance(error) {
4111
- return AISDKError$2.hasMarker(error, marker$20);
4113
+ return AISDKError$2.hasMarker(error, marker$17);
4112
4114
  }
4113
4115
  };
4114
4116
  var EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL$2 = /* @__PURE__ */ Symbol.for("vercel.ai.embeddingModel.maxInputBytesPerCall");
@@ -4118,6 +4120,247 @@ async function cancelResponseBody$2(response) {
4118
4120
  await ((_a2 = response.body) == null ? void 0 : _a2.cancel());
4119
4121
  } catch (e) {}
4120
4122
  }
4123
+ function isBrowserRuntime$2(globalThisAny = globalThis) {
4124
+ return globalThisAny.window != null;
4125
+ }
4126
+ function isSameOrigin$2(url, baseUrl) {
4127
+ try {
4128
+ return new URL(url).origin === new URL(baseUrl).origin;
4129
+ } catch (e) {
4130
+ return false;
4131
+ }
4132
+ }
4133
+ function validateDownloadUrl$2(url) {
4134
+ let parsed;
4135
+ try {
4136
+ parsed = new URL(url);
4137
+ } catch (e) {
4138
+ throw new DownloadError$2({
4139
+ url,
4140
+ message: `Invalid URL: ${url}`
4141
+ });
4142
+ }
4143
+ if (parsed.protocol === "data:") return;
4144
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new DownloadError$2({
4145
+ url,
4146
+ message: `URL scheme must be http, https, or data, got ${parsed.protocol}`
4147
+ });
4148
+ const hostname = parsed.hostname.toLowerCase().replace(/\.+$/, "");
4149
+ if (!hostname) throw new DownloadError$2({
4150
+ url,
4151
+ message: `URL must have a hostname`
4152
+ });
4153
+ if (hostname === "localhost" || hostname.endsWith(".local") || hostname.endsWith(".localhost") || hostname.endsWith(".internal")) throw new DownloadError$2({
4154
+ url,
4155
+ message: `URL with hostname ${hostname} is not allowed`
4156
+ });
4157
+ if (hostname.startsWith("[") && hostname.endsWith("]")) {
4158
+ if (isPrivateIPv6$2(hostname.slice(1, -1))) throw new DownloadError$2({
4159
+ url,
4160
+ message: `URL with IPv6 address ${hostname} is not allowed`
4161
+ });
4162
+ return;
4163
+ }
4164
+ if (isIPv4$2(hostname)) {
4165
+ if (isPrivateIPv4$2(hostname)) throw new DownloadError$2({
4166
+ url,
4167
+ message: `URL with IP address ${hostname} is not allowed`
4168
+ });
4169
+ }
4170
+ }
4171
+ function validateDownloadAddress$1({ address, family, hostname }) {
4172
+ if (family === 4 ? !isIPv4$2(address) || isPrivateIPv4$2(address) : family === 6 ? isPrivateIPv6$2(address) : true) throw new DownloadError$2({
4173
+ url: hostname,
4174
+ message: `Hostname ${hostname} resolved to disallowed IP address ${address}`
4175
+ });
4176
+ }
4177
+ function isIPv4$2(hostname) {
4178
+ const parts = hostname.split(".");
4179
+ if (parts.length !== 4) return false;
4180
+ return parts.every((part) => {
4181
+ const num = Number(part);
4182
+ return Number.isInteger(num) && num >= 0 && num <= 255 && String(num) === part;
4183
+ });
4184
+ }
4185
+ function isPrivateIPv4$2(ip) {
4186
+ const [a, b, c] = ip.split(".").map(Number);
4187
+ if (a === 0) return true;
4188
+ if (a === 10) return true;
4189
+ if (a === 100 && b >= 64 && b <= 127) return true;
4190
+ if (a === 127) return true;
4191
+ if (a === 169 && b === 254) return true;
4192
+ if (a === 172 && b >= 16 && b <= 31) return true;
4193
+ if (a === 192 && b === 0 && c === 0) return true;
4194
+ if (a === 192 && b === 168) return true;
4195
+ if (a === 198 && (b === 18 || b === 19)) return true;
4196
+ if (a >= 240) return true;
4197
+ return false;
4198
+ }
4199
+ function parseIPv6$2(ip) {
4200
+ let address = ip.toLowerCase();
4201
+ const zoneIndex = address.indexOf("%");
4202
+ if (zoneIndex !== -1) address = address.slice(0, zoneIndex);
4203
+ const halves = address.split("::");
4204
+ if (halves.length > 2) return null;
4205
+ const toGroups = (segment) => {
4206
+ if (segment === "") return [];
4207
+ const groups = [];
4208
+ const parts = segment.split(":");
4209
+ for (let i = 0; i < parts.length; i++) {
4210
+ const part = parts[i];
4211
+ if (part.includes(".")) {
4212
+ if (i !== parts.length - 1 || !isIPv4$2(part)) return null;
4213
+ const [a, b, c, d] = part.split(".").map(Number);
4214
+ groups.push(a << 8 | b, c << 8 | d);
4215
+ continue;
4216
+ }
4217
+ if (!/^[0-9a-f]{1,4}$/.test(part)) return null;
4218
+ groups.push(parseInt(part, 16));
4219
+ }
4220
+ return groups;
4221
+ };
4222
+ const head = toGroups(halves[0]);
4223
+ if (head === null) return null;
4224
+ if (halves.length === 2) {
4225
+ const tail = toGroups(halves[1]);
4226
+ if (tail === null) return null;
4227
+ const fill = 8 - head.length - tail.length;
4228
+ if (fill < 0) return null;
4229
+ return [
4230
+ ...head,
4231
+ ...new Array(fill).fill(0),
4232
+ ...tail
4233
+ ];
4234
+ }
4235
+ return head.length === 8 ? head : null;
4236
+ }
4237
+ function isPrivateIPv6$2(ip) {
4238
+ const groups = parseIPv6$2(ip);
4239
+ if (groups === null) return true;
4240
+ const topZero = (count) => groups.slice(0, count).every((group) => group === 0);
4241
+ if (topZero(7) && (groups[7] === 0 || groups[7] === 1)) return true;
4242
+ if ((groups[0] & 65024) === 64512) return true;
4243
+ if ((groups[0] & 65472) === 65152) return true;
4244
+ if ((groups[0] & 65472) === 65216) return true;
4245
+ if ((groups[0] & 65280) === 65280) return true;
4246
+ 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}`);
4247
+ return false;
4248
+ }
4249
+ function createSafeLookup$1(lookup) {
4250
+ return ((hostname, options, callback) => {
4251
+ lookup(hostname, {
4252
+ ...options,
4253
+ all: true
4254
+ }, (error, addresses) => {
4255
+ if (error) {
4256
+ callback(error);
4257
+ return;
4258
+ }
4259
+ try {
4260
+ const [firstAddress] = addresses;
4261
+ if (firstAddress == null) throw new Error(`Hostname ${hostname} did not resolve to an address`);
4262
+ for (const { address, family } of addresses) validateDownloadAddress$1({
4263
+ address,
4264
+ family,
4265
+ hostname
4266
+ });
4267
+ if (options.all === true) callback(null, addresses);
4268
+ else callback(null, firstAddress.address, firstAddress.family);
4269
+ } catch (error2) {
4270
+ callback(error2 instanceof Error ? error2 : new Error(String(error2)));
4271
+ }
4272
+ });
4273
+ });
4274
+ }
4275
+ var safeNodeFetchPromise$1;
4276
+ function isNodeRuntime$2() {
4277
+ var _a2, _b2, _c;
4278
+ const runtimeProcess = globalThis.process;
4279
+ 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;
4280
+ }
4281
+ async function getDefaultDownloadFetch$1() {
4282
+ if (!isNodeRuntime$2()) return globalThis.fetch;
4283
+ return safeNodeFetchPromise$1 != null ? safeNodeFetchPromise$1 : safeNodeFetchPromise$1 = createSafeNodeFetch$1();
4284
+ }
4285
+ async function createSafeNodeFetch$1() {
4286
+ const [module, { lookup }] = await Promise.all([loadNodeModule$1("node:module"), loadNodeModule$1("node:dns")]);
4287
+ const { Agent, fetch } = module.createRequire(getCurrentModulePath$1())("undici");
4288
+ const dispatcher = new Agent({ connect: { lookup: createSafeLookup$1(lookup) } });
4289
+ return ((input, init) => fetch(input, {
4290
+ ...init,
4291
+ dispatcher
4292
+ }));
4293
+ }
4294
+ async function loadNodeModule$1(id) {
4295
+ var _a2;
4296
+ const processWithBuiltins = globalThis.process;
4297
+ const builtinModule = (_a2 = processWithBuiltins == null ? void 0 : processWithBuiltins.getBuiltinModule) == null ? void 0 : _a2.call(processWithBuiltins, id);
4298
+ return builtinModule == null ? await importNodeModule(id) : builtinModule;
4299
+ }
4300
+ function importNodeModule(id) {
4301
+ return import(id);
4302
+ }
4303
+ function getCurrentModulePath$1() {
4304
+ const originalPrepareStackTrace = Error.prepareStackTrace;
4305
+ try {
4306
+ Error.prepareStackTrace = (_error, callSites) => callSites;
4307
+ const error = /* @__PURE__ */ new Error("Capture current module path");
4308
+ Error.captureStackTrace(error, getCurrentModulePath$1);
4309
+ const [caller] = error.stack;
4310
+ const fileName = caller == null ? void 0 : caller.getFileName();
4311
+ if (fileName == null) throw new Error("Unable to determine the current module path");
4312
+ return fileName;
4313
+ } finally {
4314
+ Error.prepareStackTrace = originalPrepareStackTrace;
4315
+ }
4316
+ }
4317
+ var MAX_DOWNLOAD_REDIRECTS$2 = 10;
4318
+ async function getValidatedFetch$1(customFetch) {
4319
+ return customFetch == null || customFetch === globalThis.fetch ? await getDefaultDownloadFetch$1() : customFetch;
4320
+ }
4321
+ async function fetchWithValidatedRedirects$2({ url, headers, abortSignal, maxRedirects = MAX_DOWNLOAD_REDIRECTS$2, fetch: customFetch, trustedOrigin }) {
4322
+ var _a2;
4323
+ let currentHeaders = headers === void 0 ? void 0 : new Headers(headers);
4324
+ const perHopInit = (redirect) => ({
4325
+ signal: abortSignal,
4326
+ redirect,
4327
+ ...currentHeaders === void 0 ? {} : { headers: new Headers(currentHeaders) }
4328
+ });
4329
+ let currentUrl = url;
4330
+ for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
4331
+ const isTrustedHop = trustedOrigin !== void 0 && isSameOrigin$2(currentUrl, trustedOrigin);
4332
+ if (!isTrustedHop) validateDownloadUrl$2(currentUrl);
4333
+ const fetch = isTrustedHop && customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getValidatedFetch$1(customFetch);
4334
+ const response = await fetch(currentUrl, perHopInit("manual"));
4335
+ if (response.type === "opaqueredirect") {
4336
+ if (!isBrowserRuntime$2()) throw new DownloadError$2({
4337
+ url,
4338
+ message: `Redirect from ${currentUrl} could not be validated and was blocked`
4339
+ });
4340
+ return await fetch(currentUrl, perHopInit("follow"));
4341
+ }
4342
+ const location = (_a2 = response.headers) == null ? void 0 : _a2.get("location");
4343
+ if (response.status >= 300 && response.status < 400 && location) {
4344
+ cancelResponseBody$2(response);
4345
+ const nextUrl = new URL(location, currentUrl).toString();
4346
+ if (new URL(currentUrl).protocol === "https:" && new URL(nextUrl).protocol === "http:") throw new DownloadError$2({
4347
+ url,
4348
+ message: "Redirect from HTTPS to HTTP was blocked"
4349
+ });
4350
+ if (currentHeaders !== void 0 && !isSameOrigin$2(nextUrl, currentUrl)) {
4351
+ const userAgent = currentHeaders.get("user-agent");
4352
+ currentHeaders = new Headers(userAgent == null ? void 0 : { "user-agent": userAgent });
4353
+ }
4354
+ currentUrl = nextUrl;
4355
+ continue;
4356
+ }
4357
+ return response;
4358
+ }
4359
+ throw new DownloadError$2({
4360
+ url,
4361
+ message: `Too many redirects (max ${maxRedirects})`
4362
+ });
4363
+ }
4121
4364
  var DEFAULT_MAX_DOWNLOAD_SIZE$2 = 2147483648;
4122
4365
  async function readResponseWithSizeLimit$2({ response, url, maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE$2 }) {
4123
4366
  const contentLength = response.headers.get("content-length");
@@ -4271,13 +4514,21 @@ function withUserAgentSuffix$2(headers, ...userAgentSuffixParts) {
4271
4514
  normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
4272
4515
  return Object.fromEntries(normalizedHeaders.entries());
4273
4516
  }
4274
- var VERSION$8 = "3.0.44";
4517
+ var VERSION$8 = "3.0.46";
4275
4518
  var getOriginalFetch$3 = () => globalThis.fetch;
4276
- var getFromApi$2 = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch = getOriginalFetch$3() }) => {
4519
+ var getFromApi$2 = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, validateUrl, credentialedOrigin, trustedOrigin }) => {
4277
4520
  try {
4278
- const response = await fetch(url, {
4521
+ const requestFetch = fetch != null ? fetch : getOriginalFetch$3();
4522
+ const requestHeaders = withUserAgentSuffix$2(credentialedOrigin !== void 0 && !isSameOrigin$2(url, credentialedOrigin) ? {} : headers, `ai-sdk/provider-utils/${VERSION$8}`, getRuntimeEnvironmentUserAgent$2());
4523
+ const response = validateUrl ? await fetchWithValidatedRedirects$2({
4524
+ url,
4525
+ headers: requestHeaders,
4526
+ abortSignal,
4527
+ fetch,
4528
+ trustedOrigin
4529
+ }) : await requestFetch(url, {
4279
4530
  method: "GET",
4280
- headers: withUserAgentSuffix$2(headers, `ai-sdk/provider-utils/${VERSION$8}`, getRuntimeEnvironmentUserAgent$2()),
4531
+ headers: requestHeaders,
4281
4532
  signal: abortSignal
4282
4533
  });
4283
4534
  const responseHeaders = extractResponseHeaders$2(response);
@@ -5712,7 +5963,7 @@ function isArrayBuffer$2(value) {
5712
5963
  function withoutTrailingSlash$2(url) {
5713
5964
  return url == null ? void 0 : url.replace(/\/$/, "");
5714
5965
  }
5715
- // ../_vendored/ai_v5/dist/dist-Culynpd6.js
5966
+ // ../_vendored/ai_v5/dist/dist-Ds6WOguF.js
5716
5967
  function getContext$2() {
5717
5968
  return { headers: {} };
5718
5969
  }
@@ -5720,10 +5971,10 @@ async function getVercelOidcToken$2() {
5720
5971
  if (process.env.VERCEL_OIDC_TOKEN) return process.env.VERCEL_OIDC_TOKEN ?? "";
5721
5972
  throw new Error("@vercel/oidc is not available in the vendored @internal AI packages. Provide an API key instead.");
5722
5973
  }
5723
- var symbol$15 = Symbol.for("vercel.ai.gateway.error");
5974
+ var symbol$21 = Symbol.for("vercel.ai.gateway.error");
5724
5975
  var _a$4;
5725
5976
  var _b$3;
5726
- var GatewayError$2 = class _GatewayError extends (_b$3 = Error, _a$4 = symbol$15, _b$3) {
5977
+ var GatewayError$2 = class _GatewayError extends (_b$3 = Error, _a$4 = symbol$21, _b$3) {
5727
5978
  constructor({ message, statusCode = 500, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500) }) {
5728
5979
  super(message);
5729
5980
  this[_a$4] = true;
@@ -5740,11 +5991,11 @@ var GatewayError$2 = class _GatewayError extends (_b$3 = Error, _a$4 = symbol$15
5740
5991
  return _GatewayError.hasMarker(error);
5741
5992
  }
5742
5993
  static hasMarker(error) {
5743
- return typeof error === "object" && error !== null && symbol$15 in error && error[symbol$15] === true;
5994
+ return typeof error === "object" && error !== null && symbol$21 in error && error[symbol$21] === true;
5744
5995
  }
5745
5996
  };
5746
- var name$10 = "GatewayAuthenticationError";
5747
- var marker2$4 = `vercel.ai.gateway.error.${name$10}`;
5997
+ var name$19 = "GatewayAuthenticationError";
5998
+ var marker2$4 = `vercel.ai.gateway.error.${name$19}`;
5748
5999
  var symbol2$4 = Symbol.for(marker2$4);
5749
6000
  var _a2$4;
5750
6001
  var _b2$2;
@@ -5756,7 +6007,7 @@ var GatewayAuthenticationError$2 = class _GatewayAuthenticationError extends (_b
5756
6007
  cause
5757
6008
  });
5758
6009
  this[_a2$4] = true;
5759
- this.name = name$10;
6010
+ this.name = name$19;
5760
6011
  this.type = "authentication_error";
5761
6012
  }
5762
6013
  static isInstance(error) {
@@ -8633,12 +8884,12 @@ var object$3 = ({ schema: inputSchema }) => {
8633
8884
  }
8634
8885
  };
8635
8886
  };
8636
- // ../_vendored/ai_v6/dist/dist-DRzIKDJV.js
8637
- var marker$1$14 = "vercel.ai.error";
8638
- var symbol$1$15 = Symbol.for(marker$1$14);
8887
+ // ../_vendored/ai_v6/dist/dist-BoOIE3nE.js
8888
+ var marker$1$10 = "vercel.ai.error";
8889
+ var symbol$1$13 = Symbol.for(marker$1$10);
8639
8890
  var _a$1$1;
8640
8891
  var _b$1;
8641
- var AISDKError$1 = class _AISDKError extends (_b$1 = Error, _a$1$1 = symbol$1$15, _b$1) {
8892
+ var AISDKError$1 = class _AISDKError extends (_b$1 = Error, _a$1$1 = symbol$1$13, _b$1) {
8642
8893
  /**
8643
8894
  * Creates an AI SDK Error.
8644
8895
  *
@@ -8659,22 +8910,22 @@ var AISDKError$1 = class _AISDKError extends (_b$1 = Error, _a$1$1 = symbol$1$15
8659
8910
  * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
8660
8911
  */
8661
8912
  static isInstance(error) {
8662
- return _AISDKError.hasMarker(error, marker$1$14);
8913
+ return _AISDKError.hasMarker(error, marker$1$10);
8663
8914
  }
8664
8915
  static hasMarker(error, marker15) {
8665
8916
  const markerSymbol = Symbol.for(marker15);
8666
8917
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
8667
8918
  }
8668
8919
  };
8669
- var name$1$14 = "AI_APICallError";
8670
- var marker2$2 = `vercel.ai.error.${name$1$14}`;
8920
+ var name$1$10 = "AI_APICallError";
8921
+ var marker2$2 = `vercel.ai.error.${name$1$10}`;
8671
8922
  var symbol2$2 = Symbol.for(marker2$2);
8672
8923
  var _a2$2;
8673
8924
  var _b2$1;
8674
8925
  var APICallError$1 = class extends (_b2$1 = AISDKError$1, _a2$2 = symbol2$2, _b2$1) {
8675
8926
  constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
8676
8927
  super({
8677
- name: name$1$14,
8928
+ name: name$1$10,
8678
8929
  message,
8679
8930
  cause
8680
8931
  });
@@ -9057,15 +9308,15 @@ async function cancelResponseBody$1(response) {
9057
9308
  await ((_a2 = response.body) == null ? void 0 : _a2.cancel());
9058
9309
  } catch (e) {}
9059
9310
  }
9060
- var name$19 = "AI_DownloadError";
9061
- var marker$15 = `vercel.ai.error.${name$19}`;
9062
- var symbol$21 = Symbol.for(marker$15);
9311
+ var name$14 = "AI_DownloadError";
9312
+ var marker$13 = `vercel.ai.error.${name$14}`;
9313
+ var symbol$17 = Symbol.for(marker$13);
9063
9314
  var _a$2;
9064
9315
  var _b$2;
9065
- var DownloadError$1 = class extends (_b$2 = AISDKError$1, _a$2 = symbol$21, _b$2) {
9316
+ var DownloadError$1 = class extends (_b$2 = AISDKError$1, _a$2 = symbol$17, _b$2) {
9066
9317
  constructor({ url, statusCode, statusText, cause, message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}` }) {
9067
9318
  super({
9068
- name: name$19,
9319
+ name: name$14,
9069
9320
  message,
9070
9321
  cause
9071
9322
  });
@@ -9075,7 +9326,7 @@ var DownloadError$1 = class extends (_b$2 = AISDKError$1, _a$2 = symbol$21, _b$2
9075
9326
  this.statusText = statusText;
9076
9327
  }
9077
9328
  static isInstance(error) {
9078
- return AISDKError$1.hasMarker(error, marker$15);
9329
+ return AISDKError$1.hasMarker(error, marker$13);
9079
9330
  }
9080
9331
  };
9081
9332
  function isBrowserRuntime$1(globalThisAny = globalThis) {
@@ -9126,7 +9377,7 @@ function validateDownloadUrl$1(url) {
9126
9377
  });
9127
9378
  }
9128
9379
  }
9129
- function validateDownloadAddress$1({ address, family, hostname }) {
9380
+ function validateDownloadAddress({ address, family, hostname }) {
9130
9381
  if (family === 4 ? !isIPv4$1(address) || isPrivateIPv4$1(address) : family === 6 ? isPrivateIPv6$1(address) : true) throw new DownloadError$1({
9131
9382
  url: hostname,
9132
9383
  message: `Hostname ${hostname} resolved to disallowed IP address ${address}`
@@ -9204,7 +9455,7 @@ function isPrivateIPv6$1(ip) {
9204
9455
  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}`);
9205
9456
  return false;
9206
9457
  }
9207
- function createSafeLookup$1(lookup) {
9458
+ function createSafeLookup(lookup) {
9208
9459
  return ((hostname, options, callback) => {
9209
9460
  lookup(hostname, {
9210
9461
  ...options,
@@ -9217,7 +9468,7 @@ function createSafeLookup$1(lookup) {
9217
9468
  try {
9218
9469
  const [firstAddress] = addresses;
9219
9470
  if (firstAddress == null) throw new Error(`Hostname ${hostname} did not resolve to an address`);
9220
- for (const { address, family } of addresses) validateDownloadAddress$1({
9471
+ for (const { address, family } of addresses) validateDownloadAddress({
9221
9472
  address,
9222
9473
  family,
9223
9474
  hostname
@@ -9230,20 +9481,20 @@ function createSafeLookup$1(lookup) {
9230
9481
  });
9231
9482
  });
9232
9483
  }
9233
- var safeNodeFetchPromise$1;
9234
- function isNodeRuntime$2() {
9484
+ var safeNodeFetchPromise;
9485
+ function isNodeRuntime$1() {
9235
9486
  var _a2, _b2, _c;
9236
9487
  const runtimeProcess = globalThis.process;
9237
9488
  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;
9238
9489
  }
9239
- async function getDefaultDownloadFetch$1() {
9240
- if (!isNodeRuntime$2()) return globalThis.fetch;
9241
- return safeNodeFetchPromise$1 != null ? safeNodeFetchPromise$1 : safeNodeFetchPromise$1 = createSafeNodeFetch$1();
9490
+ async function getDefaultDownloadFetch() {
9491
+ if (!isNodeRuntime$1()) return globalThis.fetch;
9492
+ return safeNodeFetchPromise != null ? safeNodeFetchPromise : safeNodeFetchPromise = createSafeNodeFetch();
9242
9493
  }
9243
- async function createSafeNodeFetch$1() {
9494
+ async function createSafeNodeFetch() {
9244
9495
  const [module, { lookup }] = await Promise.all([loadNodeModule("node:module"), loadNodeModule("node:dns")]);
9245
- const { Agent, fetch } = module.createRequire(getCurrentModulePath$1())("undici");
9246
- const dispatcher = new Agent({ connect: { lookup: createSafeLookup$1(lookup) } });
9496
+ const { Agent, fetch } = module.createRequire(getCurrentModulePath())("undici");
9497
+ const dispatcher = new Agent({ connect: { lookup: createSafeLookup(lookup) } });
9247
9498
  return ((input, init) => fetch(input, {
9248
9499
  ...init,
9249
9500
  dispatcher
@@ -9256,12 +9507,12 @@ async function loadNodeModule(id) {
9256
9507
  if (builtinModule == null) throw new Error(`Node.js built-in module ${id} is unavailable`);
9257
9508
  return builtinModule;
9258
9509
  }
9259
- function getCurrentModulePath$1() {
9510
+ function getCurrentModulePath() {
9260
9511
  const originalPrepareStackTrace = Error.prepareStackTrace;
9261
9512
  try {
9262
9513
  Error.prepareStackTrace = (_error, callSites) => callSites;
9263
9514
  const error = /* @__PURE__ */ new Error("Capture current module path");
9264
- Error.captureStackTrace(error, getCurrentModulePath$1);
9515
+ Error.captureStackTrace(error, getCurrentModulePath);
9265
9516
  const [caller] = error.stack;
9266
9517
  const fileName = caller == null ? void 0 : caller.getFileName();
9267
9518
  if (fileName == null) throw new Error("Unable to determine the current module path");
@@ -9305,8 +9556,8 @@ var REDIRECT_STATUS_CODES$1 = /* @__PURE__ */ new Set([
9305
9556
  307,
9306
9557
  308
9307
9558
  ]);
9308
- async function getValidatedFetch$1(customFetch) {
9309
- return customFetch == null || customFetch === globalThis.fetch ? await getDefaultDownloadFetch$1() : customFetch;
9559
+ async function getValidatedFetch(customFetch) {
9560
+ return customFetch == null || customFetch === globalThis.fetch ? await getDefaultDownloadFetch() : customFetch;
9310
9561
  }
9311
9562
  async function fetchWithValidatedRedirects$1({ url, headers, abortSignal, maxRedirects = MAX_DOWNLOAD_REDIRECTS$1, fetch: customFetch, trustedOrigin }) {
9312
9563
  var _a2;
@@ -9323,7 +9574,7 @@ async function fetchWithValidatedRedirects$1({ url, headers, abortSignal, maxRed
9323
9574
  for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
9324
9575
  const isTrustedHop = trustedOrigin !== void 0 && isSameOrigin$1(currentUrl, trustedOrigin);
9325
9576
  if (!isTrustedHop) validateDownloadUrl$1(currentUrl);
9326
- const fetch = isTrustedHop && customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getValidatedFetch$1(customFetch);
9577
+ const fetch = isTrustedHop && customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getValidatedFetch(customFetch);
9327
9578
  const response = await fetch(currentUrl, perHopInit("manual"));
9328
9579
  if (response.type === "opaqueredirect") {
9329
9580
  if (!isBrowserRuntime$1()) throw new DownloadError$1({
@@ -9336,6 +9587,10 @@ async function fetchWithValidatedRedirects$1({ url, headers, abortSignal, maxRed
9336
9587
  if (REDIRECT_STATUS_CODES$1.has(response.status) && location) {
9337
9588
  cancelResponseBody$1(response);
9338
9589
  const nextUrl = new URL(location, currentUrl).toString();
9590
+ if (new URL(currentUrl).protocol === "https:" && new URL(nextUrl).protocol === "http:") throw new DownloadError$1({
9591
+ url,
9592
+ message: "Redirect from HTTPS to HTTP was blocked"
9593
+ });
9339
9594
  if (currentHeaders !== void 0 && !isSameOrigin$1(nextUrl, currentUrl)) {
9340
9595
  const userAgent = currentHeaders.get("user-agent");
9341
9596
  currentHeaders = new Headers(userAgent == null ? void 0 : { "user-agent": userAgent });
@@ -9505,7 +9760,7 @@ function withUserAgentSuffix$1(headers, ...userAgentSuffixParts) {
9505
9760
  normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
9506
9761
  return Object.fromEntries(normalizedHeaders.entries());
9507
9762
  }
9508
- var VERSION$5 = "4.0.64";
9763
+ var VERSION$5 = "4.0.66";
9509
9764
  var getOriginalFetch$1 = () => globalThis.fetch;
9510
9765
  var getFromApi$1 = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, validateUrl, credentialedOrigin, trustedOrigin }) => {
9511
9766
  try {
@@ -10981,7 +11236,7 @@ var createJsonResponseHandler$1 = (responseSchema) => async ({ response, url, re
10981
11236
  function withoutTrailingSlash$1(url) {
10982
11237
  return url == null ? void 0 : url.replace(/\/$/, "");
10983
11238
  }
10984
- // ../_vendored/ai_v6/dist/dist-wBEpLSG4.js
11239
+ // ../_vendored/ai_v6/dist/dist-ByO0vuJJ.js
10985
11240
  function getContext$1() {
10986
11241
  return { headers: {} };
10987
11242
  }
@@ -10989,10 +11244,10 @@ async function getVercelOidcToken$1() {
10989
11244
  if (process.env.VERCEL_OIDC_TOKEN) return process.env.VERCEL_OIDC_TOKEN ?? "";
10990
11245
  throw new Error("@vercel/oidc is not available in the vendored @internal AI packages. Provide an API key instead.");
10991
11246
  }
10992
- var symbol$20 = Symbol.for("vercel.ai.gateway.error");
11247
+ var symbol$14 = Symbol.for("vercel.ai.gateway.error");
10993
11248
  var _a$1;
10994
11249
  var _b;
10995
- var GatewayError$1 = class _GatewayError extends (_b = Error, _a$1 = symbol$20, _b) {
11250
+ var GatewayError$1 = class _GatewayError extends (_b = Error, _a$1 = symbol$14, _b) {
10996
11251
  constructor({ message, statusCode = 500, cause, generationId, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500) }) {
10997
11252
  super(generationId ? `${message} [${generationId}]` : message);
10998
11253
  this[_a$1] = true;
@@ -11010,11 +11265,11 @@ var GatewayError$1 = class _GatewayError extends (_b = Error, _a$1 = symbol$20,
11010
11265
  return _GatewayError.hasMarker(error);
11011
11266
  }
11012
11267
  static hasMarker(error) {
11013
- return typeof error === "object" && error !== null && symbol$20 in error && error[symbol$20] === true;
11268
+ return typeof error === "object" && error !== null && symbol$14 in error && error[symbol$14] === true;
11014
11269
  }
11015
11270
  };
11016
- var name$18 = "GatewayAuthenticationError";
11017
- var marker2$1 = `vercel.ai.gateway.error.${name$18}`;
11271
+ var name$13 = "GatewayAuthenticationError";
11272
+ var marker2$1 = `vercel.ai.gateway.error.${name$13}`;
11018
11273
  var symbol2$1 = Symbol.for(marker2$1);
11019
11274
  var _a2$1;
11020
11275
  var _b2;
@@ -11027,7 +11282,7 @@ var GatewayAuthenticationError$1 = class _GatewayAuthenticationError extends (_b
11027
11282
  generationId
11028
11283
  });
11029
11284
  this[_a2$1] = true;
11030
- this.name = name$18;
11285
+ this.name = name$13;
11031
11286
  this.type = "authentication_error";
11032
11287
  }
11033
11288
  static isInstance(error) {
@@ -13956,14 +14211,14 @@ var __export = (target, all) => {
13956
14211
  enumerable: true
13957
14212
  });
13958
14213
  };
13959
- var name$12 = "AI_InvalidArgumentError";
13960
- var marker$12 = `vercel.ai.error.${name$12}`;
13961
- var symbol$19 = Symbol.for(marker$12);
14214
+ var name$10 = "AI_InvalidArgumentError";
14215
+ var marker$10 = `vercel.ai.error.${name$10}`;
14216
+ var symbol$13 = Symbol.for(marker$10);
13962
14217
  var _a;
13963
14218
  var InvalidArgumentError$2 = class extends AISDKError$1 {
13964
14219
  constructor({ parameter, value, message }) {
13965
14220
  super({
13966
- name: name$12,
14221
+ name: name$10,
13967
14222
  message: `Invalid argument for parameter ${parameter}: ${message}`
13968
14223
  });
13969
14224
  this[_a] = true;
@@ -13971,10 +14226,10 @@ var InvalidArgumentError$2 = class extends AISDKError$1 {
13971
14226
  this.value = value;
13972
14227
  }
13973
14228
  static isInstance(error) {
13974
- return AISDKError$1.hasMarker(error, marker$12);
14229
+ return AISDKError$1.hasMarker(error, marker$10);
13975
14230
  }
13976
14231
  };
13977
- _a = symbol$19;
14232
+ _a = symbol$13;
13978
14233
  var name9 = "AI_NoObjectGeneratedError";
13979
14234
  var marker9 = `vercel.ai.error.${name9}`;
13980
14235
  var symbol9 = Symbol.for(marker9);
@@ -15306,13 +15561,13 @@ createIdGenerator$1({
15306
15561
  prefix: "aiobj",
15307
15562
  size: 24
15308
15563
  });
15309
- // ../_vendored/ai_v7/dist/dist-MpcKalG3.js
15564
+ // ../_vendored/ai_v7/dist/dist-C-C3A1Ts.js
15310
15565
  /**
15311
15566
  * Symbol used for identifying AI SDK Error instances.
15312
15567
  * Enables checking if an error is an instance of AISDKError across package versions.
15313
15568
  */
15314
- const marker$16 = "vercel.ai.error";
15315
- const symbol$16 = Symbol.for(marker$16);
15569
+ const marker$18 = "vercel.ai.error";
15570
+ const symbol$18 = Symbol.for(marker$18);
15316
15571
  /**
15317
15572
  * Custom error class for AI SDK related errors.
15318
15573
  * @extends Error
@@ -15328,7 +15583,7 @@ var AISDKError = class AISDKError extends Error {
15328
15583
  */
15329
15584
  constructor({ name, message, cause }) {
15330
15585
  super(message);
15331
- this[symbol$16] = true;
15586
+ this[symbol$18] = true;
15332
15587
  this.name = name;
15333
15588
  this.cause = cause;
15334
15589
  }
@@ -15338,24 +15593,24 @@ var AISDKError = class AISDKError extends Error {
15338
15593
  * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
15339
15594
  */
15340
15595
  static isInstance(error) {
15341
- return AISDKError.hasMarker(error, marker$16);
15596
+ return AISDKError.hasMarker(error, marker$18);
15342
15597
  }
15343
15598
  static hasMarker(error, marker) {
15344
15599
  const markerSymbol = Symbol.for(marker);
15345
15600
  return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
15346
15601
  }
15347
15602
  };
15348
- const name$14 = "AI_APICallError";
15349
- const marker$14 = `vercel.ai.error.${name$14}`;
15350
- const symbol$14 = Symbol.for(marker$14);
15603
+ const name$16 = "AI_APICallError";
15604
+ const marker$16 = `vercel.ai.error.${name$16}`;
15605
+ const symbol$16 = Symbol.for(marker$16);
15351
15606
  var APICallError = class extends AISDKError {
15352
15607
  constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
15353
15608
  super({
15354
- name: name$14,
15609
+ name: name$16,
15355
15610
  message,
15356
15611
  cause
15357
15612
  });
15358
- this[symbol$14] = true;
15613
+ this[symbol$16] = true;
15359
15614
  this.url = url;
15360
15615
  this.requestBodyValues = requestBodyValues;
15361
15616
  this.statusCode = statusCode;
@@ -15365,22 +15620,22 @@ var APICallError = class extends AISDKError {
15365
15620
  this.data = data;
15366
15621
  }
15367
15622
  static isInstance(error) {
15368
- return AISDKError.hasMarker(error, marker$14);
15623
+ return AISDKError.hasMarker(error, marker$16);
15369
15624
  }
15370
15625
  };
15371
- const name$13 = "AI_EmptyResponseBodyError";
15372
- const marker$13 = `vercel.ai.error.${name$13}`;
15373
- const symbol$13 = Symbol.for(marker$13);
15626
+ const name$15 = "AI_EmptyResponseBodyError";
15627
+ const marker$15 = `vercel.ai.error.${name$15}`;
15628
+ const symbol$15 = Symbol.for(marker$15);
15374
15629
  var EmptyResponseBodyError = class extends AISDKError {
15375
15630
  constructor({ message = "Empty response body" } = {}) {
15376
15631
  super({
15377
- name: name$13,
15632
+ name: name$15,
15378
15633
  message
15379
15634
  });
15380
- this[symbol$13] = true;
15635
+ this[symbol$15] = true;
15381
15636
  }
15382
15637
  static isInstance(error) {
15383
- return AISDKError.hasMarker(error, marker$13);
15638
+ return AISDKError.hasMarker(error, marker$15);
15384
15639
  }
15385
15640
  };
15386
15641
  function getErrorMessage(error) {
@@ -15508,20 +15763,20 @@ var TypeValidationError = class TypeValidationError extends AISDKError {
15508
15763
  });
15509
15764
  }
15510
15765
  };
15511
- const name$16 = "AI_UnsupportedFunctionalityError";
15512
- const marker$17 = `vercel.ai.error.${name$16}`;
15513
- const symbol$17 = Symbol.for(marker$17);
15766
+ const name$18 = "AI_UnsupportedFunctionalityError";
15767
+ const marker$19 = `vercel.ai.error.${name$18}`;
15768
+ const symbol$19 = Symbol.for(marker$19);
15514
15769
  var UnsupportedFunctionalityError = class extends AISDKError {
15515
15770
  constructor({ functionality, message = `'${functionality}' functionality not supported.` }) {
15516
15771
  super({
15517
- name: name$16,
15772
+ name: name$18,
15518
15773
  message
15519
15774
  });
15520
- this[symbol$17] = true;
15775
+ this[symbol$19] = true;
15521
15776
  this.functionality = functionality;
15522
15777
  }
15523
15778
  static isInstance(error) {
15524
- return AISDKError.hasMarker(error, marker$17);
15779
+ return AISDKError.hasMarker(error, marker$19);
15525
15780
  }
15526
15781
  };
15527
15782
  var ParseError = class extends Error {
@@ -16007,7 +16262,7 @@ function handleFetchError({ error, url, requestBodyValues }) {
16007
16262
  }
16008
16263
  return error;
16009
16264
  }
16010
- const VERSION$2 = "5.0.74";
16265
+ const VERSION$2 = "5.0.81";
16011
16266
  /**
16012
16267
  * Normalizes different header inputs into a plain record with lower-case keys.
16013
16268
  * Entries with `undefined` or `null` values are removed.
@@ -16110,11 +16365,54 @@ function isSameOrigin(url, baseUrl) {
16110
16365
  }
16111
16366
  }
16112
16367
  /**
16368
+ * Request headers stripped before fetching an untrusted URL: host/virtual-host
16369
+ * routing, proxy/origin spoofing, cloud-metadata, cookies, and hop-by-hop
16370
+ * transport headers (RFC 7230 §6.1).
16371
+ *
16372
+ * `Authorization` and other credential-bearing caller headers (e.g. `x-key`)
16373
+ * are intentionally not listed because trusted provider requests may need
16374
+ * them. `fetchUntrustedUrl` separately restricts an untrusted first hop to an
16375
+ * explicit allowlist of non-credential request metadata. Both it and
16376
+ * `fetchWithValidatedRedirects` drop all caller headers except the user-agent
16377
+ * on a cross-origin redirect.
16378
+ */
16379
+ const BLOCKED_REQUEST_HEADERS = [
16380
+ "connection",
16381
+ "keep-alive",
16382
+ "te",
16383
+ "trailer",
16384
+ "transfer-encoding",
16385
+ "upgrade",
16386
+ "host",
16387
+ "forwarded",
16388
+ "proxy-authorization",
16389
+ "via",
16390
+ "x-forwarded-for",
16391
+ "x-forwarded-host",
16392
+ "x-forwarded-proto",
16393
+ "x-real-ip",
16394
+ "metadata",
16395
+ "metadata-flavor",
16396
+ "x-aws-ec2-metadata-token",
16397
+ "x-metadata-token",
16398
+ "cookie",
16399
+ "set-cookie"
16400
+ ];
16401
+ /**
16402
+ * Returns a fresh `Headers` built from `input` with {@link BLOCKED_REQUEST_HEADERS}
16403
+ * removed. The input is never mutated.
16404
+ */
16405
+ function sanitizeRequestHeaders(input) {
16406
+ const headers = new Headers(input);
16407
+ for (const name of BLOCKED_REQUEST_HEADERS) headers.delete(name);
16408
+ return headers;
16409
+ }
16410
+ /**
16113
16411
  * Validates that a URL is safe to download from, blocking private/internal addresses
16114
16412
  * to prevent SSRF attacks.
16115
16413
  *
16116
- * Note: this function performs string/literal-IP checks only. The Node.js
16117
- * download fetch additionally validates and pins DNS results at connect time.
16414
+ * This function performs string/literal-IP checks only. DNS validation must
16415
+ * be provided by the fetch transport or network egress controls.
16118
16416
  *
16119
16417
  * @param url - The URL string to validate.
16120
16418
  * @throws DownloadError if the URL is unsafe.
@@ -16157,16 +16455,6 @@ function validateDownloadUrl(url) {
16157
16455
  });
16158
16456
  }
16159
16457
  }
16160
- /**
16161
- * Validates an address returned by DNS before it is used to open a socket.
16162
- * This is intentionally not exported from the package entry point.
16163
- */
16164
- function validateDownloadAddress({ address, family, hostname }) {
16165
- if (family === 4 ? !isIPv4(address) || isPrivateIPv4(address) : family === 6 ? isPrivateIPv6(address) : true) throw new DownloadError({
16166
- url: hostname,
16167
- message: `Hostname ${hostname} resolved to disallowed IP address ${address}`
16168
- });
16169
- }
16170
16458
  function isIPv4(hostname) {
16171
16459
  const parts = hostname.split(".");
16172
16460
  if (parts.length !== 4) return false;
@@ -16250,119 +16538,6 @@ function isPrivateIPv6(ip) {
16250
16538
  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}`);
16251
16539
  return false;
16252
16540
  }
16253
- /**
16254
- * Creates a DNS lookup hook that validates every returned address before
16255
- * returning the callback shape requested by the HTTP connector. Because
16256
- * resolution and validation happen inside the connector, the socket is pinned
16257
- * to the validated result and DNS rebinding cannot introduce a second lookup.
16258
- */
16259
- function createSafeLookup(lookup) {
16260
- return ((hostname, options, callback) => {
16261
- lookup(hostname, {
16262
- ...options,
16263
- all: true
16264
- }, (error, addresses) => {
16265
- if (error) {
16266
- callback(error);
16267
- return;
16268
- }
16269
- try {
16270
- const [firstAddress] = addresses;
16271
- if (firstAddress == null) throw new Error(`Hostname ${hostname} did not resolve to an address`);
16272
- for (const { address, family } of addresses) validateDownloadAddress({
16273
- address,
16274
- family,
16275
- hostname
16276
- });
16277
- if (options.all === true) callback(null, addresses);
16278
- else callback(null, firstAddress.address, firstAddress.family);
16279
- } catch (error) {
16280
- callback(error instanceof Error ? error : new Error(String(error)));
16281
- }
16282
- });
16283
- });
16284
- }
16285
- let safeNodeFetchPromise;
16286
- function isNodeRuntime$1() {
16287
- const runtimeProcess = globalThis.process;
16288
- return runtimeProcess?.release?.name === "node" && runtimeProcess.versions?.bun == null && runtimeProcess.versions?.deno == null && runtimeProcess.title !== "workerd" && globalThis.EdgeRuntime == null;
16289
- }
16290
- async function getDefaultDownloadFetch() {
16291
- if (!isNodeRuntime$1()) return globalThis.fetch;
16292
- return safeNodeFetchPromise ??= Promise.resolve().then(createSafeNodeFetch);
16293
- }
16294
- function createSafeNodeFetch() {
16295
- const module = loadBuiltinModule$1("node:module");
16296
- const { lookup } = loadBuiltinModule$1("node:dns");
16297
- const { Agent, fetch } = module.createRequire(getCurrentModulePath())("undici");
16298
- const dispatcher = new Agent({ connect: { lookup: createSafeLookup(lookup) } });
16299
- return ((input, init) => fetch(input, {
16300
- ...init,
16301
- dispatcher
16302
- }));
16303
- }
16304
- function loadBuiltinModule$1(id) {
16305
- const builtinModule = globalThis.process?.getBuiltinModule?.(id);
16306
- if (builtinModule == null) throw new Error(`Node.js built-in module ${id} is unavailable`);
16307
- return builtinModule;
16308
- }
16309
- function getCurrentModulePath() {
16310
- const originalPrepareStackTrace = Error.prepareStackTrace;
16311
- try {
16312
- Error.prepareStackTrace = (_error, callSites) => callSites;
16313
- const error = /* @__PURE__ */ new Error("Capture current module path");
16314
- Error.captureStackTrace(error, getCurrentModulePath);
16315
- const [caller] = error.stack;
16316
- const fileName = caller?.getFileName();
16317
- if (fileName == null) throw new Error("Unable to determine the current module path");
16318
- return fileName;
16319
- } finally {
16320
- Error.prepareStackTrace = originalPrepareStackTrace;
16321
- }
16322
- }
16323
- /**
16324
- * Request headers stripped before fetching an untrusted URL: host/virtual-host
16325
- * routing, proxy/origin spoofing, cloud-metadata, cookies, and hop-by-hop
16326
- * transport headers (RFC 7230 §6.1).
16327
- *
16328
- * `Authorization` and other credential-bearing caller headers (e.g. `x-key`)
16329
- * are intentionally not listed because trusted provider requests may need
16330
- * them. `fetchUntrustedUrl` separately restricts an untrusted first hop to an
16331
- * explicit allowlist of non-credential request metadata. Both it and
16332
- * `fetchWithValidatedRedirects` drop all caller headers except the user-agent
16333
- * on a cross-origin redirect.
16334
- */
16335
- const BLOCKED_REQUEST_HEADERS = [
16336
- "connection",
16337
- "keep-alive",
16338
- "te",
16339
- "trailer",
16340
- "transfer-encoding",
16341
- "upgrade",
16342
- "host",
16343
- "forwarded",
16344
- "proxy-authorization",
16345
- "via",
16346
- "x-forwarded-for",
16347
- "x-forwarded-host",
16348
- "x-forwarded-proto",
16349
- "x-real-ip",
16350
- "metadata",
16351
- "metadata-flavor",
16352
- "x-aws-ec2-metadata-token",
16353
- "x-metadata-token",
16354
- "cookie",
16355
- "set-cookie"
16356
- ];
16357
- /**
16358
- * Returns a fresh `Headers` built from `input` with {@link BLOCKED_REQUEST_HEADERS}
16359
- * removed. The input is never mutated.
16360
- */
16361
- function sanitizeRequestHeaders(input) {
16362
- const headers = new Headers(input);
16363
- for (const name of BLOCKED_REQUEST_HEADERS) headers.delete(name);
16364
- return headers;
16365
- }
16366
16541
  const MAX_DOWNLOAD_REDIRECTS = 10;
16367
16542
  const REDIRECT_STATUS_CODES = /* @__PURE__ */ new Set([
16368
16543
  301,
@@ -16371,9 +16546,6 @@ const REDIRECT_STATUS_CODES = /* @__PURE__ */ new Set([
16371
16546
  307,
16372
16547
  308
16373
16548
  ]);
16374
- async function getValidatedFetch(customFetch) {
16375
- return customFetch == null || customFetch === globalThis.fetch ? await getDefaultDownloadFetch() : customFetch;
16376
- }
16377
16549
  /**
16378
16550
  * Fetches a URL while enforcing the download guard on every hop.
16379
16551
  *
@@ -16383,6 +16555,9 @@ async function getValidatedFetch(customFetch) {
16383
16555
  * target (e.g. an internal address) before we ever see its URL, defeating the
16384
16556
  * guard.
16385
16557
  *
16558
+ * Manually followed redirects from HTTPS to HTTP are rejected before requesting
16559
+ * the target.
16560
+ *
16386
16561
  * Request headers are also protected: {@link sanitizeRequestHeaders} strips
16387
16562
  * proxy/metadata/cookie/hop-by-hop headers before the first request, and all
16388
16563
  * caller headers except `User-Agent` are dropped on a cross-origin redirect.
@@ -16412,11 +16587,8 @@ async function getValidatedFetch(customFetch) {
16412
16587
  * The returned response is the final (non-redirect) response. The caller is
16413
16588
  * responsible for checking `response.ok` and reading the body.
16414
16589
  *
16415
- * On Node.js, the default fetch resolves every hostname through a validating
16416
- * lookup hook and passes those exact addresses to the connector, preventing
16417
- * hostname-to-private-IP and DNS-rebinding bypasses. An injected fetch is
16418
- * responsible for equivalent connect-time validation. Other runtimes should
16419
- * constrain egress at the network layer when handling untrusted URLs.
16590
+ * URL validation does not resolve DNS. Use guarded-fetch on Node.js
16591
+ * for connection-time DNS validation, or enforce network egress restrictions.
16420
16592
  *
16421
16593
  * @throws DownloadError if a hop is unsafe, the redirect limit is exceeded, or
16422
16594
  * a redirect cannot be validated on a non-browser runtime.
@@ -16433,9 +16605,8 @@ async function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedir
16433
16605
  };
16434
16606
  let currentUrl = url;
16435
16607
  for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
16436
- const isTrustedHop = trustedOrigin !== void 0 && isSameOrigin(currentUrl, trustedOrigin);
16437
- if (!isTrustedHop) validateDownloadUrl(currentUrl);
16438
- const fetch = isTrustedHop && customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getValidatedFetch(customFetch);
16608
+ if (!(trustedOrigin !== void 0 && isSameOrigin(currentUrl, trustedOrigin))) validateDownloadUrl(currentUrl);
16609
+ const fetch = customFetch ?? globalThis.fetch;
16439
16610
  const response = await fetch(currentUrl, perHopInit("manual"));
16440
16611
  if (response.type === "opaqueredirect") {
16441
16612
  if (!isBrowserRuntime()) throw new DownloadError({
@@ -16448,6 +16619,10 @@ async function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedir
16448
16619
  if (REDIRECT_STATUS_CODES.has(response.status) && location) {
16449
16620
  cancelResponseBody(response);
16450
16621
  const nextUrl = new URL(location, currentUrl).toString();
16622
+ if (new URL(currentUrl).protocol === "https:" && new URL(nextUrl).protocol === "http:") throw new DownloadError({
16623
+ url,
16624
+ message: "Redirect from HTTPS to HTTP was blocked"
16625
+ });
16451
16626
  if (currentHeaders !== void 0 && !isSameOrigin(nextUrl, currentUrl)) {
16452
16627
  const userAgent = currentHeaders.get("user-agent");
16453
16628
  currentHeaders = new Headers(userAgent == null ? void 0 : { "user-agent": userAgent });
@@ -16484,10 +16659,13 @@ const DEFAULT_MAX_DOWNLOAD_SIZE = 2147483648;
16484
16659
  * @param response - The fetch Response to read.
16485
16660
  * @param url - The URL being downloaded (used in error messages).
16486
16661
  * @param maxBytes - Maximum allowed bytes. Defaults to DEFAULT_MAX_DOWNLOAD_SIZE.
16662
+ * @param onChunk - Optional. Receives each chunk instead of the chunks being
16663
+ * collected, so the body is not held in memory, and the returned array is empty.
16664
+ * The chunk may be a view on a larger buffer, copy what you keep.
16487
16665
  * @returns A Uint8Array containing the response body.
16488
16666
  * @throws DownloadError if the response exceeds maxBytes.
16489
16667
  */
16490
- async function readResponseWithSizeLimit({ response, url, maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE }) {
16668
+ async function readResponseWithSizeLimit({ response, url, maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE, onChunk }) {
16491
16669
  const contentLength = response.headers.get("content-length");
16492
16670
  if (contentLength != null) {
16493
16671
  const length = parseInt(contentLength, 10);
@@ -16513,6 +16691,10 @@ async function readResponseWithSizeLimit({ response, url, maxBytes = DEFAULT_MAX
16513
16691
  url,
16514
16692
  message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes.`
16515
16693
  });
16694
+ if (onChunk != null) {
16695
+ onChunk(value);
16696
+ continue;
16697
+ }
16516
16698
  chunks.push(value.byteLength < value.buffer.byteLength ? new Uint8Array(value) : value);
16517
16699
  }
16518
16700
  } finally {
@@ -16522,7 +16704,7 @@ async function readResponseWithSizeLimit({ response, url, maxBytes = DEFAULT_MAX
16522
16704
  reader.releaseLock();
16523
16705
  }
16524
16706
  }
16525
- const result = new Uint8Array(totalBytes);
16707
+ const result = new Uint8Array(onChunk != null ? 0 : totalBytes);
16526
16708
  let offset = 0;
16527
16709
  for (const chunk of chunks) {
16528
16710
  result.set(chunk, offset);
@@ -17687,6 +17869,7 @@ function zod3Schema(zodSchema, options) {
17687
17869
  } });
17688
17870
  }
17689
17871
  function zod4Schema(zodSchema, options) {
17872
+ if (!(0, zod_v4_core.config)().localeError) (0, zod_v4_core.config)((0, zod_v4_locales_en_js.default)());
17690
17873
  const useReferences = options?.useReferences ?? false;
17691
17874
  return jsonSchema(() => addAdditionalPropertiesToJsonSchema((0, zod_v4_core.toJSONSchema)(zodSchema, {
17692
17875
  target: "draft-7",
@@ -17918,12 +18101,27 @@ const postToApi = async ({ url, headers = {}, body, successfulResponseHandler, f
17918
18101
  function tool(tool) {
17919
18102
  return tool;
17920
18103
  }
17921
- function createProviderExecutedToolFactory({ id, inputSchema, outputSchema, supportsDeferredResults }) {
18104
+ const telemetryRedaction = Symbol.for("vercel.ai.telemetry.redact");
18105
+ /**
18106
+ * Attach a provider-owned telemetry view without changing the original value.
18107
+ * The annotation is not serialized or included in enumerable application data.
18108
+ * Keep the annotated object when forwarding tool arguments or provider metadata.
18109
+ */
18110
+ function withTelemetryRedaction(value, redact) {
18111
+ return Object.create(Object.getPrototypeOf(value), {
18112
+ ...Object.getOwnPropertyDescriptors(value),
18113
+ [telemetryRedaction]: {
18114
+ value: redact,
18115
+ configurable: true
18116
+ }
18117
+ });
18118
+ }
18119
+ function createProviderExecutedToolFactory({ id, inputSchema, outputSchema, supportsDeferredResults, redactArgs }) {
17922
18120
  return ({ onInputStart, onInputDelta, onInputAvailable, ...args }) => tool({
17923
18121
  type: "provider",
17924
18122
  isProviderExecuted: true,
17925
18123
  id,
17926
- args,
18124
+ args: redactArgs == null ? args : withTelemetryRedaction(args, redactArgs),
17927
18125
  inputSchema,
17928
18126
  outputSchema,
17929
18127
  onInputStart,
@@ -17989,6 +18187,286 @@ async function retryWithExponentialBackoffInternal(f, { maxRetries, delayInMs, b
17989
18187
  });
17990
18188
  }
17991
18189
  }
18190
+ /**
18191
+ * Streaming extraction of large base64 strings from a JSON response body.
18192
+ *
18193
+ * A JSON response that carries an image or a file is mostly one very long
18194
+ * base64 string. The regular pipeline (collect chunks, concatenate, decode to
18195
+ * text, `JSON.parse`, decode base64) holds about four copies of that string at
18196
+ * once. The scanner reads the body chunk by chunk instead: strings at the
18197
+ * configured paths are decoded to bytes while they stream in, and the text that
18198
+ * is handed to `JSON.parse` (the "skeleton") holds a short placeholder in their
18199
+ * place.
18200
+ *
18201
+ * - The skeleton is the original body except for the extracted strings, so
18202
+ * `secureJsonParse` still sees every key (a base64 string cannot contain a
18203
+ * quote, so it cannot hide one).
18204
+ * - A string is extracted only if it is canonical standard-alphabet base64
18205
+ * (length divisible by 4, `=` only as the final padding, zero trailing bits,
18206
+ * no escape sequences or whitespace). The bytes are then exactly what `atob`
18207
+ * gives for it. Everything else stays a string. What was decoded before a
18208
+ * string turned out not to qualify is encoded back, which gives the original
18209
+ * characters.
18210
+ */
18211
+ /** Strings that decode to fewer bytes stay strings. */
18212
+ const DEFAULT_BINARY_FIELD_MIN_BYTES = 65536;
18213
+ const QUOTE = 34;
18214
+ const BACKSLASH = 92;
18215
+ const EQUALS = 61;
18216
+ const COMMA = 44;
18217
+ const COLON = 58;
18218
+ const LEFT_BRACE = 123;
18219
+ const RIGHT_BRACE = 125;
18220
+ const LEFT_BRACKET = 91;
18221
+ const RIGHT_BRACKET = 93;
18222
+ const OUTSIDE = 0;
18223
+ const KEY = 1;
18224
+ const SKIP = 2;
18225
+ const BLOB = 3;
18226
+ /**
18227
+ * Compiles paths such as `images[*]` or `content[*].data.data`: plain object
18228
+ * keys (letters, digits, `_` and `-`) joined by `.`, and `[*]` for every
18229
+ * element of an array. Keys are compared with the raw bytes of the key in the
18230
+ * body, so a key written with an escape sequence never matches.
18231
+ */
18232
+ function compileBinaryFieldPaths(paths) {
18233
+ const root = /* @__PURE__ */ new Map();
18234
+ for (const path of paths) {
18235
+ if (!/^(?:[\w-]+|\[\*])(?:\.[\w-]+|\[\*])*$/.test(path)) throw new InvalidArgumentError$1({
18236
+ argument: "experimental_binaryFields",
18237
+ message: `Invalid binary field path "${path}"`
18238
+ });
18239
+ let node = root;
18240
+ for (const segment of path.match(/\[\*]|[\w-]+/g)) {
18241
+ const edges = segment === "[*]" ? [null] : new TextEncoder().encode(`${segment}"`);
18242
+ for (const edge of edges) {
18243
+ let next = node.get(edge);
18244
+ if (next === void 0) node.set(edge, next = /* @__PURE__ */ new Map());
18245
+ node = next;
18246
+ }
18247
+ }
18248
+ node.set(true, node);
18249
+ }
18250
+ return root;
18251
+ }
18252
+ function join$2(parts, length) {
18253
+ const bytes = new Uint8Array(length);
18254
+ let at = 0;
18255
+ for (const part of parts) {
18256
+ bytes.set(part, at);
18257
+ at += part.length;
18258
+ }
18259
+ return bytes;
18260
+ }
18261
+ function createJsonBinaryFieldScanner(paths, minBytes = DEFAULT_BINARY_FIELD_MIN_BYTES) {
18262
+ const sextet = (/* @__PURE__ */ new Uint8Array(256)).fill(64);
18263
+ for (let index = 0; index < 64; index++) sextet["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(index)] = index;
18264
+ const encoder = new TextEncoder();
18265
+ const pieces = [];
18266
+ let piece = /* @__PURE__ */ new Uint8Array(65536);
18267
+ let pieceLength = 0;
18268
+ let size = 0;
18269
+ const binaries = /* @__PURE__ */ new Map();
18270
+ const frames = [];
18271
+ let skipped = 0;
18272
+ let mode = OUTSIDE;
18273
+ let escaped = false;
18274
+ let last = 0;
18275
+ let key;
18276
+ let segments = [];
18277
+ let segment = /* @__PURE__ */ new Uint8Array(0);
18278
+ let at = 0;
18279
+ let total = 0;
18280
+ let bits = 0;
18281
+ let chars = 0;
18282
+ let padding = 0;
18283
+ const add = (bytes) => {
18284
+ for (let offset = 0; offset < bytes.length;) {
18285
+ const length = Math.min(piece.length - pieceLength, bytes.length - offset);
18286
+ piece.set(bytes.subarray(offset, offset + length), pieceLength);
18287
+ pieceLength += length;
18288
+ offset += length;
18289
+ size += length;
18290
+ if (pieceLength === piece.length) {
18291
+ pieces.push(piece);
18292
+ piece = /* @__PURE__ */ new Uint8Array(65536);
18293
+ pieceLength = 0;
18294
+ }
18295
+ }
18296
+ };
18297
+ const emit = (chunk, start, end) => add(chunk.subarray(start, end));
18298
+ const reset = () => {
18299
+ segments = [];
18300
+ segment = /* @__PURE__ */ new Uint8Array(0);
18301
+ at = 0;
18302
+ total = 0;
18303
+ bits = 0;
18304
+ chars = 0;
18305
+ padding = 0;
18306
+ };
18307
+ const grow = () => {
18308
+ if (at > 0) segments.push(segment.subarray(0, at));
18309
+ segment = new Uint8Array(Math.min(Math.max(total, 4096), 4 << 20));
18310
+ at = 0;
18311
+ };
18312
+ const rest = () => bits << (4 - chars) * 6;
18313
+ const restore = () => {
18314
+ for (const part of [...segments, segment.subarray(0, at)]) add(encoder.encode(convertUint8ArrayToBase64(part)));
18315
+ const group = rest();
18316
+ add(encoder.encode(convertUint8ArrayToBase64(Uint8Array.of(group >> 16, group >> 8, group)).slice(0, chars) + "=".repeat(padding)));
18317
+ reset();
18318
+ };
18319
+ const closeBlob = () => {
18320
+ mode = OUTSIDE;
18321
+ const tail = chars && chars - 1;
18322
+ if (padding === (4 - chars) % 4 && !(bits & (1 << (4 - chars) * 2) - 1) && total + tail >= minBytes) {
18323
+ const group = rest();
18324
+ const bytes = join$2([...segments, segment.subarray(0, at)], total + tail);
18325
+ for (let index = 0; index < tail; index++) bytes[total + index] = group >> 16 - 8 * index;
18326
+ const placeholder = `[binary data: ${bytes.length} bytes; ref ${crypto.getRandomValues(/* @__PURE__ */ new Uint32Array(2)).join("-")}]`;
18327
+ binaries.set(placeholder, bytes);
18328
+ add(encoder.encode(placeholder));
18329
+ reset();
18330
+ } else restore();
18331
+ };
18332
+ const push = (chunk) => {
18333
+ let from = 0;
18334
+ const { length } = chunk;
18335
+ for (let index = 0; index < length; index++) {
18336
+ let byte = chunk[index];
18337
+ if (mode === BLOB) {
18338
+ if (padding === 0) {
18339
+ let pending = bits;
18340
+ let count = chars;
18341
+ for (let value; index < length && (value = sextet[chunk[index]]) < 64; index++) {
18342
+ pending = pending << 6 | value;
18343
+ if (++count === 4) {
18344
+ if (at + 3 > segment.length) grow();
18345
+ segment[at++] = pending >> 16;
18346
+ segment[at++] = pending >> 8;
18347
+ segment[at++] = pending;
18348
+ total += 3;
18349
+ pending = 0;
18350
+ count = 0;
18351
+ }
18352
+ }
18353
+ bits = pending;
18354
+ chars = count;
18355
+ }
18356
+ if (index >= length) break;
18357
+ byte = chunk[index];
18358
+ if (byte === QUOTE) {
18359
+ closeBlob();
18360
+ from = index;
18361
+ } else if (byte === EQUALS && chars > 1 && padding < 4 - chars) padding++;
18362
+ else {
18363
+ restore();
18364
+ mode = SKIP;
18365
+ from = index--;
18366
+ }
18367
+ } else if (mode !== OUTSIDE) {
18368
+ if (mode === KEY) key = key?.get(byte);
18369
+ if (escaped) escaped = false;
18370
+ else if (byte === BACKSLASH) escaped = true;
18371
+ else if (byte === QUOTE) {
18372
+ if (mode === KEY) frames.at(-1).next = key;
18373
+ mode = OUTSIDE;
18374
+ }
18375
+ } else if (byte === QUOTE) {
18376
+ const frame = frames.at(-1);
18377
+ if (skipped > 0) mode = SKIP;
18378
+ else if (frame?.keys && (last === LEFT_BRACE || last === COMMA)) {
18379
+ mode = KEY;
18380
+ key = frame.keys;
18381
+ } else if ((frame ? frame.next : paths)?.get(true)) {
18382
+ mode = BLOB;
18383
+ emit(chunk, from, index + 1);
18384
+ } else mode = SKIP;
18385
+ } else if (byte === LEFT_BRACE || byte === LEFT_BRACKET) {
18386
+ last = byte;
18387
+ const frame = frames.at(-1);
18388
+ const node = skipped > 0 ? void 0 : frame ? frame.next : paths;
18389
+ const items = node?.get(null);
18390
+ if (byte === LEFT_BRACE && node) frames.push({ keys: node });
18391
+ else if (byte === LEFT_BRACKET && items) frames.push({
18392
+ keys: null,
18393
+ next: items
18394
+ });
18395
+ else skipped++;
18396
+ } else if (byte === RIGHT_BRACE || byte === RIGHT_BRACKET) {
18397
+ if (skipped > 0) skipped--;
18398
+ else frames.pop();
18399
+ } else if (byte === COMMA || byte === COLON) last = byte;
18400
+ }
18401
+ if (mode !== BLOB) emit(chunk, from, length);
18402
+ };
18403
+ const finish = () => {
18404
+ if (mode === BLOB) restore();
18405
+ return {
18406
+ text: new TextDecoder().decode(join$2([...pieces, piece.subarray(0, pieceLength)], size)),
18407
+ binaries
18408
+ };
18409
+ };
18410
+ return {
18411
+ push,
18412
+ finish
18413
+ };
18414
+ }
18415
+ /**
18416
+ * Replaces the placeholders in a parsed value with the bytes they stand for.
18417
+ * Objects and arrays are copied, the parsed value is not modified. A
18418
+ * placeholder holds a random number, so a string that equals one is ours.
18419
+ */
18420
+ function replaceBinaryFieldPlaceholders(value, binaries) {
18421
+ if (typeof value === "string") return binaries.get(value) ?? value;
18422
+ if (Array.isArray(value)) return value.map((item) => replaceBinaryFieldPlaceholders(item, binaries));
18423
+ if (value != null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([name, item]) => [name, replaceBinaryFieldPlaceholders(item, binaries)]));
18424
+ return value;
18425
+ }
18426
+ /**
18427
+ * Makes `JSON.stringify` give the placeholder for each of the arrays, instead
18428
+ * of `{"0":…,"1":…}` with an entry for every byte: 24 MiB of bytes would
18429
+ * become a string of more than 300 MB. That is what a validator, or the code
18430
+ * that reports its issues, does with a value it puts into an error message.
18431
+ * The property is not enumerable, so the arrays look the same otherwise.
18432
+ * Returns the function that removes it again.
18433
+ */
18434
+ function maskBinariesInJson(binaries) {
18435
+ for (const [placeholder, bytes] of binaries) Object.defineProperty(bytes, "toJSON", {
18436
+ value: () => placeholder,
18437
+ configurable: true
18438
+ });
18439
+ return () => {
18440
+ for (const bytes of binaries.values()) Reflect.deleteProperty(bytes, "toJSON");
18441
+ };
18442
+ }
18443
+ /**
18444
+ * Wraps a schema so that it validates the extracted bytes in place of their
18445
+ * placeholders. The value parsed from the skeleton, and the value of the
18446
+ * validation error of the response, keep the placeholders: reporting an error
18447
+ * never prints the bytes.
18448
+ *
18449
+ * The errors of the schema itself may hold the bytes: a Standard Schema
18450
+ * validator wraps the value it was given into an error, and the issues it
18451
+ * reports may carry the offending input. So that their messages do not grow
18452
+ * with the image, the arrays stringify as their placeholders, and keep doing
18453
+ * so as long as an error can refer to them. When the validation succeeds the
18454
+ * arrays are plain again, for whoever receives them.
18455
+ */
18456
+ function withBinaryFields(schema, binaries) {
18457
+ if (binaries.size === 0) return schema;
18458
+ const actualSchema = asSchema(schema);
18459
+ return jsonSchema({}, { validate: async (value) => {
18460
+ const replaced = replaceBinaryFieldPlaceholders(value, binaries);
18461
+ const unmask = maskBinariesInJson(binaries);
18462
+ const result = actualSchema.validate ? await actualSchema.validate(replaced) : {
18463
+ success: true,
18464
+ value: replaced
18465
+ };
18466
+ if (result.success) unmask();
18467
+ return result;
18468
+ } });
18469
+ }
17992
18470
  const textDecoder = new TextDecoder();
17993
18471
  const DEFAULT_MAX_JSON_LINE_BYTES = 67108864;
17994
18472
  function wrapResponseBodyStream({ stream, url, requestBodyValues, statusCode, responseHeaders }) {
@@ -18111,29 +18589,45 @@ const createEventSourceResponseHandler = (chunkSchema) => async ({ response, url
18111
18589
  })
18112
18590
  };
18113
18591
  };
18114
- const createJsonResponseHandler = (responseSchema) => async ({ response, url, requestBodyValues }) => {
18115
- const responseBody = await readResponseBodyAsText({
18116
- response,
18117
- url
18118
- });
18119
- const parsedResult = await safeParseJSON({
18120
- text: responseBody,
18121
- schema: responseSchema
18122
- });
18123
- const responseHeaders = extractResponseHeaders(response);
18124
- if (!parsedResult.success) throw new APICallError({
18125
- message: "Invalid JSON response",
18126
- cause: parsedResult.error,
18127
- statusCode: response.status,
18128
- responseHeaders,
18129
- responseBody,
18130
- url,
18131
- requestBodyValues
18132
- });
18133
- return {
18134
- responseHeaders,
18135
- value: parsedResult.value,
18136
- rawValue: parsedResult.rawValue
18592
+ const createJsonResponseHandler = (responseSchema, { experimental_binaryFields } = {}) => {
18593
+ const binaryFieldPaths = experimental_binaryFields?.length ? compileBinaryFieldPaths(experimental_binaryFields) : void 0;
18594
+ return async ({ response, url, requestBodyValues }) => {
18595
+ let responseBody;
18596
+ let schema = responseSchema;
18597
+ if (binaryFieldPaths == null) responseBody = await readResponseBodyAsText({
18598
+ response,
18599
+ url
18600
+ });
18601
+ else {
18602
+ const scanner = createJsonBinaryFieldScanner(binaryFieldPaths);
18603
+ await readResponseWithSizeLimit({
18604
+ response,
18605
+ url,
18606
+ onChunk: scanner.push
18607
+ });
18608
+ const scanned = scanner.finish();
18609
+ responseBody = scanned.text;
18610
+ schema = withBinaryFields(responseSchema, scanned.binaries);
18611
+ }
18612
+ const parsedResult = await safeParseJSON({
18613
+ text: responseBody,
18614
+ schema
18615
+ });
18616
+ const responseHeaders = extractResponseHeaders(response);
18617
+ if (!parsedResult.success) throw new APICallError({
18618
+ message: "Invalid JSON response",
18619
+ cause: parsedResult.error,
18620
+ statusCode: response.status,
18621
+ responseHeaders,
18622
+ responseBody,
18623
+ url,
18624
+ requestBodyValues
18625
+ });
18626
+ return {
18627
+ responseHeaders,
18628
+ value: parsedResult.value,
18629
+ rawValue: parsedResult.rawValue
18630
+ };
18137
18631
  };
18138
18632
  };
18139
18633
  const createJsonLinesResponseHandler = (responseSchema, { maxLineBytes = DEFAULT_MAX_JSON_LINE_BYTES } = {}) => {
@@ -18217,20 +18711,20 @@ function isJSONSerializable(value) {
18217
18711
  if (Object.getPrototypeOf(value) === Object.prototype) return Object.values(value).every(isJSONSerializable);
18218
18712
  return false;
18219
18713
  }
18220
- const name$17 = "AI_SerializationError";
18221
- const marker$18 = `vercel.ai.error.${name$17}`;
18222
- const symbol$18 = Symbol.for(marker$18);
18714
+ const name$12 = "AI_SerializationError";
18715
+ const marker$12 = `vercel.ai.error.${name$12}`;
18716
+ const symbol$12 = Symbol.for(marker$12);
18223
18717
  var SerializationError = class extends AISDKError {
18224
18718
  constructor({ message = "Failed to serialize value.", cause } = {}) {
18225
18719
  super({
18226
- name: name$17,
18720
+ name: name$12,
18227
18721
  message,
18228
18722
  cause
18229
18723
  });
18230
- this[symbol$18] = true;
18724
+ this[symbol$12] = true;
18231
18725
  }
18232
18726
  static isInstance(error) {
18233
- return AISDKError.hasMarker(error, marker$18);
18727
+ return AISDKError.hasMarker(error, marker$12);
18234
18728
  }
18235
18729
  };
18236
18730
  /**
@@ -18498,7 +18992,7 @@ function isSegment(value) {
18498
18992
  function withoutTrailingSlash(url) {
18499
18993
  return url?.replace(/\/$/, "");
18500
18994
  }
18501
- // ../_vendored/ai_v7/dist/dist-Db_s9sSk.js
18995
+ // ../_vendored/ai_v7/dist/dist-BKjca_9x.js
18502
18996
  /**
18503
18997
  * Symbol used to define custom serialization for user-defined class instances.
18504
18998
  * The static method should accept an instance and return serializable data.
@@ -42891,4 +43385,4 @@ Object.defineProperty(exports, "wrapInObservationGroup", {
42891
43385
  }
42892
43386
  });
42893
43387
 
42894
- //# sourceMappingURL=src-BLniLryu.cjs.map
43388
+ //# sourceMappingURL=src-IZtKjicq.cjs.map