feat: enrich model metadata via models.dev with local cache#1
Open
ricatix wants to merge 4 commits into
Open
Conversation
- src/cache.ts: 24h TTL cache at ~/.cache/opencode-9router-plugin/
- src/models-dev.ts: fetch models.dev/api.json, build flat lookup index
- src/model-mapper.ts: map models.dev fields to OpenCode schema,
template fallback for combos/unmatched models
- src/index.ts: inject resolveModel() instead of empty {} per model
- src/cli.ts: show models.dev cache age in check command
Models with '/' in ID get real metadata (context, cost, capabilities).
Combo models without '/' use minimal template.
Falls back to template if models.dev unreachable.
Use the discovered full 9router model id for both API id and display name so models.dev metadata cannot remap requests to upstream provider credentials. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
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.
Summary
Enriches model entries with real metadata from models.dev instead of injecting empty
{}templates.What changed
src/cache.ts— 24-hour TTL cache at~/.cache/opencode-9router-plugin/models.dev.json, atomic write via temp+renamesrc/models-dev.ts— Fetchesmodels.dev/api.json, builds flat lookup index by model name across all providers. Cache-first, 15s fetch timeout, graceful fallbacksrc/model-mapper.ts\** — Maps models.dev fields to OpenCode schema (name, family, cost, context limits, modalities, capabilities). Minimal template fallback for combo models (no/`) and unmatched modelssrc/index.ts— UsesresolveModel()instead of||= {}for each discovered modelsrc/cli.ts— Shows models.dev cache age incheckcommand outputBehavior
/present)mistral/mistral-large-latest/)my-custom-combo/present, no match)unknown/some-modelTested
openai/gpt-4o→ 128k ctx, cost, text+image+pdf ✓anthropic/claude-sonnet-4-20250514→ 200k ctx, cost, text+image+pdf ✓google/gemini-2.5-flash→ 1M ctx, cost, text+image+audio+video+pdf ✓deepseek/deepseek-chat→ 1M ctx, cost, text ✓groq/llama-4-scout-17b-16e-instruct→ 128k ctx, cost, text+image ✓