From 5e97eb40cb4c05791e3b8472c6a9aa2996760388 Mon Sep 17 00:00:00 2001 From: xiaohei Date: Fri, 9 Jan 2026 16:17:21 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89Agent=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在工具注册表下方添加自定义Agent管理卡片 - 支持查看自定义Agent列表(名称、模板、状态、CPU、内存、运行时间) - 支持停止运行中的Agent - 支持重启/启动Agent - 支持删除Agent(带确认提示) - 添加刷新按钮手动更新列表 - 添加API方法:getUserCustomAgents, deleteCustomAgent, stopCustomAgent, restartCustomAgent --- app/data-tools/page.tsx | 208 +++++++++++++++++++++++++++++++++++++++- lib/api-client.ts | 50 ++++++++++ 2 files changed, 257 insertions(+), 1 deletion(-) diff --git a/app/data-tools/page.tsx b/app/data-tools/page.tsx index 7e5d463..1a6a7b2 100644 --- a/app/data-tools/page.tsx +++ b/app/data-tools/page.tsx @@ -12,7 +12,7 @@ import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Badge } from "@/components/ui/badge" import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" -import { Plus, Search, ExternalLink, Trash2, FileJson, Cloud, Cpu, Code2, Boxes, Workflow, Upload } from "lucide-react" +import { Plus, Search, ExternalLink, Trash2, FileJson, Cloud, Cpu, Code2, Boxes, Workflow, Upload, RefreshCw, Square, Play, Bot } from "lucide-react" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" import { Dialog, @@ -47,10 +47,16 @@ export default function DataToolsPage() { const [selectedServiceGateway, setSelectedServiceGateway] = useState("") const [selectedDataTemplate, setSelectedDataTemplate] = useState("") const [dataTemplates, setDataTemplates] = useState([]) + + // 自定义Agent管理状态 + const [customAgents, setCustomAgents] = useState([]) + const [customAgentsLoading, setCustomAgentsLoading] = useState(true) + const [actionLoading, setActionLoading] = useState(null) useEffect(() => { loadTools() loadStats() + loadCustomAgents() }, []) const loadTools = async () => { @@ -84,6 +90,88 @@ export default function DataToolsPage() { } } + // 加载自定义Agent列表 + const loadCustomAgents = async () => { + try { + setCustomAgentsLoading(true) + const result = await TaijiAPIClient.getUserCustomAgents() + if (result?.success && result.data?.agents) { + setCustomAgents(result.data.agents) + } + } catch (error) { + console.error("Failed to load custom agents:", error) + } finally { + setCustomAgentsLoading(false) + } + } + + // 删除自定义Agent + const handleDeleteCustomAgent = async (agentName: string) => { + if (!confirm(t(`确定要删除Agent "${agentName}" 吗?此操作不可恢复。`, `Are you sure you want to delete agent "${agentName}"? This action cannot be undone.`))) { + return + } + try { + setActionLoading(agentName) + const result = await TaijiAPIClient.deleteCustomAgent(agentName) + if (result?.success) { + loadCustomAgents() + } + } catch (error) { + console.error("Failed to delete custom agent:", error) + } finally { + setActionLoading(null) + } + } + + // 停止自定义Agent + const handleStopCustomAgent = async (agentName: string) => { + if (!confirm(t(`确定要停止Agent "${agentName}" 吗?`, `Are you sure you want to stop agent "${agentName}"?`))) { + return + } + try { + setActionLoading(agentName) + const result = await TaijiAPIClient.stopCustomAgent(agentName) + if (result?.success) { + loadCustomAgents() + } + } catch (error) { + console.error("Failed to stop custom agent:", error) + } finally { + setActionLoading(null) + } + } + + // 重启自定义Agent + const handleRestartCustomAgent = async (agentName: string) => { + try { + setActionLoading(agentName) + const result = await TaijiAPIClient.restartCustomAgent(agentName) + if (result?.success) { + loadCustomAgents() + } + } catch (error) { + console.error("Failed to restart custom agent:", error) + } finally { + setActionLoading(null) + } + } + + // 获取状态颜色 + const getStatusColor = (status: string) => { + switch (status?.toLowerCase()) { + case "running": + return "bg-green-500/10 text-green-500" + case "stopped": + return "bg-gray-500/10 text-gray-500" + case "pending": + return "bg-yellow-500/10 text-yellow-500" + case "failed": + return "bg-red-500/10 text-red-500" + default: + return "bg-gray-500/10 text-gray-500" + } + } + return ( @@ -239,6 +327,124 @@ export default function DataToolsPage() { + + {/* 自定义Agent管理 */} + + +
+
+ + + {t("自定义Agent管理", "Custom Agent Management")} + + + {t("管理已部署的自定义Agent,支持停止、重启和删除操作", "Manage deployed custom agents with stop, restart and delete operations")} + +
+ +
+
+ + + + + {t("Agent名称", "Agent Name")} + {t("模板", "Template")} + {t("状态", "Status")} + {t("CPU", "CPU")} + {t("内存", "Memory")} + {t("运行时间", "Runtime")} + {t("操作", "Actions")} + + + + {customAgentsLoading ? ( + + + {t("加载中...", "Loading...")} + + + ) : customAgents.length === 0 ? ( + + + {t("暂无自定义Agent", "No custom agents")} + + + ) : ( + customAgents.map((agent) => ( + + {agent.name} + + {agent.template || "-"} + + + + {agent.status || "Unknown"} + + + {agent.cpu || "-"} + {agent.memory || "-"} + + {agent.runningSeconds + ? `${Math.floor(agent.runningSeconds / 3600)}h ${Math.floor((agent.runningSeconds % 3600) / 60)}m` + : "-" + } + + +
+ {agent.status?.toLowerCase() === "running" ? ( + <> + + + + ) : ( + + )} + +
+
+
+ )) + )} +
+
+
+
diff --git a/lib/api-client.ts b/lib/api-client.ts index 9c76ed1..46fbf92 100644 --- a/lib/api-client.ts +++ b/lib/api-client.ts @@ -519,6 +519,56 @@ export class TaijiAPIClient { return handleResponse(response) } + /** + * 获取用户自定义Agent列表(别名) + * GET /api/user/custom-agents + */ + static async getUserCustomAgents() { + return this.getCustomAgents() + } + + /** + * 删除自定义Agent + * DELETE /api/user/custom-agents/{name} + * + * @param agentName - Agent名称 + */ + static async deleteCustomAgent(agentName: string) { + const response = await fetch(`${API_BASE_URLS.mcpServer}/api/user/custom-agents/${agentName}`, { + method: "DELETE", + headers: buildHeaders(), + }) + return handleResponse(response) + } + + /** + * 停止自定义Agent + * POST /api/user/custom-agents/{name}/stop + * + * @param agentName - Agent名称 + */ + static async stopCustomAgent(agentName: string) { + const response = await fetch(`${API_BASE_URLS.mcpServer}/api/user/custom-agents/${agentName}/stop`, { + method: "POST", + headers: buildHeaders(), + }) + return handleResponse(response) + } + + /** + * 重启自定义Agent + * POST /api/user/custom-agents/{name}/restart + * + * @param agentName - Agent名称 + */ + static async restartCustomAgent(agentName: string) { + const response = await fetch(`${API_BASE_URLS.mcpServer}/api/user/custom-agents/${agentName}/restart`, { + method: "POST", + headers: buildHeaders(), + }) + return handleResponse(response) + } + /** * 获取工作流列表 * GET /api/user/workflows/list