From a15444ee8cb349f6a03a041e98ba97e3d5353cd7 Mon Sep 17 00:00:00 2001 From: advent259141 <2968474907@qq.com> Date: Sun, 13 Jul 2025 00:15:21 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E4=BA=86mcp=E4=BC=9A?= =?UTF-8?q?=E8=AF=9D=E7=BA=A7=E7=9A=84=E5=90=AF=E5=81=9C=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E6=89=B9=E9=87=8F=E8=AE=BE=E7=BD=AE=E7=9A=84?= =?UTF-8?q?=E9=80=89=E9=A1=B9=EF=BC=8C=E5=AF=B9=E7=9B=B8=E5=85=B3=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E8=BF=9B=E8=A1=8C=E4=BA=86=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process_stage/method/llm_request.py | 17 +- .../pipeline/session_status_check/__init__.py | 1 - astrbot/core/star/session_llm_manager.py | 65 +---- .../dashboard/routes/session_management.py | 40 --- .../en-US/features/session-management.json | 10 +- .../zh-CN/features/session-management.json | 10 +- dashboard/src/views/SessionManagementPage.vue | 232 ++++++++++++++---- packages/astrbot/main.py | 17 -- session_allocate_examples.py | 0 9 files changed, 201 insertions(+), 191 deletions(-) delete mode 100644 astrbot/core/pipeline/session_status_check/__init__.py create mode 100644 session_allocate_examples.py diff --git a/astrbot/core/pipeline/process_stage/method/llm_request.py b/astrbot/core/pipeline/process_stage/method/llm_request.py index bc7259f28..75e95e032 100644 --- a/astrbot/core/pipeline/process_stage/method/llm_request.py +++ b/astrbot/core/pipeline/process_stage/method/llm_request.py @@ -100,8 +100,7 @@ class LLMRequestSubStage(Stage): if not event.message_str.startswith(self.provider_wake_prefix): return req.prompt = event.message_str[len(self.provider_wake_prefix) :] - if SessionServiceManager.should_process_mcp_request(event): - req.func_tool = self.ctx.plugin_manager.context.get_llm_tool_manager() + req.func_tool = self.ctx.plugin_manager.context.get_llm_tool_manager() for comp in event.message_obj.message: if isinstance(comp, Image): image_path = await comp.convert_to_file_path() @@ -179,13 +178,6 @@ class LLMRequestSubStage(Stage): async def requesting(): step_idx = 0 while step_idx < self.max_step: - # 在每次实际请求 LLM 前检查会话级别的启停状态,这可以防止插件或函数工具调用时绕过会话级别的限制 - if not SessionServiceManager.should_process_llm_request(event): - logger.debug( - f"会话 {event.unified_msg_origin} 禁用了 LLM,终止 LLM 请求。" - ) - return - step_idx += 1 try: async for resp in tool_loop_agent.step(): @@ -284,13 +276,6 @@ class LLMRequestSubStage(Stage): self, event: AstrMessageEvent, req: ProviderRequest, prov: Provider ): """处理 WebChat 平台的特殊情况,包括第一次 LLM 对话时总结对话内容生成 title""" - # 检查会话级别的LLM启停状态,防止标题生成功能绕过会话级别限制 - if not SessionServiceManager.should_process_llm_request(event): - logger.debug( - f"会话 {event.unified_msg_origin} 禁用了 LLM,跳过 WebChat 标题生成。" - ) - return - conversation = await self.conv_manager.get_conversation( event.unified_msg_origin, req.conversation.cid ) diff --git a/astrbot/core/pipeline/session_status_check/__init__.py b/astrbot/core/pipeline/session_status_check/__init__.py deleted file mode 100644 index 836a4f02a..000000000 --- a/astrbot/core/pipeline/session_status_check/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# Session Status Check Stage diff --git a/astrbot/core/star/session_llm_manager.py b/astrbot/core/star/session_llm_manager.py index 0c78c5637..4bceb1109 100644 --- a/astrbot/core/star/session_llm_manager.py +++ b/astrbot/core/star/session_llm_manager.py @@ -135,68 +135,6 @@ class SessionServiceManager: session_id = event.unified_msg_origin return SessionServiceManager.is_tts_enabled_for_session(session_id) - # ============================================================================= - # MCP 相关方法 - # ============================================================================= - - @staticmethod - def is_mcp_enabled_for_session(session_id: str) -> bool: - """检查MCP是否在指定会话中启用 - - Args: - session_id: 会话ID (unified_msg_origin) - - Returns: - bool: True表示启用,False表示禁用 - """ - # 获取会话服务配置 - session_config = sp.get("session_service_config", {}) or {} - session_services = session_config.get(session_id, {}) - - # 如果配置了该会话的MCP状态,返回该状态 - mcp_enabled = session_services.get("mcp_enabled") - if mcp_enabled is not None: - return mcp_enabled - - # 如果没有配置,默认为启用(兼容性考虑) - return True - - @staticmethod - def set_mcp_status_for_session(session_id: str, enabled: bool) -> None: - """设置MCP在指定会话中的启停状态 - - Args: - session_id: 会话ID (unified_msg_origin) - enabled: True表示启用,False表示禁用 - """ - # 获取当前配置 - session_config = sp.get("session_service_config", {}) or {} - if session_id not in session_config: - session_config[session_id] = {} - - # 设置MCP状态 - session_config[session_id]["mcp_enabled"] = enabled - - # 保存配置 - sp.put("session_service_config", session_config) - - logger.info( - f"会话 {session_id} 的MCP状态已更新为: {'启用' if enabled else '禁用'}" - ) - - @staticmethod - def should_process_mcp_request(event: AstrMessageEvent) -> bool: - """检查是否应该处理MCP请求 - - Args: - event: 消息事件 - - Returns: - bool: True表示应该处理,False表示跳过 - """ - session_id = event.unified_msg_origin - return SessionServiceManager.is_mcp_enabled_for_session(session_id) - # ============================================================================= # 会话整体启停相关方法 # ============================================================================= @@ -333,7 +271,7 @@ class SessionServiceManager: session_id: 会话ID (unified_msg_origin) Returns: - Dict[str, bool]: 包含session_enabled、llm_enabled、tts_enabled、mcp_enabled的字典 + Dict[str, bool]: 包含session_enabled、llm_enabled、tts_enabled的字典 """ session_config = sp.get("session_service_config", {}) or {} return session_config.get( @@ -342,7 +280,6 @@ class SessionServiceManager: "session_enabled": True, # 默认启用 "llm_enabled": True, # 默认启用 "tts_enabled": True, # 默认启用 - "mcp_enabled": True, # 默认启用 }, ) diff --git a/astrbot/dashboard/routes/session_management.py b/astrbot/dashboard/routes/session_management.py index 852323d29..fdcbdbf73 100644 --- a/astrbot/dashboard/routes/session_management.py +++ b/astrbot/dashboard/routes/session_management.py @@ -29,7 +29,6 @@ class SessionManagementRoute(Route): "/session/update_plugin": ("POST", self.update_session_plugin), "/session/update_llm": ("POST", self.update_session_llm), "/session/update_tts": ("POST", self.update_session_tts), - "/session/update_mcp": ("POST", self.update_session_mcp), "/session/update_name": ("POST", self.update_session_name), "/session/update_status": ("POST", self.update_session_status), } @@ -76,9 +75,6 @@ class SessionManagementRoute(Route): "tts_enabled": SessionServiceManager.is_tts_enabled_for_session( session_id ), - "mcp_enabled": SessionServiceManager.is_mcp_enabled_for_session( - session_id - ), "platform": session_id.split(":")[0] if ":" in session_id else "unknown", @@ -345,9 +341,6 @@ class SessionManagementRoute(Route): session_id ), "tts_enabled": None, # 将在下面设置 - "mcp_enabled": SessionServiceManager.is_mcp_enabled_for_session( - session_id - ), "platform": session_id.split(":")[0] if ":" in session_id else "unknown", @@ -613,39 +606,6 @@ class SessionManagementRoute(Route): logger.error(error_msg) return Response().error(f"更新会话TTS状态失败: {str(e)}").__dict__ - async def update_session_mcp(self): - """更新指定会话的MCP启停状态""" - try: - data = await request.get_json() - session_id = data.get("session_id") - enabled = data.get("enabled") - - if not session_id: - return Response().error("缺少必要参数: session_id").__dict__ - - if enabled is None: - return Response().error("缺少必要参数: enabled").__dict__ - - # 使用 SessionServiceManager 更新MCP状态 - SessionServiceManager.set_mcp_status_for_session(session_id, enabled) - - return ( - Response() - .ok( - { - "message": f"MCP工具调用已{'启用' if enabled else '禁用'}", - "session_id": session_id, - "mcp_enabled": enabled, - } - ) - .__dict__ - ) - - except Exception as e: - error_msg = f"更新会话MCP状态失败: {str(e)}\n{traceback.format_exc()}" - logger.error(error_msg) - return Response().error(f"更新会话MCP状态失败: {str(e)}").__dict__ - async def update_session_name(self): """更新指定会话的自定义名称""" try: diff --git a/dashboard/src/i18n/locales/en-US/features/session-management.json b/dashboard/src/i18n/locales/en-US/features/session-management.json index c8dcdddef..bc1ed90a4 100644 --- a/dashboard/src/i18n/locales/en-US/features/session-management.json +++ b/dashboard/src/i18n/locales/en-US/features/session-management.json @@ -29,7 +29,6 @@ "ttsProvider": "TTS Provider", "llmStatus": "LLM Status", "ttsStatus": "TTS Status", - "mcpStatus": "MCP Status", "pluginManagement": "Plugin Management" } }, @@ -43,7 +42,13 @@ "batchOperations": { "title": "Batch Operations", "setPersona": "Batch Set Persona", - "setChatProvider": "Batch Set Chat Provider" + "setChatProvider": "Batch Set Chat Provider", + "setSttProvider": "Batch Set STT Provider", + "setTtsProvider": "Batch Set TTS Provider", + "setLlmStatus": "Batch Set LLM Status", + "setTtsStatus": "Batch Set TTS Status", + "noSttProvider": "No STT Provider Available", + "noTtsProvider": "No TTS Provider Available" }, "pluginManagement": { "title": "Plugin Management", @@ -69,7 +74,6 @@ "sessionStatusSuccess": "Session {status}", "llmStatusSuccess": "LLM {status}", "ttsStatusSuccess": "TTS {status}", - "mcpStatusSuccess": "MCP {status}", "statusUpdateError": "Failed to update status", "loadSessionsError": "Failed to load session list", "batchUpdateSuccess": "Successfully batch updated {count} settings", diff --git a/dashboard/src/i18n/locales/zh-CN/features/session-management.json b/dashboard/src/i18n/locales/zh-CN/features/session-management.json index ab0a9d779..4639117f4 100644 --- a/dashboard/src/i18n/locales/zh-CN/features/session-management.json +++ b/dashboard/src/i18n/locales/zh-CN/features/session-management.json @@ -29,7 +29,6 @@ "ttsProvider": "TTS Provider", "llmStatus": "LLM启停", "ttsStatus": "TTS启停", - "mcpStatus": "MCP启停", "pluginManagement": "插件管理" } }, @@ -43,7 +42,13 @@ "batchOperations": { "title": "批量操作", "setPersona": "批量设置人格", - "setChatProvider": "批量设置 Chat Provider" + "setChatProvider": "批量设置 Chat Provider", + "setSttProvider": "批量设置 STT Provider", + "setTtsProvider": "批量设置 TTS Provider", + "setLlmStatus": "批量设置 LLM 状态", + "setTtsStatus": "批量设置 TTS 状态", + "noSttProvider": "暂无可用 STT Provider", + "noTtsProvider": "暂无可用 TTS Provider" }, "pluginManagement": { "title": "插件管理", @@ -69,7 +74,6 @@ "sessionStatusSuccess": "会话 {status}", "llmStatusSuccess": "LLM {status}", "ttsStatusSuccess": "TTS {status}", - "mcpStatusSuccess": "MCP {status}", "statusUpdateError": "状态更新失败", "loadSessionsError": "加载会话列表失败", "batchUpdateSuccess": "成功批量更新 {count} 项设置", diff --git a/dashboard/src/views/SessionManagementPage.vue b/dashboard/src/views/SessionManagementPage.vue index 30554d841..4efb0add5 100644 --- a/dashboard/src/views/SessionManagementPage.vue +++ b/dashboard/src/views/SessionManagementPage.vue @@ -52,9 +52,13 @@ @@ -242,21 +246,6 @@ - - -