From 7a39528d5891f479bc65b9e5806fb1a551a2cde8 Mon Sep 17 00:00:00 2001 From: kim Date: Mon, 19 Oct 2026 23:59:29 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B0=80=EB=93=9C=EA=B0=80=20=EC=B4=88?= =?UTF-8?q?=EC=95=88=EC=9D=84=20=EB=B2=84=EB=A6=AC=EA=B3=A0=20=EC=9E=AC?= =?UTF-8?q?=EC=83=9D=EC=84=B1=ED=95=A0=20=EB=95=8C=20draft=5Freset=20SSE?= =?UTF-8?q?=EB=A5=BC=20=EB=B3=B4=EB=82=B4=20=ED=99=94=EB=A9=B4=C2=B7?= =?UTF-8?q?=EC=9D=8C=EC=84=B1=20=EB=82=AD=EB=8F=85=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=B4=88=EC=95=88=20=EC=A0=9C=EA=B1=B0(=EC=B4=88=EC=95=88+?= =?UTF-8?q?=EC=9E=AC=EC=9E=91=EC=84=B1=EB=B3=B8=20=EC=9D=B4=EC=A4=91=20?= =?UTF-8?q?=EB=82=AD=EB=8F=85=20=EC=88=98=EC=A0=95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5.5 --- src/gateway/chat/handle-chat.ts | 6 ++++++ web-ui/js/app/chat-sse.js | 5 +++++ web-ui/js/voice/voice-call.js | 10 ++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/gateway/chat/handle-chat.ts b/src/gateway/chat/handle-chat.ts index d15191a..d033911 100644 --- a/src/gateway/chat/handle-chat.ts +++ b/src/gateway/chat/handle-chat.ts @@ -1525,6 +1525,12 @@ async function handleChat( // Always use streaming so text tokens appear in real-time. The streaming // handler collects tool_calls from chunks and returns them in the final // result, so tool-call rounds work correctly too. + // 가드가 직전 초안을 버리고 재생성시킨 라운드(마지막 메시지가 user 넛지): 이미 스트리밍된 초안을 클라이언트가 + // 지우게 알린다. 안 그러면 음성 통화가 초안과 재작성본을 연달아 읽는다(2026-10-19 "같은 답을 반복"). + // 도구 라운드 뒤는 마지막 메시지가 tool이라 해당 없음. + if (round > 0 && messages.length && (messages[messages.length - 1] as any)?.role === 'user') { + try { sendSSE('draft_reset', {}); } catch {} + } const generationPromise = ollama.chatWithThinkingStream(messages, 'executor', (token: string) => { try { sendSSE('token', { text: token }); } catch {} }, { diff --git a/web-ui/js/app/chat-sse.js b/web-ui/js/app/chat-sse.js index 094e687..464035f 100644 --- a/web-ui/js/app/chat-sse.js +++ b/web-ui/js/app/chat-sse.js @@ -208,6 +208,11 @@ async function sendChat(queuedMessage = null) { } break; + case 'draft_reset': // 서버 가드가 직전 초안을 버렸다 — 화면·낭독에서도 지운다 + partialContent = ''; + if (window._voiceCallResetDraft) window._voiceCallResetDraft(); + break; + case 'token': case 'text_delta': { const token = event.text || event.content || event.delta || ''; diff --git a/web-ui/js/voice/voice-call.js b/web-ui/js/voice/voice-call.js index 803e970..1c006d7 100644 --- a/web-ui/js/voice/voice-call.js +++ b/web-ui/js/voice/voice-call.js @@ -667,6 +667,16 @@ tableLines = []; }; + // 서버 가드가 초안을 버렸을 때: 아직 안 읽은 초안은 지우고 재생 중인 초안은 끊는다. + window._voiceCallResetDraft = function () { + if (!active) return; + spokenUpTo = 0; pendingTts = ''; spokenKeys.clear(); tableLines = []; ttsQueue = []; + if (playerNode) playerNode.port.postMessage({ type: 'clear' }); + playbackActive = false; + if (ws && ws.readyState === WebSocket.OPEN && currentTtsId) ws.send(JSON.stringify({ type: 'tts_cancel', id: currentTtsId })); + ttsBusy = false; currentTtsId = null; + }; + // Hooked from app.js's SSE token handler — only acts while a call is active. window._voiceCallOnToken = function (fullPartialContent) { if (!active) return;