/** * Chat Page * Conversation interface with AI */ import { useState, useEffect, useRef } from 'react'; import { Send, Trash2, Bot, User } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Card, CardContent } from '@/components/ui/card'; import { useChatStore } from '@/stores/chat'; import { LoadingSpinner } from '@/components/common/LoadingSpinner'; import { cn, formatRelativeTime } from '@/lib/utils'; export function Chat() { const { messages, loading, sending, fetchHistory, sendMessage, clearHistory } = useChatStore(); const [input, setInput] = useState(''); const messagesEndRef = useRef(null); // Fetch history on mount useEffect(() => { fetchHistory(); }, [fetchHistory]); // Auto-scroll to bottom on new messages useEffect(() => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }, [messages]); // Handle send message const handleSend = async () => { if (!input.trim() || sending) return; const content = input.trim(); setInput(''); await sendMessage(content); }; // Handle key press const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSend(); } }; return (
{/* Messages Area */}
{loading ? (
) : messages.length === 0 ? (

No messages yet

Start a conversation with your AI assistant

) : ( <> {messages.map((message) => (
{/* Avatar */}
{message.role === 'user' ? ( ) : ( )}
{/* Message Content */}

{message.content}

{formatRelativeTime(message.timestamp)}

{/* Tool Calls */} {message.toolCalls && message.toolCalls.length > 0 && (
{message.toolCalls.map((tool) => (

Tool: {tool.name}

Status: {tool.status}

))}
)}
))}
)}
{/* Input Area */}
setInput(e.target.value)} onKeyPress={handleKeyPress} placeholder="Type a message..." disabled={sending} className="flex-1" />
); } export default Chat;