From 710e743ebae5d8bb7de42490c62dc4632781e21b Mon Sep 17 00:00:00 2001 From: one Date: Fri, 13 Jun 2025 17:24:24 +0800 Subject: [PATCH] fix(TopicRenaming): captured activeTopic.id is outdated and causes accidental topic changing after renaming (#7157) * fix(TopicRenaming): captured activeTopic.id is outdated and causes accidental topic changing after renaming * fix: prevent topic changing on auto renaming * fix: filter out main text on summarizing --- src/renderer/src/hooks/useTopic.ts | 4 ++-- src/renderer/src/pages/home/Tabs/TopicsTab.tsx | 2 -- src/renderer/src/services/ApiService.ts | 5 ++++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/renderer/src/hooks/useTopic.ts b/src/renderer/src/hooks/useTopic.ts index 02868a3a90..c6913bd7eb 100644 --- a/src/renderer/src/hooks/useTopic.ts +++ b/src/renderer/src/hooks/useTopic.ts @@ -121,7 +121,7 @@ export const autoRenameTopic = async (assistant: Assistant, topicId: string) => startTopicRenaming(topicId) const data = { ...topic, name: topicName } as Topic - _setActiveTopic(data) + topic.id === _activeTopic.id && _setActiveTopic(data) store.dispatch(updateTopic({ assistantId: assistant.id, topic: data })) } finally { finishTopicRenaming(topicId) @@ -138,7 +138,7 @@ export const autoRenameTopic = async (assistant: Assistant, topicId: string) => const summaryText = await fetchMessagesSummary({ messages: topic.messages, assistant }) if (summaryText) { const data = { ...topic, name: summaryText } - _setActiveTopic(data) + topic.id === _activeTopic.id && _setActiveTopic(data) store.dispatch(updateTopic({ assistantId: assistant.id, topic: data })) } } finally { diff --git a/src/renderer/src/pages/home/Tabs/TopicsTab.tsx b/src/renderer/src/pages/home/Tabs/TopicsTab.tsx index 04930a624f..6d370484fb 100644 --- a/src/renderer/src/pages/home/Tabs/TopicsTab.tsx +++ b/src/renderer/src/pages/home/Tabs/TopicsTab.tsx @@ -197,7 +197,6 @@ const Topics: FC = ({ assistant: _assistant, activeTopic, setActiveTopic if (summaryText) { const updatedTopic = { ...topic, name: summaryText, isNameManuallyEdited: false } updateTopic(updatedTopic) - topic.id === activeTopic.id && setActiveTopic(updatedTopic) } else { window.message?.error(t('message.error.fetchTopicName')) } @@ -221,7 +220,6 @@ const Topics: FC = ({ assistant: _assistant, activeTopic, setActiveTopic if (name && topic?.name !== name) { const updatedTopic = { ...topic, name, isNameManuallyEdited: true } updateTopic(updatedTopic) - topic.id === activeTopic.id && setActiveTopic(updatedTopic) } } }, diff --git a/src/renderer/src/services/ApiService.ts b/src/renderer/src/services/ApiService.ts index d9becd6952..02763079d4 100644 --- a/src/renderer/src/services/ApiService.ts +++ b/src/renderer/src/services/ApiService.ts @@ -416,7 +416,10 @@ export async function fetchTranslate({ content, assistant, onResponse }: FetchTr export async function fetchMessagesSummary({ messages, assistant }: { messages: Message[]; assistant: Assistant }) { const prompt = (getStoreSetting('topicNamingPrompt') as string) || i18n.t('prompts.title') const model = getTopNamingModel() || assistant.model || getDefaultModel() - const userMessages = takeRight(messages, 5) + const userMessages = takeRight(messages, 5).map((message) => ({ + ...message, + content: getMainTextContent(message) + })) const provider = getProviderByModel(model)