import { ChatSession, getSessions } from '@/api/lightrag' import Button from '@/components/ui/Button' import { ScrollArea } from '@/components/ui/ScrollArea' import { cn } from '@/lib/utils' import { format } from 'date-fns' import { MessageSquareIcon, PlusIcon } from 'lucide-react' import { useEffect, useState } from 'react' interface SessionManagerProps { currentSessionId: string | null onSessionSelect: (sessionId: string) => void onNewSession: () => void } export default function SessionManager({ currentSessionId, onSessionSelect, onNewSession }: SessionManagerProps) { const [sessions, setSessions] = useState([]) const [isLoading, setIsLoading] = useState(false) const fetchSessions = async () => { setIsLoading(true) try { const data = await getSessions() setSessions(data) } catch (error) { console.error('Failed to fetch sessions:', error) } finally { setIsLoading(false) } } useEffect(() => { fetchSessions() }, [currentSessionId]) // Refresh list when session changes (e.g. new one created) const handleNewSession = async () => { onNewSession() } return (
{sessions.map((session) => ( ))} {sessions.length === 0 && !isLoading && (
No history yet
)}
) }