From b66ccd6e2f15e8d448c4b2f7ce9afbd6fc5df3a8 Mon Sep 17 00:00:00 2001 From: Bob Du Date: Wed, 4 Mar 2026 14:52:33 +0800 Subject: [PATCH] fix(chat): sync stale model mapping for image upload Signed-off-by: Bob Du --- src/views/chat/index.vue | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue index 5a87a22a..9974cc8c 100644 --- a/src/views/chat/index.vue +++ b/src/views/chat/index.vue @@ -1049,6 +1049,42 @@ const chatModelOptions = computed(() => { return [...baseModels, ...externalOptions] }) +function getModelBaseValue(value: string): string { + return value.includes('|') ? value.split('|')[0] : value +} + +const syncingStaleChatModel = ref(false) + +async function syncStaleChatModelIfNeeded() { + if (syncingStaleChatModel.value || !currentChatRoom.value?.chatModel) + return + + const currentModel = currentChatRoom.value.chatModel + if (isExternalModel(currentModel)) + return + + // If the room model still exists in options, no migration is needed. + if (chatModelOptions.value.some(option => option.value === currentModel)) + return + + // Auto-migrate only when there is a single unambiguous replacement. + const candidates = chatModelOptions.value.filter((option) => { + if (isExternalModel(option.value)) + return false + return getModelBaseValue(option.value) === getModelBaseValue(currentModel) + }) + if (candidates.length !== 1) + return + + syncingStaleChatModel.value = true + try { + await chatStore.setChatModel(candidates[0].value) + } + finally { + syncingStaleChatModel.value = false + } +} + function renderChatModelLabel(option: { label: string, value: string }, _selected: boolean) { if (isExternalModel(option.value)) { return h('span', { style: { display: 'flex', alignItems: 'center', gap: '6px' } }, [ @@ -1281,6 +1317,14 @@ watch(() => chatStore.active, () => { handleSyncChat() }) +watch( + [() => currentChatRoom.value?.roomId, () => currentChatRoom.value?.chatModel, chatModelOptions], + () => { + void syncStaleChatModelIfNeeded() + }, + { immediate: true }, +) + // Watch dataSources to update lastToolResponseId automatically. // Use immediate: false to avoid duplicate init calls (handleSyncChat already runs). watch(() => dataSources.value.length, () => {