fix: 历史回合误显示活跃状态与流式段间隐形空白

This commit is contained in:
Rick Ye
2026-09-07 19:15:17 +08:00
parent 54b99a1a58
commit 7565b8676f
3 changed files with 36 additions and 29 deletions
@@ -48,13 +48,17 @@ function renderTurns(
if (message.role === 'assistant') {
let j = i + 1
while (j < messages.length && messages[j].role === 'assistant') j += 1
// turnActive/streaming 是会话级信号:只有延伸到消息列表末尾的最后一个
// assistant 组是「活跃回合」。透传给历史回合会让它们误显示
// 「已工作/处理中」并保持过程区展开。
const isLive = j === messages.length
items.push(
<AssistantTurn
key={`${message.key}-turn`}
messages={messages.slice(i, j)}
tools={tools}
streaming={streaming}
turnActive={turnActive}
streaming={streaming && isLive}
turnActive={turnActive && isLive}
pendingApprovals={pendingApprovals}
/>
)
@@ -65,8 +69,8 @@ function renderTurns(
key={message.key}
message={message}
tools={tools}
streaming={streaming}
turnActive={turnActive}
streaming={streaming && i === messages.length - 1}
turnActive={turnActive && i === messages.length - 1}
pendingApprovals={pendingApprovals}
/>
)
@@ -177,15 +177,18 @@ export function AssistantTurn({
const streamNodes: ReactNode[] = []
let visibleThinkingRows = 0
if (stream) {
stream.segments.forEach((seg, i) => {
const segments = stream.segments
segments.forEach((seg, i) => {
if (seg.kind === 'thinking') {
if (!showStreamThinking) return
const rows = thinkingRows(seg.text)
if (rows.length === 0) return
visibleThinkingRows += rows.length
// 该思考段之后已有正文段在流:思考已完成,表头从「思考中…」切回「思考过程」
const followedByText = segments.some((s, k) => k > i && s.kind === 'text' && s.text.length > 0)
streamNodes.push(
<div key={`seg-${i}`} className="mb-3">
<Thinking rows={rows} streaming={streaming} />
<Thinking rows={rows} streaming={streaming && !followedByText} />
</div>
)
return
@@ -48,11 +48,10 @@ export function StreamingText({
/>
</div>
{/* 操作行:流式结束后淡入 */}
<div
className="mt-2 flex items-center gap-0.5 transition-opacity duration-[400ms]"
style={{ opacity: done ? 1 : 0, pointerEvents: done ? undefined : 'none' }}
>
{/* 操作行:流式结束后淡入。流式期间不渲染(opacity:0 也会占位,
* 每个正文段后会挂一块约 32px 的隐形空白,且完成后卸载造成布局跳动) */}
{done && (
<div className="mt-2 flex items-center gap-0.5" style={{ animation: 'fade-in 400ms ease both' }}>
<button
type="button"
aria-label={copied ? '已复制' : '复制回答'}
@@ -71,6 +70,7 @@ export function StreamingText({
)}
</button>
</div>
)}
{/* Follow-ups:完成后的跟进问题列表 */}
{done && followUps && followUps.length > 0 && (