Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
fix(frontend): harden chat resources cache invalidation and dedup
wizardchen4de3c3efbd37
diff --git a/frontend/src/api/model/index.ts b/frontend/src/api/model/index.tsindex 9f68291db..bdddc5cb0 100644--- a/frontend/src/api/model/index.ts+++ b/frontend/src/api/model/index.ts@@ -80,7 +80,9 @@ export function listModels(type?: string): Promise<ModelConfig[]> {}).catch((error: any) => {console.error('Failed to list models:', error);- resolve([]);+ // 抛出而非吞掉:调用方(含缓存层)才能区分「真失败」与「成功但无模型」,+ // 避免把一次瞬时失败的空结果缓存下来。各 UI 调用点均已 try/catch 兜底。+ reject(error);});});}diff --git a/frontend/src/stores/chatResources.ts b/frontend/src/stores/chatResources.tsindex 1d58030c6..5881d4846 100644--- a/frontend/src/stores/chatResources.ts+++ b/frontend/src/stores/chatResources.ts@@ -34,6 +34,10 @@ export const useChatResourcesStore = defineStore('chatResources', () => {// 可能并发触发,缓存尚未写入时不去重会重复打 listKnowledgeBases / listAgents。let kbAllInflight: Promise<any[]> | null = nulllet agentsAllInflight: Promise<{ data: CustomAgent[]; disabled_own_agent_ids: string[] }> | null = null+ // 代际计数:force 与非 force 并发时句柄会被后来者覆盖,旧请求结束时凭此判断+ // 自己是否仍是最新的那次,避免误清正在飞行的句柄。+ let kbAllGen = 0+ let agentsAllGen = 0const agentKbCache = new Map<string, { at: number; data: any[] }>()const agentKbInflight = new Map<string, Promise<any[]>>()@@ -78,6 +82,7 @@ export const useChatResourcesStore = defineStore('chatResources', () => {}if (!force && kbAllInflight) return kbAllInflight+ const gen = ++kbAllGenkbAllInflight = (async () => {try {const res: any = await listKnowledgeBases()@@ -88,7 +93,7 @@ export const useChatResourcesStore = defineStore('chatResources', () => {await orgStore.fetchSharedKnowledgeBases({ force })return data} finally {- kbAllInflight = null+ if (kbAllGen === gen) kbAllInflight = null}})()return kbAllInflight@@ -123,6 +128,7 @@ export const useChatResourcesStore = defineStore('chatResources', () => {}if (!force && agentsAllInflight) return agentsAllInflight+ const gen = ++agentsAllGenagentsAllInflight = (async () => {try {const [agentsRes] = await Promise.all([@@ -136,7 +142,7 @@ export const useChatResourcesStore = defineStore('chatResources', () => {loadedAt.value.agents = Date.now()return { data, disabled_own_agent_ids: res.disabled_own_agent_ids || [] }} finally {- agentsAllInflight = null+ if (agentsAllGen === gen) agentsAllInflight = null}})()return agentsAllInflight@@ -249,6 +255,9 @@ export const useChatResourcesStore = defineStore('chatResources', () => {allModels.value = []webSearchProviders.value = []agentKbCache.clear()+ // 同时丢弃所有 inflight 句柄,否则失效后仍在飞行的请求会把旧数据写回缓存。+ inflight.clear()+ agentKbInflight.clear()kbAllInflight = nullagentsAllInflight = nullinvalidateKnowledgeBaseDetail()@@ -256,9 +265,11 @@ export const useChatResourcesStore = defineStore('chatResources', () => {}keys.forEach((k) => {delete loadedAt.value[k]+ inflight.delete(k)})if (keys.includes('knowledgeBases')) {agentKbCache.clear()+ agentKbInflight.clear()kbAllInflight = nullinvalidateKnowledgeBaseDetail()}diff --git a/frontend/src/views/knowledge/KnowledgeBaseList.vue b/frontend/src/views/knowledge/KnowledgeBaseList.vueindex 241ff858f..f77710219 100644--- a/frontend/src/views/knowledge/KnowledgeBaseList.vue+++ b/frontend/src/views/knowledge/KnowledgeBaseList.vue@@ -1653,6 +1653,8 @@ const handleCreateKnowledgeBase = () => {const handleKBEditorSuccess = (kbId: string) => {console.log('[KnowledgeBaseList] knowledge operation success:', kbId)const shouldOpenDetailForUploadGuide = !isContextualGuideDone('kbDetail')+ // 列表页编辑同样要让单 KB 详情缓存失效,否则侧栏 / 详情页 60s 内仍显示旧信息+ chatResources.invalidateKnowledgeBaseDetail(kbId)fetchList(true).then(() => {if (shouldOpenDetailForUploadGuide && kbId) {goDetail(kbId)