From 81a9c289711b893058bc04f95314f3342779b8e2 Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Mon, 8 Dec 2025 13:40:42 +0000 Subject: [PATCH] use tool prefixes in timeline --- .../ui/src/components/message-timeline.tsx | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/ui/src/components/message-timeline.tsx b/packages/ui/src/components/message-timeline.tsx index 5957a24c..f1f70e5b 100644 --- a/packages/ui/src/components/message-timeline.tsx +++ b/packages/ui/src/components/message-timeline.tsx @@ -45,6 +45,7 @@ interface PendingSegment { texts: string[] reasoningTexts: string[] toolTitles: string[] + toolTypeLabels: string[] hasPrimaryText: boolean } @@ -117,6 +118,13 @@ function getToolTitle(part: ToolCallPart): string { return TOOL_FALLBACK_LABEL } +function getToolTypeLabel(part: ToolCallPart): string { + if (typeof part.tool === "string" && part.tool.trim().length > 0) { + return part.tool.trim().slice(0, 4) + } + return TOOL_FALLBACK_LABEL.slice(0, 4) +} + function formatTextsTooltip(texts: string[], fallback: string): string { const combined = texts .map((text) => text.trim()) @@ -151,7 +159,9 @@ export function buildTimelineSegments(instanceId: string, record: MessageRecord) pending = null return } - const label = pending.type === "tool" ? (pending.toolTitles[0] || SEGMENT_LABELS[pending.type]) : SEGMENT_LABELS[pending.type] + const label = pending.type === "tool" + ? pending.toolTypeLabels[0] || TOOL_FALLBACK_LABEL.slice(0, 4) + : SEGMENT_LABELS[pending.type] const tooltip = pending.type === "tool" ? formatToolTooltip(pending.toolTitles) : formatTextsTooltip( @@ -170,12 +180,12 @@ export function buildTimelineSegments(instanceId: string, record: MessageRecord) pending = null } - const ensureSegment = (type: TimelineSegmentType) => { + const ensureSegment = (type: TimelineSegmentType): PendingSegment => { if (!pending || pending.type !== type) { flushPending() - pending = { type, texts: [], reasoningTexts: [], toolTitles: [], hasPrimaryText: type !== "assistant" } + pending = { type, texts: [], reasoningTexts: [], toolTitles: [], toolTypeLabels: [], hasPrimaryText: type !== "assistant" } } - return pending + return pending! } @@ -186,7 +196,9 @@ export function buildTimelineSegments(instanceId: string, record: MessageRecord) if (part.type === "tool") { const target = ensureSegment("tool") - target.toolTitles.push(getToolTitle(part as ToolCallPart)) + const toolPart = part as ToolCallPart + target.toolTitles.push(getToolTitle(toolPart)) + target.toolTypeLabels.push(getToolTypeLabel(toolPart)) continue }