From 02785b962cd5d07467aea49e4a3f1b88ce1b40c8 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Tue, 30 Dec 2025 16:01:51 +0000 Subject: [PATCH] refactor: use dedicated api_req_rate_limited message type instead of string matching --- packages/evals/src/cli/runTask.ts | 1 + packages/types/src/message.ts | 2 ++ src/core/task/Task.ts | 5 ++--- webview-ui/src/components/chat/ChatRow.tsx | 12 ++++-------- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/evals/src/cli/runTask.ts b/packages/evals/src/cli/runTask.ts index a6ae6c0305..587e89b211 100644 --- a/packages/evals/src/cli/runTask.ts +++ b/packages/evals/src/cli/runTask.ts @@ -302,6 +302,7 @@ export const runTask = async ({ run, task, publish, logger, jobToken }: RunTaskO "condense_context", "condense_context_error", "api_req_retry_delayed", + "api_req_rate_limited", "api_req_retried", ] diff --git a/packages/types/src/message.ts b/packages/types/src/message.ts index 82f58f29f2..a78117fcf2 100644 --- a/packages/types/src/message.ts +++ b/packages/types/src/message.ts @@ -129,6 +129,7 @@ export function isNonBlockingAsk(ask: ClineAsk): ask is NonBlockingAsk { * - `api_req_finished`: Indicates an API request has completed successfully * - `api_req_retried`: Indicates an API request is being retried after a failure * - `api_req_retry_delayed`: Indicates an API request retry has been delayed + * - `api_req_rate_limited`: Indicates user-configured rate limiting countdown (not an error) * - `api_req_deleted`: Indicates an API request has been deleted/cancelled * - `text`: General text message or assistant response * - `reasoning`: Assistant's reasoning or thought process (often hidden from user) @@ -155,6 +156,7 @@ export const clineSays = [ "api_req_finished", "api_req_retried", "api_req_retry_delayed", + "api_req_rate_limited", "api_req_deleted", "text", "image", diff --git a/src/core/task/Task.ts b/src/core/task/Task.ts index a588d7db1b..2acc8df1e1 100644 --- a/src/core/task/Task.ts +++ b/src/core/task/Task.ts @@ -3706,10 +3706,9 @@ export class Task extends EventEmitter implements TaskLike { // Only show rate limiting message if we're not retrying. If retrying, we'll include the delay there. if (rateLimitDelay > 0 && retryAttempt === 0) { - // Show countdown timer + // Show countdown timer using dedicated rate limit message type for (let i = rateLimitDelay; i > 0; i--) { - const delayMessage = `Rate limiting for ${i} seconds...` - await this.say("api_req_retry_delayed", delayMessage, undefined, true) + await this.say("api_req_rate_limited", String(i), undefined, true) await delay(1000) } } diff --git a/webview-ui/src/components/chat/ChatRow.tsx b/webview-ui/src/components/chat/ChatRow.tsx index 6ac9288923..26cad34d73 100644 --- a/webview-ui/src/components/chat/ChatRow.tsx +++ b/webview-ui/src/components/chat/ChatRow.tsx @@ -1087,15 +1087,11 @@ export const ChatRowContent = ({ )} ) + case "api_req_rate_limited": + // User-configured rate limiting countdown (not an API error) + const rateLimitSeconds = parseInt(message.text || "0", 10) + return case "api_req_retry_delayed": - // Check if this is user-configured rate limiting (not an API error) - if (message.text?.startsWith("Rate limiting for")) { - // Extract countdown from message text: "Rate limiting for X seconds..." - const rateLimitMatch = message.text.match(/Rate limiting for (\d+) seconds/) - const countdown = rateLimitMatch ? parseInt(rateLimitMatch[1], 10) : 0 - return - } - let body = t(`chat:apiRequest.failed`) let retryInfo, rawError, code, docsURL if (message.text !== undefined) {