feat: multiple named conversations for the cooking assistant
The general assistant had exactly one conversation per user forever (recipeId null on chat_messages) — no way to start fresh or organize by topic. Adds an ai_conversations table (title, timestamps) and a nullable conversationId FK on chat_messages; the assistant panel gets a conversations menu to create/switch/rename/delete, auto-titling a new conversation from its first question. Per-recipe chat is untouched — each recipe already has one natural thread, so multi-conversation support only applies to the homepage assistant. Pre-existing general messages (no conversationId) aren't migrated into the new model and won't appear in the conversation list. Requires migration 0042 to run against a live DB — not applied in this sandbox (no Docker here); run `pnpm db:migrate`. v0.43.0
This commit is contained in:
@@ -5,6 +5,7 @@ import { requireSessionOrApiKey } from "@/lib/api-auth";
|
||||
|
||||
const Schema = z.object({
|
||||
recipeId: z.string().uuid().optional(),
|
||||
conversationId: z.string().uuid().optional(),
|
||||
// "general" restricts to the homepage cooking assistant (recipeId null);
|
||||
// omit both recipeId and scope to search across everything.
|
||||
scope: z.enum(["general"]).optional(),
|
||||
@@ -19,6 +20,7 @@ export async function GET(req: NextRequest) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const parsed = Schema.safeParse({
|
||||
recipeId: searchParams.get("recipeId") ?? undefined,
|
||||
conversationId: searchParams.get("conversationId") ?? undefined,
|
||||
scope: searchParams.get("scope") ?? undefined,
|
||||
q: searchParams.get("q") ?? undefined,
|
||||
limit: searchParams.get("limit") ?? undefined,
|
||||
@@ -26,10 +28,11 @@ export async function GET(req: NextRequest) {
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json({ error: "Validation error" }, { status: 400 });
|
||||
}
|
||||
const { recipeId, scope, q, limit } = parsed.data;
|
||||
const { recipeId, conversationId, scope, q, limit } = parsed.data;
|
||||
|
||||
const conditions = [eq(chatMessages.userId, session!.user.id)];
|
||||
if (recipeId) conditions.push(eq(chatMessages.recipeId, recipeId));
|
||||
else if (conversationId) conditions.push(eq(chatMessages.conversationId, conversationId));
|
||||
else if (scope === "general") conditions.push(isNull(chatMessages.recipeId));
|
||||
if (q?.trim()) conditions.push(ilike(chatMessages.content, `%${q.trim()}%`));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user