UNPKG

capsule-ai-cli

Version:

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

85 lines 2.88 kB
import { serviceLocator } from '../service-locator.js'; export class LocalFeatureFlags { flags = {}; constructor() { this.loadFlags(); } async loadFlags() { const licenseService = serviceLocator.getLicense(); const { valid, license } = await licenseService.validate(); if (valid && license) { if (license.tier === 'pro' || license.tier === 'cloud') { this.flags.modelFusion = true; this.flags.smartRouter = true; this.flags.advancedTools = true; this.flags.localAnalytics = true; this.flags.parallelRequests = true; this.flags.contextSharding = true; } if (license.tier === 'cloud') { this.flags.cloudAnalytics = true; this.flags.hostedModels = true; this.flags.teamCollaboration = true; this.flags.apiAccess = true; } } else { this.flags.basicChat = true; this.flags.singleModel = true; this.flags.localHistory = true; } const config = serviceLocator.getConfig(); const experimental = config.get('experimental') || {}; for (const [flag, enabled] of Object.entries(experimental)) { if (enabled && await this.isFeatureAllowed(flag)) { this.flags[flag] = true; } } } isEnabled(feature) { return this.flags[feature] === true; } getAllFlags() { return { ...this.flags }; } async isFeatureAllowed(feature) { const proFeatures = [ 'modelFusion', 'smartRouter', 'advancedTools', 'parallelRequests', 'contextSharding' ]; const cloudFeatures = [ 'cloudAnalytics', 'hostedModels', 'teamCollaboration', 'apiAccess' ]; const license = serviceLocator.getLicense(); const validation = await license.validate(); if (!validation.valid) { return false; } const tier = validation.license?.tier || 'free'; if (cloudFeatures.includes(feature)) { return tier === 'cloud'; } if (proFeatures.includes(feature)) { return tier === 'pro' || tier === 'cloud'; } return true; } async setFlag(feature, enabled) { if (!await this.isFeatureAllowed(feature)) { return false; } this.flags[feature] = enabled; const config = serviceLocator.getConfig(); const experimental = config.get('experimental') || {}; experimental[feature] = enabled; await config.set('experimental', experimental); return true; } } //# sourceMappingURL=feature-flags.js.map