ai 3.1.6 → 3.1.8

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.
@@ -177,6 +177,68 @@ function getMutableAIState(...args) {
177
177
  // rsc/streamable.tsx
178
178
  import zodToJsonSchema2 from "zod-to-json-schema";
179
179
 
180
+ // core/util/retry-with-exponential-backoff.ts
181
+ import { APICallError, RetryError } from "@ai-sdk/provider";
182
+ import { getErrorMessage, isAbortError } from "@ai-sdk/provider-utils";
183
+
184
+ // core/util/delay.ts
185
+ async function delay(delayInMs) {
186
+ return new Promise((resolve) => setTimeout(resolve, delayInMs));
187
+ }
188
+
189
+ // core/util/retry-with-exponential-backoff.ts
190
+ var retryWithExponentialBackoff = ({
191
+ maxRetries = 2,
192
+ initialDelayInMs = 2e3,
193
+ backoffFactor = 2
194
+ } = {}) => async (f) => _retryWithExponentialBackoff(f, {
195
+ maxRetries,
196
+ delayInMs: initialDelayInMs,
197
+ backoffFactor
198
+ });
199
+ async function _retryWithExponentialBackoff(f, {
200
+ maxRetries,
201
+ delayInMs,
202
+ backoffFactor
203
+ }, errors = []) {
204
+ try {
205
+ return await f();
206
+ } catch (error) {
207
+ if (isAbortError(error)) {
208
+ throw error;
209
+ }
210
+ if (maxRetries === 0) {
211
+ throw error;
212
+ }
213
+ const errorMessage = getErrorMessage(error);
214
+ const newErrors = [...errors, error];
215
+ const tryNumber = newErrors.length;
216
+ if (tryNumber > maxRetries) {
217
+ throw new RetryError({
218
+ message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
219
+ reason: "maxRetriesExceeded",
220
+ errors: newErrors
221
+ });
222
+ }
223
+ if (error instanceof Error && APICallError.isAPICallError(error) && error.isRetryable === true && tryNumber <= maxRetries) {
224
+ await delay(delayInMs);
225
+ return _retryWithExponentialBackoff(
226
+ f,
227
+ { maxRetries, delayInMs: backoffFactor * delayInMs, backoffFactor },
228
+ newErrors
229
+ );
230
+ }
231
+ if (tryNumber === 1) {
232
+ throw error;
233
+ }
234
+ throw new RetryError({
235
+ message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
236
+ reason: "errorNotRetryable",
237
+ errors: newErrors
238
+ });
239
+ }
240
+ }
241
+
180
242
  // core/util/detect-image-mimetype.ts
181
243
  var mimeTypeSignatures = [
182
244
  { mimeType: "image/gif", bytes: [71, 73, 70] },
@@ -438,68 +500,6 @@ function convertZodToJSONSchema(zodSchema) {
438
500
  return zodToJsonSchema(zodSchema);
439
501
  }
440
502
 
441
- // core/util/retry-with-exponential-backoff.ts
442
- import { APICallError, RetryError } from "@ai-sdk/provider";
443
- import { getErrorMessage, isAbortError } from "@ai-sdk/provider-utils";
444
-
445
- // core/util/delay.ts
446
- async function delay(delayInMs) {
447
- return new Promise((resolve) => setTimeout(resolve, delayInMs));
448
- }
449
-
450
- // core/util/retry-with-exponential-backoff.ts
451
- var retryWithExponentialBackoff = ({
452
- maxRetries = 2,
453
- initialDelayInMs = 2e3,
454
- backoffFactor = 2
455
- } = {}) => async (f) => _retryWithExponentialBackoff(f, {
456
- maxRetries,
457
- delayInMs: initialDelayInMs,
458
- backoffFactor
459
- });
460
- async function _retryWithExponentialBackoff(f, {
461
- maxRetries,
462
- delayInMs,
463
- backoffFactor
464
- }, errors = []) {
465
- try {
466
- return await f();
467
- } catch (error) {
468
- if (isAbortError(error)) {
469
- throw error;
470
- }
471
- if (maxRetries === 0) {
472
- throw error;
473
- }
474
- const errorMessage = getErrorMessage(error);
475
- const newErrors = [...errors, error];
476
- const tryNumber = newErrors.length;
477
- if (tryNumber > maxRetries) {
478
- throw new RetryError({
479
- message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
480
- reason: "maxRetriesExceeded",
481
- errors: newErrors
482
- });
483
- }
484
- if (error instanceof Error && APICallError.isAPICallError(error) && error.isRetryable === true && tryNumber <= maxRetries) {
485
- await delay(delayInMs);
486
- return _retryWithExponentialBackoff(
487
- f,
488
- { maxRetries, delayInMs: backoffFactor * delayInMs, backoffFactor },
489
- newErrors
490
- );
491
- }
492
- if (tryNumber === 1) {
493
- throw error;
494
- }
495
- throw new RetryError({
496
- message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
497
- reason: "errorNotRetryable",
498
- errors: newErrors
499
- });
500
- }
501
- }
502
-
503
503
  // shared/stream-parts.ts
504
504
  var textStreamPart = {
505
505
  code: "0",
@@ -596,7 +596,7 @@ var dataMessageStreamPart = {
596
596
  };
597
597
  }
598
598
  };
599
- var toolCallStreamPart = {
599
+ var toolCallsStreamPart = {
600
600
  code: "7",
601
601
  name: "tool_calls",
602
602
  parse: (value) => {
@@ -623,6 +623,36 @@ var messageAnnotationsStreamPart = {
623
623
  return { type: "message_annotations", value };
624
624
  }
625
625
  };
626
+ var toolCallStreamPart = {
627
+ code: "9",
628
+ name: "tool_call",
629
+ parse: (value) => {
630
+ if (value == null || typeof value !== "object" || !("toolCallId" in value) || typeof value.toolCallId !== "string" || !("toolName" in value) || typeof value.toolName !== "string" || !("args" in value) || typeof value.args !== "object") {
631
+ throw new Error(
632
+ '"tool_call" parts expect an object with a "toolCallId", "toolName", and "args" property.'
633
+ );
634
+ }
635
+ return {
636
+ type: "tool_call",
637
+ value
638
+ };
639
+ }
640
+ };
641
+ var toolResultStreamPart = {
642
+ code: "a",
643
+ name: "tool_result",
644
+ parse: (value) => {
645
+ if (value == null || typeof value !== "object" || !("toolCallId" in value) || typeof value.toolCallId !== "string" || !("toolName" in value) || typeof value.toolName !== "string" || !("args" in value) || typeof value.args !== "object" || !("result" in value)) {
646
+ throw new Error(
647
+ '"tool_result" parts expect an object with a "toolCallId", "toolName", "args", and "result" property.'
648
+ );
649
+ }
650
+ return {
651
+ type: "tool_result",
652
+ value
653
+ };
654
+ }
655
+ };
626
656
  var streamParts = [
627
657
  textStreamPart,
628
658
  functionCallStreamPart,
@@ -631,8 +661,10 @@ var streamParts = [
631
661
  assistantMessageStreamPart,
632
662
  assistantControlDataStreamPart,
633
663
  dataMessageStreamPart,
664
+ toolCallsStreamPart,
665
+ messageAnnotationsStreamPart,
634
666
  toolCallStreamPart,
635
- messageAnnotationsStreamPart
667
+ toolResultStreamPart
636
668
  ];
637
669
  var streamPartsByCode = {
638
670
  [textStreamPart.code]: textStreamPart,
@@ -642,8 +674,10 @@ var streamPartsByCode = {
642
674
  [assistantMessageStreamPart.code]: assistantMessageStreamPart,
643
675
  [assistantControlDataStreamPart.code]: assistantControlDataStreamPart,
644
676
  [dataMessageStreamPart.code]: dataMessageStreamPart,
677
+ [toolCallsStreamPart.code]: toolCallsStreamPart,
678
+ [messageAnnotationsStreamPart.code]: messageAnnotationsStreamPart,
645
679
  [toolCallStreamPart.code]: toolCallStreamPart,
646
- [messageAnnotationsStreamPart.code]: messageAnnotationsStreamPart
680
+ [toolResultStreamPart.code]: toolResultStreamPart
647
681
  };
648
682
  var StreamStringPrefixes = {
649
683
  [textStreamPart.name]: textStreamPart.code,
@@ -653,8 +687,10 @@ var StreamStringPrefixes = {
653
687
  [assistantMessageStreamPart.name]: assistantMessageStreamPart.code,
654
688
  [assistantControlDataStreamPart.name]: assistantControlDataStreamPart.code,
655
689
  [dataMessageStreamPart.name]: dataMessageStreamPart.code,
690
+ [toolCallsStreamPart.name]: toolCallsStreamPart.code,
691
+ [messageAnnotationsStreamPart.name]: messageAnnotationsStreamPart.code,
656
692
  [toolCallStreamPart.name]: toolCallStreamPart.code,
657
- [messageAnnotationsStreamPart.name]: messageAnnotationsStreamPart.code
693
+ [toolResultStreamPart.name]: toolResultStreamPart.code
658
694
  };
659
695
  var validCodes = streamParts.map((part) => part.code);
660
696
  var parseStreamPart = (line) => {