librechat-data-provider 0.1.7 → 0.1.8

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 CHANGED
@@ -73,6 +73,70 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
73
73
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
74
74
  };
75
75
 
76
+ function setAcceptLanguageHeader(value) {
77
+ axios.defaults.headers.common['Accept-Language'] = value;
78
+ }
79
+ function setTokenHeader(token) {
80
+ axios.defaults.headers.common['Authorization'] = 'Bearer ' + token;
81
+ }
82
+
83
+ var isRefreshing = false;
84
+ var failedQueue = [];
85
+ var processQueue = function (error, token) {
86
+ if (token === void 0) { token = null; }
87
+ failedQueue.forEach(function (prom) {
88
+ if (error) {
89
+ prom.reject(error);
90
+ }
91
+ else {
92
+ prom.resolve(token);
93
+ }
94
+ });
95
+ failedQueue = [];
96
+ };
97
+ axios.interceptors.response.use(function (response) { return response; }, function (error) {
98
+ var originalRequest = error.config;
99
+ if (error.response.status === 401 && !originalRequest._retry) {
100
+ if (isRefreshing) {
101
+ return new Promise(function (resolve, reject) {
102
+ failedQueue.push({ resolve: resolve, reject: reject });
103
+ })
104
+ .then(function (token) {
105
+ originalRequest.headers['Authorization'] = 'Bearer ' + token;
106
+ return axios(originalRequest);
107
+ })
108
+ .catch(function (err) {
109
+ return Promise.reject(err);
110
+ });
111
+ }
112
+ originalRequest._retry = true;
113
+ isRefreshing = true;
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
+ });
76
140
  function _get(url, options) {
77
141
  return __awaiter(this, void 0, void 0, function () {
78
142
  var response;
@@ -368,6 +432,7 @@ var tMessageSchema = z.object({
368
432
  sender: z.string(),
369
433
  text: z.string(),
370
434
  generation: z.string().nullable().optional(),
435
+ isEdited: z.boolean().optional(),
371
436
  isCreatedByUser: z.boolean(),
372
437
  error: z.boolean(),
373
438
  createdAt: z
@@ -515,14 +580,14 @@ var anthropicSchema = tConversationSchema
515
580
  })
516
581
  .transform(function (obj) {
517
582
  var _a, _b, _c, _d, _e, _f, _g;
518
- return (__assign(__assign({}, obj), { model: (_a = obj.model) !== null && _a !== void 0 ? _a : 'claude-1', modelLabel: (_b = obj.modelLabel) !== null && _b !== void 0 ? _b : null, promptPrefix: (_c = obj.promptPrefix) !== null && _c !== void 0 ? _c : null, temperature: (_d = obj.temperature) !== null && _d !== void 0 ? _d : 1, maxOutputTokens: (_e = obj.maxOutputTokens) !== null && _e !== void 0 ? _e : 1024, topP: (_f = obj.topP) !== null && _f !== void 0 ? _f : 0.7, topK: (_g = obj.topK) !== null && _g !== void 0 ? _g : 5 }));
583
+ return (__assign(__assign({}, obj), { model: (_a = obj.model) !== null && _a !== void 0 ? _a : 'claude-1', modelLabel: (_b = obj.modelLabel) !== null && _b !== void 0 ? _b : null, promptPrefix: (_c = obj.promptPrefix) !== null && _c !== void 0 ? _c : null, temperature: (_d = obj.temperature) !== null && _d !== void 0 ? _d : 1, maxOutputTokens: (_e = obj.maxOutputTokens) !== null && _e !== void 0 ? _e : 4000, topP: (_f = obj.topP) !== null && _f !== void 0 ? _f : 0.7, topK: (_g = obj.topK) !== null && _g !== void 0 ? _g : 5 }));
519
584
  })
520
585
  .catch(function () { return ({
521
586
  model: 'claude-1',
522
587
  modelLabel: null,
523
588
  promptPrefix: null,
524
589
  temperature: 1,
525
- maxOutputTokens: 1024,
590
+ maxOutputTokens: 4000,
526
591
  topP: 0.7,
527
592
  topK: 5,
528
593
  }); });
@@ -842,19 +907,13 @@ var useGetStartupConfig = function () {
842
907
  });
843
908
  };
844
909
 
845
- function setAcceptLanguageHeader(value) {
846
- axios.defaults.headers.common['Accept-Language'] = value;
847
- }
848
- function setTokenHeader(token) {
849
- axios.defaults.headers.common['Authorization'] = 'Bearer ' + token;
850
- }
851
-
852
910
  /* eslint-disable */
853
911
  /**
854
912
  * Copyright (C) 2016 Maxime Petazzoni <maxime.petazzoni@bulix.org>.
855
913
  * All rights reserved.
856
914
  */
857
915
 
916
+
858
917
  var SSE = function (url, options) {
859
918
  if (!(this instanceof SSE)) {
860
919
  return new SSE(url, options);
@@ -953,12 +1012,27 @@ var SSE = function (url, options) {
953
1012
  this.close();
954
1013
  };
955
1014
 
956
- this._onStreamProgress = function (e) {
1015
+ this._onStreamProgress = async function (e) {
957
1016
  if (!this.xhr) {
958
1017
  return;
959
1018
  }
960
1019
 
961
- if (this.xhr.status !== 200) {
1020
+ if (this.xhr.status === 401 && !this._retry) {
1021
+ this._retry = true;
1022
+ try {
1023
+ const refreshResponse = await refreshToken();
1024
+ this.headers = {
1025
+ 'Content-Type': 'application/json',
1026
+ Authorization: `Bearer ${refreshResponse.token}`,
1027
+ };
1028
+ setTokenHeader(refreshResponse.token);
1029
+ window.dispatchEvent(new CustomEvent('tokenUpdated', { detail: refreshResponse.token }));
1030
+ this.stream();
1031
+ } catch (err) {
1032
+ this._onStreamFailure(e);
1033
+ return;
1034
+ }
1035
+ } else if (this.xhr.status !== 200) {
962
1036
  this._onStreamFailure(e);
963
1037
  return;
964
1038
  }
package/dist/index.js CHANGED
@@ -75,6 +75,70 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
75
75
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
76
76
  };
77
77
 
78
+ function setAcceptLanguageHeader(value) {
79
+ axios.defaults.headers.common['Accept-Language'] = value;
80
+ }
81
+ function setTokenHeader(token) {
82
+ axios.defaults.headers.common['Authorization'] = 'Bearer ' + token;
83
+ }
84
+
85
+ var isRefreshing = false;
86
+ var failedQueue = [];
87
+ var processQueue = function (error, token) {
88
+ if (token === void 0) { token = null; }
89
+ failedQueue.forEach(function (prom) {
90
+ if (error) {
91
+ prom.reject(error);
92
+ }
93
+ else {
94
+ prom.resolve(token);
95
+ }
96
+ });
97
+ failedQueue = [];
98
+ };
99
+ axios.interceptors.response.use(function (response) { return response; }, function (error) {
100
+ var originalRequest = error.config;
101
+ if (error.response.status === 401 && !originalRequest._retry) {
102
+ if (isRefreshing) {
103
+ return new Promise(function (resolve, reject) {
104
+ failedQueue.push({ resolve: resolve, reject: reject });
105
+ })
106
+ .then(function (token) {
107
+ originalRequest.headers['Authorization'] = 'Bearer ' + token;
108
+ return axios(originalRequest);
109
+ })
110
+ .catch(function (err) {
111
+ return Promise.reject(err);
112
+ });
113
+ }
114
+ originalRequest._retry = true;
115
+ isRefreshing = true;
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
+ });
78
142
  function _get(url, options) {
79
143
  return __awaiter(this, void 0, void 0, function () {
80
144
  var response;
@@ -370,6 +434,7 @@ var tMessageSchema = zod.z.object({
370
434
  sender: zod.z.string(),
371
435
  text: zod.z.string(),
372
436
  generation: zod.z.string().nullable().optional(),
437
+ isEdited: zod.z.boolean().optional(),
373
438
  isCreatedByUser: zod.z.boolean(),
374
439
  error: zod.z.boolean(),
375
440
  createdAt: zod.z
@@ -517,14 +582,14 @@ var anthropicSchema = tConversationSchema
517
582
  })
518
583
  .transform(function (obj) {
519
584
  var _a, _b, _c, _d, _e, _f, _g;
520
- return (__assign(__assign({}, obj), { model: (_a = obj.model) !== null && _a !== void 0 ? _a : 'claude-1', modelLabel: (_b = obj.modelLabel) !== null && _b !== void 0 ? _b : null, promptPrefix: (_c = obj.promptPrefix) !== null && _c !== void 0 ? _c : null, temperature: (_d = obj.temperature) !== null && _d !== void 0 ? _d : 1, maxOutputTokens: (_e = obj.maxOutputTokens) !== null && _e !== void 0 ? _e : 1024, topP: (_f = obj.topP) !== null && _f !== void 0 ? _f : 0.7, topK: (_g = obj.topK) !== null && _g !== void 0 ? _g : 5 }));
585
+ return (__assign(__assign({}, obj), { model: (_a = obj.model) !== null && _a !== void 0 ? _a : 'claude-1', modelLabel: (_b = obj.modelLabel) !== null && _b !== void 0 ? _b : null, promptPrefix: (_c = obj.promptPrefix) !== null && _c !== void 0 ? _c : null, temperature: (_d = obj.temperature) !== null && _d !== void 0 ? _d : 1, maxOutputTokens: (_e = obj.maxOutputTokens) !== null && _e !== void 0 ? _e : 4000, topP: (_f = obj.topP) !== null && _f !== void 0 ? _f : 0.7, topK: (_g = obj.topK) !== null && _g !== void 0 ? _g : 5 }));
521
586
  })
522
587
  .catch(function () { return ({
523
588
  model: 'claude-1',
524
589
  modelLabel: null,
525
590
  promptPrefix: null,
526
591
  temperature: 1,
527
- maxOutputTokens: 1024,
592
+ maxOutputTokens: 4000,
528
593
  topP: 0.7,
529
594
  topK: 5,
530
595
  }); });
@@ -844,19 +909,13 @@ var useGetStartupConfig = function () {
844
909
  });
845
910
  };
846
911
 
847
- function setAcceptLanguageHeader(value) {
848
- axios.defaults.headers.common['Accept-Language'] = value;
849
- }
850
- function setTokenHeader(token) {
851
- axios.defaults.headers.common['Authorization'] = 'Bearer ' + token;
852
- }
853
-
854
912
  /* eslint-disable */
855
913
  /**
856
914
  * Copyright (C) 2016 Maxime Petazzoni <maxime.petazzoni@bulix.org>.
857
915
  * All rights reserved.
858
916
  */
859
917
 
918
+
860
919
  var SSE = function (url, options) {
861
920
  if (!(this instanceof SSE)) {
862
921
  return new SSE(url, options);
@@ -955,12 +1014,27 @@ var SSE = function (url, options) {
955
1014
  this.close();
956
1015
  };
957
1016
 
958
- this._onStreamProgress = function (e) {
1017
+ this._onStreamProgress = async function (e) {
959
1018
  if (!this.xhr) {
960
1019
  return;
961
1020
  }
962
1021
 
963
- if (this.xhr.status !== 200) {
1022
+ if (this.xhr.status === 401 && !this._retry) {
1023
+ this._retry = true;
1024
+ try {
1025
+ const refreshResponse = await refreshToken();
1026
+ this.headers = {
1027
+ 'Content-Type': 'application/json',
1028
+ Authorization: `Bearer ${refreshResponse.token}`,
1029
+ };
1030
+ setTokenHeader(refreshResponse.token);
1031
+ window.dispatchEvent(new CustomEvent('tokenUpdated', { detail: refreshResponse.token }));
1032
+ this.stream();
1033
+ } catch (err) {
1034
+ this._onStreamFailure(e);
1035
+ return;
1036
+ }
1037
+ } else if (this.xhr.status !== 200) {
964
1038
  this._onStreamFailure(e);
965
1039
  return;
966
1040
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "librechat-data-provider",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "data services for librechat apps",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.js",
@@ -11,7 +11,9 @@
11
11
  "build:watch": "rollup -c -w",
12
12
  "test": "jest --coverage --watch",
13
13
  "test:ci": "jest --coverage --ci",
14
- "verify": "npm run test:ci"
14
+ "verify": "npm run test:ci",
15
+ "b:clean": "bun run rimraf dist",
16
+ "b:build": "bun run b:clean && bun run rollup -c --silent --bundleConfigAsCjs"
15
17
  },
16
18
  "repository": {
17
19
  "type": "git",
package/src/request.ts CHANGED
@@ -1,4 +1,69 @@
1
- import axios, { AxiosRequestConfig } from 'axios';
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import axios, { AxiosRequestConfig, AxiosError } from 'axios';
3
+ // eslint-disable-next-line import/no-cycle
4
+ import { refreshToken } from './data-service';
5
+ import { setTokenHeader } from './headers-helpers';
6
+
7
+ let isRefreshing = false;
8
+ let failedQueue: { resolve: (value?: any) => void; reject: (reason?: any) => void }[] = [];
9
+
10
+ const processQueue = (error: AxiosError | null, token: string | null = null) => {
11
+ failedQueue.forEach((prom) => {
12
+ if (error) {
13
+ prom.reject(error);
14
+ } else {
15
+ prom.resolve(token);
16
+ }
17
+ });
18
+ failedQueue = [];
19
+ };
20
+
21
+ axios.interceptors.response.use(
22
+ (response) => response,
23
+ (error) => {
24
+ const originalRequest = error.config;
25
+ if (error.response.status === 401 && !originalRequest._retry) {
26
+ if (isRefreshing) {
27
+ return new Promise(function (resolve, reject) {
28
+ failedQueue.push({ resolve, reject });
29
+ })
30
+ .then((token) => {
31
+ originalRequest.headers['Authorization'] = 'Bearer ' + token;
32
+ return axios(originalRequest);
33
+ })
34
+ .catch((err) => {
35
+ return Promise.reject(err);
36
+ });
37
+ }
38
+
39
+ originalRequest._retry = true;
40
+ isRefreshing = true;
41
+
42
+ return new Promise(function (resolve, reject) {
43
+ refreshToken()
44
+ .then(({ token }) => {
45
+ if (token) {
46
+ originalRequest.headers['Authorization'] = 'Bearer ' + token;
47
+ setTokenHeader(token);
48
+ window.dispatchEvent(new CustomEvent('tokenUpdated', { detail: token }));
49
+ processQueue(null, token);
50
+ resolve(axios(originalRequest));
51
+ } else {
52
+ window.location.href = '/login';
53
+ }
54
+ })
55
+ .catch((err) => {
56
+ processQueue(err, null);
57
+ reject(err);
58
+ })
59
+ .then(() => {
60
+ isRefreshing = false;
61
+ });
62
+ });
63
+ }
64
+ return Promise.reject(error);
65
+ },
66
+ );
2
67
 
3
68
  async function _get<T>(url: string, options?: AxiosRequestConfig): Promise<T> {
4
69
  const response = await axios.get(url, { ...options });
package/src/schemas.ts CHANGED
@@ -77,6 +77,7 @@ export const tMessageSchema = z.object({
77
77
  sender: z.string(),
78
78
  text: z.string(),
79
79
  generation: z.string().nullable().optional(),
80
+ isEdited: z.boolean().optional(),
80
81
  isCreatedByUser: z.boolean(),
81
82
  error: z.boolean(),
82
83
  createdAt: z
@@ -266,7 +267,7 @@ export const anthropicSchema = tConversationSchema
266
267
  modelLabel: obj.modelLabel ?? null,
267
268
  promptPrefix: obj.promptPrefix ?? null,
268
269
  temperature: obj.temperature ?? 1,
269
- maxOutputTokens: obj.maxOutputTokens ?? 1024,
270
+ maxOutputTokens: obj.maxOutputTokens ?? 4000,
270
271
  topP: obj.topP ?? 0.7,
271
272
  topK: obj.topK ?? 5,
272
273
  }))
@@ -275,7 +276,7 @@ export const anthropicSchema = tConversationSchema
275
276
  modelLabel: null,
276
277
  promptPrefix: null,
277
278
  temperature: 1,
278
- maxOutputTokens: 1024,
279
+ maxOutputTokens: 4000,
279
280
  topP: 0.7,
280
281
  topK: 5,
281
282
  }));
package/src/sse.js CHANGED
@@ -4,6 +4,9 @@
4
4
  * All rights reserved.
5
5
  */
6
6
 
7
+ import { refreshToken } from './data-service';
8
+ import { setTokenHeader } from './headers-helpers';
9
+
7
10
  var SSE = function (url, options) {
8
11
  if (!(this instanceof SSE)) {
9
12
  return new SSE(url, options);
@@ -102,12 +105,27 @@ var SSE = function (url, options) {
102
105
  this.close();
103
106
  };
104
107
 
105
- this._onStreamProgress = function (e) {
108
+ this._onStreamProgress = async function (e) {
106
109
  if (!this.xhr) {
107
110
  return;
108
111
  }
109
112
 
110
- if (this.xhr.status !== 200) {
113
+ if (this.xhr.status === 401 && !this._retry) {
114
+ this._retry = true;
115
+ try {
116
+ const refreshResponse = await refreshToken();
117
+ this.headers = {
118
+ 'Content-Type': 'application/json',
119
+ Authorization: `Bearer ${refreshResponse.token}`,
120
+ };
121
+ setTokenHeader(refreshResponse.token);
122
+ window.dispatchEvent(new CustomEvent('tokenUpdated', { detail: refreshResponse.token }));
123
+ this.stream();
124
+ } catch (err) {
125
+ this._onStreamFailure(e);
126
+ return;
127
+ }
128
+ } else if (this.xhr.status !== 200) {
111
129
  this._onStreamFailure(e);
112
130
  return;
113
131
  }
@@ -24,6 +24,7 @@ export default function createPayload(submission: TSubmission): {
24
24
  bg?: string | null | undefined;
25
25
  title?: string | null | undefined;
26
26
  generation?: string | null | undefined;
27
+ isEdited?: boolean | undefined;
27
28
  createdAt?: string | undefined;
28
29
  updatedAt?: string | undefined;
29
30
  current?: boolean | undefined;
@@ -141,6 +141,7 @@ export declare const tMessageSchema: z.ZodObject<{
141
141
  sender: z.ZodString;
142
142
  text: z.ZodString;
143
143
  generation: z.ZodOptional<z.ZodNullable<z.ZodString>>;
144
+ isEdited: z.ZodOptional<z.ZodBoolean>;
144
145
  isCreatedByUser: z.ZodBoolean;
145
146
  error: z.ZodBoolean;
146
147
  createdAt: z.ZodDefault<z.ZodOptional<z.ZodString>>;
@@ -167,6 +168,7 @@ export declare const tMessageSchema: z.ZodObject<{
167
168
  model?: string | null | undefined;
168
169
  title?: string | null | undefined;
169
170
  generation?: string | null | undefined;
171
+ isEdited?: boolean | undefined;
170
172
  current?: boolean | undefined;
171
173
  unfinished?: boolean | undefined;
172
174
  submitting?: boolean | undefined;
@@ -187,6 +189,7 @@ export declare const tMessageSchema: z.ZodObject<{
187
189
  model?: string | null | undefined;
188
190
  title?: string | null | undefined;
189
191
  generation?: string | null | undefined;
192
+ isEdited?: boolean | undefined;
190
193
  createdAt?: string | undefined;
191
194
  updatedAt?: string | undefined;
192
195
  current?: boolean | undefined;