ForcePilot/backend/package/yuxi/channel/startup.py
Kris 9a8a27bf36 feat(channel): 新增渠道网关模块完整实现
本次提交新增了完整的多渠道消息网关系统,包括:
1. 支持飞书、钉钉、Web、Hook 四种渠道的适配器与配置
2. 领域模型层:消息、会话、绑定、出箱等核心实体
3. 应用服务层:管道、中间件、DTO 与业务逻辑
4. 基础设施层:持久化、过滤器、队列等端口实现
5. 接口层:REST API、SSE、WebSocket 通信端点
6. 前端页面与路由配置,添加渠道管理菜单
7. 新增相关依赖包与 docker-compose 部署配置
2026-05-30 21:53:09 +08:00

49 lines
1.2 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,
) -> ChannelContainer:
global _container
_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,
)
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)