@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.
package/dist/index.js CHANGED
@@ -1097,6 +1097,49 @@ function getBase64FromDataUrl(dataUrl) {
1097
1097
  const match = dataUrl.match(/^data:[^;]*;base64,(.+)$/);
1098
1098
  return match ? match[1] : dataUrl;
1099
1099
  }
1100
+ function getInputAudioData(part) {
1101
+ const fileData = getFileUrl({
1102
+ part,
1103
+ defaultMediaType: "audio/mpeg"
1104
+ });
1105
+ if (isUrl({
1106
+ url: fileData,
1107
+ protocols: /* @__PURE__ */ new Set(["http:", "https:"])
1108
+ })) {
1109
+ throw new Error(
1110
+ `Audio files cannot be provided as URLs.
1111
+
1112
+ OpenRouter requires audio to be base64-encoded. Please:
1113
+ 1. Download the audio file locally
1114
+ 2. Read it as a Buffer or Uint8Array
1115
+ 3. Pass it as the data parameter
1116
+
1117
+ The AI SDK will automatically handle base64 encoding.
1118
+
1119
+ Learn more: https://openrouter.ai/docs/features/multimodal/audio`
1120
+ );
1121
+ }
1122
+ const data = getBase64FromDataUrl(fileData);
1123
+ const mediaType = part.mediaType || "audio/mpeg";
1124
+ let format = mediaType.replace("audio/", "");
1125
+ if (format === "mpeg" || format === "mp3") {
1126
+ format = "mp3";
1127
+ } else if (format === "x-wav" || format === "wave" || format === "wav") {
1128
+ format = "wav";
1129
+ }
1130
+ if (format !== "mp3" && format !== "wav") {
1131
+ throw new Error(
1132
+ `Unsupported audio format: "${mediaType}"
1133
+
1134
+ OpenRouter only supports MP3 and WAV audio formats.
1135
+ \u2022 For MP3: use "audio/mpeg" or "audio/mp3"
1136
+ \u2022 For WAV: use "audio/wav" or "audio/x-wav"
1137
+
1138
+ Learn more: https://openrouter.ai/docs/features/multimodal/audio`
1139
+ );
1140
+ }
1141
+ return { data, format };
1142
+ }
1100
1143
 
1101
1144
  // src/chat/convert-to-openrouter-chat-messages.ts
1102
1145
  function getCacheControl(providerMetadata) {
@@ -1138,7 +1181,7 @@ function convertToOpenRouterChatMessages(prompt) {
1138
1181
  const messageCacheControl = getCacheControl(providerOptions);
1139
1182
  const contentParts = content.map(
1140
1183
  (part) => {
1141
- var _a16, _b2, _c2, _d2, _e2, _f2;
1184
+ var _a16, _b2, _c2, _d2, _e2, _f2, _g;
1142
1185
  const cacheControl = (_a16 = getCacheControl(part.providerOptions)) != null ? _a16 : messageCacheControl;
1143
1186
  switch (part.type) {
1144
1187
  case "text":
@@ -1163,8 +1206,15 @@ function convertToOpenRouterChatMessages(prompt) {
1163
1206
  cache_control: cacheControl
1164
1207
  };
1165
1208
  }
1209
+ if ((_c2 = part.mediaType) == null ? void 0 : _c2.startsWith("audio/")) {
1210
+ return {
1211
+ type: "input_audio",
1212
+ input_audio: getInputAudioData(part),
1213
+ cache_control: cacheControl
1214
+ };
1215
+ }
1166
1216
  const fileName = String(
1167
- (_f2 = (_e2 = (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d2.filename) != null ? _e2 : part.filename) != null ? _f2 : ""
1217
+ (_g = (_f2 = (_e2 = (_d2 = part.providerOptions) == null ? void 0 : _d2.openrouter) == null ? void 0 : _e2.filename) != null ? _f2 : part.filename) != null ? _g : ""
1168
1218
  );
1169
1219
  const fileData = getFileUrl({
1170
1220
  part,
@@ -1405,7 +1455,7 @@ var OpenRouterNonStreamChatCompletionResponseSchema = import_v46.z.union([
1405
1455
  content: import_v46.z.array(
1406
1456
  import_v46.z.object({
1407
1457
  type: import_v46.z.string(),
1408
- text: import_v46.z.string()
1458
+ text: import_v46.z.string().optional()
1409
1459
  }).passthrough()
1410
1460
  ).optional()
1411
1461
  }).passthrough()
@@ -1488,7 +1538,7 @@ var OpenRouterStreamChatCompletionChunkSchema = import_v46.z.union([
1488
1538
  content: import_v46.z.array(
1489
1539
  import_v46.z.object({
1490
1540
  type: import_v46.z.string(),
1491
- text: import_v46.z.string()
1541
+ text: import_v46.z.string().optional()
1492
1542
  }).passthrough()
1493
1543
  ).optional()
1494
1544
  }).passthrough()
@@ -2628,7 +2678,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
2628
2678
  }
2629
2679
 
2630
2680
  // src/version.ts
2631
- var VERSION = false ? "0.0.0-test" : "1.2.5";
2681
+ var VERSION = false ? "0.0.0-test" : "1.2.7";
2632
2682
 
2633
2683
  // src/provider.ts
2634
2684
  function createOpenRouter(options = {}) {