ai 4.0.27 → 4.0.28
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 +15 -0
- package/dist/index.d.mts +28 -4
- package/dist/index.d.ts +28 -4
- package/dist/index.js +40 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
@@ -803,43 +803,70 @@ 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
813
|
n,
|
811
814
|
size,
|
815
|
+
aspectRatio,
|
816
|
+
seed,
|
812
817
|
providerOptions,
|
813
818
|
maxRetries: maxRetriesArg,
|
814
819
|
abortSignal,
|
815
820
|
headers
|
816
821
|
}) {
|
817
822
|
const { retry } = prepareRetries({ maxRetries: maxRetriesArg });
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
823
|
+
return new DefaultGenerateImageResult(
|
824
|
+
await retry(
|
825
|
+
() => model.doGenerate({
|
826
|
+
prompt,
|
827
|
+
n: n != null ? n : 1,
|
828
|
+
abortSignal,
|
829
|
+
headers,
|
830
|
+
size,
|
831
|
+
aspectRatio,
|
832
|
+
seed,
|
833
|
+
providerOptions: providerOptions != null ? providerOptions : {}
|
834
|
+
})
|
835
|
+
)
|
827
836
|
);
|
828
|
-
return new DefaultGenerateImageResult({ base64Images: images });
|
829
837
|
}
|
830
838
|
var DefaultGenerateImageResult = class {
|
831
839
|
constructor(options) {
|
832
|
-
this.images = options.
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
}
|
837
|
-
}));
|
840
|
+
this.images = options.images.map(
|
841
|
+
(image) => new DefaultGeneratedImage({ imageData: image })
|
842
|
+
);
|
843
|
+
this.warnings = options.warnings;
|
838
844
|
}
|
839
845
|
get image() {
|
840
846
|
return this.images[0];
|
841
847
|
}
|
842
848
|
};
|
849
|
+
var DefaultGeneratedImage = class {
|
850
|
+
constructor({ imageData }) {
|
851
|
+
const isUint8Array = imageData instanceof Uint8Array;
|
852
|
+
this.base64Data = isUint8Array ? void 0 : imageData;
|
853
|
+
this.uint8ArrayData = isUint8Array ? imageData : void 0;
|
854
|
+
}
|
855
|
+
// lazy conversion with caching to avoid unnecessary conversion overhead:
|
856
|
+
get base64() {
|
857
|
+
if (this.base64Data == null) {
|
858
|
+
this.base64Data = convertUint8ArrayToBase64(this.uint8ArrayData);
|
859
|
+
}
|
860
|
+
return this.base64Data;
|
861
|
+
}
|
862
|
+
// lazy conversion with caching to avoid unnecessary conversion overhead:
|
863
|
+
get uint8Array() {
|
864
|
+
if (this.uint8ArrayData == null) {
|
865
|
+
this.uint8ArrayData = convertBase64ToUint8Array(this.base64Data);
|
866
|
+
}
|
867
|
+
return this.uint8ArrayData;
|
868
|
+
}
|
869
|
+
};
|
843
870
|
|
844
871
|
// core/generate-object/generate-object.ts
|
845
872
|
import { createIdGenerator, safeParseJSON } from "@ai-sdk/provider-utils";
|
@@ -943,7 +970,7 @@ function detectImageMimeType(image) {
|
|
943
970
|
// core/prompt/data-content.ts
|
944
971
|
import {
|
945
972
|
convertBase64ToUint8Array as convertBase64ToUint8Array2,
|
946
|
-
convertUint8ArrayToBase64
|
973
|
+
convertUint8ArrayToBase64 as convertUint8ArrayToBase642
|
947
974
|
} from "@ai-sdk/provider-utils";
|
948
975
|
|
949
976
|
// core/prompt/invalid-data-content-error.ts
|
@@ -988,9 +1015,9 @@ function convertDataContentToBase64String(content) {
|
|
988
1015
|
return content;
|
989
1016
|
}
|
990
1017
|
if (content instanceof ArrayBuffer) {
|
991
|
-
return
|
1018
|
+
return convertUint8ArrayToBase642(new Uint8Array(content));
|
992
1019
|
}
|
993
|
-
return
|
1020
|
+
return convertUint8ArrayToBase642(content);
|
994
1021
|
}
|
995
1022
|
function convertDataContentToUint8Array(content) {
|
996
1023
|
if (content instanceof Uint8Array) {
|