librechat-data-provider 0.3.9 → 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 +130 -13
- 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 +7 -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(
|
|
@@ -15,6 +42,7 @@ export const endpointSchema = z.object({
|
|
|
15
42
|
models: z.object({
|
|
16
43
|
default: z.array(z.string()).min(1),
|
|
17
44
|
fetch: z.boolean().optional(),
|
|
45
|
+
userIdQuery: z.boolean().optional(),
|
|
18
46
|
}),
|
|
19
47
|
titleConvo: z.boolean().optional(),
|
|
20
48
|
titleMethod: z.union([z.literal('completion'), z.literal('functions')]).optional(),
|
|
@@ -24,6 +52,19 @@ export const endpointSchema = z.object({
|
|
|
24
52
|
forcePrompt: z.boolean().optional(),
|
|
25
53
|
modelDisplayLabel: z.string().optional(),
|
|
26
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(),
|
|
27
68
|
});
|
|
28
69
|
|
|
29
70
|
export const configSchema = z.object({
|
|
@@ -36,11 +77,18 @@ export const configSchema = z.object({
|
|
|
36
77
|
allowedDomains: z.array(z.string()).optional(),
|
|
37
78
|
})
|
|
38
79
|
.optional(),
|
|
80
|
+
rateLimits: rateLimitSchema.optional(),
|
|
81
|
+
fileConfig: fileConfigSchema.optional(),
|
|
39
82
|
endpoints: z
|
|
40
83
|
.object({
|
|
41
|
-
|
|
84
|
+
[EModelEndpoint.assistants]: assistantEndpointSchema.optional(),
|
|
85
|
+
custom: z.array(endpointSchema.partial()).optional(),
|
|
86
|
+
})
|
|
87
|
+
.strict()
|
|
88
|
+
.refine((data) => Object.keys(data).length > 0, {
|
|
89
|
+
message: 'At least one `endpoints` field must be provided.',
|
|
42
90
|
})
|
|
43
|
-
.
|
|
91
|
+
.optional(),
|
|
44
92
|
});
|
|
45
93
|
|
|
46
94
|
export type TCustomConfig = z.infer<typeof configSchema>;
|
|
@@ -52,7 +100,7 @@ export enum KnownEndpoints {
|
|
|
52
100
|
|
|
53
101
|
export const defaultEndpoints: EModelEndpoint[] = [
|
|
54
102
|
EModelEndpoint.openAI,
|
|
55
|
-
EModelEndpoint.
|
|
103
|
+
EModelEndpoint.assistants,
|
|
56
104
|
EModelEndpoint.azureOpenAI,
|
|
57
105
|
EModelEndpoint.bingAI,
|
|
58
106
|
EModelEndpoint.chatGPTBrowser,
|
|
@@ -64,7 +112,7 @@ export const defaultEndpoints: EModelEndpoint[] = [
|
|
|
64
112
|
|
|
65
113
|
export const alternateName = {
|
|
66
114
|
[EModelEndpoint.openAI]: 'OpenAI',
|
|
67
|
-
[EModelEndpoint.
|
|
115
|
+
[EModelEndpoint.assistants]: 'Assistants',
|
|
68
116
|
[EModelEndpoint.azureOpenAI]: 'Azure OpenAI',
|
|
69
117
|
[EModelEndpoint.bingAI]: 'Bing',
|
|
70
118
|
[EModelEndpoint.chatGPTBrowser]: 'ChatGPT',
|
|
@@ -75,6 +123,21 @@ export const alternateName = {
|
|
|
75
123
|
};
|
|
76
124
|
|
|
77
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
|
+
],
|
|
78
141
|
[EModelEndpoint.google]: [
|
|
79
142
|
'gemini-pro',
|
|
80
143
|
'gemini-pro-vision',
|
|
@@ -119,6 +182,14 @@ export const defaultModels = {
|
|
|
119
182
|
],
|
|
120
183
|
};
|
|
121
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
|
+
|
|
122
193
|
export const EndpointURLs: { [key in EModelEndpoint]: string } = {
|
|
123
194
|
[EModelEndpoint.openAI]: `/api/ask/${EModelEndpoint.openAI}`,
|
|
124
195
|
[EModelEndpoint.bingAI]: `/api/ask/${EModelEndpoint.bingAI}`,
|
|
@@ -128,7 +199,7 @@ export const EndpointURLs: { [key in EModelEndpoint]: string } = {
|
|
|
128
199
|
[EModelEndpoint.gptPlugins]: `/api/ask/${EModelEndpoint.gptPlugins}`,
|
|
129
200
|
[EModelEndpoint.azureOpenAI]: `/api/ask/${EModelEndpoint.azureOpenAI}`,
|
|
130
201
|
[EModelEndpoint.chatGPTBrowser]: `/api/ask/${EModelEndpoint.chatGPTBrowser}`,
|
|
131
|
-
[EModelEndpoint.
|
|
202
|
+
[EModelEndpoint.assistants]: '/api/assistants/chat',
|
|
132
203
|
};
|
|
133
204
|
|
|
134
205
|
export const modularEndpoints = new Set<EModelEndpoint | string>([
|
|
@@ -140,14 +211,6 @@ export const modularEndpoints = new Set<EModelEndpoint | string>([
|
|
|
140
211
|
EModelEndpoint.custom,
|
|
141
212
|
]);
|
|
142
213
|
|
|
143
|
-
export const supportsFiles = {
|
|
144
|
-
[EModelEndpoint.openAI]: true,
|
|
145
|
-
[EModelEndpoint.google]: true,
|
|
146
|
-
[EModelEndpoint.assistant]: true,
|
|
147
|
-
[EModelEndpoint.azureOpenAI]: true,
|
|
148
|
-
[EModelEndpoint.custom]: true,
|
|
149
|
-
};
|
|
150
|
-
|
|
151
214
|
export const supportsBalanceCheck = {
|
|
152
215
|
[EModelEndpoint.openAI]: true,
|
|
153
216
|
[EModelEndpoint.azureOpenAI]: true,
|
|
@@ -157,6 +220,19 @@ export const supportsBalanceCheck = {
|
|
|
157
220
|
|
|
158
221
|
export const visionModels = ['gpt-4-vision', 'llava-13b', 'gemini-pro-vision'];
|
|
159
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
|
+
|
|
160
236
|
/**
|
|
161
237
|
* Enum for cache keys.
|
|
162
238
|
*/
|
|
@@ -173,10 +249,19 @@ export enum CacheKeys {
|
|
|
173
249
|
* Key for the title generation cache.
|
|
174
250
|
*/
|
|
175
251
|
GEN_TITLE = 'genTitle',
|
|
252
|
+
/**
|
|
253
|
+
/**
|
|
254
|
+
* Key for the tools cache.
|
|
255
|
+
*/
|
|
256
|
+
TOOLS = 'tools',
|
|
176
257
|
/**
|
|
177
258
|
* Key for the model config cache.
|
|
178
259
|
*/
|
|
179
260
|
MODELS_CONFIG = 'modelsConfig',
|
|
261
|
+
/**
|
|
262
|
+
* Key for the model queries cache.
|
|
263
|
+
*/
|
|
264
|
+
MODEL_QUERIES = 'modelQueries',
|
|
180
265
|
/**
|
|
181
266
|
* Key for the default endpoint config cache.
|
|
182
267
|
*/
|
|
@@ -189,10 +274,18 @@ export enum CacheKeys {
|
|
|
189
274
|
* Key for the custom config cache.
|
|
190
275
|
*/
|
|
191
276
|
CUSTOM_CONFIG = 'customConfig',
|
|
277
|
+
/**
|
|
278
|
+
* Key for accessing Abort Keys
|
|
279
|
+
*/
|
|
280
|
+
ABORT_KEYS = 'abortKeys',
|
|
192
281
|
/**
|
|
193
282
|
* Key for the override config cache.
|
|
194
283
|
*/
|
|
195
284
|
OVERRIDE_CONFIG = 'overrideConfig',
|
|
285
|
+
/**
|
|
286
|
+
* Key for accessing File Upload Violations (exceeding limit).
|
|
287
|
+
*/
|
|
288
|
+
FILE_UPLOAD_LIMIT = 'file_upload_limit',
|
|
196
289
|
}
|
|
197
290
|
|
|
198
291
|
/**
|
|
@@ -254,3 +347,27 @@ export enum SettingsTabValues {
|
|
|
254
347
|
*/
|
|
255
348
|
ACCOUNT = 'account',
|
|
256
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