const TRUNCATED_SUFFIX = "... [truncated]";
function truncateToBytes(str, maxBytes, suffix = TRUNCATED_SUFFIX) {
    const strBytes = Buffer.byteLength(str);
    if (strBytes <= maxBytes) {
        return str;
    }
    return Buffer.from(str).subarray(0, maxBytes).toString("utf8") + suffix;
}
export function stripLengthyContent(value, maxBytes = 1024 * 5) {
    if (maxBytes <= 0) {
        return value;
    }
    if (value === null || value === undefined) {
        return value;
    }
    if (Array.isArray(value)) {
        return value.map((item) => stripLengthyContent(item, maxBytes));
    }
    if (typeof value === "object") {
        const result = {};
        for (const [key, val] of Object.entries(value)) {
            result[key] = stripLengthyContent(val, maxBytes);
        }
        return result;
    }
    if (typeof value === "string") {
        return truncateToBytes(value, maxBytes);
    }
    return value;
}
//# sourceMappingURL=strip-content.js.map