'use client'; import * as React from 'react'; import { Brain, ChevronDown, Maximize2, Minimize2 } from 'lucide-react'; import { cn } from '@/lib/utils'; import Markdown from 'markdown-to-jsx'; import logger from '@/lib/logger'; interface ReasoningPanelProps { thinking: string; className?: string; isExpanded?: boolean; } const ReasoningPanel = ({ thinking, className, isExpanded: propExpanded }: ReasoningPanelProps): React.ReactElement => { const [isExpanded, setIsExpanded] = React.useState(true); const [detailsRefs, setDetailsRefs] = React.useState([]); logger.info('ReasoningPanel rendering with:', { thinking: thinking, isExpanded: propExpanded, detailsRefsCount: detailsRefs.length }); React.useEffect(() => { if (propExpanded !== undefined) { logger.info('Updating expansion state:', propExpanded); setIsExpanded(propExpanded); } }, [propExpanded]); const addDetailsRef = React.useCallback((element: HTMLDetailsElement | null) => { if (element) { setDetailsRefs(refs => { if (!refs.includes(element)) { logger.info('Adding new details ref'); return [...refs, element]; } return refs; }); } }, []); const expandAll = () => { logger.info('Expanding all details'); detailsRefs.forEach(ref => ref.open = true); }; const collapseAll = () => { logger.info('Collapsing all details'); detailsRefs.forEach(ref => ref.open = false); }; return (
{isExpanded && (
{thinking.split('\n\n').map((paragraph, index) => { if (!paragraph.trim()) return null; // Extract content without the bullet prefix const content = paragraph.replace(/^[•\-\d.]\s*/, ''); logger.info(`Processing paragraph ${index}:`, content); return (

{content}

{/* Content is shown in the summary when expanded - no need to render it again */}
); })}
)}
); }; export default ReasoningPanel;