From aafa4c688bba0599ab87057983cf2c3ee2286f8d Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Sun, 13 Jul 2025 13:46:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E6=AD=A3merge=E5=B8=A6=E6=9D=A5?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- s4u.s4u1 | 0 src/chat/planner_actions/action_modifier.py | 4 ++-- src/chat/willing/willing_manager.py | 2 +- src/plugin_system/base/base_action.py | 17 +++++++++++++++-- src/plugin_system/base/component_types.py | 1 + src/plugins/built_in/core_actions/plugin.py | 4 +++- 6 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 s4u.s4u1 diff --git a/s4u.s4u1 b/s4u.s4u1 new file mode 100644 index 000000000..e69de29bb diff --git a/src/chat/planner_actions/action_modifier.py b/src/chat/planner_actions/action_modifier.py index 7853a9b9d..5495912d3 100644 --- a/src/chat/planner_actions/action_modifier.py +++ b/src/chat/planner_actions/action_modifier.py @@ -142,7 +142,7 @@ class ActionModifier: async def _get_deactivated_actions_by_type( self, - actions_with_info: Dict[str, Any], + actions_with_info: Dict[str, ActionInfo], chat_content: str = "", ) -> List[tuple[str, str]]: """ @@ -164,7 +164,7 @@ class ActionModifier: random.shuffle(actions_to_check) for action_name, action_info in actions_to_check: - activation_type = action_info.get("activation_type", "") + activation_type = action_info.activation_type if not activation_type: activation_type = action_info.get("focus_activation_type", "") diff --git a/src/chat/willing/willing_manager.py b/src/chat/willing/willing_manager.py index 9a2507586..bcd1e11d1 100644 --- a/src/chat/willing/willing_manager.py +++ b/src/chat/willing/willing_manager.py @@ -95,7 +95,7 @@ class BaseWillingManager(ABC): def setup(self, message: dict, chat: ChatStream): person_id = PersonInfoManager.get_person_id(chat.platform, chat.user_info.user_id) # type: ignore - self.ongoing_messages[message.message_info.message_id] = WillingInfo( # type: ignore + self.ongoing_messages[message.get("message_id", "")] = WillingInfo( # type: ignore message=message, chat=chat, person_info_manager=get_person_info_manager(), diff --git a/src/plugin_system/base/base_action.py b/src/plugin_system/base/base_action.py index 886d74b8b..f0fb8affc 100644 --- a/src/plugin_system/base/base_action.py +++ b/src/plugin_system/base/base_action.py @@ -367,12 +367,25 @@ class BaseAction(ABC): return getattr(ChatMode, default.upper(), ChatMode.ALL) return attr + # 获取focus_activation_type和normal_activation_type + focus_activation_type = get_enum_value("focus_activation_type", "always") + normal_activation_type = get_enum_value("normal_activation_type", "always") + + # 处理activation_type:如果插件中声明了就用插件的值,否则默认使用focus_activation_type + activation_type = getattr(cls, "activation_type", None) + if activation_type is None: + activation_type = focus_activation_type + elif not hasattr(activation_type, "value"): + # 如果是字符串,转换为对应的枚举 + activation_type = getattr(ActionActivationType, activation_type.upper(), focus_activation_type) + return ActionInfo( name=name, component_type=ComponentType.ACTION, description=description, - focus_activation_type=get_enum_value("focus_activation_type", "always"), - normal_activation_type=get_enum_value("normal_activation_type", "always"), + focus_activation_type=focus_activation_type, + normal_activation_type=normal_activation_type, + activation_type=activation_type, activation_keywords=getattr(cls, "activation_keywords", []).copy(), keyword_case_sensitive=getattr(cls, "keyword_case_sensitive", False), mode_enable=get_mode_value("mode_enable", "all"), diff --git a/src/plugin_system/base/component_types.py b/src/plugin_system/base/component_types.py index 2bac36e5c..c21f3ba33 100644 --- a/src/plugin_system/base/component_types.py +++ b/src/plugin_system/base/component_types.py @@ -89,6 +89,7 @@ class ActionInfo(ComponentInfo): # 激活类型相关 focus_activation_type: ActionActivationType = ActionActivationType.ALWAYS normal_activation_type: ActionActivationType = ActionActivationType.ALWAYS + activation_type: ActionActivationType = ActionActivationType.ALWAYS random_activation_probability: float = 0.0 llm_judge_prompt: str = "" activation_keywords: List[str] = field(default_factory=list) # 激活关键词列表 diff --git a/src/plugins/built_in/core_actions/plugin.py b/src/plugins/built_in/core_actions/plugin.py index aea58bfd7..ad81c63fd 100644 --- a/src/plugins/built_in/core_actions/plugin.py +++ b/src/plugins/built_in/core_actions/plugin.py @@ -10,6 +10,7 @@ import time from typing import List, Tuple, Type import asyncio import re +import traceback # 导入新插件系统 from src.plugin_system import BasePlugin, register_plugin, BaseAction, ComponentInfo, ActionActivationType, ChatMode @@ -77,7 +78,7 @@ class ReplyAction(BaseAction): try: try: - success, reply_set = await asyncio.wait_for( + success, reply_set, _ = await asyncio.wait_for( generator_api.generate_reply( action_data=self.action_data, chat_id=self.chat_id, @@ -138,6 +139,7 @@ class ReplyAction(BaseAction): except Exception as e: logger.error(f"{self.log_prefix} 回复动作执行失败: {e}") + traceback.print_exc() return False, f"回复失败: {str(e)}"