feat(chat): fold long streaming timelines and steady their height (#4496)
* feat(chat): fold long streaming timelines and steady their height Keep recent steps visible while a run streams, attach finished reasoning to the following tool, and absorb sudden height drops so the followed viewport does not jump. * style(chat): use the motion token for the reasoning togglemain
parent
09b9c98d54
commit
728966bc81
|
|
@ -0,0 +1,17 @@
|
|||
import assert from 'node:assert/strict'
|
||||
import { test } from 'node:test'
|
||||
import { nextHeightFloor } from './useStreamingHeightFloor'
|
||||
|
||||
test('streaming height floor grows at once and absorbs shrinks up to the cap', () => {
|
||||
let floor = 0
|
||||
floor = nextHeightFloor(floor, 400, 200)
|
||||
assert.equal(floor, 400)
|
||||
floor = nextHeightFloor(floor, 300, 200)
|
||||
assert.equal(floor, 400, 'a folded step leaves slack instead of shrinking')
|
||||
floor = nextHeightFloor(floor, 350, 200)
|
||||
assert.equal(floor, 400, 'the next step fills the slack before the reply grows')
|
||||
floor = nextHeightFloor(floor, 450, 200)
|
||||
assert.equal(floor, 450)
|
||||
floor = nextHeightFloor(floor, 100, 200)
|
||||
assert.equal(floor, 300, 'slack never exceeds the cap, keeping new content in view')
|
||||
})
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
import { onBeforeUnmount, onMounted, onUpdated, watch, type Ref } from 'vue'
|
||||
|
||||
/**
|
||||
* Next minimum height for a streaming message. Growth raises the floor at once;
|
||||
* a shrink keeps up to `cap` pixels of slack so the following step can fill it.
|
||||
*/
|
||||
export function nextHeightFloor(floor: number, content: number, cap: number): number {
|
||||
return Math.max(content, Math.min(floor, content + cap))
|
||||
}
|
||||
|
||||
function contentHeight(node: HTMLElement): number {
|
||||
const top = node.getBoundingClientRect().top
|
||||
let bottom = top
|
||||
for (const child of Array.from(node.children)) {
|
||||
bottom = Math.max(bottom, child.getBoundingClientRect().bottom)
|
||||
}
|
||||
return bottom - top
|
||||
}
|
||||
|
||||
/**
|
||||
* While a reply streams, steps fold and previews disappear. A follow-the-bottom
|
||||
* viewport turns every such shrink into the whole conversation dropping, then
|
||||
* climbing again as the next step grows. Holding a height floor keeps scroll
|
||||
* motion one-directional; the slack is capped so the latest content stays in
|
||||
* view, and released before the completed timeline folds.
|
||||
*/
|
||||
export function useStreamingHeightFloor(
|
||||
el: Ref<HTMLElement | null>,
|
||||
active: Readonly<Ref<boolean>>,
|
||||
capRatio = 0.3,
|
||||
): void {
|
||||
let floor = 0
|
||||
let observer: ResizeObserver | null = null
|
||||
|
||||
const apply = () => {
|
||||
const node = el.value
|
||||
if (!node || !active.value) return
|
||||
const next = nextHeightFloor(floor, contentHeight(node), window.innerHeight * capRatio)
|
||||
if (next === floor) return
|
||||
floor = next
|
||||
node.style.minHeight = `${Math.ceil(next)}px`
|
||||
}
|
||||
|
||||
const release = () => {
|
||||
floor = 0
|
||||
if (el.value) el.value.style.minHeight = ''
|
||||
}
|
||||
|
||||
// Pre-flush: drop the floor before the render that folds the finished timeline.
|
||||
watch(active, on => (on ? apply() : release()))
|
||||
|
||||
onMounted(() => {
|
||||
if (!el.value || typeof ResizeObserver === 'undefined') return
|
||||
observer = new ResizeObserver(apply)
|
||||
observer.observe(el.value)
|
||||
apply()
|
||||
})
|
||||
// A shrink held by the floor does not resize the element, so re-check the
|
||||
// slack cap after each render.
|
||||
onUpdated(apply)
|
||||
onBeforeUnmount(() => {
|
||||
observer?.disconnect()
|
||||
observer = null
|
||||
})
|
||||
}
|
||||
|
|
@ -296,6 +296,8 @@ const messages = {
|
|||
"stepsCompleted": "已完成 <strong>{steps}</strong> 个步骤",
|
||||
"stepsCompletedWithDuration": "已完成 <strong>{steps}</strong> 个步骤,耗时 <strong>{duration}</strong>",
|
||||
"reasoningRounds": "思考 <strong>{rounds}</strong> 轮",
|
||||
"earlierSteps": "已完成 {count} 个步骤",
|
||||
"viewReasoning": "查看思路",
|
||||
"toolCalls": "调用 <strong>{tools}</strong> 次工具",
|
||||
"durationSuffix": "耗时 <strong>{duration}</strong>",
|
||||
"stepSummarySeparator": " · "
|
||||
|
|
@ -882,6 +884,8 @@ const messages = {
|
|||
"stepsCompleted": "已完成 <strong>{steps}</strong> 個步驟",
|
||||
"stepsCompletedWithDuration": "已完成 <strong>{steps}</strong> 個步驟,耗時 <strong>{duration}</strong>",
|
||||
"reasoningRounds": "思考 <strong>{rounds}</strong> 輪",
|
||||
"earlierSteps": "已完成 {count} 個步驟",
|
||||
"viewReasoning": "檢視思路",
|
||||
"toolCalls": "呼叫 <strong>{tools}</strong> 次工具",
|
||||
"durationSuffix": "耗時 <strong>{duration}</strong>",
|
||||
"stepSummarySeparator": " · "
|
||||
|
|
@ -1468,6 +1472,8 @@ const messages = {
|
|||
"stepsCompleted": "<strong>{steps}</strong>ステップ完了",
|
||||
"stepsCompletedWithDuration": "<strong>{steps}</strong>ステップ完了(所要時間<strong>{duration}</strong>)",
|
||||
"reasoningRounds": "推論<strong>{rounds}</strong>回",
|
||||
"earlierSteps": "完了したステップ {count} 件",
|
||||
"viewReasoning": "思考を表示",
|
||||
"toolCalls": "ツール呼び出し<strong>{tools}</strong>回",
|
||||
"durationSuffix": "所要時間<strong>{duration}</strong>",
|
||||
"stepSummarySeparator": " · "
|
||||
|
|
@ -2054,6 +2060,8 @@ const messages = {
|
|||
"stepsCompleted": "Completed <strong>{steps}</strong> step(s)",
|
||||
"stepsCompletedWithDuration": "Completed <strong>{steps}</strong> step(s) in <strong>{duration}</strong>",
|
||||
"reasoningRounds": "<strong>{rounds}</strong> reasoning round(s)",
|
||||
"earlierSteps": "{count} earlier steps",
|
||||
"viewReasoning": "View reasoning",
|
||||
"toolCalls": "<strong>{tools}</strong> tool call(s)",
|
||||
"durationSuffix": "<strong>{duration}</strong>",
|
||||
"stepSummarySeparator": " · "
|
||||
|
|
|
|||
|
|
@ -1226,6 +1226,8 @@ export default {
|
|||
toolFallback: 'Tool',
|
||||
stepsCompleted: 'Completed <strong>{steps}</strong> step(s)',
|
||||
reasoningRounds: '<strong>{rounds}</strong> reasoning round(s)',
|
||||
earlierSteps: '{count} earlier steps',
|
||||
viewReasoning: 'View reasoning',
|
||||
toolCalls: '<strong>{tools}</strong> tool call(s)',
|
||||
durationSuffix: '<strong>{duration}</strong>',
|
||||
stepSummarySeparator: ' · ',
|
||||
|
|
|
|||
|
|
@ -1226,6 +1226,8 @@ export default {
|
|||
toolFallback: 'ツール',
|
||||
stepsCompleted: '<strong>{steps}</strong>ステップ完了',
|
||||
reasoningRounds: '推論<strong>{rounds}</strong>回',
|
||||
earlierSteps: '完了したステップ {count} 件',
|
||||
viewReasoning: '思考を表示',
|
||||
toolCalls: 'ツール呼び出し<strong>{tools}</strong>回',
|
||||
durationSuffix: '<strong>{duration}</strong>',
|
||||
stepSummarySeparator: ' · ',
|
||||
|
|
|
|||
|
|
@ -7238,6 +7238,8 @@ export default {
|
|||
toolFallback: '도구',
|
||||
stepsCompleted: '<strong>{steps}</strong>개 단계 완료',
|
||||
reasoningRounds: '사고 <strong>{rounds}</strong>회',
|
||||
earlierSteps: '이전 단계 {count}개',
|
||||
viewReasoning: '사고 과정 보기',
|
||||
toolCalls: '도구 <strong>{tools}</strong>회 호출',
|
||||
durationSuffix: '소요 시간 <strong>{duration}</strong>',
|
||||
stepSummarySeparator: ' · ',
|
||||
|
|
|
|||
|
|
@ -7238,6 +7238,8 @@ export default {
|
|||
toolFallback: 'Инструмент',
|
||||
stepsCompleted: 'Выполнено <strong>{steps}</strong> шаг(ов)',
|
||||
reasoningRounds: '<strong>{rounds}</strong> раунд(ов) рассуждений',
|
||||
earlierSteps: 'Предыдущие шаги: {count}',
|
||||
viewReasoning: 'Показать рассуждения',
|
||||
toolCalls: '<strong>{tools}</strong> вызов(ов) инструментов',
|
||||
durationSuffix: '<strong>{duration}</strong>',
|
||||
stepSummarySeparator: ' · ',
|
||||
|
|
|
|||
|
|
@ -7239,6 +7239,8 @@ export default {
|
|||
toolFallback: '工具',
|
||||
stepsCompleted: '已完成 <strong>{steps}</strong> 个步骤',
|
||||
reasoningRounds: '思考 <strong>{rounds}</strong> 轮',
|
||||
earlierSteps: '已完成 {count} 个步骤',
|
||||
viewReasoning: '查看思路',
|
||||
toolCalls: '调用 <strong>{tools}</strong> 次工具',
|
||||
durationSuffix: '耗时 <strong>{duration}</strong>',
|
||||
stepSummarySeparator: ' · ',
|
||||
|
|
|
|||
|
|
@ -7239,6 +7239,8 @@ export default {
|
|||
toolFallback: '工具',
|
||||
stepsCompleted: '已完成 <strong>{steps}</strong> 個步驟',
|
||||
reasoningRounds: '思考 <strong>{rounds}</strong> 輪',
|
||||
earlierSteps: '已完成 {count} 個步驟',
|
||||
viewReasoning: '檢視思路',
|
||||
toolCalls: '呼叫 <strong>{tools}</strong> 次工具',
|
||||
durationSuffix: '耗時 <strong>{duration}</strong>',
|
||||
stepSummarySeparator: ' · ',
|
||||
|
|
|
|||
|
|
@ -79,3 +79,34 @@ test('progress grouping preserves approval, reasoning, tool, user input and fina
|
|||
assert.deepEqual(groupProgressUpdates(events), events)
|
||||
}
|
||||
})
|
||||
|
||||
test('finished untitled reasoning rides on the tool call it led to', async () => {
|
||||
const { attachReasoningToTools } = await import('./agentTimelinePresentation')
|
||||
const tool = Object.freeze({ type: 'tool_call', tool_call_id: 't1', tool_name: 'knowledge_search' })
|
||||
const events = [
|
||||
{ type: 'thinking', event_id: 'r1', content: 'Search first' }, tool,
|
||||
{ type: 'thinking', event_id: 'r2', title: '我先读一下文档', content: 'Read it' },
|
||||
{ type: 'tool_call', tool_call_id: 't2', tool_name: 'read_document' },
|
||||
{ type: 'thinking', event_id: 'r3', content: 'Still thinking' },
|
||||
{ type: 'tool_call', tool_call_id: 't3', tool_name: 'web_search' },
|
||||
{ type: 'thinking', event_id: 'r4', content: 'Wrap up' },
|
||||
]
|
||||
const output = attachReasoningToTools(events, (e: any) => e.event_id !== 'r3')
|
||||
assert.deepEqual(output.map((e: any) => e.event_id || e.tool_call_id), ['t1', 'r2', 't2', 'r3', 't3', 'r4'])
|
||||
assert.deepEqual(output[0].reasoning, { id: 'reasoning-r1', content: 'Search first' })
|
||||
assert.equal('reasoning' in tool, false)
|
||||
assert.equal(output[2].reasoning, undefined, 'titled narration keeps its own row')
|
||||
assert.equal(output[4].reasoning, undefined, 'reasoning that cannot attach keeps its own row')
|
||||
})
|
||||
|
||||
test('earlier steps fold behind recent and attention-demanding rows', async () => {
|
||||
const { earlierStepKeys } = await import('./agentTimelinePresentation')
|
||||
const rows = (n: number, sticky: string[] = []) => Array.from({ length: n }, (_, i) => ({
|
||||
key: `k${i}`, step: true, sticky: sticky.includes(`k${i}`),
|
||||
}))
|
||||
assert.deepEqual(earlierStepKeys(rows(4)), [], 'folding a single row saves nothing')
|
||||
assert.deepEqual(earlierStepKeys(rows(6)), ['k0', 'k1', 'k2'])
|
||||
assert.deepEqual(earlierStepKeys(rows(5, ['k1'])), [], 'sticky rows stay out of the fold')
|
||||
assert.deepEqual(earlierStepKeys(rows(6, ['k1'])), ['k0', 'k2'])
|
||||
assert.deepEqual(earlierStepKeys([...rows(6), { key: 'answer', step: false, sticky: false }]), ['k0', 'k1', 'k2'])
|
||||
})
|
||||
|
|
|
|||
|
|
@ -21,6 +21,46 @@ export function foldProgressIntoThinking(events: any[]): any[] {
|
|||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Move finished, untitled reasoning onto the tool call it led to, so the
|
||||
* timeline shows one row per action instead of alternating thought/tool rows.
|
||||
* Titled reasoning (a relocated preamble) is user-facing narration and stays.
|
||||
*/
|
||||
export function attachReasoningToTools(events: any[], canAttach: (event: any) => boolean): any[] {
|
||||
const result: any[] = []
|
||||
for (let i = 0; i < events.length; i++) {
|
||||
const event = events[i]
|
||||
const next = events[i + 1]
|
||||
const content = typeof event?.content === 'string' ? event.content.trim() : ''
|
||||
if (event?.type === 'thinking' && !event.title && content && event.event_id
|
||||
&& next?.type === 'tool_call' && next.tool_name !== 'thinking' && !next.reasoning
|
||||
&& canAttach(event)) {
|
||||
result.push({ ...next, reasoning: { id: `reasoning-${event.event_id}`, content: event.content } })
|
||||
i++
|
||||
continue
|
||||
}
|
||||
result.push(event)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Keys of early timeline rows to fold while a run streams. The most recent
|
||||
* rows and anything still demanding attention stay visible; folding fewer
|
||||
* than `minFolded` rows would cost a row without saving one.
|
||||
*/
|
||||
export function earlierStepKeys(
|
||||
rows: { key: string, step: boolean, sticky: boolean }[],
|
||||
keepRecent = 3,
|
||||
minFolded = 2,
|
||||
): string[] {
|
||||
const steps = rows.filter(row => row.step)
|
||||
const keys = steps.slice(0, Math.max(0, steps.length - keepRecent))
|
||||
.filter(row => !row.sticky)
|
||||
.map(row => row.key)
|
||||
return keys.length >= minFolded ? keys : []
|
||||
}
|
||||
|
||||
/** Compact adjacent visible updates without crossing tools, prompts or answers. */
|
||||
export function groupProgressUpdates(events: any[]): any[] {
|
||||
const result: any[] = []
|
||||
|
|
|
|||
|
|
@ -52,7 +52,9 @@ test('agent steps use compact muted timeline styling', () => {
|
|||
})
|
||||
|
||||
test('expanded agent step log keeps model thinking in the tool timeline', () => {
|
||||
assert.match(source, /visibleIntermediateEvents\s*=\s*computed\(\(\) => intermediateEvents\.value\)/)
|
||||
assert.match(source, /visibleIntermediateEvents\s*=\s*computed\(\(\) => attachReasoningToTools\(intermediateEvents\.value, canAttachReasoning\)\)/)
|
||||
assert.match(source, /v-for="\(event, index\) in timelineEvents"/)
|
||||
assert.match(source, /class="action-reasoning thinking-detail-content markdown-content"/)
|
||||
assert.match(source, /v-for="\(event, index\) in visibleIntermediateEvents"/)
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@
|
|||
<div v-if="event.type === 'thinking'" class="tool-event">
|
||||
<div class="action-card thinking-event-card"
|
||||
:class="{ 'action-pending': isThinkingActive(event.event_id) }">
|
||||
<div class="action-header" @click="toggleEvent(event.event_id)">
|
||||
<div class="action-header" @click="toggleThinking(event.event_id)">
|
||||
<div class="action-title" :class="{
|
||||
'thinking-inline-title': !event.title && isEventExpanded(event.event_id),
|
||||
}">
|
||||
|
|
@ -82,7 +82,8 @@
|
|||
aria-hidden="true" />
|
||||
<span v-if="event.title" class="action-name action-preamble-title">{{ event.title }}</span>
|
||||
<div v-else-if="event.content && isEventExpanded(event.event_id)"
|
||||
class="thinking-inline-content markdown-content">
|
||||
class="thinking-inline-content markdown-content"
|
||||
:class="{ 'thinking-live-window': isLiveThinking(event.event_id) }">
|
||||
<div class="thinking-inline-markdown" v-html="renderMarkdownContent(event.content)"></div>
|
||||
</div>
|
||||
<span v-else-if="getThinkingSummary(event)" class="action-summary">{{ getThinkingSummary(event)
|
||||
|
|
@ -90,7 +91,8 @@
|
|||
</div>
|
||||
</div>
|
||||
<div v-if="event.title && event.content && isEventExpanded(event.event_id)" class="action-details">
|
||||
<div class="thinking-detail-content markdown-content">
|
||||
<div class="thinking-detail-content markdown-content"
|
||||
:class="{ 'thinking-live-window': isLiveThinking(event.event_id) }">
|
||||
<div v-html="renderMarkdownContent(event.content)"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -182,9 +184,21 @@
|
|||
<span v-if="getSandboxDiffStat(event)?.added" class="diff-add">+{{ getSandboxDiffStat(event)?.added }}</span>
|
||||
<span v-if="getSandboxDiffStat(event)?.removed" class="diff-del">-{{ getSandboxDiffStat(event)?.removed }}</span>
|
||||
</span>
|
||||
<button v-if="event.reasoning" type="button" class="action-reasoning-toggle"
|
||||
:class="{ 'is-open': isEventExpanded(event.reasoning.id) }"
|
||||
:title="t('agent.viewReasoning')" :aria-label="t('agent.viewReasoning')"
|
||||
:aria-expanded="isEventExpanded(event.reasoning.id)"
|
||||
@click.stop="toggleEvent(event.reasoning.id)" @keydown.enter.stop @keydown.space.stop>
|
||||
<span class="icon-mask" :style="maskIconStyle(thinkingIcon, 14)" aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="event.reasoning && isEventExpanded(event.reasoning.id)"
|
||||
class="action-reasoning thinking-detail-content markdown-content" @click.stop>
|
||||
<div v-html="renderMarkdownContent(event.reasoning.content)"></div>
|
||||
</div>
|
||||
|
||||
<div v-if="event.pending && getSandboxFilePreview(event)" class="sandbox-file-preview">
|
||||
<pre>{{ getSandboxFilePreview(event) }}</pre>
|
||||
<div v-if="sandboxPreviewRemaining(event) > 0" class="sandbox-file-preview-more">
|
||||
|
|
@ -298,8 +312,27 @@
|
|||
@toggle="toggleMemory"
|
||||
@forget="forgetMemory"
|
||||
/>
|
||||
<template v-for="(event, index) in displayEvents" :key="getEventKey(event, index)">
|
||||
<div v-if="event && event.type" class="event-item" :class="{
|
||||
<div v-if="earlierStepsCount > 0" class="event-item tree-child earlier-steps-node">
|
||||
<div class="tree-branch"></div>
|
||||
<div class="tree-child-content">
|
||||
<div class="action-card">
|
||||
<div class="action-header" role="button" tabindex="0" :aria-expanded="earlierStepsExpanded"
|
||||
@click="earlierStepsExpanded = !earlierStepsExpanded"
|
||||
@keydown.enter.prevent="earlierStepsExpanded = !earlierStepsExpanded"
|
||||
@keydown.space.prevent="earlierStepsExpanded = !earlierStepsExpanded">
|
||||
<div class="action-title">
|
||||
<t-icon class="action-title-icon" name="ellipsis" />
|
||||
<span class="action-name">{{ t('agent.earlierSteps', { count: earlierStepsCount }) }}</span>
|
||||
<div class="action-show-icon">
|
||||
<t-icon :name="earlierStepsExpanded ? 'chevron-down' : 'chevron-right'" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<template v-for="(event, index) in timelineEvents" :key="getEventKey(event, index)">
|
||||
<div v-if="event && event.type && !foldedStepKeys.has(getEventKey(event, index))" class="event-item" :class="{
|
||||
'event-answer': event.type === 'answer',
|
||||
'tree-child': isStreamingTimelineEvent(event),
|
||||
'tree-child-progress': event.type === 'child_task',
|
||||
|
|
@ -347,14 +380,15 @@
|
|||
<div v-if="event.type === 'thinking'" class="tool-event">
|
||||
<div class="action-card thinking-event-card"
|
||||
:class="{ 'action-pending': isThinkingActive(event.event_id) }">
|
||||
<div class="action-header" @click="toggleEvent(event.event_id)">
|
||||
<div class="action-header" @click="toggleThinking(event.event_id)">
|
||||
<div class="action-title" :class="{
|
||||
'thinking-inline-title': !event.title && isEventExpanded(event.event_id),
|
||||
}">
|
||||
<span class="action-title-icon icon-mask" :style="maskIconStyle(thinkingIcon)" aria-hidden="true" />
|
||||
<span v-if="event.title" class="action-name action-preamble-title">{{ event.title }}</span>
|
||||
<div v-else-if="event.content && isEventExpanded(event.event_id)"
|
||||
class="thinking-inline-content markdown-content">
|
||||
class="thinking-inline-content markdown-content"
|
||||
:class="{ 'thinking-live-window': isLiveThinking(event.event_id) }">
|
||||
<div class="thinking-inline-markdown" v-html="renderMarkdownContent(event.content)"></div>
|
||||
</div>
|
||||
<span v-else-if="getThinkingSummary(event) && !isEventExpanded(event.event_id)"
|
||||
|
|
@ -362,7 +396,8 @@
|
|||
</div>
|
||||
</div>
|
||||
<div v-if="event.title && event.content && isEventExpanded(event.event_id)" class="action-details">
|
||||
<div class="thinking-detail-content markdown-content">
|
||||
<div class="thinking-detail-content markdown-content"
|
||||
:class="{ 'thinking-live-window': isLiveThinking(event.event_id) }">
|
||||
<div v-html="renderMarkdownContent(event.content)"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -537,9 +572,21 @@
|
|||
<span v-if="getSandboxDiffStat(event)?.added" class="diff-add">+{{ getSandboxDiffStat(event)?.added }}</span>
|
||||
<span v-if="getSandboxDiffStat(event)?.removed" class="diff-del">-{{ getSandboxDiffStat(event)?.removed }}</span>
|
||||
</span>
|
||||
<button v-if="event.reasoning" type="button" class="action-reasoning-toggle"
|
||||
:class="{ 'is-open': isEventExpanded(event.reasoning.id) }"
|
||||
:title="t('agent.viewReasoning')" :aria-label="t('agent.viewReasoning')"
|
||||
:aria-expanded="isEventExpanded(event.reasoning.id)"
|
||||
@click.stop="toggleEvent(event.reasoning.id)" @keydown.enter.stop @keydown.space.stop>
|
||||
<span class="icon-mask" :style="maskIconStyle(thinkingIcon, 14)" aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="event.reasoning && isEventExpanded(event.reasoning.id)"
|
||||
class="action-reasoning thinking-detail-content markdown-content" @click.stop>
|
||||
<div v-html="renderMarkdownContent(event.reasoning.content)"></div>
|
||||
</div>
|
||||
|
||||
<div v-if="event.pending && getSandboxFilePreview(event)" class="sandbox-file-preview">
|
||||
<pre>{{ getSandboxFilePreview(event) }}</pre>
|
||||
<div v-if="sandboxPreviewRemaining(event) > 0" class="sandbox-file-preview-more">
|
||||
|
|
@ -695,6 +742,7 @@ import { isAssistantTurnComplete } from '@/utils/steerStreamFork';
|
|||
import { isAwaitingInput } from '@/composables/useChatStreamHandler';
|
||||
import { inject, ref, computed, watch, onMounted, onBeforeUnmount, onUpdated, nextTick } from 'vue';
|
||||
import { chatReadingHistoryKey, useDeferredTimelineCompletion } from '@/composables/useChatScrollFollow';
|
||||
import { useStreamingHeightFloor } from '@/composables/useStreamingHeightFloor';
|
||||
import { useRouter, useRoute } from 'vue-router';
|
||||
import { marked } from 'marked';
|
||||
import 'katex/dist/katex.min.css';
|
||||
|
|
@ -706,7 +754,7 @@ import { useChildAgentViewer } from '@/composables/useChildAgentViewer';
|
|||
import { defineAsyncComponent } from 'vue';
|
||||
const ChildAgentStream = defineAsyncComponent(() => import('./ChildAgentStream.vue'));
|
||||
import ProgressUpdates from './ProgressUpdates.vue';
|
||||
import { foldProgressIntoThinking, groupProgressUpdates } from '@/utils/agentTimelinePresentation';
|
||||
import { attachReasoningToTools, earlierStepKeys, foldProgressIntoThinking, groupProgressUpdates } from '@/utils/agentTimelinePresentation';
|
||||
import { isUnresolvedCollaborationPrompt, collaborationActivity, collaborationWaitState, collaborationTimeline, collaborationTasks, countToolCalls } from '@/utils/collaborationDisplay';
|
||||
import ToolApprovalCard from './ToolApprovalCard.vue';
|
||||
import McpOAuthCard from './McpOAuthCard.vue';
|
||||
|
|
@ -1576,6 +1624,26 @@ const isThinkingActive = (eventId: string): boolean => {
|
|||
|
||||
const deferredThinkingFolds = new Set<string>();
|
||||
|
||||
// Auto-expanded reasoning streams inside a short window: letting it grow to
|
||||
// full length and then folding it to one line makes the followed viewport
|
||||
// jump. Reasoning the user opened is shown in full and is not auto-folded.
|
||||
const userExpandedThinking = ref<Set<string>>(new Set());
|
||||
const isLiveThinking = (eventId: string): boolean => !userExpandedThinking.value.has(eventId);
|
||||
const toggleThinking = (eventId: string) => {
|
||||
if (expandedEvents.value.has(eventId) && !userExpandedThinking.value.has(eventId)) {
|
||||
userExpandedThinking.value.add(eventId);
|
||||
return;
|
||||
}
|
||||
toggleEvent(eventId);
|
||||
if (expandedEvents.value.has(eventId)) userExpandedThinking.value.add(eventId);
|
||||
else userExpandedThinking.value.delete(eventId);
|
||||
};
|
||||
const markOverflowingLiveThinking = () => {
|
||||
rootElement.value?.querySelectorAll<HTMLElement>('.thinking-live-window').forEach((el) => {
|
||||
el.classList.toggle('is-overflowing', el.scrollHeight > el.clientHeight + 1);
|
||||
});
|
||||
};
|
||||
|
||||
// Watch event stream to auto-expand thinking events and auto-collapse when non-thinking follows
|
||||
watch([eventStream, readingHistory], ([stream]) => {
|
||||
if (!stream || !Array.isArray(stream)) return;
|
||||
|
|
@ -1608,7 +1676,7 @@ watch([eventStream, readingHistory], ([stream]) => {
|
|||
}
|
||||
if (!readingHistory.value) {
|
||||
for (const id of deferredThinkingFolds) {
|
||||
if (!newActiveIds.has(id)) expandedEvents.value.delete(id);
|
||||
if (!newActiveIds.has(id) && !userExpandedThinking.value.has(id)) expandedEvents.value.delete(id);
|
||||
}
|
||||
deferredThinkingFolds.clear();
|
||||
}
|
||||
|
|
@ -1616,6 +1684,7 @@ watch([eventStream, readingHistory], ([stream]) => {
|
|||
activeThinkingVersion.value++;
|
||||
|
||||
nextTick(async () => {
|
||||
markOverflowingLiveThinking();
|
||||
await hydrateProtectedFileImages(rootElement.value, protectedFileAccess.value);
|
||||
await enhanceMarkdownContainer(rootElement.value);
|
||||
});
|
||||
|
|
@ -1662,6 +1731,7 @@ const collaborationWait = computed(() => collaborationWaitState(eventStream.valu
|
|||
const childActivity = computed(() => props.ragMode ? undefined : collaborationActivity(eventStream.value, props.session.collaborationStatus, isSegmentDone.value));
|
||||
|
||||
const streamingMermaidSvgCache = ref<string[]>([]);
|
||||
useStreamingHeightFloor(rootElement, computed(() => !isSegmentDone.value));
|
||||
let streamingMermaidRenderTask: Promise<void> | null = null;
|
||||
|
||||
const activeAnswerMarkdown = computed(() => {
|
||||
|
|
@ -1794,8 +1864,8 @@ const showStreamingTimeline = computed(() => {
|
|||
|
||||
const lastStreamingTimelineEventIndex = computed(() => {
|
||||
if (isConversationDone.value) return -1;
|
||||
for (let i = displayEvents.value.length - 1; i >= 0; i -= 1) {
|
||||
if (isStreamingTimelineEvent(displayEvents.value[i])) return i;
|
||||
for (let i = timelineEvents.value.length - 1; i >= 0; i -= 1) {
|
||||
if (isStreamingTimelineEvent(timelineEvents.value[i])) return i;
|
||||
}
|
||||
return -1;
|
||||
});
|
||||
|
|
@ -2139,7 +2209,11 @@ const intermediateEvents = computed(() => {
|
|||
// Keep reasoning in the same compact timeline as tool calls. The template
|
||||
// auto-expands the active reasoning event and folds it again once a tool or
|
||||
// answer follows, so tool activity remains the primary structure.
|
||||
const visibleIntermediateEvents = computed(() => intermediateEvents.value);
|
||||
const visibleIntermediateEvents = computed(() => attachReasoningToTools(intermediateEvents.value, canAttachReasoning));
|
||||
|
||||
// A thought still streaming or held open by the reader keeps its own row.
|
||||
const canAttachReasoning = (event: any): boolean =>
|
||||
event.thinking !== true && !isThinkingActive(event.event_id) && !isEventExpanded(event.event_id);
|
||||
|
||||
// Events to display (non-tree: before answer starts show all, after answer starts show only answer)
|
||||
const displayEvents = computed(() => {
|
||||
|
|
@ -2271,6 +2345,38 @@ const getEventKey = (event: any, index: number): string => {
|
|||
return `event-${index}-${event.type || 'unknown'}`;
|
||||
};
|
||||
|
||||
const timelineEvents = computed(() => attachReasoningToTools(displayEvents.value, canAttachReasoning));
|
||||
|
||||
// Long runs keep only their latest steps in view; anything still waiting on
|
||||
// the agent or the user stays out of the fold.
|
||||
const isStickyStep = (event: any): boolean =>
|
||||
event.pending === true ||
|
||||
event.type === 'child_task' ||
|
||||
isUnresolvedCollaborationPrompt(event) ||
|
||||
(event.type === 'thinking' && (event.thinking === true || isThinkingActive(event.event_id)));
|
||||
|
||||
const earlierStepTargets = computed(() => earlierStepKeys(
|
||||
timelineEvents.value.map((event: any, index: number) => ({
|
||||
key: getEventKey(event, index),
|
||||
step: isStreamingTimelineEvent(event),
|
||||
sticky: isStickyStep(event),
|
||||
})),
|
||||
));
|
||||
|
||||
const earlierStepsExpanded = ref(false);
|
||||
const foldedStepKeys = ref<Set<string>>(new Set());
|
||||
// Folding more rows under a reader would pull the text they are reading upward.
|
||||
watch([earlierStepTargets, readingHistory], ([targets, reading]) => {
|
||||
if (!reading && !earlierStepsExpanded.value) foldedStepKeys.value = new Set(targets);
|
||||
}, { immediate: true });
|
||||
watch(earlierStepsExpanded, (expanded) => {
|
||||
foldedStepKeys.value = expanded ? new Set() : new Set(earlierStepTargets.value);
|
||||
});
|
||||
|
||||
const earlierStepsCount = computed(() =>
|
||||
earlierStepsExpanded.value ? earlierStepTargets.value.length : foldedStepKeys.value.size,
|
||||
);
|
||||
|
||||
const toggleIntermediateSteps = () => {
|
||||
showIntermediateSteps.value = !showIntermediateSteps.value;
|
||||
nextTick(async () => {
|
||||
|
|
@ -3743,6 +3849,44 @@ const handleAddToKnowledge = (answerEvent: any) => {
|
|||
}
|
||||
}
|
||||
|
||||
.action-reasoning-toggle {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
margin-left: -6px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: var(--app-radius-sm);
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
opacity: 0.6;
|
||||
transition: opacity var(--app-motion-fast) ease, background-color var(--app-motion-fast) ease;
|
||||
|
||||
&:hover,
|
||||
&:focus-visible,
|
||||
&.is-open {
|
||||
opacity: 1;
|
||||
background: var(--td-bg-color-container-hover);
|
||||
}
|
||||
}
|
||||
|
||||
.action-reasoning {
|
||||
padding-top: 2px;
|
||||
user-select: text;
|
||||
cursor: text;
|
||||
}
|
||||
|
||||
.earlier-steps-node .action-header {
|
||||
cursor: pointer;
|
||||
|
||||
&:hover .action-name {
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.sandbox-file-preview {
|
||||
margin: 6px 0 0;
|
||||
padding: 8px 10px;
|
||||
|
|
@ -4046,6 +4190,21 @@ const handleAddToKnowledge = (answerEvent: any) => {
|
|||
}
|
||||
}
|
||||
|
||||
// Bottom-aligned so the newest reasoning stays visible as older lines clip.
|
||||
.thinking-inline-content.thinking-live-window,
|
||||
.thinking-detail-content.thinking-live-window {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: flex-end;
|
||||
max-height: calc(1.6em * 5);
|
||||
overflow: hidden;
|
||||
|
||||
&.is-overflowing {
|
||||
mask-image: linear-gradient(to bottom, transparent, #000 1.6em);
|
||||
-webkit-mask-image: linear-gradient(to bottom, transparent, #000 1.6em);
|
||||
}
|
||||
}
|
||||
|
||||
.search-results-summary-fixed,
|
||||
.plan-status-summary-fixed {
|
||||
padding: 2px 0 0 0;
|
||||
|
|
|
|||
Loading…
Reference in New Issue