Skip to content

Commit 4924668

Browse files
philipvaschrarnoldus
authored andcommitted
Fix browser mode JSON snippets appearing in chat
1 parent 7645aad commit 4924668

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

webview-ui/src/components/chat/ChatRow.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,37 @@ export const ChatRowContent = ({
11091109
return <CodebaseSearchResultsDisplay query={query} results={results} />
11101110
case "user_edit_todos":
11111111
return <UpdateTodoListToolBlock userEdited onChange={() => {}} />
1112+
case "browser_action_result":
1113+
// This should not normally be rendered here as browser_action_result messages
1114+
// should be grouped into browser sessions and rendered by BrowserSessionRow.
1115+
// If we see this, it means the message grouping logic has a bug.
1116+
return (
1117+
<>
1118+
{title && (
1119+
<div style={headerStyle}>
1120+
{icon}
1121+
{title}
1122+
</div>
1123+
)}
1124+
<div style={{ paddingTop: 10 }}>
1125+
<div
1126+
style={{
1127+
color: "var(--vscode-errorForeground)",
1128+
fontFamily: "monospace",
1129+
fontSize: "12px",
1130+
padding: "8px",
1131+
backgroundColor: "var(--vscode-editor-background)",
1132+
border: "1px solid var(--vscode-editorError-border)",
1133+
borderRadius: "4px",
1134+
marginBottom: "8px",
1135+
}}>
1136+
⚠️ Browser action result not properly grouped - this is a bug in the message
1137+
grouping logic
1138+
</div>
1139+
<Markdown markdown={message.text} partial={message.partial} />
1140+
</div>
1141+
</>
1142+
)
11121143
default:
11131144
return (
11141145
<>

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,18 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
10341034
}
10351035

10361036
visibleMessages.forEach((message) => {
1037+
// Special handling for browser_action_result - ensure it's always in a browser session
1038+
if (message.say === "browser_action_result" && !isInBrowserSession) {
1039+
isInBrowserSession = true
1040+
currentGroup = []
1041+
}
1042+
1043+
// Special handling for browser_action - ensure it's always in a browser session
1044+
if (message.say === "browser_action" && !isInBrowserSession) {
1045+
isInBrowserSession = true
1046+
currentGroup = []
1047+
}
1048+
10371049
if (message.ask === "browser_action_launch") {
10381050
// Complete existing browser session if any.
10391051
endBrowserSession()
@@ -1063,12 +1075,14 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
10631075

10641076
if (isBrowserSessionMessage(message)) {
10651077
currentGroup.push(message)
1066-
1067-
// Check if this is a close action
1068-
if (message.say === "browser_action") {
1069-
const browserAction = JSON.parse(message.text || "{}") as ClineSayBrowserAction
1070-
if (browserAction.action === "close") {
1071-
endBrowserSession()
1078+
if (message.say === "browser_action_result") {
1079+
// Check if the previous browser_action was a close action
1080+
const lastBrowserAction = [...currentGroup].reverse().find((m) => m.say === "browser_action")
1081+
if (lastBrowserAction) {
1082+
const browserAction = JSON.parse(lastBrowserAction.text || "{}") as ClineSayBrowserAction
1083+
if (browserAction.action === "close") {
1084+
endBrowserSession()
1085+
}
10721086
}
10731087
}
10741088
} else {

0 commit comments

Comments
 (0)