Skip to content

Commit 3230669

Browse files
committed
fix(inworld): use truncateUtf16Safe for error body and parse error truncation
Two .slice(0, N) truncation sites in the Inworld TTS extension may cut UTF-16 surrogate pairs in half when the error body or parse error message contains multi-byte characters such as emoji. Replace both with truncateUtf16Safe to keep the truncated output valid Unicode.
1 parent 3f2466c commit 3230669

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

extensions/inworld/tts.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { MAX_AUDIO_BYTES } from "openclaw/plugin-sdk/media-runtime";
33
import { readResponseWithLimit } from "openclaw/plugin-sdk/response-limit-runtime";
44
import type { SpeechVoiceOption } from "openclaw/plugin-sdk/speech-core";
55
import { fetchWithSsrFGuard, type SsrFPolicy } from "openclaw/plugin-sdk/ssrf-runtime";
6+
import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
67

78
const DEFAULT_INWORLD_BASE_URL = "https://api.inworld.ai";
89
export const DEFAULT_INWORLD_VOICE_ID = "Sarah";
@@ -57,7 +58,7 @@ async function readInworldErrorBodySnippet(response: Response): Promise<string>
5758

5859
const collapsed = buffer.toString("utf8").replace(/\s+/g, " ").trim();
5960
if (collapsed.length > INWORLD_ERROR_BODY_MAX_CHARS) {
60-
return `${collapsed.slice(0, INWORLD_ERROR_BODY_MAX_CHARS)}…`;
61+
return `${truncateUtf16Safe(collapsed, INWORLD_ERROR_BODY_MAX_CHARS)}…`;
6162
}
6263
return collapsed;
6364
}
@@ -176,7 +177,7 @@ export async function inworldTTS(params: {
176177
parsed = JSON.parse(trimmed) as typeof parsed;
177178
} catch {
178179
throw new Error(
179-
`Inworld TTS stream parse error: unexpected non-JSON line: ${trimmed.slice(0, 80)}`,
180+
`Inworld TTS stream parse error: unexpected non-JSON line: ${truncateUtf16Safe(trimmed, 80)}`,
180181
);
181182
}
182183

0 commit comments

Comments
 (0)