import 'katex/dist/katex.min.css'; import { forwardRef, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import ReactMarkdown from 'react-markdown'; import { useSelector } from 'react-redux'; import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; import { vscDarkPlus, oneLight, } from 'react-syntax-highlighter/dist/cjs/styles/prism'; import rehypeKatex from 'rehype-katex'; import remarkGfm from 'remark-gfm'; import remarkMath from 'remark-math'; import { useDarkTheme } from '../hooks'; import DocsGPT3 from '../assets/cute_docsgpt3.svg'; import ChevronDown from '../assets/chevron-down.svg'; import Dislike from '../assets/dislike.svg?react'; import Document from '../assets/document.svg'; import Edit from '../assets/edit.svg'; import Like from '../assets/like.svg?react'; import Link from '../assets/link.svg'; import Sources from '../assets/sources.svg'; import UserIcon from '../assets/user.png'; import Accordion from '../components/Accordion'; import Avatar from '../components/Avatar'; import CopyButton from '../components/CopyButton'; import Sidebar from '../components/Sidebar'; import SpeakButton from '../components/TextToSpeechButton'; import { useOutsideAlerter } from '../hooks'; import { selectChunks, selectSelectedDocs, } from '../preferences/preferenceSlice'; import classes from './ConversationBubble.module.css'; import { FEEDBACK, MESSAGE_TYPE } from './conversationModels'; import { ToolCallsType } from './types'; const DisableSourceFE = import.meta.env.VITE_DISABLE_SOURCE_FE || false; const ConversationBubble = forwardRef< HTMLDivElement, { message: string; type: MESSAGE_TYPE; className?: string; feedback?: FEEDBACK; handleFeedback?: (feedback: FEEDBACK) => void; sources?: { title: string; text: string; source: string }[]; toolCalls?: ToolCallsType[]; retryBtn?: React.ReactElement; questionNumber?: number; handleUpdatedQuestionSubmission?: ( updatedquestion?: string, updated?: boolean, index?: number, ) => void; } >(function ConversationBubble( { message, type, className, feedback, handleFeedback, sources, toolCalls, retryBtn, questionNumber, handleUpdatedQuestionSubmission, }, ref, ) { const { t } = useTranslation(); const [isDarkTheme] = useDarkTheme(); // const bubbleRef = useRef(null); const chunks = useSelector(selectChunks); const selectedDocs = useSelector(selectSelectedDocs); const [isLikeHovered, setIsLikeHovered] = useState(false); const [isEditClicked, setIsEditClicked] = useState(false); const [isDislikeHovered, setIsDislikeHovered] = useState(false); const [isQuestionHovered, setIsQuestionHovered] = useState(false); const [editInputBox, setEditInputBox] = useState(''); const [isLikeClicked, setIsLikeClicked] = useState(false); const [isDislikeClicked, setIsDislikeClicked] = useState(false); const [activeTooltip, setActiveTooltip] = useState(null); const [isSidebarOpen, setIsSidebarOpen] = useState(false); const editableQueryRef = useRef(null); useOutsideAlerter(editableQueryRef, () => setIsEditClicked(false), [], true); const handleEditClick = () => { setIsEditClicked(false); handleUpdatedQuestionSubmission?.(editInputBox, true, questionNumber); }; let bubble; if (type === 'QUESTION') { bubble = (
setIsQuestionHovered(true)} onMouseLeave={() => setIsQuestionHovered(false)} >
} /> {!isEditClicked && ( <>
{message}
)} {isEditClicked && (