@openrouter/ai-sdk-provider 2.3.2 → 2.3.3

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.
@@ -6,6 +6,7 @@ import { z } from 'zod/v4';
6
6
  declare enum ReasoningFormat {
7
7
  Unknown = "unknown",
8
8
  OpenAIResponsesV1 = "openai-responses-v1",
9
+ AzureOpenAIResponsesV1 = "azure-openai-responses-v1",
9
10
  XAIResponsesV1 = "xai-responses-v1",
10
11
  AnthropicClaudeV1 = "anthropic-claude-v1",
11
12
  GoogleGeminiV1 = "google-gemini-v1"
@@ -6,6 +6,7 @@ import { z } from 'zod/v4';
6
6
  declare enum ReasoningFormat {
7
7
  Unknown = "unknown",
8
8
  OpenAIResponsesV1 = "openai-responses-v1",
9
+ AzureOpenAIResponsesV1 = "azure-openai-responses-v1",
9
10
  XAIResponsesV1 = "xai-responses-v1",
10
11
  AnthropicClaudeV1 = "anthropic-claude-v1",
11
12
  GoogleGeminiV1 = "google-gemini-v1"
@@ -2182,11 +2182,13 @@ function isDefinedOrNotNull(value) {
2182
2182
  var ReasoningFormat = /* @__PURE__ */ ((ReasoningFormat2) => {
2183
2183
  ReasoningFormat2["Unknown"] = "unknown";
2184
2184
  ReasoningFormat2["OpenAIResponsesV1"] = "openai-responses-v1";
2185
+ ReasoningFormat2["AzureOpenAIResponsesV1"] = "azure-openai-responses-v1";
2185
2186
  ReasoningFormat2["XAIResponsesV1"] = "xai-responses-v1";
2186
2187
  ReasoningFormat2["AnthropicClaudeV1"] = "anthropic-claude-v1";
2187
2188
  ReasoningFormat2["GoogleGeminiV1"] = "google-gemini-v1";
2188
2189
  return ReasoningFormat2;
2189
2190
  })(ReasoningFormat || {});
2191
+ var DEFAULT_REASONING_FORMAT = "anthropic-claude-v1" /* AnthropicClaudeV1 */;
2190
2192
 
2191
2193
  // src/schemas/reasoning-details.ts
2192
2194
  var CommonReasoningDetailSchema = import_v4.z.object({
@@ -2339,7 +2341,11 @@ var OpenRouterProviderMetadataSchema = import_v43.z.object({
2339
2341
  }).catchall(import_v43.z.any());
2340
2342
  var OpenRouterProviderOptionsSchema = import_v43.z.object({
2341
2343
  openrouter: import_v43.z.object({
2342
- reasoning_details: import_v43.z.array(ReasoningDetailUnionSchema).optional(),
2344
+ // Use ReasoningDetailArraySchema (with unknown fallback) instead of
2345
+ // z.array(ReasoningDetailUnionSchema) so that a single malformed entry
2346
+ // (e.g., a future format not yet in the enum) is individually dropped
2347
+ // rather than causing the entire array to fail parsing.
2348
+ reasoning_details: ReasoningDetailArraySchema.optional(),
2343
2349
  annotations: import_v43.z.array(FileAnnotationSchema).optional()
2344
2350
  }).optional()
2345
2351
  }).optional();
@@ -2751,8 +2757,24 @@ function convertToOpenRouterChatMessages(prompt) {
2751
2757
  const candidateReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : findFirstReasoningDetails(content);
2752
2758
  let finalReasoningDetails;
2753
2759
  if (candidateReasoningDetails && candidateReasoningDetails.length > 0) {
2760
+ const validDetails = candidateReasoningDetails.filter((detail) => {
2761
+ var _a17;
2762
+ if (detail.type !== "reasoning.text" /* Text */) {
2763
+ return true;
2764
+ }
2765
+ const format = (_a17 = detail.format) != null ? _a17 : DEFAULT_REASONING_FORMAT;
2766
+ if (format !== "anthropic-claude-v1" /* AnthropicClaudeV1 */) {
2767
+ return true;
2768
+ }
2769
+ return !!detail.signature;
2770
+ });
2771
+ if (validDetails.length < candidateReasoningDetails.length) {
2772
+ console.warn(
2773
+ "[openrouter] Some reasoning_details entries were removed because they were missing signatures. See https://github.com/OpenRouterTeam/ai-sdk-provider/issues/423 for more details."
2774
+ );
2775
+ }
2754
2776
  const uniqueDetails = [];
2755
- for (const detail of candidateReasoningDetails) {
2777
+ for (const detail of validDetails) {
2756
2778
  if (reasoningDetailsTracker.upsert(detail)) {
2757
2779
  uniqueDetails.push(detail);
2758
2780
  }
@@ -2922,13 +2944,14 @@ function filenameFromUrl(url) {
2922
2944
  }
2923
2945
  }
2924
2946
  function findFirstReasoningDetails(content) {
2925
- var _a16, _b16, _c;
2947
+ var _a16, _b16, _c, _d;
2926
2948
  for (const part of content) {
2927
2949
  if (part.type === "tool-call") {
2928
- const openrouter = (_a16 = part.providerOptions) == null ? void 0 : _a16.openrouter;
2929
- const details = openrouter == null ? void 0 : openrouter.reasoning_details;
2930
- if (Array.isArray(details) && details.length > 0) {
2931
- return details;
2950
+ const parsed = OpenRouterProviderOptionsSchema.safeParse(
2951
+ part.providerOptions
2952
+ );
2953
+ if (parsed.success && ((_b16 = (_a16 = parsed.data) == null ? void 0 : _a16.openrouter) == null ? void 0 : _b16.reasoning_details) && parsed.data.openrouter.reasoning_details.length > 0) {
2954
+ return parsed.data.openrouter.reasoning_details;
2932
2955
  }
2933
2956
  }
2934
2957
  }
@@ -2937,7 +2960,7 @@ function findFirstReasoningDetails(content) {
2937
2960
  const parsed = OpenRouterProviderOptionsSchema.safeParse(
2938
2961
  part.providerOptions
2939
2962
  );
2940
- if (parsed.success && ((_c = (_b16 = parsed.data) == null ? void 0 : _b16.openrouter) == null ? void 0 : _c.reasoning_details) && parsed.data.openrouter.reasoning_details.length > 0) {
2963
+ if (parsed.success && ((_d = (_c = parsed.data) == null ? void 0 : _c.openrouter) == null ? void 0 : _d.reasoning_details) && parsed.data.openrouter.reasoning_details.length > 0) {
2941
2964
  return parsed.data.openrouter.reasoning_details;
2942
2965
  }
2943
2966
  }