mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-05 23:02:10 +03:00
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.
This commit is contained in:
@@ -259,6 +259,7 @@ export default function PlaygroundPage() {
|
|||||||
|
|
||||||
const providerSet = new Set<string>();
|
const providerSet = new Set<string>();
|
||||||
modelList.forEach((m) => {
|
modelList.forEach((m) => {
|
||||||
|
if (typeof m?.id !== "string") return;
|
||||||
const parts = m.id.split("/");
|
const parts = m.id.split("/");
|
||||||
if (parts.length >= 2) providerSet.add(parts[0]);
|
if (parts.length >= 2) providerSet.add(parts[0]);
|
||||||
});
|
});
|
||||||
@@ -270,7 +271,9 @@ export default function PlaygroundPage() {
|
|||||||
setSelectedProvider(providerOpts[0].value);
|
setSelectedProvider(providerOpts[0].value);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch((err) => {
|
||||||
|
console.error("[playground] Failed to load models:", err);
|
||||||
|
});
|
||||||
|
|
||||||
// Fetch ALL connections (once)
|
// Fetch ALL connections (once)
|
||||||
fetch("/api/providers/client")
|
fetch("/api/providers/client")
|
||||||
@@ -295,6 +298,7 @@ export default function PlaygroundPage() {
|
|||||||
const seen = new Set<string>();
|
const seen = new Set<string>();
|
||||||
const out: Array<{ value: string; label: string }> = [];
|
const out: Array<{ value: string; label: string }> = [];
|
||||||
for (const m of models) {
|
for (const m of models) {
|
||||||
|
if (typeof m?.id !== "string") continue;
|
||||||
if (selectedProvider && !m.id.startsWith(selectedProvider + "/")) continue;
|
if (selectedProvider && !m.id.startsWith(selectedProvider + "/")) continue;
|
||||||
if (seen.has(m.id)) continue;
|
if (seen.has(m.id)) continue;
|
||||||
seen.add(m.id);
|
seen.add(m.id);
|
||||||
@@ -315,7 +319,9 @@ export default function PlaygroundPage() {
|
|||||||
setSelectedProvider(newProvider);
|
setSelectedProvider(newProvider);
|
||||||
setSelectedConnection("");
|
setSelectedConnection("");
|
||||||
const providerModels = models
|
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);
|
.map((m) => m.id);
|
||||||
const firstModel = providerModels[0] || "";
|
const firstModel = providerModels[0] || "";
|
||||||
setSelectedModel(firstModel);
|
setSelectedModel(firstModel);
|
||||||
|
|||||||
Reference in New Issue
Block a user