revert: timing for adding citation references (#7953)

This commit is contained in:
one 2025-07-08 20:02:51 +08:00 committed by GitHub
parent 14c5357fa3
commit 2a33a9af64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -429,6 +429,9 @@ const fetchAndProcessAssistantResponseImpl = async (
await handleBlockTransition(baseBlock as PlaceholderMessageBlock, MessageBlockType.UNKNOWN)
},
onTextChunk: async (text) => {
const citationBlockSource = citationBlockId
? (getState().messageBlocks.entities[citationBlockId] as CitationMessageBlock).response?.source
: WebSearchSource.WEBSEARCH
accumulatedContent += text
if (mainTextBlockId) {
const blockChanges: Partial<MessageBlock> = {
@ -441,7 +444,8 @@ const fetchAndProcessAssistantResponseImpl = async (
const initialChanges: Partial<MessageBlock> = {
type: MessageBlockType.MAIN_TEXT,
content: accumulatedContent,
status: MessageBlockStatus.STREAMING
status: MessageBlockStatus.STREAMING,
citationReferences: citationBlockId ? [{ citationBlockId, citationBlockSource }] : []
}
mainTextBlockId = initialPlaceholderBlockId
// 清理占位块
@ -451,7 +455,8 @@ const fetchAndProcessAssistantResponseImpl = async (
saveUpdatedBlockToDB(mainTextBlockId, assistantMsgId, topicId, getState)
} else {
const newBlock = createMainTextBlock(assistantMsgId, accumulatedContent, {
status: MessageBlockStatus.STREAMING
status: MessageBlockStatus.STREAMING,
citationReferences: citationBlockId ? [{ citationBlockId, citationBlockSource }] : []
})
mainTextBlockId = newBlock.id // 立即设置ID防止竞态条件
await handleBlockTransition(newBlock, MessageBlockType.MAIN_TEXT)
@ -459,15 +464,9 @@ const fetchAndProcessAssistantResponseImpl = async (
},
onTextComplete: async (finalText) => {
if (mainTextBlockId) {
let citationBlockSource: WebSearchSource | undefined
if (citationBlockId) {
const citationBlock = getState().messageBlocks.entities[citationBlockId] as CitationMessageBlock
citationBlockSource = citationBlock.response?.source
}
const changes = {
content: finalText,
status: MessageBlockStatus.SUCCESS,
citationReferences: citationBlockSource ? [{ citationBlockId, citationBlockSource }] : []
status: MessageBlockStatus.SUCCESS
}
cancelThrottledBlockUpdate(mainTextBlockId)
dispatch(updateOneBlock({ id: mainTextBlockId, changes }))