ai 6.0.279 → 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 +12 -0
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +51 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -24
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +3 -2
- package/dist/internal/index.d.ts +3 -2
- package/dist/internal/index.js +8 -5
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +8 -5
- package/dist/internal/index.mjs.map +1 -1
- package/docs/03-ai-sdk-core/35-image-generation.mdx +2 -0
- package/docs/07-reference/01-ai-sdk-core/10-generate-image.mdx +2 -1
- package/package.json +4 -4
- package/src/generate-image/generate-image.ts +63 -20
- package/src/util/data-url.ts +6 -1
- package/src/util/prepare-retries.ts +7 -1
- package/src/util/retry-with-exponential-backoff.ts +9 -4
package/dist/index.mjs
CHANGED
|
@@ -1224,7 +1224,7 @@ import {
|
|
|
1224
1224
|
} from "@ai-sdk/provider-utils";
|
|
1225
1225
|
|
|
1226
1226
|
// src/version.ts
|
|
1227
|
-
var VERSION = true ? "6.0.
|
|
1227
|
+
var VERSION = true ? "6.0.280" : "0.0.0-test";
|
|
1228
1228
|
|
|
1229
1229
|
// src/util/download/download.ts
|
|
1230
1230
|
var download = async ({
|
|
@@ -2775,13 +2775,14 @@ var retryWithExponentialBackoffRespectingRetryHeaders = ({
|
|
|
2775
2775
|
maxRetries = 2,
|
|
2776
2776
|
initialDelayInMs = 2e3,
|
|
2777
2777
|
backoffFactor = 2,
|
|
2778
|
-
abortSignal
|
|
2778
|
+
abortSignal,
|
|
2779
|
+
additionalRetryableError
|
|
2779
2780
|
} = {}) => retryWithExponentialBackoff({
|
|
2780
2781
|
maxRetries,
|
|
2781
2782
|
initialDelayInMs,
|
|
2782
2783
|
backoffFactor,
|
|
2783
2784
|
abortSignal,
|
|
2784
|
-
shouldRetry: (error) => error instanceof Error && (APICallError2.isInstance(error) && error.isRetryable === true || GatewayError.isInstance(error) && error.isRetryable === true),
|
|
2785
|
+
shouldRetry: async (error) => error instanceof Error && (APICallError2.isInstance(error) && error.isRetryable === true || GatewayError.isInstance(error) && error.isRetryable === true) || additionalRetryableError != null && await additionalRetryableError(error),
|
|
2785
2786
|
getDelayInMs: ({ error, exponentialBackoffDelay }) => getRetryDelayInMs({
|
|
2786
2787
|
error,
|
|
2787
2788
|
exponentialBackoffDelay
|
|
@@ -2792,7 +2793,8 @@ var retryWithExponentialBackoffRespectingRetryHeaders = ({
|
|
|
2792
2793
|
// src/util/prepare-retries.ts
|
|
2793
2794
|
function prepareRetries({
|
|
2794
2795
|
maxRetries,
|
|
2795
|
-
abortSignal
|
|
2796
|
+
abortSignal,
|
|
2797
|
+
additionalRetryableError
|
|
2796
2798
|
}) {
|
|
2797
2799
|
if (maxRetries != null) {
|
|
2798
2800
|
if (!Number.isInteger(maxRetries)) {
|
|
@@ -2815,7 +2817,8 @@ function prepareRetries({
|
|
|
2815
2817
|
maxRetries: maxRetriesResult,
|
|
2816
2818
|
retry: retryWithExponentialBackoffRespectingRetryHeaders({
|
|
2817
2819
|
maxRetries: maxRetriesResult,
|
|
2818
|
-
abortSignal
|
|
2820
|
+
abortSignal,
|
|
2821
|
+
additionalRetryableError
|
|
2819
2822
|
})
|
|
2820
2823
|
};
|
|
2821
2824
|
}
|
|
@@ -10652,6 +10655,12 @@ import {
|
|
|
10652
10655
|
convertBase64ToUint8Array as convertBase64ToUint8Array5,
|
|
10653
10656
|
withUserAgentSuffix as withUserAgentSuffix5
|
|
10654
10657
|
} from "@ai-sdk/provider-utils";
|
|
10658
|
+
var RetryableNoImageResultError = class extends Error {
|
|
10659
|
+
constructor() {
|
|
10660
|
+
super("No image generated.");
|
|
10661
|
+
this.name = "RetryableNoImageResultError";
|
|
10662
|
+
}
|
|
10663
|
+
};
|
|
10655
10664
|
async function generateImage({
|
|
10656
10665
|
model: modelArg,
|
|
10657
10666
|
prompt: promptArg,
|
|
@@ -10673,7 +10682,8 @@ async function generateImage({
|
|
|
10673
10682
|
);
|
|
10674
10683
|
const { retry } = prepareRetries({
|
|
10675
10684
|
maxRetries: maxRetriesArg,
|
|
10676
|
-
abortSignal
|
|
10685
|
+
abortSignal,
|
|
10686
|
+
additionalRetryableError: (error) => error instanceof RetryableNoImageResultError
|
|
10677
10687
|
});
|
|
10678
10688
|
const maxImagesPerCallWithDefault = (_a23 = maxImagesPerCall != null ? maxImagesPerCall : await invokeModelMaxImagesPerCall(model)) != null ? _a23 : 1;
|
|
10679
10689
|
const callCount = Math.ceil(n / maxImagesPerCallWithDefault);
|
|
@@ -10684,25 +10694,41 @@ async function generateImage({
|
|
|
10684
10694
|
const remainder = n % maxImagesPerCallWithDefault;
|
|
10685
10695
|
return remainder === 0 ? maxImagesPerCallWithDefault : remainder;
|
|
10686
10696
|
});
|
|
10687
|
-
const
|
|
10688
|
-
callImageCounts.map(
|
|
10689
|
-
|
|
10690
|
-
|
|
10691
|
-
|
|
10692
|
-
prompt,
|
|
10693
|
-
|
|
10694
|
-
|
|
10695
|
-
|
|
10696
|
-
|
|
10697
|
-
|
|
10698
|
-
|
|
10699
|
-
|
|
10700
|
-
|
|
10701
|
-
|
|
10697
|
+
const resultGroups = await Promise.all(
|
|
10698
|
+
callImageCounts.map(async (callImageCount) => {
|
|
10699
|
+
const callResults = [];
|
|
10700
|
+
try {
|
|
10701
|
+
await retry(async () => {
|
|
10702
|
+
const { prompt, files, mask } = normalizePrompt(promptArg);
|
|
10703
|
+
const result = await model.doGenerate({
|
|
10704
|
+
prompt,
|
|
10705
|
+
files,
|
|
10706
|
+
mask,
|
|
10707
|
+
n: callImageCount,
|
|
10708
|
+
abortSignal,
|
|
10709
|
+
headers: headersWithUserAgent,
|
|
10710
|
+
size,
|
|
10711
|
+
aspectRatio,
|
|
10712
|
+
seed,
|
|
10713
|
+
providerOptions: providerOptions != null ? providerOptions : {}
|
|
10714
|
+
});
|
|
10715
|
+
callResults.push(result);
|
|
10716
|
+
if (result.images.length === 0 && result.isRetryable !== false) {
|
|
10717
|
+
throw new RetryableNoImageResultError();
|
|
10718
|
+
}
|
|
10719
|
+
return result;
|
|
10702
10720
|
});
|
|
10703
|
-
|
|
10704
|
-
|
|
10721
|
+
return callResults;
|
|
10722
|
+
} catch (error) {
|
|
10723
|
+
const noImageResultError = error instanceof RetryableNoImageResultError ? error : RetryError.isInstance(error) && error.lastError instanceof RetryableNoImageResultError ? error.lastError : void 0;
|
|
10724
|
+
if (noImageResultError != null) {
|
|
10725
|
+
return callResults;
|
|
10726
|
+
}
|
|
10727
|
+
throw error;
|
|
10728
|
+
}
|
|
10729
|
+
})
|
|
10705
10730
|
);
|
|
10731
|
+
const results = resultGroups.flat();
|
|
10706
10732
|
const images = [];
|
|
10707
10733
|
const warnings = [];
|
|
10708
10734
|
const responses = [];
|
|
@@ -11597,6 +11623,7 @@ function createDownload(options) {
|
|
|
11597
11623
|
}
|
|
11598
11624
|
|
|
11599
11625
|
// src/util/data-url.ts
|
|
11626
|
+
var { atob } = globalThis;
|
|
11600
11627
|
function getTextFromDataUrl(dataUrl) {
|
|
11601
11628
|
const [header, base64Content] = dataUrl.split(",");
|
|
11602
11629
|
const mediaType = header.split(";")[0].split(":")[1];
|
|
@@ -11604,7 +11631,7 @@ function getTextFromDataUrl(dataUrl) {
|
|
|
11604
11631
|
throw new Error("Invalid data URL format");
|
|
11605
11632
|
}
|
|
11606
11633
|
try {
|
|
11607
|
-
return
|
|
11634
|
+
return atob(base64Content);
|
|
11608
11635
|
} catch (error) {
|
|
11609
11636
|
throw new Error(`Error decoding data URL`);
|
|
11610
11637
|
}
|