支持全局配置保存后立即应用到运行时

- 新增 Robot.apply_runtime_config 统一刷新邮件发送器、管理员列表与 LLM 运行时缓存\n- 新增 LLMRegistry.invalidate_cache 主动清理目录与 legacy 配置缓存\n- 后台保存全局配置与 LLM 目录后立即应用运行时配置,减少重启依赖
This commit is contained in:
liuwei
2026-04-29 17:27:21 +08:00
parent 28dc9da852
commit b53206d0d1
3 changed files with 60 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ import json
import yaml
import toml
from utils.markdown_to_image import get_md2img_health_snapshot, warmup_md2img_browser_sync
from utils.ai.llm_registry import LLMRegistry
# 创建系统信息蓝图
system_bp = Blueprint('system', __name__)
@@ -479,8 +480,13 @@ def update_system_config():
if getattr(server, "robot", None) and getattr(server.robot, "config", None):
server.robot.config.reload()
# 保存 YAML 后立刻把运行时依赖对象同步一遍,避免必须重启进程才能读到新值。
server.robot.apply_runtime_config(reload_catalog=True)
else:
# 即便当前没有可用 robot 实例,也尽量把 LLM 路由缓存清掉,避免后续请求短时间内读旧值。
LLMRegistry.invalidate_cache()
return jsonify({"success": True, "message": "全局配置已保存"})
return jsonify({"success": True, "message": "全局配置已保存并应用到运行时"})
except Exception as e:
logger.error(f"保存系统配置失败: {e}")
return jsonify({"success": False, "message": str(e)}), 500
@@ -606,8 +612,12 @@ def update_system_llm_config():
if getattr(server, "robot", None) and getattr(server.robot, "config", None):
server.robot.config.reload()
# LLM 目录保存到 MySQL 后,需要主动失效运行时缓存,保证插件下一次调用直接走新目录。
server.robot.apply_runtime_config(reload_catalog=True)
else:
LLMRegistry.invalidate_cache()
return jsonify({"success": True, "message": "全局 LLM 配置已保存"})
return jsonify({"success": True, "message": "全局 LLM 配置已保存并应用到运行时"})
except Exception as e:
logger.error(f"保存全局 LLM 配置失败: {e}")
return jsonify({"success": False, "message": str(e)}), 500