export function truncateUtf8(value: string, maxBytes: number) { if (maxBytes <= 0) return ""; if (Buffer.byteLength(value) <= maxBytes) return value; const buffer = Buffer.from(value); let end = Math.min(maxBytes, buffer.length); while (end > 0 && (buffer[end] & 0xc0) === 0x80) end--; return buffer.subarray(0, end).toString(); }