From 7b683ab3903975214f8455e94730b37b1ae9b419 Mon Sep 17 00:00:00 2001 From: JOJO <1498581755@qq.com> Date: Sat, 20 Jun 2026 12:15:18 +0800 Subject: [PATCH] fix(sub_agent): export TERMINAL_STATUSES in package __init__ fix(api_client): classify httpx.RemoteProtocolError as connection_error --- modules/sub_agent/__init__.py | 4 ++-- utils/api_client.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/modules/sub_agent/__init__.py b/modules/sub_agent/__init__.py index 0e0958f..5772be4 100644 --- a/modules/sub_agent/__init__.py +++ b/modules/sub_agent/__init__.py @@ -4,6 +4,6 @@ 主 WebTerminal 执行,因此自然复用主进程的宿主机沙箱 / Docker 容器链路。 """ -from modules.sub_agent.manager import SubAgentManager +from modules.sub_agent.manager import SubAgentManager, TERMINAL_STATUSES -__all__ = ["SubAgentManager"] +__all__ = ["SubAgentManager", "TERMINAL_STATUSES"] diff --git a/utils/api_client.py b/utils/api_client.py index 2193b91..0db484b 100644 --- a/utils/api_client.py +++ b/utils/api_client.py @@ -912,6 +912,30 @@ class DeepSeekClient: # legacy name; generic OpenAI-compatible client }) self._mark_request_error(dump_path, error_text="timeout") yield {"error": self.last_error_info} + except httpx.RemoteProtocolError as e: + disconnect_detail = str(e).strip() or repr(e) + self._print(f"{OUTPUT_FORMATS['error']} API服务器连接断开({disconnect_detail})") + self.last_error_info = { + "status_code": None, + "error_text": disconnect_detail, + "error_type": "connection_error", + "error_message": f"API服务器连接断开: {disconnect_detail}", + "request_dump": (str(dump_path) if dump_path else None), + "base_url": api_config.get("base_url"), + "model_id": api_config.get("model_id"), + "model_key": self.model_key + } + self._debug_log({ + "event": "server_disconnected", + "status_code": None, + "error_text": disconnect_detail, + "base_url": api_config.get("base_url"), + "model_id": api_config.get("model_id"), + "model_key": self.model_key, + "request_dump": (str(dump_path) if dump_path else None) + }) + self._mark_request_error(dump_path, error_text=f"server_disconnected: {disconnect_detail}") + yield {"error": self.last_error_info} except Exception as e: error_text = str(e).strip() or repr(e) self._print(f"{OUTPUT_FORMATS['error']} API调用异常: {error_text}")