import { useState, useCallback } from 'react'; import { Box, AppBar, Toolbar, Typography, IconButton, Drawer, useMediaQuery, useTheme, Button, Chip, } from '@mui/material'; import MenuIcon from '@mui/icons-material/Menu'; import UndoIcon from '@mui/icons-material/Undo'; import CompressIcon from '@mui/icons-material/Compress'; import FiberManualRecordIcon from '@mui/icons-material/FiberManualRecord'; import { useSessionStore } from '@/store/sessionStore'; import { useAgentStore } from '@/store/agentStore'; import { useAgentWebSocket } from '@/hooks/useAgentWebSocket'; import SessionSidebar from '@/components/SessionSidebar/SessionSidebar'; import ChatInput from '@/components/Chat/ChatInput'; import MessageList from '@/components/Chat/MessageList'; import ApprovalModal from '@/components/ApprovalModal/ApprovalModal'; const DRAWER_WIDTH = 280; export default function AppLayout() { const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down('md')); const [mobileOpen, setMobileOpen] = useState(false); const { activeSessionId } = useSessionStore(); const { isConnected, isProcessing, getMessages } = useAgentStore(); const messages = activeSessionId ? getMessages(activeSessionId) : []; useAgentWebSocket({ sessionId: activeSessionId, onReady: () => console.log('Agent ready'), onError: (error) => console.error('Agent error:', error), }); const handleDrawerToggle = () => { setMobileOpen(!mobileOpen); }; const handleUndo = useCallback(async () => { if (!activeSessionId) return; try { await fetch(`/api/undo/${activeSessionId}`, { method: 'POST' }); } catch (e) { console.error('Undo failed:', e); } }, [activeSessionId]); const handleCompact = useCallback(async () => { if (!activeSessionId) return; try { await fetch(`/api/compact/${activeSessionId}`, { method: 'POST' }); } catch (e) { console.error('Compact failed:', e); } }, [activeSessionId]); const handleSendMessage = useCallback( async (text: string) => { if (!activeSessionId || !text.trim()) return; try { await fetch('/api/submit', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ session_id: activeSessionId, text: text.trim(), }), }); } catch (e) { console.error('Send failed:', e); } }, [activeSessionId] ); const drawer = setMobileOpen(false)} />; return ( {/* App Bar */} HF Agent } label={isConnected ? 'Connected' : 'Disconnected'} size="small" variant="outlined" sx={{ mr: 2 }} /> {/* Sidebar Drawer */} {/* Mobile drawer */} {drawer} {/* Desktop drawer */} {drawer} {/* Main Content */} {/* Spacer for fixed AppBar */} {activeSessionId ? ( <> ) : ( No session selected Create a new session from the sidebar to get started )} {/* Approval Modal */} ); }