ForcePilot/backend/package/yuxi/channel/startup.py
Kris 9e503becd3
Some checks failed
Deploy VitePress site to Pages / build (push) Has been cancelled
Deploy VitePress site to Pages / Deploy (push) Has been cancelled
feat(plugin): 实现完整的插件注册管理系统
新增了插件相关的完整领域模型、应用服务、基础设施实现,包括:
1. 插件状态、注册模式、来源等基础枚举和数据结构
2. 插件清单解析、发现、加载工具类
3. 插件注册表领域服务和内存存储实现
4. 插件相关的命令、查询、事件定义
5. 插件REST API接口和DTO映射
6. 集成了原有通道适配器到插件系统
7. 新增内置插件注册和自动发现能力
2026-05-31 16:44:13 +08:00

74 lines
2.1 KiB
Python

from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from yuxi.channel.container import ChannelContainer
from yuxi.channel.container import ChannelContainerFactory, setup_channel
_container: ChannelContainer | None = None
async def init_channel(
redis_url: str = "",
agent_port=None,
*,
config_yaml_path: str = "channel_config.yaml",
mq_workers: int = 4,
mq_max_concurrent: int = 20,
default_agent_config_id: int = 1,
use_plugin_registry: bool = True,
) -> ChannelContainer:
global _container
plugin_registry_impl = None
if use_plugin_registry:
try:
from yuxi.channel.infrastructure.plugin.registry_impl import PluginRegistryImpl
plugin_registry_impl = PluginRegistryImpl()
import yuxi.channel.channels # noqa: F401
from yuxi.channel.infrastructure.plugin.bundled.register_builtin import register_builtin_plugins
await register_builtin_plugins(plugin_registry_impl.registry)
await plugin_registry_impl.discover_and_register_all()
except ImportError:
pass
_container = await ChannelContainerFactory.create(
redis_url=redis_url,
agent_port=agent_port,
config_yaml_path=config_yaml_path,
mq_workers=mq_workers,
mq_max_concurrent=mq_max_concurrent,
default_agent_config_id=default_agent_config_id,
plugin_registry_impl=plugin_registry_impl,
)
return _container
async def shutdown_channel(container: ChannelContainer | None = None) -> None:
global _container
target = container or _container
if target:
await target.shutdown()
_container = None
def get_container() -> ChannelContainer | None:
return _container
def register_channel_middleware(app) -> None:
if _container:
setup_channel(app, _container)
from yuxi.channel.interfaces.rest.router.registry import register_all_channel_routes
registered = register_all_channel_routes(app, _container.adapters)
import logging
logging.getLogger(__name__).info("registered channel routes: %s", registered)