ForcePilot/backend/package/yuxi/channel/interfaces/rest/router/registry.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

42 lines
1.2 KiB
Python

from __future__ import annotations
import logging
from fastapi import FastAPI
from yuxi.channel.domain.port.channel_adapter_port import ChannelAdapterPort
from yuxi.channel.interfaces.rest.router.contributor import ChannelRouteContributor
logger = logging.getLogger(__name__)
def register_all_channel_routes(
app: FastAPI,
adapters: dict[str, ChannelAdapterPort],
) -> list[str]:
registered: list[str] = []
for name, adapter in adapters.items():
contributor = _get_route_contributor(adapter)
if contributor is None:
continue
router = contributor.router
prefix = f"/channel/{name}"
app.include_router(router, prefix=prefix)
registered.append(prefix)
logger.info("registered channel routes: %s", prefix)
return registered
def _get_route_contributor(adapter: ChannelAdapterPort) -> ChannelRouteContributor | None:
contributor = getattr(adapter, "route_contributor", None)
if contributor is None:
return None
if isinstance(contributor, ChannelRouteContributor):
return contributor
if hasattr(contributor, "router"):
return contributor
return None