feat(agent): persist assistant model preference

This commit is contained in:
ginnoir
2026-07-08 16:24:01 -05:00
parent 876e72671a
commit bf7e07ead9
5 changed files with 32 additions and 0 deletions
+20
View File
@@ -9,6 +9,7 @@ import {
MAX_ASSISTANT_NAME_LENGTH,
MAX_ASSISTANT_SYSTEM_PROMPT_LENGTH,
} from "@/lib/assistant-config";
import { isValidLlmModelId, listLlmModels } from "@/lib/llm/models";
import { users } from "@/modules/_core/schema";
import { getCurrentSession } from "@/lib/session";
@@ -50,6 +51,25 @@ export async function setAssistantSystemPrompt(prompt: string | null): Promise<v
revalidateAssistantSurfaces();
}
export async function setAssistantModel(model: string | null): Promise<void> {
const { user } = await getCurrentSession();
const normalized = model?.trim() || null;
if (normalized !== null && !isValidLlmModelId(normalized)) {
throw new Error("Invalid assistant model");
}
const available = await listLlmModels();
const requested = normalized === available.fallbackModel ? null : normalized;
if (requested !== null && !available.models.some((option) => option.id === requested)) {
throw new Error("Invalid assistant model");
}
await db.update(users).set({ assistantModel: requested }).where(eq(users.id, user.id));
revalidateAssistantSurfaces();
}
export async function resetAssistantName(): Promise<void> {
await setAssistantName(DEFAULT_ASSISTANT_NAME);
}