fix: consolidate successive error retry messages in chat UI (#7880)
When API requests fail and auto-retry is enabled, multiple error_retry messages were shown (e.g., "Attempt 1 of 3", "Attempt 2 of 3", etc.). This change consolidates them to only show the latest retry message, reducing visual clutter during retry sequences.
This commit is contained in:
1 parent
a5f6c1d732
commit
c9f23076c2
2 files changed
+48
-1
No files matched your search
@@ -0,0 +1,46 @@
|
||||
import { ClineMessage } from "./ExtensionMessage"
|
||||
|
||||
/**
|
||||
* Consolidates error_retry messages in a retry sequence, keeping only the latest one.
|
||||
*
|
||||
* When an API request fails and auto-retry is enabled, multiple error_retry messages are created
|
||||
* (e.g., "Attempt 1 of 3", "Attempt 2 of 3", "Attempt 3 of 3"), interleaved with api_req_retried
|
||||
* messages. This function filters out earlier retry messages, showing only the most recent one.
|
||||
*
|
||||
* @param messages - An array of ClineMessage objects to process.
|
||||
* @returns A new array of ClineMessage objects with error_retry sequences consolidated.
|
||||
*
|
||||
* @example
|
||||
* const messages: ClineMessage[] = [
|
||||
* { type: 'say', say: 'error_retry', text: '{"attempt":1,"maxAttempts":3}', ts: 1000 },
|
||||
* { type: 'say', say: 'api_req_retried', ts: 1001 },
|
||||
* { type: 'say', say: 'error_retry', text: '{"attempt":2,"maxAttempts":3}', ts: 1002 },
|
||||
* { type: 'say', say: 'api_req_retried', ts: 1003 },
|
||||
* { type: 'say', say: 'error_retry', text: '{"attempt":3,"maxAttempts":3}', ts: 1004 },
|
||||
* ];
|
||||
* const result = combineErrorRetryMessages(messages);
|
||||
* // Result: [{ type: 'say', say: 'error_retry', text: '{"attempt":3,"maxAttempts":3}', ts: 1004 }]
|
||||
*/
|
||||
export function combineErrorRetryMessages(messages: ClineMessage[]): ClineMessage[] {
|
||||
const result: ClineMessage[] = []
|
||||
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
const message = messages[i]
|
||||
|
||||
if (message.say === "error_retry") {
|
||||
// Look ahead to see if the next non-api_req_retried message is also an error_retry
|
||||
let nextMessage = messages[i + 1]
|
||||
if (nextMessage?.say === "api_req_retried") {
|
||||
nextMessage = messages[i + 2]
|
||||
}
|
||||
if (nextMessage?.say === "error_retry") {
|
||||
// Skip this message, we'll show the next one (or a later one in the sequence)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
result.push(message)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { findLast } from "@shared/array"
|
||||
import { combineApiRequests } from "@shared/combineApiRequests"
|
||||
import { combineCommandSequences } from "@shared/combineCommandSequences"
|
||||
import { combineErrorRetryMessages } from "@shared/combineErrorRetryMessages"
|
||||
import { combineHookSequences } from "@shared/combineHookSequences"
|
||||
import type { ClineApiReqInfo, ClineMessage } from "@shared/ExtensionMessage"
|
||||
import { getApiMetrics } from "@shared/getApiMetrics"
|
||||
@@ -64,7 +65,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
|
||||
// Only combine hook sequences if hooks are enabled (both user setting and feature flag)
|
||||
const areHooksEnabled = hooksEnabled?.user
|
||||
const withHooks = areHooksEnabled ? combineHookSequences(slicedMessages) : slicedMessages
|
||||
return combineApiRequests(combineCommandSequences(withHooks))
|
||||
return combineErrorRetryMessages(combineApiRequests(combineCommandSequences(withHooks)))
|
||||
}, [messages, hooksEnabled])
|
||||
// has to be after api_req_finished are all reduced into api_req_started messages
|
||||
const apiMetrics = useMemo(() => getApiMetrics(modifiedMessages), [modifiedMessages])
|
||||
|
||||
Reference in new issue
Block a user