80b89fd2ea
move mcp management to plugin managemanet page * feat: 新增命令配置数据库模型 * feat: 实现核心命令管理系统 * feat: 将命令管理集成到 Star 框架 * feat: 新增命令管理后台 API * feat: 新增命令管理界面页面 * feat: 新增命令管理国际化支持 * test: 新增命令管理相关测试 * refactor(command): 移除指令重命名时的别名功能 * fix(command): 修正指令冲突检测逻辑 * fix(command): 排除已禁用指令的冲突检测 - 只有 `effective_command` 存在且 `enabled` 为 `True` 的指令才会被纳入冲突检测范围。 * feat(command): 优化指令冲突显示与提示 - 【功能】新增指令冲突警告提示,当检测到冲突时显示详细信息及解决方案。 - 【优化】调整指令列表排序逻辑,将冲突指令优先显示并分组。 - 【样式】为冲突指令行添加专属高亮样式,提升视觉识别度。 - 【国际化】更新英文和中文多语言文件,增加指令冲突警告相关的翻译文本。 * chore(command-page): 禁用命令表格部分列的排序功能 * style(command-page): 调整命令页面表格样式和图标大小 * refactor(command): 优化指令页面布局并更新冲突警告 - 【布局优化】重新组织指令管理页面布局,将筛选器移至顶部独立行 - 【信息展示】将搜索栏与总指令数、已禁用指令数合并显示,提升页面空间利用率 - 【视觉更新】更新指令冲突警告样式 * style: UI 细节 * refactor(command): 调整指令管理中的成员权限显示与筛选 - 更新指令筛选逻辑,当选择“所有人”权限筛选时,将同时包含 `everyone` 和 `member` 权限的指令。 * feat(command-management): 新增指令层级管理与UI展示 - 【后端】 - `CommandDescriptor` 新增 `parent_group_handler` 和 `sub_commands` 字段,支持指令层级结构定义。 - `list_commands` 函数重构,实现指令的层级收集与构建,将子指令正确挂载到其父指令组下。 - 新增 `_collect_all_descriptors` 和 `_find_parent_group_handler` 辅助函数,用于全面收集指令并定位父指令组。 - `_build_descriptor` 优化指令类型判断逻辑,明确区分普通指令、指令组和子指令。 - `_descriptor_to_dict` 递归处理子指令,确保 API 返回完整的指令层级数据。 - 【前端】 - 指令管理页面 (`CommandPage.vue`) 增加指令类型筛选器,并支持指令组的展开/折叠功能。 - 表格展示优化,为指令组和子指令添加不同的样式和缩进,提升层级结构的视觉可读性。 - 指令详情对话框新增指令类型、所属指令组和子指令列表的展示。 - 更新 `CommandItem` 接口,以适配后端提供的层级数据结构。 - 【i18n】 - 新增指令类型(指令、指令组、子指令)的国际化文本。 - 更新指令管理相关 UI 文本,包括表格头部、详情对话框字段和筛选器选项。 * style(command): 优化指令组子指令数量显示UI * refactor(command): 修改指令列表排序逻辑 * style(command-page): 优化命令列表UI * feat(command): 添加系统插件指令过滤与冲突处理 * refactor(command): 更新指令数展示逻辑 * style(command): 更新空状态描述 * feat(extension): 添加插件指令冲突检测与提示 - 在插件安装或启用后,自动检测并提示指令冲突。 - 当检测到指令冲突时,显示警告对话框,告知用户冲突数量及可能的影响。 * refactor(command): 移除指令表格内部加载指示器 * style(extension): 文案修改 * refactor(command): 模块化指令管理面板前端代码 * refactor(commandPanel): 重命名指令模块目录为 commandPanel * style(commandPanel): 微调指令面板UI * fix(command): 确保新命令配置的事务提交 * fix(sidebar): 补全新增侧边栏项后的侧边栏位追加逻辑 * refactor(commands): 重构/help指令以动态显示实际命令并补充部分命令描述 * style(builtin_commands): 补充命令描述 * refactor(commandPanel): 移除未使用的 filterState 常量 * perf(dashboard): 删除多余的CommandPage.vue文件(已被模块化引用) * perf(command): 优化命令冲突计数逻辑 * perf(command): 优化指令管理辅助函数和配置绑定逻辑 * perf(db): 优化重构command相关数据库操作 * refactor(sidebar): 提取侧边栏项目解析逻辑到工具函数复用 * refactor: move mcp and command page to extension page * refactor: remove unused imports in component panel * fix: update terminology for handler management in extension localization --------- Co-authored-by: Soulter <905617992@qq.com>
238 lines
8.3 KiB
Python
238 lines
8.3 KiB
Python
from astrbot.api import star
|
|
from astrbot.api.event import AstrMessageEvent, filter
|
|
|
|
from .commands import (
|
|
AdminCommands,
|
|
AlterCmdCommands,
|
|
ConversationCommands,
|
|
HelpCommand,
|
|
LLMCommands,
|
|
PersonaCommands,
|
|
PluginCommands,
|
|
ProviderCommands,
|
|
SetUnsetCommands,
|
|
SIDCommand,
|
|
T2ICommand,
|
|
ToolCommands,
|
|
TTSCommand,
|
|
)
|
|
|
|
|
|
class Main(star.Star):
|
|
def __init__(self, context: star.Context) -> None:
|
|
self.context = context
|
|
|
|
self.help_c = HelpCommand(self.context)
|
|
self.llm_c = LLMCommands(self.context)
|
|
self.tool_c = ToolCommands(self.context)
|
|
self.plugin_c = PluginCommands(self.context)
|
|
self.admin_c = AdminCommands(self.context)
|
|
self.conversation_c = ConversationCommands(self.context)
|
|
self.provider_c = ProviderCommands(self.context)
|
|
self.persona_c = PersonaCommands(self.context)
|
|
self.alter_cmd_c = AlterCmdCommands(self.context)
|
|
self.setunset_c = SetUnsetCommands(self.context)
|
|
self.t2i_c = T2ICommand(self.context)
|
|
self.tts_c = TTSCommand(self.context)
|
|
self.sid_c = SIDCommand(self.context)
|
|
|
|
@filter.command("help")
|
|
async def help(self, event: AstrMessageEvent):
|
|
"""查看帮助"""
|
|
await self.help_c.help(event)
|
|
|
|
@filter.permission_type(filter.PermissionType.ADMIN)
|
|
@filter.command("llm")
|
|
async def llm(self, event: AstrMessageEvent):
|
|
"""开启/关闭 LLM"""
|
|
await self.llm_c.llm(event)
|
|
|
|
@filter.command_group("tool")
|
|
def tool(self):
|
|
"""函数工具管理"""
|
|
|
|
@tool.command("ls")
|
|
async def tool_ls(self, event: AstrMessageEvent):
|
|
"""查看函数工具列表"""
|
|
await self.tool_c.tool_ls(event)
|
|
|
|
@tool.command("on")
|
|
async def tool_on(self, event: AstrMessageEvent, tool_name: str):
|
|
"""启用一个函数工具"""
|
|
await self.tool_c.tool_on(event, tool_name)
|
|
|
|
@tool.command("off")
|
|
async def tool_off(self, event: AstrMessageEvent, tool_name: str):
|
|
"""停用一个函数工具"""
|
|
await self.tool_c.tool_off(event, tool_name)
|
|
|
|
@tool.command("off_all")
|
|
async def tool_all_off(self, event: AstrMessageEvent):
|
|
"""停用所有函数工具"""
|
|
await self.tool_c.tool_all_off(event)
|
|
|
|
@filter.command_group("plugin")
|
|
def plugin(self):
|
|
"""插件管理"""
|
|
|
|
@plugin.command("ls")
|
|
async def plugin_ls(self, event: AstrMessageEvent):
|
|
"""获取已经安装的插件列表。"""
|
|
await self.plugin_c.plugin_ls(event)
|
|
|
|
@filter.permission_type(filter.PermissionType.ADMIN)
|
|
@plugin.command("off")
|
|
async def plugin_off(self, event: AstrMessageEvent, plugin_name: str = ""):
|
|
"""禁用插件"""
|
|
await self.plugin_c.plugin_off(event, plugin_name)
|
|
|
|
@filter.permission_type(filter.PermissionType.ADMIN)
|
|
@plugin.command("on")
|
|
async def plugin_on(self, event: AstrMessageEvent, plugin_name: str = ""):
|
|
"""启用插件"""
|
|
await self.plugin_c.plugin_on(event, plugin_name)
|
|
|
|
@filter.permission_type(filter.PermissionType.ADMIN)
|
|
@plugin.command("get")
|
|
async def plugin_get(self, event: AstrMessageEvent, plugin_repo: str = ""):
|
|
"""安装插件"""
|
|
await self.plugin_c.plugin_get(event, plugin_repo)
|
|
|
|
@plugin.command("help")
|
|
async def plugin_help(self, event: AstrMessageEvent, plugin_name: str = ""):
|
|
"""获取插件帮助"""
|
|
await self.plugin_c.plugin_help(event, plugin_name)
|
|
|
|
@filter.command("t2i")
|
|
async def t2i(self, event: AstrMessageEvent):
|
|
"""开关文本转图片"""
|
|
await self.t2i_c.t2i(event)
|
|
|
|
@filter.command("tts")
|
|
async def tts(self, event: AstrMessageEvent):
|
|
"""开关文本转语音(会话级别)"""
|
|
await self.tts_c.tts(event)
|
|
|
|
@filter.command("sid")
|
|
async def sid(self, event: AstrMessageEvent):
|
|
"""获取会话 ID 和 管理员 ID"""
|
|
await self.sid_c.sid(event)
|
|
|
|
@filter.permission_type(filter.PermissionType.ADMIN)
|
|
@filter.command("op")
|
|
async def op(self, event: AstrMessageEvent, admin_id: str = ""):
|
|
"""授权管理员。op <admin_id>"""
|
|
await self.admin_c.op(event, admin_id)
|
|
|
|
@filter.permission_type(filter.PermissionType.ADMIN)
|
|
@filter.command("deop")
|
|
async def deop(self, event: AstrMessageEvent, admin_id: str):
|
|
"""取消授权管理员。deop <admin_id>"""
|
|
await self.admin_c.deop(event, admin_id)
|
|
|
|
@filter.permission_type(filter.PermissionType.ADMIN)
|
|
@filter.command("wl")
|
|
async def wl(self, event: AstrMessageEvent, sid: str = ""):
|
|
"""添加白名单。wl <sid>"""
|
|
await self.admin_c.wl(event, sid)
|
|
|
|
@filter.permission_type(filter.PermissionType.ADMIN)
|
|
@filter.command("dwl")
|
|
async def dwl(self, event: AstrMessageEvent, sid: str):
|
|
"""删除白名单。dwl <sid>"""
|
|
await self.admin_c.dwl(event, sid)
|
|
|
|
@filter.permission_type(filter.PermissionType.ADMIN)
|
|
@filter.command("provider")
|
|
async def provider(
|
|
self,
|
|
event: AstrMessageEvent,
|
|
idx: str | int | None = None,
|
|
idx2: int | None = None,
|
|
):
|
|
"""查看或者切换 LLM Provider"""
|
|
await self.provider_c.provider(event, idx, idx2)
|
|
|
|
@filter.command("reset")
|
|
async def reset(self, message: AstrMessageEvent):
|
|
"""重置 LLM 会话"""
|
|
await self.conversation_c.reset(message)
|
|
|
|
@filter.permission_type(filter.PermissionType.ADMIN)
|
|
@filter.command("model")
|
|
async def model_ls(
|
|
self,
|
|
message: AstrMessageEvent,
|
|
idx_or_name: int | str | None = None,
|
|
):
|
|
"""查看或者切换模型"""
|
|
await self.provider_c.model_ls(message, idx_or_name)
|
|
|
|
@filter.command("history")
|
|
async def his(self, message: AstrMessageEvent, page: int = 1):
|
|
"""查看对话记录"""
|
|
await self.conversation_c.his(message, page)
|
|
|
|
@filter.command("ls")
|
|
async def convs(self, message: AstrMessageEvent, page: int = 1):
|
|
"""查看对话列表"""
|
|
await self.conversation_c.convs(message, page)
|
|
|
|
@filter.command("new")
|
|
async def new_conv(self, message: AstrMessageEvent):
|
|
"""创建新对话"""
|
|
await self.conversation_c.new_conv(message)
|
|
|
|
@filter.permission_type(filter.PermissionType.ADMIN)
|
|
@filter.command("groupnew")
|
|
async def groupnew_conv(self, message: AstrMessageEvent, sid: str):
|
|
"""创建新群聊对话"""
|
|
await self.conversation_c.groupnew_conv(message, sid)
|
|
|
|
@filter.command("switch")
|
|
async def switch_conv(self, message: AstrMessageEvent, index: int | None = None):
|
|
"""通过 /ls 前面的序号切换对话"""
|
|
await self.conversation_c.switch_conv(message, index)
|
|
|
|
@filter.command("rename")
|
|
async def rename_conv(self, message: AstrMessageEvent, new_name: str):
|
|
"""重命名对话"""
|
|
await self.conversation_c.rename_conv(message, new_name)
|
|
|
|
@filter.command("del")
|
|
async def del_conv(self, message: AstrMessageEvent):
|
|
"""删除当前对话"""
|
|
await self.conversation_c.del_conv(message)
|
|
|
|
@filter.permission_type(filter.PermissionType.ADMIN)
|
|
@filter.command("key")
|
|
async def key(self, message: AstrMessageEvent, index: int | None = None):
|
|
"""查看或者切换 Key"""
|
|
await self.provider_c.key(message, index)
|
|
|
|
@filter.permission_type(filter.PermissionType.ADMIN)
|
|
@filter.command("persona")
|
|
async def persona(self, message: AstrMessageEvent):
|
|
"""查看或者切换 Persona"""
|
|
await self.persona_c.persona(message)
|
|
|
|
@filter.permission_type(filter.PermissionType.ADMIN)
|
|
@filter.command("dashboard_update")
|
|
async def update_dashboard(self, event: AstrMessageEvent):
|
|
"""更新管理面板"""
|
|
await self.admin_c.update_dashboard(event)
|
|
|
|
@filter.command("set")
|
|
async def set_variable(self, event: AstrMessageEvent, key: str, value: str):
|
|
await self.setunset_c.set_variable(event, key, value)
|
|
|
|
@filter.command("unset")
|
|
async def unset_variable(self, event: AstrMessageEvent, key: str):
|
|
await self.setunset_c.unset_variable(event, key)
|
|
|
|
@filter.permission_type(filter.PermissionType.ADMIN)
|
|
@filter.command("alter_cmd", alias={"alter"})
|
|
async def alter_cmd(self, event: AstrMessageEvent):
|
|
"""修改命令权限"""
|
|
await self.alter_cmd_c.alter_cmd(event)
|