fix(core): exclude realtime, embedding, and reranking models from the catalog (#58458)

This commit is contained in:
Adam
2026-10-23 17:03:43 -05:00
committed by GitHub
Unverified
parent 50989519c7
commit df6fb9a460
4 changed files with 116 additions and 1 deletions
+21 -1
View File
@@ -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<Model.ID, CatalogModelType>
}
function nativePackage(provider: SourceProvider, model?: SourceModel) {
@@ -108,12 +125,14 @@ function normalize(input: Record<string, SourceProvider>): readonly Snapshot[] {
: {}),
} satisfies Provider.Info
const models: Model.Info[] = []
const types = new Map<Model.ID, CatalogModelType>()
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<string, SourceProvider>): 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
}
+5
View File
@@ -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)
+32
View File
@@ -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()
@@ -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<Model.Info, "id" | "modelID" | "name">
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, ModelsDev.CatalogModelType>([
[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