diff --git a/web/app/components/workflow/panel/chat-record.tsx b/web/app/components/workflow/panel/chat-record.tsx deleted file mode 100644 index 8776572a16..0000000000 --- a/web/app/components/workflow/panel/chat-record.tsx +++ /dev/null @@ -1,20 +0,0 @@ -import { memo } from 'react' -import UserInput from './debug-and-preview/user-input' -import Chat from '@/app/components/base/chat/chat' - -const ChatRecord = () => { - return ( - } - allToolIcons={{}} - /> - ) -} - -export default memo(ChatRecord) diff --git a/web/app/components/workflow/panel/chat-record/index.tsx b/web/app/components/workflow/panel/chat-record/index.tsx new file mode 100644 index 0000000000..decdebdfd9 --- /dev/null +++ b/web/app/components/workflow/panel/chat-record/index.tsx @@ -0,0 +1,85 @@ +import { + memo, + useCallback, + useEffect, + useMemo, + useState, +} from 'react' +import { useStore } from '../../store' +import UserInput from './user-input' +import Chat from '@/app/components/base/chat/chat' +import { fetchConvesationMessages } from '@/service/debug' +import { useStore as useAppStore } from '@/app/components/app/store' +import Loading from '@/app/components/base/loading' + +const ChatRecord = () => { + const [fetched, setFetched] = useState(false) + const [chatList, setChatList] = useState([]) + const appDetail = useAppStore(s => s.appDetail) + const currentConversationID = useStore(s => s.currentConversationID) + + const chatMessageList = useMemo(() => { + const res: any = [] + if (chatList.length) { + chatList.forEach((item: any) => { + res.push({ + id: `question-${item.id}`, + content: item.query, + isAnswer: false, + message_files: item.message_files?.filter((file: any) => file.belongs_to === 'user') || [], + }) + res.push({ + id: item.id, + content: item.answer, + feedback: item.feedback, + isAnswer: true, + citation: item.retriever_resources, + message_files: item.message_files?.filter((file: any) => file.belongs_to === 'assistant') || [], + }) + }) + } + return res as any + }, [chatList]) + + const handleFetchConvesationMessages = useCallback(async () => { + if (appDetail && currentConversationID) { + try { + setFetched(false) + const res = await fetchConvesationMessages(appDetail.id, currentConversationID) + setFetched(true) + setChatList((res as any).data) + } + catch (e) { + + } + } + }, [appDetail, currentConversationID]) + useEffect(() => { + handleFetchConvesationMessages() + }, [currentConversationID, appDetail, handleFetchConvesationMessages]) + + if (!fetched) { + return ( +
+ +
+ ) + } + + return ( + } + noChatInput + allToolIcons={{}} + showPromptLog + /> + ) +} + +export default memo(ChatRecord) diff --git a/web/app/components/workflow/panel/chat-record/user-input.tsx b/web/app/components/workflow/panel/chat-record/user-input.tsx new file mode 100644 index 0000000000..2fbff73264 --- /dev/null +++ b/web/app/components/workflow/panel/chat-record/user-input.tsx @@ -0,0 +1,56 @@ +import { + memo, + useState, +} from 'react' +import { useTranslation } from 'react-i18next' +import { ChevronDown } from '@/app/components/base/icons/src/vender/line/arrows' + +const UserInput = () => { + const { t } = useTranslation() + const [expanded, setExpanded] = useState(true) + const variables: any = [] + + if (!variables.length) + return null + + return ( +
+
setExpanded(!expanded)} + > + + {t('workflow.panel.userInputField').toLocaleUpperCase()} +
+
+ { + expanded && ( +
+ { + variables.map((variable: any) => ( +
+
+ )) + } +
+ ) + } +
+
+ ) +} + +export default memo(UserInput) diff --git a/web/app/components/workflow/panel/run-history.tsx b/web/app/components/workflow/panel/run-history.tsx index ef1d46d434..e306d4a6e6 100644 --- a/web/app/components/workflow/panel/run-history.tsx +++ b/web/app/components/workflow/panel/run-history.tsx @@ -37,7 +37,7 @@ const RunHistory = () => { {t('workflow.common.runHistory')}
workflowStore.setState({ showRunHistory: false })} + onClick={() => workflowStore.setState({ showRunHistory: false, currentConversationID: '' })} >