import type { FC } from 'react' import { memo, useMemo, useState, useCallback } from 'react' import { useTranslation } from 'react-i18next' import type { ChatItem } from '../../types' import { useChatContext } from '../context' import RegenerateBtn from '@/app/components/base/regenerate-btn' import cn from '@/utils/classnames' import CopyBtn from '@/app/components/base/copy-btn' import { MessageFast } from '@/app/components/base/icons/src/vender/solid/communication' import AudioBtn from '@/app/components/base/audio-btn' // import AnnotationCtrlBtn from '@/app/components/base/features/new-feature-panel/annotation-reply/annotation-ctrl-btn' // TODO MARS // import EditReplyModal from '@/app/components/app/annotation/edit-annotation-modal' import { ThumbsDown, ThumbsUp, } from '@/app/components/base/icons/src/vender/line/alertsAndFeedback' // import Tooltip from '@/app/components/base/tooltip' import Log from '@/app/components/chat/log' import { message, Popconfirm, Tooltip } from 'antd'; interface OperationProps { item: ChatItem question: string index: number showPromptLog?: boolean maxSize: number contentWidth: number hasWorkflowProcess: boolean noChatInput?: boolean } const Operation: FC = ({ item, question, index, showPromptLog, maxSize, contentWidth, hasWorkflowProcess, noChatInput, }) => { const { t } = useTranslation() const { config, onAnnotationAdded, onAnnotationEdited, onAnnotationRemoved, onFeedback, onRegenerate, } = useChatContext() const [isShowReplyModal, setIsShowReplyModal] = useState(false) const { id, isOpeningStatement, content: messageContent, annotation, feedback, adminFeedback, agent_thoughts, } = item const hasAnnotation = !!annotation?.id const [localFeedback, setLocalFeedback] = useState(config?.supportAnnotation ? adminFeedback : feedback) const content = useMemo(() => { if (agent_thoughts?.length) return agent_thoughts.reduce((acc, cur) => acc + cur.thought, '') return messageContent }, [agent_thoughts, messageContent]) const handleFeedback = async (rating: 'like' | 'dislike' | null) => { if (!config?.supportFeedback || !onFeedback) return if (await onFeedback?.(id, { rating })) { setLocalFeedback({ rating }) } } const confirmCancelCallback = useCallback(async () => { try { await handleFeedback(null) } finally { message.success(localFeedback!.rating === 'like' ? `${t('appDebug.operation.cancelAgree')}成功` : `${t('appDebug.operation.cancelDisagree')}成功`) } }, [handleFeedback]) const operationWidth = useMemo(() => { let width = 0 if (!isOpeningStatement) width += 28 if (!isOpeningStatement && showPromptLog) width += 102 + 8 if (!isOpeningStatement && config?.text_to_speech?.enabled) width += 33 if (!isOpeningStatement && config?.supportAnnotation && config?.annotation_reply?.enabled) width += 56 + 8 if (config?.supportFeedback && !localFeedback?.rating && onFeedback && !isOpeningStatement) width += 60 + 8 if (config?.supportFeedback && localFeedback?.rating && onFeedback && !isOpeningStatement) width += 28 + 8 return width }, [isOpeningStatement, showPromptLog, config?.text_to_speech?.enabled, config?.supportAnnotation, config?.annotation_reply?.enabled, config?.supportFeedback, localFeedback?.rating, onFeedback]) const positionRight = useMemo(() => operationWidth < maxSize, [operationWidth, maxSize]) return ( <>
{!isOpeningStatement && ( )} {!isOpeningStatement && (showPromptLog || config?.text_to_speech?.enabled) && (
{showPromptLog && ( <>
)} {(config?.text_to_speech?.enabled) && ( <> )}
)} {/* {(!isOpeningStatement && config?.supportAnnotation && config.annotation_reply?.enabled) && ( onAnnotationAdded?.(id, authorName, question, content, index)} onEdit={() => setIsShowReplyModal(true)} onRemoved={() => onAnnotationRemoved?.(index)} /> )} */} { annotation?.id && (
) } { !isOpeningStatement && !noChatInput && onRegenerate?.(item)} /> } { config?.supportFeedback && !localFeedback?.rating && onFeedback && !isOpeningStatement && (
handleFeedback('like')} >
handleFeedback('dislike')} >
) } { config?.supportFeedback && localFeedback?.rating && onFeedback && !isOpeningStatement && ( ) }
{/* setIsShowReplyModal(false)} query={question} answer={content} onEdited={(editedQuery, editedAnswer) => onAnnotationEdited?.(editedQuery, editedAnswer, index)} onAdded={(annotationId, authorName, editedQuery, editedAnswer) => onAnnotationAdded?.(annotationId, authorName, editedQuery, editedAnswer, index)} appId={config?.appId || ''} messageId={id} annotationId={annotation?.id || ''} createdAt={annotation?.created_at} onRemove={() => onAnnotationRemoved?.(index)} /> */} ) } export default memo(Operation)