"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConversationMemory = void 0;
const OmniMemory_1 = require("./OmniMemory");
const SessionManager_1 = require("./SessionManager");
class ConversationMemory {
    memory;
    sessions;
    constructor(memory = new OmniMemory_1.OmniMemory(), sessions = new SessionManager_1.SessionManager()) {
        this.memory = memory;
        this.sessions = sessions;
    }
    async recoverContext(userId, query) {
        const session = this.sessions.getSession(userId);
        const recentHistory = session.history
            .slice(-8)
            .map((h) => `${h.role}: ${h.content}`)
            .join('\n');
        let memorySnippet = '';
        try {
            memorySnippet = await this.memory.search(query);
        }
        catch {
            memorySnippet = 'Busca de memória indisponível no momento.';
        }
        return {
            recentHistory,
            memorySnippet,
            autoRecovered: Boolean(recentHistory.trim() || memorySnippet.trim())
        };
    }
}
exports.ConversationMemory = ConversationMemory;
