From 5efb76c4f3e74cbc108f6405a352d33f7bf16e86 Mon Sep 17 00:00:00 2001 From: anor Date: Fri, 17 Jul 2026 21:31:39 +1000 Subject: [PATCH] =?UTF-8?q?feat(UI=201.1):=20=D1=87=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=BD=D1=8B=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20+=20=C2=AB?= =?UTF-8?q?=D0=9F=D0=BE=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D1=82=D1=8C=C2=BB=20?= =?UTF-8?q?+=20=D1=82=D0=B5=D0=BA=D1=81=D1=82=20=D0=BD=D0=B5=20=D1=82?= =?UTF-8?q?=D0=B5=D1=80=D1=8F=D0=B5=D1=82=D1=81=D1=8F;=20bump=202026-07-17?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sendMessage разбит на sendMessage(файлы+пузырь) + runChat(стрим). httpErrText: статус→ факт+действие (не голый «Ошибка: 500»). addErrorRetry: role=alert + кнопка «Повторить» (повтор не дублирует пузырь, текст сохранён). .retry-btn с тёмной парой. Co-Authored-By: Claude Opus 4.8 (1M context) --- main.py | 2 +- static/chat.html | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index dc83ca5..4d3d909 100644 --- a/main.py +++ b/main.py @@ -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 = [ diff --git a/static/chat.html b/static/chat.html index 3006878..e6ec5b2 100644 --- a/static/chat.html +++ b/static/chat.html @@ -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(); // обновить превью/порядок чатов в панели } }