From 8c5263aef9522282d33472a4e12e6c410193bcf8 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Wed, 31 Dec 2025 19:14:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=BB=9F=E4=B8=80=E6=99=BA?= =?UTF-8?q?=E8=83=BD=E4=BD=93=E6=9C=AA=E5=B0=B1=E7=BB=AA=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/Input-field.vue | 72 ++++++------------------- frontend/src/i18n/locales/en-US.ts | 1 + frontend/src/i18n/locales/zh-CN.ts | 1 + 3 files changed, 17 insertions(+), 57 deletions(-) diff --git a/frontend/src/components/Input-field.vue b/frontend/src/components/Input-field.vue index 74b72726..aa35d644 100644 --- a/frontend/src/components/Input-field.vue +++ b/frontend/src/components/Input-field.vue @@ -1168,7 +1168,7 @@ const selectAgentMode = (mode: 'quick-answer' | 'smart-reasoning') => { if (builtinAgent) { const notReadyReasons = getBuiltinAgentNotReadyReasons(builtinAgent, mode === 'smart-reasoning'); if (notReadyReasons.length > 0) { - showBuiltinAgentNotReadyMessage(mode, notReadyReasons); + showAgentNotReadyMessage(builtinAgent, notReadyReasons); showAgentModeSelector.value = false; return; } @@ -1189,26 +1189,18 @@ const handleSelectAgent = (agent: CustomAgent) => { // 根据智能体的 agent_mode 判断是否为 Agent 模式 const isAgentType = agent.config?.agent_mode === 'smart-reasoning'; - // 内置智能体检查 - 从实际的智能体配置来判断 - if (agent.is_builtin) { - // 从 agents 列表中获取实际的内置智能体数据,如果没找到则使用传入的 agent (此时应该包含合并后的配置) - const builtinAgent = agents.value.find(a => a.id === agent.id) || agent; - if (builtinAgent) { - const notReadyReasons = getBuiltinAgentNotReadyReasons(builtinAgent, isAgentType); - if (notReadyReasons.length > 0) { - showBuiltinAgentNotReadyMessage(isAgentType ? 'smart-reasoning' : 'quick-answer', notReadyReasons); - return; - } - } - } + // 统一检查智能体是否就绪(内置和自定义智能体使用相同逻辑) + const actualAgent = agent.is_builtin + ? (agents.value.find(a => a.id === agent.id) || agent) + : agent; - // 自定义智能体检查 - if (!agent.is_builtin) { - const notReadyReasons = getCustomAgentNotReadyReasons(agent); - if (notReadyReasons.length > 0) { - showCustomAgentNotReadyMessage(agent, notReadyReasons); - return; - } + const notReadyReasons = agent.is_builtin + ? getBuiltinAgentNotReadyReasons(actualAgent, isAgentType) + : getCustomAgentNotReadyReasons(actualAgent); + + if (notReadyReasons.length > 0) { + showAgentNotReadyMessage(agent, notReadyReasons); + return; } selectedAgentId.value = agent.id; @@ -1363,17 +1355,16 @@ const getCustomAgentNotReadyReasons = (agent: CustomAgent): string[] => { return reasons } -// 显示自定义智能体未就绪的消息 -const showCustomAgentNotReadyMessage = (agent: CustomAgent, reasons: string[]) => { +// 显示智能体未就绪的消息(统一处理内置和自定义智能体) +const showAgentNotReadyMessage = (agent: CustomAgent, reasons: string[]) => { const reasonsText = reasons.join('、') const messageContent = h('div', { style: 'display: flex; flex-direction: column; gap: 8px; max-width: 320px;' }, [ - h('span', { style: 'color: #333; line-height: 1.5;' }, t('input.customAgentNotReadyDetail', { reasons: reasonsText })), + h('span', { style: 'color: #333; line-height: 1.5;' }, t('input.agentNotReadyDetail', { agentName: agent.name, reasons: reasonsText })), h('a', { href: '#', onClick: (e: Event) => { e.preventDefault(); - // 跳转到智能体编辑页面 router.push(`/platform/agents?edit=${agent.id}`); }, style: 'color: #07C05F; text-decoration: none; font-weight: 500; cursor: pointer; align-self: flex-start;', @@ -1392,39 +1383,6 @@ const showCustomAgentNotReadyMessage = (agent: CustomAgent, reasons: string[]) = }); } -// 显示内置智能体未就绪的消息 -const showBuiltinAgentNotReadyMessage = (mode: 'smart-reasoning' | 'quick-answer', reasons: string[]) => { - const agentName = mode === 'smart-reasoning' - ? t('input.builtinAgentSettingName') - : t('input.builtinNormalSettingName'); - const builtinAgentId = mode === 'smart-reasoning' ? BUILTIN_SMART_REASONING_ID : BUILTIN_QUICK_ANSWER_ID; - const reasonsText = reasons.join('、') - - const messageContent = h('div', { style: 'display: flex; flex-direction: column; gap: 8px; max-width: 320px;' }, [ - h('span', { style: 'color: #333; line-height: 1.5;' }, t('input.builtinAgentNotReadyDetail', { agentName, reasons: reasonsText })), - h('a', { - href: '#', - onClick: (e: Event) => { - e.preventDefault(); - // 跳转到内置智能体编辑页面 - router.push(`/platform/agents?edit=${builtinAgentId}`); - }, - style: 'color: #07C05F; text-decoration: none; font-weight: 500; cursor: pointer; align-self: flex-start;', - onMouseenter: (e: Event) => { - (e.target as HTMLElement).style.textDecoration = 'underline'; - }, - onMouseleave: (e: Event) => { - (e.target as HTMLElement).style.textDecoration = 'none'; - } - }, t('input.goToAgentEditor')) - ]); - - MessagePlugin.warning({ - content: () => messageContent, - duration: 5000 - }); -} - const toggleWebSearch = () => { // 互斥:虽然不是弹出层,但操作时关闭其他弹出层体验更好 showMention.value = false; diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 6ef98042..7bcb9055 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -961,6 +961,7 @@ export default { customAgentMissingSummaryModel: 'Chat Model (Summary Model)', customAgentMissingRerankModel: 'Rerank Model', goToAgentEditor: 'Go to configure →', + agentNotReadyDetail: 'Agent "{agentName}" is not ready. Please configure: {reasons}', builtinAgentNotReadyDetail: 'Built-in agent "{agentName}" is not ready. Please configure: {reasons}', builtinAgentSettingName: 'Intelligent Reasoning', builtinNormalSettingName: 'Quick Q&A', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 8bb5e616..e1bdd2be 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -1681,6 +1681,7 @@ export default { customAgentMissingSummaryModel: "对话模型(Summary Model)", customAgentMissingRerankModel: "重排模型(Rerank Model)", goToAgentEditor: "前往配置 →", + agentNotReadyDetail: "智能体「{agentName}」未就绪,需要配置以下内容:{reasons}", builtinAgentNotReadyDetail: "内置智能体「{agentName}」未就绪,需要配置以下内容:{reasons}", builtinAgentSettingName: "智能推理", builtinNormalSettingName: "快速问答",