@ai-sdk/provider-utils 3.0.26 → 3.0.28
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 -0
- package/dist/index.d.mts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +29 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -154,6 +154,15 @@ var DownloadError = class extends (_b = AISDKError, _a = symbol, _b) {
|
|
|
154
154
|
}
|
|
155
155
|
};
|
|
156
156
|
|
|
157
|
+
// src/cancel-response-body.ts
|
|
158
|
+
async function cancelResponseBody(response) {
|
|
159
|
+
var _a2;
|
|
160
|
+
try {
|
|
161
|
+
await ((_a2 = response.body) == null ? void 0 : _a2.cancel());
|
|
162
|
+
} catch (e) {
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
157
166
|
// src/is-browser-runtime.ts
|
|
158
167
|
function isBrowserRuntime(globalThisAny = globalThis) {
|
|
159
168
|
return globalThisAny.window != null;
|
|
@@ -328,6 +337,7 @@ async function fetchWithValidatedRedirects({
|
|
|
328
337
|
}
|
|
329
338
|
const location = response.headers.get("location");
|
|
330
339
|
if (response.status >= 300 && response.status < 400 && location) {
|
|
340
|
+
await cancelResponseBody(response);
|
|
331
341
|
currentUrl = new URL(location, currentUrl).toString();
|
|
332
342
|
continue;
|
|
333
343
|
}
|
|
@@ -350,6 +360,7 @@ async function readResponseWithSizeLimit({
|
|
|
350
360
|
if (contentLength != null) {
|
|
351
361
|
const length = parseInt(contentLength, 10);
|
|
352
362
|
if (!isNaN(length) && length > maxBytes) {
|
|
363
|
+
await cancelResponseBody(response);
|
|
353
364
|
throw new DownloadError({
|
|
354
365
|
url,
|
|
355
366
|
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes (Content-Length: ${length}).`
|
|
@@ -528,7 +539,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
528
539
|
}
|
|
529
540
|
|
|
530
541
|
// src/version.ts
|
|
531
|
-
var VERSION = true ? "3.0.
|
|
542
|
+
var VERSION = true ? "3.0.28" : "0.0.0-test";
|
|
532
543
|
|
|
533
544
|
// src/get-from-api.ts
|
|
534
545
|
var getOriginalFetch = () => globalThis.fetch;
|
|
@@ -1179,12 +1190,24 @@ async function resolve(value) {
|
|
|
1179
1190
|
|
|
1180
1191
|
// src/response-handler.ts
|
|
1181
1192
|
import { APICallError as APICallError4, EmptyResponseBodyError } from "@ai-sdk/provider";
|
|
1193
|
+
var textDecoder = new TextDecoder();
|
|
1194
|
+
async function readResponseBodyAsText({
|
|
1195
|
+
response,
|
|
1196
|
+
url
|
|
1197
|
+
}) {
|
|
1198
|
+
return textDecoder.decode(
|
|
1199
|
+
await readResponseWithSizeLimit({
|
|
1200
|
+
response,
|
|
1201
|
+
url
|
|
1202
|
+
})
|
|
1203
|
+
);
|
|
1204
|
+
}
|
|
1182
1205
|
var createJsonErrorResponseHandler = ({
|
|
1183
1206
|
errorSchema,
|
|
1184
1207
|
errorToMessage,
|
|
1185
1208
|
isRetryable
|
|
1186
1209
|
}) => async ({ response, url, requestBodyValues }) => {
|
|
1187
|
-
const responseBody = await response
|
|
1210
|
+
const responseBody = await readResponseBodyAsText({ response, url });
|
|
1188
1211
|
const responseHeaders = extractResponseHeaders(response);
|
|
1189
1212
|
if (responseBody.trim() === "") {
|
|
1190
1213
|
return {
|
|
@@ -1274,7 +1297,7 @@ var createJsonStreamResponseHandler = (chunkSchema) => async ({ response }) => {
|
|
|
1274
1297
|
};
|
|
1275
1298
|
};
|
|
1276
1299
|
var createJsonResponseHandler = (responseSchema) => async ({ response, url, requestBodyValues }) => {
|
|
1277
|
-
const responseBody = await response
|
|
1300
|
+
const responseBody = await readResponseBodyAsText({ response, url });
|
|
1278
1301
|
const parsedResult = await safeParseJSON({
|
|
1279
1302
|
text: responseBody,
|
|
1280
1303
|
schema: responseSchema
|
|
@@ -1329,7 +1352,7 @@ var createBinaryResponseHandler = () => async ({ response, url, requestBodyValue
|
|
|
1329
1352
|
};
|
|
1330
1353
|
var createStatusCodeErrorResponseHandler = () => async ({ response, url, requestBodyValues }) => {
|
|
1331
1354
|
const responseHeaders = extractResponseHeaders(response);
|
|
1332
|
-
const responseBody = await response
|
|
1355
|
+
const responseBody = await readResponseBodyAsText({ response, url });
|
|
1333
1356
|
return {
|
|
1334
1357
|
responseHeaders,
|
|
1335
1358
|
value: new APICallError4({
|
|
@@ -2704,6 +2727,7 @@ export {
|
|
|
2704
2727
|
VERSION,
|
|
2705
2728
|
asSchema,
|
|
2706
2729
|
asValidator,
|
|
2730
|
+
cancelResponseBody,
|
|
2707
2731
|
combineHeaders,
|
|
2708
2732
|
convertAsyncIteratorToReadableStream,
|
|
2709
2733
|
convertBase64ToUint8Array,
|