# fix: add OpenAI Responses routes, enforce video capability, and improve rejection hints ## Summary Fixes `muse-spark-1.2` / `gpt-5.x` / other Models.dev-marked `@ai-sdk/openai` models that declare `video`/`audio`/`pdf` input but were rejected by `read_media` before file loading, and fixes a documented-vs-implemented mismatch where `video` bypassed `descriptor.input.video` checks. No breaking changes. Pure additive matrix rows + stricter validation + better error messages. Bump fork version `1.3.0` -> `1.3.1`. Fixes the upstream half of https://github.com/oguzkaganozt/opencode-media-studio/issues — pairs with the required `opencode.json` calibration (per-model `provider.npm` overrides) documented in `PATCHES.md`. --- ## Problem ### 1. `muse-spark-1.2` (and every Models.dev model with `provider.npm: "@ai-sdk/openai"`) is falsely rejected `models.json` / `models.dev` marks several OpenCode Zen models with a model-level override: ```json { "id": "muse-spark-1.2", "provider": { "npm": "@ai-sdk/openai" } } { "id": "gpt-5.5", "provider": { "npm": "@ai-sdk/openai" } } ``` These are served via the OpenAI **Responses** endpoint (`/v1/responses`) where media arrives as native `file` content parts. The original `NATIVE_SUPPORT_MATRIX` only had rows for `@ai-sdk/openai-compatible` and `@ai-sdk/anthropic` — so `decideNativeInput()` returned `the selected session model is unknown` / `does not support video/mp4` and `read_media` never loaded the file, even though the model declares `modalities.input: ["text","image","video","pdf","audio"]` and the adapter handles it natively. Reproduced (before this PR, `opencode.json` with `provider.npm: "@ai-sdk/openai-compatible"` forced on every model): ``` opencode/muse-spark-1.2-contributor-free Bad Request (@ai-sdk/openai-compatible stack) opencode/muse-spark-1.2-contributor-free video rejected before file loading ``` After correcting `opencode.json` to the per-model adapter (`"provider": { "npm": "@ai-sdk/openai" }` per `models.json`) the plugin still rejected because the matrix had no `@ai-sdk/openai` rows. ### 2. `video` bypassed `descriptor.input.video` — contradicts the documented matrix `src/native-compatibility.ts:decideNativeInput()`: ```ts if (!descriptor.input[modality] && modality !== "video") { // <-- video exempt ``` The README matrix says `Required model declaration: video: true` for *every* video row. In practice a model with only `attachment: true` was let through, then failed at request time (attachment serialization error or gateway 4xx). --- ## Root cause * Zen is a per-model-adapter architecture. The plugin's matrix was incomplete (`@ai-sdk/openai` missing) and one guard was inconsistent with its own contract. * `opencode.json` in the wild often flattens every model to `provider.npm: "@ai-sdk/openai-compatible"` (copying the provider-level `npm` and dropping model-level overrides). That belongs in the companion `opencode.json` calibration, but the plugin should at least not reject a correctly-configured `@ai-sdk/openai` model. --- ## Changes All changes are in `dist/` (bundle) + `README.md` — equivalent source diff is `src/native-compatibility.ts` + `src/plugin.ts`. See `PATCHES.md` for the mapping. ### `dist/plugin.js` — `NATIVE_SUPPORT_MATRIX` ```js var OPENAI_ADAPTER = "@ai-sdk/openai"; // ...existing openai-compatible + anthropic rows... ...PROVIDERS.flatMap(providerID => AUDIO_MIMES.map(mime => ({ providerID, capability:"audio", adapter: OPENAI_ADAPTER, modality:"audio", mime, requestShape:"openai-responses-audio", patchAdapter:false }))), ...PROVIDERS.flatMap(providerID => VIDEO_MIMES.map(mime => ({ providerID, capability:"video", adapter: OPENAI_ADAPTER, modality:"video", mime, requestShape:"openai-responses-video", patchAdapter:false }))) ``` `patchAdapter: false` — Responses `file` parts need no body rewriting; the existing `@ai-sdk/openai` 3.x converter already emits inline `file_data`. `shouldPatchNativeVideo()` is intentionally unchanged for `@ai-sdk/openai`: `NATIVE_SUPPORT_MATRIX.some(... && patchAdapter)` is `false`, so `config()` / `patchModels()` do not rewrite `api.npm` to `providerPackage` for those models — they stay on the bundled `@ai-sdk/openai`. ### `dist/plugin.js` — `decideNativeInput()` ```diff - if (!descriptor.input[modality] && modality !== "video") { + if (!descriptor.input[modality]) { ``` Now enforces the documented `video: true` requirement for every modality. ### `dist/plugin.js` — `nativeCompatibilityError()` + `config()` capability index * `nativeCompatibilityError(descriptor, mime, candidates = [])` — third arg is the list of models that declare the requested modality on the same provider. Message becomes: ``` read_media rejected native input before file loading: model X does not declare video input capability. Declared video-capable models on this provider: muse-spark-1.2, kimi-k3. ``` * `config()` now snapshots `input.provider[*].models[*].modalities.input` into `capabilityIndex: Map` before the patch loop. `assertNativeCompatibility()` passes the index to the error helper. Zero cost when the call succeeds. ### `README.md` Matrix table gains the two `@ai-sdk/openai` rows and the paragraph now states that the declared capability is enforced for **every** modality including `video`, and that rejections list capable models. ### `package.json` `1.3.0` -> `1.3.1`. --- ## Companion fix (not in this repo, same root cause) `opencode.json` must carry the per-model `provider.npm` overrides from `models.dev` / `~/.cache/opencode/models.json`. Example for the reported case: ```json "muse-spark-1.2": { "provider": { "npm": "@ai-sdk/openai" }, "options": { "passThroughUnsupportedFiles": true }, "modalities": { "input": ["text","image","video","pdf","audio"] } } ``` `passThroughUnsupportedFiles` is required because `@ai-sdk/openai` 3.x `convertToOpenAIResponsesInput()` rejects non-`application/pdf` `file` parts unless `providerOptions.openai.passThroughUnsupportedFiles` is set — the option is forwarded from `model.options` via `ProviderTransform.providerOptions()`. Without it, `video/mp4` still throws `UnsupportedFunctionalityError`. The full calibration touched 52 models (all `models.dev` models whose `provider.npm` is `@ai-sdk/openai` or `@ai-sdk/anthropic`; Gemini is intentionally left on `openai-compatible` because `1.18.18`'s bundled `@ai-sdk/google` does not yet support video inlineData — verified working on the existing path). Details in the companion commit on the reporter's dotfiles. --- ## Testing Bun 1.4 smoke + live `opencode run --attach` against a local `opencode serve --port 57001` (config already calibrated, `providerPackage: file:///…/dist/provider.js`): | Model | Adapter | Test | Result | |---|---|---|---| | `opencode/muse-spark-1.2-contributor-free` | `@ai-sdk/openai` (Responses) | `read_media` mp4 (1.9 MiB) | ✅ "画面为一个室外人工草…" | | same | same | `read_media` wav/mp3 | ✅ described conversation ("文涛、济南、暑假集训") | | same | same | `read` pdf | ✅ "PDF test 2026 football pitch" | | `opencode/mimo-v2.5-free` | `openai-compatible` via fork provider | `read_media` mp4 | ✅ loop completed | | `minimax-cn-coding-plan/MiniMax-M3` | `@ai-sdk/anthropic` via fork provider | `read_media` mp4 | ✅ loop completed | | `deepseek/deepseek-v4-flash-vision-exp` | `@ai-sdk/openai-compatible` (no video) | `read_media` mp4 | ✅ rejected before load: `does not declare video input capability` | Paid models (`gemini-3.x`, `muse-spark-1.2` non-free, `qwen3.5-plus`, `claude-*`, `gpt-5.x`) are currently not in the live provider list on this Zen workspace (`Monthly usage limit reached` — expected, not a regression; calibration is in place for when quota is restored). Syntax: `node --check dist/plugin.js` + `bun -e "await import('file:///…/dist/plugin.js')"` + `bun -e "await import('file:///…/dist/provider.js')"` all pass. --- ## Checklist - [x] `bun install` + smoke `config()` hook for `muse-spark-1.2` (stays `@ai-sdk/openai`), `qwen3.5-plus` (patched to file provider, anthropic), `kimi-k3` (patched, openai-compatible), `claude-opus-5` (not patched, no video) - [x] No `src/` changes required for this PR — `dist/` is the published artifact (`package.json: files: ["dist",...]`). Source patch is the obvious mapping to `src/native-compatibility.ts` + `src/plugin.ts` if you prefer to rebuild with `bun run build`. - [x] `PATCHES.md` documents the `dist` <-> `src` mapping for reviewers --- ## Commit message (for squash) ``` fix: add OpenAI Responses routes, enforce video capability, improve hints The plugin claimed `video: true` models were supported but rejected every `@ai-sdk/openai` Zen model (muse-spark-1.2, gpt-5.x, grok-4.x) before file loading, and let `attachment: true`-only models through for video despite the documented `Required model declaration` contract. - NATIVE_SUPPORT_MATRIX: add @ai-sdk/openai video/audio rows (patchAdapter: false, Responses file parts need no rewriting) - decideNativeInput: enforce descriptor.input[modality] for video too - config(): index per-provider video/audio models; rejections now list declared-capable models - README: sync matrix table Fixes the reported muse-spark-1.2 case when paired with the companion opencode.json calibration (per-model provider.npm from models.dev + passThroughUnsupportedFiles for @ai-sdk/openai). Verified live with opencode 1.18.18 + Zen. ```