From 4ae190f70e9c5d28662933e52de718669bc8d0a3 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Sun, 27 Oct 2024 17:20:51 -0400 Subject: [PATCH] Hide progress spinner if api req in browser session failed or cancelled --- .../src/components/chat/BrowserSessionRow.tsx | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/webview-ui/src/components/chat/BrowserSessionRow.tsx b/webview-ui/src/components/chat/BrowserSessionRow.tsx index 1cf2580..b5c9f83 100644 --- a/webview-ui/src/components/chat/BrowserSessionRow.tsx +++ b/webview-ui/src/components/chat/BrowserSessionRow.tsx @@ -32,25 +32,30 @@ interface BrowserSessionRowProps { */ const BrowserSessionRow = memo((props: BrowserSessionRowProps) => { - const { messages, isLast, onHeightChange } = props + const { messages, isLast, onHeightChange, lastModifiedMessage } = props const prevHeightRef = useRef(0) 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 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) + if (info.cancelReason != null) { + return true + } + } + const lastApiReqFailed = isLast && lastModifiedMessage?.ask === "api_req_failed" + if (lastApiReqFailed) { + return true + } + return false + }, [messages, lastModifiedMessage, isLast]) const isBrowsing = useMemo(() => { - 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]) + 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, isLastApiReqInterrupted]) // Organize messages into pages with current state and next action const pages = useMemo(() => {