"use client"; import { ProgressUpdate } from "@/types"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Progress } from "@/components/ui/progress"; import { MessageSquare, Clock } from "lucide-react"; import { getAgentDisplayName } from "@/lib/agent-utils"; import { formatAbsoluteTimestamp } from "@/lib/utils"; interface ProgressTimelineProps { updates: ProgressUpdate[]; } function formatTime(timestamp: string): string { const date = new Date(timestamp); const now = new Date(); const diffMs = now.getTime() - date.getTime(); const diffMins = Math.floor(diffMs / (1000 * 60)); const diffHours = Math.floor(diffMins / 60); const diffDays = Math.floor(diffHours / 24); if (diffMins < 1) return "Just now"; if (diffMins < 60) return `${diffMins}m ago`; if (diffHours < 24) return `${diffHours}h ago`; if (diffDays < 7) return `${diffDays}d ago`; return date.toLocaleDateString("en-US", { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit", }); } export function ProgressTimeline({ updates }: ProgressTimelineProps) { // Sort by most recent first const sortedUpdates = [...updates].sort( (a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime(), ); // Get latest percentage if available const latestWithPercentage = sortedUpdates.find((u) => u.percentage !== null); const currentProgress = latestWithPercentage?.percentage ?? 0; return (
Progress Updates {updates.length} update{updates.length !== 1 ? "s" : ""}
{latestWithPercentage && (
Overall Progress {currentProgress}%
)}
{sortedUpdates.length === 0 ? (

No progress updates yet.

) : (
{/* Timeline line */}
    {sortedUpdates.map((update, idx) => (
  • {/* Timeline dot */}
    {getAgentDisplayName(update.agent_id)} {formatTime(update.timestamp)} ยท{" "} {formatAbsoluteTimestamp(update.timestamp)}

    {update.message}

    {update.percentage !== null && (
    {update.percentage}%
    )}
  • ))}
)} ); }