@ai-sdk/provider-utils 3.0.20 → 3.0.22
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/CHANGELOG.md +19 -2
- package/dist/index.d.mts +58 -2
- package/dist/index.d.ts +58 -2
- package/dist/index.js +289 -105
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +237 -57
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -100,17 +100,17 @@ var DelayedPromise = class {
|
|
|
100
100
|
return this._promise;
|
|
101
101
|
}
|
|
102
102
|
resolve(value) {
|
|
103
|
-
var
|
|
103
|
+
var _a2;
|
|
104
104
|
this.status = { type: "resolved", value };
|
|
105
105
|
if (this._promise) {
|
|
106
|
-
(
|
|
106
|
+
(_a2 = this._resolve) == null ? void 0 : _a2.call(this, value);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
reject(error) {
|
|
110
|
-
var
|
|
110
|
+
var _a2;
|
|
111
111
|
this.status = { type: "rejected", error };
|
|
112
112
|
if (this._promise) {
|
|
113
|
-
(
|
|
113
|
+
(_a2 = this._reject) == null ? void 0 : _a2.call(this, error);
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
isResolved() {
|
|
@@ -129,6 +129,86 @@ function extractResponseHeaders(response) {
|
|
|
129
129
|
return Object.fromEntries([...response.headers]);
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
// src/download-error.ts
|
|
133
|
+
import { AISDKError } from "@ai-sdk/provider";
|
|
134
|
+
var name = "AI_DownloadError";
|
|
135
|
+
var marker = `vercel.ai.error.${name}`;
|
|
136
|
+
var symbol = Symbol.for(marker);
|
|
137
|
+
var _a, _b;
|
|
138
|
+
var DownloadError = class extends (_b = AISDKError, _a = symbol, _b) {
|
|
139
|
+
constructor({
|
|
140
|
+
url,
|
|
141
|
+
statusCode,
|
|
142
|
+
statusText,
|
|
143
|
+
cause,
|
|
144
|
+
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
|
145
|
+
}) {
|
|
146
|
+
super({ name, message, cause });
|
|
147
|
+
this[_a] = true;
|
|
148
|
+
this.url = url;
|
|
149
|
+
this.statusCode = statusCode;
|
|
150
|
+
this.statusText = statusText;
|
|
151
|
+
}
|
|
152
|
+
static isInstance(error) {
|
|
153
|
+
return AISDKError.hasMarker(error, marker);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// src/read-response-with-size-limit.ts
|
|
158
|
+
var DEFAULT_MAX_DOWNLOAD_SIZE = 2 * 1024 * 1024 * 1024;
|
|
159
|
+
async function readResponseWithSizeLimit({
|
|
160
|
+
response,
|
|
161
|
+
url,
|
|
162
|
+
maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE
|
|
163
|
+
}) {
|
|
164
|
+
const contentLength = response.headers.get("content-length");
|
|
165
|
+
if (contentLength != null) {
|
|
166
|
+
const length = parseInt(contentLength, 10);
|
|
167
|
+
if (!isNaN(length) && length > maxBytes) {
|
|
168
|
+
throw new DownloadError({
|
|
169
|
+
url,
|
|
170
|
+
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes (Content-Length: ${length}).`
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const body = response.body;
|
|
175
|
+
if (body == null) {
|
|
176
|
+
return new Uint8Array(0);
|
|
177
|
+
}
|
|
178
|
+
const reader = body.getReader();
|
|
179
|
+
const chunks = [];
|
|
180
|
+
let totalBytes = 0;
|
|
181
|
+
try {
|
|
182
|
+
while (true) {
|
|
183
|
+
const { done, value } = await reader.read();
|
|
184
|
+
if (done) {
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
totalBytes += value.length;
|
|
188
|
+
if (totalBytes > maxBytes) {
|
|
189
|
+
throw new DownloadError({
|
|
190
|
+
url,
|
|
191
|
+
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes.`
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
chunks.push(value);
|
|
195
|
+
}
|
|
196
|
+
} finally {
|
|
197
|
+
try {
|
|
198
|
+
await reader.cancel();
|
|
199
|
+
} finally {
|
|
200
|
+
reader.releaseLock();
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const result = new Uint8Array(totalBytes);
|
|
204
|
+
let offset = 0;
|
|
205
|
+
for (const chunk of chunks) {
|
|
206
|
+
result.set(chunk, offset);
|
|
207
|
+
offset += chunk.length;
|
|
208
|
+
}
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
|
|
132
212
|
// src/generate-id.ts
|
|
133
213
|
import { InvalidArgumentError } from "@ai-sdk/provider";
|
|
134
214
|
var createIdGenerator = ({
|
|
@@ -212,14 +292,14 @@ function handleFetchError({
|
|
|
212
292
|
|
|
213
293
|
// src/get-runtime-environment-user-agent.ts
|
|
214
294
|
function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
215
|
-
var
|
|
295
|
+
var _a2, _b2, _c;
|
|
216
296
|
if (globalThisAny.window) {
|
|
217
297
|
return `runtime/browser`;
|
|
218
298
|
}
|
|
219
|
-
if ((
|
|
299
|
+
if ((_a2 = globalThisAny.navigator) == null ? void 0 : _a2.userAgent) {
|
|
220
300
|
return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
|
|
221
301
|
}
|
|
222
|
-
if ((_c = (
|
|
302
|
+
if ((_c = (_b2 = globalThisAny.process) == null ? void 0 : _b2.versions) == null ? void 0 : _c.node) {
|
|
223
303
|
return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
|
|
224
304
|
}
|
|
225
305
|
if (globalThisAny.EdgeRuntime) {
|
|
@@ -263,7 +343,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
263
343
|
}
|
|
264
344
|
|
|
265
345
|
// src/version.ts
|
|
266
|
-
var VERSION = true ? "3.0.
|
|
346
|
+
var VERSION = true ? "3.0.22" : "0.0.0-test";
|
|
267
347
|
|
|
268
348
|
// src/get-from-api.ts
|
|
269
349
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -360,8 +440,8 @@ function injectJsonInstructionIntoMessages({
|
|
|
360
440
|
schemaPrefix,
|
|
361
441
|
schemaSuffix
|
|
362
442
|
}) {
|
|
363
|
-
var
|
|
364
|
-
const systemMessage = ((
|
|
443
|
+
var _a2, _b2;
|
|
444
|
+
const systemMessage = ((_a2 = messages[0]) == null ? void 0 : _a2.role) === "system" ? { ...messages[0] } : { role: "system", content: "" };
|
|
365
445
|
systemMessage.content = injectJsonInstruction({
|
|
366
446
|
prompt: systemMessage.content,
|
|
367
447
|
schema,
|
|
@@ -370,7 +450,7 @@ function injectJsonInstructionIntoMessages({
|
|
|
370
450
|
});
|
|
371
451
|
return [
|
|
372
452
|
systemMessage,
|
|
373
|
-
...((
|
|
453
|
+
...((_b2 = messages[0]) == null ? void 0 : _b2.role) === "system" ? messages.slice(1) : messages
|
|
374
454
|
];
|
|
375
455
|
}
|
|
376
456
|
|
|
@@ -478,15 +558,15 @@ function loadSetting({
|
|
|
478
558
|
|
|
479
559
|
// src/media-type-to-extension.ts
|
|
480
560
|
function mediaTypeToExtension(mediaType) {
|
|
481
|
-
var
|
|
561
|
+
var _a2;
|
|
482
562
|
const [_type, subtype = ""] = mediaType.toLowerCase().split("/");
|
|
483
|
-
return (
|
|
563
|
+
return (_a2 = {
|
|
484
564
|
mpeg: "mp3",
|
|
485
565
|
"x-wav": "wav",
|
|
486
566
|
opus: "ogg",
|
|
487
567
|
mp4: "m4a",
|
|
488
568
|
"x-m4a": "m4a"
|
|
489
|
-
}[subtype]) != null ?
|
|
569
|
+
}[subtype]) != null ? _a2 : subtype;
|
|
490
570
|
}
|
|
491
571
|
|
|
492
572
|
// src/parse-json.ts
|
|
@@ -496,8 +576,8 @@ import {
|
|
|
496
576
|
} from "@ai-sdk/provider";
|
|
497
577
|
|
|
498
578
|
// src/secure-json-parse.ts
|
|
499
|
-
var suspectProtoRx = /"
|
|
500
|
-
var suspectConstructorRx = /"
|
|
579
|
+
var suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
|
|
580
|
+
var suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
501
581
|
function _parse(text) {
|
|
502
582
|
const obj = JSON.parse(text);
|
|
503
583
|
if (obj === null || typeof obj !== "object") {
|
|
@@ -517,7 +597,7 @@ function filter(obj) {
|
|
|
517
597
|
if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
|
|
518
598
|
throw new SyntaxError("Object contains forbidden prototype property");
|
|
519
599
|
}
|
|
520
|
-
if (Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
600
|
+
if (Object.prototype.hasOwnProperty.call(node, "constructor") && node.constructor !== null && typeof node.constructor === "object" && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
521
601
|
throw new SyntaxError("Object contains forbidden prototype property");
|
|
522
602
|
}
|
|
523
603
|
for (const key in node) {
|
|
@@ -835,7 +915,7 @@ function dynamicTool(tool2) {
|
|
|
835
915
|
// src/provider-defined-tool-factory.ts
|
|
836
916
|
function createProviderDefinedToolFactory({
|
|
837
917
|
id,
|
|
838
|
-
name,
|
|
918
|
+
name: name2,
|
|
839
919
|
inputSchema
|
|
840
920
|
}) {
|
|
841
921
|
return ({
|
|
@@ -849,7 +929,7 @@ function createProviderDefinedToolFactory({
|
|
|
849
929
|
}) => tool({
|
|
850
930
|
type: "provider-defined",
|
|
851
931
|
id,
|
|
852
|
-
name,
|
|
932
|
+
name: name2,
|
|
853
933
|
args,
|
|
854
934
|
inputSchema,
|
|
855
935
|
outputSchema,
|
|
@@ -862,7 +942,7 @@ function createProviderDefinedToolFactory({
|
|
|
862
942
|
}
|
|
863
943
|
function createProviderDefinedToolFactoryWithOutputSchema({
|
|
864
944
|
id,
|
|
865
|
-
name,
|
|
945
|
+
name: name2,
|
|
866
946
|
inputSchema,
|
|
867
947
|
outputSchema
|
|
868
948
|
}) {
|
|
@@ -876,7 +956,7 @@ function createProviderDefinedToolFactoryWithOutputSchema({
|
|
|
876
956
|
}) => tool({
|
|
877
957
|
type: "provider-defined",
|
|
878
958
|
id,
|
|
879
|
-
name,
|
|
959
|
+
name: name2,
|
|
880
960
|
args,
|
|
881
961
|
inputSchema,
|
|
882
962
|
outputSchema,
|
|
@@ -1152,11 +1232,11 @@ function parseAnyDef() {
|
|
|
1152
1232
|
// src/zod-to-json-schema/parsers/array.ts
|
|
1153
1233
|
import { ZodFirstPartyTypeKind } from "zod/v3";
|
|
1154
1234
|
function parseArrayDef(def, refs) {
|
|
1155
|
-
var
|
|
1235
|
+
var _a2, _b2, _c;
|
|
1156
1236
|
const res = {
|
|
1157
1237
|
type: "array"
|
|
1158
1238
|
};
|
|
1159
|
-
if (((
|
|
1239
|
+
if (((_a2 = def.type) == null ? void 0 : _a2._def) && ((_c = (_b2 = def.type) == null ? void 0 : _b2._def) == null ? void 0 : _c.typeName) !== ZodFirstPartyTypeKind.ZodAny) {
|
|
1160
1240
|
res.items = parseDef(def.type._def, {
|
|
1161
1241
|
...refs,
|
|
1162
1242
|
currentPath: [...refs.currentPath, "items"]
|
|
@@ -1549,8 +1629,8 @@ function escapeNonAlphaNumeric(source) {
|
|
|
1549
1629
|
return result;
|
|
1550
1630
|
}
|
|
1551
1631
|
function addFormat(schema, value, message, refs) {
|
|
1552
|
-
var
|
|
1553
|
-
if (schema.format || ((
|
|
1632
|
+
var _a2;
|
|
1633
|
+
if (schema.format || ((_a2 = schema.anyOf) == null ? void 0 : _a2.some((x) => x.format))) {
|
|
1554
1634
|
if (!schema.anyOf) {
|
|
1555
1635
|
schema.anyOf = [];
|
|
1556
1636
|
}
|
|
@@ -1569,8 +1649,8 @@ function addFormat(schema, value, message, refs) {
|
|
|
1569
1649
|
}
|
|
1570
1650
|
}
|
|
1571
1651
|
function addPattern(schema, regex, message, refs) {
|
|
1572
|
-
var
|
|
1573
|
-
if (schema.pattern || ((
|
|
1652
|
+
var _a2;
|
|
1653
|
+
if (schema.pattern || ((_a2 = schema.allOf) == null ? void 0 : _a2.some((x) => x.pattern))) {
|
|
1574
1654
|
if (!schema.allOf) {
|
|
1575
1655
|
schema.allOf = [];
|
|
1576
1656
|
}
|
|
@@ -1589,7 +1669,7 @@ function addPattern(schema, regex, message, refs) {
|
|
|
1589
1669
|
}
|
|
1590
1670
|
}
|
|
1591
1671
|
function stringifyRegExpWithFlags(regex, refs) {
|
|
1592
|
-
var
|
|
1672
|
+
var _a2;
|
|
1593
1673
|
if (!refs.applyRegexFlags || !regex.flags) {
|
|
1594
1674
|
return regex.source;
|
|
1595
1675
|
}
|
|
@@ -1619,7 +1699,7 @@ function stringifyRegExpWithFlags(regex, refs) {
|
|
|
1619
1699
|
pattern += source[i];
|
|
1620
1700
|
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
1621
1701
|
inCharRange = false;
|
|
1622
|
-
} else if (source[i + 1] === "-" && ((
|
|
1702
|
+
} else if (source[i + 1] === "-" && ((_a2 = source[i + 2]) == null ? void 0 : _a2.match(/[a-z]/))) {
|
|
1623
1703
|
pattern += source[i];
|
|
1624
1704
|
inCharRange = true;
|
|
1625
1705
|
} else {
|
|
@@ -1673,15 +1753,15 @@ function stringifyRegExpWithFlags(regex, refs) {
|
|
|
1673
1753
|
|
|
1674
1754
|
// src/zod-to-json-schema/parsers/record.ts
|
|
1675
1755
|
function parseRecordDef(def, refs) {
|
|
1676
|
-
var
|
|
1756
|
+
var _a2, _b2, _c, _d, _e, _f;
|
|
1677
1757
|
const schema = {
|
|
1678
1758
|
type: "object",
|
|
1679
|
-
additionalProperties: (
|
|
1759
|
+
additionalProperties: (_a2 = parseDef(def.valueType._def, {
|
|
1680
1760
|
...refs,
|
|
1681
1761
|
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1682
|
-
})) != null ?
|
|
1762
|
+
})) != null ? _a2 : refs.allowedAdditionalProperties
|
|
1683
1763
|
};
|
|
1684
|
-
if (((
|
|
1764
|
+
if (((_b2 = def.keyType) == null ? void 0 : _b2._def.typeName) === ZodFirstPartyTypeKind2.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
1685
1765
|
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
1686
1766
|
return {
|
|
1687
1767
|
...schema,
|
|
@@ -1954,8 +2034,8 @@ function safeIsOptional(schema) {
|
|
|
1954
2034
|
|
|
1955
2035
|
// src/zod-to-json-schema/parsers/optional.ts
|
|
1956
2036
|
var parseOptionalDef = (def, refs) => {
|
|
1957
|
-
var
|
|
1958
|
-
if (refs.currentPath.toString() === ((
|
|
2037
|
+
var _a2;
|
|
2038
|
+
if (refs.currentPath.toString() === ((_a2 = refs.propertyPath) == null ? void 0 : _a2.toString())) {
|
|
1959
2039
|
return parseDef(def.innerType._def, refs);
|
|
1960
2040
|
}
|
|
1961
2041
|
const innerSchema = parseDef(def.innerType._def, {
|
|
@@ -2143,10 +2223,10 @@ var selectParser = (def, typeName, refs) => {
|
|
|
2143
2223
|
|
|
2144
2224
|
// src/zod-to-json-schema/parse-def.ts
|
|
2145
2225
|
function parseDef(def, refs, forceResolution = false) {
|
|
2146
|
-
var
|
|
2226
|
+
var _a2;
|
|
2147
2227
|
const seenItem = refs.seen.get(def);
|
|
2148
2228
|
if (refs.override) {
|
|
2149
|
-
const overrideResult = (
|
|
2229
|
+
const overrideResult = (_a2 = refs.override) == null ? void 0 : _a2.call(
|
|
2150
2230
|
refs,
|
|
2151
2231
|
def,
|
|
2152
2232
|
refs,
|
|
@@ -2214,11 +2294,11 @@ var getRefs = (options) => {
|
|
|
2214
2294
|
currentPath,
|
|
2215
2295
|
propertyPath: void 0,
|
|
2216
2296
|
seen: new Map(
|
|
2217
|
-
Object.entries(_options.definitions).map(([
|
|
2297
|
+
Object.entries(_options.definitions).map(([name2, def]) => [
|
|
2218
2298
|
def._def,
|
|
2219
2299
|
{
|
|
2220
2300
|
def: def._def,
|
|
2221
|
-
path: [..._options.basePath, _options.definitionPath,
|
|
2301
|
+
path: [..._options.basePath, _options.definitionPath, name2],
|
|
2222
2302
|
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
2223
2303
|
jsonSchema: void 0
|
|
2224
2304
|
}
|
|
@@ -2229,50 +2309,50 @@ var getRefs = (options) => {
|
|
|
2229
2309
|
|
|
2230
2310
|
// src/zod-to-json-schema/zod-to-json-schema.ts
|
|
2231
2311
|
var zodToJsonSchema = (schema, options) => {
|
|
2232
|
-
var
|
|
2312
|
+
var _a2;
|
|
2233
2313
|
const refs = getRefs(options);
|
|
2234
2314
|
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
|
|
2235
|
-
(acc, [
|
|
2236
|
-
var
|
|
2315
|
+
(acc, [name3, schema2]) => {
|
|
2316
|
+
var _a3;
|
|
2237
2317
|
return {
|
|
2238
2318
|
...acc,
|
|
2239
|
-
[
|
|
2319
|
+
[name3]: (_a3 = parseDef(
|
|
2240
2320
|
schema2._def,
|
|
2241
2321
|
{
|
|
2242
2322
|
...refs,
|
|
2243
|
-
currentPath: [...refs.basePath, refs.definitionPath,
|
|
2323
|
+
currentPath: [...refs.basePath, refs.definitionPath, name3]
|
|
2244
2324
|
},
|
|
2245
2325
|
true
|
|
2246
|
-
)) != null ?
|
|
2326
|
+
)) != null ? _a3 : parseAnyDef()
|
|
2247
2327
|
};
|
|
2248
2328
|
},
|
|
2249
2329
|
{}
|
|
2250
2330
|
) : void 0;
|
|
2251
|
-
const
|
|
2252
|
-
const main = (
|
|
2331
|
+
const name2 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
|
|
2332
|
+
const main = (_a2 = parseDef(
|
|
2253
2333
|
schema._def,
|
|
2254
|
-
|
|
2334
|
+
name2 === void 0 ? refs : {
|
|
2255
2335
|
...refs,
|
|
2256
|
-
currentPath: [...refs.basePath, refs.definitionPath,
|
|
2336
|
+
currentPath: [...refs.basePath, refs.definitionPath, name2]
|
|
2257
2337
|
},
|
|
2258
2338
|
false
|
|
2259
|
-
)) != null ?
|
|
2339
|
+
)) != null ? _a2 : parseAnyDef();
|
|
2260
2340
|
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
2261
2341
|
if (title !== void 0) {
|
|
2262
2342
|
main.title = title;
|
|
2263
2343
|
}
|
|
2264
|
-
const combined =
|
|
2344
|
+
const combined = name2 === void 0 ? definitions ? {
|
|
2265
2345
|
...main,
|
|
2266
2346
|
[refs.definitionPath]: definitions
|
|
2267
2347
|
} : main : {
|
|
2268
2348
|
$ref: [
|
|
2269
2349
|
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
2270
2350
|
refs.definitionPath,
|
|
2271
|
-
|
|
2351
|
+
name2
|
|
2272
2352
|
].join("/"),
|
|
2273
2353
|
[refs.definitionPath]: {
|
|
2274
2354
|
...definitions,
|
|
2275
|
-
[
|
|
2355
|
+
[name2]: main
|
|
2276
2356
|
}
|
|
2277
2357
|
};
|
|
2278
2358
|
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
@@ -2284,8 +2364,8 @@ var zod_to_json_schema_default = zodToJsonSchema;
|
|
|
2284
2364
|
|
|
2285
2365
|
// src/zod-schema.ts
|
|
2286
2366
|
function zod3Schema(zodSchema2, options) {
|
|
2287
|
-
var
|
|
2288
|
-
const useReferences = (
|
|
2367
|
+
var _a2;
|
|
2368
|
+
const useReferences = (_a2 = options == null ? void 0 : options.useReferences) != null ? _a2 : false;
|
|
2289
2369
|
return jsonSchema(
|
|
2290
2370
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
2291
2371
|
() => zod_to_json_schema_default(zodSchema2, {
|
|
@@ -2300,8 +2380,8 @@ function zod3Schema(zodSchema2, options) {
|
|
|
2300
2380
|
);
|
|
2301
2381
|
}
|
|
2302
2382
|
function zod4Schema(zodSchema2, options) {
|
|
2303
|
-
var
|
|
2304
|
-
const useReferences = (
|
|
2383
|
+
var _a2;
|
|
2384
|
+
const useReferences = (_a2 = options == null ? void 0 : options.useReferences) != null ? _a2 : false;
|
|
2305
2385
|
return jsonSchema(
|
|
2306
2386
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
2307
2387
|
() => addAdditionalPropertiesToJsonSchema(
|
|
@@ -2386,6 +2466,102 @@ function convertToBase64(value) {
|
|
|
2386
2466
|
return value instanceof Uint8Array ? convertUint8ArrayToBase64(value) : value;
|
|
2387
2467
|
}
|
|
2388
2468
|
|
|
2469
|
+
// src/validate-download-url.ts
|
|
2470
|
+
function validateDownloadUrl(url) {
|
|
2471
|
+
let parsed;
|
|
2472
|
+
try {
|
|
2473
|
+
parsed = new URL(url);
|
|
2474
|
+
} catch (e) {
|
|
2475
|
+
throw new DownloadError({
|
|
2476
|
+
url,
|
|
2477
|
+
message: `Invalid URL: ${url}`
|
|
2478
|
+
});
|
|
2479
|
+
}
|
|
2480
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
2481
|
+
throw new DownloadError({
|
|
2482
|
+
url,
|
|
2483
|
+
message: `URL scheme must be http or https, got ${parsed.protocol}`
|
|
2484
|
+
});
|
|
2485
|
+
}
|
|
2486
|
+
const hostname = parsed.hostname;
|
|
2487
|
+
if (!hostname) {
|
|
2488
|
+
throw new DownloadError({
|
|
2489
|
+
url,
|
|
2490
|
+
message: `URL must have a hostname`
|
|
2491
|
+
});
|
|
2492
|
+
}
|
|
2493
|
+
if (hostname === "localhost" || hostname.endsWith(".local") || hostname.endsWith(".localhost")) {
|
|
2494
|
+
throw new DownloadError({
|
|
2495
|
+
url,
|
|
2496
|
+
message: `URL with hostname ${hostname} is not allowed`
|
|
2497
|
+
});
|
|
2498
|
+
}
|
|
2499
|
+
if (hostname.startsWith("[") && hostname.endsWith("]")) {
|
|
2500
|
+
const ipv6 = hostname.slice(1, -1);
|
|
2501
|
+
if (isPrivateIPv6(ipv6)) {
|
|
2502
|
+
throw new DownloadError({
|
|
2503
|
+
url,
|
|
2504
|
+
message: `URL with IPv6 address ${hostname} is not allowed`
|
|
2505
|
+
});
|
|
2506
|
+
}
|
|
2507
|
+
return;
|
|
2508
|
+
}
|
|
2509
|
+
if (isIPv4(hostname)) {
|
|
2510
|
+
if (isPrivateIPv4(hostname)) {
|
|
2511
|
+
throw new DownloadError({
|
|
2512
|
+
url,
|
|
2513
|
+
message: `URL with IP address ${hostname} is not allowed`
|
|
2514
|
+
});
|
|
2515
|
+
}
|
|
2516
|
+
return;
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
function isIPv4(hostname) {
|
|
2520
|
+
const parts = hostname.split(".");
|
|
2521
|
+
if (parts.length !== 4) return false;
|
|
2522
|
+
return parts.every((part) => {
|
|
2523
|
+
const num = Number(part);
|
|
2524
|
+
return Number.isInteger(num) && num >= 0 && num <= 255 && String(num) === part;
|
|
2525
|
+
});
|
|
2526
|
+
}
|
|
2527
|
+
function isPrivateIPv4(ip) {
|
|
2528
|
+
const parts = ip.split(".").map(Number);
|
|
2529
|
+
const [a, b] = parts;
|
|
2530
|
+
if (a === 0) return true;
|
|
2531
|
+
if (a === 10) return true;
|
|
2532
|
+
if (a === 127) return true;
|
|
2533
|
+
if (a === 169 && b === 254) return true;
|
|
2534
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
2535
|
+
if (a === 192 && b === 168) return true;
|
|
2536
|
+
return false;
|
|
2537
|
+
}
|
|
2538
|
+
function isPrivateIPv6(ip) {
|
|
2539
|
+
const normalized = ip.toLowerCase();
|
|
2540
|
+
if (normalized === "::1") return true;
|
|
2541
|
+
if (normalized === "::") return true;
|
|
2542
|
+
if (normalized.startsWith("::ffff:")) {
|
|
2543
|
+
const mappedPart = normalized.slice(7);
|
|
2544
|
+
if (isIPv4(mappedPart)) {
|
|
2545
|
+
return isPrivateIPv4(mappedPart);
|
|
2546
|
+
}
|
|
2547
|
+
const hexParts = mappedPart.split(":");
|
|
2548
|
+
if (hexParts.length === 2) {
|
|
2549
|
+
const high = parseInt(hexParts[0], 16);
|
|
2550
|
+
const low = parseInt(hexParts[1], 16);
|
|
2551
|
+
if (!isNaN(high) && !isNaN(low)) {
|
|
2552
|
+
const a = high >> 8 & 255;
|
|
2553
|
+
const b = high & 255;
|
|
2554
|
+
const c = low >> 8 & 255;
|
|
2555
|
+
const d = low & 255;
|
|
2556
|
+
return isPrivateIPv4(`${a}.${b}.${c}.${d}`);
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
2559
|
+
}
|
|
2560
|
+
if (normalized.startsWith("fc") || normalized.startsWith("fd")) return true;
|
|
2561
|
+
if (normalized.startsWith("fe80")) return true;
|
|
2562
|
+
return false;
|
|
2563
|
+
}
|
|
2564
|
+
|
|
2389
2565
|
// src/without-trailing-slash.ts
|
|
2390
2566
|
function withoutTrailingSlash(url) {
|
|
2391
2567
|
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
@@ -2421,7 +2597,9 @@ import {
|
|
|
2421
2597
|
EventSourceParserStream as EventSourceParserStream2
|
|
2422
2598
|
} from "eventsource-parser/stream";
|
|
2423
2599
|
export {
|
|
2600
|
+
DEFAULT_MAX_DOWNLOAD_SIZE,
|
|
2424
2601
|
DelayedPromise,
|
|
2602
|
+
DownloadError,
|
|
2425
2603
|
EventSourceParserStream2 as EventSourceParserStream,
|
|
2426
2604
|
VERSION,
|
|
2427
2605
|
asSchema,
|
|
@@ -2467,12 +2645,14 @@ export {
|
|
|
2467
2645
|
postFormDataToApi,
|
|
2468
2646
|
postJsonToApi,
|
|
2469
2647
|
postToApi,
|
|
2648
|
+
readResponseWithSizeLimit,
|
|
2470
2649
|
removeUndefinedEntries,
|
|
2471
2650
|
resolve,
|
|
2472
2651
|
safeParseJSON,
|
|
2473
2652
|
safeValidateTypes,
|
|
2474
2653
|
standardSchemaValidator,
|
|
2475
2654
|
tool,
|
|
2655
|
+
validateDownloadUrl,
|
|
2476
2656
|
validateTypes,
|
|
2477
2657
|
validator,
|
|
2478
2658
|
withUserAgentSuffix,
|