ai 5.0.253 → 5.0.255

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,25 @@
1
1
  # ai
2
2
 
3
+ ## 5.0.255
4
+
5
+ ### Patch Changes
6
+
7
+ - c2089a9: Retry unclassified empty image results, preserve completed-attempt diagnostics, add provider-independent result retryability classification, preserve it through the AI Gateway, and mark Google Vertex RAI-filtered results as terminal.
8
+ - 7f4e217: fix(ai): decode text data URLs in Node.js
9
+ - Updated dependencies [c2089a9]
10
+ - Updated dependencies [ab3990f]
11
+ - @ai-sdk/gateway@2.0.149
12
+ - @ai-sdk/provider@2.0.4
13
+ - @ai-sdk/provider-utils@3.0.37
14
+
15
+ ## 5.0.254
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [79ac7d9]
20
+ - Updated dependencies [ca8f9e5]
21
+ - @ai-sdk/gateway@2.0.148
22
+
3
23
  ## 5.0.253
4
24
 
5
25
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -2859,7 +2859,7 @@ Generates images using an image model.
2859
2859
  @param seed - Seed for the image generation.
2860
2860
  @param providerOptions - Additional provider-specific options that are passed through to the provider
2861
2861
  as body parameters.
2862
- @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
2862
+ @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.
2863
2863
  @param abortSignal - An optional abort signal that can be used to cancel the call.
2864
2864
  @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
2865
2865
 
@@ -2910,7 +2910,9 @@ declare function generateImage({ model: modelArg, prompt, n, maxImagesPerCall, s
2910
2910
  */
2911
2911
  providerOptions?: ProviderOptions;
2912
2912
  /**
2913
- Maximum number of retries per embedding model call. Set to 0 to disable retries.
2913
+ Maximum number of retries per image model call, including retries after
2914
+ unclassified empty responses. Empty responses marked as not retryable by the
2915
+ provider are not retried. Set to 0 to disable retries.
2914
2916
 
2915
2917
  @default 2
2916
2918
  */
package/dist/index.d.ts CHANGED
@@ -2859,7 +2859,7 @@ Generates images using an image model.
2859
2859
  @param seed - Seed for the image generation.
2860
2860
  @param providerOptions - Additional provider-specific options that are passed through to the provider
2861
2861
  as body parameters.
2862
- @param maxRetries - Maximum number of retries. Set to 0 to disable retries. Default: 2.
2862
+ @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.
2863
2863
  @param abortSignal - An optional abort signal that can be used to cancel the call.
2864
2864
  @param headers - Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers.
2865
2865
 
@@ -2910,7 +2910,9 @@ declare function generateImage({ model: modelArg, prompt, n, maxImagesPerCall, s
2910
2910
  */
2911
2911
  providerOptions?: ProviderOptions;
2912
2912
  /**
2913
- Maximum number of retries per embedding model call. Set to 0 to disable retries.
2913
+ Maximum number of retries per image model call, including retries after
2914
+ unclassified empty responses. Empty responses marked as not retryable by the
2915
+ provider are not retried. Set to 0 to disable retries.
2914
2916
 
2915
2917
  @default 2
2916
2918
  */
package/dist/index.js CHANGED
@@ -816,7 +816,7 @@ function detectMediaType({
816
816
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
817
817
 
818
818
  // src/version.ts
819
- var VERSION = true ? "5.0.253" : "0.0.0-test";
819
+ var VERSION = true ? "5.0.255" : "0.0.0-test";
820
820
 
821
821
  // src/util/download/download.ts
822
822
  var download = async ({
@@ -1863,18 +1863,21 @@ var retryWithExponentialBackoffRespectingRetryHeaders = ({
1863
1863
  maxRetries = 2,
1864
1864
  initialDelayInMs = 2e3,
1865
1865
  backoffFactor = 2,
1866
- abortSignal
1866
+ abortSignal,
1867
+ additionalRetryableError
1867
1868
  } = {}) => async (f) => _retryWithExponentialBackoff(f, {
1868
1869
  maxRetries,
1869
1870
  delayInMs: initialDelayInMs,
1870
1871
  backoffFactor,
1871
- abortSignal
1872
+ abortSignal,
1873
+ additionalRetryableError
1872
1874
  });
1873
1875
  async function _retryWithExponentialBackoff(f, {
1874
1876
  maxRetries,
1875
1877
  delayInMs,
1876
1878
  backoffFactor,
1877
- abortSignal
1879
+ abortSignal,
1880
+ additionalRetryableError
1878
1881
  }, errors = []) {
1879
1882
  try {
1880
1883
  return await f();
@@ -1895,7 +1898,7 @@ async function _retryWithExponentialBackoff(f, {
1895
1898
  errors: newErrors
1896
1899
  });
1897
1900
  }
1898
- if (error instanceof Error && (import_provider21.APICallError.isInstance(error) && error.isRetryable === true || import_gateway3.GatewayError.isInstance(error) && error.isRetryable === true) && tryNumber <= maxRetries) {
1901
+ if ((error instanceof Error && (import_provider21.APICallError.isInstance(error) && error.isRetryable === true || import_gateway3.GatewayError.isInstance(error) && error.isRetryable === true) || (additionalRetryableError == null ? void 0 : additionalRetryableError(error)) === true) && tryNumber <= maxRetries) {
1899
1902
  await (0, import_provider_utils7.delay)(
1900
1903
  getRetryDelayInMs({
1901
1904
  error,
@@ -1909,7 +1912,8 @@ async function _retryWithExponentialBackoff(f, {
1909
1912
  maxRetries,
1910
1913
  delayInMs: backoffFactor * delayInMs,
1911
1914
  backoffFactor,
1912
- abortSignal
1915
+ abortSignal,
1916
+ additionalRetryableError
1913
1917
  },
1914
1918
  newErrors
1915
1919
  );
@@ -1928,7 +1932,8 @@ async function _retryWithExponentialBackoff(f, {
1928
1932
  // src/util/prepare-retries.ts
1929
1933
  function prepareRetries({
1930
1934
  maxRetries,
1931
- abortSignal
1935
+ abortSignal,
1936
+ additionalRetryableError
1932
1937
  }) {
1933
1938
  if (maxRetries != null) {
1934
1939
  if (!Number.isInteger(maxRetries)) {
@@ -1951,7 +1956,8 @@ function prepareRetries({
1951
1956
  maxRetries: maxRetriesResult,
1952
1957
  retry: retryWithExponentialBackoffRespectingRetryHeaders({
1953
1958
  maxRetries: maxRetriesResult,
1954
- abortSignal
1959
+ abortSignal,
1960
+ additionalRetryableError
1955
1961
  })
1956
1962
  };
1957
1963
  }
@@ -6861,6 +6867,12 @@ var DefaultEmbedManyResult = class {
6861
6867
 
6862
6868
  // src/generate-image/generate-image.ts
6863
6869
  var import_provider_utils19 = require("@ai-sdk/provider-utils");
6870
+ var RetryableNoImageResultError = class extends Error {
6871
+ constructor() {
6872
+ super("No image generated.");
6873
+ this.name = "RetryableNoImageResultError";
6874
+ }
6875
+ };
6864
6876
  async function generateImage({
6865
6877
  model: modelArg,
6866
6878
  prompt,
@@ -6882,7 +6894,8 @@ async function generateImage({
6882
6894
  );
6883
6895
  const { retry } = prepareRetries({
6884
6896
  maxRetries: maxRetriesArg,
6885
- abortSignal
6897
+ abortSignal,
6898
+ additionalRetryableError: (error) => error instanceof RetryableNoImageResultError
6886
6899
  });
6887
6900
  const maxImagesPerCallWithDefault = (_a16 = maxImagesPerCall != null ? maxImagesPerCall : await invokeModelMaxImagesPerCall(model)) != null ? _a16 : 1;
6888
6901
  const callCount = Math.ceil(n / maxImagesPerCallWithDefault);
@@ -6893,22 +6906,38 @@ async function generateImage({
6893
6906
  const remainder = n % maxImagesPerCallWithDefault;
6894
6907
  return remainder === 0 ? maxImagesPerCallWithDefault : remainder;
6895
6908
  });
6896
- const results = await Promise.all(
6897
- callImageCounts.map(
6898
- async (callImageCount) => retry(
6899
- () => model.doGenerate({
6900
- prompt,
6901
- n: callImageCount,
6902
- abortSignal,
6903
- headers: headersWithUserAgent,
6904
- size,
6905
- aspectRatio,
6906
- seed,
6907
- providerOptions: providerOptions != null ? providerOptions : {}
6908
- })
6909
- )
6910
- )
6909
+ const resultGroups = await Promise.all(
6910
+ callImageCounts.map(async (callImageCount) => {
6911
+ const callResults = [];
6912
+ try {
6913
+ await retry(async () => {
6914
+ const result = await model.doGenerate({
6915
+ prompt,
6916
+ n: callImageCount,
6917
+ abortSignal,
6918
+ headers: headersWithUserAgent,
6919
+ size,
6920
+ aspectRatio,
6921
+ seed,
6922
+ providerOptions: providerOptions != null ? providerOptions : {}
6923
+ });
6924
+ callResults.push(result);
6925
+ if (result.images.length === 0 && result.isRetryable !== false) {
6926
+ throw new RetryableNoImageResultError();
6927
+ }
6928
+ return result;
6929
+ });
6930
+ return callResults;
6931
+ } catch (error) {
6932
+ const noImageResultError = error instanceof RetryableNoImageResultError ? error : RetryError.isInstance(error) && error.lastError instanceof RetryableNoImageResultError ? error.lastError : void 0;
6933
+ if (noImageResultError != null) {
6934
+ return callResults;
6935
+ }
6936
+ throw error;
6937
+ }
6938
+ })
6911
6939
  );
6940
+ const results = resultGroups.flat();
6912
6941
  const images = [];
6913
6942
  const warnings = [];
6914
6943
  const responses = [];
@@ -7734,6 +7763,7 @@ function createDownload(options) {
7734
7763
  }
7735
7764
 
7736
7765
  // src/util/data-url.ts
7766
+ var { atob } = globalThis;
7737
7767
  function getTextFromDataUrl(dataUrl) {
7738
7768
  const [header, base64Content] = dataUrl.split(",");
7739
7769
  const mediaType = header.split(";")[0].split(":")[1];
@@ -7741,7 +7771,7 @@ function getTextFromDataUrl(dataUrl) {
7741
7771
  throw new Error("Invalid data URL format");
7742
7772
  }
7743
7773
  try {
7744
- return window.atob(base64Content);
7774
+ return atob(base64Content);
7745
7775
  } catch (error) {
7746
7776
  throw new Error(`Error decoding data URL`);
7747
7777
  }