"use client"; import { useEffect, useId, useState } from "react"; import dynamic from "next/dynamic"; import { Check } from "lucide-react"; import type { OrbState } from "thinking-orbs"; import { prefetchOnIdle } from "@/components/chat-chunk-prefetch"; import { activityElapsedLabel } from "@/lib/chat-message-view"; import { visibleThinkingSteps, type PublicThinkingStep, type ThinkingStepStatus, } from "@/lib/consultation-thinking-plan"; const importThinkingOrb = () => import("thinking-orbs"); const ThinkingOrb = dynamic(async () => (await importThinkingOrb()).ThinkingOrb, { loading: () => ( ), ssr: false, }); prefetchOnIdle(importThinkingOrb); function ActivityElapsed({ startedAt }: Readonly<{ startedAt: number }>) { const [now, setNow] = useState(() => Date.now()); useEffect(() => { const timer = window.setInterval(() => setNow(Date.now()), 1000); return () => window.clearInterval(timer); }, []); const label = activityElapsedLabel(startedAt, now); if (!label) return null; return ; } function StepMarker({ status, liveState, }: Readonly<{ status: ThinkingStepStatus | "live"; liveState?: OrbState; }>) { if (status === "live" || status === "active") { return ( ); } if (status === "done") { return ( ); } return ; } type ThinkingStepGroup = Readonly<{ id: string; intent?: string; steps: readonly PublicThinkingStep[]; live?: boolean; }>; function StepList({ steps, revealAll, live, liveLabel, liveState, startedAt, }: Readonly<{ steps: readonly PublicThinkingStep[]; revealAll: boolean; live: boolean; liveLabel?: string; liveState?: OrbState; startedAt?: number; }>) { const visible = revealAll ? { visible: steps, hiddenCount: 0 } : visibleThinkingSteps(steps); const hiddenDone = visible.hiddenCount > 0 && steps.slice(visible.visible.length).every((step) => step.status === "done"); return (