@@ -9,12 +9,21 @@ import {
9
9
useWsClient ,
10
10
WsClientProviderStatus ,
11
11
} from "#/context/ws-client-provider" ;
12
+ import { useNotification } from "#/hooks/useNotification" ;
13
+ import { browserTab } from "#/utils/browser-tab" ;
14
+
15
+ const notificationStates = [
16
+ AgentState . AWAITING_USER_INPUT ,
17
+ AgentState . FINISHED ,
18
+ AgentState . AWAITING_USER_CONFIRMATION ,
19
+ ] ;
12
20
13
21
export function AgentStatusBar ( ) {
14
22
const { t, i18n } = useTranslation ( ) ;
15
23
const { curAgentState } = useSelector ( ( state : RootState ) => state . agent ) ;
16
24
const { curStatusMessage } = useSelector ( ( state : RootState ) => state . status ) ;
17
25
const { status } = useWsClient ( ) ;
26
+ const { notify } = useNotification ( ) ;
18
27
19
28
const [ statusMessage , setStatusMessage ] = React . useState < string > ( "" ) ;
20
29
@@ -45,13 +54,40 @@ export function AgentStatusBar() {
45
54
updateStatusMessage ( ) ;
46
55
} , [ curStatusMessage . id ] ) ;
47
56
57
+ // Handle window focus/blur
58
+ React . useEffect ( ( ) => {
59
+ if ( typeof window === "undefined" ) return undefined ;
60
+
61
+ const handleFocus = ( ) => {
62
+ browserTab . stopNotification ( ) ;
63
+ } ;
64
+
65
+ window . addEventListener ( "focus" , handleFocus ) ;
66
+ return ( ) => {
67
+ window . removeEventListener ( "focus" , handleFocus ) ;
68
+ browserTab . stopNotification ( ) ;
69
+ } ;
70
+ } , [ ] ) ;
71
+
48
72
React . useEffect ( ( ) => {
49
73
if ( status === WsClientProviderStatus . DISCONNECTED ) {
50
74
setStatusMessage ( "Connecting..." ) ;
51
75
} else {
52
76
setStatusMessage ( AGENT_STATUS_MAP [ curAgentState ] . message ) ;
77
+ if ( notificationStates . includes ( curAgentState ) ) {
78
+ const message = t ( AGENT_STATUS_MAP [ curAgentState ] . message ) ;
79
+ notify ( t ( AGENT_STATUS_MAP [ curAgentState ] . message ) , {
80
+ body : t ( `Agent state changed to ${ curAgentState } ` ) ,
81
+ playSound : true ,
82
+ } ) ;
83
+
84
+ // Update browser tab if window exists and is not focused
85
+ if ( typeof document !== "undefined" && ! document . hasFocus ( ) ) {
86
+ browserTab . startNotification ( message ) ;
87
+ }
88
+ }
53
89
}
54
- } , [ curAgentState ] ) ;
90
+ } , [ curAgentState , notify , t ] ) ;
55
91
56
92
return (
57
93
< div className = "flex flex-col items-center" >
0 commit comments