capsule-ai-cli
Version:
The AI Model Orchestrator - Intelligent multi-model workflows with device-locked licensing
98 lines • 3.3 kB
JavaScript
import { LocalAnalyticsService } from './local/analytics-service.js';
import { LocalModelRouter } from './local/model-router.js';
import { LocalLicenseService } from './local/license-service.js';
import { LocalConfigService } from './local/config-service.js';
import { LocalFeatureFlags } from './local/feature-flags.js';
export class ServiceLocator {
static instance;
analyticsService;
modelRouter;
licenseService;
configService;
featureFlags;
collaborationService;
constructor() { }
static getInstance() {
if (!ServiceLocator.instance) {
ServiceLocator.instance = new ServiceLocator();
}
return ServiceLocator.instance;
}
async getAnalytics() {
if (!this.analyticsService) {
const hasCloudAccess = await this.hasCloudSubscription();
if (hasCloudAccess && this.isCloudEnabled('analytics')) {
this.analyticsService = new LocalAnalyticsService();
}
else {
this.analyticsService = new LocalAnalyticsService();
}
}
return this.analyticsService;
}
async getModelRouter() {
if (!this.modelRouter) {
const hasCloudAccess = await this.hasCloudSubscription();
if (hasCloudAccess && this.isCloudEnabled('hostedModels')) {
this.modelRouter = new LocalModelRouter();
}
else {
this.modelRouter = new LocalModelRouter();
}
}
return this.modelRouter;
}
getLicense() {
if (!this.licenseService) {
this.licenseService = new LocalLicenseService();
}
return this.licenseService;
}
getConfig() {
if (!this.configService) {
this.configService = new LocalConfigService();
}
return this.configService;
}
async getFeatureFlags() {
if (!this.featureFlags) {
const hasCloudAccess = await this.hasCloudSubscription();
if (hasCloudAccess) {
this.featureFlags = new LocalFeatureFlags();
}
else {
this.featureFlags = new LocalFeatureFlags();
}
}
return this.featureFlags;
}
async getCollaboration() {
const hasCloudAccess = await this.hasCloudSubscription();
if (!hasCloudAccess) {
return null;
}
if (!this.collaborationService) {
return null;
}
return this.collaborationService;
}
async hasCloudSubscription() {
const license = await this.getLicense().validate();
return license.valid && license.license?.tier === 'cloud';
}
isCloudEnabled(feature) {
const config = this.getConfig();
const cloudFeatures = config.get('cloudFeatures') || {};
return cloudFeatures[feature] === true;
}
reset() {
this.analyticsService = undefined;
this.modelRouter = undefined;
this.licenseService = undefined;
this.configService = undefined;
this.featureFlags = undefined;
this.collaborationService = undefined;
}
}
export const serviceLocator = ServiceLocator.getInstance();
//# sourceMappingURL=service-locator.js.map