import { useLayoutEffect, useRef } from "react"; import { useSessionStore } from "../store/sessionStore"; import { isNearBottom } from "./activityScroll"; function transcriptLines(transcript: Array<{ text: string }>): string[] { return transcript.flatMap(({ text }) => text .replace(/[\s\S]*?<\/think>/g, "") .replace(/<\/?think>/g, "") .split("\n") .map((line) => line.trimEnd()) .filter((line) => line.trim() !== ""), ); } /** Compact central projection of the assistant stream while the model is working. */ export function CentralStatus({ working }: { working: boolean }) { const transcript = useSessionStore((state) => state.transcript); const rows = transcriptLines(transcript); const rowCount = rows.length; const tail = rows.at(-1); const scrollRef = useRef(null); const followRef = useRef(true); useLayoutEffect(() => { if (!working) { followRef.current = true; return; } const viewport = scrollRef.current; if (viewport && followRef.current) viewport.scrollTop = viewport.scrollHeight; }, [working, rowCount, tail]); if (!working || rows.length === 0) return null; return (
    { followRef.current = isNearBottom(event.currentTarget); }} > {rows.map((line, index) => { const isLast = index === rows.length - 1; return (
  1. › {line}
  2. ); })}
); }