import { useEffect, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { useNavigate } from 'react-router-dom'; import Spinner from '../components/Spinner'; import { setConversation, updateConversationId, } from '../conversation/conversationSlice'; import { selectSelectedAgent, selectToken, setSelectedAgent, } from '../preferences/preferenceSlice'; import AgentCard from './AgentCard'; import { agentSectionsConfig } from './agents.config'; import { Agent } from './types'; export default function AgentsList() { const dispatch = useDispatch(); const token = useSelector(selectToken); const selectedAgent = useSelector(selectSelectedAgent); useEffect(() => { dispatch(setConversation([])); dispatch( updateConversationId({ query: { conversationId: null }, }), ); if (selectedAgent) dispatch(setSelectedAgent(null)); }, [token]); return (

Agents

Discover and create custom versions of DocsGPT that combine instructions, extra knowledge, and any combination of skills

{agentSectionsConfig.map((sectionConfig) => ( ))}
); } function AgentSection({ config, }: { config: (typeof agentSectionsConfig)[number]; }) { const navigate = useNavigate(); const dispatch = useDispatch(); const token = useSelector(selectToken); const agents = useSelector(config.selectData); const [loading, setLoading] = useState(true); const updateAgents = (updatedAgents: Agent[]) => { dispatch(config.updateAction(updatedAgents)); }; useEffect(() => { const getAgents = async () => { setLoading(true); try { const response = await config.fetchAgents(token); if (!response.ok) throw new Error(`Failed to fetch ${config.id} agents`); const data = await response.json(); dispatch(config.updateAction(data)); } catch (error) { console.error(`Error fetching ${config.id} agents:`, error); dispatch(config.updateAction([])); } finally { setLoading(false); } }; getAgents(); }, [token, config, dispatch]); return (

{config.title}

{config.description}

{config.showNewAgentButton && ( )}
{loading ? (
) : agents && agents.length > 0 ? (
{agents.map((agent) => ( ))}
) : (

{config.emptyStateDescription}

{config.showNewAgentButton && ( )}
)}
); }