import React, { useState } from "react"; import { Button } from "@/components/ui/button"; import { Label } from "@/components/ui/label"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { type CreateInstanceOptions } from "@/types/instance"; import { backendsApi } from "@/lib/api"; import { toast } from "sonner"; interface ParseCommandDialogProps { open: boolean; onOpenChange: (open: boolean) => void; onParsed: (options: CreateInstanceOptions) => void; } const ParseCommandDialog: React.FC = ({ open, onOpenChange, onParsed, }) => { const [command, setCommand] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const handleParse = async () => { if (!command.trim()) { setError("Command cannot be empty"); return; } setLoading(true); setError(null); try { const options = await backendsApi.llamaCpp.parseCommand(command); onParsed(options); onOpenChange(false); // Reset form setCommand(''); setError(null); // Show success toast toast.success('Command parsed successfully'); } catch (err) { const errorMessage = err instanceof Error ? err.message : 'Failed to parse command'; setError(errorMessage); // Show error toast toast.error('Failed to parse command', { description: errorMessage }); } finally { setLoading(false); } }; const handleOpenChange = (open: boolean) => { if (!open) { // Reset form when closing setCommand(''); setError(null); } onOpenChange(open); }; return ( Parse Llama Server Command Paste your llama-server command to automatically populate the form fields