// Accordion.tsx import { useState } from 'react'; type ProcessedData = { field: string; isMarkdown: boolean; htmlContent: string | object; }; type Log = { header: string; text: string; processedData?: ProcessedData[]; }; interface AccordionProps { logs: Log[]; } const plainTextFields = ['task', 'sections', 'headers', 'sources', 'research_data']; const Accordion: React.FC = ({ logs }) => { const getLogHeaderText = (log: Log): string => { const regex = /📃 Source: (https?:\/\/[^\s]+)/; const match = log.text.match(regex); let sourceUrl = ''; if (match) { sourceUrl = match[1]; } return log.header === 'differences' ? 'The following fields on the Langgraph were updated: ' + Object.keys(JSON.parse(log.text).data).join(', ') : `📄 Retrieved relevant content from the source: ${sourceUrl}`; }; const renderLogContent = (log: Log) => { if (log.header === 'differences' && log.processedData) { return log.processedData.map((data, index) => (

{data.field}:

{data.isMarkdown ? (
) : (

{typeof data.htmlContent === 'object' ? JSON.stringify(data.htmlContent) : data.htmlContent}

)}
)); } else { return

{log.text}

; } }; const [openIndex, setOpenIndex] = useState(null); const handleToggle = (index: number) => { setOpenIndex(openIndex === index ? null : index); }; return (
{logs.map((log, index) => (

{renderLogContent(log)}
))}
); }; export default Accordion;