import { useEffect, useRef } from "preact/hooks"; import type { ThreadData } from "../../lib/types"; import { useSessionLog } from "../../lib/use-session-log"; import { fmtSessTs, typeClass, formatTypeLabel } from "../../lib/format"; interface Props { thread: ThreadData; open: boolean; onToggle: () => void; } export default function LogPanel({ thread, open, onToggle }: Props) { const isActive = thread.status === "processing"; const { entries, loading } = useSessionLog(thread.sessionFile, open, isActive); const containerRef = useRef(null); useEffect(() => { if (open && containerRef.current) { containerRef.current.scrollTop = containerRef.current.scrollHeight; } }, [entries, open]); const hasSession = !!thread.sessionFile; return ( <>
{open && hasSession && loading && (
Loading session log...
)} {open && hasSession && !loading && entries.length === 0 && (
No session log entries found.
)} {open && hasSession && entries.map((e, i) => { const content = e.type === "TOOL RESULT" && e.content.length > 120 ? e.content.slice(0, 120) + "..." : e.content; return (
{fmtSessTs(e.ts)} {formatTypeLabel(e.type)} {content}
); })} {open && !hasSession && ( thread.logLines.map((l, i) =>
{l}
) )}
); }