/* eslint-disable react/require-default-props */ import React from 'react'; import { observer } from 'mobx-react'; import { MathJax, MathJaxContext } from 'better-react-mathjax'; import ReactMarkdown from 'react-markdown'; import { AssistantMessage } from './types'; import { TbInfoCircleFilled } from 'react-icons/tb'; interface MessageComponentProps { message: AssistantMessage; toggleToolLogs: (index: number) => void; expandedLogIndex: number | null; index: number; showModal: () => void; goToLinkedDoc: (url: string) => void; setCurrentFile: (file: { url: string }) => void; onFollowUpClick: (question: string) => void; // New prop isCurrent?: boolean; } const MessageComponent: React.FC = function ({ message, toggleToolLogs, expandedLogIndex, goToLinkedDoc, index, showModal, setCurrentFile, onFollowUpClick, // New prop isCurrent = false, }) { const LinkRenderer = ({ href, children }: { href: string; children: React.ReactNode }) => { const regex = /([a-zA-Z0-9_.!-]+)~~~(citation|file_path)/; const matches = href.match(regex); const url = matches ? matches[1] : href; const linkType = matches ? matches[2] : null; if (linkType === 'citation') { children = ; } const style = { color: 'lightblue', verticalAlign: linkType === 'citation' ? 'super' : 'baseline', fontSize: linkType === 'citation' ? 'smaller' : 'inherit', }; return ( { e.preventDefault(); if (linkType === 'citation') { goToLinkedDoc(url); } else if (linkType === 'file_path') { showModal(); setCurrentFile({ url }); } }} style={style}> {children} ); }; const parseMessage = (text: string) => { const answerMatch = text.match(/([\s\S]*?)<\/answer>/); const followUpMatch = text.match(/([\s\S]*?)<\/follow_up_question>/); const answer = answerMatch ? answerMatch[1] : text; const followUpQuestions = followUpMatch ? followUpMatch[1] .split('\n') .filter(q => q.trim()) .map(q => q.replace(/^\d+\.\s*/, '').trim()) : []; return { answer, followUpQuestions }; }; const { answer, followUpQuestions } = parseMessage(message.text); console.log('Parsed answer:', answer); console.log('Parsed follow-up questions:', followUpQuestions); return (
{answer} {message.image && } {followUpQuestions.length > 0 && (

Follow-up Questions:

{followUpQuestions.map((question, idx) => ( ))}
)}
{message.tool_logs && ( )} {expandedLogIndex === index && (
{message.tool_logs}
)}
); }; export default observer(MessageComponent);