Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: support removing agents
Kyle Mendellc33a872370ce
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelteindex 7425ca056..071712e92 100644--- a/src/routes/+page.svelte+++ b/src/routes/+page.svelte@@ -301,7 +301,7 @@{#if serverStats?.diskTotal && serverStats?.diskUsage !== undefined}{@const storagePercent = Math.min(Math.max((serverStats.diskUsage / serverStats.diskTotal) * 100, 0), 100)}<div class="mb-4">- <Meter label="System Storage" valueLabel="{storagePercent.toFixed(1)}%" value={storagePercent} max={100} variant={storagePercent > 85 ? 'destructive' : storagePercent > 70 ? 'warning' : 'default'} size="sm" />+ <Meter label="System Storage" valueLabel="{storagePercent.toFixed(1)}%" value={storagePercent} max={100} variant={storagePercent > 85 ? 'destructive' : storagePercent > 70 ? 'warning' : 'success'} size="sm" /></div><div class="space-y-1 text-xs text-muted-foreground"><div class="flex justify-between">diff --git a/src/routes/agents/+page.svelte b/src/routes/agents/+page.svelteindex 3d93fd3a1..208360ce4 100644--- a/src/routes/agents/+page.svelte+++ b/src/routes/agents/+page.svelte@@ -1,11 +1,16 @@<script lang="ts">import { onMount } from 'svelte';- import { goto } from '$app/navigation';+ import { goto, invalidateAll } from '$app/navigation';import type { Agent } from '$lib/types/agent.type';import { formatDistanceToNow } from 'date-fns';- import { RefreshCw, AlertCircle, Loader2, Monitor, CheckCircle, Eye, Send, Container, HardDrive, Layers } from '@lucide/svelte';- import type { PageData } from './$types';+ import { RefreshCw, AlertCircle, Loader2, Monitor, CheckCircle, Eye, Send, Container, HardDrive, Trash2 } from '@lucide/svelte';+ import { toast } from 'svelte-sonner';import { getActualAgentStatus } from '$lib/utils/agent-status.utils';+ import { openConfirmDialog } from '$lib/components/confirm-dialog/index.js';+ import { handleApiResultWithCallbacks } from '$lib/utils/api.util.js';+ import { tryCatch } from '$lib/utils/try-catch.js';+ import Button from '$lib/components/ui/button/button.svelte';+ import ArcaneButton from '$lib/components/arcane-button.svelte';let { data } = $props();@@ -65,6 +70,32 @@}}+ async function deleteAgent(agentId: string, hostname: string) {+ openConfirmDialog({+ title: `Confirm Removal`,+ message: `Are you sure you want to remove this Agent? This action cannot be undone.`,+ confirm: {+ label: 'Remove',+ destructive: true,+ action: async () => {+ handleApiResultWithCallbacks({+ result: await tryCatch(+ fetch(`/api/agents/${agentId}`, {+ method: 'DELETE',+ credentials: 'include'+ })+ ),+ message: 'Failed to Remove Agent',+ onSuccess: async () => {+ toast.success('Agent Removed Successfully');+ await invalidateAll();+ }+ });+ }+ }+ });+ }+function getStatusColor(agent: Agent) {const actualStatus = getActualAgentStatus(agent);if (actualStatus === 'online') return 'bg-green-500';@@ -219,16 +250,11 @@<!-- Action Buttons --><div class="mt-4 flex gap-2">- <button onclick={() => viewAgentDetails(agent.id)} class="flex-1 px-3 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 rounded-lg transition-colors flex items-center justify-center gap-2">- <Eye class="h-4 w-4" />- View Details- </button>+ <ArcaneButton action="inspect" onClick={() => viewAgentDetails(agent.id)} label="View Details" class="flex-1" />{#if getActualAgentStatus(agent) === 'online'}- <button onclick={() => viewAgentDetails(agent.id)} class="flex-1 px-3 py-2 text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 rounded-lg transition-colors flex items-center justify-center gap-2">- <Send class="h-4 w-4" />- Manage- </button>+ <ArcaneButton action="edit" onClick={() => viewAgentDetails(agent.id)} label="Manage" class="flex-1" />{/if}+ <ArcaneButton action="remove" onClick={() => deleteAgent(agent.id, agent.hostname)} label="Delete" loadingLabel="Deleting..." class="flex-1" /></div></div>{/each}diff --git a/src/routes/agents/[agentId]/+page.svelte b/src/routes/agents/[agentId]/+page.svelteindex 5ba059c21..a2156c92a 100644--- a/src/routes/agents/[agentId]/+page.svelte+++ b/src/routes/agents/[agentId]/+page.svelte@@ -1,6 +1,6 @@<script lang="ts">import { onMount } from 'svelte';- import { goto } from '$app/navigation';+ import { goto, invalidateAll } from '$app/navigation';import { formatDistanceToNow } from 'date-fns';import { toast } from 'svelte-sonner';import type { Agent, AgentTask } from '$lib/types/agent.type';@@ -16,12 +16,15 @@import { Button } from '$lib/components/ui/button/index.js';import { Input } from '$lib/components/ui/input/index.js';import { Label } from '$lib/components/ui/label/index.js';- import { Monitor, Terminal, Clock, Settings, Activity, AlertCircle, Server, RefreshCw, Play, ArrowLeft, Container, HardDrive, Layers, Network, Database, Loader2, Download } from '@lucide/svelte';+ import { Monitor, Terminal, Clock, Settings, Activity, AlertCircle, Server, RefreshCw, Play, ArrowLeft, Container, HardDrive, Layers, Network, Database, Loader2, Download, Trash2 } from '@lucide/svelte';import StatusBadge from '$lib/components/badges/status-badge.svelte';import ImagePullForm from '$lib/components/forms/ImagePullForm.svelte';import StackDeploymentForm from '$lib/components/forms/StackDeploymentForm.svelte';import QuickContainerForm from '$lib/components/forms/QuickContainerForm.svelte';import { getActualAgentStatus } from '$lib/utils/agent-status.utils';+ import { openConfirmDialog } from '$lib/components/confirm-dialog/index.js';+ import { handleApiResultWithCallbacks } from '$lib/utils/api.util.js';+ import { tryCatch } from '$lib/utils/try-catch.js';let { data } = $props();@@ -67,6 +70,10 @@let containerDialogOpen = $state(false);let deploying = $state(false);+ // Add delete dialog state+ let deleteDialogOpen = $state(false);+ let deleting = $state(false);+// Predefined commandsconst predefinedCommands = [{ value: 'docker_version', label: 'Docker Version' },@@ -384,6 +391,36 @@}}+ async function deleteAgentHandler() {+ if (!agent || deleting) return;++ openConfirmDialog({+ title: `Confirm Removal`,+ message: `Are you sure you want to remove this Agent? This action cannot be undone.`,+ confirm: {+ label: 'Remove',+ destructive: true,+ action: async () => {+ handleApiResultWithCallbacks({+ result: await tryCatch(+ fetch(`/api/agents/${agentId}`, {+ method: 'DELETE',+ credentials: 'include'+ })+ ),+ setLoadingState: (value) => (deleting = value),+ message: 'Failed to Remove Agent',+ onSuccess: async () => {+ toast.success('Agent Removed Successfully');+ await invalidateAll();+ goto('/agents');+ }+ });+ }+ }+ });+ }+function getStatusClasses(agent: Agent) {const actualStatus = getActualAgentStatus(agent);if (actualStatus === 'online') return 'bg-green-100 text-green-800 dark:bg-green-900/20 dark:text-green-400';@@ -534,11 +571,17 @@<ArrowLeft class="size-4 mr-2" />Back to Agents</Button>- {#if agent && getActualAgentStatus(agent) === 'online'}- <Button onclick={() => (commandDialogOpen = true)} disabled={taskExecuting}>- <Terminal class="size-4 mr-2" />- Send Command+ {#if agent}+ <Button variant="destructive" onclick={deleteAgentHandler} disabled={deleting}>+ <Trash2 class="size-4 mr-2" />+ Delete Agent</Button>+ {#if getActualAgentStatus(agent) === 'online'}+ <Button onclick={() => (commandDialogOpen = true)} disabled={taskExecuting}>+ <Terminal class="size-4 mr-2" />+ Send Command+ </Button>+ {/if}{/if}</div></div>diff --git a/src/routes/api/agents/[agentId]/+server.ts b/src/routes/api/agents/[agentId]/+server.tsindex 765171dd2..c90f062d9 100644--- a/src/routes/api/agents/[agentId]/+server.ts+++ b/src/routes/api/agents/[agentId]/+server.ts@@ -1,6 +1,6 @@import { json } from '@sveltejs/kit';import type { RequestHandler } from './$types';-import { getAgent } from '$lib/services/agent/agent-manager';+import { getAgent, deleteAgent } from '$lib/services/agent/agent-manager';import { updateAgentHeartbeat } from '$lib/services/agent/agent-manager';export const GET: RequestHandler = async ({ locals, params }) => {@@ -28,8 +28,15 @@ export const DELETE: RequestHandler = async ({ locals, params }) => {}try {- // TODO: Implement agent deletion- return json({ success: true });+ const agent = await getAgent(params.agentId);+ if (!agent) {+ return json({ error: 'Agent not found' }, { status: 404 });+ }++ await deleteAgent(params.agentId);+ console.log(`Agent ${params.agentId} deleted successfully`);++ return json({ success: true, message: 'Agent deleted successfully' });} catch (error) {console.error('Error deleting agent:', error);return json({ error: 'Failed to delete agent' }, { status: 500 });