From 122408b28393d917ce1e117ef4982ce2907cb542 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Wed, 24 Jun 2026 20:30:56 +0800 Subject: [PATCH] feat(chat): unify resource chips and browse recent files in @ mention Add recent=true to knowledge search so the mention picker can list recent files without a keyword, and consolidate KB/FAQ/file chip styling across chat input and message history. --- frontend/src/api/knowledge-base/index.ts | 7 +- frontend/src/components/Input-field.vue | 114 ++++++++---------- frontend/src/components/MentionSelector.vue | 111 +++++++++-------- .../components/css/chat-message-shared.less | 2 + .../components/css/chat-resource-chips.less | 64 ++++++++++ frontend/src/views/chat/components/botmsg.vue | 52 +------- .../src/views/chat/components/usermsg.vue | 54 +-------- internal/handler/knowledge.go | 14 ++- 8 files changed, 194 insertions(+), 224 deletions(-) create mode 100644 frontend/src/components/css/chat-resource-chips.less diff --git a/frontend/src/api/knowledge-base/index.ts b/frontend/src/api/knowledge-base/index.ts index 2c54e659..f4e33459 100644 --- a/frontend/src/api/knowledge-base/index.ts +++ b/frontend/src/api/knowledge-base/index.ts @@ -458,16 +458,19 @@ export function searchKnowledge( offset = 0, limit = 20, fileTypes?: string[], - options?: { agent_id?: string } + options?: { agent_id?: string; recent?: boolean } ) { const query = new URLSearchParams(); - query.set('keyword', keyword); + if (keyword) { + query.set('keyword', keyword); + } query.set('offset', String(offset)); query.set('limit', String(limit)); if (fileTypes && fileTypes.length > 0) { query.set('file_types', fileTypes.join(',')); } if (options?.agent_id) query.set('agent_id', options.agent_id); + if (options?.recent) query.set('recent', 'true'); return get(`/api/v1/knowledge/search?${query.toString()}`); } diff --git a/frontend/src/components/Input-field.vue b/frontend/src/components/Input-field.vue index eed09fa8..62c0de36 100644 --- a/frontend/src/components/Input-field.vue +++ b/frontend/src/components/Input-field.vue @@ -1099,16 +1099,19 @@ const loadMentionItems = async (q: string, resetIndex = true, append = false) => const toolsAllowFiles = !hasAgentConfig.value || toolsConsumeFiles(agentAllowedTools.value); const shouldLoadFiles = kbModeAllowsFiles && toolsAllowFiles; - // 后端 /knowledge/search 要求非空 keyword;打开 @ 面板时仅展示本地 KB 列表, - // 用户输入搜索词后再拉取文件结果。 + // 空关键词时显式请求最近文件;有关键词时返回匹配文件。 + // `recent=true` 只用于浏览态,避免其他搜索调用漏传关键词时静默退化为最近列表。 const fileSearchKeyword = q.trim(); - if (shouldLoadFiles && fileSearchKeyword) { + if (shouldLoadFiles) { mentionLoading.value = true; try { const fileTypesParam = agentSupportedFileTypes.value.length > 0 ? agentSupportedFileTypes.value : undefined; const sourceTenantId = settingsStore.selectedAgentSourceTenantId; const agentId = selectedAgentId.value; - const searchOptions = sourceTenantId && agentId ? { agent_id: agentId } : undefined; + const searchOptions = { + ...(sourceTenantId && agentId ? { agent_id: agentId } : {}), + recent: !fileSearchKeyword, + }; const res: any = await searchKnowledge( fileSearchKeyword, mentionOffset.value, @@ -2366,6 +2369,8 @@ const getImgSrc = (url: string) => { }