diff --git a/src/components/ai/AIChat.tsx b/src/components/ai/AIChat.tsx index 5e69b47..905f5d1 100644 --- a/src/components/ai/AIChat.tsx +++ b/src/components/ai/AIChat.tsx @@ -186,7 +186,8 @@ export function AIChat({ conversation, onConversationUpdate }: AIChatProps) { try { setStatus(`Connecting to ${conversation.model}...`); - await aiService.sendMessage( + // Start the message send (don't await yet) + const sendPromise = aiService.sendMessage( conversation.id, content, (_chunk, _fullContent) => { @@ -194,6 +195,15 @@ export function AIChat({ conversation, onConversationUpdate }: AIChatProps) { }, ); + // Small delay to let the user message and streaming assistant message be created + await new Promise((resolve) => setTimeout(resolve, 100)); + + // Load messages to show user message and start polling for streaming updates + await loadMessages(); + + // Now wait for the stream to complete + await sendPromise; + // Reload messages to get final state await loadMessages(); setStatus(null);