summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bun.lock1
-rw-r--r--package.json3
-rw-r--r--packages/opencode/src/provider/transform.ts5
-rw-r--r--patches/@openrouter%[email protected]128
4 files changed, 135 insertions, 2 deletions
diff --git a/bun.lock b/bun.lock
index 2b4c4993a..c29176596 100644
--- a/bun.lock
+++ b/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": {
diff --git a/package.json b/package.json
index c4408e264..5d9320505 100644
--- a/package.json
+++ b/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]"
}
}
diff --git a/packages/opencode/src/provider/transform.ts b/packages/opencode/src/provider/transform.ts
index 1c92f528e..853d03c1d 100644
--- a/packages/opencode/src/provider/transform.ts
+++ b/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",
diff --git a/patches/@openrouter%[email protected] b/patches/@openrouter%[email protected]
new file mode 100644
index 000000000..6226bf790
--- /dev/null
+++ b/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) {