新增了插件相关的完整领域模型、应用服务、基础设施实现,包括: 1. 插件状态、注册模式、来源等基础枚举和数据结构 2. 插件清单解析、发现、加载工具类 3. 插件注册表领域服务和内存存储实现 4. 插件相关的命令、查询、事件定义 5. 插件REST API接口和DTO映射 6. 集成了原有通道适配器到插件系统 7. 新增内置插件注册和自动发现能力
64 lines
1.8 KiB
Python
64 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
from collections.abc import Callable
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from yuxi.channel.domain.port.channel_adapter_port import ChannelAdapterPort
|
|
from yuxi.channel.domain.port.channel_request_verifier_port import ChannelRequestVerifierPort
|
|
|
|
_channel_registry: dict[str, dict] = {}
|
|
_compat_registry: dict[str, type[ChannelAdapterPort]] = {}
|
|
|
|
|
|
def register_channel(
|
|
name: str,
|
|
adapter_cls: type[ChannelAdapterPort],
|
|
*,
|
|
config_cls: type | None = None,
|
|
verifier_factory: Callable[[dict], ChannelRequestVerifierPort] | None = None,
|
|
env_mapping: dict[str, str] | None = None,
|
|
infra_dependencies: list[str] | None = None,
|
|
) -> None:
|
|
_compat_registry[name] = adapter_cls
|
|
_channel_registry[name] = {
|
|
"adapter_cls": adapter_cls,
|
|
"config_cls": config_cls,
|
|
"verifier_factory": verifier_factory,
|
|
"env_mapping": env_mapping or {},
|
|
"infra_dependencies": infra_dependencies or [],
|
|
}
|
|
|
|
try:
|
|
from yuxi.channel.infrastructure.plugin.registry_impl import get_registry
|
|
|
|
registry = get_registry()
|
|
if registry:
|
|
registry.register_builtin_adapter(name, adapter_cls)
|
|
except ImportError:
|
|
pass
|
|
|
|
|
|
def get_channel_meta(name: str) -> dict:
|
|
return _channel_registry.get(name, {})
|
|
|
|
|
|
def get_all_meta() -> dict[str, dict]:
|
|
return dict(_channel_registry)
|
|
|
|
|
|
def get_registered_channels() -> dict[str, type[ChannelAdapterPort]]:
|
|
try:
|
|
from yuxi.channel.infrastructure.plugin.registry_impl import get_registry
|
|
|
|
registry = get_registry()
|
|
if registry:
|
|
return registry.get_registered_adapter_classes()
|
|
except ImportError:
|
|
pass
|
|
return dict(_compat_registry)
|
|
|
|
|
|
def get_compat_registry() -> dict[str, type[ChannelAdapterPort]]:
|
|
return dict(_compat_registry)
|