AI Core: Add a global JSON decoder for both streaming and none streaming responses.
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3478167. -->
Reported by: [marcus_johansson](https://www.drupal.org/user/385947)
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>Currently both AI Automators, AI Agents and the AI Assistants API are taking responses that are either streamed or unstreamed and checking if they have JSON in them and if they do decodes them.</p>
<p>We should just have one global helper service for this, that any submodule can use.</p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Create a response-to-json interface<br>
Create a response-to-json service<br>
Write tests for the service<br>
Return the response when no JSON could be found<br>
Return array when it could be found<br>
Will not work with simple string JSON, but shouldn't, aka "a string"<br>
<del>Change so AI Assistants and AI Automators uses this</del></p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<h3 id="summary-ui-changes">User interface changes</h3>
<h3 id="summary-api-changes">API changes</h3>
<h3 id="summary-data-model-changes">Data model changes</h3>
issue