'use client'; import { useEffect, useState } from 'react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { RefreshCw, Activity, Cpu, Clock, Zap } from 'lucide-react'; interface SystemStatus { gateway: { running: boolean; pid?: number; port?: number; uptime?: number; mode?: string; }; activeModel: string | null; instanceCount: number; uptime: number; } export function DashboardOverview() { const [status, setStatus] = useState(null); const [loading, setLoading] = useState(true); const [refreshing, setRefreshing] = useState(false); const fetchStatus = async () => { try { const response = await fetch('/api/status'); const data = await response.json(); setStatus(data); } catch (error) { console.error('Failed to fetch status:', error); } finally { setLoading(false); setRefreshing(false); } }; useEffect(() => { fetchStatus(); const interval = setInterval(fetchStatus, 5000); // Refresh every 5s return () => clearInterval(interval); }, []); const handleRefresh = () => { setRefreshing(true); fetchStatus(); }; if (loading) { return (
); } const formatUptime = (seconds: number) => { const h = Math.floor(seconds / 3600); const m = Math.floor((seconds % 3600) / 60); return `${h}h ${m}m`; }; return (
{/* Header Actions */}
{/* Status Cards */}
Gateway Status
{status?.gateway.running ? 'Online' : 'Offline'}
{status?.gateway.port && (

Port: {status.gateway.port}

)}
Active Model

{status?.activeModel || 'None'}

{status?.activeModel ? 'Configured' : 'Not set'}
Instances {status?.instanceCount || 0}

Active instances

System Uptime {status?.uptime ? formatUptime(status.uptime) : '--'}

Since restart

{/* Gateway Details */} Gateway Details

Status

{status?.gateway.running ? 'Running' : 'Stopped'}

Mode

{status?.gateway.mode || 'N/A'}

PID

{status?.gateway.pid || 'N/A'}

Port

{status?.gateway.port || 'N/A'}

{status?.gateway.uptime && (

Gateway Uptime

{formatUptime(status.gateway.uptime)}

)}
{/* Quick Actions Preview */} Quick Access
); }