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 +20 -0
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +55 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -25
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +2 -1
- package/dist/internal/index.d.ts +2 -1
- package/dist/internal/index.js +14 -8
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +14 -8
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -727,7 +727,7 @@ import {
|
|
|
727
727
|
} from "@ai-sdk/provider-utils";
|
|
728
728
|
|
|
729
729
|
// src/version.ts
|
|
730
|
-
var VERSION = true ? "5.0.
|
|
730
|
+
var VERSION = true ? "5.0.255" : "0.0.0-test";
|
|
731
731
|
|
|
732
732
|
// src/util/download/download.ts
|
|
733
733
|
var download = async ({
|
|
@@ -1779,18 +1779,21 @@ var retryWithExponentialBackoffRespectingRetryHeaders = ({
|
|
|
1779
1779
|
maxRetries = 2,
|
|
1780
1780
|
initialDelayInMs = 2e3,
|
|
1781
1781
|
backoffFactor = 2,
|
|
1782
|
-
abortSignal
|
|
1782
|
+
abortSignal,
|
|
1783
|
+
additionalRetryableError
|
|
1783
1784
|
} = {}) => async (f) => _retryWithExponentialBackoff(f, {
|
|
1784
1785
|
maxRetries,
|
|
1785
1786
|
delayInMs: initialDelayInMs,
|
|
1786
1787
|
backoffFactor,
|
|
1787
|
-
abortSignal
|
|
1788
|
+
abortSignal,
|
|
1789
|
+
additionalRetryableError
|
|
1788
1790
|
});
|
|
1789
1791
|
async function _retryWithExponentialBackoff(f, {
|
|
1790
1792
|
maxRetries,
|
|
1791
1793
|
delayInMs,
|
|
1792
1794
|
backoffFactor,
|
|
1793
|
-
abortSignal
|
|
1795
|
+
abortSignal,
|
|
1796
|
+
additionalRetryableError
|
|
1794
1797
|
}, errors = []) {
|
|
1795
1798
|
try {
|
|
1796
1799
|
return await f();
|
|
@@ -1811,7 +1814,7 @@ async function _retryWithExponentialBackoff(f, {
|
|
|
1811
1814
|
errors: newErrors
|
|
1812
1815
|
});
|
|
1813
1816
|
}
|
|
1814
|
-
if (error instanceof Error && (APICallError2.isInstance(error) && error.isRetryable === true || GatewayError.isInstance(error) && error.isRetryable === true) && tryNumber <= maxRetries) {
|
|
1817
|
+
if ((error instanceof Error && (APICallError2.isInstance(error) && error.isRetryable === true || GatewayError.isInstance(error) && error.isRetryable === true) || (additionalRetryableError == null ? void 0 : additionalRetryableError(error)) === true) && tryNumber <= maxRetries) {
|
|
1815
1818
|
await delay(
|
|
1816
1819
|
getRetryDelayInMs({
|
|
1817
1820
|
error,
|
|
@@ -1825,7 +1828,8 @@ async function _retryWithExponentialBackoff(f, {
|
|
|
1825
1828
|
maxRetries,
|
|
1826
1829
|
delayInMs: backoffFactor * delayInMs,
|
|
1827
1830
|
backoffFactor,
|
|
1828
|
-
abortSignal
|
|
1831
|
+
abortSignal,
|
|
1832
|
+
additionalRetryableError
|
|
1829
1833
|
},
|
|
1830
1834
|
newErrors
|
|
1831
1835
|
);
|
|
@@ -1844,7 +1848,8 @@ async function _retryWithExponentialBackoff(f, {
|
|
|
1844
1848
|
// src/util/prepare-retries.ts
|
|
1845
1849
|
function prepareRetries({
|
|
1846
1850
|
maxRetries,
|
|
1847
|
-
abortSignal
|
|
1851
|
+
abortSignal,
|
|
1852
|
+
additionalRetryableError
|
|
1848
1853
|
}) {
|
|
1849
1854
|
if (maxRetries != null) {
|
|
1850
1855
|
if (!Number.isInteger(maxRetries)) {
|
|
@@ -1867,7 +1872,8 @@ function prepareRetries({
|
|
|
1867
1872
|
maxRetries: maxRetriesResult,
|
|
1868
1873
|
retry: retryWithExponentialBackoffRespectingRetryHeaders({
|
|
1869
1874
|
maxRetries: maxRetriesResult,
|
|
1870
|
-
abortSignal
|
|
1875
|
+
abortSignal,
|
|
1876
|
+
additionalRetryableError
|
|
1871
1877
|
})
|
|
1872
1878
|
};
|
|
1873
1879
|
}
|
|
@@ -6802,6 +6808,12 @@ var DefaultEmbedManyResult = class {
|
|
|
6802
6808
|
import {
|
|
6803
6809
|
withUserAgentSuffix as withUserAgentSuffix5
|
|
6804
6810
|
} from "@ai-sdk/provider-utils";
|
|
6811
|
+
var RetryableNoImageResultError = class extends Error {
|
|
6812
|
+
constructor() {
|
|
6813
|
+
super("No image generated.");
|
|
6814
|
+
this.name = "RetryableNoImageResultError";
|
|
6815
|
+
}
|
|
6816
|
+
};
|
|
6805
6817
|
async function generateImage({
|
|
6806
6818
|
model: modelArg,
|
|
6807
6819
|
prompt,
|
|
@@ -6823,7 +6835,8 @@ async function generateImage({
|
|
|
6823
6835
|
);
|
|
6824
6836
|
const { retry } = prepareRetries({
|
|
6825
6837
|
maxRetries: maxRetriesArg,
|
|
6826
|
-
abortSignal
|
|
6838
|
+
abortSignal,
|
|
6839
|
+
additionalRetryableError: (error) => error instanceof RetryableNoImageResultError
|
|
6827
6840
|
});
|
|
6828
6841
|
const maxImagesPerCallWithDefault = (_a16 = maxImagesPerCall != null ? maxImagesPerCall : await invokeModelMaxImagesPerCall(model)) != null ? _a16 : 1;
|
|
6829
6842
|
const callCount = Math.ceil(n / maxImagesPerCallWithDefault);
|
|
@@ -6834,22 +6847,38 @@ async function generateImage({
|
|
|
6834
6847
|
const remainder = n % maxImagesPerCallWithDefault;
|
|
6835
6848
|
return remainder === 0 ? maxImagesPerCallWithDefault : remainder;
|
|
6836
6849
|
});
|
|
6837
|
-
const
|
|
6838
|
-
callImageCounts.map(
|
|
6839
|
-
|
|
6840
|
-
|
|
6841
|
-
|
|
6842
|
-
|
|
6843
|
-
|
|
6844
|
-
|
|
6845
|
-
|
|
6846
|
-
|
|
6847
|
-
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
|
|
6851
|
-
|
|
6850
|
+
const resultGroups = await Promise.all(
|
|
6851
|
+
callImageCounts.map(async (callImageCount) => {
|
|
6852
|
+
const callResults = [];
|
|
6853
|
+
try {
|
|
6854
|
+
await retry(async () => {
|
|
6855
|
+
const result = await model.doGenerate({
|
|
6856
|
+
prompt,
|
|
6857
|
+
n: callImageCount,
|
|
6858
|
+
abortSignal,
|
|
6859
|
+
headers: headersWithUserAgent,
|
|
6860
|
+
size,
|
|
6861
|
+
aspectRatio,
|
|
6862
|
+
seed,
|
|
6863
|
+
providerOptions: providerOptions != null ? providerOptions : {}
|
|
6864
|
+
});
|
|
6865
|
+
callResults.push(result);
|
|
6866
|
+
if (result.images.length === 0 && result.isRetryable !== false) {
|
|
6867
|
+
throw new RetryableNoImageResultError();
|
|
6868
|
+
}
|
|
6869
|
+
return result;
|
|
6870
|
+
});
|
|
6871
|
+
return callResults;
|
|
6872
|
+
} catch (error) {
|
|
6873
|
+
const noImageResultError = error instanceof RetryableNoImageResultError ? error : RetryError.isInstance(error) && error.lastError instanceof RetryableNoImageResultError ? error.lastError : void 0;
|
|
6874
|
+
if (noImageResultError != null) {
|
|
6875
|
+
return callResults;
|
|
6876
|
+
}
|
|
6877
|
+
throw error;
|
|
6878
|
+
}
|
|
6879
|
+
})
|
|
6852
6880
|
);
|
|
6881
|
+
const results = resultGroups.flat();
|
|
6853
6882
|
const images = [];
|
|
6854
6883
|
const warnings = [];
|
|
6855
6884
|
const responses = [];
|
|
@@ -7689,6 +7718,7 @@ function createDownload(options) {
|
|
|
7689
7718
|
}
|
|
7690
7719
|
|
|
7691
7720
|
// src/util/data-url.ts
|
|
7721
|
+
var { atob } = globalThis;
|
|
7692
7722
|
function getTextFromDataUrl(dataUrl) {
|
|
7693
7723
|
const [header, base64Content] = dataUrl.split(",");
|
|
7694
7724
|
const mediaType = header.split(";")[0].split(":")[1];
|
|
@@ -7696,7 +7726,7 @@ function getTextFromDataUrl(dataUrl) {
|
|
|
7696
7726
|
throw new Error("Invalid data URL format");
|
|
7697
7727
|
}
|
|
7698
7728
|
try {
|
|
7699
|
-
return
|
|
7729
|
+
return atob(base64Content);
|
|
7700
7730
|
} catch (error) {
|
|
7701
7731
|
throw new Error(`Error decoding data URL`);
|
|
7702
7732
|
}
|