Use UTF-8 safe functions when summarizing request messages
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3580767. -->
Reported by: [breidert](https://www.drupal.org/user/135619)
Related to !1339
>>>
<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 using as <a href="https://www.drupal.org/project/logger_db">logger_db</a> and <a href="https://www.drupal.org/project/logger_db">logger</a> as backend for observability, saving fails because of wrongly encoded data is passed to the backend.</p>
<p>The promble comes from the method <a href="https://git.drupalcode.org/project/ai/-/blob/1.x/modules/ai_observability/src/AiObservabilityUtils.php?ref_type=heads#L71">summarizeAiPayloadData</a> which uses <code>substr</code> instead of <code>mb_substr </code>when truncating the payload for logging.</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>
<p>Install <a href="https://www.drupal.org/project/logger_db">logger_db</a> and <a href="https://www.drupal.org/project/logger_db">logger</a>. Perform an AI operation with long text. Observe the wrongly encoded truncated text which causes the logger to fail.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Replace string manipulation functions with UTF-8 safe alternatives.</p>
<h3 id="summary-ai-usage">AI usage (if applicable)</h3>
<p>[ ] AI Assisted Issue<br>
This issue was generated with AI assistance, but was reviewed and refined by the creator.</p>
<p>[ ] AI Assisted Code<br>
This code was mainly generated by a human, with AI autocompleting or parts AI generated, but under full human supervision.</p>
<p>[ ] AI Generated Code<br>
This code was mainly generated by an AI with human guidance, and reviewed, tested, and refined by a human.</p>
<p>[ ] Vibe Coded<br>
This code was generated by an AI and has only been functionally tested.</p>
> Related issue: [Issue #3566762](https://www.drupal.org/node/3566762)
issue