diff --git a/src/gateway/chat/followup-hints.ts b/src/gateway/chat/followup-hints.ts index d095992..a078daf 100644 --- a/src/gateway/chat/followup-hints.ts +++ b/src/gateway/chat/followup-hints.ts @@ -18,9 +18,12 @@ const CORRECTION_RE = /^(?:아니|아냐|아니요|그게\s*아니라|아니\s* export function weatherFollowUpHint( message: string, - history: ReadonlyArray<{ role: string; content?: any }>, + historyIn: ReadonlyArray<{ role: string; content?: any }>, ): string | null { const msg = String(message || '').trim(); + // 호출 시점의 history에 현재 메시지가 이미 들어 있을 수 있다 — 그 한 줄은 "이전 대화"가 아니므로 뺀다 + const history = historyIn.length && historyIn[historyIn.length - 1].role === 'user' && String(historyIn[historyIn.length - 1].content || '').trim() === msg + ? historyIn.slice(0, -1) : historyIn; if (!msg || msg.length > MAX_FOLLOWUP_CHARS) return null; if (!WEATHER_RE.test(msg)) return placeCorrectionHint(msg, history); const notes: string[] = []; diff --git a/tests/followup-hints.test.ts b/tests/followup-hints.test.ts index 71a0188..74433f3 100644 --- a/tests/followup-hints.test.ts +++ b/tests/followup-hints.test.ts @@ -28,3 +28,8 @@ test('"아니 서울" → 장소 정정 힌트', () => { const h = weatherFollow test('"부산으로" / "서울은?" → 정정 힌트', () => { assert.match(weatherFollowUpHint('부산으로', HW)!, /"부산"/); assert.match(weatherFollowUpHint('서울은?', HW)!, /"서울"/); }); test('날씨 맥락 없으면 정정 힌트 없음', () => assert.equal(weatherFollowUpHint('아니 서울', [{ role: 'user', content: '파스타 맛집' }]), null)); test('"고마워" 같은 짧은 응답은 제외', () => { assert.equal(weatherFollowUpHint('고마워', HW), null); assert.equal(weatherFollowUpHint('알겠어요', HW), null); }); + +test('history 끝에 현재 메시지가 이미 들어 있어도 직전 날씨 질문을 찾는다', () => { + const h = weatherFollowUpHint('아니 서울', [...HW, { role: 'user', content: '아니 서울' }])!; + assert.match(h, /"서울"/); +});