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/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
- (part) => {
869
- var _a11, _b, _c;
870
- switch (part.type) {
871
- case "text": {
872
- return {
873
- type: "text",
874
- text: part.text,
875
- providerMetadata: part.experimental_providerMetadata
876
- };
877
- }
878
- case "image": {
879
- if (part.image instanceof URL) {
880
- if (downloadedImages == null) {
881
- return {
882
- type: "image",
883
- image: part.image,
884
- mimeType: part.mimeType,
885
- providerMetadata: part.experimental_providerMetadata
886
- };
887
- } else {
888
- const downloadedImage = downloadedImages[part.image.toString()];
889
- return {
890
- type: "image",
891
- image: downloadedImage.data,
892
- mimeType: (_a11 = part.mimeType) != null ? _a11 : downloadedImage.mimeType,
893
- providerMetadata: part.experimental_providerMetadata
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
- if (typeof part.image === "string") {
898
- try {
899
- const url = new URL(part.image);
900
- switch (url.protocol) {
901
- case "http:":
902
- case "https:": {
903
- if (downloadedImages == null) {
904
- return {
905
- type: "image",
906
- image: url,
907
- mimeType: part.mimeType,
908
- providerMetadata: part.experimental_providerMetadata
909
- };
910
- } else {
911
- const downloadedImage = downloadedImages[part.image];
912
- return {
913
- type: "image",
914
- image: downloadedImage.data,
915
- mimeType: (_b = part.mimeType) != null ? _b : downloadedImage.mimeType,
916
- providerMetadata: part.experimental_providerMetadata
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
- case "data:": {
921
- try {
922
- const [header, base64Content] = part.image.split(",");
923
- const mimeType = header.split(";")[0].split(":")[1];
924
- if (mimeType == null || base64Content == null) {
925
- throw new Error("Invalid data URL format");
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
- default: {
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
- `Unsupported URL protocol: ${url.protocol}`
934
+ `Error processing data URL: ${getErrorMessage2(
935
+ message
936
+ )}`
944
937
  );
945
938
  }
946
939
  }
947
- } catch (_ignored) {
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
  }