import React, { useState } from 'react'; import { X, Plus, RefreshCw } from 'lucide-react'; const TRANSPORTS = ['SSE', 'STREAMABLEHTTP', 'HTTP', 'STDIO']; export function AddServerDrawer({ backendUrl, apiKey, onClose, onRegistered }) { const [name, setName] = useState(''); const [url, setUrl] = useState(''); const [transport, setTransport] = useState('SSE'); const [description, setDescription] = useState(''); const [autoRefresh, setAutoRefresh] = useState(true); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const [success, setSuccess] = useState(false); const canSubmit = name.trim() && url.trim() && !busy; const handleSubmit = async () => { if (!canSubmit) return; setBusy(true); setError(null); try { const headers = { 'Content-Type': 'application/json' }; if (apiKey) headers['x-api-key'] = apiKey; const res = await fetch(`${backendUrl}/v1/agentic/register/gateway`, { method: 'POST', headers, body: JSON.stringify({ name: name.trim(), url: url.trim(), transport, description: description.trim(), auto_refresh: autoRefresh, }), }); const data = await res.json(); if (!res.ok || !data.ok) { throw new Error(data.detail || `HTTP ${res.status}`); } setSuccess(true); setTimeout(() => { onRegistered(); onClose(); }, 1000); } catch (e) { setError(e?.message || 'Registration failed'); } finally { setBusy(false); } }; return (