diff --git a/app/agent-factory/page.tsx b/app/agent-factory/page.tsx index 41b8d6c..1061d13 100644 --- a/app/agent-factory/page.tsx +++ b/app/agent-factory/page.tsx @@ -7,7 +7,7 @@ import { DashboardLayout } from "@/components/dashboard-layout" import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Badge } from "@/components/ui/badge" -import { Bot, Cpu, MemoryStick, Zap, Square, Loader2 } from "lucide-react" +import { Bot, Cpu, MemoryStick, Zap, Trash2, Loader2 } from "lucide-react" import { useLanguage } from "@/hooks/useLanguage" import { TaijiAPIClient } from "@/lib/api-client" import { useToast } from "@/hooks/use-toast" @@ -41,10 +41,10 @@ export default function AgentFactoryPage() { const [stats, setStats] = useState({ cpu: 0, memory: 0 }) // 已部署的平台 Agent 实例列表 const [deployedInstances, setDeployedInstances] = useState([]) - // 停止 Agent 相关状态 - const [showStopDialog, setShowStopDialog] = useState(false) - const [agentToStop, setAgentToStop] = useState(null) - const [stopping, setStopping] = useState(false) + // 删除 Agent 相关状态 + const [showDeleteDialog, setShowDeleteDialog] = useState(false) + const [agentToDelete, setAgentToDelete] = useState(null) + const [deleting, setDeleting] = useState(false) // 将CPU格式(如"500m"、"250m"、"4000m")转换为核数(如0.5、0.25、4) // 支持范围:250m-4000m (0.25-4核) @@ -167,39 +167,39 @@ export default function AgentFactoryPage() { setShowDeployDialog(true) } - // 打开停止确认对话框 - const handleStopClick = (instance: any) => { - setAgentToStop(instance) - setShowStopDialog(true) + // 打开删除确认对话框 + const handleDeleteClick = (instance: any) => { + setAgentToDelete(instance) + setShowDeleteDialog(true) } - // 确认停止平台 Agent - const handleConfirmStop = async () => { - if (!agentToStop) return + // 确认删除平台 Agent + const handleConfirmDelete = async () => { + if (!agentToDelete) return try { - setStopping(true) - const result = await TaijiAPIClient.stopUserPlatformAgent(agentToStop.name || agentToStop.instanceName) + setDeleting(true) + const result = await TaijiAPIClient.deleteUserPlatformAgent(agentToDelete.name || agentToDelete.instanceName) if (result?.success) { toast({ - title: t("停止成功", "Stop Successful"), - description: result.message || t("Agent 已停止", "Agent has been stopped"), + title: t("删除成功", "Delete Successful"), + description: result.message || t("Agent 已删除", "Agent has been deleted"), }) - setShowStopDialog(false) - setAgentToStop(null) + setShowDeleteDialog(false) + setAgentToDelete(null) loadAgents() // 重新加载数据 } else { - throw new Error(result?.detail || result?.message || "Stop failed") + throw new Error(result?.detail || result?.message || "Delete failed") } } catch (error: any) { toast({ - title: t("停止失败", "Stop Failed"), - description: error.message || t("无法停止 Agent", "Failed to stop agent"), + title: t("删除失败", "Delete Failed"), + description: error.message || t("无法删除 Agent", "Failed to delete agent"), variant: "destructive", }) } finally { - setStopping(false) + setDeleting(false) } } @@ -495,11 +495,10 @@ export default function AgentFactoryPage() { variant="outline" size="sm" className="gap-1.5 text-red-500 hover:text-red-600 hover:bg-red-500/10 border-red-200" - onClick={() => handleStopClick(instance)} - disabled={instance.status !== "Running" && instance.status !== "Pending"} + onClick={() => handleDeleteClick(instance)} > - - {t("停止", "Stop")} + + {t("删除", "Delete")} @@ -669,37 +668,37 @@ export default function AgentFactoryPage() { - {/* 停止Agent确认对话框 */} - + {/* 删除Agent确认对话框 */} + - {t("确认停止 Agent", "Confirm Stop Agent")} + {t("确认删除 Agent", "Confirm Delete Agent")} {t( - "停止后将释放 Pod 配额并结算费用,此操作不可撤销。", - "Stopping will release Pod quota and settle billing. This action cannot be undone." + "删除后将释放 Pod 配额并结算费用,此操作不可撤销。", + "Deleting will release Pod quota and settle billing. This action cannot be undone." )} - {agentToStop && ( + {agentToDelete && (
{t("实例名称", "Instance Name")}: - {agentToStop.name || agentToStop.instanceName} + {agentToDelete.name || agentToDelete.instanceName}
- {agentToStop.templateName && ( + {agentToDelete.templateName && (
{t("模板", "Template")}: - {agentToStop.templateName} + {agentToDelete.templateName}
)}
{t("状态", "Status")}: - - {agentToStop.status} + + {agentToDelete.status}
@@ -709,28 +708,28 @@ export default function AgentFactoryPage() { diff --git a/lib/api-client.ts b/lib/api-client.ts index 229d139..b55ead3 100644 --- a/lib/api-client.ts +++ b/lib/api-client.ts @@ -2759,19 +2759,28 @@ export class TaijiAPIClient { } /** - * 停止Agent实例(租户) - * DELETE /api/user/platform-agents/{instance_name} + * 删除平台 Agent 实例(租户) + * DELETE /api/user/platform-agents/{agent_name} * - * @param instanceName - Agent实例名称 + * 删除用户正在运行的平台 Agent 实例,释放 Pod 配额,结算费用 + * + * @param agentName - 平台 Agent 实例名称(Pod 名称) */ - static async stopUserPlatformAgent(instanceName: string) { - const response = await fetch(`${API_BASE_URLS.mcpServer}/api/user/platform-agents/${instanceName}`, { + static async deleteUserPlatformAgent(agentName: string) { + const response = await fetch(`${API_BASE_URLS.mcpServer}/api/user/platform-agents/${agentName}`, { method: "DELETE", headers: buildHeaders(), }) return handleResponse(response) } + /** + * @deprecated 使用 deleteUserPlatformAgent 替代 + */ + static async stopUserPlatformAgent(instanceName: string) { + return this.deleteUserPlatformAgent(instanceName) + } + /** * 获取自定义Agent配额(租户) * GET /api/user/custom-agent-quota