feat: per-user assistant name and system prompt customization
Each user can rename the AI assistant and edit their own system prompt in Settings.
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import { AGENT_SYSTEM_PROMPT } from "@/modules/agent/tools";
|
||||
|
||||
export const DEFAULT_ASSISTANT_NAME = "Assistant";
|
||||
export const MAX_ASSISTANT_NAME_LENGTH = 40;
|
||||
export const MAX_ASSISTANT_SYSTEM_PROMPT_LENGTH = 8000;
|
||||
|
||||
export function resolveAssistantSystemPrompt(customPrompt: string | null | undefined): string {
|
||||
const trimmed = customPrompt?.trim();
|
||||
return trimmed ? trimmed : AGENT_SYSTEM_PROMPT;
|
||||
}
|
||||
@@ -1,13 +1,40 @@
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "@/lib/db";
|
||||
import { DEFAULT_ASSISTANT_NAME } from "@/lib/assistant-config";
|
||||
import { users } from "@/modules/_core/schema";
|
||||
|
||||
export async function getAssistantEnabled(userId: string): Promise<boolean> {
|
||||
export {
|
||||
DEFAULT_ASSISTANT_NAME,
|
||||
MAX_ASSISTANT_NAME_LENGTH,
|
||||
MAX_ASSISTANT_SYSTEM_PROMPT_LENGTH,
|
||||
resolveAssistantSystemPrompt,
|
||||
} from "@/lib/assistant-config";
|
||||
|
||||
export type AssistantPreferences = {
|
||||
enabled: boolean;
|
||||
name: string;
|
||||
systemPrompt: string | null;
|
||||
};
|
||||
|
||||
export async function getAssistantPreferences(userId: string): Promise<AssistantPreferences> {
|
||||
const [row] = await db
|
||||
.select({ assistantEnabled: users.assistantEnabled })
|
||||
.select({
|
||||
assistantEnabled: users.assistantEnabled,
|
||||
assistantName: users.assistantName,
|
||||
assistantSystemPrompt: users.assistantSystemPrompt,
|
||||
})
|
||||
.from(users)
|
||||
.where(eq(users.id, userId))
|
||||
.limit(1);
|
||||
|
||||
return row?.assistantEnabled ?? false;
|
||||
return {
|
||||
enabled: row?.assistantEnabled ?? false,
|
||||
name: row?.assistantName?.trim() || DEFAULT_ASSISTANT_NAME,
|
||||
systemPrompt: row?.assistantSystemPrompt ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
export async function getAssistantEnabled(userId: string): Promise<boolean> {
|
||||
const prefs = await getAssistantPreferences(userId);
|
||||
return prefs.enabled;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user