timer
This commit is contained in:
parent
0a4acdacb3
commit
443c08bb83
3 changed files with 36 additions and 3 deletions
|
|
@ -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<TUIChatProps> = ({
|
|||
messages,
|
||||
setMessages,
|
||||
isWaitingForResponse,
|
||||
responseStartTime,
|
||||
inputMode,
|
||||
handleUserMessage,
|
||||
handleInterrupt,
|
||||
|
|
@ -168,10 +170,12 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
{/* Fixed bottom section */}
|
||||
<Box flexDirection="column" flexShrink={0}>
|
||||
{/* Status */}
|
||||
{isWaitingForResponse && (
|
||||
{isWaitingForResponse && responseStartTime && (
|
||||
<Box paddingX={1} flexDirection="row" gap={1}>
|
||||
<LoadingAnimation visible={isWaitingForResponse} />
|
||||
<Text color="gray">esc to interrupt</Text>
|
||||
<Text color="gray">(</Text>
|
||||
<Timer startTime={responseStartTime} />
|
||||
<Text color="gray"> • esc to interrupt )</Text>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
|
|
@ -234,4 +238,4 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
);
|
||||
};
|
||||
|
||||
export default TUIChat;
|
||||
export default TUIChat;
|
||||
|
|
|
|||
25
src/ui/Timer.tsx
Normal file
25
src/ui/Timer.tsx
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { Text } from "ink";
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
interface TimerProps {
|
||||
startTime: number;
|
||||
color?: string;
|
||||
}
|
||||
|
||||
const Timer: React.FC<TimerProps> = ({ 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 <Text color={color}>{elapsed}s</Text>;
|
||||
};
|
||||
|
||||
export default Timer;
|
||||
|
|
@ -83,6 +83,7 @@ export function useChat({
|
|||
});
|
||||
|
||||
const [isWaitingForResponse, setIsWaitingForResponse] = useState(false);
|
||||
const [responseStartTime, setResponseStartTime] = useState<number | null>(null);
|
||||
const [inputMode, setInputMode] = useState(true);
|
||||
const [abortController, setAbortController] =
|
||||
useState<AbortController | null>(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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue