From dc8f48513f6dd08feabfda51d6d558c0bd7b67fe Mon Sep 17 00:00:00 2001 From: Wenjie Zhang Date: Tue, 2 Sep 2025 19:53:12 +0800 Subject: [PATCH] =?UTF-8?q?fix(AgentConfigSidebar):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=97=A0=E6=95=88=E9=85=8D=E7=BD=AE=E7=9A=84=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/AgentConfigSidebar.vue | 25 ++++++++--------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/web/src/components/AgentConfigSidebar.vue b/web/src/components/AgentConfigSidebar.vue index a27d826b..b03903ab 100644 --- a/web/src/components/AgentConfigSidebar.vue +++ b/web/src/components/AgentConfigSidebar.vue @@ -470,42 +470,33 @@ const cancelToolsSelection = () => { const validateAndFilterConfig = () => { const validatedConfig = { ...agentConfig.value }; const configItems = configurableItems.value; - + // 遍历所有配置项 Object.keys(configItems).forEach(key => { const configItem = configItems[key]; const currentValue = validatedConfig[key]; - + // 检查工具配置 if (configItem.template_metadata?.kind === 'tools' && Array.isArray(currentValue)) { const availableToolIds = availableTools.value ? Object.values(availableTools.value).map(tool => tool.id) : []; validatedConfig[key] = currentValue.filter(toolId => availableToolIds.includes(toolId)); - + if (validatedConfig[key].length !== currentValue.length) { console.warn(`工具配置 ${key} 中包含无效的工具ID,已自动过滤`); } } - + // 检查多选配置项 (type === 'list' 且有 options) else if (configItem.type === 'list' && configItem.options && Array.isArray(currentValue)) { const validOptions = configItem.options; validatedConfig[key] = currentValue.filter(value => validOptions.includes(value)); - + if (validatedConfig[key].length !== currentValue.length) { console.warn(`配置项 ${key} 中包含无效的选项,已自动过滤`); } } - - // 检查单选配置项 (有 options 且不是 list 类型) - else if (configItem.options && configItem.type !== 'list' && currentValue !== undefined) { - const validOptions = configItem.options; - if (!validOptions.includes(currentValue)) { - console.warn(`配置项 ${key} 的值 "${currentValue}" 不在有效选项中,将重置为默认值`); - validatedConfig[key] = configItem.default || validOptions[0] || null; - } - } }); - + return validatedConfig; }; @@ -519,13 +510,13 @@ const saveConfig = async () => { try { // 验证和过滤配置 const validatedConfig = validateAndFilterConfig(); - + // 如果配置有变化,先更新到store if (JSON.stringify(validatedConfig) !== JSON.stringify(agentConfig.value)) { agentStore.updateAgentConfig(validatedConfig); message.info('检测到无效配置项,已自动过滤'); } - + await agentStore.saveAgentConfig(); message.success('配置已保存到服务器'); } catch (error) {