PostStreamingResponseEvent never gets triggered
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3526936. --> Reported by: [svendecabooter](https://www.drupal.org/user/35369) Related to !634 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>This problem came up when working on <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/ai/issues/3524435" title="Status: Closed (fixed)">#3524435: Add token usage to streamed chat</a></span>.</p> <p>The method<code> \Drupal\ai\OperationType\Chat\StreamedChatMessageIterator::triggerEvent()</code> never gets called within the AI module, so the event never gets triggered.</p> <p>Perhaps this could be added within each AI provider implementation, but it would be best if the base class could take of this.</p> <p>Feedback by Marcus Johansson on Slack regarding this:</p> <blockquote><p> hmm, that is a big bug - this is a little bit of added layers because we didn't set the architecture correct from the start. I will look into if we can run it via the base class when iteration is finished, otherwise we will have to add this task on the providers until 2.0.0 </p></blockquote> <h4 id="summary-steps-reproduce">Steps to reproduce</h4> <p>- Enable AI CKEditor integration module + AI Provider OpenAI<br> - Add AI button to CKEditor<br> - Enable "Fix spelling" for example<br> - Select a text in CKEditor that needs spelling fixes.<br> - The action gets performed, but the debugger never enters the method `\Drupal\ai\OperationType\Chat\StreamedChatMessageIterator::triggerEvent`</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Feedback by Marcus Johansson:</p> <blockquote><p>__destruct magic method would most likely work to trigger it</p></blockquote> > Related issue: [Issue #3524435](https://www.drupal.org/node/3524435) > Related issue: [Issue #3517618](https://www.drupal.org/node/3517618)
issue