@openrouter/ai-sdk-provider 1.4.1 → 1.5.1

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.
@@ -991,6 +991,19 @@ function mapOpenRouterFinishReason(finishReason) {
991
991
  }
992
992
  }
993
993
 
994
+ // src/types/openrouter-chat-completions-input.ts
995
+ var OPENROUTER_AUDIO_FORMATS = [
996
+ "wav",
997
+ "mp3",
998
+ "aiff",
999
+ "aac",
1000
+ "ogg",
1001
+ "flac",
1002
+ "m4a",
1003
+ "pcm16",
1004
+ "pcm24"
1005
+ ];
1006
+
994
1007
  // src/chat/is-url.ts
995
1008
  function isUrl({
996
1009
  url,
@@ -1032,6 +1045,34 @@ function getBase64FromDataUrl(dataUrl) {
1032
1045
  const match = dataUrl.match(/^data:[^;]*;base64,(.+)$/);
1033
1046
  return match ? match[1] : dataUrl;
1034
1047
  }
1048
+ var MIME_TO_FORMAT = {
1049
+ // MP3 variants
1050
+ mpeg: "mp3",
1051
+ mp3: "mp3",
1052
+ // WAV variants
1053
+ "x-wav": "wav",
1054
+ wave: "wav",
1055
+ wav: "wav",
1056
+ // OGG variants
1057
+ ogg: "ogg",
1058
+ vorbis: "ogg",
1059
+ // AAC variants
1060
+ aac: "aac",
1061
+ "x-aac": "aac",
1062
+ // M4A variants
1063
+ m4a: "m4a",
1064
+ "x-m4a": "m4a",
1065
+ mp4: "m4a",
1066
+ // AIFF variants
1067
+ aiff: "aiff",
1068
+ "x-aiff": "aiff",
1069
+ // FLAC
1070
+ flac: "flac",
1071
+ "x-flac": "flac",
1072
+ // PCM variants
1073
+ pcm16: "pcm16",
1074
+ pcm24: "pcm24"
1075
+ };
1035
1076
  function getInputAudioData(part) {
1036
1077
  const fileData = getFileUrl({
1037
1078
  part,
@@ -1056,19 +1097,14 @@ Learn more: https://openrouter.ai/docs/features/multimodal/audio`
1056
1097
  }
1057
1098
  const data = getBase64FromDataUrl(fileData);
1058
1099
  const mediaType = part.mediaType || "audio/mpeg";
1059
- let format = mediaType.replace("audio/", "");
1060
- if (format === "mpeg" || format === "mp3") {
1061
- format = "mp3";
1062
- } else if (format === "x-wav" || format === "wave" || format === "wav") {
1063
- format = "wav";
1064
- }
1065
- if (format !== "mp3" && format !== "wav") {
1100
+ const rawFormat = mediaType.replace("audio/", "");
1101
+ const format = MIME_TO_FORMAT[rawFormat];
1102
+ if (format === void 0) {
1103
+ const supportedList = OPENROUTER_AUDIO_FORMATS.join(", ");
1066
1104
  throw new Error(
1067
1105
  `Unsupported audio format: "${mediaType}"
1068
1106
 
1069
- OpenRouter only supports MP3 and WAV audio formats.
1070
- \u2022 For MP3: use "audio/mpeg" or "audio/mp3"
1071
- \u2022 For WAV: use "audio/wav" or "audio/x-wav"
1107
+ OpenRouter supports the following audio formats: ${supportedList}
1072
1108
 
1073
1109
  Learn more: https://openrouter.ai/docs/features/multimodal/audio`
1074
1110
  );