import React, { useState } from 'react'; import { observer } from 'mobx-react'; import { AssistantMessage, Citation, MessageContent, PROCESSING_TYPE, ProcessingInfo, TEXT_TYPE } from './types'; import ReactMarkdown from 'react-markdown'; interface MessageComponentProps { message: AssistantMessage; index: number; onFollowUpClick: (question: string) => void; onCitationClick: (citation: Citation) => void; updateMessageCitations: (index: number, citations: Citation[]) => void; } const MessageComponentBox: React.FC = function ({ message, index, onFollowUpClick, onCitationClick, updateMessageCitations }) { const [dropdownOpen, setDropdownOpen] = useState(false); const renderContent = (item: MessageContent) => { const i = item.index; console.log('item', item, 'index', i); if (item.type === TEXT_TYPE.GROUNDED) { const citation_ids = item.citation_ids || []; return ( {item.text} {citation_ids.map((id, idx) => { const citation = message.citations?.find(c => c.citation_id === id); if (!citation) return null; return ( ); })} ); } else if (item.type === TEXT_TYPE.NORMAL) { return ( {item.text} ); } else if ('query' in item) { return ( {JSON.stringify(item.query)} ); } else { return ( {JSON.stringify(item)} ); } }; const hasProcessingInfo = message.processing_info && message.processing_info.length > 0; const renderProcessingInfo = (info: ProcessingInfo) => { if (info.type === PROCESSING_TYPE.THOUGHT) { return (
Thought: {info.content}
); } else if (info.type === PROCESSING_TYPE.ACTION) { return (
Action: {info.content}
); } else { return null; } }; return (
{hasProcessingInfo && (
{dropdownOpen &&
{message.processing_info.map(renderProcessingInfo)}
}
)}
{message.content && message.content.map(messageFragment => {renderContent(messageFragment)})}
{message.follow_up_questions && message.follow_up_questions.length > 0 && (

Follow-up Questions:

{message.follow_up_questions.map((question, idx) => ( ))}
)}
); }; export default observer(MessageComponentBox);