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.
- package/dist/index.es.js +1 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/react-query/index.es.js +1 -1
- package/dist/react-query/index.es.js.map +1 -1
- package/dist/react-query/package.json +2 -1
- package/package.json +4 -1
- package/specs/actions.spec.ts +475 -0
- package/specs/filetypes.spec.ts +181 -0
- package/specs/openapiSpecs.ts +350 -0
- package/src/actions.ts +347 -0
- package/src/config.ts +130 -13
- package/src/createPayload.ts +1 -5
- package/src/data-service.ts +39 -2
- package/src/file-config.ts +264 -0
- package/src/index.ts +2 -0
- package/src/keys.ts +8 -1
- package/src/parsers.ts +10 -10
- package/src/react-query/index.ts +0 -1
- package/src/react-query/react-query-service.ts +16 -1
- package/src/schemas.ts +31 -14
- package/src/types/assistants.ts +255 -3
- package/src/types/files.ts +46 -13
- package/src/types/mutations.ts +90 -1
- package/src/types.ts +7 -0
- package/tsconfig.spec.json +10 -0
- package/src/react-query/assistants.ts +0 -138
|
@@ -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
|
-
};
|