将平台 Agent '停止'功能改为'删除'功能,对接 DELETE /api/user/platform-agents/{agent_name} 接口

This commit is contained in:
zhanggangyong
2026-01-22 03:38:50 +00:00
parent a3a3d66239
commit c81d1c813d
2 changed files with 59 additions and 51 deletions
+45 -46
View File
@@ -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<any[]>([])
// 停止 Agent 相关状态
const [showStopDialog, setShowStopDialog] = useState(false)
const [agentToStop, setAgentToStop] = useState<any>(null)
const [stopping, setStopping] = useState(false)
// 删除 Agent 相关状态
const [showDeleteDialog, setShowDeleteDialog] = useState(false)
const [agentToDelete, setAgentToDelete] = useState<any>(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)}
>
<Square className="h-3.5 w-3.5" />
{t("停止", "Stop")}
<Trash2 className="h-3.5 w-3.5" />
{t("删除", "Delete")}
</Button>
</div>
</div>
@@ -669,37 +668,37 @@ export default function AgentFactoryPage() {
</DialogContent>
</Dialog>
{/* 停止Agent确认对话框 */}
<Dialog open={showStopDialog} onOpenChange={setShowStopDialog}>
{/* 删除Agent确认对话框 */}
<Dialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
<DialogContent>
<DialogHeader>
<DialogTitle className="text-red-500">
{t("确认停止 Agent", "Confirm Stop Agent")}
{t("确认删除 Agent", "Confirm Delete Agent")}
</DialogTitle>
<DialogDescription>
{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."
)}
</DialogDescription>
</DialogHeader>
{agentToStop && (
{agentToDelete && (
<div className="rounded-lg bg-muted p-4 space-y-2">
<div className="flex items-center gap-2">
<span className="text-sm text-muted-foreground">{t("实例名称", "Instance Name")}:</span>
<span className="font-medium">{agentToStop.name || agentToStop.instanceName}</span>
<span className="font-medium">{agentToDelete.name || agentToDelete.instanceName}</span>
</div>
{agentToStop.templateName && (
{agentToDelete.templateName && (
<div className="flex items-center gap-2">
<span className="text-sm text-muted-foreground">{t("模板", "Template")}:</span>
<span>{agentToStop.templateName}</span>
<span>{agentToDelete.templateName}</span>
</div>
)}
<div className="flex items-center gap-2">
<span className="text-sm text-muted-foreground">{t("状态", "Status")}:</span>
<Badge variant={agentToStop.status === "Running" ? "default" : "secondary"}>
{agentToStop.status}
<Badge variant={agentToDelete.status === "Running" ? "default" : "secondary"}>
{agentToDelete.status}
</Badge>
</div>
</div>
@@ -709,28 +708,28 @@ export default function AgentFactoryPage() {
<Button
variant="outline"
onClick={() => {
setShowStopDialog(false)
setAgentToStop(null)
setShowDeleteDialog(false)
setAgentToDelete(null)
}}
disabled={stopping}
disabled={deleting}
>
{t("取消", "Cancel")}
</Button>
<Button
variant="destructive"
onClick={handleConfirmStop}
disabled={stopping}
onClick={handleConfirmDelete}
disabled={deleting}
className="gap-2"
>
{stopping ? (
{deleting ? (
<>
<Loader2 className="h-4 w-4 animate-spin" />
{t("停止中...", "Stopping...")}
{t("删除中...", "Deleting...")}
</>
) : (
<>
<Square className="h-4 w-4" />
{t("确认停止", "Confirm Stop")}
<Trash2 className="h-4 w-4" />
{t("确认删除", "Confirm Delete")}
</>
)}
</Button>
+14 -5
View File
@@ -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