mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 04:11:10 -05:00
Merge main
This commit is contained in:
@@ -793,7 +793,7 @@ export class Cline {
|
||||
}
|
||||
}
|
||||
|
||||
async *attemptApiRequest(previousApiReqIndex: number): ApiStream {
|
||||
async *attemptApiRequest(previousApiReqIndex: number, retryAttempt: number = 0): ApiStream {
|
||||
let mcpHub: McpHub | undefined
|
||||
|
||||
const { mcpEnabled, alwaysApproveResubmit, requestDelaySeconds } =
|
||||
@@ -887,21 +887,29 @@ export class Cline {
|
||||
// note that this api_req_failed ask is unique in that we only present this option if the api hasn't streamed any content yet (ie it fails on the first chunk due), as it would allow them to hit a retry button. However if the api failed mid-stream, it could be in any arbitrary state where some tools may have executed, so that error is handled differently and requires cancelling the task entirely.
|
||||
if (alwaysApproveResubmit) {
|
||||
const errorMsg = error.message ?? "Unknown error"
|
||||
const requestDelay = requestDelaySeconds || 5
|
||||
// Automatically retry with delay
|
||||
// Show countdown timer in error color
|
||||
for (let i = requestDelay; i > 0; i--) {
|
||||
const baseDelay = requestDelaySeconds || 5
|
||||
const exponentialDelay = Math.ceil(baseDelay * Math.pow(2, retryAttempt))
|
||||
|
||||
// Show countdown timer with exponential backoff
|
||||
for (let i = exponentialDelay; i > 0; i--) {
|
||||
await this.say(
|
||||
"api_req_retry_delayed",
|
||||
`${errorMsg}\n\nRetrying in ${i} seconds...`,
|
||||
`${errorMsg}\n\nRetry attempt ${retryAttempt + 1}\nRetrying in ${i} seconds...`,
|
||||
undefined,
|
||||
true,
|
||||
)
|
||||
await delay(1000)
|
||||
}
|
||||
await this.say("api_req_retry_delayed", `${errorMsg}\n\nRetrying now...`, undefined, false)
|
||||
// delegate generator output from the recursive call
|
||||
yield* this.attemptApiRequest(previousApiReqIndex)
|
||||
|
||||
await this.say(
|
||||
"api_req_retry_delayed",
|
||||
`${errorMsg}\n\nRetry attempt ${retryAttempt + 1}\nRetrying now...`,
|
||||
undefined,
|
||||
false,
|
||||
)
|
||||
|
||||
// delegate generator output from the recursive call with incremented retry count
|
||||
yield* this.attemptApiRequest(previousApiReqIndex, retryAttempt + 1)
|
||||
return
|
||||
} else {
|
||||
const { response } = await this.ask(
|
||||
@@ -1085,35 +1093,23 @@ export class Cline {
|
||||
const askApproval = async (type: ClineAsk, partialMessage?: string) => {
|
||||
const { response, text, images } = await this.ask(type, partialMessage, false)
|
||||
if (response !== "yesButtonClicked") {
|
||||
if (response === "messageResponse") {
|
||||
// Handle both messageResponse and noButtonClicked with text
|
||||
if (text) {
|
||||
await this.say("user_feedback", text, images)
|
||||
pushToolResult(
|
||||
formatResponse.toolResult(formatResponse.toolDeniedWithFeedback(text), images),
|
||||
)
|
||||
// this.userMessageContent.push({
|
||||
// type: "text",
|
||||
// text: `${toolDescription()}`,
|
||||
// })
|
||||
// this.toolResults.push({
|
||||
// type: "tool_result",
|
||||
// tool_use_id: toolUseId,
|
||||
// content: this.formatToolResponseWithImages(
|
||||
// await this.formatToolDeniedFeedback(text),
|
||||
// images
|
||||
// ),
|
||||
// })
|
||||
this.didRejectTool = true
|
||||
return false
|
||||
} else {
|
||||
pushToolResult(formatResponse.toolDenied())
|
||||
}
|
||||
pushToolResult(formatResponse.toolDenied())
|
||||
// this.toolResults.push({
|
||||
// type: "tool_result",
|
||||
// tool_use_id: toolUseId,
|
||||
// content: await this.formatToolDenied(),
|
||||
// })
|
||||
this.didRejectTool = true
|
||||
return false
|
||||
}
|
||||
// Handle yesButtonClicked with text
|
||||
if (text) {
|
||||
await this.say("user_feedback", text, images)
|
||||
pushToolResult(formatResponse.toolResult(formatResponse.toolApprovedWithFeedback(text), images))
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -730,25 +730,19 @@ describe("Cline", () => {
|
||||
const iterator = cline.attemptApiRequest(0)
|
||||
await iterator.next()
|
||||
|
||||
// Calculate expected delay for first retry
|
||||
const baseDelay = 3 // from requestDelaySeconds
|
||||
|
||||
// Verify countdown messages
|
||||
expect(saySpy).toHaveBeenCalledWith(
|
||||
"api_req_retry_delayed",
|
||||
expect.stringContaining("Retrying in 3 seconds"),
|
||||
undefined,
|
||||
true,
|
||||
)
|
||||
expect(saySpy).toHaveBeenCalledWith(
|
||||
"api_req_retry_delayed",
|
||||
expect.stringContaining("Retrying in 2 seconds"),
|
||||
undefined,
|
||||
true,
|
||||
)
|
||||
expect(saySpy).toHaveBeenCalledWith(
|
||||
"api_req_retry_delayed",
|
||||
expect.stringContaining("Retrying in 1 seconds"),
|
||||
undefined,
|
||||
true,
|
||||
)
|
||||
for (let i = baseDelay; i > 0; i--) {
|
||||
expect(saySpy).toHaveBeenCalledWith(
|
||||
"api_req_retry_delayed",
|
||||
expect.stringContaining(`Retrying in ${i} seconds`),
|
||||
undefined,
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
expect(saySpy).toHaveBeenCalledWith(
|
||||
"api_req_retry_delayed",
|
||||
expect.stringContaining("Retrying now"),
|
||||
@@ -757,12 +751,14 @@ describe("Cline", () => {
|
||||
)
|
||||
|
||||
// Verify delay was called correctly
|
||||
expect(mockDelay).toHaveBeenCalledTimes(3)
|
||||
expect(mockDelay).toHaveBeenCalledTimes(baseDelay)
|
||||
expect(mockDelay).toHaveBeenCalledWith(1000)
|
||||
|
||||
// Verify error message content
|
||||
const errorMessage = saySpy.mock.calls.find((call) => call[1]?.includes(mockError.message))?.[1]
|
||||
expect(errorMessage).toBe(`${mockError.message}\n\nRetrying in 3 seconds...`)
|
||||
expect(errorMessage).toBe(
|
||||
`${mockError.message}\n\nRetry attempt 1\nRetrying in ${baseDelay} seconds...`,
|
||||
)
|
||||
})
|
||||
|
||||
describe("loadContext", () => {
|
||||
|
||||
@@ -8,6 +8,9 @@ export const formatResponse = {
|
||||
toolDeniedWithFeedback: (feedback?: string) =>
|
||||
`The user denied this operation and provided the following feedback:\n<feedback>\n${feedback}\n</feedback>`,
|
||||
|
||||
toolApprovedWithFeedback: (feedback?: string) =>
|
||||
`The user approved this operation and provided the following context:\n<feedback>\n${feedback}\n</feedback>`,
|
||||
|
||||
toolError: (error?: string) => `The tool execution failed with the following error:\n<error>\n${error}\n</error>`,
|
||||
|
||||
noToolsUsed: () =>
|
||||
|
||||
@@ -16,13 +16,17 @@ MODES
|
||||
${modes.map((mode: ModeConfig) => ` * "${mode.name}" mode - ${mode.roleDefinition.split(".")[0]}`).join("\n")}
|
||||
Custom modes will be referred to by their configured name property.
|
||||
|
||||
- Custom modes can be configured by creating or editing the custom modes file at '${customModesPath}'. The following fields are required and must not be empty:
|
||||
- Custom modes can be configured by editing the custom modes file at '${customModesPath}'. The file gets created automatically on startup and should always exist. Make sure to read the latest contents before writing to it to avoid overwriting existing modes.
|
||||
|
||||
- The following fields are required and must not be empty:
|
||||
* slug: A valid slug (lowercase letters, numbers, and hyphens). Must be unique, and shorter is better.
|
||||
* name: The display name for the mode
|
||||
* roleDefinition: A detailed description of the mode's role and capabilities
|
||||
* groups: Array of allowed tool groups (can be empty). Each group can be specified either as a string (e.g., "edit" to allow editing any file) or with file restrictions (e.g., ["edit", { fileRegex: "\\.md$", description: "Markdown files only" }] to only allow editing markdown files)
|
||||
|
||||
The customInstructions field is optional.
|
||||
- The customInstructions field is optional.
|
||||
|
||||
- For multi-line text, include newline characters in the string like "This is the first line.\nThis is the next line.\n\nThis is a double line break."
|
||||
|
||||
The file should follow this structure:
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user