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) => { }