@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/internal/index.mjs
CHANGED
|
@@ -863,6 +863,7 @@ var ReasoningFormat = /* @__PURE__ */ ((ReasoningFormat2) => {
|
|
|
863
863
|
ReasoningFormat2["OpenAIResponsesV1"] = "openai-responses-v1";
|
|
864
864
|
ReasoningFormat2["XAIResponsesV1"] = "xai-responses-v1";
|
|
865
865
|
ReasoningFormat2["AnthropicClaudeV1"] = "anthropic-claude-v1";
|
|
866
|
+
ReasoningFormat2["GoogleGeminiV1"] = "google-gemini-v1";
|
|
866
867
|
return ReasoningFormat2;
|
|
867
868
|
})(ReasoningFormat || {});
|
|
868
869
|
|
|
@@ -1025,8 +1026,9 @@ function getCacheControl(providerMetadata) {
|
|
|
1025
1026
|
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;
|
|
1026
1027
|
}
|
|
1027
1028
|
function convertToOpenRouterChatMessages(prompt) {
|
|
1028
|
-
var _a15, _b, _c, _d, _e;
|
|
1029
|
+
var _a15, _b, _c, _d, _e, _f;
|
|
1029
1030
|
const messages = [];
|
|
1031
|
+
const accumulatedReasoningDetails = [];
|
|
1030
1032
|
for (const { role, content, providerOptions } of prompt) {
|
|
1031
1033
|
switch (role) {
|
|
1032
1034
|
case "system": {
|
|
@@ -1056,7 +1058,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1056
1058
|
const messageCacheControl = getCacheControl(providerOptions);
|
|
1057
1059
|
const contentParts = content.map(
|
|
1058
1060
|
(part) => {
|
|
1059
|
-
var _a16, _b2, _c2, _d2, _e2,
|
|
1061
|
+
var _a16, _b2, _c2, _d2, _e2, _f2;
|
|
1060
1062
|
const cacheControl = (_a16 = getCacheControl(part.providerOptions)) != null ? _a16 : messageCacheControl;
|
|
1061
1063
|
switch (part.type) {
|
|
1062
1064
|
case "text":
|
|
@@ -1082,7 +1084,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1082
1084
|
};
|
|
1083
1085
|
}
|
|
1084
1086
|
const fileName = String(
|
|
1085
|
-
(
|
|
1087
|
+
(_f2 = (_e2 = (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d2.filename) != null ? _e2 : part.filename) != null ? _f2 : ""
|
|
1086
1088
|
);
|
|
1087
1089
|
const fileData = getFileUrl({
|
|
1088
1090
|
part,
|
|
@@ -1136,6 +1138,12 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1136
1138
|
break;
|
|
1137
1139
|
}
|
|
1138
1140
|
case "tool-call": {
|
|
1141
|
+
const partReasoningDetails = (_c = part.providerOptions) == null ? void 0 : _c.openrouter;
|
|
1142
|
+
if ((partReasoningDetails == null ? void 0 : partReasoningDetails.reasoning_details) && Array.isArray(partReasoningDetails.reasoning_details)) {
|
|
1143
|
+
accumulatedReasoningDetails.push(
|
|
1144
|
+
...partReasoningDetails.reasoning_details
|
|
1145
|
+
);
|
|
1146
|
+
}
|
|
1139
1147
|
toolCalls.push({
|
|
1140
1148
|
id: part.toolCallId,
|
|
1141
1149
|
type: "function",
|
|
@@ -1158,14 +1166,14 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1158
1166
|
}
|
|
1159
1167
|
}
|
|
1160
1168
|
const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
|
|
1161
|
-
const
|
|
1169
|
+
const messageReasoningDetails = parsedProviderOptions.success ? (_e = (_d = parsedProviderOptions.data) == null ? void 0 : _d.openrouter) == null ? void 0 : _e.reasoning_details : void 0;
|
|
1170
|
+
const finalReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : accumulatedReasoningDetails.length > 0 ? accumulatedReasoningDetails : void 0;
|
|
1162
1171
|
messages.push({
|
|
1163
1172
|
role: "assistant",
|
|
1164
1173
|
content: text,
|
|
1165
1174
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
1166
1175
|
reasoning: reasoning || void 0,
|
|
1167
|
-
|
|
1168
|
-
reasoning_details: preservedReasoningDetails && Array.isArray(preservedReasoningDetails) && preservedReasoningDetails.length > 0 ? preservedReasoningDetails : void 0,
|
|
1176
|
+
reasoning_details: finalReasoningDetails,
|
|
1169
1177
|
cache_control: getCacheControl(providerOptions)
|
|
1170
1178
|
});
|
|
1171
1179
|
break;
|
|
@@ -1177,7 +1185,7 @@ function convertToOpenRouterChatMessages(prompt) {
|
|
|
1177
1185
|
role: "tool",
|
|
1178
1186
|
tool_call_id: toolResponse.toolCallId,
|
|
1179
1187
|
content: content2,
|
|
1180
|
-
cache_control: (
|
|
1188
|
+
cache_control: (_f = getCacheControl(providerOptions)) != null ? _f : getCacheControl(toolResponse.providerOptions)
|
|
1181
1189
|
});
|
|
1182
1190
|
}
|
|
1183
1191
|
break;
|
|
@@ -1510,7 +1518,9 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1510
1518
|
});
|
|
1511
1519
|
}
|
|
1512
1520
|
if (tools && tools.length > 0) {
|
|
1513
|
-
const mappedTools = tools.filter(
|
|
1521
|
+
const mappedTools = tools.filter(
|
|
1522
|
+
(tool) => tool.type === "function"
|
|
1523
|
+
).map((tool) => ({
|
|
1514
1524
|
type: "function",
|
|
1515
1525
|
function: {
|
|
1516
1526
|
name: tool.name,
|
|
@@ -1585,7 +1595,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1585
1595
|
if (detail.text) {
|
|
1586
1596
|
return {
|
|
1587
1597
|
type: "reasoning",
|
|
1588
|
-
text: detail.text
|
|
1598
|
+
text: detail.text,
|
|
1599
|
+
providerMetadata: {
|
|
1600
|
+
openrouter: {
|
|
1601
|
+
reasoning_details: [detail]
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1589
1604
|
};
|
|
1590
1605
|
}
|
|
1591
1606
|
break;
|
|
@@ -1594,7 +1609,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1594
1609
|
if (detail.summary) {
|
|
1595
1610
|
return {
|
|
1596
1611
|
type: "reasoning",
|
|
1597
|
-
text: detail.summary
|
|
1612
|
+
text: detail.summary,
|
|
1613
|
+
providerMetadata: {
|
|
1614
|
+
openrouter: {
|
|
1615
|
+
reasoning_details: [detail]
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1598
1618
|
};
|
|
1599
1619
|
}
|
|
1600
1620
|
break;
|
|
@@ -1603,7 +1623,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1603
1623
|
if (detail.data) {
|
|
1604
1624
|
return {
|
|
1605
1625
|
type: "reasoning",
|
|
1606
|
-
text: "[REDACTED]"
|
|
1626
|
+
text: "[REDACTED]",
|
|
1627
|
+
providerMetadata: {
|
|
1628
|
+
openrouter: {
|
|
1629
|
+
reasoning_details: [detail]
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1607
1632
|
};
|
|
1608
1633
|
}
|
|
1609
1634
|
break;
|
|
@@ -1633,7 +1658,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1633
1658
|
type: "tool-call",
|
|
1634
1659
|
toolCallId: (_j = toolCall.id) != null ? _j : generateId(),
|
|
1635
1660
|
toolName: toolCall.function.name,
|
|
1636
|
-
input: toolCall.function.arguments
|
|
1661
|
+
input: toolCall.function.arguments,
|
|
1662
|
+
providerMetadata: {
|
|
1663
|
+
openrouter: {
|
|
1664
|
+
reasoning_details: reasoningDetails
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1637
1667
|
});
|
|
1638
1668
|
}
|
|
1639
1669
|
}
|
|
@@ -1819,7 +1849,18 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1819
1849
|
});
|
|
1820
1850
|
};
|
|
1821
1851
|
if (delta.reasoning_details && delta.reasoning_details.length > 0) {
|
|
1822
|
-
|
|
1852
|
+
for (const detail of delta.reasoning_details) {
|
|
1853
|
+
if (detail.type === "reasoning.text" /* Text */) {
|
|
1854
|
+
const lastDetail = accumulatedReasoningDetails[accumulatedReasoningDetails.length - 1];
|
|
1855
|
+
if ((lastDetail == null ? void 0 : lastDetail.type) === "reasoning.text" /* Text */) {
|
|
1856
|
+
lastDetail.text = (lastDetail.text || "") + (detail.text || "");
|
|
1857
|
+
} else {
|
|
1858
|
+
accumulatedReasoningDetails.push(__spreadValues({}, detail));
|
|
1859
|
+
}
|
|
1860
|
+
} else {
|
|
1861
|
+
accumulatedReasoningDetails.push(detail);
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1823
1864
|
for (const detail of delta.reasoning_details) {
|
|
1824
1865
|
switch (detail.type) {
|
|
1825
1866
|
case "reasoning.text" /* Text */: {
|
|
@@ -1948,7 +1989,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1948
1989
|
type: "tool-call",
|
|
1949
1990
|
toolCallId: toolCall2.id,
|
|
1950
1991
|
toolName: toolCall2.function.name,
|
|
1951
|
-
input: toolCall2.function.arguments
|
|
1992
|
+
input: toolCall2.function.arguments,
|
|
1993
|
+
providerMetadata: {
|
|
1994
|
+
openrouter: {
|
|
1995
|
+
reasoning_details: accumulatedReasoningDetails
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1952
1998
|
});
|
|
1953
1999
|
toolCall2.sent = true;
|
|
1954
2000
|
}
|
|
@@ -1986,7 +2032,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
1986
2032
|
type: "tool-call",
|
|
1987
2033
|
toolCallId: (_n = toolCall.id) != null ? _n : generateId(),
|
|
1988
2034
|
toolName: toolCall.function.name,
|
|
1989
|
-
input: toolCall.function.arguments
|
|
2035
|
+
input: toolCall.function.arguments,
|
|
2036
|
+
providerMetadata: {
|
|
2037
|
+
openrouter: {
|
|
2038
|
+
reasoning_details: accumulatedReasoningDetails
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
1990
2041
|
});
|
|
1991
2042
|
toolCall.sent = true;
|
|
1992
2043
|
}
|
|
@@ -2012,7 +2063,12 @@ var OpenRouterChatLanguageModel = class {
|
|
|
2012
2063
|
toolCallId: (_a16 = toolCall.id) != null ? _a16 : generateId(),
|
|
2013
2064
|
toolName: toolCall.function.name,
|
|
2014
2065
|
// Coerce invalid arguments to an empty JSON object
|
|
2015
|
-
input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}"
|
|
2066
|
+
input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}",
|
|
2067
|
+
providerMetadata: {
|
|
2068
|
+
openrouter: {
|
|
2069
|
+
reasoning_details: accumulatedReasoningDetails
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2016
2072
|
});
|
|
2017
2073
|
toolCall.sent = true;
|
|
2018
2074
|
}
|