@openrouter/ai-sdk-provider 1.2.5 → 1.2.7

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.
@@ -1017,6 +1017,49 @@ function getBase64FromDataUrl(dataUrl) {
1017
1017
  const match = dataUrl.match(/^data:[^;]*;base64,(.+)$/);
1018
1018
  return match ? match[1] : dataUrl;
1019
1019
  }
1020
+ function getInputAudioData(part) {
1021
+ const fileData = getFileUrl({
1022
+ part,
1023
+ defaultMediaType: "audio/mpeg"
1024
+ });
1025
+ if (isUrl({
1026
+ url: fileData,
1027
+ protocols: /* @__PURE__ */ new Set(["http:", "https:"])
1028
+ })) {
1029
+ throw new Error(
1030
+ `Audio files cannot be provided as URLs.
1031
+
1032
+ OpenRouter requires audio to be base64-encoded. Please:
1033
+ 1. Download the audio file locally
1034
+ 2. Read it as a Buffer or Uint8Array
1035
+ 3. Pass it as the data parameter
1036
+
1037
+ The AI SDK will automatically handle base64 encoding.
1038
+
1039
+ Learn more: https://openrouter.ai/docs/features/multimodal/audio`
1040
+ );
1041
+ }
1042
+ const data = getBase64FromDataUrl(fileData);
1043
+ const mediaType = part.mediaType || "audio/mpeg";
1044
+ let format = mediaType.replace("audio/", "");
1045
+ if (format === "mpeg" || format === "mp3") {
1046
+ format = "mp3";
1047
+ } else if (format === "x-wav" || format === "wave" || format === "wav") {
1048
+ format = "wav";
1049
+ }
1050
+ if (format !== "mp3" && format !== "wav") {
1051
+ throw new Error(
1052
+ `Unsupported audio format: "${mediaType}"
1053
+
1054
+ OpenRouter only supports MP3 and WAV audio formats.
1055
+ \u2022 For MP3: use "audio/mpeg" or "audio/mp3"
1056
+ \u2022 For WAV: use "audio/wav" or "audio/x-wav"
1057
+
1058
+ Learn more: https://openrouter.ai/docs/features/multimodal/audio`
1059
+ );
1060
+ }
1061
+ return { data, format };
1062
+ }
1020
1063
 
1021
1064
  // src/chat/convert-to-openrouter-chat-messages.ts
1022
1065
  function getCacheControl(providerMetadata) {
@@ -1058,7 +1101,7 @@ function convertToOpenRouterChatMessages(prompt) {
1058
1101
  const messageCacheControl = getCacheControl(providerOptions);
1059
1102
  const contentParts = content.map(
1060
1103
  (part) => {
1061
- var _a16, _b2, _c2, _d2, _e2, _f2;
1104
+ var _a16, _b2, _c2, _d2, _e2, _f2, _g;
1062
1105
  const cacheControl = (_a16 = getCacheControl(part.providerOptions)) != null ? _a16 : messageCacheControl;
1063
1106
  switch (part.type) {
1064
1107
  case "text":
@@ -1083,8 +1126,15 @@ function convertToOpenRouterChatMessages(prompt) {
1083
1126
  cache_control: cacheControl
1084
1127
  };
1085
1128
  }
1129
+ if ((_c2 = part.mediaType) == null ? void 0 : _c2.startsWith("audio/")) {
1130
+ return {
1131
+ type: "input_audio",
1132
+ input_audio: getInputAudioData(part),
1133
+ cache_control: cacheControl
1134
+ };
1135
+ }
1086
1136
  const fileName = String(
1087
- (_f2 = (_e2 = (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d2.filename) != null ? _e2 : part.filename) != null ? _f2 : ""
1137
+ (_g = (_f2 = (_e2 = (_d2 = part.providerOptions) == null ? void 0 : _d2.openrouter) == null ? void 0 : _e2.filename) != null ? _f2 : part.filename) != null ? _g : ""
1088
1138
  );
1089
1139
  const fileData = getFileUrl({
1090
1140
  part,
@@ -1325,7 +1375,7 @@ var OpenRouterNonStreamChatCompletionResponseSchema = z7.union([
1325
1375
  content: z7.array(
1326
1376
  z7.object({
1327
1377
  type: z7.string(),
1328
- text: z7.string()
1378
+ text: z7.string().optional()
1329
1379
  }).passthrough()
1330
1380
  ).optional()
1331
1381
  }).passthrough()
@@ -1408,7 +1458,7 @@ var OpenRouterStreamChatCompletionChunkSchema = z7.union([
1408
1458
  content: z7.array(
1409
1459
  z7.object({
1410
1460
  type: z7.string(),
1411
- text: z7.string()
1461
+ text: z7.string().optional()
1412
1462
  }).passthrough()
1413
1463
  ).optional()
1414
1464
  }).passthrough()