From b3fbe35efe9e15f44cd0b09e46f58681f10e79b3 Mon Sep 17 00:00:00 2001 From: ousugo Date: Mon, 17 Mar 2025 18:59:24 +0800 Subject: [PATCH] refactor: add isNameManuallyEdited flag to topic management - Introduced isNameManuallyEdited property to the Topic type for better tracking of manual edits. - Updated topic update logic to set isNameManuallyEdited based on user actions in the TopicsTab. - Enhanced autoRenameTopic function to respect manual edits and prevent automatic renaming when applicable. --- src/renderer/src/hooks/useTopic.ts | 4 ++++ src/renderer/src/pages/home/Tabs/TopicsTab.tsx | 4 ++-- src/renderer/src/services/AssistantService.ts | 3 ++- src/renderer/src/types/index.ts | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/renderer/src/hooks/useTopic.ts b/src/renderer/src/hooks/useTopic.ts index d3cab75a..609da18b 100644 --- a/src/renderer/src/hooks/useTopic.ts +++ b/src/renderer/src/hooks/useTopic.ts @@ -61,6 +61,10 @@ export const autoRenameTopic = async (assistant: Assistant, topicId: string) => return } + if (topic.isNameManuallyEdited) { + return + } + if (!enableTopicNaming) { const topicName = topic.messages[0]?.content.substring(0, 50) if (topicName) { diff --git a/src/renderer/src/pages/home/Tabs/TopicsTab.tsx b/src/renderer/src/pages/home/Tabs/TopicsTab.tsx index 612660e3..9082dc2d 100644 --- a/src/renderer/src/pages/home/Tabs/TopicsTab.tsx +++ b/src/renderer/src/pages/home/Tabs/TopicsTab.tsx @@ -138,7 +138,7 @@ const Topics: FC = ({ assistant: _assistant, activeTopic, setActiveTopic if (messages.length >= 2) { const summaryText = await fetchMessagesSummary({ messages, assistant }) if (summaryText) { - updateTopic({ ...topic, name: summaryText }) + updateTopic({ ...topic, name: summaryText, isNameManuallyEdited: false }) } } } @@ -154,7 +154,7 @@ const Topics: FC = ({ assistant: _assistant, activeTopic, setActiveTopic defaultValue: topic?.name || '' }) if (name && topic?.name !== name) { - updateTopic({ ...topic, name }) + updateTopic({ ...topic, name, isNameManuallyEdited: true }) } } }, diff --git a/src/renderer/src/services/AssistantService.ts b/src/renderer/src/services/AssistantService.ts index 2abd5a39..0216c79a 100644 --- a/src/renderer/src/services/AssistantService.ts +++ b/src/renderer/src/services/AssistantService.ts @@ -47,7 +47,8 @@ export function getDefaultTopic(assistantId: string): Topic { createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(), name: i18n.t('chat.default.topic.name'), - messages: [] + messages: [], + isNameManuallyEdited: false } } diff --git a/src/renderer/src/types/index.ts b/src/renderer/src/types/index.ts index f8a52896..e4aba0a2 100644 --- a/src/renderer/src/types/index.ts +++ b/src/renderer/src/types/index.ts @@ -96,6 +96,7 @@ export type Topic = { messages: Message[] pinned?: boolean prompt?: string + isNameManuallyEdited?: boolean } export type User = {