fix: hide assistant timeline entries without text
This commit is contained in:
@@ -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,17 +145,20 @@ 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",
|
||||||
)
|
)
|
||||||
|
|
||||||
result.push({
|
result.push({
|
||||||
id: `${record.id}:${segmentIndex}`,
|
id: `${record.id}:${segmentIndex}`,
|
||||||
messageId: record.id,
|
messageId: record.id,
|
||||||
@@ -164,15 +169,16 @@ export function buildTimelineSegments(instanceId: string, record: MessageRecord)
|
|||||||
segmentIndex += 1
|
segmentIndex += 1
|
||||||
pending = null
|
pending = null
|
||||||
}
|
}
|
||||||
|
|
||||||
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,21 +194,28 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
if (part.type === "step-start" || part.type === "step-finish") {
|
if (part.type === "step-start" || part.type === "step-finish") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user