'use client'; import React, { useState } from 'react'; import { CheckCircle, XCircle, ChevronDown, ChevronUp, FileCode } from 'lucide-react'; import type { ToolResult } from '@/types/control-center'; import { cn } from '@/lib/utils'; interface ToolResultCardProps { toolResult: ToolResult; } // Threshold for auto-collapsing large results const LARGE_RESULT_THRESHOLD = 500; export const ToolResultCard: React.FC = ({ toolResult }) => { const isError = !toolResult.success; const resultData = isError ? toolResult.error : toolResult.result; // Determine if result is large and should be collapsed by default const resultString = typeof resultData === 'string' ? resultData : JSON.stringify(resultData, null, 2); const isLargeResult = resultString.length > LARGE_RESULT_THRESHOLD; const [isExpanded, setIsExpanded] = useState(!isLargeResult); const formatResult = (data: any): string => { if (data === null || data === undefined) { return 'No result data'; } if (typeof data === 'string') { return data; } return JSON.stringify(data, null, 2); }; return (
{/* Header */}
setIsExpanded(!isExpanded)} > {/* Status Icon */}
{isError ? : }
{/* Result Info */}
Tool Result
{isError ? 'Error' : 'Success'} {!isExpanded && ( {resultString.substring(0, 50)} {resultString.length > 50 ? '...' : ''} )}
{/* Expand/Collapse Toggle */}
{/* Collapsible Result Content */} {isExpanded && (

{isError ? 'Error Details' : 'Result Data'}

              {formatResult(resultData)}
            
)}
); }; export default ToolResultCard;