Only fetch session tokens when chat state is idle to avoid resetting during streaming (#4104)

This commit is contained in:
Zane
2025-08-21 12:46:24 -07:00
committed by GitHub
parent f41af2c2d7
commit 3d114f3639
+4 -2
View File
@@ -15,6 +15,7 @@ import {
TextContent,
} from '../types/message';
import { ChatType } from '../types/chat';
import { ChatState } from '../types/chatState';
// Helper function to determine if a message is a user message
const isUserMessage = (message: Message): boolean => {
@@ -211,10 +212,11 @@ export const useChatEngine = ({
console.error('Error fetching session token count:', err);
}
};
if (chat.id) {
// Only fetch session tokens when chat state is idle to avoid resetting during streaming
if (chat.id && chatState === ChatState.Idle) {
fetchSessionTokens();
}
}, [chat.id, messages]);
}, [chat.id, messages, chatState]);
// Update token counts when sessionMetadata changes from the message stream
useEffect(() => {