Add processor and field widget assist plugin system to AI Content Suggestions
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3528684. --> Reported by: [marcus_johansson](https://www.drupal.org/user/385947) Related to !665 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>Currently we have modules like AI Content Suggestions and AI Image Alt Text, that has only one purpose - on a widget, take some input, process via AI and output something. While this does show case what is possible with AI, it does not suite actual business needs. </p> <p>Alt text generation needs context from the article it is on, a Title suggesion might be based on an image in the article or some external source. In the end this is just field generation</p> <p>We need something that abstracts the processor and abstracts the field widget assist plugin system, so that any module can:</p> <ul> <li>Create a processor that can take custom input, processes it and output in a structure way that a field form widget requires.</li> <li>Create a extra assist widgets that can be attached to specific field widgets in a specific state.</li> </ul> <p>This will then open up for processors like ECA, AI Automators and AI Agents to be able to have custom workflows or agents to process the entity and fill out form fields on entities. And field modules like Address module can expose their own Extra assist widgets.</p> <p>Since everything will be configuration, this means that we can ship any business specific widget solution as recipes!</p> <p>A initial version was created here for AI Automators, but we should make it more generic: <a href="https://git.drupalcode.org/project/ai/-/tree/ai-automators-widget?ref_type=heads">https://git.drupalcode.org/project/ai/-/tree/ai-automators-widget?ref_type=heads</a></p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>These are just suggestions on how to solve it.</p> <p>In AI Content Suggestions create a processor plugin that:</p> <ul> <li>has an attribute that takes Title, Description and something like "Can give Suggestions"</li> <li>has an interface that is using ConfigurableInterface and ExecutableInterface</li> <li>has a method that can flag if the processor can handle a specific output/field widget assist plugin</li> <li>has a method that can pre-validate and send form validation errors</li> <li>has a method that can take the input - input can be a ContentEntityInterface or prompt for now? (TBD)</li> <li>has a method that can take the entity type and bundle before loading the config form on new processors or be set via form_state</li> <li>has a method that can get either the fieldconfigurationinterface and optional delta of the output field before the execute or some array/data structure representing it. Delta is being used when a button is attached to a multifield, for instance alt text generator where you only want to generate text for the delta.</li> </ul> <p>In AI Content Suggestions create a field widget assist plugin that:</p> <ul> <li>has an attribute that takes Title, Description, Field Type and Field Widget Types (array)</li> <li>has a method for getting field type and field widget types</li> <li>has a abstract base class with a helper method to call the processor of choice that takes form state and changes the values.</li> <li>this can be overriden for more complex returns that requires an AjaxResponse return type</li> <li>has a ajaxCallback method that runs when the button is triggered that triggers the helper method to process that returns the value</li> <li>Maybe the base class has a formAlter method to actually setup the button, since it might need some specific solutions on certain fields, so it can be overriden and even take form state, for things like knowing that an alt text is uploaded</li> </ul> <p>To setup:</p> <ul> <li>Alters the form display form of the details of the field widget so the processors that has flagged that they handle the field type becomes a choice and after you picked a processor it calls via ajax to get the subform of the processor.</li> <li>Stores these settings in third party settings (TBD) - we have to add the plugin deriver modules as dependencies then</li> <li>Multiple field widget assists items can be added to a specific field - think generate image and then write alt text</li> </ul> <p>To run:</p> <ul> <li>Alters the entity form for any content element and adds the form button.</li> <li>On click triggers the ajax callback that triggers the processor.</li> <li>Returns via form_state change or AjaxResponse</li> <li>(TBD) How to handle return type for suggestions</li> </ul>
issue