summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDominik Engelhardt <[email protected]>2025-07-25 18:19:44 +0200
committerGitHub <[email protected]>2025-07-25 12:19:44 -0400
commit827469c725aa0f0931b1ee211d7db1413c132dc9 (patch)
treebce52d1006c429e20e03b037d3f2f094ccc94c0f
parent613b5fbe4814397e8e874fa24a3c98f4e3ce2e4f (diff)
downloadopencode-827469c725aa0f0931b1ee211d7db1413c132dc9.tar.gz
opencode-827469c725aa0f0931b1ee211d7db1413c132dc9.zip
fix: apply content-level caching for non-anthropic providers (#1305)
-rw-r--r--packages/opencode/src/provider/transform.ts41
1 files changed, 29 insertions, 12 deletions
diff --git a/packages/opencode/src/provider/transform.ts b/packages/opencode/src/provider/transform.ts
index 9f3cf620c..50f9bbfa4 100644
--- a/packages/opencode/src/provider/transform.ts
+++ b/packages/opencode/src/provider/transform.ts
@@ -7,21 +7,38 @@ export namespace ProviderTransform {
const system = msgs.filter((msg) => msg.role === "system").slice(0, 2)
const final = msgs.filter((msg) => msg.role !== "system").slice(-2)
+ const providerOptions = {
+ anthropic: {
+ cacheControl: { type: "ephemeral" },
+ },
+ openrouter: {
+ cache_control: { type: "ephemeral" },
+ },
+ bedrock: {
+ cachePoint: { type: "ephemeral" },
+ },
+ openaiCompatible: {
+ cache_control: { type: "ephemeral" },
+ },
+ }
+
for (const msg of unique([...system, ...final])) {
+ const shouldUseContentOptions = providerID !== "anthropic" && Array.isArray(msg.content) && msg.content.length > 0
+
+ if (shouldUseContentOptions) {
+ const lastContent = msg.content[msg.content.length - 1]
+ if (lastContent && typeof lastContent === "object") {
+ lastContent.providerOptions = {
+ ...lastContent.providerOptions,
+ ...providerOptions,
+ }
+ continue
+ }
+ }
+
msg.providerOptions = {
...msg.providerOptions,
- anthropic: {
- cacheControl: { type: "ephemeral" },
- },
- openrouter: {
- cache_control: { type: "ephemeral" },
- },
- bedrock: {
- cachePoint: { type: "ephemeral" },
- },
- openaiCompatible: {
- cache_control: { type: "ephemeral" },
- },
+ ...providerOptions,
}
}
}