From 8d26861fe8452c0b142b6129bd4bb255d250c2e1 Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Mon, 26 Oct 2026 22:01:16 -0500 Subject: [PATCH] fix(core): skip catalog entrypoints this build can't load (#59475) --- packages/core/src/models-dev.ts | 27 +++++++++---- packages/core/test/models.test.ts | 64 ++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 9 deletions(-) diff --git a/packages/core/src/models-dev.ts b/packages/core/src/models-dev.ts index 4c4e1dd1e1a..c8ac507483f 100644 --- a/packages/core/src/models-dev.ts +++ b/packages/core/src/models-dev.ts @@ -164,6 +164,7 @@ const BUILDS_OWN_URL = new Set([ const normalize = Effect.fnUntraced(function* (catalog: Record) { const failed: { readonly model: string; readonly issue: unknown }[] = [] + const unknown = new Set() const snapshots = Object.values(isV1(catalog) ? toV2(catalog) : catalog).flatMap((value) => { const item = Option.getOrUndefined(decodeProvider(value)) if (!item) return [] @@ -173,7 +174,7 @@ const normalize = Effect.fnUntraced(function* (catalog: Record) if (Result.isFailure(decoded)) failed.push({ model: `${item.id}/${key}`, issue: decoded.failure }) const model = Result.isSuccess(decoded) ? decoded.success : undefined // The fetch already asks for these types, but custom files and v1 catalogs may hold any type. - const target = model && TYPES.includes(model.type) && route(providerID, model) + const target = model && TYPES.includes(model.type) && route(providerID, model, unknown) return model && target ? [{ model, route: target }] : [] }) if (sources.length === 0) return [] @@ -218,6 +219,10 @@ const normalize = Effect.fnUntraced(function* (catalog: Record) models: failed.slice(0, 10).map((item) => item.model), issue: String(failed[0]?.issue), }) + if (unknown.size > 0) + yield* Effect.logDebug("Skipped models.dev APIs with entrypoints this build doesn't have", { + entrypoints: [...unknown], + }) return snapshots as readonly Snapshot[] }) @@ -227,17 +232,17 @@ function entries(record: Record | undefined, decode: (input: ) } -function route(providerID: Provider.ID, model: SourceModel): Route | undefined { +function route(providerID: Provider.ID, model: SourceModel, unknown: Set): Route | undefined { // A chat model uses its first API with a package. Other types (image, decision…) only run through // opencode's own packages, so they use their first API that has one, and are skipped without one. - const [protocol, api] = - entries(model.api, decodeApi).find(([, entry]) => - model.type === "chat" ? entry.sdk?.opencodeai || entry.sdk?.aisdk : entry.sdk?.opencodeai, - ) ?? [] + const [protocol, api, opencodeai] = + entries(model.api, decodeApi) + .map(([protocol, entry]) => [protocol, entry, loadable(entry.sdk?.opencodeai, unknown)] as const) + .find(([, entry, opencodeai]) => (model.type === "chat" ? opencodeai || entry.sdk?.aisdk : opencodeai)) ?? [] if (!protocol || !api) return undefined const aisdk = api.sdk?.aisdk const packageName = - api.sdk?.opencodeai ?? + opencodeai ?? (aisdk && (AISDKNative.native(aisdk, { providerID, @@ -259,6 +264,14 @@ function route(providerID: Provider.ID, model: SourceModel): Route | undefined { } } +// Newer catalogs may name @opencode/ai entrypoints that older builds don't ship, so those count as no package. +function loadable(opencodeai: string | undefined, unknown: Set) { + const name = Provider.packageName(opencodeai) + if (!name?.startsWith("@opencode/ai/") || Provider.builtinPackages.has(name)) return opencodeai + unknown.add(name) + return undefined +} + function mostCommon(values: readonly T[]) { const counts = new Map() for (const value of values) counts.set(value, (counts.get(value) ?? 0) + 1) diff --git a/packages/core/test/models.test.ts b/packages/core/test/models.test.ts index 9458adb5cad..b9a3801a2f5 100644 --- a/packages/core/test/models.test.ts +++ b/packages/core/test/models.test.ts @@ -352,7 +352,10 @@ describe("ModelsDev Service", () => { }, images: { base_url: "https://api.example.test/v1", - sdk: { aisdk: "@acme/ai-sdk-provider", opencodeai: "@opencode/ai/protocols/openai-images" }, + sdk: { + aisdk: "@acme/ai-sdk-provider", + opencodeai: "@opencode/ai/providers/openai-compatible/images", + }, }, }, experimental: { modes: { fast: {} } }, @@ -378,7 +381,7 @@ describe("ModelsDev Service", () => { ["acme-image-fast", "image"], ]) expect(acme?.models[1]?.capabilities).toMatchObject({ input: ["text", "image", "pdf"], output: ["image"] }) - expect(acme?.models[1]?.package).toBe("@opencode/ai/protocols/openai-images") + expect(acme?.models[1]?.package).toBe("@opencode/ai/providers/openai-compatible/images") // Without an opencode package a non-chat model is left out ("acme-sdk-image" above). }), ) @@ -436,6 +439,63 @@ describe("ModelsDev Service", () => { }), ) + it.effect("skips APIs whose opencode entrypoint this build doesn't have", () => + Effect.gen(function* () { + const unknown = (path: string) => ({ + base_url: "https://new.acme.test/v1", + sdk: { opencodeai: `@opencode/ai/providers/acme/${path}` }, + }) + const image = (id: string, api: Record) => + sourceModel(id, { type: "image", modalities: { input: ["text"], output: ["image/png"] }, api }) + const [acme] = yield* ModelsDev.decodeSnapshot( + JSON.stringify({ + acme: { + ...fixture.acme, + models: { + next: sourceModel("next", { + api: { "new-api": unknown("new-api"), ...sourceModel("next").api }, + }), + "sdk-fallback": sourceModel("sdk-fallback", { + api: { + "new-api": { + base_url: "https://claude.acme.test/v1", + sdk: { aisdk: "@ai-sdk/anthropic", opencodeai: "@opencode/ai/providers/acme/new-api" }, + }, + }, + }), + "unknown-only": sourceModel("unknown-only", { api: { "new-api": unknown("new-api") } }), + "image-unknown": image("image-unknown", { images: unknown("images") }), + "image-known": image("image-known", { + images: unknown("images"), + "openai-images": { + base_url: "https://api.acme.test/v1", + sdk: { opencodeai: "@opencode/ai/providers/openai-compatible/images" }, + }, + }), + }, + }, + }), + ) + const model = (id: string) => acme?.models.find((item) => item.id === id) + expect(acme?.models.map((item) => item.id)).toEqual( + ["next", "sdk-fallback", "image-known"].map((id) => Model.ID.make(id)), + ) + expect(acme?.info).toMatchObject({ + package: "@opencode/ai/providers/openai-compatible", + settings: { baseURL: "https://api.example.test/v1" }, + }) + expect(model("next")).toMatchObject({ package: undefined, settings: { provider: "acme" } }) + expect(model("sdk-fallback")).toMatchObject({ + package: "@opencode/ai/providers/anthropic", + settings: { baseURL: "https://claude.acme.test/v1" }, + }) + expect(model("image-known")).toMatchObject({ + package: "@opencode/ai/providers/openai-compatible/images", + settings: { baseURL: "https://api.acme.test/v1" }, + }) + }), + ) + it.live("drops model types opencode doesn't keep", () => Effect.gen(function* () { const cache = makeCache()