@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.js
CHANGED
|
@@ -6,8 +6,8 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __export = (target, all) => {
|
|
9
|
-
for (var
|
|
10
|
-
__defProp(target,
|
|
9
|
+
for (var name2 in all)
|
|
10
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
11
11
|
};
|
|
12
12
|
var __copyProps = (to, from, except, desc) => {
|
|
13
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -31,7 +31,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var src_exports = {};
|
|
33
33
|
__export(src_exports, {
|
|
34
|
+
DEFAULT_MAX_DOWNLOAD_SIZE: () => DEFAULT_MAX_DOWNLOAD_SIZE,
|
|
34
35
|
DelayedPromise: () => DelayedPromise,
|
|
36
|
+
DownloadError: () => DownloadError,
|
|
35
37
|
EventSourceParserStream: () => import_stream2.EventSourceParserStream,
|
|
36
38
|
VERSION: () => VERSION,
|
|
37
39
|
asSchema: () => asSchema,
|
|
@@ -77,12 +79,14 @@ __export(src_exports, {
|
|
|
77
79
|
postFormDataToApi: () => postFormDataToApi,
|
|
78
80
|
postJsonToApi: () => postJsonToApi,
|
|
79
81
|
postToApi: () => postToApi,
|
|
82
|
+
readResponseWithSizeLimit: () => readResponseWithSizeLimit,
|
|
80
83
|
removeUndefinedEntries: () => removeUndefinedEntries,
|
|
81
84
|
resolve: () => resolve,
|
|
82
85
|
safeParseJSON: () => safeParseJSON,
|
|
83
86
|
safeValidateTypes: () => safeValidateTypes,
|
|
84
87
|
standardSchemaValidator: () => standardSchemaValidator,
|
|
85
88
|
tool: () => tool,
|
|
89
|
+
validateDownloadUrl: () => validateDownloadUrl,
|
|
86
90
|
validateTypes: () => validateTypes,
|
|
87
91
|
validator: () => validator,
|
|
88
92
|
withUserAgentSuffix: () => withUserAgentSuffix,
|
|
@@ -193,17 +197,17 @@ var DelayedPromise = class {
|
|
|
193
197
|
return this._promise;
|
|
194
198
|
}
|
|
195
199
|
resolve(value) {
|
|
196
|
-
var
|
|
200
|
+
var _a2;
|
|
197
201
|
this.status = { type: "resolved", value };
|
|
198
202
|
if (this._promise) {
|
|
199
|
-
(
|
|
203
|
+
(_a2 = this._resolve) == null ? void 0 : _a2.call(this, value);
|
|
200
204
|
}
|
|
201
205
|
}
|
|
202
206
|
reject(error) {
|
|
203
|
-
var
|
|
207
|
+
var _a2;
|
|
204
208
|
this.status = { type: "rejected", error };
|
|
205
209
|
if (this._promise) {
|
|
206
|
-
(
|
|
210
|
+
(_a2 = this._reject) == null ? void 0 : _a2.call(this, error);
|
|
207
211
|
}
|
|
208
212
|
}
|
|
209
213
|
isResolved() {
|
|
@@ -222,8 +226,88 @@ function extractResponseHeaders(response) {
|
|
|
222
226
|
return Object.fromEntries([...response.headers]);
|
|
223
227
|
}
|
|
224
228
|
|
|
225
|
-
// src/
|
|
229
|
+
// src/download-error.ts
|
|
226
230
|
var import_provider = require("@ai-sdk/provider");
|
|
231
|
+
var name = "AI_DownloadError";
|
|
232
|
+
var marker = `vercel.ai.error.${name}`;
|
|
233
|
+
var symbol = Symbol.for(marker);
|
|
234
|
+
var _a, _b;
|
|
235
|
+
var DownloadError = class extends (_b = import_provider.AISDKError, _a = symbol, _b) {
|
|
236
|
+
constructor({
|
|
237
|
+
url,
|
|
238
|
+
statusCode,
|
|
239
|
+
statusText,
|
|
240
|
+
cause,
|
|
241
|
+
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
|
242
|
+
}) {
|
|
243
|
+
super({ name, message, cause });
|
|
244
|
+
this[_a] = true;
|
|
245
|
+
this.url = url;
|
|
246
|
+
this.statusCode = statusCode;
|
|
247
|
+
this.statusText = statusText;
|
|
248
|
+
}
|
|
249
|
+
static isInstance(error) {
|
|
250
|
+
return import_provider.AISDKError.hasMarker(error, marker);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
// src/read-response-with-size-limit.ts
|
|
255
|
+
var DEFAULT_MAX_DOWNLOAD_SIZE = 2 * 1024 * 1024 * 1024;
|
|
256
|
+
async function readResponseWithSizeLimit({
|
|
257
|
+
response,
|
|
258
|
+
url,
|
|
259
|
+
maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE
|
|
260
|
+
}) {
|
|
261
|
+
const contentLength = response.headers.get("content-length");
|
|
262
|
+
if (contentLength != null) {
|
|
263
|
+
const length = parseInt(contentLength, 10);
|
|
264
|
+
if (!isNaN(length) && length > maxBytes) {
|
|
265
|
+
throw new DownloadError({
|
|
266
|
+
url,
|
|
267
|
+
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes (Content-Length: ${length}).`
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
const body = response.body;
|
|
272
|
+
if (body == null) {
|
|
273
|
+
return new Uint8Array(0);
|
|
274
|
+
}
|
|
275
|
+
const reader = body.getReader();
|
|
276
|
+
const chunks = [];
|
|
277
|
+
let totalBytes = 0;
|
|
278
|
+
try {
|
|
279
|
+
while (true) {
|
|
280
|
+
const { done, value } = await reader.read();
|
|
281
|
+
if (done) {
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
totalBytes += value.length;
|
|
285
|
+
if (totalBytes > maxBytes) {
|
|
286
|
+
throw new DownloadError({
|
|
287
|
+
url,
|
|
288
|
+
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes.`
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
chunks.push(value);
|
|
292
|
+
}
|
|
293
|
+
} finally {
|
|
294
|
+
try {
|
|
295
|
+
await reader.cancel();
|
|
296
|
+
} finally {
|
|
297
|
+
reader.releaseLock();
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
const result = new Uint8Array(totalBytes);
|
|
301
|
+
let offset = 0;
|
|
302
|
+
for (const chunk of chunks) {
|
|
303
|
+
result.set(chunk, offset);
|
|
304
|
+
offset += chunk.length;
|
|
305
|
+
}
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// src/generate-id.ts
|
|
310
|
+
var import_provider2 = require("@ai-sdk/provider");
|
|
227
311
|
var createIdGenerator = ({
|
|
228
312
|
prefix,
|
|
229
313
|
size = 16,
|
|
@@ -242,7 +326,7 @@ var createIdGenerator = ({
|
|
|
242
326
|
return generator;
|
|
243
327
|
}
|
|
244
328
|
if (alphabet.includes(separator)) {
|
|
245
|
-
throw new
|
|
329
|
+
throw new import_provider2.InvalidArgumentError({
|
|
246
330
|
argument: "separator",
|
|
247
331
|
message: `The separator "${separator}" must not be part of the alphabet "${alphabet}".`
|
|
248
332
|
});
|
|
@@ -266,10 +350,10 @@ function getErrorMessage(error) {
|
|
|
266
350
|
}
|
|
267
351
|
|
|
268
352
|
// src/get-from-api.ts
|
|
269
|
-
var
|
|
353
|
+
var import_provider4 = require("@ai-sdk/provider");
|
|
270
354
|
|
|
271
355
|
// src/handle-fetch-error.ts
|
|
272
|
-
var
|
|
356
|
+
var import_provider3 = require("@ai-sdk/provider");
|
|
273
357
|
|
|
274
358
|
// src/is-abort-error.ts
|
|
275
359
|
function isAbortError(error) {
|
|
@@ -290,7 +374,7 @@ function handleFetchError({
|
|
|
290
374
|
if (error instanceof TypeError && FETCH_FAILED_ERROR_MESSAGES.includes(error.message.toLowerCase())) {
|
|
291
375
|
const cause = error.cause;
|
|
292
376
|
if (cause != null) {
|
|
293
|
-
return new
|
|
377
|
+
return new import_provider3.APICallError({
|
|
294
378
|
message: `Cannot connect to API: ${cause.message}`,
|
|
295
379
|
cause,
|
|
296
380
|
url,
|
|
@@ -305,14 +389,14 @@ function handleFetchError({
|
|
|
305
389
|
|
|
306
390
|
// src/get-runtime-environment-user-agent.ts
|
|
307
391
|
function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
308
|
-
var
|
|
392
|
+
var _a2, _b2, _c;
|
|
309
393
|
if (globalThisAny.window) {
|
|
310
394
|
return `runtime/browser`;
|
|
311
395
|
}
|
|
312
|
-
if ((
|
|
396
|
+
if ((_a2 = globalThisAny.navigator) == null ? void 0 : _a2.userAgent) {
|
|
313
397
|
return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
|
|
314
398
|
}
|
|
315
|
-
if ((_c = (
|
|
399
|
+
if ((_c = (_b2 = globalThisAny.process) == null ? void 0 : _b2.versions) == null ? void 0 : _c.node) {
|
|
316
400
|
return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
|
|
317
401
|
}
|
|
318
402
|
if (globalThisAny.EdgeRuntime) {
|
|
@@ -356,7 +440,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
356
440
|
}
|
|
357
441
|
|
|
358
442
|
// src/version.ts
|
|
359
|
-
var VERSION = true ? "3.0.
|
|
443
|
+
var VERSION = true ? "3.0.22" : "0.0.0-test";
|
|
360
444
|
|
|
361
445
|
// src/get-from-api.ts
|
|
362
446
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -388,10 +472,10 @@ var getFromApi = async ({
|
|
|
388
472
|
requestBodyValues: {}
|
|
389
473
|
});
|
|
390
474
|
} catch (error) {
|
|
391
|
-
if (isAbortError(error) ||
|
|
475
|
+
if (isAbortError(error) || import_provider4.APICallError.isInstance(error)) {
|
|
392
476
|
throw error;
|
|
393
477
|
}
|
|
394
|
-
throw new
|
|
478
|
+
throw new import_provider4.APICallError({
|
|
395
479
|
message: "Failed to process error response",
|
|
396
480
|
cause: error,
|
|
397
481
|
statusCode: response.status,
|
|
@@ -410,11 +494,11 @@ var getFromApi = async ({
|
|
|
410
494
|
});
|
|
411
495
|
} catch (error) {
|
|
412
496
|
if (error instanceof Error) {
|
|
413
|
-
if (isAbortError(error) ||
|
|
497
|
+
if (isAbortError(error) || import_provider4.APICallError.isInstance(error)) {
|
|
414
498
|
throw error;
|
|
415
499
|
}
|
|
416
500
|
}
|
|
417
|
-
throw new
|
|
501
|
+
throw new import_provider4.APICallError({
|
|
418
502
|
message: "Failed to process successful response",
|
|
419
503
|
cause: error,
|
|
420
504
|
statusCode: response.status,
|
|
@@ -453,8 +537,8 @@ function injectJsonInstructionIntoMessages({
|
|
|
453
537
|
schemaPrefix,
|
|
454
538
|
schemaSuffix
|
|
455
539
|
}) {
|
|
456
|
-
var
|
|
457
|
-
const systemMessage = ((
|
|
540
|
+
var _a2, _b2;
|
|
541
|
+
const systemMessage = ((_a2 = messages[0]) == null ? void 0 : _a2.role) === "system" ? { ...messages[0] } : { role: "system", content: "" };
|
|
458
542
|
systemMessage.content = injectJsonInstruction({
|
|
459
543
|
prompt: systemMessage.content,
|
|
460
544
|
schema,
|
|
@@ -463,7 +547,7 @@ function injectJsonInstructionIntoMessages({
|
|
|
463
547
|
});
|
|
464
548
|
return [
|
|
465
549
|
systemMessage,
|
|
466
|
-
...((
|
|
550
|
+
...((_b2 = messages[0]) == null ? void 0 : _b2.role) === "system" ? messages.slice(1) : messages
|
|
467
551
|
];
|
|
468
552
|
}
|
|
469
553
|
|
|
@@ -482,7 +566,7 @@ function isUrlSupported({
|
|
|
482
566
|
}
|
|
483
567
|
|
|
484
568
|
// src/load-api-key.ts
|
|
485
|
-
var
|
|
569
|
+
var import_provider5 = require("@ai-sdk/provider");
|
|
486
570
|
function loadApiKey({
|
|
487
571
|
apiKey,
|
|
488
572
|
environmentVariableName,
|
|
@@ -493,23 +577,23 @@ function loadApiKey({
|
|
|
493
577
|
return apiKey;
|
|
494
578
|
}
|
|
495
579
|
if (apiKey != null) {
|
|
496
|
-
throw new
|
|
580
|
+
throw new import_provider5.LoadAPIKeyError({
|
|
497
581
|
message: `${description} API key must be a string.`
|
|
498
582
|
});
|
|
499
583
|
}
|
|
500
584
|
if (typeof process === "undefined") {
|
|
501
|
-
throw new
|
|
585
|
+
throw new import_provider5.LoadAPIKeyError({
|
|
502
586
|
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.`
|
|
503
587
|
});
|
|
504
588
|
}
|
|
505
589
|
apiKey = process.env[environmentVariableName];
|
|
506
590
|
if (apiKey == null) {
|
|
507
|
-
throw new
|
|
591
|
+
throw new import_provider5.LoadAPIKeyError({
|
|
508
592
|
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`
|
|
509
593
|
});
|
|
510
594
|
}
|
|
511
595
|
if (typeof apiKey !== "string") {
|
|
512
|
-
throw new
|
|
596
|
+
throw new import_provider5.LoadAPIKeyError({
|
|
513
597
|
message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
514
598
|
});
|
|
515
599
|
}
|
|
@@ -535,7 +619,7 @@ function loadOptionalSetting({
|
|
|
535
619
|
}
|
|
536
620
|
|
|
537
621
|
// src/load-setting.ts
|
|
538
|
-
var
|
|
622
|
+
var import_provider6 = require("@ai-sdk/provider");
|
|
539
623
|
function loadSetting({
|
|
540
624
|
settingValue,
|
|
541
625
|
environmentVariableName,
|
|
@@ -546,23 +630,23 @@ function loadSetting({
|
|
|
546
630
|
return settingValue;
|
|
547
631
|
}
|
|
548
632
|
if (settingValue != null) {
|
|
549
|
-
throw new
|
|
633
|
+
throw new import_provider6.LoadSettingError({
|
|
550
634
|
message: `${description} setting must be a string.`
|
|
551
635
|
});
|
|
552
636
|
}
|
|
553
637
|
if (typeof process === "undefined") {
|
|
554
|
-
throw new
|
|
638
|
+
throw new import_provider6.LoadSettingError({
|
|
555
639
|
message: `${description} setting is missing. Pass it using the '${settingName}' parameter. Environment variables is not supported in this environment.`
|
|
556
640
|
});
|
|
557
641
|
}
|
|
558
642
|
settingValue = process.env[environmentVariableName];
|
|
559
643
|
if (settingValue == null) {
|
|
560
|
-
throw new
|
|
644
|
+
throw new import_provider6.LoadSettingError({
|
|
561
645
|
message: `${description} setting is missing. Pass it using the '${settingName}' parameter or the ${environmentVariableName} environment variable.`
|
|
562
646
|
});
|
|
563
647
|
}
|
|
564
648
|
if (typeof settingValue !== "string") {
|
|
565
|
-
throw new
|
|
649
|
+
throw new import_provider6.LoadSettingError({
|
|
566
650
|
message: `${description} setting must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
567
651
|
});
|
|
568
652
|
}
|
|
@@ -571,23 +655,23 @@ function loadSetting({
|
|
|
571
655
|
|
|
572
656
|
// src/media-type-to-extension.ts
|
|
573
657
|
function mediaTypeToExtension(mediaType) {
|
|
574
|
-
var
|
|
658
|
+
var _a2;
|
|
575
659
|
const [_type, subtype = ""] = mediaType.toLowerCase().split("/");
|
|
576
|
-
return (
|
|
660
|
+
return (_a2 = {
|
|
577
661
|
mpeg: "mp3",
|
|
578
662
|
"x-wav": "wav",
|
|
579
663
|
opus: "ogg",
|
|
580
664
|
mp4: "m4a",
|
|
581
665
|
"x-m4a": "m4a"
|
|
582
|
-
}[subtype]) != null ?
|
|
666
|
+
}[subtype]) != null ? _a2 : subtype;
|
|
583
667
|
}
|
|
584
668
|
|
|
585
669
|
// src/parse-json.ts
|
|
586
|
-
var
|
|
670
|
+
var import_provider9 = require("@ai-sdk/provider");
|
|
587
671
|
|
|
588
672
|
// src/secure-json-parse.ts
|
|
589
|
-
var suspectProtoRx = /"
|
|
590
|
-
var suspectConstructorRx = /"
|
|
673
|
+
var suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
|
|
674
|
+
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*:/;
|
|
591
675
|
function _parse(text) {
|
|
592
676
|
const obj = JSON.parse(text);
|
|
593
677
|
if (obj === null || typeof obj !== "object") {
|
|
@@ -607,7 +691,7 @@ function filter(obj) {
|
|
|
607
691
|
if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
|
|
608
692
|
throw new SyntaxError("Object contains forbidden prototype property");
|
|
609
693
|
}
|
|
610
|
-
if (Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
694
|
+
if (Object.prototype.hasOwnProperty.call(node, "constructor") && node.constructor !== null && typeof node.constructor === "object" && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
611
695
|
throw new SyntaxError("Object contains forbidden prototype property");
|
|
612
696
|
}
|
|
613
697
|
for (const key in node) {
|
|
@@ -635,10 +719,10 @@ function secureJsonParse(text) {
|
|
|
635
719
|
}
|
|
636
720
|
|
|
637
721
|
// src/validate-types.ts
|
|
638
|
-
var
|
|
722
|
+
var import_provider8 = require("@ai-sdk/provider");
|
|
639
723
|
|
|
640
724
|
// src/validator.ts
|
|
641
|
-
var
|
|
725
|
+
var import_provider7 = require("@ai-sdk/provider");
|
|
642
726
|
var validatorSymbol = Symbol.for("vercel.ai.validator");
|
|
643
727
|
function validator(validate) {
|
|
644
728
|
return { [validatorSymbol]: true, validate };
|
|
@@ -663,7 +747,7 @@ function standardSchemaValidator(standardSchema) {
|
|
|
663
747
|
const result = await standardSchema["~standard"].validate(value);
|
|
664
748
|
return result.issues == null ? { success: true, value: result.value } : {
|
|
665
749
|
success: false,
|
|
666
|
-
error: new
|
|
750
|
+
error: new import_provider7.TypeValidationError({
|
|
667
751
|
value,
|
|
668
752
|
cause: result.issues
|
|
669
753
|
})
|
|
@@ -678,7 +762,7 @@ async function validateTypes({
|
|
|
678
762
|
}) {
|
|
679
763
|
const result = await safeValidateTypes({ value, schema });
|
|
680
764
|
if (!result.success) {
|
|
681
|
-
throw
|
|
765
|
+
throw import_provider8.TypeValidationError.wrap({ value, cause: result.error });
|
|
682
766
|
}
|
|
683
767
|
return result.value;
|
|
684
768
|
}
|
|
@@ -697,13 +781,13 @@ async function safeValidateTypes({
|
|
|
697
781
|
}
|
|
698
782
|
return {
|
|
699
783
|
success: false,
|
|
700
|
-
error:
|
|
784
|
+
error: import_provider8.TypeValidationError.wrap({ value, cause: result.error }),
|
|
701
785
|
rawValue: value
|
|
702
786
|
};
|
|
703
787
|
} catch (error) {
|
|
704
788
|
return {
|
|
705
789
|
success: false,
|
|
706
|
-
error:
|
|
790
|
+
error: import_provider8.TypeValidationError.wrap({ value, cause: error }),
|
|
707
791
|
rawValue: value
|
|
708
792
|
};
|
|
709
793
|
}
|
|
@@ -721,10 +805,10 @@ async function parseJSON({
|
|
|
721
805
|
}
|
|
722
806
|
return validateTypes({ value, schema });
|
|
723
807
|
} catch (error) {
|
|
724
|
-
if (
|
|
808
|
+
if (import_provider9.JSONParseError.isInstance(error) || import_provider9.TypeValidationError.isInstance(error)) {
|
|
725
809
|
throw error;
|
|
726
810
|
}
|
|
727
|
-
throw new
|
|
811
|
+
throw new import_provider9.JSONParseError({ text, cause: error });
|
|
728
812
|
}
|
|
729
813
|
}
|
|
730
814
|
async function safeParseJSON({
|
|
@@ -740,7 +824,7 @@ async function safeParseJSON({
|
|
|
740
824
|
} catch (error) {
|
|
741
825
|
return {
|
|
742
826
|
success: false,
|
|
743
|
-
error:
|
|
827
|
+
error: import_provider9.JSONParseError.isInstance(error) ? error : new import_provider9.JSONParseError({ text, cause: error }),
|
|
744
828
|
rawValue: void 0
|
|
745
829
|
};
|
|
746
830
|
}
|
|
@@ -773,7 +857,7 @@ function parseJsonEventStream({
|
|
|
773
857
|
}
|
|
774
858
|
|
|
775
859
|
// src/parse-provider-options.ts
|
|
776
|
-
var
|
|
860
|
+
var import_provider10 = require("@ai-sdk/provider");
|
|
777
861
|
async function parseProviderOptions({
|
|
778
862
|
provider,
|
|
779
863
|
providerOptions,
|
|
@@ -787,7 +871,7 @@ async function parseProviderOptions({
|
|
|
787
871
|
schema
|
|
788
872
|
});
|
|
789
873
|
if (!parsedProviderOptions.success) {
|
|
790
|
-
throw new
|
|
874
|
+
throw new import_provider10.InvalidArgumentError({
|
|
791
875
|
argument: "providerOptions",
|
|
792
876
|
message: `invalid ${provider} provider options`,
|
|
793
877
|
cause: parsedProviderOptions.error
|
|
@@ -797,7 +881,7 @@ async function parseProviderOptions({
|
|
|
797
881
|
}
|
|
798
882
|
|
|
799
883
|
// src/post-to-api.ts
|
|
800
|
-
var
|
|
884
|
+
var import_provider11 = require("@ai-sdk/provider");
|
|
801
885
|
var getOriginalFetch2 = () => globalThis.fetch;
|
|
802
886
|
var postJsonToApi = async ({
|
|
803
887
|
url,
|
|
@@ -872,10 +956,10 @@ var postToApi = async ({
|
|
|
872
956
|
requestBodyValues: body.values
|
|
873
957
|
});
|
|
874
958
|
} catch (error) {
|
|
875
|
-
if (isAbortError(error) ||
|
|
959
|
+
if (isAbortError(error) || import_provider11.APICallError.isInstance(error)) {
|
|
876
960
|
throw error;
|
|
877
961
|
}
|
|
878
|
-
throw new
|
|
962
|
+
throw new import_provider11.APICallError({
|
|
879
963
|
message: "Failed to process error response",
|
|
880
964
|
cause: error,
|
|
881
965
|
statusCode: response.status,
|
|
@@ -894,11 +978,11 @@ var postToApi = async ({
|
|
|
894
978
|
});
|
|
895
979
|
} catch (error) {
|
|
896
980
|
if (error instanceof Error) {
|
|
897
|
-
if (isAbortError(error) ||
|
|
981
|
+
if (isAbortError(error) || import_provider11.APICallError.isInstance(error)) {
|
|
898
982
|
throw error;
|
|
899
983
|
}
|
|
900
984
|
}
|
|
901
|
-
throw new
|
|
985
|
+
throw new import_provider11.APICallError({
|
|
902
986
|
message: "Failed to process successful response",
|
|
903
987
|
cause: error,
|
|
904
988
|
statusCode: response.status,
|
|
@@ -923,7 +1007,7 @@ function dynamicTool(tool2) {
|
|
|
923
1007
|
// src/provider-defined-tool-factory.ts
|
|
924
1008
|
function createProviderDefinedToolFactory({
|
|
925
1009
|
id,
|
|
926
|
-
name,
|
|
1010
|
+
name: name2,
|
|
927
1011
|
inputSchema
|
|
928
1012
|
}) {
|
|
929
1013
|
return ({
|
|
@@ -937,7 +1021,7 @@ function createProviderDefinedToolFactory({
|
|
|
937
1021
|
}) => tool({
|
|
938
1022
|
type: "provider-defined",
|
|
939
1023
|
id,
|
|
940
|
-
name,
|
|
1024
|
+
name: name2,
|
|
941
1025
|
args,
|
|
942
1026
|
inputSchema,
|
|
943
1027
|
outputSchema,
|
|
@@ -950,7 +1034,7 @@ function createProviderDefinedToolFactory({
|
|
|
950
1034
|
}
|
|
951
1035
|
function createProviderDefinedToolFactoryWithOutputSchema({
|
|
952
1036
|
id,
|
|
953
|
-
name,
|
|
1037
|
+
name: name2,
|
|
954
1038
|
inputSchema,
|
|
955
1039
|
outputSchema
|
|
956
1040
|
}) {
|
|
@@ -964,7 +1048,7 @@ function createProviderDefinedToolFactoryWithOutputSchema({
|
|
|
964
1048
|
}) => tool({
|
|
965
1049
|
type: "provider-defined",
|
|
966
1050
|
id,
|
|
967
|
-
name,
|
|
1051
|
+
name: name2,
|
|
968
1052
|
args,
|
|
969
1053
|
inputSchema,
|
|
970
1054
|
outputSchema,
|
|
@@ -992,7 +1076,7 @@ async function resolve(value) {
|
|
|
992
1076
|
}
|
|
993
1077
|
|
|
994
1078
|
// src/response-handler.ts
|
|
995
|
-
var
|
|
1079
|
+
var import_provider12 = require("@ai-sdk/provider");
|
|
996
1080
|
var createJsonErrorResponseHandler = ({
|
|
997
1081
|
errorSchema,
|
|
998
1082
|
errorToMessage,
|
|
@@ -1003,7 +1087,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
1003
1087
|
if (responseBody.trim() === "") {
|
|
1004
1088
|
return {
|
|
1005
1089
|
responseHeaders,
|
|
1006
|
-
value: new
|
|
1090
|
+
value: new import_provider12.APICallError({
|
|
1007
1091
|
message: response.statusText,
|
|
1008
1092
|
url,
|
|
1009
1093
|
requestBodyValues,
|
|
@@ -1021,7 +1105,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
1021
1105
|
});
|
|
1022
1106
|
return {
|
|
1023
1107
|
responseHeaders,
|
|
1024
|
-
value: new
|
|
1108
|
+
value: new import_provider12.APICallError({
|
|
1025
1109
|
message: errorToMessage(parsedError),
|
|
1026
1110
|
url,
|
|
1027
1111
|
requestBodyValues,
|
|
@@ -1035,7 +1119,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
1035
1119
|
} catch (parseError) {
|
|
1036
1120
|
return {
|
|
1037
1121
|
responseHeaders,
|
|
1038
|
-
value: new
|
|
1122
|
+
value: new import_provider12.APICallError({
|
|
1039
1123
|
message: response.statusText,
|
|
1040
1124
|
url,
|
|
1041
1125
|
requestBodyValues,
|
|
@@ -1050,7 +1134,7 @@ var createJsonErrorResponseHandler = ({
|
|
|
1050
1134
|
var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) => {
|
|
1051
1135
|
const responseHeaders = extractResponseHeaders(response);
|
|
1052
1136
|
if (response.body == null) {
|
|
1053
|
-
throw new
|
|
1137
|
+
throw new import_provider12.EmptyResponseBodyError({});
|
|
1054
1138
|
}
|
|
1055
1139
|
return {
|
|
1056
1140
|
responseHeaders,
|
|
@@ -1063,7 +1147,7 @@ var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) =>
|
|
|
1063
1147
|
var createJsonStreamResponseHandler = (chunkSchema) => async ({ response }) => {
|
|
1064
1148
|
const responseHeaders = extractResponseHeaders(response);
|
|
1065
1149
|
if (response.body == null) {
|
|
1066
|
-
throw new
|
|
1150
|
+
throw new import_provider12.EmptyResponseBodyError({});
|
|
1067
1151
|
}
|
|
1068
1152
|
let buffer = "";
|
|
1069
1153
|
return {
|
|
@@ -1095,7 +1179,7 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
|
1095
1179
|
});
|
|
1096
1180
|
const responseHeaders = extractResponseHeaders(response);
|
|
1097
1181
|
if (!parsedResult.success) {
|
|
1098
|
-
throw new
|
|
1182
|
+
throw new import_provider12.APICallError({
|
|
1099
1183
|
message: "Invalid JSON response",
|
|
1100
1184
|
cause: parsedResult.error,
|
|
1101
1185
|
statusCode: response.status,
|
|
@@ -1114,7 +1198,7 @@ var createJsonResponseHandler = (responseSchema) => async ({ response, url, requ
|
|
|
1114
1198
|
var createBinaryResponseHandler = () => async ({ response, url, requestBodyValues }) => {
|
|
1115
1199
|
const responseHeaders = extractResponseHeaders(response);
|
|
1116
1200
|
if (!response.body) {
|
|
1117
|
-
throw new
|
|
1201
|
+
throw new import_provider12.APICallError({
|
|
1118
1202
|
message: "Response body is empty",
|
|
1119
1203
|
url,
|
|
1120
1204
|
requestBodyValues,
|
|
@@ -1130,7 +1214,7 @@ var createBinaryResponseHandler = () => async ({ response, url, requestBodyValue
|
|
|
1130
1214
|
value: new Uint8Array(buffer)
|
|
1131
1215
|
};
|
|
1132
1216
|
} catch (error) {
|
|
1133
|
-
throw new
|
|
1217
|
+
throw new import_provider12.APICallError({
|
|
1134
1218
|
message: "Failed to read response as array buffer",
|
|
1135
1219
|
url,
|
|
1136
1220
|
requestBodyValues,
|
|
@@ -1146,7 +1230,7 @@ var createStatusCodeErrorResponseHandler = () => async ({ response, url, request
|
|
|
1146
1230
|
const responseBody = await response.text();
|
|
1147
1231
|
return {
|
|
1148
1232
|
responseHeaders,
|
|
1149
|
-
value: new
|
|
1233
|
+
value: new import_provider12.APICallError({
|
|
1150
1234
|
message: response.statusText,
|
|
1151
1235
|
url,
|
|
1152
1236
|
requestBodyValues,
|
|
@@ -1240,11 +1324,11 @@ function parseAnyDef() {
|
|
|
1240
1324
|
// src/zod-to-json-schema/parsers/array.ts
|
|
1241
1325
|
var import_v3 = require("zod/v3");
|
|
1242
1326
|
function parseArrayDef(def, refs) {
|
|
1243
|
-
var
|
|
1327
|
+
var _a2, _b2, _c;
|
|
1244
1328
|
const res = {
|
|
1245
1329
|
type: "array"
|
|
1246
1330
|
};
|
|
1247
|
-
if (((
|
|
1331
|
+
if (((_a2 = def.type) == null ? void 0 : _a2._def) && ((_c = (_b2 = def.type) == null ? void 0 : _b2._def) == null ? void 0 : _c.typeName) !== import_v3.ZodFirstPartyTypeKind.ZodAny) {
|
|
1248
1332
|
res.items = parseDef(def.type._def, {
|
|
1249
1333
|
...refs,
|
|
1250
1334
|
currentPath: [...refs.currentPath, "items"]
|
|
@@ -1635,8 +1719,8 @@ function escapeNonAlphaNumeric(source) {
|
|
|
1635
1719
|
return result;
|
|
1636
1720
|
}
|
|
1637
1721
|
function addFormat(schema, value, message, refs) {
|
|
1638
|
-
var
|
|
1639
|
-
if (schema.format || ((
|
|
1722
|
+
var _a2;
|
|
1723
|
+
if (schema.format || ((_a2 = schema.anyOf) == null ? void 0 : _a2.some((x) => x.format))) {
|
|
1640
1724
|
if (!schema.anyOf) {
|
|
1641
1725
|
schema.anyOf = [];
|
|
1642
1726
|
}
|
|
@@ -1655,8 +1739,8 @@ function addFormat(schema, value, message, refs) {
|
|
|
1655
1739
|
}
|
|
1656
1740
|
}
|
|
1657
1741
|
function addPattern(schema, regex, message, refs) {
|
|
1658
|
-
var
|
|
1659
|
-
if (schema.pattern || ((
|
|
1742
|
+
var _a2;
|
|
1743
|
+
if (schema.pattern || ((_a2 = schema.allOf) == null ? void 0 : _a2.some((x) => x.pattern))) {
|
|
1660
1744
|
if (!schema.allOf) {
|
|
1661
1745
|
schema.allOf = [];
|
|
1662
1746
|
}
|
|
@@ -1675,7 +1759,7 @@ function addPattern(schema, regex, message, refs) {
|
|
|
1675
1759
|
}
|
|
1676
1760
|
}
|
|
1677
1761
|
function stringifyRegExpWithFlags(regex, refs) {
|
|
1678
|
-
var
|
|
1762
|
+
var _a2;
|
|
1679
1763
|
if (!refs.applyRegexFlags || !regex.flags) {
|
|
1680
1764
|
return regex.source;
|
|
1681
1765
|
}
|
|
@@ -1705,7 +1789,7 @@ function stringifyRegExpWithFlags(regex, refs) {
|
|
|
1705
1789
|
pattern += source[i];
|
|
1706
1790
|
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
1707
1791
|
inCharRange = false;
|
|
1708
|
-
} else if (source[i + 1] === "-" && ((
|
|
1792
|
+
} else if (source[i + 1] === "-" && ((_a2 = source[i + 2]) == null ? void 0 : _a2.match(/[a-z]/))) {
|
|
1709
1793
|
pattern += source[i];
|
|
1710
1794
|
inCharRange = true;
|
|
1711
1795
|
} else {
|
|
@@ -1759,15 +1843,15 @@ function stringifyRegExpWithFlags(regex, refs) {
|
|
|
1759
1843
|
|
|
1760
1844
|
// src/zod-to-json-schema/parsers/record.ts
|
|
1761
1845
|
function parseRecordDef(def, refs) {
|
|
1762
|
-
var
|
|
1846
|
+
var _a2, _b2, _c, _d, _e, _f;
|
|
1763
1847
|
const schema = {
|
|
1764
1848
|
type: "object",
|
|
1765
|
-
additionalProperties: (
|
|
1849
|
+
additionalProperties: (_a2 = parseDef(def.valueType._def, {
|
|
1766
1850
|
...refs,
|
|
1767
1851
|
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1768
|
-
})) != null ?
|
|
1852
|
+
})) != null ? _a2 : refs.allowedAdditionalProperties
|
|
1769
1853
|
};
|
|
1770
|
-
if (((
|
|
1854
|
+
if (((_b2 = def.keyType) == null ? void 0 : _b2._def.typeName) === import_v32.ZodFirstPartyTypeKind.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
1771
1855
|
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
1772
1856
|
return {
|
|
1773
1857
|
...schema,
|
|
@@ -2040,8 +2124,8 @@ function safeIsOptional(schema) {
|
|
|
2040
2124
|
|
|
2041
2125
|
// src/zod-to-json-schema/parsers/optional.ts
|
|
2042
2126
|
var parseOptionalDef = (def, refs) => {
|
|
2043
|
-
var
|
|
2044
|
-
if (refs.currentPath.toString() === ((
|
|
2127
|
+
var _a2;
|
|
2128
|
+
if (refs.currentPath.toString() === ((_a2 = refs.propertyPath) == null ? void 0 : _a2.toString())) {
|
|
2045
2129
|
return parseDef(def.innerType._def, refs);
|
|
2046
2130
|
}
|
|
2047
2131
|
const innerSchema = parseDef(def.innerType._def, {
|
|
@@ -2229,10 +2313,10 @@ var selectParser = (def, typeName, refs) => {
|
|
|
2229
2313
|
|
|
2230
2314
|
// src/zod-to-json-schema/parse-def.ts
|
|
2231
2315
|
function parseDef(def, refs, forceResolution = false) {
|
|
2232
|
-
var
|
|
2316
|
+
var _a2;
|
|
2233
2317
|
const seenItem = refs.seen.get(def);
|
|
2234
2318
|
if (refs.override) {
|
|
2235
|
-
const overrideResult = (
|
|
2319
|
+
const overrideResult = (_a2 = refs.override) == null ? void 0 : _a2.call(
|
|
2236
2320
|
refs,
|
|
2237
2321
|
def,
|
|
2238
2322
|
refs,
|
|
@@ -2300,11 +2384,11 @@ var getRefs = (options) => {
|
|
|
2300
2384
|
currentPath,
|
|
2301
2385
|
propertyPath: void 0,
|
|
2302
2386
|
seen: new Map(
|
|
2303
|
-
Object.entries(_options.definitions).map(([
|
|
2387
|
+
Object.entries(_options.definitions).map(([name2, def]) => [
|
|
2304
2388
|
def._def,
|
|
2305
2389
|
{
|
|
2306
2390
|
def: def._def,
|
|
2307
|
-
path: [..._options.basePath, _options.definitionPath,
|
|
2391
|
+
path: [..._options.basePath, _options.definitionPath, name2],
|
|
2308
2392
|
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
2309
2393
|
jsonSchema: void 0
|
|
2310
2394
|
}
|
|
@@ -2315,50 +2399,50 @@ var getRefs = (options) => {
|
|
|
2315
2399
|
|
|
2316
2400
|
// src/zod-to-json-schema/zod-to-json-schema.ts
|
|
2317
2401
|
var zodToJsonSchema = (schema, options) => {
|
|
2318
|
-
var
|
|
2402
|
+
var _a2;
|
|
2319
2403
|
const refs = getRefs(options);
|
|
2320
2404
|
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
|
|
2321
|
-
(acc, [
|
|
2322
|
-
var
|
|
2405
|
+
(acc, [name3, schema2]) => {
|
|
2406
|
+
var _a3;
|
|
2323
2407
|
return {
|
|
2324
2408
|
...acc,
|
|
2325
|
-
[
|
|
2409
|
+
[name3]: (_a3 = parseDef(
|
|
2326
2410
|
schema2._def,
|
|
2327
2411
|
{
|
|
2328
2412
|
...refs,
|
|
2329
|
-
currentPath: [...refs.basePath, refs.definitionPath,
|
|
2413
|
+
currentPath: [...refs.basePath, refs.definitionPath, name3]
|
|
2330
2414
|
},
|
|
2331
2415
|
true
|
|
2332
|
-
)) != null ?
|
|
2416
|
+
)) != null ? _a3 : parseAnyDef()
|
|
2333
2417
|
};
|
|
2334
2418
|
},
|
|
2335
2419
|
{}
|
|
2336
2420
|
) : void 0;
|
|
2337
|
-
const
|
|
2338
|
-
const main = (
|
|
2421
|
+
const name2 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
|
|
2422
|
+
const main = (_a2 = parseDef(
|
|
2339
2423
|
schema._def,
|
|
2340
|
-
|
|
2424
|
+
name2 === void 0 ? refs : {
|
|
2341
2425
|
...refs,
|
|
2342
|
-
currentPath: [...refs.basePath, refs.definitionPath,
|
|
2426
|
+
currentPath: [...refs.basePath, refs.definitionPath, name2]
|
|
2343
2427
|
},
|
|
2344
2428
|
false
|
|
2345
|
-
)) != null ?
|
|
2429
|
+
)) != null ? _a2 : parseAnyDef();
|
|
2346
2430
|
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
2347
2431
|
if (title !== void 0) {
|
|
2348
2432
|
main.title = title;
|
|
2349
2433
|
}
|
|
2350
|
-
const combined =
|
|
2434
|
+
const combined = name2 === void 0 ? definitions ? {
|
|
2351
2435
|
...main,
|
|
2352
2436
|
[refs.definitionPath]: definitions
|
|
2353
2437
|
} : main : {
|
|
2354
2438
|
$ref: [
|
|
2355
2439
|
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
2356
2440
|
refs.definitionPath,
|
|
2357
|
-
|
|
2441
|
+
name2
|
|
2358
2442
|
].join("/"),
|
|
2359
2443
|
[refs.definitionPath]: {
|
|
2360
2444
|
...definitions,
|
|
2361
|
-
[
|
|
2445
|
+
[name2]: main
|
|
2362
2446
|
}
|
|
2363
2447
|
};
|
|
2364
2448
|
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
@@ -2370,8 +2454,8 @@ var zod_to_json_schema_default = zodToJsonSchema;
|
|
|
2370
2454
|
|
|
2371
2455
|
// src/zod-schema.ts
|
|
2372
2456
|
function zod3Schema(zodSchema2, options) {
|
|
2373
|
-
var
|
|
2374
|
-
const useReferences = (
|
|
2457
|
+
var _a2;
|
|
2458
|
+
const useReferences = (_a2 = options == null ? void 0 : options.useReferences) != null ? _a2 : false;
|
|
2375
2459
|
return jsonSchema(
|
|
2376
2460
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
2377
2461
|
() => zod_to_json_schema_default(zodSchema2, {
|
|
@@ -2386,8 +2470,8 @@ function zod3Schema(zodSchema2, options) {
|
|
|
2386
2470
|
);
|
|
2387
2471
|
}
|
|
2388
2472
|
function zod4Schema(zodSchema2, options) {
|
|
2389
|
-
var
|
|
2390
|
-
const useReferences = (
|
|
2473
|
+
var _a2;
|
|
2474
|
+
const useReferences = (_a2 = options == null ? void 0 : options.useReferences) != null ? _a2 : false;
|
|
2391
2475
|
return jsonSchema(
|
|
2392
2476
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
2393
2477
|
() => addAdditionalPropertiesToJsonSchema(
|
|
@@ -2472,6 +2556,102 @@ function convertToBase64(value) {
|
|
|
2472
2556
|
return value instanceof Uint8Array ? convertUint8ArrayToBase64(value) : value;
|
|
2473
2557
|
}
|
|
2474
2558
|
|
|
2559
|
+
// src/validate-download-url.ts
|
|
2560
|
+
function validateDownloadUrl(url) {
|
|
2561
|
+
let parsed;
|
|
2562
|
+
try {
|
|
2563
|
+
parsed = new URL(url);
|
|
2564
|
+
} catch (e) {
|
|
2565
|
+
throw new DownloadError({
|
|
2566
|
+
url,
|
|
2567
|
+
message: `Invalid URL: ${url}`
|
|
2568
|
+
});
|
|
2569
|
+
}
|
|
2570
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
2571
|
+
throw new DownloadError({
|
|
2572
|
+
url,
|
|
2573
|
+
message: `URL scheme must be http or https, got ${parsed.protocol}`
|
|
2574
|
+
});
|
|
2575
|
+
}
|
|
2576
|
+
const hostname = parsed.hostname;
|
|
2577
|
+
if (!hostname) {
|
|
2578
|
+
throw new DownloadError({
|
|
2579
|
+
url,
|
|
2580
|
+
message: `URL must have a hostname`
|
|
2581
|
+
});
|
|
2582
|
+
}
|
|
2583
|
+
if (hostname === "localhost" || hostname.endsWith(".local") || hostname.endsWith(".localhost")) {
|
|
2584
|
+
throw new DownloadError({
|
|
2585
|
+
url,
|
|
2586
|
+
message: `URL with hostname ${hostname} is not allowed`
|
|
2587
|
+
});
|
|
2588
|
+
}
|
|
2589
|
+
if (hostname.startsWith("[") && hostname.endsWith("]")) {
|
|
2590
|
+
const ipv6 = hostname.slice(1, -1);
|
|
2591
|
+
if (isPrivateIPv6(ipv6)) {
|
|
2592
|
+
throw new DownloadError({
|
|
2593
|
+
url,
|
|
2594
|
+
message: `URL with IPv6 address ${hostname} is not allowed`
|
|
2595
|
+
});
|
|
2596
|
+
}
|
|
2597
|
+
return;
|
|
2598
|
+
}
|
|
2599
|
+
if (isIPv4(hostname)) {
|
|
2600
|
+
if (isPrivateIPv4(hostname)) {
|
|
2601
|
+
throw new DownloadError({
|
|
2602
|
+
url,
|
|
2603
|
+
message: `URL with IP address ${hostname} is not allowed`
|
|
2604
|
+
});
|
|
2605
|
+
}
|
|
2606
|
+
return;
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
2609
|
+
function isIPv4(hostname) {
|
|
2610
|
+
const parts = hostname.split(".");
|
|
2611
|
+
if (parts.length !== 4) return false;
|
|
2612
|
+
return parts.every((part) => {
|
|
2613
|
+
const num = Number(part);
|
|
2614
|
+
return Number.isInteger(num) && num >= 0 && num <= 255 && String(num) === part;
|
|
2615
|
+
});
|
|
2616
|
+
}
|
|
2617
|
+
function isPrivateIPv4(ip) {
|
|
2618
|
+
const parts = ip.split(".").map(Number);
|
|
2619
|
+
const [a, b] = parts;
|
|
2620
|
+
if (a === 0) return true;
|
|
2621
|
+
if (a === 10) return true;
|
|
2622
|
+
if (a === 127) return true;
|
|
2623
|
+
if (a === 169 && b === 254) return true;
|
|
2624
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
2625
|
+
if (a === 192 && b === 168) return true;
|
|
2626
|
+
return false;
|
|
2627
|
+
}
|
|
2628
|
+
function isPrivateIPv6(ip) {
|
|
2629
|
+
const normalized = ip.toLowerCase();
|
|
2630
|
+
if (normalized === "::1") return true;
|
|
2631
|
+
if (normalized === "::") return true;
|
|
2632
|
+
if (normalized.startsWith("::ffff:")) {
|
|
2633
|
+
const mappedPart = normalized.slice(7);
|
|
2634
|
+
if (isIPv4(mappedPart)) {
|
|
2635
|
+
return isPrivateIPv4(mappedPart);
|
|
2636
|
+
}
|
|
2637
|
+
const hexParts = mappedPart.split(":");
|
|
2638
|
+
if (hexParts.length === 2) {
|
|
2639
|
+
const high = parseInt(hexParts[0], 16);
|
|
2640
|
+
const low = parseInt(hexParts[1], 16);
|
|
2641
|
+
if (!isNaN(high) && !isNaN(low)) {
|
|
2642
|
+
const a = high >> 8 & 255;
|
|
2643
|
+
const b = high & 255;
|
|
2644
|
+
const c = low >> 8 & 255;
|
|
2645
|
+
const d = low & 255;
|
|
2646
|
+
return isPrivateIPv4(`${a}.${b}.${c}.${d}`);
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2649
|
+
}
|
|
2650
|
+
if (normalized.startsWith("fc") || normalized.startsWith("fd")) return true;
|
|
2651
|
+
if (normalized.startsWith("fe80")) return true;
|
|
2652
|
+
return false;
|
|
2653
|
+
}
|
|
2654
|
+
|
|
2475
2655
|
// src/without-trailing-slash.ts
|
|
2476
2656
|
function withoutTrailingSlash(url) {
|
|
2477
2657
|
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
@@ -2506,7 +2686,9 @@ __reExport(src_exports, require("@standard-schema/spec"), module.exports);
|
|
|
2506
2686
|
var import_stream2 = require("eventsource-parser/stream");
|
|
2507
2687
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2508
2688
|
0 && (module.exports = {
|
|
2689
|
+
DEFAULT_MAX_DOWNLOAD_SIZE,
|
|
2509
2690
|
DelayedPromise,
|
|
2691
|
+
DownloadError,
|
|
2510
2692
|
EventSourceParserStream,
|
|
2511
2693
|
VERSION,
|
|
2512
2694
|
asSchema,
|
|
@@ -2552,12 +2734,14 @@ var import_stream2 = require("eventsource-parser/stream");
|
|
|
2552
2734
|
postFormDataToApi,
|
|
2553
2735
|
postJsonToApi,
|
|
2554
2736
|
postToApi,
|
|
2737
|
+
readResponseWithSizeLimit,
|
|
2555
2738
|
removeUndefinedEntries,
|
|
2556
2739
|
resolve,
|
|
2557
2740
|
safeParseJSON,
|
|
2558
2741
|
safeValidateTypes,
|
|
2559
2742
|
standardSchemaValidator,
|
|
2560
2743
|
tool,
|
|
2744
|
+
validateDownloadUrl,
|
|
2561
2745
|
validateTypes,
|
|
2562
2746
|
validator,
|
|
2563
2747
|
withUserAgentSuffix,
|