@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.js +57 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -5
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +56 -4
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +56 -4
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -950,9 +950,9 @@ var ReasoningFormat = /* @__PURE__ */ ((ReasoningFormat2) => {
|
|
|
950
950
|
// src/schemas/reasoning-details.ts
|
|
951
951
|
var CommonReasoningDetailSchema = import_v4.z.object({
|
|
952
952
|
id: import_v4.z.string().nullish(),
|
|
953
|
-
format: import_v4.z.
|
|
953
|
+
format: import_v4.z.enum(ReasoningFormat).nullish(),
|
|
954
954
|
index: import_v4.z.number().optional()
|
|
955
|
-
}).
|
|
955
|
+
}).loose();
|
|
956
956
|
var ReasoningDetailSummarySchema = import_v4.z.object({
|
|
957
957
|
type: import_v4.z.literal("reasoning.summary" /* Summary */),
|
|
958
958
|
summary: import_v4.z.string()
|
|
@@ -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
|
-
(
|
|
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,
|
|
@@ -1934,6 +1984,8 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1934
1984
|
const lastDetail = accumulatedReasoningDetails[accumulatedReasoningDetails.length - 1];
|
|
1935
1985
|
if ((lastDetail == null ? void 0 : lastDetail.type) === "reasoning.text" /* Text */) {
|
|
1936
1986
|
lastDetail.text = (lastDetail.text || "") + (detail.text || "");
|
|
1987
|
+
lastDetail.signature = lastDetail.signature || detail.signature;
|
|
1988
|
+
lastDetail.format = lastDetail.format || detail.format;
|
|
1937
1989
|
} else {
|
|
1938
1990
|
accumulatedReasoningDetails.push(__spreadValues({}, detail));
|
|
1939
1991
|
}
|
|
@@ -2628,7 +2680,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
2628
2680
|
}
|
|
2629
2681
|
|
|
2630
2682
|
// src/version.ts
|
|
2631
|
-
var VERSION = false ? "0.0.0-test" : "1.2.
|
|
2683
|
+
var VERSION = false ? "0.0.0-test" : "1.2.8";
|
|
2632
2684
|
|
|
2633
2685
|
// src/provider.ts
|
|
2634
2686
|
function createOpenRouter(options = {}) {
|