/**
 * 공용 부트스트랩 함수
 * HTTP 서버와 MCP 서버가 공통으로 사용하는 서비스 초기화 로직
 * @memento/core 내부: createMementoCore에서 사용
 */
import Database from 'better-sqlite3';
import { mementoConfig } from './shared/config/index.js';
import { HybridSearchEngine } from './domains/search/algorithms/hybrid-search-engine.js';
import { createSearchEmbeddingAndOptimizerServices } from './bootstrap/search-and-embedding.js';
import { MemoryEmbeddingService } from './domains/memory/services/memory-embedding-service.js';
import { ForgettingPolicyService } from './domains/forgetting/services/forgetting-policy-service.js';
import { getPerformanceMonitor } from './domains/monitoring/services/performance-monitor.js';
import { ErrorLoggingService } from './domains/monitoring/services/error-logging-service.js';
import { PerformanceAlertService } from './domains/monitoring/services/performance-alert-service.js';
import { createAnchorStack } from './bootstrap/anchor-stack.js';
import { createWriteCoalescingMetaAndScore } from './bootstrap/write-and-meta.js';
import { createMonitoringAndSchedulers } from './bootstrap/monitoring-schedulers.js';
import { createBatchTelemetryRelationAndSleep } from './bootstrap/batch-telemetry-relation.js';
import { createRuntimeDiagnosticsSampler } from './bootstrap/runtime-diagnostics-sampler.js';
import { startFailureAndReflexion } from './bootstrap/failure-reflexion.js';
import { getVectorSearchEngine } from './domains/search/algorithms/vector-search-engine.js';
import { SleepConsolidationService } from './domains/consolidation/services/sleep-consolidation-service.js';
import { WalCheckpointScheduler } from './infrastructure/database/wal-checkpoint-scheduler.js';
import { DatabaseLockMonitor } from './infrastructure/database/database-lock-monitor.js';
import { IntrospectionScanCache } from './domains/memory/services/introspection-scan-cache.js';
import { TelemetryService } from './domains/telemetry/services/telemetry-service.js';
import { RuntimeDiagnosticsLogger } from './domains/monitoring/services/runtime-diagnostics-logger.js';
export async function initializeServices(db) {
    try {
        const { searchEngine, embeddingService, hybridSearchEngine, forgettingPolicyService, databaseOptimizer, } = createSearchEmbeddingAndOptimizerServices(db);
        const errorLoggingService = new ErrorLoggingService();
        const performanceAlertService = new PerformanceAlertService('./logs');
        const { vectorSearchEngine, anchorManager } = await createAnchorStack(db, embeddingService, hybridSearchEngine, errorLoggingService);
        const { failureDetector, reflexionWorker } = await startFailureAndReflexion(db);
        const { performanceMonitor, runtimeDiagnosticsLogger, walCheckpointScheduler, databaseLockMonitor } = await createMonitoringAndSchedulers(db);
        const { writeCoalescingManager, consolidationScoreService, metaMemoryService } = createWriteCoalescingMetaAndScore(db);
        const { introspectionScanCache, batchScheduler, telemetryService, relationGraph, sleepConsolidationService } = await createBatchTelemetryRelationAndSleep(db, embeddingService, runtimeDiagnosticsLogger, reflexionWorker);
        const { runtimeDiagnosticsSamplerCleanup } = createRuntimeDiagnosticsSampler({
            mementoConfig,
            batchScheduler,
            runtimeDiagnosticsLogger
        });
        return {
            searchEngine,
            hybridSearchEngine,
            vectorSearchEngine,
            embeddingService,
            forgettingPolicyService,
            performanceMonitor,
            databaseOptimizer,
            errorLoggingService,
            performanceAlertService,
            consolidationScoreService,
            writeCoalescingManager,
            metaMemoryService,
            anchorManager,
            relationGraph,
            failureDetector,
            reflexionWorker,
            walCheckpointScheduler,
            databaseLockMonitor,
            batchScheduler,
            introspectionScanCache,
            sleepConsolidationService,
            telemetryService,
            runtimeDiagnosticsLogger,
            runtimeDiagnosticsSamplerCleanup
        };
    }
    catch (error) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        throw new Error(`서비스 초기화 실패: ${errorMessage}`);
    }
}
//# sourceMappingURL=bootstrap.js.map