feat: 更新消息管理和数据库操作日志,增强调试信息

This commit is contained in:
Windpicker-owo
2025-11-30 15:13:01 +08:00
parent 1750004ffa
commit fc85338d0b
5 changed files with 18 additions and 13 deletions

View File

@@ -162,17 +162,17 @@ class StreamContext(BaseDataModel):
"stream_id": self.stream_id, "stream_id": self.stream_id,
} }
await unified_manager.add_message(message_dict) await unified_manager.add_message(message_dict)
logger.debug(f"<EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ: {message.message_id}") logger.debug(f"消息已添加到统一记忆系统: {message.message_id}")
except Exception as e: except Exception as e:
logger.error(f"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳʧ<EFBFBD><EFBFBD>: {e}") logger.error(f"添加消息到统一记忆系统失败: {e}")
return True return True
except Exception as e: except Exception as e:
logger.error(f"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD> {self.stream_id}: {e}") logger.error(f"添加消息到上下文失败 {self.stream_id}: {e}")
return False return False
async def update_message(self, message_id: str, updates: dict[str, Any]) -> bool: async def update_message(self, message_id: str, updates: dict[str, Any]) -> bool:
"""<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD>Ϣ""" """更新上下文中的消息信息"""
try: try:
for message in self.unread_messages: for message in self.unread_messages:
if str(message.message_id) == str(message_id): if str(message.message_id) == str(message_id):
@@ -194,10 +194,10 @@ class StreamContext(BaseDataModel):
message.should_reply = updates["should_reply"] message.should_reply = updates["should_reply"]
break break
logger.debug(f"<EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ: {self.stream_id}/{message_id}") logger.debug(f"更新消息信息: {self.stream_id}/{message_id}")
return True return True
except Exception as e: except Exception as e:
logger.error(f"<EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣʧ<EFBFBD><EFBFBD> {self.stream_id}/{message_id}: {e}") logger.error(f"更新消息信息失败 {self.stream_id}/{message_id}: {e}")
return False return False
def add_action_to_message(self, message_id: str, action: str): def add_action_to_message(self, message_id: str, action: str):

View File

@@ -149,7 +149,6 @@ class CRUDBase:
cache = await get_cache() cache = await get_cache()
cached_dict = await cache.get(cache_key) cached_dict = await cache.get(cache_key)
if cached_dict is not None: if cached_dict is not None:
logger.debug(f"缓存命中: {cache_key}")
# 从字典恢复对象 # 从字典恢复对象
return _dict_to_model(self.model, cached_dict) return _dict_to_model(self.model, cached_dict)
@@ -194,7 +193,6 @@ class CRUDBase:
cache = await get_cache() cache = await get_cache()
cached_dict = await cache.get(cache_key) cached_dict = await cache.get(cache_key)
if cached_dict is not None: if cached_dict is not None:
logger.debug(f"缓存命中: {cache_key}")
# 从字典恢复对象 # 从字典恢复对象
return _dict_to_model(self.model, cached_dict) return _dict_to_model(self.model, cached_dict)
@@ -247,7 +245,6 @@ class CRUDBase:
cache = await get_cache() cache = await get_cache()
cached_dicts = await cache.get(cache_key) cached_dicts = await cache.get(cache_key)
if cached_dicts is not None: if cached_dicts is not None:
logger.debug(f"缓存命中: {cache_key}")
# 从字典列表恢复对象列表 # 从字典列表恢复对象列表
return [_dict_to_model(self.model, d) for d in cached_dicts] return [_dict_to_model(self.model, d) for d in cached_dicts]

View File

@@ -199,7 +199,6 @@ class QueryBuilder(Generic[T]):
cache = await get_cache() cache = await get_cache()
cached_dicts = await cache.get(cache_key) cached_dicts = await cache.get(cache_key)
if cached_dicts is not None: if cached_dicts is not None:
logger.debug(f"缓存命中: {cache_key}")
dict_rows = [dict(row) for row in cached_dicts] dict_rows = [dict(row) for row in cached_dicts]
if as_dict: if as_dict:
return dict_rows return dict_rows
@@ -238,7 +237,6 @@ class QueryBuilder(Generic[T]):
cache = await get_cache() cache = await get_cache()
cached_dict = await cache.get(cache_key) cached_dict = await cache.get(cache_key)
if cached_dict is not None: if cached_dict is not None:
logger.debug(f"缓存命中: {cache_key}")
row = dict(cached_dict) row = dict(cached_dict)
if as_dict: if as_dict:
return row return row
@@ -277,7 +275,6 @@ class QueryBuilder(Generic[T]):
cache = await get_cache() cache = await get_cache()
cached = await cache.get(cache_key) cached = await cache.get(cache_key)
if cached is not None: if cached is not None:
logger.debug(f"缓存命中: {cache_key}")
return cached return cached
# 构建count查询 # 构建count查询

View File

@@ -192,7 +192,6 @@ def cached(
cached_result = await cache.get(cache_key) cached_result = await cache.get(cache_key)
if cached_result is not None: if cached_result is not None:
logger.debug(f"缓存命中: {cache_key}")
return cached_result return cached_result
# 执行函数 # 执行函数

View File

@@ -663,6 +663,18 @@ class ChatterPlanFilter:
f"[{action}] 找不到目标消息target_message_id: {action_data.get('target_message_id')}" f"[{action}] 找不到目标消息target_message_id: {action_data.get('target_message_id')}"
) )
# reply 动作必须有目标消息,如果仍然为 None则使用最新消息
if action in ["reply", "proactive_reply"] and action_message_obj is None:
logger.warning(f"[{action}] 目标消息为空,强制使用最新消息作为兜底")
latest_message_dict = self._get_latest_message(message_id_list)
if latest_message_dict:
from src.common.data_models.database_data_model import DatabaseMessages
try:
action_message_obj = DatabaseMessages(**latest_message_dict)
logger.info(f"[{action}] 成功使用最新消息: {action_message_obj.message_id}")
except Exception as e:
logger.error(f"[{action}] 无法转换最新消息: {e}")
return ActionPlannerInfo( return ActionPlannerInfo(
action_type=action, action_type=action,
reasoning=reasoning, reasoning=reasoning,