import React, { useState, useMemo } from "react"; interface ResultBlockProps { error?: string; result?: unknown; } const ResultBlock: React.FC = ({ error, result, }) => { const [isExpanded, setIsExpanded] = useState(false); const MAX_LENGTH = 10000; // Characters to show before truncating const formattedResult = useMemo(() => { if (result === undefined || result === null) { return "No result"; } if (typeof result !== "object") { return String(result); } try { const fullString = JSON.stringify(result, null, 2); // If the result is very large, provide truncation if (fullString.length > MAX_LENGTH && !isExpanded) { return fullString.substring(0, MAX_LENGTH); } return fullString; } catch (err) { // Handle circular references or other JSON.stringify errors return String(result); } }, [result, isExpanded]); const isTruncated = useMemo(() => { if (typeof result !== "object" || result === null) return false; try { return JSON.stringify(result, null, 2).length > MAX_LENGTH; } catch { return false; } }, [result]); return (
{error ?

Error: {error}

: null}
        {formattedResult}
        {isTruncated && !isExpanded && (
          ... (truncated)
        )}
      
{isTruncated && ( )}
); }; export default ResultBlock;