mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-25 17:54:34 +08:00
fix(ai): ignore stale context estimates
Only apply context-token estimates that still belong to the latest active global conversation request.
This commit is contained in:
1 parent
5d63fc4d92
commit
17553ccd23
1 file changed
+5
@@ -37,6 +37,7 @@ const initializing = ref(true)
|
||||
const chatInputRef = ref<{ clearDraft: () => void } | null>(null)
|
||||
let isUnmounted = false
|
||||
let conversationSelectionRequestId = 0
|
||||
let contextEstimateRequestId = 0
|
||||
|
||||
function isGlobalPageActive(): boolean {
|
||||
return !isUnmounted && route.name === 'global-ai'
|
||||
@@ -161,14 +162,17 @@ watch(currentAIChatId, (aiChatId, previousId) => {
|
||||
watch(
|
||||
currentAIChatId,
|
||||
async (aiChatId) => {
|
||||
const requestId = ++contextEstimateRequestId
|
||||
if (!aiChatId) {
|
||||
estimatedContextTokens.value = 0
|
||||
return
|
||||
}
|
||||
try {
|
||||
const result = await aiService.estimateContextTokens(aiChatId)
|
||||
if (requestId !== contextEstimateRequestId || currentAIChatId.value !== aiChatId) return
|
||||
estimatedContextTokens.value = result.success ? result.tokens : 0
|
||||
} catch {
|
||||
if (requestId !== contextEstimateRequestId || currentAIChatId.value !== aiChatId) return
|
||||
estimatedContextTokens.value = 0
|
||||
}
|
||||
},
|
||||
@@ -220,6 +224,7 @@ onMounted(async () => {
|
||||
onUnmounted(() => {
|
||||
isUnmounted = true
|
||||
conversationSelectionRequestId++
|
||||
contextEstimateRequestId++
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in new issue
Block a user