fix: start animation only if the topic should be renamed (#7125)

This commit is contained in:
one 2025-06-12 22:43:44 +08:00 committed by GitHub
parent 1a54447947
commit 198c9e24be

View File

@ -88,20 +88,15 @@ export const finishTopicRenaming = (topicId: string) => {
}, 700) }, 700)
} }
/** const topicRenamingLocks = new Set<string>()
*
*/
export const isTopicRenaming = (topicId: string) => {
return store.getState().runtime.chat.renamingTopics.includes(topicId)
}
export const autoRenameTopic = async (assistant: Assistant, topicId: string) => { export const autoRenameTopic = async (assistant: Assistant, topicId: string) => {
if (isTopicRenaming(topicId)) { if (topicRenamingLocks.has(topicId)) {
return return
} }
try { try {
startTopicRenaming(topicId) topicRenamingLocks.add(topicId)
const topic = await getTopicById(topicId) const topic = await getTopicById(topicId)
const enableTopicNaming = getStoreSetting('enableTopicNaming') const enableTopicNaming = getStoreSetting('enableTopicNaming')
@ -122,24 +117,36 @@ export const autoRenameTopic = async (assistant: Assistant, topicId: string) =>
.join('\n\n') .join('\n\n')
.substring(0, 50) .substring(0, 50)
if (topicName) { if (topicName) {
const data = { ...topic, name: topicName } as Topic try {
_setActiveTopic(data) startTopicRenaming(topicId)
store.dispatch(updateTopic({ assistantId: assistant.id, topic: data }))
const data = { ...topic, name: topicName } as Topic
_setActiveTopic(data)
store.dispatch(updateTopic({ assistantId: assistant.id, topic: data }))
} finally {
finishTopicRenaming(topicId)
}
} }
return return
} }
if (topic && topic.name === i18n.t('chat.default.topic.name') && topic.messages.length >= 2) { if (topic && topic.name === i18n.t('chat.default.topic.name') && topic.messages.length >= 2) {
const { fetchMessagesSummary } = await import('@renderer/services/ApiService') try {
const summaryText = await fetchMessagesSummary({ messages: topic.messages, assistant }) startTopicRenaming(topicId)
if (summaryText) {
const data = { ...topic, name: summaryText } const { fetchMessagesSummary } = await import('@renderer/services/ApiService')
_setActiveTopic(data) const summaryText = await fetchMessagesSummary({ messages: topic.messages, assistant })
store.dispatch(updateTopic({ assistantId: assistant.id, topic: data })) if (summaryText) {
const data = { ...topic, name: summaryText }
_setActiveTopic(data)
store.dispatch(updateTopic({ assistantId: assistant.id, topic: data }))
}
} finally {
finishTopicRenaming(topicId)
} }
} }
} finally { } finally {
finishTopicRenaming(topicId) topicRenamingLocks.delete(topicId)
} }
} }