@adminforth/rich-editor 1.5.2 → 1.5.4
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.js +12 -9
- package/index.ts +7 -3
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -18,11 +18,15 @@ import * as cheerio from 'cheerio';
|
|
|
18
18
|
// },
|
|
19
19
|
export default class RichEditorPlugin extends AdminForthPlugin {
|
|
20
20
|
constructor(options) {
|
|
21
|
+
var _a, _b;
|
|
21
22
|
super(options, import.meta.url);
|
|
22
23
|
this.resourceConfig = undefined;
|
|
23
24
|
this.activationOrder = 100000;
|
|
24
25
|
this.attachmentResource = undefined;
|
|
25
26
|
this.options = options;
|
|
27
|
+
if ((_a = this.options.completion.rateLimit) === null || _a === void 0 ? void 0 : _a.limit) {
|
|
28
|
+
this.rateLimiter = new RateLimiter((_b = this.options.completion.rateLimit) === null || _b === void 0 ? void 0 : _b.limit);
|
|
29
|
+
}
|
|
26
30
|
}
|
|
27
31
|
modifyResourceConfig(adminforth, resourceConfig) {
|
|
28
32
|
const _super = Object.create(null, {
|
|
@@ -215,17 +219,16 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
215
219
|
method: 'POST',
|
|
216
220
|
path: `/plugin/${this.pluginInstanceId}/doComplete`,
|
|
217
221
|
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, headers }) {
|
|
218
|
-
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q
|
|
222
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
219
223
|
const { record } = body;
|
|
220
|
-
if (
|
|
224
|
+
if (this.rateLimiter) {
|
|
221
225
|
// rate limit
|
|
222
226
|
// const { error } = RateLimiter.checkRateLimit(
|
|
223
227
|
// this.pluginInstanceId,
|
|
224
228
|
// this.options.completion.rateLimit?.limit,
|
|
225
229
|
// this.adminforth.auth.getClientIp(headers),
|
|
226
230
|
// );
|
|
227
|
-
|
|
228
|
-
if (!rateLimiter.consume(`${this.pluginInstanceId}-${this.adminforth.auth.getClientIp(headers)}`)) {
|
|
231
|
+
if (!(yield this.rateLimiter.consume(`${this.pluginInstanceId}-${this.adminforth.auth.getClientIp(headers)}`))) {
|
|
229
232
|
return {
|
|
230
233
|
completion: [],
|
|
231
234
|
};
|
|
@@ -234,12 +237,12 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
234
237
|
const recordNoField = Object.assign({}, record);
|
|
235
238
|
delete recordNoField[this.options.htmlFieldName];
|
|
236
239
|
let currentVal = record[this.options.htmlFieldName];
|
|
237
|
-
const promptLimit = ((
|
|
238
|
-
const inputContext = this.generateRecordContext(recordNoField, ((
|
|
240
|
+
const promptLimit = ((_b = this.options.completion.expert) === null || _b === void 0 ? void 0 : _b.promptInputLimit) || 500;
|
|
241
|
+
const inputContext = this.generateRecordContext(recordNoField, ((_d = (_c = this.options.completion.expert) === null || _c === void 0 ? void 0 : _c.recordContext) === null || _d === void 0 ? void 0 : _d.maxFields) || 5, ((_f = (_e = this.options.completion.expert) === null || _e === void 0 ? void 0 : _e.recordContext) === null || _f === void 0 ? void 0 : _f.maxFieldLength) || 300, ((_h = (_g = this.options.completion.expert) === null || _g === void 0 ? void 0 : _g.recordContext) === null || _h === void 0 ? void 0 : _h.splitParts) || 5);
|
|
239
242
|
if (currentVal && currentVal.length > promptLimit) {
|
|
240
243
|
currentVal = currentVal.slice(-promptLimit);
|
|
241
244
|
}
|
|
242
|
-
const fieldLabel = ((
|
|
245
|
+
const fieldLabel = ((_k = (_j = this.resourceConfig) === null || _j === void 0 ? void 0 : _j.columns.find(c => c.name === this.options.htmlFieldName)) === null || _k === void 0 ? void 0 : _k.label) || this.options.htmlFieldName;
|
|
243
246
|
const resLabel = this.resourceConfig.label;
|
|
244
247
|
let content;
|
|
245
248
|
if (currentVal) {
|
|
@@ -254,8 +257,8 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
254
257
|
"Be short, clear and precise. No quotes. Don't talk to me. Just write text\n";
|
|
255
258
|
}
|
|
256
259
|
process.env.HEAVY_DEBUG && console.log('🪲 OpenAI Prompt 🧠', content);
|
|
257
|
-
const { content: respContent, finishReason } = yield this.options.completion.adapter.complete(content, (
|
|
258
|
-
const stop = ((
|
|
260
|
+
const { content: respContent, finishReason } = yield this.options.completion.adapter.complete(content, (_m = (_l = this.options.completion) === null || _l === void 0 ? void 0 : _l.expert) === null || _m === void 0 ? void 0 : _m.stop, (_p = (_o = this.options.completion) === null || _o === void 0 ? void 0 : _o.expert) === null || _p === void 0 ? void 0 : _p.maxTokens);
|
|
261
|
+
const stop = ((_q = this.options.completion.expert) === null || _q === void 0 ? void 0 : _q.stop) || ['.'];
|
|
259
262
|
let suggestion = respContent + (finishReason === 'stop' ? (stop[0] === '.' && stop.length === 1 ? '. ' : '') : '');
|
|
260
263
|
if (suggestion.startsWith(currentVal)) {
|
|
261
264
|
suggestion = suggestion.slice(currentVal.length);
|
package/index.ts
CHANGED
|
@@ -24,10 +24,15 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
24
24
|
attachmentResource: AdminForthResource = undefined;
|
|
25
25
|
|
|
26
26
|
adminforth: IAdminForth;
|
|
27
|
+
|
|
28
|
+
rateLimiter: RateLimiter;
|
|
27
29
|
|
|
28
30
|
constructor(options: PluginOptions) {
|
|
29
31
|
super(options, import.meta.url);
|
|
30
32
|
this.options = options;
|
|
33
|
+
if (this.options.completion.rateLimit?.limit) {
|
|
34
|
+
this.rateLimiter = new RateLimiter(this.options.completion.rateLimit?.limit);
|
|
35
|
+
}
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
async modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
|
|
@@ -271,15 +276,14 @@ export default class RichEditorPlugin extends AdminForthPlugin {
|
|
|
271
276
|
handler: async ({ body, headers }) => {
|
|
272
277
|
const { record } = body;
|
|
273
278
|
|
|
274
|
-
if (this.
|
|
279
|
+
if (this.rateLimiter) {
|
|
275
280
|
// rate limit
|
|
276
281
|
// const { error } = RateLimiter.checkRateLimit(
|
|
277
282
|
// this.pluginInstanceId,
|
|
278
283
|
// this.options.completion.rateLimit?.limit,
|
|
279
284
|
// this.adminforth.auth.getClientIp(headers),
|
|
280
285
|
// );
|
|
281
|
-
|
|
282
|
-
if (!rateLimiter.consume(`${this.pluginInstanceId}-${this.adminforth.auth.getClientIp(headers)}`)) {
|
|
286
|
+
if (!await this.rateLimiter.consume(`${this.pluginInstanceId}-${this.adminforth.auth.getClientIp(headers)}`)) {
|
|
283
287
|
return {
|
|
284
288
|
completion: [],
|
|
285
289
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/rich-editor",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.4",
|
|
4
4
|
"description": "Rich editor plugin for adminforth",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"author": "devforth",
|
|
25
25
|
"license": "ISC",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"adminforth": "^2.4.0-next.
|
|
27
|
+
"adminforth": "^2.4.0-next.238",
|
|
28
28
|
"cheerio": "^1.0.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|