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
+1
View File
@@ -0,0 +1 @@
ALTER TABLE "users" ADD COLUMN "assistant_model" text;
+7
View File
@@ -176,6 +176,13 @@
"when": 1780394000000,
"tag": "0024_user_assistant_customization",
"breakpoints": true
},
{
"idx": 25,
"version": "7",
"when": 1783560000000,
"tag": "0025_assistant_model",
"breakpoints": true
}
]
}
+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);
}
+3
View File
@@ -14,6 +14,7 @@ export type AssistantPreferences = {
enabled: boolean;
name: string;
systemPrompt: string | null;
model: string | null;
};
export async function getAssistantPreferences(userId: string): Promise<AssistantPreferences> {
@@ -22,6 +23,7 @@ export async function getAssistantPreferences(userId: string): Promise<Assistant
assistantEnabled: users.assistantEnabled,
assistantName: users.assistantName,
assistantSystemPrompt: users.assistantSystemPrompt,
assistantModel: users.assistantModel,
})
.from(users)
.where(eq(users.id, userId))
@@ -31,6 +33,7 @@ export async function getAssistantPreferences(userId: string): Promise<Assistant
enabled: row?.assistantEnabled ?? false,
name: row?.assistantName?.trim() || DEFAULT_ASSISTANT_NAME,
systemPrompt: row?.assistantSystemPrompt ?? null,
model: row?.assistantModel?.trim() || null,
};
}
+1
View File
@@ -38,6 +38,7 @@ export const users = pgTable("users", {
assistantEnabled: boolean("assistant_enabled").notNull().default(false),
assistantName: text("assistant_name").notNull().default("Assistant"),
assistantSystemPrompt: text("assistant_system_prompt"),
assistantModel: text("assistant_model"),
defaultEventReminderOffsets: jsonb("default_event_reminder_offsets")
.notNull()
.$type<number[]>()