From df6fb9a4602b8984426ac04477cc9426086c6df2 Mon Sep 17 00:00:00 2001 From: Adam <2363879+adamdotdevin@users.noreply.github.com> Date: Fri, 23 Oct 2026 17:03:43 -0500 Subject: [PATCH] fix(core): exclude realtime, embedding, and reranking models from the catalog (#58458) --- packages/core/src/models-dev.ts | 22 +++++++- packages/core/src/plugin/models-dev.ts | 5 ++ packages/core/test/models.test.ts | 32 +++++++++++ packages/core/test/plugin/models-dev.test.ts | 58 ++++++++++++++++++++ 4 files changed, 116 insertions(+), 1 deletion(-) diff --git a/packages/core/src/models-dev.ts b/packages/core/src/models-dev.ts index cc4b42635f3..05b63ec89f6 100644 --- a/packages/core/src/models-dev.ts +++ b/packages/core/src/models-dev.ts @@ -18,6 +18,20 @@ import snapshotText from "./models-dev/snapshot.txt" with { type: "text" } export const CatalogModelStatus = Schema.Literals(["alpha", "beta", "deprecated"]) export type CatalogModelStatus = typeof CatalogModelStatus.Type +// models.dev treats a model without a type as a chat model. +export const CatalogModelType = Schema.Literals([ + "chat", + "image", + "video", + "embedding", + "reranking", + "decision", + "transcription", + "speech", + "realtime", +]) +export type CatalogModelType = typeof CatalogModelType.Type + type Cost = { readonly input: Money.USDPerMillionTokens readonly output: Money.USDPerMillionTokens @@ -31,6 +45,7 @@ type Modality = "text" | "audio" | "image" | "video" | "pdf" type SourceModel = { readonly id: string readonly name: string + readonly type?: CatalogModelType readonly family?: string readonly release_date: string readonly attachment: boolean @@ -80,6 +95,8 @@ export type Snapshot = { readonly info: Provider.Info readonly models: readonly Model.Info[] readonly environment: readonly string[] + /** The models.dev type of each typed model, by catalog model ID. */ + readonly types?: ReadonlyMap } function nativePackage(provider: SourceProvider, model?: SourceModel) { @@ -108,12 +125,14 @@ function normalize(input: Record): readonly Snapshot[] { : {}), } satisfies Provider.Info const models: Model.Info[] = [] + const types = new Map() for (const model of Object.values(item.models)) { const baseCost = cost(model.cost) const id = Model.ID.make(model.id) const base = modelInfo(item, id, model, { cost: baseCost }) const variants = Variant.resolve({ ...base, package: nativePackage(item, model) }, supports(model)) models.push({ ...base, variants }) + if (model.type) types.set(id, model.type) for (const [mode, options] of Object.entries(model.experimental?.modes ?? {})) { const modeID = Model.ID.make(`${model.id}-${mode}`) models.push( @@ -124,9 +143,10 @@ function normalize(input: Record): readonly Snapshot[] { variants, }), ) + if (model.type) types.set(modeID, model.type) } } - providers.push({ info, models, environment: [...item.env] }) + providers.push({ info, models, environment: [...item.env], types }) } return providers } diff --git a/packages/core/src/plugin/models-dev.ts b/packages/core/src/plugin/models-dev.ts index 89a2b53a5eb..9a225d5201d 100644 --- a/packages/core/src/plugin/models-dev.ts +++ b/packages/core/src/plugin/models-dev.ts @@ -30,6 +30,10 @@ const BEDROCK_PROFILE_ONLY_IDS = [ "writer.palmyra-x5-v1:0", ] +// models.dev lists text input and output for these, but realtime models only run live voice sessions, and embedding +// and reranking models return vectors and scores, so none of them can answer a chat request. +const NON_CHAT_TYPES: readonly ModelsDev.CatalogModelType[] = ["realtime", "embedding", "reranking"] + export const ModelsDevPlugin = define({ id: "opencode.models.dev", effect: Effect.fn(function* (ctx) { @@ -97,6 +101,7 @@ function snapshots(data: readonly ModelsDev.Snapshot[]) { (model) => model.status !== "deprecated" && Model.supportsText(model) && + !NON_CHAT_TYPES.includes(provider.types?.get(model.id) ?? "chat") && !( provider.info.id === Provider.ID.amazonBedrock && BEDROCK_PROFILE_ONLY_IDS.includes(model.modelID ?? model.id) diff --git a/packages/core/test/models.test.ts b/packages/core/test/models.test.ts index 2919c8c2b4e..c4f952a1b32 100644 --- a/packages/core/test/models.test.ts +++ b/packages/core/test/models.test.ts @@ -85,6 +85,7 @@ const fixtureSnapshot = [ }, ], environment: ["ACME_API_KEY"], + types: new Map(), }, ] satisfies readonly ModelsDev.Snapshot[] @@ -147,6 +148,7 @@ const fixture2Snapshot = [ }, ], environment: ["BETA_API_KEY"], + types: new Map(), }, ] satisfies readonly ModelsDev.Snapshot[] @@ -294,6 +296,36 @@ describe("ModelsDev Service", () => { }), ) + it.live("keeps typed models in the snapshot with their models.dev type", () => + Effect.gen(function* () { + const cache = makeCache() + writeCache(cache, { + acme: { + ...fixture.acme, + models: { + ...fixture.acme.models, + "acme-live": { + ...fixture.acme.models["acme-1"], + id: "acme-live", + type: "realtime", + experimental: { modes: { fast: {} } }, + }, + }, + }, + }) + const state = yield* Ref.make(initialState) + const [acme] = yield* provided( + state, + cache, + ModelsDev.Service.use((service) => service.get()), + ) + expect(acme?.models.map((model) => model.id)).toEqual( + ["acme-1", "acme-live", "acme-live-fast"].map((id) => Model.ID.make(id)), + ) + expect(Object.fromEntries(acme?.types ?? [])).toEqual({ "acme-live": "realtime", "acme-live-fast": "realtime" }) + }), + ) + it.live("get() returns empty catalog when KV is empty, fetch disabled, and the bundled snapshot is disabled", () => Effect.gen(function* () { const cache = makeCache() diff --git a/packages/core/test/plugin/models-dev.test.ts b/packages/core/test/plugin/models-dev.test.ts index 58c1fe6f125..656608be894 100644 --- a/packages/core/test/plugin/models-dev.test.ts +++ b/packages/core/test/plugin/models-dev.test.ts @@ -706,6 +706,64 @@ describe("ModelsDevPlugin", () => { }), ) + it.effect("omits realtime, embedding, and reranking models even when they list text input and output", () => + Effect.gen(function* () { + const integrations = yield* Integration.Service + const providers = yield* Provider.Service + const modelState = yield* Model.Service + const providerID = Provider.ID.make("acme") + const ids = ["gpt-5.5", "gpt-audio", "jev-1.13", "gpt-realtime-2.1", "text-embedding-3-large", "rerank-v3.5"].map( + (id) => Model.ID.make(id), + ) + const model = { + providerID, + capabilities: { tools: true, input: ["text"], output: ["text"] }, + variants: [], + time: { released: Date.parse("2026-01-01") }, + cost: [], + status: "active", + enabled: true, + limit: { context: 128_000, output: 32_000 }, + } satisfies Omit + const snapshot = { + info: { + id: providerID, + name: "Acme", + activation: "auto", + package: "@opencode/ai/providers/openai-compatible", + }, + environment: [], + models: ids.map((id) => ({ ...model, id, modelID: id, name: id })), + // gpt-5.5 has no type, which models.dev treats as chat. + types: new Map([ + [Model.ID.make("gpt-audio"), "chat"], + [Model.ID.make("jev-1.13"), "decision"], + [Model.ID.make("gpt-realtime-2.1"), "realtime"], + [Model.ID.make("text-embedding-3-large"), "embedding"], + [Model.ID.make("rerank-v3.5"), "reranking"], + ]), + } satisfies ModelsDev.Snapshot + + yield* ModelsDevPlugin.effect( + host({ + provider: providerHost(providers), + integration: integrationHost(integrations), + }), + ).pipe( + Effect.provideService( + ModelsDev.Service, + ModelsDev.Service.of({ get: () => Effect.succeed([snapshot]), refresh: () => Effect.void }), + ), + ) + + yield* activate(providers) + const listed = yield* Effect.forEach(ids, (id) => modelState.get(providerID, id)) + expect(listed.flatMap((item) => item?.id ?? [])).toEqual( + ["gpt-5.5", "gpt-audio", "jev-1.13"].map((id) => Model.ID.make(id)), + ) + }), + ) + it.effect("registers key methods for providers with environment variables", () => Effect.gen(function* () { const integrations = yield* Integration.Service