librechat-data-provider 0.3.9 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,138 +0,0 @@
1
- import { useQuery, useMutation, useQueryClient, useInfiniteQuery } from '@tanstack/react-query';
2
- import type {
3
- UseQueryOptions,
4
- UseMutationResult,
5
- QueryObserverResult,
6
- UseInfiniteQueryOptions,
7
- } from '@tanstack/react-query';
8
- import * as t from '../types/assistants';
9
- import * as dataService from '../data-service';
10
- import { QueryKeys } from '../keys';
11
-
12
- /**
13
- * Hook for listing all assistants, with optional parameters provided for pagination and sorting
14
- */
15
- export const useListAssistantsQuery = <TData = t.AssistantListResponse>(
16
- params?: t.AssistantListParams,
17
- config?: UseQueryOptions<t.AssistantListResponse, unknown, TData>,
18
- ): QueryObserverResult<TData> => {
19
- return useQuery<t.AssistantListResponse, unknown, TData>(
20
- [QueryKeys.assistants, params],
21
- () => dataService.listAssistants(params),
22
- {
23
- // Example selector to sort them by created_at
24
- // select: (res) => {
25
- // return res.data.sort((a, b) => a.created_at - b.created_at);
26
- // },
27
- refetchOnWindowFocus: false,
28
- refetchOnReconnect: false,
29
- refetchOnMount: false,
30
- retry: false,
31
- ...config,
32
- },
33
- );
34
- };
35
-
36
- export const useListAssistantsInfiniteQuery = (
37
- params?: t.AssistantListParams,
38
- config?: UseInfiniteQueryOptions<t.AssistantListResponse, Error>,
39
- ) => {
40
- return useInfiniteQuery<t.AssistantListResponse, Error>(
41
- ['assistantsList', params],
42
- ({ pageParam = '' }) => dataService.listAssistants({ ...params, after: pageParam }),
43
- {
44
- getNextPageParam: (lastPage) => {
45
- // lastPage is of type AssistantListResponse, you can use the has_more and last_id from it directly
46
- if (lastPage.has_more) {
47
- return lastPage.last_id;
48
- }
49
- return undefined;
50
- },
51
- ...config,
52
- },
53
- );
54
- };
55
-
56
- /**
57
- * Hook for creating a new assistant
58
- */
59
- export const useCreateAssistantMutation = (): UseMutationResult<
60
- t.Assistant,
61
- Error,
62
- t.AssistantCreateParams
63
- > => {
64
- const queryClient = useQueryClient();
65
- return useMutation(
66
- (newAssistantData: t.AssistantCreateParams) => dataService.createAssistant(newAssistantData),
67
- {
68
- onSuccess: () => {
69
- // Invalidate and refetch assistants query to update list
70
- queryClient.invalidateQueries([QueryKeys.assistants]);
71
- },
72
- },
73
- );
74
- };
75
-
76
- /**
77
- * Hook for retrieving details about a single assistant
78
- */
79
- export const useGetAssistantByIdQuery = (
80
- assistant_id: string,
81
- config?: UseQueryOptions<t.Assistant>,
82
- ): QueryObserverResult<t.Assistant> => {
83
- return useQuery<t.Assistant>(
84
- [QueryKeys.assistant, assistant_id],
85
- () => dataService.getAssistantById(assistant_id),
86
- {
87
- enabled: !!assistant_id, // Query will not execute until the assistant_id exists
88
- refetchOnWindowFocus: false,
89
- refetchOnReconnect: false,
90
- refetchOnMount: false,
91
- retry: false,
92
- ...config,
93
- },
94
- );
95
- };
96
-
97
- /**
98
- * Hook for updating an assistant
99
- */
100
- export const useUpdateAssistantMutation = (): UseMutationResult<
101
- t.Assistant,
102
- Error,
103
- { assistant_id: string; data: t.AssistantUpdateParams }
104
- > => {
105
- const queryClient = useQueryClient();
106
- return useMutation(
107
- ({ assistant_id, data }: { assistant_id: string; data: t.AssistantUpdateParams }) =>
108
- dataService.updateAssistant(assistant_id, data),
109
- {
110
- onSuccess: (_, { assistant_id }) => {
111
- // Invalidate and refetch assistant details query
112
- queryClient.invalidateQueries([QueryKeys.assistant, assistant_id]);
113
- // Optionally invalidate and refetch list of assistants
114
- queryClient.invalidateQueries([QueryKeys.assistants]);
115
- },
116
- },
117
- );
118
- };
119
-
120
- /**
121
- * Hook for deleting an assistant
122
- */
123
- export const useDeleteAssistantMutation = (): UseMutationResult<
124
- void,
125
- Error,
126
- { assistant_id: string }
127
- > => {
128
- const queryClient = useQueryClient();
129
- return useMutation(
130
- ({ assistant_id }: { assistant_id: string }) => dataService.deleteAssistant(assistant_id),
131
- {
132
- onSuccess: () => {
133
- // Invalidate and refetch assistant list query
134
- queryClient.invalidateQueries([QueryKeys.assistants]);
135
- },
136
- },
137
- );
138
- };