feat: support model variant in opencode provider path - #230
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for OpenCode model variants by introducing an optional opencodeVariant configuration value and threading it through all OpenCode structured-output calls as model.variant, enabling provider aliases that require explicit variant selection to work correctly.
Changes:
- Add
opencodeVariant?: stringto config parsing and documentation. - Extend
generateStructuredOutputto accept an optionalvariantand include it in the OpenCode request model object only when set. - Update structured-output call sites to pass
CONFIG.opencodeVariant, and add tests verifying inclusion/omission behavior.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/opencode-provider.test.ts | Adds assertions that model.variant is sent when provided and omitted when not provided. |
| tests/config-resolution.test.ts | Verifies opencodeVariant is parsed from project-scoped config alongside provider/model. |
| src/services/user-profile/user-profile-manager.ts | Passes CONFIG.opencodeVariant into structured-output calls used for profile operations. |
| src/services/user-profile/ai-cleanup.ts | Adds model.variant to the direct session.prompt request when configured. |
| src/services/user-memory-learning.ts | Passes CONFIG.opencodeVariant through structured-output paths in memory learning flows. |
| src/services/auto-capture.ts | Passes CONFIG.opencodeVariant to the structured-output call used by auto-capture analysis. |
| src/services/ai/opencode-provider.ts | Threads optional variant through both SDK and raw-fetch transports via sessionPromptFields. |
| src/config.ts | Introduces opencodeVariant config field, includes it in the template comments, and returns it in runtime config. |
| README.md | Documents the new opencodeVariant setting and its effect on OpenCode requests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Motivating issue: #169 (Auto Capture Failed — thinking/tool_choice incompatibility on models with thinking enabled). This PR addresses the root gap that issue exposed: opencode-mem could not express a model variant (e.g. thinking-off) in its structured-output calls, so auto-capture/user-profile failed on providers requiring the variant to be explicit. Adds optional opencodeVariant config forwarded as model.variant; no behavior change when unset. |
Problem
opencode-memsendsPOST /session/{id}/messagewith a model object containing onlyproviderIDandmodelID. The opencode SDK/API also accepts an optionalvarianton the model object (e.g.thinking-offfordeepseek-v4-flash).For custom provider aliases (like an
opencode-goalias for deepseek) some model variants require the variant to be sent explicitly — omitting it leads to a 401 /ProviderModelNotFoundErroron those aliases while the same model with a variant works.Change
Add an optional
opencodeVariantconfig field (string) that is forwarded verbatim asmodel.varianton every opencode structured-output request:src/config.ts: newopencodeVariant?: stringconfig field, parsed next toopencodeProvider/opencodeModel, plus sample config docs.src/services/ai/opencode-provider.ts:generateStructuredOutputacceptsvariantin opts and propagates it through both transports (v2 SDK client and raw fetch) viasessionPromptFields, which addsvariantto the model object only when set (no behavior change when unset).CONFIG.opencodeVariant:auto-capture.ts,user-memory-learning.ts(both profile analysis and learning-paths paths),user-profile/user-profile-manager.ts(dedup, conflict, description evolution), anduser-profile/ai-cleanup.ts(directsession.promptcall).README.md: documents the newopencodeVariantfield.Config
Tests
bun run typecheckpasses.bun test: 347 pass / 0 fail (added 2 tests inopencode-provider.test.tsasserting the variant is included in the model object when set and omitted when not, plus 1 config-resolution test).bun run build:tscdist build passes; the web build fails on pre-existing environment issues unrelated to this change (missingweb/node_modules+ TS 7baseUrlremoval), reproducible on a clean checkout.Backward compatibility
Fully optional: when
opencodeVariantis unset, the model object is byte-identical to before.