@openrouter/ai-sdk-provider 1.2.6 → 1.2.8

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.
@@ -904,9 +904,9 @@ var ReasoningFormat = /* @__PURE__ */ ((ReasoningFormat2) => {
904
904
  // src/schemas/reasoning-details.ts
905
905
  var CommonReasoningDetailSchema = import_v4.z.object({
906
906
  id: import_v4.z.string().nullish(),
907
- format: import_v4.z.nativeEnum(ReasoningFormat).nullish(),
907
+ format: import_v4.z.enum(ReasoningFormat).nullish(),
908
908
  index: import_v4.z.number().optional()
909
- }).passthrough();
909
+ }).loose();
910
910
  var ReasoningDetailSummarySchema = import_v4.z.object({
911
911
  type: import_v4.z.literal("reasoning.summary" /* Summary */),
912
912
  summary: import_v4.z.string()
@@ -1051,6 +1051,49 @@ function getBase64FromDataUrl(dataUrl) {
1051
1051
  const match = dataUrl.match(/^data:[^;]*;base64,(.+)$/);
1052
1052
  return match ? match[1] : dataUrl;
1053
1053
  }
1054
+ function getInputAudioData(part) {
1055
+ const fileData = getFileUrl({
1056
+ part,
1057
+ defaultMediaType: "audio/mpeg"
1058
+ });
1059
+ if (isUrl({
1060
+ url: fileData,
1061
+ protocols: /* @__PURE__ */ new Set(["http:", "https:"])
1062
+ })) {
1063
+ throw new Error(
1064
+ `Audio files cannot be provided as URLs.
1065
+
1066
+ OpenRouter requires audio to be base64-encoded. Please:
1067
+ 1. Download the audio file locally
1068
+ 2. Read it as a Buffer or Uint8Array
1069
+ 3. Pass it as the data parameter
1070
+
1071
+ The AI SDK will automatically handle base64 encoding.
1072
+
1073
+ Learn more: https://openrouter.ai/docs/features/multimodal/audio`
1074
+ );
1075
+ }
1076
+ const data = getBase64FromDataUrl(fileData);
1077
+ const mediaType = part.mediaType || "audio/mpeg";
1078
+ let format = mediaType.replace("audio/", "");
1079
+ if (format === "mpeg" || format === "mp3") {
1080
+ format = "mp3";
1081
+ } else if (format === "x-wav" || format === "wave" || format === "wav") {
1082
+ format = "wav";
1083
+ }
1084
+ if (format !== "mp3" && format !== "wav") {
1085
+ throw new Error(
1086
+ `Unsupported audio format: "${mediaType}"
1087
+
1088
+ OpenRouter only supports MP3 and WAV audio formats.
1089
+ \u2022 For MP3: use "audio/mpeg" or "audio/mp3"
1090
+ \u2022 For WAV: use "audio/wav" or "audio/x-wav"
1091
+
1092
+ Learn more: https://openrouter.ai/docs/features/multimodal/audio`
1093
+ );
1094
+ }
1095
+ return { data, format };
1096
+ }
1054
1097
 
1055
1098
  // src/chat/convert-to-openrouter-chat-messages.ts
1056
1099
  function getCacheControl(providerMetadata) {
@@ -1092,7 +1135,7 @@ function convertToOpenRouterChatMessages(prompt) {
1092
1135
  const messageCacheControl = getCacheControl(providerOptions);
1093
1136
  const contentParts = content.map(
1094
1137
  (part) => {
1095
- var _a16, _b2, _c2, _d2, _e2, _f2;
1138
+ var _a16, _b2, _c2, _d2, _e2, _f2, _g;
1096
1139
  const cacheControl = (_a16 = getCacheControl(part.providerOptions)) != null ? _a16 : messageCacheControl;
1097
1140
  switch (part.type) {
1098
1141
  case "text":
@@ -1117,8 +1160,15 @@ function convertToOpenRouterChatMessages(prompt) {
1117
1160
  cache_control: cacheControl
1118
1161
  };
1119
1162
  }
1163
+ if ((_c2 = part.mediaType) == null ? void 0 : _c2.startsWith("audio/")) {
1164
+ return {
1165
+ type: "input_audio",
1166
+ input_audio: getInputAudioData(part),
1167
+ cache_control: cacheControl
1168
+ };
1169
+ }
1120
1170
  const fileName = String(
1121
- (_f2 = (_e2 = (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d2.filename) != null ? _e2 : part.filename) != null ? _f2 : ""
1171
+ (_g = (_f2 = (_e2 = (_d2 = part.providerOptions) == null ? void 0 : _d2.openrouter) == null ? void 0 : _e2.filename) != null ? _f2 : part.filename) != null ? _g : ""
1122
1172
  );
1123
1173
  const fileData = getFileUrl({
1124
1174
  part,
@@ -1888,6 +1938,8 @@ var OpenRouterChatLanguageModel = class {
1888
1938
  const lastDetail = accumulatedReasoningDetails[accumulatedReasoningDetails.length - 1];
1889
1939
  if ((lastDetail == null ? void 0 : lastDetail.type) === "reasoning.text" /* Text */) {
1890
1940
  lastDetail.text = (lastDetail.text || "") + (detail.text || "");
1941
+ lastDetail.signature = lastDetail.signature || detail.signature;
1942
+ lastDetail.format = lastDetail.format || detail.format;
1891
1943
  } else {
1892
1944
  accumulatedReasoningDetails.push(__spreadValues({}, detail));
1893
1945
  }