重构ChatStream和StreamContext:移除context_manager引用
- 在ChatStream及相关类中,将所有context_manager的实例替换为直接上下文访问。 - 更新方法,利用新的上下文结构来管理聊天状态和消息。 - 增强的StreamContext,增加了用于消息处理、统计和历史管理的方法。 - 在重构过程中改进了错误处理和日志记录。
This commit is contained in:
@@ -477,7 +477,7 @@ class ChatterPlanExecutor:
|
||||
)
|
||||
|
||||
# 添加到chat_stream的已读消息中
|
||||
chat_stream.context_manager.context.history_messages.append(bot_message)
|
||||
chat_stream.context.history_messages.append(bot_message)
|
||||
logger.debug(f"机器人回复已添加到已读消息: {reply_content[:50]}...")
|
||||
|
||||
except Exception as e:
|
||||
|
||||
@@ -169,7 +169,7 @@ class ChatterPlanFilter:
|
||||
logger.debug("尝试添加空的决策历史,已跳过")
|
||||
return
|
||||
|
||||
context = chat_stream.context_manager.context
|
||||
context = chat_stream.context
|
||||
new_record = DecisionRecord(thought=thought, action=action)
|
||||
|
||||
# 添加新记录
|
||||
@@ -204,7 +204,7 @@ class ChatterPlanFilter:
|
||||
if not chat_stream:
|
||||
return ""
|
||||
|
||||
context = chat_stream.context_manager.context
|
||||
context = chat_stream.context
|
||||
if not context.decision_history:
|
||||
return ""
|
||||
|
||||
@@ -344,7 +344,7 @@ class ChatterPlanFilter:
|
||||
logger.warning(f"[plan_filter] 聊天流 {plan.chat_id} 不存在")
|
||||
return "最近没有聊天内容。", "没有未读消息。", []
|
||||
|
||||
stream_context = chat_stream.context_manager
|
||||
stream_context = chat_stream.context
|
||||
|
||||
# 获取真正的已读和未读消息
|
||||
read_messages = (
|
||||
|
||||
@@ -599,7 +599,7 @@ class ChatterActionPlanner:
|
||||
if chat_manager:
|
||||
chat_stream = await chat_manager.get_stream(context.stream_id)
|
||||
if chat_stream:
|
||||
chat_stream.context_manager.context.chat_mode = context.chat_mode
|
||||
chat_stream.context.chat_mode = context.chat_mode
|
||||
chat_stream.saved = False # 标记需要保存
|
||||
logger.debug(f"已同步chat_mode {context.chat_mode.value} 到ChatStream {context.stream_id}")
|
||||
except Exception as e:
|
||||
|
||||
@@ -564,7 +564,7 @@ async def execute_proactive_thinking(stream_id: str):
|
||||
chat_manager = get_chat_manager()
|
||||
chat_stream = await chat_manager.get_stream(stream_id)
|
||||
|
||||
if chat_stream and chat_stream.context_manager.context.is_chatter_processing:
|
||||
if chat_stream and chat_stream.context.is_chatter_processing:
|
||||
logger.warning(f"⚠️ 主动思考跳过:聊天流 {stream_id} 的 chatter 正在处理消息")
|
||||
return
|
||||
except Exception as e:
|
||||
|
||||
@@ -61,7 +61,7 @@ class ReminderTask(AsyncTask):
|
||||
logger.info(f"执行提醒任务: 给 {self.target_user_name} 发送关于 '{self.event_details}' 的提醒")
|
||||
|
||||
extra_info = f"现在是提醒时间,请你以一种符合你人设的、俏皮的方式提醒 {self.target_user_name}。\n提醒内容: {self.event_details}\n设置提醒的人: {self.creator_name}"
|
||||
last_message = self.chat_stream.context_manager.context.get_last_message()
|
||||
last_message = self.chat_stream.context.get_last_message()
|
||||
reply_message_dict = last_message.flatten() if last_message else None
|
||||
success, reply_set, _ = await generator_api.generate_reply(
|
||||
chat_stream=self.chat_stream,
|
||||
@@ -523,7 +523,7 @@ class RemindAction(BaseAction):
|
||||
|
||||
# 4. 生成并发送确认消息
|
||||
extra_info = f"你已经成功设置了一个提醒,请以一种符合你人设的、俏皮的方式回复用户。\n提醒时间: {target_time.strftime('%Y-%m-%d %H:%M:%S')}\n提醒对象: {user_name_to_remind}\n提醒内容: {event_details}"
|
||||
last_message = self.chat_stream.context_manager.context.get_last_message()
|
||||
last_message = self.chat_stream.context.get_last_message()
|
||||
reply_message_dict = last_message.flatten() if last_message else None
|
||||
success, reply_set, _ = await generator_api.generate_reply(
|
||||
chat_stream=self.chat_stream,
|
||||
|
||||
@@ -54,7 +54,7 @@ class TTSAction(BaseAction):
|
||||
|
||||
success, response_set, _ = await generate_reply(
|
||||
chat_stream=self.chat_stream,
|
||||
reply_message=self.chat_stream.context_manager.context.get_last_message(),
|
||||
reply_message=self.chat_stream.context.get_last_message(),
|
||||
enable_tool=global_config.tool.enable_tool,
|
||||
request_type="chat.tts",
|
||||
from_plugin=False,
|
||||
|
||||
Reference in New Issue
Block a user