fix: 回合活跃判定放宽——压缩/通知行尾随不再误收起

This commit is contained in:
Rick Ye
2026-09-10 02:16:26 +08:00
parent 367f3f5c5b
commit 46813c23cd
2 changed files with 92 additions and 3 deletions
@@ -108,7 +108,14 @@ function renderTurns(
// turnActive/streaming 是会话级信号:只有延伸到消息列表末尾的最后一个
// assistant 组是「活跃回合」。透传给历史回合会让它们误显示
// 「已工作/处理中」并保持过程区展开。
const isLive = j === messages.length
// 放宽:会话级 turnActive 期间,组后仅尾随非真实用户消息(自动压缩/分支
// 摘要通知行)时不算离开末尾——否则压缩间隙 live 跌落,600ms 自动收起后
// 续跑又展开,形成展开/收起反复横跳(慢工具/长会话反复压缩尤甚)。
let liveEnd = j
while (liveEnd < messages.length && !(messages[liveEnd].role === 'user' && !messages[liveEnd].local)) {
liveEnd += 1
}
const isLive = j === messages.length || (turnActive && liveEnd === messages.length)
// 本回合之后第一条真实用户消息(跳过压缩/摘要行):分叉锚点,'before' 含本回合答案为止
let nextUser = j
while (nextUser < messages.length && !(messages[nextUser].role === 'user' && !messages[nextUser].local)) {
@@ -183,7 +190,8 @@ export function ChatView({
onFork,
onForkAt,
onPickSuggestion,
onQuoteSelection
onQuoteSelection,
visible = true
}: {
messages: UiMessage[]
tools: Record<string, ToolState>
@@ -212,6 +220,8 @@ export function ChatView({
onForkAt: (entryId: string) => void
onPickSuggestion: (text: string) => void
onQuoteSelection: (selection: string) => void
/** 聊天列是否可见(切到插件视图时 display:none 保活;隐藏期滚动测量为 0,切回重新吸底) */
visible?: boolean
}): ReactNode {
const scrollRef = useRef<HTMLDivElement>(null)
const pinnedRef = useRef(true)
@@ -280,7 +290,7 @@ export function ChatView({
el.scrollTop = el.scrollHeight
})
return () => cancelAnimationFrame(raf)
}, [messages, tools, streaming])
}, [messages, tools, streaming, visible])
// 压缩结果通知 8 秒后自动消退
useEffect(() => {