librechat-data-provider 0.7.78 → 0.7.82

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.
@@ -0,0 +1,90 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Enum for Permission Types
5
+ */
6
+ export enum PermissionTypes {
7
+ /**
8
+ * Type for Prompt Permissions
9
+ */
10
+ PROMPTS = 'PROMPTS',
11
+ /**
12
+ * Type for Bookmark Permissions
13
+ */
14
+ BOOKMARKS = 'BOOKMARKS',
15
+ /**
16
+ * Type for Agent Permissions
17
+ */
18
+ AGENTS = 'AGENTS',
19
+ /**
20
+ * Type for Multi-Conversation Permissions
21
+ */
22
+ MULTI_CONVO = 'MULTI_CONVO',
23
+ /**
24
+ * Type for Temporary Chat
25
+ */
26
+ TEMPORARY_CHAT = 'TEMPORARY_CHAT',
27
+ /**
28
+ * Type for using the "Run Code" LC Code Interpreter API feature
29
+ */
30
+ RUN_CODE = 'RUN_CODE',
31
+ }
32
+
33
+ /**
34
+ * Enum for Role-Based Access Control Constants
35
+ */
36
+ export enum Permissions {
37
+ SHARED_GLOBAL = 'SHARED_GLOBAL',
38
+ USE = 'USE',
39
+ CREATE = 'CREATE',
40
+ UPDATE = 'UPDATE',
41
+ READ = 'READ',
42
+ READ_AUTHOR = 'READ_AUTHOR',
43
+ SHARE = 'SHARE',
44
+ }
45
+
46
+ export const promptPermissionsSchema = z.object({
47
+ [Permissions.SHARED_GLOBAL]: z.boolean().default(false),
48
+ [Permissions.USE]: z.boolean().default(true),
49
+ [Permissions.CREATE]: z.boolean().default(true),
50
+ // [Permissions.SHARE]: z.boolean().default(false),
51
+ });
52
+ export type TPromptPermissions = z.infer<typeof promptPermissionsSchema>;
53
+
54
+ export const bookmarkPermissionsSchema = z.object({
55
+ [Permissions.USE]: z.boolean().default(true),
56
+ });
57
+ export type TBookmarkPermissions = z.infer<typeof bookmarkPermissionsSchema>;
58
+
59
+ export const agentPermissionsSchema = z.object({
60
+ [Permissions.SHARED_GLOBAL]: z.boolean().default(false),
61
+ [Permissions.USE]: z.boolean().default(true),
62
+ [Permissions.CREATE]: z.boolean().default(true),
63
+ // [Permissions.SHARE]: z.boolean().default(false),
64
+ });
65
+ export type TAgentPermissions = z.infer<typeof agentPermissionsSchema>;
66
+
67
+ export const multiConvoPermissionsSchema = z.object({
68
+ [Permissions.USE]: z.boolean().default(true),
69
+ });
70
+ export type TMultiConvoPermissions = z.infer<typeof multiConvoPermissionsSchema>;
71
+
72
+ export const temporaryChatPermissionsSchema = z.object({
73
+ [Permissions.USE]: z.boolean().default(true),
74
+ });
75
+ export type TTemporaryChatPermissions = z.infer<typeof temporaryChatPermissionsSchema>;
76
+
77
+ export const runCodePermissionsSchema = z.object({
78
+ [Permissions.USE]: z.boolean().default(true),
79
+ });
80
+ export type TRunCodePermissions = z.infer<typeof runCodePermissionsSchema>;
81
+
82
+ // Define a single permissions schema that holds all permission types.
83
+ export const permissionsSchema = z.object({
84
+ [PermissionTypes.PROMPTS]: promptPermissionsSchema,
85
+ [PermissionTypes.BOOKMARKS]: bookmarkPermissionsSchema,
86
+ [PermissionTypes.AGENTS]: agentPermissionsSchema,
87
+ [PermissionTypes.MULTI_CONVO]: multiConvoPermissionsSchema,
88
+ [PermissionTypes.TEMPORARY_CHAT]: temporaryChatPermissionsSchema,
89
+ [PermissionTypes.RUN_CODE]: runCodePermissionsSchema,
90
+ });
@@ -4,7 +4,7 @@ import type {
4
4
  UseMutationResult,
5
5
  QueryObserverResult,
6
6
  } from '@tanstack/react-query';
7
- import { initialModelsConfig } from '../config';
7
+ import { Constants, 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';
@@ -29,22 +29,6 @@ export const useAbortRequestWithMessage = (): UseMutationResult<
29
29
  );
30
30
  };
31
31
 
32
- export const useGetMessagesByConvoId = <TData = s.TMessage[]>(
33
- id: string,
34
- config?: UseQueryOptions<s.TMessage[], unknown, TData>,
35
- ): QueryObserverResult<TData> => {
36
- return useQuery<s.TMessage[], unknown, TData>(
37
- [QueryKeys.messages, id],
38
- () => dataService.getMessagesByConvoId(id),
39
- {
40
- refetchOnWindowFocus: false,
41
- refetchOnReconnect: false,
42
- refetchOnMount: false,
43
- ...config,
44
- },
45
- );
46
- };
47
-
48
32
  export const useGetSharedMessages = (
49
33
  shareId: string,
50
34
  config?: UseQueryOptions<t.TSharedMessagesResponse>,
@@ -70,6 +54,10 @@ export const useGetSharedLinkQuery = (
70
54
  [QueryKeys.sharedLinks, conversationId],
71
55
  () => dataService.getSharedLink(conversationId),
72
56
  {
57
+ enabled:
58
+ !!conversationId &&
59
+ conversationId !== Constants.NEW_CONVO &&
60
+ conversationId !== Constants.PENDING_CONVO,
73
61
  refetchOnWindowFocus: false,
74
62
  refetchOnReconnect: false,
75
63
  refetchOnMount: false,
@@ -242,23 +230,6 @@ export const useDeletePresetMutation = (): UseMutationResult<
242
230
  });
243
231
  };
244
232
 
245
- export const useSearchQuery = (
246
- searchQuery: string,
247
- pageNumber: string,
248
- config?: UseQueryOptions<t.TSearchResults>,
249
- ): QueryObserverResult<t.TSearchResults> => {
250
- return useQuery<t.TSearchResults>(
251
- [QueryKeys.searchResults, pageNumber, searchQuery],
252
- () => dataService.searchConversations(searchQuery, pageNumber),
253
- {
254
- refetchOnWindowFocus: false,
255
- refetchOnReconnect: false,
256
- refetchOnMount: false,
257
- ...config,
258
- },
259
- );
260
- };
261
-
262
233
  export const useUpdateTokenCountMutation = (): UseMutationResult<
263
234
  t.TUpdateTokenCountResponse,
264
235
  unknown,
package/src/roles.ts CHANGED
@@ -1,4 +1,15 @@
1
1
  import { z } from 'zod';
2
+ import {
3
+ Permissions,
4
+ PermissionTypes,
5
+ permissionsSchema,
6
+ agentPermissionsSchema,
7
+ promptPermissionsSchema,
8
+ runCodePermissionsSchema,
9
+ bookmarkPermissionsSchema,
10
+ multiConvoPermissionsSchema,
11
+ temporaryChatPermissionsSchema,
12
+ } from './permissions';
2
13
 
3
14
  /**
4
15
  * Enum for System Defined Roles
@@ -14,153 +25,88 @@ export enum SystemRoles {
14
25
  USER = 'USER',
15
26
  }
16
27
 
17
- /**
18
- * Enum for Permission Types
19
- */
20
- export enum PermissionTypes {
21
- /**
22
- * Type for Prompt Permissions
23
- */
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',
45
- }
46
-
47
- /**
48
- * Enum for Role-Based Access Control Constants
49
- */
50
- export enum Permissions {
51
- SHARED_GLOBAL = 'SHARED_GLOBAL',
52
- USE = 'USE',
53
- CREATE = 'CREATE',
54
- UPDATE = 'UPDATE',
55
- READ = 'READ',
56
- READ_AUTHOR = 'READ_AUTHOR',
57
- SHARE = 'SHARE',
58
- }
59
-
60
- export const promptPermissionsSchema = z.object({
61
- [Permissions.SHARED_GLOBAL]: z.boolean().default(false),
62
- [Permissions.USE]: z.boolean().default(true),
63
- [Permissions.CREATE]: z.boolean().default(true),
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),
88
- });
89
-
28
+ // The role schema now only needs to reference the permissions schema.
90
29
  export const roleSchema = z.object({
91
30
  name: z.string(),
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,
31
+ permissions: permissionsSchema,
98
32
  });
99
33
 
100
34
  export type TRole = z.infer<typeof roleSchema>;
101
- export type TAgentPermissions = z.infer<typeof agentPermissionsSchema>;
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>;
107
35
 
36
+ // Define default roles using the new structure.
108
37
  const defaultRolesSchema = z.object({
109
38
  [SystemRoles.ADMIN]: roleSchema.extend({
110
39
  name: z.literal(SystemRoles.ADMIN),
111
- [PermissionTypes.PROMPTS]: promptPermissionsSchema.extend({
112
- [Permissions.SHARED_GLOBAL]: z.boolean().default(true),
113
- [Permissions.USE]: z.boolean().default(true),
114
- [Permissions.CREATE]: 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),
40
+ permissions: permissionsSchema.extend({
41
+ [PermissionTypes.PROMPTS]: promptPermissionsSchema.extend({
42
+ [Permissions.SHARED_GLOBAL]: z.boolean().default(true),
43
+ [Permissions.USE]: z.boolean().default(true),
44
+ [Permissions.CREATE]: z.boolean().default(true),
45
+ // [Permissions.SHARE]: z.boolean().default(true),
46
+ }),
47
+ [PermissionTypes.BOOKMARKS]: bookmarkPermissionsSchema.extend({
48
+ [Permissions.USE]: z.boolean().default(true),
49
+ }),
50
+ [PermissionTypes.AGENTS]: agentPermissionsSchema.extend({
51
+ [Permissions.SHARED_GLOBAL]: z.boolean().default(true),
52
+ [Permissions.USE]: z.boolean().default(true),
53
+ [Permissions.CREATE]: z.boolean().default(true),
54
+ // [Permissions.SHARE]: z.boolean().default(true),
55
+ }),
56
+ [PermissionTypes.MULTI_CONVO]: multiConvoPermissionsSchema.extend({
57
+ [Permissions.USE]: z.boolean().default(true),
58
+ }),
59
+ [PermissionTypes.TEMPORARY_CHAT]: temporaryChatPermissionsSchema.extend({
60
+ [Permissions.USE]: z.boolean().default(true),
61
+ }),
62
+ [PermissionTypes.RUN_CODE]: runCodePermissionsSchema.extend({
63
+ [Permissions.USE]: z.boolean().default(true),
64
+ }),
134
65
  }),
135
66
  }),
136
67
  [SystemRoles.USER]: roleSchema.extend({
137
68
  name: z.literal(SystemRoles.USER),
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,
69
+ permissions: permissionsSchema,
144
70
  }),
145
71
  });
146
72
 
147
73
  export const roleDefaults = defaultRolesSchema.parse({
148
74
  [SystemRoles.ADMIN]: {
149
75
  name: SystemRoles.ADMIN,
150
- [PermissionTypes.PROMPTS]: {},
151
- [PermissionTypes.BOOKMARKS]: {},
152
- [PermissionTypes.AGENTS]: {},
153
- [PermissionTypes.MULTI_CONVO]: {},
154
- [PermissionTypes.TEMPORARY_CHAT]: {},
155
- [PermissionTypes.RUN_CODE]: {},
76
+ permissions: {
77
+ [PermissionTypes.PROMPTS]: {
78
+ [Permissions.SHARED_GLOBAL]: true,
79
+ [Permissions.USE]: true,
80
+ [Permissions.CREATE]: true,
81
+ },
82
+ [PermissionTypes.BOOKMARKS]: {
83
+ [Permissions.USE]: true,
84
+ },
85
+ [PermissionTypes.AGENTS]: {
86
+ [Permissions.SHARED_GLOBAL]: true,
87
+ [Permissions.USE]: true,
88
+ [Permissions.CREATE]: true,
89
+ },
90
+ [PermissionTypes.MULTI_CONVO]: {
91
+ [Permissions.USE]: true,
92
+ },
93
+ [PermissionTypes.TEMPORARY_CHAT]: {
94
+ [Permissions.USE]: true,
95
+ },
96
+ [PermissionTypes.RUN_CODE]: {
97
+ [Permissions.USE]: true,
98
+ },
99
+ },
156
100
  },
157
101
  [SystemRoles.USER]: {
158
102
  name: SystemRoles.USER,
159
- [PermissionTypes.PROMPTS]: {},
160
- [PermissionTypes.BOOKMARKS]: {},
161
- [PermissionTypes.AGENTS]: {},
162
- [PermissionTypes.MULTI_CONVO]: {},
163
- [PermissionTypes.TEMPORARY_CHAT]: {},
164
- [PermissionTypes.RUN_CODE]: {},
103
+ permissions: {
104
+ [PermissionTypes.PROMPTS]: {},
105
+ [PermissionTypes.BOOKMARKS]: {},
106
+ [PermissionTypes.AGENTS]: {},
107
+ [PermissionTypes.MULTI_CONVO]: {},
108
+ [PermissionTypes.TEMPORARY_CHAT]: {},
109
+ [PermissionTypes.RUN_CODE]: {},
110
+ },
165
111
  },
166
112
  });