@adminforth/rich-editor 1.5.3 → 1.5.5

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/build.log CHANGED
@@ -10,5 +10,5 @@ custom/package.json
10
10
  custom/quillEditor.vue
11
11
  custom/tsconfig.json
12
12
 
13
- sent 21,704 bytes received 115 bytes 43,638.00 bytes/sec
14
- total size is 21,281 speedup is 0.98
13
+ sent 21,694 bytes received 115 bytes 43,618.00 bytes/sec
14
+ total size is 21,271 speedup is 0.98
@@ -1,19 +1,27 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "baseUrl": ".", // This should point to your project root
3
+ "baseUrl": ".",
4
4
  "paths": {
5
5
  "@/*": [
6
- // "node_modules/adminforth/dist/spa/src/*"
7
- "../../../spa/src/*"
6
+ "../../../adminforth/spa/src/*"
8
7
  ],
9
8
  "*": [
10
- // "node_modules/adminforth/dist/spa/node_modules/*"
11
- "../../../spa/node_modules/*"
9
+ "../../../adminforth/spa/node_modules/*"
12
10
  ],
13
11
  "@@/*": [
14
- // "node_modules/adminforth/dist/spa/src/*"
15
12
  "."
16
13
  ]
17
14
  }
18
- }
15
+ },
16
+ "include": [
17
+ "./**/*.ts",
18
+ "./**/*.tsx",
19
+ "./**/*.vue",
20
+ "../**/*.ts",
21
+ "../**/*.tsx",
22
+ "../**/*.vue",
23
+ "../*.vue",
24
+ "../*.ts",
25
+ "../*.tsx"
26
+ ]
19
27
  }
@@ -1,19 +1,27 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "baseUrl": ".", // This should point to your project root
3
+ "baseUrl": ".",
4
4
  "paths": {
5
5
  "@/*": [
6
- // "node_modules/adminforth/dist/spa/src/*"
7
- "../../../spa/src/*"
6
+ "../../../adminforth/spa/src/*"
8
7
  ],
9
8
  "*": [
10
- // "node_modules/adminforth/dist/spa/node_modules/*"
11
- "../../../spa/node_modules/*"
9
+ "../../../adminforth/spa/node_modules/*"
12
10
  ],
13
11
  "@@/*": [
14
- // "node_modules/adminforth/dist/spa/src/*"
15
12
  "."
16
13
  ]
17
14
  }
18
- }
15
+ },
16
+ "include": [
17
+ "./**/*.ts",
18
+ "./**/*.tsx",
19
+ "./**/*.vue",
20
+ "../**/*.ts",
21
+ "../**/*.tsx",
22
+ "../**/*.vue",
23
+ "../*.vue",
24
+ "../*.ts",
25
+ "../*.tsx"
26
+ ]
19
27
  }
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, _r, _s;
222
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
219
223
  const { record } = body;
220
- if ((_b = this.options.completion.rateLimit) === null || _b === void 0 ? void 0 : _b.limit) {
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
- const rateLimiter = new RateLimiter((_c = this.options.completion.rateLimit) === null || _c === void 0 ? void 0 : _c.limit);
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 = ((_d = this.options.completion.expert) === null || _d === void 0 ? void 0 : _d.promptInputLimit) || 500;
238
- const inputContext = this.generateRecordContext(recordNoField, ((_f = (_e = this.options.completion.expert) === null || _e === void 0 ? void 0 : _e.recordContext) === null || _f === void 0 ? void 0 : _f.maxFields) || 5, ((_h = (_g = this.options.completion.expert) === null || _g === void 0 ? void 0 : _g.recordContext) === null || _h === void 0 ? void 0 : _h.maxFieldLength) || 300, ((_k = (_j = this.options.completion.expert) === null || _j === void 0 ? void 0 : _j.recordContext) === null || _k === void 0 ? void 0 : _k.splitParts) || 5);
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 = ((_m = (_l = this.resourceConfig) === null || _l === void 0 ? void 0 : _l.columns.find(c => c.name === this.options.htmlFieldName)) === null || _m === void 0 ? void 0 : _m.label) || this.options.htmlFieldName;
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, (_p = (_o = this.options.completion) === null || _o === void 0 ? void 0 : _o.expert) === null || _p === void 0 ? void 0 : _p.stop, (_r = (_q = this.options.completion) === null || _q === void 0 ? void 0 : _q.expert) === null || _r === void 0 ? void 0 : _r.maxTokens);
258
- const stop = ((_s = this.options.completion.expert) === null || _s === void 0 ? void 0 : _s.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.options.completion.rateLimit?.limit) {
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
- const rateLimiter = new RateLimiter(this.options.completion.rateLimit?.limit);
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",
3
+ "version": "1.5.5",
4
4
  "description": "Rich editor plugin for adminforth",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",