Streamed response is not fully logged
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3535010. -->
Reported by: [a.dmitriiev](https://www.drupal.org/user/3235287)
Related to !731
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>When using the CKEditor module all the plugins work in Streamed mode. As a result logs do not have the output text and no usage can be tracked as well.</p>
<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>
<ol>
<li>Use OpenAI provider.</li>
<li>Enable AI logging module.</li>
<li>Enable AI CKEditor module.</li>
<li>Perform some operation with AI CKEditor assistant.</li>
<li>Check AI logs, no output text is logged. It is always empty json object.</li>
</ol>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Collect the message from chunks and add it to output of PostStreamingResponseEvent that is triggered from StreamedChatMessageIterator. This iterator has method <code>triggerEvent</code> that is not used anywhere at the moment. I suggest to pass message text, role and usage to that method and call it in the StreamResponse callback.</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<p>Review MR.</p>
<h3>Optional: Other details as applicable (e.g., User interface changes, API changes, Data model changes)</h3>
<p>Method triggerEvent from StreamedChatMessageIterator class will have 3 new optional parameters.</p>
> Related issue: [Issue #3481403](https://www.drupal.org/node/3481403)
issue