重构适配器系统并增强插件架构
- 在mofox_bus中,将BaseAdapter重命名为AdapterBase以提高清晰度。 - 引入了AdapterInfo类来封装适配器组件信息。 - 增强的PluginManager,支持核心消息接收器配置和适配器注册。 - 实现了EnvelopeConverter,用于将MessageEnvelope转换为内部消息格式。 - 创建了BaseAdapter类来管理插件的生命周期、配置和健康检查。 - 开发了AdapterManager,用于管理适配器实例和子流程。 - 添加了一个示例适配器插件,以展示与新适配器系统的集成。 - 删除了过时的Phi插件文档。
This commit is contained in:
@@ -21,7 +21,7 @@ import websockets
|
||||
sys.path.append(str(Path(__file__).resolve().parents[1] / "src"))
|
||||
|
||||
from mofox_bus import (
|
||||
BaseAdapter,
|
||||
AdapterBase,
|
||||
InProcessCoreSink,
|
||||
MessageEnvelope,
|
||||
MessageRuntime,
|
||||
@@ -86,13 +86,16 @@ class FakePlatformServer:
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 2. 适配器实现:仅关注核心转换逻辑,网络层交由 BaseAdapter 管理
|
||||
# 2. 适配器实现:仅关注核心转换逻辑,网络层交由 AdapterBase 管理
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class DemoWsAdapter(BaseAdapter):
|
||||
platform = "demo"
|
||||
class DemoWsAdapter(AdapterBase): # 继承AdapterBase
|
||||
platform = "demo" # 定义平台名称
|
||||
|
||||
# 实现 from_platform_message 方法,将平台消息转换为 MessageEnvelope
|
||||
# 该方法必须被实现以便 AdapterBase 正确处理消息转换
|
||||
# 该方法会在adapter接收到平台消息后被调用
|
||||
def from_platform_message(self, raw: Dict[str, Any]) -> MessageEnvelope:
|
||||
return {
|
||||
"id": raw["message_id"],
|
||||
@@ -105,7 +108,6 @@ class DemoWsAdapter(BaseAdapter):
|
||||
"content": {"type": "text", "text": raw["text"]},
|
||||
}
|
||||
|
||||
|
||||
def incoming_parser(raw: str | bytes) -> Any:
|
||||
data = orjson.loads(raw)
|
||||
if data.get("type") == "message":
|
||||
|
||||
Reference in New Issue
Block a user