Skip to content

Commit 5ef89d5

Browse files
committed
Redirect if agent name is invalid
1 parent 11def0f commit 5ef89d5

2 files changed

Lines changed: 31 additions & 28 deletions

File tree

agentex-ui/app/page.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { connection } from 'next/server';
22

33
import { AgentexUIRoot } from '@/components/agentex-ui-root';
4+
import { AgentexProvider } from '@/components/providers';
45

56
export default async function RootPage() {
67
await connection();
@@ -19,9 +20,11 @@ export default async function RootPage() {
1920
}
2021

2122
return (
22-
<AgentexUIRoot
23+
<AgentexProvider
2324
sgpAppURL={sgpAppURL}
2425
agentexAPIBaseURL={agentexAPIBaseURL}
25-
/>
26+
>
27+
<AgentexUIRoot />
28+
</AgentexProvider>
2629
);
2730
}

agentex-ui/components/agentex-ui-root.tsx

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,41 @@ import { useCallback, useEffect, useState } from 'react';
55
import { ToastContainer } from 'react-toastify';
66

77
import { PrimaryContent } from '@/components/primary-content/primary-content';
8-
import { AgentexProvider } from '@/components/providers';
8+
import { useAgentexClient } from '@/components/providers';
99
import { TaskSidebar } from '@/components/task-sidebar/task-sidebar';
1010
import { TracesSidebar } from '@/components/traces-sidebar/traces-sidebar';
11+
import { useAgents } from '@/hooks/use-agents';
1112
import { useLocalStorageState } from '@/hooks/use-local-storage-state';
1213
import {
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

Comments
 (0)