From 1368d84baccb50d17a26f102e7b3ea16e93dfcdd Mon Sep 17 00:00:00 2001 From: Prakhar Pandey Date: Mon, 22 Jun 2026 12:49:48 +0530 Subject: [PATCH] fix(onboarding): filter non-chat models from provider list using models.dev --- apps/x/packages/core/src/models/models-dev.ts | 19 +++++++++++++++++++ apps/x/packages/core/src/models/models.ts | 12 +++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/apps/x/packages/core/src/models/models-dev.ts b/apps/x/packages/core/src/models/models-dev.ts index 4a86c1b2..50e91411 100644 --- a/apps/x/packages/core/src/models/models-dev.ts +++ b/apps/x/packages/core/src/models/models-dev.ts @@ -224,3 +224,22 @@ export async function listOnboardingModels(): Promise<{ providers: ProviderSumma return { providers, lastUpdated: fetchedAt }; } + +export async function getChatModelIds( + flavor: "openai" | "anthropic" | "google", +): Promise> { + try { + const { data } = await getModelsDevData(); + const provider = pickProvider(data, flavor); + if (!provider) return new Set(); + const ids = new Set(); + for (const [id, model] of Object.entries(provider.models)) { + if (isStableModel(model) && supportsToolCall(model)) { + ids.add(model.id ?? id); + } + } + return ids; + } catch { + return new Set(); + } +} diff --git a/apps/x/packages/core/src/models/models.ts b/apps/x/packages/core/src/models/models.ts index 1939f7b7..c50393c6 100644 --- a/apps/x/packages/core/src/models/models.ts +++ b/apps/x/packages/core/src/models/models.ts @@ -10,6 +10,7 @@ import { LlmModelConfig, LlmProvider } from "@x/shared/dist/models.js"; import z from "zod"; import { getGatewayProvider } from "./gateway.js"; import { getDefaultModelAndProvider, resolveProviderConfig } from "./defaults.js"; +import { getChatModelIds } from "./models-dev.js"; import { withUseCase } from "../analytics/use_case.js"; export const Provider = LlmProvider; @@ -158,7 +159,16 @@ export async function listModelsForProvider( // OpenAI-shaped: { data: [{ id: "..." }] } ids = (data.data ?? []).map((m: { id: string }) => m.id); } - return ids.filter((id: string) => typeof id === "string" && id.length > 0); + const cleaned = ids.filter((id: string) => typeof id === "string" && id.length > 0); + if (flavor === "openai" || flavor === "anthropic" || flavor === "google") { + const chatIds = await getChatModelIds(flavor); + // Only filter when models.dev returned data; if it's empty (offline/no + // cache/unknown provider) keep the full list rather than showing none. + if (chatIds.size > 0) { + return cleaned.filter((id) => chatIds.has(id)); + } + } + return cleaned; } finally { clearTimeout(timeout); }