@openrouter/ai-sdk-provider 1.2.3 → 1.2.5
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.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +73 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -17
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +2 -1
- package/dist/internal/index.d.ts +2 -1
- package/dist/internal/index.js +72 -16
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +72 -16
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -7,7 +7,8 @@ declare enum ReasoningFormat {
|
|
|
7
7
|
Unknown = "unknown",
|
|
8
8
|
OpenAIResponsesV1 = "openai-responses-v1",
|
|
9
9
|
XAIResponsesV1 = "xai-responses-v1",
|
|
10
|
-
AnthropicClaudeV1 = "anthropic-claude-v1"
|
|
10
|
+
AnthropicClaudeV1 = "anthropic-claude-v1",
|
|
11
|
+
GoogleGeminiV1 = "google-gemini-v1"
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
declare enum ReasoningDetailType {
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ declare enum ReasoningFormat {
|
|
|
7
7
|
Unknown = "unknown",
|
|
8
8
|
OpenAIResponsesV1 = "openai-responses-v1",
|
|
9
9
|
XAIResponsesV1 = "xai-responses-v1",
|
|
10
|
-
AnthropicClaudeV1 = "anthropic-claude-v1"
|
|
10
|
+
AnthropicClaudeV1 = "anthropic-claude-v1",
|
|
11
|
+
GoogleGeminiV1 = "google-gemini-v1"
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
declare enum ReasoningDetailType {
|
package/dist/internal/index.js
CHANGED
|
@@ -897,6 +897,7 @@ var ReasoningFormat = /* @__PURE__ */ ((ReasoningFormat2) => {
|
|
|
897
897
|
ReasoningFormat2["OpenAIResponsesV1"] = "openai-responses-v1";
|
|
898
898
|
ReasoningFormat2["XAIResponsesV1"] = "xai-responses-v1";
|
|
899
899
|
ReasoningFormat2["AnthropicClaudeV1"] = "anthropic-claude-v1";
|
|
900
|
+
ReasoningFormat2["GoogleGeminiV1"] = "google-gemini-v1";
|
|
900
901
|
return ReasoningFormat2;
|
|
901
902
|
})(ReasoningFormat || {});
|
|
902
903
|
|
|
@@ -1059,8 +1060,9 @@ function getCacheControl(providerMetadata) {
|
|
|
1059
1060
|
return (_c = (_b = (_a15 = openrouter == null ? void 0 : openrouter.cacheControl) != null ? _a15 : openrouter == null ? void 0 : openrouter.cache_control) != null ? _b : anthropic == null ? void 0 : anthropic.cacheControl) != null ? _c : anthropic == null ? void 0 : anthropic.cache_control;
|
|
1060
1061
|
}
|
|
1061
1062
|
function convertToOpenRouterChatMessages(prompt) {
|
|
1062
|
-
var _a15, _b, _c, _d, _e;
|
|
1063
|
+
var _a15, _b, _c, _d, _e, _f;
|
|
1063
1064
|
const messages = [];
|
|
1065
|
+
const accumulatedReasoningDetails = [];
|
|
1064
1066
|
for (const { role, content, providerOptions } of prompt) {
|
|
1065
1067
|
switch (role) {
|
|
1066
1068
|
case "system": {
|
|
@@ -1090,7 +1092,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1090
1092
|
const messageCacheControl = getCacheControl(providerOptions);
|
|
1091
1093
|
const contentParts = content.map(
|
|
1092
1094
|
(part) => {
|
|
1093
|
-
var _a16, _b2, _c2, _d2, _e2,
|
|
1095
|
+
var _a16, _b2, _c2, _d2, _e2, _f2;
|
|
1094
1096
|
const cacheControl = (_a16 = getCacheControl(part.providerOptions)) != null ? _a16 : messageCacheControl;
|
|
1095
1097
|
switch (part.type) {
|
|
1096
1098
|
case "text":
|
|
@@ -1116,7 +1118,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1116
1118
|
};
|
|
1117
1119
|
}
|
|
1118
1120
|
const fileName = String(
|
|
1119
|
-
(
|
|
1121
|
+
(_f2 = (_e2 = (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d2.filename) != null ? _e2 : part.filename) != null ? _f2 : ""
|
|
1120
1122
|
);
|
|
1121
1123
|
const fileData = getFileUrl({
|
|
1122
1124
|
part,
|
|
@@ -1170,6 +1172,12 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1170
1172
|
break;
|
|
1171
1173
|
}
|
|
1172
1174
|
case "tool-call": {
|
|
1175
|
+
const partReasoningDetails = (_c = part.providerOptions) == null ? void 0 : _c.openrouter;
|
|
1176
|
+
if ((partReasoningDetails == null ? void 0 : partReasoningDetails.reasoning_details) && Array.isArray(partReasoningDetails.reasoning_details)) {
|
|
1177
|
+
accumulatedReasoningDetails.push(
|
|
1178
|
+
...partReasoningDetails.reasoning_details
|
|
1179
|
+
);
|
|
1180
|
+
}
|
|
1173
1181
|
toolCalls.push({
|
|
1174
1182
|
id: part.toolCallId,
|
|
1175
1183
|
type: "function",
|
|
@@ -1192,14 +1200,14 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1192
1200
|
}
|
|
1193
1201
|
}
|
|
1194
1202
|
const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
|
|
1195
|
-
const
|
|
1203
|
+
const messageReasoningDetails = parsedProviderOptions.success ? (_e = (_d = parsedProviderOptions.data) == null ? void 0 : _d.openrouter) == null ? void 0 : _e.reasoning_details : void 0;
|
|
1204
|
+
const finalReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : accumulatedReasoningDetails.length > 0 ? accumulatedReasoningDetails : void 0;
|
|
1196
1205
|
messages.push({
|
|
1197
1206
|
role: "assistant",
|
|
1198
1207
|
content: text,
|
|
1199
1208
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
1200
1209
|
reasoning: reasoning || void 0,
|
|
1201
|
-
|
|
1202
|
-
reasoning_details: preservedReasoningDetails && Array.isArray(preservedReasoningDetails) && preservedReasoningDetails.length > 0 ? preservedReasoningDetails : void 0,
|
|
1210
|
+
reasoning_details: finalReasoningDetails,
|
|
1203
1211
|
cache_control: getCacheControl(providerOptions)
|
|
1204
1212
|
});
|
|
1205
1213
|
break;
|
|
@@ -1211,7 +1219,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1211
1219
|
role: "tool",
|
|
1212
1220
|
tool_call_id: toolResponse.toolCallId,
|
|
1213
1221
|
content: content2,
|
|
1214
|
-
cache_control: (
|
|
1222
|
+
cache_control: (_f = getCacheControl(providerOptions)) != null ? _f : getCacheControl(toolResponse.providerOptions)
|
|
1215
1223
|
});
|
|
1216
1224
|
}
|
|
1217
1225
|
break;
|
|
@@ -1544,7 +1552,9 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1544
1552
|
});
|
|
1545
1553
|
}
|
|
1546
1554
|
if (tools && tools.length > 0) {
|
|
1547
|
-
const mappedTools = tools.filter(
|
|
1555
|
+
const mappedTools = tools.filter(
|
|
1556
|
+
(tool) => tool.type === "function"
|
|
1557
|
+
).map((tool) => ({
|
|
1548
1558
|
type: "function",
|
|
1549
1559
|
function: {
|
|
1550
1560
|
name: tool.name,
|
|
@@ -1619,7 +1629,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1619
1629
|
if (detail.text) {
|
|
1620
1630
|
return {
|
|
1621
1631
|
type: "reasoning",
|
|
1622
|
-
text: detail.text
|
|
1632
|
+
text: detail.text,
|
|
1633
|
+
providerMetadata: {
|
|
1634
|
+
openrouter: {
|
|
1635
|
+
reasoning_details: [detail]
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1623
1638
|
};
|
|
1624
1639
|
}
|
|
1625
1640
|
break;
|
|
@@ -1628,7 +1643,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1628
1643
|
if (detail.summary) {
|
|
1629
1644
|
return {
|
|
1630
1645
|
type: "reasoning",
|
|
1631
|
-
text: detail.summary
|
|
1646
|
+
text: detail.summary,
|
|
1647
|
+
providerMetadata: {
|
|
1648
|
+
openrouter: {
|
|
1649
|
+
reasoning_details: [detail]
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1632
1652
|
};
|
|
1633
1653
|
}
|
|
1634
1654
|
break;
|
|
@@ -1637,7 +1657,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1637
1657
|
if (detail.data) {
|
|
1638
1658
|
return {
|
|
1639
1659
|
type: "reasoning",
|
|
1640
|
-
text: "[REDACTED]"
|
|
1660
|
+
text: "[REDACTED]",
|
|
1661
|
+
providerMetadata: {
|
|
1662
|
+
openrouter: {
|
|
1663
|
+
reasoning_details: [detail]
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1641
1666
|
};
|
|
1642
1667
|
}
|
|
1643
1668
|
break;
|
|
@@ -1667,7 +1692,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1667
1692
|
type: "tool-call",
|
|
1668
1693
|
toolCallId: (_j = toolCall.id) != null ? _j : generateId(),
|
|
1669
1694
|
toolName: toolCall.function.name,
|
|
1670
|
-
input: toolCall.function.arguments
|
|
1695
|
+
input: toolCall.function.arguments,
|
|
1696
|
+
providerMetadata: {
|
|
1697
|
+
openrouter: {
|
|
1698
|
+
reasoning_details: reasoningDetails
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1671
1701
|
});
|
|
1672
1702
|
}
|
|
1673
1703
|
}
|
|
@@ -1853,7 +1883,18 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1853
1883
|
});
|
|
1854
1884
|
};
|
|
1855
1885
|
if (delta.reasoning_details && delta.reasoning_details.length > 0) {
|
|
1856
|
-
|
|
1886
|
+
for (const detail of delta.reasoning_details) {
|
|
1887
|
+
if (detail.type === "reasoning.text" /* Text */) {
|
|
1888
|
+
const lastDetail = accumulatedReasoningDetails[accumulatedReasoningDetails.length - 1];
|
|
1889
|
+
if ((lastDetail == null ? void 0 : lastDetail.type) === "reasoning.text" /* Text */) {
|
|
1890
|
+
lastDetail.text = (lastDetail.text || "") + (detail.text || "");
|
|
1891
|
+
} else {
|
|
1892
|
+
accumulatedReasoningDetails.push(__spreadValues({}, detail));
|
|
1893
|
+
}
|
|
1894
|
+
} else {
|
|
1895
|
+
accumulatedReasoningDetails.push(detail);
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1857
1898
|
for (const detail of delta.reasoning_details) {
|
|
1858
1899
|
switch (detail.type) {
|
|
1859
1900
|
case "reasoning.text" /* Text */: {
|
|
@@ -1982,7 +2023,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1982
2023
|
type: "tool-call",
|
|
1983
2024
|
toolCallId: toolCall2.id,
|
|
1984
2025
|
toolName: toolCall2.function.name,
|
|
1985
|
-
input: toolCall2.function.arguments
|
|
2026
|
+
input: toolCall2.function.arguments,
|
|
2027
|
+
providerMetadata: {
|
|
2028
|
+
openrouter: {
|
|
2029
|
+
reasoning_details: accumulatedReasoningDetails
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
1986
2032
|
});
|
|
1987
2033
|
toolCall2.sent = true;
|
|
1988
2034
|
}
|
|
@@ -2020,7 +2066,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
2020
2066
|
type: "tool-call",
|
|
2021
2067
|
toolCallId: (_n = toolCall.id) != null ? _n : generateId(),
|
|
2022
2068
|
toolName: toolCall.function.name,
|
|
2023
|
-
input: toolCall.function.arguments
|
|
2069
|
+
input: toolCall.function.arguments,
|
|
2070
|
+
providerMetadata: {
|
|
2071
|
+
openrouter: {
|
|
2072
|
+
reasoning_details: accumulatedReasoningDetails
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2024
2075
|
});
|
|
2025
2076
|
toolCall.sent = true;
|
|
2026
2077
|
}
|
|
@@ -2046,7 +2097,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
2046
2097
|
toolCallId: (_a16 = toolCall.id) != null ? _a16 : generateId(),
|
|
2047
2098
|
toolName: toolCall.function.name,
|
|
2048
2099
|
// Coerce invalid arguments to an empty JSON object
|
|
2049
|
-
input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}"
|
|
2100
|
+
input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}",
|
|
2101
|
+
providerMetadata: {
|
|
2102
|
+
openrouter: {
|
|
2103
|
+
reasoning_details: accumulatedReasoningDetails
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2050
2106
|
});
|
|
2051
2107
|
toolCall.sent = true;
|
|
2052
2108
|
}
|