3636 :carouselSaveImages =" carouselSaveImages"
3737 :carouselImageIndex =" carouselImageIndex"
3838 :regenerateImagesRefreshRate =" props.meta.refreshRates?.regenerateImages"
39+ :isAiGenerationError =" isAiGenerationError"
40+ :aiGenerationErrorMessage =" aiGenerationErrorMessage"
41+ :isAiImageGenerationError =" isAiImageGenerationError"
42+ :imageGenerationErrorMessage =" imageGenerationErrorMessage"
43+ @regenerate-images =" regenerateImages"
3944 />
4045 </div >
4146 <div class =" text-red-600 flex items-center w-full" >
@@ -53,6 +58,7 @@ import VisionTable from './VisionTable.vue'
5358import adminforth from ' @/adminforth' ;
5459import { useI18n } from ' vue-i18n' ;
5560import { AdminUser , type AdminForthResourceCommon } from ' @/types' ;
61+ import { run } from ' node:test' ;
5662
5763const { t } = useI18n ();
5864const props = defineProps <{
@@ -94,6 +100,10 @@ const isGeneratingImages = ref(false);
94100const isAnalizingFields = ref (false );
95101const isAnalizingImages = ref (false );
96102const isDialogOpen = ref (false );
103+ const isAiGenerationError = ref <boolean []>([false ]);
104+ const aiGenerationErrorMessage = ref <string []>([]);
105+ const isAiImageGenerationError = ref <boolean []>([false ]);
106+ const imageGenerationErrorMessage = ref <string []>([]);
97107
98108const openDialog = async () => {
99109 isDialogOpen .value = true ;
@@ -416,47 +426,59 @@ async function runAiAction({
416426 actionType ,
417427 responseFlag ,
418428 updateOnSuccess = true ,
429+ recordsIds = props .checkboxes ,
430+ disableRateLimitCheck = false ,
419431}: {
420432 endpoint: string ;
421433 actionType: ' analyze' | ' analyze_no_images' | ' generate_images' ;
422434 responseFlag: Ref <boolean []>;
423435 updateOnSuccess? : boolean ;
436+ recordsIds? : any [];
437+ disableRateLimitCheck? : boolean ;
424438}) {
425439 let hasError = false ;
426440 let errorMessage = ' ' ;
427441 const jobsIds: { jobId: any ; recordId: any ; }[] = [];
428- responseFlag .value = props .checkboxes .map (() => false );
442+ // responseFlag.value = props.checkboxes.map(() => false);
443+ for (let i = 0 ; i < recordsIds .length ; i ++ ) {
444+ const index = props .checkboxes .findIndex (item => String (item ) === String (recordsIds [i ]));
445+ if (index !== - 1 ) {
446+ responseFlag .value [index ] = false ;
447+ }
448+ }
429449 let isRateLimitExceeded = false ;
430- try {
431- const rateLimitRes = await callAdminForthApi ({
432- path: ` /plugin/${props .meta .pluginInstanceId }/update-rate-limits ` ,
433- method: ' POST' ,
434- body: {
435- actionType: actionType ,
436- },
437- });
438- if (rateLimitRes ?.error ) {
439- isRateLimitExceeded = true ;
450+ if (! disableRateLimitCheck ){
451+ try {
452+ const rateLimitRes = await callAdminForthApi ({
453+ path: ` /plugin/${props .meta .pluginInstanceId }/update-rate-limits ` ,
454+ method: ' POST' ,
455+ body: {
456+ actionType: actionType ,
457+ },
458+ });
459+ if (rateLimitRes ?.error ) {
460+ isRateLimitExceeded = true ;
461+ adminforth .alert ({
462+ message: ` Rate limit exceeded for "${actionType .replace (' _' , ' ' )}" action. Please try again later. ` ,
463+ variant: ' danger' ,
464+ timeout: ' unlimited' ,
465+ });
466+ return ;
467+ }
468+ } catch (e ) {
440469 adminforth .alert ({
441- message: ` Rate limit exceeded for "${actionType .replace (' _' , ' ' )}" action. Please try again later .` ,
442- variant: ' danger' ,
443- timeout: ' unlimited' ,
444- });
445- return ;
470+ message: ` Error checking rate limit for "${actionType .replace (' _' , ' ' )}" action.` ,
471+ variant: ' danger' ,
472+ timeout: ' unlimited' ,
473+ });
474+ isRateLimitExceeded = true ;
446475 }
447- } catch (e ) {
448- adminforth .alert ({
449- message: ` Error checking rate limit for "${actionType .replace (' _' , ' ' )}" action. ` ,
450- variant: ' danger' ,
451- timeout: ' unlimited' ,
452- });
453- isRateLimitExceeded = true ;
476+ if (isRateLimitExceeded ) {
477+ return ;
478+ };
454479 }
455- if (isRateLimitExceeded ) {
456- return ;
457- };
458480 // creating jobs
459- const tasks = props . checkboxes .map (async (checkbox , i ) => {
481+ const tasks = recordsIds .map (async (checkbox , i ) => {
460482 try {
461483 const res = await callAdminForthApi ({
462484 path: ` /plugin/${props .meta .pluginInstanceId }/create-job ` ,
@@ -549,13 +571,22 @@ async function runAiAction({
549571 }
550572 if (index !== - 1 ) {
551573 jobsIds .splice (jobsIds .findIndex (j => j .jobId === jobId ), 1 );
574+ } else {
575+ jobsIds .splice (0 , jobsIds .length );
552576 }
553577 isAtLeastOneInProgress = true ;
554578 adminforth .alert ({
555579 message: ` Generation action "${actionType .replace (' _' , ' ' )}" failed for record: ${recordId }. Error: ${jobResponse .job ?.error || ' Unknown error' } ` ,
556580 variant: ' danger' ,
557581 timeout: ' unlimited' ,
558582 });
583+ if (actionType === ' generate_images' ) {
584+ isAiImageGenerationError .value [index ] = true ;
585+ imageGenerationErrorMessage .value [index ] = jobResponse .job ?.error || ' Unknown error' ;
586+ } else {
587+ isAiGenerationError .value [index ] = true ;
588+ aiGenerationErrorMessage .value [index ] = jobResponse .job ?.error || ' Unknown error' ;
589+ }
559590 }
560591 }
561592 if (! isAtLeastOneInProgress ) {
@@ -668,4 +699,15 @@ async function uploadImage(imgBlob, id, fieldName) {
668699 }
669700}
670701
702+ function regenerateImages(recordInfo : any ) {
703+ isGeneratingImages .value = true ;
704+ runAiAction ({
705+ endpoint: ' initial_image_generate' ,
706+ actionType: ' generate_images' ,
707+ responseFlag: isAiResponseReceivedImage ,
708+ recordsIds: [recordInfo .recordInfo ],
709+ disableRateLimitCheck: true ,
710+ });
711+ }
712+
671713 </script >
0 commit comments