Add AI Assistant API ChatProcessor plugin
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3585075. --> Reported by: [ahmad khader](https://www.drupal.org/user/3727855) Related to !1496 >>> <p>[Tracker]<br> <strong>Update Summary: </strong>[One-line status update for stakeholders]<br> <strong>Short Description: </strong>[One-line issue summary for stakeholders]<br> <strong>Check-in Date: </strong>MM/DD/YYYY<br> <em>Metadata is used by the <a href="https://www.drupalstarforge.ai/" title="AI Tracker">AI Tracker.</a> Docs and additional fields <a href="https://www.drupalstarforge.ai/ai-dashboard/docs" title="AI Issue Tracker Documentation">here</a>.</em><br> [/Tracker]</p> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <h4 id="summary-steps-reproduce">Steps to reproduce (required for bugs, but not feature requests)</h4> <p>Please provide information like AI modules enabled, which AI provider, browser, etc.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Create an <code>AiAssistantApiProcessor</code> ChatProcessor plugin that wraps the existing AI Assistant API, allowing AI Assistants to be used as chat processors through the new ChatProcessor plugin system (added in <a href="https://www.drupal.org/project/ai/issues/3492940">#3492940</a>).</p> <p>The ChatProcessor plugin system provides a unified interface for chat processing, but the existing AI Assistant API (which powers most current chatbot use cases) is not yet available as a ChatProcessor plugin. Site builders who want to use their configured AI Assistants through the new plugin system have no way to do so.</p> <p>This was originally developed as part of #3492940 but deferred to 1.5.x per <a href="https://www.drupal.org/project/ai/issues/3492940#comment-15738317">comment #47</a> since it requires update hooks and depends on the chatbot integration ticket.</p> <h3>Proposed resolution</h3> <p>As a rule of thumb, we should make sure the terminology follows <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/ai_initiative/-/work_items/3560667" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/ai_initiative/-/work_items/3560667</a></span></p> <h4>1. AiAssistantApiProcessor plugin</h4> <p>Create <code>modules/ai_chatbot/src/Plugin/ChatProcessor/AiAssistantApiProcessor.php</code> &mdash; a ChatProcessor plugin that delegates to the AI Assistant API runner:</p> <ul> <li>Extends <code>ChatProcessorBase</code>, implements <code>ContainerFactoryPluginInterface</code>.</li> <li>Plugin ID: <code>ai_assistant_api_Processor</code>.</li> <li>Injects <code>AiAssistantApiRunner</code> and <code>EntityTypeManagerInterface</code>.</li> <li><strong>Configuration form</strong>: dropdown to select an AI Assistant entity, plus checkboxes for stream output and verbose mode.</li> <li><strong><code>doExecute()</code></strong>: loads the selected AI Assistant entity, configures the runner (streaming, verbose mode, thread ID), converts <code>ChatInput</code> to <code>UserMessage</code>, calls <code>$runner-&gt;process()</code>, returns the <code>ChatOutput</code>.</li> </ul> <h4>2. Documentation update</h4> <p>Update <code>docs/modules/ai_assistant_api/index.md</code> to document the ChatProcessor integration and how AI Assistants can now be used as chat processors.</p> <h4>3. Update hooks</h4> <p>May require update hooks if existing chatbot block configurations need to be migrated to use the new processor selection.</p> <h3>Existing code</h3> <p>The implementation was developed in the <code>3492940-add-chatconsumer</code> branch and reverted in commit <code>9859703c</code>. The code can be re-applied from that commit's diff.</p> <h3>Files involved</h3> <ul> <li><code>modules/ai_chatbot/src/Plugin/ChatProcessor/AiAssistantApiProcessor.php</code> (new)</li> <li><code>docs/modules/ai_assistant_api/index.md</code> (updated)</li> </ul> <h3>Related issues</h3> <ul> <li>Parent: <a href="https://www.drupal.org/project/ai/issues/3492940">#3492940: Add ChatProcessor</a></li> </ul> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <h3>Optional: Other details as applicable (e.g., User interface changes, API changes, Data model changes)</h3> <h3 id="summary-ai-usage">AI usage (if applicable)</h3> <p>[ ] AI Assisted Issue<br> This issue was generated with AI assistance, but was reviewed and refined by the creator.</p> <p>[ ] AI Assisted Code<br> This code was mainly generated by a human, with AI autocompleting or parts AI generated, but under full human supervision.</p> <p>[ ] AI Generated Code<br> This code was mainly generated by an AI with human guidance, and reviewed, tested, and refined by a human.</p> <p>[ ] Vibe Coded<br> This code was generated by an AI and has only been functionally tested.</p> > Related issue: [Issue #3585077](https://www.drupal.org/node/3585077) > Related issue: [Issue #3492940](https://www.drupal.org/node/3492940)
issue