"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PromptConditioner = void 0;
class PromptConditioner {
    maxTokens;
    constructor(maxTokens = 50) {
        this.maxTokens = maxTokens;
    }
    conditionPrompt(basePrompt, patterns) {
        if (basePrompt.includes('[TASTE:')) {
            return basePrompt;
        }
        const tasteContext = this.buildTasteContext(patterns);
        if (!tasteContext) {
            return basePrompt;
        }
        return `${tasteContext}\n\n${basePrompt}`;
    }
    buildTasteContext(patterns) {
        const applicablePatterns = patterns.filter((p) => p.confidence.mean >= 0.5);
        if (applicablePatterns.length === 0) {
            return '';
        }
        const sorted = applicablePatterns.sort((a, b) => b.confidence.mean - a.confidence.mean);
        const seen = new Set();
        const entries = [];
        let tokenEstimate = 0;
        for (const pattern of sorted) {
            const entry = `${pattern.description.toLowerCase()}(${pattern.confidence.mean})`;
            const key = `${pattern.category}|${pattern.from}|${pattern.to}`;
            if (seen.has(key))
                continue;
            seen.add(key);
            const entryTokens = Math.ceil(entry.length / 3);
            if (tokenEstimate + entryTokens > this.maxTokens) {
                break;
            }
            entries.push(entry);
            tokenEstimate += entryTokens;
        }
        if (entries.length === 0) {
            return '';
        }
        return `[TASTE: ${entries.join(', ')}]`;
    }
    getBypassMessage() {
        return '[Use my taste: ON] [Skip for this request] [Pause for this session]';
    }
    isTasteApplicable(patterns) {
        return patterns.some((p) => p.confidence.mean >= 0.5);
    }
}
exports.PromptConditioner = PromptConditioner;
//# sourceMappingURL=prompt-conditioner.js.map