Skip to content

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

Open

Description

@rwjxrj

Problem / motivation

Tag migration needs a model that works without a live session, so isOpencodeTagMigrationConfigured() in src/services/api-handlers.ts deliberately rejects "opencodeModel": "inherit":

// "inherit" needs a live session model; tag migration has none.
return Boolean(CONFIG.opencodeProvider && CONFIG.opencodeModel && CONFIG.opencodeModel !== "inherit");

"inherit" is what the README recommends for auto-capture, and it works there now (thanks to #453 / #508). But the moment you open the Web UI and let it migrate tags, every batch fails with

No tag-migration provider configured. Set opencodeProvider/opencodeModel or memoryModel/memoryApiUrl/memoryApiKey.

The UI cannot tell you that before you click, and cannot fix it: no /api/* route reads or writes config, so the only option is to open ~/.config/opencode/opencode-mem.jsonc by hand, replace "inherit" with a concrete model id, and restart OpenCode. That is exactly the hand-editing this plugin is supposed to spare people from.

Proposed solution

Already implemented locally on a branch; no new dependencies.

Backend:

  1. GET /api/config/model-provider — returns the configured providerID/modelID, whether the migration path would accept them, and the provider/model directory, including which providers are connected. On v2 hosts the directory comes from ctx.provider.list() + ctx.model.list() (the legacy client only exposes connected), with the v1 provider.list() shape as fallback. Reports available: false plus a reason when no directory is reachable.
  2. PUT /api/config/model-provider — validates both ids, rewrites only opencodeProvider / opencodeModel in the config file that already supplied them (project file if it sets either key, else the first existing global file), preserving comments, trailing commas and CRLF, re-parsing the result before an atomic rename. On success the plugin reloads config in-process through a reloadConfig callback, so no restart is needed.

Web UI:

  • The tag-migration dialog gets a provider → model pair of selects and a save button; "Start migration" stays disabled until a concrete model is configured.
  • The same picker is a shared component, also reachable any time from a new sidebar entry Model (/model-settings), with a note that these two keys are shared with auto-capture.
  • Sim mode (OPENCODE_MEM_SIM=1) answers the new endpoints from a fixture, so the picker is demoable offline.

Screenshots (attached): blocked dialog with inherit, saved state, the new Model page.

Alternatives considered

  • Treat inherit as configured for migration and fail at runtime. Same dead end, just later.
  • Add UI for the manual API channel too (memoryModel / memoryApiUrl / memoryApiKey). Would also solve it, but means accepting an API key in the browser UI — bigger surface, separate concern.
  • Write the config but require a restart. Simpler, but the UI then reports "saved" while still refusing to migrate.
  • Only extend /api/migration/tags/detect. It reports count, not whether a provider exists, so the UI still could not explain the failure before it happens.
  • Parse the JSONC with a library. Not needed for two known keys; the writer does line-level replacement and self-checks with the existing stripJsoncComments.

Additional context

  • Branch feat/web-model-selector, 9 commits: config writer + 12 unit tests, catalog/route, dialog picker, three fixes found by real use (model ids containing /, a config comment mentioning /api/* confusing the writer's comment tracking, and the in-process reload needing the plugin's own config instance), the Model page, and sim support.
  • Verified against a real OpenCode v2 host on Windows: catalog lists the connected providers, saving takes effect without a restart, and the config file keeps its comments and a single copy of each key.
  • bun run check and bun run web:build pass. bun test: new tests pass; remaining failures reproduce on main here (profile runtime timeouts, onnxruntime shim, the 500-memory portability test under load).
  • Questions before I open a PR:
    1. Does a writable Web UI fit the direction you want, or would you rather keep it read-only and solve this in config/inherit handling?
    2. Writing back to the project config file when it already sets these keys, vs always the global file — any preference?
    3. Is in-process reload acceptable, or should the UI ask for a restart?
    4. Should getAutoCaptureProviderStatus() also flag inherit as not migration-ready? Today it reports ready, which is why the mismatch is invisible until a batch fails. (I left it alone.)
1-inherit-blocked 2-model-saved 6-model-page

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions