'use client' import React, { useState } from 'react' import { ModalBase } from './ModalBase' import { apiFetch } from '../_api' import type { LLMPolicy } from '../_types' export function PolicyModal({ existing, onClose, onSaved }: { existing: LLMPolicy | null; onClose: () => void; onSaved: () => void }) { const [form, setForm] = useState({ name: existing?.name || '', description: existing?.description || '', allowed_models: (existing?.allowed_models || []).join(', '), blocked_models: (existing?.blocked_models || []).join(', '), rate_limit_rpm: existing?.rate_limit_rpm ?? 60, rate_limit_tpd: existing?.rate_limit_tpd ?? 1000000, max_tokens_per_request: existing?.max_tokens_per_request ?? 4096, pii_detection_required: existing?.pii_detection_required ?? true, pii_redaction_required: existing?.pii_redaction_required ?? false, is_active: existing?.is_active ?? true, }) const [saving, setSaving] = useState(false) const [error, setError] = useState(null) const handleSubmit = async () => { if (!form.name) { setError('Name ist Pflichtfeld'); return } setSaving(true) try { const body = { ...form, allowed_models: form.allowed_models.split(',').map(s => s.trim()).filter(Boolean), blocked_models: form.blocked_models.split(',').map(s => s.trim()).filter(Boolean), } if (existing) { await apiFetch(`llm/policies/${existing.id}`, { method: 'PUT', body: JSON.stringify(body) }) } else { await apiFetch('llm/policies', { method: 'POST', body: JSON.stringify(body) }) } onSaved() } catch (e) { setError(e instanceof Error ? e.message : 'Fehler') } finally { setSaving(false) } } return ( {error &&
{error}
}
setForm(f => ({ ...f, name: e.target.value }))} className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm" />
setForm(f => ({ ...f, description: e.target.value }))} className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm" />
setForm(f => ({ ...f, allowed_models: e.target.value }))} placeholder="qwen3:30b-a3b, claude-sonnet-4-5" className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm font-mono" />
setForm(f => ({ ...f, blocked_models: e.target.value }))} className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm font-mono" />
setForm(f => ({ ...f, rate_limit_rpm: +e.target.value }))} className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm" />
setForm(f => ({ ...f, rate_limit_tpd: +e.target.value }))} className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm" />
setForm(f => ({ ...f, max_tokens_per_request: +e.target.value }))} className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm" />
) }