@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.
package/dist/index.mjs CHANGED
@@ -2183,11 +2183,13 @@ function isDefinedOrNotNull(value) {
2183
2183
  var ReasoningFormat = /* @__PURE__ */ ((ReasoningFormat2) => {
2184
2184
  ReasoningFormat2["Unknown"] = "unknown";
2185
2185
  ReasoningFormat2["OpenAIResponsesV1"] = "openai-responses-v1";
2186
+ ReasoningFormat2["AzureOpenAIResponsesV1"] = "azure-openai-responses-v1";
2186
2187
  ReasoningFormat2["XAIResponsesV1"] = "xai-responses-v1";
2187
2188
  ReasoningFormat2["AnthropicClaudeV1"] = "anthropic-claude-v1";
2188
2189
  ReasoningFormat2["GoogleGeminiV1"] = "google-gemini-v1";
2189
2190
  return ReasoningFormat2;
2190
2191
  })(ReasoningFormat || {});
2192
+ var DEFAULT_REASONING_FORMAT = "anthropic-claude-v1" /* AnthropicClaudeV1 */;
2191
2193
 
2192
2194
  // src/schemas/reasoning-details.ts
2193
2195
  var CommonReasoningDetailSchema = z.object({
@@ -2340,7 +2342,11 @@ var OpenRouterProviderMetadataSchema = z3.object({
2340
2342
  }).catchall(z3.any());
2341
2343
  var OpenRouterProviderOptionsSchema = z3.object({
2342
2344
  openrouter: z3.object({
2343
- reasoning_details: z3.array(ReasoningDetailUnionSchema).optional(),
2345
+ // Use ReasoningDetailArraySchema (with unknown fallback) instead of
2346
+ // z.array(ReasoningDetailUnionSchema) so that a single malformed entry
2347
+ // (e.g., a future format not yet in the enum) is individually dropped
2348
+ // rather than causing the entire array to fail parsing.
2349
+ reasoning_details: ReasoningDetailArraySchema.optional(),
2344
2350
  annotations: z3.array(FileAnnotationSchema).optional()
2345
2351
  }).optional()
2346
2352
  }).optional();
@@ -2752,8 +2758,24 @@ function convertToOpenRouterChatMessages(prompt) {
2752
2758
  const candidateReasoningDetails = messageReasoningDetails && Array.isArray(messageReasoningDetails) && messageReasoningDetails.length > 0 ? messageReasoningDetails : findFirstReasoningDetails(content);
2753
2759
  let finalReasoningDetails;
2754
2760
  if (candidateReasoningDetails && candidateReasoningDetails.length > 0) {
2761
+ const validDetails = candidateReasoningDetails.filter((detail) => {
2762
+ var _a17;
2763
+ if (detail.type !== "reasoning.text" /* Text */) {
2764
+ return true;
2765
+ }
2766
+ const format = (_a17 = detail.format) != null ? _a17 : DEFAULT_REASONING_FORMAT;
2767
+ if (format !== "anthropic-claude-v1" /* AnthropicClaudeV1 */) {
2768
+ return true;
2769
+ }
2770
+ return !!detail.signature;
2771
+ });
2772
+ if (validDetails.length < candidateReasoningDetails.length) {
2773
+ console.warn(
2774
+ "[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."
2775
+ );
2776
+ }
2755
2777
  const uniqueDetails = [];
2756
- for (const detail of candidateReasoningDetails) {
2778
+ for (const detail of validDetails) {
2757
2779
  if (reasoningDetailsTracker.upsert(detail)) {
2758
2780
  uniqueDetails.push(detail);
2759
2781
  }
@@ -2923,13 +2945,14 @@ function filenameFromUrl(url) {
2923
2945
  }
2924
2946
  }
2925
2947
  function findFirstReasoningDetails(content) {
2926
- var _a16, _b16, _c;
2948
+ var _a16, _b16, _c, _d;
2927
2949
  for (const part of content) {
2928
2950
  if (part.type === "tool-call") {
2929
- const openrouter2 = (_a16 = part.providerOptions) == null ? void 0 : _a16.openrouter;
2930
- const details = openrouter2 == null ? void 0 : openrouter2.reasoning_details;
2931
- if (Array.isArray(details) && details.length > 0) {
2932
- return details;
2951
+ const parsed = OpenRouterProviderOptionsSchema.safeParse(
2952
+ part.providerOptions
2953
+ );
2954
+ 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) {
2955
+ return parsed.data.openrouter.reasoning_details;
2933
2956
  }
2934
2957
  }
2935
2958
  }
@@ -2938,7 +2961,7 @@ function findFirstReasoningDetails(content) {
2938
2961
  const parsed = OpenRouterProviderOptionsSchema.safeParse(
2939
2962
  part.providerOptions
2940
2963
  );
2941
- 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) {
2964
+ 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) {
2942
2965
  return parsed.data.openrouter.reasoning_details;
2943
2966
  }
2944
2967
  }
@@ -4691,7 +4714,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
4691
4714
  }
4692
4715
 
4693
4716
  // src/version.ts
4694
- var VERSION2 = false ? "0.0.0-test" : "2.3.2";
4717
+ var VERSION2 = false ? "0.0.0-test" : "2.3.3";
4695
4718
 
4696
4719
  // src/provider.ts
4697
4720
  function createOpenRouter(options = {}) {