本提交新增了全渠道SDK核心模块: 1. 异步锁、目标解析、动作调度等基础工具 2. 消息动作注册与统一调度系统 3. 测试套件与契约测试框架 4. 完整的目标解析流水线与工具函数 5. 资源依赖注入与生命周期管理
486 lines
12 KiB
Python
486 lines
12 KiB
Python
from yuxi import __version__, get_version
|
|
from yuxi.channel.approval import ApprovalEngine
|
|
from yuxi.channel.capabilities import ChannelCapabilities
|
|
from yuxi.channel.context import (
|
|
ChannelContext,
|
|
ChannelRuntimeContexts,
|
|
ContextVisibilityMode,
|
|
ConversationBinding,
|
|
SupplementalContext,
|
|
task_scoped_contexts,
|
|
)
|
|
from yuxi.channel.doctor import ChannelDoctorRunner, doctor_runner, get_doctor_runner, reset_doctor_runner, set_doctor_runner
|
|
from yuxi.channel.doctor.models import (
|
|
CheckStatus,
|
|
ConnectivityCheckResult,
|
|
CredentialCheckResult,
|
|
DiagnosisResult,
|
|
DiagnosisWarning,
|
|
DoctorOptions,
|
|
DoctorRepairMode,
|
|
LegacyConfigRule,
|
|
PermissionCheckResult,
|
|
RepairResult,
|
|
RepairStep,
|
|
Severity,
|
|
)
|
|
from yuxi.channel.gateway.client import GatewayClient, GatewayClientError
|
|
from yuxi.channel.gateway.lanes import ChannelLane, LaneManager
|
|
from yuxi.channel.gateway.channel_plugin import GatewayChannelPlugin
|
|
from yuxi.channel.gateway.protocol import (
|
|
DeliveryMode,
|
|
FrameType,
|
|
GatewayErrorCode,
|
|
GatewayRpcMethod,
|
|
)
|
|
from yuxi.channel.gateway.routes import WebhookRegistry, build_webhook_path
|
|
from yuxi.channel.gateway.validation import (
|
|
DiagnoseParams,
|
|
ProbeParams,
|
|
RepairParams,
|
|
SendMessageParams,
|
|
StartAccountParams,
|
|
StopAccountParams,
|
|
validate_params,
|
|
)
|
|
from yuxi.channel.hooks.lifecycle import HookCallback, HookEvent, HookRegistration, LifecycleHookRegistry
|
|
from yuxi.channel.runtime.manager import gateway, get_gateway, reset_gateway, set_gateway
|
|
from yuxi.channel.message.durable_send import (
|
|
DurableMessageReceipt,
|
|
DurableStrategy,
|
|
MessageSendContext,
|
|
MessageSendState,
|
|
)
|
|
from yuxi.channel.message.models import (
|
|
ChunkType,
|
|
DispatchResult,
|
|
GroupContext,
|
|
MentionSource,
|
|
MessageReceipt,
|
|
MessageType,
|
|
PeerInfo,
|
|
ReplyPayload,
|
|
ReplyStage,
|
|
StreamingChunk,
|
|
UnifiedMessage,
|
|
)
|
|
from yuxi.channel.protocols import (
|
|
AgentPromptContext,
|
|
AgentPromptProtocol,
|
|
AgentTool,
|
|
AgentToolParam,
|
|
AgentToolProtocol,
|
|
AllowlistManagementProtocol,
|
|
ApprovalAction,
|
|
ApprovalDecision,
|
|
ApprovalPluginProtocol,
|
|
ApprovalProtocol,
|
|
ApprovalRequest,
|
|
ApprovalResult,
|
|
AuthProtocol,
|
|
BasePluginProtocol,
|
|
BoundReplyPayload,
|
|
CapabilitiesProtocol,
|
|
ChannelAccountSnapshot,
|
|
ChannelStatusIssue,
|
|
ChannelCommand,
|
|
CommandsProtocol,
|
|
ConfigPluginProtocol,
|
|
ConfigProtocol,
|
|
ConfigSchemaProtocol,
|
|
DefaultsProtocol,
|
|
DirectoryGroup,
|
|
DirectoryPeer,
|
|
DirectoryProtocol,
|
|
DirectorySearchParams,
|
|
DirectorySearchResult,
|
|
DoctorProtocol,
|
|
ElevatedProtocol,
|
|
FullMessagingPluginProtocol,
|
|
GatewayPluginProtocol,
|
|
GatewayProtocol,
|
|
GroupsProtocol,
|
|
HeartbeatProtocol,
|
|
InboundMessageHook,
|
|
LifecycleProtocol,
|
|
MentionsProtocol,
|
|
MessageActionCapability,
|
|
MessageActionProtocol,
|
|
MessageSendingHook,
|
|
MessagingProtocol,
|
|
MetaProtocol,
|
|
OutboundPluginProtocol,
|
|
OutboundProtocol,
|
|
PairingProtocol,
|
|
PollingPluginProtocol,
|
|
ReloadProtocol,
|
|
ReplyTransport,
|
|
ResolverProtocol,
|
|
ResolveTarget,
|
|
SecurityProtocol,
|
|
SendLifecycleHook,
|
|
SessionPluginProtocol,
|
|
SessionResolution,
|
|
SetupProtocol,
|
|
SetupWizardProtocol,
|
|
SetupWizardStep,
|
|
StatusProtocol,
|
|
StreamingProtocol,
|
|
ThreadInfo,
|
|
ThreadingProtocol,
|
|
)
|
|
from yuxi.channel.plugins.registry import ChannelPluginRegistry
|
|
from yuxi.channel.routing.models import PeerKind
|
|
from yuxi.channel.routing.session_key import SessionKeyBuilder
|
|
from yuxi.channel.sdk.actions import (
|
|
MESSAGE_ACTION_GROUPS,
|
|
MESSAGE_ACTIONS_ATTACHMENT,
|
|
MESSAGE_ACTIONS_BASIC,
|
|
MESSAGE_ACTIONS_GROUP,
|
|
MESSAGE_ACTIONS_POLL,
|
|
MESSAGE_ACTIONS_THREAD,
|
|
ActionDescriptor,
|
|
ActionHandler,
|
|
MessageAction,
|
|
MessageActionRegistry,
|
|
)
|
|
from yuxi.channel.sdk.actions.dispatch import (
|
|
DispatchContext,
|
|
dispatch_message_action,
|
|
)
|
|
from yuxi.channel.sdk.actions.discovery import (
|
|
build_unified_message_tool_schema,
|
|
get_channel_actions_schema,
|
|
list_all_actions,
|
|
list_channel_actions,
|
|
)
|
|
from yuxi.channel.sdk.async_lock import create_async_lock
|
|
from yuxi.channel.sdk.async_utils import KeyedAsyncQueue, KeyedAsyncQueueHooks, enqueue_keyed_task
|
|
from yuxi.channel.sdk.channel_lifecycle import (
|
|
keep_http_server_task_alive,
|
|
run_passive_account_lifecycle,
|
|
wait_until_abort,
|
|
)
|
|
from yuxi.channel.sdk.dependencies import PluginResourceProvider, get_resources, inject_resources, reset_resources
|
|
from yuxi.channel.sdk.test_utils import create_test_resources, reset_test_resources
|
|
from yuxi.channel.sdk.testing import ContractTestBase, FixtureFactory, create_mock_channel_plugin
|
|
from yuxi.channel.security.allowlist import (
|
|
AllowlistChecker,
|
|
AllowlistCheckResult,
|
|
AllowlistHitReason,
|
|
AllowlistStore,
|
|
DmPolicyMode,
|
|
GroupPolicyMode,
|
|
InMemoryAllowlistStore,
|
|
PostgresAllowlistStore,
|
|
create_allowlist_checker,
|
|
get_allowlist_checker,
|
|
reset_allowlist_checker,
|
|
set_allowlist_checker,
|
|
)
|
|
from yuxi.channel.security.identity_link import IdentityLinkResolver
|
|
from yuxi.channel.security.pairing import (
|
|
InMemoryPairingStore,
|
|
PairingManager,
|
|
PairingStore,
|
|
PostgresPairingStore,
|
|
)
|
|
from yuxi.channel.session import SessionRecorder, SessionOpResult
|
|
from yuxi.channel.streaming.block_chunker import (
|
|
BlockChunker,
|
|
EmbeddedBlockChunker,
|
|
StreamingBlock,
|
|
)
|
|
from yuxi.channel.streaming.draft_stream import (
|
|
DraftStreamLoop,
|
|
FinalizableDraftStreamControls,
|
|
get_tool_status_label,
|
|
)
|
|
from yuxi.channel.streaming.models import (
|
|
DraftStreamSession,
|
|
DraftStreamState,
|
|
StreamingConfig,
|
|
)
|
|
from yuxi.channel.streaming.strategy_selector import (
|
|
StreamingStrategy,
|
|
StreamingStrategySelector,
|
|
)
|
|
from yuxi.channel.utils.lazy import LazyClass, LazyModule, run_sync, run_sync_partial
|
|
from yuxi.channel.security.html_guard import sanitize_text_content_preserve_entities, sanitize_url
|
|
from yuxi.channel.render.parser import parse_markdown
|
|
from yuxi.channel.render.ir import (
|
|
BlockQuote,
|
|
Bold,
|
|
BoldItalic,
|
|
CodeBlock,
|
|
Document,
|
|
Heading,
|
|
Image,
|
|
InlineCode,
|
|
IrNode,
|
|
Italic,
|
|
LineBreak,
|
|
Link,
|
|
ListItem,
|
|
OrderedList,
|
|
Paragraph,
|
|
Strikethrough,
|
|
Table,
|
|
Text,
|
|
ThematicBreak,
|
|
UnorderedList,
|
|
)
|
|
|
|
__all__ = [
|
|
# version
|
|
"__version__",
|
|
"get_version",
|
|
# dependencies
|
|
"PluginResourceProvider",
|
|
"inject_resources",
|
|
"get_resources",
|
|
"reset_resources",
|
|
# async utils
|
|
"KeyedAsyncQueue",
|
|
"KeyedAsyncQueueHooks",
|
|
"enqueue_keyed_task",
|
|
# async lock
|
|
"create_async_lock",
|
|
# channel lifecycle
|
|
"wait_until_abort",
|
|
"run_passive_account_lifecycle",
|
|
"keep_http_server_task_alive",
|
|
# test utils
|
|
"create_test_resources",
|
|
"reset_test_resources",
|
|
"ContractTestBase",
|
|
"FixtureFactory",
|
|
"create_mock_channel_plugin",
|
|
# core
|
|
"ChannelPluginRegistry",
|
|
"ChannelCapabilities",
|
|
"ChannelContext",
|
|
"ChannelRuntimeContexts",
|
|
"ContextVisibilityMode",
|
|
"ConversationBinding",
|
|
"SupplementalContext",
|
|
"task_scoped_contexts",
|
|
# approval
|
|
"ApprovalEngine",
|
|
"ApprovalAction",
|
|
"ApprovalDecision",
|
|
"ApprovalProtocol",
|
|
"ApprovalRequest",
|
|
"ApprovalResult",
|
|
# commands
|
|
"ChannelCommand",
|
|
"CommandsProtocol",
|
|
# resolver
|
|
"ResolveTarget",
|
|
"ResolverProtocol",
|
|
# gateway
|
|
"ChannelLane",
|
|
"DeliveryMode",
|
|
"FrameType",
|
|
"GatewayErrorCode",
|
|
"GatewayClient",
|
|
"GatewayClientError",
|
|
"GatewayChannelPlugin",
|
|
"GatewayRpcMethod",
|
|
"LaneManager",
|
|
"WebhookRegistry",
|
|
"build_webhook_path",
|
|
# validation
|
|
"StartAccountParams",
|
|
"StopAccountParams",
|
|
"SendMessageParams",
|
|
"ProbeParams",
|
|
"DiagnoseParams",
|
|
"RepairParams",
|
|
"validate_params",
|
|
# protocols
|
|
"MetaProtocol",
|
|
"CapabilitiesProtocol",
|
|
"ChannelAccountSnapshot",
|
|
"ChannelStatusIssue",
|
|
"ConfigProtocol",
|
|
"ConfigSchemaProtocol",
|
|
"DefaultsProtocol",
|
|
"ReloadProtocol",
|
|
"SetupProtocol",
|
|
"SetupWizardProtocol",
|
|
"SetupWizardStep",
|
|
"DirectoryGroup",
|
|
"DirectoryPeer",
|
|
"DirectoryProtocol",
|
|
"DirectorySearchParams",
|
|
"DirectorySearchResult",
|
|
"DoctorProtocol",
|
|
"GatewayProtocol",
|
|
"OutboundProtocol",
|
|
"StatusProtocol",
|
|
"SecurityProtocol",
|
|
"PairingProtocol",
|
|
"GroupsProtocol",
|
|
"MentionsProtocol",
|
|
"StreamingProtocol",
|
|
"LifecycleProtocol",
|
|
"AgentPromptContext",
|
|
"AgentPromptProtocol",
|
|
"ReplyTransport",
|
|
"ThreadInfo",
|
|
"ThreadingProtocol",
|
|
"MessagingProtocol",
|
|
"BoundReplyPayload",
|
|
"SessionResolution",
|
|
"HeartbeatProtocol",
|
|
"AgentTool",
|
|
"AgentToolParam",
|
|
"AgentToolProtocol",
|
|
"MessageActionCapability",
|
|
"MessageActionProtocol",
|
|
"AuthProtocol",
|
|
"ElevatedProtocol",
|
|
"AllowlistManagementProtocol",
|
|
"MessageSendingHook",
|
|
"InboundMessageHook",
|
|
"SendLifecycleHook",
|
|
# protocol composition type aliases
|
|
"BasePluginProtocol",
|
|
"ConfigPluginProtocol",
|
|
"GatewayPluginProtocol",
|
|
"OutboundPluginProtocol",
|
|
"SessionPluginProtocol",
|
|
"FullMessagingPluginProtocol",
|
|
"WebhookPluginProtocol",
|
|
"PollingPluginProtocol",
|
|
"ApprovalPluginProtocol",
|
|
# hooks
|
|
"HookCallback",
|
|
"HookEvent",
|
|
"HookRegistration",
|
|
"LifecycleHookRegistry",
|
|
# message
|
|
"UnifiedMessage",
|
|
"DispatchResult",
|
|
"PeerInfo",
|
|
"GroupContext",
|
|
"MessageType",
|
|
"MentionSource",
|
|
"PeerKind",
|
|
"StreamingChunk",
|
|
"ChunkType",
|
|
"ReplyStage",
|
|
"ReplyPayload",
|
|
# routing
|
|
"SessionKeyBuilder",
|
|
# session
|
|
"SessionRecorder",
|
|
"SessionOpResult",
|
|
# security
|
|
"AllowlistChecker",
|
|
"AllowlistCheckResult",
|
|
"AllowlistHitReason",
|
|
"AllowlistStore",
|
|
"DmPolicyMode",
|
|
"GroupPolicyMode",
|
|
"InMemoryAllowlistStore",
|
|
"PostgresAllowlistStore",
|
|
"get_allowlist_checker",
|
|
"reset_allowlist_checker",
|
|
"create_allowlist_checker",
|
|
"set_allowlist_checker",
|
|
"IdentityLinkResolver",
|
|
"PairingManager",
|
|
"PairingStore",
|
|
"InMemoryPairingStore",
|
|
"PostgresPairingStore",
|
|
# utils
|
|
"run_sync",
|
|
"run_sync_partial",
|
|
"LazyClass",
|
|
"LazyModule",
|
|
"DurableMessageReceipt",
|
|
"DurableStrategy",
|
|
"MessageReceipt",
|
|
"MessageSendContext",
|
|
"MessageSendState",
|
|
# doctor models
|
|
"CheckStatus",
|
|
"ConnectivityCheckResult",
|
|
"CredentialCheckResult",
|
|
"DiagnosisResult",
|
|
"DiagnosisWarning",
|
|
"DoctorOptions",
|
|
"DoctorRepairMode",
|
|
"LegacyConfigRule",
|
|
"PermissionCheckResult",
|
|
"RepairResult",
|
|
"RepairStep",
|
|
"Severity",
|
|
# doctor runner
|
|
"ChannelDoctorRunner",
|
|
"doctor_runner",
|
|
"get_doctor_runner",
|
|
"set_doctor_runner",
|
|
"reset_doctor_runner",
|
|
# manager
|
|
"gateway",
|
|
"RetireResult",
|
|
"get_gateway",
|
|
"set_gateway",
|
|
"reset_gateway",
|
|
# streaming
|
|
"DraftStreamSession",
|
|
"DraftStreamState",
|
|
"StreamingConfig",
|
|
"DraftStreamLoop",
|
|
"FinalizableDraftStreamControls",
|
|
"BlockChunker",
|
|
"EmbeddedBlockChunker",
|
|
"StreamingBlock",
|
|
"StreamingStrategy",
|
|
"StreamingStrategySelector",
|
|
"get_tool_status_label",
|
|
"MessageAction",
|
|
"MessageActionRegistry",
|
|
"ActionDescriptor",
|
|
"ActionHandler",
|
|
"MESSAGE_ACTION_GROUPS",
|
|
"MESSAGE_ACTIONS_BASIC",
|
|
"MESSAGE_ACTIONS_GROUP",
|
|
"MESSAGE_ACTIONS_THREAD",
|
|
"MESSAGE_ACTIONS_POLL",
|
|
"MESSAGE_ACTIONS_ATTACHMENT",
|
|
"DispatchContext",
|
|
"dispatch_message_action",
|
|
"build_unified_message_tool_schema",
|
|
"get_channel_actions_schema",
|
|
"list_all_actions",
|
|
"list_channel_actions",
|
|
# render / security
|
|
"sanitize_text_content_preserve_entities",
|
|
"sanitize_url",
|
|
"parse_markdown",
|
|
"BlockQuote",
|
|
"Bold",
|
|
"BoldItalic",
|
|
"CodeBlock",
|
|
"Document",
|
|
"Heading",
|
|
"Image",
|
|
"InlineCode",
|
|
"IrNode",
|
|
"Italic",
|
|
"LineBreak",
|
|
"Link",
|
|
"ListItem",
|
|
"OrderedList",
|
|
"Paragraph",
|
|
"Strikethrough",
|
|
"Table",
|
|
"Text",
|
|
"ThematicBreak",
|
|
"UnorderedList",
|
|
]
|