@adminforth/bulk-ai-flow 1.11.0 → 1.12.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.
Files changed (3) hide show
  1. package/dist/index.js +47 -0
  2. package/index.ts +48 -0
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { AdminForthPlugin, Filters } from "adminforth";
11
+ import { suggestIfTypo } from "adminforth";
11
12
  import Handlebars from 'handlebars';
12
13
  import { RateLimiter } from "adminforth";
13
14
  import { randomUUID } from "crypto";
@@ -443,6 +444,52 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
443
444
  `);
444
445
  }
445
446
  }
447
+ if (this.options.fillFieldsFromImages || this.options.fillPlainFields || this.options.generateImages) {
448
+ let matches = [];
449
+ const regex = /{{(.*?)}}/g;
450
+ if (this.options.fillFieldsFromImages) {
451
+ for (const [key, value] of Object.entries((this.options.fillFieldsFromImages))) {
452
+ const template = value;
453
+ const templateMatches = template.match(regex);
454
+ if (templateMatches) {
455
+ matches.push(...templateMatches);
456
+ }
457
+ }
458
+ }
459
+ if (this.options.fillPlainFields) {
460
+ for (const [key, value] of Object.entries((this.options.fillPlainFields))) {
461
+ const template = value;
462
+ const templateMatches = template.match(regex);
463
+ if (templateMatches) {
464
+ matches.push(...templateMatches);
465
+ }
466
+ }
467
+ }
468
+ if (this.options.generateImages) {
469
+ for (const [key, value] of Object.entries((this.options.generateImages))) {
470
+ const template = value.prompt;
471
+ const templateMatches = template.match(regex);
472
+ if (templateMatches) {
473
+ matches.push(...templateMatches);
474
+ }
475
+ }
476
+ }
477
+ if (matches) {
478
+ matches.forEach((match) => {
479
+ const field = match.replace(/{{|}}/g, '').trim();
480
+ if (!resourceConfig.columns.find((column) => column.name === field)) {
481
+ const similar = suggestIfTypo(resourceConfig.columns.map((column) => column.name), field);
482
+ throw new Error(`Field "${field}" specified in generationPrompt not found in resource "${resourceConfig.label}". ${similar ? `Did you mean "${similar}"?` : ''}`);
483
+ }
484
+ else {
485
+ let column = resourceConfig.columns.find((column) => column.name === field);
486
+ if (column.backendOnly === true) {
487
+ throw new Error(`Field "${field}" specified in generationPrompt is marked as backendOnly in resource "${resourceConfig.label}". Please remove backendOnly or choose another field.`);
488
+ }
489
+ }
490
+ });
491
+ }
492
+ }
446
493
  }
447
494
  }
448
495
  instanceUniqueRepresentation(pluginOptions) {
package/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { AdminForthPlugin, Filters } from "adminforth";
2
2
  import type { IAdminForth, IHttpServer, AdminForthComponentDeclaration, AdminForthResource } from "adminforth";
3
+ import { suggestIfTypo } from "adminforth";
3
4
  import type { PluginOptions } from './types.js';
4
5
  import Handlebars from 'handlebars';
5
6
  import { RateLimiter } from "adminforth";
@@ -461,6 +462,53 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
461
462
  `);
462
463
  }
463
464
  }
465
+ if (this.options.fillFieldsFromImages || this.options.fillPlainFields || this.options.generateImages) {
466
+ let matches: string[] = [];
467
+ const regex = /{{(.*?)}}/g;
468
+
469
+ if (this.options.fillFieldsFromImages) {
470
+ for (const [key, value] of Object.entries((this.options.fillFieldsFromImages ))) {
471
+ const template = value;
472
+ const templateMatches = template.match(regex);
473
+ if (templateMatches) {
474
+ matches.push(...templateMatches);
475
+ }
476
+ }
477
+ }
478
+ if (this.options.fillPlainFields) {
479
+ for (const [key, value] of Object.entries((this.options.fillPlainFields))) {
480
+ const template = value;
481
+ const templateMatches = template.match(regex);
482
+ if (templateMatches) {
483
+ matches.push(...templateMatches);
484
+ }
485
+ }
486
+ }
487
+ if (this.options.generateImages) {
488
+ for (const [key, value] of Object.entries((this.options.generateImages ))) {
489
+ const template = value.prompt;
490
+ const templateMatches = template.match(regex);
491
+ if (templateMatches) {
492
+ matches.push(...templateMatches);
493
+ }
494
+ }
495
+ }
496
+
497
+ if (matches) {
498
+ matches.forEach((match) => {
499
+ const field = match.replace(/{{|}}/g, '').trim();
500
+ if (!resourceConfig.columns.find((column: any) => column.name === field)) {
501
+ const similar = suggestIfTypo(resourceConfig.columns.map((column: any) => column.name), field);
502
+ throw new Error(`Field "${field}" specified in generationPrompt not found in resource "${resourceConfig.label}". ${similar ? `Did you mean "${similar}"?` : ''}`);
503
+ } else {
504
+ let column = resourceConfig.columns.find((column: any) => column.name === field);
505
+ if (column.backendOnly === true) {
506
+ throw new Error(`Field "${field}" specified in generationPrompt is marked as backendOnly in resource "${resourceConfig.label}". Please remove backendOnly or choose another field.`);
507
+ }
508
+ }
509
+ });
510
+ }
511
+ }
464
512
  }
465
513
  }
466
514
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/bulk-ai-flow",
3
- "version": "1.11.0",
3
+ "version": "1.12.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },