import { useState, useEffect } from 'react'; import { useSessionManager } from '@/hooks/useSessionManager'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; import { Activity, Clock, Loader2, MessageSquare, X } from 'lucide-react'; import type { SessionState } from '@/lib/SessionManager'; import { cn } from '@/lib/utils'; interface SessionStatusIndicatorProps { className?: string; currentProjectId?: string; } /** * Component that shows the status of all active AI sessions */ export function SessionStatusIndicator({ className, currentProjectId }: SessionStatusIndicatorProps) { const sessionManager = useSessionManager(); const [sessions, setSessions] = useState([]); const [isOpen, setIsOpen] = useState(false); // Update sessions when they change useEffect(() => { const updateSessions = () => { setSessions(sessionManager.getAllSessions()); }; // Initial load updateSessions(); // Subscribe to session changes sessionManager.on('sessionCreated', updateSessions); sessionManager.on('sessionUpdated', updateSessions); sessionManager.on('sessionDeleted', updateSessions); return () => { sessionManager.off('sessionCreated', updateSessions); sessionManager.off('sessionUpdated', updateSessions); sessionManager.off('sessionDeleted', updateSessions); }; }, [sessionManager]); const activeSessions = sessions.filter(session => session.isLoading); const totalSessions = sessions.length; if (totalSessions === 0) { return null; } const handleStopSession = (sessionId: string, e: React.MouseEvent) => { e.stopPropagation(); sessionManager.stopGeneration(sessionId); }; const handleDeleteSession = (sessionId: string, e: React.MouseEvent) => { e.stopPropagation(); sessionManager.deleteSession(sessionId); }; const formatLastActivity = (date: Date) => { const now = new Date(); const diff = now.getTime() - date.getTime(); const minutes = Math.floor(diff / 60000); const hours = Math.floor(diff / 3600000); if (minutes < 1) return 'Just now'; if (minutes < 60) return `${minutes}m ago`; if (hours < 24) return `${hours}h ago`; return date.toLocaleDateString(); }; return (

AI Sessions

{totalSessions} active session{totalSessions !== 1 ? 's' : ''} {activeSessions.length > 0 && ` (${activeSessions.length} running)`}

{sessions.map((session) => (
{session.projectName}
{session.isLoading && ( )}
{session.messages.length} messages {formatLastActivity(session.lastActivity)}
{session.streamingMessage?.content && (

{session.streamingMessage.content.slice(0, 50)}...

)}
{session.isLoading && ( )}
))}
); }