@ai-sdk/provider-utils 3.0.43 → 3.0.45
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 +15 -0
- package/dist/index.d.mts +50 -2
- package/dist/index.d.ts +50 -2
- package/dist/index.js +100 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +96 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -456,10 +456,12 @@ async function fetchWithValidatedRedirects({
|
|
|
456
456
|
trustedOrigin
|
|
457
457
|
}) {
|
|
458
458
|
var _a2;
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
459
|
+
let currentHeaders = headers === void 0 ? void 0 : new Headers(headers);
|
|
460
|
+
const perHopInit = (redirect) => ({
|
|
461
|
+
signal: abortSignal,
|
|
462
|
+
redirect,
|
|
463
|
+
...currentHeaders === void 0 ? {} : { headers: new Headers(currentHeaders) }
|
|
464
|
+
});
|
|
463
465
|
let currentUrl = url;
|
|
464
466
|
for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
|
|
465
467
|
const isTrustedHop = trustedOrigin !== void 0 && isSameOrigin(currentUrl, trustedOrigin);
|
|
@@ -467,10 +469,7 @@ async function fetchWithValidatedRedirects({
|
|
|
467
469
|
validateDownloadUrl(currentUrl);
|
|
468
470
|
}
|
|
469
471
|
const fetch = isTrustedHop && customFetch != null ? customFetch : isTrustedHop ? globalThis.fetch : await getValidatedFetch(customFetch);
|
|
470
|
-
const response = await fetch(currentUrl,
|
|
471
|
-
...baseInit,
|
|
472
|
-
redirect: "manual"
|
|
473
|
-
});
|
|
472
|
+
const response = await fetch(currentUrl, perHopInit("manual"));
|
|
474
473
|
if (response.type === "opaqueredirect") {
|
|
475
474
|
if (!isBrowserRuntime()) {
|
|
476
475
|
throw new DownloadError({
|
|
@@ -478,12 +477,25 @@ async function fetchWithValidatedRedirects({
|
|
|
478
477
|
message: `Redirect from ${currentUrl} could not be validated and was blocked`
|
|
479
478
|
});
|
|
480
479
|
}
|
|
481
|
-
return await fetch(currentUrl,
|
|
480
|
+
return await fetch(currentUrl, perHopInit("follow"));
|
|
482
481
|
}
|
|
483
482
|
const location = (_a2 = response.headers) == null ? void 0 : _a2.get("location");
|
|
484
483
|
if (response.status >= 300 && response.status < 400 && location) {
|
|
485
|
-
|
|
486
|
-
|
|
484
|
+
void cancelResponseBody(response);
|
|
485
|
+
const nextUrl = new URL(location, currentUrl).toString();
|
|
486
|
+
if (new URL(currentUrl).protocol === "https:" && new URL(nextUrl).protocol === "http:") {
|
|
487
|
+
throw new DownloadError({
|
|
488
|
+
url,
|
|
489
|
+
message: "Redirect from HTTPS to HTTP was blocked"
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
if (currentHeaders !== void 0 && !isSameOrigin(nextUrl, currentUrl)) {
|
|
493
|
+
const userAgent = currentHeaders.get("user-agent");
|
|
494
|
+
currentHeaders = new Headers(
|
|
495
|
+
userAgent == null ? void 0 : { "user-agent": userAgent }
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
currentUrl = nextUrl;
|
|
487
499
|
continue;
|
|
488
500
|
}
|
|
489
501
|
return response;
|
|
@@ -740,7 +752,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
740
752
|
}
|
|
741
753
|
|
|
742
754
|
// src/version.ts
|
|
743
|
-
var VERSION = true ? "3.0.
|
|
755
|
+
var VERSION = true ? "3.0.45" : "0.0.0-test";
|
|
744
756
|
|
|
745
757
|
// src/get-from-api.ts
|
|
746
758
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -750,16 +762,28 @@ var getFromApi = async ({
|
|
|
750
762
|
successfulResponseHandler,
|
|
751
763
|
failedResponseHandler,
|
|
752
764
|
abortSignal,
|
|
753
|
-
fetch
|
|
765
|
+
fetch,
|
|
766
|
+
validateUrl,
|
|
767
|
+
credentialedOrigin,
|
|
768
|
+
trustedOrigin
|
|
754
769
|
}) => {
|
|
755
770
|
try {
|
|
756
|
-
const
|
|
771
|
+
const requestFetch = fetch != null ? fetch : getOriginalFetch();
|
|
772
|
+
const outgoingHeaders = credentialedOrigin !== void 0 && !isSameOrigin(url, credentialedOrigin) ? {} : headers;
|
|
773
|
+
const requestHeaders = withUserAgentSuffix(
|
|
774
|
+
outgoingHeaders,
|
|
775
|
+
`ai-sdk/provider-utils/${VERSION}`,
|
|
776
|
+
getRuntimeEnvironmentUserAgent()
|
|
777
|
+
);
|
|
778
|
+
const response = validateUrl ? await fetchWithValidatedRedirects({
|
|
779
|
+
url,
|
|
780
|
+
headers: requestHeaders,
|
|
781
|
+
abortSignal,
|
|
782
|
+
fetch,
|
|
783
|
+
trustedOrigin
|
|
784
|
+
}) : await requestFetch(url, {
|
|
757
785
|
method: "GET",
|
|
758
|
-
headers:
|
|
759
|
-
headers,
|
|
760
|
-
`ai-sdk/provider-utils/${VERSION}`,
|
|
761
|
-
getRuntimeEnvironmentUserAgent()
|
|
762
|
-
),
|
|
786
|
+
headers: requestHeaders,
|
|
763
787
|
signal: abortSignal
|
|
764
788
|
});
|
|
765
789
|
const responseHeaders = extractResponseHeaders(response);
|
|
@@ -3288,7 +3312,11 @@ var { btoa, atob } = globalThis;
|
|
|
3288
3312
|
function convertBase64ToUint8Array(base64String) {
|
|
3289
3313
|
const base64Url = base64String.replace(/-/g, "+").replace(/_/g, "/");
|
|
3290
3314
|
const latin1string = atob(base64Url);
|
|
3291
|
-
|
|
3315
|
+
const bytes = new Uint8Array(latin1string.length);
|
|
3316
|
+
for (let i = 0; i < latin1string.length; i++) {
|
|
3317
|
+
bytes[i] = latin1string.charCodeAt(i);
|
|
3318
|
+
}
|
|
3319
|
+
return bytes;
|
|
3292
3320
|
}
|
|
3293
3321
|
function convertUint8ArrayToBase64(array) {
|
|
3294
3322
|
var _a2;
|
|
@@ -3306,8 +3334,30 @@ function convertUint8ArrayToBase64(array) {
|
|
|
3306
3334
|
}
|
|
3307
3335
|
return btoa(chunks.join(""));
|
|
3308
3336
|
}
|
|
3337
|
+
var typedArrayTag = Object.getOwnPropertyDescriptor(
|
|
3338
|
+
Object.getPrototypeOf(Uint8Array.prototype),
|
|
3339
|
+
Symbol.toStringTag
|
|
3340
|
+
).get;
|
|
3341
|
+
var arrayBufferByteLength = Object.getOwnPropertyDescriptor(
|
|
3342
|
+
ArrayBuffer.prototype,
|
|
3343
|
+
"byteLength"
|
|
3344
|
+
).get;
|
|
3345
|
+
function isUint8Array(value) {
|
|
3346
|
+
return ArrayBuffer.isView(value) && typedArrayTag.call(value) === "Uint8Array";
|
|
3347
|
+
}
|
|
3348
|
+
function isArrayBuffer(value) {
|
|
3349
|
+
if (typeof value !== "object" || value === null || !("byteLength" in value)) {
|
|
3350
|
+
return false;
|
|
3351
|
+
}
|
|
3352
|
+
try {
|
|
3353
|
+
arrayBufferByteLength.call(value);
|
|
3354
|
+
return true;
|
|
3355
|
+
} catch (e) {
|
|
3356
|
+
return false;
|
|
3357
|
+
}
|
|
3358
|
+
}
|
|
3309
3359
|
function convertToBase64(value) {
|
|
3310
|
-
return value
|
|
3360
|
+
return isUint8Array(value) ? convertUint8ArrayToBase64(value) : value;
|
|
3311
3361
|
}
|
|
3312
3362
|
|
|
3313
3363
|
// src/without-trailing-slash.ts
|
|
@@ -3344,6 +3394,27 @@ export * from "@standard-schema/spec";
|
|
|
3344
3394
|
import {
|
|
3345
3395
|
EventSourceParserStream as EventSourceParserStream2
|
|
3346
3396
|
} from "eventsource-parser/stream";
|
|
3397
|
+
|
|
3398
|
+
// src/stringify-with-bigint-and-cycles.ts
|
|
3399
|
+
function stringifyWithBigIntAndCycles(value) {
|
|
3400
|
+
const ancestors = [];
|
|
3401
|
+
return JSON.stringify(value, function(_key, value2) {
|
|
3402
|
+
if (typeof value2 === "bigint") {
|
|
3403
|
+
return value2.toString();
|
|
3404
|
+
}
|
|
3405
|
+
if (typeof value2 !== "object" || value2 === null) {
|
|
3406
|
+
return value2;
|
|
3407
|
+
}
|
|
3408
|
+
while (ancestors.length > 0 && ancestors.at(-1) !== this) {
|
|
3409
|
+
ancestors.pop();
|
|
3410
|
+
}
|
|
3411
|
+
if (ancestors.includes(value2)) {
|
|
3412
|
+
return "[Circular]";
|
|
3413
|
+
}
|
|
3414
|
+
ancestors.push(value2);
|
|
3415
|
+
return value2;
|
|
3416
|
+
});
|
|
3417
|
+
}
|
|
3347
3418
|
export {
|
|
3348
3419
|
DEFAULT_MAX_DOWNLOAD_SIZE,
|
|
3349
3420
|
DelayedPromise,
|
|
@@ -3382,9 +3453,11 @@ export {
|
|
|
3382
3453
|
getRuntimeEnvironmentUserAgent,
|
|
3383
3454
|
injectJsonInstructionIntoMessages,
|
|
3384
3455
|
isAbortError,
|
|
3456
|
+
isArrayBuffer,
|
|
3385
3457
|
isBrowserRuntime,
|
|
3386
3458
|
isParsableJson,
|
|
3387
3459
|
isSameOrigin,
|
|
3460
|
+
isUint8Array,
|
|
3388
3461
|
isUrlSupported,
|
|
3389
3462
|
isValidator,
|
|
3390
3463
|
jsonSchema,
|
|
@@ -3406,7 +3479,9 @@ export {
|
|
|
3406
3479
|
resolve,
|
|
3407
3480
|
safeParseJSON,
|
|
3408
3481
|
safeValidateTypes,
|
|
3482
|
+
secureJsonParse,
|
|
3409
3483
|
standardSchemaValidator,
|
|
3484
|
+
stringifyWithBigIntAndCycles,
|
|
3410
3485
|
tool,
|
|
3411
3486
|
validateDownloadUrl,
|
|
3412
3487
|
validateTypes,
|