// Adapted from Beautiful UI's MIT-licensed ThinkingState (Steps). // Uses real server progress rather than the reference's timed demo sequence. import { useEffect, useId, useState } from "react"; import { Check, ChevronDown, CircleAlert, LoaderCircle, Pause, Sparkles } from "lucide-react"; import { useMobileLayout } from '../useMobileLayout'; export function ThinkingState({ steps, working, started, failed, stopped, outcome, }: { steps: string[]; working: boolean; started: number; failed?: boolean; stopped?: boolean; outcome?: string; }) { const mobile = useMobileLayout(); const traceId = useId(); const [manualExpanded, setExpanded] = useState(null); const [elapsed, setElapsed] = useState(0); useEffect(() => { if (!working) return; const update = () => setElapsed((Date.now() - started) / 1000); update(); const timer = window.setInterval(update, 1000); return () => window.clearInterval(timer); }, [working, started]); const expanded = manualExpanded ?? (working && !mobile); const StatusIcon = working ? LoaderCircle : stopped ? Pause : failed ? CircleAlert : Sparkles; return (
    {!steps.length &&
  1. {working ? "正在连接分析服务…" : "暂无执行步骤"}
  2. } {steps.map((step, index) => (
  3. {working && index === steps.length - 1 ? (
  4. ))}
{working && ( {steps.at(-1) || "正在连接分析服务"} )}
); }