import { CONTEXT_COMPACTION_AUTO_QUERY, CONTEXT_COMPACTION_DEFAULT_COMPRESSION_RATIO, CONTEXT_COMPACTION_DEFAULT_PRESERVE_RECENT, } from "./context-compaction-types.js";
const CONTEXT_COMPACTION_QUERY_MAX_CHARS = 1000;
function normalizeCompressionRatio(value) {
    return typeof value === "number" && Number.isFinite(value) && value > 0 && value < 1
        ? value
        : CONTEXT_COMPACTION_DEFAULT_COMPRESSION_RATIO;
}
function normalizePreserveRecent(value) {
    return typeof value === "number" && Number.isFinite(value) ? Math.max(0, Math.floor(value)) : CONTEXT_COMPACTION_DEFAULT_PRESERVE_RECENT;
}
export function normalizeContextCompactionQuery(value, fallbackQuery) {
    const query = value?.trim() || fallbackQuery.trim() || CONTEXT_COMPACTION_AUTO_QUERY;
    return query.length > CONTEXT_COMPACTION_QUERY_MAX_CHARS
        ? `${query.slice(0, CONTEXT_COMPACTION_QUERY_MAX_CHARS)}\n[... ${query.length - CONTEXT_COMPACTION_QUERY_MAX_CHARS} more characters omitted from compaction query]`
        : query;
}
export function normalizeContextCompactionParameters(input = {}, fallbackQuery = CONTEXT_COMPACTION_AUTO_QUERY) {
    return {
        compression_ratio: normalizeCompressionRatio(input.compression_ratio),
        preserve_recent: normalizePreserveRecent(input.preserve_recent),
        query: normalizeContextCompactionQuery(input.query, fallbackQuery),
    };
}
export function getTranscriptCompactionParameters(transcript) {
    return normalizeContextCompactionParameters(transcript.parameters ?? transcript.settings, transcript.parameters?.query ?? transcript.settings.query ?? CONTEXT_COMPACTION_AUTO_QUERY);
}
//# sourceMappingURL=context-compaction-strategy.js.map