ai 7.0.9 → 7.0.10

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,14 @@
1
1
  # ai
2
2
 
3
+ ## 7.0.10
4
+
5
+ ### Patch Changes
6
+
7
+ - 8c616f0: feat(mcp): add maxRetries option for failed mcp tool calls
8
+ - Updated dependencies [8c616f0]
9
+ - @ai-sdk/provider-utils@5.0.3
10
+ - @ai-sdk/gateway@4.0.8
11
+
3
12
  ## 7.0.9
4
13
 
5
14
  ### 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.10" : "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({
@@ -5522,7 +5476,7 @@ async function generateText({
5522
5476
  toolCallId: toolCall.toolCallId,
5523
5477
  toolName: toolCall.toolName,
5524
5478
  input: toolCall.input,
5525
- error: getErrorMessage5(toolCall.error),
5479
+ error: getErrorMessage4(toolCall.error),
5526
5480
  dynamic: true
5527
5481
  });
5528
5482
  }
@@ -6036,7 +5990,7 @@ function asContent({
6036
5990
 
6037
5991
  // src/generate-text/stream-text.ts
6038
5992
  import {
6039
- getErrorMessage as getErrorMessage7,
5993
+ getErrorMessage as getErrorMessage6,
6040
5994
  UnsupportedFunctionalityError as UnsupportedFunctionalityError2
6041
5995
  } from "@ai-sdk/provider";
6042
5996
  import {
@@ -6044,7 +5998,7 @@ import {
6044
5998
  createIdGenerator as createIdGenerator3,
6045
5999
  DelayedPromise,
6046
6000
  filterNullable as filterNullable2,
6047
- isAbortError as isAbortError2
6001
+ isAbortError
6048
6002
  } from "@ai-sdk/provider-utils";
6049
6003
 
6050
6004
  // src/util/prepare-headers.ts
@@ -7906,7 +7860,7 @@ function invokeToolCallbacksFromStream({
7906
7860
 
7907
7861
  // src/generate-text/stream-language-model-call.ts
7908
7862
  import {
7909
- getErrorMessage as getErrorMessage6
7863
+ getErrorMessage as getErrorMessage5
7910
7864
  } from "@ai-sdk/provider";
7911
7865
  import {
7912
7866
  createIdGenerator as createIdGenerator2
@@ -8234,7 +8188,7 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({
8234
8188
  toolCallId: toolCall.toolCallId,
8235
8189
  toolName: toolCall.toolName,
8236
8190
  input: toolCall.input,
8237
- error: getErrorMessage6(toolCall.error),
8191
+ error: getErrorMessage5(toolCall.error),
8238
8192
  dynamic: true,
8239
8193
  title: toolCall.title,
8240
8194
  ...toolCall.toolMetadata != null ? { toolMetadata: toolCall.toolMetadata } : {}
@@ -8953,7 +8907,7 @@ var DefaultStreamTextResult = class {
8953
8907
  // The `reason` is usually of type DOMException, but it can also be of any type,
8954
8908
  // so we use getErrorMessage for serialization because it is already designed to accept values of the unknown type.
8955
8909
  // 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) } : {}
8910
+ ...(abortSignal == null ? void 0 : abortSignal.reason) !== void 0 ? { reason: getErrorMessage6(abortSignal.reason) } : {}
8957
8911
  });
8958
8912
  controller.close();
8959
8913
  }
@@ -8969,7 +8923,7 @@ var DefaultStreamTextResult = class {
8969
8923
  }
8970
8924
  controller.enqueue(value);
8971
8925
  } catch (error) {
8972
- if (isAbortError2(error) && (abortSignal == null ? void 0 : abortSignal.aborted)) {
8926
+ if (isAbortError(error) && (abortSignal == null ? void 0 : abortSignal.aborted)) {
8973
8927
  await abort();
8974
8928
  } else {
8975
8929
  controller.error(error);
@@ -12594,12 +12548,12 @@ function simulateReadableStream({
12594
12548
  _internal
12595
12549
  }) {
12596
12550
  var _a22;
12597
- const delay2 = (_a22 = _internal == null ? void 0 : _internal.delay) != null ? _a22 : delayFunction;
12551
+ const delay = (_a22 = _internal == null ? void 0 : _internal.delay) != null ? _a22 : delayFunction;
12598
12552
  let index = 0;
12599
12553
  return new ReadableStream({
12600
12554
  async pull(controller) {
12601
12555
  if (index < chunks.length) {
12602
- await delay2(index === 0 ? initialDelayInMs : chunkDelayInMs);
12556
+ await delay(index === 0 ? initialDelayInMs : chunkDelayInMs);
12603
12557
  controller.enqueue(chunks[index++]);
12604
12558
  } else {
12605
12559
  controller.close();
@@ -13324,7 +13278,7 @@ var CHUNKING_REGEXPS = {
13324
13278
  function smoothStream({
13325
13279
  delayInMs = 10,
13326
13280
  chunking = "word",
13327
- _internal: { delay: delay2 = originalDelay } = {}
13281
+ _internal: { delay = originalDelay } = {}
13328
13282
  } = {}) {
13329
13283
  let detectChunk;
13330
13284
  if (chunking != null && typeof chunking === "object" && "segment" in chunking && typeof chunking.segment === "function") {
@@ -13405,7 +13359,7 @@ function smoothStream({
13405
13359
  while ((match = detectChunk(buffer)) != null) {
13406
13360
  controller.enqueue({ type, text: match, id });
13407
13361
  buffer = buffer.slice(match.length);
13408
- await delay2(delayInMs);
13362
+ await delay(delayInMs);
13409
13363
  }
13410
13364
  }
13411
13365
  });