mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-05 08:02:53 +00:00
fix: nested modalities, per-tier metadata, drop committed cache
- capabilityModel now reads the nested modalities.{input,output} object
the catalog actually serves; the old top-level input/output tags
never matched and left both arrays permanently empty.
- Metadata is stored per tier and /v1/models selects by route.Tier,
so same-named Zen/Go models (glm-5, minimax-m3, ...) advertise the
limits of the tier that will serve them. Anonymous routes resolve
to TierZen, keeping the keyless path on Zen metadata.
- Cache schema 2 -> 3; stale flat caches are refused and fall back
to live refresh.
- Untrack config.json.models.catalog.json and ignore
*.models.catalog.json: it is a runtime snapshot, not source.
- Add models_test.go fixtures: nested modalities, tier-split limits,
tier selection, v3 round-trip, v2 rejection.
This commit is contained in:
1 parent
f3593e3790
commit
ce89cc01cb
5 files changed
+244
-1011
No files matched your search
@@ -7,3 +7,4 @@ opencode2api.exe
|
||||
*.log
|
||||
.tmp/
|
||||
.gocache/
|
||||
*.models.catalog.json
|
||||
@@ -1,973 +0,0 @@
|
||||
{
|
||||
"schema_version": 2,
|
||||
"updated_at": "2026-09-04T05:22:53.853695398Z",
|
||||
"zen": [
|
||||
"big-pickle",
|
||||
"claude-fable-5",
|
||||
"claude-fable-5-1",
|
||||
"claude-haiku-4-5",
|
||||
"claude-opus-4-5",
|
||||
"claude-opus-4-6",
|
||||
"claude-opus-4-7",
|
||||
"claude-opus-4-8",
|
||||
"claude-opus-5",
|
||||
"claude-sonnet-4",
|
||||
"claude-sonnet-4-5",
|
||||
"claude-sonnet-4-6",
|
||||
"claude-sonnet-5",
|
||||
"deepseek-v4-flash",
|
||||
"deepseek-v4-flash-free",
|
||||
"deepseek-v4-pro",
|
||||
"gemini-3-flash",
|
||||
"gemini-3.1-pro",
|
||||
"gemini-3.5-flash",
|
||||
"gemini-3.5-flash-lite",
|
||||
"gemini-3.6-flash",
|
||||
"gemini-3.7-flash",
|
||||
"gemini-3.8-flash",
|
||||
"glm-5",
|
||||
"glm-5.1",
|
||||
"glm-5.2",
|
||||
"gpt-5",
|
||||
"gpt-5-codex",
|
||||
"gpt-5-nano",
|
||||
"gpt-5.1",
|
||||
"gpt-5.1-codex",
|
||||
"gpt-5.1-codex-max",
|
||||
"gpt-5.1-codex-mini",
|
||||
"gpt-5.2",
|
||||
"gpt-5.2-codex",
|
||||
"gpt-5.3-codex",
|
||||
"gpt-5.3-codex-spark",
|
||||
"gpt-5.4",
|
||||
"gpt-5.4-mini",
|
||||
"gpt-5.4-nano",
|
||||
"gpt-5.4-pro",
|
||||
"gpt-5.5",
|
||||
"gpt-5.5-pro",
|
||||
"gpt-5.6-luna",
|
||||
"gpt-5.6-sol",
|
||||
"gpt-5.6-terra",
|
||||
"grok-4.5",
|
||||
"grok-4.6",
|
||||
"grok-build-0.1",
|
||||
"kimi-k2.5",
|
||||
"kimi-k2.6",
|
||||
"kimi-k2.7-code",
|
||||
"kimi-k3",
|
||||
"laguna-s-2.1-free",
|
||||
"ling-3.0-flash-fin-free",
|
||||
"mimo-v2.5-free",
|
||||
"minimax-m2.5",
|
||||
"minimax-m2.7",
|
||||
"minimax-m3",
|
||||
"muse-spark-1.2",
|
||||
"muse-spark-1.2-contributor-free",
|
||||
"muse-spark-1.3-contributor-free",
|
||||
"nemotron-3-ultra-free",
|
||||
"nemotron-3.5-lightning-free",
|
||||
"qwen3.5-plus",
|
||||
"qwen3.6-plus"
|
||||
],
|
||||
"go": [],
|
||||
"native_protocols": {
|
||||
"go": {
|
||||
"deepseek-v4-flash": "chat",
|
||||
"deepseek-v4-flash-vision-exp": "chat",
|
||||
"deepseek-v4-pro": "chat",
|
||||
"glm-5": "chat",
|
||||
"glm-5.1": "chat",
|
||||
"glm-5.2": "chat",
|
||||
"glm-5.3": "chat",
|
||||
"glm-5.3-flash": "chat",
|
||||
"gpt-5.6-luna": "responses",
|
||||
"grok-4.5": "responses",
|
||||
"grok-4.6": "responses",
|
||||
"hy3": "chat",
|
||||
"hy4-preview": "chat",
|
||||
"kimi-k2.5": "chat",
|
||||
"kimi-k2.6": "chat",
|
||||
"kimi-k2.7-code": "chat",
|
||||
"kimi-k3": "chat",
|
||||
"longcat-2.0": "chat",
|
||||
"mimo-v2-omni": "chat",
|
||||
"mimo-v2-pro": "chat",
|
||||
"mimo-v2.5": "chat",
|
||||
"mimo-v2.5-pro": "chat",
|
||||
"minimax-m2.5": "anthropic",
|
||||
"minimax-m2.7": "anthropic",
|
||||
"minimax-m3": "anthropic",
|
||||
"muse-spark-1.2-contributor": "responses",
|
||||
"muse-spark-1.3-contributor": "responses",
|
||||
"omen-alpha": "chat",
|
||||
"ox-alpha-free": "chat",
|
||||
"qwen3.5-plus": "chat",
|
||||
"qwen3.6-plus": "anthropic",
|
||||
"qwen3.7-max": "anthropic",
|
||||
"qwen3.7-plus": "anthropic",
|
||||
"qwen3.8-flash": "anthropic",
|
||||
"qwen3.8-max": "anthropic"
|
||||
},
|
||||
"zen": {
|
||||
"big-pickle": "chat",
|
||||
"claude-3-5-haiku": "anthropic",
|
||||
"claude-fable-5": "anthropic",
|
||||
"claude-fable-5-1": "anthropic",
|
||||
"claude-haiku-4-5": "anthropic",
|
||||
"claude-opus-4-1": "anthropic",
|
||||
"claude-opus-4-5": "anthropic",
|
||||
"claude-opus-4-6": "anthropic",
|
||||
"claude-opus-4-7": "anthropic",
|
||||
"claude-opus-4-8": "anthropic",
|
||||
"claude-opus-5": "anthropic",
|
||||
"claude-sonnet-4": "anthropic",
|
||||
"claude-sonnet-4-5": "anthropic",
|
||||
"claude-sonnet-4-6": "anthropic",
|
||||
"claude-sonnet-5": "anthropic",
|
||||
"deepseek-v4-flash": "chat",
|
||||
"deepseek-v4-flash-free": "chat",
|
||||
"deepseek-v4-pro": "chat",
|
||||
"glm-4.6": "chat",
|
||||
"glm-4.7": "chat",
|
||||
"glm-4.7-free": "chat",
|
||||
"glm-5": "chat",
|
||||
"glm-5-free": "chat",
|
||||
"glm-5.1": "chat",
|
||||
"glm-5.2": "chat",
|
||||
"gpt-5": "responses",
|
||||
"gpt-5-codex": "responses",
|
||||
"gpt-5-nano": "responses",
|
||||
"gpt-5.1": "responses",
|
||||
"gpt-5.1-codex": "responses",
|
||||
"gpt-5.1-codex-max": "responses",
|
||||
"gpt-5.1-codex-mini": "responses",
|
||||
"gpt-5.2": "responses",
|
||||
"gpt-5.2-codex": "responses",
|
||||
"gpt-5.3-codex": "responses",
|
||||
"gpt-5.3-codex-spark": "responses",
|
||||
"gpt-5.4": "responses",
|
||||
"gpt-5.4-mini": "responses",
|
||||
"gpt-5.4-nano": "responses",
|
||||
"gpt-5.4-pro": "responses",
|
||||
"gpt-5.5": "responses",
|
||||
"gpt-5.5-pro": "responses",
|
||||
"gpt-5.6-luna": "responses",
|
||||
"gpt-5.6-sol": "responses",
|
||||
"gpt-5.6-terra": "responses",
|
||||
"grok-4.5": "responses",
|
||||
"grok-4.6": "responses",
|
||||
"grok-build-0.1": "responses",
|
||||
"grok-code": "chat",
|
||||
"hy3-free": "chat",
|
||||
"hy3-preview-free": "chat",
|
||||
"kimi-k2": "chat",
|
||||
"kimi-k2-thinking": "chat",
|
||||
"kimi-k2.5": "chat",
|
||||
"kimi-k2.5-free": "chat",
|
||||
"kimi-k2.6": "chat",
|
||||
"kimi-k2.7-code": "chat",
|
||||
"kimi-k3": "chat",
|
||||
"laguna-s-2.1-free": "chat",
|
||||
"ling-2.6-flash-free": "chat",
|
||||
"ling-3.0-flash-fin-free": "chat",
|
||||
"ling-3.0-flash-free": "chat",
|
||||
"ling-3.0-tiny-free": "chat",
|
||||
"longcat-2.0-free": "chat",
|
||||
"mimo-v2-flash-free": "chat",
|
||||
"mimo-v2-omni-free": "chat",
|
||||
"mimo-v2-pro-free": "chat",
|
||||
"mimo-v2.5-free": "chat",
|
||||
"minimax-m2.1": "chat",
|
||||
"minimax-m2.1-free": "anthropic",
|
||||
"minimax-m2.5": "chat",
|
||||
"minimax-m2.5-free": "anthropic",
|
||||
"minimax-m2.7": "chat",
|
||||
"minimax-m3": "chat",
|
||||
"minimax-m3-free": "anthropic",
|
||||
"muse-spark-1.2": "responses",
|
||||
"muse-spark-1.2-contributor-free": "responses",
|
||||
"muse-spark-1.3-contributor-free": "responses",
|
||||
"nemotron-3-super-free": "chat",
|
||||
"nemotron-3-ultra-free": "chat",
|
||||
"nemotron-3.5-lightning-free": "chat",
|
||||
"north-mini-code-free": "chat",
|
||||
"qwen3-coder": "chat",
|
||||
"qwen3.5-plus": "anthropic",
|
||||
"qwen3.6-plus": "anthropic",
|
||||
"qwen3.6-plus-free": "anthropic",
|
||||
"qwen3.7-max": "anthropic",
|
||||
"qwen3.7-plus": "anthropic",
|
||||
"ring-2.6-1t-free": "chat",
|
||||
"trinity-large-preview-free": "chat",
|
||||
"x-preview-f-free": "chat"
|
||||
}
|
||||
},
|
||||
"unsupported": {
|
||||
"go": {},
|
||||
"zen": {
|
||||
"gemini-3-flash": true,
|
||||
"gemini-3-pro": true,
|
||||
"gemini-3.1-pro": true,
|
||||
"gemini-3.5-flash": true,
|
||||
"gemini-3.5-flash-lite": true,
|
||||
"gemini-3.6-flash": true,
|
||||
"gemini-3.7-flash": true,
|
||||
"gemini-3.8-flash": true
|
||||
}
|
||||
},
|
||||
"metadata": {
|
||||
"big-pickle": {
|
||||
"context_window": 200000,
|
||||
"max_input": 160000,
|
||||
"max_output": 32000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"claude-3-5-haiku": {
|
||||
"context_window": 200000,
|
||||
"max_output": 8192,
|
||||
"tool_call": true
|
||||
},
|
||||
"claude-fable-5": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"claude-fable-5-1": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"claude-haiku-4-5": {
|
||||
"context_window": 200000,
|
||||
"max_output": 64000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"claude-opus-4-1": {
|
||||
"context_window": 200000,
|
||||
"max_output": 32000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"claude-opus-4-5": {
|
||||
"context_window": 200000,
|
||||
"max_output": 64000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"claude-opus-4-6": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"claude-opus-4-7": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"claude-opus-4-8": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"claude-opus-5": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"claude-sonnet-4": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 64000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"claude-sonnet-4-5": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 64000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"claude-sonnet-4-6": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 64000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"claude-sonnet-5": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"deepseek-v4-flash": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 384000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"deepseek-v4-flash-free": {
|
||||
"context_window": 200000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"deepseek-v4-flash-vision-exp": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 384000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"deepseek-v4-pro": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 384000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gemini-3-flash": {
|
||||
"context_window": 1048576,
|
||||
"max_output": 65536,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gemini-3-pro": {
|
||||
"context_window": 1048576,
|
||||
"max_output": 65536,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gemini-3.1-pro": {
|
||||
"context_window": 1048576,
|
||||
"max_output": 65536,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gemini-3.5-flash": {
|
||||
"context_window": 1048576,
|
||||
"max_output": 65536,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gemini-3.5-flash-lite": {
|
||||
"context_window": 1048576,
|
||||
"max_output": 65536,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gemini-3.6-flash": {
|
||||
"context_window": 1048576,
|
||||
"max_output": 65536,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gemini-3.7-flash": {
|
||||
"context_window": 1048576,
|
||||
"max_output": 65536,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gemini-3.8-flash": {
|
||||
"context_window": 1048576,
|
||||
"max_output": 65536,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"glm-4.6": {
|
||||
"context_window": 204800,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"glm-4.7": {
|
||||
"context_window": 204800,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"glm-4.7-free": {
|
||||
"context_window": 204800,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"glm-5": {
|
||||
"context_window": 204800,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"glm-5-free": {
|
||||
"context_window": 204800,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"glm-5.1": {
|
||||
"context_window": 204800,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"glm-5.2": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"glm-5.3": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"glm-5.3-flash": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gpt-5": {
|
||||
"context_window": 400000,
|
||||
"max_input": 272000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gpt-5-codex": {
|
||||
"context_window": 400000,
|
||||
"max_input": 272000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gpt-5-nano": {
|
||||
"context_window": 400000,
|
||||
"max_input": 272000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gpt-5.1": {
|
||||
"context_window": 400000,
|
||||
"max_input": 272000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gpt-5.1-codex": {
|
||||
"context_window": 400000,
|
||||
"max_input": 272000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gpt-5.1-codex-max": {
|
||||
"context_window": 400000,
|
||||
"max_input": 272000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gpt-5.1-codex-mini": {
|
||||
"context_window": 400000,
|
||||
"max_input": 272000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gpt-5.2": {
|
||||
"context_window": 400000,
|
||||
"max_input": 272000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gpt-5.2-codex": {
|
||||
"context_window": 400000,
|
||||
"max_input": 272000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gpt-5.3-codex": {
|
||||
"context_window": 400000,
|
||||
"max_input": 272000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gpt-5.3-codex-spark": {
|
||||
"context_window": 128000,
|
||||
"max_input": 128000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gpt-5.4": {
|
||||
"context_window": 1050000,
|
||||
"max_input": 922000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gpt-5.4-mini": {
|
||||
"context_window": 400000,
|
||||
"max_input": 272000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gpt-5.4-nano": {
|
||||
"context_window": 400000,
|
||||
"max_input": 272000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gpt-5.4-pro": {
|
||||
"context_window": 1050000,
|
||||
"max_input": 922000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"gpt-5.5": {
|
||||
"context_window": 1050000,
|
||||
"max_input": 922000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gpt-5.5-pro": {
|
||||
"context_window": 1050000,
|
||||
"max_input": 922000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"gpt-5.6-luna": {
|
||||
"context_window": 1050000,
|
||||
"max_input": 922000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gpt-5.6-sol": {
|
||||
"context_window": 1050000,
|
||||
"max_input": 922000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"gpt-5.6-terra": {
|
||||
"context_window": 1050000,
|
||||
"max_input": 922000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"grok-4.5": {
|
||||
"context_window": 500000,
|
||||
"max_output": 500000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"grok-4.6": {
|
||||
"context_window": 500000,
|
||||
"max_output": 500000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"grok-build-0.1": {
|
||||
"context_window": 256000,
|
||||
"max_output": 256000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"grok-code": {
|
||||
"context_window": 256000,
|
||||
"max_output": 256000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"hy3": {
|
||||
"context_window": 256000,
|
||||
"max_input": 192000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"hy3-free": {
|
||||
"context_window": 190000,
|
||||
"max_input": 192000,
|
||||
"max_output": 64000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"hy3-preview-free": {
|
||||
"context_window": 256000,
|
||||
"max_output": 64000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"hy4-preview": {
|
||||
"context_window": 1024000,
|
||||
"max_output": 64000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"kimi-k2": {
|
||||
"context_window": 262144,
|
||||
"max_output": 262144,
|
||||
"tool_call": true
|
||||
},
|
||||
"kimi-k2-thinking": {
|
||||
"context_window": 262144,
|
||||
"max_output": 262144,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"kimi-k2.5": {
|
||||
"context_window": 262144,
|
||||
"max_output": 65536,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"kimi-k2.5-free": {
|
||||
"context_window": 262144,
|
||||
"max_output": 262144,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"kimi-k2.6": {
|
||||
"context_window": 262144,
|
||||
"max_output": 65536,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"kimi-k2.7-code": {
|
||||
"context_window": 262144,
|
||||
"max_output": 262144,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"kimi-k3": {
|
||||
"context_window": 1048576,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"laguna-s-2.1-free": {
|
||||
"context_window": 256000,
|
||||
"max_output": 32000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"ling-2.6-flash-free": {
|
||||
"context_window": 262100,
|
||||
"max_output": 32800,
|
||||
"tool_call": true
|
||||
},
|
||||
"ling-3.0-flash-fin-free": {
|
||||
"context_window": 262144,
|
||||
"max_output": 32768,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"ling-3.0-flash-free": {
|
||||
"context_window": 262144,
|
||||
"max_output": 32768,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"ling-3.0-tiny-free": {
|
||||
"context_window": 262144,
|
||||
"max_output": 32768,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"longcat-2.0": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"longcat-2.0-free": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"mimo-v2-flash-free": {
|
||||
"context_window": 262144,
|
||||
"max_output": 65536,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"mimo-v2-omni": {
|
||||
"context_window": 262144,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"mimo-v2-omni-free": {
|
||||
"context_window": 262144,
|
||||
"max_output": 64000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"mimo-v2-pro": {
|
||||
"context_window": 1048576,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"mimo-v2-pro-free": {
|
||||
"context_window": 1048576,
|
||||
"max_output": 64000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"mimo-v2.5": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"mimo-v2.5-free": {
|
||||
"context_window": 200000,
|
||||
"max_output": 32000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"mimo-v2.5-pro": {
|
||||
"context_window": 1048576,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"minimax-m2.1": {
|
||||
"context_window": 204800,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"minimax-m2.1-free": {
|
||||
"context_window": 204800,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"minimax-m2.5": {
|
||||
"context_window": 204800,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"minimax-m2.5-free": {
|
||||
"context_window": 204800,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"minimax-m2.7": {
|
||||
"context_window": 204800,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"minimax-m3": {
|
||||
"context_window": 512000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"minimax-m3-free": {
|
||||
"context_window": 200000,
|
||||
"max_output": 32000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"muse-spark-1.2": {
|
||||
"context_window": 1048576,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"muse-spark-1.2-contributor": {
|
||||
"context_window": 1048576,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"muse-spark-1.2-contributor-free": {
|
||||
"context_window": 1048576,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"muse-spark-1.3-contributor": {
|
||||
"context_window": 1048576,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"muse-spark-1.3-contributor-free": {
|
||||
"context_window": 1048576,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"nemotron-3-super-free": {
|
||||
"context_window": 204800,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"nemotron-3-ultra-free": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 128000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"nemotron-3.5-lightning-free": {
|
||||
"context_window": 262144,
|
||||
"max_output": 262144,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"north-mini-code-free": {
|
||||
"context_window": 256000,
|
||||
"max_output": 64000,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"ox-alpha-free": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"qwen3-coder": {
|
||||
"context_window": 262144,
|
||||
"max_output": 65536,
|
||||
"tool_call": true
|
||||
},
|
||||
"qwen3.5-plus": {
|
||||
"context_window": 262144,
|
||||
"max_output": 65536,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"qwen3.6-plus": {
|
||||
"context_window": 262144,
|
||||
"max_output": 65536,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"qwen3.6-plus-free": {
|
||||
"context_window": 262144,
|
||||
"max_output": 65536,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"qwen3.7-max": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 65536,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"qwen3.7-plus": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 65536,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"qwen3.8-flash": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"qwen3.8-max": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
},
|
||||
"ring-2.6-1t-free": {
|
||||
"context_window": 262000,
|
||||
"max_output": 66000,
|
||||
"reasoning": true,
|
||||
"tool_call": true
|
||||
},
|
||||
"trinity-large-preview-free": {
|
||||
"context_window": 131072,
|
||||
"max_output": 131072,
|
||||
"tool_call": true
|
||||
},
|
||||
"x-preview-f-free": {
|
||||
"context_window": 1000000,
|
||||
"max_output": 131072,
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": true
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -211,10 +211,13 @@ func (g *Gateway) handleModels(w http.ResponseWriter, _ *http.Request) {
|
||||
if g.cfg.Anonymous && len(g.cfg.ZenKeys) == 0 && len(g.cfg.GoKeys) == 0 && !g.catalog.anonymousDecision(model).Allowed {
|
||||
continue
|
||||
}
|
||||
if _, err := g.catalog.Route(model, len(g.cfg.ZenKeys) > 0, len(g.cfg.GoKeys) > 0, g.cfg.Anonymous); err != nil {
|
||||
route, err := g.catalog.Route(model, len(g.cfg.ZenKeys) > 0, len(g.cfg.GoKeys) > 0, g.cfg.Anonymous)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
md := g.catalog.Metadata(model)
|
||||
// Tier-scoped metadata: the advertised context window must match
|
||||
// the tier that will serve the request (anonymous ⇒ Zen).
|
||||
md := g.catalog.MetadataForTier(model, route.Tier)
|
||||
entry := map[string]any{
|
||||
"id": model, "object": "model", "created": now, "owned_by": "opencode",
|
||||
"metadata": md,
|
||||
|
||||
@@ -88,7 +88,7 @@ type modelCatalog struct {
|
||||
// catalog. protocols remains the user-configured override map.
|
||||
nativeProtocols map[Tier]map[string]Protocol
|
||||
unsupported map[Tier]map[string]bool
|
||||
modelMeta map[string]ModelMetadata
|
||||
modelMeta map[Tier]map[string]ModelMetadata
|
||||
updatedAt time.Time
|
||||
prefer Tier
|
||||
metadata *modelMetadataStore
|
||||
@@ -108,18 +108,18 @@ type modelCatalogSnapshot struct {
|
||||
Stale bool `json:"stale"`
|
||||
}
|
||||
|
||||
const modelCatalogCacheSchemaVersion = 2
|
||||
const modelCatalogCacheSchemaVersion = 3
|
||||
|
||||
var modelCatalogCacheWriteMu sync.Mutex
|
||||
|
||||
type modelCatalogCache struct {
|
||||
SchemaVersion int `json:"schema_version"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Zen []string `json:"zen"`
|
||||
Go []string `json:"go"`
|
||||
NativeProtocols map[Tier]map[string]Protocol `json:"native_protocols"`
|
||||
Unsupported map[Tier]map[string]bool `json:"unsupported"`
|
||||
Metadata map[string]ModelMetadata `json:"metadata,omitempty"`
|
||||
SchemaVersion int `json:"schema_version"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Zen []string `json:"zen"`
|
||||
Go []string `json:"go"`
|
||||
NativeProtocols map[Tier]map[string]Protocol `json:"native_protocols"`
|
||||
Unsupported map[Tier]map[string]bool `json:"unsupported"`
|
||||
Metadata map[Tier]map[string]ModelMetadata `json:"metadata,omitempty"`
|
||||
}
|
||||
|
||||
func newModelCatalog(prefer Tier, overrides map[string]string) *modelCatalog {
|
||||
@@ -151,7 +151,7 @@ func (c *modelCatalog) Replace(zen, goModels []string) {
|
||||
c.ReplaceWithCapabilities(zen, goModels, nil, nil, nil)
|
||||
}
|
||||
|
||||
func (c *modelCatalog) ReplaceWithCapabilities(zen, goModels []string, native map[Tier]map[string]Protocol, unsupported map[Tier]map[string]bool, metadata map[string]ModelMetadata) {
|
||||
func (c *modelCatalog) ReplaceWithCapabilities(zen, goModels []string, native map[Tier]map[string]Protocol, unsupported map[Tier]map[string]bool, metadata map[Tier]map[string]ModelMetadata) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
if zen != nil {
|
||||
@@ -449,14 +449,17 @@ func (c *modelCatalog) Supported(model string) bool {
|
||||
return c.supportedLocked(model)
|
||||
}
|
||||
|
||||
// Metadata returns the rich per-model metadata (context window, reasoning,
|
||||
// tool call, modalities) captured from the opencode catalog. The zero value
|
||||
// is returned for models the catalog does not describe (or before the first
|
||||
// capability refresh).
|
||||
func (c *modelCatalog) Metadata(model string) ModelMetadata {
|
||||
// MetadataForTier returns the rich per-model metadata (context window,
|
||||
// reasoning, tool call, modalities) captured from the opencode catalog for
|
||||
// the tier that will actually serve the request. Same-named models can carry
|
||||
// different limits per tier, so callers must pass route.Tier — never a
|
||||
// tier-blind lookup. Anonymous routes always resolve to TierZen, which keeps
|
||||
// the keyless path on Zen metadata. The zero value is returned for models
|
||||
// the catalog does not describe (or before the first capability refresh).
|
||||
func (c *modelCatalog) MetadataForTier(model string, tier Tier) ModelMetadata {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
return c.modelMeta[model]
|
||||
return c.modelMeta[tier][model]
|
||||
}
|
||||
|
||||
func (c *modelCatalog) supportedLocked(model string) bool {
|
||||
@@ -511,13 +514,12 @@ func cloneBools(source map[string]bool) map[string]bool {
|
||||
return result
|
||||
}
|
||||
|
||||
func cloneModelMeta(source map[string]ModelMetadata) map[string]ModelMetadata {
|
||||
if source == nil {
|
||||
return nil
|
||||
}
|
||||
result := make(map[string]ModelMetadata, len(source))
|
||||
for id, md := range source {
|
||||
result[id] = md
|
||||
func cloneModelMeta(source map[Tier]map[string]ModelMetadata) map[Tier]map[string]ModelMetadata {
|
||||
result := map[Tier]map[string]ModelMetadata{TierZen: {}, TierGo: {}}
|
||||
for _, tier := range []Tier{TierZen, TierGo} {
|
||||
for id, md := range source[tier] {
|
||||
result[tier][id] = md
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -705,7 +707,7 @@ func saveModelCatalogCache(path string, cache modelCatalogCache) error {
|
||||
type protocolCapabilities struct {
|
||||
Protocols map[Tier]map[string]Protocol
|
||||
Unsupported map[Tier]map[string]bool
|
||||
Metadata map[string]ModelMetadata
|
||||
Metadata map[Tier]map[string]ModelMetadata
|
||||
}
|
||||
|
||||
type capabilityProvider struct {
|
||||
@@ -716,14 +718,18 @@ type capabilityProvider struct {
|
||||
}
|
||||
|
||||
type capabilityModel struct {
|
||||
ID string `json:"id"`
|
||||
Provider *capabilityModelProvider `json:"provider"`
|
||||
Limit *capabilityModelLimit `json:"limit"`
|
||||
Reasoning bool `json:"reasoning"`
|
||||
ToolCall bool `json:"tool_call"`
|
||||
StructuredOutput bool `json:"structured_output"`
|
||||
InputModalities []string `json:"input"`
|
||||
OutputModalities []string `json:"output"`
|
||||
ID string `json:"id"`
|
||||
Provider *capabilityModelProvider `json:"provider"`
|
||||
Limit *capabilityModelLimit `json:"limit"`
|
||||
Reasoning bool `json:"reasoning"`
|
||||
ToolCall bool `json:"tool_call"`
|
||||
StructuredOutput bool `json:"structured_output"`
|
||||
Modalities *capabilityModelModalities `json:"modalities"`
|
||||
}
|
||||
|
||||
type capabilityModelModalities struct {
|
||||
Input []string `json:"input"`
|
||||
Output []string `json:"output"`
|
||||
}
|
||||
|
||||
type capabilityModelLimit struct {
|
||||
@@ -752,8 +758,10 @@ func (m *capabilityModel) metadata() ModelMetadata {
|
||||
Reasoning: m.Reasoning,
|
||||
ToolCall: m.ToolCall,
|
||||
StructuredOutput: m.StructuredOutput,
|
||||
InputModalities: m.InputModalities,
|
||||
OutputModalities: m.OutputModalities,
|
||||
}
|
||||
if m.Modalities != nil {
|
||||
md.InputModalities = m.Modalities.Input
|
||||
md.OutputModalities = m.Modalities.Output
|
||||
}
|
||||
if m.Limit != nil {
|
||||
md.ContextWindow = m.Limit.Context
|
||||
@@ -797,7 +805,7 @@ func fetchProtocolCapabilities(ctx context.Context, client *http.Client, endpoin
|
||||
result := protocolCapabilities{
|
||||
Protocols: map[Tier]map[string]Protocol{TierZen: {}, TierGo: {}},
|
||||
Unsupported: map[Tier]map[string]bool{TierZen: {}, TierGo: {}},
|
||||
Metadata: map[string]ModelMetadata{},
|
||||
Metadata: map[Tier]map[string]ModelMetadata{TierZen: {}, TierGo: {}},
|
||||
}
|
||||
for providerID, provider := range providers {
|
||||
tier, ok := capabilityTier(providerID, provider.API)
|
||||
@@ -817,7 +825,7 @@ func fetchProtocolCapabilities(ctx context.Context, client *http.Client, endpoin
|
||||
} else {
|
||||
result.Unsupported[tier][modelID] = true
|
||||
}
|
||||
result.Metadata[modelID] = model.metadata()
|
||||
result.Metadata[tier][modelID] = model.metadata()
|
||||
}
|
||||
}
|
||||
// The machine catalog is the primary source. The upstream endpoint tables
|
||||
|
||||
+194
@@ -0,0 +1,194 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// fixtureCatalog mirrors the real models.opencode.ai/api.json shape: providers
|
||||
// keyed by ID, each model carrying limit/reasoning/flags plus a NESTED
|
||||
// modalities object. tier-split-model intentionally carries different limits
|
||||
// per tier, reproducing the glm-5/minimax-m3 class of bug where a tier-blind
|
||||
// metadata map advertises the wrong tier's context window.
|
||||
const fixtureCatalog = `{
|
||||
"opencode": {
|
||||
"id": "opencode",
|
||||
"api": "https://opencode.ai/zen/v1",
|
||||
"npm": "@ai-sdk/openai-compatible",
|
||||
"models": {
|
||||
"tier-split-model": {
|
||||
"id": "tier-split-model",
|
||||
"limit": {"context": 1000000, "input": 990000, "output": 128000},
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": false,
|
||||
"modalities": {"input": ["text", "image"], "output": ["text"]}
|
||||
},
|
||||
"zen-only-model": {
|
||||
"limit": {"context": 200000, "output": 32000},
|
||||
"reasoning": false,
|
||||
"tool_call": true,
|
||||
"structured_output": true,
|
||||
"modalities": {"input": ["text"], "output": ["text"]}
|
||||
}
|
||||
}
|
||||
},
|
||||
"opencode-go": {
|
||||
"id": "opencode-go",
|
||||
"api": "https://opencode.ai/go/v1",
|
||||
"npm": "@ai-sdk/openai-compatible",
|
||||
"models": {
|
||||
"tier-split-model": {
|
||||
"id": "tier-split-model",
|
||||
"limit": {"context": 200000, "input": 190000, "output": 32000},
|
||||
"reasoning": true,
|
||||
"tool_call": true,
|
||||
"structured_output": false,
|
||||
"modalities": {"input": ["text"], "output": ["text"]}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
// fixtureRoundTripper serves the catalog fixture for the capability endpoint
|
||||
// and fails everything else immediately, keeping protocol-docs fallback
|
||||
// fetches hermetic instead of hitting the network.
|
||||
type fixtureRoundTripper struct {
|
||||
catalogURL string
|
||||
}
|
||||
|
||||
func (f fixtureRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
if req.URL.String() != f.catalogURL {
|
||||
return nil, &testDNSError{url: req.URL.String()}
|
||||
}
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(strings.NewReader(fixtureCatalog)),
|
||||
Header: make(http.Header),
|
||||
}, nil
|
||||
}
|
||||
|
||||
type testDNSError struct{ url string }
|
||||
|
||||
func (e *testDNSError) Error() string { return "blocked test request to " + e.url }
|
||||
|
||||
func testParseCapabilities(t *testing.T) protocolCapabilities {
|
||||
t.Helper()
|
||||
const catalogURL = "https://example.invalid/api.json"
|
||||
client := &http.Client{Transport: fixtureRoundTripper{catalogURL: catalogURL}}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
caps, err := fetchProtocolCapabilities(ctx, client, catalogURL)
|
||||
if err != nil {
|
||||
t.Fatalf("fetchProtocolCapabilities: %v", err)
|
||||
}
|
||||
return caps
|
||||
}
|
||||
|
||||
func TestNestedModalitiesParsed(t *testing.T) {
|
||||
caps := testParseCapabilities(t)
|
||||
md := caps.Metadata[TierZen]["tier-split-model"]
|
||||
if len(md.InputModalities) != 2 || md.InputModalities[0] != "text" || md.InputModalities[1] != "image" {
|
||||
t.Fatalf("zen input modalities = %v, want [text image]", md.InputModalities)
|
||||
}
|
||||
if len(md.OutputModalities) != 1 || md.OutputModalities[0] != "text" {
|
||||
t.Fatalf("zen output modalities = %v, want [text]", md.OutputModalities)
|
||||
}
|
||||
if !md.Reasoning || !md.ToolCall || md.StructuredOutput {
|
||||
t.Fatalf("zen flags = %+v, want reasoning+tool_call", md)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTierSplitMetadataKeptSeparate(t *testing.T) {
|
||||
caps := testParseCapabilities(t)
|
||||
zen := caps.Metadata[TierZen]["tier-split-model"]
|
||||
goMd := caps.Metadata[TierGo]["tier-split-model"]
|
||||
if zen.ContextWindow != 1000000 {
|
||||
t.Fatalf("zen context = %d, want 1000000", zen.ContextWindow)
|
||||
}
|
||||
if goMd.ContextWindow != 200000 {
|
||||
t.Fatalf("go context = %d, want 200000", goMd.ContextWindow)
|
||||
}
|
||||
if zen.MaxOutput != 128000 || goMd.MaxOutput != 32000 {
|
||||
t.Fatalf("max_output zen=%d go=%d, want 128000/32000", zen.MaxOutput, goMd.MaxOutput)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMetadataForTierSelection(t *testing.T) {
|
||||
caps := testParseCapabilities(t)
|
||||
cat := newModelCatalog(TierZen, nil)
|
||||
cat.ReplaceWithCapabilities(
|
||||
[]string{"tier-split-model"}, []string{"tier-split-model"},
|
||||
caps.Protocols, caps.Unsupported, caps.Metadata,
|
||||
)
|
||||
if got := cat.MetadataForTier("tier-split-model", TierZen).ContextWindow; got != 1000000 {
|
||||
t.Fatalf("zen selection = %d, want 1000000", got)
|
||||
}
|
||||
if got := cat.MetadataForTier("tier-split-model", TierGo).ContextWindow; got != 200000 {
|
||||
t.Fatalf("go selection = %d, want 200000", got)
|
||||
}
|
||||
if got := cat.MetadataForTier("missing-model", TierZen).ContextWindow; got != 0 {
|
||||
t.Fatalf("unknown model = %d, want zero value", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMetadataCacheRoundTripV3(t *testing.T) {
|
||||
caps := testParseCapabilities(t)
|
||||
cat := newModelCatalog(TierZen, nil)
|
||||
cat.SetCachePath(filepath.Join(t.TempDir(), "cache.models.catalog.json"))
|
||||
cat.ReplaceWithCapabilities(
|
||||
[]string{"tier-split-model", "zen-only-model"}, []string{"tier-split-model"},
|
||||
caps.Protocols, caps.Unsupported, caps.Metadata,
|
||||
)
|
||||
if err := cat.SaveCache(); err != nil {
|
||||
t.Fatalf("SaveCache: %v", err)
|
||||
}
|
||||
restored := newModelCatalog(TierZen, nil)
|
||||
if err := restored.LoadCache(cat.cachePath); err != nil {
|
||||
t.Fatalf("LoadCache: %v", err)
|
||||
}
|
||||
if got := restored.MetadataForTier("tier-split-model", TierGo).ContextWindow; got != 200000 {
|
||||
t.Fatalf("restored go context = %d, want 200000", got)
|
||||
}
|
||||
restoredMd := restored.MetadataForTier("tier-split-model", TierZen)
|
||||
if len(restoredMd.InputModalities) != 2 || restoredMd.MaxOutput != 128000 {
|
||||
t.Fatalf("restored zen metadata = %+v, want modalities+128k output", restoredMd)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLegacyV2CacheRejected(t *testing.T) {
|
||||
// A pre-tier-split cache (flat metadata map, schema 2) must be refused
|
||||
// rather than misread: flat entries cannot be attributed to a tier.
|
||||
path := filepath.Join(t.TempDir(), "v2.models.catalog.json")
|
||||
legacy := map[string]any{
|
||||
"schema_version": 2,
|
||||
"updated_at": time.Now().UTC().Format(time.RFC3339Nano),
|
||||
"zen": []string{"tier-split-model"},
|
||||
"go": []string{},
|
||||
"metadata": map[string]any{
|
||||
"tier-split-model": map[string]any{"context_window": 1000000},
|
||||
},
|
||||
}
|
||||
raw, err := json.Marshal(legacy)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(path, raw, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cat := newModelCatalog(TierZen, nil)
|
||||
// The flat v2 metadata shape cannot even decode into the per-tier v3
|
||||
// struct, so rejection surfaces as a decode error before the explicit
|
||||
// version gate. Either way the stale cache is refused and the gateway
|
||||
// falls back to a live refresh — it must never be half-read.
|
||||
if err := cat.LoadCache(path); err == nil {
|
||||
t.Fatal("LoadCache accepted schema v2, want rejection")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user