Refuse a request for a model that isn't loaded; show the slug in /models

The MLX proxy rewrote every request's "model" to the preloaded one, so asking
for a model the server wasn't running returned another model's output wearing
the requested name -- silently. The rewrite itself has to stay (mlx_lm would
otherwise try to load a model matching the name), so validate first: a name
that is neither the served name nor its repo id gets 404 model_not_found,
naming what is loaded and how to switch. An unstated name still means "the
loaded one", and the key is still checked before the model.

opencode's /models hid the same trap twice over. Label models
`<title> · <slug> (<where>)` so the list is searchable by the id used
everywhere else -- titles alone had dropped the slug -- and mark the loaded
one `(Local, loaded)`, refreshed by both switch paths (CLI and dashboard)
through a new opencode.sync(), which only ever refreshes a block that is
already there.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Neil Bantoc 2026-11-03 00:38:35 -08:00
parent 8c6615dbb4
commit 2c0818ca2b
5 changed files with 78 additions and 11 deletions

View file

@ -350,6 +350,8 @@ def cmd_switch(a):
cfg["active"] = a.model
paths.save_config(cfg)
service.restart("model")
if opencode.sync(cfg):
say(f"Updated opencode's model list; {a.model} is the one marked loaded.")
say(f"Switched to {a.model}. Watch it load with: llmhost watch")