feat(UI 1.1): честные ошибки отправки + «Повторить» + текст не теряется; bump 2026-07-17g
sendMessage разбит на sendMessage(файлы+пузырь) + runChat(стрим). httpErrText: статус→ факт+действие (не голый «Ошибка: 500»). addErrorRetry: role=alert + кнопка «Повторить» (повтор не дублирует пузырь, текст сохранён). .retry-btn с тёмной парой. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -138,7 +138,7 @@ MAX_MESSAGE_LEN = 10_000
|
||||
|
||||
# ⚠️ Версия UI — единый источник. БАМПАТЬ ПРИ КАЖДОМ ДЕПЛОЕ (формат: YYYY-MM-DD + буква).
|
||||
# Фронт берёт её через GET /api/version (chat.html + admin.html, элемент .app-version).
|
||||
APP_VERSION = "2026-07-17f"
|
||||
APP_VERSION = "2026-07-17g"
|
||||
|
||||
# Audit: path → action name mapping
|
||||
_AUDIT_MAP = [
|
||||
|
||||
+30
-3
@@ -79,6 +79,9 @@ button { font-family: inherit; }
|
||||
.dl-btn { display: block; width: fit-content; margin: .35rem 0 0; padding: .45rem .8rem; background: #16a34a; color: #fff !important; border-radius: var(--radius); font-weight: 600; }
|
||||
.dl-btn:hover { background: #15803d; text-decoration: none !important; }
|
||||
.msg-error { align-self: center; background: var(--error-bg); border: 1px solid var(--error-border); color: #e03131; font-size: .85rem; box-shadow: none; }
|
||||
.retry-btn { display: inline-block; margin-top: .5rem; background: transparent; border: 1px solid #e03131; border-radius: 6px; cursor: pointer; font-size: .78rem; padding: .25rem .7rem; color: #e03131; transition: all .15s; }
|
||||
.retry-btn:hover { background: rgba(224,49,49,.08); }
|
||||
:root[data-theme="dark"] .retry-btn { border-color: #ff8585; color: #ff8585; }
|
||||
.msg-system { align-self: center; background: var(--system-bg); border: none; font-size: .8rem; color: var(--system-text); box-shadow: none; padding: .4rem .8rem; }
|
||||
.typing { align-self: flex-start; color: var(--text-light); font-style: italic; font-size: .85rem; padding: .4rem 0; }
|
||||
|
||||
@@ -897,6 +900,27 @@ function handleKey(e) {
|
||||
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); sendMessage(); }
|
||||
}
|
||||
|
||||
// Честный текст ошибки по HTTP-статусу: констатируем факт + одно действие,
|
||||
// не выдумываем причину (CLAUDE.md). Никогда не показываем голый «Ошибка: 500».
|
||||
function httpErrText(status) {
|
||||
if (status === 429) return 'Слишком много запросов — подождите минуту и повторите.';
|
||||
if (status === 413) return 'Слишком большой запрос — сократите сообщение.';
|
||||
if (status === 400) return 'Запрос отклонён (возможно, слишком длинное сообщение).';
|
||||
if (status >= 500) return 'Сервис не ответил (код ' + status + '). Можно повторить.';
|
||||
return 'Не удалось отправить (код ' + status + ').';
|
||||
}
|
||||
|
||||
// Ошибка с кнопкой «Повторить» — текст пользователя не теряется, повтор не дублирует пузырь.
|
||||
function addErrorRetry(msg, retryText) {
|
||||
const div = addMsg('error', msg);
|
||||
div.setAttribute('role', 'alert');
|
||||
const btn = document.createElement('button');
|
||||
btn.textContent = 'Повторить';
|
||||
btn.className = 'retry-btn';
|
||||
btn.onclick = () => { div.remove(); runChat(retryText); };
|
||||
div.appendChild(btn);
|
||||
}
|
||||
|
||||
async function sendMessage() {
|
||||
if (streaming) return;
|
||||
const input = document.getElementById('msg-input');
|
||||
@@ -918,7 +942,10 @@ async function sendMessage() {
|
||||
addMsg('user', text);
|
||||
input.value = '';
|
||||
input.style.height = 'auto';
|
||||
await runChat(text);
|
||||
}
|
||||
|
||||
async function runChat(text) {
|
||||
streaming = true;
|
||||
document.getElementById('send-btn').disabled = true;
|
||||
addTyping();
|
||||
@@ -931,7 +958,7 @@ async function sendMessage() {
|
||||
});
|
||||
|
||||
if (r.status === 401) { logout(); return; }
|
||||
if (!r.ok) { addMsg('error', 'Ошибка: ' + r.status); return; }
|
||||
if (!r.ok) { removeTyping(); addErrorRetry(httpErrText(r.status), text); return; }
|
||||
|
||||
removeTyping();
|
||||
let aiDiv = null;
|
||||
@@ -993,11 +1020,11 @@ async function sendMessage() {
|
||||
|
||||
} catch (err) {
|
||||
removeTyping();
|
||||
addMsg('error', 'Ошибка соединения: ' + err.message);
|
||||
addErrorRetry('Нет связи с сервисом. ' + (err.message || ''), text);
|
||||
} finally {
|
||||
streaming = false;
|
||||
document.getElementById('send-btn').disabled = false;
|
||||
input.focus();
|
||||
document.getElementById('msg-input').focus();
|
||||
loadSessions(); // обновить превью/порядок чатов в панели
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user