opencode: offer one model, not a menu where four of five fail

Only one model is loaded at a time, so listing every model that fits gave a
picker with one working entry and four that now answer 404 -- and the entry that
worked changed id on every `llmhost switch`, invalidating any client's saved
default.

Replace the list with a single entry, `default`, which is a name the API itself
answers to: vLLM takes it as a second --served-model-name and still reports the
real slug, being first in the list; the MLX proxy accepts it as an alias. So
`llmhost/default` survives a switch. The local entry is labelled with whatever is
loaded, refreshed by both switch paths; a remote block is pasted once and never
refreshed, so it names no model rather than make a claim that goes stale.

Existing configs point at a specific model, which this provider no longer has and
opencode would reject, so configure() and sync() migrate `<prov>/<model>` to
`<prov>/default`. Other providers' defaults are untouched, and an older remote
block that still lists many models keeps working, including as the fallback when
the local provider is removed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Neil Bantoc 2026-11-03 02:26:34 -08:00
parent 51c2880a2e
commit 9af7f1e545
6 changed files with 124 additions and 50 deletions

View file

@ -72,8 +72,7 @@ A config with comments (`.jsonc`) is never rewritten, since that would drop them
**On another machine**, run `llmhost opencode-config` on the server. It prints a provider block and a one-liner
that copies the API key over. That block is named **LLMHost (<the server's hostname>)** — e.g. `LLMHost (popos.local)`
— under the provider id `llmhost-<shorthost>`. Only one model is loaded at a time; pick the one the server is
currently running.
— under the provider id `llmhost-<shorthost>`.
### One opencode, several servers
@ -85,11 +84,16 @@ of remote ones at once, each named after the machine it reaches:
| local | `llmhost` | `LLMHost (Local)` | read straight from `~/.config/llm-host/api_key` |
| remote | `llmhost-<shorthost>` | `LLMHost (<host>)` | copied to `~/.config/opencode/llmhost-<shorthost>.key` |
Models are listed as `<title> · <slug> (<where>)` — `Qwen3.8 27B · qwen3.8-27b (Local)` — so the picker is
searchable by the slug, which is the id used everywhere else (`--model llmhost/<slug>`, `llmhost switch <slug>`).
Since only one model is loaded at a time, the local provider marks the loaded one `(Local, loaded)` and
`llmhost switch` (and the dashboard) refresh that marker. Picking one of the others is not a silent mistake:
the API answers `404 model_not_found` naming what is actually loaded.
Each provider offers a **single model**, `default`, rather than every model that fits. One model is loaded at a
time, so a list of them would be a menu of one entry that works and the rest answering `404 model_not_found` —
and naming the loaded model would break the client's saved default on the next `llmhost switch`. `default` is a
name the API also answers to, so `llmhost/default` keeps working across switches: vLLM takes it as a second
`--served-model-name` (and still reports the real slug, being the first), and on a Mac the proxy accepts it as an
alias. The local entry is labelled with whatever is loaded — `Default model · Qwen3.8 27B (Local)` — and
`llmhost switch`, the dashboard and `llmhost update` keep that label current. A config that still points at a
specific model (`llmhost/qwen3.8-27b`) is migrated to `llmhost/default` the next time llm-host writes the block.
To serve a different model, switch the server: `llmhost switch <name>` or the dashboard. Clients don't choose.
Which block belongs to *this* machine is decided by the key-file reference it carries, not by its name. So the
provider is still recognised after you rename it, a remote provider that happens to sit under the `llmhost` id is