fix(web): agent deep thinking loading
This commit is contained in:
@@ -68,14 +68,14 @@ const Chat: FC<ChatProps> = ({
|
|||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [isCluster, setIsCluster] = useState(source === 'multi_agent')
|
const [isCluster, setIsCluster] = useState(source === 'multi_agent')
|
||||||
const [conversationId, setConversationId] = useState<string | null>(null)
|
const [conversationId, setConversationId] = useState<string | null>(null)
|
||||||
const [compareLoading, setCompareLoading] = useState(false)
|
const compareLoadingRef = useRef(false)
|
||||||
const [fileList, setFileList] = useState<any[]>([])
|
const [fileList, setFileList] = useState<any[]>([])
|
||||||
const [message, setMessage] = useState<string | undefined>(undefined)
|
const [message, setMessage] = useState<string | undefined>(undefined)
|
||||||
const [features, setFeatures] = useState<FeaturesConfigForm>({} as FeaturesConfigForm)
|
const [features, setFeatures] = useState<FeaturesConfigForm>({} as FeaturesConfigForm)
|
||||||
const [audioStatusMap, setAudioStatusMap] = useState<Record<string, string>>({})
|
const [audioStatusMap, setAudioStatusMap] = useState<Record<string, string>>({})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setCompareLoading(false)
|
compareLoadingRef.current = false
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
return () => {
|
return () => {
|
||||||
audioPollingRef.current.forEach(timer => clearInterval(timer))
|
audioPollingRef.current.forEach(timer => clearInterval(timer))
|
||||||
@@ -254,7 +254,7 @@ const Chat: FC<ChatProps> = ({
|
|||||||
const handleSend = (msg?: string) => {
|
const handleSend = (msg?: string) => {
|
||||||
if (loading || !id) return
|
if (loading || !id) return
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
setCompareLoading(true)
|
compareLoadingRef.current = true
|
||||||
const files = (fileList || []).filter(item => !['uploading', 'error'].includes(item.status))
|
const files = (fileList || []).filter(item => !['uploading', 'error'].includes(item.status))
|
||||||
handleSave(false)
|
handleSave(false)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -280,7 +280,7 @@ const Chat: FC<ChatProps> = ({
|
|||||||
}
|
}
|
||||||
if (!isCanSend) {
|
if (!isCanSend) {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
setCompareLoading(false)
|
compareLoadingRef.current = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,20 +305,20 @@ const Chat: FC<ChatProps> = ({
|
|||||||
|
|
||||||
switch (item.event) {
|
switch (item.event) {
|
||||||
case 'model_reasoning':
|
case 'model_reasoning':
|
||||||
if (compareLoading) {
|
if (compareLoadingRef.current) {
|
||||||
setCompareLoading(false)
|
compareLoadingRef.current = false
|
||||||
}
|
}
|
||||||
updateAssistantReasoningMessage(content, model_config_id, conversation_id)
|
updateAssistantReasoningMessage(content, model_config_id, conversation_id)
|
||||||
break;
|
break;
|
||||||
case 'model_message':
|
case 'model_message':
|
||||||
if (compareLoading) {
|
if (compareLoadingRef.current) {
|
||||||
setCompareLoading(false)
|
compareLoadingRef.current = false
|
||||||
}
|
}
|
||||||
updateAssistantMessage(content, model_config_id, conversation_id, audio_url)
|
updateAssistantMessage(content, model_config_id, conversation_id, audio_url)
|
||||||
break;
|
break;
|
||||||
case 'model_end':
|
case 'model_end':
|
||||||
if (compareLoading) {
|
if (compareLoadingRef.current) {
|
||||||
setCompareLoading(false)
|
compareLoadingRef.current = false
|
||||||
}
|
}
|
||||||
const idToPoll = `${model_config_id}_${audio_url}`
|
const idToPoll = `${model_config_id}_${audio_url}`
|
||||||
if (audio_url && !audioStatusMap[idToPoll]) {
|
if (audio_url && !audioStatusMap[idToPoll]) {
|
||||||
@@ -360,8 +360,8 @@ const Chat: FC<ChatProps> = ({
|
|||||||
updateErrorAssistantMessage(message_length, model_config_id)
|
updateErrorAssistantMessage(message_length, model_config_id)
|
||||||
break;
|
break;
|
||||||
case 'compare_end':
|
case 'compare_end':
|
||||||
if (compareLoading) {
|
if (compareLoadingRef.current) {
|
||||||
setCompareLoading(false)
|
compareLoadingRef.current = false
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
break;
|
break;
|
||||||
@@ -396,18 +396,18 @@ const Chat: FC<ChatProps> = ({
|
|||||||
}, handleStreamMessage)
|
}, handleStreamMessage)
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
setCompareLoading(false)
|
compareLoadingRef.current = false
|
||||||
updateClusterErrorAssistantMessage(0)
|
updateClusterErrorAssistantMessage(0)
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
setCompareLoading(false)
|
compareLoadingRef.current = false
|
||||||
})
|
})
|
||||||
}, 0)
|
}, 0)
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
setCompareLoading(false)
|
compareLoadingRef.current = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,7 +471,7 @@ const Chat: FC<ChatProps> = ({
|
|||||||
const handleClusterSend = (msg?: string) => {
|
const handleClusterSend = (msg?: string) => {
|
||||||
if (loading || !id) return
|
if (loading || !id) return
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
setCompareLoading(true)
|
compareLoadingRef.current = true
|
||||||
const files = (fileList || []).filter(item => !['uploading', 'error'].includes(item.status))
|
const files = (fileList || []).filter(item => !['uploading', 'error'].includes(item.status))
|
||||||
handleSave(false)
|
handleSave(false)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -495,8 +495,8 @@ const Chat: FC<ChatProps> = ({
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
case 'message':
|
case 'message':
|
||||||
if (compareLoading) {
|
if (compareLoadingRef.current) {
|
||||||
setCompareLoading(false)
|
compareLoadingRef.current = false
|
||||||
}
|
}
|
||||||
updateClusterAssistantMessage(content)
|
updateClusterAssistantMessage(content)
|
||||||
if (conversation_id && conversationId !== conversation_id) {
|
if (conversation_id && conversationId !== conversation_id) {
|
||||||
@@ -504,14 +504,14 @@ const Chat: FC<ChatProps> = ({
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'model_end':
|
case 'model_end':
|
||||||
if (compareLoading) {
|
if (compareLoadingRef.current) {
|
||||||
setCompareLoading(false)
|
compareLoadingRef.current = false
|
||||||
}
|
}
|
||||||
updateClusterErrorAssistantMessage(message_length)
|
updateClusterErrorAssistantMessage(message_length)
|
||||||
break;
|
break;
|
||||||
case 'compare_end':
|
case 'compare_end':
|
||||||
if (compareLoading) {
|
if (compareLoadingRef.current) {
|
||||||
setCompareLoading(false)
|
compareLoadingRef.current = false
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
break;
|
break;
|
||||||
@@ -541,18 +541,18 @@ const Chat: FC<ChatProps> = ({
|
|||||||
)
|
)
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
setCompareLoading(false)
|
compareLoadingRef.current = false
|
||||||
updateClusterErrorAssistantMessage(0)
|
updateClusterErrorAssistantMessage(0)
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
setCompareLoading(false)
|
compareLoadingRef.current = false
|
||||||
})
|
})
|
||||||
}, 0)
|
}, 0)
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
setCompareLoading(false)
|
compareLoadingRef.current = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -622,7 +622,7 @@ const Chat: FC<ChatProps> = ({
|
|||||||
/>}
|
/>}
|
||||||
onSend={isCluster ? handleClusterSend : handleSend}
|
onSend={isCluster ? handleClusterSend : handleSend}
|
||||||
data={chat.list || []}
|
data={chat.list || []}
|
||||||
streamLoading={compareLoading}
|
streamLoading={compareLoadingRef.current}
|
||||||
labelPosition="top"
|
labelPosition="top"
|
||||||
labelFormat={(item) => item.role === 'user' ? t('application.you') : chat.label || t(`application.ai`)}
|
labelFormat={(item) => item.role === 'user' ? t('application.you') : chat.label || t(`application.ai`)}
|
||||||
errorDesc={t('application.ReplyException')}
|
errorDesc={t('application.ReplyException')}
|
||||||
|
|||||||
Reference in New Issue
Block a user