/* * @Author: ZhaoYing * @Date: 2026-02-03 17:09:03 * @Last Modified by: ZhaoYing * @Last Modified time: 2026-03-19 16:00:39 */ /** * Memory Conversation Page * Interactive conversation interface with memory analysis * Supports deep thinking, normal reply, and quick reply modes */ import { type FC, type ReactNode, useState, useEffect } from 'react' import { useTranslation } from 'react-i18next' import { Col, Row, App, Skeleton, Select, Segmented, Tooltip, Flex } from 'antd' import dayjs from 'dayjs' import type { AnyObject } from 'antd/es/_util/type'; import ConversationEmptyIcon from '@/assets/images/conversation/conversationEmpty.svg' import AnalysisEmptyIcon from '@/assets/images/conversation/analysisEmpty.png' import { readService, getUserMemoryList } from '@/api/memory' import Empty from '@/components/Empty' import Markdown from '@/components/Markdown' import type { Data } from '@/views/UserMemory/types' import Chat from '@/components/Chat' import type { ChatItem } from '@/components/Chat/types' import RbCard from '@/components/RbCard/Card'; import styles from './index.module.css' import ResultCard from '@/components/RbCard/ResultCard' /** Search mode configuration */ const searchSwitchList = [ { icon:
, value: '0', key: 'deepThinking' }, { icon:
, value: '1', key: 'normalReply' }, { icon:
, value: '2', key: 'quickReply' }, ] /** * Test parameters for conversation API */ export interface TestParams { /** End user identifier */ end_user_id: string; /** User message content */ message: string; /** Search mode switch (0: deep thinking, 1: normal, 2: quick) */ search_switch: string; /** Conversation history */ history: { role: string; content: string }[]; /** Enable web search */ web_search?: boolean; /** Enable memory function */ memory?: boolean; /** Conversation ID */ conversation_id?: string; } /** * Data item in analysis logs */ interface DataItem { id: string; question: string; type: string; reason: string; } /** * Log item for conversation analysis */ export interface LogItem { type: string; title: string; data?: DataItem[] | AnyObject; raw_results?: string | AnyObject; summary?: string; query?: string; reason?: string; result?: string; original_query: string; index?: number; } /** * Content wrapper component for analysis items */ const ContentWrapper: FC<{ children: ReactNode }> = ({ children }) => (
{children}
) const MemoryConversation: FC = () => { const { t } = useTranslation() const { message } = App.useApp(); const [userId, setUserId] = useState() const [loading, setLoading] = useState(false) const [chatData, setChatData] = useState([]) const [logs, setLogs] = useState([]) const [userList, setUserList] = useState([]) const [search_switch, setSearchSwitch] = useState('0') const [msg, setMsg] = useState('') const [expandedLogs, setExpandedLogs] = useState>({}) /** Load user list on mount */ useEffect(() => { getUserMemoryList().then(res => { setUserList((res as Data[] || []).map(item => ({ ...item, name: item.end_user?.other_name && item.end_user?.other_name !== '' ? item.end_user?.other_name : item.end_user?.id }))) }) }, []) /** Handle message send */ const handleSend = () => { if(!userId) { message.warning(t('common.inputPlaceholder', { title: t('memoryConversation.userID') })) return } setChatData(prev => [...prev, { content: msg, created_at: new Date().getTime(), role: 'user' }]) setLoading(true) setExpandedLogs({}) readService({ message: msg, end_user_id: userId, search_switch: search_switch, history: [], }) .then(res => { const response = res as { answer: string; intermediate_outputs: LogItem[] } setChatData(prev => [...prev, { content: response.answer || '-', created_at: new Date().getTime(), role: 'assistant' }]) setLogs(response.intermediate_outputs) setExpandedLogs(Object.fromEntries(response.intermediate_outputs.map((_, i) => [i, true]))) }) .finally(() => { setLoading(false) }) } /** Handle search mode change */ const handleChange = (value: string) => { setSearchSwitch(value) } return ( <>