feat(models): dynamic open-source model catalog from CC provider API - #8
Merged
Conversation
Replace the fully hand-maintained models.json catalog with a hybrid: the CC provider /provider/v1/models endpoint is now the source of truth for the model list, display names, and context windows (1h TTL cache, modeled on fetchLatestCliVersion), while models.json keeps what the API never returns — aliases, reasoning efforts, max output tokens — and doubles as the offline fallback. Closed models (claude-*, gpt-*, google/* and other closed orgs) are filtered out so the proxy only exposes open-source models available on the GO plan. New CC models now appear without a proxy release. - new src/translate/catalog.ts: merge (static-first order preserves the default model), isClosedModel, TTL + inflight-deduped refreshCatalog - models.ts/server.ts/opencode.ts read the live catalog; opencode setup fetches it when a key is available (env or saved auth) - models.json: closedModelOrgs blocklist + metadata/aliases for the new open models (GLM-5.3, Qwen 3.8 family, Grok 4.6, Hy4, Muse Spark, Fugu, Laguna, free MiniMax variants, ...) Co-Authored-By: Claude <noreply@anthropic.com>
…helpers Post-review of PR #8: - remove fetchModelList (no remaining callers after server.ts migrated to refreshCatalog) - extract displayNameFor() to collapse the three display-name fallback chains in catalog.ts - share the URL-filtering CC models fetch mock between test files via tests/helpers.ts Co-Authored-By: Claude <noreply@anthropic.com>
Closes the four gaps flagged in the review of PR #8: - TTL expiry actually elapses and refetches (Date.now spy) - static entries survive when the API no longer lists them (retired upstream models keep static name/context, source: "static") - malformed payloads: data:null keeps the catalog; id-less and null items are skipped instead of discarding the whole refresh (also hardened the filter in catalog.ts for this); null context_length falls back to 128k - resolveAnthropicModel keeps the claude-* default pinned to the static first entry even when the API returns a reordered list 166 tests pass, typecheck clean. Co-Authored-By: Claude <noreply@anthropic.com>
Self-review pass: an API payload listing the same API-only id twice would append it twice to the catalog (the `seen` set only tracked static ids). Now the second loop adds to `seen` as well; first occurrence wins. Regression test included. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
/provider/v1/modelsAPI (1h TTL, in-memory cache), merged withmodels.jsonstatic-first so the default model staysdeepseek/deepseek-v4-pro.claude-*,gpt-*,google/*, …viaclosedModelOrgsblocklist) are filtered out — the proxy only exposes models usable on the GO plan.Key changes
src/translate/catalog.ts(new):getCatalog/refreshCatalog(TTL + inflight dedupe, never throws — falls back to static) /isClosedModel.src/translate/models.ts:resolveModel/getDefaultModelsread the dynamic catalog.src/server.ts:/v1/modelsserves the catalog (Anthropic-style responses now include realdisplay_name).src/setup/opencode.ts: generates the opencode config from the live catalog when a key is available (env or saved auth).Verification
vitest run: 162/162 pass (newtests/catalog.test.ts+ updated setup-opencode tests; tests mock fetch only for CC API URLs and mockreadAuthKeyso they never hit the real API)./v1/modelsreturns 44 open models, zero closed leaks, all new models present; Anthropic-style endpoint shows display names.🤖 Generated with Claude Code