fix: send message error when last sent message not succeeded (#8682)

This commit is contained in:
Hash Brown
2024-09-23 18:44:09 +08:00
committed by GitHub
parent c7eacd1aac
commit 11d09a92d0
6 changed files with 27 additions and 37 deletions

View File

@@ -6,6 +6,7 @@ import type {
OnSend,
} from '../types'
import { useChat } from '../chat/hooks'
import { getLastAnswer } from '../utils'
import { useEmbeddedChatbotContext } from './context'
import ConfigPanel from './config-panel'
import { isDify } from './utils'
@@ -69,17 +70,11 @@ const ChatWrapper = () => {
}, [])
const doSend: OnSend = useCallback((message, files, last_answer) => {
const lastAnswer = chatListRef.current.at(-1)
const data: any = {
query: message,
inputs: currentConversationId ? currentConversationItem?.inputs : newConversationInputs,
conversation_id: currentConversationId,
parent_message_id: last_answer?.id || (lastAnswer
? lastAnswer.isOpeningStatement
? null
: lastAnswer.id
: null),
parent_message_id: last_answer?.id || getLastAnswer(chatListRef.current)?.id || null,
}
if (appConfig?.file_upload?.image.enabled && files?.length)
@@ -113,13 +108,13 @@ const ChatWrapper = () => {
const prevMessages = chatList.slice(0, index)
const question = prevMessages.pop()
const lastAnswer = prevMessages.at(-1)
const lastAnswer = getLastAnswer(prevMessages)
if (!question)
return
handleUpdateChatList(prevMessages)
doSend(question.content, question.message_files, (!lastAnswer || lastAnswer.isOpeningStatement) ? undefined : lastAnswer)
doSend(question.content, question.message_files, lastAnswer)
}, [chatList, handleUpdateChatList, doSend])
const chatNode = useMemo(() => {