refactor(channel-domain): 重构端口定义与导入结构

1. 新增多个领域端口协议类,包括签名验证、路由贡献、关键词匹配等完整的端口定义
2. 重构ChannelRouteContributor重命名为ChannelRouteContributorPort并统一导入路径
3. 调整端口目录结构,拆分external和internal子目录并分别导出
4. 更新所有引用了旧端口定义的业务代码和测试用例
This commit is contained in:
Kris 2026-05-31 17:38:33 +08:00
parent 6b9fb39807
commit 39b7df2ce0
26 changed files with 54 additions and 32 deletions

View File

@ -9,7 +9,7 @@ from yuxi.channel.domain.model.message.dispatch_result import SendResult
from yuxi.channel.domain.model.message.unified_message import UnifiedMessage
from yuxi.channel.domain.model.shared.channel_capabilities import ChannelCapabilities
from yuxi.channel.domain.model.shared.channel_type import ChannelType
from yuxi.channel.domain.port.channel_route_contributor import ChannelRouteContributor
from yuxi.channel.domain.port.channel_route_contributor_port import ChannelRouteContributorPort
from yuxi.channel.domain.port.ws_connection_port import WsConnectionPort
logger = logging.getLogger(__name__)
@ -57,7 +57,7 @@ class FeishuAdapter:
return self._ws
@property
def route_contributor(self) -> ChannelRouteContributor | None:
def route_contributor(self) -> ChannelRouteContributorPort | None:
return _FeishuRouteContributor()
@classmethod

View File

@ -8,7 +8,7 @@ from yuxi.channel.domain.model.message.dispatch_result import SendResult
from yuxi.channel.domain.model.message.unified_message import UnifiedMessage
from yuxi.channel.domain.model.shared.channel_capabilities import ChannelCapabilities
from yuxi.channel.domain.model.shared.channel_type import ChannelType
from yuxi.channel.domain.port.channel_route_contributor import ChannelRouteContributor
from yuxi.channel.domain.port.channel_route_contributor_port import ChannelRouteContributorPort
from yuxi.channel.domain.port.ws_connection_port import WsConnectionPort
logger = logging.getLogger(__name__)
@ -55,7 +55,7 @@ class HooksAdapter:
return None
@property
def route_contributor(self) -> ChannelRouteContributor | None:
def route_contributor(self) -> ChannelRouteContributorPort | None:
return _HooksRouteContributor()
@classmethod

View File

@ -8,7 +8,7 @@ from yuxi.channel.domain.model.message.dispatch_result import SendResult
from yuxi.channel.domain.model.message.unified_message import UnifiedMessage
from yuxi.channel.domain.model.shared.channel_capabilities import ChannelCapabilities
from yuxi.channel.domain.model.shared.channel_type import ChannelType
from yuxi.channel.domain.port.channel_route_contributor import ChannelRouteContributor
from yuxi.channel.domain.port.channel_route_contributor_port import ChannelRouteContributorPort
from yuxi.channel.domain.port.sse_push_port import SsePushPort
from yuxi.channel.domain.port.ws_connection_port import WsConnectionPort
@ -41,7 +41,7 @@ class WebAdapter:
return None
@property
def route_contributor(self) -> ChannelRouteContributor | None:
def route_contributor(self) -> ChannelRouteContributorPort | None:
return _WebRouteContributor()
@classmethod

View File

@ -29,7 +29,7 @@ _LAZY_IMPORTS = {
"KeywordMatcherPort": "yuxi.channel.domain.port",
"CachePort": "yuxi.channel.domain.port",
"ChannelAdapterPort": "yuxi.channel.domain.port",
"ChannelRouteContributor": "yuxi.channel.domain.port",
"ChannelRouteContributorPort": "yuxi.channel.domain.port",
"CircuitBreakerPort": "yuxi.channel.domain.port",
"ConfigReloadPort": "yuxi.channel.domain.port",
"ContentFilterPort": "yuxi.channel.domain.port",

View File

@ -1,16 +1,22 @@
from yuxi.channel.domain.port.agent_port import AgentPort
from yuxi.channel.domain.port.bot_loop_guard_port import BotLoopGuardPort
from yuxi.channel.domain.port.cache_port import CachePort
from yuxi.channel.domain.port.channel_adapter_port import ChannelAdapterPort
from yuxi.channel.domain.port.channel_route_contributor import ChannelRouteContributor
from yuxi.channel.domain.port.circuit_breaker_port import CircuitBreakerPort
from yuxi.channel.domain.port.config_reload_port import ConfigReloadPort
from yuxi.channel.domain.port.content_filter_port import ContentFilterPort, FilterResult
from yuxi.channel.domain.port.event_publisher_port import DomainEvent, EventPublisherPort
from yuxi.channel.domain.port.keyword_matcher_port import KeywordMatcherPort
from yuxi.channel.domain.port.metrics_port import MetricsPort
from yuxi.channel.domain.port.queue_port import QueuePort
from yuxi.channel.domain.port.rate_limit_port import RateLimitPort
from yuxi.channel.domain.port.signature_verify_port import SignatureVerifyPort
from yuxi.channel.domain.port.sse_push_port import SsePushPort
from yuxi.channel.domain.port.ws_connection_port import WsConnectionPort
from yuxi.channel.domain.port.external import (
ChannelAdapterPort,
ChannelRouteContributorPort,
SignatureVerifyPort,
WsConnectionPort,
)
from yuxi.channel.domain.port.internal import (
AgentPort,
BotLoopGuardPort,
CachePort,
CircuitBreakerPort,
ConfigReloadPort,
ContentFilterPort,
DomainEvent,
EventPublisherPort,
FilterResult,
KeywordMatcherPort,
MetricsPort,
QueuePort,
RateLimitPort,
SsePushPort,
)

View File

@ -0,0 +1,4 @@
from yuxi.channel.domain.port.external.channel_adapter_port import ChannelAdapterPort
from yuxi.channel.domain.port.external.channel_route_contributor_port import ChannelRouteContributorPort
from yuxi.channel.domain.port.external.signature_verify_port import SignatureVerifyPort
from yuxi.channel.domain.port.external.ws_connection_port import WsConnectionPort

View File

@ -4,6 +4,6 @@ from typing import Protocol, runtime_checkable
@runtime_checkable
class ChannelRouteContributor(Protocol):
class ChannelRouteContributorPort(Protocol):
@property
def router(self) -> object: ...

View File

@ -0,0 +1,12 @@
from yuxi.channel.domain.port.internal.agent_port import AgentPort
from yuxi.channel.domain.port.internal.bot_loop_guard_port import BotLoopGuardPort
from yuxi.channel.domain.port.internal.cache_port import CachePort
from yuxi.channel.domain.port.internal.circuit_breaker_port import CircuitBreakerPort
from yuxi.channel.domain.port.internal.config_reload_port import ConfigReloadPort
from yuxi.channel.domain.port.internal.content_filter_port import ContentFilterPort, FilterResult
from yuxi.channel.domain.port.internal.event_publisher_port import DomainEvent, EventPublisherPort
from yuxi.channel.domain.port.internal.keyword_matcher_port import KeywordMatcherPort
from yuxi.channel.domain.port.internal.metrics_port import MetricsPort
from yuxi.channel.domain.port.internal.queue_port import QueuePort
from yuxi.channel.domain.port.internal.rate_limit_port import RateLimitPort
from yuxi.channel.domain.port.internal.sse_push_port import SsePushPort

View File

@ -5,7 +5,7 @@ import logging
from fastapi import FastAPI
from yuxi.channel.domain.port.channel_adapter_port import ChannelAdapterPort
from yuxi.channel.domain.port.channel_route_contributor import ChannelRouteContributor
from yuxi.channel.domain.port.channel_route_contributor_port import ChannelRouteContributorPort
logger = logging.getLogger(__name__)
@ -30,11 +30,11 @@ def register_all_channel_routes(
return registered
def _get_route_contributor(adapter: ChannelAdapterPort) -> ChannelRouteContributor | None:
def _get_route_contributor(adapter: ChannelAdapterPort) -> ChannelRouteContributorPort | None:
contributor = getattr(adapter, "route_contributor", None)
if contributor is None:
return None
if isinstance(contributor, ChannelRouteContributor):
if isinstance(contributor, ChannelRouteContributorPort):
return contributor
if hasattr(contributor, "router"):
return contributor

View File

@ -1,10 +1,10 @@
from __future__ import annotations
from yuxi.channel.domain.port.channel_route_contributor import ChannelRouteContributor
from yuxi.channel.domain.port.channel_route_contributor_port import ChannelRouteContributorPort
def test_channel_route_contributor_is_protocol() -> None:
assert hasattr(ChannelRouteContributor, "router")
def test_channel_route_contributor_port_is_protocol() -> None:
assert hasattr(ChannelRouteContributorPort, "router")
class _FakeContributor:
@ -15,4 +15,4 @@ class _FakeContributor:
def test_fake_contributor_is_instance() -> None:
obj = _FakeContributor()
assert isinstance(obj, ChannelRouteContributor)
assert isinstance(obj, ChannelRouteContributorPort)

View File

@ -4,7 +4,7 @@ import pytest
from fastapi import FastAPI, APIRouter
from yuxi.channel.interfaces.rest.router.registry import register_all_channel_routes, _get_route_contributor
from yuxi.channel.domain.port.channel_route_contributor import ChannelRouteContributor
from yuxi.channel.domain.port.channel_route_contributor_port import ChannelRouteContributorPort
class _FakeContributor: