From 4e2e668def00314e159a86152d59ac476877f93d Mon Sep 17 00:00:00 2001 From: yangdx Date: Tue, 29 Apr 2025 02:36:17 +0800 Subject: [PATCH] Bump webui setting version to 12 --- .../src/features/RetrievalTesting.tsx | 37 ++++++++++++++----- lightrag_webui/src/stores/settings.ts | 6 ++- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/lightrag_webui/src/features/RetrievalTesting.tsx b/lightrag_webui/src/features/RetrievalTesting.tsx index 6e7bdf7e..70ff2e7d 100644 --- a/lightrag_webui/src/features/RetrievalTesting.tsx +++ b/lightrag_webui/src/features/RetrievalTesting.tsx @@ -15,16 +15,33 @@ import type { QueryMode } from '@/api/lightrag' export default function RetrievalTesting() { const { t } = useTranslation() const [messages, setMessages] = useState(() => { - const history = useSettingsStore.getState().retrievalHistory || [] - // Ensure each message from history has a unique ID and mermaidRendered status - return history.map((msg, index) => { - const msgWithError = msg as MessageWithError // Cast to access potential properties - return { - ...msg, - id: msgWithError.id || `hist-${Date.now()}-${index}`, // Add ID if missing - mermaidRendered: msgWithError.mermaidRendered ?? true // Assume historical mermaid is rendered - } - }) + try { + const history = useSettingsStore.getState().retrievalHistory || [] + // Ensure each message from history has a unique ID and mermaidRendered status + return history.map((msg, index) => { + try { + const msgWithError = msg as MessageWithError // Cast to access potential properties + return { + ...msg, + id: msgWithError.id || `hist-${Date.now()}-${index}`, // Add ID if missing + mermaidRendered: msgWithError.mermaidRendered ?? true // Assume historical mermaid is rendered + } + } catch (error) { + console.error('Error processing message:', error) + // Return a default message if there's an error + return { + role: 'system', + content: 'Error loading message', + id: `error-${Date.now()}-${index}`, + isError: true, + mermaidRendered: true + } + } + }) + } catch (error) { + console.error('Error loading history:', error) + return [] // Return an empty array if there's an error + } }) const [inputValue, setInputValue] = useState('') const [isLoading, setIsLoading] = useState(false) diff --git a/lightrag_webui/src/stores/settings.ts b/lightrag_webui/src/stores/settings.ts index 5da8107e..7de78f15 100644 --- a/lightrag_webui/src/stores/settings.ts +++ b/lightrag_webui/src/stores/settings.ts @@ -167,7 +167,7 @@ const useSettingsStoreBase = create()( { name: 'settings-storage', storage: createJSONStorage(() => localStorage), - version: 11, + version: 12, migrate: (state: any, version: number) => { if (version < 2) { state.showEdgeLabel = false @@ -221,6 +221,10 @@ const useSettingsStoreBase = create()( state.minEdgeSize = 1 state.maxEdgeSize = 1 } + if (version < 12) { + // Clear retrieval history to avoid compatibility issues with MessageWithError type + state.retrievalHistory = [] + } return state } }