|
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 |
|
|
0 commit comments