import { useEffect, useRef, useState } from 'react'; import { RightOutlined } from '@ant-design/icons'; import { thinkingTextFrame, type ModelThinking } from './analysisModelThinking'; export function AnalysisThinkingBlock({ entry, running }: { entry: ModelThinking; running: boolean }) { const active = running && entry.status === 'running'; const [open, setOpen] = useState(false); const priorId = useRef(entry.id); const [text, setText] = useState(entry.text); const shown = useRef(entry.text); useEffect(() => { if (priorId.current !== entry.id) { priorId.current = entry.id; setOpen(false); } else if (!active) setOpen(false); // A late adjacent call must not reopen a disclosure that already closed. }, [active, entry.id]); useEffect(() => { const target = entry.text; if (!active || !open || window.matchMedia('(prefers-reduced-motion: reduce)').matches || !target.startsWith(shown.current)) { shown.current = target; setText(target); return; } const from = shown.current, start = performance.now(); let frame = 0; const update = (now: number) => { const next = thinkingTextFrame(from, target, now - start); shown.current = next; setText(next); if (next !== target) frame = requestAnimationFrame(update); }; frame = requestAnimationFrame(update); return () => cancelAnimationFrame(frame); }, [entry.id, entry.text, active, open]); if (!entry.text) return null; return
setOpen(event.currentTarget.open)} data-process-id={entry.id}> 深度思考
{active && open ? text : entry.text}
; }