feat(plugin_system): 增加对最后一个启用 Chatter 的禁用保护
为了确保每个 stream 至少有一个可用的 Chatter 组件,此更改引入了一项保护机制。 在尝试禁用一个 Chatter 组件时,系统现在会检查它是否是当前 stream 中唯一启用的 Chatter。如果是,则禁用操作将被阻止,以避免导致该 stream 无法响应。
This commit is contained in:
@@ -102,6 +102,18 @@ def set_component_enabled_local(stream_id: str, name: str, component_type: Compo
|
||||
Returns:
|
||||
bool: 操作成功则为 True。
|
||||
"""
|
||||
# Chatter 唯一性保护
|
||||
if component_type == ComponentType.CHATTER and not enabled:
|
||||
# 检查当前 stream_id 上下文中的启用状态
|
||||
enabled_chatters = component_registry.get_enabled_components_by_type(
|
||||
ComponentType.CHATTER, stream_id=stream_id
|
||||
)
|
||||
if len(enabled_chatters) <= 1 and name in enabled_chatters:
|
||||
logger.warning(
|
||||
f"操作被阻止:在 stream '{stream_id}' 中,不能禁用最后一个启用的 Chatter 组件 ('{name}')。"
|
||||
)
|
||||
return False
|
||||
|
||||
component_registry.set_local_component_state(stream_id, name, component_type, enabled)
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user