From 443c08bb83fca5339e007901cb8feb9f7f23f280 Mon Sep 17 00:00:00 2001 From: Nate Date: Sat, 19 Jul 2025 21:47:56 -0700 Subject: [PATCH] timer --- src/ui/TUIChat.tsx | 10 +++++++--- src/ui/Timer.tsx | 25 +++++++++++++++++++++++++ src/ui/hooks/useChat.ts | 4 ++++ 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 src/ui/Timer.tsx diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index ea84a3734..c82f63c97 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -13,6 +13,7 @@ import { useMessageRenderer } from "./hooks/useMessageRenderer.js"; import { useOrganizationSelector } from "./hooks/useOrganizationSelector.js"; import LoadingAnimation from "./LoadingAnimation.js"; import OrganizationSelector from "./OrganizationSelector.js"; +import Timer from "./Timer.js"; import UserInput from "./UserInput.js"; interface TUIChatProps { @@ -100,6 +101,7 @@ const TUIChat: React.FC = ({ messages, setMessages, isWaitingForResponse, + responseStartTime, inputMode, handleUserMessage, handleInterrupt, @@ -168,10 +170,12 @@ const TUIChat: React.FC = ({ {/* Fixed bottom section */} {/* Status */} - {isWaitingForResponse && ( + {isWaitingForResponse && responseStartTime && ( - esc to interrupt + ( + + • esc to interrupt ) )} @@ -234,4 +238,4 @@ const TUIChat: React.FC = ({ ); }; -export default TUIChat; \ No newline at end of file +export default TUIChat; diff --git a/src/ui/Timer.tsx b/src/ui/Timer.tsx new file mode 100644 index 000000000..33f540cea --- /dev/null +++ b/src/ui/Timer.tsx @@ -0,0 +1,25 @@ +import { Text } from "ink"; +import React, { useEffect, useState } from "react"; + +interface TimerProps { + startTime: number; + color?: string; +} + +const Timer: React.FC = ({ startTime, color = "gray" }) => { + const [elapsed, setElapsed] = useState(0); + + useEffect(() => { + const interval = setInterval(() => { + const now = Date.now(); + const elapsedSeconds = Math.floor((now - startTime) / 1000); + setElapsed(elapsedSeconds); + }, 100); // Update every 100ms for smooth display + + return () => clearInterval(interval); + }, [startTime]); + + return {elapsed}s; +}; + +export default Timer; \ No newline at end of file diff --git a/src/ui/hooks/useChat.ts b/src/ui/hooks/useChat.ts index 03700dec5..9909a6fd1 100644 --- a/src/ui/hooks/useChat.ts +++ b/src/ui/hooks/useChat.ts @@ -83,6 +83,7 @@ export function useChat({ }); const [isWaitingForResponse, setIsWaitingForResponse] = useState(false); + const [responseStartTime, setResponseStartTime] = useState(null); const [inputMode, setInputMode] = useState(true); const [abortController, setAbortController] = useState(null); @@ -185,6 +186,7 @@ export function useChat({ const controller = new AbortController(); setAbortController(controller); setIsWaitingForResponse(true); + setResponseStartTime(Date.now()); setInputMode(false); logger.debug('Starting chat response stream', { messageLength: message.length, historyLength: newHistory.length }); @@ -331,6 +333,7 @@ export function useChat({ } finally { setAbortController(null); setIsWaitingForResponse(false); + setResponseStartTime(null); setInputMode(true); } }; @@ -369,6 +372,7 @@ export function useChat({ chatHistory, setChatHistory, isWaitingForResponse, + responseStartTime, inputMode, attachedFiles, handleUserMessage,