import { useState } from 'react' import { useQuery, useQueryClient } from '@tanstack/react-query' import { listTasks } from '../services/api' import { AlertCircle, RefreshCw, Filter, CheckCircle, Circle, Clock, XCircle, Loader, ListTodo } from 'lucide-react' import type { Task } from '../types' const STATUS_FILTERS = ['all', 'pending', 'running', 'completed', 'failed'] as const type StatusFilter = (typeof STATUS_FILTERS)[number] const STATUS_ICON: Record = { pending: Clock, running: Loader, completed: CheckCircle, failed: XCircle, } const STATUS_COLOR: Record = { pending: 'text-yellow-500', running: 'text-blue-400', completed: 'text-green-500', failed: 'text-red-500', } export default function LogsPage() { const queryClient = useQueryClient() const [statusFilter, setStatusFilter] = useState('all') const { data, isLoading, error } = useQuery({ queryKey: ['tasks'], queryFn: listTasks, }) const tasks = (data?.data ?? []) as Task[] const filtered = statusFilter === 'all' ? tasks : tasks.filter((t) => t.status === statusFilter) // Sort newest first const sorted = [...filtered].sort( (a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime() ) if (isLoading) return if (error) { return (

Failed to load activity logs

) } return (

Activity Logs

Task activity across all agents

{/* Filter tabs */}
{STATUS_FILTERS.map((f) => ( ))}
{/* Activity feed */} {sorted.length === 0 ? (

No tasks found

{statusFilter === 'all' ? 'Tasks will appear here as agents execute work.' : `No ${statusFilter} tasks.`}

) : (
{sorted.map((task) => { const Icon = STATUS_ICON[task.status] ?? Circle const fmtTime = formatTime(task.createdAt) return (

{task.title}

Agent {task.agentId} {task.sessionKey && ` ยท ${task.sessionKey}`}

{task.status} {task.progress != null && task.progress > 0 && task.progress < 100 && ( {task.progress}% )}
{fmtTime}
) })}
)}
) } function formatTime(iso: string): string { try { const d = new Date(iso) const now = new Date() const diffMs = now.getTime() - d.getTime() const diffMin = Math.floor(diffMs / 60_000) if (diffMin < 1) return 'just now' if (diffMin < 60) return `${diffMin}m ago` const diffHr = Math.floor(diffMin / 60) if (diffHr < 24) return `${diffHr}h ago` return d.toLocaleDateString() } catch { return iso } } function LogsSkeleton() { return (
{[...Array(5)].map((_, i) => (
))}
{[...Array(6)].map((_, i) => (
))}
) }