import { useState } from 'react' import { Plus } from 'lucide-react' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { Dialog, DialogTrigger } from '@/components/ui/dialog' import { SettingsList, SettingsListRow } from '@/components/ui/settings-list' import { CommandDialog } from './CommandDialog' import { UploadFolderButton } from './UploadFolderButton' import { DirectoryFilesList } from './DirectoryFilesList' import type { OpenCodeDirectoryFileInfo } from '@/api/types/settings' interface Command { template: string description?: string agent?: string model?: string subtask?: boolean topP?: number } interface CommandsEditorProps { commands: Record directoryCommands?: OpenCodeDirectoryFileInfo[] onChange: (commands: Record) => void } export function CommandsEditor({ commands, directoryCommands = [], onChange }: CommandsEditorProps) { const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false) const [editingCommand, setEditingCommand] = useState<{ name: string; command: Command } | null>(null) const hasCommands = Object.keys(commands).length > 0 || directoryCommands.length > 0 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) setIsCreateDialogOpen(false) } } const deleteCommand = (name: string) => { const updatedCommands = { ...commands } delete updatedCommands[name] onChange(updatedCommands) } const startEdit = (name: string, command: Command) => { setEditingCommand({ name, command }) } return (
{Object.entries(commands).map(([name, command]) => ( {command.agent} } onClick={() => startEdit(name, command)} primaryAction={{ label: 'Edit', onClick: () => startEdit(name, command) }} actions={[{ label: 'Delete', destructive: true, onClick: () => deleteCommand(name) }]} actionsLabel={`Actions for ${name}`} /> ))} setEditingCommand(null)} onSubmit={handleCommandSubmit} editingCommand={editingCommand} />
) }