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.
Files changed (45) hide show
  1. package/check_updates.sh +1 -0
  2. package/dist/index.es.js +1 -1
  3. package/dist/index.es.js.map +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/react-query/index.es.js +1 -1
  7. package/dist/react-query/index.es.js.map +1 -1
  8. package/package.json +4 -4
  9. package/server-rollup.config.js +3 -3
  10. package/specs/actions.spec.ts +424 -35
  11. package/specs/azure.spec.ts +8 -5
  12. package/specs/filetypes.spec.ts +1 -7
  13. package/specs/mcp.spec.ts +52 -0
  14. package/specs/utils.spec.ts +129 -0
  15. package/src/actions.ts +209 -82
  16. package/src/api-endpoints.ts +39 -16
  17. package/src/azure.ts +40 -33
  18. package/src/bedrock.ts +84 -4
  19. package/src/config.ts +199 -95
  20. package/src/createPayload.ts +3 -1
  21. package/src/data-service.ts +114 -20
  22. package/src/file-config.ts +10 -2
  23. package/src/generate.ts +1 -1
  24. package/src/index.ts +7 -4
  25. package/src/keys.ts +6 -0
  26. package/src/mcp.ts +87 -0
  27. package/src/models.ts +1 -1
  28. package/src/parsers.ts +43 -43
  29. package/src/react-query/react-query-service.ts +40 -126
  30. package/src/request.ts +28 -7
  31. package/src/roles.ts +33 -1
  32. package/src/schemas.ts +250 -198
  33. package/src/types/agents.ts +57 -1
  34. package/src/types/assistants.ts +33 -2
  35. package/src/types/files.ts +1 -0
  36. package/src/types/mutations.ts +96 -8
  37. package/src/types/queries.ts +39 -21
  38. package/src/types/runs.ts +1 -0
  39. package/src/types.ts +90 -81
  40. package/src/utils.ts +44 -0
  41. package/src/zod.spec.ts +526 -0
  42. package/src/zod.ts +86 -0
  43. package/tsconfig.json +1 -2
  44. package/specs/parsers.spec.ts +0 -48
  45. 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, LocalStorageKeys } from '../config';
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 useGetUserBalance = (
78
- config?: UseQueryOptions<string>,
79
- ): QueryObserverResult<string> => {
80
- return useQuery<string>([QueryKeys.balance], () => dataService.getUserBalance(), {
81
- refetchOnWindowFocus: true,
82
- refetchOnReconnect: true,
83
- refetchOnMount: true,
84
- ...config,
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((payload: t.TRegisterUser) => dataService.register(payload), {
330
- ...options,
331
- onSuccess: (...args) => {
332
- queryClient.invalidateQueries([QueryKeys.user]);
333
- if (options?.onSuccess) {
334
- options.onSuccess(...args);
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 = (): UseMutationResult<
412
- t.TUser,
413
- unknown,
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
- onSuccess: () => {
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, { AxiosRequestConfig, AxiosError } from '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) => _post(endpoints.refreshToken(retry));
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 { token } = await refreshToken(
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
- setTokenHeader(token);
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(false),
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
  });