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(); }