@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.
package/dist/index.mjs CHANGED
@@ -915,9 +915,9 @@ var ReasoningFormat = /* @__PURE__ */ ((ReasoningFormat2) => {
915
915
  // src/schemas/reasoning-details.ts
916
916
  var CommonReasoningDetailSchema = z.object({
917
917
  id: z.string().nullish(),
918
- format: z.nativeEnum(ReasoningFormat).nullish(),
918
+ format: z.enum(ReasoningFormat).nullish(),
919
919
  index: z.number().optional()
920
- }).passthrough();
920
+ }).loose();
921
921
  var ReasoningDetailSummarySchema = z.object({
922
922
  type: z.literal("reasoning.summary" /* Summary */),
923
923
  summary: z.string()
@@ -1062,6 +1062,49 @@ function getBase64FromDataUrl(dataUrl) {
1062
1062
  const match = dataUrl.match(/^data:[^;]*;base64,(.+)$/);
1063
1063
  return match ? match[1] : dataUrl;
1064
1064
  }
1065
+ function getInputAudioData(part) {
1066
+ const fileData = getFileUrl({
1067
+ part,
1068
+ defaultMediaType: "audio/mpeg"
1069
+ });
1070
+ if (isUrl({
1071
+ url: fileData,
1072
+ protocols: /* @__PURE__ */ new Set(["http:", "https:"])
1073
+ })) {
1074
+ throw new Error(
1075
+ `Audio files cannot be provided as URLs.
1076
+
1077
+ OpenRouter requires audio to be base64-encoded. Please:
1078
+ 1. Download the audio file locally
1079
+ 2. Read it as a Buffer or Uint8Array
1080
+ 3. Pass it as the data parameter
1081
+
1082
+ The AI SDK will automatically handle base64 encoding.
1083
+
1084
+ Learn more: https://openrouter.ai/docs/features/multimodal/audio`
1085
+ );
1086
+ }
1087
+ const data = getBase64FromDataUrl(fileData);
1088
+ const mediaType = part.mediaType || "audio/mpeg";
1089
+ let format = mediaType.replace("audio/", "");
1090
+ if (format === "mpeg" || format === "mp3") {
1091
+ format = "mp3";
1092
+ } else if (format === "x-wav" || format === "wave" || format === "wav") {
1093
+ format = "wav";
1094
+ }
1095
+ if (format !== "mp3" && format !== "wav") {
1096
+ throw new Error(
1097
+ `Unsupported audio format: "${mediaType}"
1098
+
1099
+ OpenRouter only supports MP3 and WAV audio formats.
1100
+ \u2022 For MP3: use "audio/mpeg" or "audio/mp3"
1101
+ \u2022 For WAV: use "audio/wav" or "audio/x-wav"
1102
+
1103
+ Learn more: https://openrouter.ai/docs/features/multimodal/audio`
1104
+ );
1105
+ }
1106
+ return { data, format };
1107
+ }
1065
1108
 
1066
1109
  // src/chat/convert-to-openrouter-chat-messages.ts
1067
1110
  function getCacheControl(providerMetadata) {
@@ -1103,7 +1146,7 @@ function convertToOpenRouterChatMessages(prompt) {
1103
1146
  const messageCacheControl = getCacheControl(providerOptions);
1104
1147
  const contentParts = content.map(
1105
1148
  (part) => {
1106
- var _a16, _b2, _c2, _d2, _e2, _f2;
1149
+ var _a16, _b2, _c2, _d2, _e2, _f2, _g;
1107
1150
  const cacheControl = (_a16 = getCacheControl(part.providerOptions)) != null ? _a16 : messageCacheControl;
1108
1151
  switch (part.type) {
1109
1152
  case "text":
@@ -1128,8 +1171,15 @@ function convertToOpenRouterChatMessages(prompt) {
1128
1171
  cache_control: cacheControl
1129
1172
  };
1130
1173
  }
1174
+ if ((_c2 = part.mediaType) == null ? void 0 : _c2.startsWith("audio/")) {
1175
+ return {
1176
+ type: "input_audio",
1177
+ input_audio: getInputAudioData(part),
1178
+ cache_control: cacheControl
1179
+ };
1180
+ }
1131
1181
  const fileName = String(
1132
- (_f2 = (_e2 = (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d2.filename) != null ? _e2 : part.filename) != null ? _f2 : ""
1182
+ (_g = (_f2 = (_e2 = (_d2 = part.providerOptions) == null ? void 0 : _d2.openrouter) == null ? void 0 : _e2.filename) != null ? _f2 : part.filename) != null ? _g : ""
1133
1183
  );
1134
1184
  const fileData = getFileUrl({
1135
1185
  part,
@@ -1899,6 +1949,8 @@ var OpenRouterChatLanguageModel = class {
1899
1949
  const lastDetail = accumulatedReasoningDetails[accumulatedReasoningDetails.length - 1];
1900
1950
  if ((lastDetail == null ? void 0 : lastDetail.type) === "reasoning.text" /* Text */) {
1901
1951
  lastDetail.text = (lastDetail.text || "") + (detail.text || "");
1952
+ lastDetail.signature = lastDetail.signature || detail.signature;
1953
+ lastDetail.format = lastDetail.format || detail.format;
1902
1954
  } else {
1903
1955
  accumulatedReasoningDetails.push(__spreadValues({}, detail));
1904
1956
  }
@@ -2593,7 +2645,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
2593
2645
  }
2594
2646
 
2595
2647
  // src/version.ts
2596
- var VERSION = false ? "0.0.0-test" : "1.2.6";
2648
+ var VERSION = false ? "0.0.0-test" : "1.2.8";
2597
2649
 
2598
2650
  // src/provider.ts
2599
2651
  function createOpenRouter(options = {}) {