@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.
@@ -870,9 +870,9 @@ var ReasoningFormat = /* @__PURE__ */ ((ReasoningFormat2) => {
870
870
  // src/schemas/reasoning-details.ts
871
871
  var CommonReasoningDetailSchema = z.object({
872
872
  id: z.string().nullish(),
873
- format: z.nativeEnum(ReasoningFormat).nullish(),
873
+ format: z.enum(ReasoningFormat).nullish(),
874
874
  index: z.number().optional()
875
- }).passthrough();
875
+ }).loose();
876
876
  var ReasoningDetailSummarySchema = z.object({
877
877
  type: z.literal("reasoning.summary" /* Summary */),
878
878
  summary: z.string()
@@ -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,
@@ -1854,6 +1904,8 @@ var OpenRouterChatLanguageModel = class {
1854
1904
  const lastDetail = accumulatedReasoningDetails[accumulatedReasoningDetails.length - 1];
1855
1905
  if ((lastDetail == null ? void 0 : lastDetail.type) === "reasoning.text" /* Text */) {
1856
1906
  lastDetail.text = (lastDetail.text || "") + (detail.text || "");
1907
+ lastDetail.signature = lastDetail.signature || detail.signature;
1908
+ lastDetail.format = lastDetail.format || detail.format;
1857
1909
  } else {
1858
1910
  accumulatedReasoningDetails.push(__spreadValues({}, detail));
1859
1911
  }