@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.mjs CHANGED
@@ -908,6 +908,7 @@ var ReasoningFormat = /* @__PURE__ */ ((ReasoningFormat2) => {
908
908
  ReasoningFormat2["OpenAIResponsesV1"] = "openai-responses-v1";
909
909
  ReasoningFormat2["XAIResponsesV1"] = "xai-responses-v1";
910
910
  ReasoningFormat2["AnthropicClaudeV1"] = "anthropic-claude-v1";
911
+ ReasoningFormat2["GoogleGeminiV1"] = "google-gemini-v1";
911
912
  return ReasoningFormat2;
912
913
  })(ReasoningFormat || {});
913
914
 
@@ -1070,8 +1071,9 @@ function getCacheControl(providerMetadata) {
1070
1071
  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;
1071
1072
  }
1072
1073
  function convertToOpenRouterChatMessages(prompt) {
1073
- var _a15, _b, _c, _d, _e;
1074
+ var _a15, _b, _c, _d, _e, _f;
1074
1075
  const messages = [];
1076
+ const accumulatedReasoningDetails = [];
1075
1077
  for (const { role, content, providerOptions } of prompt) {
1076
1078
  switch (role) {
1077
1079
  case "system": {
@@ -1101,7 +1103,7 @@ function convertToOpenRouterChatMessages(prompt) {
1101
1103
  const messageCacheControl = getCacheControl(providerOptions);
1102
1104
  const contentParts = content.map(
1103
1105
  (part) => {
1104
- var _a16, _b2, _c2, _d2, _e2, _f;
1106
+ var _a16, _b2, _c2, _d2, _e2, _f2;
1105
1107
  const cacheControl = (_a16 = getCacheControl(part.providerOptions)) != null ? _a16 : messageCacheControl;
1106
1108
  switch (part.type) {
1107
1109
  case "text":
@@ -1127,7 +1129,7 @@ function convertToOpenRouterChatMessages(prompt) {
1127
1129
  };
1128
1130
  }
1129
1131
  const fileName = String(
1130
- (_f = (_e2 = (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d2.filename) != null ? _e2 : part.filename) != null ? _f : ""
1132
+ (_f2 = (_e2 = (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d2.filename) != null ? _e2 : part.filename) != null ? _f2 : ""
1131
1133
  );
1132
1134
  const fileData = getFileUrl({
1133
1135
  part,
@@ -1181,6 +1183,12 @@ function convertToOpenRouterChatMessages(prompt) {
1181
1183
  break;
1182
1184
  }
1183
1185
  case "tool-call": {
1186
+ const partReasoningDetails = (_c = part.providerOptions) == null ? void 0 : _c.openrouter;
1187
+ if ((partReasoningDetails == null ? void 0 : partReasoningDetails.reasoning_details) && Array.isArray(partReasoningDetails.reasoning_details)) {
1188
+ accumulatedReasoningDetails.push(
1189
+ ...partReasoningDetails.reasoning_details
1190
+ );
1191
+ }
1184
1192
  toolCalls.push({
1185
1193
  id: part.toolCallId,
1186
1194
  type: "function",
@@ -1203,14 +1211,14 @@ function convertToOpenRouterChatMessages(prompt) {
1203
1211
  }
1204
1212
  }
1205
1213
  const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
1206
- const preservedReasoningDetails = parsedProviderOptions.success ? (_d = (_c = parsedProviderOptions.data) == null ? void 0 : _c.openrouter) == null ? void 0 : _d.reasoning_details : void 0;
1214
+ const messageReasoningDetails = parsedProviderOptions.success ? (_e = (_d = parsedProviderOptions.data) == null ? void 0 : _d.openrouter) == null ? void 0 : _e.reasoning_details : void 0;
1215
+ const finalReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : accumulatedReasoningDetails.length > 0 ? accumulatedReasoningDetails : void 0;
1207
1216
  messages.push({
1208
1217
  role: "assistant",
1209
1218
  content: text,
1210
1219
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
1211
1220
  reasoning: reasoning || void 0,
1212
- // Only include reasoning_details if we have the preserved original version
1213
- reasoning_details: preservedReasoningDetails && Array.isArray(preservedReasoningDetails) && preservedReasoningDetails.length > 0 ? preservedReasoningDetails : void 0,
1221
+ reasoning_details: finalReasoningDetails,
1214
1222
  cache_control: getCacheControl(providerOptions)
1215
1223
  });
1216
1224
  break;
@@ -1222,7 +1230,7 @@ function convertToOpenRouterChatMessages(prompt) {
1222
1230
  role: "tool",
1223
1231
  tool_call_id: toolResponse.toolCallId,
1224
1232
  content: content2,
1225
- cache_control: (_e = getCacheControl(providerOptions)) != null ? _e : getCacheControl(toolResponse.providerOptions)
1233
+ cache_control: (_f = getCacheControl(providerOptions)) != null ? _f : getCacheControl(toolResponse.providerOptions)
1226
1234
  });
1227
1235
  }
1228
1236
  break;
@@ -1555,7 +1563,9 @@ var OpenRouterChatLanguageModel = class {
1555
1563
  });
1556
1564
  }
1557
1565
  if (tools && tools.length > 0) {
1558
- const mappedTools = tools.filter((tool) => tool.type === "function").map((tool) => ({
1566
+ const mappedTools = tools.filter(
1567
+ (tool) => tool.type === "function"
1568
+ ).map((tool) => ({
1559
1569
  type: "function",
1560
1570
  function: {
1561
1571
  name: tool.name,
@@ -1630,7 +1640,12 @@ var OpenRouterChatLanguageModel = class {
1630
1640
  if (detail.text) {
1631
1641
  return {
1632
1642
  type: "reasoning",
1633
- text: detail.text
1643
+ text: detail.text,
1644
+ providerMetadata: {
1645
+ openrouter: {
1646
+ reasoning_details: [detail]
1647
+ }
1648
+ }
1634
1649
  };
1635
1650
  }
1636
1651
  break;
@@ -1639,7 +1654,12 @@ var OpenRouterChatLanguageModel = class {
1639
1654
  if (detail.summary) {
1640
1655
  return {
1641
1656
  type: "reasoning",
1642
- text: detail.summary
1657
+ text: detail.summary,
1658
+ providerMetadata: {
1659
+ openrouter: {
1660
+ reasoning_details: [detail]
1661
+ }
1662
+ }
1643
1663
  };
1644
1664
  }
1645
1665
  break;
@@ -1648,7 +1668,12 @@ var OpenRouterChatLanguageModel = class {
1648
1668
  if (detail.data) {
1649
1669
  return {
1650
1670
  type: "reasoning",
1651
- text: "[REDACTED]"
1671
+ text: "[REDACTED]",
1672
+ providerMetadata: {
1673
+ openrouter: {
1674
+ reasoning_details: [detail]
1675
+ }
1676
+ }
1652
1677
  };
1653
1678
  }
1654
1679
  break;
@@ -1678,7 +1703,12 @@ var OpenRouterChatLanguageModel = class {
1678
1703
  type: "tool-call",
1679
1704
  toolCallId: (_j = toolCall.id) != null ? _j : generateId(),
1680
1705
  toolName: toolCall.function.name,
1681
- input: toolCall.function.arguments
1706
+ input: toolCall.function.arguments,
1707
+ providerMetadata: {
1708
+ openrouter: {
1709
+ reasoning_details: reasoningDetails
1710
+ }
1711
+ }
1682
1712
  });
1683
1713
  }
1684
1714
  }
@@ -1864,7 +1894,18 @@ var OpenRouterChatLanguageModel = class {
1864
1894
  });
1865
1895
  };
1866
1896
  if (delta.reasoning_details && delta.reasoning_details.length > 0) {
1867
- accumulatedReasoningDetails.push(...delta.reasoning_details);
1897
+ for (const detail of delta.reasoning_details) {
1898
+ if (detail.type === "reasoning.text" /* Text */) {
1899
+ const lastDetail = accumulatedReasoningDetails[accumulatedReasoningDetails.length - 1];
1900
+ if ((lastDetail == null ? void 0 : lastDetail.type) === "reasoning.text" /* Text */) {
1901
+ lastDetail.text = (lastDetail.text || "") + (detail.text || "");
1902
+ } else {
1903
+ accumulatedReasoningDetails.push(__spreadValues({}, detail));
1904
+ }
1905
+ } else {
1906
+ accumulatedReasoningDetails.push(detail);
1907
+ }
1908
+ }
1868
1909
  for (const detail of delta.reasoning_details) {
1869
1910
  switch (detail.type) {
1870
1911
  case "reasoning.text" /* Text */: {
@@ -1993,7 +2034,12 @@ var OpenRouterChatLanguageModel = class {
1993
2034
  type: "tool-call",
1994
2035
  toolCallId: toolCall2.id,
1995
2036
  toolName: toolCall2.function.name,
1996
- input: toolCall2.function.arguments
2037
+ input: toolCall2.function.arguments,
2038
+ providerMetadata: {
2039
+ openrouter: {
2040
+ reasoning_details: accumulatedReasoningDetails
2041
+ }
2042
+ }
1997
2043
  });
1998
2044
  toolCall2.sent = true;
1999
2045
  }
@@ -2031,7 +2077,12 @@ var OpenRouterChatLanguageModel = class {
2031
2077
  type: "tool-call",
2032
2078
  toolCallId: (_n = toolCall.id) != null ? _n : generateId(),
2033
2079
  toolName: toolCall.function.name,
2034
- input: toolCall.function.arguments
2080
+ input: toolCall.function.arguments,
2081
+ providerMetadata: {
2082
+ openrouter: {
2083
+ reasoning_details: accumulatedReasoningDetails
2084
+ }
2085
+ }
2035
2086
  });
2036
2087
  toolCall.sent = true;
2037
2088
  }
@@ -2057,7 +2108,12 @@ var OpenRouterChatLanguageModel = class {
2057
2108
  toolCallId: (_a16 = toolCall.id) != null ? _a16 : generateId(),
2058
2109
  toolName: toolCall.function.name,
2059
2110
  // Coerce invalid arguments to an empty JSON object
2060
- input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}"
2111
+ input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}",
2112
+ providerMetadata: {
2113
+ openrouter: {
2114
+ reasoning_details: accumulatedReasoningDetails
2115
+ }
2116
+ }
2061
2117
  });
2062
2118
  toolCall.sent = true;
2063
2119
  }
@@ -2537,7 +2593,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
2537
2593
  }
2538
2594
 
2539
2595
  // src/version.ts
2540
- var VERSION = false ? "0.0.0-test" : "1.2.3";
2596
+ var VERSION = false ? "0.0.0-test" : "1.2.5";
2541
2597
 
2542
2598
  // src/provider.ts
2543
2599
  function createOpenRouter(options = {}) {