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
This commit is contained in:
one 2025-06-13 17:24:24 +08:00 committed by GitHub
parent 12ffa8f9d9
commit 710e743eba
3 changed files with 6 additions and 5 deletions

View File

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

View File

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

View File

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