@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
package/dist/index.d.mts
CHANGED
|
@@ -217,7 +217,8 @@ declare enum ReasoningFormat {
|
|
|
217
217
|
Unknown = "unknown",
|
|
218
218
|
OpenAIResponsesV1 = "openai-responses-v1",
|
|
219
219
|
XAIResponsesV1 = "xai-responses-v1",
|
|
220
|
-
AnthropicClaudeV1 = "anthropic-claude-v1"
|
|
220
|
+
AnthropicClaudeV1 = "anthropic-claude-v1",
|
|
221
|
+
GoogleGeminiV1 = "google-gemini-v1"
|
|
221
222
|
}
|
|
222
223
|
|
|
223
224
|
declare enum ReasoningDetailType {
|
package/dist/index.d.ts
CHANGED
|
@@ -217,7 +217,8 @@ declare enum ReasoningFormat {
|
|
|
217
217
|
Unknown = "unknown",
|
|
218
218
|
OpenAIResponsesV1 = "openai-responses-v1",
|
|
219
219
|
XAIResponsesV1 = "xai-responses-v1",
|
|
220
|
-
AnthropicClaudeV1 = "anthropic-claude-v1"
|
|
220
|
+
AnthropicClaudeV1 = "anthropic-claude-v1",
|
|
221
|
+
GoogleGeminiV1 = "google-gemini-v1"
|
|
221
222
|
}
|
|
222
223
|
|
|
223
224
|
declare enum ReasoningDetailType {
|
package/dist/index.js
CHANGED
|
@@ -943,6 +943,7 @@ var ReasoningFormat = /* @__PURE__ */ ((ReasoningFormat2) => {
|
|
|
943
943
|
ReasoningFormat2["OpenAIResponsesV1"] = "openai-responses-v1";
|
|
944
944
|
ReasoningFormat2["XAIResponsesV1"] = "xai-responses-v1";
|
|
945
945
|
ReasoningFormat2["AnthropicClaudeV1"] = "anthropic-claude-v1";
|
|
946
|
+
ReasoningFormat2["GoogleGeminiV1"] = "google-gemini-v1";
|
|
946
947
|
return ReasoningFormat2;
|
|
947
948
|
})(ReasoningFormat || {});
|
|
948
949
|
|
|
@@ -1105,8 +1106,9 @@ function getCacheControl(providerMetadata) {
|
|
|
1105
1106
|
return (_c = (_b = (_a15 = openrouter2 == null ? void 0 : openrouter2.cacheControl) != null ? _a15 : openrouter2 == null ? void 0 : openrouter2.cache_control) != null ? _b : anthropic == null ? void 0 : anthropic.cacheControl) != null ? _c : anthropic == null ? void 0 : anthropic.cache_control;
|
|
1106
1107
|
}
|
|
1107
1108
|
function convertToOpenRouterChatMessages(prompt) {
|
|
1108
|
-
var _a15, _b, _c, _d, _e;
|
|
1109
|
+
var _a15, _b, _c, _d, _e, _f;
|
|
1109
1110
|
const messages = [];
|
|
1111
|
+
const accumulatedReasoningDetails = [];
|
|
1110
1112
|
for (const { role, content, providerOptions } of prompt) {
|
|
1111
1113
|
switch (role) {
|
|
1112
1114
|
case "system": {
|
|
@@ -1136,7 +1138,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1136
1138
|
const messageCacheControl = getCacheControl(providerOptions);
|
|
1137
1139
|
const contentParts = content.map(
|
|
1138
1140
|
(part) => {
|
|
1139
|
-
var _a16, _b2, _c2, _d2, _e2,
|
|
1141
|
+
var _a16, _b2, _c2, _d2, _e2, _f2;
|
|
1140
1142
|
const cacheControl = (_a16 = getCacheControl(part.providerOptions)) != null ? _a16 : messageCacheControl;
|
|
1141
1143
|
switch (part.type) {
|
|
1142
1144
|
case "text":
|
|
@@ -1162,7 +1164,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1162
1164
|
};
|
|
1163
1165
|
}
|
|
1164
1166
|
const fileName = String(
|
|
1165
|
-
(
|
|
1167
|
+
(_f2 = (_e2 = (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d2.filename) != null ? _e2 : part.filename) != null ? _f2 : ""
|
|
1166
1168
|
);
|
|
1167
1169
|
const fileData = getFileUrl({
|
|
1168
1170
|
part,
|
|
@@ -1216,6 +1218,12 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1216
1218
|
break;
|
|
1217
1219
|
}
|
|
1218
1220
|
case "tool-call": {
|
|
1221
|
+
const partReasoningDetails = (_c = part.providerOptions) == null ? void 0 : _c.openrouter;
|
|
1222
|
+
if ((partReasoningDetails == null ? void 0 : partReasoningDetails.reasoning_details) && Array.isArray(partReasoningDetails.reasoning_details)) {
|
|
1223
|
+
accumulatedReasoningDetails.push(
|
|
1224
|
+
...partReasoningDetails.reasoning_details
|
|
1225
|
+
);
|
|
1226
|
+
}
|
|
1219
1227
|
toolCalls.push({
|
|
1220
1228
|
id: part.toolCallId,
|
|
1221
1229
|
type: "function",
|
|
@@ -1238,14 +1246,14 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1238
1246
|
}
|
|
1239
1247
|
}
|
|
1240
1248
|
const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
|
|
1241
|
-
const
|
|
1249
|
+
const messageReasoningDetails = parsedProviderOptions.success ? (_e = (_d = parsedProviderOptions.data) == null ? void 0 : _d.openrouter) == null ? void 0 : _e.reasoning_details : void 0;
|
|
1250
|
+
const finalReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : accumulatedReasoningDetails.length > 0 ? accumulatedReasoningDetails : void 0;
|
|
1242
1251
|
messages.push({
|
|
1243
1252
|
role: "assistant",
|
|
1244
1253
|
content: text,
|
|
1245
1254
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
1246
1255
|
reasoning: reasoning || void 0,
|
|
1247
|
-
|
|
1248
|
-
reasoning_details: preservedReasoningDetails && Array.isArray(preservedReasoningDetails) && preservedReasoningDetails.length > 0 ? preservedReasoningDetails : void 0,
|
|
1256
|
+
reasoning_details: finalReasoningDetails,
|
|
1249
1257
|
cache_control: getCacheControl(providerOptions)
|
|
1250
1258
|
});
|
|
1251
1259
|
break;
|
|
@@ -1257,7 +1265,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1257
1265
|
role: "tool",
|
|
1258
1266
|
tool_call_id: toolResponse.toolCallId,
|
|
1259
1267
|
content: content2,
|
|
1260
|
-
cache_control: (
|
|
1268
|
+
cache_control: (_f = getCacheControl(providerOptions)) != null ? _f : getCacheControl(toolResponse.providerOptions)
|
|
1261
1269
|
});
|
|
1262
1270
|
}
|
|
1263
1271
|
break;
|
|
@@ -1590,7 +1598,9 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1590
1598
|
});
|
|
1591
1599
|
}
|
|
1592
1600
|
if (tools && tools.length > 0) {
|
|
1593
|
-
const mappedTools = tools.filter(
|
|
1601
|
+
const mappedTools = tools.filter(
|
|
1602
|
+
(tool) => tool.type === "function"
|
|
1603
|
+
).map((tool) => ({
|
|
1594
1604
|
type: "function",
|
|
1595
1605
|
function: {
|
|
1596
1606
|
name: tool.name,
|
|
@@ -1665,7 +1675,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1665
1675
|
if (detail.text) {
|
|
1666
1676
|
return {
|
|
1667
1677
|
type: "reasoning",
|
|
1668
|
-
text: detail.text
|
|
1678
|
+
text: detail.text,
|
|
1679
|
+
providerMetadata: {
|
|
1680
|
+
openrouter: {
|
|
1681
|
+
reasoning_details: [detail]
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1669
1684
|
};
|
|
1670
1685
|
}
|
|
1671
1686
|
break;
|
|
@@ -1674,7 +1689,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1674
1689
|
if (detail.summary) {
|
|
1675
1690
|
return {
|
|
1676
1691
|
type: "reasoning",
|
|
1677
|
-
text: detail.summary
|
|
1692
|
+
text: detail.summary,
|
|
1693
|
+
providerMetadata: {
|
|
1694
|
+
openrouter: {
|
|
1695
|
+
reasoning_details: [detail]
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1678
1698
|
};
|
|
1679
1699
|
}
|
|
1680
1700
|
break;
|
|
@@ -1683,7 +1703,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1683
1703
|
if (detail.data) {
|
|
1684
1704
|
return {
|
|
1685
1705
|
type: "reasoning",
|
|
1686
|
-
text: "[REDACTED]"
|
|
1706
|
+
text: "[REDACTED]",
|
|
1707
|
+
providerMetadata: {
|
|
1708
|
+
openrouter: {
|
|
1709
|
+
reasoning_details: [detail]
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1687
1712
|
};
|
|
1688
1713
|
}
|
|
1689
1714
|
break;
|
|
@@ -1713,7 +1738,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1713
1738
|
type: "tool-call",
|
|
1714
1739
|
toolCallId: (_j = toolCall.id) != null ? _j : generateId(),
|
|
1715
1740
|
toolName: toolCall.function.name,
|
|
1716
|
-
input: toolCall.function.arguments
|
|
1741
|
+
input: toolCall.function.arguments,
|
|
1742
|
+
providerMetadata: {
|
|
1743
|
+
openrouter: {
|
|
1744
|
+
reasoning_details: reasoningDetails
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1717
1747
|
});
|
|
1718
1748
|
}
|
|
1719
1749
|
}
|
|
@@ -1899,7 +1929,18 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1899
1929
|
});
|
|
1900
1930
|
};
|
|
1901
1931
|
if (delta.reasoning_details && delta.reasoning_details.length > 0) {
|
|
1902
|
-
|
|
1932
|
+
for (const detail of delta.reasoning_details) {
|
|
1933
|
+
if (detail.type === "reasoning.text" /* Text */) {
|
|
1934
|
+
const lastDetail = accumulatedReasoningDetails[accumulatedReasoningDetails.length - 1];
|
|
1935
|
+
if ((lastDetail == null ? void 0 : lastDetail.type) === "reasoning.text" /* Text */) {
|
|
1936
|
+
lastDetail.text = (lastDetail.text || "") + (detail.text || "");
|
|
1937
|
+
} else {
|
|
1938
|
+
accumulatedReasoningDetails.push(__spreadValues({}, detail));
|
|
1939
|
+
}
|
|
1940
|
+
} else {
|
|
1941
|
+
accumulatedReasoningDetails.push(detail);
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1903
1944
|
for (const detail of delta.reasoning_details) {
|
|
1904
1945
|
switch (detail.type) {
|
|
1905
1946
|
case "reasoning.text" /* Text */: {
|
|
@@ -2028,7 +2069,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
2028
2069
|
type: "tool-call",
|
|
2029
2070
|
toolCallId: toolCall2.id,
|
|
2030
2071
|
toolName: toolCall2.function.name,
|
|
2031
|
-
input: toolCall2.function.arguments
|
|
2072
|
+
input: toolCall2.function.arguments,
|
|
2073
|
+
providerMetadata: {
|
|
2074
|
+
openrouter: {
|
|
2075
|
+
reasoning_details: accumulatedReasoningDetails
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2032
2078
|
});
|
|
2033
2079
|
toolCall2.sent = true;
|
|
2034
2080
|
}
|
|
@@ -2066,7 +2112,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
2066
2112
|
type: "tool-call",
|
|
2067
2113
|
toolCallId: (_n = toolCall.id) != null ? _n : generateId(),
|
|
2068
2114
|
toolName: toolCall.function.name,
|
|
2069
|
-
input: toolCall.function.arguments
|
|
2115
|
+
input: toolCall.function.arguments,
|
|
2116
|
+
providerMetadata: {
|
|
2117
|
+
openrouter: {
|
|
2118
|
+
reasoning_details: accumulatedReasoningDetails
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2070
2121
|
});
|
|
2071
2122
|
toolCall.sent = true;
|
|
2072
2123
|
}
|
|
@@ -2092,7 +2143,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
2092
2143
|
toolCallId: (_a16 = toolCall.id) != null ? _a16 : generateId(),
|
|
2093
2144
|
toolName: toolCall.function.name,
|
|
2094
2145
|
// Coerce invalid arguments to an empty JSON object
|
|
2095
|
-
input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}"
|
|
2146
|
+
input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}",
|
|
2147
|
+
providerMetadata: {
|
|
2148
|
+
openrouter: {
|
|
2149
|
+
reasoning_details: accumulatedReasoningDetails
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2096
2152
|
});
|
|
2097
2153
|
toolCall.sent = true;
|
|
2098
2154
|
}
|
|
@@ -2572,7 +2628,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
2572
2628
|
}
|
|
2573
2629
|
|
|
2574
2630
|
// src/version.ts
|
|
2575
|
-
var VERSION = false ? "0.0.0-test" : "1.2.
|
|
2631
|
+
var VERSION = false ? "0.0.0-test" : "1.2.5";
|
|
2576
2632
|
|
|
2577
2633
|
// src/provider.ts
|
|
2578
2634
|
function createOpenRouter(options = {}) {
|