'use client' import Image from 'next/image' import { useEffect, useState } from 'react' import { useMissionControl } from '@/store' import { useNavigateToPanel } from '@/lib/navigation' import { createClientLogger } from '@/lib/client-logger' import { Button } from '@/components/ui/button' const log = createClientLogger('Sidebar') type SystemStats = { memory?: { used: number total: number } disk?: { usage?: string } processes?: unknown[] } function readSystemStats(value: unknown): SystemStats | null { if (!value || typeof value !== 'object') return null const record = value as Record const memory = record.memory && typeof record.memory === 'object' ? record.memory as Record : null const disk = record.disk && typeof record.disk === 'object' ? record.disk as Record : null return { memory: memory && typeof memory.used === 'number' && typeof memory.total === 'number' ? { used: memory.used, total: memory.total } : undefined, disk: disk ? { usage: typeof disk.usage === 'string' ? disk.usage : undefined } : undefined, processes: Array.isArray(record.processes) ? record.processes : undefined, } } interface MenuItem { id: string label: string icon: string description?: string } const menuItems: MenuItem[] = [ { id: 'overview', label: 'Overview', icon: '📊', description: 'System dashboard' }, { id: 'chat', label: 'Chat', icon: '💬', description: 'Agent chat sessions' }, { id: 'tasks', label: 'Task Board', icon: '📋', description: 'Kanban task management' }, { id: 'agents', label: 'Agent Squad', icon: '🤖', description: 'Agent management & status' }, { id: 'activity', label: 'Activity Feed', icon: '📣', description: 'Real-time activity stream' }, { id: 'notifications', label: 'Notifications', icon: '🔔', description: 'Mentions & alerts' }, { id: 'standup', label: 'Daily Standup', icon: '📈', description: 'Generate standup reports' }, { id: 'spawn', label: 'Spawn Agent', icon: '🚀', description: 'Launch new sub-agents' }, { id: 'logs', label: 'Logs', icon: '📝', description: 'Real-time log viewer' }, { id: 'cron', label: 'Cron Jobs', icon: '⏰', description: 'Automated tasks' }, { id: 'memory', label: 'Memory', icon: '🧠', description: 'Knowledge browser' }, { id: 'tokens', label: 'Tokens', icon: '💰', description: 'Usage & cost tracking' }, { id: 'channels', label: 'Channels', icon: '📡', description: 'Messaging platform status' }, { id: 'nodes', label: 'Nodes', icon: '🖥', description: 'Connected instances' }, { id: 'exec-approvals', label: 'Approvals', icon: '✅', description: 'Exec approval queue' }, { id: 'debug', label: 'Debug', icon: '🐛', description: 'System diagnostics' }, ] export function Sidebar() { const { activeTab, connection, sessions } = useMissionControl() const navigateToPanel = useNavigateToPanel() const [systemStats, setSystemStats] = useState(null) useEffect(() => { let cancelled = false fetch('/api/status?action=overview') .then(res => res.json()) .then(data => { if (!cancelled) setSystemStats(readSystemStats(data)) }) .catch(err => log.error('Failed to fetch system status:', err)) return () => { cancelled = true } }, []) const activeSessions = sessions.filter(s => s.active).length const totalSessions = sessions.length return ( ) }