@openrouter/ai-sdk-provider 1.4.0 → 1.5.0
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/README.md +58 -0
- package/dist/index.d.mts +208 -2
- package/dist/index.d.ts +208 -2
- package/dist/index.js +183 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +181 -30
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +185 -120
- package/dist/internal/index.d.ts +185 -120
- package/dist/internal/index.js +56 -25
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +56 -25
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +8 -1
package/dist/internal/index.js
CHANGED
|
@@ -1025,6 +1025,19 @@ function mapOpenRouterFinishReason(finishReason) {
|
|
|
1025
1025
|
}
|
|
1026
1026
|
}
|
|
1027
1027
|
|
|
1028
|
+
// src/types/openrouter-chat-completions-input.ts
|
|
1029
|
+
var OPENROUTER_AUDIO_FORMATS = [
|
|
1030
|
+
"wav",
|
|
1031
|
+
"mp3",
|
|
1032
|
+
"aiff",
|
|
1033
|
+
"aac",
|
|
1034
|
+
"ogg",
|
|
1035
|
+
"flac",
|
|
1036
|
+
"m4a",
|
|
1037
|
+
"pcm16",
|
|
1038
|
+
"pcm24"
|
|
1039
|
+
];
|
|
1040
|
+
|
|
1028
1041
|
// src/chat/is-url.ts
|
|
1029
1042
|
function isUrl({
|
|
1030
1043
|
url,
|
|
@@ -1066,6 +1079,34 @@ function getBase64FromDataUrl(dataUrl) {
|
|
|
1066
1079
|
const match = dataUrl.match(/^data:[^;]*;base64,(.+)$/);
|
|
1067
1080
|
return match ? match[1] : dataUrl;
|
|
1068
1081
|
}
|
|
1082
|
+
var MIME_TO_FORMAT = {
|
|
1083
|
+
// MP3 variants
|
|
1084
|
+
mpeg: "mp3",
|
|
1085
|
+
mp3: "mp3",
|
|
1086
|
+
// WAV variants
|
|
1087
|
+
"x-wav": "wav",
|
|
1088
|
+
wave: "wav",
|
|
1089
|
+
wav: "wav",
|
|
1090
|
+
// OGG variants
|
|
1091
|
+
ogg: "ogg",
|
|
1092
|
+
vorbis: "ogg",
|
|
1093
|
+
// AAC variants
|
|
1094
|
+
aac: "aac",
|
|
1095
|
+
"x-aac": "aac",
|
|
1096
|
+
// M4A variants
|
|
1097
|
+
m4a: "m4a",
|
|
1098
|
+
"x-m4a": "m4a",
|
|
1099
|
+
mp4: "m4a",
|
|
1100
|
+
// AIFF variants
|
|
1101
|
+
aiff: "aiff",
|
|
1102
|
+
"x-aiff": "aiff",
|
|
1103
|
+
// FLAC
|
|
1104
|
+
flac: "flac",
|
|
1105
|
+
"x-flac": "flac",
|
|
1106
|
+
// PCM variants
|
|
1107
|
+
pcm16: "pcm16",
|
|
1108
|
+
pcm24: "pcm24"
|
|
1109
|
+
};
|
|
1069
1110
|
function getInputAudioData(part) {
|
|
1070
1111
|
const fileData = getFileUrl({
|
|
1071
1112
|
part,
|
|
@@ -1090,19 +1131,14 @@ Learn more: https://openrouter.ai/docs/features/multimodal/audio`
|
|
|
1090
1131
|
}
|
|
1091
1132
|
const data = getBase64FromDataUrl(fileData);
|
|
1092
1133
|
const mediaType = part.mediaType || "audio/mpeg";
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
format = "wav";
|
|
1098
|
-
}
|
|
1099
|
-
if (format !== "mp3" && format !== "wav") {
|
|
1134
|
+
const rawFormat = mediaType.replace("audio/", "");
|
|
1135
|
+
const format = MIME_TO_FORMAT[rawFormat];
|
|
1136
|
+
if (format === void 0) {
|
|
1137
|
+
const supportedList = OPENROUTER_AUDIO_FORMATS.join(", ");
|
|
1100
1138
|
throw new Error(
|
|
1101
1139
|
`Unsupported audio format: "${mediaType}"
|
|
1102
1140
|
|
|
1103
|
-
OpenRouter
|
|
1104
|
-
\u2022 For MP3: use "audio/mpeg" or "audio/mp3"
|
|
1105
|
-
\u2022 For WAV: use "audio/wav" or "audio/x-wav"
|
|
1141
|
+
OpenRouter supports the following audio formats: ${supportedList}
|
|
1106
1142
|
|
|
1107
1143
|
Learn more: https://openrouter.ai/docs/features/multimodal/audio`
|
|
1108
1144
|
);
|
|
@@ -1597,7 +1633,16 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1597
1633
|
presence_penalty: presencePenalty,
|
|
1598
1634
|
seed,
|
|
1599
1635
|
stop: stopSequences,
|
|
1600
|
-
response_format: responseFormat
|
|
1636
|
+
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
|
|
1637
|
+
type: "json_schema",
|
|
1638
|
+
json_schema: __spreadValues({
|
|
1639
|
+
schema: responseFormat.schema,
|
|
1640
|
+
strict: true,
|
|
1641
|
+
name: (_a15 = responseFormat.name) != null ? _a15 : "response"
|
|
1642
|
+
}, responseFormat.description && {
|
|
1643
|
+
description: responseFormat.description
|
|
1644
|
+
})
|
|
1645
|
+
} : { type: "json_object" } : void 0,
|
|
1601
1646
|
top_k: topK,
|
|
1602
1647
|
// messages:
|
|
1603
1648
|
messages: convertToOpenRouterChatMessages(prompt),
|
|
@@ -1613,20 +1658,6 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1613
1658
|
// Debug settings:
|
|
1614
1659
|
debug: this.settings.debug
|
|
1615
1660
|
}, this.config.extraBody), this.settings.extraBody);
|
|
1616
|
-
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
|
|
1617
|
-
return __spreadProps(__spreadValues({}, baseArgs), {
|
|
1618
|
-
response_format: {
|
|
1619
|
-
type: "json_schema",
|
|
1620
|
-
json_schema: __spreadValues({
|
|
1621
|
-
schema: responseFormat.schema,
|
|
1622
|
-
strict: true,
|
|
1623
|
-
name: (_a15 = responseFormat.name) != null ? _a15 : "response"
|
|
1624
|
-
}, responseFormat.description && {
|
|
1625
|
-
description: responseFormat.description
|
|
1626
|
-
})
|
|
1627
|
-
}
|
|
1628
|
-
});
|
|
1629
|
-
}
|
|
1630
1661
|
if (tools && tools.length > 0) {
|
|
1631
1662
|
const mappedTools = tools.filter(
|
|
1632
1663
|
(tool) => tool.type === "function"
|