@adminforth/bulk-ai-flow 1.4.1 → 1.5.0
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 +2 -1
- package/custom/visionAction.vue +70 -29
- package/dist/custom/package-lock.json +3505 -57
- package/dist/custom/package.json +2 -1
- package/dist/custom/visionAction.vue +70 -29
- package/dist/index.js +19 -7
- package/index.ts +20 -8
- package/package.json +2 -2
- package/types.ts +6 -4
package/dist/custom/package.json
CHANGED
|
@@ -66,7 +66,7 @@
|
|
|
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';
|
|
@@ -143,7 +143,7 @@ const openDialog = async () => {
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
watch(selected, (val) => {
|
|
146
|
-
console.log('Selected changed:', val);
|
|
146
|
+
//console.log('Selected changed:', val);
|
|
147
147
|
checkedCount.value = val.filter(item => item.isChecked === true).length;
|
|
148
148
|
}, { deep: true });
|
|
149
149
|
|
|
@@ -158,6 +158,7 @@ const closeDialog = () => {
|
|
|
158
158
|
tableColumns.value = [];
|
|
159
159
|
tableColumnsIndexes.value = [];
|
|
160
160
|
isError.value = false;
|
|
161
|
+
isCriticalError.value = false;
|
|
161
162
|
errorMessage.value = '';
|
|
162
163
|
}
|
|
163
164
|
|
|
@@ -340,22 +341,42 @@ async function analyzeFields() {
|
|
|
340
341
|
|
|
341
342
|
isAiResponseReceivedAnalize.value = props.checkboxes.map(() => true);
|
|
342
343
|
|
|
343
|
-
res
|
|
344
|
-
|
|
344
|
+
if (res?.error) {
|
|
345
|
+
adminforth.alert({
|
|
346
|
+
message: res.error,
|
|
347
|
+
variant: 'danger',
|
|
348
|
+
timeout: 'unlimited',
|
|
349
|
+
});
|
|
345
350
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
351
|
+
console.error('Failed to analyze image(s):', res.error);
|
|
352
|
+
isError.value = true;
|
|
353
|
+
isCriticalError.value = true;
|
|
354
|
+
errorMessage.value = `Failed to fetch analyze image(s). Please, try to re-run the action.`;
|
|
355
|
+
} else {
|
|
356
|
+
res.result.forEach((item, idx) => {
|
|
357
|
+
const pk = selected.value[idx]?.[primaryKey]
|
|
358
|
+
|
|
359
|
+
if (pk) {
|
|
360
|
+
selected.value[idx] = {
|
|
361
|
+
...selected.value[idx],
|
|
362
|
+
...item,
|
|
363
|
+
isChecked: true,
|
|
364
|
+
[primaryKey]: pk
|
|
365
|
+
}
|
|
352
366
|
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
367
|
+
})
|
|
368
|
+
}
|
|
355
369
|
} catch (error) {
|
|
370
|
+
adminforth.alert({
|
|
371
|
+
message: error,
|
|
372
|
+
variant: 'danger',
|
|
373
|
+
timeout: 'unlimited',
|
|
374
|
+
});
|
|
375
|
+
|
|
356
376
|
console.error('Failed to analyze image(s):', error);
|
|
357
377
|
isError.value = true;
|
|
358
|
-
|
|
378
|
+
isCriticalError.value = true;
|
|
379
|
+
errorMessage.value = res.error;
|
|
359
380
|
}
|
|
360
381
|
}
|
|
361
382
|
|
|
@@ -374,23 +395,40 @@ async function analyzeFieldsNoImages() {
|
|
|
374
395
|
if(!props.meta.isFieldsForAnalizeFromImages) {
|
|
375
396
|
isAiResponseReceivedAnalize.value = props.checkboxes.map(() => true);
|
|
376
397
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
398
|
+
if(res?.error) {
|
|
399
|
+
adminforth.alert({
|
|
400
|
+
message: res.error,
|
|
401
|
+
variant: 'danger',
|
|
402
|
+
timeout: 'unlimited',
|
|
403
|
+
});
|
|
404
|
+
console.error('Failed to analyze fields:', res.error);
|
|
405
|
+
isError.value = true;
|
|
406
|
+
isCriticalError.value = true;
|
|
407
|
+
errorMessage.value = res.error;
|
|
408
|
+
} else {
|
|
409
|
+
res.result.forEach((item, idx) => {
|
|
410
|
+
const pk = selected.value[idx]?.[primaryKey]
|
|
411
|
+
|
|
412
|
+
if (pk) {
|
|
413
|
+
selected.value[idx] = {
|
|
414
|
+
...selected.value[idx],
|
|
415
|
+
...item,
|
|
416
|
+
isChecked: true,
|
|
417
|
+
[primaryKey]: pk
|
|
418
|
+
}
|
|
387
419
|
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
420
|
+
})
|
|
421
|
+
}
|
|
390
422
|
} catch (error) {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
423
|
+
adminforth.alert({
|
|
424
|
+
message: error,
|
|
425
|
+
variant: 'danger',
|
|
426
|
+
timeout: 'unlimited',
|
|
427
|
+
});
|
|
428
|
+
console.error('Failed to analyze fields:', error);
|
|
429
|
+
isError.value = true;
|
|
430
|
+
isCriticalError.value = true;
|
|
431
|
+
errorMessage.value = `Failed to analyze fields. Please, try to re-run the action.`;
|
|
394
432
|
}
|
|
395
433
|
}
|
|
396
434
|
|
|
@@ -490,7 +528,10 @@ async function generateImages() {
|
|
|
490
528
|
message: error,
|
|
491
529
|
variant: 'danger',
|
|
492
530
|
timeout: 'unlimited',
|
|
493
|
-
})
|
|
531
|
+
});;
|
|
532
|
+
isError.value = true;
|
|
533
|
+
isCriticalError.value = true;
|
|
534
|
+
errorMessage.value = error;
|
|
494
535
|
} else {
|
|
495
536
|
res.result.forEach((item, idx) => {
|
|
496
537
|
const pk = selected.value[idx]?.[primaryKey]
|
package/dist/index.js
CHANGED
|
@@ -58,10 +58,10 @@ 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
|
}
|
|
@@ -198,6 +198,11 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
198
198
|
path: `/plugin/${this.pluginInstanceId}/analyze`,
|
|
199
199
|
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers }) {
|
|
200
200
|
const selectedIds = body.selectedIds || [];
|
|
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
|
+
}
|
|
205
|
+
}
|
|
201
206
|
const tasks = selectedIds.map((ID) => __awaiter(this, void 0, void 0, function* () {
|
|
202
207
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
203
208
|
// Fetch the record using the provided ID
|
|
@@ -235,6 +240,11 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
235
240
|
path: `/plugin/${this.pluginInstanceId}/analyze_no_images`,
|
|
236
241
|
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers }) {
|
|
237
242
|
const selectedIds = body.selectedIds || [];
|
|
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
|
+
}
|
|
247
|
+
}
|
|
238
248
|
const tasks = selectedIds.map((ID) => __awaiter(this, void 0, void 0, function* () {
|
|
239
249
|
// Fetch the record using the provided ID
|
|
240
250
|
const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
|
|
@@ -353,11 +363,11 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
353
363
|
const Id = body.recordId || [];
|
|
354
364
|
const prompt = body.prompt || '';
|
|
355
365
|
const fieldName = body.fieldName || '';
|
|
356
|
-
if (this.checkRateLimit(this.options.generateImages[fieldName].rateLimit, headers)) {
|
|
366
|
+
if (this.checkRateLimit(fieldName, this.options.generateImages[fieldName].rateLimit, headers)) {
|
|
357
367
|
return { error: "Rate limit exceeded" };
|
|
358
368
|
}
|
|
359
369
|
const start = +new Date();
|
|
360
|
-
const STUB_MODE =
|
|
370
|
+
const STUB_MODE = true;
|
|
361
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)]);
|
|
362
372
|
let attachmentFiles;
|
|
363
373
|
if (!this.options.attachFiles) {
|
|
@@ -396,9 +406,11 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
396
406
|
path: `/plugin/${this.pluginInstanceId}/initial_image_generate`,
|
|
397
407
|
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, headers }) {
|
|
398
408
|
const selectedIds = body.selectedIds || [];
|
|
399
|
-
const STUB_MODE =
|
|
400
|
-
if (
|
|
401
|
-
|
|
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
|
+
}
|
|
402
414
|
}
|
|
403
415
|
const start = +new Date();
|
|
404
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,6 +75,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
|
|
78
79
|
async modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
|
|
79
80
|
super.modifyResourceConfig(adminforth, resourceConfig);
|
|
80
81
|
|
|
@@ -224,6 +225,11 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
224
225
|
path: `/plugin/${this.pluginInstanceId}/analyze`,
|
|
225
226
|
handler: async ({ body, adminUser, headers }) => {
|
|
226
227
|
const selectedIds = body.selectedIds || [];
|
|
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
|
+
}
|
|
232
|
+
}
|
|
227
233
|
const tasks = selectedIds.map(async (ID) => {
|
|
228
234
|
// Fetch the record using the provided ID
|
|
229
235
|
const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
|
|
@@ -269,6 +275,11 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
269
275
|
path: `/plugin/${this.pluginInstanceId}/analyze_no_images`,
|
|
270
276
|
handler: async ({ body, adminUser, headers }) => {
|
|
271
277
|
const selectedIds = body.selectedIds || [];
|
|
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
|
+
}
|
|
282
|
+
}
|
|
272
283
|
const tasks = selectedIds.map(async (ID) => {
|
|
273
284
|
// Fetch the record using the provided ID
|
|
274
285
|
const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
|
|
@@ -400,11 +411,11 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
400
411
|
const Id = body.recordId || [];
|
|
401
412
|
const prompt = body.prompt || '';
|
|
402
413
|
const fieldName = body.fieldName || '';
|
|
403
|
-
if (this.checkRateLimit(this.options.generateImages[fieldName].rateLimit, headers)) {
|
|
414
|
+
if (this.checkRateLimit(fieldName, this.options.generateImages[fieldName].rateLimit, headers)) {
|
|
404
415
|
return { error: "Rate limit exceeded" };
|
|
405
416
|
}
|
|
406
417
|
const start = +new Date();
|
|
407
|
-
const STUB_MODE =
|
|
418
|
+
const STUB_MODE = true;
|
|
408
419
|
const record = await this.adminforth.resource(this.resourceConfig.resourceId).get([Filters.EQ(this.resourceConfig.columns.find(c => c.primaryKey)?.name, Id)]);
|
|
409
420
|
let attachmentFiles
|
|
410
421
|
if(!this.options.attachFiles){
|
|
@@ -449,10 +460,11 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
449
460
|
path: `/plugin/${this.pluginInstanceId}/initial_image_generate`,
|
|
450
461
|
handler: async ({ body, headers }) => {
|
|
451
462
|
const selectedIds = body.selectedIds || [];
|
|
452
|
-
const STUB_MODE =
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
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
|
+
}
|
|
456
468
|
}
|
|
457
469
|
const start = +new Date();
|
|
458
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.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@types/handlebars": "^4.0.40",
|
|
23
|
-
"adminforth": "^2.4.0-next.
|
|
23
|
+
"adminforth": "^2.4.0-next.112",
|
|
24
24
|
"handlebars": "^4.7.8",
|
|
25
25
|
"medium-zoom": "^1.1.0"
|
|
26
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
|