채팅 중지 버튼이 서버에 직접 알림(/api/chat/stop) — 연결 끊김만으론 서버가 중지를 놓쳐 사용자가 못 본 답이 세션 기록에 남고 다음 턴이 어긋남. 입력창 Enter는 한글 조합 중(isComposing/229)이면 무시
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8ed1a23931
commit
d635253080
3 files changed
+25
No files matched your search
@@ -3140,6 +3140,19 @@ app.get('/api/status', async (_req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
const activeChatAborts = new Map<string, { aborted: boolean }>();
|
||||
|
||||
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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user