fix(web): persist thinking mode toggle

This commit is contained in:
JOJO 2025-11-18 10:35:12 +08:00
parent 7ca7bddba4
commit 041c79f3b7
5 changed files with 9 additions and 24 deletions

View File

@ -252,10 +252,7 @@ class WebTerminal(MainTerminal):
# 构建状态信息 # 构建状态信息
status = { status = {
"project_path": self.project_path, "project_path": self.project_path,
"thinking_mode": { "thinking_mode": self.thinking_mode,
"enabled": self.thinking_mode,
"label": self.get_thinking_mode_status()
},
"thinking_status": self.get_thinking_mode_status(), "thinking_status": self.get_thinking_mode_status(),
"context": { "context": {
"usage_percent": context_status['usage_percent'], "usage_percent": context_status['usage_percent'],

View File

@ -592,11 +592,7 @@ async function bootstrapApp() {
this.socket.on('system_ready', (data) => { this.socket.on('system_ready', (data) => {
this.projectPath = data.project_path || ''; this.projectPath = data.project_path || '';
this.agentVersion = data.version || this.agentVersion; this.agentVersion = data.version || this.agentVersion;
if (typeof data.thinking_mode === 'object') { this.thinkingMode = !!data.thinking_mode;
this.thinkingMode = !!data.thinking_mode.enabled;
} else {
this.thinkingMode = data.thinking_mode === '思考模式';
}
console.log('系统就绪:', data); console.log('系统就绪:', data);
// 系统就绪后立即加载对话列表 // 系统就绪后立即加载对话列表
@ -1293,7 +1289,6 @@ async function bootstrapApp() {
this.toolMenuOpen = false; this.toolMenuOpen = false;
this.toolSettingsLoading = false; this.toolSettingsLoading = false;
this.toolSettings = []; this.toolSettings = [];
this.thinkingMode = false;
console.log('前端状态重置完成'); console.log('前端状态重置完成');
}, },
@ -1326,11 +1321,7 @@ async function bootstrapApp() {
const statusData = await statusResponse.json(); const statusData = await statusResponse.json();
this.projectPath = statusData.project_path || ''; this.projectPath = statusData.project_path || '';
this.agentVersion = statusData.version || this.agentVersion; this.agentVersion = statusData.version || this.agentVersion;
if (statusData.thinking_mode) { this.thinkingMode = !!statusData.thinking_mode;
this.thinkingMode = !!statusData.thinking_mode.enabled;
} else {
this.thinkingMode = false;
}
// 获取当前对话信息 // 获取当前对话信息
const statusConversationId = statusData.conversation && statusData.conversation.current_id; const statusConversationId = statusData.conversation && statusData.conversation.current_id;

View File

@ -538,7 +538,7 @@
class="menu-btn mode-entry" class="menu-btn mode-entry"
@click="toggleThinkingMode" @click="toggleThinkingMode"
:disabled="streamingMessage || !isConnected"> :disabled="streamingMessage || !isConnected">
{{ thinkingMode ? '当前:思考模式(点此切换为快速模式)' : '当前:快速模式(点此切换为思考模式)' }} {{ thinkingMode ? '思考模式' : '快速模式' }}
</button> </button>
<button type="button" <button type="button"
class="menu-btn compress-entry" class="menu-btn compress-entry"

View File

@ -47,6 +47,10 @@ class DeepSeekClient:
} }
self.thinking_mode = thinking_mode # True=智能思考模式, False=快速模式 self.thinking_mode = thinking_mode # True=智能思考模式, False=快速模式
self.web_mode = web_mode # Web模式标志用于禁用print输出 self.web_mode = web_mode # Web模式标志用于禁用print输出
# 兼容旧代码路径
self.api_base_url = self.fast_api_config["base_url"]
self.api_key = self.fast_api_config["api_key"]
self.model_id = self.fast_api_config["model_id"]
# 每个任务的独立状态 # 每个任务的独立状态
self.current_task_first_call = True # 当前任务是否是第一次调用 self.current_task_first_call = True # 当前任务是否是第一次调用
self.current_task_thinking = "" # 当前任务的思考内容 self.current_task_thinking = "" # 当前任务的思考内容

View File

@ -69,13 +69,6 @@ stop_flags: Dict[str, Dict[str, Any]] = {}
DEFAULT_PORT = 8091 DEFAULT_PORT = 8091
def serialize_thinking_mode(terminal: WebTerminal) -> Dict[str, Any]:
"""构造思考模式状态payload包含是否启用与显示标签。"""
return {
"enabled": bool(getattr(terminal, "thinking_mode", False)),
"label": terminal.get_thinking_mode_status() if hasattr(terminal, "get_thinking_mode_status") else ("思考模式" if getattr(terminal, "thinking_mode", False) else "快速模式")
}
def format_read_file_result(result_data: Dict) -> str: def format_read_file_result(result_data: Dict) -> str:
"""格式化 read_file 工具的输出便于在Web端展示。""" """格式化 read_file 工具的输出便于在Web端展示。"""
if not isinstance(result_data, dict): if not isinstance(result_data, dict):
@ -1088,7 +1081,7 @@ def handle_connect():
reset_system_state(terminal) reset_system_state(terminal)
emit('system_ready', { emit('system_ready', {
'project_path': str(workspace.project_path), 'project_path': str(workspace.project_path),
'thinking_mode': serialize_thinking_mode(terminal), 'thinking_mode': bool(getattr(terminal, "thinking_mode", False)),
'version': AGENT_VERSION 'version': AGENT_VERSION
}, room=request.sid) }, room=request.sid)