ai 3.1.7 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "3.1.7",
3
+ "version": "3.1.8",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -57,8 +57,8 @@
57
57
  }
58
58
  },
59
59
  "dependencies": {
60
- "@ai-sdk/provider": "0.0.4",
61
- "@ai-sdk/provider-utils": "0.0.7",
60
+ "@ai-sdk/provider": "0.0.5",
61
+ "@ai-sdk/provider-utils": "0.0.8",
62
62
  "secure-json-parse": "2.7.0",
63
63
  "eventsource-parser": "1.1.2",
64
64
  "jsondiffpatch": "0.6.0",
@@ -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",