Commit 2d419f61 by Liu

fix conversation toolId handling

parent 1912c563
......@@ -171,7 +171,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
setIsToolBtnActive(false)
try {
await dispatch(createConversation({
conversationData: {},
conversationData: { toolId: tool.toolId },
shouldNavigate: true,
shouldSendQuestion: '',
})).unwrap()
......
......@@ -206,7 +206,8 @@ export const Chat: React.FC = () => {
setIsLoading(true)
try {
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) => {
if (item.role === 'ai' && item.answerList?.[0]?.answer) {
......@@ -224,12 +225,11 @@ export const Chat: React.FC = () => {
return item
})
setAllItems(processedMessages)
const latestToolRecord = [...processedMessages].reverse().find(item => item.role === 'ai' && item.toolId !== undefined)
const trimmedToolId = latestToolRecord?.toolId?.trim?.()
const hasQaRecords = processedMessages.some(item => item.role !== 'system')
const latestToolId = [...qaRecords].reverse().find(item => Boolean(item.toolId))?.toolId?.trim?.()
const hasQaRecords = qaRecords.length > 0
if (hasQaRecords) {
if (trimmedToolId) {
dispatch(setCurrentToolId(trimmedToolId))
if (latestToolId) {
dispatch(setCurrentToolId(latestToolId))
}
else {
dispatch(clearCurrentToolId())
......
......@@ -85,6 +85,10 @@ export const Collect: React.FC = () => {
// 添加返回上一页的函数
const handleGoBack = () => {
if (window.history.length > 1) {
navigate(-1)
return
}
const conversationId = sessionStorage.getItem('currentConversationId') || ''
navigate(`/chat/${conversationId}`, { state: { fromCollect: true } })
}
......
......@@ -64,8 +64,12 @@ export const createConversation = createAsyncThunk<
'conversation/createConversation',
async ({ conversationData, shouldNavigate, shouldSendQuestion }, { dispatch, getState }) => {
const state = getState()
const toolId = state.conversation.currentToolId || ''
const response = await fetchCreateConversation({ ...conversationData, toolId })
const resolvedToolId = conversationData.toolId ?? state.conversation.currentToolId
const requestPayload = {
...conversationData,
...(resolvedToolId ? { toolId: resolvedToolId } : {}),
}
const response = await fetchCreateConversation(requestPayload)
const newConversation = response.data
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