From 49fe356b91ca5ba2966d99eb93ae8c16478faa5a Mon Sep 17 00:00:00 2001 From: diegosouzapw Date: Wed, 20 May 2026 00:40:00 -0300 Subject: [PATCH] fix(playground): guard against non-string model ids before .split/.startsWith The /v1/models endpoint can include synthetic entries (combos, locals, in-progress imports) with a null/undefined id. The playground used to call m.id.split("/") in the provider-discovery loop, which threw on the first non-string entry; the surrounding .catch(() => {}) silently swallowed the error, so the provider/model/account dropdowns ended up empty even though /v1/models returned thousands of valid entries. - Skip entries without a string id before split/startsWith. - Log the rejection in the .catch handler so future regressions are visible in DevTools instead of silently emptying the UI. --- src/app/(dashboard)/dashboard/playground/page.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/app/(dashboard)/dashboard/playground/page.tsx b/src/app/(dashboard)/dashboard/playground/page.tsx index 96b51e14a8..08e9b87c80 100644 --- a/src/app/(dashboard)/dashboard/playground/page.tsx +++ b/src/app/(dashboard)/dashboard/playground/page.tsx @@ -259,6 +259,7 @@ export default function PlaygroundPage() { const providerSet = new Set(); modelList.forEach((m) => { + if (typeof m?.id !== "string") return; const parts = m.id.split("/"); if (parts.length >= 2) providerSet.add(parts[0]); }); @@ -270,7 +271,9 @@ export default function PlaygroundPage() { setSelectedProvider(providerOpts[0].value); } }) - .catch(() => {}); + .catch((err) => { + console.error("[playground] Failed to load models:", err); + }); // Fetch ALL connections (once) fetch("/api/providers/client") @@ -295,6 +298,7 @@ export default function PlaygroundPage() { const seen = new Set(); const out: Array<{ value: string; label: string }> = []; for (const m of models) { + if (typeof m?.id !== "string") continue; if (selectedProvider && !m.id.startsWith(selectedProvider + "/")) continue; if (seen.has(m.id)) continue; seen.add(m.id); @@ -315,7 +319,9 @@ export default function PlaygroundPage() { setSelectedProvider(newProvider); setSelectedConnection(""); const providerModels = models - .filter((m) => !newProvider || m.id.startsWith(newProvider + "/")) + .filter( + (m) => typeof m?.id === "string" && (!newProvider || m.id.startsWith(newProvider + "/")) + ) .map((m) => m.id); const firstModel = providerModels[0] || ""; setSelectedModel(firstModel);