From f04cc1da6079bd5a4355e75755c8b7bcc7e626ae Mon Sep 17 00:00:00 2001 From: anor Date: Fri, 11 Sep 2026 01:05:08 +1000 Subject: [PATCH] =?UTF-8?q?fix(=D1=87=D0=B0=D1=82):=20=D1=82=D0=B8=D0=BF?= =?UTF-8?q?=20=D1=81=D0=BE=D0=B1=D1=8B=D1=82=D0=B8=D1=8F=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=B6=D0=B8=D0=B2=D0=B0=D0=B5=D1=82=20=D0=B3=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=86=D1=83=20=D0=BF=D0=BE=D1=80=D1=86=D0=B8?= =?UTF-8?q?=D0=B9,=20=D0=B8=D1=82=D0=BE=D0=B3=20=D0=BF=D0=BE=D0=B4=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D0=B2=D0=BB=D1=8F=D0=B5=D1=82=D1=81=D1=8F=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D0=BD=D0=B5=D0=B4=D0=BE=D0=B1=D0=BE=D1=80=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Сеть режет событие между строкой event и строкой data; тип события хранился внутри чтения одной порции и терялся вместе с ней — блок разбора сметы на 11 КБ молча выбрасывался. Объявление переехало за цикл чтения. Запасной путь в конце потока теперь подставляет ответ целиком, если показанный текст короче итогового, а не только когда на экране пусто. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01SrxPccQVeKJc7dTH9ejt7M --- static/chat.html | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/static/chat.html b/static/chat.html index 4fb3c89..e351854 100644 --- a/static/chat.html +++ b/static/chat.html @@ -1888,6 +1888,9 @@ async function runChat(text) { const reader = r.body.getReader(); const decoder = new TextDecoder(); let buffer = ''; + // Тип события живёт между порциями: сеть режет «event: text\n» и «data: …» по разным + // чтениям, и 10.09.2026 так молча пропал блок разбора сметы на 11 КБ. + let eventType = ''; while (true) { const {done, value} = await reader.read(); @@ -1897,7 +1900,6 @@ async function runChat(text) { const lines = buffer.split('\n'); buffer = lines.pop(); - let eventType = ''; for (const line of lines) { if (line.startsWith('event: ')) { eventType = line.slice(7); @@ -1934,8 +1936,11 @@ async function runChat(text) { addTyping().textContent = label; } else if (eventType === 'done') { removeTyping(); - // Always show final result if we haven't shown text yet - if (!aiText && data.result) { + // Показанное короче итога — часть потока не дошла: ставим ответ целиком, тот же, + // что лёг в историю. Равные длины — норма, пузырь не трогаем. + if (data.result && data.result.length > aiText.length) { + if (aiDiv) aiDiv.remove(); + aiText = data.result; aiDiv = addMsg('ai', data.result); } } else if (eventType === 'spend') {