import { useRef, useEffect, useMemo } from "react"; import { useTranslation } from "react-i18next"; import { ChatMessage } from "@/components/ChatMessage"; import { Greetings } from "./Greetings"; import FileList from "@/components/Assistant/FileList"; import { useChatScroll } from "@/hooks/useChatScroll"; import { useChatStore } from "@/stores/chatStore"; import type { Chat, IChunkData } from "./types"; import SessionFile from "./SessionFile"; import { useConnectStore } from "@/stores/connectStore"; interface ChatContentProps { activeChat?: Chat; curChatEnd: boolean; query_intent?: IChunkData; fetch_source?: IChunkData; pick_source?: IChunkData; deep_read?: IChunkData; think?: IChunkData; response?: IChunkData; loadingStep?: Record; timedoutShow: boolean; errorShow: boolean; Question: string; handleSendMessage: (content: string, newChat?: Chat) => void; getFileUrl: (path: string) => string; } export const ChatContent = ({ activeChat, curChatEnd, query_intent, fetch_source, pick_source, deep_read, think, response, loadingStep, timedoutShow, errorShow, Question, handleSendMessage, getFileUrl, }: ChatContentProps) => { const sessionId = useConnectStore((state) => state.currentSessionId); const setCurrentSessionId = useConnectStore((state) => { return state.setCurrentSessionId; }); useEffect(() => { setCurrentSessionId(activeChat?._id); }, [activeChat]); const { t } = useTranslation(); const uploadFiles = useChatStore((state) => state.uploadFiles); const messagesEndRef = useRef(null); const { scrollToBottom } = useChatScroll(messagesEndRef); useEffect(() => { scrollToBottom(); }, [ activeChat?.messages, query_intent?.message_chunk, fetch_source?.message_chunk, pick_source?.message_chunk, deep_read?.message_chunk, think?.message_chunk, response?.message_chunk, curChatEnd, ]); useEffect(() => { return () => { scrollToBottom.cancel(); }; }, [scrollToBottom]); return (
{activeChat?.messages?.map((message, index) => ( ))} {(!curChatEnd || query_intent || fetch_source || pick_source || deep_read || think || response) && activeChat?._id ? ( ) : null} {timedoutShow ? ( ) : null} {errorShow ? ( ) : null}
{sessionId && uploadFiles.length > 0 && (
)} {sessionId && }
); };