Skip to content

feat(models): dynamic open-source model catalog from CC provider API - #8

Merged
thaolaptrinh merged 4 commits into
mainfrom
feat/dynamic-model-catalog
Aug 30, 2026
Merged

feat(models): dynamic open-source model catalog from CC provider API#8
thaolaptrinh merged 4 commits into
mainfrom
feat/dynamic-model-catalog

Conversation

@thaolaptrinh

Copy link
Copy Markdown
Owner

What

  • Dynamic catalog: model list, display names, and context windows now come from the CC provider /provider/v1/models API (1h TTL, in-memory cache), merged with models.json static-first so the default model stays deepseek/deepseek-v4-pro.
  • Open-source only: closed models (claude-*, gpt-*, google/*, …via closedModelOrgs blocklist) are filtered out — the proxy only exposes models usable on the GO plan.
  • models.json is now a metadata layer: aliases, reasoning efforts, max output tokens (API never returns these) + offline fallback. Updated with the new open models (GLM-5.3, Qwen 3.8 family, Grok 4.6, Hy4, Muse Spark, Fugu, Laguna, free MiniMax, …).
  • New CC models now show up without a proxy release.

Key changes

  • src/translate/catalog.ts (new): getCatalog / refreshCatalog (TTL + inflight dedupe, never throws — falls back to static) / isClosedModel.
  • src/translate/models.ts: resolveModel/getDefaultModels read the dynamic catalog.
  • src/server.ts: /v1/models serves the catalog (Anthropic-style responses now include real display_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 (new tests/catalog.test.ts + updated setup-opencode tests; tests mock fetch only for CC API URLs and mock readAuthKey so they never hit the real API).
  • Live run: proxy started with a real key → /v1/models returns 44 open models, zero closed leaks, all new models present; Anthropic-style endpoint shows display names.

🤖 Generated with Claude Code

thaolaptrinh and others added 4 commits August 30, 2026 18:59
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>
@thaolaptrinh
thaolaptrinh merged commit ccf3354 into main Aug 30, 2026
2 checks passed
@thaolaptrinh
thaolaptrinh deleted the feat/dynamic-model-catalog branch August 30, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant