librechat-data-provider 0.7.78 → 0.7.81
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/package.json +2 -1
- package/specs/actions.spec.ts +238 -0
- package/specs/parsers.spec.ts +125 -0
- package/src/actions.ts +73 -19
- package/src/api-endpoints.ts +42 -10
- package/src/config.ts +28 -1
- package/src/createPayload.ts +13 -2
- package/src/data-service.ts +47 -69
- package/src/file-config.ts +3 -2
- package/src/index.ts +1 -0
- package/src/parsers.ts +45 -16
- package/src/permissions.ts +90 -0
- package/src/react-query/react-query-service.ts +5 -34
- package/src/roles.ts +72 -126
- package/src/schemas.ts +151 -178
- package/src/types/assistants.ts +16 -18
- package/src/types/mutations.ts +8 -2
- package/src/types/queries.ts +28 -13
- package/src/types.ts +10 -0
- package/src/zod.spec.ts +569 -1
- package/src/zod.ts +318 -9
package/src/config.ts
CHANGED
|
@@ -541,6 +541,7 @@ export type TStartupConfig = {
|
|
|
541
541
|
analyticsGtmId?: string;
|
|
542
542
|
instanceProjectId: string;
|
|
543
543
|
bundlerURL?: string;
|
|
544
|
+
staticBundlerURL?: string;
|
|
544
545
|
};
|
|
545
546
|
|
|
546
547
|
export enum OCRStrategy {
|
|
@@ -855,7 +856,10 @@ export const visionModels = [
|
|
|
855
856
|
'gpt-4o',
|
|
856
857
|
'gpt-4-turbo',
|
|
857
858
|
'gpt-4-vision',
|
|
859
|
+
'o4-mini',
|
|
860
|
+
'o3',
|
|
858
861
|
'o1',
|
|
862
|
+
'gpt-4.1',
|
|
859
863
|
'gpt-4.5',
|
|
860
864
|
'llava',
|
|
861
865
|
'llava-13b',
|
|
@@ -864,6 +868,8 @@ export const visionModels = [
|
|
|
864
868
|
'gemini-exp',
|
|
865
869
|
'gemini-1.5',
|
|
866
870
|
'gemini-2.0',
|
|
871
|
+
'gemini-2.5',
|
|
872
|
+
'gemini-3',
|
|
867
873
|
'moondream',
|
|
868
874
|
'llama3.2-vision',
|
|
869
875
|
'llama-3.2-11b-vision',
|
|
@@ -1007,6 +1013,10 @@ export enum CacheKeys {
|
|
|
1007
1013
|
* Key for in-progress flow states.
|
|
1008
1014
|
*/
|
|
1009
1015
|
FLOWS = 'flows',
|
|
1016
|
+
/**
|
|
1017
|
+
* Key for pending chat requests (concurrency check)
|
|
1018
|
+
*/
|
|
1019
|
+
PENDING_REQ = 'pending_req',
|
|
1010
1020
|
/**
|
|
1011
1021
|
* Key for s3 check intervals per user
|
|
1012
1022
|
*/
|
|
@@ -1217,13 +1227,15 @@ export enum TTSProviders {
|
|
|
1217
1227
|
/** Enum for app-wide constants */
|
|
1218
1228
|
export enum Constants {
|
|
1219
1229
|
/** Key for the app's version. */
|
|
1220
|
-
VERSION = 'v0.7.
|
|
1230
|
+
VERSION = 'v0.7.8-rc1',
|
|
1221
1231
|
/** Key for the Custom Config's version (librechat.yaml). */
|
|
1222
1232
|
CONFIG_VERSION = '1.2.4',
|
|
1223
1233
|
/** Standard value for the first message's `parentMessageId` value, to indicate no parent exists. */
|
|
1224
1234
|
NO_PARENT = '00000000-0000-0000-0000-000000000000',
|
|
1225
1235
|
/** Standard value for the initial conversationId before a request is sent */
|
|
1226
1236
|
NEW_CONVO = 'new',
|
|
1237
|
+
/** Standard value for the temporary conversationId after a request is sent and before the server responds */
|
|
1238
|
+
PENDING_CONVO = 'PENDING',
|
|
1227
1239
|
/** Standard value for the conversationId used for search queries */
|
|
1228
1240
|
SEARCH = 'search',
|
|
1229
1241
|
/** Fixed, encoded domain length for Azure OpenAI Assistants Function name parsing. */
|
|
@@ -1244,6 +1256,8 @@ export enum Constants {
|
|
|
1244
1256
|
GLOBAL_PROJECT_NAME = 'instance',
|
|
1245
1257
|
/** Delimiter for MCP tools */
|
|
1246
1258
|
mcp_delimiter = '_mcp_',
|
|
1259
|
+
/** Placeholder Agent ID for Ephemeral Agents */
|
|
1260
|
+
EPHEMERAL_AGENT_ID = 'ephemeral',
|
|
1247
1261
|
}
|
|
1248
1262
|
|
|
1249
1263
|
export enum LocalStorageKeys {
|
|
@@ -1279,6 +1293,10 @@ export enum LocalStorageKeys {
|
|
|
1279
1293
|
ENABLE_USER_MSG_MARKDOWN = 'enableUserMsgMarkdown',
|
|
1280
1294
|
/** Key for displaying analysis tool code input */
|
|
1281
1295
|
SHOW_ANALYSIS_CODE = 'showAnalysisCode',
|
|
1296
|
+
/** Last selected MCP values per conversation ID */
|
|
1297
|
+
LAST_MCP_ = 'LAST_MCP_',
|
|
1298
|
+
/** Last checked toggle for Code Interpreter API per conversation ID */
|
|
1299
|
+
LAST_CODE_TOGGLE_ = 'LAST_CODE_TOGGLE_',
|
|
1282
1300
|
}
|
|
1283
1301
|
|
|
1284
1302
|
export enum ForkOptions {
|
|
@@ -1331,3 +1349,12 @@ export const providerEndpointMap = {
|
|
|
1331
1349
|
[EModelEndpoint.anthropic]: EModelEndpoint.anthropic,
|
|
1332
1350
|
[EModelEndpoint.azureOpenAI]: EModelEndpoint.azureOpenAI,
|
|
1333
1351
|
};
|
|
1352
|
+
|
|
1353
|
+
export const specialVariables = {
|
|
1354
|
+
current_date: true,
|
|
1355
|
+
current_user: true,
|
|
1356
|
+
iso_datetime: true,
|
|
1357
|
+
current_datetime: true,
|
|
1358
|
+
};
|
|
1359
|
+
|
|
1360
|
+
export type TSpecialVarLabel = `com_ui_special_var_${keyof typeof specialVariables}`;
|
package/src/createPayload.ts
CHANGED
|
@@ -3,8 +3,15 @@ import { EndpointURLs } from './config';
|
|
|
3
3
|
import * as s from './schemas';
|
|
4
4
|
|
|
5
5
|
export default function createPayload(submission: t.TSubmission) {
|
|
6
|
-
const {
|
|
7
|
-
|
|
6
|
+
const {
|
|
7
|
+
conversation,
|
|
8
|
+
userMessage,
|
|
9
|
+
endpointOption,
|
|
10
|
+
isEdited,
|
|
11
|
+
isContinued,
|
|
12
|
+
isTemporary,
|
|
13
|
+
ephemeralAgent,
|
|
14
|
+
} = submission;
|
|
8
15
|
const { conversationId } = s.tConvoUpdateSchema.parse(conversation);
|
|
9
16
|
const { endpoint, endpointType } = endpointOption as {
|
|
10
17
|
endpoint: s.EModelEndpoint;
|
|
@@ -12,16 +19,20 @@ export default function createPayload(submission: t.TSubmission) {
|
|
|
12
19
|
};
|
|
13
20
|
|
|
14
21
|
let server = EndpointURLs[endpointType ?? endpoint];
|
|
22
|
+
const isEphemeral = s.isEphemeralAgent(endpoint, ephemeralAgent);
|
|
15
23
|
|
|
16
24
|
if (isEdited && s.isAssistantsEndpoint(endpoint)) {
|
|
17
25
|
server += '/modify';
|
|
18
26
|
} else if (isEdited) {
|
|
19
27
|
server = server.replace('/ask/', '/edit/');
|
|
28
|
+
} else if (isEphemeral) {
|
|
29
|
+
server = `${EndpointURLs[s.EModelEndpoint.agents]}/${endpoint}`;
|
|
20
30
|
}
|
|
21
31
|
|
|
22
32
|
const payload: t.TPayload = {
|
|
23
33
|
...userMessage,
|
|
24
34
|
...endpointOption,
|
|
35
|
+
ephemeralAgent: isEphemeral ? ephemeralAgent : undefined,
|
|
25
36
|
isContinued: !!(isEdited && isContinued),
|
|
26
37
|
conversationId,
|
|
27
38
|
isTemporary,
|
package/src/data-service.ts
CHANGED
|
@@ -30,13 +30,6 @@ export function deleteUser(): Promise<s.TPreset> {
|
|
|
30
30
|
return request.delete(endpoints.deleteUser());
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export function getMessagesByConvoId(conversationId: string): Promise<s.TMessage[]> {
|
|
34
|
-
if (conversationId === 'new') {
|
|
35
|
-
return Promise.resolve([]);
|
|
36
|
-
}
|
|
37
|
-
return request.get(endpoints.messages(conversationId));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
33
|
export function getSharedMessages(shareId: string): Promise<t.TSharedMessagesResponse> {
|
|
41
34
|
return request.get(endpoints.shareMessages(shareId));
|
|
42
35
|
}
|
|
@@ -67,31 +60,6 @@ export function deleteSharedLink(shareId: string): Promise<m.TDeleteSharedLinkRe
|
|
|
67
60
|
return request.delete(endpoints.shareMessages(shareId));
|
|
68
61
|
}
|
|
69
62
|
|
|
70
|
-
export function updateMessage(payload: t.TUpdateMessageRequest): Promise<unknown> {
|
|
71
|
-
const { conversationId, messageId, text } = payload;
|
|
72
|
-
if (!conversationId) {
|
|
73
|
-
throw new Error('conversationId is required');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return request.put(endpoints.messages(conversationId, messageId), { text });
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export const editArtifact = async ({
|
|
80
|
-
messageId,
|
|
81
|
-
...params
|
|
82
|
-
}: m.TEditArtifactRequest): Promise<m.TEditArtifactResponse> => {
|
|
83
|
-
return request.post(`/api/messages/artifact/${messageId}`, params);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export function updateMessageContent(payload: t.TUpdateMessageContent): Promise<unknown> {
|
|
87
|
-
const { conversationId, messageId, index, text } = payload;
|
|
88
|
-
if (!conversationId) {
|
|
89
|
-
throw new Error('conversationId is required');
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return request.put(endpoints.messages(conversationId, messageId), { text, index });
|
|
93
|
-
}
|
|
94
|
-
|
|
95
63
|
export function updateUserKey(payload: t.TUpdateUserKeyRequest) {
|
|
96
64
|
const { value } = payload;
|
|
97
65
|
if (!value) {
|
|
@@ -589,46 +557,21 @@ export function forkConversation(payload: t.TForkConvoRequest): Promise<t.TForkC
|
|
|
589
557
|
}
|
|
590
558
|
|
|
591
559
|
export function deleteConversation(payload: t.TDeleteConversationRequest) {
|
|
592
|
-
|
|
593
|
-
return request.post(endpoints.deleteConversation(), { arg: payload });
|
|
560
|
+
return request.deleteWithOptions(endpoints.deleteConversation(), { data: { arg: payload } });
|
|
594
561
|
}
|
|
595
562
|
|
|
596
563
|
export function clearAllConversations(): Promise<unknown> {
|
|
597
|
-
return request.
|
|
564
|
+
return request.delete(endpoints.deleteAllConversation());
|
|
598
565
|
}
|
|
599
566
|
|
|
600
567
|
export const listConversations = (
|
|
601
568
|
params?: q.ConversationListParams,
|
|
602
569
|
): Promise<q.ConversationListResponse> => {
|
|
603
|
-
|
|
604
|
-
const pageNumber = (params?.pageNumber ?? '1') || '1'; // Default to page 1 if not provided
|
|
605
|
-
const isArchived = params?.isArchived ?? false; // Default to false if not provided
|
|
606
|
-
const tags = params?.tags || []; // Default to an empty array if not provided
|
|
607
|
-
return request.get(endpoints.conversations(pageNumber, isArchived, tags));
|
|
608
|
-
};
|
|
609
|
-
|
|
610
|
-
export const listConversationsByQuery = (
|
|
611
|
-
params?: q.ConversationListParams & { searchQuery?: string },
|
|
612
|
-
): Promise<q.ConversationListResponse> => {
|
|
613
|
-
const pageNumber = (params?.pageNumber ?? '1') || '1'; // Default to page 1 if not provided
|
|
614
|
-
const searchQuery = params?.searchQuery ?? ''; // If no search query is provided, default to an empty string
|
|
615
|
-
// Update the endpoint to handle a search query
|
|
616
|
-
if (searchQuery !== '') {
|
|
617
|
-
return request.get(endpoints.search(searchQuery, pageNumber));
|
|
618
|
-
} else {
|
|
619
|
-
return request.get(endpoints.conversations(pageNumber));
|
|
620
|
-
}
|
|
570
|
+
return request.get(endpoints.conversations(params ?? {}));
|
|
621
571
|
};
|
|
622
572
|
|
|
623
|
-
export
|
|
624
|
-
|
|
625
|
-
pageNumber: string,
|
|
626
|
-
): Promise<t.TSearchResults> => {
|
|
627
|
-
return request.get(endpoints.search(q, pageNumber));
|
|
628
|
-
};
|
|
629
|
-
|
|
630
|
-
export function getConversations(pageNumber: string): Promise<t.TGetConversationsResponse> {
|
|
631
|
-
return request.get(endpoints.conversations(pageNumber));
|
|
573
|
+
export function getConversations(cursor: string): Promise<t.TGetConversationsResponse> {
|
|
574
|
+
return request.get(endpoints.conversations({ cursor }));
|
|
632
575
|
}
|
|
633
576
|
|
|
634
577
|
export function getConversationById(id: string): Promise<s.TConversation> {
|
|
@@ -651,6 +594,45 @@ export function genTitle(payload: m.TGenTitleRequest): Promise<m.TGenTitleRespon
|
|
|
651
594
|
return request.post(endpoints.genTitle(), payload);
|
|
652
595
|
}
|
|
653
596
|
|
|
597
|
+
export const listMessages = (params?: q.MessagesListParams): Promise<q.MessagesListResponse> => {
|
|
598
|
+
return request.get(endpoints.messages(params ?? {}));
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
export function updateMessage(payload: t.TUpdateMessageRequest): Promise<unknown> {
|
|
602
|
+
const { conversationId, messageId, text } = payload;
|
|
603
|
+
if (!conversationId) {
|
|
604
|
+
throw new Error('conversationId is required');
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
return request.put(endpoints.messages({ conversationId, messageId }), { text });
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
export function updateMessageContent(payload: t.TUpdateMessageContent): Promise<unknown> {
|
|
611
|
+
const { conversationId, messageId, index, text } = payload;
|
|
612
|
+
if (!conversationId) {
|
|
613
|
+
throw new Error('conversationId is required');
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
return request.put(endpoints.messages({ conversationId, messageId }), { text, index });
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
export const editArtifact = async ({
|
|
620
|
+
messageId,
|
|
621
|
+
...params
|
|
622
|
+
}: m.TEditArtifactRequest): Promise<m.TEditArtifactResponse> => {
|
|
623
|
+
return request.post(`/api/messages/artifact/${messageId}`, params);
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
export function getMessagesByConvoId(conversationId: string): Promise<s.TMessage[]> {
|
|
627
|
+
if (
|
|
628
|
+
conversationId === config.Constants.NEW_CONVO ||
|
|
629
|
+
conversationId === config.Constants.PENDING_CONVO
|
|
630
|
+
) {
|
|
631
|
+
return Promise.resolve([]);
|
|
632
|
+
}
|
|
633
|
+
return request.get(endpoints.messages({ conversationId }));
|
|
634
|
+
}
|
|
635
|
+
|
|
654
636
|
export function getPrompt(id: string): Promise<{ prompt: t.TPrompt }> {
|
|
655
637
|
return request.get(endpoints.getPrompt(id));
|
|
656
638
|
}
|
|
@@ -779,15 +761,11 @@ export function enableTwoFactor(): Promise<t.TEnable2FAResponse> {
|
|
|
779
761
|
return request.get(endpoints.enableTwoFactor());
|
|
780
762
|
}
|
|
781
763
|
|
|
782
|
-
export function verifyTwoFactor(
|
|
783
|
-
payload: t.TVerify2FARequest,
|
|
784
|
-
): Promise<t.TVerify2FAResponse> {
|
|
764
|
+
export function verifyTwoFactor(payload: t.TVerify2FARequest): Promise<t.TVerify2FAResponse> {
|
|
785
765
|
return request.post(endpoints.verifyTwoFactor(), payload);
|
|
786
766
|
}
|
|
787
767
|
|
|
788
|
-
export function confirmTwoFactor(
|
|
789
|
-
payload: t.TVerify2FARequest,
|
|
790
|
-
): Promise<t.TVerify2FAResponse> {
|
|
768
|
+
export function confirmTwoFactor(payload: t.TVerify2FARequest): Promise<t.TVerify2FAResponse> {
|
|
791
769
|
return request.post(endpoints.confirmTwoFactor(), payload);
|
|
792
770
|
}
|
|
793
771
|
|
|
@@ -803,4 +781,4 @@ export function verifyTwoFactorTemp(
|
|
|
803
781
|
payload: t.TVerify2FATempRequest,
|
|
804
782
|
): Promise<t.TVerify2FATempResponse> {
|
|
805
783
|
return request.post(endpoints.verifyTwoFactorTemp(), payload);
|
|
806
|
-
}
|
|
784
|
+
}
|
package/src/file-config.ts
CHANGED
|
@@ -112,7 +112,7 @@ export const excelMimeTypes =
|
|
|
112
112
|
/^application\/(vnd\.ms-excel|msexcel|x-msexcel|x-ms-excel|x-excel|x-dos_ms_excel|xls|x-xls|vnd\.openxmlformats-officedocument\.spreadsheetml\.sheet)$/;
|
|
113
113
|
|
|
114
114
|
export const textMimeTypes =
|
|
115
|
-
/^(text\/(x-c|x-csharp|x-c\+\+|x-java|html|markdown|x-php|x-python|x-script\.python|x-ruby|x-tex|plain|css|vtt|javascript|csv))$/;
|
|
115
|
+
/^(text\/(x-c|x-csharp|tab-separated-values|x-c\+\+|x-java|html|markdown|x-php|x-python|x-script\.python|x-ruby|x-tex|plain|css|vtt|javascript|csv))$/;
|
|
116
116
|
|
|
117
117
|
export const applicationMimeTypes =
|
|
118
118
|
/^(application\/(epub\+zip|csv|json|pdf|x-tar|typescript|vnd\.openxmlformats-officedocument\.(wordprocessingml\.document|presentationml\.presentation|spreadsheetml\.sheet)|xml|zip))$/;
|
|
@@ -152,6 +152,7 @@ export const codeTypeMapping: { [key: string]: string } = {
|
|
|
152
152
|
yml: 'application/x-yaml',
|
|
153
153
|
yaml: 'application/x-yaml',
|
|
154
154
|
log: 'text/plain',
|
|
155
|
+
tsv: 'text/tab-separated-values',
|
|
155
156
|
};
|
|
156
157
|
|
|
157
158
|
export const retrievalMimeTypes = [
|
|
@@ -230,7 +231,7 @@ export const convertStringsToRegex = (patterns: string[]): RegExp[] =>
|
|
|
230
231
|
const regex = new RegExp(pattern);
|
|
231
232
|
acc.push(regex);
|
|
232
233
|
} catch (error) {
|
|
233
|
-
console.error(`Invalid regex pattern "${pattern}" skipped
|
|
234
|
+
console.error(`Invalid regex pattern "${pattern}" skipped.`, error);
|
|
234
235
|
}
|
|
235
236
|
return acc;
|
|
236
237
|
}, []);
|
package/src/index.ts
CHANGED
package/src/parsers.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
1
2
|
import type { ZodIssue } from 'zod';
|
|
2
3
|
import type * as a from './types/assistants';
|
|
3
4
|
import type * as s from './schemas';
|
|
@@ -13,8 +14,6 @@ import {
|
|
|
13
14
|
// agentsSchema,
|
|
14
15
|
compactAgentsSchema,
|
|
15
16
|
compactGoogleSchema,
|
|
16
|
-
compactChatGPTSchema,
|
|
17
|
-
chatGPTBrowserSchema,
|
|
18
17
|
compactPluginsSchema,
|
|
19
18
|
compactAssistantSchema,
|
|
20
19
|
} from './schemas';
|
|
@@ -26,19 +25,19 @@ type EndpointSchema =
|
|
|
26
25
|
| typeof openAISchema
|
|
27
26
|
| typeof googleSchema
|
|
28
27
|
| typeof anthropicSchema
|
|
29
|
-
| typeof chatGPTBrowserSchema
|
|
30
28
|
| typeof gptPluginsSchema
|
|
31
29
|
| typeof assistantSchema
|
|
32
30
|
| typeof compactAgentsSchema
|
|
33
31
|
| typeof bedrockInputSchema;
|
|
34
32
|
|
|
35
|
-
|
|
33
|
+
export type EndpointSchemaKey = Exclude<EModelEndpoint, EModelEndpoint.chatGPTBrowser>;
|
|
34
|
+
|
|
35
|
+
const endpointSchemas: Record<EndpointSchemaKey, EndpointSchema> = {
|
|
36
36
|
[EModelEndpoint.openAI]: openAISchema,
|
|
37
37
|
[EModelEndpoint.azureOpenAI]: openAISchema,
|
|
38
38
|
[EModelEndpoint.custom]: openAISchema,
|
|
39
39
|
[EModelEndpoint.google]: googleSchema,
|
|
40
40
|
[EModelEndpoint.anthropic]: anthropicSchema,
|
|
41
|
-
[EModelEndpoint.chatGPTBrowser]: chatGPTBrowserSchema,
|
|
42
41
|
[EModelEndpoint.gptPlugins]: gptPluginsSchema,
|
|
43
42
|
[EModelEndpoint.assistants]: assistantSchema,
|
|
44
43
|
[EModelEndpoint.azureAssistants]: assistantSchema,
|
|
@@ -167,8 +166,8 @@ export const parseConvo = ({
|
|
|
167
166
|
conversation,
|
|
168
167
|
possibleValues,
|
|
169
168
|
}: {
|
|
170
|
-
endpoint:
|
|
171
|
-
endpointType?:
|
|
169
|
+
endpoint: EndpointSchemaKey;
|
|
170
|
+
endpointType?: EndpointSchemaKey | null;
|
|
172
171
|
conversation: Partial<s.TConversation | s.TPreset> | null;
|
|
173
172
|
possibleValues?: TPossibleValues;
|
|
174
173
|
// TODO: POC for default schema
|
|
@@ -252,8 +251,10 @@ export const getResponseSender = (endpointOption: t.TEndpointOption): string =>
|
|
|
252
251
|
return modelLabel;
|
|
253
252
|
} else if (model && extractOmniVersion(model)) {
|
|
254
253
|
return extractOmniVersion(model);
|
|
255
|
-
} else if (model && model.includes('mistral')) {
|
|
254
|
+
} else if (model && (model.includes('mistral') || model.includes('codestral'))) {
|
|
256
255
|
return 'Mistral';
|
|
256
|
+
} else if (model && model.includes('deepseek')) {
|
|
257
|
+
return 'Deepseek';
|
|
257
258
|
} else if (model && model.includes('gpt-')) {
|
|
258
259
|
const gptVersion = extractGPTVersion(model);
|
|
259
260
|
return gptVersion || 'GPT';
|
|
@@ -288,8 +289,10 @@ export const getResponseSender = (endpointOption: t.TEndpointOption): string =>
|
|
|
288
289
|
return chatGptLabel;
|
|
289
290
|
} else if (model && extractOmniVersion(model)) {
|
|
290
291
|
return extractOmniVersion(model);
|
|
291
|
-
} else if (model && model.includes('mistral')) {
|
|
292
|
+
} else if (model && (model.includes('mistral') || model.includes('codestral'))) {
|
|
292
293
|
return 'Mistral';
|
|
294
|
+
} else if (model && model.includes('deepseek')) {
|
|
295
|
+
return 'Deepseek';
|
|
293
296
|
} else if (model && model.includes('gpt-')) {
|
|
294
297
|
const gptVersion = extractGPTVersion(model);
|
|
295
298
|
return gptVersion || 'GPT';
|
|
@@ -309,11 +312,10 @@ type CompactEndpointSchema =
|
|
|
309
312
|
| typeof compactAgentsSchema
|
|
310
313
|
| typeof compactGoogleSchema
|
|
311
314
|
| typeof anthropicSchema
|
|
312
|
-
| typeof compactChatGPTSchema
|
|
313
315
|
| typeof bedrockInputSchema
|
|
314
316
|
| typeof compactPluginsSchema;
|
|
315
317
|
|
|
316
|
-
const compactEndpointSchemas: Record<
|
|
318
|
+
const compactEndpointSchemas: Record<EndpointSchemaKey, CompactEndpointSchema> = {
|
|
317
319
|
[EModelEndpoint.openAI]: openAISchema,
|
|
318
320
|
[EModelEndpoint.azureOpenAI]: openAISchema,
|
|
319
321
|
[EModelEndpoint.custom]: openAISchema,
|
|
@@ -323,7 +325,6 @@ const compactEndpointSchemas: Record<string, CompactEndpointSchema> = {
|
|
|
323
325
|
[EModelEndpoint.google]: compactGoogleSchema,
|
|
324
326
|
[EModelEndpoint.bedrock]: bedrockInputSchema,
|
|
325
327
|
[EModelEndpoint.anthropic]: anthropicSchema,
|
|
326
|
-
[EModelEndpoint.chatGPTBrowser]: compactChatGPTSchema,
|
|
327
328
|
[EModelEndpoint.gptPlugins]: compactPluginsSchema,
|
|
328
329
|
};
|
|
329
330
|
|
|
@@ -333,8 +334,8 @@ export const parseCompactConvo = ({
|
|
|
333
334
|
conversation,
|
|
334
335
|
possibleValues,
|
|
335
336
|
}: {
|
|
336
|
-
endpoint?:
|
|
337
|
-
endpointType?:
|
|
337
|
+
endpoint?: EndpointSchemaKey;
|
|
338
|
+
endpointType?: EndpointSchemaKey | null;
|
|
338
339
|
conversation: Partial<s.TConversation | s.TPreset>;
|
|
339
340
|
possibleValues?: TPossibleValues;
|
|
340
341
|
// TODO: POC for default schema
|
|
@@ -371,7 +372,10 @@ export const parseCompactConvo = ({
|
|
|
371
372
|
return convo;
|
|
372
373
|
};
|
|
373
374
|
|
|
374
|
-
export function parseTextParts(
|
|
375
|
+
export function parseTextParts(
|
|
376
|
+
contentParts: a.TMessageContentParts[],
|
|
377
|
+
skipReasoning: boolean = false,
|
|
378
|
+
): string {
|
|
375
379
|
let result = '';
|
|
376
380
|
|
|
377
381
|
for (const part of contentParts) {
|
|
@@ -390,7 +394,7 @@ export function parseTextParts(contentParts: a.TMessageContentParts[]): string {
|
|
|
390
394
|
result += ' ';
|
|
391
395
|
}
|
|
392
396
|
result += textValue;
|
|
393
|
-
} else if (part.type === ContentTypes.THINK) {
|
|
397
|
+
} else if (part.type === ContentTypes.THINK && !skipReasoning) {
|
|
394
398
|
const textValue = typeof part.think === 'string' ? part.think : '';
|
|
395
399
|
if (
|
|
396
400
|
result.length > 0 &&
|
|
@@ -419,3 +423,28 @@ export function findLastSeparatorIndex(text: string, separators = SEPARATORS): n
|
|
|
419
423
|
}
|
|
420
424
|
return lastIndex;
|
|
421
425
|
}
|
|
426
|
+
|
|
427
|
+
export function replaceSpecialVars({ text, user }: { text: string; user?: t.TUser | null }) {
|
|
428
|
+
let result = text;
|
|
429
|
+
if (!result) {
|
|
430
|
+
return result;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// e.g., "2024-04-29 (1)" (1=Monday)
|
|
434
|
+
const currentDate = dayjs().format('YYYY-MM-DD');
|
|
435
|
+
const dayNumber = dayjs().day();
|
|
436
|
+
const combinedDate = `${currentDate} (${dayNumber})`;
|
|
437
|
+
result = result.replace(/{{current_date}}/gi, combinedDate);
|
|
438
|
+
|
|
439
|
+
const currentDatetime = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
440
|
+
result = result.replace(/{{current_datetime}}/gi, `${currentDatetime} (${dayNumber})`);
|
|
441
|
+
|
|
442
|
+
const isoDatetime = dayjs().toISOString();
|
|
443
|
+
result = result.replace(/{{iso_datetime}}/gi, isoDatetime);
|
|
444
|
+
|
|
445
|
+
if (user && user.name) {
|
|
446
|
+
result = result.replace(/{{current_user}}/gi, user.name);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
return result;
|
|
450
|
+
}
|
|
@@ -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,
|