Skip to content

feat: support model variant in opencode provider path - #230

Open
Ghilteras wants to merge 1 commit into
tickernelz:mainfrom
Ghilteras:feat/opencode-variant
Open

feat: support model variant in opencode provider path#230
Ghilteras wants to merge 1 commit into
tickernelz:mainfrom
Ghilteras:feat/opencode-variant

Conversation

@Ghilteras

Copy link
Copy Markdown

Problem

opencode-mem sends POST /session/{id}/message with a model object containing only providerID and modelID. The opencode SDK/API also accepts an optional variant on the model object (e.g. thinking-off for deepseek-v4-flash).

For custom provider aliases (like an opencode-go alias for deepseek) some model variants require the variant to be sent explicitly — omitting it leads to a 401 / ProviderModelNotFoundError on those aliases while the same model with a variant works.

Change

Add an optional opencodeVariant config field (string) that is forwarded verbatim as model.variant on every opencode structured-output request:

  • src/config.ts: new opencodeVariant?: string config field, parsed next to opencodeProvider / opencodeModel, plus sample config docs.
  • src/services/ai/opencode-provider.ts: generateStructuredOutput accepts variant in opts and propagates it through both transports (v2 SDK client and raw fetch) via sessionPromptFields, which adds variant to the model object only when set (no behavior change when unset).
  • Callers pass 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), and user-profile/ai-cleanup.ts (direct session.prompt call).
  • README.md: documents the new opencodeVariant field.

Config

"opencodeProvider": "opencode-go",
"opencodeModel": "deepseek-v4-flash",
"opencodeVariant": "thinking-off"

Tests

  • bun run typecheck passes.
  • bun test: 347 pass / 0 fail (added 2 tests in opencode-provider.test.ts asserting the variant is included in the model object when set and omitted when not, plus 1 config-resolution test).
  • bun run build: tsc dist build passes; the web build fails on pre-existing environment issues unrelated to this change (missing web/node_modules + TS 7 baseUrl removal), reproducible on a clean checkout.

Backward compatibility

Fully optional: when opencodeVariant is unset, the model object is byte-identical to before.

Copilot AI review requested due to automatic review settings August 2, 2026 19:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?: string to config parsing and documentation.
  • Extend generateStructuredOutput to accept an optional variant and 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.

@Ghilteras

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants