@adminforth/bulk-ai-flow 1.4.2 → 1.5.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/build.log +2 -2
- package/custom/package-lock.json +3505 -57
- package/custom/package.json +1 -1
- package/custom/visionAction.vue +1 -2
- package/dist/custom/package-lock.json +3505 -57
- package/dist/custom/package.json +1 -1
- package/dist/custom/visionAction.vue +1 -2
- package/dist/index.js +17 -35
- package/index.ts +17 -37
- package/package.json +3 -4
- package/types.ts +6 -4
package/dist/custom/package.json
CHANGED
|
@@ -66,14 +66,13 @@
|
|
|
66
66
|
|
|
67
67
|
<script lang="ts" setup>
|
|
68
68
|
import { callAdminForthApi } from '@/utils';
|
|
69
|
-
import {
|
|
69
|
+
import { ref, watch } from 'vue'
|
|
70
70
|
import { Dialog, Button } from '@/afcl';
|
|
71
71
|
import VisionTable from './visionTable.vue'
|
|
72
72
|
import adminforth from '@/adminforth';
|
|
73
73
|
import { useI18n } from 'vue-i18n';
|
|
74
74
|
import { useRoute } from 'vue-router';
|
|
75
75
|
import { AdminUser, type AdminForthResourceCommon } from '@/types';
|
|
76
|
-
import { RateLimiter } from "adminforth";
|
|
77
76
|
|
|
78
77
|
const route = useRoute();
|
|
79
78
|
const { t } = useI18n();
|
package/dist/index.js
CHANGED
|
@@ -58,39 +58,15 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
58
58
|
}
|
|
59
59
|
return compiled;
|
|
60
60
|
}
|
|
61
|
-
checkRateLimit(fieldNameRateLimit, headers) {
|
|
61
|
+
checkRateLimit(field, fieldNameRateLimit, headers) {
|
|
62
62
|
if (fieldNameRateLimit) {
|
|
63
63
|
// rate limit
|
|
64
|
-
const { error } = RateLimiter.checkRateLimit(
|
|
64
|
+
const { error } = RateLimiter.checkRateLimit(field, fieldNameRateLimit, this.adminforth.auth.getClientIp(headers));
|
|
65
65
|
if (error) {
|
|
66
66
|
return { error: "Rate limit exceeded" };
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
checkRateLimitForBulkGenerationRateLimit(source_api, headers) {
|
|
71
|
-
if (!this.options.bulkGenerationRateLimit) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const hasGenerateImages = !!this.options.generateImages && Object.keys(this.options.generateImages).length > 0;
|
|
75
|
-
const hasFillFieldsFromImages = !!this.options.fillFieldsFromImages && Object.keys(this.options.fillFieldsFromImages).length > 0;
|
|
76
|
-
const hasFillPlainFields = !!this.options.fillPlainFields && Object.keys(this.options.fillPlainFields).length > 0;
|
|
77
|
-
let shouldCheckRateLimit = false;
|
|
78
|
-
if (hasGenerateImages && source_api === 'generateImages') {
|
|
79
|
-
shouldCheckRateLimit = true;
|
|
80
|
-
}
|
|
81
|
-
else if (hasFillFieldsFromImages && source_api === 'fillFieldsFromImages' && !hasGenerateImages) {
|
|
82
|
-
shouldCheckRateLimit = true;
|
|
83
|
-
}
|
|
84
|
-
else if (hasFillPlainFields && source_api === 'fillPlainFields' && !hasFillFieldsFromImages && !hasGenerateImages) {
|
|
85
|
-
shouldCheckRateLimit = true;
|
|
86
|
-
}
|
|
87
|
-
if (shouldCheckRateLimit) {
|
|
88
|
-
const result = this.checkRateLimit(this.options.bulkGenerationRateLimit, headers);
|
|
89
|
-
if (result) {
|
|
90
|
-
return { error: "Rate limit exceeded" };
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
70
|
modifyResourceConfig(adminforth, resourceConfig) {
|
|
95
71
|
const _super = Object.create(null, {
|
|
96
72
|
modifyResourceConfig: { get: () => super.modifyResourceConfig }
|
|
@@ -222,8 +198,10 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
222
198
|
path: `/plugin/${this.pluginInstanceId}/analyze`,
|
|
223
199
|
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers }) {
|
|
224
200
|
const selectedIds = body.selectedIds || [];
|
|
225
|
-
if (this.
|
|
226
|
-
|
|
201
|
+
if (typeof (this.options.rateLimits.fillFieldsFromImages) === 'string') {
|
|
202
|
+
if (this.checkRateLimit("fillFieldsFromImages", this.options.rateLimits.fillFieldsFromImages, headers)) {
|
|
203
|
+
return { error: "Rate limit exceeded" };
|
|
204
|
+
}
|
|
227
205
|
}
|
|
228
206
|
const tasks = selectedIds.map((ID) => __awaiter(this, void 0, void 0, function* () {
|
|
229
207
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
@@ -262,8 +240,10 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
262
240
|
path: `/plugin/${this.pluginInstanceId}/analyze_no_images`,
|
|
263
241
|
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers }) {
|
|
264
242
|
const selectedIds = body.selectedIds || [];
|
|
265
|
-
if (this.
|
|
266
|
-
|
|
243
|
+
if (typeof (this.options.rateLimits.fillPlainFields) === 'string') {
|
|
244
|
+
if (this.checkRateLimit("fillPlainFields", this.options.rateLimits.fillPlainFields, headers)) {
|
|
245
|
+
return { error: "Rate limit exceeded" };
|
|
246
|
+
}
|
|
267
247
|
}
|
|
268
248
|
const tasks = selectedIds.map((ID) => __awaiter(this, void 0, void 0, function* () {
|
|
269
249
|
// Fetch the record using the provided ID
|
|
@@ -383,11 +363,11 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
383
363
|
const Id = body.recordId || [];
|
|
384
364
|
const prompt = body.prompt || '';
|
|
385
365
|
const fieldName = body.fieldName || '';
|
|
386
|
-
if (this.checkRateLimit(this.options.generateImages[fieldName].rateLimit, headers)) {
|
|
366
|
+
if (this.checkRateLimit(fieldName, this.options.generateImages[fieldName].rateLimit, headers)) {
|
|
387
367
|
return { error: "Rate limit exceeded" };
|
|
388
368
|
}
|
|
389
369
|
const start = +new Date();
|
|
390
|
-
const STUB_MODE =
|
|
370
|
+
const STUB_MODE = true;
|
|
391
371
|
const record = yield this.adminforth.resource(this.resourceConfig.resourceId).get([Filters.EQ((_b = this.resourceConfig.columns.find(c => c.primaryKey)) === null || _b === void 0 ? void 0 : _b.name, Id)]);
|
|
392
372
|
let attachmentFiles;
|
|
393
373
|
if (!this.options.attachFiles) {
|
|
@@ -426,9 +406,11 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
426
406
|
path: `/plugin/${this.pluginInstanceId}/initial_image_generate`,
|
|
427
407
|
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, headers }) {
|
|
428
408
|
const selectedIds = body.selectedIds || [];
|
|
429
|
-
const STUB_MODE =
|
|
430
|
-
if (this.
|
|
431
|
-
|
|
409
|
+
const STUB_MODE = true;
|
|
410
|
+
if (typeof (this.options.rateLimits.generateImages) === 'string') {
|
|
411
|
+
if (this.checkRateLimit("generateImages", this.options.rateLimits.generateImages, headers)) {
|
|
412
|
+
return { error: "Rate limit exceeded" };
|
|
413
|
+
}
|
|
432
414
|
}
|
|
433
415
|
const start = +new Date();
|
|
434
416
|
const tasks = selectedIds.map((ID) => __awaiter(this, void 0, void 0, function* () {
|
package/index.ts
CHANGED
|
@@ -61,11 +61,11 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
61
61
|
return compiled;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
private checkRateLimit(fieldNameRateLimit: string | undefined, headers: Record<string, string | string[] | undefined>): { error?: string } | void {
|
|
64
|
+
private checkRateLimit(field: string,fieldNameRateLimit: string | undefined, headers: Record<string, string | string[] | undefined>): { error?: string } | void {
|
|
65
65
|
if (fieldNameRateLimit) {
|
|
66
66
|
// rate limit
|
|
67
67
|
const { error } = RateLimiter.checkRateLimit(
|
|
68
|
-
|
|
68
|
+
field,
|
|
69
69
|
fieldNameRateLimit,
|
|
70
70
|
this.adminforth.auth.getClientIp(headers),
|
|
71
71
|
);
|
|
@@ -75,32 +75,6 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
private checkRateLimitForBulkGenerationRateLimit(source_api: string, headers: Record<string, string | string[] | undefined>): { error?: string } | void {
|
|
79
|
-
if (!this.options.bulkGenerationRateLimit) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const hasGenerateImages = !!this.options.generateImages && Object.keys(this.options.generateImages).length > 0;
|
|
84
|
-
const hasFillFieldsFromImages = !!this.options.fillFieldsFromImages && Object.keys(this.options.fillFieldsFromImages).length > 0;
|
|
85
|
-
const hasFillPlainFields = !!this.options.fillPlainFields && Object.keys(this.options.fillPlainFields).length > 0;
|
|
86
|
-
|
|
87
|
-
let shouldCheckRateLimit = false;
|
|
88
|
-
|
|
89
|
-
if (hasGenerateImages && source_api === 'generateImages') {
|
|
90
|
-
shouldCheckRateLimit = true;
|
|
91
|
-
} else if (hasFillFieldsFromImages && source_api === 'fillFieldsFromImages' && !hasGenerateImages) {
|
|
92
|
-
shouldCheckRateLimit = true;
|
|
93
|
-
} else if (hasFillPlainFields && source_api === 'fillPlainFields' && !hasFillFieldsFromImages && !hasGenerateImages) {
|
|
94
|
-
shouldCheckRateLimit = true;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (shouldCheckRateLimit) {
|
|
98
|
-
const result = this.checkRateLimit(this.options.bulkGenerationRateLimit, headers);
|
|
99
|
-
if (result) {
|
|
100
|
-
return { error: "Rate limit exceeded" };
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
78
|
|
|
105
79
|
async modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
|
|
106
80
|
super.modifyResourceConfig(adminforth, resourceConfig);
|
|
@@ -251,8 +225,10 @@ private checkRateLimitForBulkGenerationRateLimit(source_api: string, headers: Re
|
|
|
251
225
|
path: `/plugin/${this.pluginInstanceId}/analyze`,
|
|
252
226
|
handler: async ({ body, adminUser, headers }) => {
|
|
253
227
|
const selectedIds = body.selectedIds || [];
|
|
254
|
-
if (this.
|
|
255
|
-
|
|
228
|
+
if (typeof(this.options.rateLimits.fillFieldsFromImages) === 'string'){
|
|
229
|
+
if (this.checkRateLimit("fillFieldsFromImages" ,this.options.rateLimits.fillFieldsFromImages, headers)) {
|
|
230
|
+
return { error: "Rate limit exceeded" };
|
|
231
|
+
}
|
|
256
232
|
}
|
|
257
233
|
const tasks = selectedIds.map(async (ID) => {
|
|
258
234
|
// Fetch the record using the provided ID
|
|
@@ -299,8 +275,10 @@ private checkRateLimitForBulkGenerationRateLimit(source_api: string, headers: Re
|
|
|
299
275
|
path: `/plugin/${this.pluginInstanceId}/analyze_no_images`,
|
|
300
276
|
handler: async ({ body, adminUser, headers }) => {
|
|
301
277
|
const selectedIds = body.selectedIds || [];
|
|
302
|
-
if (this.
|
|
303
|
-
|
|
278
|
+
if (typeof(this.options.rateLimits.fillPlainFields) === 'string'){
|
|
279
|
+
if (this.checkRateLimit("fillPlainFields", this.options.rateLimits.fillPlainFields, headers)) {
|
|
280
|
+
return { error: "Rate limit exceeded" };
|
|
281
|
+
}
|
|
304
282
|
}
|
|
305
283
|
const tasks = selectedIds.map(async (ID) => {
|
|
306
284
|
// Fetch the record using the provided ID
|
|
@@ -433,11 +411,11 @@ private checkRateLimitForBulkGenerationRateLimit(source_api: string, headers: Re
|
|
|
433
411
|
const Id = body.recordId || [];
|
|
434
412
|
const prompt = body.prompt || '';
|
|
435
413
|
const fieldName = body.fieldName || '';
|
|
436
|
-
if (this.checkRateLimit(this.options.generateImages[fieldName].rateLimit, headers)) {
|
|
414
|
+
if (this.checkRateLimit(fieldName, this.options.generateImages[fieldName].rateLimit, headers)) {
|
|
437
415
|
return { error: "Rate limit exceeded" };
|
|
438
416
|
}
|
|
439
417
|
const start = +new Date();
|
|
440
|
-
const STUB_MODE =
|
|
418
|
+
const STUB_MODE = true;
|
|
441
419
|
const record = await this.adminforth.resource(this.resourceConfig.resourceId).get([Filters.EQ(this.resourceConfig.columns.find(c => c.primaryKey)?.name, Id)]);
|
|
442
420
|
let attachmentFiles
|
|
443
421
|
if(!this.options.attachFiles){
|
|
@@ -482,9 +460,11 @@ private checkRateLimitForBulkGenerationRateLimit(source_api: string, headers: Re
|
|
|
482
460
|
path: `/plugin/${this.pluginInstanceId}/initial_image_generate`,
|
|
483
461
|
handler: async ({ body, headers }) => {
|
|
484
462
|
const selectedIds = body.selectedIds || [];
|
|
485
|
-
const STUB_MODE =
|
|
486
|
-
if (this.
|
|
487
|
-
|
|
463
|
+
const STUB_MODE = true;
|
|
464
|
+
if (typeof(this.options.rateLimits.generateImages) === 'string'){
|
|
465
|
+
if (this.checkRateLimit("generateImages", this.options.rateLimits.generateImages, headers)) {
|
|
466
|
+
return { error: "Rate limit exceeded" };
|
|
467
|
+
}
|
|
488
468
|
}
|
|
489
469
|
const start = +new Date();
|
|
490
470
|
const tasks = selectedIds.map(async (ID) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/bulk-ai-flow",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -20,8 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@types/handlebars": "^4.0.40",
|
|
23
|
-
"adminforth": "^2.4.0-next.
|
|
24
|
-
"handlebars": "^4.7.8"
|
|
25
|
-
"medium-zoom": "^1.1.0"
|
|
23
|
+
"adminforth": "^2.4.0-next.112",
|
|
24
|
+
"handlebars": "^4.7.8"
|
|
26
25
|
}
|
|
27
26
|
}
|
package/types.ts
CHANGED
|
@@ -43,10 +43,12 @@ export interface PluginOptions {
|
|
|
43
43
|
*/
|
|
44
44
|
countToGenerate: number,
|
|
45
45
|
}>,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
rateLimits?: {
|
|
47
|
+
fillFieldsFromImages?: string, // e.g. 5/1d - 5 requests per day
|
|
48
|
+
fillPlainFields?: string,
|
|
49
|
+
generateImages?: string,
|
|
50
|
+
},
|
|
51
|
+
|
|
50
52
|
|
|
51
53
|
/**
|
|
52
54
|
* Whether the user is allowed to save the generated images
|