@@ -10,7 +10,7 @@ import {
1010import type { StreamBatchEvent } from '@/lib/copilot/request/session/types'
1111import {
1212 getReplayCompletedWorkflowToolCallIds ,
13- hasExecutingBrowserToolCall ,
13+ panelForExecutingClientTool ,
1414 reconcileLiveAssistantTurn ,
1515 selectReconnectReplayState ,
1616} from '@/app/workspace/[workspaceId]/home/hooks/use-chat'
@@ -220,7 +220,7 @@ describe('getReplayCompletedWorkflowToolCallIds', () => {
220220 } )
221221} )
222222
223- describe ( 'hasExecutingBrowserToolCall ' , ( ) => {
223+ describe ( 'panelForExecutingClientTool ' , ( ) => {
224224 function toolCallMessage ( id : string , name : string , status : ToolCallStatus ) : ChatMessage {
225225 return {
226226 id,
@@ -236,16 +236,42 @@ describe('hasExecutingBrowserToolCall', () => {
236236 toolCallMessage ( 'm2' , 'browser_navigate' , 'executing' ) ,
237237 ]
238238
239- expect ( hasExecutingBrowserToolCall ( messages ) ) . toBe ( true )
239+ expect ( panelForExecutingClientTool ( messages ) ) . toBe ( 'browser' )
240240 } )
241241
242- it ( 'ignores completed browser tool calls and executing non-browser tools' , ( ) => {
242+ it ( 'detects a terminal tool call that is still executing' , ( ) => {
243+ const messages = [
244+ toolCallMessage ( 'm1' , 'terminal' , 'success' ) ,
245+ toolCallMessage ( 'm2' , 'terminal' , 'executing' ) ,
246+ ]
247+
248+ expect ( panelForExecutingClientTool ( messages ) ) . toBe ( 'terminal' )
249+ } )
250+
251+ it ( 'ignores completed calls and executing tools that own no panel' , ( ) => {
243252 const messages = [
244253 toolCallMessage ( 'm1' , 'browser_click' , 'success' ) ,
245- toolCallMessage ( 'm2' , 'run_workflow' , 'executing' ) ,
246- { id : 'm3' , role : 'assistant' as const , content : 'no blocks' } ,
254+ toolCallMessage ( 'm2' , 'terminal' , 'success' ) ,
255+ toolCallMessage ( 'm3' , 'run_workflow' , 'executing' ) ,
256+ { id : 'm4' , role : 'assistant' as const , content : 'no blocks' } ,
257+ ]
258+
259+ expect ( panelForExecutingClientTool ( messages ) ) . toBe ( null )
260+ } )
261+
262+ // Both panels can be in flight at once; the later call is the one the user
263+ // was watching when they navigated away.
264+ it ( 'picks the later panel when both are mid-action' , ( ) => {
265+ const browserFirst = [
266+ toolCallMessage ( 'm1' , 'browser_navigate' , 'executing' ) ,
267+ toolCallMessage ( 'm2' , 'terminal' , 'executing' ) ,
268+ ]
269+ const terminalFirst = [
270+ toolCallMessage ( 'm1' , 'terminal' , 'executing' ) ,
271+ toolCallMessage ( 'm2' , 'browser_navigate' , 'executing' ) ,
247272 ]
248273
249- expect ( hasExecutingBrowserToolCall ( messages ) ) . toBe ( false )
274+ expect ( panelForExecutingClientTool ( browserFirst ) ) . toBe ( 'terminal' )
275+ expect ( panelForExecutingClientTool ( terminalFirst ) ) . toBe ( 'browser' )
250276 } )
251277} )
0 commit comments