diff --git a/frontend/js/admin/sections/assistant.js b/frontend/js/admin/sections/assistant.js index e6e0e8b..1f00033 100644 --- a/frontend/js/admin/sections/assistant.js +++ b/frontend/js/admin/sections/assistant.js @@ -84,15 +84,18 @@ '
' + '
' + '
' + - '
Добавить провайдера
' + - '
Пресет
' + - '' + - '
Название
' + - '
URL (chat/completions)
' + - '' + - '
Модель
' + - '
API-ключ
' + - '
'; + '' + + ''; host.appendChild(pc); // ── Настройки/статистика ── @@ -137,7 +140,8 @@ ''; }).join(''); - function clearForm() { editingId = null; Q('#asst-fhead').textContent = 'Добавить провайдера'; Q('#asst-name').value = ''; Q('#asst-url').value = ''; Q('#asst-model').value = ''; Q('#asst-key').value = ''; Q('#asst-key').placeholder = 'ключ'; Q('#asst-cancel').style.display = 'none'; toggleKilo(); } + function openForm(show) { Q('#asst-form').style.display = show ? 'flex' : 'none'; } + function clearForm() { editingId = null; Q('#asst-fhead').textContent = 'Новый провайдер'; Q('#asst-preset').value = ''; Q('#asst-name').value = ''; Q('#asst-url').value = ''; Q('#asst-model').value = ''; Q('#asst-key').value = ''; Q('#asst-key').placeholder = 'ключ'; toggleKilo(); openForm(false); } function toggleKilo() { var isKilo = /kilocode\.ai/.test(Q('#asst-url').value || ''); Q('#asst-kbox').style.display = isKilo ? '' : 'none'; @@ -163,7 +167,7 @@ editingId = id; Q('#asst-fhead').textContent = 'Изменить: ' + (p.name || ''); Q('#asst-name').value = p.name || ''; Q('#asst-url').value = p.url || ''; Q('#asst-model').value = p.model || ''; Q('#asst-key').value = ''; Q('#asst-key').placeholder = p.hasKey ? 'ключ сохранён — введите новый, чтобы заменить' : 'ключ'; - Q('#asst-cancel').style.display = ''; toggleKilo(); Q('#asst-name').focus(); + toggleKilo(); openForm(true); Q('#asst-form').scrollIntoView({ behavior: 'smooth', block: 'nearest' }); Q('#asst-name').focus(); } else if (act === 'test') { var res = Q('#asst-ptest'); res.innerHTML = 'Проверяю…'; try { var r = await LS.adminTestAssistant({ id: id }); res.innerHTML = r && r.ok ? '✓ Работает (' + esc(r.model || '') + '): ' + esc(String(r.sample || 'ответ получен')) + '' : '✗ ' + esc(String((r && (r.error || ('HTTP ' + r.status))) || 'ошибка').slice(0, 200)) + ''; } catch (e) { res.innerHTML = '✗ ' + esc(e.message || 'ошибка') + ''; } @@ -172,6 +176,7 @@ }); // форма + Q('#asst-ftoggle').addEventListener('click', function () { var open = Q('#asst-form').style.display !== 'none'; if (open) { clearForm(); } else { clearForm(); openForm(true); Q('#asst-name').focus(); } }); Q('#asst-preset').addEventListener('change', function () { var p = presets[Number(this.value)]; if (p) { Q('#asst-url').value = p.url; Q('#asst-model').value = p.model; if (!Q('#asst-name').value) Q('#asst-name').value = p.name; toggleKilo(); } }); Q('#asst-url').addEventListener('input', toggleKilo); Q('#asst-kmodels').addEventListener('change', function () { Q('#asst-model').value = this.value; });