Skip to content

feat: enrich model metadata via models.dev with local cache#1

Open
ricatix wants to merge 4 commits into
mdhb2:masterfrom
ricatix:master
Open

feat: enrich model metadata via models.dev with local cache#1
ricatix wants to merge 4 commits into
mdhb2:masterfrom
ricatix:master

Conversation

@ricatix

@ricatix ricatix commented Jun 11, 2026

Copy link
Copy Markdown

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+rename
  • src/models-dev.ts — Fetches models.dev/api.json, builds flat lookup index by model name across all providers. Cache-first, 15s fetch timeout, graceful fallback
  • **src/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 models
  • src/index.ts — Uses resolveModel() instead of ||= {} for each discovered model
  • src/cli.ts — Shows models.dev cache age in check command output

Behavior

Model ID type Example Result
Provider model (/ present) mistral/mistral-large-latest Full metadata: 262k ctx, cost, vision+tool_call
Combo model (no /) my-custom-combo Minimal template
Unknown model (/ present, no match) unknown/some-model Minimal template
models.dev unreachable any Minimal template (graceful fallback)

Tested

  • 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 ✓
  • Combo models → template fallback ✓
  • Cache: 2.2MB, created on first access, TTL 24h ✓

- 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.
ricatix and others added 3 commits June 13, 2026 08:49
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>
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