fix: chat history might be empty in log detail view (#10905)

This commit is contained in:
Hash Brown
2024-11-21 14:12:01 +08:00
committed by GitHub
parent f358db9f02
commit ea0ebc020c
4 changed files with 386 additions and 11 deletions

View File

@@ -127,19 +127,16 @@ function buildChatItemTree(allMessages: IChatItem[]): ChatItemInTree[] {
lastAppendedLegacyAnswer = answerNode
}
else {
if (!parentMessageId)
if (
!parentMessageId
|| !allMessages.some(item => item.id === parentMessageId) // parent message might not be fetched yet, in this case we will append the question to the root nodes
)
rootNodes.push(questionNode)
else
map[parentMessageId]?.children!.push(questionNode)
}
}
// If no messages have parentMessageId=null (indicating a root node),
// then we likely have a partial chat history. In this case,
// use the first available message as the root node.
if (rootNodes.length === 0 && allMessages.length > 0)
rootNodes.push(map[allMessages[0]!.id]!)
return rootNodes
}