feat(opencode): add auto model detection for OpenAI-compatible providers
What does this PR do?
This PR adds automatic model detection/discovery for providers that use npm: @ai-sdk/openai-compatible. It allows OpenCode to utilize the GET /v1/models API to populate the model list.
Models may come from 3 sources now: Models.dev, config file, and detected via API. The "filtering" logic is: the model will be visible, if it's detected via API or declared in config file; if it is visible, its metadata will be merged from API -> config -> Models.dev (with prescedence from high to low).
Fixes #6231 Fixes #4232 Fixes #2456
Note: I understand it may be by design to rely entirely on Models.dev for providers and models, but having OpenCode core automatically populate the model list would be a major improvement for users running LM Studio or other local providers.
How did you verify your code works?
- I ran an LM Studio server locally and downloaded two models (
openai/gpt-oss-20bandzai-org/glm-4.6v-flash). - I configured my
~/.config/opencode/opencode.jsonwith two LM Studio providers and two models. One of the models does not exist in LM Studio, but should still appear later. (File attached: opencode.json). - I used a debugger and breakpoints to inspect the
providersvalue atpackages/opencode/src/provider/provider.ts#958, and it looked correct to me. - I ran
bun dev -- models, and the output looked correct. - I launched the TUI with
bun dev, ran/models, and the output also looked correct. - From the TUI, I was able to use both local models in LM Studio and cloud models I had previously configured.
- I shut down the LM Studio server and repeated steps 3–6; everything behaved as expected.