From d635253080bf9ccbe8c83a1f11c258076b548d44 Mon Sep 17 00:00:00 2001 From: kim Date: Thu, 22 Oct 2026 14:03:47 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B1=84=ED=8C=85=20=EC=A4=91=EC=A7=80=20?= =?UTF-8?q?=EB=B2=84=ED=8A=BC=EC=9D=B4=20=EC=84=9C=EB=B2=84=EC=97=90=20?= =?UTF-8?q?=EC=A7=81=EC=A0=91=20=EC=95=8C=EB=A6=BC(/api/chat/stop)=20?= =?UTF-8?q?=E2=80=94=20=EC=97=B0=EA=B2=B0=20=EB=81=8A=EA=B9=80=EB=A7=8C?= =?UTF-8?q?=EC=9C=BC=EB=A1=A0=20=EC=84=9C=EB=B2=84=EA=B0=80=20=EC=A4=91?= =?UTF-8?q?=EC=A7=80=EB=A5=BC=20=EB=86=93=EC=B3=90=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=EA=B0=80=20=EB=AA=BB=20=EB=B3=B8=20=EB=8B=B5=EC=9D=B4?= =?UTF-8?q?=20=EC=84=B8=EC=85=98=20=EA=B8=B0=EB=A1=9D=EC=97=90=20=EB=82=A8?= =?UTF-8?q?=EA=B3=A0=20=EB=8B=A4=EC=9D=8C=20=ED=84=B4=EC=9D=B4=20=EC=96=B4?= =?UTF-8?q?=EA=B8=8B=EB=82=A8.=20=EC=9E=85=EB=A0=A5=EC=B0=BD=20Enter?= =?UTF-8?q?=EB=8A=94=20=ED=95=9C=EA=B8=80=20=EC=A1=B0=ED=95=A9=20=EC=A4=91?= =?UTF-8?q?(isComposing/229)=EC=9D=B4=EB=A9=B4=20=EB=AC=B4=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- src/gateway/server.ts | 18 ++++++++++++++++++ web-ui/js/app/app.js | 5 +++++ web-ui/js/app/chat-render.js | 2 ++ 3 files changed, 25 insertions(+) diff --git a/src/gateway/server.ts b/src/gateway/server.ts index 77b81ef..8af9feb 100644 --- a/src/gateway/server.ts +++ b/src/gateway/server.ts @@ -3140,6 +3140,19 @@ app.get('/api/status', async (_req, res) => { }); }); +const activeChatAborts = new Map(); + +app.post('/api/chat/stop', (req, res) => { + const sessionId = String(req.body?.sessionId || 'default'); + const user = (req as any).user; + const sig = activeChatAborts.get(`${user?.username || ''}:${sessionId}`); + if (sig && !sig.aborted) { + sig.aborted = true; + console.log(`[v2] Stop requested — aborting task for session ${sessionId}`); + } + res.json({ success: true, stopped: !!sig }); +}); + app.post('/api/chat', async (req, res) => { const { message, sessionId = 'default', pinnedMessages, model: reqModel, direct, history: clientHistory, codeAiLocal, useTools, boardContext, skillContext } = req.body; if (!message || typeof message !== 'string') { res.status(400).json({ error: 'Message required' }); return; } @@ -3184,6 +3197,10 @@ app.post('/api/chat', async (req, res) => { console.log(`[v2] Client disconnected — aborting task for session ${sessionId}`); } }); + // 중지 버튼은 /api/chat/stop으로도 알린다 — 연결 끊김만으론 서버가 중지를 놓쳐 사용자가 못 본 답이 + // 세션 기록에 저장되고, 다음 턴에서 모델과 화면이 어긋났다(10-21 '장난감 롭' 건). + const _stopKey = `${user?.username || ''}:${sessionId}`; + activeChatAborts.set(_stopKey, abortSignal); try { const isCodeEditorSessionEarly = /^(code_ai_|proj-plan-|proj-gen-)/.test(String(sessionId)); @@ -3325,6 +3342,7 @@ app.post('/api/chat', async (req, res) => { } } finally { requestCompleted = true; + if (activeChatAborts.get(_stopKey) === abortSignal) activeChatAborts.delete(_stopKey); clearInterval(heartbeat); isModelBusy = false; // release busy guard — cron scheduler may now run isModelBusySince = 0; diff --git a/web-ui/js/app/app.js b/web-ui/js/app/app.js index 45cfb8c..410d473 100644 --- a/web-ui/js/app/app.js +++ b/web-ui/js/app/app.js @@ -1278,6 +1278,11 @@ function handleSendStop() { function stopGeneration() { if (currentAbortController) { + // 연결만 끊으면 서버가 중지를 놓쳐 못 본 답이 세션 기록에 남는다 — 서버에도 직접 알림 + try { + fetch('/api/chat/stop', { method: 'POST', headers: authHeaders({ 'Content-Type': 'application/json' }), + body: JSON.stringify({ sessionId: agentSessionId }) }).catch(() => {}); + } catch {} currentAbortController.abort(); currentAbortController = null; } diff --git a/web-ui/js/app/chat-render.js b/web-ui/js/app/chat-render.js index 322dce1..25566ad 100644 --- a/web-ui/js/app/chat-render.js +++ b/web-ui/js/app/chat-render.js @@ -905,6 +905,8 @@ function exportChat(format) { // Enter to send, Shift+Enter for newline document.getElementById('chat-input').addEventListener('keydown', e => { if (e.key === 'Enter' && !e.shiftKey) { + // 한글 조합 중 Enter(isComposing, keyCode 229)는 글자 확정용 — 여기서 보내면 '롭'처럼 잘린 채 전송됨 + if (e.isComposing || e.keyCode === 229) return; e.preventDefault(); sendChat(); }