refactor: 将流循环管理器替换为调度器分发器以处理消息
- 引入SchedulerDispatcher以通过统一调度器管理消息分发。 - 更新了MessageManager以使用新的调度器,移除了旧的流循环管理功能。 - 增强了 add_message 方法,以便在接收消息时通知调度器。 - 已移除废弃的中断处理方法,将其逻辑整合至调度器中。 - 修改了action_manager,改为等待数据库操作而非使用asyncio.create_task以实现更精细的控制。 - 优化了统一调度器,支持并发任务执行及运行中任务的取消。 - 为重构流程和新架构添加了全面的文档说明。
This commit is contained in:
@@ -204,20 +204,19 @@ class ChatterActionManager:
|
||||
action_prompt_display=reason,
|
||||
)
|
||||
else:
|
||||
asyncio.create_task( # noqa: RUF006
|
||||
database_api.store_action_info(
|
||||
chat_stream=chat_stream,
|
||||
action_build_into_prompt=False,
|
||||
action_prompt_display=reason,
|
||||
action_done=True,
|
||||
thinking_id=thinking_id or "",
|
||||
action_data={"reason": reason},
|
||||
action_name="no_reply",
|
||||
)
|
||||
# 改为同步等待,确保存储完成
|
||||
await database_api.store_action_info(
|
||||
chat_stream=chat_stream,
|
||||
action_build_into_prompt=False,
|
||||
action_prompt_display=reason,
|
||||
action_done=True,
|
||||
thinking_id=thinking_id or "",
|
||||
action_data={"reason": reason},
|
||||
action_name="no_reply",
|
||||
)
|
||||
|
||||
# 自动清空所有未读消息
|
||||
asyncio.create_task(self._clear_all_unread_messages(chat_stream.stream_id, "no_reply")) # noqa: RUF006
|
||||
# 自动清空所有未读消息(改为同步等待)
|
||||
await self._clear_all_unread_messages(chat_stream.stream_id, "no_reply")
|
||||
|
||||
return {"action_type": "no_reply", "success": True, "reply_text": "", "command": ""}
|
||||
|
||||
@@ -233,16 +232,14 @@ class ChatterActionManager:
|
||||
target_message,
|
||||
)
|
||||
|
||||
# 记录执行的动作到目标消息
|
||||
# 记录执行的动作到目标消息(改为同步等待)
|
||||
if success:
|
||||
asyncio.create_task( # noqa: RUF006
|
||||
self._record_action_to_message(chat_stream, action_name, target_message, action_data)
|
||||
)
|
||||
await self._record_action_to_message(chat_stream, action_name, target_message, action_data)
|
||||
# 自动清空所有未读消息
|
||||
if clear_unread_messages:
|
||||
asyncio.create_task(self._clear_all_unread_messages(chat_stream.stream_id, action_name)) # noqa: RUF006
|
||||
await self._clear_all_unread_messages(chat_stream.stream_id, action_name)
|
||||
# 重置打断计数
|
||||
asyncio.create_task(self._reset_interruption_count_after_action(chat_stream.stream_id)) # noqa: RUF006
|
||||
await self._reset_interruption_count_after_action(chat_stream.stream_id)
|
||||
|
||||
return {
|
||||
"action_type": action_name,
|
||||
@@ -292,14 +289,14 @@ class ChatterActionManager:
|
||||
should_quote_reply, # 传递should_quote_reply参数
|
||||
)
|
||||
|
||||
# 记录回复动作到目标消息
|
||||
asyncio.create_task(self._record_action_to_message(chat_stream, "reply", target_message, action_data)) # noqa: RUF006
|
||||
# 记录回复动作到目标消息(改为同步等待)
|
||||
await self._record_action_to_message(chat_stream, "reply", target_message, action_data)
|
||||
|
||||
if clear_unread_messages:
|
||||
asyncio.create_task(self._clear_all_unread_messages(chat_stream.stream_id, "reply")) # noqa: RUF006
|
||||
await self._clear_all_unread_messages(chat_stream.stream_id, "reply")
|
||||
|
||||
# 回复成功,重置打断计数
|
||||
asyncio.create_task(self._reset_interruption_count_after_action(chat_stream.stream_id)) # noqa: RUF006
|
||||
# 回复成功,重置打断计数(改为同步等待)
|
||||
await self._reset_interruption_count_after_action(chat_stream.stream_id)
|
||||
|
||||
return {"action_type": "reply", "success": True, "reply_text": reply_text, "loop_info": loop_info}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user