From c13d584010b7331e1ada2a35de7d9769ebeb4f5d Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Wed, 12 Mar 2025 11:55:53 +0800 Subject: [PATCH] fix(AssistantsStore): Clear messages when updating topics Modify topic update logic to reset messages array when updating topics or individual topics in the assistants store --- src/renderer/src/store/assistants.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/renderer/src/store/assistants.ts b/src/renderer/src/store/assistants.ts index f2664617..f91d3b66 100644 --- a/src/renderer/src/store/assistants.ts +++ b/src/renderer/src/store/assistants.ts @@ -3,7 +3,7 @@ import { DEFAULT_CONTEXTCOUNT, DEFAULT_TEMPERATURE } from '@renderer/config/cons import { TopicManager } from '@renderer/hooks/useTopic' import { getDefaultAssistant, getDefaultTopic } from '@renderer/services/AssistantService' import { Assistant, AssistantSettings, Model, Topic } from '@renderer/types' -import { uniqBy } from 'lodash' +import { isEmpty, uniqBy } from 'lodash' export interface AssistantsState { defaultAssistant: Assistant @@ -87,7 +87,11 @@ const assistantsSlice = createSlice({ assistant.id === action.payload.assistantId ? { ...assistant, - topics: assistant.topics.map((topic) => (topic.id === newTopic.id ? newTopic : topic)) + topics: assistant.topics.map((topic) => { + const _topic = topic.id === newTopic.id ? newTopic : topic + _topic.messages = [] + return _topic + }) } : assistant ) @@ -97,7 +101,9 @@ const assistantsSlice = createSlice({ assistant.id === action.payload.assistantId ? { ...assistant, - topics: action.payload.topics + topics: action.payload.topics.map((topic) => + isEmpty(topic.messages) ? topic : { ...topic, messages: [] } + ) } : assistant )