Files
openclaw/packages/normalization-core/src/text-decoding.ts
Peter Steinberger d185f9a0b4 fix(infra): preserve characters in truncated response snippets (#103136)
* fix(infra): preserve bounded response text characters

Co-authored-by: qingminlong <34085845+qingminglong@users.noreply.github.com>

* ci(plugin-sdk): refresh API baseline

---------

Co-authored-by: qingminlong <34085845+qingminglong@users.noreply.github.com>
2026-07-09 23:43:26 +01:00

13 lines
585 B
TypeScript

export type DecodeTextPrefixOptions = {
encoding?: string;
truncated?: boolean;
};
/** Decodes a byte prefix without inventing a replacement character for a cut trailing sequence. */
export function decodeTextPrefix(bytes: Uint8Array, options: DecodeTextPrefixOptions = {}): string {
const decoder = new TextDecoder(options.encoding);
// Streaming mode retains an incomplete tail; discarding this one-shot decoder
// drops only that cut sequence while complete bodies still flush normally.
return decoder.decode(bytes, options.truncated ? { stream: true } : undefined);
}