"use client"; import { useEffect, useRef, useState } from "react"; export function LiveLogViewer({ sessionId }: { sessionId: string }) { const [lines, setLines] = useState([]); const boxRef = useRef(null); useEffect(() => { let cancelled = false; async function poll() { try { const res = await fetch(`/api/debug/capture/${sessionId}`, { cache: "no-store" }); const data = (await res.json()) as { lines: string[] }; if (!cancelled) setLines(data.lines); } catch { // transient fetch failures are fine to just skip — next tick retries } } poll(); const timer = setInterval(poll, 4000); return () => { cancelled = true; clearInterval(timer); }; }, [sessionId]); useEffect(() => { if (boxRef.current) boxRef.current.scrollTop = boxRef.current.scrollHeight; }, [lines]); return (
      {lines.length > 0 ? lines.join("\n") : "Log bekleniyor…"}
    
); }