@@ -41,6 +41,11 @@ interface CopyButtonProps {
4141 textToCopy : string | undefined
4242}
4343
44+ const normalColor = "var(--vscode-foreground)"
45+ const errorColor = "var(--vscode-errorForeground)"
46+ const successColor = "var(--vscode-charts-green)"
47+ const cancelledColor = "var(--vscode-descriptionForeground)"
48+
4449const CopyButtonStyled = styled ( VSCodeButton ) `
4550 position: absolute;
4651 bottom: 2px;
@@ -153,6 +158,40 @@ const Markdown = memo(({ markdown }: { markdown?: string }) => {
153158 )
154159} )
155160
161+ const RetryMessage = ( { seconds, attempt, retryOperations } : { retryOperations : number ; attempt : number ; seconds ?: number } ) => {
162+ const [ remainingSeconds , setRemainingSeconds ] = useState ( seconds || 0 )
163+
164+ useEffect ( ( ) => {
165+ if ( seconds && seconds > 0 ) {
166+ setRemainingSeconds ( seconds )
167+
168+ const interval = setInterval ( ( ) => {
169+ setRemainingSeconds ( ( prev ) => {
170+ if ( prev <= 1 ) {
171+ clearInterval ( interval )
172+ return 0
173+ }
174+ return prev - 1
175+ } )
176+ } , 1000 )
177+
178+ return ( ) => clearInterval ( interval )
179+ }
180+ } , [ seconds ] )
181+
182+ return (
183+ < span
184+ style = { {
185+ color : normalColor ,
186+ fontWeight : "bold" ,
187+ } } >
188+ { `API Request (Retrying failed attempt ${ attempt } /${ retryOperations } ` }
189+ { remainingSeconds > 0 && ` in ${ remainingSeconds } seconds` }
190+ )...
191+ </ span >
192+ )
193+ }
194+
156195const ChatRow = memo (
157196 ( props : ChatRowProps ) => {
158197 const { isLast, onHeightChange, message, lastModifiedMessage, inputValue } = props
@@ -230,11 +269,6 @@ export const ChatRowContent = ({
230269
231270 const type = message . type === "ask" ? message . ask : message . say
232271
233- const normalColor = "var(--vscode-foreground)"
234- const errorColor = "var(--vscode-errorForeground)"
235- const successColor = "var(--vscode-charts-green)"
236- const cancelledColor = "var(--vscode-descriptionForeground)"
237-
238272 const handleMessage = useCallback ( ( event : MessageEvent ) => {
239273 const message : ExtensionMessage = event . data
240274 switch ( message . type ) {
@@ -448,11 +482,11 @@ export const ChatRowContent = ({
448482 if ( retryStatus && cost == null && ! apiReqCancelReason ) {
449483 const retryOperations = retryStatus . maxAttempts > 0 ? retryStatus . maxAttempts - 1 : 0
450484 return (
451- < span
452- style = { {
453- color : normalColor ,
454- fontWeight : "bold" ,
455- } } > { `API Request (Retrying failed attempt ${ retryStatus . attempt } / ${ retryOperations } )...` } </ span >
485+ < RetryMessage
486+ seconds = { retryStatus . delaySec }
487+ attempt = { retryStatus . attempt }
488+ retryOperations = { retryOperations }
489+ / >
456490 )
457491 }
458492
0 commit comments