Explorar o código

fix: ensure anthropic models on OR also have variant support (#13498)

Aiden Cline hai 1 mes
pai
achega
839c5cda12

+ 1 - 0
bun.lock

@@ -504,6 +504,7 @@
     "tree-sitter-bash",
   ],
   "patchedDependencies": {
+    "@openrouter/[email protected]": "patches/@openrouter%[email protected]",
     "@standard-community/[email protected]": "patches/@standard-community%[email protected]",
   },
   "overrides": {

+ 2 - 1
package.json

@@ -103,6 +103,7 @@
     "@types/node": "catalog:"
   },
   "patchedDependencies": {
-    "@standard-community/[email protected]": "patches/@standard-community%[email protected]"
+    "@standard-community/[email protected]": "patches/@standard-community%[email protected]",
+    "@openrouter/[email protected]": "patches/@openrouter%[email protected]"
   }
 }

+ 4 - 1
packages/opencode/src/provider/transform.ts

@@ -361,7 +361,7 @@ export namespace ProviderTransform {
 
     switch (model.api.npm) {
       case "@openrouter/ai-sdk-provider":
-        if (!model.id.includes("gpt") && !model.id.includes("gemini-3")) return {}
+        if (!model.id.includes("gpt") && !model.id.includes("gemini-3") && !model.id.includes("claude")) return {}
         return Object.fromEntries(OPENAI_EFFORTS.map((effort) => [effort, { reasoning: { effort } }]))
 
       case "@ai-sdk/gateway":
@@ -763,6 +763,9 @@ export namespace ProviderTransform {
       result["promptCacheKey"] = input.sessionID
     }
 
+    if (input.model.providerID === "openrouter") {
+      result["prompt_cache_key"] = input.sessionID
+    }
     if (input.model.api.npm === "@ai-sdk/gateway") {
       result["gateway"] = {
         caching: "auto",

+ 128 - 0
patches/@openrouter%[email protected]

@@ -0,0 +1,128 @@
+diff --git a/dist/index.js b/dist/index.js
+index f33510a50d11a2cb92a90ea70cc0ac84c89f29b9..e887a60352c0c08ab794b1e6821854dfeefd20cc 100644
+--- a/dist/index.js
++++ b/dist/index.js
+@@ -2110,7 +2110,12 @@ var OpenRouterChatLanguageModel = class {
+               if (reasoningStarted && !textStarted) {
+                 controller.enqueue({
+                   type: "reasoning-end",
+-                  id: reasoningId || generateId()
++                  id: reasoningId || generateId(),
++                  providerMetadata: accumulatedReasoningDetails.length > 0 ? {
++                    openrouter: {
++                      reasoning_details: accumulatedReasoningDetails
++                    }
++                  } : undefined
+                 });
+                 reasoningStarted = false;
+               }
+@@ -2307,7 +2312,12 @@ var OpenRouterChatLanguageModel = class {
+             if (reasoningStarted) {
+               controller.enqueue({
+                 type: "reasoning-end",
+-                id: reasoningId || generateId()
++                id: reasoningId || generateId(),
++                providerMetadata: accumulatedReasoningDetails.length > 0 ? {
++                  openrouter: {
++                    reasoning_details: accumulatedReasoningDetails
++                  }
++                } : undefined
+               });
+             }
+             if (textStarted) {
+diff --git a/dist/index.mjs b/dist/index.mjs
+index 8a688331b88b4af738ee4ca8062b5f24124d3d81..6310cb8b7c8d0a728d86e1eed09906c6b4c91ae2 100644
+--- a/dist/index.mjs
++++ b/dist/index.mjs
+@@ -2075,7 +2075,12 @@ var OpenRouterChatLanguageModel = class {
+               if (reasoningStarted && !textStarted) {
+                 controller.enqueue({
+                   type: "reasoning-end",
+-                  id: reasoningId || generateId()
++                  id: reasoningId || generateId(),
++                  providerMetadata: accumulatedReasoningDetails.length > 0 ? {
++                    openrouter: {
++                      reasoning_details: accumulatedReasoningDetails
++                    }
++                  } : undefined
+                 });
+                 reasoningStarted = false;
+               }
+@@ -2272,7 +2277,12 @@ var OpenRouterChatLanguageModel = class {
+             if (reasoningStarted) {
+               controller.enqueue({
+                 type: "reasoning-end",
+-                id: reasoningId || generateId()
++                id: reasoningId || generateId(),
++                providerMetadata: accumulatedReasoningDetails.length > 0 ? {
++                  openrouter: {
++                    reasoning_details: accumulatedReasoningDetails
++                  }
++                } : undefined
+               });
+             }
+             if (textStarted) {
+diff --git a/dist/internal/index.js b/dist/internal/index.js
+index d40fa66125941155ac13a4619503caba24d89f8a..8dd86d1b473f2fa31c1acd9881d72945b294a197 100644
+--- a/dist/internal/index.js
++++ b/dist/internal/index.js
+@@ -2064,7 +2064,12 @@ var OpenRouterChatLanguageModel = class {
+               if (reasoningStarted && !textStarted) {
+                 controller.enqueue({
+                   type: "reasoning-end",
+-                  id: reasoningId || generateId()
++                  id: reasoningId || generateId(),
++                  providerMetadata: accumulatedReasoningDetails.length > 0 ? {
++                    openrouter: {
++                      reasoning_details: accumulatedReasoningDetails
++                    }
++                  } : undefined
+                 });
+                 reasoningStarted = false;
+               }
+@@ -2261,7 +2266,12 @@ var OpenRouterChatLanguageModel = class {
+             if (reasoningStarted) {
+               controller.enqueue({
+                 type: "reasoning-end",
+-                id: reasoningId || generateId()
++                id: reasoningId || generateId(),
++                providerMetadata: accumulatedReasoningDetails.length > 0 ? {
++                  openrouter: {
++                    reasoning_details: accumulatedReasoningDetails
++                  }
++                } : undefined
+               });
+             }
+             if (textStarted) {
+diff --git a/dist/internal/index.mjs b/dist/internal/index.mjs
+index b0ed9d113549c5c55ea3b1e08abb3db6f92ae5a7..5695930a8e038facc071d58a4179a369a29be9c7 100644
+--- a/dist/internal/index.mjs
++++ b/dist/internal/index.mjs
+@@ -2030,7 +2030,12 @@ var OpenRouterChatLanguageModel = class {
+               if (reasoningStarted && !textStarted) {
+                 controller.enqueue({
+                   type: "reasoning-end",
+-                  id: reasoningId || generateId()
++                  id: reasoningId || generateId(),
++                  providerMetadata: accumulatedReasoningDetails.length > 0 ? {
++                    openrouter: {
++                      reasoning_details: accumulatedReasoningDetails
++                    }
++                  } : undefined
+                 });
+                 reasoningStarted = false;
+               }
+@@ -2227,7 +2232,12 @@ var OpenRouterChatLanguageModel = class {
+             if (reasoningStarted) {
+               controller.enqueue({
+                 type: "reasoning-end",
+-                id: reasoningId || generateId()
++                id: reasoningId || generateId(),
++                providerMetadata: accumulatedReasoningDetails.length > 0 ? {
++                  openrouter: {
++                    reasoning_details: accumulatedReasoningDetails
++                  }
++                } : undefined
+               });
+             }
+             if (textStarted) {