Skip to content

feat(web): add model selector for structured-output providers - #515

Open
rwjxrj wants to merge 9 commits into
tickernelz:mainfrom
rwjxrj:feat/web-model-selector
Open

rwjxrj wants to merge 9 commits into
tickernelz:mainfrom
rwjxrj:feat/web-model-selector

Conversation

@rwjxrj

@rwjxrj rwjxrj commented Nov 20, 2026

Copy link
Copy Markdown

Summary

Fixes #514.

Tag migration and auto-capture share opencodeProvider/opencodeModel. On the migration path there is no live session, so "inherit" cannot resolve (isOpencodeTagMigrationConfigured() rejects it) and the only workaround today is hand-editing opencode-mem.jsonc and restarting. This adds a model picker to the web UI:

  • GET/PUT /api/config/model-provider: a provider/model catalog for the connected providers, plus a writer that updates the existing jsonc config in place. Comments, trailing commas and every other key are preserved; the result is re-parsed before it is written, and the write goes through a temp file + rename, so a failure leaves the original file untouched.
  • The catalog is read from the native v2 context (ctx.provider.list() + ctx.model.list()), with the legacy client.provider.list() path as a fallback for v1.
  • The config is reloaded in-process after a successful write. The web server receives the plugin's own reloadConfig callback, because a lazily imported copy of the config module is a second instance when the plugin is bundled.
  • UI: a shared ModelPicker used by the tag migration dialog and by a new sidebar page Model (/model-settings). The dialog disables Start migration until an explicit model is configured.
  • Sim mode (OPENCODE_MEM_SIM=1) serves the new endpoints, so the picker works offline in bun run web:dev.
  • The writer lives in src/services/model-config-writer.ts and has 12 unit tests.

The external channel (memoryModel/memoryApiUrl/memoryApiKey) is intentionally out of scope: it needs key input, which belongs in a separate change.

Test plan

  • Exercised the change locally (real instance on port 4747 and OPENCODE_MEM_SIM=1 dev server)
  • Noted any follow-up or known limitations: the reload is in-process only, and a project-level config file that sets these keys still wins (the picker then reports the effective value instead of claiming success). getAutoCaptureProviderStatus() still treats inherit as ready — deliberately untouched here.

Commands:

  • bun test — 1247 pass, and the 5–7 failures are the same ones a clean main produces in this environment (onnxruntime resolve shim, memory profile runtime timeouts, one portability test under load). tests/model-config-writer.test.ts is 12/12.
  • bun run typecheck, bun run check, bun run web:build — pass (svelte-check reports 0 errors).
  • Manual: picked magpie / auto/glm-5.3-flash, saved, verified comments and trailing commas survived and the file has each key exactly once, confirmed the dialog's Start button becomes enabled without a restart; then saved inherit again and confirmed the dialog goes back to "needs an explicit model".

Checklist

  • Branch is based on main (do not open PRs from commits already on main)
  • bun test passes (or N/A)
  • bun run typecheck passes (or N/A)
  • bun run check passes (format + lint + typecheck; or N/A)
  • Docs / README updated when behavior or contribution process changes

Locates the config file that already supplies opencodeProvider/opencodeModel (project file first, then the first global file) and rewrites just those two values in place, keeping comments, trailing commas and CRLF. The rewritten text is re-parsed before an atomic write, so a bad edit never lands.
The host already lists connected providers; cache that directory on the plugin side because the lazy V2 client only proxies session calls. GET/PUT /api/config/model-provider then lets the web UI read the directory and save an explicit provider/model for tag migration, reloading config in place.
Tag migration rejects the inherit model because it has no live session, so the dialog now shows the configured provider/model, lists connected providers and their models, and saves a selection before starting. The start button stays disabled until a concrete model is configured.
The block-comment scan treated any /* in a line, including one inside a
line comment such as "Protects /api/* with a token.", as opening a block,
so every later key was skipped and each save appended another pair. Track
the comment state per line instead, and reload through the plugin config
instance because the lazily imported module is a second copy under
bundling.
The tag migration dialog could pick a provider and model, but only when it
opened on its own. The sidebar now links to /model-settings, which renders the
same picker as a page, plus a note that the two keys are shared with
auto-capture.
Drop the unused onSaved callback and the extra padding wrapper inside
BorderedPanel, which already supplies its own. README now lists six views.
Sim mode had no answer for /api/config/model-provider, so the picker always
showed the unavailable branch. Serve the catalog from a fixture and keep PUT
selections for the session, matching the other simulated mutations.

This branch has not been deployed

No deployments
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.

Feature Request: Web UI model picker for the shared opencode provider/model

1 participant