ai 4.0.27 → 4.0.29
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 +21 -0
- package/dist/index.d.mts +28 -4
- package/dist/index.d.ts +28 -4
- package/dist/index.js +60 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
@@ -803,43 +803,89 @@ var DefaultEmbedManyResult = class {
|
|
803
803
|
};
|
804
804
|
|
805
805
|
// core/generate-image/generate-image.ts
|
806
|
-
import {
|
806
|
+
import {
|
807
|
+
convertBase64ToUint8Array,
|
808
|
+
convertUint8ArrayToBase64
|
809
|
+
} from "@ai-sdk/provider-utils";
|
807
810
|
async function generateImage({
|
808
811
|
model,
|
809
812
|
prompt,
|
810
|
-
n,
|
813
|
+
n = 1,
|
811
814
|
size,
|
815
|
+
aspectRatio,
|
816
|
+
seed,
|
812
817
|
providerOptions,
|
813
818
|
maxRetries: maxRetriesArg,
|
814
819
|
abortSignal,
|
815
820
|
headers
|
816
821
|
}) {
|
822
|
+
var _a14;
|
817
823
|
const { retry } = prepareRetries({ maxRetries: maxRetriesArg });
|
818
|
-
const
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
824
|
+
const maxImagesPerCall = (_a14 = model.maxImagesPerCall) != null ? _a14 : 1;
|
825
|
+
const callCount = Math.ceil(n / maxImagesPerCall);
|
826
|
+
const callImageCounts = Array.from({ length: callCount }, (_, i) => {
|
827
|
+
if (i < callCount - 1) {
|
828
|
+
return maxImagesPerCall;
|
829
|
+
}
|
830
|
+
const remainder = n % maxImagesPerCall;
|
831
|
+
return remainder === 0 ? maxImagesPerCall : remainder;
|
832
|
+
});
|
833
|
+
const results = await Promise.all(
|
834
|
+
callImageCounts.map(
|
835
|
+
async (callImageCount) => retry(
|
836
|
+
() => model.doGenerate({
|
837
|
+
prompt,
|
838
|
+
n: callImageCount,
|
839
|
+
abortSignal,
|
840
|
+
headers,
|
841
|
+
size,
|
842
|
+
aspectRatio,
|
843
|
+
seed,
|
844
|
+
providerOptions: providerOptions != null ? providerOptions : {}
|
845
|
+
})
|
846
|
+
)
|
847
|
+
)
|
827
848
|
);
|
828
|
-
|
849
|
+
const images = [];
|
850
|
+
const warnings = [];
|
851
|
+
for (const result of results) {
|
852
|
+
images.push(
|
853
|
+
...result.images.map((image) => new DefaultGeneratedImage({ image }))
|
854
|
+
);
|
855
|
+
warnings.push(...result.warnings);
|
856
|
+
}
|
857
|
+
return new DefaultGenerateImageResult({ images, warnings });
|
829
858
|
}
|
830
859
|
var DefaultGenerateImageResult = class {
|
831
860
|
constructor(options) {
|
832
|
-
this.images = options.
|
833
|
-
|
834
|
-
get uint8Array() {
|
835
|
-
return convertBase64ToUint8Array(this.base64);
|
836
|
-
}
|
837
|
-
}));
|
861
|
+
this.images = options.images;
|
862
|
+
this.warnings = options.warnings;
|
838
863
|
}
|
839
864
|
get image() {
|
840
865
|
return this.images[0];
|
841
866
|
}
|
842
867
|
};
|
868
|
+
var DefaultGeneratedImage = class {
|
869
|
+
constructor({ image }) {
|
870
|
+
const isUint8Array = image instanceof Uint8Array;
|
871
|
+
this.base64Data = isUint8Array ? void 0 : image;
|
872
|
+
this.uint8ArrayData = isUint8Array ? image : void 0;
|
873
|
+
}
|
874
|
+
// lazy conversion with caching to avoid unnecessary conversion overhead:
|
875
|
+
get base64() {
|
876
|
+
if (this.base64Data == null) {
|
877
|
+
this.base64Data = convertUint8ArrayToBase64(this.uint8ArrayData);
|
878
|
+
}
|
879
|
+
return this.base64Data;
|
880
|
+
}
|
881
|
+
// lazy conversion with caching to avoid unnecessary conversion overhead:
|
882
|
+
get uint8Array() {
|
883
|
+
if (this.uint8ArrayData == null) {
|
884
|
+
this.uint8ArrayData = convertBase64ToUint8Array(this.base64Data);
|
885
|
+
}
|
886
|
+
return this.uint8ArrayData;
|
887
|
+
}
|
888
|
+
};
|
843
889
|
|
844
890
|
// core/generate-object/generate-object.ts
|
845
891
|
import { createIdGenerator, safeParseJSON } from "@ai-sdk/provider-utils";
|
@@ -943,7 +989,7 @@ function detectImageMimeType(image) {
|
|
943
989
|
// core/prompt/data-content.ts
|
944
990
|
import {
|
945
991
|
convertBase64ToUint8Array as convertBase64ToUint8Array2,
|
946
|
-
convertUint8ArrayToBase64
|
992
|
+
convertUint8ArrayToBase64 as convertUint8ArrayToBase642
|
947
993
|
} from "@ai-sdk/provider-utils";
|
948
994
|
|
949
995
|
// core/prompt/invalid-data-content-error.ts
|
@@ -988,9 +1034,9 @@ function convertDataContentToBase64String(content) {
|
|
988
1034
|
return content;
|
989
1035
|
}
|
990
1036
|
if (content instanceof ArrayBuffer) {
|
991
|
-
return
|
1037
|
+
return convertUint8ArrayToBase642(new Uint8Array(content));
|
992
1038
|
}
|
993
|
-
return
|
1039
|
+
return convertUint8ArrayToBase642(content);
|
994
1040
|
}
|
995
1041
|
function convertDataContentToUint8Array(content) {
|
996
1042
|
if (content instanceof Uint8Array) {
|