From ce67ba0310888a16372f65ff43aec63923e9423c Mon Sep 17 00:00:00 2001 From: wizardchen Date: Mon, 18 May 2026 00:47:10 +0800 Subject: [PATCH] refactor(InputField): clean up computed properties and improve agent selection logic Refactored the Input-field.vue component to enhance the clarity and maintainability of computed properties related to selected items. Improved the logic for handling agent configurations and user-selected files, ensuring a more streamlined approach to displaying knowledge bases and files. Additionally, adjusted the handling of disabled agents to ensure proper fallback selection when necessary. Refs: #1303 --- frontend/src/components/Input-field.vue | 718 +++++++++++------------- frontend/src/views/agent/AgentList.vue | 19 +- 2 files changed, 342 insertions(+), 395 deletions(-) diff --git a/frontend/src/components/Input-field.vue b/frontend/src/components/Input-field.vue index 54342501..20fd2f03 100644 --- a/frontend/src/components/Input-field.vue +++ b/frontend/src/components/Input-field.vue @@ -447,49 +447,49 @@ const selectedFiles = computed(() => { }); }); - // 合并所有选中项(用于输入框内显示) - // 现在智能体配置的知识库也在 store 中,统一从 selectedKbs 获取 - const allSelectedItems = computed(() => { - // 获取智能体预配置的知识库 IDs(用于标记和排序) - const agentKbIds = agentKnowledgeBases.value; - - // 所有选中的知识库,标记是否为智能体配置 - const allKbs = selectedKbs.value.map(kb => ({ - ...kb, - type: 'kb' as const, - kbType: kb.type, - isAgentConfigured: agentKbIds.includes(kb.id) - })); - - // 用户选择的文件(根据 fileIdToKbId + 共享列表/共享智能体补全 org_name,用于角标) - const sharedKbOrgMap: Record = {}; - (orgStore.sharedKnowledgeBases || []).forEach((s: any) => { - if (s.knowledge_base?.id != null && s.org_name) { - sharedKbOrgMap[String(s.knowledge_base.id)] = s.org_name; - } - }); - if (sharedAgentOrgName.value) { - (sharedAgentKbList.value || []).forEach((kb) => { - sharedKbOrgMap[String(kb.id)] = sharedAgentOrgName.value; - }); +// 合并所有选中项(用于输入框内显示) +// 现在智能体配置的知识库也在 store 中,统一从 selectedKbs 获取 +const allSelectedItems = computed(() => { + // 获取智能体预配置的知识库 IDs(用于标记和排序) + const agentKbIds = agentKnowledgeBases.value; + + // 所有选中的知识库,标记是否为智能体配置 + const allKbs = selectedKbs.value.map(kb => ({ + ...kb, + type: 'kb' as const, + kbType: kb.type, + isAgentConfigured: agentKbIds.includes(kb.id) + })); + + // 用户选择的文件(根据 fileIdToKbId + 共享列表/共享智能体补全 org_name,用于角标) + const sharedKbOrgMap: Record = {}; + (orgStore.sharedKnowledgeBases || []).forEach((s: any) => { + if (s.knowledge_base?.id != null && s.org_name) { + sharedKbOrgMap[String(s.knowledge_base.id)] = s.org_name; } - const files = selectedFiles.value.map((f: { id: string; name: string }) => { - const kbId = fileIdToKbId.value[f.id]; - const org_name = kbId ? sharedKbOrgMap[String(kbId)] || '' : ''; - return { - ...f, - type: 'file' as const, - isAgentConfigured: false, - org_name - }; - }); - - // 智能体配置的放在前面 - const agentConfiguredKbs = allKbs.filter(kb => kb.isAgentConfigured); - const userSelectedKbs = allKbs.filter(kb => !kb.isAgentConfigured); - - return [...agentConfiguredKbs, ...userSelectedKbs, ...files]; }); + if (sharedAgentOrgName.value) { + (sharedAgentKbList.value || []).forEach((kb) => { + sharedKbOrgMap[String(kb.id)] = sharedAgentOrgName.value; + }); + } + const files = selectedFiles.value.map((f: { id: string; name: string }) => { + const kbId = fileIdToKbId.value[f.id]; + const org_name = kbId ? sharedKbOrgMap[String(kbId)] || '' : ''; + return { + ...f, + type: 'file' as const, + isAgentConfigured: false, + org_name + }; + }); + + // 智能体配置的放在前面 + const agentConfiguredKbs = allKbs.filter(kb => kb.isAgentConfigured); + const userSelectedKbs = allKbs.filter(kb => !kb.isAgentConfigured); + + return [...agentConfiguredKbs, ...userSelectedKbs, ...files]; +}); // 移除选中项(智能体配置的项也可以移除) const removeSelectedItem = (item: { id: string; type: 'kb' | 'file'; isAgentConfigured?: boolean }) => { @@ -526,10 +526,10 @@ const inputPlaceholder = computed(() => { } return t('input.placeholderAgent', { name: selectedAgent.value.name }); } - + const hasKnowledge = allSelectedItems.value.length > 0; const hasWebSearch = isWebSearchEnabled.value && isWebSearchConfigured.value; - + if (hasKnowledge && hasWebSearch) { // 有知识库 + 有网络搜索 return t('input.placeholderKbAndWeb'); @@ -560,7 +560,7 @@ const loadKnowledgeBases = async () => { knowledgeBases.value = validKbs; // 拉取共享知识库(供 @ 提及与清理选中项时识别) - await orgStore.fetchSharedKnowledgeBases().catch(() => {}); + await orgStore.fetchSharedKnowledgeBases().catch(() => { }); // 清理无效的知识库ID:只移除既不在自己列表、也不在组织共享、也不在共享智能体知识库中的 ID(刷新后保留共享智能体下已选知识库) const validKbIds = new Set(validKbs.map((kb: any) => kb.id)); @@ -682,11 +682,43 @@ const loadAgents = async () => { const res = agentsRes as { data?: CustomAgent[]; disabled_own_agent_ids?: string[] } agents.value = res.data || [] disabledOwnAgentIds.value = res.disabled_own_agent_ids || [] + ensureSelectedAgentNotDisabled() } catch (error) { console.error('Failed to load agents:', error) } } +// 默认选中的 builtin(builtin-quick-answer)也可能被当前租户管理员停用。 +// 列表加载完后做一次纠偏:若当前选中的是本租户停用的 agent(仅限「我的/builtin」, +// 共享智能体由源租户决定,本地停用列表不适用),按 智能推理 → 快速问答 → +// 第一个可用 的顺序兜底切换。全部都被停用时保持原选择不动(极端场景,UI 仍会 +// 在 enabledAgents 过滤后显示空,由用户在智能体页恢复任意一个)。 +const ensureSelectedAgentNotDisabled = () => { + if (settingsStore.selectedAgentSourceTenantId) return + const currentId = settingsStore.selectedAgentId || BUILTIN_QUICK_ANSWER_ID + if (!disabledOwnAgentIds.value.includes(currentId)) return + + const isEnabled = (id: string) => + agents.value.some(a => a.id === id) && !disabledOwnAgentIds.value.includes(id) + + let fallback: CustomAgent | undefined + if (isEnabled(BUILTIN_SMART_REASONING_ID)) { + fallback = agents.value.find(a => a.id === BUILTIN_SMART_REASONING_ID) + } else if (isEnabled(BUILTIN_QUICK_ANSWER_ID)) { + fallback = agents.value.find(a => a.id === BUILTIN_QUICK_ANSWER_ID) + } else { + fallback = agents.value.find(a => !disabledOwnAgentIds.value.includes(a.id)) + } + if (!fallback) return + + settingsStore.selectAgent(fallback.id) + // selectAgent 内部仅对两个 builtin 常量自动切 isAgentEnabled;自定义 agent 兜底时 + // 需要按其 agent_mode 显式同步一次,保证模式徽标与对话行为一致。 + if (fallback.id !== BUILTIN_QUICK_ANSWER_ID && fallback.id !== BUILTIN_SMART_REASONING_ID) { + settingsStore.toggleAgent(fallback.config?.agent_mode === 'smart-reasoning') + } +} + // 对话下拉中展示的「我的」智能体(排除当前租户已停用的) const enabledAgents = computed(() => agents.value.filter(a => !disabledOwnAgentIds.value.includes(a.id)) @@ -853,7 +885,7 @@ const updateModelDropdownPosition = () => { }; return; } - + // 获取按钮相对于视口的位置 const rect = anchor.getBoundingClientRect(); console.log('[Model Dropdown] Button rect:', { @@ -864,16 +896,16 @@ const updateModelDropdownPosition = () => { width: rect.width, height: rect.height }); - + const dropdownWidth = 280; const offsetY = 8; const vw = window.innerWidth; const vh = window.innerHeight; - + // 左对齐到触发元素的左边缘 // 使用 Math.floor 而不是 Math.round,避免像素对齐问题 let left = Math.floor(rect.left); - + // 边界处理:不超出视口左右(留 16px margin) const minLeft = 16; const maxLeft = Math.max(16, vw - dropdownWidth - 16); @@ -886,16 +918,16 @@ const updateModelDropdownPosition = () => { const topMargin = 20; // 顶部留白 const spaceBelow = vh - rect.bottom; // 下方剩余空间 const spaceAbove = rect.top; // 上方剩余空间 - + console.log('[Model Dropdown] Space check:', { spaceBelow, spaceAbove, windowHeight: vh }); - + let actualHeight: number; let shouldOpenBelow: boolean; - + // 优先考虑下方空间 if (spaceBelow >= minDropdownHeight + offsetY) { // 下方有足够空间,向下弹出 @@ -915,7 +947,7 @@ const updateModelDropdownPosition = () => { shouldOpenBelow = false; console.log('[Model Dropdown] Position: above button', { actualHeight }); } - + // 根据弹出方向使用不同的定位方式 if (shouldOpenBelow) { // 向下弹出:使用 top 定位,左对齐 @@ -946,7 +978,7 @@ const updateModelDropdownPosition = () => { padding: '0 !important' }; } - + console.log('[Model Dropdown] Applied style:', modelDropdownStyle.value); }; @@ -954,11 +986,11 @@ const updateModelDropdownPosition = () => { let lastMentionQuery = ''; const loadMentionItems = async (q: string, resetIndex = true, append = false) => { console.log('[Mention] loadMentionItems called with query:', q, 'append:', append); - + if (!append) { mentionOffset.value = 0; } - + // 根据智能体的 kb_selection_mode 过滤知识库;选中共享智能体时使用该租户下的知识库,否则使用本租户 + 共享给自己的 let kbItems: any[] = []; if (!append) { @@ -1059,7 +1091,7 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) => orgName: kb.org_name || sharedAgentOrgName.value || undefined })); } - + // Fetch Files from API // 仅当满足以下两点才加载文件: // 1. 智能体确实会用到知识库(kb_selection_mode !== 'none'); @@ -1069,7 +1101,7 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) => const kbModeAllowsFiles = !hasAgentConfig.value || agentKBSelectionMode.value !== 'none'; const toolsAllowFiles = !hasAgentConfig.value || toolsConsumeFiles(agentAllowedTools.value); const shouldLoadFiles = kbModeAllowsFiles && toolsAllowFiles; - + if (shouldLoadFiles) { mentionLoading.value = true; try { @@ -1131,7 +1163,7 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) => } else { mentionHasMore.value = false; } - + if (append) { // Append file items to existing list mentionItems.value = [...mentionItems.value, ...fileItems]; @@ -1139,7 +1171,7 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) => mentionItems.value = [...kbItems, ...fileItems]; } console.log('[Mention] Total items:', mentionItems.value.length, { kbItems: kbItems.length, fileItems: fileItems.length }); - + // Only reset index if query changed or explicitly requested if (resetIndex || q !== lastMentionQuery) { mentionActiveIndex.value = 0; @@ -1174,18 +1206,18 @@ const onInput = (val: string | InputEvent) => { // TDesign t-textarea passes the value directly, not an event const inputVal = typeof val === 'string' ? val : query.value; - + const textarea = getTextareaEl(); if (!textarea) { console.warn('[Mention] Could not get textarea element'); return; } - + const cursor = textarea.selectionStart; const textBeforeCursor = inputVal.slice(0, cursor); - + console.log('[Mention] onInput called', { inputVal, cursor, textBeforeCursor, showMention: showMention.value }); - + if (showMention.value) { // 如果不是按钮触发的,检查 @ 符号 if (!isMentionTriggeredByButton.value) { @@ -1201,12 +1233,12 @@ const onInput = (val: string | InputEvent) => { showMention.value = false; return; } - + // Get query // 如果是按钮触发,mentionStartPos 是起始位置,不需要 +1 跳过 @ const start = isMentionTriggeredByButton.value ? mentionStartPos.value : mentionStartPos.value + 1; const q = inputVal.slice(start, cursor); - + if (q.includes(' ')) { showMention.value = false; return; @@ -1226,50 +1258,50 @@ const onInput = (val: string | InputEvent) => { if (isKnowledgeBaseLockedByAgent.value) { return; } - + console.log('[Mention] @ detected, opening menu'); isMentionTriggeredByButton.value = false; mentionStartPos.value = cursor - 1; showMention.value = true; mentionQuery.value = ""; - + const coords = getCaretCoordinates(textarea, cursor); const rect = textarea.getBoundingClientRect(); const scrollTop = textarea.scrollTop; const menuHeight = 320; // 预估最大高度 - + let left = rect.left + coords.left; // Prevent menu from going off-screen horizontally if (left + 300 > window.innerWidth) { left = window.innerWidth - 300 - 10; } - + // 光标相对于视口的实际 top 位置 const cursorAbsoluteTop = rect.top + coords.top - scrollTop; const lineHeight = coords.height; // 光标高度 // Check vertical space below cursor const spaceBelow = window.innerHeight - (cursorAbsoluteTop + lineHeight); - + if (spaceBelow < menuHeight && cursorAbsoluteTop > menuHeight) { - // Show above cursor (using bottom positioning) - // bottom distance = viewport height - cursor top position - const bottom = window.innerHeight - cursorAbsoluteTop; - mentionStyle.value = { - left: `${left}px`, - bottom: `${bottom}px`, - top: 'auto' - }; + // Show above cursor (using bottom positioning) + // bottom distance = viewport height - cursor top position + const bottom = window.innerHeight - cursorAbsoluteTop; + mentionStyle.value = { + left: `${left}px`, + bottom: `${bottom}px`, + top: 'auto' + }; } else { - // Show below cursor (using top positioning) - const top = cursorAbsoluteTop + lineHeight; - mentionStyle.value = { - left: `${left}px`, - top: `${top}px`, - bottom: 'auto' - }; + // Show below cursor (using top positioning) + const top = cursorAbsoluteTop + lineHeight; + mentionStyle.value = { + left: `${left}px`, + top: `${top}px`, + bottom: 'auto' + }; } - + loadMentionItems(""); } } @@ -1296,29 +1328,29 @@ const triggerMention = () => { MessagePlugin.warning(t(msgKey)); return; } - + const textarea = getTextareaEl(); if (!textarea) return; - + // 关闭其他选择器 showAgentModeSelector.value = false; showModelSelector.value = false; textarea.focus(); - + // 直接显示菜单,不插入 @ showMention.value = true; isMentionTriggeredByButton.value = true; mentionQuery.value = ""; mentionStartPos.value = textarea.selectionStart; - + const rect = textarea.getBoundingClientRect(); const menuHeight = 320; - + // 判断输入框上方空间 const spaceAbove = rect.top; const spaceBelow = window.innerHeight - rect.bottom; - + // 优先显示在上方,除非上方空间不足且下方空间充足 if (spaceAbove > menuHeight || spaceAbove > spaceBelow) { // Show above textarea @@ -1335,25 +1367,25 @@ const triggerMention = () => { bottom: 'auto' }; } - + loadMentionItems(""); }; const onMentionSelect = (item: any) => { if (item.type === 'kb') { - settingsStore.addKnowledgeBase(item.id); + settingsStore.addKnowledgeBase(item.id); } else if (item.type === 'file') { - settingsStore.addFile(item.id); - if (item.kbId) { - fileIdToKbId.value[item.id] = item.kbId; - settingsStore.setFileKbMap({ [item.id]: item.kbId }); - } - // Add to local cache immediately - if (!fileList.value.find(f => f.id === item.id)) { - fileList.value.push({ id: item.id, name: item.name }); - } + settingsStore.addFile(item.id); + if (item.kbId) { + fileIdToKbId.value[item.id] = item.kbId; + settingsStore.setFileKbMap({ [item.id]: item.kbId }); + } + // Add to local cache immediately + if (!fileList.value.find(f => f.id === item.id)) { + fileList.value.push({ id: item.id, name: item.name }); + } } - + const textarea = getTextareaEl(); if (textarea) { // 如果是通过输入 @ 触发的,需要删除 @ 和后面的查询文字 @@ -1362,7 +1394,7 @@ const onMentionSelect = (item: any) => { const textBeforeAt = query.value.slice(0, mentionStartPos.value); const textAfterCursor = query.value.slice(cursor); query.value = textBeforeAt + textAfterCursor; - + nextTick(() => { textarea.selectionStart = textarea.selectionEnd = mentionStartPos.value; textarea.focus(); @@ -1371,21 +1403,21 @@ const onMentionSelect = (item: any) => { // 通过按钮触发的,如果用户输入了查询词,需要删除查询词 const cursor = textarea.selectionStart; if (cursor > mentionStartPos.value) { - const textBeforeStart = query.value.slice(0, mentionStartPos.value); - const textAfterCursor = query.value.slice(cursor); - query.value = textBeforeStart + textAfterCursor; - - nextTick(() => { - textarea.selectionStart = textarea.selectionEnd = mentionStartPos.value; - textarea.focus(); - }); + const textBeforeStart = query.value.slice(0, mentionStartPos.value); + const textAfterCursor = query.value.slice(cursor); + query.value = textBeforeStart + textAfterCursor; + + nextTick(() => { + textarea.selectionStart = textarea.selectionEnd = mentionStartPos.value; + textarea.focus(); + }); } else { - // 直接聚焦 - textarea.focus(); + // 直接聚焦 + textarea.focus(); } } } - + showMention.value = false; }; @@ -1400,7 +1432,7 @@ const toggleModelSelector = () => { MessagePlugin.warning(t('input.modelLockedByAgent')); return; } - + // 互斥:关闭其他 showMention.value = false; showAgentModeSelector.value = false; @@ -1463,7 +1495,7 @@ onMounted(() => { }); fileIdToKbId.value = next; } - + // 如果从知识库内部进入,自动选中该知识库 const kbId = (route.params as any)?.kbId as string; if (kbId && !selectedKbIds.value.includes(kbId)) { @@ -1483,7 +1515,7 @@ onMounted(() => { document.addEventListener('click', closeAgentModeSelector); document.addEventListener('click', closeModelSelector); document.addEventListener('click', closeMentionSelector); - + // 监听窗口大小变化和滚动,重新计算位置 resizeHandler = () => { if (showModelSelector.value) { @@ -1501,7 +1533,7 @@ onMounted(() => { updateAgentModeDropdownPosition(); } }; - + window.addEventListener('resize', resizeHandler, { passive: true }); window.addEventListener('scroll', scrollHandler, { passive: true, capture: true }); }); @@ -1579,28 +1611,28 @@ const createSession = async (val: string) => { })); const imageFiles = uploadedImages.value.map(img => img.file); const attachmentFiles = uploadedAttachments.value; - + // Blur the textarea BEFORE emitting, so that when the parent navigates away // and Vue unmounts this component, TDesign's blur handler won't fire on a // detached DOM element (which causes getComputedStyle to throw). const textarea = getTextareaEl(); if (textarea) textarea.blur(); emit('send-msg', val, selectedModelId.value, mentionedItems, imageFiles, attachmentFiles); - + // Clean up image previews uploadedImages.value.forEach(img => URL.revokeObjectURL(img.preview)); uploadedImages.value = []; - + // Clean up attachments attachmentUploadRef.value?.clear(); uploadedAttachments.value = []; - + clearvalue(); } const updateAgentModeDropdownPosition = () => { const anchor = agentModeButtonRef.value; - + if (!anchor) { agentModeDropdownStyle.value = { position: 'fixed', @@ -1616,13 +1648,13 @@ const updateAgentModeDropdownPosition = () => { const offsetY = 8; const vw = window.innerWidth; const vh = window.innerHeight; - + // 水平位置:左对齐 let left = Math.floor(rect.left); const minLeft = 16; const maxLeft = Math.max(16, vw - dropdownWidth - 16); left = Math.max(minLeft, Math.min(maxLeft, left)); - + // 垂直位置:紧贴按钮,使用合理的高度避免空白 const preferredDropdownHeight = 140; // Agent 模式选择器内容较少,用更小的优选高度 const maxDropdownHeight = 150; @@ -1630,21 +1662,21 @@ const updateAgentModeDropdownPosition = () => { const topMargin = 20; const spaceBelow = vh - rect.bottom; const spaceAbove = rect.top; - + console.log('[Agent Dropdown] Space check:', { spaceBelow, spaceAbove, windowHeight: vh }); - + let actualHeight: number; - + // 优先考虑下方空间 if (spaceBelow >= minDropdownHeight + offsetY) { // 下方有足够空间,向下弹出 actualHeight = Math.min(preferredDropdownHeight, spaceBelow - offsetY - 16); const top = Math.floor(rect.bottom + offsetY); - + agentModeDropdownStyle.value = { position: 'fixed !important', width: `${dropdownWidth}px`, @@ -1664,9 +1696,9 @@ const updateAgentModeDropdownPosition = () => { } else { actualHeight = Math.max(minDropdownHeight, availableHeight); } - + const bottom = vh - rect.top + offsetY; - + agentModeDropdownStyle.value = { position: 'fixed !important', width: `${dropdownWidth}px`, @@ -1706,7 +1738,7 @@ const toggleAgentModeSelector = () => { const selectAgentMode = (mode: 'quick-answer' | 'smart-reasoning') => { const builtinAgentId = mode === 'smart-reasoning' ? BUILTIN_SMART_REASONING_ID : BUILTIN_QUICK_ANSWER_ID; const builtinAgent = agents.value.find(a => a.id === builtinAgentId); - + if (builtinAgent) { const notReadyReasons = getBuiltinAgentNotReadyReasons(builtinAgent, mode === 'smart-reasoning'); if (notReadyReasons.length > 0) { @@ -1715,7 +1747,7 @@ const selectAgentMode = (mode: 'quick-answer' | 'smart-reasoning') => { return; } } - + const shouldEnableAgent = mode === 'smart-reasoning'; if (shouldEnableAgent !== isAgentEnabled.value) { settingsStore.toggleAgent(shouldEnableAgent); @@ -1730,24 +1762,24 @@ const selectAgentMode = (mode: 'quick-answer' | 'smart-reasoning') => { const handleSelectAgent = (agent: CustomAgent, sourceTenantId?: string) => { // 根据智能体的 agent_mode 判断是否为 Agent 模式 const isAgentType = agent.config?.agent_mode === 'smart-reasoning'; - + // 统一检查智能体是否就绪(内置和自定义智能体使用相同逻辑) - const actualAgent = agent.is_builtin + const actualAgent = agent.is_builtin ? (agents.value.find(a => a.id === agent.id) || agent) : agent; - + const notReadyReasons = agent.is_builtin ? getBuiltinAgentNotReadyReasons(actualAgent, isAgentType) : getCustomAgentNotReadyReasons(actualAgent); - + if (notReadyReasons.length > 0) { showAgentNotReadyMessage(agent, notReadyReasons); return; } - + settingsStore.selectAgent(agent.id, sourceTenantId); settingsStore.toggleAgent(!!isAgentType); - + // 同步智能体的配置状态(含内置、自定义、共享智能体):模型、网络搜索、知识库由 watch 同步 // 1. 同步网络搜索状态 const agentWebSearch = agent.config?.web_search_enabled; @@ -1756,7 +1788,7 @@ const handleSelectAgent = (agent: CustomAgent, sourceTenantId?: string) => { } else if (agent.is_builtin) { // 内置智能体未配置时保留当前用户设置 } - + // 2. 同步模型(选中的对话模型随智能体切换,含共享智能体) const agentModel = agent.config?.model_id; if (agentModel && agentModel.trim() !== '') { @@ -1767,10 +1799,10 @@ const handleSelectAgent = (agent: CustomAgent, sourceTenantId?: string) => { selectedModelId.value = lastPick; } } - + showAgentModeSelector.value = false; - - const message = agent.is_builtin + + const message = agent.is_builtin ? (isAgentType ? t('input.messages.agentSwitchedOn') : t('input.messages.agentSwitchedOff')) : t('input.messages.agentSelected', { name: agent.name }); MessagePlugin.success(message); @@ -1803,8 +1835,8 @@ const onKeydown = (val: string, event: { e: { preventDefault(): unknown; keyCode return; } if (event.e.keyCode === 27) { // Esc - showMention.value = false; - return; + showMention.value = false; + return; } } @@ -1882,9 +1914,9 @@ const handleGoToAgentSettings = (section?: string) => { const getBuiltinAgentNotReadyReasons = (agent: CustomAgent, isAgentMode: boolean): string[] => { const reasons: string[] = [] const config = agent.config || {} - + // 内置智能体会自动回退到租户的默认模型,因此不再在前端强制校验 model_id - + // 检查重排模型(Rerank Model)- 仅当允许使用 knowledge_search 工具时需要 // 内置智能体允许重排模型为空(使用默认配置) // const hasKnowledgeSearchTool = config.allowed_tools && config.allowed_tools.includes('knowledge_search') @@ -1893,14 +1925,14 @@ const getBuiltinAgentNotReadyReasons = (agent: CustomAgent, isAgentMode: boolean // reasons.push(t('input.customAgentMissingRerankModel')) // } // } - + // Agent 模式还需要检查允许的工具 if (isAgentMode) { if (!config.allowed_tools || config.allowed_tools.length === 0) { reasons.push(t('input.agentMissingAllowedTools')) } } - + return reasons } @@ -1908,7 +1940,7 @@ const getBuiltinAgentNotReadyReasons = (agent: CustomAgent, isAgentMode: boolean const getCustomAgentNotReadyReasons = (agent: CustomAgent): string[] => { const reasons: string[] = [] const config = agent.config || {} - + // 检查对话模型(Summary Model) if (!config.model_id || config.model_id.trim() === '') { reasons.push(t('input.customAgentMissingSummaryModel')) @@ -1924,7 +1956,7 @@ const getCustomAgentNotReadyReasons = (agent: CustomAgent): 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: var(--td-text-color-primary); line-height: 1.5;' }, t('input.agentNotReadyDetail', { agentName: agent.name, reasons: reasonsText })), h('a', { @@ -1942,7 +1974,7 @@ const showAgentNotReadyMessage = (agent: CustomAgent, reasons: string[]) => { } }, t('input.goToAgentEditor')) ]); - + MessagePlugin.warning({ content: () => messageContent, duration: 5000 @@ -2005,18 +2037,18 @@ const handleStop = async () => { MessagePlugin.warning(t('input.messages.sessionMissing')); return; } - + if (!props.assistantMessageId) { console.error('[Stop] Assistant message ID is empty'); MessagePlugin.warning(t('input.messages.messageMissing')); return; } - + console.log('[Stop] Stopping generation for message:', props.assistantMessageId); - + // 发送 stop 事件,通知父组件立即清除 loading 状态 emit('stop-generation'); - + try { await stopSession(props.sessionId, props.assistantMessageId); MessagePlugin.success(t('input.messages.stopSuccess')); @@ -2043,126 +2075,79 @@ defineExpose({ -
- - - - - - +
+ + + + + +
@@ -2212,18 +2189,15 @@ defineExpose({
{{ $t('chat.imageUploadTooltip') }} -
+
- - - + + + {{ uploadedImages.length }}
@@ -2232,16 +2206,17 @@ defineExpose({ -
+
- - + + {{ uploadedAttachments.length }}
@@ -2254,46 +2229,37 @@ defineExpose({ {{ $t('input.kbDisabledByAgent') }} {{ $t('input.goToAgentSettings') }}
- {{ allSelectedItems.length > 0 ? $t('input.knowledgeBaseWithCount', { count: allSelectedItems.length }) : $t('input.knowledgeBase') }} + {{ allSelectedItems.length > 0 ? $t('input.knowledgeBaseWithCount', { + count: + allSelectedItems.length + }) : $t('input.knowledgeBase') }} -
- - - +
+ + + {{ allSelectedItems.length }}
- +
-
+
{{ selectedModelDisplayName }} - - + +
@@ -2302,22 +2268,17 @@ defineExpose({
-
+
{{ $t('conversationSettings.models.chatGroupLabel') }}
-
+
{{ model.name }} {{ $t('input.remote') }} @@ -2340,15 +2301,8 @@ defineExpose({
- -
+ +
@@ -2356,24 +2310,16 @@ defineExpose({ -
- +
+
- +
@@ -2403,7 +2349,7 @@ const getImgSrc = (url: string) => { border-radius: 12px; border: .5px solid var(--td-component-border, #E7E7E7); box-shadow: 0 6px 6px 0 rgba(0, 0, 0, 0.04), 0 12px 12px -1px rgba(0, 0, 0, 0.08); - + &:focus-within { border-color: var(--td-brand-color, #07C05F); } @@ -2418,7 +2364,8 @@ const getImgSrc = (url: string) => { padding: 6px 12px 6px; border-bottom: .5px solid var(--td-component-stroke, #e7e7e7); background: var(--td-bg-color-container, #fff); - border-radius: 11px 11px 0 0; /* 与 .rich-input-container 内缘上边圆角一致(12px - 1px 边框) */ + border-radius: 11px 11px 0 0; + /* 与 .rich-input-container 内缘上边圆角一致(12px - 1px 边框) */ } .mention-chip { @@ -2660,7 +2607,7 @@ const getImgSrc = (url: string) => { &.disabled { opacity: 0.5; cursor: not-allowed; - + &:hover { background: var(--td-bg-color-secondarycontainer, #f5f5f5); } @@ -2711,24 +2658,24 @@ const getImgSrc = (url: string) => { padding: 0 10px; min-width: auto; position: relative; - + &.active { background: rgba(16, 185, 129, 0.1); color: var(--td-brand-color); - + &:hover { background: rgba(16, 185, 129, 0.15); } } - + &.agent-controlled { cursor: not-allowed; opacity: 0.85; - + &:hover { background: var(--td-bg-color-secondarycontainer, #f5f5f5); } - + &.active:hover { background: rgba(16, 185, 129, 0.1); } @@ -2893,41 +2840,41 @@ const getImgSrc = (url: string) => { align-items: center; justify-content: center; position: relative; - + &.active { background: rgba(16, 185, 129, 0.1); - + .websearch-icon { color: var(--td-brand-color); } - + &:hover { background: rgba(16, 185, 129, 0.15); } } - + &:not(.active) { .websearch-icon { color: var(--td-text-color-secondary, #666); } - + &:hover { background: var(--td-bg-color-secondarycontainer-hover, #f0f0f0); - + .websearch-icon { color: var(--td-text-color-primary, #333); } } } - + &.agent-controlled { cursor: not-allowed; opacity: 0.85; - + &:hover { background: var(--td-bg-color-secondarycontainer, #f5f5f5); } - + &.active:hover { background: rgba(16, 185, 129, 0.1); } @@ -2970,7 +2917,7 @@ const getImgSrc = (url: string) => { height: 10px; margin-left: 2px; transition: transform 0.12s; - + &.rotate { transform: rotate(180deg); } @@ -2993,20 +2940,20 @@ const getImgSrc = (url: string) => { display: flex; align-items: center; justify-content: center; - + &:hover { background: rgba(16, 185, 129, 0.12); border-color: var(--td-brand-color); } - + &:active { background: rgba(16, 185, 129, 0.15); } - + svg { display: none; } - + &::before { content: ''; width: 12px; @@ -3019,10 +2966,13 @@ const getImgSrc = (url: string) => { } @keyframes stopBtnPulse { - 0%, 100% { + + 0%, + 100% { transform: scale(1); opacity: 1; } + 50% { transform: scale(0.75); opacity: 0.6; @@ -3034,15 +2984,15 @@ const getImgSrc = (url: string) => { height: 28px; padding: 0; background-color: var(--td-brand-color); - + &:hover:not(.disabled) { background-color: var(--td-brand-color-active); } - + &.disabled { background-color: var(--td-success-color-light); } - + img { width: 16px; height: 16px; @@ -3106,7 +3056,7 @@ const getImgSrc = (url: string) => { color: var(--td-text-color-placeholder, #999); flex-shrink: 0; transition: transform 0.12s; - + &.rotate { transform: rotate(180deg); } @@ -3173,13 +3123,13 @@ const getImgSrc = (url: string) => { font-weight: 500; cursor: pointer; transition: all 0.2s; - + .add-icon { font-size: 14px; line-height: 1; font-weight: 400; } - + &:hover { color: var(--td-brand-color-hover, #05a04f); background: var(--td-bg-color-secondarycontainer, #f3f3f3); @@ -3192,30 +3142,30 @@ const getImgSrc = (url: string) => { transition: background 0.12s; border-radius: 6px; margin-bottom: 4px; - + &:last-child { margin-bottom: 0; } - + &:hover { background: var(--td-bg-color-container-hover, #f6f8f7); } - + &.selected { background: var(--td-brand-color-light, #eefdf5); - + .model-option-name { color: var(--td-success-color); font-weight: 600; } } - + &.empty { color: var(--td-text-color-disabled, #9aa0a6); cursor: default; text-align: center; padding: 20px 8px; - + &:hover { background: transparent; } @@ -3304,23 +3254,23 @@ const getImgSrc = (url: string) => { border-radius: 6px; position: relative; margin: 4px 6px; - + &:hover:not(.disabled) { background: var(--td-bg-color-container-hover, #f6f8f7); } - + &.disabled { opacity: 0.6; cursor: not-allowed; - + &:hover { background: transparent; } } - + &.selected { background: var(--td-brand-color-light, #eefdf5); - + .agent-mode-option-name { color: var(--td-success-color); font-weight: 700; @@ -3362,7 +3312,7 @@ const getImgSrc = (url: string) => { display: flex; align-items: center; margin-left: 6px; - + .warning-icon { color: var(--td-warning-color); font-size: 14px; @@ -3385,12 +3335,10 @@ const getImgSrc = (url: string) => { align-items: center; gap: 3px; transition: all 0.12s; - + &:hover { color: var(--td-brand-color-active); text-decoration: underline; } } - - diff --git a/frontend/src/views/agent/AgentList.vue b/frontend/src/views/agent/AgentList.vue index 6bc604ab..d8567ca1 100644 --- a/frontend/src/views/agent/AgentList.vue +++ b/frontend/src/views/agent/AgentList.vue @@ -135,7 +135,7 @@ {{ agent.name }}
@@ -150,7 +150,7 @@ -