import { useCallback, useEffect, useMemo, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { Plus, Sparkles, ArrowRight, MessageCircle, Bot, BriefcaseBusiness, Info, Pencil, Trash2, Eye, EyeOff, MessageCircleMore, InfoIcon, Edit } from 'lucide-react'; import { Dialog, Loading, MessagePlugin, Popconfirm, Switch } from 'tdesign-react'; import { useTheme } from '../../contexts/ThemeContext'; import { useExpertAuthBootstrap } from '../../hooks'; import { knowledgetoolUrl } from '@/hooks/useExpertAuthBootstrap'; interface ExpertAgentItem { id: number; name: string; avatar_url: string | null; description: string | null; model_name: string; is_draft: boolean; user_id: string; created_at: string; } type ExpertTab = 'mine' | 'published'; export default function AgentExpertCenterPage() { const { theme } = useTheme(); const isDark = theme === 'dark'; const { llmList, currentUser, authedFetch } = useExpertAuthBootstrap(); const navigate = useNavigate(); const [activeTab, setActiveTab] = useState('mine'); const [agentList, setAgentList] = useState([]); const [isListLoading, setIsListLoading] = useState(false); const [isStatusUpdating, setIsStatusUpdating] = useState(false); const [detailVisible, setDetailVisible] = useState(false); const [selectedAgent, setSelectedAgent] = useState(null); const fetchExpertList = useCallback(async () => { setIsListLoading(true); try { const isDraft = activeTab === 'mine'; const res = await authedFetch(`${knowledgetoolUrl}/api/v1/expert-agents/list`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ is_draft: isDraft }), }); if (!res.ok) { console.error('expert-agents/list接口调用失败:', res.status, res.statusText); setAgentList([]); return; } const data: unknown = await res.json(); const rawList = Array.isArray(data) ? (data as ExpertAgentItem[]) : []; if (isDraft) { const mineFromList = currentUser ? rawList.filter((item) => item.user_id === currentUser.id) : []; const allRes = await authedFetch(`${knowledgetoolUrl}/api/v1/expert-agents`, { method: 'GET', }); let mineFromAll: ExpertAgentItem[] = []; if (allRes.ok) { const allData: unknown = await allRes.json(); const allList = Array.isArray(allData) ? (allData as ExpertAgentItem[]) : []; mineFromAll = currentUser ? allList.filter((item) => item.user_id === currentUser.id) : []; } else { console.error('expert-agents接口调用失败:', allRes.status, allRes.statusText); } const mergedMap = new Map(); [...mineFromList, ...mineFromAll].forEach((item) => mergedMap.set(item.id, item)); setAgentList(Array.from(mergedMap.values())); return; } setAgentList(rawList); } catch (error) { console.error('expert-agents/list接口异常:', error); setAgentList([]); } finally { setIsListLoading(false); } }, [activeTab, authedFetch, currentUser]); useEffect(() => { if (activeTab === 'mine' && !currentUser) return; void fetchExpertList(); }, [activeTab, currentUser, fetchExpertList]); const handleStatusToggle = async (nextPublished: boolean) => { if (!selectedAgent) return; const nextIsDraft = !nextPublished; setIsStatusUpdating(true); try { const res = await authedFetch(`${knowledgetoolUrl}/api/v1/expert-agents/${selectedAgent.id}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ is_draft: nextIsDraft }), }); if (!res.ok) { console.error('更新专家状态失败:', res.status, res.statusText); return; } setSelectedAgent({ ...selectedAgent, is_draft: nextIsDraft }); await fetchExpertList(); } catch (error) { console.error('更新专家状态异常:', error); } finally { setIsStatusUpdating(false); } }; const addAgentSearch = async () => { const parmy = { model_name: 'Qwen3.5-27B', name: '未命名专家', system_prompt: '你是一个专业的助手,能够回答用户的问题。' } const res: any = await authedFetch(`${knowledgetoolUrl}/api/v1/expert-agents`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(parmy), }); console.log('创建专家', res); const data: any = await res.json() navigate(`/agent-expert-edit?id=${data.id}`) } const delAgentSearch = async (id) => { const res: any = await authedFetch(`${knowledgetoolUrl}/api/v1/expert-agents/${id}`, { method: 'DELETE', headers: { 'Content-Type': 'application/json', }, }); MessagePlugin.success('操作成功') await fetchExpertList(); } const cards = useMemo( () => agentList.map((item) => ({ id: String(item.id), title: item.name || '未命名专家', desc: item.description || '暂无描述', status: item.is_draft ? '草稿' : '已发布', avatarSvg: item.avatar_url, raw: item, })), [agentList], ); return (

我的智能体

管理你的专属 AI 专家助手

已加载模型:{llmList.length}

{isListLoading ? (
) : cards.length === 0 ? (

{activeTab === 'mine' ? '暂无我的专家' : '暂无发布的专家'}

创建你的第一个专家助手,开始高效工作

) : (
{cards.map((item, idx) => (
{item.avatarSvg ? ( {item.title} ) : (
{idx % 2 === 0 ? : }
)}

{item.title}

{item.desc}

{activeTab === 'mine' && ( <> delAgentSearch(item.id)} > )} {item.status}
))}
)}

不确定从哪个开始?

直接开始对话,AI 会自动匹配最合适的专家助手

setDetailVisible(false)} confirmBtn={null} cancelBtn={null} header="专家详情" width={520} >
{selectedAgent?.avatar_url ? ( {selectedAgent?.name ) : (
)}

{selectedAgent?.name || '未命名专家'}

{selectedAgent?.description || '暂无描述'}

{selectedAgent?.is_draft ? : } {selectedAgent?.is_draft ? '草稿状态' : '已发布'}
{ void handleStatusToggle(value as boolean); }} />
); }