@ai-sdk/provider-utils 3.0.21 → 3.0.23
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 +14 -1
- package/dist/index.d.mts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +112 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +107 -7
- package/dist/index.mjs.map +1 -1
- package/dist/test/index.js +3 -3
- package/package.json +1 -3
package/dist/index.mjs
CHANGED
|
@@ -343,7 +343,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
343
343
|
}
|
|
344
344
|
|
|
345
345
|
// src/version.ts
|
|
346
|
-
var VERSION = true ? "3.0.
|
|
346
|
+
var VERSION = true ? "3.0.23" : "0.0.0-test";
|
|
347
347
|
|
|
348
348
|
// src/get-from-api.ts
|
|
349
349
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -576,8 +576,8 @@ import {
|
|
|
576
576
|
} from "@ai-sdk/provider";
|
|
577
577
|
|
|
578
578
|
// src/secure-json-parse.ts
|
|
579
|
-
var suspectProtoRx = /"
|
|
580
|
-
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*:/;
|
|
581
581
|
function _parse(text) {
|
|
582
582
|
const obj = JSON.parse(text);
|
|
583
583
|
if (obj === null || typeof obj !== "object") {
|
|
@@ -597,7 +597,7 @@ function filter(obj) {
|
|
|
597
597
|
if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
|
|
598
598
|
throw new SyntaxError("Object contains forbidden prototype property");
|
|
599
599
|
}
|
|
600
|
-
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")) {
|
|
601
601
|
throw new SyntaxError("Object contains forbidden prototype property");
|
|
602
602
|
}
|
|
603
603
|
for (const key in node) {
|
|
@@ -629,7 +629,7 @@ import { TypeValidationError as TypeValidationError2 } from "@ai-sdk/provider";
|
|
|
629
629
|
|
|
630
630
|
// src/validator.ts
|
|
631
631
|
import { TypeValidationError } from "@ai-sdk/provider";
|
|
632
|
-
var validatorSymbol = Symbol.for("vercel.ai.validator");
|
|
632
|
+
var validatorSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.validator");
|
|
633
633
|
function validator(validate) {
|
|
634
634
|
return { [validatorSymbol]: true, validate };
|
|
635
635
|
}
|
|
@@ -1189,7 +1189,7 @@ var getRelativePath = (pathA, pathB) => {
|
|
|
1189
1189
|
};
|
|
1190
1190
|
|
|
1191
1191
|
// src/zod-to-json-schema/options.ts
|
|
1192
|
-
var ignoreOverride = Symbol(
|
|
1192
|
+
var ignoreOverride = /* @__PURE__ */ Symbol(
|
|
1193
1193
|
"Let zodToJsonSchema decide on which parser to use"
|
|
1194
1194
|
);
|
|
1195
1195
|
var defaultOptions = {
|
|
@@ -2411,7 +2411,7 @@ function zodSchema(zodSchema2, options) {
|
|
|
2411
2411
|
}
|
|
2412
2412
|
|
|
2413
2413
|
// src/schema.ts
|
|
2414
|
-
var schemaSymbol = Symbol.for("vercel.ai.schema");
|
|
2414
|
+
var schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
2415
2415
|
function lazySchema(createSchema) {
|
|
2416
2416
|
let schema;
|
|
2417
2417
|
return () => {
|
|
@@ -2466,6 +2466,105 @@ function convertToBase64(value) {
|
|
|
2466
2466
|
return value instanceof Uint8Array ? convertUint8ArrayToBase64(value) : value;
|
|
2467
2467
|
}
|
|
2468
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 === "data:") {
|
|
2481
|
+
return;
|
|
2482
|
+
}
|
|
2483
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
2484
|
+
throw new DownloadError({
|
|
2485
|
+
url,
|
|
2486
|
+
message: `URL scheme must be http, https, or data, got ${parsed.protocol}`
|
|
2487
|
+
});
|
|
2488
|
+
}
|
|
2489
|
+
const hostname = parsed.hostname;
|
|
2490
|
+
if (!hostname) {
|
|
2491
|
+
throw new DownloadError({
|
|
2492
|
+
url,
|
|
2493
|
+
message: `URL must have a hostname`
|
|
2494
|
+
});
|
|
2495
|
+
}
|
|
2496
|
+
if (hostname === "localhost" || hostname.endsWith(".local") || hostname.endsWith(".localhost")) {
|
|
2497
|
+
throw new DownloadError({
|
|
2498
|
+
url,
|
|
2499
|
+
message: `URL with hostname ${hostname} is not allowed`
|
|
2500
|
+
});
|
|
2501
|
+
}
|
|
2502
|
+
if (hostname.startsWith("[") && hostname.endsWith("]")) {
|
|
2503
|
+
const ipv6 = hostname.slice(1, -1);
|
|
2504
|
+
if (isPrivateIPv6(ipv6)) {
|
|
2505
|
+
throw new DownloadError({
|
|
2506
|
+
url,
|
|
2507
|
+
message: `URL with IPv6 address ${hostname} is not allowed`
|
|
2508
|
+
});
|
|
2509
|
+
}
|
|
2510
|
+
return;
|
|
2511
|
+
}
|
|
2512
|
+
if (isIPv4(hostname)) {
|
|
2513
|
+
if (isPrivateIPv4(hostname)) {
|
|
2514
|
+
throw new DownloadError({
|
|
2515
|
+
url,
|
|
2516
|
+
message: `URL with IP address ${hostname} is not allowed`
|
|
2517
|
+
});
|
|
2518
|
+
}
|
|
2519
|
+
return;
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
function isIPv4(hostname) {
|
|
2523
|
+
const parts = hostname.split(".");
|
|
2524
|
+
if (parts.length !== 4) return false;
|
|
2525
|
+
return parts.every((part) => {
|
|
2526
|
+
const num = Number(part);
|
|
2527
|
+
return Number.isInteger(num) && num >= 0 && num <= 255 && String(num) === part;
|
|
2528
|
+
});
|
|
2529
|
+
}
|
|
2530
|
+
function isPrivateIPv4(ip) {
|
|
2531
|
+
const parts = ip.split(".").map(Number);
|
|
2532
|
+
const [a, b] = parts;
|
|
2533
|
+
if (a === 0) return true;
|
|
2534
|
+
if (a === 10) return true;
|
|
2535
|
+
if (a === 127) return true;
|
|
2536
|
+
if (a === 169 && b === 254) return true;
|
|
2537
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
2538
|
+
if (a === 192 && b === 168) return true;
|
|
2539
|
+
return false;
|
|
2540
|
+
}
|
|
2541
|
+
function isPrivateIPv6(ip) {
|
|
2542
|
+
const normalized = ip.toLowerCase();
|
|
2543
|
+
if (normalized === "::1") return true;
|
|
2544
|
+
if (normalized === "::") return true;
|
|
2545
|
+
if (normalized.startsWith("::ffff:")) {
|
|
2546
|
+
const mappedPart = normalized.slice(7);
|
|
2547
|
+
if (isIPv4(mappedPart)) {
|
|
2548
|
+
return isPrivateIPv4(mappedPart);
|
|
2549
|
+
}
|
|
2550
|
+
const hexParts = mappedPart.split(":");
|
|
2551
|
+
if (hexParts.length === 2) {
|
|
2552
|
+
const high = parseInt(hexParts[0], 16);
|
|
2553
|
+
const low = parseInt(hexParts[1], 16);
|
|
2554
|
+
if (!isNaN(high) && !isNaN(low)) {
|
|
2555
|
+
const a = high >> 8 & 255;
|
|
2556
|
+
const b = high & 255;
|
|
2557
|
+
const c = low >> 8 & 255;
|
|
2558
|
+
const d = low & 255;
|
|
2559
|
+
return isPrivateIPv4(`${a}.${b}.${c}.${d}`);
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
if (normalized.startsWith("fc") || normalized.startsWith("fd")) return true;
|
|
2564
|
+
if (normalized.startsWith("fe80")) return true;
|
|
2565
|
+
return false;
|
|
2566
|
+
}
|
|
2567
|
+
|
|
2469
2568
|
// src/without-trailing-slash.ts
|
|
2470
2569
|
function withoutTrailingSlash(url) {
|
|
2471
2570
|
return url == null ? void 0 : url.replace(/\/$/, "");
|
|
@@ -2556,6 +2655,7 @@ export {
|
|
|
2556
2655
|
safeValidateTypes,
|
|
2557
2656
|
standardSchemaValidator,
|
|
2558
2657
|
tool,
|
|
2658
|
+
validateDownloadUrl,
|
|
2559
2659
|
validateTypes,
|
|
2560
2660
|
validator,
|
|
2561
2661
|
withUserAgentSuffix,
|