feat: 插件权限控制精细到群聊
修复了 #1281
Motivation
插件开关控制到群聊
Modifications
基于原先PlatformCompatibilityStage 扩展插件对于群聊的控制
前端配置入口设置在对话数据库的列表中,群聊类型有权限按钮。
-
platform_compatibility重命名为plugin_compatibility. 处理activated_handlers 调用is_enabled_for_platform方法添加 platform_compatible Tag -
在
StarMetadata新增group_permissions字典 缓存插件 黑名单机制- 格式为
{group_id: bool},key为群聊ID,value为插件是否启用
- 格式为
-
在处理链路中的过滤逻辑: activated_handlers 过滤带了platform_compatible 的 tag
get_handlers_by_event_type方法:集中过滤特定事件类型的处理器- 当指定
platform_id或group_id时,会调用is_enabled_for_platform方法过滤不兼容的处理器 - 若只需要激活的插件(
only_activated=True),会检查插件的activated状态 - 特殊情况下,
OnAstrBotLoadedEvent事件类型会跳过平台兼容性检查
- 当指定
-
is_enabled_for_platform方法 新增group_id参数- 传入group_id时 检查插件元数据是否存在、优先检查群聊黑名单,其次检查平台是否在支持列表中,并返回相应的兼容性状态
-
当平台配置或群聊插件权限配置更新时:
update_plugin_compatibility方法会遍历所有插件,更新其平台兼容性设置 以及清除group_permissions重新生成插件黑名单- 同时会刷新所有处理器的缓存,确保处理器使用最新的兼容性配置
Check
- [x] 我的 Commit Message 符合良好的规范
- [x] 我新增/修复/优化的功能经过良好的测试
Sourcery 总结
为群聊实现细粒度的插件权限控制,允许管理员为单个群聊启用或禁用特定插件。
新功能:
- 在仪表板中添加群组级别的插件权限配置
- 实现对群组特定插件权限的后端支持
- 创建一个新的 UI 对话框,用于管理群聊插件权限
增强功能:
- 重构平台兼容性逻辑以支持群组特定的插件设置
- 改进插件兼容性缓存机制
- 为插件权限调试添加更详细的日志记录
杂项:
- 将
platform_compatibility重命名为plugin_compatibility - 更新方法名称以反映新的插件权限处理
Original summary in English
Summary by Sourcery
Implement fine-grained plugin permission control for group chats, allowing administrators to enable or disable specific plugins for individual group chats
New Features:
- Add group-level plugin permission configuration in the dashboard
- Implement backend support for group-specific plugin permissions
- Create a new UI dialog for managing group chat plugin permissions
Enhancements:
- Refactor platform compatibility logic to support group-specific plugin settings
- Improve plugin compatibility caching mechanism
- Add more detailed logging for plugin permission debugging
Chores:
- Rename platform_compatibility to plugin_compatibility
- Update method names to reflect new plugin permission handling
## Sourcery 评审员指南
此 Pull Request 引入了组聊天级别的细粒度插件权限控制。它扩展了现有的平台兼容性设置,以包含特定于组的配置,允许管理员为单个组聊天启用或禁用插件。该实现涉及前端、API 端点、插件元数据和兼容性逻辑的更改。实施了缓存机制来优化权限检查过程。
#### 更新插件兼容性的顺序图
```mermaid
sequenceDiagram
participant PluginManager
participant StarMetadata
participant Config
PluginManager->>Config: Get plugin_enable_config
Config-->>PluginManager: Returns plugin_enable_config
loop For each plugin
PluginManager->>StarMetadata: update_plugin_compatibility(plugin_enable_config)
StarMetadata->>StarMetadata: Clear supported_platforms and group_permissions
StarMetadata->>StarMetadata: Update supported_platforms from plugin_enable_config
StarMetadata->>StarMetadata: Update group_permissions from config
end
事件处理期间检查插件权限的顺序图
sequenceDiagram
participant Event
participant StarHandlerMetadata
participant StarMetadata
Event->>StarHandlerMetadata: is_enabled_for_platform(platform_id, group_id)
StarHandlerMetadata->>StarMetadata: Get plugin metadata
alt group_id is present
StarMetadata->>StarMetadata: Check group_permissions for group_id
alt group_id in group_permissions
StarMetadata-->>StarHandlerMetadata: Return group_permissions[group_id]
else group_id not in group_permissions
StarMetadata->>StarMetadata: Check supported_platforms for platform_id
StarMetadata-->>StarHandlerMetadata: Return supported_platforms[platform_id]
end
else group_id is not present
StarMetadata->>StarMetadata: Check supported_platforms for platform_id
StarMetadata-->>StarHandlerMetadata: Return supported_platforms[platform_id]
end
StarMetadata 的更新类图
classDiagram
class StarMetadata {
name: str
desc: str
version: str
repo: str
supported_platforms: Dict[str, bool]
group_permissions: Dict[str, bool]
+update_plugin_compatibility(plugin_enable_config: dict) : None
}
note for StarMetadata "存储插件元数据,包括特定于组的权限。"
文件级别更改
| 变更 | 详情 | 文件 |
|---|---|---|
| 引入了一项新功能,可以在群聊级别控制插件权限,从而增强现有的平台兼容性设置。 |
|
dashboard/src/views/ConversationPage.vueastrbot/dashboard/routes/conversation.pyastrbot/core/star/star.pyastrbot/core/pipeline/process_stage/method/llm_request.pyastrbot/core/star/star_handler.pyastrbot/core/pipeline/plugin_compatibility/stage.pyastrbot/core/pipeline/respond/stage.pyastrbot/core/star/star_manager.pyastrbot/core/pipeline/waking_check/stage.pyastrbot/dashboard/routes/plugin.pyastrbot/core/pipeline/__init__.py |
将 platform_compatibility 重命名为 plugin_compatibility,以反映兼容性设置的更广泛范围,现在包括群聊。 |
|
dashboard/src/views/ConversationPage.vueastrbot/dashboard/routes/conversation.pyastrbot/core/star/star.pyastrbot/core/pipeline/process_stage/method/llm_request.pyastrbot/core/star/star_handler.pyastrbot/core/pipeline/plugin_compatibility/stage.pyastrbot/core/pipeline/respond/stage.pyastrbot/core/star/star_manager.pyastrbot/core/pipeline/waking_check/stage.pyastrbot/dashboard/routes/plugin.pyastrbot/core/pipeline/__init__.py |
| 实施特定于组的插件权限缓存,以优化权限检查过程。 |
|
dashboard/src/views/ConversationPage.vueastrbot/dashboard/routes/conversation.pyastrbot/core/star/star.pyastrbot/core/pipeline/process_stage/method/llm_request.pyastrbot/core/star/star_handler.pyastrbot/core/pipeline/plugin_compatibility/stage.pyastrbot/core/pipeline/respond/stage.pyastrbot/core/star/star_manager.pyastrbot/core/pipeline/waking_check/stage.pyastrbot/dashboard/routes/plugin.pyastrbot/core/pipeline/__init__.py |
提示和命令
与 Sourcery 互动
- 触发新的审查: 在 Pull Request 上评论
@sourcery-ai review。 - 继续讨论: 直接回复 Sourcery 的审查评论。
- 从审查评论生成 GitHub issue: 通过回复审查评论,要求 Sourcery 从审查评论创建一个 issue。您也可以回复带有
@sourcery-ai issue的审查评论以从中创建一个 issue。 - 生成 Pull Request 标题: 在 Pull Request 标题中的任何位置写入
@sourcery-ai以随时生成标题。您也可以在 Pull Request 上评论@sourcery-ai title以随时(重新)生成标题。 - 生成 Pull Request 摘要: 在 Pull Request 正文中的任何位置写入
@sourcery-ai summary以随时在您想要的位置生成 PR 摘要。您也可以在 Pull Request 上评论@sourcery-ai summary以随时(重新)生成摘要。 - 生成评审员指南: 在 Pull Request 上评论
@sourcery-ai guide以随时(重新)生成评审员指南。 - 解决所有 Sourcery 评论: 在 Pull Request 上评论
@sourcery-ai resolve以解决所有 Sourcery 评论。如果您已经解决了所有评论并且不想再看到它们,这将非常有用。 - 驳回所有 Sourcery 审查: 在 Pull Request 上评论
@sourcery-ai dismiss以驳回所有现有的 Sourcery 审查。如果您想重新开始新的审查,这将特别有用 - 不要忘记评论@sourcery-ai review以触发新的审查! - 为 issue 生成行动计划: 在 issue 上评论
@sourcery-ai plan以为其生成行动计划。
自定义您的体验
访问您的 仪表板 以:
- 启用或禁用审查功能,例如 Sourcery 生成的 Pull Request 摘要、评审员指南等。
- 更改审查语言。
- 添加、删除或编辑自定义审查说明。
- 调整其他审查设置。
获得帮助
Original review guide in English
Reviewer's Guide by Sourcery
This pull request introduces fine-grained plugin permission control at the group chat level. It extends the existing platform compatibility settings to include group-specific configurations, allowing administrators to enable or disable plugins for individual group chats. The implementation involves changes to the frontend, API endpoints, plugin metadata, and compatibility logic. Caching mechanisms are implemented to optimize the permission checking process.
Sequence Diagram for Updating Plugin Compatibility
sequenceDiagram
participant PluginManager
participant StarMetadata
participant Config
PluginManager->>Config: Get plugin_enable_config
Config-->>PluginManager: Returns plugin_enable_config
loop For each plugin
PluginManager->>StarMetadata: update_plugin_compatibility(plugin_enable_config)
StarMetadata->>StarMetadata: Clear supported_platforms and group_permissions
StarMetadata->>StarMetadata: Update supported_platforms from plugin_enable_config
StarMetadata->>StarMetadata: Update group_permissions from config
end
Sequence Diagram for Checking Plugin Permissions during Event Processing
sequenceDiagram
participant Event
participant StarHandlerMetadata
participant StarMetadata
Event->>StarHandlerMetadata: is_enabled_for_platform(platform_id, group_id)
StarHandlerMetadata->>StarMetadata: Get plugin metadata
alt group_id is present
StarMetadata->>StarMetadata: Check group_permissions for group_id
alt group_id in group_permissions
StarMetadata-->>StarHandlerMetadata: Return group_permissions[group_id]
else group_id not in group_permissions
StarMetadata->>StarMetadata: Check supported_platforms for platform_id
StarMetadata-->>StarHandlerMetadata: Return supported_platforms[platform_id]
end
else group_id is not present
StarMetadata->>StarMetadata: Check supported_platforms for platform_id
StarMetadata-->>StarHandlerMetadata: Return supported_platforms[platform_id]
end
Updated Class Diagram for StarMetadata
classDiagram
class StarMetadata {
name: str
desc: str
version: str
repo: str
supported_platforms: Dict[str, bool]
group_permissions: Dict[str, bool]
+update_plugin_compatibility(plugin_enable_config: dict) : None
}
note for StarMetadata "Stores plugin metadata, including group-specific permissions."
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Introduces a new feature to control plugin permissions at the group chat level, enhancing the existing platform compatibility settings. |
|
dashboard/src/views/ConversationPage.vueastrbot/dashboard/routes/conversation.pyastrbot/core/star/star.pyastrbot/core/pipeline/process_stage/method/llm_request.pyastrbot/core/star/star_handler.pyastrbot/core/pipeline/plugin_compatibility/stage.pyastrbot/core/pipeline/respond/stage.pyastrbot/core/star/star_manager.pyastrbot/core/pipeline/waking_check/stage.pyastrbot/dashboard/routes/plugin.pyastrbot/core/pipeline/__init__.py |
Renames platform_compatibility to plugin_compatibility to reflect the broader scope of compatibility settings, which now includes group chats. |
|
dashboard/src/views/ConversationPage.vueastrbot/dashboard/routes/conversation.pyastrbot/core/star/star.pyastrbot/core/pipeline/process_stage/method/llm_request.pyastrbot/core/star/star_handler.pyastrbot/core/pipeline/plugin_compatibility/stage.pyastrbot/core/pipeline/respond/stage.pyastrbot/core/star/star_manager.pyastrbot/core/pipeline/waking_check/stage.pyastrbot/dashboard/routes/plugin.pyastrbot/core/pipeline/__init__.py |
| Implements caching of group-specific plugin permissions to optimize the permission checking process. |
|
dashboard/src/views/ConversationPage.vueastrbot/dashboard/routes/conversation.pyastrbot/core/star/star.pyastrbot/core/pipeline/process_stage/method/llm_request.pyastrbot/core/star/star_handler.pyastrbot/core/pipeline/plugin_compatibility/stage.pyastrbot/core/pipeline/respond/stage.pyastrbot/core/star/star_manager.pyastrbot/core/pipeline/waking_check/stage.pyastrbot/dashboard/routes/plugin.pyastrbot/core/pipeline/__init__.py |
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
- Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with
@sourcery-ai issueto create an issue from it. - Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore. - Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment@sourcery-ai reviewto trigger a new review! - Generate a plan of action for an issue: Comment
@sourcery-ai planon an issue to generate a plan of action for it.
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
- Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.