fix: clear reply suggestions cache on cancel, regenerate when switching styles - Cancel now clears reply_suggestions from email_context - Selecting style with empty cache triggers fresh AI generation - Selecting style with cache uses cached suggestions - Tests: 3/3 passing

This commit is contained in:
2026-07-17 20:33:09 +08:00
parent 84f2428aeb
commit 6ce9a806ea

View File

@@ -356,11 +356,23 @@ def _handle_callback(tg_cfg: TelegramConfig, cfg: Config, cb: dict):
logger.info(" 进入回复流程, prompt_msg_id=%d", prompt_msg_id) logger.info(" 进入回复流程, prompt_msg_id=%d", prompt_msg_id)
elif action in (CALLBACK_AI_REPLY_FULL, CALLBACK_AI_REPLY_SHORT) and ctx: elif action in (CALLBACK_AI_REPLY_FULL, CALLBACK_AI_REPLY_SHORT) and ctx:
suggestions = ctx["summary_data"].get("reply_suggestions", [])
style = "full" if action == CALLBACK_AI_REPLY_FULL else "short" style = "full" if action == CALLBACK_AI_REPLY_FULL else "short"
suggestions = ctx["summary_data"].get("reply_suggestions", [])
# 缓存为空时重新生成
if not suggestions: if not suggestions:
send_text(tg_cfg, str(chat_id), "此邮件无需回复。") logger.info(" 缓存为空,重新生成 AI 回复 (style=%s)", style)
logger.info(" AI 判定无需回复,隐藏") _tg_req(tg_cfg, "editMessageText", {
"chat_id": chat_id, "message_id": msg_id,
"text": "🤖 *AI思考中…*", "parse_mode": "MarkdownV2",
})
conv = load_conversation(chat_id) or {}
conv["state"] = "ai_reply_selection"
conv["summary_msg_id"] = msg_id
conv["reply_style"] = style
conv["all_suggestions"] = []
save_conversation(chat_id, conv)
_ai_pool.submit(_do_regen, cfg, chat_id, msg_id, ctx, conv)
return return
save_conversation(chat_id, { save_conversation(chat_id, {
@@ -433,7 +445,10 @@ def _handle_callback(tg_cfg: TelegramConfig, cfg: Config, cb: dict):
elif action == CALLBACK_CANCEL: elif action == CALLBACK_CANCEL:
delete_conversation(chat_id) delete_conversation(chat_id)
# 清除回复建议缓存,重新选择时会重新生成
if ctx: if ctx:
ctx["summary_data"]["reply_suggestions"] = []
save_email_context(msg_id, ctx)
can_reply = ctx.get("can_reply", True) can_reply = ctx.get("can_reply", True)
_tg_req(tg_cfg, "editMessageText", { _tg_req(tg_cfg, "editMessageText", {
"chat_id": chat_id, "message_id": msg_id, "chat_id": chat_id, "message_id": msg_id,