Output streaming is handled inconsistently, fails to work in API AI-explorer
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3571925. --> Reported by: [fago](https://www.drupal.org/user/16747) Related to !1164 >>> <p>[Tracker]<br> <strong>Update Summary: Output streaming fails to work in API AI-explorer</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</h3> <p>I noticed output streaming is not working in API explorer in my setup with nginx. It's working when using the CKEditor integration to generate something.</p> <p>Turns out, we are not setting headers consistently and API explorer misses the X-Accel-Buffering: no header which nginx obeys. Let's fix this!</p> <h4 id="summary-steps-reproduce">Steps to reproduce (required for bugs, but not feature requests)</h4> <p>Nginx setup<br> Use mistral-provider and test streamed chat responses</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>We have got 4 cases with varying implementation:</p> <table> <tr> <th>Location</th> <th>X-Accel-Buffering: no</th> <th>Cache-Control</th> <th>Content-Type</th> <th>Clears<br> OB</th> </tr> <tr> <td>ai_ckeditor AiRequest.php:152</td> <td>&#9989;</td> <td>&#9989; no-cache,<br> must-revalidate</td> <td>text/event-stream</td> <td>&#10060;</td> </tr> <tr> <td>ai_chatbot DeepChatApi.php:315</td> <td>&#10060;</td> <td>&#9989; no-cache</td> <td>text/plain</td> <td>&#9989;<br> ob_end_flush</td> </tr> <tr> <td>ai_chatbot ChatForm.php:170</td> <td>&#10060;</td> <td>&#10060;</td> <td>&#10060;</td> <td>&#10060;</td> </tr> <tr> <td>ai_api_explorer ChatGenerator.php:408</td> <td>&#10060;</td> <td>&#10060;</td> <td>&#10060;</td> <td>&#10060;</td> </tr> <tr> <td><strong>Suggested</strong></td> <td>&#9989;</td> <td>no-cache</td> <td>text/plain</td> <td> ob_end_clean</td> </tr> </table> <p> Introduce a centralized AiStreamedResponse class (extending Symfony's StreamedResponse) in AI core that:</p> <p> - Sets required headers by default (X-Accel-Buffering: no, Cache-Control: no-cache, Content-Type)<br> - Use in all cases.</p> <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>[ x ] AI Assisted Issue<br> This issue was generated with AI assistance, but was reviewed and refined by the creator.</p>
issue