Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ’„ style(chat): roll turn durations up to hours past the hour mark (#19742)

Arvin Xuaef2a58e3ad3
diff --git a/src/features/Conversation/Messages/AssistantGroup/constants.ts b/src/features/Conversation/Messages/AssistantGroup/constants.ts
index fa018b2c48a..6ef2a3daf51 100644
--- a/src/features/Conversation/Messages/AssistantGroup/constants.ts
+++ b/src/features/Conversation/Messages/AssistantGroup/constants.ts
@@ -68,6 +68,9 @@ export const DURATION_SECONDS_PER_MINUTE = 60;
/** Duration inputs are in milliseconds; convert to whole seconds for display. */
export const TIME_MS_PER_SECOND = 1000;
+/** Minutes per hour; long turns roll up to "4h 11m" instead of "251m 49s". */
+export const DURATION_MINUTES_PER_HOUR = 60;
+
// ─── apiName β†’ i18n key for human-readable label (workflow summary & headlines) ─
/** Translation keys for built-in / known tool api names. Unknown api names use title-cased fallback. */
diff --git a/src/features/Conversation/Messages/AssistantGroup/toolDisplayNames.test.ts b/src/features/Conversation/Messages/AssistantGroup/toolDisplayNames.test.ts
index 01eadba4658..c9f2c1621d1 100644
--- a/src/features/Conversation/Messages/AssistantGroup/toolDisplayNames.test.ts
+++ b/src/features/Conversation/Messages/AssistantGroup/toolDisplayNames.test.ts
@@ -3,6 +3,7 @@ import { describe, expect, it } from 'vitest';
import type { AssistantContentBlock } from '@/types/index';
import {
+ formatReasoningDuration,
getToolDisplayName,
getWorkflowStreamingHeadlineState,
getWorkflowSummaryText,
@@ -239,3 +240,22 @@ describe('reasoning headline extraction', () => {
});
});
});
+
+describe('formatReasoningDuration', () => {
+ it('formats sub-minute durations in seconds', () => {
+ expect(formatReasoningDuration(49_000)).toBe('49s');
+ });
+
+ it('formats sub-hour durations in minutes and seconds', () => {
+ expect(formatReasoningDuration(217_000)).toBe('3m 37s');
+ expect(formatReasoningDuration(180_000)).toBe('3m');
+ });
+
+ it('rolls minutes up to hours past the hour mark', () => {
+ // The row used to read "251m 49s" for this turn.
+ expect(formatReasoningDuration(15_109_000)).toBe('4h 11m');
+ expect(formatReasoningDuration(3_600_000)).toBe('1h');
+ expect(formatReasoningDuration(3_660_000)).toBe('1h 1m');
+ expect(formatReasoningDuration(3_599_000)).toBe('59m 59s');
+ });
+});
diff --git a/src/features/Conversation/Messages/AssistantGroup/toolDisplayNames.ts b/src/features/Conversation/Messages/AssistantGroup/toolDisplayNames.ts
index 772b06d3389..ca54426893a 100644
--- a/src/features/Conversation/Messages/AssistantGroup/toolDisplayNames.ts
+++ b/src/features/Conversation/Messages/AssistantGroup/toolDisplayNames.ts
@@ -9,6 +9,7 @@ import { LOADING_FLAT } from '@/const/message';
import type { AssistantContentBlock } from '@/types/index';
import {
+ DURATION_MINUTES_PER_HOUR,
DURATION_SECONDS_PER_MINUTE,
TIME_MS_PER_SECOND,
TOOL_API_DISPLAY_NAMES,
@@ -324,12 +325,23 @@ export const getWorkflowStreamingHeadlineState = (
return { kind: 'idle' };
};
+/**
+ * Hour-scale turns roll up to "4h 11m": seconds are noise next to hours, and a
+ * bare "251m 49s" makes the reader do the division themselves.
+ */
export const formatReasoningDuration = (ms: number): string => {
const totalSeconds = Math.round(ms / TIME_MS_PER_SECOND);
if (totalSeconds < DURATION_SECONDS_PER_MINUTE) return `${totalSeconds}s`;
- const minutes = Math.floor(totalSeconds / DURATION_SECONDS_PER_MINUTE);
+
+ const totalMinutes = Math.floor(totalSeconds / DURATION_SECONDS_PER_MINUTE);
const seconds = totalSeconds % DURATION_SECONDS_PER_MINUTE;
- return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`;
+
+ if (totalMinutes < DURATION_MINUTES_PER_HOUR)
+ return seconds > 0 ? `${totalMinutes}m ${seconds}s` : `${totalMinutes}m`;
+
+ const hours = Math.floor(totalMinutes / DURATION_MINUTES_PER_HOUR);
+ const minutes = totalMinutes % DURATION_MINUTES_PER_HOUR;
+ return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`;
};
/**