Only fetch session tokens when chat state is idle to avoid resetting during streaming (#4104)
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
|||||||
TextContent,
|
TextContent,
|
||||||
} from '../types/message';
|
} from '../types/message';
|
||||||
import { ChatType } from '../types/chat';
|
import { ChatType } from '../types/chat';
|
||||||
|
import { ChatState } from '../types/chatState';
|
||||||
|
|
||||||
// Helper function to determine if a message is a user message
|
// Helper function to determine if a message is a user message
|
||||||
const isUserMessage = (message: Message): boolean => {
|
const isUserMessage = (message: Message): boolean => {
|
||||||
@@ -211,10 +212,11 @@ export const useChatEngine = ({
|
|||||||
console.error('Error fetching session token count:', err);
|
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();
|
fetchSessionTokens();
|
||||||
}
|
}
|
||||||
}, [chat.id, messages]);
|
}, [chat.id, messages, chatState]);
|
||||||
|
|
||||||
// Update token counts when sessionMetadata changes from the message stream
|
// Update token counts when sessionMetadata changes from the message stream
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user