@openrouter/ai-sdk-provider 1.2.4 → 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.
@@ -1060,8 +1060,9 @@ function getCacheControl(providerMetadata) {
1060
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;
1061
1061
  }
1062
1062
  function convertToOpenRouterChatMessages(prompt) {
1063
- var _a15, _b, _c, _d, _e;
1063
+ var _a15, _b, _c, _d, _e, _f;
1064
1064
  const messages = [];
1065
+ const accumulatedReasoningDetails = [];
1065
1066
  for (const { role, content, providerOptions } of prompt) {
1066
1067
  switch (role) {
1067
1068
  case "system": {
@@ -1091,7 +1092,7 @@ function convertToOpenRouterChatMessages(prompt) {
1091
1092
  const messageCacheControl = getCacheControl(providerOptions);
1092
1093
  const contentParts = content.map(
1093
1094
  (part) => {
1094
- var _a16, _b2, _c2, _d2, _e2, _f;
1095
+ var _a16, _b2, _c2, _d2, _e2, _f2;
1095
1096
  const cacheControl = (_a16 = getCacheControl(part.providerOptions)) != null ? _a16 : messageCacheControl;
1096
1097
  switch (part.type) {
1097
1098
  case "text":
@@ -1117,7 +1118,7 @@ function convertToOpenRouterChatMessages(prompt) {
1117
1118
  };
1118
1119
  }
1119
1120
  const fileName = String(
1120
- (_f = (_e2 = (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d2.filename) != null ? _e2 : part.filename) != null ? _f : ""
1121
+ (_f2 = (_e2 = (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d2.filename) != null ? _e2 : part.filename) != null ? _f2 : ""
1121
1122
  );
1122
1123
  const fileData = getFileUrl({
1123
1124
  part,
@@ -1171,6 +1172,12 @@ function convertToOpenRouterChatMessages(prompt) {
1171
1172
  break;
1172
1173
  }
1173
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
+ }
1174
1181
  toolCalls.push({
1175
1182
  id: part.toolCallId,
1176
1183
  type: "function",
@@ -1193,14 +1200,14 @@ function convertToOpenRouterChatMessages(prompt) {
1193
1200
  }
1194
1201
  }
1195
1202
  const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
1196
- const preservedReasoningDetails = parsedProviderOptions.success ? (_d = (_c = parsedProviderOptions.data) == null ? void 0 : _c.openrouter) == null ? void 0 : _d.reasoning_details : void 0;
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;
1197
1205
  messages.push({
1198
1206
  role: "assistant",
1199
1207
  content: text,
1200
1208
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
1201
1209
  reasoning: reasoning || void 0,
1202
- // Only include reasoning_details if we have the preserved original version
1203
- reasoning_details: preservedReasoningDetails && Array.isArray(preservedReasoningDetails) && preservedReasoningDetails.length > 0 ? preservedReasoningDetails : void 0,
1210
+ reasoning_details: finalReasoningDetails,
1204
1211
  cache_control: getCacheControl(providerOptions)
1205
1212
  });
1206
1213
  break;
@@ -1212,7 +1219,7 @@ function convertToOpenRouterChatMessages(prompt) {
1212
1219
  role: "tool",
1213
1220
  tool_call_id: toolResponse.toolCallId,
1214
1221
  content: content2,
1215
- cache_control: (_e = getCacheControl(providerOptions)) != null ? _e : getCacheControl(toolResponse.providerOptions)
1222
+ cache_control: (_f = getCacheControl(providerOptions)) != null ? _f : getCacheControl(toolResponse.providerOptions)
1216
1223
  });
1217
1224
  }
1218
1225
  break;