/** * ThinkingBlock — displays model thinking/reasoning blocks in the chat. * Matches original claw-code thinkback feature. */ import { useState } from "react"; import { Brain, ChevronDown, ChevronRight, Clock } from "lucide-react"; interface ThinkingBlockProps { thinking: string; durationMs?: number; collapsed?: boolean; } export function ThinkingBlock({ thinking, durationMs, collapsed: initialCollapsed = true }: ThinkingBlockProps) { const [collapsed, setCollapsed] = useState(initialCollapsed); if (!thinking) return null; const lines = thinking.split("\n"); const preview = lines.slice(0, 3).join("\n"); const hasMore = lines.length > 3 || thinking.length > 300; return (
{!collapsed && (
{thinking}
)} {collapsed && hasMore && (
{preview.substring(0, 200)}{preview.length >= 200 ? "..." : ""}
)}
); } /** * Parse thinking blocks from a message content array. */ export function extractThinkingBlocks(content: unknown): { type: "thinking"; thinking: string; durationMs?: number }[] { if (!Array.isArray(content)) return []; return content.filter( (block: any) => block.type === "thinking" && block.thinking ) as { type: "thinking"; thinking: string; durationMs?: number }[]; }