UNPKG

lorehub

Version:

Capture and surface the collective wisdom of your codebase

77 lines 2.51 kB
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs'; import { dirname, join } from 'path'; import { homedir } from 'os'; import { z } from 'zod'; // Configuration schema export const ConfigSchema = z.object({ embeddingModel: z.string().default('all-mpnet-base-v2'), embeddingDimensions: z.number().default(768), // Add more config options as needed defaultConfidence: z.number().min(0).max(100).default(80), semanticSearchThreshold: z.number().min(0).max(10).default(2.0), // L2 distance threshold searchMode: z.enum(['literal', 'semantic', 'hybrid']).default('literal'), defaultListLimit: z.number().min(1).default(50), }); export class ConfigManager { static instance; configPath; config; constructor() { // Store config in ~/.lorehub/config.json const lorehubDir = join(homedir(), '.lorehub'); this.configPath = join(lorehubDir, 'config.json'); // Ensure directory exists if (!existsSync(lorehubDir)) { mkdirSync(lorehubDir, { recursive: true }); } this.config = this.loadConfig(); } static getInstance() { if (!ConfigManager.instance) { ConfigManager.instance = new ConfigManager(); } return ConfigManager.instance; } loadConfig() { try { if (existsSync(this.configPath)) { const rawConfig = JSON.parse(readFileSync(this.configPath, 'utf-8')); return ConfigSchema.parse(rawConfig); } } catch (error) { console.warn('Failed to load config, using defaults:', error); } // Create default config const defaultConfig = ConfigSchema.parse({}); this.saveConfig(defaultConfig); return defaultConfig; } saveConfig(config) { try { writeFileSync(this.configPath, JSON.stringify(config, null, 2)); } catch (error) { console.error('Failed to save config:', error); } } get(key) { return this.config[key]; } set(key, value) { this.config[key] = value; this.saveConfig(this.config); } getAll() { return { ...this.config }; } update(updates) { this.config = { ...this.config, ...updates }; this.saveConfig(this.config); } reset() { this.config = ConfigSchema.parse({}); this.saveConfig(this.config); } } //# sourceMappingURL=config.js.map