2026-07-02 03:22:12 +08:00
|
|
|
|
"""多渠道网关契约层入口。
|
|
|
|
|
|
|
|
|
|
|
|
契约层是横切层,所有层(core/application/adapters/framework)均可依赖,
|
|
|
|
|
|
自身不得依赖任何实现层。本包聚合驱动端口、被驱动端口、DTO、错误类型、
|
|
|
|
|
|
渠道插件协议等子模块,提供统一导出入口。
|
|
|
|
|
|
|
|
|
|
|
|
子包分组:
|
2026-07-03 19:18:13 +08:00
|
|
|
|
- **端口**(ports):25 个驱动端口 + 28 个被驱动端口,定义核心与外部边界
|
2026-07-02 03:22:12 +08:00
|
|
|
|
的交互契约,使用 ``typing.Protocol`` + ``@runtime_checkable`` 风格声明。
|
|
|
|
|
|
- **DTO**(dtos):38 个模块的跨层共享不可变值对象(``dataclass(frozen=True)``),
|
|
|
|
|
|
覆盖渠道、消息、路由、身份、会话、健康、配置、审计、插件等全场景。
|
|
|
|
|
|
- **错误**(errors):Client / Server / Domain 三大类错误层级,禁止原生异常
|
|
|
|
|
|
穿透至核心层。
|
|
|
|
|
|
- **插件协议**(plugin):渠道插件协议(组合式适配器契约),包含插件入口、
|
|
|
|
|
|
清单、能力声明与证明、生命周期钩子、扩展点协议与 15 个适配器协议。
|
|
|
|
|
|
|
|
|
|
|
|
入参 / 出参均为契约层不可变值对象,不泄露领域实体引用。
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
|
|
# DTO(dtos):核心跨层共享值对象(按使用频率选取主要类型)
|
|
|
|
|
|
from yuxi.channels.contract.dtos import (
|
|
|
|
|
|
AdminSendCmd,
|
|
|
|
|
|
AdminSendResult,
|
|
|
|
|
|
Attachment,
|
|
|
|
|
|
ChannelAccount,
|
|
|
|
|
|
ChannelHealth,
|
|
|
|
|
|
ChannelSession,
|
|
|
|
|
|
ChannelType,
|
|
|
|
|
|
ControlCmd,
|
|
|
|
|
|
ControlResult,
|
|
|
|
|
|
ConversationId,
|
|
|
|
|
|
FailureDetail,
|
|
|
|
|
|
HealthQuery,
|
|
|
|
|
|
InboundMessageCmd,
|
|
|
|
|
|
InboundResult,
|
|
|
|
|
|
LifecycleCmd,
|
|
|
|
|
|
LifecycleResult,
|
|
|
|
|
|
Message,
|
|
|
|
|
|
MessageContent,
|
|
|
|
|
|
MessageFormat,
|
|
|
|
|
|
MessageId,
|
|
|
|
|
|
Operator,
|
|
|
|
|
|
OperatorRole,
|
|
|
|
|
|
RawEvent,
|
|
|
|
|
|
RequestId,
|
|
|
|
|
|
SaveMessageCmd,
|
|
|
|
|
|
SkipDetail,
|
|
|
|
|
|
TraceContext,
|
|
|
|
|
|
TraceId,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# 错误类型(errors):base / client / server / domain
|
|
|
|
|
|
from yuxi.channels.contract.errors import (
|
|
|
|
|
|
AuthError,
|
|
|
|
|
|
BotLoopBudgetExceededError,
|
|
|
|
|
|
CapabilityNotProvenError,
|
|
|
|
|
|
ChannelDegradedError,
|
|
|
|
|
|
ClientError,
|
|
|
|
|
|
ConfigNotHotReloadableError,
|
|
|
|
|
|
ConfigRestartRequiredError,
|
|
|
|
|
|
ConfigRollbackError,
|
|
|
|
|
|
ConfigValidationError,
|
|
|
|
|
|
ConfigVersionConflictError,
|
|
|
|
|
|
ConflictError,
|
|
|
|
|
|
DependencyError,
|
|
|
|
|
|
DmDeniedError,
|
|
|
|
|
|
DomainError,
|
|
|
|
|
|
Error,
|
|
|
|
|
|
InternalError,
|
|
|
|
|
|
NotFoundError,
|
2026-07-04 00:14:56 +08:00
|
|
|
|
OperationTimeoutError,
|
2026-07-02 03:22:12 +08:00
|
|
|
|
PairingExpiredError,
|
|
|
|
|
|
PermissionDeniedError,
|
|
|
|
|
|
PluginAlreadyRegisteredError,
|
|
|
|
|
|
PluginFailedError,
|
|
|
|
|
|
PluginNotFoundError,
|
|
|
|
|
|
RateLimitError,
|
|
|
|
|
|
RuleViolationError,
|
|
|
|
|
|
SchemaInitializationError,
|
|
|
|
|
|
ServerError,
|
|
|
|
|
|
ValidationError,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# 插件协议(plugin):manifest / entry / capability / lifecycle / extension_point / adapters
|
|
|
|
|
|
from yuxi.channels.contract.plugin import (
|
|
|
|
|
|
CHANNEL_ENTRY,
|
|
|
|
|
|
CapabilityDeclaration,
|
|
|
|
|
|
CapabilityProof,
|
|
|
|
|
|
CapabilityProver,
|
|
|
|
|
|
ChannelManifest,
|
|
|
|
|
|
CommandAdapter,
|
|
|
|
|
|
ConfigField,
|
|
|
|
|
|
ConfigSource,
|
|
|
|
|
|
ConflictStrategy,
|
|
|
|
|
|
DirectoryAdapter,
|
|
|
|
|
|
DoctorAdapter,
|
|
|
|
|
|
EventSubscription,
|
|
|
|
|
|
FailurePolicy,
|
|
|
|
|
|
FailureStrategy,
|
|
|
|
|
|
IdentityResolverAdapter,
|
|
|
|
|
|
InboundAdapter,
|
|
|
|
|
|
LifecycleHook,
|
|
|
|
|
|
LifecycleHookHandler,
|
|
|
|
|
|
LifecycleState,
|
|
|
|
|
|
MentionAdapter,
|
|
|
|
|
|
MessageOpsAdapter,
|
|
|
|
|
|
OutboundAdapter,
|
|
|
|
|
|
PluginDependency,
|
|
|
|
|
|
PluginHost,
|
|
|
|
|
|
PluginManifest,
|
|
|
|
|
|
ResourceQuota,
|
|
|
|
|
|
RichMessageAdapter,
|
|
|
|
|
|
SessionAdapter,
|
|
|
|
|
|
Stage,
|
|
|
|
|
|
StageSlot,
|
|
|
|
|
|
StatusAdapter,
|
|
|
|
|
|
StreamingAdapter,
|
|
|
|
|
|
ToolsAdapter,
|
|
|
|
|
|
WhitelistAdapter,
|
|
|
|
|
|
WizardAdapter,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2026-07-03 19:18:13 +08:00
|
|
|
|
# 端口(ports):26 个驱动端口 + 27 个被驱动端口
|
2026-07-02 03:22:12 +08:00
|
|
|
|
from yuxi.channels.contract.ports import (
|
|
|
|
|
|
AccountManagementPort,
|
|
|
|
|
|
AdminMessagePort,
|
2026-07-03 19:18:13 +08:00
|
|
|
|
AgentManagementPort,
|
2026-07-02 03:22:12 +08:00
|
|
|
|
AgentRunExecutionPort,
|
|
|
|
|
|
AgentRunPort,
|
2026-07-03 19:18:13 +08:00
|
|
|
|
AnalyticsViewPort,
|
2026-07-02 03:22:12 +08:00
|
|
|
|
AuditLogRepositoryPort,
|
|
|
|
|
|
AuditQueryPort,
|
|
|
|
|
|
CachePort,
|
2026-07-03 19:18:13 +08:00
|
|
|
|
CapabilityQueryPort,
|
2026-07-02 03:22:12 +08:00
|
|
|
|
ChannelAccountRepositoryPort,
|
|
|
|
|
|
ChannelContextProviderPort,
|
|
|
|
|
|
ChannelLoginPort,
|
|
|
|
|
|
ChannelSessionRepositoryPort,
|
|
|
|
|
|
ChannelToolExecutorPort,
|
|
|
|
|
|
CloseablePort,
|
|
|
|
|
|
ConfigManagementPort,
|
|
|
|
|
|
ConfigPort,
|
2026-07-03 19:18:13 +08:00
|
|
|
|
ContentReviewPort,
|
|
|
|
|
|
ContentReviewQueryPort,
|
2026-07-02 03:22:12 +08:00
|
|
|
|
ConversationPort,
|
2026-07-03 19:18:13 +08:00
|
|
|
|
DashboardViewPort,
|
2026-07-02 03:22:12 +08:00
|
|
|
|
DirectoryPort,
|
|
|
|
|
|
DoctorPort,
|
|
|
|
|
|
EventPublisherPort,
|
|
|
|
|
|
HealthAggregatorPort,
|
|
|
|
|
|
HealthCheckPort,
|
|
|
|
|
|
IdempotencyRepositoryPort,
|
|
|
|
|
|
IdentityResolverPort,
|
|
|
|
|
|
InboundMessagePort,
|
|
|
|
|
|
LoggerPort,
|
|
|
|
|
|
MaskingPort,
|
2026-07-03 19:18:13 +08:00
|
|
|
|
MessageManagementPort,
|
2026-07-02 03:22:12 +08:00
|
|
|
|
MessageOpsPort,
|
2026-07-03 19:18:13 +08:00
|
|
|
|
OutboxManagementPort,
|
2026-07-02 03:22:12 +08:00
|
|
|
|
OutboxRepositoryPort,
|
|
|
|
|
|
PairingManagementPort,
|
|
|
|
|
|
PairingRepositoryPort,
|
|
|
|
|
|
PersistenceHealthPort,
|
|
|
|
|
|
PersistencePort,
|
|
|
|
|
|
PingablePort,
|
|
|
|
|
|
PluginLifecycleManagerPort,
|
|
|
|
|
|
PluginLifecyclePort,
|
2026-07-03 19:18:13 +08:00
|
|
|
|
PluginManagementPort,
|
2026-07-02 03:22:12 +08:00
|
|
|
|
QueuePort,
|
|
|
|
|
|
SessionManagementPort,
|
|
|
|
|
|
TracerPort,
|
|
|
|
|
|
TransactionPort,
|
2026-07-03 19:18:13 +08:00
|
|
|
|
UserBindingPort,
|
2026-07-02 03:22:12 +08:00
|
|
|
|
UserIdentityRepositoryPort,
|
|
|
|
|
|
WhitelistCommandPort,
|
|
|
|
|
|
WhitelistManagementPort,
|
|
|
|
|
|
WizardPort,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
|
|
# 端口(ports)
|
|
|
|
|
|
"AccountManagementPort",
|
|
|
|
|
|
"AdminMessagePort",
|
2026-07-03 19:18:13 +08:00
|
|
|
|
"AgentManagementPort",
|
2026-07-02 03:22:12 +08:00
|
|
|
|
"AgentRunExecutionPort",
|
|
|
|
|
|
"AgentRunPort",
|
2026-07-03 19:18:13 +08:00
|
|
|
|
"AnalyticsViewPort",
|
2026-07-02 03:22:12 +08:00
|
|
|
|
"AuditLogRepositoryPort",
|
|
|
|
|
|
"AuditQueryPort",
|
|
|
|
|
|
"CachePort",
|
2026-07-03 19:18:13 +08:00
|
|
|
|
"CapabilityQueryPort",
|
2026-07-02 03:22:12 +08:00
|
|
|
|
"ChannelAccountRepositoryPort",
|
|
|
|
|
|
"ChannelContextProviderPort",
|
|
|
|
|
|
"ChannelLoginPort",
|
|
|
|
|
|
"ChannelSessionRepositoryPort",
|
|
|
|
|
|
"ChannelToolExecutorPort",
|
|
|
|
|
|
"CloseablePort",
|
|
|
|
|
|
"ConfigManagementPort",
|
|
|
|
|
|
"ConfigPort",
|
2026-07-03 19:18:13 +08:00
|
|
|
|
"ContentReviewPort",
|
|
|
|
|
|
"ContentReviewQueryPort",
|
2026-07-02 03:22:12 +08:00
|
|
|
|
"ConversationPort",
|
2026-07-03 19:18:13 +08:00
|
|
|
|
"DashboardViewPort",
|
2026-07-02 03:22:12 +08:00
|
|
|
|
"DirectoryPort",
|
|
|
|
|
|
"DoctorPort",
|
|
|
|
|
|
"EventPublisherPort",
|
|
|
|
|
|
"HealthAggregatorPort",
|
|
|
|
|
|
"HealthCheckPort",
|
|
|
|
|
|
"IdempotencyRepositoryPort",
|
|
|
|
|
|
"IdentityResolverPort",
|
|
|
|
|
|
"InboundMessagePort",
|
|
|
|
|
|
"LoggerPort",
|
|
|
|
|
|
"MaskingPort",
|
2026-07-03 19:18:13 +08:00
|
|
|
|
"MessageManagementPort",
|
2026-07-02 03:22:12 +08:00
|
|
|
|
"MessageOpsPort",
|
2026-07-03 19:18:13 +08:00
|
|
|
|
"OutboxManagementPort",
|
2026-07-02 03:22:12 +08:00
|
|
|
|
"OutboxRepositoryPort",
|
|
|
|
|
|
"PairingManagementPort",
|
|
|
|
|
|
"PairingRepositoryPort",
|
|
|
|
|
|
"PersistenceHealthPort",
|
|
|
|
|
|
"PersistencePort",
|
|
|
|
|
|
"PingablePort",
|
|
|
|
|
|
"PluginLifecycleManagerPort",
|
|
|
|
|
|
"PluginLifecyclePort",
|
2026-07-03 19:18:13 +08:00
|
|
|
|
"PluginManagementPort",
|
2026-07-02 03:22:12 +08:00
|
|
|
|
"QueuePort",
|
|
|
|
|
|
"SessionManagementPort",
|
|
|
|
|
|
"TransactionPort",
|
|
|
|
|
|
"TracerPort",
|
2026-07-03 19:18:13 +08:00
|
|
|
|
"UserBindingPort",
|
2026-07-02 03:22:12 +08:00
|
|
|
|
"UserIdentityRepositoryPort",
|
|
|
|
|
|
"WhitelistCommandPort",
|
|
|
|
|
|
"WhitelistManagementPort",
|
|
|
|
|
|
"WizardPort",
|
|
|
|
|
|
# 错误类型(errors)
|
|
|
|
|
|
"AuthError",
|
|
|
|
|
|
"BotLoopBudgetExceededError",
|
|
|
|
|
|
"CapabilityNotProvenError",
|
|
|
|
|
|
"ChannelDegradedError",
|
|
|
|
|
|
"ClientError",
|
|
|
|
|
|
"ConfigNotHotReloadableError",
|
|
|
|
|
|
"ConfigRestartRequiredError",
|
|
|
|
|
|
"ConfigRollbackError",
|
|
|
|
|
|
"ConfigValidationError",
|
|
|
|
|
|
"ConfigVersionConflictError",
|
|
|
|
|
|
"ConflictError",
|
|
|
|
|
|
"DependencyError",
|
|
|
|
|
|
"DmDeniedError",
|
|
|
|
|
|
"DomainError",
|
|
|
|
|
|
"Error",
|
|
|
|
|
|
"InternalError",
|
|
|
|
|
|
"NotFoundError",
|
|
|
|
|
|
"PairingExpiredError",
|
|
|
|
|
|
"PermissionDeniedError",
|
|
|
|
|
|
"PluginAlreadyRegisteredError",
|
|
|
|
|
|
"PluginFailedError",
|
|
|
|
|
|
"PluginNotFoundError",
|
|
|
|
|
|
"RateLimitError",
|
|
|
|
|
|
"RuleViolationError",
|
|
|
|
|
|
"SchemaInitializationError",
|
|
|
|
|
|
"ServerError",
|
2026-07-03 19:18:13 +08:00
|
|
|
|
"OperationTimeoutError",
|
2026-07-02 03:22:12 +08:00
|
|
|
|
"ValidationError",
|
|
|
|
|
|
# 插件协议(plugin)
|
|
|
|
|
|
"CHANNEL_ENTRY",
|
|
|
|
|
|
"CapabilityDeclaration",
|
|
|
|
|
|
"CapabilityProof",
|
|
|
|
|
|
"CapabilityProver",
|
|
|
|
|
|
"ChannelManifest",
|
|
|
|
|
|
"CommandAdapter",
|
|
|
|
|
|
"ConfigField",
|
|
|
|
|
|
"ConflictStrategy",
|
|
|
|
|
|
"ConfigSource",
|
|
|
|
|
|
"DirectoryAdapter",
|
|
|
|
|
|
"DoctorAdapter",
|
|
|
|
|
|
"EventSubscription",
|
|
|
|
|
|
"FailurePolicy",
|
|
|
|
|
|
"FailureStrategy",
|
|
|
|
|
|
"IdentityResolverAdapter",
|
|
|
|
|
|
"InboundAdapter",
|
|
|
|
|
|
"LifecycleHook",
|
|
|
|
|
|
"LifecycleHookHandler",
|
|
|
|
|
|
"LifecycleState",
|
|
|
|
|
|
"MentionAdapter",
|
|
|
|
|
|
"MessageOpsAdapter",
|
|
|
|
|
|
"OutboundAdapter",
|
|
|
|
|
|
"PluginDependency",
|
|
|
|
|
|
"PluginHost",
|
|
|
|
|
|
"PluginManifest",
|
|
|
|
|
|
"ResourceQuota",
|
|
|
|
|
|
"RichMessageAdapter",
|
|
|
|
|
|
"SessionAdapter",
|
|
|
|
|
|
"Stage",
|
|
|
|
|
|
"StageSlot",
|
|
|
|
|
|
"StatusAdapter",
|
|
|
|
|
|
"StreamingAdapter",
|
|
|
|
|
|
"ToolsAdapter",
|
|
|
|
|
|
"WhitelistAdapter",
|
|
|
|
|
|
"WizardAdapter",
|
|
|
|
|
|
# DTO(dtos)核心类型
|
|
|
|
|
|
"AdminSendCmd",
|
|
|
|
|
|
"AdminSendResult",
|
|
|
|
|
|
"Attachment",
|
|
|
|
|
|
"ChannelAccount",
|
|
|
|
|
|
"ChannelHealth",
|
|
|
|
|
|
"ChannelSession",
|
|
|
|
|
|
"ChannelType",
|
|
|
|
|
|
"ControlCmd",
|
|
|
|
|
|
"ControlResult",
|
|
|
|
|
|
"ConversationId",
|
|
|
|
|
|
"FailureDetail",
|
|
|
|
|
|
"HealthQuery",
|
|
|
|
|
|
"InboundMessageCmd",
|
|
|
|
|
|
"InboundResult",
|
|
|
|
|
|
"LifecycleCmd",
|
|
|
|
|
|
"LifecycleResult",
|
|
|
|
|
|
"Message",
|
|
|
|
|
|
"MessageContent",
|
|
|
|
|
|
"MessageFormat",
|
|
|
|
|
|
"MessageId",
|
|
|
|
|
|
"Operator",
|
|
|
|
|
|
"OperatorRole",
|
|
|
|
|
|
"RawEvent",
|
|
|
|
|
|
"RequestId",
|
|
|
|
|
|
"SaveMessageCmd",
|
|
|
|
|
|
"SkipDetail",
|
|
|
|
|
|
"TraceContext",
|
|
|
|
|
|
"TraceId",
|
|
|
|
|
|
]
|