@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 +55 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -5
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +54 -4
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +54 -4
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -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
|
-
(
|
|
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,
|
|
@@ -1370,7 +1420,7 @@ var OpenRouterNonStreamChatCompletionResponseSchema = z7.union([
|
|
|
1370
1420
|
content: z7.array(
|
|
1371
1421
|
z7.object({
|
|
1372
1422
|
type: z7.string(),
|
|
1373
|
-
text: z7.string()
|
|
1423
|
+
text: z7.string().optional()
|
|
1374
1424
|
}).passthrough()
|
|
1375
1425
|
).optional()
|
|
1376
1426
|
}).passthrough()
|
|
@@ -1453,7 +1503,7 @@ var OpenRouterStreamChatCompletionChunkSchema = z7.union([
|
|
|
1453
1503
|
content: z7.array(
|
|
1454
1504
|
z7.object({
|
|
1455
1505
|
type: z7.string(),
|
|
1456
|
-
text: z7.string()
|
|
1506
|
+
text: z7.string().optional()
|
|
1457
1507
|
}).passthrough()
|
|
1458
1508
|
).optional()
|
|
1459
1509
|
}).passthrough()
|
|
@@ -2593,7 +2643,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
2593
2643
|
}
|
|
2594
2644
|
|
|
2595
2645
|
// src/version.ts
|
|
2596
|
-
var VERSION = false ? "0.0.0-test" : "1.2.
|
|
2646
|
+
var VERSION = false ? "0.0.0-test" : "1.2.7";
|
|
2597
2647
|
|
|
2598
2648
|
// src/provider.ts
|
|
2599
2649
|
function createOpenRouter(options = {}) {
|