librechat-data-provider 0.7.5 → 0.7.7
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/check_updates.sh +1 -0
- 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/package.json +4 -4
- package/server-rollup.config.js +3 -3
- package/specs/actions.spec.ts +424 -35
- package/specs/azure.spec.ts +8 -5
- package/specs/filetypes.spec.ts +1 -7
- package/specs/mcp.spec.ts +52 -0
- package/specs/utils.spec.ts +129 -0
- package/src/actions.ts +209 -82
- package/src/api-endpoints.ts +39 -16
- package/src/azure.ts +40 -33
- package/src/bedrock.ts +84 -4
- package/src/config.ts +199 -95
- package/src/createPayload.ts +3 -1
- package/src/data-service.ts +114 -20
- package/src/file-config.ts +10 -2
- package/src/generate.ts +1 -1
- package/src/index.ts +7 -4
- package/src/keys.ts +6 -0
- package/src/mcp.ts +87 -0
- package/src/models.ts +1 -1
- package/src/parsers.ts +43 -43
- package/src/react-query/react-query-service.ts +40 -126
- package/src/request.ts +28 -7
- package/src/roles.ts +33 -1
- package/src/schemas.ts +250 -198
- package/src/types/agents.ts +57 -1
- package/src/types/assistants.ts +33 -2
- package/src/types/files.ts +1 -0
- package/src/types/mutations.ts +96 -8
- package/src/types/queries.ts +39 -21
- package/src/types/runs.ts +1 -0
- package/src/types.ts +90 -81
- package/src/utils.ts +44 -0
- package/src/zod.spec.ts +526 -0
- package/src/zod.ts +86 -0
- package/tsconfig.json +1 -2
- package/specs/parsers.spec.ts +0 -48
- package/src/sse.js +0 -242
|
@@ -4,12 +4,11 @@ import type {
|
|
|
4
4
|
UseMutationResult,
|
|
5
5
|
QueryObserverResult,
|
|
6
6
|
} from '@tanstack/react-query';
|
|
7
|
-
import { initialModelsConfig
|
|
7
|
+
import { initialModelsConfig } from '../config';
|
|
8
8
|
import { defaultOrderQuery } from '../types/assistants';
|
|
9
9
|
import * as dataService from '../data-service';
|
|
10
10
|
import * as m from '../types/mutations';
|
|
11
11
|
import { QueryKeys } from '../keys';
|
|
12
|
-
import request from '../request';
|
|
13
12
|
import * as s from '../schemas';
|
|
14
13
|
import * as t from '../types';
|
|
15
14
|
|
|
@@ -30,18 +29,6 @@ export const useAbortRequestWithMessage = (): UseMutationResult<
|
|
|
30
29
|
);
|
|
31
30
|
};
|
|
32
31
|
|
|
33
|
-
export const useGetUserQuery = (
|
|
34
|
-
config?: UseQueryOptions<t.TUser>,
|
|
35
|
-
): QueryObserverResult<t.TUser> => {
|
|
36
|
-
return useQuery<t.TUser>([QueryKeys.user], () => dataService.getUser(), {
|
|
37
|
-
refetchOnWindowFocus: false,
|
|
38
|
-
refetchOnReconnect: false,
|
|
39
|
-
refetchOnMount: false,
|
|
40
|
-
retry: false,
|
|
41
|
-
...config,
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
|
|
45
32
|
export const useGetMessagesByConvoId = <TData = s.TMessage[]>(
|
|
46
33
|
id: string,
|
|
47
34
|
config?: UseQueryOptions<s.TMessage[], unknown, TData>,
|
|
@@ -74,15 +61,27 @@ export const useGetSharedMessages = (
|
|
|
74
61
|
);
|
|
75
62
|
};
|
|
76
63
|
|
|
77
|
-
export const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
64
|
+
export const useGetSharedLinkQuery = (
|
|
65
|
+
conversationId: string,
|
|
66
|
+
config?: UseQueryOptions<t.TSharedLinkGetResponse>,
|
|
67
|
+
): QueryObserverResult<t.TSharedLinkGetResponse> => {
|
|
68
|
+
const queryClient = useQueryClient();
|
|
69
|
+
return useQuery<t.TSharedLinkGetResponse>(
|
|
70
|
+
[QueryKeys.sharedLinks, conversationId],
|
|
71
|
+
() => dataService.getSharedLink(conversationId),
|
|
72
|
+
{
|
|
73
|
+
refetchOnWindowFocus: false,
|
|
74
|
+
refetchOnReconnect: false,
|
|
75
|
+
refetchOnMount: false,
|
|
76
|
+
onSuccess: (data) => {
|
|
77
|
+
queryClient.setQueryData([QueryKeys.sharedLinks, conversationId], {
|
|
78
|
+
conversationId: data.conversationId,
|
|
79
|
+
shareId: data.shareId,
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
...config,
|
|
83
|
+
},
|
|
84
|
+
);
|
|
86
85
|
};
|
|
87
86
|
|
|
88
87
|
export const useGetConversationByIdQuery = (
|
|
@@ -202,33 +201,6 @@ export const useRevokeAllUserKeysMutation = (): UseMutationResult<unknown> => {
|
|
|
202
201
|
});
|
|
203
202
|
};
|
|
204
203
|
|
|
205
|
-
export const useGetSearchEnabledQuery = (
|
|
206
|
-
config?: UseQueryOptions<boolean>,
|
|
207
|
-
): QueryObserverResult<boolean> => {
|
|
208
|
-
return useQuery<boolean>([QueryKeys.searchEnabled], () => dataService.getSearchEnabled(), {
|
|
209
|
-
refetchOnWindowFocus: false,
|
|
210
|
-
refetchOnReconnect: false,
|
|
211
|
-
refetchOnMount: false,
|
|
212
|
-
...config,
|
|
213
|
-
});
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
export const useGetEndpointsQuery = <TData = t.TEndpointsConfig>(
|
|
217
|
-
config?: UseQueryOptions<t.TEndpointsConfig, unknown, TData>,
|
|
218
|
-
): QueryObserverResult<TData> => {
|
|
219
|
-
return useQuery<t.TEndpointsConfig, unknown, TData>(
|
|
220
|
-
[QueryKeys.endpoints],
|
|
221
|
-
() => dataService.getAIEndpoints(),
|
|
222
|
-
{
|
|
223
|
-
staleTime: Infinity,
|
|
224
|
-
refetchOnWindowFocus: false,
|
|
225
|
-
refetchOnReconnect: false,
|
|
226
|
-
refetchOnMount: false,
|
|
227
|
-
...config,
|
|
228
|
-
},
|
|
229
|
-
);
|
|
230
|
-
};
|
|
231
|
-
|
|
232
204
|
export const useGetModelsQuery = (
|
|
233
205
|
config?: UseQueryOptions<t.TModelsConfig>,
|
|
234
206
|
): QueryObserverResult<t.TModelsConfig> => {
|
|
@@ -301,54 +273,22 @@ export const useUpdateTokenCountMutation = (): UseMutationResult<
|
|
|
301
273
|
});
|
|
302
274
|
};
|
|
303
275
|
|
|
304
|
-
export const useLoginUserMutation = (): UseMutationResult<
|
|
305
|
-
t.TLoginResponse,
|
|
306
|
-
unknown,
|
|
307
|
-
t.TLoginUser,
|
|
308
|
-
unknown
|
|
309
|
-
> => {
|
|
310
|
-
const queryClient = useQueryClient();
|
|
311
|
-
return useMutation((payload: t.TLoginUser) => dataService.login(payload), {
|
|
312
|
-
onMutate: () => {
|
|
313
|
-
queryClient.removeQueries();
|
|
314
|
-
localStorage.removeItem(LocalStorageKeys.LAST_CONVO_SETUP);
|
|
315
|
-
localStorage.removeItem(`${LocalStorageKeys.LAST_CONVO_SETUP}_0`);
|
|
316
|
-
localStorage.removeItem(`${LocalStorageKeys.LAST_CONVO_SETUP}_1`);
|
|
317
|
-
localStorage.removeItem(LocalStorageKeys.LAST_MODEL);
|
|
318
|
-
localStorage.removeItem(LocalStorageKeys.LAST_TOOLS);
|
|
319
|
-
localStorage.removeItem(LocalStorageKeys.FILES_TO_DELETE);
|
|
320
|
-
// localStorage.removeItem('lastAssistant');
|
|
321
|
-
},
|
|
322
|
-
});
|
|
323
|
-
};
|
|
324
|
-
|
|
325
276
|
export const useRegisterUserMutation = (
|
|
326
277
|
options?: m.RegistrationOptions,
|
|
327
278
|
): UseMutationResult<t.TError, unknown, t.TRegisterUser, unknown> => {
|
|
328
279
|
const queryClient = useQueryClient();
|
|
329
|
-
return useMutation
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
export const useRefreshTokenMutation = (): UseMutationResult<
|
|
341
|
-
t.TRefreshTokenResponse,
|
|
342
|
-
unknown,
|
|
343
|
-
unknown,
|
|
344
|
-
unknown
|
|
345
|
-
> => {
|
|
346
|
-
const queryClient = useQueryClient();
|
|
347
|
-
return useMutation(() => request.refreshToken(), {
|
|
348
|
-
onMutate: () => {
|
|
349
|
-
queryClient.removeQueries();
|
|
280
|
+
return useMutation<t.TRegisterUserResponse, t.TError, t.TRegisterUser>(
|
|
281
|
+
(payload: t.TRegisterUser) => dataService.register(payload),
|
|
282
|
+
{
|
|
283
|
+
...options,
|
|
284
|
+
onSuccess: (...args) => {
|
|
285
|
+
queryClient.invalidateQueries([QueryKeys.user]);
|
|
286
|
+
if (options?.onSuccess) {
|
|
287
|
+
options.onSuccess(...args);
|
|
288
|
+
}
|
|
289
|
+
},
|
|
350
290
|
},
|
|
351
|
-
|
|
291
|
+
);
|
|
352
292
|
};
|
|
353
293
|
|
|
354
294
|
export const useUserKeyQuery = (
|
|
@@ -408,35 +348,20 @@ export const useAvailablePluginsQuery = <TData = s.TPlugin[]>(
|
|
|
408
348
|
);
|
|
409
349
|
};
|
|
410
350
|
|
|
411
|
-
export const useUpdateUserPluginsMutation = (
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
t.TUpdateUserPlugins,
|
|
415
|
-
unknown
|
|
416
|
-
> => {
|
|
351
|
+
export const useUpdateUserPluginsMutation = (
|
|
352
|
+
_options?: m.UpdatePluginAuthOptions,
|
|
353
|
+
): UseMutationResult<t.TUser, unknown, t.TUpdateUserPlugins, unknown> => {
|
|
417
354
|
const queryClient = useQueryClient();
|
|
355
|
+
const { onSuccess, ...options } = _options ?? {};
|
|
418
356
|
return useMutation((payload: t.TUpdateUserPlugins) => dataService.updateUserPlugins(payload), {
|
|
419
|
-
|
|
357
|
+
...options,
|
|
358
|
+
onSuccess: (...args) => {
|
|
420
359
|
queryClient.invalidateQueries([QueryKeys.user]);
|
|
360
|
+
onSuccess?.(...args);
|
|
421
361
|
},
|
|
422
362
|
});
|
|
423
363
|
};
|
|
424
364
|
|
|
425
|
-
export const useGetStartupConfig = (
|
|
426
|
-
config?: UseQueryOptions<t.TStartupConfig>,
|
|
427
|
-
): QueryObserverResult<t.TStartupConfig> => {
|
|
428
|
-
return useQuery<t.TStartupConfig>(
|
|
429
|
-
[QueryKeys.startupConfig],
|
|
430
|
-
() => dataService.getStartupConfig(),
|
|
431
|
-
{
|
|
432
|
-
refetchOnWindowFocus: false,
|
|
433
|
-
refetchOnReconnect: false,
|
|
434
|
-
refetchOnMount: false,
|
|
435
|
-
...config,
|
|
436
|
-
},
|
|
437
|
-
);
|
|
438
|
-
};
|
|
439
|
-
|
|
440
365
|
export const useGetCustomConfigSpeechQuery = (
|
|
441
366
|
config?: UseQueryOptions<t.TCustomConfigSpeechResponse>,
|
|
442
367
|
): QueryObserverResult<t.TCustomConfigSpeechResponse> => {
|
|
@@ -451,14 +376,3 @@ export const useGetCustomConfigSpeechQuery = (
|
|
|
451
376
|
},
|
|
452
377
|
);
|
|
453
378
|
};
|
|
454
|
-
|
|
455
|
-
export const useGetBannerQuery = (
|
|
456
|
-
config?: UseQueryOptions<t.TBannerResponse>,
|
|
457
|
-
): QueryObserverResult<t.TBannerResponse> => {
|
|
458
|
-
return useQuery<t.TBannerResponse>([QueryKeys.banner], () => dataService.getBanner(), {
|
|
459
|
-
refetchOnWindowFocus: false,
|
|
460
|
-
refetchOnReconnect: false,
|
|
461
|
-
refetchOnMount: false,
|
|
462
|
-
...config,
|
|
463
|
-
});
|
|
464
|
-
};
|
package/src/request.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import axios, {
|
|
3
|
-
import { setTokenHeader } from './headers-helpers';
|
|
2
|
+
import axios, { AxiosError, AxiosRequestConfig } from 'axios';
|
|
4
3
|
import * as endpoints from './api-endpoints';
|
|
4
|
+
import { setTokenHeader } from './headers-helpers';
|
|
5
|
+
import type * as t from './types';
|
|
5
6
|
|
|
6
7
|
async function _get<T>(url: string, options?: AxiosRequestConfig): Promise<T> {
|
|
7
8
|
const response = await axios.get(url, { ...options });
|
|
@@ -63,7 +64,13 @@ async function _patch(url: string, data?: any) {
|
|
|
63
64
|
let isRefreshing = false;
|
|
64
65
|
let failedQueue: { resolve: (value?: any) => void; reject: (reason?: any) => void }[] = [];
|
|
65
66
|
|
|
66
|
-
const refreshToken = (retry?: boolean) =>
|
|
67
|
+
const refreshToken = (retry?: boolean): Promise<t.TRefreshTokenResponse | undefined> =>
|
|
68
|
+
_post(endpoints.refreshToken(retry));
|
|
69
|
+
|
|
70
|
+
const dispatchTokenUpdatedEvent = (token: string) => {
|
|
71
|
+
setTokenHeader(token);
|
|
72
|
+
window.dispatchEvent(new CustomEvent('tokenUpdated', { detail: token }));
|
|
73
|
+
};
|
|
67
74
|
|
|
68
75
|
const processQueue = (error: AxiosError | null, token: string | null = null) => {
|
|
69
76
|
failedQueue.forEach((prom) => {
|
|
@@ -84,7 +91,15 @@ axios.interceptors.response.use(
|
|
|
84
91
|
return Promise.reject(error);
|
|
85
92
|
}
|
|
86
93
|
|
|
94
|
+
if (originalRequest.url?.includes('/api/auth/2fa') === true) {
|
|
95
|
+
return Promise.reject(error);
|
|
96
|
+
}
|
|
97
|
+
if (originalRequest.url?.includes('/api/auth/logout') === true) {
|
|
98
|
+
return Promise.reject(error);
|
|
99
|
+
}
|
|
100
|
+
|
|
87
101
|
if (error.response.status === 401 && !originalRequest._retry) {
|
|
102
|
+
console.warn('401 error, refreshing token');
|
|
88
103
|
originalRequest._retry = true;
|
|
89
104
|
|
|
90
105
|
if (isRefreshing) {
|
|
@@ -102,17 +117,22 @@ axios.interceptors.response.use(
|
|
|
102
117
|
isRefreshing = true;
|
|
103
118
|
|
|
104
119
|
try {
|
|
105
|
-
const
|
|
120
|
+
const response = await refreshToken(
|
|
106
121
|
// Handle edge case where we get a blank screen if the initial 401 error is from a refresh token request
|
|
107
|
-
originalRequest.url?.includes('api/auth/refresh') ? true : false,
|
|
122
|
+
originalRequest.url?.includes('api/auth/refresh') === true ? true : false,
|
|
108
123
|
);
|
|
109
124
|
|
|
125
|
+
const token = response?.token ?? '';
|
|
126
|
+
|
|
110
127
|
if (token) {
|
|
111
128
|
originalRequest.headers['Authorization'] = 'Bearer ' + token;
|
|
112
|
-
|
|
113
|
-
window.dispatchEvent(new CustomEvent('tokenUpdated', { detail: token }));
|
|
129
|
+
dispatchTokenUpdatedEvent(token);
|
|
114
130
|
processQueue(null, token);
|
|
115
131
|
return await axios(originalRequest);
|
|
132
|
+
} else if (window.location.href.includes('share/')) {
|
|
133
|
+
console.log(
|
|
134
|
+
`Refresh token failed from shared link, attempting request to ${originalRequest.url}`,
|
|
135
|
+
);
|
|
116
136
|
} else {
|
|
117
137
|
window.location.href = '/login';
|
|
118
138
|
}
|
|
@@ -139,4 +159,5 @@ export default {
|
|
|
139
159
|
deleteWithOptions: _deleteWithOptions,
|
|
140
160
|
patch: _patch,
|
|
141
161
|
refreshToken,
|
|
162
|
+
dispatchTokenUpdatedEvent,
|
|
142
163
|
};
|
package/src/roles.ts
CHANGED
|
@@ -34,6 +34,14 @@ export enum PermissionTypes {
|
|
|
34
34
|
* Type for Multi-Conversation Permissions
|
|
35
35
|
*/
|
|
36
36
|
MULTI_CONVO = 'MULTI_CONVO',
|
|
37
|
+
/**
|
|
38
|
+
* Type for Temporary Chat
|
|
39
|
+
*/
|
|
40
|
+
TEMPORARY_CHAT = 'TEMPORARY_CHAT',
|
|
41
|
+
/**
|
|
42
|
+
* Type for using the "Run Code" LC Code Interpreter API feature
|
|
43
|
+
*/
|
|
44
|
+
RUN_CODE = 'RUN_CODE',
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
/**
|
|
@@ -68,7 +76,15 @@ export const agentPermissionsSchema = z.object({
|
|
|
68
76
|
});
|
|
69
77
|
|
|
70
78
|
export const multiConvoPermissionsSchema = z.object({
|
|
71
|
-
[Permissions.USE]: z.boolean().default(
|
|
79
|
+
[Permissions.USE]: z.boolean().default(true),
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
export const temporaryChatPermissionsSchema = z.object({
|
|
83
|
+
[Permissions.USE]: z.boolean().default(true),
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
export const runCodePermissionsSchema = z.object({
|
|
87
|
+
[Permissions.USE]: z.boolean().default(true),
|
|
72
88
|
});
|
|
73
89
|
|
|
74
90
|
export const roleSchema = z.object({
|
|
@@ -77,6 +93,8 @@ export const roleSchema = z.object({
|
|
|
77
93
|
[PermissionTypes.BOOKMARKS]: bookmarkPermissionsSchema,
|
|
78
94
|
[PermissionTypes.AGENTS]: agentPermissionsSchema,
|
|
79
95
|
[PermissionTypes.MULTI_CONVO]: multiConvoPermissionsSchema,
|
|
96
|
+
[PermissionTypes.TEMPORARY_CHAT]: temporaryChatPermissionsSchema,
|
|
97
|
+
[PermissionTypes.RUN_CODE]: runCodePermissionsSchema,
|
|
80
98
|
});
|
|
81
99
|
|
|
82
100
|
export type TRole = z.infer<typeof roleSchema>;
|
|
@@ -84,6 +102,8 @@ export type TAgentPermissions = z.infer<typeof agentPermissionsSchema>;
|
|
|
84
102
|
export type TPromptPermissions = z.infer<typeof promptPermissionsSchema>;
|
|
85
103
|
export type TBookmarkPermissions = z.infer<typeof bookmarkPermissionsSchema>;
|
|
86
104
|
export type TMultiConvoPermissions = z.infer<typeof multiConvoPermissionsSchema>;
|
|
105
|
+
export type TTemporaryChatPermissions = z.infer<typeof temporaryChatPermissionsSchema>;
|
|
106
|
+
export type TRunCodePermissions = z.infer<typeof runCodePermissionsSchema>;
|
|
87
107
|
|
|
88
108
|
const defaultRolesSchema = z.object({
|
|
89
109
|
[SystemRoles.ADMIN]: roleSchema.extend({
|
|
@@ -106,6 +126,12 @@ const defaultRolesSchema = z.object({
|
|
|
106
126
|
[PermissionTypes.MULTI_CONVO]: multiConvoPermissionsSchema.extend({
|
|
107
127
|
[Permissions.USE]: z.boolean().default(true),
|
|
108
128
|
}),
|
|
129
|
+
[PermissionTypes.TEMPORARY_CHAT]: temporaryChatPermissionsSchema.extend({
|
|
130
|
+
[Permissions.USE]: z.boolean().default(true),
|
|
131
|
+
}),
|
|
132
|
+
[PermissionTypes.RUN_CODE]: runCodePermissionsSchema.extend({
|
|
133
|
+
[Permissions.USE]: z.boolean().default(true),
|
|
134
|
+
}),
|
|
109
135
|
}),
|
|
110
136
|
[SystemRoles.USER]: roleSchema.extend({
|
|
111
137
|
name: z.literal(SystemRoles.USER),
|
|
@@ -113,6 +139,8 @@ const defaultRolesSchema = z.object({
|
|
|
113
139
|
[PermissionTypes.BOOKMARKS]: bookmarkPermissionsSchema,
|
|
114
140
|
[PermissionTypes.AGENTS]: agentPermissionsSchema,
|
|
115
141
|
[PermissionTypes.MULTI_CONVO]: multiConvoPermissionsSchema,
|
|
142
|
+
[PermissionTypes.TEMPORARY_CHAT]: temporaryChatPermissionsSchema,
|
|
143
|
+
[PermissionTypes.RUN_CODE]: runCodePermissionsSchema,
|
|
116
144
|
}),
|
|
117
145
|
});
|
|
118
146
|
|
|
@@ -123,6 +151,8 @@ export const roleDefaults = defaultRolesSchema.parse({
|
|
|
123
151
|
[PermissionTypes.BOOKMARKS]: {},
|
|
124
152
|
[PermissionTypes.AGENTS]: {},
|
|
125
153
|
[PermissionTypes.MULTI_CONVO]: {},
|
|
154
|
+
[PermissionTypes.TEMPORARY_CHAT]: {},
|
|
155
|
+
[PermissionTypes.RUN_CODE]: {},
|
|
126
156
|
},
|
|
127
157
|
[SystemRoles.USER]: {
|
|
128
158
|
name: SystemRoles.USER,
|
|
@@ -130,5 +160,7 @@ export const roleDefaults = defaultRolesSchema.parse({
|
|
|
130
160
|
[PermissionTypes.BOOKMARKS]: {},
|
|
131
161
|
[PermissionTypes.AGENTS]: {},
|
|
132
162
|
[PermissionTypes.MULTI_CONVO]: {},
|
|
163
|
+
[PermissionTypes.TEMPORARY_CHAT]: {},
|
|
164
|
+
[PermissionTypes.RUN_CODE]: {},
|
|
133
165
|
},
|
|
134
166
|
});
|