@@ -16,7 +16,17 @@ import { TodoGuide } from "./TodoGuide";
1616import { OnboardingGuide } from "./OnboardingGuide" ;
1717import { OnboardingCompletionPopup } from "./OnboardingCompletionPopup" ;
1818import { useNotificationService } from "../../service/notification-service" ;
19+ import { useAxiosPrivate } from "../../service/axios-service" ;
1920import { SpinnerLoader } from "../../widgets/spinner_loader" ;
21+ import { useSessionStore } from "../../store/session-store" ;
22+
23+ // Cloud-only: fetch per-message token usage (unavailable in OSS — import fails gracefully)
24+ let getTokenUsage = null ;
25+ try {
26+ ( { getTokenUsage } = require ( "../../plugins/token-management/token-usage" ) ) ;
27+ } catch {
28+ // OSS: token usage API not available
29+ }
2030
2131const ExistingChat = memo ( function ExistingChat ( {
2232 selectedChatId,
@@ -61,8 +71,9 @@ const ExistingChat = memo(function ExistingChat({
6171 onSkipCurrentTask,
6272 onSendButtonClick,
6373} ) {
64- const { getChatMessagesByChatId, getTokenUsage, updateChatName } =
65- useChatAIService ( ) ;
74+ const { getChatMessagesByChatId, updateChatName } = useChatAIService ( ) ;
75+ const axiosPrivate = useAxiosPrivate ( ) ;
76+ const isCloud = useSessionStore ( ( state ) => state . sessionDetails ?. is_cloud ) ;
6677 const chatContainerRef = useRef ( null ) ;
6778
6879 const [ isLoadingChats , setIsLoadingChats ] = useState ( false ) ;
@@ -262,10 +273,15 @@ const ExistingChat = memo(function ExistingChat({
262273 : [ msg . response ] . filter ( Boolean ) ,
263274 } ) ) ;
264275
265- // Fetch token usage for all messages to display in historical conversations
266- if ( updatedData . length > 0 ) {
276+ // Fetch token usage for all messages to display in historical conversations.
277+ // Only available in cloud mode via the token-usage plugin.
278+ if ( getTokenUsage && isCloud && updatedData . length > 0 ) {
267279 const tokenUsagePromises = updatedData . map ( ( msg ) =>
268- getTokenUsage ( selectedChatId , msg . chat_message_id ) . catch ( ( ) => null )
280+ getTokenUsage (
281+ axiosPrivate ,
282+ selectedChatId ,
283+ msg . chat_message_id
284+ ) . catch ( ( ) => null )
269285 ) ;
270286 const tokenUsageResults = await Promise . all ( tokenUsagePromises ) ;
271287
0 commit comments