|
6 | 6 | type ExportModel, |
7 | 7 | type GajaeGeneratedConfig, |
8 | 8 | type HermesGeneratedConfig, |
| 9 | + type OpencodeGeneratedConfig, |
9 | 10 | type PiGeneratedConfig, |
10 | 11 | } from "../../src/clients/config-export"; |
11 | 12 | import type { OcxConfig } from "../../src/types"; |
@@ -52,6 +53,11 @@ function hermesModels(models: ExportModel[]) { |
52 | 53 | .providers[OPENCODE_PROVIDER_ID].models; |
53 | 54 | } |
54 | 55 |
|
| 56 | +function opencodeModels(models: ExportModel[]) { |
| 57 | + return (buildClientConfig("opencode", ctx(models)) as OpencodeGeneratedConfig) |
| 58 | + .providers[OPENCODE_PROVIDER_ID].models; |
| 59 | +} |
| 60 | + |
55 | 61 | /** The live failure, by its real id and real modality list. */ |
56 | 62 | const MIXED: ExportModel = { |
57 | 63 | namespaced: "zenmux/meta-muse-spark-1.1", |
@@ -147,3 +153,94 @@ describe("exported modalities stay inside the enum each client accepts", () => { |
147 | 153 | } |
148 | 154 | }); |
149 | 155 | }); |
| 156 | + |
| 157 | +/** |
| 158 | + * opencode is the third shape of this problem, and the only one where the fix is a |
| 159 | + * capability field rather than a filter. |
| 160 | + * |
| 161 | + * Its model schema accepts a WIDER enum than our internal vocabulary |
| 162 | + * (`text | audio | image | video | pdf`, opencode.ai/config.json), and its client gates |
| 163 | + * pasting on `attachment` / `modalities.input` INSTEAD of rejecting the file we hand it. So |
| 164 | + * an out-of-enum value is dropped, but a row left with nothing acceptable keeps its entry |
| 165 | + * and carries no capability keys — never a fabricated `text`, which would advertise input |
| 166 | + * the model cannot read. |
| 167 | + */ |
| 168 | +describe("opencode receives the capability fields its client gates attachments on", () => { |
| 169 | + test("a declared model advertises attachment plus every modality opencode accepts", () => { |
| 170 | + // The live catalog shape: meta-muse-spark-1.1 declares text|image|audio, and audio is |
| 171 | + // INSIDE opencode's enum, so unlike Pi and Gajae nothing is dropped here. |
| 172 | + expect(opencodeModels([MIXED])["zenmux/meta-muse-spark-1.1"]).toEqual({ |
| 173 | + name: "meta-muse-spark-1.1 (zenmux)", |
| 174 | + limit: { context: 1_048_576, output: 32_000 }, |
| 175 | + attachment: true, |
| 176 | + modalities: { input: ["text", "image", "audio"], output: ["text"] }, |
| 177 | + }); |
| 178 | + }); |
| 179 | + |
| 180 | + test("an audio-only row stays audio-only instead of being retyped as text", () => { |
| 181 | + // opencode accepts audio, so the Pi/Gajae answer — omit the row — would lose a model for |
| 182 | + // no reason. Faithfulness costs nothing here. |
| 183 | + expect(opencodeModels([AUDIO_ONLY])["p/audio-only"]).toEqual({ |
| 184 | + name: "audio-only (p)", |
| 185 | + attachment: true, |
| 186 | + modalities: { input: ["audio"], output: ["text"] }, |
| 187 | + }); |
| 188 | + }); |
| 189 | + |
| 190 | + test("a text-only declaration is advertised as text-only rather than omitted", () => { |
| 191 | + const textOnly: ExportModel = { namespaced: "p/text", provider: "p", id: "text", inputModalities: ["text"] }; |
| 192 | + expect(opencodeModels([textOnly])["p/text"]).toEqual({ |
| 193 | + name: "text (p)", |
| 194 | + attachment: false, |
| 195 | + modalities: { input: ["text"], output: ["text"] }, |
| 196 | + }); |
| 197 | + }); |
| 198 | + |
| 199 | + test("a row that declares nothing carries no capability keys at all", () => { |
| 200 | + // Not the same as `{ input: ["text"] }`: opencode already falls back to text-only for an |
| 201 | + // entry without capabilities, and the omission keeps the pre-#4286 bytes for every model |
| 202 | + // whose row says nothing. |
| 203 | + const bare: ExportModel = { namespaced: "p/bare", provider: "p", id: "bare" }; |
| 204 | + const empty: ExportModel = { ...bare, namespaced: "p/empty", id: "empty", inputModalities: [] }; |
| 205 | + const models = opencodeModels([bare, empty]); |
| 206 | + expect(models["p/bare"]).toEqual({ name: "bare (p)" }); |
| 207 | + expect(models["p/empty"]).toEqual({ name: "empty (p)" }); |
| 208 | + }); |
| 209 | + |
| 210 | + test("an out-of-enum value is dropped and duplicates collapse", () => { |
| 211 | + const odd: ExportModel = { |
| 212 | + namespaced: "p/odd", provider: "p", id: "odd", inputModalities: ["file", "image", "image"], |
| 213 | + }; |
| 214 | + expect(opencodeModels([odd])["p/odd"]).toEqual({ |
| 215 | + name: "odd (p)", |
| 216 | + attachment: true, |
| 217 | + modalities: { input: ["image"], output: ["text"] }, |
| 218 | + }); |
| 219 | + }); |
| 220 | + |
| 221 | + test("a model whose only declaration is out of enum keeps its entry, without capabilities", () => { |
| 222 | + const foreign: ExportModel = { namespaced: "p/foreign", provider: "p", id: "foreign", inputModalities: ["file"] }; |
| 223 | + expect(opencodeModels([foreign])["p/foreign"]).toEqual({ name: "foreign (p)" }); |
| 224 | + }); |
| 225 | + |
| 226 | + test("no emitted entry in a whole catalog carries a value opencode rejects", () => { |
| 227 | + const catalog: ExportModel[] = [ |
| 228 | + MIXED, |
| 229 | + AUDIO_ONLY, |
| 230 | + { namespaced: "p/bare", provider: "p", id: "bare" }, |
| 231 | + { namespaced: "p/foreign", provider: "p", id: "foreign", inputModalities: ["file"] }, |
| 232 | + { namespaced: "p/vision", provider: "p", id: "vision", inputModalities: ["text", "image"] }, |
| 233 | + ]; |
| 234 | + const models = opencodeModels(catalog); |
| 235 | + // The entry survives where Pi and Gajae would have dropped it; only its bad value goes. |
| 236 | + expect(Object.keys(models)).toContain("p/foreign"); |
| 237 | + for (const entry of Object.values(models)) { |
| 238 | + for (const value of entry.modalities?.input ?? []) { |
| 239 | + expect(["text", "audio", "image", "video", "pdf"]).toContain(value); |
| 240 | + } |
| 241 | + for (const value of entry.modalities?.output ?? []) { |
| 242 | + expect(["text", "audio", "image", "video", "pdf"]).toContain(value); |
| 243 | + } |
| 244 | + } |
| 245 | + }); |
| 246 | +}); |
0 commit comments