librechat-data-provider 0.4.0 → 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 +123 -12
- 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 +6 -0
- package/tsconfig.spec.json +10 -0
- package/src/react-query/assistants.ts +0 -138
package/src/config.ts
CHANGED
|
@@ -1,9 +1,36 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
1
2
|
import { z } from 'zod';
|
|
2
3
|
import { EModelEndpoint, eModelEndpointSchema } from './schemas';
|
|
4
|
+
import { fileConfigSchema } from './file-config';
|
|
3
5
|
import { FileSources } from './types/files';
|
|
4
6
|
|
|
5
7
|
export const fileSourceSchema = z.nativeEnum(FileSources);
|
|
6
8
|
|
|
9
|
+
export const assistantEndpointSchema = z.object({
|
|
10
|
+
/* assistants specific */
|
|
11
|
+
disableBuilder: z.boolean().optional(),
|
|
12
|
+
pollIntervalMs: z.number().optional(),
|
|
13
|
+
timeoutMs: z.number().optional(),
|
|
14
|
+
supportedIds: z.array(z.string()).min(1).optional(),
|
|
15
|
+
excludedIds: z.array(z.string()).min(1).optional(),
|
|
16
|
+
/* general */
|
|
17
|
+
apiKey: z.string().optional(),
|
|
18
|
+
baseURL: z.string().optional(),
|
|
19
|
+
models: z
|
|
20
|
+
.object({
|
|
21
|
+
default: z.array(z.string()).min(1),
|
|
22
|
+
fetch: z.boolean().optional(),
|
|
23
|
+
userIdQuery: z.boolean().optional(),
|
|
24
|
+
})
|
|
25
|
+
.optional(),
|
|
26
|
+
titleConvo: z.boolean().optional(),
|
|
27
|
+
titleMethod: z.union([z.literal('completion'), z.literal('functions')]).optional(),
|
|
28
|
+
titleModel: z.string().optional(),
|
|
29
|
+
headers: z.record(z.any()).optional(),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export type TAssistantEndpoint = z.infer<typeof assistantEndpointSchema>;
|
|
33
|
+
|
|
7
34
|
export const endpointSchema = z.object({
|
|
8
35
|
name: z.string().refine((value) => !eModelEndpointSchema.safeParse(value).success, {
|
|
9
36
|
message: `Value cannot be one of the default endpoint (EModelEndpoint) values: ${Object.values(
|
|
@@ -25,6 +52,19 @@ export const endpointSchema = z.object({
|
|
|
25
52
|
forcePrompt: z.boolean().optional(),
|
|
26
53
|
modelDisplayLabel: z.string().optional(),
|
|
27
54
|
headers: z.record(z.any()).optional(),
|
|
55
|
+
addParams: z.record(z.any()).optional(),
|
|
56
|
+
dropParams: z.array(z.string()).optional(),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export const rateLimitSchema = z.object({
|
|
60
|
+
fileUploads: z
|
|
61
|
+
.object({
|
|
62
|
+
ipMax: z.number().optional(),
|
|
63
|
+
ipWindowInMinutes: z.number().optional(),
|
|
64
|
+
userMax: z.number().optional(),
|
|
65
|
+
userWindowInMinutes: z.number().optional(),
|
|
66
|
+
})
|
|
67
|
+
.optional(),
|
|
28
68
|
});
|
|
29
69
|
|
|
30
70
|
export const configSchema = z.object({
|
|
@@ -37,11 +77,17 @@ export const configSchema = z.object({
|
|
|
37
77
|
allowedDomains: z.array(z.string()).optional(),
|
|
38
78
|
})
|
|
39
79
|
.optional(),
|
|
80
|
+
rateLimits: rateLimitSchema.optional(),
|
|
81
|
+
fileConfig: fileConfigSchema.optional(),
|
|
40
82
|
endpoints: z
|
|
41
83
|
.object({
|
|
42
|
-
|
|
84
|
+
[EModelEndpoint.assistants]: assistantEndpointSchema.optional(),
|
|
85
|
+
custom: z.array(endpointSchema.partial()).optional(),
|
|
43
86
|
})
|
|
44
87
|
.strict()
|
|
88
|
+
.refine((data) => Object.keys(data).length > 0, {
|
|
89
|
+
message: 'At least one `endpoints` field must be provided.',
|
|
90
|
+
})
|
|
45
91
|
.optional(),
|
|
46
92
|
});
|
|
47
93
|
|
|
@@ -54,7 +100,7 @@ export enum KnownEndpoints {
|
|
|
54
100
|
|
|
55
101
|
export const defaultEndpoints: EModelEndpoint[] = [
|
|
56
102
|
EModelEndpoint.openAI,
|
|
57
|
-
EModelEndpoint.
|
|
103
|
+
EModelEndpoint.assistants,
|
|
58
104
|
EModelEndpoint.azureOpenAI,
|
|
59
105
|
EModelEndpoint.bingAI,
|
|
60
106
|
EModelEndpoint.chatGPTBrowser,
|
|
@@ -66,7 +112,7 @@ export const defaultEndpoints: EModelEndpoint[] = [
|
|
|
66
112
|
|
|
67
113
|
export const alternateName = {
|
|
68
114
|
[EModelEndpoint.openAI]: 'OpenAI',
|
|
69
|
-
[EModelEndpoint.
|
|
115
|
+
[EModelEndpoint.assistants]: 'Assistants',
|
|
70
116
|
[EModelEndpoint.azureOpenAI]: 'Azure OpenAI',
|
|
71
117
|
[EModelEndpoint.bingAI]: 'Bing',
|
|
72
118
|
[EModelEndpoint.chatGPTBrowser]: 'ChatGPT',
|
|
@@ -77,6 +123,21 @@ export const alternateName = {
|
|
|
77
123
|
};
|
|
78
124
|
|
|
79
125
|
export const defaultModels = {
|
|
126
|
+
[EModelEndpoint.assistants]: [
|
|
127
|
+
'gpt-3.5-turbo-0125',
|
|
128
|
+
'gpt-4-0125-preview',
|
|
129
|
+
'gpt-4-turbo-preview',
|
|
130
|
+
'gpt-4-1106-preview',
|
|
131
|
+
'gpt-3.5-turbo-1106',
|
|
132
|
+
'gpt-3.5-turbo-16k-0613',
|
|
133
|
+
'gpt-3.5-turbo-16k',
|
|
134
|
+
'gpt-3.5-turbo',
|
|
135
|
+
'gpt-4',
|
|
136
|
+
'gpt-4-0314',
|
|
137
|
+
'gpt-4-32k-0314',
|
|
138
|
+
'gpt-4-0613',
|
|
139
|
+
'gpt-3.5-turbo-0613',
|
|
140
|
+
],
|
|
80
141
|
[EModelEndpoint.google]: [
|
|
81
142
|
'gemini-pro',
|
|
82
143
|
'gemini-pro-vision',
|
|
@@ -121,6 +182,14 @@ export const defaultModels = {
|
|
|
121
182
|
],
|
|
122
183
|
};
|
|
123
184
|
|
|
185
|
+
export const supportsRetrieval = new Set([
|
|
186
|
+
'gpt-3.5-turbo-0125',
|
|
187
|
+
'gpt-4-0125-preview',
|
|
188
|
+
'gpt-4-turbo-preview',
|
|
189
|
+
'gpt-4-1106-preview',
|
|
190
|
+
'gpt-3.5-turbo-1106',
|
|
191
|
+
]);
|
|
192
|
+
|
|
124
193
|
export const EndpointURLs: { [key in EModelEndpoint]: string } = {
|
|
125
194
|
[EModelEndpoint.openAI]: `/api/ask/${EModelEndpoint.openAI}`,
|
|
126
195
|
[EModelEndpoint.bingAI]: `/api/ask/${EModelEndpoint.bingAI}`,
|
|
@@ -130,7 +199,7 @@ export const EndpointURLs: { [key in EModelEndpoint]: string } = {
|
|
|
130
199
|
[EModelEndpoint.gptPlugins]: `/api/ask/${EModelEndpoint.gptPlugins}`,
|
|
131
200
|
[EModelEndpoint.azureOpenAI]: `/api/ask/${EModelEndpoint.azureOpenAI}`,
|
|
132
201
|
[EModelEndpoint.chatGPTBrowser]: `/api/ask/${EModelEndpoint.chatGPTBrowser}`,
|
|
133
|
-
[EModelEndpoint.
|
|
202
|
+
[EModelEndpoint.assistants]: '/api/assistants/chat',
|
|
134
203
|
};
|
|
135
204
|
|
|
136
205
|
export const modularEndpoints = new Set<EModelEndpoint | string>([
|
|
@@ -142,14 +211,6 @@ export const modularEndpoints = new Set<EModelEndpoint | string>([
|
|
|
142
211
|
EModelEndpoint.custom,
|
|
143
212
|
]);
|
|
144
213
|
|
|
145
|
-
export const supportsFiles = {
|
|
146
|
-
[EModelEndpoint.openAI]: true,
|
|
147
|
-
[EModelEndpoint.google]: true,
|
|
148
|
-
[EModelEndpoint.assistant]: true,
|
|
149
|
-
[EModelEndpoint.azureOpenAI]: true,
|
|
150
|
-
[EModelEndpoint.custom]: true,
|
|
151
|
-
};
|
|
152
|
-
|
|
153
214
|
export const supportsBalanceCheck = {
|
|
154
215
|
[EModelEndpoint.openAI]: true,
|
|
155
216
|
[EModelEndpoint.azureOpenAI]: true,
|
|
@@ -159,6 +220,19 @@ export const supportsBalanceCheck = {
|
|
|
159
220
|
|
|
160
221
|
export const visionModels = ['gpt-4-vision', 'llava-13b', 'gemini-pro-vision'];
|
|
161
222
|
|
|
223
|
+
export function validateVisionModel(
|
|
224
|
+
model: string | undefined,
|
|
225
|
+
additionalModels: string[] | undefined = [],
|
|
226
|
+
) {
|
|
227
|
+
if (!model) {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return visionModels.concat(additionalModels).some((visionModel) => model.includes(visionModel));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export const imageGenTools = new Set(['dalle', 'dall-e', 'stable-diffusion']);
|
|
235
|
+
|
|
162
236
|
/**
|
|
163
237
|
* Enum for cache keys.
|
|
164
238
|
*/
|
|
@@ -175,6 +249,11 @@ export enum CacheKeys {
|
|
|
175
249
|
* Key for the title generation cache.
|
|
176
250
|
*/
|
|
177
251
|
GEN_TITLE = 'genTitle',
|
|
252
|
+
/**
|
|
253
|
+
/**
|
|
254
|
+
* Key for the tools cache.
|
|
255
|
+
*/
|
|
256
|
+
TOOLS = 'tools',
|
|
178
257
|
/**
|
|
179
258
|
* Key for the model config cache.
|
|
180
259
|
*/
|
|
@@ -195,10 +274,18 @@ export enum CacheKeys {
|
|
|
195
274
|
* Key for the custom config cache.
|
|
196
275
|
*/
|
|
197
276
|
CUSTOM_CONFIG = 'customConfig',
|
|
277
|
+
/**
|
|
278
|
+
* Key for accessing Abort Keys
|
|
279
|
+
*/
|
|
280
|
+
ABORT_KEYS = 'abortKeys',
|
|
198
281
|
/**
|
|
199
282
|
* Key for the override config cache.
|
|
200
283
|
*/
|
|
201
284
|
OVERRIDE_CONFIG = 'overrideConfig',
|
|
285
|
+
/**
|
|
286
|
+
* Key for accessing File Upload Violations (exceeding limit).
|
|
287
|
+
*/
|
|
288
|
+
FILE_UPLOAD_LIMIT = 'file_upload_limit',
|
|
202
289
|
}
|
|
203
290
|
|
|
204
291
|
/**
|
|
@@ -260,3 +347,27 @@ export enum SettingsTabValues {
|
|
|
260
347
|
*/
|
|
261
348
|
ACCOUNT = 'account',
|
|
262
349
|
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Enum for app-wide constants
|
|
353
|
+
*/
|
|
354
|
+
export enum Constants {
|
|
355
|
+
/**
|
|
356
|
+
* Key for the app's version.
|
|
357
|
+
*/
|
|
358
|
+
VERSION = 'v0.6.9',
|
|
359
|
+
/**
|
|
360
|
+
* Key for the Custom Config's version (librechat.yaml).
|
|
361
|
+
*/
|
|
362
|
+
CONFIG_VERSION = '1.0.3',
|
|
363
|
+
/**
|
|
364
|
+
* Standard value for the first message's `parentMessageId` value, to indicate no parent exists.
|
|
365
|
+
*/
|
|
366
|
+
NO_PARENT = '00000000-0000-0000-0000-000000000000',
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export const defaultOrderQuery: {
|
|
370
|
+
order: 'asc';
|
|
371
|
+
} = {
|
|
372
|
+
order: 'asc',
|
|
373
|
+
};
|
package/src/createPayload.ts
CHANGED
|
@@ -12,7 +12,7 @@ export default function createPayload(submission: TSubmission) {
|
|
|
12
12
|
|
|
13
13
|
let server = EndpointURLs[endpointType ?? endpoint];
|
|
14
14
|
|
|
15
|
-
if (isEdited && endpoint === EModelEndpoint.
|
|
15
|
+
if (isEdited && endpoint === EModelEndpoint.assistants) {
|
|
16
16
|
server += '/modify';
|
|
17
17
|
} else if (isEdited) {
|
|
18
18
|
server = server.replace('/ask/', '/edit/');
|
|
@@ -32,9 +32,5 @@ export default function createPayload(submission: TSubmission) {
|
|
|
32
32
|
conversationId,
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
if (endpoint === EModelEndpoint.assistant) {
|
|
36
|
-
payload.messages = messages;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
35
|
return { server, payload };
|
|
40
36
|
}
|
package/src/data-service.ts
CHANGED
|
@@ -196,23 +196,57 @@ export const listAssistants = (
|
|
|
196
196
|
return request.get(endpoints.assistants(), { params });
|
|
197
197
|
};
|
|
198
198
|
|
|
199
|
+
/* Tools */
|
|
200
|
+
|
|
201
|
+
export const getAvailableTools = (): Promise<s.TPlugin[]> => {
|
|
202
|
+
return request.get(`${endpoints.assistants()}/tools`);
|
|
203
|
+
};
|
|
204
|
+
|
|
199
205
|
/* Files */
|
|
200
206
|
|
|
201
207
|
export const getFiles = (): Promise<f.TFile[]> => {
|
|
202
208
|
return request.get(endpoints.files());
|
|
203
209
|
};
|
|
204
210
|
|
|
211
|
+
export const getFileConfig = (): Promise<f.FileConfig> => {
|
|
212
|
+
return request.get(`${endpoints.files()}/config`);
|
|
213
|
+
};
|
|
214
|
+
|
|
205
215
|
export const uploadImage = (data: FormData): Promise<f.TFileUpload> => {
|
|
206
216
|
return request.postMultiPart(endpoints.images(), data);
|
|
207
217
|
};
|
|
208
218
|
|
|
219
|
+
export const uploadFile = (data: FormData): Promise<f.TFileUpload> => {
|
|
220
|
+
return request.postMultiPart(endpoints.files(), data);
|
|
221
|
+
};
|
|
222
|
+
|
|
209
223
|
export const uploadAvatar = (data: FormData): Promise<f.AvatarUploadResponse> => {
|
|
210
224
|
return request.postMultiPart(endpoints.avatar(), data);
|
|
211
225
|
};
|
|
212
226
|
|
|
213
|
-
export const
|
|
227
|
+
export const uploadAssistantAvatar = (data: m.AssistantAvatarVariables): Promise<a.Assistant> => {
|
|
228
|
+
return request.postMultiPart(endpoints.assistants(`avatar/${data.assistant_id}`), data.formData);
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
export const updateAction = (data: m.UpdateActionVariables): Promise<m.UpdateActionResponse> => {
|
|
232
|
+
const { assistant_id, ...body } = data;
|
|
233
|
+
return request.post(endpoints.assistants(`actions/${assistant_id}`), body);
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
export function getActions(): Promise<a.Action[]> {
|
|
237
|
+
return request.get(endpoints.assistants('actions'));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function getAssistantDocs(): Promise<a.AssistantDocument[]> {
|
|
241
|
+
return request.get(endpoints.assistants('documents'));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export const deleteFiles = async (
|
|
245
|
+
files: f.BatchFile[],
|
|
246
|
+
assistant_id?: string,
|
|
247
|
+
): Promise<f.DeleteFilesResponse> =>
|
|
214
248
|
request.deleteWithOptions(endpoints.files(), {
|
|
215
|
-
data: { files },
|
|
249
|
+
data: { files, assistant_id },
|
|
216
250
|
});
|
|
217
251
|
|
|
218
252
|
/* conversations */
|
|
@@ -237,3 +271,6 @@ export const listConversationsByQuery = (
|
|
|
237
271
|
return request.get(endpoints.conversations(pageNumber));
|
|
238
272
|
}
|
|
239
273
|
};
|
|
274
|
+
|
|
275
|
+
export const deleteAction = async (assistant_id: string, action_id: string): Promise<void> =>
|
|
276
|
+
request.delete(endpoints.assistants(`actions/${assistant_id}/${action_id}`));
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { EModelEndpoint } from './schemas';
|
|
4
|
+
import type { FileConfig, EndpointFileConfig } from './types/files';
|
|
5
|
+
|
|
6
|
+
export const supportsFiles = {
|
|
7
|
+
[EModelEndpoint.openAI]: true,
|
|
8
|
+
[EModelEndpoint.google]: true,
|
|
9
|
+
[EModelEndpoint.assistants]: true,
|
|
10
|
+
[EModelEndpoint.azureOpenAI]: true,
|
|
11
|
+
[EModelEndpoint.custom]: true,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const excelFileTypes = [
|
|
15
|
+
'application/vnd.ms-excel',
|
|
16
|
+
'application/msexcel',
|
|
17
|
+
'application/x-msexcel',
|
|
18
|
+
'application/x-ms-excel',
|
|
19
|
+
'application/x-excel',
|
|
20
|
+
'application/x-dos_ms_excel',
|
|
21
|
+
'application/xls',
|
|
22
|
+
'application/x-xls',
|
|
23
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
export const fullMimeTypesList = [
|
|
27
|
+
'text/x-c',
|
|
28
|
+
'text/x-c++',
|
|
29
|
+
'application/csv',
|
|
30
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
31
|
+
'text/html',
|
|
32
|
+
'text/x-java',
|
|
33
|
+
'application/json',
|
|
34
|
+
'text/markdown',
|
|
35
|
+
'application/pdf',
|
|
36
|
+
'text/x-php',
|
|
37
|
+
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
38
|
+
'text/x-python',
|
|
39
|
+
'text/x-script.python',
|
|
40
|
+
'text/x-ruby',
|
|
41
|
+
'text/x-tex',
|
|
42
|
+
'text/plain',
|
|
43
|
+
'text/css',
|
|
44
|
+
'image/jpeg',
|
|
45
|
+
'text/javascript',
|
|
46
|
+
'image/gif',
|
|
47
|
+
'image/png',
|
|
48
|
+
'application/x-tar',
|
|
49
|
+
'application/typescript',
|
|
50
|
+
'application/xml',
|
|
51
|
+
'application/zip',
|
|
52
|
+
...excelFileTypes,
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
export const codeInterpreterMimeTypesList = [
|
|
56
|
+
'text/x-c',
|
|
57
|
+
'text/x-c++',
|
|
58
|
+
'application/csv',
|
|
59
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
60
|
+
'text/html',
|
|
61
|
+
'text/x-java',
|
|
62
|
+
'application/json',
|
|
63
|
+
'text/markdown',
|
|
64
|
+
'application/pdf',
|
|
65
|
+
'text/x-php',
|
|
66
|
+
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
67
|
+
'text/x-python',
|
|
68
|
+
'text/x-script.python',
|
|
69
|
+
'text/x-ruby',
|
|
70
|
+
'text/x-tex',
|
|
71
|
+
'text/plain',
|
|
72
|
+
'text/css',
|
|
73
|
+
'image/jpeg',
|
|
74
|
+
'text/javascript',
|
|
75
|
+
'image/gif',
|
|
76
|
+
'image/png',
|
|
77
|
+
'application/x-tar',
|
|
78
|
+
'application/typescript',
|
|
79
|
+
'application/xml',
|
|
80
|
+
'application/zip',
|
|
81
|
+
...excelFileTypes,
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
export const retrievalMimeTypesList = [
|
|
85
|
+
'text/x-c',
|
|
86
|
+
'text/x-c++',
|
|
87
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
88
|
+
'text/html',
|
|
89
|
+
'text/x-java',
|
|
90
|
+
'application/json',
|
|
91
|
+
'text/markdown',
|
|
92
|
+
'application/pdf',
|
|
93
|
+
'text/x-php',
|
|
94
|
+
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
95
|
+
'text/x-python',
|
|
96
|
+
'text/x-script.python',
|
|
97
|
+
'text/x-ruby',
|
|
98
|
+
'text/x-tex',
|
|
99
|
+
'text/plain',
|
|
100
|
+
];
|
|
101
|
+
|
|
102
|
+
export const imageExtRegex = /\.(jpg|jpeg|png|gif|webp)$/i;
|
|
103
|
+
|
|
104
|
+
export const excelMimeTypes =
|
|
105
|
+
/^application\/(vnd\.ms-excel|msexcel|x-msexcel|x-ms-excel|x-excel|x-dos_ms_excel|xls|x-xls|vnd\.openxmlformats-officedocument\.spreadsheetml\.sheet)$/;
|
|
106
|
+
|
|
107
|
+
export const textMimeTypes =
|
|
108
|
+
/^(text\/(x-c|x-c\+\+|x-java|html|markdown|x-php|x-python|x-script\.python|x-ruby|x-tex|plain|css|javascript|csv))$/;
|
|
109
|
+
|
|
110
|
+
export const applicationMimeTypes =
|
|
111
|
+
/^(application\/(csv|json|pdf|x-tar|typescript|vnd\.openxmlformats-officedocument\.(wordprocessingml\.document|presentationml\.presentation|spreadsheetml\.sheet)|xml|zip))$/;
|
|
112
|
+
|
|
113
|
+
export const imageMimeTypes = /^image\/(jpeg|gif|png|webp)$/;
|
|
114
|
+
|
|
115
|
+
export const supportedMimeTypes = [
|
|
116
|
+
textMimeTypes,
|
|
117
|
+
excelMimeTypes,
|
|
118
|
+
applicationMimeTypes,
|
|
119
|
+
imageMimeTypes,
|
|
120
|
+
];
|
|
121
|
+
|
|
122
|
+
export const codeInterpreterMimeTypes = [
|
|
123
|
+
textMimeTypes,
|
|
124
|
+
excelMimeTypes,
|
|
125
|
+
applicationMimeTypes,
|
|
126
|
+
imageMimeTypes,
|
|
127
|
+
];
|
|
128
|
+
|
|
129
|
+
export const retrievalMimeTypes = [
|
|
130
|
+
/^(text\/(x-c|x-c\+\+|html|x-java|markdown|x-php|x-python|x-script\.python|x-ruby|x-tex|plain))$/,
|
|
131
|
+
/^(application\/(json|pdf|vnd\.openxmlformats-officedocument\.(wordprocessingml\.document|presentationml\.presentation)))$/,
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
export const megabyte = 1024 * 1024;
|
|
135
|
+
/** Helper function to get megabytes value */
|
|
136
|
+
export const mbToBytes = (mb: number): number => mb * megabyte;
|
|
137
|
+
|
|
138
|
+
export const fileConfig = {
|
|
139
|
+
endpoints: {
|
|
140
|
+
[EModelEndpoint.assistants]: {
|
|
141
|
+
fileLimit: 10,
|
|
142
|
+
fileSizeLimit: mbToBytes(512),
|
|
143
|
+
totalSizeLimit: mbToBytes(512),
|
|
144
|
+
supportedMimeTypes,
|
|
145
|
+
disabled: false,
|
|
146
|
+
},
|
|
147
|
+
default: {
|
|
148
|
+
fileLimit: 10,
|
|
149
|
+
fileSizeLimit: mbToBytes(20),
|
|
150
|
+
totalSizeLimit: mbToBytes(25),
|
|
151
|
+
supportedMimeTypes: [imageMimeTypes],
|
|
152
|
+
disabled: false,
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
serverFileSizeLimit: mbToBytes(512),
|
|
156
|
+
avatarSizeLimit: mbToBytes(2),
|
|
157
|
+
checkType: function (fileType: string, supportedTypes: RegExp[] = supportedMimeTypes) {
|
|
158
|
+
return supportedTypes.some((regex) => regex.test(fileType));
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const supportedMimeTypesSchema = z
|
|
163
|
+
.array(z.any())
|
|
164
|
+
.optional()
|
|
165
|
+
.refine(
|
|
166
|
+
(mimeTypes) => {
|
|
167
|
+
if (!mimeTypes) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
return mimeTypes.every(
|
|
171
|
+
(mimeType) => mimeType instanceof RegExp || typeof mimeType === 'string',
|
|
172
|
+
);
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
message: 'Each mimeType must be a string or a RegExp object.',
|
|
176
|
+
},
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
export const endpointFileConfigSchema = z.object({
|
|
180
|
+
disabled: z.boolean().optional(),
|
|
181
|
+
fileLimit: z.number().min(0).optional(),
|
|
182
|
+
fileSizeLimit: z.number().min(0).optional(),
|
|
183
|
+
totalSizeLimit: z.number().min(0).optional(),
|
|
184
|
+
supportedMimeTypes: supportedMimeTypesSchema.optional(),
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
export const fileConfigSchema = z.object({
|
|
188
|
+
endpoints: z.record(endpointFileConfigSchema).optional(),
|
|
189
|
+
serverFileSizeLimit: z.number().min(0).optional(),
|
|
190
|
+
avatarSizeLimit: z.number().min(0).optional(),
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
/** Helper function to safely convert string patterns to RegExp objects */
|
|
194
|
+
export const convertStringsToRegex = (patterns: string[]): RegExp[] =>
|
|
195
|
+
patterns.reduce((acc: RegExp[], pattern) => {
|
|
196
|
+
try {
|
|
197
|
+
const regex = new RegExp(pattern);
|
|
198
|
+
acc.push(regex);
|
|
199
|
+
} catch (error) {
|
|
200
|
+
console.error(`Invalid regex pattern "${pattern}" skipped.`);
|
|
201
|
+
}
|
|
202
|
+
return acc;
|
|
203
|
+
}, []);
|
|
204
|
+
|
|
205
|
+
export function mergeFileConfig(dynamic: z.infer<typeof fileConfigSchema> | undefined): FileConfig {
|
|
206
|
+
const mergedConfig = fileConfig as FileConfig;
|
|
207
|
+
if (!dynamic) {
|
|
208
|
+
return mergedConfig;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (dynamic.serverFileSizeLimit !== undefined) {
|
|
212
|
+
mergedConfig.serverFileSizeLimit = mbToBytes(dynamic.serverFileSizeLimit);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (dynamic.avatarSizeLimit !== undefined) {
|
|
216
|
+
mergedConfig.avatarSizeLimit = mbToBytes(dynamic.avatarSizeLimit);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (!dynamic.endpoints) {
|
|
220
|
+
return mergedConfig;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
for (const key in dynamic.endpoints) {
|
|
224
|
+
const dynamicEndpoint = (dynamic.endpoints as Record<string, EndpointFileConfig>)[key];
|
|
225
|
+
|
|
226
|
+
if (!mergedConfig.endpoints[key]) {
|
|
227
|
+
mergedConfig.endpoints[key] = {};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const mergedEndpoint = mergedConfig.endpoints[key];
|
|
231
|
+
|
|
232
|
+
if (dynamicEndpoint.disabled === true) {
|
|
233
|
+
mergedEndpoint.disabled = true;
|
|
234
|
+
mergedEndpoint.fileLimit = 0;
|
|
235
|
+
mergedEndpoint.fileSizeLimit = 0;
|
|
236
|
+
mergedEndpoint.totalSizeLimit = 0;
|
|
237
|
+
mergedEndpoint.supportedMimeTypes = [];
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (dynamicEndpoint.fileSizeLimit !== undefined) {
|
|
242
|
+
mergedEndpoint.fileSizeLimit = mbToBytes(dynamicEndpoint.fileSizeLimit);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (dynamicEndpoint.totalSizeLimit !== undefined) {
|
|
246
|
+
mergedEndpoint.totalSizeLimit = mbToBytes(dynamicEndpoint.totalSizeLimit);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const configKeys = ['fileLimit'] as const;
|
|
250
|
+
configKeys.forEach((field) => {
|
|
251
|
+
if (dynamicEndpoint[field] !== undefined) {
|
|
252
|
+
mergedEndpoint[field] = dynamicEndpoint[field];
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
if (dynamicEndpoint.supportedMimeTypes) {
|
|
257
|
+
mergedEndpoint.supportedMimeTypes = convertStringsToRegex(
|
|
258
|
+
dynamicEndpoint.supportedMimeTypes as unknown as string[],
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return mergedConfig;
|
|
264
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* config */
|
|
2
2
|
export * from './config';
|
|
3
|
+
export * from './file-config';
|
|
3
4
|
/* schema helpers */
|
|
4
5
|
export * from './parsers';
|
|
5
6
|
/* types (exports schemas from `./types` as they contain needed in other defs) */
|
|
@@ -17,4 +18,5 @@ import * as dataService from './data-service';
|
|
|
17
18
|
export { dataService };
|
|
18
19
|
/* general helpers */
|
|
19
20
|
export * from './sse';
|
|
21
|
+
export * from './actions';
|
|
20
22
|
export { default as createPayload } from './createPayload';
|
package/src/keys.ts
CHANGED
|
@@ -18,13 +18,20 @@ export enum QueryKeys {
|
|
|
18
18
|
assistant = 'assistant',
|
|
19
19
|
endpointsConfigOverride = 'endpointsConfigOverride',
|
|
20
20
|
files = 'files',
|
|
21
|
+
fileConfig = 'fileConfig',
|
|
22
|
+
tools = 'tools',
|
|
23
|
+
actions = 'actions',
|
|
24
|
+
assistantDocs = 'assistantDocs',
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
export enum MutationKeys {
|
|
24
|
-
|
|
28
|
+
fileUpload = 'fileUpload',
|
|
25
29
|
fileDelete = 'fileDelete',
|
|
26
30
|
updatePreset = 'updatePreset',
|
|
27
31
|
deletePreset = 'deletePreset',
|
|
28
32
|
logoutUser = 'logoutUser',
|
|
29
33
|
avatarUpload = 'avatarUpload',
|
|
34
|
+
assistantAvatarUpload = 'assistantAvatarUpload',
|
|
35
|
+
updateAction = 'updateAction',
|
|
36
|
+
deleteAction = 'deleteAction',
|
|
30
37
|
}
|
package/src/parsers.ts
CHANGED
|
@@ -35,7 +35,7 @@ const endpointSchemas: Record<EModelEndpoint, EndpointSchema> = {
|
|
|
35
35
|
[EModelEndpoint.anthropic]: anthropicSchema,
|
|
36
36
|
[EModelEndpoint.chatGPTBrowser]: chatGPTBrowserSchema,
|
|
37
37
|
[EModelEndpoint.gptPlugins]: gptPluginsSchema,
|
|
38
|
-
[EModelEndpoint.
|
|
38
|
+
[EModelEndpoint.assistants]: assistantSchema,
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
// const schemaCreators: Record<EModelEndpoint, (customSchema: DefaultSchemaValues) => EndpointSchema> = {
|
|
@@ -172,16 +172,16 @@ type CompactEndpointSchema =
|
|
|
172
172
|
| typeof compactPluginsSchema;
|
|
173
173
|
|
|
174
174
|
const compactEndpointSchemas: Record<string, CompactEndpointSchema> = {
|
|
175
|
-
openAI: compactOpenAISchema,
|
|
176
|
-
azureOpenAI: compactOpenAISchema,
|
|
177
|
-
custom: compactOpenAISchema,
|
|
178
|
-
|
|
179
|
-
google: compactGoogleSchema,
|
|
175
|
+
[EModelEndpoint.openAI]: compactOpenAISchema,
|
|
176
|
+
[EModelEndpoint.azureOpenAI]: compactOpenAISchema,
|
|
177
|
+
[EModelEndpoint.custom]: compactOpenAISchema,
|
|
178
|
+
[EModelEndpoint.assistants]: assistantSchema,
|
|
179
|
+
[EModelEndpoint.google]: compactGoogleSchema,
|
|
180
180
|
/* BingAI needs all fields */
|
|
181
|
-
bingAI: bingAISchema,
|
|
182
|
-
anthropic: compactAnthropicSchema,
|
|
183
|
-
chatGPTBrowser: compactChatGPTSchema,
|
|
184
|
-
gptPlugins: compactPluginsSchema,
|
|
181
|
+
[EModelEndpoint.bingAI]: bingAISchema,
|
|
182
|
+
[EModelEndpoint.anthropic]: compactAnthropicSchema,
|
|
183
|
+
[EModelEndpoint.chatGPTBrowser]: compactChatGPTSchema,
|
|
184
|
+
[EModelEndpoint.gptPlugins]: compactPluginsSchema,
|
|
185
185
|
};
|
|
186
186
|
|
|
187
187
|
export const parseCompactConvo = ({
|
package/src/react-query/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import * as t from '../types';
|
|
10
10
|
import * as s from '../schemas';
|
|
11
11
|
import * as m from '../types/mutations';
|
|
12
|
+
import { defaultOrderQuery } from '../config';
|
|
12
13
|
import * as dataService from '../data-service';
|
|
13
14
|
import request from '../request';
|
|
14
15
|
import { QueryKeys } from '../keys';
|
|
@@ -136,6 +137,14 @@ export const useRevokeUserKeyMutation = (name: string): UseMutationResult<unknow
|
|
|
136
137
|
return useMutation(() => dataService.revokeUserKey(name), {
|
|
137
138
|
onSuccess: () => {
|
|
138
139
|
queryClient.invalidateQueries([QueryKeys.name]);
|
|
140
|
+
if (name === s.EModelEndpoint.assistants) {
|
|
141
|
+
queryClient.invalidateQueries([QueryKeys.assistants, defaultOrderQuery]);
|
|
142
|
+
queryClient.invalidateQueries([QueryKeys.assistantDocs]);
|
|
143
|
+
queryClient.invalidateQueries([QueryKeys.assistants]);
|
|
144
|
+
queryClient.invalidateQueries([QueryKeys.assistant]);
|
|
145
|
+
queryClient.invalidateQueries([QueryKeys.actions]);
|
|
146
|
+
queryClient.invalidateQueries([QueryKeys.tools]);
|
|
147
|
+
}
|
|
139
148
|
},
|
|
140
149
|
});
|
|
141
150
|
};
|
|
@@ -145,6 +154,12 @@ export const useRevokeAllUserKeysMutation = (): UseMutationResult<unknown> => {
|
|
|
145
154
|
return useMutation(() => dataService.revokeAllUserKeys(), {
|
|
146
155
|
onSuccess: () => {
|
|
147
156
|
queryClient.invalidateQueries([QueryKeys.name]);
|
|
157
|
+
queryClient.invalidateQueries([QueryKeys.assistants, defaultOrderQuery]);
|
|
158
|
+
queryClient.invalidateQueries([QueryKeys.assistantDocs]);
|
|
159
|
+
queryClient.invalidateQueries([QueryKeys.assistants]);
|
|
160
|
+
queryClient.invalidateQueries([QueryKeys.assistant]);
|
|
161
|
+
queryClient.invalidateQueries([QueryKeys.actions]);
|
|
162
|
+
queryClient.invalidateQueries([QueryKeys.tools]);
|
|
148
163
|
},
|
|
149
164
|
});
|
|
150
165
|
};
|
|
@@ -277,7 +292,7 @@ export const useLoginUserMutation = (): UseMutationResult<
|
|
|
277
292
|
localStorage.removeItem('lastSelectedModel');
|
|
278
293
|
localStorage.removeItem('lastSelectedTools');
|
|
279
294
|
localStorage.removeItem('filesToDelete');
|
|
280
|
-
localStorage.removeItem('lastAssistant');
|
|
295
|
+
// localStorage.removeItem('lastAssistant');
|
|
281
296
|
},
|
|
282
297
|
});
|
|
283
298
|
};
|