librechat-data-provider 0.7.4 → 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 (49) 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/dist/react-query/package.json +1 -1
  9. package/package.json +6 -6
  10. package/react-query/package.json +1 -1
  11. package/server-rollup.config.js +3 -3
  12. package/specs/actions.spec.ts +700 -36
  13. package/specs/azure.spec.ts +8 -5
  14. package/specs/filetypes.spec.ts +1 -7
  15. package/specs/mcp.spec.ts +52 -0
  16. package/specs/openapiSpecs.ts +127 -0
  17. package/specs/utils.spec.ts +129 -0
  18. package/src/actions.ts +311 -101
  19. package/src/api-endpoints.ts +70 -13
  20. package/src/artifacts.ts +3104 -0
  21. package/src/azure.ts +40 -33
  22. package/src/bedrock.ts +227 -0
  23. package/src/config.ts +344 -78
  24. package/src/createPayload.ts +3 -1
  25. package/src/data-service.ts +353 -90
  26. package/src/file-config.ts +13 -2
  27. package/src/generate.ts +31 -2
  28. package/src/index.ts +12 -4
  29. package/src/keys.ts +17 -0
  30. package/src/mcp.ts +87 -0
  31. package/src/models.ts +1 -1
  32. package/src/parsers.ts +118 -60
  33. package/src/react-query/react-query-service.ts +54 -115
  34. package/src/request.ts +31 -7
  35. package/src/roles.ts +91 -2
  36. package/src/schemas.ts +513 -340
  37. package/src/types/agents.ts +276 -0
  38. package/src/types/assistants.ts +181 -27
  39. package/src/types/files.ts +6 -0
  40. package/src/types/mutations.ts +170 -7
  41. package/src/types/queries.ts +43 -21
  42. package/src/types/runs.ts +23 -0
  43. package/src/types.ts +132 -67
  44. package/src/utils.ts +44 -0
  45. package/src/zod.spec.ts +526 -0
  46. package/src/zod.ts +86 -0
  47. package/tsconfig.json +1 -2
  48. package/specs/parsers.spec.ts +0 -48
  49. 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 = (
@@ -124,6 +123,20 @@ export const useUpdateMessageMutation = (
124
123
  });
125
124
  };
126
125
 
126
+ export const useUpdateMessageContentMutation = (
127
+ conversationId: string,
128
+ ): UseMutationResult<unknown, unknown, t.TUpdateMessageContent, unknown> => {
129
+ const queryClient = useQueryClient();
130
+ return useMutation(
131
+ (payload: t.TUpdateMessageContent) => dataService.updateMessageContent(payload),
132
+ {
133
+ onSuccess: () => {
134
+ queryClient.invalidateQueries([QueryKeys.messages, conversationId]);
135
+ },
136
+ },
137
+ );
138
+ };
139
+
127
140
  export const useUpdateUserKeysMutation = (): UseMutationResult<
128
141
  t.TUser,
129
142
  unknown,
@@ -188,33 +201,6 @@ export const useRevokeAllUserKeysMutation = (): UseMutationResult<unknown> => {
188
201
  });
189
202
  };
190
203
 
191
- export const useGetSearchEnabledQuery = (
192
- config?: UseQueryOptions<boolean>,
193
- ): QueryObserverResult<boolean> => {
194
- return useQuery<boolean>([QueryKeys.searchEnabled], () => dataService.getSearchEnabled(), {
195
- refetchOnWindowFocus: false,
196
- refetchOnReconnect: false,
197
- refetchOnMount: false,
198
- ...config,
199
- });
200
- };
201
-
202
- export const useGetEndpointsQuery = <TData = t.TEndpointsConfig>(
203
- config?: UseQueryOptions<t.TEndpointsConfig, unknown, TData>,
204
- ): QueryObserverResult<TData> => {
205
- return useQuery<t.TEndpointsConfig, unknown, TData>(
206
- [QueryKeys.endpoints],
207
- () => dataService.getAIEndpoints(),
208
- {
209
- staleTime: Infinity,
210
- refetchOnWindowFocus: false,
211
- refetchOnReconnect: false,
212
- refetchOnMount: false,
213
- ...config,
214
- },
215
- );
216
- };
217
-
218
204
  export const useGetModelsQuery = (
219
205
  config?: UseQueryOptions<t.TModelsConfig>,
220
206
  ): QueryObserverResult<t.TModelsConfig> => {
@@ -287,54 +273,22 @@ export const useUpdateTokenCountMutation = (): UseMutationResult<
287
273
  });
288
274
  };
289
275
 
290
- export const useLoginUserMutation = (): UseMutationResult<
291
- t.TLoginResponse,
292
- unknown,
293
- t.TLoginUser,
294
- unknown
295
- > => {
296
- const queryClient = useQueryClient();
297
- return useMutation((payload: t.TLoginUser) => dataService.login(payload), {
298
- onMutate: () => {
299
- queryClient.removeQueries();
300
- localStorage.removeItem(LocalStorageKeys.LAST_CONVO_SETUP);
301
- localStorage.removeItem(`${LocalStorageKeys.LAST_CONVO_SETUP}_0`);
302
- localStorage.removeItem(`${LocalStorageKeys.LAST_CONVO_SETUP}_1`);
303
- localStorage.removeItem(LocalStorageKeys.LAST_MODEL);
304
- localStorage.removeItem(LocalStorageKeys.LAST_TOOLS);
305
- localStorage.removeItem(LocalStorageKeys.FILES_TO_DELETE);
306
- // localStorage.removeItem('lastAssistant');
307
- },
308
- });
309
- };
310
-
311
276
  export const useRegisterUserMutation = (
312
277
  options?: m.RegistrationOptions,
313
278
  ): UseMutationResult<t.TError, unknown, t.TRegisterUser, unknown> => {
314
279
  const queryClient = useQueryClient();
315
- return useMutation((payload: t.TRegisterUser) => dataService.register(payload), {
316
- ...options,
317
- onSuccess: (...args) => {
318
- queryClient.invalidateQueries([QueryKeys.user]);
319
- if (options?.onSuccess) {
320
- options.onSuccess(...args);
321
- }
322
- },
323
- });
324
- };
325
-
326
- export const useRefreshTokenMutation = (): UseMutationResult<
327
- t.TRefreshTokenResponse,
328
- unknown,
329
- unknown,
330
- unknown
331
- > => {
332
- const queryClient = useQueryClient();
333
- return useMutation(() => request.refreshToken(), {
334
- onMutate: () => {
335
- 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
+ },
336
290
  },
337
- });
291
+ );
338
292
  };
339
293
 
340
294
  export const useUserKeyQuery = (
@@ -394,35 +348,20 @@ export const useAvailablePluginsQuery = <TData = s.TPlugin[]>(
394
348
  );
395
349
  };
396
350
 
397
- export const useUpdateUserPluginsMutation = (): UseMutationResult<
398
- t.TUser,
399
- unknown,
400
- t.TUpdateUserPlugins,
401
- unknown
402
- > => {
351
+ export const useUpdateUserPluginsMutation = (
352
+ _options?: m.UpdatePluginAuthOptions,
353
+ ): UseMutationResult<t.TUser, unknown, t.TUpdateUserPlugins, unknown> => {
403
354
  const queryClient = useQueryClient();
355
+ const { onSuccess, ...options } = _options ?? {};
404
356
  return useMutation((payload: t.TUpdateUserPlugins) => dataService.updateUserPlugins(payload), {
405
- onSuccess: () => {
357
+ ...options,
358
+ onSuccess: (...args) => {
406
359
  queryClient.invalidateQueries([QueryKeys.user]);
360
+ onSuccess?.(...args);
407
361
  },
408
362
  });
409
363
  };
410
364
 
411
- export const useGetStartupConfig = (
412
- config?: UseQueryOptions<t.TStartupConfig>,
413
- ): QueryObserverResult<t.TStartupConfig> => {
414
- return useQuery<t.TStartupConfig>(
415
- [QueryKeys.startupConfig],
416
- () => dataService.getStartupConfig(),
417
- {
418
- refetchOnWindowFocus: false,
419
- refetchOnReconnect: false,
420
- refetchOnMount: false,
421
- ...config,
422
- },
423
- );
424
- };
425
-
426
365
  export const useGetCustomConfigSpeechQuery = (
427
366
  config?: UseQueryOptions<t.TCustomConfigSpeechResponse>,
428
367
  ): QueryObserverResult<t.TCustomConfigSpeechResponse> => {
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) => {
@@ -80,8 +87,19 @@ axios.interceptors.response.use(
80
87
  (response) => response,
81
88
  async (error) => {
82
89
  const originalRequest = error.config;
90
+ if (!error.response) {
91
+ return Promise.reject(error);
92
+ }
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
+ }
83
100
 
84
101
  if (error.response.status === 401 && !originalRequest._retry) {
102
+ console.warn('401 error, refreshing token');
85
103
  originalRequest._retry = true;
86
104
 
87
105
  if (isRefreshing) {
@@ -99,17 +117,22 @@ axios.interceptors.response.use(
99
117
  isRefreshing = true;
100
118
 
101
119
  try {
102
- const { token } = await refreshToken(
120
+ const response = await refreshToken(
103
121
  // Handle edge case where we get a blank screen if the initial 401 error is from a refresh token request
104
- originalRequest.url?.includes('api/auth/refresh') ? true : false,
122
+ originalRequest.url?.includes('api/auth/refresh') === true ? true : false,
105
123
  );
106
124
 
125
+ const token = response?.token ?? '';
126
+
107
127
  if (token) {
108
128
  originalRequest.headers['Authorization'] = 'Bearer ' + token;
109
- setTokenHeader(token);
110
- window.dispatchEvent(new CustomEvent('tokenUpdated', { detail: token }));
129
+ dispatchTokenUpdatedEvent(token);
111
130
  processQueue(null, token);
112
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
+ );
113
136
  } else {
114
137
  window.location.href = '/login';
115
138
  }
@@ -136,4 +159,5 @@ export default {
136
159
  deleteWithOptions: _deleteWithOptions,
137
160
  patch: _patch,
138
161
  refreshToken,
162
+ dispatchTokenUpdatedEvent,
139
163
  };
package/src/roles.ts CHANGED
@@ -22,6 +22,26 @@ export enum PermissionTypes {
22
22
  * Type for Prompt Permissions
23
23
  */
24
24
  PROMPTS = 'PROMPTS',
25
+ /**
26
+ * Type for Bookmark Permissions
27
+ */
28
+ BOOKMARKS = 'BOOKMARKS',
29
+ /**
30
+ * Type for Agent Permissions
31
+ */
32
+ AGENTS = 'AGENTS',
33
+ /**
34
+ * Type for Multi-Conversation Permissions
35
+ */
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',
25
45
  }
26
46
 
27
47
  /**
@@ -31,6 +51,9 @@ export enum Permissions {
31
51
  SHARED_GLOBAL = 'SHARED_GLOBAL',
32
52
  USE = 'USE',
33
53
  CREATE = 'CREATE',
54
+ UPDATE = 'UPDATE',
55
+ READ = 'READ',
56
+ READ_AUTHOR = 'READ_AUTHOR',
34
57
  SHARE = 'SHARE',
35
58
  }
36
59
 
@@ -38,16 +61,49 @@ export const promptPermissionsSchema = z.object({
38
61
  [Permissions.SHARED_GLOBAL]: z.boolean().default(false),
39
62
  [Permissions.USE]: z.boolean().default(true),
40
63
  [Permissions.CREATE]: z.boolean().default(true),
41
- [Permissions.SHARE]: z.boolean().default(false),
64
+ // [Permissions.SHARE]: z.boolean().default(false),
65
+ });
66
+
67
+ export const bookmarkPermissionsSchema = z.object({
68
+ [Permissions.USE]: z.boolean().default(true),
69
+ });
70
+
71
+ export const agentPermissionsSchema = z.object({
72
+ [Permissions.SHARED_GLOBAL]: z.boolean().default(false),
73
+ [Permissions.USE]: z.boolean().default(true),
74
+ [Permissions.CREATE]: z.boolean().default(true),
75
+ // [Permissions.SHARE]: z.boolean().default(false),
76
+ });
77
+
78
+ export const multiConvoPermissionsSchema = z.object({
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),
42
88
  });
43
89
 
44
90
  export const roleSchema = z.object({
45
91
  name: z.string(),
46
92
  [PermissionTypes.PROMPTS]: promptPermissionsSchema,
93
+ [PermissionTypes.BOOKMARKS]: bookmarkPermissionsSchema,
94
+ [PermissionTypes.AGENTS]: agentPermissionsSchema,
95
+ [PermissionTypes.MULTI_CONVO]: multiConvoPermissionsSchema,
96
+ [PermissionTypes.TEMPORARY_CHAT]: temporaryChatPermissionsSchema,
97
+ [PermissionTypes.RUN_CODE]: runCodePermissionsSchema,
47
98
  });
48
99
 
49
100
  export type TRole = z.infer<typeof roleSchema>;
101
+ export type TAgentPermissions = z.infer<typeof agentPermissionsSchema>;
50
102
  export type TPromptPermissions = z.infer<typeof promptPermissionsSchema>;
103
+ export type TBookmarkPermissions = z.infer<typeof bookmarkPermissionsSchema>;
104
+ export type TMultiConvoPermissions = z.infer<typeof multiConvoPermissionsSchema>;
105
+ export type TTemporaryChatPermissions = z.infer<typeof temporaryChatPermissionsSchema>;
106
+ export type TRunCodePermissions = z.infer<typeof runCodePermissionsSchema>;
51
107
 
52
108
  const defaultRolesSchema = z.object({
53
109
  [SystemRoles.ADMIN]: roleSchema.extend({
@@ -56,12 +112,35 @@ const defaultRolesSchema = z.object({
56
112
  [Permissions.SHARED_GLOBAL]: z.boolean().default(true),
57
113
  [Permissions.USE]: z.boolean().default(true),
58
114
  [Permissions.CREATE]: z.boolean().default(true),
59
- [Permissions.SHARE]: z.boolean().default(true),
115
+ // [Permissions.SHARE]: z.boolean().default(true),
116
+ }),
117
+ [PermissionTypes.BOOKMARKS]: bookmarkPermissionsSchema.extend({
118
+ [Permissions.USE]: z.boolean().default(true),
119
+ }),
120
+ [PermissionTypes.AGENTS]: agentPermissionsSchema.extend({
121
+ [Permissions.SHARED_GLOBAL]: z.boolean().default(true),
122
+ [Permissions.USE]: z.boolean().default(true),
123
+ [Permissions.CREATE]: z.boolean().default(true),
124
+ // [Permissions.SHARE]: z.boolean().default(true),
125
+ }),
126
+ [PermissionTypes.MULTI_CONVO]: multiConvoPermissionsSchema.extend({
127
+ [Permissions.USE]: z.boolean().default(true),
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),
60
134
  }),
61
135
  }),
62
136
  [SystemRoles.USER]: roleSchema.extend({
63
137
  name: z.literal(SystemRoles.USER),
64
138
  [PermissionTypes.PROMPTS]: promptPermissionsSchema,
139
+ [PermissionTypes.BOOKMARKS]: bookmarkPermissionsSchema,
140
+ [PermissionTypes.AGENTS]: agentPermissionsSchema,
141
+ [PermissionTypes.MULTI_CONVO]: multiConvoPermissionsSchema,
142
+ [PermissionTypes.TEMPORARY_CHAT]: temporaryChatPermissionsSchema,
143
+ [PermissionTypes.RUN_CODE]: runCodePermissionsSchema,
65
144
  }),
66
145
  });
67
146
 
@@ -69,9 +148,19 @@ export const roleDefaults = defaultRolesSchema.parse({
69
148
  [SystemRoles.ADMIN]: {
70
149
  name: SystemRoles.ADMIN,
71
150
  [PermissionTypes.PROMPTS]: {},
151
+ [PermissionTypes.BOOKMARKS]: {},
152
+ [PermissionTypes.AGENTS]: {},
153
+ [PermissionTypes.MULTI_CONVO]: {},
154
+ [PermissionTypes.TEMPORARY_CHAT]: {},
155
+ [PermissionTypes.RUN_CODE]: {},
72
156
  },
73
157
  [SystemRoles.USER]: {
74
158
  name: SystemRoles.USER,
75
159
  [PermissionTypes.PROMPTS]: {},
160
+ [PermissionTypes.BOOKMARKS]: {},
161
+ [PermissionTypes.AGENTS]: {},
162
+ [PermissionTypes.MULTI_CONVO]: {},
163
+ [PermissionTypes.TEMPORARY_CHAT]: {},
164
+ [PermissionTypes.RUN_CODE]: {},
76
165
  },
77
166
  });