重构聊天系统中的消息发送与处理

- 更新了`uni_message_sender.py`,使用`MessageEnvelope`来发送消息,取代了之前的`MessageSending`结构。
- 引入了`send_envelope`函数,通过改进日志记录和错误处理来简化消息发送流程。
- 修改了`HeartFCSender`以直接处理`MessageEnvelope`,确保与新消息结构的兼容性。
- 重构了`default_generator.py`,以构建`MessageEnvelope`而不是`MessageSending`,从而增强了消息构建逻辑。
- 调整了`utils.py`中的效用函数,以使用`DatabaseUserInfo`来处理用户信息。
- 更新了`send_api.py`以构建和发送`MessageEnvelope`,从而改进了消息分发逻辑。
- 从插件系统中移除了已弃用的`MaiMessages`类,清理了未使用的代码。
- 增强了`napcat_adapter_plugin`以适应新的消息结构,确保消息的正确处理和发送。
- 对代码进行整体清理和整理,以提高可维护性和可读性。
This commit is contained in:
Windpicker-owo
2025-11-25 21:54:27 +08:00
parent c268ea2fb2
commit b6de9b5a9c
20 changed files with 295 additions and 1056 deletions

View File

@@ -24,7 +24,6 @@ from .component_types import (
ComponentType,
EventHandlerInfo,
EventType,
MaiMessages,
PluginInfo,
PlusCommandInfo,
PythonDependency,
@@ -55,7 +54,6 @@ __all__ = [
"ConfigField",
"EventHandlerInfo",
"EventType",
"MaiMessages",
"PluginInfo",
"PluginMetadata",
# 增强命令系统

View File

@@ -33,9 +33,6 @@ class InjectionRule:
] and self.target_content is None:
raise ValueError(f"'{self.injection_type.value}'类型的注入规则必须提供 'target_content'")
from mofox_bus import Seg
from src.llm_models.payload_content.tool_option import ToolCall as ToolCall
from src.llm_models.payload_content.tool_option import ToolParamType as ToolParamType
@@ -410,56 +407,6 @@ class PluginInfo:
return requirements
@dataclass
class MaiMessages:
"""MaiM插件消息"""
message_segments: list[Seg] = field(default_factory=list)
"""消息段列表,支持多段消息"""
message_base_info: dict[str, Any] = field(default_factory=dict)
"""消息基本信息,包含平台,用户信息等数据"""
plain_text: str = ""
"""纯文本消息内容"""
raw_message: str | None = None
"""原始消息内容"""
is_group_message: bool = False
"""是否为群组消息"""
is_private_message: bool = False
"""是否为私聊消息"""
stream_id: str | None = None
"""流ID用于标识消息流"""
llm_prompt: str | None = None
"""LLM提示词"""
llm_response_content: str | None = None
"""LLM响应内容"""
llm_response_reasoning: str | None = None
"""LLM响应推理内容"""
llm_response_model: str | None = None
"""LLM响应模型名称"""
llm_response_tool_call: list[ToolCall] | None = None
"""LLM使用的工具调用"""
action_usage: list[str] | None = None
"""使用的Action"""
additional_data: dict[Any, Any] = field(default_factory=dict)
"""附加数据,可以存储额外信息"""
def __post_init__(self):
if self.message_segments is None:
self.message_segments = []
@dataclass
class RouterInfo(ComponentInfo):
"""路由组件信息"""