Skip to content

Commit c8ef1cc

Browse files
lsr911claude
andcommitted
fix(mistral): use truncateUtf16Safe for error text truncation
Replace naive .slice(0, maxChars) with truncateUtf16Safe() in truncateErrorText() to prevent surrogate pair splitting in Mistral provider error messages shown to users. Co-Authored-By: Claude <[email protected]>
1 parent 9566ade commit c8ef1cc

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

packages/ai/src/providers/mistral.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Mistral provider adapts Mistral streams and tool calls to the runtime.
22
import { HTTPClient, Mistral, type Fetcher } from "@mistralai/mistralai";
3+
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
34
import type {
45
ChatCompletionStreamRequest,
56
ChatCompletionStreamRequestMessage,
@@ -295,7 +296,7 @@ function truncateErrorText(text: string, maxChars: number): string {
295296
if (text.length <= maxChars) {
296297
return text;
297298
}
298-
return `${text.slice(0, maxChars)}... [truncated ${text.length - maxChars} chars]`;
299+
return `${truncateUtf16Safe(text, maxChars)}... [truncated ${text.length - maxChars} chars]`;
299300
}
300301

301302
function safeJsonStringify(value: unknown): string {

0 commit comments

Comments
 (0)