"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { Plus, Trash2, Swords, Pickaxe, Bot, Loader2, LayoutGrid, List, GitBranch, Network, } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Table, TableHeader, TableBody, TableHead, TableRow, TableCell, } from "@/components/ui/table"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, } from "@/components/ui/dialog"; import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs"; import { useAutomations, useAutomationStatuses, useDeleteAutomation, } from "@/hooks/use-automations"; import { useWorkflows } from "@/hooks/use-workflows"; import { usePipelines } from "@/hooks/use-pipelines"; import { RunControls } from "@/components/automation/run-controls"; import { AutomationGallery } from "@/components/automation/automation-gallery"; import { WorkflowList } from "@/components/workflow/workflow-list"; import { WorkflowTemplateGallery } from "@/components/workflow/workflow-template-gallery"; import { PipelineList } from "@/components/pipeline/pipeline-list"; import { PipelineTemplateGallery } from "@/components/pipeline/pipeline-template-gallery"; import { toast } from "sonner"; import { cn } from "@/lib/utils"; const STRATEGY_ICONS: Record = { combat: , gathering: , crafting: , trading: , task: , leveling: , }; const STRATEGY_COLORS: Record = { combat: "text-red-400", gathering: "text-green-400", crafting: "text-blue-400", trading: "text-yellow-400", task: "text-purple-400", leveling: "text-cyan-400", }; export default function AutomationsPage() { const router = useRouter(); const { data: automations, isLoading, error } = useAutomations(); const { data: statuses } = useAutomationStatuses(); const { data: workflows } = useWorkflows(); const { data: pipelines } = usePipelines(); const deleteMutation = useDeleteAutomation(); const [deleteTarget, setDeleteTarget] = useState<{ id: number; name: string; } | null>(null); const statusMap = new Map( (statuses ?? []).map((s) => [s.config_id, s]) ); function handleDelete() { if (!deleteTarget) return; deleteMutation.mutate(deleteTarget.id, { onSuccess: () => { toast.success(`Automation "${deleteTarget.name}" deleted`); setDeleteTarget(null); }, onError: (err) => { toast.error(`Failed to delete: ${err.message}`); }, }); } return (

Automations

Manage automated strategies for your characters

Gallery My Automations {automations && automations.length > 0 && ( {automations.length} )} Workflows {workflows && workflows.length > 0 && ( {workflows.length} )} Pipelines {pipelines && pipelines.length > 0 && ( {pipelines.length} )} {error && (

Failed to load automations. Make sure the backend is running.

)} {isLoading && (
)} {automations && automations.length === 0 && !isLoading && (

No automations configured yet. Pick one from the Gallery or create a custom one.

)} {automations && automations.length > 0 && ( Name Character Strategy Status / Controls {automations.map((automation) => { const status = statusMap.get(automation.id); const currentStatus = status?.status ?? "stopped"; const actionsCount = status?.actions_count ?? 0; return ( router.push(`/automations/${automation.id}`) } > {automation.name} {automation.character_name}
{STRATEGY_ICONS[automation.strategy_type] ?? ( )} {automation.strategy_type}
e.stopPropagation()}> e.stopPropagation()}>
); })}
)}
!open && setDeleteTarget(null)} > Delete Automation Are you sure you want to delete “{deleteTarget?.name} ”? This action cannot be undone. Any running automation will be stopped.
); }