@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.
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +94 -94
- package/dist/docs/references/docs-harness-background-tasks.md +53 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/processors/index.cjs +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/{src-Xhctgeae.js → src-BkElV36S.js} +762 -269
- package/dist/src-BkElV36S.js.map +1 -0
- package/dist/{src-BLniLryu.cjs → src-IZtKjicq.cjs} +762 -268
- package/dist/src-IZtKjicq.cjs.map +1 -0
- package/package.json +8 -8
- package/dist/src-BLniLryu.cjs.map +0 -1
- package/dist/src-Xhctgeae.js.map +0 -1
- /package/dist/_types/{@internal_ai-sdk-v4@0.0.96 → @internal_ai-sdk-v4@0.0.97}/dist/index.d.ts +0 -0
- /package/dist/_types/{@internal_ai-sdk-v4@0.0.96 → @internal_ai-sdk-v4@0.0.97}/package.json +0 -0
|
@@ -2,7 +2,8 @@ import { ZodFirstPartyTypeKind } from "zod/v3";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import * as z4 from "zod/v4";
|
|
4
4
|
import { any, array, boolean, custom, discriminatedUnion, enum as enum$1, instanceof as instanceof$1, json, lazy, literal, looseObject, never, null as null$1, number, object, record, safeParseAsync, string, union, unknown, z as z$1 } from "zod/v4";
|
|
5
|
-
import { toJSONSchema } from "zod/v4/core";
|
|
5
|
+
import { config, toJSONSchema } from "zod/v4/core";
|
|
6
|
+
import en from "zod/v4/locales/en.js";
|
|
6
7
|
import { Agent, MessageList } from "@mastra/core/agent";
|
|
7
8
|
import { ErrorCategory, ErrorDomain, MastraError, classifyProviderError } from "@mastra/core/error";
|
|
8
9
|
import { coreFeatures } from "@mastra/core/features";
|
|
@@ -2782,8 +2783,8 @@ var UnsupportedModelVersionError$3 = class extends AISDKError$3 {
|
|
|
2782
2783
|
}
|
|
2783
2784
|
};
|
|
2784
2785
|
var name$21 = "AI_InvalidArgumentError";
|
|
2785
|
-
var marker$
|
|
2786
|
-
var symbol$
|
|
2786
|
+
var marker$20 = `vercel.ai.error.${name$21}`;
|
|
2787
|
+
var symbol$24 = Symbol.for(marker$20);
|
|
2787
2788
|
var _a$6;
|
|
2788
2789
|
var InvalidArgumentError$6 = class extends AISDKError$3 {
|
|
2789
2790
|
constructor({ parameter, value, message }) {
|
|
@@ -2796,10 +2797,10 @@ var InvalidArgumentError$6 = class extends AISDKError$3 {
|
|
|
2796
2797
|
this.value = value;
|
|
2797
2798
|
}
|
|
2798
2799
|
static isInstance(error) {
|
|
2799
|
-
return AISDKError$3.hasMarker(error, marker$
|
|
2800
|
+
return AISDKError$3.hasMarker(error, marker$20);
|
|
2800
2801
|
}
|
|
2801
2802
|
};
|
|
2802
|
-
_a$6 = symbol$
|
|
2803
|
+
_a$6 = symbol$24;
|
|
2803
2804
|
var name2$6 = "AI_RetryError";
|
|
2804
2805
|
var marker2$6 = `vercel.ai.error.${name2$6}`;
|
|
2805
2806
|
var symbol2$6 = Symbol.for(marker2$6);
|
|
@@ -3689,12 +3690,12 @@ function trimStartOfStream() {
|
|
|
3689
3690
|
return text2;
|
|
3690
3691
|
};
|
|
3691
3692
|
}
|
|
3692
|
-
// ../_vendored/ai_v5/dist/dist-
|
|
3693
|
-
var marker$1$
|
|
3694
|
-
var symbol$1$
|
|
3693
|
+
// ../_vendored/ai_v5/dist/dist-DIfsHMRS.js
|
|
3694
|
+
var marker$1$11 = "vercel.ai.error";
|
|
3695
|
+
var symbol$1$21 = Symbol.for(marker$1$11);
|
|
3695
3696
|
var _a$1$2;
|
|
3696
3697
|
var _b$1$4;
|
|
3697
|
-
var AISDKError$2 = class _AISDKError extends (_b$1$4 = Error, _a$1$2 = symbol$1$
|
|
3698
|
+
var AISDKError$2 = class _AISDKError extends (_b$1$4 = Error, _a$1$2 = symbol$1$21, _b$1$4) {
|
|
3698
3699
|
/**
|
|
3699
3700
|
* Creates an AI SDK Error.
|
|
3700
3701
|
*
|
|
@@ -3715,22 +3716,22 @@ var AISDKError$2 = class _AISDKError extends (_b$1$4 = Error, _a$1$2 = symbol$1$
|
|
|
3715
3716
|
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
|
|
3716
3717
|
*/
|
|
3717
3718
|
static isInstance(error) {
|
|
3718
|
-
return _AISDKError.hasMarker(error, marker$1$
|
|
3719
|
+
return _AISDKError.hasMarker(error, marker$1$11);
|
|
3719
3720
|
}
|
|
3720
3721
|
static hasMarker(error, marker15) {
|
|
3721
3722
|
const markerSymbol = Symbol.for(marker15);
|
|
3722
3723
|
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
3723
3724
|
}
|
|
3724
3725
|
};
|
|
3725
|
-
var name$1$
|
|
3726
|
-
var marker2$5 = `vercel.ai.error.${name$1$
|
|
3726
|
+
var name$1$19 = "AI_APICallError";
|
|
3727
|
+
var marker2$5 = `vercel.ai.error.${name$1$19}`;
|
|
3727
3728
|
var symbol2$5 = Symbol.for(marker2$5);
|
|
3728
3729
|
var _a2$5;
|
|
3729
3730
|
var _b2$3;
|
|
3730
3731
|
var APICallError$2 = class extends (_b2$3 = AISDKError$2, _a2$5 = symbol2$5, _b2$3) {
|
|
3731
3732
|
constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
|
|
3732
3733
|
super({
|
|
3733
|
-
name: name$1$
|
|
3734
|
+
name: name$1$19,
|
|
3734
3735
|
message,
|
|
3735
3736
|
cause
|
|
3736
3737
|
});
|
|
@@ -4069,15 +4070,15 @@ function createAbortError$2() {
|
|
|
4069
4070
|
function extractResponseHeaders$2(response) {
|
|
4070
4071
|
return Object.fromEntries([...response.headers]);
|
|
4071
4072
|
}
|
|
4072
|
-
var name$
|
|
4073
|
-
var marker$
|
|
4074
|
-
var symbol$
|
|
4073
|
+
var name$20 = "AI_DownloadError";
|
|
4074
|
+
var marker$17 = `vercel.ai.error.${name$20}`;
|
|
4075
|
+
var symbol$22 = Symbol.for(marker$17);
|
|
4075
4076
|
var _a$5;
|
|
4076
4077
|
var _b$5;
|
|
4077
|
-
var DownloadError$2 = class extends (_b$5 = AISDKError$2, _a$5 = symbol$
|
|
4078
|
+
var DownloadError$2 = class extends (_b$5 = AISDKError$2, _a$5 = symbol$22, _b$5) {
|
|
4078
4079
|
constructor({ url, statusCode, statusText, cause, message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}` }) {
|
|
4079
4080
|
super({
|
|
4080
|
-
name: name$
|
|
4081
|
+
name: name$20,
|
|
4081
4082
|
message,
|
|
4082
4083
|
cause
|
|
4083
4084
|
});
|
|
@@ -4087,7 +4088,7 @@ var DownloadError$2 = class extends (_b$5 = AISDKError$2, _a$5 = symbol$24, _b$5
|
|
|
4087
4088
|
this.statusText = statusText;
|
|
4088
4089
|
}
|
|
4089
4090
|
static isInstance(error) {
|
|
4090
|
-
return AISDKError$2.hasMarker(error, marker$
|
|
4091
|
+
return AISDKError$2.hasMarker(error, marker$17);
|
|
4091
4092
|
}
|
|
4092
4093
|
};
|
|
4093
4094
|
var EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL$2 = /* @__PURE__ */ Symbol.for("vercel.ai.embeddingModel.maxInputBytesPerCall");
|
|
@@ -4097,6 +4098,247 @@ async function cancelResponseBody$2(response) {
|
|
|
4097
4098
|
await ((_a2 = response.body) == null ? void 0 : _a2.cancel());
|
|
4098
4099
|
} catch (e) {}
|
|
4099
4100
|
}
|
|
4101
|
+
function isBrowserRuntime$2(globalThisAny = globalThis) {
|
|
4102
|
+
return globalThisAny.window != null;
|
|
4103
|
+
}
|
|
4104
|
+
function isSameOrigin$2(url, baseUrl) {
|
|
4105
|
+
try {
|
|
4106
|
+
return new URL(url).origin === new URL(baseUrl).origin;
|
|
4107
|
+
} catch (e) {
|
|
4108
|
+
return false;
|
|
4109
|
+
}
|
|
4110
|
+
}
|
|
4111
|
+
function validateDownloadUrl$2(url) {
|
|
4112
|
+
let parsed;
|
|
4113
|
+
try {
|
|
4114
|
+
parsed = new URL(url);
|
|
4115
|
+
} catch (e) {
|
|
4116
|
+
throw new DownloadError$2({
|
|
4117
|
+
url,
|
|
4118
|
+
message: `Invalid URL: ${url}`
|
|
4119
|
+
});
|
|
4120
|
+
}
|
|
4121
|
+
if (parsed.protocol === "data:") return;
|
|
4122
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new DownloadError$2({
|
|
4123
|
+
url,
|
|
4124
|
+
message: `URL scheme must be http, https, or data, got ${parsed.protocol}`
|
|
4125
|
+
});
|
|
4126
|
+
const hostname = parsed.hostname.toLowerCase().replace(/\.+$/, "");
|
|
4127
|
+
if (!hostname) throw new DownloadError$2({
|
|
4128
|
+
url,
|
|
4129
|
+
message: `URL must have a hostname`
|
|
4130
|
+
});
|
|
4131
|
+
if (hostname === "localhost" || hostname.endsWith(".local") || hostname.endsWith(".localhost") || hostname.endsWith(".internal")) throw new DownloadError$2({
|
|
4132
|
+
url,
|
|
4133
|
+
message: `URL with hostname ${hostname} is not allowed`
|
|
4134
|
+
});
|
|
4135
|
+
if (hostname.startsWith("[") && hostname.endsWith("]")) {
|
|
4136
|
+
if (isPrivateIPv6$2(hostname.slice(1, -1))) throw new DownloadError$2({
|
|
4137
|
+
url,
|
|
4138
|
+
message: `URL with IPv6 address ${hostname} is not allowed`
|
|
4139
|
+
});
|
|
4140
|
+
return;
|
|
4141
|
+
}
|
|
4142
|
+
if (isIPv4$2(hostname)) {
|
|
4143
|
+
if (isPrivateIPv4$2(hostname)) throw new DownloadError$2({
|
|
4144
|
+
url,
|
|
4145
|
+
message: `URL with IP address ${hostname} is not allowed`
|
|
4146
|
+
});
|
|
4147
|
+
}
|
|
4148
|
+
}
|
|
4149
|
+
function validateDownloadAddress$1({ address, family, hostname }) {
|
|
4150
|
+
if (family === 4 ? !isIPv4$2(address) || isPrivateIPv4$2(address) : family === 6 ? isPrivateIPv6$2(address) : true) throw new DownloadError$2({
|
|
4151
|
+
url: hostname,
|
|
4152
|
+
message: `Hostname ${hostname} resolved to disallowed IP address ${address}`
|
|
4153
|
+
});
|
|
4154
|
+
}
|
|
4155
|
+
function isIPv4$2(hostname) {
|
|
4156
|
+
const parts = hostname.split(".");
|
|
4157
|
+
if (parts.length !== 4) return false;
|
|
4158
|
+
return parts.every((part) => {
|
|
4159
|
+
const num = Number(part);
|
|
4160
|
+
return Number.isInteger(num) && num >= 0 && num <= 255 && String(num) === part;
|
|
4161
|
+
});
|
|
4162
|
+
}
|
|
4163
|
+
function isPrivateIPv4$2(ip) {
|
|
4164
|
+
const [a, b, c] = ip.split(".").map(Number);
|
|
4165
|
+
if (a === 0) return true;
|
|
4166
|
+
if (a === 10) return true;
|
|
4167
|
+
if (a === 100 && b >= 64 && b <= 127) return true;
|
|
4168
|
+
if (a === 127) return true;
|
|
4169
|
+
if (a === 169 && b === 254) return true;
|
|
4170
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
4171
|
+
if (a === 192 && b === 0 && c === 0) return true;
|
|
4172
|
+
if (a === 192 && b === 168) return true;
|
|
4173
|
+
if (a === 198 && (b === 18 || b === 19)) return true;
|
|
4174
|
+
if (a >= 240) return true;
|
|
4175
|
+
return false;
|
|
4176
|
+
}
|
|
4177
|
+
function parseIPv6$2(ip) {
|
|
4178
|
+
let address = ip.toLowerCase();
|
|
4179
|
+
const zoneIndex = address.indexOf("%");
|
|
4180
|
+
if (zoneIndex !== -1) address = address.slice(0, zoneIndex);
|
|
4181
|
+
const halves = address.split("::");
|
|
4182
|
+
if (halves.length > 2) return null;
|
|
4183
|
+
const toGroups = (segment) => {
|
|
4184
|
+
if (segment === "") return [];
|
|
4185
|
+
const groups = [];
|
|
4186
|
+
const parts = segment.split(":");
|
|
4187
|
+
for (let i = 0; i < parts.length; i++) {
|
|
4188
|
+
const part = parts[i];
|
|
4189
|
+
if (part.includes(".")) {
|
|
4190
|
+
if (i !== parts.length - 1 || !isIPv4$2(part)) return null;
|
|
4191
|
+
const [a, b, c, d] = part.split(".").map(Number);
|
|
4192
|
+
groups.push(a << 8 | b, c << 8 | d);
|
|
4193
|
+
continue;
|
|
4194
|
+
}
|
|
4195
|
+
if (!/^[0-9a-f]{1,4}$/.test(part)) return null;
|
|
4196
|
+
groups.push(parseInt(part, 16));
|
|
4197
|
+
}
|
|
4198
|
+
return groups;
|
|
4199
|
+
};
|
|
4200
|
+
const head = toGroups(halves[0]);
|
|
4201
|
+
if (head === null) return null;
|
|
4202
|
+
if (halves.length === 2) {
|
|
4203
|
+
const tail = toGroups(halves[1]);
|
|
4204
|
+
if (tail === null) return null;
|
|
4205
|
+
const fill = 8 - head.length - tail.length;
|
|
4206
|
+
if (fill < 0) return null;
|
|
4207
|
+
return [
|
|
4208
|
+
...head,
|
|
4209
|
+
...new Array(fill).fill(0),
|
|
4210
|
+
...tail
|
|
4211
|
+
];
|
|
4212
|
+
}
|
|
4213
|
+
return head.length === 8 ? head : null;
|
|
4214
|
+
}
|
|
4215
|
+
function isPrivateIPv6$2(ip) {
|
|
4216
|
+
const groups = parseIPv6$2(ip);
|
|
4217
|
+
if (groups === null) return true;
|
|
4218
|
+
const topZero = (count) => groups.slice(0, count).every((group) => group === 0);
|
|
4219
|
+
if (topZero(7) && (groups[7] === 0 || groups[7] === 1)) return true;
|
|
4220
|
+
if ((groups[0] & 65024) === 64512) return true;
|
|
4221
|
+
if ((groups[0] & 65472) === 65152) return true;
|
|
4222
|
+
if ((groups[0] & 65472) === 65216) return true;
|
|
4223
|
+
if ((groups[0] & 65280) === 65280) return true;
|
|
4224
|
+
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}`);
|
|
4225
|
+
return false;
|
|
4226
|
+
}
|
|
4227
|
+
function createSafeLookup$1(lookup) {
|
|
4228
|
+
return ((hostname, options, callback) => {
|
|
4229
|
+
lookup(hostname, {
|
|
4230
|
+
...options,
|
|
4231
|
+
all: true
|
|
4232
|
+
}, (error, addresses) => {
|
|
4233
|
+
if (error) {
|
|
4234
|
+
callback(error);
|
|
4235
|
+
return;
|
|
4236
|
+
}
|
|
4237
|
+
try {
|
|
4238
|
+
const [firstAddress] = addresses;
|
|
4239
|
+
if (firstAddress == null) throw new Error(`Hostname ${hostname} did not resolve to an address`);
|
|
4240
|
+
for (const { address, family } of addresses) validateDownloadAddress$1({
|
|
4241
|
+
address,
|
|
4242
|
+
family,
|
|
4243
|
+
hostname
|
|
4244
|
+
});
|
|
4245
|
+
if (options.all === true) callback(null, addresses);
|
|
4246
|
+
else callback(null, firstAddress.address, firstAddress.family);
|
|
4247
|
+
} catch (error2) {
|
|
4248
|
+
callback(error2 instanceof Error ? error2 : new Error(String(error2)));
|
|
4249
|
+
}
|
|
4250
|
+
});
|
|
4251
|
+
});
|
|
4252
|
+
}
|
|
4253
|
+
var safeNodeFetchPromise$1;
|
|
4254
|
+
function isNodeRuntime$2() {
|
|
4255
|
+
var _a2, _b2, _c;
|
|
4256
|
+
const runtimeProcess = globalThis.process;
|
|
4257
|
+
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;
|
|
4258
|
+
}
|
|
4259
|
+
async function getDefaultDownloadFetch$1() {
|
|
4260
|
+
if (!isNodeRuntime$2()) return globalThis.fetch;
|
|
4261
|
+
return safeNodeFetchPromise$1 != null ? safeNodeFetchPromise$1 : safeNodeFetchPromise$1 = createSafeNodeFetch$1();
|
|
4262
|
+
}
|
|
4263
|
+
async function createSafeNodeFetch$1() {
|
|
4264
|
+
const [module, { lookup }] = await Promise.all([loadNodeModule$1("node:module"), loadNodeModule$1("node:dns")]);
|
|
4265
|
+
const { Agent, fetch } = module.createRequire(getCurrentModulePath$1())("undici");
|
|
4266
|
+
const dispatcher = new Agent({ connect: { lookup: createSafeLookup$1(lookup) } });
|
|
4267
|
+
return ((input, init) => fetch(input, {
|
|
4268
|
+
...init,
|
|
4269
|
+
dispatcher
|
|
4270
|
+
}));
|
|
4271
|
+
}
|
|
4272
|
+
async function loadNodeModule$1(id) {
|
|
4273
|
+
var _a2;
|
|
4274
|
+
const processWithBuiltins = globalThis.process;
|
|
4275
|
+
const builtinModule = (_a2 = processWithBuiltins == null ? void 0 : processWithBuiltins.getBuiltinModule) == null ? void 0 : _a2.call(processWithBuiltins, id);
|
|
4276
|
+
return builtinModule == null ? await importNodeModule(id) : builtinModule;
|
|
4277
|
+
}
|
|
4278
|
+
function importNodeModule(id) {
|
|
4279
|
+
return import(id);
|
|
4280
|
+
}
|
|
4281
|
+
function getCurrentModulePath$1() {
|
|
4282
|
+
const originalPrepareStackTrace = Error.prepareStackTrace;
|
|
4283
|
+
try {
|
|
4284
|
+
Error.prepareStackTrace = (_error, callSites) => callSites;
|
|
4285
|
+
const error = /* @__PURE__ */ new Error("Capture current module path");
|
|
4286
|
+
Error.captureStackTrace(error, getCurrentModulePath$1);
|
|
4287
|
+
const [caller] = error.stack;
|
|
4288
|
+
const fileName = caller == null ? void 0 : caller.getFileName();
|
|
4289
|
+
if (fileName == null) throw new Error("Unable to determine the current module path");
|
|
4290
|
+
return fileName;
|
|
4291
|
+
} finally {
|
|
4292
|
+
Error.prepareStackTrace = originalPrepareStackTrace;
|
|
4293
|
+
}
|
|
4294
|
+
}
|
|
4295
|
+
var MAX_DOWNLOAD_REDIRECTS$2 = 10;
|
|
4296
|
+
async function getValidatedFetch$1(customFetch) {
|
|
4297
|
+
return customFetch == null || customFetch === globalThis.fetch ? await getDefaultDownloadFetch$1() : customFetch;
|
|
4298
|
+
}
|
|
4299
|
+
async function fetchWithValidatedRedirects$2({ url, headers, abortSignal, maxRedirects = MAX_DOWNLOAD_REDIRECTS$2, fetch: customFetch, trustedOrigin }) {
|
|
4300
|
+
var _a2;
|
|
4301
|
+
let currentHeaders = headers === void 0 ? void 0 : new Headers(headers);
|
|
4302
|
+
const perHopInit = (redirect) => ({
|
|
4303
|
+
signal: abortSignal,
|
|
4304
|
+
redirect,
|
|
4305
|
+
...currentHeaders === void 0 ? {} : { headers: new Headers(currentHeaders) }
|
|
4306
|
+
});
|
|
4307
|
+
let currentUrl = url;
|
|
4308
|
+
for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
|
|
4309
|
+
const isTrustedHop = trustedOrigin !== void 0 && isSameOrigin$2(currentUrl, trustedOrigin);
|
|
4310
|
+
if (!isTrustedHop) validateDownloadUrl$2(currentUrl);
|
|
4311
|
+
const fetch = isTrustedHop && customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getValidatedFetch$1(customFetch);
|
|
4312
|
+
const response = await fetch(currentUrl, perHopInit("manual"));
|
|
4313
|
+
if (response.type === "opaqueredirect") {
|
|
4314
|
+
if (!isBrowserRuntime$2()) throw new DownloadError$2({
|
|
4315
|
+
url,
|
|
4316
|
+
message: `Redirect from ${currentUrl} could not be validated and was blocked`
|
|
4317
|
+
});
|
|
4318
|
+
return await fetch(currentUrl, perHopInit("follow"));
|
|
4319
|
+
}
|
|
4320
|
+
const location = (_a2 = response.headers) == null ? void 0 : _a2.get("location");
|
|
4321
|
+
if (response.status >= 300 && response.status < 400 && location) {
|
|
4322
|
+
cancelResponseBody$2(response);
|
|
4323
|
+
const nextUrl = new URL(location, currentUrl).toString();
|
|
4324
|
+
if (new URL(currentUrl).protocol === "https:" && new URL(nextUrl).protocol === "http:") throw new DownloadError$2({
|
|
4325
|
+
url,
|
|
4326
|
+
message: "Redirect from HTTPS to HTTP was blocked"
|
|
4327
|
+
});
|
|
4328
|
+
if (currentHeaders !== void 0 && !isSameOrigin$2(nextUrl, currentUrl)) {
|
|
4329
|
+
const userAgent = currentHeaders.get("user-agent");
|
|
4330
|
+
currentHeaders = new Headers(userAgent == null ? void 0 : { "user-agent": userAgent });
|
|
4331
|
+
}
|
|
4332
|
+
currentUrl = nextUrl;
|
|
4333
|
+
continue;
|
|
4334
|
+
}
|
|
4335
|
+
return response;
|
|
4336
|
+
}
|
|
4337
|
+
throw new DownloadError$2({
|
|
4338
|
+
url,
|
|
4339
|
+
message: `Too many redirects (max ${maxRedirects})`
|
|
4340
|
+
});
|
|
4341
|
+
}
|
|
4100
4342
|
var DEFAULT_MAX_DOWNLOAD_SIZE$2 = 2147483648;
|
|
4101
4343
|
async function readResponseWithSizeLimit$2({ response, url, maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE$2 }) {
|
|
4102
4344
|
const contentLength = response.headers.get("content-length");
|
|
@@ -4250,13 +4492,21 @@ function withUserAgentSuffix$2(headers, ...userAgentSuffixParts) {
|
|
|
4250
4492
|
normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
|
|
4251
4493
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
4252
4494
|
}
|
|
4253
|
-
var VERSION$8 = "3.0.
|
|
4495
|
+
var VERSION$8 = "3.0.46";
|
|
4254
4496
|
var getOriginalFetch$3 = () => globalThis.fetch;
|
|
4255
|
-
var getFromApi$2 = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch
|
|
4497
|
+
var getFromApi$2 = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, validateUrl, credentialedOrigin, trustedOrigin }) => {
|
|
4256
4498
|
try {
|
|
4257
|
-
const
|
|
4499
|
+
const requestFetch = fetch != null ? fetch : getOriginalFetch$3();
|
|
4500
|
+
const requestHeaders = withUserAgentSuffix$2(credentialedOrigin !== void 0 && !isSameOrigin$2(url, credentialedOrigin) ? {} : headers, `ai-sdk/provider-utils/${VERSION$8}`, getRuntimeEnvironmentUserAgent$2());
|
|
4501
|
+
const response = validateUrl ? await fetchWithValidatedRedirects$2({
|
|
4502
|
+
url,
|
|
4503
|
+
headers: requestHeaders,
|
|
4504
|
+
abortSignal,
|
|
4505
|
+
fetch,
|
|
4506
|
+
trustedOrigin
|
|
4507
|
+
}) : await requestFetch(url, {
|
|
4258
4508
|
method: "GET",
|
|
4259
|
-
headers:
|
|
4509
|
+
headers: requestHeaders,
|
|
4260
4510
|
signal: abortSignal
|
|
4261
4511
|
});
|
|
4262
4512
|
const responseHeaders = extractResponseHeaders$2(response);
|
|
@@ -5691,7 +5941,7 @@ function isArrayBuffer$2(value) {
|
|
|
5691
5941
|
function withoutTrailingSlash$2(url) {
|
|
5692
5942
|
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
5693
5943
|
}
|
|
5694
|
-
// ../_vendored/ai_v5/dist/dist-
|
|
5944
|
+
// ../_vendored/ai_v5/dist/dist-Ds6WOguF.js
|
|
5695
5945
|
function getContext$2() {
|
|
5696
5946
|
return { headers: {} };
|
|
5697
5947
|
}
|
|
@@ -5699,10 +5949,10 @@ async function getVercelOidcToken$2() {
|
|
|
5699
5949
|
if (process.env.VERCEL_OIDC_TOKEN) return process.env.VERCEL_OIDC_TOKEN ?? "";
|
|
5700
5950
|
throw new Error("@vercel/oidc is not available in the vendored @internal AI packages. Provide an API key instead.");
|
|
5701
5951
|
}
|
|
5702
|
-
var symbol$
|
|
5952
|
+
var symbol$21 = Symbol.for("vercel.ai.gateway.error");
|
|
5703
5953
|
var _a$4;
|
|
5704
5954
|
var _b$3;
|
|
5705
|
-
var GatewayError$2 = class _GatewayError extends (_b$3 = Error, _a$4 = symbol$
|
|
5955
|
+
var GatewayError$2 = class _GatewayError extends (_b$3 = Error, _a$4 = symbol$21, _b$3) {
|
|
5706
5956
|
constructor({ message, statusCode = 500, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500) }) {
|
|
5707
5957
|
super(message);
|
|
5708
5958
|
this[_a$4] = true;
|
|
@@ -5719,11 +5969,11 @@ var GatewayError$2 = class _GatewayError extends (_b$3 = Error, _a$4 = symbol$15
|
|
|
5719
5969
|
return _GatewayError.hasMarker(error);
|
|
5720
5970
|
}
|
|
5721
5971
|
static hasMarker(error) {
|
|
5722
|
-
return typeof error === "object" && error !== null && symbol$
|
|
5972
|
+
return typeof error === "object" && error !== null && symbol$21 in error && error[symbol$21] === true;
|
|
5723
5973
|
}
|
|
5724
5974
|
};
|
|
5725
|
-
var name$
|
|
5726
|
-
var marker2$4 = `vercel.ai.gateway.error.${name$
|
|
5975
|
+
var name$19 = "GatewayAuthenticationError";
|
|
5976
|
+
var marker2$4 = `vercel.ai.gateway.error.${name$19}`;
|
|
5727
5977
|
var symbol2$4 = Symbol.for(marker2$4);
|
|
5728
5978
|
var _a2$4;
|
|
5729
5979
|
var _b2$2;
|
|
@@ -5735,7 +5985,7 @@ var GatewayAuthenticationError$2 = class _GatewayAuthenticationError extends (_b
|
|
|
5735
5985
|
cause
|
|
5736
5986
|
});
|
|
5737
5987
|
this[_a2$4] = true;
|
|
5738
|
-
this.name = name$
|
|
5988
|
+
this.name = name$19;
|
|
5739
5989
|
this.type = "authentication_error";
|
|
5740
5990
|
}
|
|
5741
5991
|
static isInstance(error) {
|
|
@@ -8612,12 +8862,12 @@ var object$2 = ({ schema: inputSchema }) => {
|
|
|
8612
8862
|
}
|
|
8613
8863
|
};
|
|
8614
8864
|
};
|
|
8615
|
-
// ../_vendored/ai_v6/dist/dist-
|
|
8616
|
-
var marker$1$
|
|
8617
|
-
var symbol$1$
|
|
8865
|
+
// ../_vendored/ai_v6/dist/dist-BoOIE3nE.js
|
|
8866
|
+
var marker$1$10 = "vercel.ai.error";
|
|
8867
|
+
var symbol$1$13 = Symbol.for(marker$1$10);
|
|
8618
8868
|
var _a$1$1;
|
|
8619
8869
|
var _b$1;
|
|
8620
|
-
var AISDKError$1 = class _AISDKError extends (_b$1 = Error, _a$1$1 = symbol$1$
|
|
8870
|
+
var AISDKError$1 = class _AISDKError extends (_b$1 = Error, _a$1$1 = symbol$1$13, _b$1) {
|
|
8621
8871
|
/**
|
|
8622
8872
|
* Creates an AI SDK Error.
|
|
8623
8873
|
*
|
|
@@ -8638,22 +8888,22 @@ var AISDKError$1 = class _AISDKError extends (_b$1 = Error, _a$1$1 = symbol$1$15
|
|
|
8638
8888
|
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
|
|
8639
8889
|
*/
|
|
8640
8890
|
static isInstance(error) {
|
|
8641
|
-
return _AISDKError.hasMarker(error, marker$1$
|
|
8891
|
+
return _AISDKError.hasMarker(error, marker$1$10);
|
|
8642
8892
|
}
|
|
8643
8893
|
static hasMarker(error, marker15) {
|
|
8644
8894
|
const markerSymbol = Symbol.for(marker15);
|
|
8645
8895
|
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
8646
8896
|
}
|
|
8647
8897
|
};
|
|
8648
|
-
var name$1$
|
|
8649
|
-
var marker2$2 = `vercel.ai.error.${name$1$
|
|
8898
|
+
var name$1$10 = "AI_APICallError";
|
|
8899
|
+
var marker2$2 = `vercel.ai.error.${name$1$10}`;
|
|
8650
8900
|
var symbol2$2 = Symbol.for(marker2$2);
|
|
8651
8901
|
var _a2$2;
|
|
8652
8902
|
var _b2$1;
|
|
8653
8903
|
var APICallError$1 = class extends (_b2$1 = AISDKError$1, _a2$2 = symbol2$2, _b2$1) {
|
|
8654
8904
|
constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
|
|
8655
8905
|
super({
|
|
8656
|
-
name: name$1$
|
|
8906
|
+
name: name$1$10,
|
|
8657
8907
|
message,
|
|
8658
8908
|
cause
|
|
8659
8909
|
});
|
|
@@ -9036,15 +9286,15 @@ async function cancelResponseBody$1(response) {
|
|
|
9036
9286
|
await ((_a2 = response.body) == null ? void 0 : _a2.cancel());
|
|
9037
9287
|
} catch (e) {}
|
|
9038
9288
|
}
|
|
9039
|
-
var name$
|
|
9040
|
-
var marker$
|
|
9041
|
-
var symbol$
|
|
9289
|
+
var name$14 = "AI_DownloadError";
|
|
9290
|
+
var marker$13 = `vercel.ai.error.${name$14}`;
|
|
9291
|
+
var symbol$17 = Symbol.for(marker$13);
|
|
9042
9292
|
var _a$2;
|
|
9043
9293
|
var _b$2;
|
|
9044
|
-
var DownloadError$1 = class extends (_b$2 = AISDKError$1, _a$2 = symbol$
|
|
9294
|
+
var DownloadError$1 = class extends (_b$2 = AISDKError$1, _a$2 = symbol$17, _b$2) {
|
|
9045
9295
|
constructor({ url, statusCode, statusText, cause, message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}` }) {
|
|
9046
9296
|
super({
|
|
9047
|
-
name: name$
|
|
9297
|
+
name: name$14,
|
|
9048
9298
|
message,
|
|
9049
9299
|
cause
|
|
9050
9300
|
});
|
|
@@ -9054,7 +9304,7 @@ var DownloadError$1 = class extends (_b$2 = AISDKError$1, _a$2 = symbol$21, _b$2
|
|
|
9054
9304
|
this.statusText = statusText;
|
|
9055
9305
|
}
|
|
9056
9306
|
static isInstance(error) {
|
|
9057
|
-
return AISDKError$1.hasMarker(error, marker$
|
|
9307
|
+
return AISDKError$1.hasMarker(error, marker$13);
|
|
9058
9308
|
}
|
|
9059
9309
|
};
|
|
9060
9310
|
function isBrowserRuntime$1(globalThisAny = globalThis) {
|
|
@@ -9105,7 +9355,7 @@ function validateDownloadUrl$1(url) {
|
|
|
9105
9355
|
});
|
|
9106
9356
|
}
|
|
9107
9357
|
}
|
|
9108
|
-
function validateDownloadAddress
|
|
9358
|
+
function validateDownloadAddress({ address, family, hostname }) {
|
|
9109
9359
|
if (family === 4 ? !isIPv4$1(address) || isPrivateIPv4$1(address) : family === 6 ? isPrivateIPv6$1(address) : true) throw new DownloadError$1({
|
|
9110
9360
|
url: hostname,
|
|
9111
9361
|
message: `Hostname ${hostname} resolved to disallowed IP address ${address}`
|
|
@@ -9183,7 +9433,7 @@ function isPrivateIPv6$1(ip) {
|
|
|
9183
9433
|
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}`);
|
|
9184
9434
|
return false;
|
|
9185
9435
|
}
|
|
9186
|
-
function createSafeLookup
|
|
9436
|
+
function createSafeLookup(lookup) {
|
|
9187
9437
|
return ((hostname, options, callback) => {
|
|
9188
9438
|
lookup(hostname, {
|
|
9189
9439
|
...options,
|
|
@@ -9196,7 +9446,7 @@ function createSafeLookup$1(lookup) {
|
|
|
9196
9446
|
try {
|
|
9197
9447
|
const [firstAddress] = addresses;
|
|
9198
9448
|
if (firstAddress == null) throw new Error(`Hostname ${hostname} did not resolve to an address`);
|
|
9199
|
-
for (const { address, family } of addresses) validateDownloadAddress
|
|
9449
|
+
for (const { address, family } of addresses) validateDownloadAddress({
|
|
9200
9450
|
address,
|
|
9201
9451
|
family,
|
|
9202
9452
|
hostname
|
|
@@ -9209,20 +9459,20 @@ function createSafeLookup$1(lookup) {
|
|
|
9209
9459
|
});
|
|
9210
9460
|
});
|
|
9211
9461
|
}
|
|
9212
|
-
var safeNodeFetchPromise
|
|
9213
|
-
function isNodeRuntime$
|
|
9462
|
+
var safeNodeFetchPromise;
|
|
9463
|
+
function isNodeRuntime$1() {
|
|
9214
9464
|
var _a2, _b2, _c;
|
|
9215
9465
|
const runtimeProcess = globalThis.process;
|
|
9216
9466
|
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;
|
|
9217
9467
|
}
|
|
9218
|
-
async function getDefaultDownloadFetch
|
|
9219
|
-
if (!isNodeRuntime$
|
|
9220
|
-
return safeNodeFetchPromise
|
|
9468
|
+
async function getDefaultDownloadFetch() {
|
|
9469
|
+
if (!isNodeRuntime$1()) return globalThis.fetch;
|
|
9470
|
+
return safeNodeFetchPromise != null ? safeNodeFetchPromise : safeNodeFetchPromise = createSafeNodeFetch();
|
|
9221
9471
|
}
|
|
9222
|
-
async function createSafeNodeFetch
|
|
9472
|
+
async function createSafeNodeFetch() {
|
|
9223
9473
|
const [module, { lookup }] = await Promise.all([loadNodeModule("node:module"), loadNodeModule("node:dns")]);
|
|
9224
|
-
const { Agent, fetch } = module.createRequire(getCurrentModulePath
|
|
9225
|
-
const dispatcher = new Agent({ connect: { lookup: createSafeLookup
|
|
9474
|
+
const { Agent, fetch } = module.createRequire(getCurrentModulePath())("undici");
|
|
9475
|
+
const dispatcher = new Agent({ connect: { lookup: createSafeLookup(lookup) } });
|
|
9226
9476
|
return ((input, init) => fetch(input, {
|
|
9227
9477
|
...init,
|
|
9228
9478
|
dispatcher
|
|
@@ -9235,12 +9485,12 @@ async function loadNodeModule(id) {
|
|
|
9235
9485
|
if (builtinModule == null) throw new Error(`Node.js built-in module ${id} is unavailable`);
|
|
9236
9486
|
return builtinModule;
|
|
9237
9487
|
}
|
|
9238
|
-
function getCurrentModulePath
|
|
9488
|
+
function getCurrentModulePath() {
|
|
9239
9489
|
const originalPrepareStackTrace = Error.prepareStackTrace;
|
|
9240
9490
|
try {
|
|
9241
9491
|
Error.prepareStackTrace = (_error, callSites) => callSites;
|
|
9242
9492
|
const error = /* @__PURE__ */ new Error("Capture current module path");
|
|
9243
|
-
Error.captureStackTrace(error, getCurrentModulePath
|
|
9493
|
+
Error.captureStackTrace(error, getCurrentModulePath);
|
|
9244
9494
|
const [caller] = error.stack;
|
|
9245
9495
|
const fileName = caller == null ? void 0 : caller.getFileName();
|
|
9246
9496
|
if (fileName == null) throw new Error("Unable to determine the current module path");
|
|
@@ -9284,8 +9534,8 @@ var REDIRECT_STATUS_CODES$1 = /* @__PURE__ */ new Set([
|
|
|
9284
9534
|
307,
|
|
9285
9535
|
308
|
|
9286
9536
|
]);
|
|
9287
|
-
async function getValidatedFetch
|
|
9288
|
-
return customFetch == null || customFetch === globalThis.fetch ? await getDefaultDownloadFetch
|
|
9537
|
+
async function getValidatedFetch(customFetch) {
|
|
9538
|
+
return customFetch == null || customFetch === globalThis.fetch ? await getDefaultDownloadFetch() : customFetch;
|
|
9289
9539
|
}
|
|
9290
9540
|
async function fetchWithValidatedRedirects$1({ url, headers, abortSignal, maxRedirects = MAX_DOWNLOAD_REDIRECTS$1, fetch: customFetch, trustedOrigin }) {
|
|
9291
9541
|
var _a2;
|
|
@@ -9302,7 +9552,7 @@ async function fetchWithValidatedRedirects$1({ url, headers, abortSignal, maxRed
|
|
|
9302
9552
|
for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
|
|
9303
9553
|
const isTrustedHop = trustedOrigin !== void 0 && isSameOrigin$1(currentUrl, trustedOrigin);
|
|
9304
9554
|
if (!isTrustedHop) validateDownloadUrl$1(currentUrl);
|
|
9305
|
-
const fetch = isTrustedHop && customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getValidatedFetch
|
|
9555
|
+
const fetch = isTrustedHop && customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getValidatedFetch(customFetch);
|
|
9306
9556
|
const response = await fetch(currentUrl, perHopInit("manual"));
|
|
9307
9557
|
if (response.type === "opaqueredirect") {
|
|
9308
9558
|
if (!isBrowserRuntime$1()) throw new DownloadError$1({
|
|
@@ -9315,6 +9565,10 @@ async function fetchWithValidatedRedirects$1({ url, headers, abortSignal, maxRed
|
|
|
9315
9565
|
if (REDIRECT_STATUS_CODES$1.has(response.status) && location) {
|
|
9316
9566
|
cancelResponseBody$1(response);
|
|
9317
9567
|
const nextUrl = new URL(location, currentUrl).toString();
|
|
9568
|
+
if (new URL(currentUrl).protocol === "https:" && new URL(nextUrl).protocol === "http:") throw new DownloadError$1({
|
|
9569
|
+
url,
|
|
9570
|
+
message: "Redirect from HTTPS to HTTP was blocked"
|
|
9571
|
+
});
|
|
9318
9572
|
if (currentHeaders !== void 0 && !isSameOrigin$1(nextUrl, currentUrl)) {
|
|
9319
9573
|
const userAgent = currentHeaders.get("user-agent");
|
|
9320
9574
|
currentHeaders = new Headers(userAgent == null ? void 0 : { "user-agent": userAgent });
|
|
@@ -9484,7 +9738,7 @@ function withUserAgentSuffix$1(headers, ...userAgentSuffixParts) {
|
|
|
9484
9738
|
normalizedHeaders.set("user-agent", [currentUserAgentHeader, ...userAgentSuffixParts].filter(Boolean).join(" "));
|
|
9485
9739
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
9486
9740
|
}
|
|
9487
|
-
var VERSION$5 = "4.0.
|
|
9741
|
+
var VERSION$5 = "4.0.66";
|
|
9488
9742
|
var getOriginalFetch$1 = () => globalThis.fetch;
|
|
9489
9743
|
var getFromApi$1 = async ({ url, headers = {}, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, validateUrl, credentialedOrigin, trustedOrigin }) => {
|
|
9490
9744
|
try {
|
|
@@ -10960,7 +11214,7 @@ var createJsonResponseHandler$1 = (responseSchema) => async ({ response, url, re
|
|
|
10960
11214
|
function withoutTrailingSlash$1(url) {
|
|
10961
11215
|
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
10962
11216
|
}
|
|
10963
|
-
// ../_vendored/ai_v6/dist/dist-
|
|
11217
|
+
// ../_vendored/ai_v6/dist/dist-ByO0vuJJ.js
|
|
10964
11218
|
function getContext$1() {
|
|
10965
11219
|
return { headers: {} };
|
|
10966
11220
|
}
|
|
@@ -10968,10 +11222,10 @@ async function getVercelOidcToken$1() {
|
|
|
10968
11222
|
if (process.env.VERCEL_OIDC_TOKEN) return process.env.VERCEL_OIDC_TOKEN ?? "";
|
|
10969
11223
|
throw new Error("@vercel/oidc is not available in the vendored @internal AI packages. Provide an API key instead.");
|
|
10970
11224
|
}
|
|
10971
|
-
var symbol$
|
|
11225
|
+
var symbol$14 = Symbol.for("vercel.ai.gateway.error");
|
|
10972
11226
|
var _a$1;
|
|
10973
11227
|
var _b;
|
|
10974
|
-
var GatewayError$1 = class _GatewayError extends (_b = Error, _a$1 = symbol$
|
|
11228
|
+
var GatewayError$1 = class _GatewayError extends (_b = Error, _a$1 = symbol$14, _b) {
|
|
10975
11229
|
constructor({ message, statusCode = 500, cause, generationId, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500) }) {
|
|
10976
11230
|
super(generationId ? `${message} [${generationId}]` : message);
|
|
10977
11231
|
this[_a$1] = true;
|
|
@@ -10989,11 +11243,11 @@ var GatewayError$1 = class _GatewayError extends (_b = Error, _a$1 = symbol$20,
|
|
|
10989
11243
|
return _GatewayError.hasMarker(error);
|
|
10990
11244
|
}
|
|
10991
11245
|
static hasMarker(error) {
|
|
10992
|
-
return typeof error === "object" && error !== null && symbol$
|
|
11246
|
+
return typeof error === "object" && error !== null && symbol$14 in error && error[symbol$14] === true;
|
|
10993
11247
|
}
|
|
10994
11248
|
};
|
|
10995
|
-
var name$
|
|
10996
|
-
var marker2$1 = `vercel.ai.gateway.error.${name$
|
|
11249
|
+
var name$13 = "GatewayAuthenticationError";
|
|
11250
|
+
var marker2$1 = `vercel.ai.gateway.error.${name$13}`;
|
|
10997
11251
|
var symbol2$1 = Symbol.for(marker2$1);
|
|
10998
11252
|
var _a2$1;
|
|
10999
11253
|
var _b2;
|
|
@@ -11006,7 +11260,7 @@ var GatewayAuthenticationError$1 = class _GatewayAuthenticationError extends (_b
|
|
|
11006
11260
|
generationId
|
|
11007
11261
|
});
|
|
11008
11262
|
this[_a2$1] = true;
|
|
11009
|
-
this.name = name$
|
|
11263
|
+
this.name = name$13;
|
|
11010
11264
|
this.type = "authentication_error";
|
|
11011
11265
|
}
|
|
11012
11266
|
static isInstance(error) {
|
|
@@ -13935,14 +14189,14 @@ var __export = (target, all) => {
|
|
|
13935
14189
|
enumerable: true
|
|
13936
14190
|
});
|
|
13937
14191
|
};
|
|
13938
|
-
var name$
|
|
13939
|
-
var marker$
|
|
13940
|
-
var symbol$
|
|
14192
|
+
var name$10 = "AI_InvalidArgumentError";
|
|
14193
|
+
var marker$10 = `vercel.ai.error.${name$10}`;
|
|
14194
|
+
var symbol$13 = Symbol.for(marker$10);
|
|
13941
14195
|
var _a;
|
|
13942
14196
|
var InvalidArgumentError$2 = class extends AISDKError$1 {
|
|
13943
14197
|
constructor({ parameter, value, message }) {
|
|
13944
14198
|
super({
|
|
13945
|
-
name: name$
|
|
14199
|
+
name: name$10,
|
|
13946
14200
|
message: `Invalid argument for parameter ${parameter}: ${message}`
|
|
13947
14201
|
});
|
|
13948
14202
|
this[_a] = true;
|
|
@@ -13950,10 +14204,10 @@ var InvalidArgumentError$2 = class extends AISDKError$1 {
|
|
|
13950
14204
|
this.value = value;
|
|
13951
14205
|
}
|
|
13952
14206
|
static isInstance(error) {
|
|
13953
|
-
return AISDKError$1.hasMarker(error, marker$
|
|
14207
|
+
return AISDKError$1.hasMarker(error, marker$10);
|
|
13954
14208
|
}
|
|
13955
14209
|
};
|
|
13956
|
-
_a = symbol$
|
|
14210
|
+
_a = symbol$13;
|
|
13957
14211
|
var name9 = "AI_NoObjectGeneratedError";
|
|
13958
14212
|
var marker9 = `vercel.ai.error.${name9}`;
|
|
13959
14213
|
var symbol9 = Symbol.for(marker9);
|
|
@@ -15285,13 +15539,13 @@ createIdGenerator$1({
|
|
|
15285
15539
|
prefix: "aiobj",
|
|
15286
15540
|
size: 24
|
|
15287
15541
|
});
|
|
15288
|
-
// ../_vendored/ai_v7/dist/dist-
|
|
15542
|
+
// ../_vendored/ai_v7/dist/dist-C-C3A1Ts.js
|
|
15289
15543
|
/**
|
|
15290
15544
|
* Symbol used for identifying AI SDK Error instances.
|
|
15291
15545
|
* Enables checking if an error is an instance of AISDKError across package versions.
|
|
15292
15546
|
*/
|
|
15293
|
-
const marker$
|
|
15294
|
-
const symbol$
|
|
15547
|
+
const marker$18 = "vercel.ai.error";
|
|
15548
|
+
const symbol$18 = Symbol.for(marker$18);
|
|
15295
15549
|
/**
|
|
15296
15550
|
* Custom error class for AI SDK related errors.
|
|
15297
15551
|
* @extends Error
|
|
@@ -15307,7 +15561,7 @@ var AISDKError = class AISDKError extends Error {
|
|
|
15307
15561
|
*/
|
|
15308
15562
|
constructor({ name, message, cause }) {
|
|
15309
15563
|
super(message);
|
|
15310
|
-
this[symbol$
|
|
15564
|
+
this[symbol$18] = true;
|
|
15311
15565
|
this.name = name;
|
|
15312
15566
|
this.cause = cause;
|
|
15313
15567
|
}
|
|
@@ -15317,24 +15571,24 @@ var AISDKError = class AISDKError extends Error {
|
|
|
15317
15571
|
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
|
|
15318
15572
|
*/
|
|
15319
15573
|
static isInstance(error) {
|
|
15320
|
-
return AISDKError.hasMarker(error, marker$
|
|
15574
|
+
return AISDKError.hasMarker(error, marker$18);
|
|
15321
15575
|
}
|
|
15322
15576
|
static hasMarker(error, marker) {
|
|
15323
15577
|
const markerSymbol = Symbol.for(marker);
|
|
15324
15578
|
return error != null && typeof error === "object" && markerSymbol in error && typeof error[markerSymbol] === "boolean" && error[markerSymbol] === true;
|
|
15325
15579
|
}
|
|
15326
15580
|
};
|
|
15327
|
-
const name$
|
|
15328
|
-
const marker$
|
|
15329
|
-
const symbol$
|
|
15581
|
+
const name$16 = "AI_APICallError";
|
|
15582
|
+
const marker$16 = `vercel.ai.error.${name$16}`;
|
|
15583
|
+
const symbol$16 = Symbol.for(marker$16);
|
|
15330
15584
|
var APICallError = class extends AISDKError {
|
|
15331
15585
|
constructor({ message, url, requestBodyValues, statusCode, responseHeaders, responseBody, cause, isRetryable = statusCode != null && (statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500), data }) {
|
|
15332
15586
|
super({
|
|
15333
|
-
name: name$
|
|
15587
|
+
name: name$16,
|
|
15334
15588
|
message,
|
|
15335
15589
|
cause
|
|
15336
15590
|
});
|
|
15337
|
-
this[symbol$
|
|
15591
|
+
this[symbol$16] = true;
|
|
15338
15592
|
this.url = url;
|
|
15339
15593
|
this.requestBodyValues = requestBodyValues;
|
|
15340
15594
|
this.statusCode = statusCode;
|
|
@@ -15344,22 +15598,22 @@ var APICallError = class extends AISDKError {
|
|
|
15344
15598
|
this.data = data;
|
|
15345
15599
|
}
|
|
15346
15600
|
static isInstance(error) {
|
|
15347
|
-
return AISDKError.hasMarker(error, marker$
|
|
15601
|
+
return AISDKError.hasMarker(error, marker$16);
|
|
15348
15602
|
}
|
|
15349
15603
|
};
|
|
15350
|
-
const name$
|
|
15351
|
-
const marker$
|
|
15352
|
-
const symbol$
|
|
15604
|
+
const name$15 = "AI_EmptyResponseBodyError";
|
|
15605
|
+
const marker$15 = `vercel.ai.error.${name$15}`;
|
|
15606
|
+
const symbol$15 = Symbol.for(marker$15);
|
|
15353
15607
|
var EmptyResponseBodyError = class extends AISDKError {
|
|
15354
15608
|
constructor({ message = "Empty response body" } = {}) {
|
|
15355
15609
|
super({
|
|
15356
|
-
name: name$
|
|
15610
|
+
name: name$15,
|
|
15357
15611
|
message
|
|
15358
15612
|
});
|
|
15359
|
-
this[symbol$
|
|
15613
|
+
this[symbol$15] = true;
|
|
15360
15614
|
}
|
|
15361
15615
|
static isInstance(error) {
|
|
15362
|
-
return AISDKError.hasMarker(error, marker$
|
|
15616
|
+
return AISDKError.hasMarker(error, marker$15);
|
|
15363
15617
|
}
|
|
15364
15618
|
};
|
|
15365
15619
|
function getErrorMessage(error) {
|
|
@@ -15487,20 +15741,20 @@ var TypeValidationError = class TypeValidationError extends AISDKError {
|
|
|
15487
15741
|
});
|
|
15488
15742
|
}
|
|
15489
15743
|
};
|
|
15490
|
-
const name$
|
|
15491
|
-
const marker$
|
|
15492
|
-
const symbol$
|
|
15744
|
+
const name$18 = "AI_UnsupportedFunctionalityError";
|
|
15745
|
+
const marker$19 = `vercel.ai.error.${name$18}`;
|
|
15746
|
+
const symbol$19 = Symbol.for(marker$19);
|
|
15493
15747
|
var UnsupportedFunctionalityError = class extends AISDKError {
|
|
15494
15748
|
constructor({ functionality, message = `'${functionality}' functionality not supported.` }) {
|
|
15495
15749
|
super({
|
|
15496
|
-
name: name$
|
|
15750
|
+
name: name$18,
|
|
15497
15751
|
message
|
|
15498
15752
|
});
|
|
15499
|
-
this[symbol$
|
|
15753
|
+
this[symbol$19] = true;
|
|
15500
15754
|
this.functionality = functionality;
|
|
15501
15755
|
}
|
|
15502
15756
|
static isInstance(error) {
|
|
15503
|
-
return AISDKError.hasMarker(error, marker$
|
|
15757
|
+
return AISDKError.hasMarker(error, marker$19);
|
|
15504
15758
|
}
|
|
15505
15759
|
};
|
|
15506
15760
|
var ParseError = class extends Error {
|
|
@@ -15986,7 +16240,7 @@ function handleFetchError({ error, url, requestBodyValues }) {
|
|
|
15986
16240
|
}
|
|
15987
16241
|
return error;
|
|
15988
16242
|
}
|
|
15989
|
-
const VERSION$2 = "5.0.
|
|
16243
|
+
const VERSION$2 = "5.0.81";
|
|
15990
16244
|
/**
|
|
15991
16245
|
* Normalizes different header inputs into a plain record with lower-case keys.
|
|
15992
16246
|
* Entries with `undefined` or `null` values are removed.
|
|
@@ -16089,11 +16343,54 @@ function isSameOrigin(url, baseUrl) {
|
|
|
16089
16343
|
}
|
|
16090
16344
|
}
|
|
16091
16345
|
/**
|
|
16346
|
+
* Request headers stripped before fetching an untrusted URL: host/virtual-host
|
|
16347
|
+
* routing, proxy/origin spoofing, cloud-metadata, cookies, and hop-by-hop
|
|
16348
|
+
* transport headers (RFC 7230 §6.1).
|
|
16349
|
+
*
|
|
16350
|
+
* `Authorization` and other credential-bearing caller headers (e.g. `x-key`)
|
|
16351
|
+
* are intentionally not listed because trusted provider requests may need
|
|
16352
|
+
* them. `fetchUntrustedUrl` separately restricts an untrusted first hop to an
|
|
16353
|
+
* explicit allowlist of non-credential request metadata. Both it and
|
|
16354
|
+
* `fetchWithValidatedRedirects` drop all caller headers except the user-agent
|
|
16355
|
+
* on a cross-origin redirect.
|
|
16356
|
+
*/
|
|
16357
|
+
const BLOCKED_REQUEST_HEADERS = [
|
|
16358
|
+
"connection",
|
|
16359
|
+
"keep-alive",
|
|
16360
|
+
"te",
|
|
16361
|
+
"trailer",
|
|
16362
|
+
"transfer-encoding",
|
|
16363
|
+
"upgrade",
|
|
16364
|
+
"host",
|
|
16365
|
+
"forwarded",
|
|
16366
|
+
"proxy-authorization",
|
|
16367
|
+
"via",
|
|
16368
|
+
"x-forwarded-for",
|
|
16369
|
+
"x-forwarded-host",
|
|
16370
|
+
"x-forwarded-proto",
|
|
16371
|
+
"x-real-ip",
|
|
16372
|
+
"metadata",
|
|
16373
|
+
"metadata-flavor",
|
|
16374
|
+
"x-aws-ec2-metadata-token",
|
|
16375
|
+
"x-metadata-token",
|
|
16376
|
+
"cookie",
|
|
16377
|
+
"set-cookie"
|
|
16378
|
+
];
|
|
16379
|
+
/**
|
|
16380
|
+
* Returns a fresh `Headers` built from `input` with {@link BLOCKED_REQUEST_HEADERS}
|
|
16381
|
+
* removed. The input is never mutated.
|
|
16382
|
+
*/
|
|
16383
|
+
function sanitizeRequestHeaders(input) {
|
|
16384
|
+
const headers = new Headers(input);
|
|
16385
|
+
for (const name of BLOCKED_REQUEST_HEADERS) headers.delete(name);
|
|
16386
|
+
return headers;
|
|
16387
|
+
}
|
|
16388
|
+
/**
|
|
16092
16389
|
* Validates that a URL is safe to download from, blocking private/internal addresses
|
|
16093
16390
|
* to prevent SSRF attacks.
|
|
16094
16391
|
*
|
|
16095
|
-
*
|
|
16096
|
-
*
|
|
16392
|
+
* This function performs string/literal-IP checks only. DNS validation must
|
|
16393
|
+
* be provided by the fetch transport or network egress controls.
|
|
16097
16394
|
*
|
|
16098
16395
|
* @param url - The URL string to validate.
|
|
16099
16396
|
* @throws DownloadError if the URL is unsafe.
|
|
@@ -16136,16 +16433,6 @@ function validateDownloadUrl(url) {
|
|
|
16136
16433
|
});
|
|
16137
16434
|
}
|
|
16138
16435
|
}
|
|
16139
|
-
/**
|
|
16140
|
-
* Validates an address returned by DNS before it is used to open a socket.
|
|
16141
|
-
* This is intentionally not exported from the package entry point.
|
|
16142
|
-
*/
|
|
16143
|
-
function validateDownloadAddress({ address, family, hostname }) {
|
|
16144
|
-
if (family === 4 ? !isIPv4(address) || isPrivateIPv4(address) : family === 6 ? isPrivateIPv6(address) : true) throw new DownloadError({
|
|
16145
|
-
url: hostname,
|
|
16146
|
-
message: `Hostname ${hostname} resolved to disallowed IP address ${address}`
|
|
16147
|
-
});
|
|
16148
|
-
}
|
|
16149
16436
|
function isIPv4(hostname) {
|
|
16150
16437
|
const parts = hostname.split(".");
|
|
16151
16438
|
if (parts.length !== 4) return false;
|
|
@@ -16229,119 +16516,6 @@ function isPrivateIPv6(ip) {
|
|
|
16229
16516
|
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}`);
|
|
16230
16517
|
return false;
|
|
16231
16518
|
}
|
|
16232
|
-
/**
|
|
16233
|
-
* Creates a DNS lookup hook that validates every returned address before
|
|
16234
|
-
* returning the callback shape requested by the HTTP connector. Because
|
|
16235
|
-
* resolution and validation happen inside the connector, the socket is pinned
|
|
16236
|
-
* to the validated result and DNS rebinding cannot introduce a second lookup.
|
|
16237
|
-
*/
|
|
16238
|
-
function createSafeLookup(lookup) {
|
|
16239
|
-
return ((hostname, options, callback) => {
|
|
16240
|
-
lookup(hostname, {
|
|
16241
|
-
...options,
|
|
16242
|
-
all: true
|
|
16243
|
-
}, (error, addresses) => {
|
|
16244
|
-
if (error) {
|
|
16245
|
-
callback(error);
|
|
16246
|
-
return;
|
|
16247
|
-
}
|
|
16248
|
-
try {
|
|
16249
|
-
const [firstAddress] = addresses;
|
|
16250
|
-
if (firstAddress == null) throw new Error(`Hostname ${hostname} did not resolve to an address`);
|
|
16251
|
-
for (const { address, family } of addresses) validateDownloadAddress({
|
|
16252
|
-
address,
|
|
16253
|
-
family,
|
|
16254
|
-
hostname
|
|
16255
|
-
});
|
|
16256
|
-
if (options.all === true) callback(null, addresses);
|
|
16257
|
-
else callback(null, firstAddress.address, firstAddress.family);
|
|
16258
|
-
} catch (error) {
|
|
16259
|
-
callback(error instanceof Error ? error : new Error(String(error)));
|
|
16260
|
-
}
|
|
16261
|
-
});
|
|
16262
|
-
});
|
|
16263
|
-
}
|
|
16264
|
-
let safeNodeFetchPromise;
|
|
16265
|
-
function isNodeRuntime$1() {
|
|
16266
|
-
const runtimeProcess = globalThis.process;
|
|
16267
|
-
return runtimeProcess?.release?.name === "node" && runtimeProcess.versions?.bun == null && runtimeProcess.versions?.deno == null && runtimeProcess.title !== "workerd" && globalThis.EdgeRuntime == null;
|
|
16268
|
-
}
|
|
16269
|
-
async function getDefaultDownloadFetch() {
|
|
16270
|
-
if (!isNodeRuntime$1()) return globalThis.fetch;
|
|
16271
|
-
return safeNodeFetchPromise ??= Promise.resolve().then(createSafeNodeFetch);
|
|
16272
|
-
}
|
|
16273
|
-
function createSafeNodeFetch() {
|
|
16274
|
-
const module = loadBuiltinModule$1("node:module");
|
|
16275
|
-
const { lookup } = loadBuiltinModule$1("node:dns");
|
|
16276
|
-
const { Agent, fetch } = module.createRequire(getCurrentModulePath())("undici");
|
|
16277
|
-
const dispatcher = new Agent({ connect: { lookup: createSafeLookup(lookup) } });
|
|
16278
|
-
return ((input, init) => fetch(input, {
|
|
16279
|
-
...init,
|
|
16280
|
-
dispatcher
|
|
16281
|
-
}));
|
|
16282
|
-
}
|
|
16283
|
-
function loadBuiltinModule$1(id) {
|
|
16284
|
-
const builtinModule = globalThis.process?.getBuiltinModule?.(id);
|
|
16285
|
-
if (builtinModule == null) throw new Error(`Node.js built-in module ${id} is unavailable`);
|
|
16286
|
-
return builtinModule;
|
|
16287
|
-
}
|
|
16288
|
-
function getCurrentModulePath() {
|
|
16289
|
-
const originalPrepareStackTrace = Error.prepareStackTrace;
|
|
16290
|
-
try {
|
|
16291
|
-
Error.prepareStackTrace = (_error, callSites) => callSites;
|
|
16292
|
-
const error = /* @__PURE__ */ new Error("Capture current module path");
|
|
16293
|
-
Error.captureStackTrace(error, getCurrentModulePath);
|
|
16294
|
-
const [caller] = error.stack;
|
|
16295
|
-
const fileName = caller?.getFileName();
|
|
16296
|
-
if (fileName == null) throw new Error("Unable to determine the current module path");
|
|
16297
|
-
return fileName;
|
|
16298
|
-
} finally {
|
|
16299
|
-
Error.prepareStackTrace = originalPrepareStackTrace;
|
|
16300
|
-
}
|
|
16301
|
-
}
|
|
16302
|
-
/**
|
|
16303
|
-
* Request headers stripped before fetching an untrusted URL: host/virtual-host
|
|
16304
|
-
* routing, proxy/origin spoofing, cloud-metadata, cookies, and hop-by-hop
|
|
16305
|
-
* transport headers (RFC 7230 §6.1).
|
|
16306
|
-
*
|
|
16307
|
-
* `Authorization` and other credential-bearing caller headers (e.g. `x-key`)
|
|
16308
|
-
* are intentionally not listed because trusted provider requests may need
|
|
16309
|
-
* them. `fetchUntrustedUrl` separately restricts an untrusted first hop to an
|
|
16310
|
-
* explicit allowlist of non-credential request metadata. Both it and
|
|
16311
|
-
* `fetchWithValidatedRedirects` drop all caller headers except the user-agent
|
|
16312
|
-
* on a cross-origin redirect.
|
|
16313
|
-
*/
|
|
16314
|
-
const BLOCKED_REQUEST_HEADERS = [
|
|
16315
|
-
"connection",
|
|
16316
|
-
"keep-alive",
|
|
16317
|
-
"te",
|
|
16318
|
-
"trailer",
|
|
16319
|
-
"transfer-encoding",
|
|
16320
|
-
"upgrade",
|
|
16321
|
-
"host",
|
|
16322
|
-
"forwarded",
|
|
16323
|
-
"proxy-authorization",
|
|
16324
|
-
"via",
|
|
16325
|
-
"x-forwarded-for",
|
|
16326
|
-
"x-forwarded-host",
|
|
16327
|
-
"x-forwarded-proto",
|
|
16328
|
-
"x-real-ip",
|
|
16329
|
-
"metadata",
|
|
16330
|
-
"metadata-flavor",
|
|
16331
|
-
"x-aws-ec2-metadata-token",
|
|
16332
|
-
"x-metadata-token",
|
|
16333
|
-
"cookie",
|
|
16334
|
-
"set-cookie"
|
|
16335
|
-
];
|
|
16336
|
-
/**
|
|
16337
|
-
* Returns a fresh `Headers` built from `input` with {@link BLOCKED_REQUEST_HEADERS}
|
|
16338
|
-
* removed. The input is never mutated.
|
|
16339
|
-
*/
|
|
16340
|
-
function sanitizeRequestHeaders(input) {
|
|
16341
|
-
const headers = new Headers(input);
|
|
16342
|
-
for (const name of BLOCKED_REQUEST_HEADERS) headers.delete(name);
|
|
16343
|
-
return headers;
|
|
16344
|
-
}
|
|
16345
16519
|
const MAX_DOWNLOAD_REDIRECTS = 10;
|
|
16346
16520
|
const REDIRECT_STATUS_CODES = /* @__PURE__ */ new Set([
|
|
16347
16521
|
301,
|
|
@@ -16350,9 +16524,6 @@ const REDIRECT_STATUS_CODES = /* @__PURE__ */ new Set([
|
|
|
16350
16524
|
307,
|
|
16351
16525
|
308
|
|
16352
16526
|
]);
|
|
16353
|
-
async function getValidatedFetch(customFetch) {
|
|
16354
|
-
return customFetch == null || customFetch === globalThis.fetch ? await getDefaultDownloadFetch() : customFetch;
|
|
16355
|
-
}
|
|
16356
16527
|
/**
|
|
16357
16528
|
* Fetches a URL while enforcing the download guard on every hop.
|
|
16358
16529
|
*
|
|
@@ -16362,6 +16533,9 @@ async function getValidatedFetch(customFetch) {
|
|
|
16362
16533
|
* target (e.g. an internal address) before we ever see its URL, defeating the
|
|
16363
16534
|
* guard.
|
|
16364
16535
|
*
|
|
16536
|
+
* Manually followed redirects from HTTPS to HTTP are rejected before requesting
|
|
16537
|
+
* the target.
|
|
16538
|
+
*
|
|
16365
16539
|
* Request headers are also protected: {@link sanitizeRequestHeaders} strips
|
|
16366
16540
|
* proxy/metadata/cookie/hop-by-hop headers before the first request, and all
|
|
16367
16541
|
* caller headers except `User-Agent` are dropped on a cross-origin redirect.
|
|
@@ -16391,11 +16565,8 @@ async function getValidatedFetch(customFetch) {
|
|
|
16391
16565
|
* The returned response is the final (non-redirect) response. The caller is
|
|
16392
16566
|
* responsible for checking `response.ok` and reading the body.
|
|
16393
16567
|
*
|
|
16394
|
-
*
|
|
16395
|
-
*
|
|
16396
|
-
* hostname-to-private-IP and DNS-rebinding bypasses. An injected fetch is
|
|
16397
|
-
* responsible for equivalent connect-time validation. Other runtimes should
|
|
16398
|
-
* constrain egress at the network layer when handling untrusted URLs.
|
|
16568
|
+
* URL validation does not resolve DNS. Use guarded-fetch on Node.js
|
|
16569
|
+
* for connection-time DNS validation, or enforce network egress restrictions.
|
|
16399
16570
|
*
|
|
16400
16571
|
* @throws DownloadError if a hop is unsafe, the redirect limit is exceeded, or
|
|
16401
16572
|
* a redirect cannot be validated on a non-browser runtime.
|
|
@@ -16412,9 +16583,8 @@ async function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedir
|
|
|
16412
16583
|
};
|
|
16413
16584
|
let currentUrl = url;
|
|
16414
16585
|
for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
|
|
16415
|
-
|
|
16416
|
-
|
|
16417
|
-
const fetch = isTrustedHop && customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getValidatedFetch(customFetch);
|
|
16586
|
+
if (!(trustedOrigin !== void 0 && isSameOrigin(currentUrl, trustedOrigin))) validateDownloadUrl(currentUrl);
|
|
16587
|
+
const fetch = customFetch ?? globalThis.fetch;
|
|
16418
16588
|
const response = await fetch(currentUrl, perHopInit("manual"));
|
|
16419
16589
|
if (response.type === "opaqueredirect") {
|
|
16420
16590
|
if (!isBrowserRuntime()) throw new DownloadError({
|
|
@@ -16427,6 +16597,10 @@ async function fetchWithValidatedRedirects({ url, headers, abortSignal, maxRedir
|
|
|
16427
16597
|
if (REDIRECT_STATUS_CODES.has(response.status) && location) {
|
|
16428
16598
|
cancelResponseBody(response);
|
|
16429
16599
|
const nextUrl = new URL(location, currentUrl).toString();
|
|
16600
|
+
if (new URL(currentUrl).protocol === "https:" && new URL(nextUrl).protocol === "http:") throw new DownloadError({
|
|
16601
|
+
url,
|
|
16602
|
+
message: "Redirect from HTTPS to HTTP was blocked"
|
|
16603
|
+
});
|
|
16430
16604
|
if (currentHeaders !== void 0 && !isSameOrigin(nextUrl, currentUrl)) {
|
|
16431
16605
|
const userAgent = currentHeaders.get("user-agent");
|
|
16432
16606
|
currentHeaders = new Headers(userAgent == null ? void 0 : { "user-agent": userAgent });
|
|
@@ -16463,10 +16637,13 @@ const DEFAULT_MAX_DOWNLOAD_SIZE = 2147483648;
|
|
|
16463
16637
|
* @param response - The fetch Response to read.
|
|
16464
16638
|
* @param url - The URL being downloaded (used in error messages).
|
|
16465
16639
|
* @param maxBytes - Maximum allowed bytes. Defaults to DEFAULT_MAX_DOWNLOAD_SIZE.
|
|
16640
|
+
* @param onChunk - Optional. Receives each chunk instead of the chunks being
|
|
16641
|
+
* collected, so the body is not held in memory, and the returned array is empty.
|
|
16642
|
+
* The chunk may be a view on a larger buffer, copy what you keep.
|
|
16466
16643
|
* @returns A Uint8Array containing the response body.
|
|
16467
16644
|
* @throws DownloadError if the response exceeds maxBytes.
|
|
16468
16645
|
*/
|
|
16469
|
-
async function readResponseWithSizeLimit({ response, url, maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE }) {
|
|
16646
|
+
async function readResponseWithSizeLimit({ response, url, maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE, onChunk }) {
|
|
16470
16647
|
const contentLength = response.headers.get("content-length");
|
|
16471
16648
|
if (contentLength != null) {
|
|
16472
16649
|
const length = parseInt(contentLength, 10);
|
|
@@ -16492,6 +16669,10 @@ async function readResponseWithSizeLimit({ response, url, maxBytes = DEFAULT_MAX
|
|
|
16492
16669
|
url,
|
|
16493
16670
|
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes.`
|
|
16494
16671
|
});
|
|
16672
|
+
if (onChunk != null) {
|
|
16673
|
+
onChunk(value);
|
|
16674
|
+
continue;
|
|
16675
|
+
}
|
|
16495
16676
|
chunks.push(value.byteLength < value.buffer.byteLength ? new Uint8Array(value) : value);
|
|
16496
16677
|
}
|
|
16497
16678
|
} finally {
|
|
@@ -16501,7 +16682,7 @@ async function readResponseWithSizeLimit({ response, url, maxBytes = DEFAULT_MAX
|
|
|
16501
16682
|
reader.releaseLock();
|
|
16502
16683
|
}
|
|
16503
16684
|
}
|
|
16504
|
-
const result = new Uint8Array(totalBytes);
|
|
16685
|
+
const result = new Uint8Array(onChunk != null ? 0 : totalBytes);
|
|
16505
16686
|
let offset = 0;
|
|
16506
16687
|
for (const chunk of chunks) {
|
|
16507
16688
|
result.set(chunk, offset);
|
|
@@ -17666,6 +17847,7 @@ function zod3Schema(zodSchema, options) {
|
|
|
17666
17847
|
} });
|
|
17667
17848
|
}
|
|
17668
17849
|
function zod4Schema(zodSchema, options) {
|
|
17850
|
+
if (!config().localeError) config(en());
|
|
17669
17851
|
const useReferences = options?.useReferences ?? false;
|
|
17670
17852
|
return jsonSchema(() => addAdditionalPropertiesToJsonSchema(toJSONSchema(zodSchema, {
|
|
17671
17853
|
target: "draft-7",
|
|
@@ -17897,12 +18079,27 @@ const postToApi = async ({ url, headers = {}, body, successfulResponseHandler, f
|
|
|
17897
18079
|
function tool(tool) {
|
|
17898
18080
|
return tool;
|
|
17899
18081
|
}
|
|
17900
|
-
|
|
18082
|
+
const telemetryRedaction = Symbol.for("vercel.ai.telemetry.redact");
|
|
18083
|
+
/**
|
|
18084
|
+
* Attach a provider-owned telemetry view without changing the original value.
|
|
18085
|
+
* The annotation is not serialized or included in enumerable application data.
|
|
18086
|
+
* Keep the annotated object when forwarding tool arguments or provider metadata.
|
|
18087
|
+
*/
|
|
18088
|
+
function withTelemetryRedaction(value, redact) {
|
|
18089
|
+
return Object.create(Object.getPrototypeOf(value), {
|
|
18090
|
+
...Object.getOwnPropertyDescriptors(value),
|
|
18091
|
+
[telemetryRedaction]: {
|
|
18092
|
+
value: redact,
|
|
18093
|
+
configurable: true
|
|
18094
|
+
}
|
|
18095
|
+
});
|
|
18096
|
+
}
|
|
18097
|
+
function createProviderExecutedToolFactory({ id, inputSchema, outputSchema, supportsDeferredResults, redactArgs }) {
|
|
17901
18098
|
return ({ onInputStart, onInputDelta, onInputAvailable, ...args }) => tool({
|
|
17902
18099
|
type: "provider",
|
|
17903
18100
|
isProviderExecuted: true,
|
|
17904
18101
|
id,
|
|
17905
|
-
args,
|
|
18102
|
+
args: redactArgs == null ? args : withTelemetryRedaction(args, redactArgs),
|
|
17906
18103
|
inputSchema,
|
|
17907
18104
|
outputSchema,
|
|
17908
18105
|
onInputStart,
|
|
@@ -17968,6 +18165,286 @@ async function retryWithExponentialBackoffInternal(f, { maxRetries, delayInMs, b
|
|
|
17968
18165
|
});
|
|
17969
18166
|
}
|
|
17970
18167
|
}
|
|
18168
|
+
/**
|
|
18169
|
+
* Streaming extraction of large base64 strings from a JSON response body.
|
|
18170
|
+
*
|
|
18171
|
+
* A JSON response that carries an image or a file is mostly one very long
|
|
18172
|
+
* base64 string. The regular pipeline (collect chunks, concatenate, decode to
|
|
18173
|
+
* text, `JSON.parse`, decode base64) holds about four copies of that string at
|
|
18174
|
+
* once. The scanner reads the body chunk by chunk instead: strings at the
|
|
18175
|
+
* configured paths are decoded to bytes while they stream in, and the text that
|
|
18176
|
+
* is handed to `JSON.parse` (the "skeleton") holds a short placeholder in their
|
|
18177
|
+
* place.
|
|
18178
|
+
*
|
|
18179
|
+
* - The skeleton is the original body except for the extracted strings, so
|
|
18180
|
+
* `secureJsonParse` still sees every key (a base64 string cannot contain a
|
|
18181
|
+
* quote, so it cannot hide one).
|
|
18182
|
+
* - A string is extracted only if it is canonical standard-alphabet base64
|
|
18183
|
+
* (length divisible by 4, `=` only as the final padding, zero trailing bits,
|
|
18184
|
+
* no escape sequences or whitespace). The bytes are then exactly what `atob`
|
|
18185
|
+
* gives for it. Everything else stays a string. What was decoded before a
|
|
18186
|
+
* string turned out not to qualify is encoded back, which gives the original
|
|
18187
|
+
* characters.
|
|
18188
|
+
*/
|
|
18189
|
+
/** Strings that decode to fewer bytes stay strings. */
|
|
18190
|
+
const DEFAULT_BINARY_FIELD_MIN_BYTES = 65536;
|
|
18191
|
+
const QUOTE = 34;
|
|
18192
|
+
const BACKSLASH = 92;
|
|
18193
|
+
const EQUALS = 61;
|
|
18194
|
+
const COMMA = 44;
|
|
18195
|
+
const COLON = 58;
|
|
18196
|
+
const LEFT_BRACE = 123;
|
|
18197
|
+
const RIGHT_BRACE = 125;
|
|
18198
|
+
const LEFT_BRACKET = 91;
|
|
18199
|
+
const RIGHT_BRACKET = 93;
|
|
18200
|
+
const OUTSIDE = 0;
|
|
18201
|
+
const KEY = 1;
|
|
18202
|
+
const SKIP = 2;
|
|
18203
|
+
const BLOB = 3;
|
|
18204
|
+
/**
|
|
18205
|
+
* Compiles paths such as `images[*]` or `content[*].data.data`: plain object
|
|
18206
|
+
* keys (letters, digits, `_` and `-`) joined by `.`, and `[*]` for every
|
|
18207
|
+
* element of an array. Keys are compared with the raw bytes of the key in the
|
|
18208
|
+
* body, so a key written with an escape sequence never matches.
|
|
18209
|
+
*/
|
|
18210
|
+
function compileBinaryFieldPaths(paths) {
|
|
18211
|
+
const root = /* @__PURE__ */ new Map();
|
|
18212
|
+
for (const path of paths) {
|
|
18213
|
+
if (!/^(?:[\w-]+|\[\*])(?:\.[\w-]+|\[\*])*$/.test(path)) throw new InvalidArgumentError$1({
|
|
18214
|
+
argument: "experimental_binaryFields",
|
|
18215
|
+
message: `Invalid binary field path "${path}"`
|
|
18216
|
+
});
|
|
18217
|
+
let node = root;
|
|
18218
|
+
for (const segment of path.match(/\[\*]|[\w-]+/g)) {
|
|
18219
|
+
const edges = segment === "[*]" ? [null] : new TextEncoder().encode(`${segment}"`);
|
|
18220
|
+
for (const edge of edges) {
|
|
18221
|
+
let next = node.get(edge);
|
|
18222
|
+
if (next === void 0) node.set(edge, next = /* @__PURE__ */ new Map());
|
|
18223
|
+
node = next;
|
|
18224
|
+
}
|
|
18225
|
+
}
|
|
18226
|
+
node.set(true, node);
|
|
18227
|
+
}
|
|
18228
|
+
return root;
|
|
18229
|
+
}
|
|
18230
|
+
function join$1(parts, length) {
|
|
18231
|
+
const bytes = new Uint8Array(length);
|
|
18232
|
+
let at = 0;
|
|
18233
|
+
for (const part of parts) {
|
|
18234
|
+
bytes.set(part, at);
|
|
18235
|
+
at += part.length;
|
|
18236
|
+
}
|
|
18237
|
+
return bytes;
|
|
18238
|
+
}
|
|
18239
|
+
function createJsonBinaryFieldScanner(paths, minBytes = DEFAULT_BINARY_FIELD_MIN_BYTES) {
|
|
18240
|
+
const sextet = (/* @__PURE__ */ new Uint8Array(256)).fill(64);
|
|
18241
|
+
for (let index = 0; index < 64; index++) sextet["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(index)] = index;
|
|
18242
|
+
const encoder = new TextEncoder();
|
|
18243
|
+
const pieces = [];
|
|
18244
|
+
let piece = /* @__PURE__ */ new Uint8Array(65536);
|
|
18245
|
+
let pieceLength = 0;
|
|
18246
|
+
let size = 0;
|
|
18247
|
+
const binaries = /* @__PURE__ */ new Map();
|
|
18248
|
+
const frames = [];
|
|
18249
|
+
let skipped = 0;
|
|
18250
|
+
let mode = OUTSIDE;
|
|
18251
|
+
let escaped = false;
|
|
18252
|
+
let last = 0;
|
|
18253
|
+
let key;
|
|
18254
|
+
let segments = [];
|
|
18255
|
+
let segment = /* @__PURE__ */ new Uint8Array(0);
|
|
18256
|
+
let at = 0;
|
|
18257
|
+
let total = 0;
|
|
18258
|
+
let bits = 0;
|
|
18259
|
+
let chars = 0;
|
|
18260
|
+
let padding = 0;
|
|
18261
|
+
const add = (bytes) => {
|
|
18262
|
+
for (let offset = 0; offset < bytes.length;) {
|
|
18263
|
+
const length = Math.min(piece.length - pieceLength, bytes.length - offset);
|
|
18264
|
+
piece.set(bytes.subarray(offset, offset + length), pieceLength);
|
|
18265
|
+
pieceLength += length;
|
|
18266
|
+
offset += length;
|
|
18267
|
+
size += length;
|
|
18268
|
+
if (pieceLength === piece.length) {
|
|
18269
|
+
pieces.push(piece);
|
|
18270
|
+
piece = /* @__PURE__ */ new Uint8Array(65536);
|
|
18271
|
+
pieceLength = 0;
|
|
18272
|
+
}
|
|
18273
|
+
}
|
|
18274
|
+
};
|
|
18275
|
+
const emit = (chunk, start, end) => add(chunk.subarray(start, end));
|
|
18276
|
+
const reset = () => {
|
|
18277
|
+
segments = [];
|
|
18278
|
+
segment = /* @__PURE__ */ new Uint8Array(0);
|
|
18279
|
+
at = 0;
|
|
18280
|
+
total = 0;
|
|
18281
|
+
bits = 0;
|
|
18282
|
+
chars = 0;
|
|
18283
|
+
padding = 0;
|
|
18284
|
+
};
|
|
18285
|
+
const grow = () => {
|
|
18286
|
+
if (at > 0) segments.push(segment.subarray(0, at));
|
|
18287
|
+
segment = new Uint8Array(Math.min(Math.max(total, 4096), 4 << 20));
|
|
18288
|
+
at = 0;
|
|
18289
|
+
};
|
|
18290
|
+
const rest = () => bits << (4 - chars) * 6;
|
|
18291
|
+
const restore = () => {
|
|
18292
|
+
for (const part of [...segments, segment.subarray(0, at)]) add(encoder.encode(convertUint8ArrayToBase64(part)));
|
|
18293
|
+
const group = rest();
|
|
18294
|
+
add(encoder.encode(convertUint8ArrayToBase64(Uint8Array.of(group >> 16, group >> 8, group)).slice(0, chars) + "=".repeat(padding)));
|
|
18295
|
+
reset();
|
|
18296
|
+
};
|
|
18297
|
+
const closeBlob = () => {
|
|
18298
|
+
mode = OUTSIDE;
|
|
18299
|
+
const tail = chars && chars - 1;
|
|
18300
|
+
if (padding === (4 - chars) % 4 && !(bits & (1 << (4 - chars) * 2) - 1) && total + tail >= minBytes) {
|
|
18301
|
+
const group = rest();
|
|
18302
|
+
const bytes = join$1([...segments, segment.subarray(0, at)], total + tail);
|
|
18303
|
+
for (let index = 0; index < tail; index++) bytes[total + index] = group >> 16 - 8 * index;
|
|
18304
|
+
const placeholder = `[binary data: ${bytes.length} bytes; ref ${crypto.getRandomValues(/* @__PURE__ */ new Uint32Array(2)).join("-")}]`;
|
|
18305
|
+
binaries.set(placeholder, bytes);
|
|
18306
|
+
add(encoder.encode(placeholder));
|
|
18307
|
+
reset();
|
|
18308
|
+
} else restore();
|
|
18309
|
+
};
|
|
18310
|
+
const push = (chunk) => {
|
|
18311
|
+
let from = 0;
|
|
18312
|
+
const { length } = chunk;
|
|
18313
|
+
for (let index = 0; index < length; index++) {
|
|
18314
|
+
let byte = chunk[index];
|
|
18315
|
+
if (mode === BLOB) {
|
|
18316
|
+
if (padding === 0) {
|
|
18317
|
+
let pending = bits;
|
|
18318
|
+
let count = chars;
|
|
18319
|
+
for (let value; index < length && (value = sextet[chunk[index]]) < 64; index++) {
|
|
18320
|
+
pending = pending << 6 | value;
|
|
18321
|
+
if (++count === 4) {
|
|
18322
|
+
if (at + 3 > segment.length) grow();
|
|
18323
|
+
segment[at++] = pending >> 16;
|
|
18324
|
+
segment[at++] = pending >> 8;
|
|
18325
|
+
segment[at++] = pending;
|
|
18326
|
+
total += 3;
|
|
18327
|
+
pending = 0;
|
|
18328
|
+
count = 0;
|
|
18329
|
+
}
|
|
18330
|
+
}
|
|
18331
|
+
bits = pending;
|
|
18332
|
+
chars = count;
|
|
18333
|
+
}
|
|
18334
|
+
if (index >= length) break;
|
|
18335
|
+
byte = chunk[index];
|
|
18336
|
+
if (byte === QUOTE) {
|
|
18337
|
+
closeBlob();
|
|
18338
|
+
from = index;
|
|
18339
|
+
} else if (byte === EQUALS && chars > 1 && padding < 4 - chars) padding++;
|
|
18340
|
+
else {
|
|
18341
|
+
restore();
|
|
18342
|
+
mode = SKIP;
|
|
18343
|
+
from = index--;
|
|
18344
|
+
}
|
|
18345
|
+
} else if (mode !== OUTSIDE) {
|
|
18346
|
+
if (mode === KEY) key = key?.get(byte);
|
|
18347
|
+
if (escaped) escaped = false;
|
|
18348
|
+
else if (byte === BACKSLASH) escaped = true;
|
|
18349
|
+
else if (byte === QUOTE) {
|
|
18350
|
+
if (mode === KEY) frames.at(-1).next = key;
|
|
18351
|
+
mode = OUTSIDE;
|
|
18352
|
+
}
|
|
18353
|
+
} else if (byte === QUOTE) {
|
|
18354
|
+
const frame = frames.at(-1);
|
|
18355
|
+
if (skipped > 0) mode = SKIP;
|
|
18356
|
+
else if (frame?.keys && (last === LEFT_BRACE || last === COMMA)) {
|
|
18357
|
+
mode = KEY;
|
|
18358
|
+
key = frame.keys;
|
|
18359
|
+
} else if ((frame ? frame.next : paths)?.get(true)) {
|
|
18360
|
+
mode = BLOB;
|
|
18361
|
+
emit(chunk, from, index + 1);
|
|
18362
|
+
} else mode = SKIP;
|
|
18363
|
+
} else if (byte === LEFT_BRACE || byte === LEFT_BRACKET) {
|
|
18364
|
+
last = byte;
|
|
18365
|
+
const frame = frames.at(-1);
|
|
18366
|
+
const node = skipped > 0 ? void 0 : frame ? frame.next : paths;
|
|
18367
|
+
const items = node?.get(null);
|
|
18368
|
+
if (byte === LEFT_BRACE && node) frames.push({ keys: node });
|
|
18369
|
+
else if (byte === LEFT_BRACKET && items) frames.push({
|
|
18370
|
+
keys: null,
|
|
18371
|
+
next: items
|
|
18372
|
+
});
|
|
18373
|
+
else skipped++;
|
|
18374
|
+
} else if (byte === RIGHT_BRACE || byte === RIGHT_BRACKET) {
|
|
18375
|
+
if (skipped > 0) skipped--;
|
|
18376
|
+
else frames.pop();
|
|
18377
|
+
} else if (byte === COMMA || byte === COLON) last = byte;
|
|
18378
|
+
}
|
|
18379
|
+
if (mode !== BLOB) emit(chunk, from, length);
|
|
18380
|
+
};
|
|
18381
|
+
const finish = () => {
|
|
18382
|
+
if (mode === BLOB) restore();
|
|
18383
|
+
return {
|
|
18384
|
+
text: new TextDecoder().decode(join$1([...pieces, piece.subarray(0, pieceLength)], size)),
|
|
18385
|
+
binaries
|
|
18386
|
+
};
|
|
18387
|
+
};
|
|
18388
|
+
return {
|
|
18389
|
+
push,
|
|
18390
|
+
finish
|
|
18391
|
+
};
|
|
18392
|
+
}
|
|
18393
|
+
/**
|
|
18394
|
+
* Replaces the placeholders in a parsed value with the bytes they stand for.
|
|
18395
|
+
* Objects and arrays are copied, the parsed value is not modified. A
|
|
18396
|
+
* placeholder holds a random number, so a string that equals one is ours.
|
|
18397
|
+
*/
|
|
18398
|
+
function replaceBinaryFieldPlaceholders(value, binaries) {
|
|
18399
|
+
if (typeof value === "string") return binaries.get(value) ?? value;
|
|
18400
|
+
if (Array.isArray(value)) return value.map((item) => replaceBinaryFieldPlaceholders(item, binaries));
|
|
18401
|
+
if (value != null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([name, item]) => [name, replaceBinaryFieldPlaceholders(item, binaries)]));
|
|
18402
|
+
return value;
|
|
18403
|
+
}
|
|
18404
|
+
/**
|
|
18405
|
+
* Makes `JSON.stringify` give the placeholder for each of the arrays, instead
|
|
18406
|
+
* of `{"0":…,"1":…}` with an entry for every byte: 24 MiB of bytes would
|
|
18407
|
+
* become a string of more than 300 MB. That is what a validator, or the code
|
|
18408
|
+
* that reports its issues, does with a value it puts into an error message.
|
|
18409
|
+
* The property is not enumerable, so the arrays look the same otherwise.
|
|
18410
|
+
* Returns the function that removes it again.
|
|
18411
|
+
*/
|
|
18412
|
+
function maskBinariesInJson(binaries) {
|
|
18413
|
+
for (const [placeholder, bytes] of binaries) Object.defineProperty(bytes, "toJSON", {
|
|
18414
|
+
value: () => placeholder,
|
|
18415
|
+
configurable: true
|
|
18416
|
+
});
|
|
18417
|
+
return () => {
|
|
18418
|
+
for (const bytes of binaries.values()) Reflect.deleteProperty(bytes, "toJSON");
|
|
18419
|
+
};
|
|
18420
|
+
}
|
|
18421
|
+
/**
|
|
18422
|
+
* Wraps a schema so that it validates the extracted bytes in place of their
|
|
18423
|
+
* placeholders. The value parsed from the skeleton, and the value of the
|
|
18424
|
+
* validation error of the response, keep the placeholders: reporting an error
|
|
18425
|
+
* never prints the bytes.
|
|
18426
|
+
*
|
|
18427
|
+
* The errors of the schema itself may hold the bytes: a Standard Schema
|
|
18428
|
+
* validator wraps the value it was given into an error, and the issues it
|
|
18429
|
+
* reports may carry the offending input. So that their messages do not grow
|
|
18430
|
+
* with the image, the arrays stringify as their placeholders, and keep doing
|
|
18431
|
+
* so as long as an error can refer to them. When the validation succeeds the
|
|
18432
|
+
* arrays are plain again, for whoever receives them.
|
|
18433
|
+
*/
|
|
18434
|
+
function withBinaryFields(schema, binaries) {
|
|
18435
|
+
if (binaries.size === 0) return schema;
|
|
18436
|
+
const actualSchema = asSchema(schema);
|
|
18437
|
+
return jsonSchema({}, { validate: async (value) => {
|
|
18438
|
+
const replaced = replaceBinaryFieldPlaceholders(value, binaries);
|
|
18439
|
+
const unmask = maskBinariesInJson(binaries);
|
|
18440
|
+
const result = actualSchema.validate ? await actualSchema.validate(replaced) : {
|
|
18441
|
+
success: true,
|
|
18442
|
+
value: replaced
|
|
18443
|
+
};
|
|
18444
|
+
if (result.success) unmask();
|
|
18445
|
+
return result;
|
|
18446
|
+
} });
|
|
18447
|
+
}
|
|
17971
18448
|
const textDecoder = new TextDecoder();
|
|
17972
18449
|
const DEFAULT_MAX_JSON_LINE_BYTES = 67108864;
|
|
17973
18450
|
function wrapResponseBodyStream({ stream, url, requestBodyValues, statusCode, responseHeaders }) {
|
|
@@ -18090,29 +18567,45 @@ const createEventSourceResponseHandler = (chunkSchema) => async ({ response, url
|
|
|
18090
18567
|
})
|
|
18091
18568
|
};
|
|
18092
18569
|
};
|
|
18093
|
-
const createJsonResponseHandler = (responseSchema
|
|
18094
|
-
const
|
|
18095
|
-
|
|
18096
|
-
|
|
18097
|
-
|
|
18098
|
-
|
|
18099
|
-
|
|
18100
|
-
|
|
18101
|
-
|
|
18102
|
-
|
|
18103
|
-
|
|
18104
|
-
|
|
18105
|
-
|
|
18106
|
-
|
|
18107
|
-
|
|
18108
|
-
|
|
18109
|
-
|
|
18110
|
-
|
|
18111
|
-
|
|
18112
|
-
|
|
18113
|
-
|
|
18114
|
-
|
|
18115
|
-
|
|
18570
|
+
const createJsonResponseHandler = (responseSchema, { experimental_binaryFields } = {}) => {
|
|
18571
|
+
const binaryFieldPaths = experimental_binaryFields?.length ? compileBinaryFieldPaths(experimental_binaryFields) : void 0;
|
|
18572
|
+
return async ({ response, url, requestBodyValues }) => {
|
|
18573
|
+
let responseBody;
|
|
18574
|
+
let schema = responseSchema;
|
|
18575
|
+
if (binaryFieldPaths == null) responseBody = await readResponseBodyAsText({
|
|
18576
|
+
response,
|
|
18577
|
+
url
|
|
18578
|
+
});
|
|
18579
|
+
else {
|
|
18580
|
+
const scanner = createJsonBinaryFieldScanner(binaryFieldPaths);
|
|
18581
|
+
await readResponseWithSizeLimit({
|
|
18582
|
+
response,
|
|
18583
|
+
url,
|
|
18584
|
+
onChunk: scanner.push
|
|
18585
|
+
});
|
|
18586
|
+
const scanned = scanner.finish();
|
|
18587
|
+
responseBody = scanned.text;
|
|
18588
|
+
schema = withBinaryFields(responseSchema, scanned.binaries);
|
|
18589
|
+
}
|
|
18590
|
+
const parsedResult = await safeParseJSON({
|
|
18591
|
+
text: responseBody,
|
|
18592
|
+
schema
|
|
18593
|
+
});
|
|
18594
|
+
const responseHeaders = extractResponseHeaders(response);
|
|
18595
|
+
if (!parsedResult.success) throw new APICallError({
|
|
18596
|
+
message: "Invalid JSON response",
|
|
18597
|
+
cause: parsedResult.error,
|
|
18598
|
+
statusCode: response.status,
|
|
18599
|
+
responseHeaders,
|
|
18600
|
+
responseBody,
|
|
18601
|
+
url,
|
|
18602
|
+
requestBodyValues
|
|
18603
|
+
});
|
|
18604
|
+
return {
|
|
18605
|
+
responseHeaders,
|
|
18606
|
+
value: parsedResult.value,
|
|
18607
|
+
rawValue: parsedResult.rawValue
|
|
18608
|
+
};
|
|
18116
18609
|
};
|
|
18117
18610
|
};
|
|
18118
18611
|
const createJsonLinesResponseHandler = (responseSchema, { maxLineBytes = DEFAULT_MAX_JSON_LINE_BYTES } = {}) => {
|
|
@@ -18196,20 +18689,20 @@ function isJSONSerializable(value) {
|
|
|
18196
18689
|
if (Object.getPrototypeOf(value) === Object.prototype) return Object.values(value).every(isJSONSerializable);
|
|
18197
18690
|
return false;
|
|
18198
18691
|
}
|
|
18199
|
-
const name$
|
|
18200
|
-
const marker$
|
|
18201
|
-
const symbol$
|
|
18692
|
+
const name$12 = "AI_SerializationError";
|
|
18693
|
+
const marker$12 = `vercel.ai.error.${name$12}`;
|
|
18694
|
+
const symbol$12 = Symbol.for(marker$12);
|
|
18202
18695
|
var SerializationError = class extends AISDKError {
|
|
18203
18696
|
constructor({ message = "Failed to serialize value.", cause } = {}) {
|
|
18204
18697
|
super({
|
|
18205
|
-
name: name$
|
|
18698
|
+
name: name$12,
|
|
18206
18699
|
message,
|
|
18207
18700
|
cause
|
|
18208
18701
|
});
|
|
18209
|
-
this[symbol$
|
|
18702
|
+
this[symbol$12] = true;
|
|
18210
18703
|
}
|
|
18211
18704
|
static isInstance(error) {
|
|
18212
|
-
return AISDKError.hasMarker(error, marker$
|
|
18705
|
+
return AISDKError.hasMarker(error, marker$12);
|
|
18213
18706
|
}
|
|
18214
18707
|
};
|
|
18215
18708
|
/**
|
|
@@ -18477,7 +18970,7 @@ function isSegment(value) {
|
|
|
18477
18970
|
function withoutTrailingSlash(url) {
|
|
18478
18971
|
return url?.replace(/\/$/, "");
|
|
18479
18972
|
}
|
|
18480
|
-
// ../_vendored/ai_v7/dist/dist-
|
|
18973
|
+
// ../_vendored/ai_v7/dist/dist-BKjca_9x.js
|
|
18481
18974
|
/**
|
|
18482
18975
|
* Symbol used to define custom serialization for user-defined class instances.
|
|
18483
18976
|
* The static method should accept an instance and return serializable data.
|
|
@@ -42595,4 +43088,4 @@ Notes:
|
|
|
42595
43088
|
};
|
|
42596
43089
|
export { summarizeConversation as A, injectAnchorIds as B, wrapInObservationGroup as C, WorkingMemoryExtractor as D, Subconscious as E, extractCurrentTask as F, OBSERVATION_CONTEXT_INSTRUCTIONS as G, stripEphemeralAnchorIds as H, formatMessagesForObserver as I, OBSERVATION_CONTINUATION_HINT as J, OBSERVATION_CONTEXT_PROMPT as K, hasCurrentTaskSection as L, OBSERVER_SYSTEM_PROMPT as M, buildObserverPrompt as N, deepMergeWorkingMemory as O, buildObserverSystemPrompt as P, optimizeObservationsForContext as R, stripObservationGroups as S, StaleKnowledgeSemanticIndexError as T, Extractor as U, parseAnchorId as V, OBSERVATIONAL_MEMORY_DEFAULTS as W, getObservationContextPrompt as Y, combineObservationGroupRanges as _, extractWorkingMemoryContent as a, reconcileObservationGroupsFromReflection as b, getObservationsAsOf as c, AUTO_MODEL_BY_PROVIDER as d, resolveAutoModelId as f, ModelByInputTokens as g, WorkingMemoryStateProcessor as h, WorkingMemory as i, TokenCounter as j, SUMMARIZE_THREAD_DEFAULTS as k, ObservationalMemoryProcessor as l, WORKING_MEMORY_STATE_PROCESSOR_ID as m, MessageHistory$1 as n, extractWorkingMemoryTags as o, WORKING_MEMORY_STATE_ID as p, OBSERVATION_CONTEXT_PROMPT_THREAD as q, SemanticRecall as r, removeWorkingMemoryTags as s, Memory as t, ObservationalMemory as u, deriveObservationGroupProvenance as v, KnowledgeSemanticIndexCoordinator as w, renderObservationGroupsForReflection as x, parseObservationGroups as y, parseObserverOutput as z };
|
|
42597
43090
|
|
|
42598
|
-
//# sourceMappingURL=src-
|
|
43091
|
+
//# sourceMappingURL=src-BkElV36S.js.map
|