import { tr } from '../lib/i18n'; import { useRef, useState } from 'react'; import { Btn, Icon, Select } from './ui'; import { draftParams, readConfig, type ConfigDocument } from '../lib/config'; import type { EngineConfig, ExpertParam } from '../lib/types'; export function RunExpertEditor({ engine, config, text, onChange, onText, onRestore, onError }: { engine: EngineConfig; config: ConfigDocument | null; text: string; onChange: (config: ConfigDocument) => void; onText: (text: string) => void; onRestore: () => void; onError: (message: string) => void; }) { const [tab, setTab] = useState('parameters'); const [query, setQuery] = useState(''); const [group, setGroup] = useState('all'); const [changedOnly, setChangedOnly] = useState(false); const [unsupported, setUnsupported] = useState(false); const [descriptions, setDescriptions] = useState(false); const file = useRef(null); const params = config ? draftParams(engine, config) : []; const changed = params.filter(p => p.value !== p.recommended); const groups = [...new Set(params.map(p => p.group))]; const rows = params.filter(p => p.id !== 'server.host' && (unsupported || !!p.applies && !p.applies.startsWith('Preserved'))) .filter(p => (group === 'all' || p.group === group) && (!changedOnly || p.value !== p.recommended) && `${p.label} ${p.id} ${p.effect}`.toLowerCase().includes(query.toLowerCase())); function changeParam(id: string, value: ExpertParam['value']) { if (!config) return; const next: ConfigDocument = { ...config, beginner: { ...config.beginner }, expert: { ...config.expert, [id]: value } }; if (id === 'ctx.length') next.beginner.contextLength = String(value).toLowerCase() as ConfigDocument['beginner']['contextLength']; if (id === 'perf.batch') next.batchAutomatic = false; onChange(next); } function download() { const url = URL.createObjectURL(new Blob([text], { type: 'application/json' })); const link = document.createElement('a'); link.href = url; link.download = 'strata-run-config.json'; link.click(); URL.revokeObjectURL(url); } return

{tr("Expert settings")}

{tr(changed.length)}{tr(" custom values")}
{tr(['parameters', 'json'].map(item => ))}
{tr(tab === 'json' ?
{tr("One configuration for every control.")}{tr("Export")} file.current?.click()}>{tr("Import")}