import React, { SyntheticEvent, useEffect, useRef, useState } from 'react'; import { useSelector, useDispatch } from 'react-redux'; import { Route, Routes, useNavigate } from 'react-router-dom'; import userService from '../api/services/userService'; import Copy from '../assets/copy-linear.svg'; import Edit from '../assets/edit.svg'; import Monitoring from '../assets/monitoring.svg'; import Trash from '../assets/red-trash.svg'; import Robot from '../assets/robot.svg'; import ThreeDots from '../assets/three-dots.svg'; import ContextMenu, { MenuOption } from '../components/ContextMenu'; import ConfirmationModal from '../modals/ConfirmationModal'; import { ActiveState } from '../models/misc'; import { selectToken, setSelectedAgent, setAgents, selectAgents, selectSelectedAgent, } from '../preferences/preferenceSlice'; import AgentLogs from './AgentLogs'; import NewAgent from './NewAgent'; import { Agent } from './types'; import Spinner from '../components/Spinner'; export default function Agents() { return ( } /> } /> } /> } /> ); } function AgentsList() { const navigate = useNavigate(); const dispatch = useDispatch(); const token = useSelector(selectToken); const agents = useSelector(selectAgents); const selectedAgent = useSelector(selectSelectedAgent); const [userAgents, setUserAgents] = useState(agents || []); const [loading, setLoading] = useState(true); const getAgents = async () => { try { setLoading(true); const response = await userService.getAgents(token); if (!response.ok) throw new Error('Failed to fetch agents'); const data = await response.json(); setUserAgents(data); dispatch(setAgents(data)); setLoading(false); } catch (error) { console.error('Error:', error); setLoading(false); } }; useEffect(() => { getAgents(); 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.

{/* Premade agents section */} {/*

Premade by DocsGPT

{Array.from({ length: 5 }, (_, index) => (
agent-logo

{}

{}

))}
*/}

Created by You

{loading ? (
) : userAgents.length > 0 ? ( userAgents.map((agent) => ( )) ) : (

You don’t have any created agents yet

)}
); } function AgentCard({ agent, setUserAgents, }: { agent: Agent; setUserAgents: React.Dispatch>; }) { const navigate = useNavigate(); const dispatch = useDispatch(); const token = useSelector(selectToken); const [isMenuOpen, setIsMenuOpen] = useState(false); const [deleteConfirmation, setDeleteConfirmation] = useState('INACTIVE'); const menuRef = useRef(null); const menuOptions: MenuOption[] = [ { icon: Monitoring, label: 'Logs', onClick: (e: SyntheticEvent) => { e.stopPropagation(); navigate(`/agents/logs/${agent.id}`); }, variant: 'primary', iconWidth: 14, iconHeight: 14, }, { icon: Edit, label: 'Edit', onClick: (e: SyntheticEvent) => { e.stopPropagation(); navigate(`/agents/edit/${agent.id}`); }, variant: 'primary', iconWidth: 14, iconHeight: 14, }, { icon: Trash, label: 'Delete', onClick: (e: SyntheticEvent) => { e.stopPropagation(); setDeleteConfirmation('ACTIVE'); }, variant: 'danger', iconWidth: 12, iconHeight: 12, }, ]; const handleClick = () => { if (agent.status === 'published') { dispatch(setSelectedAgent(agent)); navigate(`/`); } }; const handleDelete = async (agentId: string) => { const response = await userService.deleteAgent(agentId, token); if (!response.ok) throw new Error('Failed to delete agent'); const data = await response.json(); setUserAgents((prevAgents) => prevAgents.filter((prevAgent) => prevAgent.id !== data.id), ); }; return (
{ e.stopPropagation(); handleClick(); }} >
{ e.stopPropagation(); setIsMenuOpen(true); }} className="absolute right-4 top-4 z-50 cursor-pointer" > {'use-agent'}
{`${agent.name}`} {agent.status === 'draft' && (

{`(Draft)`}

)}

{agent.name}

{agent.description}

{ handleDelete(agent.id || ''); setDeleteConfirmation('INACTIVE'); }} cancelLabel="Cancel" variant="danger" />
); }