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;