import { useQuery, useQueryClient } from '@tanstack/react-query'
import { listSessions } from '../services/api'
import { AlertCircle, Monitor, RefreshCw, Cpu, MessageSquare, Clock, Hash } from 'lucide-react'
export default function SessionsPage() {
const queryClient = useQueryClient()
const { data, isLoading, error } = useQuery({
queryKey: ['sessions'],
queryFn: listSessions,
})
const sessions = data?.data ?? []
if (isLoading) return
if (error) {
return (
Failed to load sessions
)
}
return (
{sessions.length === 0 ? (
No active sessions
Sessions will appear when agents connect.
) : (
<>
{/* Desktop: Table view */}
| Agent |
Session Key |
Channel |
Model |
Context Tokens |
Started |
{sessions.map((s) => (
| {s.agentId} |
{s.sessionKey}
|
{s.channel} |
{s.model} |
{s.contextTokens.toLocaleString()}
|
{formatDateTime(s.startedAt)}
|
))}
{/* Mobile: Card view */}
{sessions.map((s) => (
{s.agentId}
{s.sessionKey}
{s.channel}
{s.model}
{s.contextTokens.toLocaleString()}
{formatDateTime(s.startedAt)}
))}
>
)}
)
}
function Row({ icon: Icon, label, children }: { icon: React.ElementType; label: string; children: React.ReactNode }) {
return (
{label}
{children}
)
}
function formatDateTime(iso: string): string {
try {
const d = new Date(iso)
return d.toLocaleString(undefined, {
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: '2-digit',
})
} catch {
return iso
}
}
function SessionsSkeleton() {
return (
{/* Desktop skeleton */}
{[...Array(6)].map((_, i) => (
))}
{[...Array(5)].map((_, i) => (
{[...Array(6)].map((_, j) => (
))}
))}
{/* Mobile skeleton */}
{[...Array(4)].map((_, i) => (
{[...Array(5)].map((_, j) => (
))}
))}
)
}