import { useState } from 'react' import { Plus, Trash2, Edit } from 'lucide-react' import { Button } from '@/components/ui/button' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Dialog, DialogTrigger } from '@/components/ui/dialog' import { CommandDialog } from './CommandDialog' interface Command { template: string description?: string agent?: string model?: string subtask?: boolean topP?: number } interface CommandsEditorProps { commands: Record onChange: (commands: Record) => void } export function CommandsEditor({ commands, onChange }: CommandsEditorProps) { const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false) const [editingCommand, setEditingCommand] = useState<{ name: string; command: Command } | null>(null) const handleCommandSubmit = (name: string, command: Command) => { if (editingCommand) { const updatedCommands = { ...commands } delete updatedCommands[editingCommand.name] updatedCommands[name] = command onChange(updatedCommands) setEditingCommand(null) } else { const updatedCommands = { ...commands, [name]: command } onChange(updatedCommands) } } const deleteCommand = (name: string) => { const updatedCommands = { ...commands } delete updatedCommands[name] onChange(updatedCommands) } const startEdit = (name: string, command: Command) => { setEditingCommand({ name, command }) } return (

Commands

{Object.keys(commands).length === 0 ? (

No commands configured. Add your first command to get started.

) : (
{Object.entries(commands).map(([name, command]) => (
/{name}
{command.description && (

{command.description}

)}
{command.agent &&

Agent: {command.agent}

} {command.model &&

Model: {command.model}

} {command.topP !== undefined &&

Top P: {command.topP}

} {command.subtask &&

Subtask: Yes

}
{command.template}
))}
)} setEditingCommand(null)} onSubmit={handleCommandSubmit} editingCommand={editingCommand} />
) }