Dispatch JS event when DeepChat completes agent calls
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3577970. -->
Reported by: [bbruno](https://www.drupal.org/user/3691195)
Related to !1299
>>>
<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>
<p>When the DeepChat chatbot runs in verbose mode and needs to loop through Agents, the current implementation repeatedly updates the initial “Contacting Agents...” message with the latest response.</p>
<p>Because the same message is updated instead of emitting a new message, the native onMessage event provided by DeepChat is not triggered when Agent calls finish.</p>
<p>As a result, it is currently not possible to reliably detect when Agent execution has completed using the standard DeepChat event system.</p>
<p>It would be beneficial to introduce a custom event that fires when the Agent calling process has finished. This would allow external scripts or integrations to listen for a clear signal that Agent execution has completed.</p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<p>1. Create an assistant which has the ability of using an Agent<br>
2. Using JS (can also be done in the browser), attach an event listener to the `deep-chat` element, listening for `new-message` events.<br>
3. Send a message which should trigger an Agent call<br>
4. See that the `new-message` event only fires when the initial loading message comes on screen, and there is no way to detect when agent call is done.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Add to the end of the `deepchat-init.js` logic that deals with the final updating of the message from an Agent call, the firing of a distinct event that can be used to properly identify when this action is done</p>
<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