librechat-data-provider 0.1.8 → 0.2.0
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 +45 -8
- package/dist/index.js +47 -6
- package/package.json +3 -2
- package/src/api-endpoints.ts +4 -0
- package/src/data-service.ts +10 -0
- package/src/react-query-service.ts +39 -3
- package/src/request.ts +1 -0
- package/src/schemas.ts +12 -6
- package/src/types.ts +13 -11
- package/types/api-endpoints.d.ts +2 -0
- package/types/data-service.d.ts +2 -0
- package/types/react-query-service.d.ts +4 -0
- package/types/schemas.d.ts +69 -13
- package/types/types.d.ts +11 -11
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { useMutation, useQuery
|
|
3
|
+
import { useQueryClient, useMutation, useQuery } from '@tanstack/react-query';
|
|
4
4
|
|
|
5
5
|
/******************************************************************************
|
|
6
6
|
Copyright (c) Microsoft Corporation.
|
|
@@ -245,6 +245,7 @@ var request = {
|
|
|
245
245
|
};
|
|
246
246
|
|
|
247
247
|
var user = function () { return '/api/user'; };
|
|
248
|
+
var balance = function () { return '/api/balance'; };
|
|
248
249
|
var userPlugins = function () { return '/api/user/plugins'; };
|
|
249
250
|
var messages = function (conversationId, messageId) {
|
|
250
251
|
return "/api/messages/".concat(conversationId).concat(messageId ? "/".concat(messageId) : '');
|
|
@@ -266,6 +267,7 @@ var searchEnabled = function () { return '/api/search/enable'; };
|
|
|
266
267
|
var presets = function () { return '/api/presets'; };
|
|
267
268
|
var deletePreset$1 = function () { return '/api/presets/delete'; };
|
|
268
269
|
var aiEndpoints = function () { return '/api/endpoints'; };
|
|
270
|
+
var models = function () { return '/api/models'; };
|
|
269
271
|
var tokenizer = function () { return '/api/tokenizer'; };
|
|
270
272
|
var login$1 = function () { return '/api/auth/login'; };
|
|
271
273
|
var logout$1 = function () { return '/api/auth/logout'; };
|
|
@@ -337,6 +339,9 @@ function getSearchEnabled() {
|
|
|
337
339
|
function getUser() {
|
|
338
340
|
return request.get(user());
|
|
339
341
|
}
|
|
342
|
+
function getUserBalance() {
|
|
343
|
+
return request.get(balance());
|
|
344
|
+
}
|
|
340
345
|
var searchConversations = function (q, pageNumber) { return __awaiter(void 0, void 0, void 0, function () {
|
|
341
346
|
return __generator(this, function (_a) {
|
|
342
347
|
return [2 /*return*/, request.get(search(q, pageNumber))];
|
|
@@ -345,6 +350,9 @@ var searchConversations = function (q, pageNumber) { return __awaiter(void 0, vo
|
|
|
345
350
|
var getAIEndpoints = function () {
|
|
346
351
|
return request.get(aiEndpoints());
|
|
347
352
|
};
|
|
353
|
+
var getModels = function () {
|
|
354
|
+
return request.get(models());
|
|
355
|
+
};
|
|
348
356
|
var updateTokenCount = function (text) {
|
|
349
357
|
return request.post(tokenizer(), { arg: text });
|
|
350
358
|
};
|
|
@@ -428,7 +436,7 @@ var tMessageSchema = z.object({
|
|
|
428
436
|
overrideParentMessageId: z.string().nullable().optional(),
|
|
429
437
|
bg: z.string().nullable().optional(),
|
|
430
438
|
model: z.string().nullable().optional(),
|
|
431
|
-
title: z.string().nullable().
|
|
439
|
+
title: z.string().nullable().or(z.literal('New Chat')).default('New Chat'),
|
|
432
440
|
sender: z.string(),
|
|
433
441
|
text: z.string(),
|
|
434
442
|
generation: z.string().nullable().optional(),
|
|
@@ -451,7 +459,7 @@ var tMessageSchema = z.object({
|
|
|
451
459
|
});
|
|
452
460
|
var tConversationSchema = z.object({
|
|
453
461
|
conversationId: z.string().nullable(),
|
|
454
|
-
title: z.string(),
|
|
462
|
+
title: z.string().nullable().or(z.literal('New Chat')).default('New Chat'),
|
|
455
463
|
user: z.string().optional(),
|
|
456
464
|
endpoint: eModelEndpointSchema.nullable(),
|
|
457
465
|
suggestions: z.array(z.string()).optional(),
|
|
@@ -660,14 +668,18 @@ function getFirstDefinedValue(possibleValues) {
|
|
|
660
668
|
return returnValue;
|
|
661
669
|
}
|
|
662
670
|
var parseConvo = function (endpoint, conversation, possibleValues) {
|
|
663
|
-
var _a;
|
|
671
|
+
var _a, _b;
|
|
664
672
|
var schema = endpointSchemas[endpoint];
|
|
665
673
|
if (!schema) {
|
|
666
674
|
throw new Error("Unknown endpoint: ".concat(endpoint));
|
|
667
675
|
}
|
|
668
676
|
var convo = schema.parse(conversation);
|
|
669
|
-
|
|
670
|
-
|
|
677
|
+
var _c = possibleValues !== null && possibleValues !== void 0 ? possibleValues : {}, models = _c.models, secondaryModels = _c.secondaryModels;
|
|
678
|
+
if (models && convo) {
|
|
679
|
+
convo.model = (_a = getFirstDefinedValue(models)) !== null && _a !== void 0 ? _a : convo.model;
|
|
680
|
+
}
|
|
681
|
+
if (secondaryModels && convo.agentOptions) {
|
|
682
|
+
convo.agentOptions.model = (_b = getFirstDefinedValue(secondaryModels)) !== null && _b !== void 0 ? _b : convo.agentOptions.model;
|
|
671
683
|
}
|
|
672
684
|
return convo;
|
|
673
685
|
};
|
|
@@ -696,6 +708,8 @@ var QueryKeys;
|
|
|
696
708
|
QueryKeys["searchEnabled"] = "searchEnabled";
|
|
697
709
|
QueryKeys["user"] = "user";
|
|
698
710
|
QueryKeys["name"] = "name";
|
|
711
|
+
QueryKeys["models"] = "models";
|
|
712
|
+
QueryKeys["balance"] = "balance";
|
|
699
713
|
QueryKeys["endpoints"] = "endpoints";
|
|
700
714
|
QueryKeys["presets"] = "presets";
|
|
701
715
|
QueryKeys["searchResults"] = "searchResults";
|
|
@@ -704,9 +718,14 @@ var QueryKeys;
|
|
|
704
718
|
QueryKeys["startupConfig"] = "startupConfig";
|
|
705
719
|
})(QueryKeys || (QueryKeys = {}));
|
|
706
720
|
var useAbortRequestWithMessage = function () {
|
|
721
|
+
var queryClient = useQueryClient();
|
|
707
722
|
return useMutation(function (_a) {
|
|
708
723
|
var endpoint = _a.endpoint, abortKey = _a.abortKey, message = _a.message;
|
|
709
724
|
return abortRequestWithMessage(endpoint, abortKey, message);
|
|
725
|
+
}, {
|
|
726
|
+
onSuccess: function () {
|
|
727
|
+
queryClient.invalidateQueries([QueryKeys.balance]);
|
|
728
|
+
},
|
|
710
729
|
});
|
|
711
730
|
};
|
|
712
731
|
var useGetUserQuery = function (config) {
|
|
@@ -715,6 +734,9 @@ var useGetUserQuery = function (config) {
|
|
|
715
734
|
var useGetMessagesByConvoId = function (id, config) {
|
|
716
735
|
return useQuery([QueryKeys.messages, id], function () { return getMessagesByConvoId(id); }, __assign({ refetchOnWindowFocus: false, refetchOnReconnect: false, refetchOnMount: false }, config));
|
|
717
736
|
};
|
|
737
|
+
var useGetUserBalance = function (config) {
|
|
738
|
+
return useQuery([QueryKeys.balance], function () { return getUserBalance(); }, __assign({ refetchOnWindowFocus: true, refetchOnReconnect: true, refetchOnMount: true }, config));
|
|
739
|
+
};
|
|
718
740
|
var useGetConversationByIdQuery = function (id, config) {
|
|
719
741
|
return useQuery([QueryKeys.conversation, id], function () { return getConversationById(id); }, __assign({ refetchOnWindowFocus: false, refetchOnReconnect: false, refetchOnMount: false }, config));
|
|
720
742
|
};
|
|
@@ -800,6 +822,13 @@ var useGetEndpointsQuery = function () {
|
|
|
800
822
|
refetchOnMount: false,
|
|
801
823
|
});
|
|
802
824
|
};
|
|
825
|
+
var useGetModelsQuery = function () {
|
|
826
|
+
return useQuery([QueryKeys.models], function () { return getModels(); }, {
|
|
827
|
+
refetchOnWindowFocus: false,
|
|
828
|
+
refetchOnReconnect: false,
|
|
829
|
+
refetchOnMount: false,
|
|
830
|
+
});
|
|
831
|
+
};
|
|
803
832
|
var useCreatePresetMutation = function () {
|
|
804
833
|
var queryClient = useQueryClient();
|
|
805
834
|
return useMutation(function (payload) { return createPreset(payload); }, {
|
|
@@ -847,6 +876,9 @@ var useLoginUserMutation = function () {
|
|
|
847
876
|
onSuccess: function () {
|
|
848
877
|
queryClient.invalidateQueries([QueryKeys.user]);
|
|
849
878
|
},
|
|
879
|
+
onMutate: function () {
|
|
880
|
+
queryClient.invalidateQueries([QueryKeys.models]);
|
|
881
|
+
},
|
|
850
882
|
});
|
|
851
883
|
};
|
|
852
884
|
var useRegisterUserMutation = function () {
|
|
@@ -866,7 +898,12 @@ var useLogoutUserMutation = function () {
|
|
|
866
898
|
});
|
|
867
899
|
};
|
|
868
900
|
var useRefreshTokenMutation = function () {
|
|
869
|
-
|
|
901
|
+
var queryClient = useQueryClient();
|
|
902
|
+
return useMutation(function () { return refreshToken(); }, {
|
|
903
|
+
onMutate: function () {
|
|
904
|
+
queryClient.invalidateQueries([QueryKeys.models]);
|
|
905
|
+
},
|
|
906
|
+
});
|
|
870
907
|
};
|
|
871
908
|
var useUserKeyQuery = function (name, config) {
|
|
872
909
|
return useQuery([QueryKeys.name, name], function () {
|
|
@@ -1168,4 +1205,4 @@ function createPayload(submission) {
|
|
|
1168
1205
|
return { server: server, payload: payload };
|
|
1169
1206
|
}
|
|
1170
1207
|
|
|
1171
|
-
export { EModelEndpoint, QueryKeys, SSE, abortRequestWithMessage, anthropicSchema, bingAISchema, chatGPTBrowserSchema, clearAllConversations, createPayload, createPreset, deleteConversation, deletePreset, eModelEndpointSchema, getAIEndpoints, getAvailablePlugins, getConversationById, getConversations, getLoginGoogle, getMessagesByConvoId, getPresets, getResponseSender, getSearchEnabled, getStartupConfig, getUser, googleSchema, gptPluginsSchema, login, logout, openAISchema, parseConvo, refreshToken, register, requestPasswordReset, resetPassword, revokeAllUserKeys, revokeUserKey, searchConversations, setAcceptLanguageHeader, setTokenHeader, tAgentOptionsSchema, tConversationSchema, tExampleSchema, tMessageSchema, tPluginAuthConfigSchema, tPluginSchema, tPresetSchema, updateConversation, updateMessage, updatePreset, updateTokenCount, updateUserKey, updateUserPlugins, useAbortRequestWithMessage, useAvailablePluginsQuery, useClearConversationsMutation, useCreatePresetMutation, useDeleteConversationMutation, useDeletePresetMutation, useGetConversationByIdMutation, useGetConversationByIdQuery, useGetConversationsQuery, useGetEndpointsQuery, useGetMessagesByConvoId, useGetPresetsQuery, useGetSearchEnabledQuery, useGetStartupConfig, useGetUserQuery, useLoginUserMutation, useLogoutUserMutation, useRefreshTokenMutation, useRegisterUserMutation, useRequestPasswordResetMutation, useResetPasswordMutation, useRevokeAllUserKeysMutation, useRevokeUserKeyMutation, useSearchQuery, useUpdateConversationMutation, useUpdateMessageMutation, useUpdatePresetMutation, useUpdateTokenCountMutation, useUpdateUserKeysMutation, useUpdateUserPluginsMutation, useUserKeyQuery, userKeyQuery };
|
|
1208
|
+
export { EModelEndpoint, QueryKeys, SSE, abortRequestWithMessage, anthropicSchema, bingAISchema, chatGPTBrowserSchema, clearAllConversations, createPayload, createPreset, deleteConversation, deletePreset, eModelEndpointSchema, getAIEndpoints, getAvailablePlugins, getConversationById, getConversations, getLoginGoogle, getMessagesByConvoId, getModels, getPresets, getResponseSender, getSearchEnabled, getStartupConfig, getUser, getUserBalance, googleSchema, gptPluginsSchema, login, logout, openAISchema, parseConvo, refreshToken, register, requestPasswordReset, resetPassword, revokeAllUserKeys, revokeUserKey, searchConversations, setAcceptLanguageHeader, setTokenHeader, tAgentOptionsSchema, tConversationSchema, tExampleSchema, tMessageSchema, tPluginAuthConfigSchema, tPluginSchema, tPresetSchema, updateConversation, updateMessage, updatePreset, updateTokenCount, updateUserKey, updateUserPlugins, useAbortRequestWithMessage, useAvailablePluginsQuery, useClearConversationsMutation, useCreatePresetMutation, useDeleteConversationMutation, useDeletePresetMutation, useGetConversationByIdMutation, useGetConversationByIdQuery, useGetConversationsQuery, useGetEndpointsQuery, useGetMessagesByConvoId, useGetModelsQuery, useGetPresetsQuery, useGetSearchEnabledQuery, useGetStartupConfig, useGetUserBalance, useGetUserQuery, useLoginUserMutation, useLogoutUserMutation, useRefreshTokenMutation, useRegisterUserMutation, useRequestPasswordResetMutation, useResetPasswordMutation, useRevokeAllUserKeysMutation, useRevokeUserKeyMutation, useSearchQuery, useUpdateConversationMutation, useUpdateMessageMutation, useUpdatePresetMutation, useUpdateTokenCountMutation, useUpdateUserKeysMutation, useUpdateUserPluginsMutation, useUserKeyQuery, userKeyQuery };
|
package/dist/index.js
CHANGED
|
@@ -247,6 +247,7 @@ var request = {
|
|
|
247
247
|
};
|
|
248
248
|
|
|
249
249
|
var user = function () { return '/api/user'; };
|
|
250
|
+
var balance = function () { return '/api/balance'; };
|
|
250
251
|
var userPlugins = function () { return '/api/user/plugins'; };
|
|
251
252
|
var messages = function (conversationId, messageId) {
|
|
252
253
|
return "/api/messages/".concat(conversationId).concat(messageId ? "/".concat(messageId) : '');
|
|
@@ -268,6 +269,7 @@ var searchEnabled = function () { return '/api/search/enable'; };
|
|
|
268
269
|
var presets = function () { return '/api/presets'; };
|
|
269
270
|
var deletePreset$1 = function () { return '/api/presets/delete'; };
|
|
270
271
|
var aiEndpoints = function () { return '/api/endpoints'; };
|
|
272
|
+
var models = function () { return '/api/models'; };
|
|
271
273
|
var tokenizer = function () { return '/api/tokenizer'; };
|
|
272
274
|
var login$1 = function () { return '/api/auth/login'; };
|
|
273
275
|
var logout$1 = function () { return '/api/auth/logout'; };
|
|
@@ -339,6 +341,9 @@ function getSearchEnabled() {
|
|
|
339
341
|
function getUser() {
|
|
340
342
|
return request.get(user());
|
|
341
343
|
}
|
|
344
|
+
function getUserBalance() {
|
|
345
|
+
return request.get(balance());
|
|
346
|
+
}
|
|
342
347
|
var searchConversations = function (q, pageNumber) { return __awaiter(void 0, void 0, void 0, function () {
|
|
343
348
|
return __generator(this, function (_a) {
|
|
344
349
|
return [2 /*return*/, request.get(search(q, pageNumber))];
|
|
@@ -347,6 +352,9 @@ var searchConversations = function (q, pageNumber) { return __awaiter(void 0, vo
|
|
|
347
352
|
var getAIEndpoints = function () {
|
|
348
353
|
return request.get(aiEndpoints());
|
|
349
354
|
};
|
|
355
|
+
var getModels = function () {
|
|
356
|
+
return request.get(models());
|
|
357
|
+
};
|
|
350
358
|
var updateTokenCount = function (text) {
|
|
351
359
|
return request.post(tokenizer(), { arg: text });
|
|
352
360
|
};
|
|
@@ -430,7 +438,7 @@ var tMessageSchema = zod.z.object({
|
|
|
430
438
|
overrideParentMessageId: zod.z.string().nullable().optional(),
|
|
431
439
|
bg: zod.z.string().nullable().optional(),
|
|
432
440
|
model: zod.z.string().nullable().optional(),
|
|
433
|
-
title: zod.z.string().nullable().
|
|
441
|
+
title: zod.z.string().nullable().or(zod.z.literal('New Chat')).default('New Chat'),
|
|
434
442
|
sender: zod.z.string(),
|
|
435
443
|
text: zod.z.string(),
|
|
436
444
|
generation: zod.z.string().nullable().optional(),
|
|
@@ -453,7 +461,7 @@ var tMessageSchema = zod.z.object({
|
|
|
453
461
|
});
|
|
454
462
|
var tConversationSchema = zod.z.object({
|
|
455
463
|
conversationId: zod.z.string().nullable(),
|
|
456
|
-
title: zod.z.string(),
|
|
464
|
+
title: zod.z.string().nullable().or(zod.z.literal('New Chat')).default('New Chat'),
|
|
457
465
|
user: zod.z.string().optional(),
|
|
458
466
|
endpoint: eModelEndpointSchema.nullable(),
|
|
459
467
|
suggestions: zod.z.array(zod.z.string()).optional(),
|
|
@@ -662,14 +670,18 @@ function getFirstDefinedValue(possibleValues) {
|
|
|
662
670
|
return returnValue;
|
|
663
671
|
}
|
|
664
672
|
var parseConvo = function (endpoint, conversation, possibleValues) {
|
|
665
|
-
var _a;
|
|
673
|
+
var _a, _b;
|
|
666
674
|
var schema = endpointSchemas[endpoint];
|
|
667
675
|
if (!schema) {
|
|
668
676
|
throw new Error("Unknown endpoint: ".concat(endpoint));
|
|
669
677
|
}
|
|
670
678
|
var convo = schema.parse(conversation);
|
|
671
|
-
|
|
672
|
-
|
|
679
|
+
var _c = possibleValues !== null && possibleValues !== void 0 ? possibleValues : {}, models = _c.models, secondaryModels = _c.secondaryModels;
|
|
680
|
+
if (models && convo) {
|
|
681
|
+
convo.model = (_a = getFirstDefinedValue(models)) !== null && _a !== void 0 ? _a : convo.model;
|
|
682
|
+
}
|
|
683
|
+
if (secondaryModels && convo.agentOptions) {
|
|
684
|
+
convo.agentOptions.model = (_b = getFirstDefinedValue(secondaryModels)) !== null && _b !== void 0 ? _b : convo.agentOptions.model;
|
|
673
685
|
}
|
|
674
686
|
return convo;
|
|
675
687
|
};
|
|
@@ -698,6 +710,8 @@ exports.QueryKeys = void 0;
|
|
|
698
710
|
QueryKeys["searchEnabled"] = "searchEnabled";
|
|
699
711
|
QueryKeys["user"] = "user";
|
|
700
712
|
QueryKeys["name"] = "name";
|
|
713
|
+
QueryKeys["models"] = "models";
|
|
714
|
+
QueryKeys["balance"] = "balance";
|
|
701
715
|
QueryKeys["endpoints"] = "endpoints";
|
|
702
716
|
QueryKeys["presets"] = "presets";
|
|
703
717
|
QueryKeys["searchResults"] = "searchResults";
|
|
@@ -706,9 +720,14 @@ exports.QueryKeys = void 0;
|
|
|
706
720
|
QueryKeys["startupConfig"] = "startupConfig";
|
|
707
721
|
})(exports.QueryKeys || (exports.QueryKeys = {}));
|
|
708
722
|
var useAbortRequestWithMessage = function () {
|
|
723
|
+
var queryClient = reactQuery.useQueryClient();
|
|
709
724
|
return reactQuery.useMutation(function (_a) {
|
|
710
725
|
var endpoint = _a.endpoint, abortKey = _a.abortKey, message = _a.message;
|
|
711
726
|
return abortRequestWithMessage(endpoint, abortKey, message);
|
|
727
|
+
}, {
|
|
728
|
+
onSuccess: function () {
|
|
729
|
+
queryClient.invalidateQueries([exports.QueryKeys.balance]);
|
|
730
|
+
},
|
|
712
731
|
});
|
|
713
732
|
};
|
|
714
733
|
var useGetUserQuery = function (config) {
|
|
@@ -717,6 +736,9 @@ var useGetUserQuery = function (config) {
|
|
|
717
736
|
var useGetMessagesByConvoId = function (id, config) {
|
|
718
737
|
return reactQuery.useQuery([exports.QueryKeys.messages, id], function () { return getMessagesByConvoId(id); }, __assign({ refetchOnWindowFocus: false, refetchOnReconnect: false, refetchOnMount: false }, config));
|
|
719
738
|
};
|
|
739
|
+
var useGetUserBalance = function (config) {
|
|
740
|
+
return reactQuery.useQuery([exports.QueryKeys.balance], function () { return getUserBalance(); }, __assign({ refetchOnWindowFocus: true, refetchOnReconnect: true, refetchOnMount: true }, config));
|
|
741
|
+
};
|
|
720
742
|
var useGetConversationByIdQuery = function (id, config) {
|
|
721
743
|
return reactQuery.useQuery([exports.QueryKeys.conversation, id], function () { return getConversationById(id); }, __assign({ refetchOnWindowFocus: false, refetchOnReconnect: false, refetchOnMount: false }, config));
|
|
722
744
|
};
|
|
@@ -802,6 +824,13 @@ var useGetEndpointsQuery = function () {
|
|
|
802
824
|
refetchOnMount: false,
|
|
803
825
|
});
|
|
804
826
|
};
|
|
827
|
+
var useGetModelsQuery = function () {
|
|
828
|
+
return reactQuery.useQuery([exports.QueryKeys.models], function () { return getModels(); }, {
|
|
829
|
+
refetchOnWindowFocus: false,
|
|
830
|
+
refetchOnReconnect: false,
|
|
831
|
+
refetchOnMount: false,
|
|
832
|
+
});
|
|
833
|
+
};
|
|
805
834
|
var useCreatePresetMutation = function () {
|
|
806
835
|
var queryClient = reactQuery.useQueryClient();
|
|
807
836
|
return reactQuery.useMutation(function (payload) { return createPreset(payload); }, {
|
|
@@ -849,6 +878,9 @@ var useLoginUserMutation = function () {
|
|
|
849
878
|
onSuccess: function () {
|
|
850
879
|
queryClient.invalidateQueries([exports.QueryKeys.user]);
|
|
851
880
|
},
|
|
881
|
+
onMutate: function () {
|
|
882
|
+
queryClient.invalidateQueries([exports.QueryKeys.models]);
|
|
883
|
+
},
|
|
852
884
|
});
|
|
853
885
|
};
|
|
854
886
|
var useRegisterUserMutation = function () {
|
|
@@ -868,7 +900,12 @@ var useLogoutUserMutation = function () {
|
|
|
868
900
|
});
|
|
869
901
|
};
|
|
870
902
|
var useRefreshTokenMutation = function () {
|
|
871
|
-
|
|
903
|
+
var queryClient = reactQuery.useQueryClient();
|
|
904
|
+
return reactQuery.useMutation(function () { return refreshToken(); }, {
|
|
905
|
+
onMutate: function () {
|
|
906
|
+
queryClient.invalidateQueries([exports.QueryKeys.models]);
|
|
907
|
+
},
|
|
908
|
+
});
|
|
872
909
|
};
|
|
873
910
|
var useUserKeyQuery = function (name, config) {
|
|
874
911
|
return reactQuery.useQuery([exports.QueryKeys.name, name], function () {
|
|
@@ -1187,11 +1224,13 @@ exports.getConversationById = getConversationById;
|
|
|
1187
1224
|
exports.getConversations = getConversations;
|
|
1188
1225
|
exports.getLoginGoogle = getLoginGoogle;
|
|
1189
1226
|
exports.getMessagesByConvoId = getMessagesByConvoId;
|
|
1227
|
+
exports.getModels = getModels;
|
|
1190
1228
|
exports.getPresets = getPresets;
|
|
1191
1229
|
exports.getResponseSender = getResponseSender;
|
|
1192
1230
|
exports.getSearchEnabled = getSearchEnabled;
|
|
1193
1231
|
exports.getStartupConfig = getStartupConfig;
|
|
1194
1232
|
exports.getUser = getUser;
|
|
1233
|
+
exports.getUserBalance = getUserBalance;
|
|
1195
1234
|
exports.googleSchema = googleSchema;
|
|
1196
1235
|
exports.gptPluginsSchema = gptPluginsSchema;
|
|
1197
1236
|
exports.login = login;
|
|
@@ -1231,9 +1270,11 @@ exports.useGetConversationByIdQuery = useGetConversationByIdQuery;
|
|
|
1231
1270
|
exports.useGetConversationsQuery = useGetConversationsQuery;
|
|
1232
1271
|
exports.useGetEndpointsQuery = useGetEndpointsQuery;
|
|
1233
1272
|
exports.useGetMessagesByConvoId = useGetMessagesByConvoId;
|
|
1273
|
+
exports.useGetModelsQuery = useGetModelsQuery;
|
|
1234
1274
|
exports.useGetPresetsQuery = useGetPresetsQuery;
|
|
1235
1275
|
exports.useGetSearchEnabledQuery = useGetSearchEnabledQuery;
|
|
1236
1276
|
exports.useGetStartupConfig = useGetStartupConfig;
|
|
1277
|
+
exports.useGetUserBalance = useGetUserBalance;
|
|
1237
1278
|
exports.useGetUserQuery = useGetUserQuery;
|
|
1238
1279
|
exports.useLoginUserMutation = useLoginUserMutation;
|
|
1239
1280
|
exports.useLogoutUserMutation = useLogoutUserMutation;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "librechat-data-provider",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "data services for librechat apps",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.es.js",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@tanstack/react-query": "^4.28.0",
|
|
30
30
|
"axios": "^1.3.4",
|
|
31
|
-
"
|
|
31
|
+
"openai": "^4.11.1",
|
|
32
|
+
"zod": "^3.22.4"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@babel/preset-env": "^7.21.5",
|
package/src/api-endpoints.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export const user = () => '/api/user';
|
|
2
2
|
|
|
3
|
+
export const balance = () => '/api/balance';
|
|
4
|
+
|
|
3
5
|
export const userPlugins = () => '/api/user/plugins';
|
|
4
6
|
|
|
5
7
|
export const messages = (conversationId: string, messageId?: string) =>
|
|
@@ -36,6 +38,8 @@ export const deletePreset = () => '/api/presets/delete';
|
|
|
36
38
|
|
|
37
39
|
export const aiEndpoints = () => '/api/endpoints';
|
|
38
40
|
|
|
41
|
+
export const models = () => '/api/models';
|
|
42
|
+
|
|
39
43
|
export const tokenizer = () => '/api/tokenizer';
|
|
40
44
|
|
|
41
45
|
export const login = () => '/api/auth/login';
|
package/src/data-service.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as t from './types';
|
|
2
2
|
import * as s from './schemas';
|
|
3
|
+
/* TODO: fix dependency cycle */
|
|
4
|
+
// eslint-disable-next-line import/no-cycle
|
|
3
5
|
import request from './request';
|
|
4
6
|
import * as endpoints from './api-endpoints';
|
|
5
7
|
|
|
@@ -88,6 +90,10 @@ export function getUser(): Promise<t.TUser> {
|
|
|
88
90
|
return request.get(endpoints.user());
|
|
89
91
|
}
|
|
90
92
|
|
|
93
|
+
export function getUserBalance(): Promise<string> {
|
|
94
|
+
return request.get(endpoints.balance());
|
|
95
|
+
}
|
|
96
|
+
|
|
91
97
|
export const searchConversations = async (
|
|
92
98
|
q: string,
|
|
93
99
|
pageNumber: string,
|
|
@@ -99,6 +105,10 @@ export const getAIEndpoints = () => {
|
|
|
99
105
|
return request.get(endpoints.aiEndpoints());
|
|
100
106
|
};
|
|
101
107
|
|
|
108
|
+
export const getModels = () => {
|
|
109
|
+
return request.get(endpoints.models());
|
|
110
|
+
};
|
|
111
|
+
|
|
102
112
|
export const updateTokenCount = (text: string) => {
|
|
103
113
|
return request.post(endpoints.tokenizer(), { arg: text });
|
|
104
114
|
};
|
|
@@ -17,6 +17,8 @@ export enum QueryKeys {
|
|
|
17
17
|
searchEnabled = 'searchEnabled',
|
|
18
18
|
user = 'user',
|
|
19
19
|
name = 'name', // user key name
|
|
20
|
+
models = 'models',
|
|
21
|
+
balance = 'balance',
|
|
20
22
|
endpoints = 'endpoints',
|
|
21
23
|
presets = 'presets',
|
|
22
24
|
searchResults = 'searchResults',
|
|
@@ -30,8 +32,15 @@ export const useAbortRequestWithMessage = (): UseMutationResult<
|
|
|
30
32
|
Error,
|
|
31
33
|
{ endpoint: string; abortKey: string; message: string }
|
|
32
34
|
> => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
const queryClient = useQueryClient();
|
|
36
|
+
return useMutation(
|
|
37
|
+
({ endpoint, abortKey, message }) =>
|
|
38
|
+
dataService.abortRequestWithMessage(endpoint, abortKey, message),
|
|
39
|
+
{
|
|
40
|
+
onSuccess: () => {
|
|
41
|
+
queryClient.invalidateQueries([QueryKeys.balance]);
|
|
42
|
+
},
|
|
43
|
+
},
|
|
35
44
|
);
|
|
36
45
|
};
|
|
37
46
|
|
|
@@ -63,6 +72,17 @@ export const useGetMessagesByConvoId = (
|
|
|
63
72
|
);
|
|
64
73
|
};
|
|
65
74
|
|
|
75
|
+
export const useGetUserBalance = (
|
|
76
|
+
config?: UseQueryOptions<string>,
|
|
77
|
+
): QueryObserverResult<string> => {
|
|
78
|
+
return useQuery<string>([QueryKeys.balance], () => dataService.getUserBalance(), {
|
|
79
|
+
refetchOnWindowFocus: true,
|
|
80
|
+
refetchOnReconnect: true,
|
|
81
|
+
refetchOnMount: true,
|
|
82
|
+
...config,
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
|
|
66
86
|
export const useGetConversationByIdQuery = (
|
|
67
87
|
id: string,
|
|
68
88
|
config?: UseQueryOptions<s.TConversation>,
|
|
@@ -218,6 +238,14 @@ export const useGetEndpointsQuery = (): QueryObserverResult<t.TEndpointsConfig>
|
|
|
218
238
|
});
|
|
219
239
|
};
|
|
220
240
|
|
|
241
|
+
export const useGetModelsQuery = (): QueryObserverResult<t.TModelsConfig> => {
|
|
242
|
+
return useQuery([QueryKeys.models], () => dataService.getModels(), {
|
|
243
|
+
refetchOnWindowFocus: false,
|
|
244
|
+
refetchOnReconnect: false,
|
|
245
|
+
refetchOnMount: false,
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
|
|
221
249
|
export const useCreatePresetMutation = (): UseMutationResult<
|
|
222
250
|
s.TPreset[],
|
|
223
251
|
unknown,
|
|
@@ -313,6 +341,9 @@ export const useLoginUserMutation = (): UseMutationResult<
|
|
|
313
341
|
onSuccess: () => {
|
|
314
342
|
queryClient.invalidateQueries([QueryKeys.user]);
|
|
315
343
|
},
|
|
344
|
+
onMutate: () => {
|
|
345
|
+
queryClient.invalidateQueries([QueryKeys.models]);
|
|
346
|
+
},
|
|
316
347
|
});
|
|
317
348
|
};
|
|
318
349
|
|
|
@@ -345,7 +376,12 @@ export const useRefreshTokenMutation = (): UseMutationResult<
|
|
|
345
376
|
unknown,
|
|
346
377
|
unknown
|
|
347
378
|
> => {
|
|
348
|
-
|
|
379
|
+
const queryClient = useQueryClient();
|
|
380
|
+
return useMutation(() => dataService.refreshToken(), {
|
|
381
|
+
onMutate: () => {
|
|
382
|
+
queryClient.invalidateQueries([QueryKeys.models]);
|
|
383
|
+
},
|
|
384
|
+
});
|
|
349
385
|
};
|
|
350
386
|
|
|
351
387
|
export const useUserKeyQuery = (
|
package/src/request.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import axios, { AxiosRequestConfig, AxiosError } from 'axios';
|
|
3
|
+
/* TODO: fix dependency cycle */
|
|
3
4
|
// eslint-disable-next-line import/no-cycle
|
|
4
5
|
import { refreshToken } from './data-service';
|
|
5
6
|
import { setTokenHeader } from './headers-helpers';
|
package/src/schemas.ts
CHANGED
|
@@ -73,7 +73,7 @@ export const tMessageSchema = z.object({
|
|
|
73
73
|
overrideParentMessageId: z.string().nullable().optional(),
|
|
74
74
|
bg: z.string().nullable().optional(),
|
|
75
75
|
model: z.string().nullable().optional(),
|
|
76
|
-
title: z.string().nullable().
|
|
76
|
+
title: z.string().nullable().or(z.literal('New Chat')).default('New Chat'),
|
|
77
77
|
sender: z.string(),
|
|
78
78
|
text: z.string(),
|
|
79
79
|
generation: z.string().nullable().optional(),
|
|
@@ -103,7 +103,7 @@ export type TMessage = z.input<typeof tMessageSchema> & {
|
|
|
103
103
|
|
|
104
104
|
export const tConversationSchema = z.object({
|
|
105
105
|
conversationId: z.string().nullable(),
|
|
106
|
-
title: z.string(),
|
|
106
|
+
title: z.string().nullable().or(z.literal('New Chat')).default('New Chat'),
|
|
107
107
|
user: z.string().optional(),
|
|
108
108
|
endpoint: eModelEndpointSchema.nullable(),
|
|
109
109
|
suggestions: z.array(z.string()).optional(),
|
|
@@ -369,7 +369,8 @@ function getFirstDefinedValue(possibleValues: string[]) {
|
|
|
369
369
|
}
|
|
370
370
|
|
|
371
371
|
type TPossibleValues = {
|
|
372
|
-
|
|
372
|
+
models: string[];
|
|
373
|
+
secondaryModels?: string[];
|
|
373
374
|
};
|
|
374
375
|
|
|
375
376
|
export const parseConvo = (
|
|
@@ -383,10 +384,15 @@ export const parseConvo = (
|
|
|
383
384
|
throw new Error(`Unknown endpoint: ${endpoint}`);
|
|
384
385
|
}
|
|
385
386
|
|
|
386
|
-
const convo = schema.parse(conversation);
|
|
387
|
+
const convo = schema.parse(conversation) as TConversation;
|
|
388
|
+
const { models, secondaryModels } = possibleValues ?? {};
|
|
387
389
|
|
|
388
|
-
if (
|
|
389
|
-
convo.model = getFirstDefinedValue(
|
|
390
|
+
if (models && convo) {
|
|
391
|
+
convo.model = getFirstDefinedValue(models) ?? convo.model;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (secondaryModels && convo.agentOptions) {
|
|
395
|
+
convo.agentOptions.model = getFirstDefinedValue(secondaryModels) ?? convo.agentOptions.model;
|
|
390
396
|
}
|
|
391
397
|
|
|
392
398
|
return convo;
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
2
|
import type { UseMutationResult } from '@tanstack/react-query';
|
|
3
|
+
import type { TResPlugin, TMessage, TConversation, TEndpointOption } from './schemas';
|
|
4
|
+
|
|
5
|
+
export type TOpenAIMessage = OpenAI.Chat.ChatCompletionMessageParam;
|
|
6
|
+
export type TOpenAIFunction = OpenAI.Chat.ChatCompletionCreateParams.Function;
|
|
7
|
+
export type TOpenAIFunctionCall = OpenAI.Chat.ChatCompletionCreateParams.FunctionCallOption;
|
|
3
8
|
|
|
4
9
|
export type TMutation = UseMutationResult<unknown>;
|
|
5
10
|
|
|
@@ -69,6 +74,7 @@ export type TGetConversationsResponse = {
|
|
|
69
74
|
export type TUpdateMessageRequest = {
|
|
70
75
|
conversationId: string;
|
|
71
76
|
messageId: string;
|
|
77
|
+
model: string;
|
|
72
78
|
text: string;
|
|
73
79
|
};
|
|
74
80
|
|
|
@@ -111,21 +117,16 @@ export type TSearchResults = {
|
|
|
111
117
|
};
|
|
112
118
|
|
|
113
119
|
export type TConfig = {
|
|
114
|
-
availableModels
|
|
120
|
+
availableModels?: [];
|
|
115
121
|
userProvide?: boolean | null;
|
|
116
122
|
availableTools?: [];
|
|
117
123
|
plugins?: [];
|
|
124
|
+
azure?: boolean;
|
|
118
125
|
};
|
|
119
126
|
|
|
120
|
-
export type
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
chatGPTBrowser: TConfig | null;
|
|
124
|
-
anthropic: TConfig | null;
|
|
125
|
-
google: TConfig | null;
|
|
126
|
-
openAI: TConfig | null;
|
|
127
|
-
gptPlugins: TConfig | null;
|
|
128
|
-
};
|
|
127
|
+
export type TModelsConfig = Record<string, string[]>;
|
|
128
|
+
|
|
129
|
+
export type TEndpointsConfig = Record<string, TConfig | null>;
|
|
129
130
|
|
|
130
131
|
export type TUpdateTokenCountResponse = {
|
|
131
132
|
count: number;
|
|
@@ -179,6 +180,7 @@ export type TStartupConfig = {
|
|
|
179
180
|
registrationEnabled: boolean;
|
|
180
181
|
socialLoginEnabled: boolean;
|
|
181
182
|
emailEnabled: boolean;
|
|
183
|
+
checkBalance: boolean;
|
|
182
184
|
};
|
|
183
185
|
|
|
184
186
|
export type TRefreshTokenResponse = {
|
package/types/api-endpoints.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const user: () => string;
|
|
2
|
+
export declare const balance: () => string;
|
|
2
3
|
export declare const userPlugins: () => string;
|
|
3
4
|
export declare const messages: (conversationId: string, messageId?: string) => string;
|
|
4
5
|
export declare const keys: () => string;
|
|
@@ -15,6 +16,7 @@ export declare const searchEnabled: () => string;
|
|
|
15
16
|
export declare const presets: () => string;
|
|
16
17
|
export declare const deletePreset: () => string;
|
|
17
18
|
export declare const aiEndpoints: () => string;
|
|
19
|
+
export declare const models: () => string;
|
|
18
20
|
export declare const tokenizer: () => string;
|
|
19
21
|
export declare const login: () => string;
|
|
20
22
|
export declare const logout: () => string;
|
package/types/data-service.d.ts
CHANGED
|
@@ -17,8 +17,10 @@ export declare function updatePreset(payload: s.TPreset): Promise<s.TPreset[]>;
|
|
|
17
17
|
export declare function deletePreset(arg: s.TPreset | object): Promise<s.TPreset[]>;
|
|
18
18
|
export declare function getSearchEnabled(): Promise<boolean>;
|
|
19
19
|
export declare function getUser(): Promise<t.TUser>;
|
|
20
|
+
export declare function getUserBalance(): Promise<string>;
|
|
20
21
|
export declare const searchConversations: (q: string, pageNumber: string) => Promise<t.TSearchResults>;
|
|
21
22
|
export declare const getAIEndpoints: () => Promise<unknown>;
|
|
23
|
+
export declare const getModels: () => Promise<unknown>;
|
|
22
24
|
export declare const updateTokenCount: (text: string) => Promise<any>;
|
|
23
25
|
export declare const login: (payload: t.TLoginUser) => Promise<any>;
|
|
24
26
|
export declare const logout: () => Promise<any>;
|
|
@@ -8,6 +8,8 @@ export declare enum QueryKeys {
|
|
|
8
8
|
searchEnabled = "searchEnabled",
|
|
9
9
|
user = "user",
|
|
10
10
|
name = "name",
|
|
11
|
+
models = "models",
|
|
12
|
+
balance = "balance",
|
|
11
13
|
endpoints = "endpoints",
|
|
12
14
|
presets = "presets",
|
|
13
15
|
searchResults = "searchResults",
|
|
@@ -22,6 +24,7 @@ export declare const useAbortRequestWithMessage: () => UseMutationResult<void, E
|
|
|
22
24
|
}>;
|
|
23
25
|
export declare const useGetUserQuery: (config?: UseQueryOptions<t.TUser>) => QueryObserverResult<t.TUser>;
|
|
24
26
|
export declare const useGetMessagesByConvoId: (id: string, config?: UseQueryOptions<s.TMessage[]>) => QueryObserverResult<s.TMessage[]>;
|
|
27
|
+
export declare const useGetUserBalance: (config?: UseQueryOptions<string>) => QueryObserverResult<string>;
|
|
25
28
|
export declare const useGetConversationByIdQuery: (id: string, config?: UseQueryOptions<s.TConversation>) => QueryObserverResult<s.TConversation>;
|
|
26
29
|
export declare const useGetConversationByIdMutation: (id: string) => UseMutationResult<s.TConversation>;
|
|
27
30
|
export declare const useUpdateConversationMutation: (id: string) => UseMutationResult<t.TUpdateConversationResponse, unknown, t.TUpdateConversationRequest, unknown>;
|
|
@@ -34,6 +37,7 @@ export declare const useRevokeAllUserKeysMutation: () => UseMutationResult<unkno
|
|
|
34
37
|
export declare const useGetConversationsQuery: (pageNumber: string, config?: UseQueryOptions<t.TGetConversationsResponse>) => QueryObserverResult<t.TGetConversationsResponse>;
|
|
35
38
|
export declare const useGetSearchEnabledQuery: (config?: UseQueryOptions<boolean>) => QueryObserverResult<boolean>;
|
|
36
39
|
export declare const useGetEndpointsQuery: () => QueryObserverResult<t.TEndpointsConfig>;
|
|
40
|
+
export declare const useGetModelsQuery: () => QueryObserverResult<t.TModelsConfig>;
|
|
37
41
|
export declare const useCreatePresetMutation: () => UseMutationResult<s.TPreset[], unknown, s.TPreset, unknown>;
|
|
38
42
|
export declare const useUpdatePresetMutation: () => UseMutationResult<s.TPreset[], unknown, s.TPreset, unknown>;
|
|
39
43
|
export declare const useGetPresetsQuery: (config?: UseQueryOptions<s.TPreset[]>) => QueryObserverResult<s.TPreset[], unknown>;
|
package/types/schemas.d.ts
CHANGED
|
@@ -137,7 +137,7 @@ export declare const tMessageSchema: z.ZodObject<{
|
|
|
137
137
|
overrideParentMessageId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
138
138
|
bg: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
139
139
|
model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
140
|
-
title: z.
|
|
140
|
+
title: z.ZodDefault<z.ZodUnion<[z.ZodNullable<z.ZodString>, z.ZodLiteral<"New Chat">]>>;
|
|
141
141
|
sender: z.ZodString;
|
|
142
142
|
text: z.ZodString;
|
|
143
143
|
generation: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -156,6 +156,7 @@ export declare const tMessageSchema: z.ZodObject<{
|
|
|
156
156
|
messageId: string;
|
|
157
157
|
conversationId: string | null;
|
|
158
158
|
parentMessageId: string | null;
|
|
159
|
+
title: string | null;
|
|
159
160
|
sender: string;
|
|
160
161
|
text: string;
|
|
161
162
|
isCreatedByUser: boolean;
|
|
@@ -166,7 +167,6 @@ export declare const tMessageSchema: z.ZodObject<{
|
|
|
166
167
|
overrideParentMessageId?: string | null | undefined;
|
|
167
168
|
bg?: string | null | undefined;
|
|
168
169
|
model?: string | null | undefined;
|
|
169
|
-
title?: string | null | undefined;
|
|
170
170
|
generation?: string | null | undefined;
|
|
171
171
|
isEdited?: boolean | undefined;
|
|
172
172
|
current?: boolean | undefined;
|
|
@@ -205,7 +205,7 @@ export type TMessage = z.input<typeof tMessageSchema> & {
|
|
|
205
205
|
};
|
|
206
206
|
export declare const tConversationSchema: z.ZodObject<{
|
|
207
207
|
conversationId: z.ZodNullable<z.ZodString>;
|
|
208
|
-
title: z.ZodString
|
|
208
|
+
title: z.ZodDefault<z.ZodUnion<[z.ZodNullable<z.ZodString>, z.ZodLiteral<"New Chat">]>>;
|
|
209
209
|
user: z.ZodOptional<z.ZodString>;
|
|
210
210
|
endpoint: z.ZodNullable<z.ZodNativeEnum<typeof EModelEndpoint>>;
|
|
211
211
|
suggestions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
@@ -326,7 +326,7 @@ export declare const tConversationSchema: z.ZodObject<{
|
|
|
326
326
|
}>>>;
|
|
327
327
|
}, "strip", z.ZodTypeAny, {
|
|
328
328
|
conversationId: string | null;
|
|
329
|
-
title: string;
|
|
329
|
+
title: string | null;
|
|
330
330
|
createdAt: string;
|
|
331
331
|
updatedAt: string;
|
|
332
332
|
endpoint: EModelEndpoint | null;
|
|
@@ -383,10 +383,10 @@ export declare const tConversationSchema: z.ZodObject<{
|
|
|
383
383
|
} | null | undefined;
|
|
384
384
|
}, {
|
|
385
385
|
conversationId: string | null;
|
|
386
|
-
title: string;
|
|
387
386
|
createdAt: string;
|
|
388
387
|
updatedAt: string;
|
|
389
388
|
endpoint: EModelEndpoint | null;
|
|
389
|
+
title?: string | null | undefined;
|
|
390
390
|
user?: string | undefined;
|
|
391
391
|
suggestions?: string[] | undefined;
|
|
392
392
|
messages?: string[] | undefined;
|
|
@@ -676,7 +676,7 @@ export declare const tPresetSchema: z.ZodObject<{
|
|
|
676
676
|
export type TPreset = z.infer<typeof tPresetSchema>;
|
|
677
677
|
export declare const openAISchema: z.ZodCatch<z.ZodEffects<z.ZodObject<Pick<{
|
|
678
678
|
conversationId: z.ZodNullable<z.ZodString>;
|
|
679
|
-
title: z.ZodString
|
|
679
|
+
title: z.ZodDefault<z.ZodUnion<[z.ZodNullable<z.ZodString>, z.ZodLiteral<"New Chat">]>>;
|
|
680
680
|
user: z.ZodOptional<z.ZodString>;
|
|
681
681
|
endpoint: z.ZodNullable<z.ZodNativeEnum<typeof EModelEndpoint>>;
|
|
682
682
|
suggestions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
@@ -830,7 +830,7 @@ export declare const openAISchema: z.ZodCatch<z.ZodEffects<z.ZodObject<Pick<{
|
|
|
830
830
|
}>>;
|
|
831
831
|
export declare const googleSchema: z.ZodCatch<z.ZodEffects<z.ZodObject<Pick<{
|
|
832
832
|
conversationId: z.ZodNullable<z.ZodString>;
|
|
833
|
-
title: z.ZodString
|
|
833
|
+
title: z.ZodDefault<z.ZodUnion<[z.ZodNullable<z.ZodString>, z.ZodLiteral<"New Chat">]>>;
|
|
834
834
|
user: z.ZodOptional<z.ZodString>;
|
|
835
835
|
endpoint: z.ZodNullable<z.ZodNativeEnum<typeof EModelEndpoint>>;
|
|
836
836
|
suggestions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
@@ -1016,7 +1016,7 @@ export declare const googleSchema: z.ZodCatch<z.ZodEffects<z.ZodObject<Pick<{
|
|
|
1016
1016
|
}>>;
|
|
1017
1017
|
export declare const bingAISchema: z.ZodCatch<z.ZodEffects<z.ZodObject<Pick<{
|
|
1018
1018
|
conversationId: z.ZodNullable<z.ZodString>;
|
|
1019
|
-
title: z.ZodString
|
|
1019
|
+
title: z.ZodDefault<z.ZodUnion<[z.ZodNullable<z.ZodString>, z.ZodLiteral<"New Chat">]>>;
|
|
1020
1020
|
user: z.ZodOptional<z.ZodString>;
|
|
1021
1021
|
endpoint: z.ZodNullable<z.ZodNativeEnum<typeof EModelEndpoint>>;
|
|
1022
1022
|
suggestions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
@@ -1175,7 +1175,7 @@ export declare const bingAISchema: z.ZodCatch<z.ZodEffects<z.ZodObject<Pick<{
|
|
|
1175
1175
|
}>>;
|
|
1176
1176
|
export declare const anthropicSchema: z.ZodCatch<z.ZodEffects<z.ZodObject<Pick<{
|
|
1177
1177
|
conversationId: z.ZodNullable<z.ZodString>;
|
|
1178
|
-
title: z.ZodString
|
|
1178
|
+
title: z.ZodDefault<z.ZodUnion<[z.ZodNullable<z.ZodString>, z.ZodLiteral<"New Chat">]>>;
|
|
1179
1179
|
user: z.ZodOptional<z.ZodString>;
|
|
1180
1180
|
endpoint: z.ZodNullable<z.ZodNativeEnum<typeof EModelEndpoint>>;
|
|
1181
1181
|
suggestions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
@@ -1329,7 +1329,7 @@ export declare const anthropicSchema: z.ZodCatch<z.ZodEffects<z.ZodObject<Pick<{
|
|
|
1329
1329
|
}>>;
|
|
1330
1330
|
export declare const chatGPTBrowserSchema: z.ZodCatch<z.ZodEffects<z.ZodObject<Pick<{
|
|
1331
1331
|
conversationId: z.ZodNullable<z.ZodString>;
|
|
1332
|
-
title: z.ZodString
|
|
1332
|
+
title: z.ZodDefault<z.ZodUnion<[z.ZodNullable<z.ZodString>, z.ZodLiteral<"New Chat">]>>;
|
|
1333
1333
|
user: z.ZodOptional<z.ZodString>;
|
|
1334
1334
|
endpoint: z.ZodNullable<z.ZodNativeEnum<typeof EModelEndpoint>>;
|
|
1335
1335
|
suggestions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
@@ -1459,7 +1459,7 @@ export declare const chatGPTBrowserSchema: z.ZodCatch<z.ZodEffects<z.ZodObject<P
|
|
|
1459
1459
|
}>>;
|
|
1460
1460
|
export declare const gptPluginsSchema: z.ZodCatch<z.ZodEffects<z.ZodObject<Pick<{
|
|
1461
1461
|
conversationId: z.ZodNullable<z.ZodString>;
|
|
1462
|
-
title: z.ZodString
|
|
1462
|
+
title: z.ZodDefault<z.ZodUnion<[z.ZodNullable<z.ZodString>, z.ZodLiteral<"New Chat">]>>;
|
|
1463
1463
|
user: z.ZodOptional<z.ZodString>;
|
|
1464
1464
|
endpoint: z.ZodNullable<z.ZodNativeEnum<typeof EModelEndpoint>>;
|
|
1465
1465
|
suggestions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
@@ -1688,10 +1688,66 @@ export declare const gptPluginsSchema: z.ZodCatch<z.ZodEffects<z.ZodObject<Pick<
|
|
|
1688
1688
|
} | null | undefined;
|
|
1689
1689
|
}>>;
|
|
1690
1690
|
type TPossibleValues = {
|
|
1691
|
-
|
|
1691
|
+
models: string[];
|
|
1692
|
+
secondaryModels?: string[];
|
|
1692
1693
|
};
|
|
1693
1694
|
export declare const parseConvo: (endpoint: EModelEndpoint, conversation: Partial<TConversation | TPreset>, possibleValues?: TPossibleValues) => {
|
|
1694
|
-
|
|
1695
|
+
conversationId: string | null;
|
|
1696
|
+
title: string | null;
|
|
1697
|
+
createdAt: string;
|
|
1698
|
+
updatedAt: string;
|
|
1699
|
+
endpoint: EModelEndpoint | null;
|
|
1700
|
+
user?: string | undefined;
|
|
1701
|
+
suggestions?: string[] | undefined;
|
|
1702
|
+
messages?: string[] | undefined;
|
|
1703
|
+
tools?: {
|
|
1704
|
+
description: string;
|
|
1705
|
+
name: string;
|
|
1706
|
+
pluginKey: string;
|
|
1707
|
+
icon: string;
|
|
1708
|
+
authConfig: {
|
|
1709
|
+
authField: string;
|
|
1710
|
+
label: string;
|
|
1711
|
+
description: string;
|
|
1712
|
+
}[];
|
|
1713
|
+
authenticated?: boolean | undefined;
|
|
1714
|
+
isButton?: boolean | undefined;
|
|
1715
|
+
}[] | undefined;
|
|
1716
|
+
systemMessage?: string | null | undefined;
|
|
1717
|
+
modelLabel?: string | null | undefined;
|
|
1718
|
+
examples?: {
|
|
1719
|
+
input: {
|
|
1720
|
+
content: string;
|
|
1721
|
+
};
|
|
1722
|
+
output: {
|
|
1723
|
+
content: string;
|
|
1724
|
+
};
|
|
1725
|
+
}[] | undefined;
|
|
1726
|
+
chatGptLabel?: string | null | undefined;
|
|
1727
|
+
userLabel?: string | undefined;
|
|
1728
|
+
model?: string | null | undefined;
|
|
1729
|
+
promptPrefix?: string | null | undefined;
|
|
1730
|
+
temperature?: number | undefined;
|
|
1731
|
+
topP?: number | undefined;
|
|
1732
|
+
topK?: number | undefined;
|
|
1733
|
+
context?: string | null | undefined;
|
|
1734
|
+
top_p?: number | undefined;
|
|
1735
|
+
frequency_penalty?: number | undefined;
|
|
1736
|
+
presence_penalty?: number | undefined;
|
|
1737
|
+
jailbreak?: boolean | undefined;
|
|
1738
|
+
jailbreakConversationId?: string | null | undefined;
|
|
1739
|
+
conversationSignature?: string | null | undefined;
|
|
1740
|
+
parentMessageId?: string | undefined;
|
|
1741
|
+
clientId?: string | null | undefined;
|
|
1742
|
+
invocationId?: number | null | undefined;
|
|
1743
|
+
toneStyle?: string | null | undefined;
|
|
1744
|
+
maxOutputTokens?: number | undefined;
|
|
1745
|
+
agentOptions?: {
|
|
1746
|
+
agent: string;
|
|
1747
|
+
skipCompletion: boolean;
|
|
1748
|
+
model: string;
|
|
1749
|
+
temperature: number;
|
|
1750
|
+
} | null | undefined;
|
|
1695
1751
|
};
|
|
1696
1752
|
export type TEndpointOption = {
|
|
1697
1753
|
endpoint: EModelEndpoint;
|
package/types/types.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
2
|
import type { UseMutationResult } from '@tanstack/react-query';
|
|
3
|
+
import type { TResPlugin, TMessage, TConversation, TEndpointOption } from './schemas';
|
|
4
|
+
export type TOpenAIMessage = OpenAI.Chat.ChatCompletionMessageParam;
|
|
5
|
+
export type TOpenAIFunction = OpenAI.Chat.ChatCompletionCreateParams.Function;
|
|
6
|
+
export type TOpenAIFunctionCall = OpenAI.Chat.ChatCompletionCreateParams.FunctionCallOption;
|
|
3
7
|
export type TMutation = UseMutationResult<unknown>;
|
|
4
8
|
export * from './schemas';
|
|
5
9
|
export type TMessages = TMessage[];
|
|
@@ -58,6 +62,7 @@ export type TGetConversationsResponse = {
|
|
|
58
62
|
export type TUpdateMessageRequest = {
|
|
59
63
|
conversationId: string;
|
|
60
64
|
messageId: string;
|
|
65
|
+
model: string;
|
|
61
66
|
text: string;
|
|
62
67
|
};
|
|
63
68
|
export type TUpdateUserKeyRequest = {
|
|
@@ -93,20 +98,14 @@ export type TSearchResults = {
|
|
|
93
98
|
filter: object;
|
|
94
99
|
};
|
|
95
100
|
export type TConfig = {
|
|
96
|
-
availableModels
|
|
101
|
+
availableModels?: [];
|
|
97
102
|
userProvide?: boolean | null;
|
|
98
103
|
availableTools?: [];
|
|
99
104
|
plugins?: [];
|
|
105
|
+
azure?: boolean;
|
|
100
106
|
};
|
|
101
|
-
export type
|
|
102
|
-
|
|
103
|
-
bingAI: TConfig | null;
|
|
104
|
-
chatGPTBrowser: TConfig | null;
|
|
105
|
-
anthropic: TConfig | null;
|
|
106
|
-
google: TConfig | null;
|
|
107
|
-
openAI: TConfig | null;
|
|
108
|
-
gptPlugins: TConfig | null;
|
|
109
|
-
};
|
|
107
|
+
export type TModelsConfig = Record<string, string[]>;
|
|
108
|
+
export type TEndpointsConfig = Record<string, TConfig | null>;
|
|
110
109
|
export type TUpdateTokenCountResponse = {
|
|
111
110
|
count: number;
|
|
112
111
|
};
|
|
@@ -150,6 +149,7 @@ export type TStartupConfig = {
|
|
|
150
149
|
registrationEnabled: boolean;
|
|
151
150
|
socialLoginEnabled: boolean;
|
|
152
151
|
emailEnabled: boolean;
|
|
152
|
+
checkBalance: boolean;
|
|
153
153
|
};
|
|
154
154
|
export type TRefreshTokenResponse = {
|
|
155
155
|
token: string;
|