feat: explain-archive LLM endpoint + UI button v1.3.40
This commit is contained in:
@@ -75,6 +75,53 @@ function lintArchiveFile(prefix) {
|
||||
});
|
||||
}
|
||||
|
||||
// explainArchiveFile — отправляет zip-архив на /console/api/ai/explain-archive,
|
||||
// показывает ответ LLM в блоке {prefix}-ai-result.
|
||||
function explainArchiveFile(prefix) {
|
||||
var input = document.getElementById(prefix + '-archive-file');
|
||||
var resEl = document.getElementById(prefix + '-ai-result');
|
||||
var btn = document.getElementById(prefix + '-explain-archive-btn');
|
||||
function showRes(text, bg, color) {
|
||||
if (resEl) {
|
||||
resEl.style.display = 'block';
|
||||
resEl.style.background = bg;
|
||||
resEl.style.color = color;
|
||||
resEl.textContent = text;
|
||||
}
|
||||
}
|
||||
if (!input || !input.files || !input.files[0]) {
|
||||
showRes('Выберите .zip файл', '#3a1a1a', '#f88');
|
||||
return;
|
||||
}
|
||||
var file = input.files[0];
|
||||
if (file.size > 100 * 1024) {
|
||||
showRes('Архив слишком большой: максимум 100 KB', '#3a1a1a', '#f88');
|
||||
return;
|
||||
}
|
||||
if (btn) { btn.disabled = true; btn.textContent = '⏳ Спрашиваю LLM…'; }
|
||||
showRes('Запрашиваю у LLM…', 'var(--bg-alt)', 'var(--fg)');
|
||||
var fd = new FormData();
|
||||
fd.append('archive', file);
|
||||
fetch(API_BASE + '/ai/explain-archive', {
|
||||
method: 'POST',
|
||||
headers: authHeaders(),
|
||||
body: fd
|
||||
})
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(data) {
|
||||
if (btn) { btn.disabled = false; btn.textContent = '📖 LLM: Что делает?'; }
|
||||
if (data.error) {
|
||||
showRes('Ошибка: ' + data.error, '#3a2a00', '#ffa');
|
||||
return;
|
||||
}
|
||||
showRes(data.answer || '(пустой ответ)', '#1a2a3a', '#8cf');
|
||||
})
|
||||
.catch(function(e) {
|
||||
if (btn) { btn.disabled = false; btn.textContent = '📖 LLM: Что делает?'; }
|
||||
showRes('Ошибка сети: ' + e.message, '#3a2a00', '#ffa');
|
||||
});
|
||||
}
|
||||
|
||||
function parseMethods(v) {
|
||||
const items = String(v || '').split(',').map(s => s.trim().toUpperCase()).filter(Boolean);
|
||||
return items.length ? Array.from(new Set(items)) : ['GET'];
|
||||
|
||||
Reference in New Issue
Block a user