Skip to content

Commit ad8bb4d

Browse files
rootroot
authored andcommitted
fix(provider): use deep merge for providerOptions in applyCaching - Issue anomalyco#10241
- Change from shallow spread (...) to mergeDeep() for provider options - Fixes bug where applyCaching overrides previous provider options - Preserves interleaving options from normalizeMessages transform - Ensures all provider options are properly merged instead of replaced Root cause: The spread operator ({...a, ...b}) overwrites properties instead of deep merging them, causing options set in earlier transforms to be lost. Example: OpenAI-compatible provider with Claude model uses interleaving (set in normalizeMessages), but applyCaching was overwriting these options. Fix: Use remeda's mergeDeep() to properly merge nested option objects.
1 parent 04b511e commit ad8bb4d

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

‎packages/opencode/src/provider/transform.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { APICallError, ModelMessage } from "ai"
2-
import { unique } from "remeda"
2+
import { mergeDeep, unique } from "remeda"
33
import type { JSONSchema } from "zod/v4/core"
44
import type { Provider } from "./provider"
55
import type { ModelsDev } from "./models"
@@ -186,18 +186,18 @@ export namespace ProviderTransform {
186186
if (shouldUseContentOptions) {
187187
const lastContent = msg.content[msg.content.length - 1]
188188
if (lastContent && typeof lastContent === "object") {
189-
lastContent.providerOptions = {
190-
...lastContent.providerOptions,
191-
...providerOptions,
192-
}
189+
lastContent.providerOptions = mergeDeep(
190+
lastContent.providerOptions ?? {},
191+
providerOptions[providerID as keyof typeof providerOptions] ?? providerOptions.anthropic
192+
)
193193
continue
194194
}
195195
}
196196

197-
msg.providerOptions = {
198-
...msg.providerOptions,
199-
...providerOptions,
200-
}
197+
msg.providerOptions = mergeDeep(
198+
msg.providerOptions ?? {},
199+
providerOptions[providerID as keyof typeof providerOptions] ?? providerOptions.anthropic
200+
)
201201
}
202202

203203
return msgs

0 commit comments

Comments
 (0)