🔍 refactor: Search & Message Retrieval (#6903)

* refactor: conversation search fetch

* refactor: Message and Convo fetch with paramters and search

* refactor: update search states and cleanup old store states

* refactor: re-enable search API; fix: search conversation

* fix: message's convo fetch

* fix: redirect when searching

* chore: use logger instead of console

* fix: search message loading

* feat: small optimizations

* feat(Message): remove cache for search path

* fix: handle delete of all archivedConversation and sharedLinks

* chore: cleanup

* fix: search messages

* style: update ConvoOptions styles

* refactor(SearchButtons): streamline conversation fetching and remove unused state

* fix: ensure messages are invalidated after fetching conversation data

* fix: add iconURL to conversation query selection

---------

Co-authored-by: Danny Avila <danny@librechat.ai>
This commit is contained in:
Marco Beretta 2025-04-17 03:07:43 +02:00 committed by GitHub
parent 851938e7a6
commit 88f4ad7c47
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 489 additions and 576 deletions

View file

@ -16,11 +16,10 @@ import type t from 'librechat-data-provider';
import type {
Action,
TPreset,
TPlugin,
ConversationListResponse,
ConversationListParams,
SearchConversationListResponse,
SearchConversationListParams,
MessagesListParams,
MessagesListResponse,
Assistant,
AssistantListParams,
AssistantListResponse,
@ -30,6 +29,7 @@ import type {
SharedLinksListParams,
SharedLinksResponse,
} from 'librechat-data-provider';
import type { ConversationCursorData } from '~/utils/convos';
export const useGetPresetsQuery = (
config?: UseQueryOptions<TPreset[]>,
@ -68,9 +68,9 @@ export const useGetConvoIdQuery = (
[QueryKeys.conversation, id],
() => {
// Try to find in all fetched infinite pages
const convosQuery = queryClient.getQueryData<
InfiniteData<import('~/utils').ConversationCursorData>
>([QueryKeys.allConversations]);
const convosQuery = queryClient.getQueryData<InfiniteData<ConversationCursorData>>([
QueryKeys.allConversations,
]);
const found = convosQuery?.pages
.flatMap((page) => page.conversations)
.find((c) => c.conversationId === id);
@ -90,30 +90,6 @@ export const useGetConvoIdQuery = (
);
};
export const useSearchInfiniteQuery = (
params?: SearchConversationListParams,
config?: UseInfiniteQueryOptions<SearchConversationListResponse, unknown>,
) => {
return useInfiniteQuery<SearchConversationListResponse, unknown>(
[QueryKeys.searchConversations, params],
({ pageParam = null }) =>
dataService
.listConversations({
...params,
search: params?.search ?? '',
cursor: pageParam?.toString(),
})
.then((res) => ({ ...res })) as Promise<SearchConversationListResponse>,
{
getNextPageParam: (lastPage) => lastPage.nextCursor ?? undefined,
refetchOnWindowFocus: false,
refetchOnReconnect: false,
refetchOnMount: false,
...config,
},
);
};
export const useConversationsInfiniteQuery = (
params: ConversationListParams,
config?: UseInfiniteQueryOptions<ConversationListResponse, unknown>,
@ -134,7 +110,36 @@ export const useConversationsInfiniteQuery = (
search,
cursor: pageParam?.toString(),
}),
getNextPageParam: (lastPage) => lastPage.nextCursor ?? undefined,
getNextPageParam: (lastPage) => lastPage?.nextCursor ?? undefined,
keepPreviousData: true,
staleTime: 5 * 60 * 1000, // 5 minutes
cacheTime: 30 * 60 * 1000, // 30 minutes
...config,
});
};
export const useMessagesInfiniteQuery = (
params: MessagesListParams,
config?: UseInfiniteQueryOptions<MessagesListResponse, unknown>,
) => {
const { sortBy, sortDirection, pageSize, conversationId, messageId, search } = params;
return useInfiniteQuery<MessagesListResponse>({
queryKey: [
QueryKeys.messages,
{ sortBy, sortDirection, pageSize, conversationId, messageId, search },
],
queryFn: ({ pageParam }) =>
dataService.listMessages({
sortBy,
sortDirection,
pageSize,
conversationId,
messageId,
search,
cursor: pageParam?.toString(),
}),
getNextPageParam: (lastPage) => lastPage?.nextCursor ?? undefined,
keepPreviousData: true,
staleTime: 5 * 60 * 1000, // 5 minutes
cacheTime: 30 * 60 * 1000, // 30 minutes
@ -159,7 +164,7 @@ export const useSharedLinksQuery = (
sortBy,
sortDirection,
}),
getNextPageParam: (lastPage) => lastPage.nextCursor ?? undefined,
getNextPageParam: (lastPage) => lastPage?.nextCursor ?? undefined,
keepPreviousData: true,
staleTime: 5 * 60 * 1000, // 5 minutes
cacheTime: 30 * 60 * 1000, // 30 minutes