refactor: swap conversationCosts query hooks out for new modelCosts query and move to react-query-service

This commit is contained in:
Dustin Healy 2025-09-13 12:42:43 -07:00
parent 4fb9d7bdff
commit 95ebef13df
2 changed files with 17 additions and 33 deletions

View file

@ -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<TPreset[]>,
@ -90,25 +76,6 @@ export const useGetConvoIdQuery = (
);
};
export const useGetConversationCosts = (
conversationId: string,
config?: UseQueryOptions<TConversationCosts>,
): QueryObserverResult<TConversationCosts> => {
return useQuery<TConversationCosts>(
[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<ConversationListResponse, unknown>,

View file

@ -77,6 +77,23 @@ export const useGetConversationByIdQuery = (
);
};
export const useGetModelCostsQuery = (
modelHistory: Array<{ model: string; endpoint: string }>,
config?: UseQueryOptions<t.TModelCosts>,
): QueryObserverResult<t.TModelCosts> => {
return useQuery<t.TModelCosts>(
[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<s.TConversation> => {