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

@ -82,6 +82,18 @@ check("200 when absent", post(None)[0] == 200)
check("200 when empty", post("")[0] == 200)
check("200 when blank", post(" ")[0] == 200)
check.section("4b. the stable alias always means whatever is loaded")
from llmhost import plan
check("alias accepted", post(plan.SERVED_ALIAS)[0] == 200, post(plan.SERVED_ALIAS)[0])
check("alias is 'default'", plan.SERVED_ALIAS == "default")
seen.clear()
post(plan.SERVED_ALIAS)
check("still forwarded as default_model", seen and seen[-1].get("model") == "default_model", seen[-1] if seen else None)
check("vLLM is told to serve it as a second name",
plan.vllm_args({"name": "m", "context": 1024}, {"repo": "r", "util": 0.9}, 8000, 1)[1:4]
== ["--served-model-name", "m", plan.SERVED_ALIAS],
plan.vllm_args({"name": "m", "context": 1024}, {"repo": "r", "util": 0.9}, 8000, 1)[:5])
print("\n5. a model that ISN'T loaded is refused, not silently answered")
code, body = post("qwen3.8-27b")
check("404", code == 404, code)