import { sanitizeText } from "../../shared/index.js";
export function formatSafeTranscript(message, options = {}) {
    const includeToolContent = options.includeToolContent ?? true;
    const maxChars = Math.max(0, options.maxChars ?? 4000);
    const chunks = [];
    let reasoningPartsOmitted = 0;
    let toolPartsIncluded = 0;
    for (const part of message?.parts ?? []) {
        if (isReasoningPart(part)) {
            reasoningPartsOmitted += 1;
            continue;
        }
        if (part.type === "text" && typeof part.text === "string") {
            chunks.push(part.text);
            continue;
        }
        if (!includeToolContent)
            continue;
        const toolText = toolPartText(part);
        if (toolText) {
            chunks.push(toolText);
            toolPartsIncluded += 1;
        }
    }
    const text = sanitizeText(chunks.join("\n\n")).trim().slice(0, maxChars);
    return {
        text,
        reasoning_parts_omitted: reasoningPartsOmitted,
        tool_parts_included: toolPartsIncluded,
        redaction_count: countRedactions(text),
    };
}
export function countRedactions(input) {
    return (input.match(/\[REDACTED(?:_[A-Z]+)?\]/g) ?? []).length;
}
function isReasoningPart(part) {
    const type = typeof part.type === "string" ? part.type.toLowerCase() : "";
    if (type.includes("reasoning"))
        return true;
    if ("reasoning" in part || "reasoningEncryptedContent" in part || "reasoning_encrypted_content" in part)
        return true;
    return false;
}
function toolPartText(part) {
    if (part.type === "tool" && typeof part.content === "string")
        return part.content;
    if (part.type !== "tool_result")
        return "";
    if (typeof part.content === "string")
        return part.content;
    if (!Array.isArray(part.content))
        return "";
    const chunks = [];
    for (const block of part.content) {
        if (block && typeof block === "object" && "text" in block && typeof block.text === "string") {
            chunks.push(block.text);
        }
    }
    return chunks.join("\n\n");
}
//# sourceMappingURL=index.js.map