From 7a64371603d87c5cafac41587b68d01533e94d6a Mon Sep 17 00:00:00 2001 From: wizardchen Date: Thu, 6 Nov 2025 02:45:44 +0800 Subject: [PATCH] feat: Implement theme management and UI enhancements across the application - Added theme initialization and management in the UI store. - Enhanced dark mode styles for various components, including tables, dialogs, and inputs. - Updated multiple components to use CSS variables for consistent theming. - Introduced a new simplified API for updating knowledge base configurations. - Improved overall UI consistency and responsiveness with new styles. --- frontend/src/App.vue | 109 ++- frontend/src/api/initialization/index.ts | 56 +- frontend/src/components/Input-field.vue | 54 +- frontend/src/components/ModelSelector.vue | 161 +++++ frontend/src/components/UserMenu.vue | 32 +- frontend/src/components/menu.vue | 113 +-- frontend/src/stores/ui.ts | 76 +- .../chat/components/AgentStreamDisplay.vue | 64 +- frontend/src/views/chat/components/botmsg.vue | 4 +- .../components/tool-results/tool-results.less | 54 +- .../src/views/chat/components/usermsg.vue | 4 +- frontend/src/views/chat/index.vue | 8 +- .../src/views/knowledge/KnowledgeBaseList.vue | 41 +- .../knowledge/KnowledgeBaseSettingsModal.vue | 668 ++++++++++++++++++ .../knowledge/settings/KBAdvancedSettings.vue | 482 +++++++++++++ .../views/knowledge/settings/KBBasicInfo.vue | 198 ++++++ .../knowledge/settings/KBChunkingSettings.vue | 227 ++++++ .../knowledge/settings/KBModelConfig.vue | 217 ++++++ frontend/src/views/settings/AgentSettings.vue | 100 ++- .../src/views/settings/GeneralSettings.vue | 25 +- .../views/settings/KnowledgeBaseSettings.vue | 12 +- frontend/src/views/settings/ModelSettings.vue | 38 +- .../src/views/settings/OllamaSettings.vue | 67 +- frontend/src/views/settings/Settings.vue | 87 ++- frontend/src/views/settings/SystemInfo.vue | 22 +- internal/handler/initialization.go | 216 +++++- internal/handler/tenant.go | 2 +- internal/router/router.go | 1 + 28 files changed, 2808 insertions(+), 330 deletions(-) create mode 100644 frontend/src/components/ModelSelector.vue create mode 100644 frontend/src/views/knowledge/KnowledgeBaseSettingsModal.vue create mode 100644 frontend/src/views/knowledge/settings/KBAdvancedSettings.vue create mode 100644 frontend/src/views/knowledge/settings/KBBasicInfo.vue create mode 100644 frontend/src/views/knowledge/settings/KBChunkingSettings.vue create mode 100644 frontend/src/views/knowledge/settings/KBModelConfig.vue diff --git a/frontend/src/App.vue b/frontend/src/App.vue index e7d4d2bf..1854102b 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -1,4 +1,13 @@ + diff --git a/frontend/src/views/knowledge/settings/KBAdvancedSettings.vue b/frontend/src/views/knowledge/settings/KBAdvancedSettings.vue new file mode 100644 index 00000000..90d8bd7e --- /dev/null +++ b/frontend/src/views/knowledge/settings/KBAdvancedSettings.vue @@ -0,0 +1,482 @@ + + + + + + diff --git a/frontend/src/views/knowledge/settings/KBBasicInfo.vue b/frontend/src/views/knowledge/settings/KBBasicInfo.vue new file mode 100644 index 00000000..1610061c --- /dev/null +++ b/frontend/src/views/knowledge/settings/KBBasicInfo.vue @@ -0,0 +1,198 @@ + + + + + + diff --git a/frontend/src/views/knowledge/settings/KBChunkingSettings.vue b/frontend/src/views/knowledge/settings/KBChunkingSettings.vue new file mode 100644 index 00000000..7a7e978e --- /dev/null +++ b/frontend/src/views/knowledge/settings/KBChunkingSettings.vue @@ -0,0 +1,227 @@ + + + + + + diff --git a/frontend/src/views/knowledge/settings/KBModelConfig.vue b/frontend/src/views/knowledge/settings/KBModelConfig.vue new file mode 100644 index 00000000..e81ae178 --- /dev/null +++ b/frontend/src/views/knowledge/settings/KBModelConfig.vue @@ -0,0 +1,217 @@ + + + + + + diff --git a/frontend/src/views/settings/AgentSettings.vue b/frontend/src/views/settings/AgentSettings.vue index 63402b56..c9793136 100644 --- a/frontend/src/views/settings/AgentSettings.vue +++ b/frontend/src/views/settings/AgentSettings.vue @@ -57,7 +57,7 @@ filterable placeholder="搜索模型..." @change="handleThinkingModelChange" - @focus="loadChatModels" + @focus="loadAllModels" style="width: 280px;" > @@ -98,7 +98,7 @@ filterable placeholder="搜索模型..." @change="handleRerankModelChange" - @focus="loadRerankModels" + @focus="loadAllModels" style="width: 280px;" > @@ -209,16 +209,24 @@ const availableTools = ref([]) // 配置加载状态 const loadingConfig = ref(false) +const configLoaded = ref(false) // 防止重复加载 +const isInitializing = ref(true) // 标记是否正在初始化,防止初始化时触发保存 // 初始化加载 onMounted(async () => { + // 防止重复加载 + if (configLoaded.value) return + loadingConfig.value = true + configLoaded.value = true + isInitializing.value = true + try { // 从后台加载配置 const res = await getAgentConfig() const config = res.data - // 更新本地状态 + // 更新本地状态(在初始化期间,不会触发保存) localAgentEnabled.value = config.enabled localMaxIterations.value = config.max_iterations localTemperature.value = config.temperature @@ -227,17 +235,12 @@ onMounted(async () => { localAllowedTools.value = config.allowed_tools || [] availableTools.value = config.available_tools || [] - // 如果配置了思考模型,立即加载模型列表以显示模型名称 - if (config.thinking_model_id) { - await loadChatModels() + // 统一加载所有模型(只调用一次API) + if (config.thinking_model_id || config.rerank_model_id) { + await loadAllModels() } - // 如果配置了 rerank 模型,立即加载模型列表以显示模型名称 - if (config.rerank_model_id) { - await loadRerankModels() - } - - // 同步到store + // 同步到store(只更新本地存储,不触发API保存) settingsStore.toggleAgent(config.enabled) settingsStore.updateAgentConfig({ maxIterations: config.max_iterations, @@ -245,9 +248,13 @@ onMounted(async () => { thinkingModelId: config.thinking_model_id, rerankModelId: config.rerank_model_id }) + + // 初始化完成 + isInitializing.value = false } catch (error) { console.error('加载Agent配置失败:', error) MessagePlugin.error('加载Agent配置失败') + configLoaded.value = false // 加载失败时重置标记,允许重试 // 失败时从store加载 localAgentEnabled.value = settingsStore.isAgentEnabled @@ -257,6 +264,7 @@ onMounted(async () => { localRerankModelId.value = settingsStore.agentConfig.rerankModelId } finally { loadingConfig.value = false + isInitializing.value = false // 确保初始化完成,即使失败也要允许后续操作 } }) @@ -283,6 +291,11 @@ const getErrorMessage = (error: any): string => { // 处理 Agent 开关 const handleAgentToggle = async (value: boolean) => { + // 如果正在初始化,不触发保存(但用户手动切换开关应该允许) + // 注意:这个可能不需要检查,因为用户手动切换开关应该保存 + // 但为了安全,如果初始化时开关状态变化,也不保存 + if (isInitializing.value) return + try { // 构建完整配置 const config: AgentConfig = { @@ -308,6 +321,9 @@ const handleAgentToggle = async (value: boolean) => { // 处理最大迭代次数变化 const handleMaxIterationsChange = async (value: number) => { + // 如果正在初始化,不触发保存 + if (isInitializing.value) return + try { const config: AgentConfig = { enabled: localAgentEnabled.value, @@ -328,40 +344,39 @@ const handleMaxIterationsChange = async (value: number) => { } } -// 加载对话模型列表 -const loadChatModels = async () => { - if (chatModels.value.length > 0) return // 已经加载过 +// 统一加载所有模型(只调用一次API) +const loadAllModels = async () => { + if (chatModels.value.length > 0 && rerankModels.value.length > 0) return // 已经加载过 loadingModels.value = true try { const allModels = await listModels() - // 只获取对话模型(KnowledgeQA 类型) + // 按类型过滤,避免重复调用 chatModels.value = allModels.filter(m => m.type === 'KnowledgeQA') + rerankModels.value = allModels.filter(m => m.type === 'Rerank') } catch (error) { + console.error('加载模型列表失败:', error) MessagePlugin.error('加载模型列表失败') } finally { loadingModels.value = false } } -// 加载 Rerank 模型列表 +// 加载对话模型列表(已废弃,使用 loadAllModels) +const loadChatModels = async () => { + await loadAllModels() +} + +// 加载 Rerank 模型列表(已废弃,使用 loadAllModels) const loadRerankModels = async () => { - if (rerankModels.value.length > 0) return // 已经加载过 - - loadingModels.value = true - try { - const allModels = await listModels() - rerankModels.value = allModels.filter(m => m.type === 'Rerank') - } catch (error) { - console.error('加载 Rerank 模型列表失败:', error) - MessagePlugin.error('加载 Rerank 模型列表失败') - } finally { - loadingModels.value = false - } + await loadAllModels() } // 处理思考模型变化 const handleThinkingModelChange = async (value: string) => { + // 如果正在初始化,不触发保存 + if (isInitializing.value) return + // 如果选择添加新模型,跳转到模型配置页 if (value === '__add_model__') { router.push('/settings?section=models') @@ -391,6 +406,9 @@ const handleThinkingModelChange = async (value: string) => { // 监听模型选择,处理"添加模型"跳转 // 处理 Rerank 模型变化 const handleRerankModelChange = async (value: string) => { + // 如果正在初始化,不触发保存 + if (isInitializing.value) return + // 如果选择添加新模型,跳转到模型配置页 if (value === '__add_model__') { router.push('/settings?section=models&subsection=rerank') @@ -474,6 +492,9 @@ watch(() => localRerankModelId.value, (newValue) => { // 处理温度参数变化 const handleTemperatureChange = async (value: number) => { + // 如果正在初始化,不触发保存 + if (isInitializing.value) return + try { const config: AgentConfig = { enabled: localAgentEnabled.value, @@ -496,6 +517,9 @@ const handleTemperatureChange = async (value: number) => { // 处理允许工具变化 const handleAllowedToolsChange = async (value: string[]) => { + // 如果正在初始化,不触发保存 + if (isInitializing.value) return + try { const config: AgentConfig = { enabled: localAgentEnabled.value, @@ -530,13 +554,13 @@ const handleAllowedToolsChange = async (value: string[]) => { h2 { font-size: 20px; font-weight: 600; - color: #333333; + color: var(--td-text-color-primary); margin: 0 0 8px 0; } .section-description { font-size: 14px; - color: #666666; + color: var(--td-text-color-secondary); margin: 0; line-height: 1.5; } @@ -553,7 +577,7 @@ const handleAllowedToolsChange = async (value: string[]) => { align-items: flex-start; justify-content: space-between; padding: 20px 0; - border-bottom: 1px solid #e5e7eb; + border-bottom: 1px solid var(--td-component-border); &:last-child { border-bottom: none; @@ -582,14 +606,14 @@ const handleAllowedToolsChange = async (value: string[]) => { label { font-size: 15px; font-weight: 500; - color: #333333; + color: var(--td-text-color-primary); display: block; margin-bottom: 4px; } .desc { font-size: 13px; - color: #666666; + color: var(--td-text-color-secondary); margin: 0; line-height: 1.5; } @@ -613,7 +637,7 @@ const handleAllowedToolsChange = async (value: string[]) => { .value-display { font-size: 14px; font-weight: 500; - color: #333333; + color: var(--td-text-color-primary); min-width: 40px; text-align: right; } @@ -627,12 +651,12 @@ const handleAllowedToolsChange = async (value: string[]) => { .model-icon { font-size: 14px; - color: #07C05F; + color: var(--td-brand-color); } .add-icon { font-size: 14px; - color: #07C05F; + color: var(--td-brand-color); } .model-name { @@ -642,7 +666,7 @@ const handleAllowedToolsChange = async (value: string[]) => { &.add { .model-name { - color: #07C05F; + color: var(--td-brand-color); font-weight: 500; } } diff --git a/frontend/src/views/settings/GeneralSettings.vue b/frontend/src/views/settings/GeneralSettings.vue index c2330b15..757b8ff3 100644 --- a/frontend/src/views/settings/GeneralSettings.vue +++ b/frontend/src/views/settings/GeneralSettings.vue @@ -48,8 +48,11 @@ @@ -105,13 +114,13 @@ const handleThemeChange = () => { h2 { font-size: 20px; font-weight: 600; - color: #333333; + color: var(--td-text-color-primary); margin: 0 0 8px 0; } .section-description { font-size: 14px; - color: #666666; + color: var(--td-text-color-secondary); margin: 0; line-height: 1.5; } @@ -128,7 +137,7 @@ const handleThemeChange = () => { align-items: flex-start; justify-content: space-between; padding: 20px 0; - border-bottom: 1px solid #e5e7eb; + border-bottom: 1px solid var(--td-component-border); &:last-child { border-bottom: none; @@ -143,14 +152,14 @@ const handleThemeChange = () => { label { font-size: 15px; font-weight: 500; - color: #333333; + color: var(--td-text-color-primary); display: block; margin-bottom: 4px; } .desc { font-size: 13px; - color: #666666; + color: var(--td-text-color-secondary); margin: 0; line-height: 1.5; } diff --git a/frontend/src/views/settings/KnowledgeBaseSettings.vue b/frontend/src/views/settings/KnowledgeBaseSettings.vue index f2043863..3c355328 100644 --- a/frontend/src/views/settings/KnowledgeBaseSettings.vue +++ b/frontend/src/views/settings/KnowledgeBaseSettings.vue @@ -138,13 +138,13 @@ const handleLanguageDetectionChange = () => { h2 { font-size: 20px; font-weight: 600; - color: #333333; + color: var(--td-text-color-primary); margin: 0 0 8px 0; } .section-description { font-size: 14px; - color: #666666; + color: var(--td-text-color-secondary); margin: 0; line-height: 1.5; } @@ -161,7 +161,7 @@ const handleLanguageDetectionChange = () => { align-items: flex-start; justify-content: space-between; padding: 20px 0; - border-bottom: 1px solid #e5e7eb; + border-bottom: 1px solid var(--td-component-border); &:last-child { border-bottom: none; @@ -176,14 +176,14 @@ const handleLanguageDetectionChange = () => { label { font-size: 15px; font-weight: 500; - color: #333333; + color: var(--td-text-color-primary); display: block; margin-bottom: 4px; } .desc { font-size: 13px; - color: #666666; + color: var(--td-text-color-secondary); margin: 0; line-height: 1.5; } @@ -207,7 +207,7 @@ const handleLanguageDetectionChange = () => { .value-display { font-size: 14px; font-weight: 500; - color: #333333; + color: var(--td-text-color-primary); min-width: 40px; text-align: right; } diff --git a/frontend/src/views/settings/ModelSettings.vue b/frontend/src/views/settings/ModelSettings.vue index 30924455..8945465c 100644 --- a/frontend/src/views/settings/ModelSettings.vue +++ b/frontend/src/views/settings/ModelSettings.vue @@ -466,13 +466,13 @@ onMounted(() => { h2 { font-size: 20px; font-weight: 600; - color: #333333; + color: var(--td-text-color-primary); margin: 0 0 8px 0; } .section-description { font-size: 14px; - color: #666666; + color: var(--td-text-color-secondary); margin: 0; line-height: 1.5; } @@ -480,10 +480,10 @@ onMounted(() => { .model-category-section { margin-bottom: 24px; - border: 1px solid #e5e7eb; + border: 1px solid var(--td-component-border); border-radius: 8px; padding: 24px; - background: #ffffff; + background: var(--td-bg-color-container); &:last-child { margin-bottom: 0; @@ -502,13 +502,13 @@ onMounted(() => { h3 { font-size: 16px; font-weight: 600; - color: #333333; + color: var(--td-text-color-primary); margin: 0 0 4px 0; } p { font-size: 14px; - color: #666666; + color: var(--td-text-color-secondary); margin: 0; line-height: 1.5; } @@ -543,16 +543,16 @@ onMounted(() => { align-items: center; justify-content: space-between; padding: 10px 12px; - border: 1px solid #e5e7eb; + border: 1px solid var(--td-component-border); border-radius: 6px; - background: #fafafa; + background: var(--td-bg-color-secondarycontainer); transition: all 0.2s; position: relative; overflow: visible; &:hover { - border-color: #07C05F; - background: #ffffff; + border-color: var(--td-brand-color); + background: var(--td-bg-color-container); } } @@ -563,7 +563,7 @@ onMounted(() => { .model-name { font-size: 14px; font-weight: 500; - color: #333333; + color: var(--td-text-color-primary); margin-bottom: 4px; display: flex; align-items: center; @@ -575,22 +575,22 @@ onMounted(() => { align-items: center; gap: 10px; font-size: 12px; - color: #666666; + color: var(--td-text-color-secondary); .source-tag { padding: 1px 6px; - background: #e5e7eb; + background: var(--td-bg-color-component); border-radius: 3px; font-size: 11px; } .model-id { font-family: monospace; - color: #666666; + color: var(--td-text-color-secondary); } .dimension { - color: #999999; + color: var(--td-text-color-placeholder); } } } @@ -606,12 +606,12 @@ onMounted(() => { z-index: 1001; // 确保高于设置窗口的z-index (9999) .more-btn { - color: #666666; + color: var(--td-text-color-secondary); padding: 4px; &:hover { - background: #f5f7fa; - color: #333333; + background: var(--td-bg-color-component-hover); + color: var(--td-text-color-primary); } } } @@ -626,7 +626,7 @@ onMounted(() => { .empty-text { font-size: 14px; - color: #999999; + color: var(--td-text-color-placeholder); margin: 0 0 16px 0; } } diff --git a/frontend/src/views/settings/OllamaSettings.vue b/frontend/src/views/settings/OllamaSettings.vue index 7d3bfe54..b99e36b5 100644 --- a/frontend/src/views/settings/OllamaSettings.vue +++ b/frontend/src/views/settings/OllamaSettings.vue @@ -355,23 +355,30 @@ const initOllamaBaseUrl = async () => { // 如果接口没返回且 store 中也没有,使用默认值 localBaseUrl.value = 'http://localhost:11434' } + + // 如果启用了,直接使用初始化时获取的状态,避免重复调用 + if (localEnabled.value) { + connectionStatus.value = result.available + if (result.available) { + refreshModels() + } + } + + return result } catch (error) { console.error('初始化 Ollama 地址失败:', error) // 如果获取失败,使用默认值或 store 中的值 if (!localBaseUrl.value) { localBaseUrl.value = 'http://localhost:11434' } + return null } } // 组件挂载时自动检查连接 onMounted(async () => { - // 先初始化服务地址 + // 初始化服务地址,如果启用则直接使用返回的状态,避免重复调用 await initOllamaBaseUrl() - - if (localEnabled.value) { - testConnection() - } }) @@ -386,13 +393,13 @@ onMounted(async () => { h2 { font-size: 20px; font-weight: 600; - color: #333333; + color: var(--td-text-color-primary); margin: 0 0 8px 0; } .section-description { font-size: 14px; - color: #666666; + color: var(--td-text-color-secondary); margin: 0; line-height: 1.5; } @@ -409,7 +416,7 @@ onMounted(async () => { align-items: flex-start; justify-content: space-between; padding: 20px 0; - border-bottom: 1px solid #e5e7eb; + border-bottom: 1px solid var(--td-component-border); &:last-child { border-bottom: none; @@ -424,14 +431,14 @@ onMounted(async () => { label { font-size: 15px; font-weight: 500; - color: #333333; + color: var(--td-text-color-primary); display: block; margin-bottom: 4px; } .desc { font-size: 13px; - color: #666666; + color: var(--td-text-color-secondary); margin: 0; line-height: 1.5; } @@ -460,11 +467,11 @@ onMounted(async () => { font-size: 18px; &.success { - color: #07C05F; + color: var(--td-success-color); } &.error { - color: #e34d59; + color: var(--td-error-color); } &.spinning { @@ -476,10 +483,10 @@ onMounted(async () => { .model-category-section { margin-bottom: 24px; - border: 1px solid #e5e7eb; + border: 1px solid var(--td-component-border); border-radius: 8px; padding: 24px; - background: #ffffff; + background: var(--td-bg-color-container); &:last-child { margin-bottom: 0; @@ -498,13 +505,13 @@ onMounted(async () => { h3 { font-size: 16px; font-weight: 600; - color: #333333; + color: var(--td-text-color-primary); margin: 0 0 4px 0; } p { font-size: 14px; - color: #666666; + color: var(--td-text-color-secondary); margin: 0; line-height: 1.5; } @@ -517,7 +524,7 @@ onMounted(async () => { justify-content: center; gap: 8px; padding: 60px; - color: #666666; + color: var(--td-text-color-secondary); font-size: 14px; } @@ -536,14 +543,14 @@ onMounted(async () => { align-items: center; justify-content: space-between; padding: 10px 12px; - border: 1px solid #e5e7eb; + border: 1px solid var(--td-component-border); border-radius: 6px; - background: #fafafa; + background: var(--td-bg-color-secondarycontainer); transition: all 0.2s; &:hover { - border-color: #07C05F; - background: #ffffff; + border-color: var(--td-brand-color); + background: var(--td-bg-color-container); } } @@ -554,7 +561,7 @@ onMounted(async () => { .model-name { font-size: 14px; font-weight: 500; - color: #333333; + color: var(--td-text-color-primary); margin-bottom: 4px; font-family: monospace; } @@ -563,7 +570,7 @@ onMounted(async () => { display: flex; gap: 12px; font-size: 12px; - color: #666666; + color: var(--td-text-color-secondary); } } @@ -579,7 +586,7 @@ onMounted(async () => { .download-progress { padding: 12px; - background: #f5f7fa; + background: var(--td-bg-color-component); border-radius: 6px; .progress-info { @@ -587,14 +594,14 @@ onMounted(async () => { justify-content: space-between; margin-bottom: 8px; font-size: 13px; - color: #333333; + color: var(--td-text-color-primary); } } .recommended-models { .recommended-label { font-size: 13px; - color: #666666; + color: var(--td-text-color-secondary); margin: 0 0 10px 0; font-weight: 500; } @@ -610,9 +617,9 @@ onMounted(async () => { font-size: 12px; &:hover { - background: #07C05F; - color: #ffffff; - border-color: #07C05F; + background: var(--td-brand-color); + color: var(--td-text-color-anti); + border-color: var(--td-brand-color); } } } @@ -625,7 +632,7 @@ onMounted(async () => { .empty-text { font-size: 14px; - color: #999999; + color: var(--td-text-color-placeholder); margin: 0; } } diff --git a/frontend/src/views/settings/Settings.vue b/frontend/src/views/settings/Settings.vue index fe511672..f706310e 100644 --- a/frontend/src/views/settings/Settings.vue +++ b/frontend/src/views/settings/Settings.vue @@ -59,32 +59,32 @@
-
+
-
+
-
+
-
+
-
+
-
+
@@ -179,6 +179,27 @@ const handleClose = () => { } } +// 监听初始导航设置 +watch(() => uiStore.settingsInitialSection, (section) => { + if (section && visible.value) { + currentSection.value = section + if (uiStore.settingsInitialSubSection) { + currentSubSection.value = uiStore.settingsInitialSubSection + // 展开对应的父菜单 + if (!expandedMenus.value.includes(section)) { + expandedMenus.value.push(section) + } + // 滚动到对应区域 + setTimeout(() => { + const element = document.querySelector(`[data-model-type="${uiStore.settingsInitialSubSection}"]`) + if (element) { + element.scrollIntoView({ behavior: 'smooth', block: 'start' }) + } + }, 300) + } + } +}, { immediate: true }) + // ESC 键关闭 const handleEscape = (e: KeyboardEvent) => { if (e.key === 'Escape' && visible.value) { @@ -221,7 +242,7 @@ onUnmounted(() => { .settings-overlay { position: fixed; inset: 0; - z-index: 999; + z-index: 1000; background: transparent; display: flex; align-items: center; @@ -235,9 +256,9 @@ onUnmounted(() => { width: 100%; max-width: 900px; height: 700px; - background: #ffffff; + background: var(--td-bg-color-container); border-radius: 12px; - box-shadow: 0 6px 28px rgba(15, 23, 42, 0.08); + box-shadow: var(--td-shadow-3); overflow: hidden; display: flex; flex-direction: column; @@ -252,7 +273,7 @@ onUnmounted(() => { height: 32px; border: none; background: transparent; - color: #666666; + color: var(--td-text-color-secondary); cursor: pointer; border-radius: 6px; display: flex; @@ -262,8 +283,8 @@ onUnmounted(() => { z-index: 10; &:hover { - background: #f5f5f5; - color: #333333; + background: var(--td-bg-color-container-hover); + color: var(--td-text-color-primary); } } @@ -277,8 +298,8 @@ onUnmounted(() => { /* 左侧导航栏 */ .settings-sidebar { width: 220px; - background-color: #f8f9fa; - border-right: 1px solid #e5e7eb; + background-color: var(--td-bg-color-secondarycontainer); + border-right: 1px solid var(--td-component-border); flex-shrink: 0; overflow-y: auto; display: flex; @@ -287,13 +308,13 @@ onUnmounted(() => { .sidebar-header { padding: 24px 16px 16px; - border-bottom: 1px solid #e5e7eb; + border-bottom: 1px solid var(--td-component-border); } .sidebar-title { font-size: 18px; font-weight: 600; - color: #333333; + color: var(--td-text-color-primary); margin: 0; } @@ -309,19 +330,19 @@ onUnmounted(() => { margin-bottom: 4px; border-radius: 6px; cursor: pointer; - color: #666666; + color: var(--td-text-color-secondary); font-size: 14px; transition: all 0.2s ease; user-select: none; &:hover { - background-color: #e8f5ed; - color: #333333; + background-color: var(--td-bg-color-container-hover); + color: var(--td-text-color-primary); } &.active { - background-color: rgba(7, 192, 95, 0.1); - color: #07C05F; + background-color: var(--td-brand-color-light); + color: var(--td-brand-color); font-weight: 500; } } @@ -358,19 +379,19 @@ onUnmounted(() => { margin-bottom: 2px; border-radius: 4px; cursor: pointer; - color: #666666; + color: var(--td-text-color-secondary); font-size: 13px; transition: all 0.2s ease; user-select: none; &:hover { - background-color: #f5f7fa; - color: #333333; + background-color: var(--td-bg-color-component-hover); + color: var(--td-text-color-primary); } &.active { - background-color: rgba(7, 192, 95, 0.08); - color: #07C05F; + background-color: var(--td-brand-color-light); + color: var(--td-brand-color); font-weight: 500; } } @@ -409,7 +430,7 @@ onUnmounted(() => { .settings-content { flex: 1; overflow-y: auto; - background-color: #ffffff; + background-color: var(--td-bg-color-container); } .content-wrapper { @@ -461,29 +482,29 @@ onUnmounted(() => { } .settings-sidebar::-webkit-scrollbar-track { - background: #f8f9fa; + background: var(--td-bg-color-secondarycontainer); } .settings-sidebar::-webkit-scrollbar-thumb { - background: #d0d0d0; + background: var(--td-bg-color-component); border-radius: 3px; } .settings-sidebar::-webkit-scrollbar-thumb:hover { - background: #b0b0b0; + background: var(--td-bg-color-component-hover); } .settings-content::-webkit-scrollbar-track { - background: #ffffff; + background: var(--td-bg-color-container); } .settings-content::-webkit-scrollbar-thumb { - background: #d0d0d0; + background: var(--td-bg-color-component); border-radius: 3px; } .settings-content::-webkit-scrollbar-thumb:hover { - background: #b0b0b0; + background: var(--td-bg-color-component-hover); } diff --git a/frontend/src/views/settings/SystemInfo.vue b/frontend/src/views/settings/SystemInfo.vue index 258e9b96..0b4878f7 100644 --- a/frontend/src/views/settings/SystemInfo.vue +++ b/frontend/src/views/settings/SystemInfo.vue @@ -411,13 +411,13 @@ onMounted(() => { h2 { font-size: 20px; font-weight: 600; - color: #333333; + color: var(--td-text-color-primary); margin: 0 0 8px 0; } .section-description { font-size: 14px; - color: #666666; + color: var(--td-text-color-secondary); margin: 0; line-height: 1.5; } @@ -429,7 +429,7 @@ onMounted(() => { gap: 12px; padding: 40px 0; justify-content: center; - color: #666666; + color: var(--td-text-color-secondary); font-size: 14px; } @@ -448,7 +448,7 @@ onMounted(() => { align-items: flex-start; justify-content: space-between; padding: 20px 0; - border-bottom: 1px solid #e5e7eb; + border-bottom: 1px solid var(--td-component-border); &:last-child { border-bottom: none; @@ -463,14 +463,14 @@ onMounted(() => { label { font-size: 15px; font-weight: 500; - color: #333333; + color: var(--td-text-color-primary); display: block; margin-bottom: 4px; } .desc { font-size: 13px; - color: #666666; + color: var(--td-text-color-secondary); margin: 0; line-height: 1.5; } @@ -485,12 +485,12 @@ onMounted(() => { .info-value { font-size: 14px; - color: #333333; + color: var(--td-text-color-primary); text-align: right; word-break: break-word; .commit-info { - color: #999999; + color: var(--td-text-color-placeholder); font-size: 12px; margin-left: 6px; } @@ -512,8 +512,8 @@ onMounted(() => { .usage-text { font-size: 14px; - font-weight: 500; - color: #333333; + font-weight: 500; + color: var(--td-text-color-primary); min-width: 50px; text-align: right; } @@ -522,7 +522,7 @@ onMounted(() => { .info-section-title { font-size: 14px; font-weight: 600; - color: #333333; + color: var(--td-text-color-primary); margin-top: 24px; margin-bottom: 12px; diff --git a/internal/handler/initialization.go b/internal/handler/initialization.go index a78bef0c..22471df3 100644 --- a/internal/handler/initialization.go +++ b/internal/handler/initialization.go @@ -83,6 +83,49 @@ func NewInitializationHandler( } } +// KBModelConfigRequest 知识库模型配置请求(简化版,只传模型ID) +type KBModelConfigRequest struct { + LLMModelID string `json:"llmModelId" binding:"required"` + EmbeddingModelID string `json:"embeddingModelId" binding:"required"` + RerankModelID string `json:"rerankModelId"` // 可选 + VLLMModelID string `json:"vllmModelId"` // 可选 + + // 文档分块配置 + DocumentSplitting struct { + ChunkSize int `json:"chunkSize"` + ChunkOverlap int `json:"chunkOverlap"` + Separators []string `json:"separators"` + } `json:"documentSplitting"` + + // 多模态配置 + Multimodal struct { + Enabled bool `json:"enabled"` + StorageType string `json:"storageType"` // "cos" or "minio" + COS *struct { + SecretID string `json:"secretId"` + SecretKey string `json:"secretKey"` + Region string `json:"region"` + BucketName string `json:"bucketName"` + AppID string `json:"appId"` + PathPrefix string `json:"pathPrefix"` + } `json:"cos"` + Minio *struct { + BucketName string `json:"bucketName"` + UseSSL bool `json:"useSSL"` + PathPrefix string `json:"pathPrefix"` + } `json:"minio"` + } `json:"multimodal"` + + // 知识图谱配置 + NodeExtract struct { + Enabled bool `json:"enabled"` + Text string `json:"text"` + Tags []string `json:"tags"` + Nodes []types.GraphNode `json:"nodes"` + Relations []types.GraphRelation `json:"relations"` + } `json:"nodeExtract"` +} + // InitializationRequest 初始化请求结构 type InitializationRequest struct { LLM struct { @@ -152,6 +195,164 @@ type InitializationRequest struct { } `json:"nodeExtract"` } +// UpdateKBConfig 根据知识库ID和模型ID更新配置(简化版) +func (h *InitializationHandler) UpdateKBConfig(c *gin.Context) { + ctx := c.Request.Context() + kbIdStr := c.Param("kbId") + + var req KBModelConfigRequest + if err := c.ShouldBindJSON(&req); err != nil { + logger.Error(ctx, "Failed to parse KB config request", err) + c.Error(errors.NewBadRequestError(err.Error())) + return + } + logger.Infof(ctx, "Starting KB configuration update with model IDs, kbId: %s", kbIdStr) + + // 获取知识库信息 + kb, err := h.kbService.GetKnowledgeBaseByID(ctx, kbIdStr) + if err != nil || kb == nil { + logger.ErrorWithFields(ctx, err, map[string]interface{}{"kbId": kbIdStr}) + c.Error(errors.NewNotFoundError("知识库不存在")) + return + } + + // 检查Embedding模型是否可以修改 + if kb.EmbeddingModelID != "" && kb.EmbeddingModelID != req.EmbeddingModelID { + // 检查是否已有文件 + knowledgeList, err := h.knowledgeService.ListPagedKnowledgeByKnowledgeBaseID(ctx, + kbIdStr, &types.Pagination{ + Page: 1, + PageSize: 1, + }) + if err == nil && knowledgeList != nil && knowledgeList.Total > 0 { + logger.Error(ctx, "Cannot change embedding model when files exist") + c.Error(errors.NewBadRequestError("知识库中已有文件,无法修改Embedding模型")) + return + } + } + + // 从数据库获取模型详情并验证 + llmModel, err := h.modelService.GetModelByID(ctx, req.LLMModelID) + if err != nil || llmModel == nil { + logger.Error(ctx, "LLM model not found", "modelId", req.LLMModelID) + c.Error(errors.NewBadRequestError("LLM模型不存在")) + return + } + + embeddingModel, err := h.modelService.GetModelByID(ctx, req.EmbeddingModelID) + if err != nil || embeddingModel == nil { + logger.Error(ctx, "Embedding model not found", "modelId", req.EmbeddingModelID) + c.Error(errors.NewBadRequestError("Embedding模型不存在")) + return + } + + // 更新知识库的模型ID + kb.SummaryModelID = req.LLMModelID + kb.EmbeddingModelID = req.EmbeddingModelID + + // 处理可选的Rerank模型 + if req.RerankModelID != "" { + rerankModel, err := h.modelService.GetModelByID(ctx, req.RerankModelID) + if err != nil || rerankModel == nil { + logger.Warn(ctx, "Rerank model not found", "modelId", req.RerankModelID) + } else { + kb.RerankModelID = req.RerankModelID + } + } else { + kb.RerankModelID = "" + } + + // 处理可选的VLLM模型 + if req.VLLMModelID != "" { + vllmModel, err := h.modelService.GetModelByID(ctx, req.VLLMModelID) + if err != nil || vllmModel == nil { + logger.Warn(ctx, "VLLM model not found", "modelId", req.VLLMModelID) + } else { + // 只存储模型ID + kb.VLMModelID = req.VLLMModelID + } + } else { + kb.VLMModelID = "" + } + + // 更新文档分块配置 + if req.DocumentSplitting.ChunkSize > 0 { + kb.ChunkingConfig.ChunkSize = req.DocumentSplitting.ChunkSize + } + if req.DocumentSplitting.ChunkOverlap >= 0 { + kb.ChunkingConfig.ChunkOverlap = req.DocumentSplitting.ChunkOverlap + } + if len(req.DocumentSplitting.Separators) > 0 { + kb.ChunkingConfig.Separators = req.DocumentSplitting.Separators + } + + // 更新多模态配置 + if req.Multimodal.Enabled { + switch strings.ToLower(req.Multimodal.StorageType) { + case "cos": + if req.Multimodal.COS != nil { + kb.StorageConfig = types.StorageConfig{ + SecretID: req.Multimodal.COS.SecretID, + SecretKey: req.Multimodal.COS.SecretKey, + Region: req.Multimodal.COS.Region, + BucketName: req.Multimodal.COS.BucketName, + AppID: req.Multimodal.COS.AppID, + PathPrefix: req.Multimodal.COS.PathPrefix, + Provider: "cos", + } + } + case "minio": + if req.Multimodal.Minio != nil { + kb.StorageConfig = types.StorageConfig{ + BucketName: req.Multimodal.Minio.BucketName, + PathPrefix: req.Multimodal.Minio.PathPrefix, + Provider: "minio", + SecretID: os.Getenv("MINIO_ACCESS_KEY_ID"), + SecretKey: os.Getenv("MINIO_SECRET_ACCESS_KEY"), + } + } + } + } else { + // 多模态未启用时,清空存储配置 + kb.StorageConfig = types.StorageConfig{} + } + + // 更新知识图谱配置 + if req.NodeExtract.Enabled { + // 转换 Nodes 和 Relations 为指针类型 + nodes := make([]*types.GraphNode, len(req.NodeExtract.Nodes)) + for i := range req.NodeExtract.Nodes { + nodes[i] = &req.NodeExtract.Nodes[i] + } + relations := make([]*types.GraphRelation, len(req.NodeExtract.Relations)) + for i := range req.NodeExtract.Relations { + relations[i] = &req.NodeExtract.Relations[i] + } + + kb.ExtractConfig = &types.ExtractConfig{ + Text: req.NodeExtract.Text, + Tags: req.NodeExtract.Tags, + Nodes: nodes, + Relations: relations, + } + } else { + kb.ExtractConfig = nil + } + + // 保存更新后的知识库 + if err := h.kbRepository.UpdateKnowledgeBase(ctx, kb); err != nil { + logger.Error(ctx, "Failed to update knowledge base", err) + c.Error(errors.NewInternalServerError("更新知识库失败: " + err.Error())) + return + } + + logger.Info(ctx, "KB configuration updated successfully", "kbId", kbIdStr) + c.JSON(http.StatusOK, gin.H{ + "success": true, + "message": "配置更新成功", + }) +} + // InitializeByKB 根据知识库ID执行配置更新 func (h *InitializationHandler) InitializeByKB(c *gin.Context) { ctx := c.Request.Context() @@ -989,19 +1190,22 @@ func (h *InitializationHandler) buildConfigResponse(ctx context.Context, models } multimodal := config["multimodal"].(map[string]interface{}) multimodal["vlm"] = map[string]interface{}{ - "modelName": model.Name, - "baseUrl": model.Parameters.BaseURL, - "apiKey": model.Parameters.APIKey, - "interfaceType": kb.VLMConfig.InterfaceType, + "modelName": model.Name, + "baseUrl": model.Parameters.BaseURL, + "apiKey": model.Parameters.APIKey, } } } - // 如果没有VLM模型,设置multimodal为disabled + // 判断多模态是否启用:有VLM模型ID或有存储配置 + hasMultimodal := (kb.VLMModelID != "" || kb.StorageConfig.SecretID != "" || kb.StorageConfig.BucketName != "") if config["multimodal"] == nil { config["multimodal"] = map[string]interface{}{ - "enabled": false, + "enabled": hasMultimodal, } + } else { + // 如果已经设置过 multimodal,更新 enabled 状态 + config["multimodal"].(map[string]interface{})["enabled"] = hasMultimodal } // 如果没有Rerank模型,设置rerank为disabled diff --git a/internal/handler/tenant.go b/internal/handler/tenant.go index 8516c9b3..d5b92432 100644 --- a/internal/handler/tenant.go +++ b/internal/handler/tenant.go @@ -334,7 +334,7 @@ func (h *TenantHandler) UpdateTenantAgentConfig(c *gin.Context) { // Validate configuration if req.Enabled { - if req.MaxIterations <= 0 || req.MaxIterations > 20 { + if req.MaxIterations <= 0 || req.MaxIterations > 30 { c.Error(errors.NewAgentInvalidMaxIterationsError()) return } diff --git a/internal/router/router.go b/internal/router/router.go index 35754c63..0365b95f 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -264,6 +264,7 @@ func RegisterInitializationRoutes(r *gin.RouterGroup, handler *handler.Initializ // 初始化接口 r.GET("/initialization/config/:kbId", handler.GetCurrentConfigByKB) r.POST("/initialization/initialize/:kbId", handler.InitializeByKB) + r.PUT("/initialization/config/:kbId", handler.UpdateKBConfig) // 新的简化版接口,只传模型ID // Ollama相关接口 r.GET("/initialization/ollama/status", handler.CheckOllamaStatus)