From 621b706d415d7d0f3d7d96cddfead2c7c4617848 Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Sat, 5 Jul 2025 01:37:54 +0800 Subject: [PATCH] =?UTF-8?q?fix=E4=BF=AE=E5=A4=8Dfocus=E5=86=B7=E5=8D=B4?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=AF=BC=E8=87=B4=E7=9A=84=E5=9B=BA=E5=AE=9A?= =?UTF-8?q?=E6=B2=89=E9=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelogs/changelog.md | 13 +++++++++++++ src/chat/heart_flow/sub_heartflow.py | 8 ++++++-- src/chat/normal_chat/normal_chat.py | 12 +++++++----- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/changelogs/changelog.md b/changelogs/changelog.md index 92d59d18c..8fe8c5e32 100644 --- a/changelogs/changelog.md +++ b/changelogs/changelog.md @@ -2,8 +2,21 @@ ## [0.8.1] - 2025-6-27 +功能更新: + +- normal现在和focus一样支持tool +- focus现在和normal一样每次调用lpmm +- 移除人格表达 + +优化和修复: + - 修复表情包配置无效问题 - 合并normal和focus的prompt构建 +- 非TTY环境禁用console_input_loop +- 修复过滤消息仍被存储至数据库的问题 +- 私聊强制开启focus模式 +- 支持解析reply_to和at +- 修复focus冷却时间导致的固定沉默 diff --git a/src/chat/heart_flow/sub_heartflow.py b/src/chat/heart_flow/sub_heartflow.py index 03bb71c62..d255061fb 100644 --- a/src/chat/heart_flow/sub_heartflow.py +++ b/src/chat/heart_flow/sub_heartflow.py @@ -137,27 +137,31 @@ class SubHeartflow: self.normal_chat_instance = None # 启动/初始化失败,清理实例 return False - async def _handle_switch_to_focus_request(self) -> None: + async def _handle_switch_to_focus_request(self) -> bool: """ 处理来自NormalChat的切换到focus模式的请求 Args: stream_id: 请求切换的stream_id + Returns: + bool: 切换成功返回True,失败返回False """ logger.info(f"{self.log_prefix} 收到NormalChat请求切换到focus模式") # 检查是否在focus冷却期内 if self.is_in_focus_cooldown(): logger.info(f"{self.log_prefix} 正在focus冷却期内,忽略切换到focus模式的请求") - return + return False # 切换到focus模式 current_state = self.chat_state.chat_status if current_state == ChatState.NORMAL: await self.change_chat_state(ChatState.FOCUSED) logger.info(f"{self.log_prefix} 已根据NormalChat请求从NORMAL切换到FOCUSED状态") + return True else: logger.warning(f"{self.log_prefix} 当前状态为{current_state.value},无法切换到FOCUSED状态") + return False async def _handle_stop_focus_chat_request(self) -> None: """ diff --git a/src/chat/normal_chat/normal_chat.py b/src/chat/normal_chat/normal_chat.py index c7edbff3b..a53a3d185 100644 --- a/src/chat/normal_chat/normal_chat.py +++ b/src/chat/normal_chat/normal_chat.py @@ -124,8 +124,6 @@ class NormalChat: self._chat_task: Optional[asyncio.Task] = None self._disabled = False # 停用标志 - self.on_switch_to_focus_callback = on_switch_to_focus_callback - # 新增:回复模式和优先级管理器 self.reply_mode = self.chat_stream.context.get_priority_mode() if self.reply_mode == "priority": @@ -729,10 +727,14 @@ class NormalChat: # 新增:在auto模式下检查是否需要直接切换到focus模式 if global_config.chat.chat_mode == "auto": if await self._check_should_switch_to_focus(): - logger.info(f"[{self.stream_name}] 检测到切换到focus聊天模式的条件,直接执行切换") + logger.info(f"[{self.stream_name}] 检测到切换到focus聊天模式的条件,尝试执行切换") if self.on_switch_to_focus_callback: - await self.on_switch_to_focus_callback() - return + switched_successfully = await self.on_switch_to_focus_callback() + if switched_successfully: + logger.info(f"[{self.stream_name}] 成功切换到focus模式,中止NormalChat处理") + return + else: + logger.info(f"[{self.stream_name}] 切换到focus模式失败(可能在冷却中),继续NormalChat处理") else: logger.warning(f"[{self.stream_name}] 没有设置切换到focus聊天模式的回调函数,无法执行切换")