"use client"; import Link from "next/link"; import { useEffect, useState } from "react"; import { apiUrl } from "@/lib/api"; interface RecentBot { bot_id: string; name: string; running: boolean; last_message: string; updated_at: string; } function relativeTime(iso: string): string { const diff = Date.now() - new Date(iso).getTime(); const mins = Math.floor(diff / 60000); if (mins < 1) return "just now"; if (mins < 60) return `${mins}m`; const hrs = Math.floor(mins / 60); if (hrs < 24) return `${hrs}h`; const days = Math.floor(hrs / 24); return `${days}d`; } export function TutorBotRecent({ collapsed = false }: { collapsed?: boolean }) { const [bots, setBots] = useState([]); useEffect(() => { let cancelled = false; (async () => { try { const res = await fetch(apiUrl("/api/v1/tutorbot/recent?limit=3")); if (!res.ok) return; const data = await res.json(); if (!cancelled) setBots(data); } catch { /* ignore */ } })(); return () => { cancelled = true; }; }, []); if (bots.length === 0) return null; if (collapsed) return null; return (
{bots.map((bot) => (
{bot.running ? ( ) : ( )}
{bot.name} {relativeTime(bot.updated_at)} ))}
); }