@@ -16,28 +16,27 @@ import { Button } from "@/components/ui/button";
1616import { Input } from "@/components/ui/input" ;
1717import { Label } from "@/components/ui/label" ;
1818import { Badge } from "@/components/ui/badge" ;
19- import { cn } from "@/lib/utils" ;
20- import {
21- saveCustomAgent ,
22- validateAgentUrl ,
19+ import {
20+ validateAgentUrl ,
2321 testAgentConnection ,
24- type CustomAgent
22+ type CustomAgent ,
2523} from "@/lib/agent-storage" ;
24+ import { useAgentManagement } from "@/lib/agent-context" ;
25+ import { type Agent } from "@/lib/config" ;
2626
27- interface AddAgentModalProps {
27+ export interface AddAgentModalProps {
2828 open : boolean ;
2929 onOpenChange : ( open : boolean ) => void ;
3030 onAgentAdded : ( agent : CustomAgent ) => void ;
3131}
3232
33- export function AddAgentModal ( {
34- open,
35- onOpenChange,
36- onAgentAdded
33+ export function AddAgentModal ( {
34+ open,
35+ onOpenChange,
36+ onAgentAdded,
3737} : AddAgentModalProps ) {
3838 const [ name , setName ] = useState ( "" ) ;
3939 const [ url , setUrl ] = useState ( "" ) ;
40- const [ isLoading , setIsLoading ] = useState ( false ) ;
4140 const [ isTestingConnection , setIsTestingConnection ] = useState ( false ) ;
4241 const [ connectionStatus , setConnectionStatus ] = useState < {
4342 tested : boolean ;
@@ -46,12 +45,14 @@ export function AddAgentModal({
4645 } > ( { tested : false , online : false } ) ;
4746 const [ error , setError ] = useState < string | null > ( null ) ;
4847
48+ // Use the agent management context
49+ const { addAgent, isLoading } = useAgentManagement ( ) ;
50+
4951 const resetForm = ( ) => {
5052 setName ( "" ) ;
5153 setUrl ( "" ) ;
5254 setError ( null ) ;
5355 setConnectionStatus ( { tested : false , online : false } ) ;
54- setIsLoading ( false ) ;
5556 setIsTestingConnection ( false ) ;
5657 } ;
5758
@@ -77,7 +78,7 @@ export function AddAgentModal({
7778 online : result . isOnline ,
7879 error : result . error ,
7980 } ) ;
80-
81+
8182 if ( ! result . isOnline ) {
8283 setError ( `Connection failed: ${ result . error } ` ) ;
8384 }
@@ -91,7 +92,7 @@ export function AddAgentModal({
9192
9293 const handleSubmit = async ( e : React . FormEvent ) => {
9394 e . preventDefault ( ) ;
94-
95+
9596 if ( ! name . trim ( ) || ! url . trim ( ) ) {
9697 setError ( "Both name and URL are required" ) ;
9798 return ;
@@ -104,17 +105,21 @@ export function AddAgentModal({
104105 return ;
105106 }
106107
107- setIsLoading ( true ) ;
108108 setError ( null ) ;
109109
110110 try {
111- const newAgent = saveCustomAgent ( name . trim ( ) , url . trim ( ) ) ;
112- onAgentAdded ( newAgent ) ;
113- handleClose ( ) ;
111+ const result = await addAgent ( name . trim ( ) , url . trim ( ) ) ;
112+ if ( result . success ) {
113+ // Find the newly added agent (it will be in the context)
114+ // For now, we'll just notify that an agent was added
115+ // The actual agent object will be available through the context
116+ onAgentAdded ( { } as Agent ) ;
117+ handleClose ( ) ;
118+ } else {
119+ setError ( result . error || "Failed to add agent" ) ;
120+ }
114121 } catch ( err ) {
115122 setError ( err instanceof Error ? err . message : "Failed to save agent" ) ;
116- } finally {
117- setIsLoading ( false ) ;
118123 }
119124 } ;
120125
@@ -123,7 +128,7 @@ export function AddAgentModal({
123128 < DialogPortal >
124129 { /* Custom solid overlay */ }
125130 < DialogOverlay className = "bg-black/90 backdrop-blur-sm" />
126- < DialogContent
131+ < DialogContent
127132 className = "sm:max-w-md bg-white dark:bg-gray-900 border border-gray-300 dark:border-gray-600 shadow-2xl"
128133 showCloseButton = { true }
129134 >
@@ -133,13 +138,19 @@ export function AddAgentModal({
133138 Add New Agent
134139 </ DialogTitle >
135140 < DialogDescription className = "text-gray-600 dark:text-gray-300" >
136- Add a custom agent by providing a name and URL. The URL should point to a running agent instance.
141+ Add a custom agent by providing a name and URL. The URL should
142+ point to a running agent instance.
137143 </ DialogDescription >
138144 </ DialogHeader >
139145
140146 < form onSubmit = { handleSubmit } className = "space-y-4" >
141147 < div className = "space-y-2" >
142- < Label htmlFor = "agent-name" className = "text-gray-900 dark:text-white font-medium" > Agent Name</ Label >
148+ < Label
149+ htmlFor = "agent-name"
150+ className = "text-gray-900 dark:text-white font-medium"
151+ >
152+ Agent Name
153+ </ Label >
143154 < Input
144155 id = "agent-name"
145156 placeholder = "My Custom Agent"
@@ -150,7 +161,12 @@ export function AddAgentModal({
150161 </ div >
151162
152163 < div className = "space-y-2" >
153- < Label htmlFor = "agent-url" className = "text-gray-900 dark:text-white font-medium" > Agent URL</ Label >
164+ < Label
165+ htmlFor = "agent-url"
166+ className = "text-gray-900 dark:text-white font-medium"
167+ >
168+ Agent URL
169+ </ Label >
154170 < div className = "flex gap-2" >
155171 < Input
156172 id = "agent-url"
@@ -177,21 +193,27 @@ export function AddAgentModal({
177193 ) }
178194 </ Button >
179195 </ div >
180-
196+
181197 { /* Connection Status */ }
182198 { connectionStatus . tested && (
183199 < div className = "flex items-center gap-2 text-sm" >
184200 { connectionStatus . online ? (
185201 < >
186202 < Check className = "h-4 w-4 text-green-500" />
187- < Badge variant = "outline" className = "text-green-600 border-green-200 bg-green-50 dark:bg-green-900/20" >
203+ < Badge
204+ variant = "outline"
205+ className = "text-green-600 border-green-200 bg-green-50 dark:bg-green-900/20"
206+ >
188207 Connection successful
189208 </ Badge >
190209 </ >
191210 ) : (
192211 < >
193212 < AlertCircle className = "h-4 w-4 text-red-500" />
194- < Badge variant = "outline" className = "text-red-600 border-red-200 bg-red-50 dark:bg-red-900/20" >
213+ < Badge
214+ variant = "outline"
215+ className = "text-red-600 border-red-200 bg-red-50 dark:bg-red-900/20"
216+ >
195217 Connection failed
196218 </ Badge >
197219 </ >
@@ -210,17 +232,17 @@ export function AddAgentModal({
210232 ) }
211233
212234 < DialogFooter className = "gap-2" >
213- < Button
214- type = "button"
215- variant = "outline"
235+ < Button
236+ type = "button"
237+ variant = "outline"
216238 onClick = { handleClose }
217239 disabled = { isLoading }
218240 className = "bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-600 text-gray-900 dark:text-white hover:bg-gray-50 dark:hover:bg-gray-700"
219241 >
220242 Cancel
221243 </ Button >
222- < Button
223- type = "submit"
244+ < Button
245+ type = "submit"
224246 disabled = { isLoading || ! name . trim ( ) || ! url . trim ( ) }
225247 className = "min-w-[80px] bg-blue-600 hover:bg-blue-700 text-white border-0"
226248 >
0 commit comments