UNPKG

capsule-ai-cli

Version:

The AI Model Orchestrator - Intelligent multi-model workflows with device-locked licensing

103 lines 2.97 kB
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs'; import path from 'path'; import { homedir } from 'os'; export class LocalConfigService { configPath; config = {}; constructor() { const capsuleDir = path.join(homedir(), '.capsule'); if (!existsSync(capsuleDir)) { mkdirSync(capsuleDir, { recursive: true }); } this.configPath = path.join(capsuleDir, 'config.json'); this.loadConfig(); } loadConfig() { try { if (existsSync(this.configPath)) { const data = readFileSync(this.configPath, 'utf8'); this.config = JSON.parse(data); } else { this.config = this.getDefaultConfig(); this.saveConfig(); } } catch (error) { console.error('Failed to load config:', error); this.config = this.getDefaultConfig(); } } saveConfig() { try { writeFileSync(this.configPath, JSON.stringify(this.config, null, 2), 'utf8'); } catch (error) { console.error('Failed to save config:', error); } } getDefaultConfig() { return { version: '1.0.0', theme: 'dark', analytics: { enabled: true, shareAnonymous: false }, ui: { showCosts: true, animations: true, compactMode: false }, models: { default: 'gpt-4o', temperature: 0.7, maxTokens: 2048 }, cloudFeatures: { analytics: false, hostedModels: false, collaboration: false }, experimental: { modelFusion: false, parallelRequests: false } }; } get(key) { const keys = key.split('.'); let value = this.config; for (const k of keys) { if (value && typeof value === 'object' && k in value) { value = value[k]; } else { return undefined; } } return value; } async set(key, value) { const keys = key.split('.'); let current = this.config; for (let i = 0; i < keys.length - 1; i++) { const k = keys[i]; if (!(k in current) || typeof current[k] !== 'object') { current[k] = {}; } current = current[k]; } const lastKey = keys[keys.length - 1]; current[lastKey] = value; this.saveConfig(); } getAll() { return { ...this.config }; } async reset() { this.config = this.getDefaultConfig(); this.saveConfig(); } } //# sourceMappingURL=config-service.js.map