fix(backend): validate configured model provider pair

This commit is contained in:
User
2026-07-14 18:39:37 +02:00
parent c463de8da2
commit 3d23d0543c
5 changed files with 61 additions and 7 deletions
+7 -3
View File
@@ -25,15 +25,19 @@ export function settingsRoutes(
app.put("/settings", async (req, reply) => {
const b = (req.body ?? {}) as Settings;
if (b.model) {
let available: { id: string }[] = [];
let available: { provider: string; id: string }[] = [];
try {
available = await deps.listModels();
} catch {
available = [];
}
// Only validate when Pi gave us a non-empty list; otherwise allow (degraded).
if (available.length > 0 && !available.some((m) => m.id === b.model)) {
return reply.code(400).send({ error: `Unknown model: ${b.model}` });
if (available.length > 0 && !available.some(
(candidate) => candidate.provider === b.provider && candidate.id === b.model,
)) {
return reply.code(400).send({
error: `Unknown model: ${b.provider ?? "unknown"}/${b.model}`,
});
}
}
const next: Settings = {