Merge afc branch into dev, prioritizing afc changes and migrating database async modifications from dev
This commit is contained in:
@@ -93,7 +93,6 @@ class BaseAction(ABC):
|
||||
self.associated_types: list[str] = getattr(self.__class__, "associated_types", []).copy()
|
||||
self.chat_type_allow: ChatType = getattr(self.__class__, "chat_type_allow", ChatType.ALL)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 便捷属性 - 直接在初始化时获取常用聊天信息(带类型注解)
|
||||
# =============================================================================
|
||||
@@ -398,6 +397,7 @@ class BaseAction(ABC):
|
||||
try:
|
||||
# 1. 从注册中心获取Action类
|
||||
from src.plugin_system.core.component_registry import component_registry
|
||||
|
||||
action_class = component_registry.get_component_class(action_name, ComponentType.ACTION)
|
||||
if not action_class:
|
||||
logger.error(f"{log_prefix} 未找到Action: {action_name}")
|
||||
@@ -406,7 +406,7 @@ class BaseAction(ABC):
|
||||
# 2. 准备实例化参数
|
||||
# 复用当前Action的大部分上下文信息
|
||||
called_action_data = action_data if action_data is not None else self.action_data
|
||||
|
||||
|
||||
component_info = component_registry.get_component_info(action_name, ComponentType.ACTION)
|
||||
if not component_info:
|
||||
logger.warning(f"{log_prefix} 未找到Action组件信息: {action_name}")
|
||||
|
||||
55
src/plugin_system/base/base_chatter.py
Normal file
55
src/plugin_system/base/base_chatter.py
Normal file
@@ -0,0 +1,55 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import List, Optional, TYPE_CHECKING
|
||||
from src.common.data_models.message_manager_data_model import StreamContext
|
||||
from .component_types import ChatType
|
||||
from src.plugin_system.base.component_types import ChatterInfo, ComponentType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from src.chat.planner_actions.action_manager import ChatterActionManager
|
||||
from src.plugins.built_in.affinity_flow_chatter.planner import ChatterActionPlanner as ActionPlanner
|
||||
|
||||
class BaseChatter(ABC):
|
||||
chatter_name: str = ""
|
||||
"""Chatter组件的名称"""
|
||||
chatter_description: str = ""
|
||||
"""Chatter组件的描述"""
|
||||
chat_types: List[ChatType] = [ChatType.PRIVATE, ChatType.GROUP]
|
||||
|
||||
def __init__(self, stream_id: str, action_manager: 'ChatterActionManager'):
|
||||
"""
|
||||
初始化聊天处理器
|
||||
|
||||
Args:
|
||||
stream_id: 聊天流ID
|
||||
action_manager: 动作管理器
|
||||
"""
|
||||
self.stream_id = stream_id
|
||||
self.action_manager = action_manager
|
||||
|
||||
@abstractmethod
|
||||
async def execute(self, context: StreamContext) -> dict:
|
||||
"""
|
||||
执行聊天处理流程
|
||||
|
||||
Args:
|
||||
context: StreamContext对象,包含聊天流的所有消息信息
|
||||
|
||||
Returns:
|
||||
处理结果字典
|
||||
"""
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def get_chatter_info(cls) -> "ChatterInfo":
|
||||
"""从类属性生成ChatterInfo
|
||||
Returns:
|
||||
ChatterInfo对象
|
||||
"""
|
||||
|
||||
return ChatterInfo(
|
||||
name=cls.chatter_name,
|
||||
description=cls.chatter_description or "No description provided.",
|
||||
chat_type_allow=cls.chat_types[0],
|
||||
component_type=ComponentType.CHATTER,
|
||||
)
|
||||
|
||||
@@ -73,7 +73,7 @@ class BaseCommand(ABC):
|
||||
return True
|
||||
|
||||
# 检查是否为群聊消息
|
||||
is_group = hasattr(self.message, "is_group_message") and self.message.is_group_message
|
||||
is_group = self.message.message_info.group_info
|
||||
|
||||
if self.chat_type_allow == ChatType.GROUP and is_group:
|
||||
return True
|
||||
|
||||
@@ -98,7 +98,7 @@ class BaseEventHandler(ABC):
|
||||
weight=cls.weight,
|
||||
intercept_message=cls.intercept_message,
|
||||
)
|
||||
|
||||
|
||||
def set_plugin_name(self, plugin_name: str) -> None:
|
||||
"""设置插件名称
|
||||
|
||||
@@ -107,9 +107,9 @@ class BaseEventHandler(ABC):
|
||||
"""
|
||||
self.plugin_name = plugin_name
|
||||
|
||||
def set_plugin_config(self,plugin_config) -> None:
|
||||
def set_plugin_config(self, plugin_config) -> None:
|
||||
self.plugin_config = plugin_config
|
||||
|
||||
|
||||
def get_config(self, key: str, default=None):
|
||||
"""获取插件配置值,支持嵌套键访问
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ class ComponentType(Enum):
|
||||
TOOL = "tool" # 工具组件
|
||||
SCHEDULER = "scheduler" # 定时任务组件(预留)
|
||||
EVENT_HANDLER = "event_handler" # 事件处理组件
|
||||
CHATTER = "chatter" # 聊天处理器组件
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.value
|
||||
@@ -39,8 +40,8 @@ class ActionActivationType(Enum):
|
||||
# 聊天模式枚举
|
||||
class ChatMode(Enum):
|
||||
"""聊天模式枚举"""
|
||||
|
||||
FOCUS = "focus" # Focus聊天模式
|
||||
|
||||
FOCUS = "focus" # 专注模式
|
||||
NORMAL = "normal" # Normal聊天模式
|
||||
PROACTIVE = "proactive" # 主动思考模式
|
||||
PRIORITY = "priority" # 优先级聊天模式
|
||||
@@ -54,8 +55,8 @@ class ChatMode(Enum):
|
||||
class ChatType(Enum):
|
||||
"""聊天类型枚举,用于限制插件在不同聊天环境中的使用"""
|
||||
|
||||
GROUP = "group" # 仅群聊可用
|
||||
PRIVATE = "private" # 仅私聊可用
|
||||
GROUP = "group" # 仅群聊可用
|
||||
ALL = "all" # 群聊和私聊都可用
|
||||
|
||||
def __str__(self):
|
||||
@@ -69,7 +70,7 @@ class EventType(Enum):
|
||||
"""
|
||||
|
||||
ON_START = "on_start" # 启动事件,用于调用按时任务
|
||||
ON_STOP ="on_stop"
|
||||
ON_STOP = "on_stop"
|
||||
ON_MESSAGE = "on_message"
|
||||
ON_PLAN = "on_plan"
|
||||
POST_LLM = "post_llm"
|
||||
@@ -210,6 +211,17 @@ class EventHandlerInfo(ComponentInfo):
|
||||
self.component_type = ComponentType.EVENT_HANDLER
|
||||
|
||||
|
||||
@dataclass
|
||||
class ChatterInfo(ComponentInfo):
|
||||
"""聊天处理器组件信息"""
|
||||
|
||||
chat_type_allow: ChatType = ChatType.ALL # 允许的聊天类型
|
||||
|
||||
def __post_init__(self):
|
||||
super().__post_init__()
|
||||
self.component_type = ComponentType.CHATTER
|
||||
|
||||
|
||||
@dataclass
|
||||
class EventInfo(ComponentInfo):
|
||||
"""事件组件信息"""
|
||||
|
||||
Reference in New Issue
Block a user