librechat-data-provider 0.1.9 → 0.2.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 +74 -53
- package/dist/index.js +75 -51
- package/package.json +3 -2
- package/src/api-endpoints.ts +2 -0
- package/src/data-service.ts +5 -1
- package/src/index.ts +1 -1
- package/src/react-query-service.ts +27 -5
- package/src/request.ts +9 -10
- package/src/types.ts +8 -1
- package/types/api-endpoints.d.ts +1 -0
- package/types/data-service.d.ts +2 -1
- package/types/index.d.ts +1 -1
- package/types/react-query-service.d.ts +4 -2
- package/types/types.d.ts +7 -1
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.
|
|
@@ -94,49 +94,59 @@ var processQueue = function (error, token) {
|
|
|
94
94
|
});
|
|
95
95
|
failedQueue = [];
|
|
96
96
|
};
|
|
97
|
-
axios.interceptors.response.use(function (response) { return response; }, function (error) {
|
|
98
|
-
var originalRequest
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
97
|
+
axios.interceptors.response.use(function (response) { return response; }, function (error) { return __awaiter(void 0, void 0, void 0, function () {
|
|
98
|
+
var originalRequest, token, err_1;
|
|
99
|
+
return __generator(this, function (_a) {
|
|
100
|
+
switch (_a.label) {
|
|
101
|
+
case 0:
|
|
102
|
+
originalRequest = error.config;
|
|
103
|
+
if (!(error.response.status === 401 && !originalRequest._retry)) return [3 /*break*/, 7];
|
|
104
|
+
if (!isRefreshing) return [3 /*break*/, 6];
|
|
105
|
+
_a.label = 1;
|
|
106
|
+
case 1:
|
|
107
|
+
_a.trys.push([1, 4, , 6]);
|
|
108
|
+
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
109
|
+
failedQueue.push({ resolve: resolve, reject: reject });
|
|
110
|
+
})];
|
|
111
|
+
case 2:
|
|
112
|
+
token = _a.sent();
|
|
105
113
|
originalRequest.headers['Authorization'] = 'Bearer ' + token;
|
|
106
|
-
return axios(originalRequest);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
114
|
+
return [4 /*yield*/, axios(originalRequest)];
|
|
115
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
116
|
+
case 4:
|
|
117
|
+
err_1 = _a.sent();
|
|
118
|
+
return [4 /*yield*/, Promise.reject(err_1)];
|
|
119
|
+
case 5: return [2 /*return*/, _a.sent()];
|
|
120
|
+
case 6:
|
|
121
|
+
originalRequest._retry = true;
|
|
122
|
+
isRefreshing = true;
|
|
123
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
124
|
+
refreshToken()
|
|
125
|
+
.then(function (_a) {
|
|
126
|
+
var token = _a.token;
|
|
127
|
+
if (token) {
|
|
128
|
+
originalRequest.headers['Authorization'] = 'Bearer ' + token;
|
|
129
|
+
setTokenHeader(token);
|
|
130
|
+
window.dispatchEvent(new CustomEvent('tokenUpdated', { detail: token }));
|
|
131
|
+
processQueue(null, token);
|
|
132
|
+
resolve(axios(originalRequest));
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
window.location.href = '/login';
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
.catch(function (err) {
|
|
139
|
+
processQueue(err, null);
|
|
140
|
+
reject(err);
|
|
141
|
+
})
|
|
142
|
+
.then(function () {
|
|
143
|
+
isRefreshing = false;
|
|
144
|
+
});
|
|
145
|
+
})];
|
|
146
|
+
case 7: return [2 /*return*/, Promise.reject(error)];
|
|
111
147
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return new Promise(function (resolve, reject) {
|
|
115
|
-
refreshToken()
|
|
116
|
-
.then(function (_a) {
|
|
117
|
-
var token = _a.token;
|
|
118
|
-
if (token) {
|
|
119
|
-
originalRequest.headers['Authorization'] = 'Bearer ' + token;
|
|
120
|
-
setTokenHeader(token);
|
|
121
|
-
window.dispatchEvent(new CustomEvent('tokenUpdated', { detail: token }));
|
|
122
|
-
processQueue(null, token);
|
|
123
|
-
resolve(axios(originalRequest));
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
window.location.href = '/login';
|
|
127
|
-
}
|
|
128
|
-
})
|
|
129
|
-
.catch(function (err) {
|
|
130
|
-
processQueue(err, null);
|
|
131
|
-
reject(err);
|
|
132
|
-
})
|
|
133
|
-
.then(function () {
|
|
134
|
-
isRefreshing = false;
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
return Promise.reject(error);
|
|
139
|
-
});
|
|
148
|
+
});
|
|
149
|
+
}); });
|
|
140
150
|
function _get(url, options) {
|
|
141
151
|
return __awaiter(this, void 0, void 0, function () {
|
|
142
152
|
var response;
|
|
@@ -245,6 +255,7 @@ var request = {
|
|
|
245
255
|
};
|
|
246
256
|
|
|
247
257
|
var user = function () { return '/api/user'; };
|
|
258
|
+
var balance = function () { return '/api/balance'; };
|
|
248
259
|
var userPlugins = function () { return '/api/user/plugins'; };
|
|
249
260
|
var messages = function (conversationId, messageId) {
|
|
250
261
|
return "/api/messages/".concat(conversationId).concat(messageId ? "/".concat(messageId) : '');
|
|
@@ -338,6 +349,9 @@ function getSearchEnabled() {
|
|
|
338
349
|
function getUser() {
|
|
339
350
|
return request.get(user());
|
|
340
351
|
}
|
|
352
|
+
function getUserBalance() {
|
|
353
|
+
return request.get(balance());
|
|
354
|
+
}
|
|
341
355
|
var searchConversations = function (q, pageNumber) { return __awaiter(void 0, void 0, void 0, function () {
|
|
342
356
|
return __generator(this, function (_a) {
|
|
343
357
|
return [2 /*return*/, request.get(search(q, pageNumber))];
|
|
@@ -346,9 +360,11 @@ var searchConversations = function (q, pageNumber) { return __awaiter(void 0, vo
|
|
|
346
360
|
var getAIEndpoints = function () {
|
|
347
361
|
return request.get(aiEndpoints());
|
|
348
362
|
};
|
|
349
|
-
var getModels = function () {
|
|
350
|
-
return
|
|
351
|
-
|
|
363
|
+
var getModels = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
364
|
+
return __generator(this, function (_a) {
|
|
365
|
+
return [2 /*return*/, request.get(models())];
|
|
366
|
+
});
|
|
367
|
+
}); };
|
|
352
368
|
var updateTokenCount = function (text) {
|
|
353
369
|
return request.post(tokenizer(), { arg: text });
|
|
354
370
|
};
|
|
@@ -698,13 +714,14 @@ var getResponseSender = function (endpointOption) {
|
|
|
698
714
|
|
|
699
715
|
var QueryKeys;
|
|
700
716
|
(function (QueryKeys) {
|
|
701
|
-
QueryKeys["messages"] = "
|
|
717
|
+
QueryKeys["messages"] = "messages";
|
|
702
718
|
QueryKeys["allConversations"] = "allConversations";
|
|
703
719
|
QueryKeys["conversation"] = "conversation";
|
|
704
720
|
QueryKeys["searchEnabled"] = "searchEnabled";
|
|
705
721
|
QueryKeys["user"] = "user";
|
|
706
722
|
QueryKeys["name"] = "name";
|
|
707
723
|
QueryKeys["models"] = "models";
|
|
724
|
+
QueryKeys["balance"] = "balance";
|
|
708
725
|
QueryKeys["endpoints"] = "endpoints";
|
|
709
726
|
QueryKeys["presets"] = "presets";
|
|
710
727
|
QueryKeys["searchResults"] = "searchResults";
|
|
@@ -713,9 +730,14 @@ var QueryKeys;
|
|
|
713
730
|
QueryKeys["startupConfig"] = "startupConfig";
|
|
714
731
|
})(QueryKeys || (QueryKeys = {}));
|
|
715
732
|
var useAbortRequestWithMessage = function () {
|
|
733
|
+
var queryClient = useQueryClient();
|
|
716
734
|
return useMutation(function (_a) {
|
|
717
735
|
var endpoint = _a.endpoint, abortKey = _a.abortKey, message = _a.message;
|
|
718
736
|
return abortRequestWithMessage(endpoint, abortKey, message);
|
|
737
|
+
}, {
|
|
738
|
+
onSuccess: function () {
|
|
739
|
+
queryClient.invalidateQueries([QueryKeys.balance]);
|
|
740
|
+
},
|
|
719
741
|
});
|
|
720
742
|
};
|
|
721
743
|
var useGetUserQuery = function (config) {
|
|
@@ -724,6 +746,9 @@ var useGetUserQuery = function (config) {
|
|
|
724
746
|
var useGetMessagesByConvoId = function (id, config) {
|
|
725
747
|
return useQuery([QueryKeys.messages, id], function () { return getMessagesByConvoId(id); }, __assign({ refetchOnWindowFocus: false, refetchOnReconnect: false, refetchOnMount: false }, config));
|
|
726
748
|
};
|
|
749
|
+
var useGetUserBalance = function (config) {
|
|
750
|
+
return useQuery([QueryKeys.balance], function () { return getUserBalance(); }, __assign({ refetchOnWindowFocus: true, refetchOnReconnect: true, refetchOnMount: true }, config));
|
|
751
|
+
};
|
|
727
752
|
var useGetConversationByIdQuery = function (id, config) {
|
|
728
753
|
return useQuery([QueryKeys.conversation, id], function () { return getConversationById(id); }, __assign({ refetchOnWindowFocus: false, refetchOnReconnect: false, refetchOnMount: false }, config));
|
|
729
754
|
};
|
|
@@ -809,12 +834,8 @@ var useGetEndpointsQuery = function () {
|
|
|
809
834
|
refetchOnMount: false,
|
|
810
835
|
});
|
|
811
836
|
};
|
|
812
|
-
var useGetModelsQuery = function () {
|
|
813
|
-
return useQuery([QueryKeys.models], function () { return getModels(); }, {
|
|
814
|
-
refetchOnWindowFocus: false,
|
|
815
|
-
refetchOnReconnect: false,
|
|
816
|
-
refetchOnMount: false,
|
|
817
|
-
});
|
|
837
|
+
var useGetModelsQuery = function (config) {
|
|
838
|
+
return useQuery([QueryKeys.models], function () { return getModels(); }, __assign({ refetchOnWindowFocus: false, refetchOnReconnect: false, refetchOnMount: false }, config));
|
|
818
839
|
};
|
|
819
840
|
var useCreatePresetMutation = function () {
|
|
820
841
|
var queryClient = useQueryClient();
|
|
@@ -1192,4 +1213,4 @@ function createPayload(submission) {
|
|
|
1192
1213
|
return { server: server, payload: payload };
|
|
1193
1214
|
}
|
|
1194
1215
|
|
|
1195
|
-
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, 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, useGetUserQuery, useLoginUserMutation, useLogoutUserMutation, useRefreshTokenMutation, useRegisterUserMutation, useRequestPasswordResetMutation, useResetPasswordMutation, useRevokeAllUserKeysMutation, useRevokeUserKeyMutation, useSearchQuery, useUpdateConversationMutation, useUpdateMessageMutation, useUpdatePresetMutation, useUpdateTokenCountMutation, useUpdateUserKeysMutation, useUpdateUserPluginsMutation, useUserKeyQuery, userKeyQuery };
|
|
1216
|
+
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, request, 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
|
@@ -96,49 +96,59 @@ var processQueue = function (error, token) {
|
|
|
96
96
|
});
|
|
97
97
|
failedQueue = [];
|
|
98
98
|
};
|
|
99
|
-
axios.interceptors.response.use(function (response) { return response; }, function (error) {
|
|
100
|
-
var originalRequest
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
axios.interceptors.response.use(function (response) { return response; }, function (error) { return __awaiter(void 0, void 0, void 0, function () {
|
|
100
|
+
var originalRequest, token, err_1;
|
|
101
|
+
return __generator(this, function (_a) {
|
|
102
|
+
switch (_a.label) {
|
|
103
|
+
case 0:
|
|
104
|
+
originalRequest = error.config;
|
|
105
|
+
if (!(error.response.status === 401 && !originalRequest._retry)) return [3 /*break*/, 7];
|
|
106
|
+
if (!isRefreshing) return [3 /*break*/, 6];
|
|
107
|
+
_a.label = 1;
|
|
108
|
+
case 1:
|
|
109
|
+
_a.trys.push([1, 4, , 6]);
|
|
110
|
+
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
111
|
+
failedQueue.push({ resolve: resolve, reject: reject });
|
|
112
|
+
})];
|
|
113
|
+
case 2:
|
|
114
|
+
token = _a.sent();
|
|
107
115
|
originalRequest.headers['Authorization'] = 'Bearer ' + token;
|
|
108
|
-
return axios(originalRequest);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
return [4 /*yield*/, axios(originalRequest)];
|
|
117
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
118
|
+
case 4:
|
|
119
|
+
err_1 = _a.sent();
|
|
120
|
+
return [4 /*yield*/, Promise.reject(err_1)];
|
|
121
|
+
case 5: return [2 /*return*/, _a.sent()];
|
|
122
|
+
case 6:
|
|
123
|
+
originalRequest._retry = true;
|
|
124
|
+
isRefreshing = true;
|
|
125
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
126
|
+
refreshToken()
|
|
127
|
+
.then(function (_a) {
|
|
128
|
+
var token = _a.token;
|
|
129
|
+
if (token) {
|
|
130
|
+
originalRequest.headers['Authorization'] = 'Bearer ' + token;
|
|
131
|
+
setTokenHeader(token);
|
|
132
|
+
window.dispatchEvent(new CustomEvent('tokenUpdated', { detail: token }));
|
|
133
|
+
processQueue(null, token);
|
|
134
|
+
resolve(axios(originalRequest));
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
window.location.href = '/login';
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
.catch(function (err) {
|
|
141
|
+
processQueue(err, null);
|
|
142
|
+
reject(err);
|
|
143
|
+
})
|
|
144
|
+
.then(function () {
|
|
145
|
+
isRefreshing = false;
|
|
146
|
+
});
|
|
147
|
+
})];
|
|
148
|
+
case 7: return [2 /*return*/, Promise.reject(error)];
|
|
113
149
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return new Promise(function (resolve, reject) {
|
|
117
|
-
refreshToken()
|
|
118
|
-
.then(function (_a) {
|
|
119
|
-
var token = _a.token;
|
|
120
|
-
if (token) {
|
|
121
|
-
originalRequest.headers['Authorization'] = 'Bearer ' + token;
|
|
122
|
-
setTokenHeader(token);
|
|
123
|
-
window.dispatchEvent(new CustomEvent('tokenUpdated', { detail: token }));
|
|
124
|
-
processQueue(null, token);
|
|
125
|
-
resolve(axios(originalRequest));
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
window.location.href = '/login';
|
|
129
|
-
}
|
|
130
|
-
})
|
|
131
|
-
.catch(function (err) {
|
|
132
|
-
processQueue(err, null);
|
|
133
|
-
reject(err);
|
|
134
|
-
})
|
|
135
|
-
.then(function () {
|
|
136
|
-
isRefreshing = false;
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
return Promise.reject(error);
|
|
141
|
-
});
|
|
150
|
+
});
|
|
151
|
+
}); });
|
|
142
152
|
function _get(url, options) {
|
|
143
153
|
return __awaiter(this, void 0, void 0, function () {
|
|
144
154
|
var response;
|
|
@@ -247,6 +257,7 @@ var request = {
|
|
|
247
257
|
};
|
|
248
258
|
|
|
249
259
|
var user = function () { return '/api/user'; };
|
|
260
|
+
var balance = function () { return '/api/balance'; };
|
|
250
261
|
var userPlugins = function () { return '/api/user/plugins'; };
|
|
251
262
|
var messages = function (conversationId, messageId) {
|
|
252
263
|
return "/api/messages/".concat(conversationId).concat(messageId ? "/".concat(messageId) : '');
|
|
@@ -340,6 +351,9 @@ function getSearchEnabled() {
|
|
|
340
351
|
function getUser() {
|
|
341
352
|
return request.get(user());
|
|
342
353
|
}
|
|
354
|
+
function getUserBalance() {
|
|
355
|
+
return request.get(balance());
|
|
356
|
+
}
|
|
343
357
|
var searchConversations = function (q, pageNumber) { return __awaiter(void 0, void 0, void 0, function () {
|
|
344
358
|
return __generator(this, function (_a) {
|
|
345
359
|
return [2 /*return*/, request.get(search(q, pageNumber))];
|
|
@@ -348,9 +362,11 @@ var searchConversations = function (q, pageNumber) { return __awaiter(void 0, vo
|
|
|
348
362
|
var getAIEndpoints = function () {
|
|
349
363
|
return request.get(aiEndpoints());
|
|
350
364
|
};
|
|
351
|
-
var getModels = function () {
|
|
352
|
-
return
|
|
353
|
-
|
|
365
|
+
var getModels = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
366
|
+
return __generator(this, function (_a) {
|
|
367
|
+
return [2 /*return*/, request.get(models())];
|
|
368
|
+
});
|
|
369
|
+
}); };
|
|
354
370
|
var updateTokenCount = function (text) {
|
|
355
371
|
return request.post(tokenizer(), { arg: text });
|
|
356
372
|
};
|
|
@@ -700,13 +716,14 @@ var getResponseSender = function (endpointOption) {
|
|
|
700
716
|
|
|
701
717
|
exports.QueryKeys = void 0;
|
|
702
718
|
(function (QueryKeys) {
|
|
703
|
-
QueryKeys["messages"] = "
|
|
719
|
+
QueryKeys["messages"] = "messages";
|
|
704
720
|
QueryKeys["allConversations"] = "allConversations";
|
|
705
721
|
QueryKeys["conversation"] = "conversation";
|
|
706
722
|
QueryKeys["searchEnabled"] = "searchEnabled";
|
|
707
723
|
QueryKeys["user"] = "user";
|
|
708
724
|
QueryKeys["name"] = "name";
|
|
709
725
|
QueryKeys["models"] = "models";
|
|
726
|
+
QueryKeys["balance"] = "balance";
|
|
710
727
|
QueryKeys["endpoints"] = "endpoints";
|
|
711
728
|
QueryKeys["presets"] = "presets";
|
|
712
729
|
QueryKeys["searchResults"] = "searchResults";
|
|
@@ -715,9 +732,14 @@ exports.QueryKeys = void 0;
|
|
|
715
732
|
QueryKeys["startupConfig"] = "startupConfig";
|
|
716
733
|
})(exports.QueryKeys || (exports.QueryKeys = {}));
|
|
717
734
|
var useAbortRequestWithMessage = function () {
|
|
735
|
+
var queryClient = reactQuery.useQueryClient();
|
|
718
736
|
return reactQuery.useMutation(function (_a) {
|
|
719
737
|
var endpoint = _a.endpoint, abortKey = _a.abortKey, message = _a.message;
|
|
720
738
|
return abortRequestWithMessage(endpoint, abortKey, message);
|
|
739
|
+
}, {
|
|
740
|
+
onSuccess: function () {
|
|
741
|
+
queryClient.invalidateQueries([exports.QueryKeys.balance]);
|
|
742
|
+
},
|
|
721
743
|
});
|
|
722
744
|
};
|
|
723
745
|
var useGetUserQuery = function (config) {
|
|
@@ -726,6 +748,9 @@ var useGetUserQuery = function (config) {
|
|
|
726
748
|
var useGetMessagesByConvoId = function (id, config) {
|
|
727
749
|
return reactQuery.useQuery([exports.QueryKeys.messages, id], function () { return getMessagesByConvoId(id); }, __assign({ refetchOnWindowFocus: false, refetchOnReconnect: false, refetchOnMount: false }, config));
|
|
728
750
|
};
|
|
751
|
+
var useGetUserBalance = function (config) {
|
|
752
|
+
return reactQuery.useQuery([exports.QueryKeys.balance], function () { return getUserBalance(); }, __assign({ refetchOnWindowFocus: true, refetchOnReconnect: true, refetchOnMount: true }, config));
|
|
753
|
+
};
|
|
729
754
|
var useGetConversationByIdQuery = function (id, config) {
|
|
730
755
|
return reactQuery.useQuery([exports.QueryKeys.conversation, id], function () { return getConversationById(id); }, __assign({ refetchOnWindowFocus: false, refetchOnReconnect: false, refetchOnMount: false }, config));
|
|
731
756
|
};
|
|
@@ -811,12 +836,8 @@ var useGetEndpointsQuery = function () {
|
|
|
811
836
|
refetchOnMount: false,
|
|
812
837
|
});
|
|
813
838
|
};
|
|
814
|
-
var useGetModelsQuery = function () {
|
|
815
|
-
return reactQuery.useQuery([exports.QueryKeys.models], function () { return getModels(); }, {
|
|
816
|
-
refetchOnWindowFocus: false,
|
|
817
|
-
refetchOnReconnect: false,
|
|
818
|
-
refetchOnMount: false,
|
|
819
|
-
});
|
|
839
|
+
var useGetModelsQuery = function (config) {
|
|
840
|
+
return reactQuery.useQuery([exports.QueryKeys.models], function () { return getModels(); }, __assign({ refetchOnWindowFocus: false, refetchOnReconnect: false, refetchOnMount: false }, config));
|
|
820
841
|
};
|
|
821
842
|
var useCreatePresetMutation = function () {
|
|
822
843
|
var queryClient = reactQuery.useQueryClient();
|
|
@@ -1217,6 +1238,7 @@ exports.getResponseSender = getResponseSender;
|
|
|
1217
1238
|
exports.getSearchEnabled = getSearchEnabled;
|
|
1218
1239
|
exports.getStartupConfig = getStartupConfig;
|
|
1219
1240
|
exports.getUser = getUser;
|
|
1241
|
+
exports.getUserBalance = getUserBalance;
|
|
1220
1242
|
exports.googleSchema = googleSchema;
|
|
1221
1243
|
exports.gptPluginsSchema = gptPluginsSchema;
|
|
1222
1244
|
exports.login = login;
|
|
@@ -1225,6 +1247,7 @@ exports.openAISchema = openAISchema;
|
|
|
1225
1247
|
exports.parseConvo = parseConvo;
|
|
1226
1248
|
exports.refreshToken = refreshToken;
|
|
1227
1249
|
exports.register = register;
|
|
1250
|
+
exports.request = request;
|
|
1228
1251
|
exports.requestPasswordReset = requestPasswordReset;
|
|
1229
1252
|
exports.resetPassword = resetPassword;
|
|
1230
1253
|
exports.revokeAllUserKeys = revokeAllUserKeys;
|
|
@@ -1260,6 +1283,7 @@ exports.useGetModelsQuery = useGetModelsQuery;
|
|
|
1260
1283
|
exports.useGetPresetsQuery = useGetPresetsQuery;
|
|
1261
1284
|
exports.useGetSearchEnabledQuery = useGetSearchEnabledQuery;
|
|
1262
1285
|
exports.useGetStartupConfig = useGetStartupConfig;
|
|
1286
|
+
exports.useGetUserBalance = useGetUserBalance;
|
|
1263
1287
|
exports.useGetUserQuery = useGetUserQuery;
|
|
1264
1288
|
exports.useLoginUserMutation = useLoginUserMutation;
|
|
1265
1289
|
exports.useLogoutUserMutation = useLogoutUserMutation;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "librechat-data-provider",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
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
package/src/data-service.ts
CHANGED
|
@@ -90,6 +90,10 @@ export function getUser(): Promise<t.TUser> {
|
|
|
90
90
|
return request.get(endpoints.user());
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
export function getUserBalance(): Promise<string> {
|
|
94
|
+
return request.get(endpoints.balance());
|
|
95
|
+
}
|
|
96
|
+
|
|
93
97
|
export const searchConversations = async (
|
|
94
98
|
q: string,
|
|
95
99
|
pageNumber: string,
|
|
@@ -101,7 +105,7 @@ export const getAIEndpoints = () => {
|
|
|
101
105
|
return request.get(endpoints.aiEndpoints());
|
|
102
106
|
};
|
|
103
107
|
|
|
104
|
-
export const getModels = () => {
|
|
108
|
+
export const getModels = async (): Promise<t.TModelsConfig> => {
|
|
105
109
|
return request.get(endpoints.models());
|
|
106
110
|
};
|
|
107
111
|
|
package/src/index.ts
CHANGED
|
@@ -11,13 +11,14 @@ import * as s from './schemas';
|
|
|
11
11
|
import * as dataService from './data-service';
|
|
12
12
|
|
|
13
13
|
export enum QueryKeys {
|
|
14
|
-
messages = '
|
|
14
|
+
messages = 'messages',
|
|
15
15
|
allConversations = 'allConversations',
|
|
16
16
|
conversation = 'conversation',
|
|
17
17
|
searchEnabled = 'searchEnabled',
|
|
18
18
|
user = 'user',
|
|
19
19
|
name = 'name', // user key name
|
|
20
20
|
models = 'models',
|
|
21
|
+
balance = 'balance',
|
|
21
22
|
endpoints = 'endpoints',
|
|
22
23
|
presets = 'presets',
|
|
23
24
|
searchResults = 'searchResults',
|
|
@@ -31,8 +32,15 @@ export const useAbortRequestWithMessage = (): UseMutationResult<
|
|
|
31
32
|
Error,
|
|
32
33
|
{ endpoint: string; abortKey: string; message: string }
|
|
33
34
|
> => {
|
|
34
|
-
|
|
35
|
-
|
|
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
|
+
},
|
|
36
44
|
);
|
|
37
45
|
};
|
|
38
46
|
|
|
@@ -64,6 +72,17 @@ export const useGetMessagesByConvoId = (
|
|
|
64
72
|
);
|
|
65
73
|
};
|
|
66
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
|
+
|
|
67
86
|
export const useGetConversationByIdQuery = (
|
|
68
87
|
id: string,
|
|
69
88
|
config?: UseQueryOptions<s.TConversation>,
|
|
@@ -219,11 +238,14 @@ export const useGetEndpointsQuery = (): QueryObserverResult<t.TEndpointsConfig>
|
|
|
219
238
|
});
|
|
220
239
|
};
|
|
221
240
|
|
|
222
|
-
export const useGetModelsQuery = (
|
|
223
|
-
|
|
241
|
+
export const useGetModelsQuery = (
|
|
242
|
+
config?: UseQueryOptions<t.TModelsConfig>,
|
|
243
|
+
): QueryObserverResult<t.TModelsConfig> => {
|
|
244
|
+
return useQuery<t.TModelsConfig>([QueryKeys.models], () => dataService.getModels(), {
|
|
224
245
|
refetchOnWindowFocus: false,
|
|
225
246
|
refetchOnReconnect: false,
|
|
226
247
|
refetchOnMount: false,
|
|
248
|
+
...config,
|
|
227
249
|
});
|
|
228
250
|
};
|
|
229
251
|
|
package/src/request.ts
CHANGED
|
@@ -21,20 +21,19 @@ const processQueue = (error: AxiosError | null, token: string | null = null) =>
|
|
|
21
21
|
|
|
22
22
|
axios.interceptors.response.use(
|
|
23
23
|
(response) => response,
|
|
24
|
-
(error) => {
|
|
24
|
+
async (error) => {
|
|
25
25
|
const originalRequest = error.config;
|
|
26
26
|
if (error.response.status === 401 && !originalRequest._retry) {
|
|
27
27
|
if (isRefreshing) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.then((token) => {
|
|
32
|
-
originalRequest.headers['Authorization'] = 'Bearer ' + token;
|
|
33
|
-
return axios(originalRequest);
|
|
34
|
-
})
|
|
35
|
-
.catch((err) => {
|
|
36
|
-
return Promise.reject(err);
|
|
28
|
+
try {
|
|
29
|
+
const token = await new Promise(function (resolve, reject) {
|
|
30
|
+
failedQueue.push({ resolve, reject });
|
|
37
31
|
});
|
|
32
|
+
originalRequest.headers['Authorization'] = 'Bearer ' + token;
|
|
33
|
+
return await axios(originalRequest);
|
|
34
|
+
} catch (err) {
|
|
35
|
+
return await Promise.reject(err);
|
|
36
|
+
}
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
originalRequest._retry = true;
|
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
|
|
|
@@ -174,6 +180,7 @@ export type TStartupConfig = {
|
|
|
174
180
|
registrationEnabled: boolean;
|
|
175
181
|
socialLoginEnabled: boolean;
|
|
176
182
|
emailEnabled: boolean;
|
|
183
|
+
checkBalance: boolean;
|
|
177
184
|
};
|
|
178
185
|
|
|
179
186
|
export type TRefreshTokenResponse = {
|
package/types/api-endpoints.d.ts
CHANGED
package/types/data-service.d.ts
CHANGED
|
@@ -17,9 +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>;
|
|
22
|
-
export declare const getModels: () => Promise<
|
|
23
|
+
export declare const getModels: () => Promise<t.TModelsConfig>;
|
|
23
24
|
export declare const updateTokenCount: (text: string) => Promise<any>;
|
|
24
25
|
export declare const login: (payload: t.TLoginUser) => Promise<any>;
|
|
25
26
|
export declare const logout: () => Promise<any>;
|
package/types/index.d.ts
CHANGED
|
@@ -2,13 +2,14 @@ import { UseQueryOptions, UseMutationResult, QueryObserverResult } from '@tansta
|
|
|
2
2
|
import * as t from './types';
|
|
3
3
|
import * as s from './schemas';
|
|
4
4
|
export declare enum QueryKeys {
|
|
5
|
-
messages = "
|
|
5
|
+
messages = "messages",
|
|
6
6
|
allConversations = "allConversations",
|
|
7
7
|
conversation = "conversation",
|
|
8
8
|
searchEnabled = "searchEnabled",
|
|
9
9
|
user = "user",
|
|
10
10
|
name = "name",
|
|
11
11
|
models = "models",
|
|
12
|
+
balance = "balance",
|
|
12
13
|
endpoints = "endpoints",
|
|
13
14
|
presets = "presets",
|
|
14
15
|
searchResults = "searchResults",
|
|
@@ -23,6 +24,7 @@ export declare const useAbortRequestWithMessage: () => UseMutationResult<void, E
|
|
|
23
24
|
}>;
|
|
24
25
|
export declare const useGetUserQuery: (config?: UseQueryOptions<t.TUser>) => QueryObserverResult<t.TUser>;
|
|
25
26
|
export declare const useGetMessagesByConvoId: (id: string, config?: UseQueryOptions<s.TMessage[]>) => QueryObserverResult<s.TMessage[]>;
|
|
27
|
+
export declare const useGetUserBalance: (config?: UseQueryOptions<string>) => QueryObserverResult<string>;
|
|
26
28
|
export declare const useGetConversationByIdQuery: (id: string, config?: UseQueryOptions<s.TConversation>) => QueryObserverResult<s.TConversation>;
|
|
27
29
|
export declare const useGetConversationByIdMutation: (id: string) => UseMutationResult<s.TConversation>;
|
|
28
30
|
export declare const useUpdateConversationMutation: (id: string) => UseMutationResult<t.TUpdateConversationResponse, unknown, t.TUpdateConversationRequest, unknown>;
|
|
@@ -35,7 +37,7 @@ export declare const useRevokeAllUserKeysMutation: () => UseMutationResult<unkno
|
|
|
35
37
|
export declare const useGetConversationsQuery: (pageNumber: string, config?: UseQueryOptions<t.TGetConversationsResponse>) => QueryObserverResult<t.TGetConversationsResponse>;
|
|
36
38
|
export declare const useGetSearchEnabledQuery: (config?: UseQueryOptions<boolean>) => QueryObserverResult<boolean>;
|
|
37
39
|
export declare const useGetEndpointsQuery: () => QueryObserverResult<t.TEndpointsConfig>;
|
|
38
|
-
export declare const useGetModelsQuery: () => QueryObserverResult<t.TModelsConfig>;
|
|
40
|
+
export declare const useGetModelsQuery: (config?: UseQueryOptions<t.TModelsConfig>) => QueryObserverResult<t.TModelsConfig>;
|
|
39
41
|
export declare const useCreatePresetMutation: () => UseMutationResult<s.TPreset[], unknown, s.TPreset, unknown>;
|
|
40
42
|
export declare const useUpdatePresetMutation: () => UseMutationResult<s.TPreset[], unknown, s.TPreset, unknown>;
|
|
41
43
|
export declare const useGetPresetsQuery: (config?: UseQueryOptions<s.TPreset[]>) => QueryObserverResult<s.TPreset[], unknown>;
|
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 = {
|
|
@@ -144,6 +149,7 @@ export type TStartupConfig = {
|
|
|
144
149
|
registrationEnabled: boolean;
|
|
145
150
|
socialLoginEnabled: boolean;
|
|
146
151
|
emailEnabled: boolean;
|
|
152
|
+
checkBalance: boolean;
|
|
147
153
|
};
|
|
148
154
|
export type TRefreshTokenResponse = {
|
|
149
155
|
token: string;
|