fix(core): skip image models without an image package (#59926)

This commit is contained in:
Aiden Cline
2026-10-28 10:16:34 -05:00
committed by GitHub
Unverified
parent d1bd20facf
commit 8c2e163030
2 changed files with 46 additions and 6 deletions
+4 -5
View File
@@ -240,17 +240,16 @@ function entries<A>(record: Record<string, unknown> | undefined, decode: (input:
}
function route(providerID: Provider.ID, model: SourceModel, unknown: Set<string>): Route | undefined {
// A chat model uses its first API with a package. Other types (image, decision…) only run through
// opencode's own packages: among the ones this build can load, they prefer the entrypoint for their type
// (`providers/<P>/images`) over a chat API listed first, then their first API with one, and are skipped without one.
// A chat model uses its first API with a package. Other types (image, decision…) only run through the
// opencode entrypoint for their type (`providers/<P>/images`) that this build can load, and are skipped
// without one: a chat entrypoint loads a chat model, which can't generate images or decisions.
const apis = entries(model.api, decodeApi).map(
([protocol, entry]) => [protocol, entry, loadable(entry.sdk?.opencodeai, unknown)] as const,
)
const [protocol, api, opencodeai] =
(model.type === "chat"
? apis.find(([, entry, opencodeai]) => opencodeai || entry.sdk?.aisdk)
: (apis.find(([, , opencodeai]) => opencodeai?.endsWith(`/${model.type}s`)) ??
apis.find(([, , opencodeai]) => opencodeai))) ?? []
: apis.find(([, , opencodeai]) => opencodeai?.endsWith(`/${model.type}s`))) ?? []
if (!protocol || !api) return undefined
const aisdk = api.sdk?.aisdk
const packageName =
+42 -1
View File
@@ -496,11 +496,52 @@ describe("ModelsDev Service", () => {
}),
)
it.effect("skips non-chat models whose only opencode package serves another type", () =>
Effect.gen(function* () {
const api = (opencodeai: string) => ({
"chat-completions": { base_url: "https://api.acme.test/v1", sdk: { opencodeai } },
})
const chatPackage = "@opencode/ai/providers/openai-compatible"
const [acme] = yield* ModelsDev.decodeSnapshot(
JSON.stringify({
acme: {
...fixture.acme,
models: {
chat: sourceModel("chat", { api: api(chatPackage) }),
"image-chat-only": sourceModel("image-chat-only", { type: "image", api: api(chatPackage) }),
image: sourceModel("image", {
type: "image",
api: {
...api(chatPackage),
images: api("@opencode/ai/providers/openai-compatible/images")["chat-completions"],
},
}),
"decision-chat-only": sourceModel("decision-chat-only", { type: "decision", api: api(chatPackage) }),
"decision-image-only": sourceModel("decision-image-only", {
type: "decision",
api: api("@opencode/ai/providers/openrouter/images"),
}),
decision: sourceModel("decision", {
type: "decision",
api: api("@opencode/ai/providers/openrouter/decisions"),
}),
},
},
}),
)
expect(acme?.models.map((item) => [item.id, item.type, item.package ?? acme.info.package])).toEqual([
[Model.ID.make("chat"), "chat", chatPackage],
[Model.ID.make("image"), "image", "@opencode/ai/providers/openai-compatible/images"],
[Model.ID.make("decision"), "decision", "@opencode/ai/providers/openrouter/decisions"],
])
}),
)
it.live("drops model types opencode doesn't keep", () =>
Effect.gen(function* () {
const cache = makeCache()
const api = {
images: { base_url: "https://api.acme.test/v1", sdk: { opencodeai: "@opencode/ai/providers/openai" } },
images: { base_url: "https://api.acme.test/v1", sdk: { opencodeai: "@opencode/ai/providers/openai/images" } },
}
const model = (id: string, type: string) => ({
id,