@openrouter/ai-sdk-provider 1.2.4 → 1.2.6

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.
@@ -1026,8 +1026,9 @@ function getCacheControl(providerMetadata) {
1026
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;
1027
1027
  }
1028
1028
  function convertToOpenRouterChatMessages(prompt) {
1029
- var _a15, _b, _c, _d, _e;
1029
+ var _a15, _b, _c, _d, _e, _f;
1030
1030
  const messages = [];
1031
+ const accumulatedReasoningDetails = [];
1031
1032
  for (const { role, content, providerOptions } of prompt) {
1032
1033
  switch (role) {
1033
1034
  case "system": {
@@ -1057,7 +1058,7 @@ function convertToOpenRouterChatMessages(prompt) {
1057
1058
  const messageCacheControl = getCacheControl(providerOptions);
1058
1059
  const contentParts = content.map(
1059
1060
  (part) => {
1060
- var _a16, _b2, _c2, _d2, _e2, _f;
1061
+ var _a16, _b2, _c2, _d2, _e2, _f2;
1061
1062
  const cacheControl = (_a16 = getCacheControl(part.providerOptions)) != null ? _a16 : messageCacheControl;
1062
1063
  switch (part.type) {
1063
1064
  case "text":
@@ -1083,7 +1084,7 @@ function convertToOpenRouterChatMessages(prompt) {
1083
1084
  };
1084
1085
  }
1085
1086
  const fileName = String(
1086
- (_f = (_e2 = (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d2.filename) != null ? _e2 : part.filename) != null ? _f : ""
1087
+ (_f2 = (_e2 = (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2.openrouter) == null ? void 0 : _d2.filename) != null ? _e2 : part.filename) != null ? _f2 : ""
1087
1088
  );
1088
1089
  const fileData = getFileUrl({
1089
1090
  part,
@@ -1137,6 +1138,12 @@ function convertToOpenRouterChatMessages(prompt) {
1137
1138
  break;
1138
1139
  }
1139
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
+ }
1140
1147
  toolCalls.push({
1141
1148
  id: part.toolCallId,
1142
1149
  type: "function",
@@ -1159,14 +1166,14 @@ function convertToOpenRouterChatMessages(prompt) {
1159
1166
  }
1160
1167
  }
1161
1168
  const parsedProviderOptions = OpenRouterProviderOptionsSchema.safeParse(providerOptions);
1162
- const preservedReasoningDetails = parsedProviderOptions.success ? (_d = (_c = parsedProviderOptions.data) == null ? void 0 : _c.openrouter) == null ? void 0 : _d.reasoning_details : void 0;
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;
1163
1171
  messages.push({
1164
1172
  role: "assistant",
1165
1173
  content: text,
1166
1174
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
1167
1175
  reasoning: reasoning || void 0,
1168
- // Only include reasoning_details if we have the preserved original version
1169
- reasoning_details: preservedReasoningDetails && Array.isArray(preservedReasoningDetails) && preservedReasoningDetails.length > 0 ? preservedReasoningDetails : void 0,
1176
+ reasoning_details: finalReasoningDetails,
1170
1177
  cache_control: getCacheControl(providerOptions)
1171
1178
  });
1172
1179
  break;
@@ -1178,7 +1185,7 @@ function convertToOpenRouterChatMessages(prompt) {
1178
1185
  role: "tool",
1179
1186
  tool_call_id: toolResponse.toolCallId,
1180
1187
  content: content2,
1181
- cache_control: (_e = getCacheControl(providerOptions)) != null ? _e : getCacheControl(toolResponse.providerOptions)
1188
+ cache_control: (_f = getCacheControl(providerOptions)) != null ? _f : getCacheControl(toolResponse.providerOptions)
1182
1189
  });
1183
1190
  }
1184
1191
  break;
@@ -1318,7 +1325,7 @@ var OpenRouterNonStreamChatCompletionResponseSchema = z7.union([
1318
1325
  content: z7.array(
1319
1326
  z7.object({
1320
1327
  type: z7.string(),
1321
- text: z7.string()
1328
+ text: z7.string().optional()
1322
1329
  }).passthrough()
1323
1330
  ).optional()
1324
1331
  }).passthrough()
@@ -1401,7 +1408,7 @@ var OpenRouterStreamChatCompletionChunkSchema = z7.union([
1401
1408
  content: z7.array(
1402
1409
  z7.object({
1403
1410
  type: z7.string(),
1404
- text: z7.string()
1411
+ text: z7.string().optional()
1405
1412
  }).passthrough()
1406
1413
  ).optional()
1407
1414
  }).passthrough()