fix: AgentChatPage dependencies and Spin component warning
This commit is contained in:
@@ -15,22 +15,18 @@ const AgentChatPage = () => {
|
||||
const { currentProject } = useProjectStore()
|
||||
const { knowledgeBases, fetchKnowledgeBases } = useKnowledgeBaseStore()
|
||||
|
||||
// 智能体相关状态
|
||||
const [agent, setAgent] = useState<AgentConfig | null>(null)
|
||||
// 智能体相关状� const [agent, setAgent] = useState<AgentConfig | null>(null)
|
||||
const [agentLoading, setAgentLoading] = useState(true)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
// 对话相关状态
|
||||
const [conversation, setConversation] = useState<Conversation | null>(null)
|
||||
// 对è¯<EFBFBD>相关状æ€? const [conversation, setConversation] = useState<Conversation | null>(null)
|
||||
const [messages, setMessages] = useState<Message[]>([])
|
||||
const [selectedModel, setSelectedModel] = useState<ModelType>('deepseek-v3')
|
||||
|
||||
// 消息发送状态
|
||||
const [sending, setSending] = useState(false)
|
||||
// 消æ<EFBFBD>¯å<EFBFBD>‘é€<EFBFBD>状æ€? const [sending, setSending] = useState(false)
|
||||
const [streamingContent, setStreamingContent] = useState('')
|
||||
|
||||
// 加载智能体配置
|
||||
useEffect(() => {
|
||||
// åŠ è½½æ™ºèƒ½ä½“é…<EFBFBD>ç½? useEffect(() => {
|
||||
const fetchAgent = async () => {
|
||||
if (!agentId) return
|
||||
|
||||
@@ -45,8 +41,8 @@ const AgentChatPage = () => {
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to load agent:', err)
|
||||
setError('加载智能体配置失败')
|
||||
message.error('加载智能体配置失败')
|
||||
setError('åŠ è½½æ™ºèƒ½ä½“é…<EFBFBD>置失è´?)
|
||||
message.error('åŠ è½½æ™ºèƒ½ä½“é…<EFBFBD>置失è´?)
|
||||
} finally {
|
||||
setAgentLoading(false)
|
||||
}
|
||||
@@ -55,22 +51,19 @@ const AgentChatPage = () => {
|
||||
fetchAgent()
|
||||
}, [agentId])
|
||||
|
||||
// 加载知识库列表
|
||||
useEffect(() => {
|
||||
// åŠ è½½çŸ¥è¯†åº“åˆ—è¡? useEffect(() => {
|
||||
fetchKnowledgeBases()
|
||||
}, [])
|
||||
|
||||
// 创建或加载对话
|
||||
useEffect(() => {
|
||||
// åˆ›å»ºæˆ–åŠ è½½å¯¹è¯? useEffect(() => {
|
||||
const initConversation = async () => {
|
||||
if (!agent || !currentProject) return
|
||||
|
||||
try {
|
||||
// 创建新对话
|
||||
const response = await conversationApi.createConversation({
|
||||
// 创建新对� const response = await conversationApi.createConversation({
|
||||
projectId: currentProject.id,
|
||||
agentId: agent.id,
|
||||
title: `与${agent.name}的对话`,
|
||||
title: `ä¸?{agent.name}的对è¯<C3A8>`,
|
||||
})
|
||||
|
||||
setConversation(response.data.data || null)
|
||||
@@ -84,15 +77,13 @@ const AgentChatPage = () => {
|
||||
initConversation()
|
||||
}, [agent, currentProject])
|
||||
|
||||
// 发送消息(流式)
|
||||
const handleSendMessage = async (content: string, knowledgeBaseIds: string[]) => {
|
||||
// å<EFBFBD>‘é€<EFBFBD>消æ<EFBFBD>¯ï¼ˆæµ<EFBFBD>å¼<EFBFBD>ï¼? const handleSendMessage = async (content: string, knowledgeBaseIds: string[]) => {
|
||||
if (!conversation || sending) return
|
||||
|
||||
setSending(true)
|
||||
setStreamingContent('')
|
||||
|
||||
// 添加用户消息到列表
|
||||
const userMessage: Message = {
|
||||
// æ·»åŠ ç”¨æˆ·æ¶ˆæ<EFBFBD>¯åˆ°åˆ—è¡? const userMessage: Message = {
|
||||
id: `temp-${Date.now()}`,
|
||||
conversationId: conversation.id,
|
||||
role: 'user',
|
||||
@@ -118,8 +109,7 @@ const AgentChatPage = () => {
|
||||
},
|
||||
// onComplete
|
||||
() => {
|
||||
// 流式完成后,添加完整的助手消息
|
||||
const assistantMessage: Message = {
|
||||
// æµ<EFBFBD>å¼<EFBFBD>完æˆ<EFBFBD>å<EFBFBD>Žï¼Œæ·»åŠ å®Œæ•´çš„åŠ©æ‰‹æ¶ˆæ<EFBFBD>? const assistantMessage: Message = {
|
||||
id: `temp-assistant-${Date.now()}`,
|
||||
conversationId: conversation.id,
|
||||
role: 'assistant',
|
||||
@@ -141,7 +131,7 @@ const AgentChatPage = () => {
|
||||
)
|
||||
} catch (err) {
|
||||
console.error('Failed to send message:', err)
|
||||
message.error('发送消息失败')
|
||||
message.error('å<EFBFBD>‘é€<EFBFBD>消æ<EFBFBD>¯å¤±è´?)
|
||||
setStreamingContent('')
|
||||
setSending(false)
|
||||
}
|
||||
@@ -159,7 +149,7 @@ const AgentChatPage = () => {
|
||||
return (
|
||||
<Alert
|
||||
message="请先选择项目"
|
||||
description="请在侧边栏选择一个项目后再开始对话"
|
||||
description="请在侧边æ <C3A6>选择一个项目å<C2AE>Žå†<C3A5>开始对è¯?
|
||||
type="info"
|
||||
showIcon
|
||||
/>
|
||||
@@ -190,7 +180,7 @@ const AgentChatPage = () => {
|
||||
|
||||
return (
|
||||
<div style={{ height: '100%', display: 'flex', flexDirection: 'column' }}>
|
||||
{/* 顶部工具栏 - 紧凑设计 */}
|
||||
{/* 顶部工具æ ?- 紧凑设计 */}
|
||||
<div style={{
|
||||
padding: '12px 24px',
|
||||
background: '#fff',
|
||||
@@ -212,7 +202,7 @@ const AgentChatPage = () => {
|
||||
</div>
|
||||
</Space>
|
||||
|
||||
{/* 模型选择器 */}
|
||||
{/* 模型选择�*/}
|
||||
<ModelSelector
|
||||
value={selectedModel}
|
||||
onChange={setSelectedModel}
|
||||
@@ -236,17 +226,15 @@ const AgentChatPage = () => {
|
||||
flex: 1,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
minHeight: 0, // 重要:确保可以滚动
|
||||
overflow: 'hidden',
|
||||
minHeight: 0, // é‡<C3A9>è¦<C3A8>:确ä¿<C3A4>å<EFBFBD>¯ä»¥æ»šåŠ? overflow: 'hidden',
|
||||
}}>
|
||||
{messages.length === 0 && !sending ? (
|
||||
<div style={{ flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center', background: '#fafafa' }}>
|
||||
<div style={{ textAlign: 'center', color: '#999' }}>
|
||||
<RobotOutlined style={{ fontSize: 64, marginBottom: 16 }} />
|
||||
<div style={{ fontSize: 16 }}>开始对话,我将为您提供专业的研究建议</div>
|
||||
<div style={{ fontSize: 16 }}>开始对è¯<EFBFBD>,我将为您æ<EFBFBD><EFBFBD>ä¾›ä¸“ä¸šçš„ç ”ç©¶å»ºè®?/div>
|
||||
<div style={{ fontSize: 14, marginTop: 8 }}>
|
||||
您可以直接输入问题,或使用@知识库功能引用文献
|
||||
</div>
|
||||
您å<EFBFBD>¯ä»¥ç›´æŽ¥è¾“入问题,或使用@知识库功能引用文çŒ? </div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
@@ -263,7 +251,7 @@ const AgentChatPage = () => {
|
||||
onSend={handleSendMessage}
|
||||
loading={sending}
|
||||
knowledgeBases={knowledgeBases}
|
||||
placeholder={`向${agent.name}提问...(Shift+Enter换行,Enter发送)`}
|
||||
placeholder={`å<EFBFBD>?{agent.name}æ<><C3A6>é—®...(Shift+Enteræ<72>¢è¡Œï¼ŒEnterå<72>‘é€<C3A9>)`}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user