[Research] AI Prompt Management @mentions type functionality
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3525122. --> Reported by: [scott_euser](https://www.drupal.org/user/3267594) >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>Follow-up from <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/ai/issues/3509235" title="Status: Closed (fixed)">#3509235: Add AI Prompt management functionality within AI core</a></span>. Would be great to have mentions working</p> <h4 id="summary-steps-reproduce">Steps to reproduce</h4> <p>Variables are validated but manually input at the moment:</p> <p><img src="https://www.drupal.org/files/issues/2025-05-18/2025-05-18_06-05.png" alt="Screenshot of manual input"></p> <p>And with tokens:</p> <p><img src="https://www.drupal.org/files/issues/2025-05-18/2025-05-18_06-07.png" alt="Screenshot with tokens"></p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>I have tried so many different tools, sadly feels like no community has rallied around a single one:</p> <ol> <li>Even tried including becoming a co-maintainer of <a href="https://www.drupal.org/project/ckeditor_mentions">CK Editor 5 Mentions</a> in Drupal; however, CKE is heavily tied to the text format and not the instance of the text area, so having the available prompt types differ per text area would ultimately result in a high number of text formats which means overriding a number of places in core to suppress that elsewhere + many contrib extend it. Essentially too risk IMO.</li> <li>Generic JS functionalities like Tribute.js but it seems its rare for this to have been successfully achieved as its very opinionated on how it should be built, and most tend towards mentioning users of course like <a href="https://css-tricks.com/so-you-want-to-build-an-mention-autocomplete-feature/">https://css-tricks.com/so-you-want-to-build-an-mention-autocomplete-feature/</a>. Many also only support a single tag type, but we have both variables and tokens. </li> <li>Tribute.js itself seems to not be actively maintained so too high risk.</li> </ol> <p>Most maintained seems to be <a href="https://github.com/signavio/react-mentions">https://github.com/signavio/react-mentions</a> which does allow multiple tag types. Given XB is using React, it seems fair to use a React component to extend the textarea in src/Form/AiPromptSubform.php and I believe this will even sync back to the textarea for us.</p> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <ol> <li>Decide which library to use (or roll own)</li> <li>Decide on triggers for look ahead. If we use '@' is there risk we conflict with other tools eventually? It will be hard to update later given module developers will do the find and replace themselves using their own logic. @ and ! are the variables used in <code>t()</code> so perhaps have some level of familiarity with Drupal developers as indicative of variables</li> <li>Implement</li> <li>Ensure backwards compatibility, e.g. Keeping same storage of variables/tokens to avoid breaking existing sites using this since the documentation advice is to manually replace as desired.</li> </ol> <h3 id="summary-ui-changes">User interface changes</h3> <p>Suggestions appear when adding variables to prompts</p> <h3 id="summary-api-changes">API changes</h3> <p>N/A</p> <h3 id="summary-data-model-changes">Data model changes</h3> <p>N/A</p>
issue