本次提交对频道模块进行了全面重构并新增多项核心功能: 1. 优化适配器状态获取逻辑,修复状态返回空值问题 2. 新增4种频道异常类型,完善错误处理体系 3. 大幅精简Mixin类,移除冗余的抽象方法定义 4. 重构适配器注册系统,统一注册入口并新增内置适配器加载方法 5. 扩展插件系统,新增更多元数据配置项支持 6. 新增线程类型、会话范围等模型定义,扩展事件类型枚举 7. 优化用户映射逻辑,使用PostgreSQL upsert避免重复创建 8. 新增历史消息注入模块,支持多格式历史格式化与缓存管理 9. 新增线程能力配置与各平台预置适配配置 10. 新增线程绑定管理器,支持多类型线程绑定生命周期管理 11. 重构__init__.py,整理导出模块与类型 12. 扩展基础适配器类,新增凭证解析、状态存储等核心方法 13. 重写消息路由器,支持按频道加载策略、安全校验与多命令处理 14. 新增/history、/context、/summary等交互命令实现 15. 优化消息记录与统计逻辑,完善路由调度链路
193 lines
5.1 KiB
Python
193 lines
5.1 KiB
Python
from yuxi.channels.auth import (
|
|
AuthHealth,
|
|
AuthHealthMonitor,
|
|
BackoffConfig,
|
|
BaseTokenProvider,
|
|
CertificateTokenProvider,
|
|
CompatTokenProvider,
|
|
DmPolicy,
|
|
ExponentialBackoff,
|
|
GroupPolicy,
|
|
NetworkGuardError,
|
|
OAuth2TokenProvider,
|
|
QRTokenProvider,
|
|
SecretManager,
|
|
SecretSource,
|
|
SecurityPolicy,
|
|
SecurityPolicyEngine,
|
|
SensitiveDataFilter,
|
|
StaticTokenProvider,
|
|
TokenProviderType,
|
|
TokenState,
|
|
UnifiedTokenManager,
|
|
apply_ssrf_guard_defaults,
|
|
build_ssrf_safe_headers,
|
|
check_response_size,
|
|
check_response_text,
|
|
fetch_with_ssrf_guard,
|
|
get_health_monitor,
|
|
get_secret_manager,
|
|
get_security_policy_engine,
|
|
get_token_manager,
|
|
init_secret_manager,
|
|
is_hostname_allowed,
|
|
is_private_url,
|
|
redact_sensitive,
|
|
safe_webhook_url,
|
|
sanitize_transport_kwargs,
|
|
validate_url,
|
|
validate_url_with_whitelist,
|
|
)
|
|
from yuxi.channels.base import BaseChannelAdapter
|
|
from yuxi.channels.bridge import BridgeAdapter
|
|
from yuxi.channels.capabilities import ChannelCapabilities
|
|
from yuxi.channels.exceptions import (
|
|
ChannelAuthenticationError,
|
|
ChannelConnectionError,
|
|
ChannelException,
|
|
ChannelNotConnectedError,
|
|
ChannelRateLimitError,
|
|
DeliveryFailedError,
|
|
MessageFormatError,
|
|
)
|
|
from yuxi.channels.infra.broadcast import EventBroadcaster
|
|
from yuxi.channels.infra.circuit_breaker import CircuitBreaker, CircuitBreakerOpenError, CircuitState
|
|
from yuxi.channels.infra.config_watcher import ConfigWatcher
|
|
from yuxi.channels.manager import ChannelManager
|
|
from yuxi.channels.meta import ChannelMeta
|
|
from yuxi.channels.models import (
|
|
AgentRequest,
|
|
AgentResult,
|
|
Attachment,
|
|
ChannelAccountSnapshot,
|
|
ChannelIdentity,
|
|
ChannelMessage,
|
|
ChannelResponse,
|
|
ChannelStatus,
|
|
ChannelType,
|
|
ChatType,
|
|
DeliveryResult,
|
|
EventType,
|
|
HealthStatus,
|
|
MentionsInfo,
|
|
MessageType,
|
|
TokenStatus,
|
|
build_snapshot_from_adapter,
|
|
)
|
|
from yuxi.channels.plugin import ChannelPlugin, channel_plugin
|
|
from yuxi.channels.policy.heartbeat import BaseHeartbeatAdapter
|
|
from yuxi.channels.protocols import (
|
|
ChannelConfigProtocol,
|
|
ChannelGatewayProtocol,
|
|
ChannelHeartbeatProtocol,
|
|
ChannelLifecycleProtocol,
|
|
ChannelMessageActionProtocol,
|
|
ChannelMessagingProtocol,
|
|
ChannelOutboundProtocol,
|
|
ChannelStatusProtocol,
|
|
ChannelThreadingProtocol,
|
|
)
|
|
from yuxi.channels.registry import ChannelRegistry, register_builtin_adapter
|
|
from yuxi.channels.router import MessageRouter
|
|
from yuxi.channels.services.context import ChatAbortEntry, ChatRunBuffer, GatewayRequestContext
|
|
from yuxi.channels.services.doctor import ConfigDoctor, DiagnosisIssue
|
|
from yuxi.channels.services.maintenance import MaintenanceRunner
|
|
from yuxi.channels.session_mapper import SessionMapper
|
|
|
|
__all__ = [
|
|
"AgentRequest",
|
|
"AgentResult",
|
|
"Attachment",
|
|
"ChannelAccountSnapshot",
|
|
"ChannelIdentity",
|
|
"ChannelMessage",
|
|
"ChannelResponse",
|
|
"ChannelStatus",
|
|
"ChannelType",
|
|
"ChatType",
|
|
"DeliveryResult",
|
|
"EventType",
|
|
"HealthStatus",
|
|
"MentionsInfo",
|
|
"MessageType",
|
|
"TokenStatus",
|
|
"build_snapshot_from_adapter",
|
|
"BaseChannelAdapter",
|
|
"BaseHeartbeatAdapter",
|
|
"ChannelAuthenticationError",
|
|
"ChannelConnectionError",
|
|
"ChannelException",
|
|
"ChannelNotConnectedError",
|
|
"ChannelRateLimitError",
|
|
"DeliveryFailedError",
|
|
"MessageFormatError",
|
|
"CircuitBreaker",
|
|
"CircuitBreakerOpenError",
|
|
"CircuitState",
|
|
"ChannelRegistry",
|
|
"register_builtin_adapter",
|
|
"ChannelManager",
|
|
"MessageRouter",
|
|
"SessionMapper",
|
|
"MaintenanceRunner",
|
|
"BridgeAdapter",
|
|
"ChannelPlugin",
|
|
"channel_plugin",
|
|
"ChannelMeta",
|
|
"ChannelCapabilities",
|
|
"ChannelConfigProtocol",
|
|
"ChannelGatewayProtocol",
|
|
"ChannelHeartbeatProtocol",
|
|
"ChannelLifecycleProtocol",
|
|
"ChannelMessageActionProtocol",
|
|
"ChannelMessagingProtocol",
|
|
"ChannelOutboundProtocol",
|
|
"ChannelStatusProtocol",
|
|
"ChannelThreadingProtocol",
|
|
"ChatAbortEntry",
|
|
"ChatRunBuffer",
|
|
"GatewayRequestContext",
|
|
"EventBroadcaster",
|
|
"ConfigWatcher",
|
|
"ConfigDoctor",
|
|
"DiagnosisIssue",
|
|
"SecretManager",
|
|
"SecretSource",
|
|
"get_secret_manager",
|
|
"init_secret_manager",
|
|
"BaseTokenProvider",
|
|
"TokenProviderType",
|
|
"TokenState",
|
|
"UnifiedTokenManager",
|
|
"get_token_manager",
|
|
"CertificateTokenProvider",
|
|
"CompatTokenProvider",
|
|
"OAuth2TokenProvider",
|
|
"QRTokenProvider",
|
|
"StaticTokenProvider",
|
|
"AuthHealth",
|
|
"AuthHealthMonitor",
|
|
"get_health_monitor",
|
|
"BackoffConfig",
|
|
"ExponentialBackoff",
|
|
"DmPolicy",
|
|
"GroupPolicy",
|
|
"SecurityPolicy",
|
|
"SecurityPolicyEngine",
|
|
"get_security_policy_engine",
|
|
"SensitiveDataFilter",
|
|
"redact_sensitive",
|
|
"NetworkGuardError",
|
|
"apply_ssrf_guard_defaults",
|
|
"build_ssrf_safe_headers",
|
|
"check_response_size",
|
|
"check_response_text",
|
|
"fetch_with_ssrf_guard",
|
|
"is_hostname_allowed",
|
|
"is_private_url",
|
|
"safe_webhook_url",
|
|
"sanitize_transport_kwargs",
|
|
"validate_url",
|
|
"validate_url_with_whitelist",
|
|
]
|