import { useEffect, useState } from 'react'; import { useSelector } from 'react-redux'; import { Agent } from '../agents/types'; import userService from '../api/services/userService'; import CopyButton from '../components/CopyButton'; import Spinner from '../components/Spinner'; import { ActiveState } from '../models/misc'; import { selectToken } from '../preferences/preferenceSlice'; import WrapperModal from './WrapperModal'; const baseURL = import.meta.env.VITE_BASE_URL; type AgentDetailsModalProps = { agent: Agent; mode: 'new' | 'edit' | 'draft'; modalState: ActiveState; setModalState: (state: ActiveState) => void; }; export default function AgentDetailsModal({ agent, mode, modalState, setModalState, }: AgentDetailsModalProps) { const token = useSelector(selectToken); const [sharedToken, setSharedToken] = useState( agent.shared_token ?? null, ); const [apiKey, setApiKey] = useState(null); const [webhookUrl, setWebhookUrl] = useState(null); const [loadingStates, setLoadingStates] = useState({ publicLink: false, apiKey: false, webhook: false, }); const setLoading = ( key: 'publicLink' | 'apiKey' | 'webhook', state: boolean, ) => { setLoadingStates((prev) => ({ ...prev, [key]: state })); }; const handleGeneratePublicLink = async () => { setLoading('publicLink', true); const response = await userService.shareAgent( { id: agent.id ?? '', shared: true }, token, ); if (!response.ok) { setLoading('publicLink', false); return; } const data = await response.json(); setSharedToken(data.shared_token); setLoading('publicLink', false); }; const handleGenerateWebhook = async () => { setLoading('webhook', true); const response = await userService.getAgentWebhook(agent.id ?? '', token); if (!response.ok) { setLoading('webhook', false); return; } const data = await response.json(); setWebhookUrl(data.webhook_url); setLoading('webhook', false); }; useEffect(() => { setSharedToken(agent.shared_token ?? null); setApiKey(agent.key ?? null); }, [agent]); if (modalState !== 'ACTIVE') return null; return ( { setModalState('INACTIVE'); }} >

Access Details

Public Link

{sharedToken && (
)}
{sharedToken ? (

{`${baseURL}/shared/agent/${sharedToken}`}

) : ( )}

API Key

{apiKey ? ( {apiKey} ) : ( )}

Webhook URL

{webhookUrl && (
)}
{webhookUrl ? (

{webhookUrl}

) : ( )}
); }