diff --git a/core/web_terminal.py b/core/web_terminal.py index 8ee8781..6589fa5 100644 --- a/core/web_terminal.py +++ b/core/web_terminal.py @@ -132,10 +132,17 @@ class WebTerminal(MainTerminal): try: success = self.context_manager.load_conversation_by_id(conversation_id) if success: - # 重置相关状态 - if self.thinking_mode: + # 根据对话元数据同步思考模式 + try: + conv_data = self.context_manager.conversation_manager.load_conversation(conversation_id) or {} + meta = conv_data.get("metadata", {}) or {} + mode = bool(meta.get("thinking_mode", self.thinking_mode)) + self.thinking_mode = mode + self.api_client.thinking_mode = mode self.api_client.start_new_task() - + except Exception: + pass + # 重置相关状态 self.current_session_id += 1 # 获取对话信息 diff --git a/utils/context_manager.py b/utils/context_manager.py index 2574791..0ea8008 100644 --- a/utils/context_manager.py +++ b/utils/context_manager.py @@ -370,7 +370,8 @@ class ContextManager: conversation_id=self.current_conversation_id, messages=self.conversation_history, project_path=str(self.project_path), - todo_list=self.todo_list + todo_list=self.todo_list, + thinking_mode=getattr(self.main_terminal, "thinking_mode", None) if hasattr(self, "main_terminal") else None ) if success: diff --git a/web_server.py b/web_server.py index 8d08c7a..8704d21 100644 --- a/web_server.py +++ b/web_server.py @@ -280,6 +280,16 @@ def ensure_conversation_loaded(terminal: WebTerminal, conversation_id: Optional[ load_result = terminal.load_conversation(conversation_id) if not load_result.get("success"): raise RuntimeError(load_result.get("message", "对话加载失败")) + # 切换到对话记录的思考模式 + try: + conv_data = terminal.context_manager.conversation_manager.load_conversation(conversation_id) or {} + meta = conv_data.get("metadata", {}) or {} + mode = bool(meta.get("thinking_mode", terminal.thinking_mode)) + terminal.thinking_mode = mode + terminal.api_client.thinking_mode = mode + terminal.api_client.start_new_task() + except Exception: + pass return conversation_id, created_new def reset_system_state(terminal: Optional[WebTerminal]): @@ -509,6 +519,19 @@ def update_thinking_mode(terminal: WebTerminal, workspace: UserWorkspace, userna terminal.api_client.thinking_mode = desired_mode terminal.api_client.start_new_task() session['thinking_mode'] = desired_mode + # 更新当前对话的元数据 + ctx = terminal.context_manager + if ctx.current_conversation_id: + try: + ctx.conversation_manager.save_conversation( + conversation_id=ctx.current_conversation_id, + messages=ctx.conversation_history, + project_path=str(ctx.project_path), + todo_list=ctx.todo_list, + thinking_mode=desired_mode + ) + except Exception as exc: + print(f"[API] 保存思考模式到对话失败: {exc}") status = terminal.get_status() socketio.emit('status_update', status, room=f"user_{username}")