feat(web): agent feature add config
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* @Author: ZhaoYing
|
||||
* @Date: 2026-03-13 17:27:52
|
||||
* @Last Modified by: ZhaoYing
|
||||
* @Last Modified time: 2026-03-24 10:19:31
|
||||
* @Last Modified time: 2026-03-26 13:43:02
|
||||
*/
|
||||
import { type FC, useState, useRef, useEffect } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
@@ -88,11 +88,31 @@ const TestChat: FC<TestChatProps> = ({
|
||||
getVariables()
|
||||
}, [application, config])
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
audioPollingRef.current.forEach(timer => clearInterval(timer))
|
||||
audioPollingRef.current.clear()
|
||||
}
|
||||
}, [])
|
||||
|
||||
const getVariables = () => {
|
||||
if (!application || !config) return
|
||||
|
||||
setFeatures(config?.features || {} as FeaturesConfigForm)
|
||||
|
||||
|
||||
if (config?.features?.opening_statement?.statement && config?.features?.opening_statement?.statement.trim() !== '') {
|
||||
setChatList(prev => [...prev, {
|
||||
role: 'assistant',
|
||||
created_at: Date.now(),
|
||||
content: config?.features?.opening_statement?.statement,
|
||||
meta_data: {
|
||||
suggested_questions: config?.features?.opening_statement?.suggested_questions || []
|
||||
}
|
||||
}])
|
||||
}
|
||||
|
||||
|
||||
let initVariables: Variable[] = []
|
||||
|
||||
switch (application.type) {
|
||||
@@ -142,7 +162,7 @@ const TestChat: FC<TestChatProps> = ({
|
||||
}])
|
||||
}
|
||||
|
||||
const updateAssistantMessage = (content: string, audio_url?: string) => {
|
||||
const updateAssistantMessage = (content: string, audio_url?: string, audio_status?: string, citations?: any[]) => {
|
||||
setChatList(prev => {
|
||||
const newList = [...prev]
|
||||
const lastMsg = newList[newList.length - 1]
|
||||
@@ -150,7 +170,11 @@ const TestChat: FC<TestChatProps> = ({
|
||||
newList[newList.length - 1] = {
|
||||
...lastMsg,
|
||||
content: lastMsg.content + content,
|
||||
...(audio_url !== undefined ? { meta_data: { ...lastMsg.meta_data, audio_url, audio_status: 'pending' } } : {})
|
||||
meta_data: {
|
||||
audio_url: audio_url || lastMsg.meta_data?.audio_url,
|
||||
audio_status: audio_status || lastMsg.meta_data?.audio_status,
|
||||
citations: citations || lastMsg.meta_data?.citations
|
||||
}
|
||||
}
|
||||
}
|
||||
return newList
|
||||
@@ -188,14 +212,14 @@ const TestChat: FC<TestChatProps> = ({
|
||||
return { isCanSend, params }
|
||||
}
|
||||
|
||||
const handleSend = () => {
|
||||
if (loading || !application || !message || !message?.trim()) return
|
||||
const handleSend = (msg?: string) => {
|
||||
if (loading || !application || !((message && message?.trim() !== '') || (msg && msg?.trim() !== ''))) return
|
||||
const files = (toolbarRef.current?.getFiles() || []).filter(item => !['uploading', 'error'].includes(item.status))
|
||||
const variables = toolbarRef.current?.getVariables() || []
|
||||
const { isCanSend, params } = buildVariableParams(variables)
|
||||
if (!isCanSend) return
|
||||
|
||||
addUserMessage(message, files)
|
||||
addUserMessage((msg || message) as string, files)
|
||||
setMessage(undefined)
|
||||
toolbarRef.current?.setFiles([])
|
||||
setFileList([])
|
||||
@@ -205,7 +229,7 @@ const TestChat: FC<TestChatProps> = ({
|
||||
|
||||
draftRun(
|
||||
application.id,
|
||||
formatParams(message, conversationId, files, params),
|
||||
formatParams((msg || message) as string, conversationId, files, params),
|
||||
handleStreamMessage
|
||||
)
|
||||
.catch(() => {
|
||||
@@ -236,7 +260,15 @@ const TestChat: FC<TestChatProps> = ({
|
||||
|
||||
const handleStreamMessage = (data: SSEMessage[]) => {
|
||||
data.map(item => {
|
||||
const { conversation_id, content, message_length, audio_url } = item.data as { conversation_id: string, content: string, message_length: number; audio_url?: string; };
|
||||
const { conversation_id, content, message_length, audio_url, citations } = item.data as {
|
||||
conversation_id: string, content: string, message_length: number; audio_url?: string;
|
||||
citations?: {
|
||||
document_id: string;
|
||||
file_name: string;
|
||||
knowledge_id: string;
|
||||
score: string;
|
||||
}[]
|
||||
};
|
||||
switch (item.event) {
|
||||
case 'start':
|
||||
if (conversation_id && conversationId !== conversation_id) setConversationId(conversation_id)
|
||||
@@ -253,7 +285,7 @@ const TestChat: FC<TestChatProps> = ({
|
||||
}))
|
||||
}
|
||||
if (audio_url) {
|
||||
updateAssistantMessage(content || '', audio_url)
|
||||
updateAssistantMessage(content || '', audio_url, 'pending')
|
||||
const { file_id } = item.data as { file_id?: string }
|
||||
const idToPoll = file_id || audio_url || ''
|
||||
const fileId = audio_url.split('/').pop()
|
||||
@@ -279,6 +311,9 @@ const TestChat: FC<TestChatProps> = ({
|
||||
audioPollingRef.current.set(idToPoll, timer)
|
||||
}
|
||||
}
|
||||
if (citations && citations.length > 0) {
|
||||
updateAssistantMessage(content, audio_url, undefined, citations)
|
||||
}
|
||||
updateErrorAssistantMessage(message_length)
|
||||
setStreamLoading(false)
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user