refactor(chat): 重构消息管理器以使用集中式上下文管理和能量系统

- 将流上下文管理从MessageManager迁移到专门的ContextManager
- 使用统一的能量系统计算focus_energy和分发间隔
- 重构ChatStream的消息数据转换逻辑,支持更完整的数据字段
- 更新数据库模型,移除interest_degree字段,统一使用interest_value
- 集成新的兴趣度管理系统替代原有的评分系统
- 添加消息存储的interest_value修复功能
This commit is contained in:
Windpicker-owo
2025-09-27 14:23:48 +08:00
parent 0478be7d2a
commit c49b3f3ac4
15 changed files with 3518 additions and 495 deletions

View File

@@ -96,7 +96,6 @@ class DatabaseMessages(BaseDataModel):
chat_info_create_time: float = 0.0,
chat_info_last_active_time: float = 0.0,
# 新增字段
interest_degree: float = 0.0,
actions: Optional[list] = None,
should_reply: bool = False,
**kwargs: Any,
@@ -108,7 +107,6 @@ class DatabaseMessages(BaseDataModel):
self.interest_value = interest_value
# 新增字段
self.interest_degree = interest_degree
self.actions = actions
self.should_reply = should_reply
@@ -201,7 +199,6 @@ class DatabaseMessages(BaseDataModel):
"selected_expressions": self.selected_expressions,
"is_read": self.is_read,
# 新增字段
"interest_degree": self.interest_degree,
"actions": self.actions,
"should_reply": self.should_reply,
"user_id": self.user_info.user_id,
@@ -221,17 +218,17 @@ class DatabaseMessages(BaseDataModel):
"chat_info_user_cardname": self.chat_info.user_info.user_cardname,
}
def update_message_info(self, interest_degree: float = None, actions: list = None, should_reply: bool = None):
def update_message_info(self, interest_value: float = None, actions: list = None, should_reply: bool = None):
"""
更新消息信息
Args:
interest_degree: 兴趣度值
interest_value: 兴趣度值
actions: 执行的动作列表
should_reply: 是否应该回复
"""
if interest_degree is not None:
self.interest_degree = interest_degree
if interest_value is not None:
self.interest_value = interest_value
if actions is not None:
self.actions = actions
if should_reply is not None:
@@ -268,7 +265,7 @@ class DatabaseMessages(BaseDataModel):
return {
"message_id": self.message_id,
"time": self.time,
"interest_degree": self.interest_degree,
"interest_value": self.interest_value,
"actions": self.actions,
"should_reply": self.should_reply,
"user_nickname": self.user_info.user_nickname,

View File

@@ -61,27 +61,27 @@ class StreamContext(BaseDataModel):
self._detect_chat_type(message)
def update_message_info(
self, message_id: str, interest_degree: float = None, actions: list = None, should_reply: bool = None
self, message_id: str, interest_value: float = None, actions: list = None, should_reply: bool = None
):
"""
更新消息信息
Args:
message_id: 消息ID
interest_degree: 兴趣度值
interest_value: 兴趣度值
actions: 执行的动作列表
should_reply: 是否应该回复
"""
# 在未读消息中查找并更新
for message in self.unread_messages:
if message.message_id == message_id:
message.update_message_info(interest_degree, actions, should_reply)
message.update_message_info(interest_value, actions, should_reply)
break
# 在历史消息中查找并更新
for message in self.history_messages:
if message.message_id == message_id:
message.update_message_info(interest_degree, actions, should_reply)
message.update_message_info(interest_value, actions, should_reply)
break
def add_action_to_message(self, message_id: str, action: str):