@openrouter/ai-sdk-provider 1.5.1 → 1.5.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
@@ -988,10 +988,10 @@ var FileAnnotationSchema = z3.object({
988
988
  z3.object({
989
989
  type: z3.string(),
990
990
  text: z3.string().optional()
991
- }).passthrough()
991
+ }).catchall(z3.any())
992
992
  ).optional()
993
- }).passthrough()
994
- });
993
+ }).catchall(z3.any())
994
+ }).catchall(z3.any());
995
995
  var OpenRouterProviderMetadataSchema = z3.object({
996
996
  provider: z3.string(),
997
997
  reasoning_details: z3.array(ReasoningDetailUnionSchema).optional(),
@@ -1000,18 +1000,18 @@ var OpenRouterProviderMetadataSchema = z3.object({
1000
1000
  promptTokens: z3.number(),
1001
1001
  promptTokensDetails: z3.object({
1002
1002
  cachedTokens: z3.number()
1003
- }).passthrough().optional(),
1003
+ }).catchall(z3.any()).optional(),
1004
1004
  completionTokens: z3.number(),
1005
1005
  completionTokensDetails: z3.object({
1006
1006
  reasoningTokens: z3.number()
1007
- }).passthrough().optional(),
1007
+ }).catchall(z3.any()).optional(),
1008
1008
  totalTokens: z3.number(),
1009
1009
  cost: z3.number().optional(),
1010
1010
  costDetails: z3.object({
1011
1011
  upstreamInferenceCost: z3.number()
1012
- }).passthrough().optional()
1013
- }).passthrough()
1014
- }).passthrough();
1012
+ }).catchall(z3.any()).optional()
1013
+ }).catchall(z3.any())
1014
+ }).catchall(z3.any());
1015
1015
  var OpenRouterProviderOptionsSchema = z3.object({
1016
1016
  openrouter: z3.object({
1017
1017
  reasoning_details: z3.array(ReasoningDetailUnionSchema).optional(),
@@ -1849,9 +1849,15 @@ var OpenRouterChatLanguageModel = class {
1849
1849
  const fileAnnotations = (_k = choice.message.annotations) == null ? void 0 : _k.filter(
1850
1850
  (a) => a.type === "file"
1851
1851
  );
1852
+ const hasToolCalls = choice.message.tool_calls && choice.message.tool_calls.length > 0;
1853
+ const hasEncryptedReasoning = reasoningDetails.some(
1854
+ (d) => d.type === "reasoning.encrypted" /* Encrypted */ && d.data
1855
+ );
1856
+ const shouldOverrideFinishReason = hasToolCalls && hasEncryptedReasoning && choice.finish_reason === "stop";
1857
+ const effectiveFinishReason = shouldOverrideFinishReason ? "tool-calls" : mapOpenRouterFinishReason(choice.finish_reason);
1852
1858
  return {
1853
1859
  content,
1854
- finishReason: mapOpenRouterFinishReason(choice.finish_reason),
1860
+ finishReason: effectiveFinishReason,
1855
1861
  usage: usageInfo,
1856
1862
  warnings: [],
1857
1863
  providerMetadata: {
@@ -1923,6 +1929,7 @@ var OpenRouterChatLanguageModel = class {
1923
1929
  };
1924
1930
  const openrouterUsage = {};
1925
1931
  const accumulatedReasoningDetails = [];
1932
+ const accumulatedFileAnnotations = [];
1926
1933
  let textStarted = false;
1927
1934
  let reasoningStarted = false;
1928
1935
  let textId;
@@ -2101,6 +2108,13 @@ var OpenRouterChatLanguageModel = class {
2101
2108
  }
2102
2109
  }
2103
2110
  });
2111
+ } else if (annotation.type === "file") {
2112
+ const file = annotation.file;
2113
+ if (file && typeof file === "object" && "hash" in file && "name" in file) {
2114
+ accumulatedFileAnnotations.push(
2115
+ annotation
2116
+ );
2117
+ }
2104
2118
  }
2105
2119
  }
2106
2120
  }
@@ -2229,6 +2243,13 @@ var OpenRouterChatLanguageModel = class {
2229
2243
  },
2230
2244
  flush(controller) {
2231
2245
  var _a16;
2246
+ const hasToolCalls = toolCalls.length > 0;
2247
+ const hasEncryptedReasoning = accumulatedReasoningDetails.some(
2248
+ (d) => d.type === "reasoning.encrypted" /* Encrypted */ && d.data
2249
+ );
2250
+ if (hasToolCalls && hasEncryptedReasoning && finishReason === "stop") {
2251
+ finishReason = "tool-calls";
2252
+ }
2232
2253
  if (finishReason === "tool-calls") {
2233
2254
  for (const toolCall of toolCalls) {
2234
2255
  if (toolCall && !toolCall.sent) {
@@ -2269,6 +2290,9 @@ var OpenRouterChatLanguageModel = class {
2269
2290
  if (accumulatedReasoningDetails.length > 0) {
2270
2291
  openrouterMetadata.reasoning_details = accumulatedReasoningDetails;
2271
2292
  }
2293
+ if (accumulatedFileAnnotations.length > 0) {
2294
+ openrouterMetadata.annotations = accumulatedFileAnnotations;
2295
+ }
2272
2296
  controller.enqueue({
2273
2297
  type: "finish",
2274
2298
  finishReason,
@@ -2820,7 +2844,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
2820
2844
  }
2821
2845
 
2822
2846
  // src/version.ts
2823
- var VERSION = false ? "0.0.0-test" : "1.5.1";
2847
+ var VERSION = false ? "0.0.0-test" : "1.5.3";
2824
2848
 
2825
2849
  // src/provider.ts
2826
2850
  function createOpenRouter(options = {}) {