fix: hide assistant timeline entries without text

This commit is contained in:
Shantur Rathore
2025-12-08 10:34:00 +00:00
parent dc702b1fb2
commit 710938eef8

View File

@@ -43,7 +43,9 @@ type ToolCallPart = Extract<ClientPart, { type: "tool" }>
interface PendingSegment { interface PendingSegment {
type: TimelineSegmentType type: TimelineSegmentType
texts: string[] texts: string[]
reasoningTexts: string[]
toolTitles: string[] toolTitles: string[]
hasPrimaryText: boolean
} }
function truncateText(value: string): string { function truncateText(value: string): string {
@@ -143,14 +145,17 @@ export function buildTimelineSegments(instanceId: string, record: MessageRecord)
const result: TimelineSegment[] = [] const result: TimelineSegment[] = []
let segmentIndex = 0 let segmentIndex = 0
let pending: PendingSegment | null = null let pending: PendingSegment | null = null
const flushPending = () => { const flushPending = () => {
if (!pending) return if (!pending) return
if (pending.type === "assistant" && !pending.hasPrimaryText) {
pending = null
return
}
const label = SEGMENT_LABELS[pending.type] const label = SEGMENT_LABELS[pending.type]
const tooltip = pending.type === "tool" const tooltip = pending.type === "tool"
? formatToolTooltip(pending.toolTitles) ? formatToolTooltip(pending.toolTitles)
: formatTextsTooltip( : formatTextsTooltip(
pending.texts, [...pending.texts, ...pending.reasoningTexts],
pending.type === "user" ? "User message" : "Assistant response", pending.type === "user" ? "User message" : "Assistant response",
) )
@@ -168,11 +173,12 @@ export function buildTimelineSegments(instanceId: string, record: MessageRecord)
const ensureSegment = (type: TimelineSegmentType) => { const ensureSegment = (type: TimelineSegmentType) => {
if (!pending || pending.type !== type) { if (!pending || pending.type !== type) {
flushPending() flushPending()
pending = { type, texts: [], toolTitles: [] } pending = { type, texts: [], reasoningTexts: [], toolTitles: [], hasPrimaryText: type !== "assistant" }
} }
return pending return pending
} }
const defaultContentType: TimelineSegmentType = record.role === "user" ? "user" : "assistant" const defaultContentType: TimelineSegmentType = record.role === "user" ? "user" : "assistant"
for (const part of orderedParts) { for (const part of orderedParts) {
@@ -188,7 +194,9 @@ export function buildTimelineSegments(instanceId: string, record: MessageRecord)
const text = collectReasoningText(part) const text = collectReasoningText(part)
if (text.trim().length === 0) continue if (text.trim().length === 0) continue
const target = ensureSegment(defaultContentType) const target = ensureSegment(defaultContentType)
target.texts.push(text) if (target) {
target.reasoningTexts.push(text)
}
continue continue
} }
@@ -199,10 +207,15 @@ export function buildTimelineSegments(instanceId: string, record: MessageRecord)
const text = collectTextFromPart(part) const text = collectTextFromPart(part)
if (text.trim().length === 0) continue if (text.trim().length === 0) continue
const target = ensureSegment(defaultContentType) const target = ensureSegment(defaultContentType)
target.texts.push(text) if (target) {
target.texts.push(text)
target.hasPrimaryText = true
}
} }
flushPending() flushPending()
return result return result
} }