feat(3.5): кнопка «сообщить об ошибке» — endpoint /api/feedback + таблица feedback + UI на AI-сообщениях
Замыкает петлю обратной связи: дефекты ответов копятся в БД, а не теряются. Кликабельные нормативные ссылки НЕ делаем (нет надёжного реестра URL первоисточников). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+25
-3
@@ -707,6 +707,27 @@ function addMsg(type, text, ts) {
|
||||
};
|
||||
div.appendChild(btn);
|
||||
}
|
||||
if (type === 'ai') {
|
||||
const rep = document.createElement('button');
|
||||
rep.className = 'copy-btn report-btn';
|
||||
rep.textContent = 'Сообщить об ошибке';
|
||||
rep.onclick = async () => {
|
||||
const comment = prompt('Что не так с этим ответом? (можно оставить пустым)');
|
||||
if (comment === null) return; // отмена
|
||||
rep.disabled = true;
|
||||
try {
|
||||
const r = await authFetch('/api/feedback', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({comment: comment || '', answer: div._rawText || ''})
|
||||
});
|
||||
rep.textContent = r.ok ? 'Спасибо, отправлено' : 'Ошибка отправки';
|
||||
if (r.ok) rep.classList.add('copied');
|
||||
} catch (e) { rep.textContent = 'Ошибка отправки'; }
|
||||
setTimeout(() => { rep.textContent = 'Сообщить об ошибке'; rep.classList.remove('copied'); rep.disabled = false; }, 2200);
|
||||
};
|
||||
div.appendChild(rep);
|
||||
}
|
||||
msgs.appendChild(div);
|
||||
msgs.scrollTop = msgs.scrollHeight;
|
||||
return div;
|
||||
@@ -937,12 +958,13 @@ async function sendMessage() {
|
||||
}
|
||||
aiText += data.text;
|
||||
aiDiv._rawText = aiText;
|
||||
// Re-render markdown (keep time + copy button)
|
||||
const copyBtn = aiDiv.querySelector('.copy-btn');
|
||||
// Re-render markdown, сохраняя время и ВСЕ контрол-кнопки
|
||||
// (копирование + «сообщить об ошибке» — обе .copy-btn).
|
||||
const ctrlBtns = Array.from(aiDiv.querySelectorAll('.copy-btn'));
|
||||
const timeEl = aiDiv.querySelector('.msg-time');
|
||||
aiDiv.innerHTML = renderMarkdown(aiText);
|
||||
if (timeEl) aiDiv.prepend(timeEl);
|
||||
if (copyBtn) aiDiv.appendChild(copyBtn);
|
||||
ctrlBtns.forEach(b => aiDiv.appendChild(b));
|
||||
msgs.scrollTop = msgs.scrollHeight;
|
||||
} else if (eventType === 'tool') {
|
||||
// Show minimal status, not raw code
|
||||
|
||||
Reference in New Issue
Block a user