From 0451a7fef4a049fd6ea2f1b16799bd7b967819a2 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sat, 7 Mar 2026 21:52:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AE=A4=E8=AF=81=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E9=80=BB=E8=BE=91=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E7=8A=B6=E6=80=81=E6=98=BE=E7=A4=BA=E5=9C=A8=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E4=BD=8D=E7=BD=AE=EF=BC=9B=E6=9B=B4=E6=96=B0=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=AA=8C=E8=AF=81=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=B7=B1=E6=8B=B7=E8=B4=9D=E7=A1=AE=E4=BF=9D=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=AE=8C=E6=95=B4=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dashboard/src/components/layout/Layout.tsx | 18 +++++++++--------- dashboard/src/routes/config/bot.tsx | 10 +++++----- src/webui/routers/config.py | 12 +++++++----- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/dashboard/src/components/layout/Layout.tsx b/dashboard/src/components/layout/Layout.tsx index 6169133e..058bfca7 100644 --- a/dashboard/src/components/layout/Layout.tsx +++ b/dashboard/src/components/layout/Layout.tsx @@ -94,15 +94,6 @@ export function Layout({ children }: LayoutProps) { return unsubscribe }, [router, announce, t]) - // 认证检查中,显示加载状态 - if (checking) { - return ( -
-
{t('layout.verifyingLogin')}
-
- ) - } - // 获取实际应用的主题(处理 system 情况) const getActualTheme = () => { if (theme === 'system') { @@ -114,6 +105,15 @@ export function Layout({ children }: LayoutProps) { const actualTheme = getActualTheme() const pageBg = useBackground('page') + // 认证检查中,显示加载状态 + if (checking) { + return ( +
+
{t('layout.verifyingLogin')}
+
+ ) + } + return ( diff --git a/dashboard/src/routes/config/bot.tsx b/dashboard/src/routes/config/bot.tsx index 0f81d58a..84133f92 100644 --- a/dashboard/src/routes/config/bot.tsx +++ b/dashboard/src/routes/config/bot.tsx @@ -189,8 +189,8 @@ function BotConfigPageContent() { setBotConfig(config.bot as BotConfig) setPersonalityConfig(config.personality as PersonalityConfig) - // 确保 talk_value_rules 有默认值 - const chatConfigData = config.chat as ChatConfig + // 确保 chat 配置和 talk_value_rules 有默认值 + const chatConfigData = (config.chat ?? {}) as ChatConfig if (!chatConfigData.talk_value_rules) { chatConfigData.talk_value_rules = [] } @@ -265,7 +265,7 @@ function BotConfigPageContent() { }) return } - const raw = result.data + const raw = (result.data as unknown as Record).content as string // 将 TOML 基本字符串中的转义序列转换为实际字符以便在编辑器中正确显示 // 使用正则表达式只处理双引号字符串内的转义序列,不影响单引号字符串 const unescaped = raw.replace(/"([^"]*)"/g, (_match, content) => { @@ -302,7 +302,7 @@ function BotConfigPageContent() { setLoading(false) return } - parseAndSetConfig(result.data) + parseAndSetConfig((result.data as Record).config as Record) setHasUnsavedChanges(false) initialLoadRef.current = false @@ -455,7 +455,7 @@ function BotConfigPageContent() { }) return } - parseAndSetConfig(result.data) + parseAndSetConfig((result.data as Record).config as Record) setHasUnsavedChanges(false) } catch (error) { console.error('加载配置失败:', error) diff --git a/src/webui/routers/config.py b/src/webui/routers/config.py index a5004a73..1ebe2066 100644 --- a/src/webui/routers/config.py +++ b/src/webui/routers/config.py @@ -2,6 +2,7 @@ 配置管理API路由 """ +import copy import os import tomlkit from fastapi import APIRouter, HTTPException, Body, Depends, Cookie, Header @@ -11,6 +12,7 @@ from src.common.logger import get_logger from src.webui.core import verify_auth_token_from_cookie_or_header from src.webui.utils.toml_utils import save_toml_with_format, _update_toml_doc from src.config.config import Config, ModelConfig, CONFIG_DIR, PROJECT_ROOT +from src.config.config_base import AttributeData from src.config.official_configs import ( BotConfig, PersonalityConfig, @@ -204,7 +206,7 @@ async def update_bot_config(config_data: ConfigBody, _auth: bool = Depends(requi try: # 验证配置数据 try: - Config.from_dict(config_data) + Config.from_dict(AttributeData(), copy.deepcopy(config_data)) except Exception as e: raise HTTPException(status_code=400, detail=f"配置数据验证失败: {str(e)}") from e @@ -227,7 +229,7 @@ async def update_model_config(config_data: ConfigBody, _auth: bool = Depends(req try: # 验证配置数据 try: - ModelConfig.from_dict(config_data) + ModelConfig.from_dict(AttributeData(), copy.deepcopy(config_data)) except Exception as e: raise HTTPException(status_code=400, detail=f"配置数据验证失败: {str(e)}") from e @@ -277,7 +279,7 @@ async def update_bot_config_section(section_name: str, section_data: SectionBody # 验证完整配置 try: - Config.from_dict(config_data) + Config.from_dict(AttributeData(), copy.deepcopy(dict(config_data))) except Exception as e: raise HTTPException(status_code=400, detail=f"配置数据验证失败: {str(e)}") from e @@ -327,7 +329,7 @@ async def update_bot_config_raw(raw_content: RawContentBody, _auth: bool = Depen # 验证配置数据结构 try: - Config.from_dict(config_data) + Config.from_dict(AttributeData(), copy.deepcopy(dict(config_data))) except Exception as e: raise HTTPException(status_code=400, detail=f"配置数据验证失败: {str(e)}") from e @@ -377,7 +379,7 @@ async def update_model_config_section( # 验证完整配置 try: - ModelConfig.from_dict(config_data) + ModelConfig.from_dict(AttributeData(), copy.deepcopy(dict(config_data))) except Exception as e: logger.error(f"配置数据验证失败,详细错误: {str(e)}") # 特殊处理:如果是更新 api_providers,检查是否有模型引用了已删除的provider