import React, { useMemo, useState } from 'react'; import { Box, useTheme, Flex, Image } from '@chakra-ui/react'; import type { ChatHistoryItemResType } from '@fastgpt/global/core/chat/type.d'; import { useTranslation } from 'next-i18next'; import { moduleTemplatesFlat } from '@fastgpt/global/core/workflow/template/constants'; import Tabs from '../Tabs'; import MyModal from '@fastgpt/web/components/common/MyModal'; import MyTooltip from '../MyTooltip'; import { QuestionOutlineIcon } from '@chakra-ui/icons'; import Markdown from '../Markdown'; import { QuoteList } from './QuoteModal'; import { DatasetSearchModeMap } from '@fastgpt/global/core/dataset/constants'; import { formatNumber } from '@fastgpt/global/common/math/tools'; function Row({ label, value, rawDom }: { label: string; value?: string | number | boolean; rawDom?: React.ReactNode; }) { const { t } = useTranslation(); const theme = useTheme(); const val = value || rawDom; const strValue = `${value}`; const isCodeBlock = strValue.startsWith('~~~json'); return val !== undefined && val !== '' && val !== 'undefined' ? ( {t(label)}: {value && } {rawDom} ) : null; } const WholeResponseModal = ({ response, showDetail, onClose }: { response: ChatHistoryItemResType[]; showDetail: boolean; onClose: () => void; }) => { const { t } = useTranslation(); return ( {t('core.chat.response.Complete Response')} } > ); }; export default WholeResponseModal; export const ResponseBox = React.memo(function ResponseBox({ response, showDetail, hideTabs = false }: { response: ChatHistoryItemResType[]; showDetail: boolean; hideTabs?: boolean; }) { const theme = useTheme(); const { t } = useTranslation(); const list = useMemo( () => response.map((item, i) => ({ label: ( item.moduleType === template.flowNodeType) ?.avatar } alt={''} w={['14px', '16px']} /> {t(item.moduleName)} ), id: `${i}` })), [response, t] ); const [currentTab, setCurrentTab] = useState(`0`); const activeModule = useMemo(() => response[Number(currentTab)], [currentTab, response]); return ( <> {!hideTabs && ( )} <> {activeModule?.totalPoints !== undefined && ( )} {/* ai chat */} <> {activeModule.historyPreview?.map((item, i) => ( {item.obj} {item.value} ))} ) : ( '' ) } /> {/* dataset search */} <> {activeModule?.searchMode && ( )} {activeModule.quoteList && activeModule.quoteList.length > 0 && ( } /> )} {/* classify question */} <> { if (!activeModule?.cqList) return ''; return activeModule.cqList.map((item) => `* ${item.value}`).join('\n'); })()} /> {/* if-else */} <> {/* extract */} <> {activeModule?.extractResult && ( )} {/* http */} <> {activeModule?.headers && ( )} {activeModule?.params && ( )} {activeModule?.body && ( )} {activeModule?.httpResult && ( )} {/* plugin */} <> {activeModule?.pluginOutput && ( )} {activeModule?.pluginDetail && activeModule?.pluginDetail.length > 0 && ( } /> )} {/* text output */} {/* tool call */} {activeModule?.toolDetail && activeModule?.toolDetail.length > 0 && ( } /> )} ); });