import { useState } from "react"; import { Terminal } from "lucide-react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Textarea } from "@/components/ui/textarea"; import { AgentSelector } from "@/components/AgentSelector"; import { runCommand, type Agent, type CommandKind } from "@/api"; type Props = { agents: Agent[]; selectedAgentId: string; onSelectAgent: (agentId: string) => void; onAfterCommand?: () => Promise; }; export function CommandsPage({ agents, selectedAgentId, onSelectAgent, onAfterCommand, }: Props) { const [kind, setKind] = useState("devs"); const [query, setQuery] = useState(""); const [output, setOutput] = useState("Select agent and run a command"); const [running, setRunning] = useState(false); async function submit(e: React.FormEvent) { e.preventDefault(); if (!selectedAgentId) return; setRunning(true); setOutput("Running..."); try { const out = await runCommand(selectedAgentId, kind, query.trim()); setOutput(JSON.stringify(out, null, 2)); toast.success(`Command "${kind}" completed`); if (onAfterCommand) await onAfterCommand(); } catch (err) { setOutput(String(err)); toast.error("Command failed", { description: String(err) }); } finally { setRunning(false); } } return ( Command Runner Debug tool: send raw commands to agents and inspect JSON responses