@ai-sdk/provider-utils 3.0.33 → 3.0.36

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/dist/index.mjs CHANGED
@@ -154,6 +154,11 @@ var DownloadError = class extends (_b = AISDKError, _a = symbol, _b) {
154
154
  }
155
155
  };
156
156
 
157
+ // src/embedding-model-capabilities.ts
158
+ var EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL = /* @__PURE__ */ Symbol.for(
159
+ "vercel.ai.embeddingModel.maxInputBytesPerCall"
160
+ );
161
+
157
162
  // src/cancel-response-body.ts
158
163
  async function cancelResponseBody(response) {
159
164
  var _a2;
@@ -368,6 +373,9 @@ async function getDefaultDownloadFetch() {
368
373
  return safeNodeFetchPromise != null ? safeNodeFetchPromise : safeNodeFetchPromise = createSafeNodeFetch();
369
374
  }
370
375
  function isNodeDefaultFetch(fetch) {
376
+ if (typeof fetch !== "function") {
377
+ return false;
378
+ }
371
379
  const source = Function.prototype.toString.call(fetch);
372
380
  return source.includes("internal/deps/undici") || source.includes("lazy loading of undici");
373
381
  }
@@ -575,6 +583,32 @@ function isAbortError(error) {
575
583
 
576
584
  // src/handle-fetch-error.ts
577
585
  var FETCH_FAILED_ERROR_MESSAGES = ["fetch failed", "failed to fetch"];
586
+ var RETRYABLE_NETWORK_ERROR_CODES = /* @__PURE__ */ new Set([
587
+ "ConnectionRefused",
588
+ "ConnectionClosed",
589
+ "FailedToOpenSocket",
590
+ "ECONNRESET",
591
+ "ECONNREFUSED",
592
+ "ETIMEDOUT",
593
+ "EPIPE",
594
+ "UND_ERR_SOCKET",
595
+ "UND_ERR_HEADERS_TIMEOUT",
596
+ "UND_ERR_BODY_TIMEOUT",
597
+ "UND_ERR_CONNECT_TIMEOUT"
598
+ ]);
599
+ function findNetworkError(error) {
600
+ const visited = /* @__PURE__ */ new Set();
601
+ let current = error;
602
+ while (current instanceof Error && !visited.has(current)) {
603
+ visited.add(current);
604
+ const errorWithCode = current;
605
+ if (typeof errorWithCode.code === "string" && RETRYABLE_NETWORK_ERROR_CODES.has(errorWithCode.code)) {
606
+ return errorWithCode;
607
+ }
608
+ current = current.cause;
609
+ }
610
+ return void 0;
611
+ }
578
612
  function handleFetchError({
579
613
  error,
580
614
  url,
@@ -596,6 +630,29 @@ function handleFetchError({
596
630
  });
597
631
  }
598
632
  }
633
+ const networkError = findNetworkError(error);
634
+ if (networkError != null) {
635
+ if (APICallError.isInstance(error)) {
636
+ return new APICallError({
637
+ message: error.message,
638
+ cause: error.cause,
639
+ url: error.url,
640
+ requestBodyValues: error.requestBodyValues,
641
+ statusCode: error.statusCode,
642
+ responseHeaders: error.responseHeaders,
643
+ responseBody: error.responseBody,
644
+ data: error.data,
645
+ isRetryable: true
646
+ });
647
+ }
648
+ return new APICallError({
649
+ message: `Cannot connect to API: ${error instanceof Error ? error.message : networkError.message}`,
650
+ cause: error,
651
+ url,
652
+ requestBodyValues,
653
+ isRetryable: true
654
+ });
655
+ }
599
656
  return error;
600
657
  }
601
658
 
@@ -652,7 +709,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
652
709
  }
653
710
 
654
711
  // src/version.ts
655
- var VERSION = true ? "3.0.33" : "0.0.0-test";
712
+ var VERSION = true ? "3.0.36" : "0.0.0-test";
656
713
 
657
714
  // src/get-from-api.ts
658
715
  var getOriginalFetch = () => globalThis.fetch;
@@ -1304,6 +1361,62 @@ async function resolve(value) {
1304
1361
  // src/response-handler.ts
1305
1362
  import { APICallError as APICallError4, EmptyResponseBodyError } from "@ai-sdk/provider";
1306
1363
  var textDecoder = new TextDecoder();
1364
+ function wrapResponseBodyStream({
1365
+ stream,
1366
+ url,
1367
+ requestBodyValues,
1368
+ statusCode,
1369
+ responseHeaders
1370
+ }) {
1371
+ const reader = stream.getReader();
1372
+ let readerReleased = false;
1373
+ const releaseReader = () => {
1374
+ if (!readerReleased) {
1375
+ reader.releaseLock();
1376
+ readerReleased = true;
1377
+ }
1378
+ };
1379
+ return new ReadableStream({
1380
+ async pull(controller) {
1381
+ try {
1382
+ const { done, value } = await reader.read();
1383
+ if (done) {
1384
+ releaseReader();
1385
+ controller.close();
1386
+ } else {
1387
+ controller.enqueue(value);
1388
+ }
1389
+ } catch (error) {
1390
+ releaseReader();
1391
+ if (isAbortError(error)) {
1392
+ controller.error(error);
1393
+ return;
1394
+ }
1395
+ controller.error(
1396
+ handleFetchError({
1397
+ error: new APICallError4({
1398
+ message: "Failed to process successful response",
1399
+ cause: error,
1400
+ statusCode,
1401
+ url,
1402
+ responseHeaders,
1403
+ requestBodyValues
1404
+ }),
1405
+ url,
1406
+ requestBodyValues
1407
+ })
1408
+ );
1409
+ }
1410
+ },
1411
+ async cancel(reason) {
1412
+ try {
1413
+ await reader.cancel(reason);
1414
+ } finally {
1415
+ releaseReader();
1416
+ }
1417
+ }
1418
+ });
1419
+ }
1307
1420
  async function readResponseBodyAsText({
1308
1421
  response,
1309
1422
  url
@@ -1369,7 +1482,7 @@ var createJsonErrorResponseHandler = ({
1369
1482
  };
1370
1483
  }
1371
1484
  };
1372
- var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) => {
1485
+ var createEventSourceResponseHandler = (chunkSchema) => async ({ response, url, requestBodyValues }) => {
1373
1486
  const responseHeaders = extractResponseHeaders(response);
1374
1487
  if (response.body == null) {
1375
1488
  throw new EmptyResponseBodyError({});
@@ -1377,7 +1490,13 @@ var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) =>
1377
1490
  return {
1378
1491
  responseHeaders,
1379
1492
  value: parseJsonEventStream({
1380
- stream: response.body,
1493
+ stream: wrapResponseBodyStream({
1494
+ stream: response.body,
1495
+ url,
1496
+ requestBodyValues,
1497
+ statusCode: response.status,
1498
+ responseHeaders
1499
+ }),
1381
1500
  schema: chunkSchema
1382
1501
  })
1383
1502
  };
@@ -1514,7 +1633,8 @@ import * as z4 from "zod/v4";
1514
1633
  // src/add-additional-properties-to-json-schema.ts
1515
1634
  function addAdditionalPropertiesToJsonSchema(jsonSchema2) {
1516
1635
  if (jsonSchema2.type === "object") {
1517
- jsonSchema2.additionalProperties = false;
1636
+ const { additionalProperties } = jsonSchema2;
1637
+ jsonSchema2.additionalProperties = additionalProperties != null && typeof additionalProperties !== "boolean" ? addAdditionalPropertiesToJsonSchema(additionalProperties) : false;
1518
1638
  const properties = jsonSchema2.properties;
1519
1639
  if (properties != null) {
1520
1640
  for (const property in properties) {
@@ -2836,6 +2956,7 @@ export {
2836
2956
  DEFAULT_MAX_DOWNLOAD_SIZE,
2837
2957
  DelayedPromise,
2838
2958
  DownloadError,
2959
+ EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL,
2839
2960
  EventSourceParserStream2 as EventSourceParserStream,
2840
2961
  VERSION,
2841
2962
  asSchema,