@@ -5,36 +5,41 @@ import { useCallback, useEffect, useState } from 'react';
55import { ToastContainer } from 'react-toastify' ;
66
77import { PrimaryContent } from '@/components/primary-content/primary-content' ;
8- import { AgentexProvider } from '@/components/providers' ;
8+ import { useAgentexClient } from '@/components/providers' ;
99import { TaskSidebar } from '@/components/task-sidebar/task-sidebar' ;
1010import { TracesSidebar } from '@/components/traces-sidebar/traces-sidebar' ;
11+ import { useAgents } from '@/hooks/use-agents' ;
1112import { useLocalStorageState } from '@/hooks/use-local-storage-state' ;
1213import {
1314 SearchParamKey ,
1415 useSafeSearchParams ,
1516} from '@/hooks/use-safe-search-params' ;
1617
17- type AgentexUIRootProps = {
18- sgpAppURL : string ;
19- agentexAPIBaseURL : string ;
20- } ;
21-
22- export function AgentexUIRoot ( {
23- sgpAppURL,
24- agentexAPIBaseURL,
25- } : AgentexUIRootProps ) {
18+ export function AgentexUIRoot ( ) {
2619 const { agentName, taskID, updateParams } = useSafeSearchParams ( ) ;
2720 const [ isTracesSidebarOpen , setIsTracesSidebarOpen ] = useState ( false ) ;
21+ const { agentexClient } = useAgentexClient ( ) ;
22+ const { data : agents = [ ] , isLoading } = useAgents ( agentexClient ) ;
2823 const [ localAgentName , setLocalAgentName ] = useLocalStorageState <
2924 string | undefined
3025 > ( 'lastSelectedAgent' , undefined ) ;
3126
3227 useEffect ( ( ) => {
28+ if ( isLoading ) return ;
29+
30+ const selectedAgent = agents . find ( agent => agent . name === agentName ) ;
31+ const isAgentValid = selectedAgent && selectedAgent . status === 'Ready' ;
32+
33+ if ( ! isAgentValid ) {
34+ updateParams ( { [ SearchParamKey . AGENT_NAME ] : null } ) ;
35+ setLocalAgentName ( undefined ) ;
36+ }
37+
3338 if ( ! agentName && localAgentName ) {
3439 updateParams ( { [ SearchParamKey . AGENT_NAME ] : localAgentName } ) ;
3540 }
3641 // eslint-disable-next-line react-hooks/exhaustive-deps
37- } , [ ] ) ;
42+ } , [ isLoading ] ) ;
3843
3944 const handleSelectTask = useCallback (
4045 ( taskId : string | null ) => {
@@ -70,21 +75,16 @@ export function AgentexUIRoot({
7075
7176 return (
7277 < >
73- < AgentexProvider
74- sgpAppURL = { sgpAppURL ?? '' }
75- agentexAPIBaseURL = { agentexAPIBaseURL }
76- >
77- < div className = "fixed inset-0 flex w-full" >
78- < TaskSidebar />
79- < PrimaryContent
80- isTracesSidebarOpen = { isTracesSidebarOpen }
81- toggleTracesSidebar = { ( ) =>
82- setIsTracesSidebarOpen ( ! isTracesSidebarOpen )
83- }
84- />
85- < TracesSidebar isOpen = { isTracesSidebarOpen } />
86- </ div >
87- </ AgentexProvider >
78+ < div className = "fixed inset-0 flex w-full" >
79+ < TaskSidebar />
80+ < PrimaryContent
81+ isTracesSidebarOpen = { isTracesSidebarOpen }
82+ toggleTracesSidebar = { ( ) =>
83+ setIsTracesSidebarOpen ( ! isTracesSidebarOpen )
84+ }
85+ />
86+ < TracesSidebar isOpen = { isTracesSidebarOpen } />
87+ </ div >
8888 < ToastContainer />
8989 </ >
9090 ) ;
0 commit comments