增加注释

This commit is contained in:
Windpicker-owo
2025-09-01 13:13:56 +08:00
parent 6e50eb5929
commit d49ad0ad01

View File

@@ -66,6 +66,7 @@ class CycleProcessor:
loop_start_time = time.time() loop_start_time = time.time()
# 第一步:动作修改
with Timer("动作修改", cycle_timers): with Timer("动作修改", cycle_timers):
try: try:
await self.action_modifier.modify_actions() await self.action_modifier.modify_actions()
@@ -82,6 +83,7 @@ class CycleProcessor:
if self.context.loop_mode == ChatMode.FOCUS and at_bot_mentioned and "no_reply" in available_actions: if self.context.loop_mode == ChatMode.FOCUS and at_bot_mentioned and "no_reply" in available_actions:
available_actions = {k: v for k, v in available_actions.items() if k != "no_reply"} available_actions = {k: v for k, v in available_actions.items() if k != "no_reply"}
# 检查是否在normal模式下没有可用动作除了reply相关动作
skip_planner = False skip_planner = False
if self.context.loop_mode == ChatMode.NORMAL: if self.context.loop_mode == ChatMode.NORMAL:
non_reply_actions = { non_reply_actions = {
@@ -89,33 +91,37 @@ class CycleProcessor:
} }
if not non_reply_actions: if not non_reply_actions:
skip_planner = True skip_planner = True
logger.info(f"{self.log_prefix} Normal模式下没有可用动作直接回复")
plan_result = self._get_direct_reply_plan(loop_start_time) plan_result = self._get_direct_reply_plan(loop_start_time)
target_message = message_data target_message = message_data
gen_task = None gen_task = None
if not skip_planner and self.context.loop_mode == ChatMode.NORMAL: # 如果normal模式且不跳过规划器开始一个回复生成进程先准备好回复其实是和planer同时进行的
reply_to_str = await self._build_reply_to_str(message_data) if not skip_planner:
gen_task = asyncio.create_task( reply_to_str = await self._build_reply_to_str(message_data)
self.response_handler.generate_response( gen_task = asyncio.create_task(
message_data=message_data, self.response_handler.generate_response(
available_actions=available_actions, message_data=message_data,
reply_to=reply_to_str, available_actions=available_actions,
request_type="chat.replyer.normal", reply_to=reply_to_str,
request_type="chat.replyer.normal",
)
) )
)
# Focus模式
if not skip_planner: if not skip_planner:
plan_result, target_message = await self.action_planner.plan(mode=self.context.loop_mode) from src.plugin_system.core.event_manager import event_manager
from src.plugin_system.base.component_types import EventType
from src.plugin_system.core.event_manager import event_manager # 触发 ON_PLAN 事件
from src.plugin_system.base.component_types import EventType result = await event_manager.trigger_event(
EventType.ON_PLAN, plugin_name="SYSTEM", stream_id=self.context.stream_id
)
if result and not result.all_continue_process():
return
# 触发 ON_PLAN 事件 with Timer("规划器", cycle_timers):
result = await event_manager.trigger_event( plan_result, target_message = await self.action_planner.plan(mode=self.context.loop_mode)
EventType.ON_PLAN, plugin_name="SYSTEM", stream_id=self.context.stream_id
)
if result and not result.all_continue_process():
return
action_result = plan_result.get("action_result", {}) if isinstance(plan_result, dict) else {} action_result = plan_result.get("action_result", {}) if isinstance(plan_result, dict) else {}
if not isinstance(action_result, dict): if not isinstance(action_result, dict):