diff --git a/web/app/components/base/chat/chat/answer/operation.tsx b/web/app/components/base/chat/chat/answer/operation.tsx index 0c8d23de33..0fbb7ceef1 100644 --- a/web/app/components/base/chat/chat/answer/operation.tsx +++ b/web/app/components/base/chat/chat/answer/operation.tsx @@ -7,7 +7,6 @@ import { import { useTranslation } from 'react-i18next' import { RiClipboardLine, - RiEditLine, RiResetLeftLine, RiThumbDownLine, RiThumbUpLine, @@ -16,6 +15,7 @@ import type { ChatItem } from '../../types' import { useChatContext } from '../context' import copy from 'copy-to-clipboard' import Toast from '@/app/components/base/toast' +import AnnotationCtrlButton from '@/app/components/base/features/new-feature-panel/annotation-reply/annotation-ctrl-button' import EditReplyModal from '@/app/components/app/annotation/edit-annotation-modal' import Log from '@/app/components/base/chat/chat/log' import ActionButton, { ActionButtonState } from '@/app/components/base/action-button' @@ -134,9 +134,15 @@ const Operation: FC = ({ )} {(config?.supportAnnotation && config.annotation_reply?.enabled) && ( - setIsShowReplyModal(true)}> - - + onAnnotationAdded?.(id, authorName, question, content, index)} + onEdit={() => setIsShowReplyModal(true)} + /> )} )} diff --git a/web/app/components/base/features/new-feature-panel/annotation-reply/annotation-ctrl-button.tsx b/web/app/components/base/features/new-feature-panel/annotation-reply/annotation-ctrl-button.tsx new file mode 100644 index 0000000000..3050249bb6 --- /dev/null +++ b/web/app/components/base/features/new-feature-panel/annotation-reply/annotation-ctrl-button.tsx @@ -0,0 +1,79 @@ +'use client' +import type { FC } from 'react' +import React from 'react' +import { useTranslation } from 'react-i18next' +import { + RiEditLine, + RiFileEditLine, +} from '@remixicon/react' +import ActionButton from '@/app/components/base/action-button' +import Tooltip from '@/app/components/base/tooltip' +import { addAnnotation } from '@/service/annotation' +import Toast from '@/app/components/base/toast' +import { useProviderContext } from '@/context/provider-context' +import { useModalContext } from '@/context/modal-context' + +type Props = { + appId: string + messageId?: string + cached: boolean + query: string + answer: string + onAdded: (annotationId: string, authorName: string) => void + onEdit: () => void +} + +const AnnotationCtrlButton: FC = ({ + cached, + query, + answer, + appId, + messageId, + onAdded, + onEdit, +}) => { + const { t } = useTranslation() + const { plan, enableBilling } = useProviderContext() + const isAnnotationFull = (enableBilling && plan.usage.annotatedResponse >= plan.total.annotatedResponse) + const { setShowAnnotationFullModal } = useModalContext() + const handleAdd = async () => { + if (isAnnotationFull) { + setShowAnnotationFullModal() + return + } + const res: any = await addAnnotation(appId, { + message_id: messageId, + question: query, + answer, + }) + Toast.notify({ + message: t('common.api.actionSuccess') as string, + type: 'success', + }) + onAdded(res.id, res.account?.name) + } + + return ( + <> + {cached && ( + + + + + + )} + {!cached && answer && ( + + + + + + )} + + ) +} +export default React.memo(AnnotationCtrlButton)