diff --git a/README.md b/README.md index 89c5b23..2b74e57 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [Command Code](https://commandcode.ai) API provider for [opencode](https://opencode.ai). Use Claude, GPT, Gemini, DeepSeek, Qwen, Kimi, GLM, MiniMax, Step, and other models through a single API key. -This plugin is for Command Code accounts with Provider API access. GOAT is the live-tested baseline; other API-enabled plans can use models their account is entitled to. The $1 Go plan has no Provider API access. The catalog follows the provider-wide model list, so a model appearing in OpenCode does not imply that every account can call it. See [GOAT plan details](https://commandcode.ai/docs/plans/goat) and [Provider API docs](https://commandcode.ai/docs/provider). +This plugin is for Command Code accounts with Provider API access. GOAT is the live-tested baseline; other accounts can use models they're entitled to. The $1 Go plan's monthly allowance does not cover Provider API requests, but Go users can call the API with eligible free or purchased credits. The catalog follows the provider-wide model list, so a model appearing in OpenCode does not imply that every account can call it. See the [Go plan's API support](https://commandcode.ai/docs/plans/go#api-support) and [Provider API docs](https://commandcode.ai/docs/provider). This package keeps a **bundled** model catalog current via CI. You do **not** need a local `command-code` CLI. Catalog patches publish automatically after a green PR merges to `main`. @@ -22,10 +22,10 @@ This package is based on **[FanFan4204/opencode-commandcode-provider](https://gi - V1 and V2 use their native plugin and provider surfaces. V1 `server()` fills `provider.commandcode` and registers API-key auth; V2 `setup()` registers provider/model transforms and a key/env integration for `/connect` and `opencode auth login`. - Validation at the boundaries via `src/schemas.ts` (zod): bundled `models.json` / `manifest.json` reads, provider availability payloads, and the plugin config file. - CLI cost extraction can fail without dropping models; official docs fill missing costs, remaining paid gaps use [models.dev](https://models.dev) as a reference price at sync time. Command Code free SKUs stay `$0`. -- Vision vs text-only comes from the Command Code CLI catalog (`inputModalities` on every SKU). [models.dev](https://models.dev) only adds extra inputs (video/audio/pdf) when it matches. +- The Provider API accepts text and images only. The bundled catalog advertises image input only when the CLI catalog or a matching [models.dev](https://models.dev) entry lists it. It does not advertise audio, video, PDF, or other file inputs. - Reasoning effort **variants** on models that declare `reasoningEfforts`. - Release date, family, input limits, model status, vendor context limits, and matched context-price tiers flow through the bundled catalog. V2 gets native release, family, input, status, and tier fields; V1 keeps its supported fields and base prices, with `context_over_200k` where representable. -- The provider's `supported_endpoints` metadata chooses each model's API route. Messages is preferred when advertised; otherwise Chat Completions is preferred, and Responses is used only when it is the sole advertised route. This avoids the malformed Responses function-call start event observed on DeepSeek V4.1 Flash `#max` in OpenCode V2.0.18: `response.output_item.added` contained a `function_call` item without its required `arguments` string. That exact tool-call flow now passes through Chat Completions on V1 and V2. Responses mappings remain available for response-only models, but the current catalog has none. Claude Sonnet 4.6 returned `MODEL_NOT_IN_PLAN` with the message “available in Pro and above plans or extra on-demand usage”; entitled Claude access has not been live-verified. If a model fails on an account entitled to use it, please [open an issue](https://github.com/BrainerVirus/opencode-commandcode/issues) with the model ID and OpenCode version, or submit a PR with a reproducible fix. +- Routing uses each model's `supported_endpoints`. Claude uses Anthropic Messages when advertised. Other models use Chat Completions whenever advertised, even if they also advertise Messages or Responses. Outside the Claude preference, Chat Completions is preferred whenever advertised; if only Messages and/or Responses are advertised, Messages is preferred when available, otherwise Responses. Without endpoint metadata, Claude defaults to Messages and other models default to Chat Completions. This keeps DeepSeek V4.1 Flash `#max` on the previously verified Chat Completions tool-call path on V1 and V2. Claude Sonnet 4.6 returned `MODEL_NOT_IN_PLAN` on the tested GOAT account; entitled Claude access has not been live-verified. If an entitled model fails, please [open an issue](https://github.com/BrainerVirus/opencode-commandcode/issues) with the model ID and OpenCode version. - Quiet OpenCode startup (diagnostics go to `startup.json`, not stdout). - Free models show `(Free)` after their display name on V1 and V2 when all catalog prices are zero. Model IDs and routing stay unchanged; this is a name suffix, not a native desktop badge. Names that already end in `Free` or `(Free)` keep their existing label. - Zero data retention on request: `CMD_ZDR=1` or `zdr: true` in the plugin config adds `x-cmd-zdr: 1` to every Command Code Provider API (`/provider/v1/*`) request on both OpenCode generations. @@ -35,7 +35,7 @@ This package is based on **[FanFan4204/opencode-commandcode-provider](https://gi For published plugin versions, the six-hour CI schedule extracts the latest `command-code` npm bundle and refreshes callable models plus endpoint metadata, even when the CLI version is unchanged. It opens a catalog PR only when generated artifacts change; at startup the plugin loads those artifacts and registers them with OpenCode — never the other way around. - **Extract + filter** — model entries (ids, names, reasoning, `inputModalities`, limits) are evaluated out of the minified CLI bundle (`src/catalog.ts`), then intersected with the callable IDs reported by the provider API. -- **Metadata + costs merge** — vendor context length tightens only a fallback context limit, while `supported_endpoints` selects Messages, Chat Completions, or Responses per model in that preference order; missing endpoint metadata preserves the last known route data. models.dev contributes release date, family, input limit, status, modalities, and cost tiers when present. Tier rows are accepted only when their base prices match this Command Code catalog. Base costs use CLI bundle → official Command Code docs → free SKUs (`$0`) → [models.dev](https://models.dev) reference prices → unmatched placeholder. Anything still unmatched marks the catalog `degraded`. This runs at sync time only; runtime never fetches metadata or prices. +- **Metadata + costs merge** — vendor context length tightens only a fallback context limit, and missing endpoint metadata preserves the last known route data. models.dev contributes release date, family, input limit, status, vision metadata, and cost tiers when present. Tier rows are accepted only when their base prices match this Command Code catalog. Base costs use CLI bundle → official Command Code docs → free SKUs (`$0`) → [models.dev](https://models.dev) reference prices → unmatched placeholder. Anything still unmatched marks the catalog `degraded`. This runs at sync time only; runtime never fetches metadata or prices. - **Artifacts** — `models.json` (the catalog), `_version.txt` (upstream version), `manifest.json` (counts, per-source cost stats, `healthy`/`degraded`/`broken` status). - **Version-specific registration** — V1 uses the `plugin` config key, direct AI SDK packages, the `server()` provider map, and its auth callback. V2 uses `plugins`, OpenCode's native provider runtimes, provider/model transforms, and a `commandcode` integration with key and `COMMANDCODE_API_KEY` environment methods. Both retain the Command Code wire model ID. V2 exposes tiered context pricing; V1 emits its supported `context_over_200k` field and keeps flat pricing for other tiers. - **Degraded/cache fallbacks** — a `degraded`/`broken` manifest sets the degraded flag with a reason; an unreadable bundled `models.json` falls back to the last-good cache; auth/connect still registers even with an empty catalog. @@ -107,7 +107,8 @@ Header names are matched case-insensitively, and the plugin collapses any spelli `x-cmd-zdr` key, so a request never carries two ZDR headers. Custom npm transports keep owning their options. Behavior to expect from the API: when set, requests route only through ZDR-capable upstreams, and a model without one -**fails with `422 cmd_zdr_no_providers`** instead of falling back to a non-ZDR provider. ZDR can change which upstream +**fails with `422 cmd_zdr_no_providers`** instead of falling back to a non-ZDR provider. Free models are not ZDR-routed; +choose a model with ZDR coverage rather than relying on a `(Free)` SKU for ZDR. ZDR can change which upstream serves a request, so it may cost more. The header is sent on the Chat Completions, Messages, and Responses routes alike; live verification so far covers Chat Completions only. diff --git a/docs/specs/2026-09-28-v2-parity.md b/docs/specs/2026-09-28-v2-parity.md index 446a258..59726bc 100644 --- a/docs/specs/2026-09-28-v2-parity.md +++ b/docs/specs/2026-09-28-v2-parity.md @@ -13,9 +13,9 @@ features when V1 has no equivalent; do not weaken or remove the V1 path. The provider catalog is global, while Command Code enforces account entitlements at request time. GOAT is the live-tested baseline. Other plans with Provider API access are in scope for models they entitle, but plan-specific access is not -claimed as live-verified. The $1 Go plan is unsupported because Command Code -documents that it does not include Provider API access; this is an API -availability limit, not a claim about its Terms of Service. See the official +claimed as live-verified. The $1 Go plan's monthly allowance does not pay for +Provider API requests; Go accounts can use the API with eligible free or +purchased credits. See the official [GOAT plan](https://commandcode.ai/docs/plans/goat), [Go plan](https://commandcode.ai/docs/plans/go), and [Provider API](https://commandcode.ai/docs/provider) documentation. @@ -33,19 +33,20 @@ and [Provider API](https://commandcode.ai/docs/provider) documentation. ## A — Endpoint-aware model routing -The provider's live `/models` metadata is the route authority when -`supported_endpoints` is present. Prefer Anthropic Messages when advertised, -then Chat Completions, and use Responses when it is the only advertised route. -This is a shared endpoint policy, not a DeepSeek-specific model override. The -actual OpenCode V2.0.18 session error was a `response.output_item.added` event -whose `function_call` item omitted its required `arguments` string during a -DeepSeek V4.1 Flash `#max` shell-tool request. The earlier annotation-event -diagnosis was incorrect. Current Command Code metadata advertises Chat on all -74 non-Messages-only models, so the policy sends those models through Chat; -Messages-only models keep Anthropic Messages. The 0.10.2 Responses mappings -remain for future models that advertise Responses without another route, but -the current catalog has no such entry. Other models' Responses tool-call streams -were not individually live-tested. +The shared V1/V2 policy uses Command Code's `/models` `supported_endpoints` +metadata. Claude uses Anthropic Messages when advertised. Other models use +Chat Completions whenever advertised, even when they also list Messages or +Responses. Outside the Claude preference, Chat Completions is preferred whenever +advertised; if only Messages and/or Responses are advertised, Messages is +preferred when available, otherwise Responses. With no usable route +selection, the default is Messages for Claude and Chat Completions otherwise. +In particular, DeepSeek V4 Flash, DeepSeek V4.1 Flash, Kimi K3, GLM-5.3 Flash, +and Ergo 1.0 keep the default Chat transport despite advertising Messages. +This preserves the path verified for the DeepSeek V4.1 Flash `#max` shell-tool +request. The prior Responses failure on V2.0.18 was a +`response.output_item.added` event whose `function_call` item omitted its +required `arguments` string. + V1 uses `@ai-sdk/openai` for Responses and the Anthropic SDK for Messages. V2 uses OpenCode's native `@opencode/ai/providers/openai-compatible`, `@opencode/ai/providers/openai/responses`, and @@ -53,11 +54,8 @@ uses OpenCode's native `@opencode/ai/providers/openai-compatible`, not reliably carry provider settings into model requests: image requests and an existing image-bearing session returned `Invalid input` until a manual provider base URL was supplied. The native runtime preserves the plugin's base -URL and requires no manual provider block. If an older catalog -lacks route metadata, Claude retains the Messages fallback and other models -retain Chat Completions. The current 84-model catalog has 66 models advertising -both Chat Completions and Responses, 10 Messages-only, and 8 Chat-only; it has -no Responses-only model. +URL and requires no manual provider block. A Responses-only model is covered +by mapping tests, not live inference. The isolated GOAT-key probes for Claude Sonnet and Haiku returned `MODEL_NOT_IN_PLAN`. Claude Sonnet 4.6 reported that it is available on Pro and @@ -86,12 +84,9 @@ The strict catalog pipeline carries: Qwen 3.6 Plus, and MiniMax M2.7 to 200K. 3. models.dev `limit.input`, `family`, and `beta`/`deprecated` status when present. Missing status remains active. -4. Existing modalities and costs without clearing known values when a metadata - source is partial. - -The current 84-model catalog has release dates for 82 entries, family for 78, -input limits for 13, one beta model, and one deprecated model. These are -generated-data counts, not fixed schema expectations. +4. Sync-time inputs limited to text and, when the CLI or a matching models.dev + row lists it, image. PDF, video, audio, and file inputs are not supported by + the Provider API. The runtime schema still accepts older catalog modalities. ## C — V2 integration and auth @@ -115,8 +110,7 @@ temporary container environment, the eligible DeepSeek smoke test succeeded. The sync pipeline preserves models.dev context tiers and `context_over_200k`. Tier aliases are accepted only when their base input and output prices match the Command Code catalog, preventing another provider's rates from entering -this catalog. The current sync has tiers for 23 models, with boundaries at -32K, 128K, 200K, 200001, 256K, 262144, 272K, and 512K tokens. +this catalog. V2 emits native `cost[]` tiers. V1 emits `context_over_200k` when an exact 200K tier is available and keeps its flat base price for other tiers that its @@ -127,15 +121,20 @@ model schema cannot express. README examples use the bare unpinned npm package with `plugin` for V1 and `plugins` for V2. They explain that V2 checks for package updates at startup but does not silently replace its cache, describe both auth surfaces and their -distinct cost support, and state the plan/test limits. The stable-model-identity +distinct cost support, state the plan/test limits, and note that free models +are not ZDR-routed. The stable-model-identity spec describes the 0.9.1 baseline historically and links here for current V2 auth and metadata behavior. ## Verification - Unit tests cover strict schema validation, source merging, vendor context - clamps, tier alias price matching, V1/V2 metadata and cost mappings, Claude - package selection, and V2 integration registration. + clamps, tier alias price matching, V1/V2 metadata and cost mappings, route + selection (including the five non-Claude models with both Chat and Messages), + sync-time input filtering, and V2 integration registration. + +Earlier live and release-candidate verification: + - `bun run check` passed: lint, formatting, typecheck, and 235 unit tests (668 expectations). - `bun run build` passed and produced `dist/plugin.js` (0.73 MB). diff --git a/models.json b/models.json index a9b8c01..f12acb0 100644 --- a/models.json +++ b/models.json @@ -26,8 +26,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -66,8 +65,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -106,8 +104,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -139,8 +136,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -191,8 +187,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -249,8 +244,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -307,8 +301,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -347,8 +340,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -387,8 +379,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -441,8 +432,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -481,8 +471,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -521,8 +510,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -613,8 +601,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -707,8 +694,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -767,8 +753,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -825,8 +810,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -883,8 +867,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -941,8 +924,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -1001,8 +983,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -1061,8 +1042,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -1121,8 +1101,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -1508,10 +1487,7 @@ "modalities": { "input": [ "text", - "image", - "video", - "audio", - "pdf" + "image" ], "output": [ "text" @@ -1548,10 +1524,7 @@ "modalities": { "input": [ "text", - "image", - "video", - "audio", - "pdf" + "image" ], "output": [ "text" @@ -1588,10 +1561,7 @@ "modalities": { "input": [ "text", - "image", - "video", - "audio", - "pdf" + "image" ], "output": [ "text" @@ -1628,10 +1598,7 @@ "modalities": { "input": [ "text", - "image", - "video", - "audio", - "pdf" + "image" ], "output": [ "text" @@ -1669,10 +1636,7 @@ "modalities": { "input": [ "text", - "image", - "video", - "audio", - "pdf" + "image" ], "output": [ "text" @@ -1708,10 +1672,7 @@ "modalities": { "input": [ "text", - "image", - "video", - "audio", - "pdf" + "image" ], "output": [ "text" @@ -1748,10 +1709,7 @@ "modalities": { "input": [ "text", - "image", - "video", - "audio", - "pdf" + "image" ], "output": [ "text" @@ -1788,10 +1746,7 @@ "modalities": { "input": [ "text", - "image", - "video", - "audio", - "pdf" + "image" ], "output": [ "text" @@ -1829,10 +1784,7 @@ "modalities": { "input": [ "text", - "image", - "video", - "audio", - "pdf" + "image" ], "output": [ "text" @@ -2036,9 +1988,7 @@ "modalities": { "input": [ "text", - "image", - "video", - "pdf" + "image" ], "output": [ "text" @@ -2075,9 +2025,7 @@ "modalities": { "input": [ "text", - "image", - "video", - "pdf" + "image" ], "output": [ "text" @@ -2114,8 +2062,7 @@ "modalities": { "input": [ "text", - "image", - "video" + "image" ], "output": [ "text" @@ -2210,8 +2157,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -2270,8 +2216,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -2330,8 +2275,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -2594,8 +2538,7 @@ "modalities": { "input": [ "text", - "image", - "audio" + "image" ], "output": [ "text" @@ -2627,8 +2570,7 @@ "modalities": { "input": [ "text", - "image", - "video" + "image" ], "output": [ "text" @@ -2660,8 +2602,7 @@ "modalities": { "input": [ "text", - "image", - "video" + "image" ], "output": [ "text" @@ -2693,8 +2634,7 @@ "modalities": { "input": [ "text", - "image", - "video" + "image" ], "output": [ "text" @@ -2726,8 +2666,7 @@ "modalities": { "input": [ "text", - "image", - "video" + "image" ], "output": [ "text" @@ -2764,8 +2703,7 @@ "modalities": { "input": [ "text", - "image", - "video" + "image" ], "output": [ "text" @@ -2803,8 +2741,7 @@ "modalities": { "input": [ "text", - "image", - "pdf" + "image" ], "output": [ "text" @@ -2936,9 +2873,7 @@ "modalities": { "input": [ "text", - "image", - "audio", - "video" + "image" ], "output": [ "text" @@ -2970,9 +2905,7 @@ "modalities": { "input": [ "text", - "image", - "audio", - "video" + "image" ], "output": [ "text" @@ -3004,9 +2937,7 @@ "modalities": { "input": [ "text", - "image", - "audio", - "video" + "image" ], "output": [ "text" @@ -3122,8 +3053,7 @@ "modalities": { "input": [ "text", - "image", - "video" + "image" ], "output": [ "text" @@ -3162,8 +3092,7 @@ "modalities": { "input": [ "text", - "image", - "video" + "image" ], "output": [ "text" @@ -3254,11 +3183,7 @@ "modalities": { "input": [ "text", - "image", - "file", - "video", - "pdf", - "audio" + "image" ], "output": [ "text" @@ -3296,10 +3221,7 @@ "modalities": { "input": [ "text", - "image", - "pdf", - "video", - "audio" + "image" ], "output": [ "text" @@ -3337,10 +3259,7 @@ "modalities": { "input": [ "text", - "image", - "video", - "pdf", - "audio" + "image" ], "output": [ "text" @@ -3378,10 +3297,7 @@ "modalities": { "input": [ "text", - "image", - "video", - "pdf", - "audio" + "image" ], "output": [ "text" @@ -3420,10 +3336,7 @@ "modalities": { "input": [ "text", - "image", - "video", - "pdf", - "audio" + "image" ], "output": [ "text" @@ -3461,10 +3374,7 @@ "modalities": { "input": [ "text", - "image", - "video", - "pdf", - "audio" + "image" ], "output": [ "text" @@ -3501,8 +3411,7 @@ "modalities": { "input": [ "text", - "image", - "video" + "image" ], "output": [ "text" @@ -3540,11 +3449,7 @@ "modalities": { "input": [ "text", - "image", - "file", - "video", - "pdf", - "audio" + "image" ], "output": [ "text" @@ -3612,8 +3517,7 @@ "modalities": { "input": [ "text", - "image", - "video" + "image" ], "output": [ "text" @@ -3726,8 +3630,7 @@ "modalities": { "input": [ "text", - "image", - "video" + "image" ], "output": [ "text" @@ -3783,8 +3686,7 @@ "modalities": { "input": [ "text", - "image", - "video" + "image" ], "output": [ "text" @@ -3885,8 +3787,7 @@ "modalities": { "input": [ "text", - "image", - "video" + "image" ], "output": [ "text" @@ -3923,9 +3824,7 @@ "modalities": { "input": [ "text", - "image", - "video", - "pdf" + "image" ], "output": [ "text" @@ -3962,8 +3861,7 @@ "modalities": { "input": [ "text", - "image", - "video" + "image" ], "output": [ "text" @@ -4000,9 +3898,7 @@ "modalities": { "input": [ "text", - "image", - "video", - "pdf" + "image" ], "output": [ "text" @@ -4039,8 +3935,7 @@ "modalities": { "input": [ "text", - "image", - "video" + "image" ], "output": [ "text" @@ -4077,8 +3972,7 @@ "modalities": { "input": [ "text", - "image", - "video" + "image" ], "output": [ "text" @@ -4115,9 +4009,7 @@ "modalities": { "input": [ "text", - "image", - "audio", - "video" + "image" ], "output": [ "text" @@ -4156,8 +4048,7 @@ "modalities": { "input": [ "text", - "image", - "video" + "image" ], "output": [ "text" @@ -4222,8 +4113,7 @@ "modalities": { "input": [ "text", - "image", - "video" + "image" ], "output": [ "text" @@ -4263,8 +4153,7 @@ "modalities": { "input": [ "text", - "image", - "video" + "image" ], "output": [ "text" diff --git a/src/catalog.ts b/src/catalog.ts index e46916e..27b8590 100644 --- a/src/catalog.ts +++ b/src/catalog.ts @@ -841,10 +841,16 @@ export function modelApi(entry: Pick): return path === route || path.endsWith(`/${route}`); }) ?? false; - if (supports("messages")) return "messages"; + const claude = usesAnthropicMessagesApi(entry.id); + const messages = supports("messages"); + if (claude && messages) return "messages"; if (supports("chat/completions")) return "chat"; - if (supports("responses")) return "responses"; - return usesAnthropicMessagesApi(entry.id) ? "messages" : "chat"; + const responses = supports("responses"); + // No Chat route: prefer Messages when offered, including the + // Messages+Responses pairing; Responses stands alone. + if (messages) return "messages"; + if (responses) return "responses"; + return claude ? "messages" : "chat"; } export function generateOpencodeModels(entries: ModelEntry[]): Record { diff --git a/src/costs-models-dev.ts b/src/costs-models-dev.ts index 4e81363..07f8564 100644 --- a/src/costs-models-dev.ts +++ b/src/costs-models-dev.ts @@ -194,39 +194,22 @@ export function applyFreeCosts( return filled; } -function textOnly(): { input: string[]; output: string[] } { - return { input: [...TEXT_ONLY_MODALITIES.input], output: [...TEXT_ONLY_MODALITIES.output] }; -} - export function applyModelsDevModalities(models: ModelEntry[], rows: ModelsDevRow[]): number { const index = indexRows(rows); let filled = 0; for (const model of models) { - const row = findRow(model, index); + const reference = findRow(model, index)?.modalities; const current = model.modalities; - if (current && model.attachment !== undefined) { - const extra = row?.modalities?.input?.filter((x) => !current.input.includes(x)) ?? []; - if (extra.length > 0) { - model.modalities = { - input: [...current.input, ...extra], - output: [...current.output], - }; - if (model.modalities.input.includes("image")) model.attachment = true; - filled++; - } - continue; - } - if (row && (row.modalities || row.attachment !== undefined)) { - const modalities = row.modalities - ? { input: [...row.modalities.input], output: [...row.modalities.output] } - : textOnly(); - model.modalities = modalities; - model.attachment = row.attachment ?? modalities.input.includes("image"); - filled++; - } else { - model.attachment = false; - model.modalities = textOnly(); - } + const cliVision = current?.input.includes("image") ?? false; + const referenceVision = reference?.input.includes("image") ?? false; + const vision = cliVision || referenceVision; + // The Provider API only accepts text and image inputs. + model.modalities = { + input: vision ? ["text", "image"] : [...TEXT_ONLY_MODALITIES.input], + output: [...(current?.output ?? reference?.output ?? TEXT_ONLY_MODALITIES.output)], + }; + model.attachment = vision; + if (reference && (!current || (!cliVision && referenceVision))) filled++; } return filled; } diff --git a/tests/unit/catalog.test.ts b/tests/unit/catalog.test.ts index 7035e8b..689b338 100644 --- a/tests/unit/catalog.test.ts +++ b/tests/unit/catalog.test.ts @@ -273,11 +273,14 @@ describe("generateOpencodeModels", () => { "claude-sonnet-4-6", "claude-fable-5", "claude-fable-5-1", + "claude-fable-5-2", "claude-opus-5-5", "claude-opus-5", "claude-opus-4-8", "claude-opus-4-7", "claude-haiku-4-5-20251001", + "claude-haiku-5-5", + "claude-sonnet-5-5", ]; const models = generateOpencodeModels( ids.map((id) => ({ @@ -288,6 +291,7 @@ describe("generateOpencodeModels", () => { tool_call: true, cost: { input: 1, output: 2 }, limit: { context: 200000, output: 16000 }, + supported_endpoints: ["/messages"], })), ); for (const id of ids) { @@ -349,26 +353,24 @@ describe("generateOpencodeModels", () => { expect((models["gemini-3.5-flash"] as Record).provider).toBeUndefined(); }); - test("prefers Messages, then Chat Completions, then Responses and keeps the Claude fallback", () => { - expect( - modelApi({ id: "vendor/model", supported_endpoints: ["/v1/messages", "/v1/responses"] }), - ).toBe("messages"); - expect( - modelApi({ - id: "deepseek/model", - supported_endpoints: ["/v1/chat/completions", "/v1/responses"], - }), - ).toBe("chat"); - expect(modelApi({ id: "openai/model", supported_endpoints: ["/v1/responses"] })).toBe( - "responses", - ); - expect(modelApi({ id: "vendor/model", supported_endpoints: ["/v1/messages"] })).toBe( - "messages", - ); - expect( - modelApi({ id: "claude-sonnet-4-6", supported_endpoints: ["/v1/chat/completions"] }), - ).toBe("chat"); - expect(modelApi({ id: "claude-sonnet-4-6" })).toBe("messages"); + const chatResponsesMessages = ["/chat/completions", "/responses", "/messages"]; + test.each([ + ["deepseek/deepseek-v4-flash", chatResponsesMessages, "chat"], + ["deepseek/deepseek-v4.1-flash", chatResponsesMessages, "chat"], + ["moonshotai/Kimi-K3", chatResponsesMessages, "chat"], + ["z-ai/glm-5.3-flash", ["/chat/completions", "/messages"], "chat"], + ["amazon/ergo-1.0", chatResponsesMessages, "chat"], + ["claude-sonnet-4-6", ["/messages"], "messages"], + ["anthropic/claude-sonnet-4-6", chatResponsesMessages, "messages"], + ["vendor/messages-only", ["/v1/messages"], "messages"], + ["vendor/responses-only", ["/v1/responses"], "responses"], + ["vendor/messages-and-responses", ["/v1/messages", "/v1/responses"], "messages"], + ["deepseek/model", ["/v1/chat/completions", "/v1/responses"], "chat"], + ["claude-sonnet-4-6", ["/v1/chat/completions"], "chat"], + ["claude-sonnet-4-6", undefined, "messages"], + ["vendor/model", undefined, "chat"], + ] as const)("routes %s with endpoints %j through %s", (id, endpoints, expected) => { + expect(modelApi({ id, supported_endpoints: endpoints && [...endpoints] })).toBe(expected); }); test("emits attachment and modalities, defaulting to text-only", () => { diff --git a/tests/unit/costs-models-dev.test.ts b/tests/unit/costs-models-dev.test.ts index 3536f08..2b94025 100644 --- a/tests/unit/costs-models-dev.test.ts +++ b/tests/unit/costs-models-dev.test.ts @@ -84,13 +84,13 @@ describe("applyModelsDevModalities", () => { readFileSync(join(import.meta.dir, "../fixtures/models-dev/api.subset.json"), "utf-8"), ); - test("keeps CLI modalities on unmatched SKUs and only enriches extras from models.dev", () => { + test("keeps CLI vision and drops inputs the Provider API rejects", () => { const models = [ model({ id: "google/gemini-3.5-flash", name: "Gemini 3.5 Flash", attachment: true, - modalities: { input: ["text", "image"], output: ["text"] }, + modalities: { input: ["text", "image", "video"], output: ["text"] }, }), model({ id: "unknown/cli-vision-only", @@ -107,9 +107,9 @@ describe("applyModelsDevModalities", () => { model({ id: "no-cli-no-dev", name: "Gap" }), ]; const n = applyModelsDevModalities(models, rows); - expect(n).toBe(1); + expect(n).toBe(0); expect(models[0].modalities).toEqual({ - input: ["text", "image", "video", "audio", "pdf"], + input: ["text", "image"], output: ["text"], }); expect(models[1].attachment).toBe(true); @@ -119,6 +119,38 @@ describe("applyModelsDevModalities", () => { expect(models[3].attachment).toBe(false); expect(models[3].modalities).toEqual({ ...TEXT_ONLY_MODALITIES }); }); + + test.each([ + { input: ["text", "image", "pdf", "video", "audio", "file"], expected: ["text", "image"] }, + { input: ["text", "pdf", "video", "audio", "file"], expected: ["text"] }, + ])("allows image only when models.dev input $input lists it", ({ input, expected }) => { + const entry = model({ id: "vendor/model", name: "Model" }); + applyModelsDevModalities( + [entry], + [ + { + id: entry.id, + name: entry.name, + attachment: true, + modalities: { input, output: ["text"] }, + }, + ], + ); + expect(entry.modalities).toEqual({ input: expected, output: ["text"] }); + expect(entry.attachment).toBe(expected.includes("image")); + }); + + test("fills a missing vision capability from a matching models.dev row", () => { + const entry = model({ + id: "google/gemini-3.5-flash", + name: "Gemini 3.5 Flash", + attachment: false, + modalities: { input: ["text"], output: ["text"] }, + }); + expect(applyModelsDevModalities([entry], rows)).toBe(1); + expect(entry.modalities).toEqual({ input: ["text", "image"], output: ["text"] }); + expect(entry.attachment).toBe(true); + }); }); describe("applyModelsDevMetadata", () => { diff --git a/tests/unit/v2models.test.ts b/tests/unit/v2models.test.ts index 1074e9b..cbcec2e 100644 --- a/tests/unit/v2models.test.ts +++ b/tests/unit/v2models.test.ts @@ -84,18 +84,36 @@ test("Claude catalog models use the Anthropic Messages package", () => { "claude-sonnet-4-6", "claude-fable-5", "claude-fable-5-1", + "claude-fable-5-2", "claude-opus-5-5", "claude-opus-5", "claude-opus-4-8", "claude-opus-4-7", "claude-haiku-4-5-20251001", + "claude-haiku-5-5", + "claude-sonnet-5-5", ]; - const models = generateV2Models(ids.map((id) => ({ ...base, id }))); + const models = generateV2Models( + ids.map((id) => ({ ...base, id, supported_endpoints: ["/messages"] })), + ); expect(models.map((model) => model.package)).toEqual( ids.map(() => "@opencode/ai/providers/anthropic"), ); }); +test.each([ + ["deepseek/deepseek-v4-flash", "deepseek-v4-flash"], + ["deepseek/deepseek-v4.1-flash", "deepseek-v4.1-flash"], + ["moonshotai/Kimi-K3", "kimi-k3"], + ["z-ai/glm-5.3-flash", "glm-5.3-flash"], + ["amazon/ergo-1.0", "ergo-1.0"], +])("%s keeps the default Chat provider on V1 and V2 even with Messages", (id, key) => { + const entry = { ...base, id, supported_endpoints: ["/chat/completions", "/messages"] }; + const v1 = generateOpencodeModels([entry])[key] as { provider?: unknown }; + expect(v1.provider).toBeUndefined(); + expect(toV2Model(entry).package).toBeUndefined(); +}); + test("V2 maps advertised Responses and Messages packages", () => { expect( toV2Model({