@openrouter/ai-sdk-provider 1.4.0 → 1.5.0

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
  );
@@ -1563,7 +1599,16 @@ var OpenRouterChatLanguageModel = class {
1563
1599
  presence_penalty: presencePenalty,
1564
1600
  seed,
1565
1601
  stop: stopSequences,
1566
- response_format: responseFormat,
1602
+ response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
1603
+ type: "json_schema",
1604
+ json_schema: __spreadValues({
1605
+ schema: responseFormat.schema,
1606
+ strict: true,
1607
+ name: (_a15 = responseFormat.name) != null ? _a15 : "response"
1608
+ }, responseFormat.description && {
1609
+ description: responseFormat.description
1610
+ })
1611
+ } : { type: "json_object" } : void 0,
1567
1612
  top_k: topK,
1568
1613
  // messages:
1569
1614
  messages: convertToOpenRouterChatMessages(prompt),
@@ -1579,20 +1624,6 @@ var OpenRouterChatLanguageModel = class {
1579
1624
  // Debug settings:
1580
1625
  debug: this.settings.debug
1581
1626
  }, this.config.extraBody), this.settings.extraBody);
1582
- if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
1583
- return __spreadProps(__spreadValues({}, baseArgs), {
1584
- response_format: {
1585
- type: "json_schema",
1586
- json_schema: __spreadValues({
1587
- schema: responseFormat.schema,
1588
- strict: true,
1589
- name: (_a15 = responseFormat.name) != null ? _a15 : "response"
1590
- }, responseFormat.description && {
1591
- description: responseFormat.description
1592
- })
1593
- }
1594
- });
1595
- }
1596
1627
  if (tools && tools.length > 0) {
1597
1628
  const mappedTools = tools.filter(
1598
1629
  (tool) => tool.type === "function"