ai 6.0.278 → 6.0.280

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,23 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.280
4
+
5
+ ### Patch Changes
6
+
7
+ - 04783ca: fix(ai): call `atob` without a receiver for Cloudflare Workers compatibility
8
+ - 1a4dbb1: Retry unclassified empty image results, preserve retry-attempt accounting, add provider-independent result retryability classification, preserve it through the AI Gateway, and mark Google and Google Vertex content-filtered results as terminal.
9
+ - Updated dependencies [1a4dbb1]
10
+ - Updated dependencies [b273f40]
11
+ - @ai-sdk/gateway@3.0.191
12
+ - @ai-sdk/provider@3.0.16
13
+ - @ai-sdk/provider-utils@4.0.51
14
+
15
+ ## 6.0.279
16
+
17
+ ### Patch Changes
18
+
19
+ - 6517262: fix(ai): decode text data URLs in Node.js
20
+
3
21
  ## 6.0.278
4
22
 
5
23
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -5094,7 +5094,7 @@ type GenerateImagePrompt = string | {
5094
5094
  * @param seed - Seed for the image generation.
5095
5095
  * @param providerOptions - Additional provider-specific options that are passed through to the provider
5096
5096
  * as body parameters.
5097
- * @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
5097
+ * @param maxRetries - Maximum number of retries per image model call, including retries after unclassified empty responses. Empty responses marked as not retryable by the provider are not retried. Set to 0 to disable retries. Default: 2.
5098
5098
  * @param abortSignal - An optional abort signal that can be used to cancel the call.
5099
5099
  * @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
5100
5100
  *
@@ -5145,7 +5145,9 @@ declare function generateImage({ model: modelArg, prompt: promptArg, n, maxImage
5145
5145
  */
5146
5146
  providerOptions?: ProviderOptions;
5147
5147
  /**
5148
- * Maximum number of retries per image model call. Set to 0 to disable retries.
5148
+ * Maximum number of retries per image model call, including retries after
5149
+ * unclassified empty responses. Empty responses marked as not retryable by
5150
+ * the provider are not retried. Set to 0 to disable retries.
5149
5151
  *
5150
5152
  * @default 2
5151
5153
  */
package/dist/index.d.ts CHANGED
@@ -5094,7 +5094,7 @@ type GenerateImagePrompt = string | {
5094
5094
  * @param seed - Seed for the image generation.
5095
5095
  * @param providerOptions - Additional provider-specific options that are passed through to the provider
5096
5096
  * as body parameters.
5097
- * @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
5097
+ * @param maxRetries - Maximum number of retries per image model call, including retries after unclassified empty responses. Empty responses marked as not retryable by the provider are not retried. Set to 0 to disable retries. Default: 2.
5098
5098
  * @param abortSignal - An optional abort signal that can be used to cancel the call.
5099
5099
  * @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
5100
5100
  *
@@ -5145,7 +5145,9 @@ declare function generateImage({ model: modelArg, prompt: promptArg, n, maxImage
5145
5145
  */
5146
5146
  providerOptions?: ProviderOptions;
5147
5147
  /**
5148
- * Maximum number of retries per image model call. Set to 0 to disable retries.
5148
+ * Maximum number of retries per image model call, including retries after
5149
+ * unclassified empty responses. Empty responses marked as not retryable by
5150
+ * the provider are not retried. Set to 0 to disable retries.
5149
5151
  *
5150
5152
  * @default 2
5151
5153
  */
package/dist/index.js CHANGED
@@ -1334,7 +1334,7 @@ function detectMediaType({
1334
1334
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
1335
1335
 
1336
1336
  // src/version.ts
1337
- var VERSION = true ? "6.0.278" : "0.0.0-test";
1337
+ var VERSION = true ? "6.0.280" : "0.0.0-test";
1338
1338
 
1339
1339
  // src/util/download/download.ts
1340
1340
  var download = async ({
@@ -2875,13 +2875,14 @@ var retryWithExponentialBackoffRespectingRetryHeaders = ({
2875
2875
  maxRetries = 2,
2876
2876
  initialDelayInMs = 2e3,
2877
2877
  backoffFactor = 2,
2878
- abortSignal
2878
+ abortSignal,
2879
+ additionalRetryableError
2879
2880
  } = {}) => (0, import_provider_utils8.retryWithExponentialBackoff)({
2880
2881
  maxRetries,
2881
2882
  initialDelayInMs,
2882
2883
  backoffFactor,
2883
2884
  abortSignal,
2884
- shouldRetry: (error) => error instanceof Error && (import_provider28.APICallError.isInstance(error) && error.isRetryable === true || import_gateway3.GatewayError.isInstance(error) && error.isRetryable === true),
2885
+ shouldRetry: async (error) => error instanceof Error && (import_provider28.APICallError.isInstance(error) && error.isRetryable === true || import_gateway3.GatewayError.isInstance(error) && error.isRetryable === true) || additionalRetryableError != null && await additionalRetryableError(error),
2885
2886
  getDelayInMs: ({ error, exponentialBackoffDelay }) => getRetryDelayInMs({
2886
2887
  error,
2887
2888
  exponentialBackoffDelay
@@ -2892,7 +2893,8 @@ var retryWithExponentialBackoffRespectingRetryHeaders = ({
2892
2893
  // src/util/prepare-retries.ts
2893
2894
  function prepareRetries({
2894
2895
  maxRetries,
2895
- abortSignal
2896
+ abortSignal,
2897
+ additionalRetryableError
2896
2898
  }) {
2897
2899
  if (maxRetries != null) {
2898
2900
  if (!Number.isInteger(maxRetries)) {
@@ -2915,7 +2917,8 @@ function prepareRetries({
2915
2917
  maxRetries: maxRetriesResult,
2916
2918
  retry: retryWithExponentialBackoffRespectingRetryHeaders({
2917
2919
  maxRetries: maxRetriesResult,
2918
- abortSignal
2920
+ abortSignal,
2921
+ additionalRetryableError
2919
2922
  })
2920
2923
  };
2921
2924
  }
@@ -10705,6 +10708,12 @@ var DefaultEmbedManyResult = class {
10705
10708
 
10706
10709
  // src/generate-image/generate-image.ts
10707
10710
  var import_provider_utils28 = require("@ai-sdk/provider-utils");
10711
+ var RetryableNoImageResultError = class extends Error {
10712
+ constructor() {
10713
+ super("No image generated.");
10714
+ this.name = "RetryableNoImageResultError";
10715
+ }
10716
+ };
10708
10717
  async function generateImage({
10709
10718
  model: modelArg,
10710
10719
  prompt: promptArg,
@@ -10726,7 +10735,8 @@ async function generateImage({
10726
10735
  );
10727
10736
  const { retry } = prepareRetries({
10728
10737
  maxRetries: maxRetriesArg,
10729
- abortSignal
10738
+ abortSignal,
10739
+ additionalRetryableError: (error) => error instanceof RetryableNoImageResultError
10730
10740
  });
10731
10741
  const maxImagesPerCallWithDefault = (_a23 = maxImagesPerCall != null ? maxImagesPerCall : await invokeModelMaxImagesPerCall(model)) != null ? _a23 : 1;
10732
10742
  const callCount = Math.ceil(n / maxImagesPerCallWithDefault);
@@ -10737,25 +10747,41 @@ async function generateImage({
10737
10747
  const remainder = n % maxImagesPerCallWithDefault;
10738
10748
  return remainder === 0 ? maxImagesPerCallWithDefault : remainder;
10739
10749
  });
10740
- const results = await Promise.all(
10741
- callImageCounts.map(
10742
- async (callImageCount) => retry(() => {
10743
- const { prompt, files, mask } = normalizePrompt(promptArg);
10744
- return model.doGenerate({
10745
- prompt,
10746
- files,
10747
- mask,
10748
- n: callImageCount,
10749
- abortSignal,
10750
- headers: headersWithUserAgent,
10751
- size,
10752
- aspectRatio,
10753
- seed,
10754
- providerOptions: providerOptions != null ? providerOptions : {}
10750
+ const resultGroups = await Promise.all(
10751
+ callImageCounts.map(async (callImageCount) => {
10752
+ const callResults = [];
10753
+ try {
10754
+ await retry(async () => {
10755
+ const { prompt, files, mask } = normalizePrompt(promptArg);
10756
+ const result = await model.doGenerate({
10757
+ prompt,
10758
+ files,
10759
+ mask,
10760
+ n: callImageCount,
10761
+ abortSignal,
10762
+ headers: headersWithUserAgent,
10763
+ size,
10764
+ aspectRatio,
10765
+ seed,
10766
+ providerOptions: providerOptions != null ? providerOptions : {}
10767
+ });
10768
+ callResults.push(result);
10769
+ if (result.images.length === 0 && result.isRetryable !== false) {
10770
+ throw new RetryableNoImageResultError();
10771
+ }
10772
+ return result;
10755
10773
  });
10756
- })
10757
- )
10774
+ return callResults;
10775
+ } catch (error) {
10776
+ const noImageResultError = error instanceof RetryableNoImageResultError ? error : RetryError.isInstance(error) && error.lastError instanceof RetryableNoImageResultError ? error.lastError : void 0;
10777
+ if (noImageResultError != null) {
10778
+ return callResults;
10779
+ }
10780
+ throw error;
10781
+ }
10782
+ })
10758
10783
  );
10784
+ const results = resultGroups.flat();
10759
10785
  const images = [];
10760
10786
  const warnings = [];
10761
10787
  const responses = [];
@@ -11636,6 +11662,7 @@ function createDownload(options) {
11636
11662
  }
11637
11663
 
11638
11664
  // src/util/data-url.ts
11665
+ var { atob } = globalThis;
11639
11666
  function getTextFromDataUrl(dataUrl) {
11640
11667
  const [header, base64Content] = dataUrl.split(",");
11641
11668
  const mediaType = header.split(";")[0].split(":")[1];
@@ -11643,7 +11670,7 @@ function getTextFromDataUrl(dataUrl) {
11643
11670
  throw new Error("Invalid data URL format");
11644
11671
  }
11645
11672
  try {
11646
- return window.atob(base64Content);
11673
+ return atob(base64Content);
11647
11674
  } catch (error) {
11648
11675
  throw new Error(`Error decoding data URL`);
11649
11676
  }