Commit 2d419f61 by Liu

fix conversation toolId handling

parent 1912c563
...@@ -171,7 +171,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth, ...@@ -171,7 +171,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
setIsToolBtnActive(false) setIsToolBtnActive(false)
try { try {
await dispatch(createConversation({ await dispatch(createConversation({
conversationData: {}, conversationData: { toolId: tool.toolId },
shouldNavigate: true, shouldNavigate: true,
shouldSendQuestion: '', shouldSendQuestion: '',
})).unwrap() })).unwrap()
......
...@@ -206,7 +206,8 @@ export const Chat: React.FC = () => { ...@@ -206,7 +206,8 @@ export const Chat: React.FC = () => {
setIsLoading(true) setIsLoading(true)
try { try {
const res = await fetchUserQaRecordPage(conversationId) const res = await fetchUserQaRecordPage(conversationId)
const messages = [{ role: 'system' } as ChatRecord, ...processApiResponse(res.data)] const qaRecords = res.data || []
const messages = [{ role: 'system' } as ChatRecord, ...processApiResponse(qaRecords)]
// 处理历史记录中的参考文档标记 // 处理历史记录中的参考文档标记
const processedMessages = messages.map((item) => { const processedMessages = messages.map((item) => {
if (item.role === 'ai' && item.answerList?.[0]?.answer) { if (item.role === 'ai' && item.answerList?.[0]?.answer) {
...@@ -224,12 +225,11 @@ export const Chat: React.FC = () => { ...@@ -224,12 +225,11 @@ export const Chat: React.FC = () => {
return item return item
}) })
setAllItems(processedMessages) setAllItems(processedMessages)
const latestToolRecord = [...processedMessages].reverse().find(item => item.role === 'ai' && item.toolId !== undefined) const latestToolId = [...qaRecords].reverse().find(item => Boolean(item.toolId))?.toolId?.trim?.()
const trimmedToolId = latestToolRecord?.toolId?.trim?.() const hasQaRecords = qaRecords.length > 0
const hasQaRecords = processedMessages.some(item => item.role !== 'system')
if (hasQaRecords) { if (hasQaRecords) {
if (trimmedToolId) { if (latestToolId) {
dispatch(setCurrentToolId(trimmedToolId)) dispatch(setCurrentToolId(latestToolId))
} }
else { else {
dispatch(clearCurrentToolId()) dispatch(clearCurrentToolId())
......
...@@ -85,6 +85,10 @@ export const Collect: React.FC = () => { ...@@ -85,6 +85,10 @@ export const Collect: React.FC = () => {
// 添加返回上一页的函数 // 添加返回上一页的函数
const handleGoBack = () => { const handleGoBack = () => {
if (window.history.length > 1) {
navigate(-1)
return
}
const conversationId = sessionStorage.getItem('currentConversationId') || '' const conversationId = sessionStorage.getItem('currentConversationId') || ''
navigate(`/chat/${conversationId}`, { state: { fromCollect: true } }) navigate(`/chat/${conversationId}`, { state: { fromCollect: true } })
} }
......
...@@ -64,8 +64,12 @@ export const createConversation = createAsyncThunk< ...@@ -64,8 +64,12 @@ export const createConversation = createAsyncThunk<
'conversation/createConversation', 'conversation/createConversation',
async ({ conversationData, shouldNavigate, shouldSendQuestion }, { dispatch, getState }) => { async ({ conversationData, shouldNavigate, shouldSendQuestion }, { dispatch, getState }) => {
const state = getState() const state = getState()
const toolId = state.conversation.currentToolId || '' const resolvedToolId = conversationData.toolId ?? state.conversation.currentToolId
const response = await fetchCreateConversation({ ...conversationData, toolId }) const requestPayload = {
...conversationData,
...(resolvedToolId ? { toolId: resolvedToolId } : {}),
}
const response = await fetchCreateConversation(requestPayload)
const newConversation = response.data const newConversation = response.data
dispatch(fetchConversations()) dispatch(fetchConversations())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment