agentscope.app.channelChannelTypeRegistry
class ChannelTypeRegistry
agentscope/app/channel/_registry.py:41–172渠道类型注册表,把智能体接入外部消息渠道与企业平台。位于 agentscope.app.channel 包。核心成员包括 register、get、has_type、create_channel、schema_of、list_types。
The channel types a service allows, keyed by channel_type. Declared in agentscope.app.channel.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
def __init__(channels: list[type['ChannelBase']] | None = None) -> None | 初始化 `ChannelTypeRegistry` 实例。 Build the registry from a list of channel classes. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
def __bool__() -> bool | 判断是否任意渠道类型是已注册(特性已启用)。 Whether any channel type is registered (feature enabled). |
def register(channel_cls: type['ChannelBase']) -> None | 设置注册。 Register a channel class under its ``channel_type``. |
def get(channel_type: str) -> type['ChannelBase'] | None | 返回渠道类用于类型,或`None`。 Return the channel class for a type, or ``None``. |
def has_type(channel_type: str) -> bool | 判断是否类型是已注册。 Whether a type is registered. |
def create_channel(channel_type: str, channel_id: str, credentials: dict, config: dict) -> 'ChannelBase' | 创建渠道。 Validate stored credentials/config against the class's nested models and build the channel instance. |
def schema_of(channel_cls: type['ChannelBase']) -> ChannelTypeSchema | 设置模式的。 Build the frontend schema for one channel class. |
def list_types() -> list[ChannelTypeSchema] | 列出类型。 List frontend schemas for all registered types. |
def extract_platform_bot_id(channel_type: str, credentials: dict) -> str | 执行 `extract_platform_bot_id` 方法。 Read the bot-identifying credential field, for uniqueness. |
构造器详情Constructor Detail
ChannelTypeRegistry
def __init__(channels: list[type['ChannelBase']] | None = None) -> None
初始化 ChannelTypeRegistry 实例。
Build the registry from a list of channel classes.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
channels默认default None | list[type['ChannelBase']] | None | 渠道(类型 `list[type['ChannelBase']] | None`)。Channel classes to allow. Passed through from `create_app(channels=[...])`. |
agentscope/app/channel/_registry.py:44–57方法详情Method Detail
__bool__
def __bool__() -> bool
判断是否任意渠道类型是已注册(特性已启用)。
Whether any channel type is registered (feature enabled).
agentscope/app/channel/_registry.py:59–61register
def register(channel_cls: type['ChannelBase']) -> None
设置注册。
Register a channel class under its channel_type.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
channel_cls | type['ChannelBase'] | 渠道类到添加。The channel class to add. |
agentscope/app/channel/_registry.py:63–75get
def get(channel_type: str) -> type['ChannelBase'] | None
返回渠道类用于类型,或None。
Return the channel class for a type, or None.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
channel_type | str | 平台类型标识。The platform type id. |
agentscope/app/channel/_registry.py:77–83has_type
def has_type(channel_type: str) -> bool
判断是否类型是已注册。
Whether a type is registered.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
channel_type | str | 平台类型标识。The platform type id. |
agentscope/app/channel/_registry.py:85–91create_channel
def create_channel(channel_type: str, channel_id: str, credentials: dict, config: dict) -> 'ChannelBase'
创建渠道。
Validate stored credentials/config against the class's nested models and build the channel instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
channel_type | str | 平台类型标识。The platform type id. |
channel_id | str | 渠道标识(类型 `str`)。The instance's unique id. |
credentials | dict | 凭证(类型 `dict`)。Raw credentials to validate. |
config | dict | 配置对象(类型 `dict`)。Raw platform options to validate. |
- 当`ValueError`:If`channel_type`是不已注册时抛出 `Exception`。`ValueError`: If `channel_type` is not registered.
agentscope/app/channel/_registry.py:93–122schema_of
def schema_of(channel_cls: type['ChannelBase']) -> ChannelTypeSchema
设置模式的。
Build the frontend schema for one channel class.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
channel_cls | type['ChannelBase'] | 渠道类。The channel class. |
agentscope/app/channel/_registry.py:124–144list_types
def list_types() -> list[ChannelTypeSchema]
列出类型。
List frontend schemas for all registered types.
agentscope/app/channel/_registry.py:146–148extract_platform_bot_id
def extract_platform_bot_id(channel_type: str, credentials: dict) -> str
执行 extract_platform_bot_id 方法。
Read the bot-identifying credential field, for uniqueness.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
channel_type | str | 平台类型标识。The platform type id. |
credentials | dict | 凭证(类型 `dict`)。Raw credentials to read the bot id from. |
agentscope/app/channel/_registry.py:150–172