Skip to content

Commit 23237f5

Browse files
authored
fix(chat): sync stale model mapping for image upload (#693)
Signed-off-by: Bob Du <i@bobdu.cc>
1 parent 20dfaf5 commit 23237f5

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

src/views/chat/index.vue

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,42 @@ const chatModelOptions = computed(() => {
10491049
return [...baseModels, ...externalOptions]
10501050
})
10511051
1052+
function getModelBaseValue(value: string): string {
1053+
return value.includes('|') ? value.split('|')[0] : value
1054+
}
1055+
1056+
const syncingStaleChatModel = ref(false)
1057+
1058+
async function syncStaleChatModelIfNeeded() {
1059+
if (syncingStaleChatModel.value || !currentChatRoom.value?.chatModel)
1060+
return
1061+
1062+
const currentModel = currentChatRoom.value.chatModel
1063+
if (isExternalModel(currentModel))
1064+
return
1065+
1066+
// If the room model still exists in options, no migration is needed.
1067+
if (chatModelOptions.value.some(option => option.value === currentModel))
1068+
return
1069+
1070+
// Auto-migrate only when there is a single unambiguous replacement.
1071+
const candidates = chatModelOptions.value.filter((option) => {
1072+
if (isExternalModel(option.value))
1073+
return false
1074+
return getModelBaseValue(option.value) === getModelBaseValue(currentModel)
1075+
})
1076+
if (candidates.length !== 1)
1077+
return
1078+
1079+
syncingStaleChatModel.value = true
1080+
try {
1081+
await chatStore.setChatModel(candidates[0].value)
1082+
}
1083+
finally {
1084+
syncingStaleChatModel.value = false
1085+
}
1086+
}
1087+
10521088
function renderChatModelLabel(option: { label: string, value: string }, _selected: boolean) {
10531089
if (isExternalModel(option.value)) {
10541090
return h('span', { style: { display: 'flex', alignItems: 'center', gap: '6px' } }, [
@@ -1281,6 +1317,14 @@ watch(() => chatStore.active, () => {
12811317
handleSyncChat()
12821318
})
12831319
1320+
watch(
1321+
[() => currentChatRoom.value?.roomId, () => currentChatRoom.value?.chatModel, chatModelOptions],
1322+
() => {
1323+
void syncStaleChatModelIfNeeded()
1324+
},
1325+
{ immediate: true },
1326+
)
1327+
12841328
// Watch dataSources to update lastToolResponseId automatically.
12851329
// Use immediate: false to avoid duplicate init calls (handleSyncChat already runs).
12861330
watch(() => dataSources.value.length, () => {

0 commit comments

Comments
 (0)