ai 3.3.32 → 3.3.33
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 +6 -0
- package/dist/index.js +80 -82
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +80 -82
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/rsc/dist/rsc-server.mjs +80 -82
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/dist/index.mjs
CHANGED
@@ -864,100 +864,98 @@ function convertToLanguageModelMessage(message, downloadedImages) {
|
|
864
864
|
}
|
865
865
|
return {
|
866
866
|
role: "user",
|
867
|
-
content: message.content.map(
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
if (
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
};
|
895
|
-
}
|
867
|
+
content: message.content.map((part) => {
|
868
|
+
var _a11, _b, _c;
|
869
|
+
switch (part.type) {
|
870
|
+
case "text": {
|
871
|
+
return {
|
872
|
+
type: "text",
|
873
|
+
text: part.text,
|
874
|
+
providerMetadata: part.experimental_providerMetadata
|
875
|
+
};
|
876
|
+
}
|
877
|
+
case "image": {
|
878
|
+
if (part.image instanceof URL) {
|
879
|
+
if (downloadedImages == null) {
|
880
|
+
return {
|
881
|
+
type: "image",
|
882
|
+
image: part.image,
|
883
|
+
mimeType: part.mimeType,
|
884
|
+
providerMetadata: part.experimental_providerMetadata
|
885
|
+
};
|
886
|
+
} else {
|
887
|
+
const downloadedImage = downloadedImages[part.image.toString()];
|
888
|
+
return {
|
889
|
+
type: "image",
|
890
|
+
image: downloadedImage.data,
|
891
|
+
mimeType: (_a11 = part.mimeType) != null ? _a11 : downloadedImage.mimeType,
|
892
|
+
providerMetadata: part.experimental_providerMetadata
|
893
|
+
};
|
896
894
|
}
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
}
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
}
|
895
|
+
}
|
896
|
+
if (typeof part.image === "string") {
|
897
|
+
try {
|
898
|
+
const url = new URL(part.image);
|
899
|
+
switch (url.protocol) {
|
900
|
+
case "http:":
|
901
|
+
case "https:": {
|
902
|
+
if (downloadedImages == null) {
|
903
|
+
return {
|
904
|
+
type: "image",
|
905
|
+
image: url,
|
906
|
+
mimeType: part.mimeType,
|
907
|
+
providerMetadata: part.experimental_providerMetadata
|
908
|
+
};
|
909
|
+
} else {
|
910
|
+
const downloadedImage = downloadedImages[part.image];
|
911
|
+
return {
|
912
|
+
type: "image",
|
913
|
+
image: downloadedImage.data,
|
914
|
+
mimeType: (_b = part.mimeType) != null ? _b : downloadedImage.mimeType,
|
915
|
+
providerMetadata: part.experimental_providerMetadata
|
916
|
+
};
|
919
917
|
}
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
return {
|
928
|
-
type: "image",
|
929
|
-
image: convertDataContentToUint8Array(base64Content),
|
930
|
-
mimeType,
|
931
|
-
providerMetadata: part.experimental_providerMetadata
|
932
|
-
};
|
933
|
-
} catch (error) {
|
934
|
-
throw new Error(
|
935
|
-
`Error processing data URL: ${getErrorMessage2(
|
936
|
-
message
|
937
|
-
)}`
|
938
|
-
);
|
918
|
+
}
|
919
|
+
case "data:": {
|
920
|
+
try {
|
921
|
+
const [header, base64Content] = part.image.split(",");
|
922
|
+
const mimeType = header.split(";")[0].split(":")[1];
|
923
|
+
if (mimeType == null || base64Content == null) {
|
924
|
+
throw new Error("Invalid data URL format");
|
939
925
|
}
|
940
|
-
|
941
|
-
|
926
|
+
return {
|
927
|
+
type: "image",
|
928
|
+
image: convertDataContentToUint8Array(base64Content),
|
929
|
+
mimeType,
|
930
|
+
providerMetadata: part.experimental_providerMetadata
|
931
|
+
};
|
932
|
+
} catch (error) {
|
942
933
|
throw new Error(
|
943
|
-
`
|
934
|
+
`Error processing data URL: ${getErrorMessage2(
|
935
|
+
message
|
936
|
+
)}`
|
944
937
|
);
|
945
938
|
}
|
946
939
|
}
|
947
|
-
|
940
|
+
default: {
|
941
|
+
throw new Error(
|
942
|
+
`Unsupported URL protocol: ${url.protocol}`
|
943
|
+
);
|
944
|
+
}
|
948
945
|
}
|
946
|
+
} catch (_ignored) {
|
949
947
|
}
|
950
|
-
const imageUint8 = convertDataContentToUint8Array(part.image);
|
951
|
-
return {
|
952
|
-
type: "image",
|
953
|
-
image: imageUint8,
|
954
|
-
mimeType: (_c = part.mimeType) != null ? _c : detectImageMimeType(imageUint8),
|
955
|
-
providerMetadata: part.experimental_providerMetadata
|
956
|
-
};
|
957
948
|
}
|
949
|
+
const imageUint8 = convertDataContentToUint8Array(part.image);
|
950
|
+
return {
|
951
|
+
type: "image",
|
952
|
+
image: imageUint8,
|
953
|
+
mimeType: (_c = part.mimeType) != null ? _c : detectImageMimeType(imageUint8),
|
954
|
+
providerMetadata: part.experimental_providerMetadata
|
955
|
+
};
|
958
956
|
}
|
959
957
|
}
|
960
|
-
),
|
958
|
+
}).filter((part) => part.type !== "text" || part.text !== ""),
|
961
959
|
providerMetadata: message.experimental_providerMetadata
|
962
960
|
};
|
963
961
|
}
|