Commit 548b62d4 by Liu

fix:历史记录正常展示

parent 306d592c
...@@ -146,6 +146,8 @@ export const Chat: React.FC = () => { ...@@ -146,6 +146,8 @@ export const Chat: React.FC = () => {
const newItems = [...prevItems] // 创建数组的浅拷贝 const newItems = [...prevItems] // 创建数组的浅拷贝
const lastIndex = newItems.length - 1 const lastIndex = newItems.length - 1
const isEmptyQuestion = !question.trim() const isEmptyQuestion = !question.trim()
// 提质增效自动欢迎语场景:空问题的流式回答应追加在历史记录之后,避免复用最后一条历史 AI 记录
const shouldAlwaysAppendAi = isAutoSubmitQualityImprovementRef.current && isEmptyQuestion
// 提质增效模式下,自动调用时收集首个有效 answer 作为欢迎语候选(按流式增量累积) // 提质增效模式下,自动调用时收集首个有效 answer 作为欢迎语候选(按流式增量累积)
if (isAutoSubmitQualityImprovementRef.current && isEmptyQuestion) { if (isAutoSubmitQualityImprovementRef.current && isEmptyQuestion) {
...@@ -183,8 +185,8 @@ export const Chat: React.FC = () => { ...@@ -183,8 +185,8 @@ export const Chat: React.FC = () => {
} }
} }
// 如果是空问题且最后一项不是AI回答,需要添加AI回答 // 如果是空问题且需要追加新的 AI 记录(历史末尾没有 AI,或提质增效自动欢迎语场景),则添加 AI 回答占位
if (isEmptyQuestion && (lastIndex < 0 || newItems[lastIndex].role !== 'ai')) { if (isEmptyQuestion && (lastIndex < 0 || newItems[lastIndex].role !== 'ai' || shouldAlwaysAppendAi)) {
newItems.push({ newItems.push({
role: 'ai', role: 'ai',
answerList: [{ answer: '' }], answerList: [{ answer: '' }],
...@@ -1008,12 +1010,21 @@ export const Chat: React.FC = () => { ...@@ -1008,12 +1010,21 @@ export const Chat: React.FC = () => {
// 如果是自动调用提问接口(空问题且是流式返回的新记录),不显示问题和回答 // 如果是自动调用提问接口(空问题且是流式返回的新记录),不显示问题和回答
// 判断条件:question === undefined(空问题)且 isShow === false(流式返回的新记录,不是历史记录) // 判断条件:question === undefined(空问题)且 isShow === false(流式返回的新记录,不是历史记录)
const shouldHideEmptyQuestionAnswer = record.role === 'ai' && record.question === undefined && record.answerList?.[0]?.isShow === false const shouldHideEmptyQuestionAnswer = record.role === 'ai' && record.question === undefined && record.answerList?.[0]?.isShow === false
// 白名单:当同一条 AI 记录里同时有 question + answer(且 firstQaFlag 不为 true)时,强制展示,避免误隐藏
const hasQuestion = typeof record.question === 'string' && record.question.trim().length > 0
const firstAnswer = record.answerList?.[0]
const hasAnswer = typeof firstAnswer?.answer === 'string' && firstAnswer.answer.trim().length > 0
const hasCardList = Array.isArray(firstAnswer?.cardList) && firstAnswer!.cardList.length > 0
const shouldForceShow = record.role === 'ai'
&& hasQuestion
&& (hasAnswer || hasCardList)
&& firstAnswer?.firstQaFlag !== true
console.log('9yyyyyyyyyy', record.answerList?.[0]?.answer, uniqueKey)
return ( return (
<div <div
className="w-full chatItem mx-auto" className="w-full chatItem mx-auto"
key={uniqueKey} key={uniqueKey}
style={(shouldHideHistoryItem || shouldHideEmptyQuestionAnswer) ? { visibility: 'hidden', height: 0, overflow: 'hidden', margin: 0, padding: 0 } : undefined} style={(!shouldForceShow && (shouldHideHistoryItem || shouldHideEmptyQuestionAnswer)) ? { visibility: 'hidden', height: 0, overflow: 'hidden', margin: 0, padding: 0 } : undefined}
> >
{record.role === 'system' && <ChatWelcome toolName={currentToolName} welcomeText={(record as any).welcomeText} />} {record.role === 'system' && <ChatWelcome toolName={currentToolName} welcomeText={(record as any).welcomeText} />}
{record.role === 'user' && <ChatItemUser record={record} />} {record.role === 'user' && <ChatItemUser record={record} />}
......
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