fix(models): preserve session model selection
This commit is contained in:
parent
779140ef59
commit
9399d3f41e
@ -116,7 +116,7 @@ class MainTerminalToolsPolicyMixin:
|
|||||||
continue
|
continue
|
||||||
self.tool_category_states[key] = bool(value)
|
self.tool_category_states[key] = bool(value)
|
||||||
|
|
||||||
def apply_personalization_preferences(self, config: Optional[Dict[str, Any]] = None):
|
def apply_personalization_preferences(self, config: Optional[Dict[str, Any]] = None, *, apply_default_model: bool = True):
|
||||||
"""Apply persisted personalization settings that affect runtime behavior."""
|
"""Apply persisted personalization settings that affect runtime behavior."""
|
||||||
try:
|
try:
|
||||||
effective_config = config or load_personalization_config(self.data_dir)
|
effective_config = config or load_personalization_config(self.data_dir)
|
||||||
@ -176,7 +176,7 @@ class MainTerminalToolsPolicyMixin:
|
|||||||
|
|
||||||
# 默认模型偏好(优先应用,再处理运行模式)
|
# 默认模型偏好(优先应用,再处理运行模式)
|
||||||
preferred_model = effective_config.get("default_model")
|
preferred_model = effective_config.get("default_model")
|
||||||
if isinstance(preferred_model, str) and preferred_model != self.model_key:
|
if apply_default_model and isinstance(preferred_model, str) and preferred_model != self.model_key:
|
||||||
try:
|
try:
|
||||||
self.set_model(preferred_model)
|
self.set_model(preferred_model)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|||||||
@ -67,7 +67,29 @@ def _apply_workspace_personalization_preferences(terminal: WebTerminal, workspac
|
|||||||
"""Apply persisted workspace personalization after policy/workspace resolution."""
|
"""Apply persisted workspace personalization after policy/workspace resolution."""
|
||||||
try:
|
try:
|
||||||
config = load_personalization_config(workspace.data_dir)
|
config = load_personalization_config(workspace.data_dir)
|
||||||
terminal.apply_personalization_preferences(config)
|
session_model = None
|
||||||
|
if has_request_context():
|
||||||
|
raw_session_model = session.get("model_key")
|
||||||
|
if isinstance(raw_session_model, str) and raw_session_model.strip():
|
||||||
|
session_model = raw_session_model.strip()
|
||||||
|
|
||||||
|
# default_model 是“新会话初始偏好”,不能在每次 /api/status、任务创建、
|
||||||
|
# 加载资源时覆盖用户已经在当前会话里手动切换的模型。
|
||||||
|
if session_model and session_model != getattr(terminal, "model_key", None):
|
||||||
|
try:
|
||||||
|
terminal.set_model(session_model)
|
||||||
|
except Exception as exc:
|
||||||
|
debug_log(f"[Personalization] 恢复会话模型失败: {session_model} ({exc})")
|
||||||
|
|
||||||
|
apply_default_model = not bool(session_model) and not bool(
|
||||||
|
getattr(terminal, "_workspace_default_model_applied", False)
|
||||||
|
)
|
||||||
|
terminal.apply_personalization_preferences(config, apply_default_model=apply_default_model)
|
||||||
|
if apply_default_model:
|
||||||
|
try:
|
||||||
|
terminal._workspace_default_model_applied = True
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
if has_request_context():
|
if has_request_context():
|
||||||
session["run_mode"] = getattr(terminal, "run_mode", session.get("run_mode"))
|
session["run_mode"] = getattr(terminal, "run_mode", session.get("run_mode"))
|
||||||
session["thinking_mode"] = getattr(terminal, "thinking_mode", session.get("thinking_mode"))
|
session["thinking_mode"] = getattr(terminal, "thinking_mode", session.get("thinking_mode"))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user