/** * AgentEditModal * Modal for editing AI agent settings * ADR-024: AI Chat improvements */ import { logger } from '@/shared/utils/logger'; import { useState, useEffect } from 'react'; import { Modal, Button, Input } from '@/shared/components/ui'; import { Loader2 } from 'lucide-react'; import { apiClient } from '@/shared/utils/apiClient'; import type { AIAgent } from '../types'; interface AgentEditModalProps { isOpen: boolean; onClose: () => void; agent: AIAgent | null; // Pass agent data directly onSave?: () => void; } interface AgentFormData { name: string; description: string; icon: string; system_prompt: string; is_active: boolean; } export function AgentEditModal({ isOpen, onClose, agent, onSave }: AgentEditModalProps) { const [formData, setFormData] = useState({ name: '', description: '', icon: 'πŸ€–', system_prompt: '', is_active: true, }); const [isSaving, setIsSaving] = useState(false); const [error, setError] = useState(null); // Initialize form data from agent prop useEffect(() => { if (isOpen && agent) { setFormData({ name: agent.name || '', description: agent.description || '', icon: agent.icon || 'πŸ€–', system_prompt: agent.system_prompt || '', is_active: agent.is_active ?? true, }); setError(null); } }, [isOpen, agent]); const handleSave = async () => { if (!agent) return; setIsSaving(true); setError(null); try { await apiClient.put(`/ai/agents/${agent.id}`, formData); onSave?.(); onClose(); } catch (err) { setError('Ошибка сохранСния'); logger.error('Failed to save agent:', err); } finally { setIsSaving(false); } }; const handleChange = (field: keyof AgentFormData, value: string | boolean) => { setFormData(prev => ({ ...prev, [field]: value })); }; if (!agent) return null; return ( !open && onClose()} title="Π Π΅Π΄Π°ΠΊΡ‚ΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ Π°Π³Π΅Π½Ρ‚Π°" size="md" primaryAction={{ label: isSaving ? 'Π‘ΠΎΡ…Ρ€Π°Π½Π΅Π½ΠΈΠ΅...' : 'Π‘ΠΎΡ…Ρ€Π°Π½ΠΈΡ‚ΡŒ', onClick: handleSave, variant: 'primary', }} secondaryAction={{ label: 'ΠžΡ‚ΠΌΠ΅Π½Π°', onClick: onClose, variant: 'ghost', }} >
{error && (
{error}
)} {/* Icon + Name row */}
handleChange('icon', e.target.value)} className="w-14 h-10 text-center text-2xl rounded-lg bg-[var(--bg-tertiary)] border border-[var(--border-secondary)] focus:outline-none focus:ring-2 focus:ring-[var(--color-primary-500)]/30" maxLength={4} />
handleChange('name', e.target.value)} placeholder="НапримСр: ΠŸΠΎΠΌΠΎΡ‰Π½ΠΈΠΊ" />
{/* Description */}
handleChange('description', e.target.value)} placeholder="ΠšΡ€Π°Ρ‚ΠΊΠΎΠ΅ описаниС Π°Π³Π΅Π½Ρ‚Π°" />
{/* System prompt */}