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.
This commit is contained in:
ousugo 2025-03-17 18:59:24 +08:00 committed by 亢奋猫
parent 3fdbb5a9da
commit b3fbe35efe
4 changed files with 9 additions and 3 deletions

View File

@ -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) {

View File

@ -138,7 +138,7 @@ const Topics: FC<Props> = ({ 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<Props> = ({ assistant: _assistant, activeTopic, setActiveTopic
defaultValue: topic?.name || ''
})
if (name && topic?.name !== name) {
updateTopic({ ...topic, name })
updateTopic({ ...topic, name, isNameManuallyEdited: true })
}
}
},

View File

@ -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
}
}

View File

@ -96,6 +96,7 @@ export type Topic = {
messages: Message[]
pinned?: boolean
prompt?: string
isNameManuallyEdited?: boolean
}
export type User = {