// Conversation sidebar with conversation list and management import { useConversation } from '@/contexts/ConversationContext'; import { useInference } from '@/contexts/InferenceContext'; import { useMCP } from '@/contexts/MCPContext'; export function ConversationSidebar() { const { conversations, activeConversationId, createConversation, deleteConversation, setActiveConversation, } = useConversation(); const { clearProvider, provider } = useInference(); const { connections, removeMcpServer } = useMCP(); const handleNewConversation = () => { createConversation(); }; const handleReset = () => { if (confirm('Are you sure you want to reset the application? This will clear all data including conversations, authentication, and server connections.')) { // Clear inference provider authentication clearProvider(); // Remove all MCP servers (this will disconnect them) connections.forEach(connection => { removeMcpServer(connection.id); }); // Clear all conversations conversations.forEach(conversation => { deleteConversation(conversation.id); }); // Clear ALL localStorage data localStorage.clear(); // Refresh the page to ensure clean state window.location.reload(); } }; const formatDate = (date: Date): string => { const now = new Date(); const diff = now.getTime() - date.getTime(); const days = Math.floor(diff / (1000 * 60 * 60 * 24)); if (days === 0) { return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); } else if (days === 1) { return 'Yesterday'; } else if (days < 7) { return date.toLocaleDateString([], { weekday: 'short' }); } else { return date.toLocaleDateString([], { month: 'short', day: 'numeric' }); } }; const getStatusIndicator = (status: string) => { switch (status) { case 'thinking': return '💭'; case 'calling_tools': return '🔧'; case 'error': return '❌'; default: return ''; } }; return (
{/* New Conversation Button */}
{/* Conversations List */}
{conversations.length === 0 ? (

No conversations yet.

Click "New Conversation" to get started.

) : (
{conversations.map((conversation) => (
setActiveConversation(conversation.id)} className={`p-3 rounded-lg cursor-pointer transition-colors group ${ activeConversationId === conversation.id ? 'bg-blue-100 dark:bg-blue-900/50 border border-blue-200 dark:border-blue-800' : 'hover:bg-gray-100 dark:hover:bg-gray-700' }`} >

{conversation.title}

{getStatusIndicator(conversation.status)}

{formatDate(conversation.updatedAt)}

{conversation.messages.length > 0 && (

{(() => { const lastMessage = conversation.messages[conversation.messages.length - 1]; const firstBlock = lastMessage?.content?.[0]; return firstBlock?.type === 'text' ? firstBlock.text : 'Tool interaction'; })()}

)}
))}
)}
{/* Reset Button */} {provider && (
)}
); }