diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 15f553e..2f296db 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -614,7 +614,7 @@ export class Cline { newUserContent.push({ type: "text", text: - `[TASK RESUMPTION] This task was interrupted ${agoText}. It may or may not be complete, so please reassess the task context. Be aware that the project state may have changed since then. The current working directory is now '${cwd.toPosix()}'. If the task has not been completed, retry the last step before interruption and proceed with completing the task.\n\nNote: If you previously attempted a tool use that the user did not provide a result for, you should assume the tool use was not successful and assess whether you should retry.${ + `[TASK RESUMPTION] This task was interrupted ${agoText}. It may or may not be complete, so please reassess the task context. Be aware that the project state may have changed since then. The current working directory is now '${cwd.toPosix()}'. If the task has not been completed, retry the last step before interruption and proceed with completing the task.\n\nNote: If you previously attempted a tool use that the user did not provide a result for, you should assume the tool use was not successful and assess whether you should retry. If the last tool was a browser_action, the browser has been closed and you must launch a new browser if needed.${ wasRecent ? "\n\nIMPORTANT: If the last tool use was a write_to_file that was interrupted, the file was reverted back to its original state before the interrupted edit, and you do NOT need to re-read the file as you already have its up-to-date contents." : "" diff --git a/webview-ui/src/components/chat/BrowserSessionRow.tsx b/webview-ui/src/components/chat/BrowserSessionRow.tsx index 2f436bf..1cf2580 100644 --- a/webview-ui/src/components/chat/BrowserSessionRow.tsx +++ b/webview-ui/src/components/chat/BrowserSessionRow.tsx @@ -37,8 +37,19 @@ const BrowserSessionRow = memo((props: BrowserSessionRowProps) => { const [maxActionHeight, setMaxActionHeight] = useState(0) const [consoleLogsExpanded, setConsoleLogsExpanded] = useState(false) + // const isLastApiReqInterrupted = useMemo(() => { + // // Check if last api_req_started is cancelled + // const lastApiReqStarted = [...messages].reverse().find((m) => m.say === "api_req_started") + // if (lastApiReqStarted?.text != null) { + // const info = JSON.parse(lastApiReqStarted.text) + // return info.cancelReason != null + // } + // const lastApiReqFailed = isLast && lastModifiedMessage?.ask === "api_req_failed" + // return lastApiReqFailed + // }, [messages, lastModifiedMessage, isLast]) + const isBrowsing = useMemo(() => { - return isLast && messages.some((m) => m.say === "browser_action_result") // after user approves, browser_action_result with "" is sent to indicate that the session has started + return isLast && messages.some((m) => m.say === "browser_action_result") //&& !isLastApiReqInterrupted // after user approves, browser_action_result with "" is sent to indicate that the session has started }, [isLast, messages]) // Organize messages into pages with current state and next action diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index 9676571..6f6c081 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -473,6 +473,22 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie isInBrowserSession = true currentGroup.push(message) } else if (isInBrowserSession) { + // end session if api_req_started is cancelled + + if (message.say === "api_req_started") { + // get last api_req_started in currentGroup to check if it's cancelled. If it is then this api req is not part of the current browser session + const lastApiReqStarted = [...currentGroup].reverse().find((m) => m.say === "api_req_started") + if (lastApiReqStarted?.text != null) { + const info = JSON.parse(lastApiReqStarted.text) + const isCancelled = info.cancelReason != null + if (isCancelled) { + endBrowserSession() + result.push(message) + return + } + } + } + if (isBrowserSessionMessage(message)) { currentGroup.push(message)