diff --git a/backend/models.py b/backend/models.py new file mode 100644 index 0000000..2c3d8fb --- /dev/null +++ b/backend/models.py @@ -0,0 +1,13 @@ +from pydantic import BaseModel +from typing import Literal, Optional + +class Agent(BaseModel): + id: str + name: str + status: Literal["online", "offline", "busy"] = "online" + runtime: str = "?" + model: str = "?" + healthy: bool = True + +class AgentUpdate(BaseModel): + status: Literal["online", "offline", "busy"] diff --git a/frontend/src/components/agents/AgentGrid.tsx b/frontend/src/components/agents/AgentGrid.tsx index 537096d..b3af39f 100644 --- a/frontend/src/components/agents/AgentGrid.tsx +++ b/frontend/src/components/agents/AgentGrid.tsx @@ -2,44 +2,42 @@ import { motion } from 'framer-motion' import { Cpu, Server } from 'lucide-react' import { Badge } from '@/components/ui/badge' import { useAppStore } from '@/store/useAppStore' +import { useQuery } from '@tanstack/react-query' export function AgentGrid() { const { agents, setAgents } = useAppStore() - const { useQuery } = require('@tanstack/react-query') - const { data, isLoading } = (useQuery as any)({ + const { isLoading } = useQuery({ queryKey: ['agents'], queryFn: async () => { const r = await fetch('/api/v1/agents/health') const raw = await r.json() - return Object.entries(raw).map(([id, info]: [string, any]) => ({ + const mapped = Object.entries(raw).map(([id, info]: [string, any]) => ({ id, name: id.replace('worker-', ''), - status: info.healthy ? ('online' as const) : ('offline' as const), + status: info.healthy ? ('online' as const) : ('busy' as const), runtime: info.model?.split('/')[0] || '?', model: info.model?.split('/').pop() || '?', healthy: info.healthy, cpu: Math.floor(Math.random() * 60 + 10), activeRuns: Math.floor(Math.random() * 5), })) + setAgents(mapped) + return mapped }, refetchInterval: 15000, - onSuccess: (d: any) => setAgents(d), }) const online = agents.filter(a => a.healthy).length - const busy = agents.filter(a => a.status === 'busy').length return (

Live Agents

-
- {online} online{busy > 0 ? ` ยท ${busy} busy` : ''} -
+
{online} online
- {isLoading ? ( + {isLoading && !agents.length ? (
Loading agents...
) : (