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: format tool execution time as Xmin Ys instead of X.Y min (#14641)

Arvin Xub85a1ad851be
diff --git a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/ExecutionTime.test.tsx b/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/ExecutionTime.test.tsx
index d5f40d8a851..35ff2e891a1 100644
--- a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/ExecutionTime.test.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/ExecutionTime.test.tsx
@@ -86,6 +86,29 @@ describe('ExecutionTime', () => {
expect(screen.getByText('0ms')).toBeTruthy();
});
+ it('formats elapsed times longer than a minute as Xmin Ys', () => {
+ vi.useFakeTimers();
+ vi.setSystemTime(10_000);
+
+ const { rerender } = render(
+ <ExecutionTime isExecuting startTime={10_000} timerKey="tool-minutes" />,
+ );
+
+ act(() => {
+ vi.advanceTimersByTime(83_000);
+ });
+
+ expect(screen.getByText('1min23s')).toBeTruthy();
+
+ rerender(<ExecutionTime isExecuting startTime={10_000} timerKey="tool-minutes" />);
+
+ act(() => {
+ vi.advanceTimersByTime(60_000);
+ });
+
+ expect(screen.getByText('2min23s')).toBeTruthy();
+ });
+
it('clears the cached start time when execution stops', () => {
vi.useFakeTimers();
vi.setSystemTime(10_000);
diff --git a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/ExecutionTime.tsx b/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/ExecutionTime.tsx
index f356a573e72..ed2ddf66327 100644
--- a/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/ExecutionTime.tsx
+++ b/src/features/Conversation/Messages/AssistantGroup/Tool/Inspector/ExecutionTime.tsx
@@ -37,8 +37,10 @@ const formatElapsedTime = (ms: number): string => {
const seconds = ms / 1000;
if (seconds < 60) return `${seconds.toFixed(1)}s`;
- const minutes = seconds / 60;
- return `${minutes.toFixed(1)}min`;
+ const totalSeconds = Math.floor(seconds);
+ const minutes = Math.floor(totalSeconds / 60);
+ const remainingSeconds = totalSeconds % 60;
+ return `${minutes}min${remainingSeconds}s`;
};
const ExecutionTime = memo<ExecutionTimeProps>(({ isExecuting, startTime, timerKey }) => {