@adminforth/bulk-ai-flow 1.20.0 → 1.21.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 CHANGED
@@ -13,5 +13,5 @@ custom/package-lock.json
13
13
  custom/package.json
14
14
  custom/tsconfig.json
15
15
 
16
- sent 95,557 bytes received 172 bytes 191,458.00 bytes/sec
17
- total size is 94,921 speedup is 0.99
16
+ sent 96,594 bytes received 172 bytes 193,532.00 bytes/sec
17
+ total size is 95,949 speedup is 0.99
@@ -140,19 +140,19 @@
140
140
  <div class="flex items-center justify-between mb-2 w-full">
141
141
  <div class="flex items-center justify-center gap-2">
142
142
  <IconShieldSolid class="w-6 h-6 text-lightPrimary dark:text-darkPrimary" />
143
- <p class="sm:text-base text-sm">{{ t('Do not overwrite existing values') }}</p>
143
+ <p class="sm:text-base text-sm">{{ t('Overwrite existing values') }}</p>
144
144
  <Tooltip>
145
145
  <IconInfoCircleSolid class="w-5 h-5 me-2 text-lightPrimary dark:text-darkPrimary"/>
146
146
  <template #tooltip>
147
- <p class="max-w-64">{{ t('When enabled, the AI will skip generating content for fields that already have data. This helps to preserve existing information and avoid overwriting valuable content.') }}</p>
147
+ <p class="max-w-64">{{ t('When enabled, the AI will overwrite content for fields that already have data. When off - this helps to preserve existing information and avoid overwriting valuable content.') }}</p>
148
148
  </template>
149
149
  </Tooltip>
150
150
  </div>
151
151
  <Toggle
152
- v-model="skipFilledFieldsForGeneration"
152
+ v-model="overwriteExistingValues"
153
153
  />
154
154
  </div>
155
- <div :class="skipFilledFieldsForGeneration === false ? 'opacity-100' : 'opacity-0'" class="flex items-center text-yellow-800 bg-yellow-100 p-2 rounded-md border border-yellow-300">
155
+ <div :class="overwriteExistingValues === true ? 'opacity-100' : 'opacity-0'" class="flex items-center text-yellow-800 bg-yellow-100 p-2 rounded-md border border-yellow-300">
156
156
  <IconExclamationTriangle class="w-6 h-6 me-2"/>
157
157
  <p class="sm:text-base text-sm">{{ t('Warning: Existing values will be overwritten.') }}</p>
158
158
  </div>
@@ -236,7 +236,9 @@ const generationPrompts = ref<any>({});
236
236
  const isDataSaved = ref(false);
237
237
 
238
238
  const regeneratingFieldsStatus = ref<Record<string, Record<string, boolean>>>({});
239
- const skipFilledFieldsForGeneration = ref<boolean>(true);
239
+ const overwriteExistingValues = ref<boolean>(false);
240
+
241
+ const listOfImageThatWasNotGeneratedPerRecord = ref<Record<string, string[]>>({});
240
242
 
241
243
  const openDialog = async () => {
242
244
  window.addEventListener('beforeunload', beforeUnloadHandler);
@@ -544,6 +546,14 @@ async function saveData() {
544
546
  if (!value) {
545
547
  continue;
546
548
  }
549
+ if (!overwriteExistingValues.value) {
550
+ const imageURL = selected.value.find(rec => rec[primaryKey] === item[primaryKey])[key];
551
+ const originalImageUrl = listOfImageThatWasNotGeneratedPerRecord.value[item[primaryKey]][key].originalImage;
552
+ if (originalImageUrl === imageURL) {
553
+ reqData.find(rec => rec[primaryKey] === item[primaryKey])[key] = undefined;
554
+ continue;
555
+ }
556
+ }
547
557
  const p = uploadImage(value, item[primaryKey], key).then(result => {
548
558
  item[key] = result;
549
559
  });
@@ -553,7 +563,6 @@ async function saveData() {
553
563
  }
554
564
  await Promise.all(imagesToUpload);
555
565
  }
556
-
557
566
  const res = await callAdminForthApi({
558
567
  path: `/plugin/${props.meta.pluginInstanceId}/update_fields`,
559
568
  method: 'POST',
@@ -668,7 +677,7 @@ async function runAiAction({
668
677
  actionType: actionType,
669
678
  recordId: checkbox,
670
679
  ...(customPrompt !== undefined ? { customPrompt: JSON.stringify(customPrompt) } : {}),
671
- filterFilledFields: skipFilledFieldsForGeneration.value,
680
+ filterFilledFields: !overwriteExistingValues.value,
672
681
  },
673
682
  silentError: true,
674
683
  });
@@ -729,7 +738,14 @@ async function runAiAction({
729
738
  for (const [key, value] of Object.entries(carouselSaveImages.value[index])) {
730
739
  if (props.meta.outputImageFields?.includes(key)) {
731
740
  carouselSaveImages.value[index][key] = [jobResponse.job.result[key]];
732
- }
741
+ if (jobResponse.job.recordMeta?.[`${key}_meta`]) {
742
+ carouselSaveImages.value[index][key] = [jobResponse.job.recordMeta[`${key}_meta`].originalImage];
743
+ if (!listOfImageThatWasNotGeneratedPerRecord.value[recordId]) {
744
+ listOfImageThatWasNotGeneratedPerRecord.value[recordId] = [];
745
+ }
746
+ listOfImageThatWasNotGeneratedPerRecord.value[recordId][key] = jobResponse.job.recordMeta[`${key}_meta`];
747
+ }
748
+ }
733
749
  }
734
750
  }
735
751
  //marking that we received response for this record
@@ -140,19 +140,19 @@
140
140
  <div class="flex items-center justify-between mb-2 w-full">
141
141
  <div class="flex items-center justify-center gap-2">
142
142
  <IconShieldSolid class="w-6 h-6 text-lightPrimary dark:text-darkPrimary" />
143
- <p class="sm:text-base text-sm">{{ t('Do not overwrite existing values') }}</p>
143
+ <p class="sm:text-base text-sm">{{ t('Overwrite existing values') }}</p>
144
144
  <Tooltip>
145
145
  <IconInfoCircleSolid class="w-5 h-5 me-2 text-lightPrimary dark:text-darkPrimary"/>
146
146
  <template #tooltip>
147
- <p class="max-w-64">{{ t('When enabled, the AI will skip generating content for fields that already have data. This helps to preserve existing information and avoid overwriting valuable content.') }}</p>
147
+ <p class="max-w-64">{{ t('When enabled, the AI will overwrite content for fields that already have data. When off - this helps to preserve existing information and avoid overwriting valuable content.') }}</p>
148
148
  </template>
149
149
  </Tooltip>
150
150
  </div>
151
151
  <Toggle
152
- v-model="skipFilledFieldsForGeneration"
152
+ v-model="overwriteExistingValues"
153
153
  />
154
154
  </div>
155
- <div :class="skipFilledFieldsForGeneration === false ? 'opacity-100' : 'opacity-0'" class="flex items-center text-yellow-800 bg-yellow-100 p-2 rounded-md border border-yellow-300">
155
+ <div :class="overwriteExistingValues === true ? 'opacity-100' : 'opacity-0'" class="flex items-center text-yellow-800 bg-yellow-100 p-2 rounded-md border border-yellow-300">
156
156
  <IconExclamationTriangle class="w-6 h-6 me-2"/>
157
157
  <p class="sm:text-base text-sm">{{ t('Warning: Existing values will be overwritten.') }}</p>
158
158
  </div>
@@ -236,7 +236,9 @@ const generationPrompts = ref<any>({});
236
236
  const isDataSaved = ref(false);
237
237
 
238
238
  const regeneratingFieldsStatus = ref<Record<string, Record<string, boolean>>>({});
239
- const skipFilledFieldsForGeneration = ref<boolean>(true);
239
+ const overwriteExistingValues = ref<boolean>(false);
240
+
241
+ const listOfImageThatWasNotGeneratedPerRecord = ref<Record<string, string[]>>({});
240
242
 
241
243
  const openDialog = async () => {
242
244
  window.addEventListener('beforeunload', beforeUnloadHandler);
@@ -544,6 +546,14 @@ async function saveData() {
544
546
  if (!value) {
545
547
  continue;
546
548
  }
549
+ if (!overwriteExistingValues.value) {
550
+ const imageURL = selected.value.find(rec => rec[primaryKey] === item[primaryKey])[key];
551
+ const originalImageUrl = listOfImageThatWasNotGeneratedPerRecord.value[item[primaryKey]][key].originalImage;
552
+ if (originalImageUrl === imageURL) {
553
+ reqData.find(rec => rec[primaryKey] === item[primaryKey])[key] = undefined;
554
+ continue;
555
+ }
556
+ }
547
557
  const p = uploadImage(value, item[primaryKey], key).then(result => {
548
558
  item[key] = result;
549
559
  });
@@ -553,7 +563,6 @@ async function saveData() {
553
563
  }
554
564
  await Promise.all(imagesToUpload);
555
565
  }
556
-
557
566
  const res = await callAdminForthApi({
558
567
  path: `/plugin/${props.meta.pluginInstanceId}/update_fields`,
559
568
  method: 'POST',
@@ -668,7 +677,7 @@ async function runAiAction({
668
677
  actionType: actionType,
669
678
  recordId: checkbox,
670
679
  ...(customPrompt !== undefined ? { customPrompt: JSON.stringify(customPrompt) } : {}),
671
- filterFilledFields: skipFilledFieldsForGeneration.value,
680
+ filterFilledFields: !overwriteExistingValues.value,
672
681
  },
673
682
  silentError: true,
674
683
  });
@@ -729,7 +738,14 @@ async function runAiAction({
729
738
  for (const [key, value] of Object.entries(carouselSaveImages.value[index])) {
730
739
  if (props.meta.outputImageFields?.includes(key)) {
731
740
  carouselSaveImages.value[index][key] = [jobResponse.job.result[key]];
732
- }
741
+ if (jobResponse.job.recordMeta?.[`${key}_meta`]) {
742
+ carouselSaveImages.value[index][key] = [jobResponse.job.recordMeta[`${key}_meta`].originalImage];
743
+ if (!listOfImageThatWasNotGeneratedPerRecord.value[recordId]) {
744
+ listOfImageThatWasNotGeneratedPerRecord.value[recordId] = [];
745
+ }
746
+ listOfImageThatWasNotGeneratedPerRecord.value[recordId][key] = jobResponse.job.recordMeta[`${key}_meta`];
747
+ }
748
+ }
733
749
  }
734
750
  }
735
751
  //marking that we received response for this record
package/dist/index.js CHANGED
@@ -265,7 +265,17 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
265
265
  }
266
266
  const fieldTasks = Object.keys(((_b = this.options) === null || _b === void 0 ? void 0 : _b.generateImages) || {}).map((key) => __awaiter(this, void 0, void 0, function* () {
267
267
  if (record[key] && filterFilledFields) {
268
- return { key, images: [] };
268
+ const plugin = this.adminforth.activatedPlugins.find(p => p.resourceConfig.resourceId === this.resourceConfig.resourceId &&
269
+ p.pluginOptions.pathColumnName === key);
270
+ const image_url = yield plugin.pluginOptions.storageAdapter.getDownloadUrl(record[key]);
271
+ return {
272
+ key,
273
+ images: [image_url],
274
+ meta: {
275
+ skippedToNotOverwrite: true,
276
+ originalImage: image_url,
277
+ }
278
+ };
269
279
  }
270
280
  const prompt = (yield this.compileGenerationFieldTemplates(record, customPrompt))[key];
271
281
  let images;
@@ -320,14 +330,18 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
320
330
  }));
321
331
  const fieldResults = yield Promise.all(fieldTasks);
322
332
  const recordResult = {};
323
- fieldResults.forEach(({ key, images }) => {
333
+ const recordMeta = {};
334
+ fieldResults.forEach(({ key, images, meta }) => {
324
335
  recordResult[key] = images;
336
+ if (meta) {
337
+ recordMeta[`${key}_meta`] = meta;
338
+ }
325
339
  });
326
340
  const result = recordResult;
327
341
  if (!isError) {
328
342
  this.totalCalls++;
329
343
  this.totalDuration += (+new Date() - start) / 1000;
330
- jobs.set(jobId, { status: 'completed', result });
344
+ jobs.set(jobId, { status: 'completed', result, recordMeta });
331
345
  return { ok: true };
332
346
  }
333
347
  else {
package/index.ts CHANGED
@@ -260,7 +260,19 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
260
260
  }
261
261
  const fieldTasks = Object.keys(this.options?.generateImages || {}).map(async (key) => {
262
262
  if ( record[key] && filterFilledFields ) {
263
- return { key, images: [] };
263
+ const plugin = this.adminforth.activatedPlugins.find(p =>
264
+ p.resourceConfig!.resourceId === this.resourceConfig.resourceId &&
265
+ p.pluginOptions.pathColumnName === key
266
+ );
267
+ const image_url = await plugin.pluginOptions.storageAdapter.getDownloadUrl(record[key]);
268
+ return {
269
+ key,
270
+ images: [image_url],
271
+ meta: {
272
+ skippedToNotOverwrite: true,
273
+ originalImage: image_url,
274
+ }
275
+ };
264
276
  }
265
277
  const prompt = (await this.compileGenerationFieldTemplates(record, customPrompt))[key];
266
278
  let images;
@@ -312,10 +324,14 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
312
324
  });
313
325
 
314
326
  const fieldResults = await Promise.all(fieldTasks);
315
- const recordResult: Record<string, string[]> = {};
327
+ const recordResult: Record<string, any> = {};
328
+ const recordMeta: Record<string, any> = {};
316
329
 
317
- fieldResults.forEach(({ key, images }) => {
330
+ fieldResults.forEach(({ key, images, meta }) => {
318
331
  recordResult[key] = images;
332
+ if (meta) {
333
+ recordMeta[`${key}_meta`] = meta;
334
+ }
319
335
  });
320
336
 
321
337
  const result = recordResult;
@@ -323,7 +339,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
323
339
  if (!isError) {
324
340
  this.totalCalls++;
325
341
  this.totalDuration += (+new Date() - start) / 1000;
326
- jobs.set(jobId, { status: 'completed', result });
342
+ jobs.set(jobId, { status: 'completed', result, recordMeta });
327
343
  return { ok: true }
328
344
  } else {
329
345
  return { ok: false, error: 'Error during image generation' };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/bulk-ai-flow",
3
- "version": "1.20.0",
3
+ "version": "1.21.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },