ai 7.0.9 → 7.0.11

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 CHANGED
@@ -1,5 +1,20 @@
1
1
  # ai
2
2
 
3
+ ## 7.0.11
4
+
5
+ ### Patch Changes
6
+
7
+ - 0a87626: fix(ai): replace dynamic import() with loadBuiltinModule for diagnostics_channel to fix React Native/Hermes builds
8
+
9
+ ## 7.0.10
10
+
11
+ ### Patch Changes
12
+
13
+ - 8c616f0: feat(mcp): add maxRetries option for failed mcp tool calls
14
+ - Updated dependencies [8c616f0]
15
+ - @ai-sdk/provider-utils@5.0.3
16
+ - @ai-sdk/gateway@4.0.8
17
+
3
18
  ## 7.0.9
4
19
 
5
20
  ### Patch Changes
package/dist/index.js CHANGED
@@ -27,7 +27,7 @@ import {
27
27
  import {
28
28
  asArray as asArray5,
29
29
  createIdGenerator,
30
- getErrorMessage as getErrorMessage5,
30
+ getErrorMessage as getErrorMessage4,
31
31
  withUserAgentSuffix as withUserAgentSuffix2
32
32
  } from "@ai-sdk/provider-utils";
33
33
 
@@ -1089,7 +1089,7 @@ import {
1089
1089
  } from "@ai-sdk/provider-utils";
1090
1090
 
1091
1091
  // src/version.ts
1092
- var VERSION = true ? "7.0.9" : "0.0.0-test";
1092
+ var VERSION = true ? "7.0.11" : "0.0.0-test";
1093
1093
 
1094
1094
  // src/util/download/download.ts
1095
1095
  var download = async ({
@@ -2639,7 +2639,9 @@ async function notify(options) {
2639
2639
  // src/util/retry-with-exponential-backoff.ts
2640
2640
  import { APICallError as APICallError2 } from "@ai-sdk/provider";
2641
2641
  import { GatewayError } from "@ai-sdk/gateway";
2642
- import { delay, getErrorMessage as getErrorMessage4, isAbortError } from "@ai-sdk/provider-utils";
2642
+ import {
2643
+ retryWithExponentialBackoff
2644
+ } from "@ai-sdk/provider-utils";
2643
2645
  function getRetryDelayInMs({
2644
2646
  error,
2645
2647
  exponentialBackoffDelay
@@ -2674,66 +2676,18 @@ var retryWithExponentialBackoffRespectingRetryHeaders = ({
2674
2676
  initialDelayInMs = 2e3,
2675
2677
  backoffFactor = 2,
2676
2678
  abortSignal
2677
- } = {}) => async (f) => _retryWithExponentialBackoff(f, {
2679
+ } = {}) => retryWithExponentialBackoff({
2678
2680
  maxRetries,
2679
- delayInMs: initialDelayInMs,
2681
+ initialDelayInMs,
2680
2682
  backoffFactor,
2681
- abortSignal
2683
+ abortSignal,
2684
+ shouldRetry: (error) => error instanceof Error && (APICallError2.isInstance(error) && error.isRetryable === true || GatewayError.isInstance(error) && error.isRetryable === true),
2685
+ getDelayInMs: ({ error, exponentialBackoffDelay }) => getRetryDelayInMs({
2686
+ error,
2687
+ exponentialBackoffDelay
2688
+ }),
2689
+ createRetryError: ({ message, reason, errors }) => new RetryError({ message, reason, errors })
2682
2690
  });
2683
- async function _retryWithExponentialBackoff(f, {
2684
- maxRetries,
2685
- delayInMs,
2686
- backoffFactor,
2687
- abortSignal
2688
- }, errors = []) {
2689
- try {
2690
- return await f();
2691
- } catch (error) {
2692
- if (isAbortError(error)) {
2693
- throw error;
2694
- }
2695
- if (maxRetries === 0) {
2696
- throw error;
2697
- }
2698
- const errorMessage = getErrorMessage4(error);
2699
- const newErrors = [...errors, error];
2700
- const tryNumber = newErrors.length;
2701
- if (tryNumber > maxRetries) {
2702
- throw new RetryError({
2703
- message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
2704
- reason: "maxRetriesExceeded",
2705
- errors: newErrors
2706
- });
2707
- }
2708
- if (error instanceof Error && (APICallError2.isInstance(error) && error.isRetryable === true || GatewayError.isInstance(error) && error.isRetryable === true) && tryNumber <= maxRetries) {
2709
- await delay(
2710
- getRetryDelayInMs({
2711
- error,
2712
- exponentialBackoffDelay: delayInMs
2713
- }),
2714
- { abortSignal }
2715
- );
2716
- return _retryWithExponentialBackoff(
2717
- f,
2718
- {
2719
- maxRetries,
2720
- delayInMs: backoffFactor * delayInMs,
2721
- backoffFactor,
2722
- abortSignal
2723
- },
2724
- newErrors
2725
- );
2726
- }
2727
- if (tryNumber === 1) {
2728
- throw error;
2729
- }
2730
- throw new RetryError({
2731
- message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
2732
- reason: "errorNotRetryable",
2733
- errors: newErrors
2734
- });
2735
- }
2736
- }
2737
2691
 
2738
2692
  // src/util/prepare-retries.ts
2739
2693
  function prepareRetries({
@@ -4057,10 +4011,9 @@ async function loadDiagnosticsChannel() {
4057
4011
  return void 0;
4058
4012
  }
4059
4013
  if (diagnosticsChannelPromise == null) {
4060
- diagnosticsChannelPromise = import(
4061
- /* webpackIgnore: true */
4062
- "diagnostics_channel"
4063
- ).catch(() => void 0);
4014
+ diagnosticsChannelPromise = Promise.resolve(
4015
+ loadBuiltinModule("node:diagnostics_channel")
4016
+ );
4064
4017
  }
4065
4018
  return diagnosticsChannelPromise;
4066
4019
  }
@@ -5522,7 +5475,7 @@ async function generateText({
5522
5475
  toolCallId: toolCall.toolCallId,
5523
5476
  toolName: toolCall.toolName,
5524
5477
  input: toolCall.input,
5525
- error: getErrorMessage5(toolCall.error),
5478
+ error: getErrorMessage4(toolCall.error),
5526
5479
  dynamic: true
5527
5480
  });
5528
5481
  }
@@ -6036,7 +5989,7 @@ function asContent({
6036
5989
 
6037
5990
  // src/generate-text/stream-text.ts
6038
5991
  import {
6039
- getErrorMessage as getErrorMessage7,
5992
+ getErrorMessage as getErrorMessage6,
6040
5993
  UnsupportedFunctionalityError as UnsupportedFunctionalityError2
6041
5994
  } from "@ai-sdk/provider";
6042
5995
  import {
@@ -6044,7 +5997,7 @@ import {
6044
5997
  createIdGenerator as createIdGenerator3,
6045
5998
  DelayedPromise,
6046
5999
  filterNullable as filterNullable2,
6047
- isAbortError as isAbortError2
6000
+ isAbortError
6048
6001
  } from "@ai-sdk/provider-utils";
6049
6002
 
6050
6003
  // src/util/prepare-headers.ts
@@ -7906,7 +7859,7 @@ function invokeToolCallbacksFromStream({
7906
7859
 
7907
7860
  // src/generate-text/stream-language-model-call.ts
7908
7861
  import {
7909
- getErrorMessage as getErrorMessage6
7862
+ getErrorMessage as getErrorMessage5
7910
7863
  } from "@ai-sdk/provider";
7911
7864
  import {
7912
7865
  createIdGenerator as createIdGenerator2
@@ -8234,7 +8187,7 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({
8234
8187
  toolCallId: toolCall.toolCallId,
8235
8188
  toolName: toolCall.toolName,
8236
8189
  input: toolCall.input,
8237
- error: getErrorMessage6(toolCall.error),
8190
+ error: getErrorMessage5(toolCall.error),
8238
8191
  dynamic: true,
8239
8192
  title: toolCall.title,
8240
8193
  ...toolCall.toolMetadata != null ? { toolMetadata: toolCall.toolMetadata } : {}
@@ -8953,7 +8906,7 @@ var DefaultStreamTextResult = class {
8953
8906
  // The `reason` is usually of type DOMException, but it can also be of any type,
8954
8907
  // so we use getErrorMessage for serialization because it is already designed to accept values of the unknown type.
8955
8908
  // See: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/reason
8956
- ...(abortSignal == null ? void 0 : abortSignal.reason) !== void 0 ? { reason: getErrorMessage7(abortSignal.reason) } : {}
8909
+ ...(abortSignal == null ? void 0 : abortSignal.reason) !== void 0 ? { reason: getErrorMessage6(abortSignal.reason) } : {}
8957
8910
  });
8958
8911
  controller.close();
8959
8912
  }
@@ -8969,7 +8922,7 @@ var DefaultStreamTextResult = class {
8969
8922
  }
8970
8923
  controller.enqueue(value);
8971
8924
  } catch (error) {
8972
- if (isAbortError2(error) && (abortSignal == null ? void 0 : abortSignal.aborted)) {
8925
+ if (isAbortError(error) && (abortSignal == null ? void 0 : abortSignal.aborted)) {
8973
8926
  await abort();
8974
8927
  } else {
8975
8928
  controller.error(error);
@@ -12594,12 +12547,12 @@ function simulateReadableStream({
12594
12547
  _internal
12595
12548
  }) {
12596
12549
  var _a22;
12597
- const delay2 = (_a22 = _internal == null ? void 0 : _internal.delay) != null ? _a22 : delayFunction;
12550
+ const delay = (_a22 = _internal == null ? void 0 : _internal.delay) != null ? _a22 : delayFunction;
12598
12551
  let index = 0;
12599
12552
  return new ReadableStream({
12600
12553
  async pull(controller) {
12601
12554
  if (index < chunks.length) {
12602
- await delay2(index === 0 ? initialDelayInMs : chunkDelayInMs);
12555
+ await delay(index === 0 ? initialDelayInMs : chunkDelayInMs);
12603
12556
  controller.enqueue(chunks[index++]);
12604
12557
  } else {
12605
12558
  controller.close();
@@ -13324,7 +13277,7 @@ var CHUNKING_REGEXPS = {
13324
13277
  function smoothStream({
13325
13278
  delayInMs = 10,
13326
13279
  chunking = "word",
13327
- _internal: { delay: delay2 = originalDelay } = {}
13280
+ _internal: { delay = originalDelay } = {}
13328
13281
  } = {}) {
13329
13282
  let detectChunk;
13330
13283
  if (chunking != null && typeof chunking === "object" && "segment" in chunking && typeof chunking.segment === "function") {
@@ -13405,7 +13358,7 @@ function smoothStream({
13405
13358
  while ((match = detectChunk(buffer)) != null) {
13406
13359
  controller.enqueue({ type, text: match, id });
13407
13360
  buffer = buffer.slice(match.length);
13408
- await delay2(delayInMs);
13361
+ await delay(delayInMs);
13409
13362
  }
13410
13363
  }
13411
13364
  });