diff --git a/src/app/ai/page.tsx b/src/app/ai/page.tsx index f2956a3..12cb19c 100644 --- a/src/app/ai/page.tsx +++ b/src/app/ai/page.tsx @@ -77,6 +77,17 @@ export default function AIChatPage() { const userContent = input.trim(); setInput(""); + // Show user message immediately in UI + const tempUserMsg = { id: "temp-" + Date.now(), role: "user" as const, content: userContent, createdAt: new Date().toISOString() }; + if (currentSessionId) { + const sessionIdx = sessions.findIndex(s => s.id === currentSessionId); + if (sessionIdx >= 0) { + const updatedSessions = [...sessions]; + updatedSessions[sessionIdx] = { ...updatedSessions[sessionIdx], messages: [...(updatedSessions[sessionIdx].messages || []), tempUserMsg] }; + setSessions(updatedSessions); + } + } + // Auto-create session if none selected let sessionId = currentSessionId; if (!sessionId && childId) { @@ -89,7 +100,7 @@ export default function AIChatPage() { const data = await res.json(); if (data.session) { sessionId = data.session.id; - const newSession = { ...data.session, messages: [] }; + const newSession = { ...data.session, messages: [tempUserMsg] }; setSessions([newSession, ...sessions]); setCurrentSessionId(sessionId); } @@ -166,10 +177,18 @@ export default function AIChatPage() {