/**
 * AI Service Modules
 * Provides a modular architecture for AI-powered operations
 */
import { RecursiveCharacterTextSplitter } from '@langchain/textsplitters';
import { BufferMemory } from '@langchain/classic/memory';
import { OpenAIEmbeddings, ChatOpenAI } from '@langchain/openai';
import { getLogger } from '../../../core/logger.js';
const logger = getLogger('ai-modules');
/**
 * Handles document chunking and preprocessing
 */
export class DocumentProcessor {
    constructor(chunkSize = 2000, chunkOverlap = 200) {
        this.splitter = new RecursiveCharacterTextSplitter({
            chunkSize,
            chunkOverlap,
            separators: ['\n\n\n', '\n\n', '\n', '. ', ' ', '']
        });
    }
    async chunkDocument(content, metadata = {}) {
        return await this.splitter.createDocuments([content], [metadata]);
    }
    async processDocuments(contents, metadatas) {
        return await this.splitter.createDocuments(contents, metadatas);
    }
}
/**
 * Manages conversation memory and context state
 */
export class ConversationManager {
    constructor() {
        this.memories = new Map();
    }
    async getMemory(sessionId) {
        if (!this.memories.has(sessionId)) {
            this.memories.set(sessionId, new BufferMemory({
                memoryKey: 'chat_history',
                returnMessages: true
            }));
        }
        return this.memories.get(sessionId);
    }
    async clearMemory(sessionId) {
        this.memories.delete(sessionId);
    }
}
/**
 * Handles embedding generation and similarity calculations
 */
export class EmbeddingService {
    constructor(apiKey) {
        this.model = new OpenAIEmbeddings({
            openAIApiKey: apiKey || process.env.OPENAI_API_KEY,
            modelName: 'text-embedding-3-small'
        });
    }
    async generateEmbeddings(text) {
        return await this.model.embedQuery(text);
    }
    async generateBatchEmbeddings(texts) {
        return await this.model.embedDocuments(texts);
    }
}
/**
 * Centralized manager for different AI model providers and configurations
 */
export class ModelManager {
    constructor() {
        this.models = new Map();
    }
    getModel(name, temperature = 0.7) {
        const key = `${name}-${temperature}`;
        if (!this.models.has(key)) {
            this.models.set(key, new ChatOpenAI({
                modelName: name,
                temperature,
                openAIApiKey: process.env.OPENAI_API_KEY
            }));
        }
        return this.models.get(key);
    }
}
//# sourceMappingURL=index.js.map