@adminforth/text-complete 1.0.21

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.
@@ -0,0 +1,368 @@
1
+ {
2
+ "name": "custom",
3
+ "version": "1.0.0",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "custom",
9
+ "version": "1.0.0",
10
+ "license": "ISC",
11
+ "devDependencies": {
12
+ "vue-suggestion-input": "^0.0.18"
13
+ }
14
+ },
15
+ "node_modules/@babel/helper-string-parser": {
16
+ "version": "7.24.8",
17
+ "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.24.8.tgz",
18
+ "integrity": "sha512-pO9KhhRcuUyGnJWwyEgnRJTSIZHiT+vMD0kPeD+so0l7mxkMT19g3pjY9GTnHySck/hDzq+dtW/4VgnMkippsQ==",
19
+ "dev": true,
20
+ "engines": {
21
+ "node": ">=6.9.0"
22
+ }
23
+ },
24
+ "node_modules/@babel/helper-validator-identifier": {
25
+ "version": "7.24.7",
26
+ "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.7.tgz",
27
+ "integrity": "sha512-rR+PBcQ1SMQDDyF6X0wxtG8QyLCgUB0eRAGguqRLfkCA87l7yAP7ehq8SNj96OOGTO8OBV70KhuFYcIkHXOg0w==",
28
+ "dev": true,
29
+ "engines": {
30
+ "node": ">=6.9.0"
31
+ }
32
+ },
33
+ "node_modules/@babel/parser": {
34
+ "version": "7.25.3",
35
+ "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.25.3.tgz",
36
+ "integrity": "sha512-iLTJKDbJ4hMvFPgQwwsVoxtHyWpKKPBrxkANrSYewDPaPpT5py5yeVkgPIJ7XYXhndxJpaA3PyALSXQ7u8e/Dw==",
37
+ "dev": true,
38
+ "dependencies": {
39
+ "@babel/types": "^7.25.2"
40
+ },
41
+ "bin": {
42
+ "parser": "bin/babel-parser.js"
43
+ },
44
+ "engines": {
45
+ "node": ">=6.0.0"
46
+ }
47
+ },
48
+ "node_modules/@babel/types": {
49
+ "version": "7.25.2",
50
+ "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.25.2.tgz",
51
+ "integrity": "sha512-YTnYtra7W9e6/oAZEHj0bJehPRUlLH9/fbpT5LfB0NhQXyALCRkRs3zH9v07IYhkgpqX6Z78FnuccZr/l4Fs4Q==",
52
+ "dev": true,
53
+ "dependencies": {
54
+ "@babel/helper-string-parser": "^7.24.8",
55
+ "@babel/helper-validator-identifier": "^7.24.7",
56
+ "to-fast-properties": "^2.0.0"
57
+ },
58
+ "engines": {
59
+ "node": ">=6.9.0"
60
+ }
61
+ },
62
+ "node_modules/@jridgewell/sourcemap-codec": {
63
+ "version": "1.5.0",
64
+ "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz",
65
+ "integrity": "sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==",
66
+ "dev": true
67
+ },
68
+ "node_modules/@vue/compiler-core": {
69
+ "version": "3.4.35",
70
+ "resolved": "https://registry.npmjs.org/@vue/compiler-core/-/compiler-core-3.4.35.tgz",
71
+ "integrity": "sha512-gKp0zGoLnMYtw4uS/SJRRO7rsVggLjvot3mcctlMXunYNsX+aRJDqqw/lV5/gHK91nvaAAlWFgdVl020AW1Prg==",
72
+ "dev": true,
73
+ "dependencies": {
74
+ "@babel/parser": "^7.24.7",
75
+ "@vue/shared": "3.4.35",
76
+ "entities": "^4.5.0",
77
+ "estree-walker": "^2.0.2",
78
+ "source-map-js": "^1.2.0"
79
+ }
80
+ },
81
+ "node_modules/@vue/compiler-dom": {
82
+ "version": "3.4.35",
83
+ "resolved": "https://registry.npmjs.org/@vue/compiler-dom/-/compiler-dom-3.4.35.tgz",
84
+ "integrity": "sha512-pWIZRL76/oE/VMhdv/ovZfmuooEni6JPG1BFe7oLk5DZRo/ImydXijoZl/4kh2406boRQ7lxTYzbZEEXEhj9NQ==",
85
+ "dev": true,
86
+ "dependencies": {
87
+ "@vue/compiler-core": "3.4.35",
88
+ "@vue/shared": "3.4.35"
89
+ }
90
+ },
91
+ "node_modules/@vue/compiler-sfc": {
92
+ "version": "3.4.35",
93
+ "resolved": "https://registry.npmjs.org/@vue/compiler-sfc/-/compiler-sfc-3.4.35.tgz",
94
+ "integrity": "sha512-xacnRS/h/FCsjsMfxBkzjoNxyxEyKyZfBch/P4vkLRvYJwe5ChXmZZrj8Dsed/752H2Q3JE8kYu9Uyha9J6PgA==",
95
+ "dev": true,
96
+ "dependencies": {
97
+ "@babel/parser": "^7.24.7",
98
+ "@vue/compiler-core": "3.4.35",
99
+ "@vue/compiler-dom": "3.4.35",
100
+ "@vue/compiler-ssr": "3.4.35",
101
+ "@vue/shared": "3.4.35",
102
+ "estree-walker": "^2.0.2",
103
+ "magic-string": "^0.30.10",
104
+ "postcss": "^8.4.40",
105
+ "source-map-js": "^1.2.0"
106
+ }
107
+ },
108
+ "node_modules/@vue/compiler-ssr": {
109
+ "version": "3.4.35",
110
+ "resolved": "https://registry.npmjs.org/@vue/compiler-ssr/-/compiler-ssr-3.4.35.tgz",
111
+ "integrity": "sha512-7iynB+0KB1AAJKk/biENTV5cRGHRdbdaD7Mx3nWcm1W8bVD6QmnH3B4AHhQQ1qZHhqFwzEzMwiytXm3PX1e60A==",
112
+ "dev": true,
113
+ "dependencies": {
114
+ "@vue/compiler-dom": "3.4.35",
115
+ "@vue/shared": "3.4.35"
116
+ }
117
+ },
118
+ "node_modules/@vue/reactivity": {
119
+ "version": "3.4.35",
120
+ "resolved": "https://registry.npmjs.org/@vue/reactivity/-/reactivity-3.4.35.tgz",
121
+ "integrity": "sha512-Ggtz7ZZHakriKioveJtPlStYardwQH6VCs9V13/4qjHSQb/teE30LVJNrbBVs4+aoYGtTQKJbTe4CWGxVZrvEw==",
122
+ "dev": true,
123
+ "dependencies": {
124
+ "@vue/shared": "3.4.35"
125
+ }
126
+ },
127
+ "node_modules/@vue/runtime-core": {
128
+ "version": "3.4.35",
129
+ "resolved": "https://registry.npmjs.org/@vue/runtime-core/-/runtime-core-3.4.35.tgz",
130
+ "integrity": "sha512-D+BAjFoWwT5wtITpSxwqfWZiBClhBbR+bm0VQlWYFOadUUXFo+5wbe9ErXhLvwguPiLZdEF13QAWi2vP3ZD5tA==",
131
+ "dev": true,
132
+ "dependencies": {
133
+ "@vue/reactivity": "3.4.35",
134
+ "@vue/shared": "3.4.35"
135
+ }
136
+ },
137
+ "node_modules/@vue/runtime-dom": {
138
+ "version": "3.4.35",
139
+ "resolved": "https://registry.npmjs.org/@vue/runtime-dom/-/runtime-dom-3.4.35.tgz",
140
+ "integrity": "sha512-yGOlbos+MVhlS5NWBF2HDNgblG8e2MY3+GigHEyR/dREAluvI5tuUUgie3/9XeqhPE4LF0i2wjlduh5thnfOqw==",
141
+ "dev": true,
142
+ "dependencies": {
143
+ "@vue/reactivity": "3.4.35",
144
+ "@vue/runtime-core": "3.4.35",
145
+ "@vue/shared": "3.4.35",
146
+ "csstype": "^3.1.3"
147
+ }
148
+ },
149
+ "node_modules/@vue/server-renderer": {
150
+ "version": "3.4.35",
151
+ "resolved": "https://registry.npmjs.org/@vue/server-renderer/-/server-renderer-3.4.35.tgz",
152
+ "integrity": "sha512-iZ0e/u9mRE4T8tNhlo0tbA+gzVkgv8r5BX6s1kRbOZqfpq14qoIvCZ5gIgraOmYkMYrSEZgkkojFPr+Nyq/Mnw==",
153
+ "dev": true,
154
+ "dependencies": {
155
+ "@vue/compiler-ssr": "3.4.35",
156
+ "@vue/shared": "3.4.35"
157
+ },
158
+ "peerDependencies": {
159
+ "vue": "3.4.35"
160
+ }
161
+ },
162
+ "node_modules/@vue/shared": {
163
+ "version": "3.4.35",
164
+ "resolved": "https://registry.npmjs.org/@vue/shared/-/shared-3.4.35.tgz",
165
+ "integrity": "sha512-hvuhBYYDe+b1G8KHxsQ0diDqDMA8D9laxWZhNAjE83VZb5UDaXl9Xnz7cGdDSyiHM90qqI/CyGMcpBpiDy6VVQ==",
166
+ "dev": true
167
+ },
168
+ "node_modules/csstype": {
169
+ "version": "3.1.3",
170
+ "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz",
171
+ "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==",
172
+ "dev": true
173
+ },
174
+ "node_modules/entities": {
175
+ "version": "4.5.0",
176
+ "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz",
177
+ "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==",
178
+ "dev": true,
179
+ "engines": {
180
+ "node": ">=0.12"
181
+ },
182
+ "funding": {
183
+ "url": "https://github.com/fb55/entities?sponsor=1"
184
+ }
185
+ },
186
+ "node_modules/estree-walker": {
187
+ "version": "2.0.2",
188
+ "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz",
189
+ "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==",
190
+ "dev": true
191
+ },
192
+ "node_modules/eventemitter3": {
193
+ "version": "5.0.1",
194
+ "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz",
195
+ "integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==",
196
+ "dev": true
197
+ },
198
+ "node_modules/fast-diff": {
199
+ "version": "1.3.0",
200
+ "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.3.0.tgz",
201
+ "integrity": "sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==",
202
+ "dev": true
203
+ },
204
+ "node_modules/lodash-es": {
205
+ "version": "4.17.21",
206
+ "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.21.tgz",
207
+ "integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==",
208
+ "dev": true
209
+ },
210
+ "node_modules/lodash.clonedeep": {
211
+ "version": "4.5.0",
212
+ "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
213
+ "integrity": "sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==",
214
+ "dev": true
215
+ },
216
+ "node_modules/lodash.isequal": {
217
+ "version": "4.5.0",
218
+ "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz",
219
+ "integrity": "sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==",
220
+ "dev": true
221
+ },
222
+ "node_modules/magic-string": {
223
+ "version": "0.30.11",
224
+ "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.11.tgz",
225
+ "integrity": "sha512-+Wri9p0QHMy+545hKww7YAu5NyzF8iomPL/RQazugQ9+Ez4Ic3mERMd8ZTX5rfK944j+560ZJi8iAwgak1Ac7A==",
226
+ "dev": true,
227
+ "dependencies": {
228
+ "@jridgewell/sourcemap-codec": "^1.5.0"
229
+ }
230
+ },
231
+ "node_modules/nanoid": {
232
+ "version": "3.3.7",
233
+ "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz",
234
+ "integrity": "sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==",
235
+ "dev": true,
236
+ "funding": [
237
+ {
238
+ "type": "github",
239
+ "url": "https://github.com/sponsors/ai"
240
+ }
241
+ ],
242
+ "bin": {
243
+ "nanoid": "bin/nanoid.cjs"
244
+ },
245
+ "engines": {
246
+ "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
247
+ }
248
+ },
249
+ "node_modules/parchment": {
250
+ "version": "3.0.0",
251
+ "resolved": "https://registry.npmjs.org/parchment/-/parchment-3.0.0.tgz",
252
+ "integrity": "sha512-HUrJFQ/StvgmXRcQ1ftY6VEZUq3jA2t9ncFN4F84J/vN0/FPpQF+8FKXb3l6fLces6q0uOHj6NJn+2xvZnxO6A==",
253
+ "dev": true
254
+ },
255
+ "node_modules/picocolors": {
256
+ "version": "1.0.1",
257
+ "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.1.tgz",
258
+ "integrity": "sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==",
259
+ "dev": true
260
+ },
261
+ "node_modules/postcss": {
262
+ "version": "8.4.40",
263
+ "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.40.tgz",
264
+ "integrity": "sha512-YF2kKIUzAofPMpfH6hOi2cGnv/HrUlfucspc7pDyvv7kGdqXrfj8SCl/t8owkEgKEuu8ZcRjSOxFxVLqwChZ2Q==",
265
+ "dev": true,
266
+ "funding": [
267
+ {
268
+ "type": "opencollective",
269
+ "url": "https://opencollective.com/postcss/"
270
+ },
271
+ {
272
+ "type": "tidelift",
273
+ "url": "https://tidelift.com/funding/github/npm/postcss"
274
+ },
275
+ {
276
+ "type": "github",
277
+ "url": "https://github.com/sponsors/ai"
278
+ }
279
+ ],
280
+ "dependencies": {
281
+ "nanoid": "^3.3.7",
282
+ "picocolors": "^1.0.1",
283
+ "source-map-js": "^1.2.0"
284
+ },
285
+ "engines": {
286
+ "node": "^10 || ^12 || >=14"
287
+ }
288
+ },
289
+ "node_modules/quill": {
290
+ "version": "2.0.2",
291
+ "resolved": "https://registry.npmjs.org/quill/-/quill-2.0.2.tgz",
292
+ "integrity": "sha512-QfazNrhMakEdRG57IoYFwffUIr04LWJxbS/ZkidRFXYCQt63c1gK6Z7IHUXMx/Vh25WgPBU42oBaNzQ0K1R/xw==",
293
+ "dev": true,
294
+ "dependencies": {
295
+ "eventemitter3": "^5.0.1",
296
+ "lodash-es": "^4.17.21",
297
+ "parchment": "^3.0.0",
298
+ "quill-delta": "^5.1.0"
299
+ },
300
+ "engines": {
301
+ "npm": ">=8.2.3"
302
+ }
303
+ },
304
+ "node_modules/quill-delta": {
305
+ "version": "5.1.0",
306
+ "resolved": "https://registry.npmjs.org/quill-delta/-/quill-delta-5.1.0.tgz",
307
+ "integrity": "sha512-X74oCeRI4/p0ucjb5Ma8adTXd9Scumz367kkMK5V/IatcX6A0vlgLgKbzXWy5nZmCGeNJm2oQX0d2Eqj+ZIlCA==",
308
+ "dev": true,
309
+ "dependencies": {
310
+ "fast-diff": "^1.3.0",
311
+ "lodash.clonedeep": "^4.5.0",
312
+ "lodash.isequal": "^4.5.0"
313
+ },
314
+ "engines": {
315
+ "node": ">= 12.0.0"
316
+ }
317
+ },
318
+ "node_modules/source-map-js": {
319
+ "version": "1.2.0",
320
+ "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.0.tgz",
321
+ "integrity": "sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==",
322
+ "dev": true,
323
+ "engines": {
324
+ "node": ">=0.10.0"
325
+ }
326
+ },
327
+ "node_modules/to-fast-properties": {
328
+ "version": "2.0.0",
329
+ "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
330
+ "integrity": "sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==",
331
+ "dev": true,
332
+ "engines": {
333
+ "node": ">=4"
334
+ }
335
+ },
336
+ "node_modules/vue": {
337
+ "version": "3.4.35",
338
+ "resolved": "https://registry.npmjs.org/vue/-/vue-3.4.35.tgz",
339
+ "integrity": "sha512-+fl/GLmI4GPileHftVlCdB7fUL4aziPcqTudpTGXCT8s+iZWuOCeNEB5haX6Uz2IpRrbEXOgIFbe+XciCuGbNQ==",
340
+ "dev": true,
341
+ "dependencies": {
342
+ "@vue/compiler-dom": "3.4.35",
343
+ "@vue/compiler-sfc": "3.4.35",
344
+ "@vue/runtime-dom": "3.4.35",
345
+ "@vue/server-renderer": "3.4.35",
346
+ "@vue/shared": "3.4.35"
347
+ },
348
+ "peerDependencies": {
349
+ "typescript": "*"
350
+ },
351
+ "peerDependenciesMeta": {
352
+ "typescript": {
353
+ "optional": true
354
+ }
355
+ }
356
+ },
357
+ "node_modules/vue-suggestion-input": {
358
+ "version": "0.0.18",
359
+ "resolved": "https://registry.npmjs.org/vue-suggestion-input/-/vue-suggestion-input-0.0.18.tgz",
360
+ "integrity": "sha512-jYyImQFcOvY9l2WJvSJ9mDCnQLSNzrGtCsbACL77p3jePWfbvPNCRwFEzEELCoBVYqYFmRtON+24Qhrb2Da7kw==",
361
+ "dev": true,
362
+ "dependencies": {
363
+ "quill": "^2.0.2",
364
+ "vue": "^3.4.31"
365
+ }
366
+ }
367
+ }
368
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "custom",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "devDependencies": {
13
+ "vue-suggestion-input": "^0.0.18"
14
+ }
15
+ }
package/dist/index.js ADDED
@@ -0,0 +1,141 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { AdminForthPlugin, AdminForthDataTypes, RateLimiter } from "adminforth";
11
+ export default class TextCompletePlugin extends AdminForthPlugin {
12
+ constructor(options) {
13
+ super(options, import.meta.url);
14
+ this.options = options;
15
+ }
16
+ instanceUniqueRepresentation(pluginOptions) {
17
+ return `${pluginOptions.fieldName}`;
18
+ }
19
+ validateConfigAfterDiscover(adminforth, resourceConfig) {
20
+ this.adminforth = adminforth;
21
+ const column = this.resourceConfig.columns.find(f => f.name === this.options.fieldName);
22
+ if (![AdminForthDataTypes.STRING, AdminForthDataTypes.TEXT].includes(column.type)) {
23
+ throw new Error(`Field ${this.options.fieldName} should be string or text type, but it is ${column.type}`);
24
+ }
25
+ if (!this.options.adapter) {
26
+ throw new Error('adapter is required');
27
+ }
28
+ }
29
+ generateRecordContext(record, maxFields, inputFieldLimit, partsCount) {
30
+ // stringify each field
31
+ let fields = Object.entries(record).map(([key, value]) => {
32
+ return [key, JSON.stringify(value)];
33
+ });
34
+ // sort fields by length, higher first
35
+ fields = fields.sort((a, b) => b[1].length - a[1].length);
36
+ // select longest maxFields fields
37
+ fields = fields.slice(0, maxFields);
38
+ const minLimit = '...'.length * partsCount;
39
+ if (inputFieldLimit < minLimit) {
40
+ throw new Error(`inputFieldLimit should be at least ${minLimit}`);
41
+ }
42
+ // for each field, if it is longer than inputFieldLimit, truncate it using next way:
43
+ // split into 5 parts, divide inputFieldLimit by 5, crop each part to this length, join parts using '...'
44
+ fields = fields.map(([key, value]) => {
45
+ if (value.length > inputFieldLimit) {
46
+ const partLength = Math.floor(inputFieldLimit / partsCount) - '...'.length;
47
+ const parts = [];
48
+ for (let i = 0; i < partsCount; i++) {
49
+ parts.push(value.slice(i * partLength, (i + 1) * partLength));
50
+ }
51
+ value = parts.join('...');
52
+ return [key, value];
53
+ }
54
+ return [key, value];
55
+ });
56
+ return JSON.stringify(Object.fromEntries(fields));
57
+ }
58
+ setupEndpoints(server) {
59
+ server.endpoint({
60
+ method: 'POST',
61
+ path: `/plugin/${this.pluginInstanceId}/doComplete`,
62
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, headers }) {
63
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
64
+ if ((_b = this.options.rateLimit) === null || _b === void 0 ? void 0 : _b.limit) {
65
+ // rate limit
66
+ const { error } = RateLimiter.checkRateLimit(this.pluginInstanceId, (_c = this.options.rateLimit) === null || _c === void 0 ? void 0 : _c.limit, this.adminforth.auth.getClientIp(headers));
67
+ if (error) {
68
+ return {
69
+ completion: [],
70
+ };
71
+ }
72
+ }
73
+ const { record } = body;
74
+ const recordNoField = Object.assign({}, record);
75
+ delete recordNoField[this.options.fieldName];
76
+ let currentVal = record[this.options.fieldName];
77
+ const promptLimit = ((_d = this.options.expert) === null || _d === void 0 ? void 0 : _d.promptInputLimit) || 500;
78
+ const inputContext = this.generateRecordContext(recordNoField, ((_f = (_e = this.options.expert) === null || _e === void 0 ? void 0 : _e.recordContext) === null || _f === void 0 ? void 0 : _f.maxFields) || 5, ((_h = (_g = this.options.expert) === null || _g === void 0 ? void 0 : _g.recordContext) === null || _h === void 0 ? void 0 : _h.maxFieldLength) || 300, ((_k = (_j = this.options.expert) === null || _j === void 0 ? void 0 : _j.recordContext) === null || _k === void 0 ? void 0 : _k.splitParts) || 5);
79
+ if (currentVal && currentVal.length > promptLimit) {
80
+ currentVal = currentVal.slice(-promptLimit);
81
+ }
82
+ const resLabel = this.resourceConfig.label;
83
+ let content;
84
+ if (currentVal) {
85
+ content = `Continue writing for text/string field "${this.options.fieldName}" in the table "${resLabel}"\n` +
86
+ (Object.keys(recordNoField).length > 0 ? `Record has values for the context: ${inputContext}\n` : '') +
87
+ `Current field value: ${currentVal}\n` +
88
+ "Don't talk to me. Just write text. No quotes. Don't repeat current field value, just write completion\n";
89
+ }
90
+ else {
91
+ content = `Fill text/string field "${this.options.fieldName}" in the table "${resLabel}"\n` +
92
+ (Object.keys(recordNoField).length > 0 ? `Record has values for the context: ${inputContext}\n` : '') +
93
+ "Be short, clear and precise. No quotes. Don't talk to me. Just write text\n";
94
+ }
95
+ process.env.HEAVY_DEBUG && console.log('🪲 OpenAI Prompt 🧠', content);
96
+ const { content: respContent, finishReason } = yield this.options.adapter.complete(content, (_l = this.options.expert) === null || _l === void 0 ? void 0 : _l.stop, (_m = this.options.expert) === null || _m === void 0 ? void 0 : _m.maxTokens);
97
+ const stop = ((_o = this.options.expert) === null || _o === void 0 ? void 0 : _o.stop) || ['.'];
98
+ let suggestion = respContent + (finishReason === 'stop' ? (stop[0] === '.' && stop.length === 1 && this.columnType === AdminForthDataTypes.TEXT ? '. ' : '') : '');
99
+ if (suggestion.startsWith(currentVal)) {
100
+ suggestion = suggestion.slice(currentVal.length);
101
+ }
102
+ const wordsList = suggestion.split(' ').map((w, i) => {
103
+ return (i === suggestion.split(' ').length - 1) ? w : w + ' ';
104
+ });
105
+ // remove quotes from start and end
106
+ return {
107
+ completion: wordsList
108
+ };
109
+ })
110
+ });
111
+ }
112
+ modifyResourceConfig(adminforth, resourceConfig) {
113
+ const _super = Object.create(null, {
114
+ modifyResourceConfig: { get: () => super.modifyResourceConfig }
115
+ });
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ var _a;
118
+ _super.modifyResourceConfig.call(this, adminforth, resourceConfig);
119
+ this.resourceConfig = resourceConfig;
120
+ // ensure that column exists
121
+ const column = this.resourceConfig.columns.find(f => f.name === this.options.fieldName);
122
+ if (!column) {
123
+ throw new Error(`Field ${this.options.fieldName} not found in resource ${this.resourceConfig.label}`);
124
+ }
125
+ if (!column.components) {
126
+ column.components = {};
127
+ }
128
+ const filed = {
129
+ file: this.componentPath('completionInput.vue'),
130
+ meta: {
131
+ pluginInstanceId: this.pluginInstanceId,
132
+ fieldName: this.options.fieldName,
133
+ debounceTime: ((_a = this.options.expert) === null || _a === void 0 ? void 0 : _a.debounceTime) || 300,
134
+ }
135
+ };
136
+ column.components.create = filed;
137
+ column.components.edit = filed;
138
+ this.columnType = column.type;
139
+ });
140
+ }
141
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};