import React from 'react'; import { observer } from 'mobx-react'; import { AssistantMessage, CHUNK_TYPE, Citation } from './types'; import { TbInfoCircleFilled } from 'react-icons/tb'; import { Docs } from '../../../documents/Documents'; import { DocumentType } from '../../../documents/DocumentTypes'; 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 }) { // public static LayoutString(fieldKey: string) { // return FieldView.LayoutString(MessageComponentBox, fieldKey); // } // the presentation view that renders this slide // @computed // get chatBoxView() { // return this.DocumentView?.().containerViewPath?.().lastElement()?.ComponentView as ChatBox; // } const renderContent = (text: string) => { const citationRegex = /([^<]*)<\/citation>/g; const parts = []; let lastIndex = 0; let match; const citations: Citation[] = []; while ((match = citationRegex.exec(text)) !== null) { const [fullMatch, chunkId, type, content] = match; const citation: Citation = { chunk_id: chunkId, type: type as CHUNK_TYPE, text: content }; citations.push(citation); parts.push(text.slice(lastIndex, match.index)); parts.push( { e.preventDefault(); onCitationClick(citation); }} style={{ color: 'lightblue', verticalAlign: 'super', fontSize: 'smaller', }}> ); lastIndex = match.index + fullMatch.length; } parts.push(text.slice(lastIndex)); updateMessageCitations(index, citations); return <>{parts}; }; return (
{renderContent(message.text)}
{message.follow_up_questions && message.follow_up_questions.length > 0 && (

Follow-up Questions:

{message.follow_up_questions.map((question, idx) => ( ))}
)}
); }; // Docs.Prototypes.TemplateMap.set(DocumentType.MESSAGE, { // layout: { view: MessageComponentBox, dataField: 'data' }, // options: { // acl: '', // _height: 35, // _xMargin: 10, // _yMargin: 10, // _layout_nativeDimEditable: true, // _layout_reflowVertical: true, // _layout_reflowHorizontal: true, // defaultDoubleClick: 'ignore', // systemIcon: 'BsFileEarmarkTextFill', // layout_borderRounding: '10px', // }, // }); export default observer(MessageComponentBox);