From 95ebef13dfc65ec114fe759025ca3fac6108ce32 Mon Sep 17 00:00:00 2001 From: Dustin Healy Date: Sat, 13 Sep 2025 12:42:43 -0700 Subject: [PATCH] refactor: swap conversationCosts query hooks out for new modelCosts query and move to react-query-service --- client/src/data-provider/queries.ts | 33 ------------------- .../src/react-query/react-query-service.ts | 17 ++++++++++ 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/client/src/data-provider/queries.ts b/client/src/data-provider/queries.ts index 24d1d6c9e5..447775067e 100644 --- a/client/src/data-provider/queries.ts +++ b/client/src/data-provider/queries.ts @@ -32,20 +32,6 @@ import type { } from 'librechat-data-provider'; import type { ConversationCursorData } from '~/utils/convos'; import { findConversationInInfinite } from '~/utils'; -type TConversationCosts = { - conversationId: string; - totals: { - prompt: { usd: number; tokenCount: number }; - completion: { usd: number; tokenCount: number }; - total: { usd: number; tokenCount: number }; - }; - perMessage: Array<{ - messageId: string; - tokenType: 'prompt' | 'completion'; - tokenCount: number; - usd: number; - }>; -}; export const useGetPresetsQuery = ( config?: UseQueryOptions, @@ -90,25 +76,6 @@ export const useGetConvoIdQuery = ( ); }; -export const useGetConversationCosts = ( - conversationId: string, - config?: UseQueryOptions, -): QueryObserverResult => { - return useQuery( - [QueryKeys.conversation, conversationId, 'costs'], - () => { - return dataService.getConversationCosts(conversationId) as unknown as TConversationCosts; - }, - { - refetchOnWindowFocus: false, - refetchOnReconnect: false, - refetchOnMount: false, - enabled: !!conversationId && conversationId !== 'new', - ...config, - }, - ); -}; - export const useConversationsInfiniteQuery = ( params: ConversationListParams, config?: UseInfiniteQueryOptions, diff --git a/packages/data-provider/src/react-query/react-query-service.ts b/packages/data-provider/src/react-query/react-query-service.ts index ab150a1336..d299130e60 100644 --- a/packages/data-provider/src/react-query/react-query-service.ts +++ b/packages/data-provider/src/react-query/react-query-service.ts @@ -77,6 +77,23 @@ export const useGetConversationByIdQuery = ( ); }; +export const useGetModelCostsQuery = ( + modelHistory: Array<{ model: string; endpoint: string }>, + config?: UseQueryOptions, +): QueryObserverResult => { + return useQuery( + [QueryKeys.modelCosts, modelHistory], + () => dataService.getModelCosts(modelHistory), + { + refetchOnWindowFocus: false, + refetchOnReconnect: false, + refetchOnMount: false, + enabled: !!modelHistory && modelHistory.length > 0, + ...config, + }, + ); +}; + //This isn't ideal because its just a query and we're using mutation, but it was the only way //to make it work with how the Chat component is structured export const useGetConversationByIdMutation = (id: string): UseMutationResult => {