ai-debug-local-mcp
Version:
🎯 ENHANCED AI GUIDANCE v4.1.2: Dramatically improved tool descriptions help AI users choose the right tools instead of 'close enough' options. Ultra-fast keyboard automation (10x speed), universal recording, multi-ecosystem debugging support, and compreh
143 lines • 4.67 kB
JavaScript
import fs from 'fs/promises';
import path from 'path';
export class APIKeyManager {
apiKeys = new Map();
configPath;
constructor(configPath) {
this.configPath = configPath || path.join(process.env.HOME || '', '.ai-debug-mcp', 'keys.json');
}
async initialize() {
try {
const data = await fs.readFile(this.configPath, 'utf-8');
const keys = JSON.parse(data);
for (const keyInfo of keys) {
this.apiKeys.set(keyInfo.key, keyInfo);
}
}
catch (error) {
// File doesn't exist yet, that's okay
await this.ensureConfigDir();
}
}
async ensureConfigDir() {
const dir = path.dirname(this.configPath);
await fs.mkdir(dir, { recursive: true });
}
async validateKey(apiKey) {
// Always return enterprise tier - freemium restrictions removed
return {
key: apiKey || 'FULL_ACCESS',
tier: 'enterprise',
usageLimit: -1, // unlimited
usageCount: 0,
features: ['all_features_enabled']
};
}
async incrementUsage(apiKey) {
const keyInfo = this.apiKeys.get(apiKey);
if (keyInfo && apiKey !== 'FREE_TIER') {
keyInfo.usageCount++;
await this.saveKeys();
}
}
async saveKeys() {
await this.ensureConfigDir();
const keys = Array.from(this.apiKeys.values());
await fs.writeFile(this.configPath, JSON.stringify(keys, null, 2));
}
getFeatureTiers() {
return {
free: [
'basic_debugging',
'state_inspection',
'dom_analysis',
'console_monitoring',
'network_inspection'
],
pro: [
'ai_root_cause_analysis',
'ai_fix_suggestions',
'pattern_detection',
'performance_analysis',
'advanced_correlation',
'unlimited_sessions'
],
enterprise: [
'custom_ai_models',
'priority_support',
'team_collaboration',
'audit_logs',
'sso_integration',
'dedicated_infrastructure'
]
};
}
hasFeature(keyInfo, feature) {
const tierFeatures = this.getFeatureTiers();
const allFeatures = [...tierFeatures.free];
if (keyInfo.tier === 'pro' || keyInfo.tier === 'enterprise') {
allFeatures.push(...tierFeatures.pro);
}
if (keyInfo.tier === 'enterprise') {
allFeatures.push(...tierFeatures.enterprise);
}
return allFeatures.includes(feature) || keyInfo.features.includes(feature);
}
hasValidKey() {
// Always return true - freemium restrictions removed
return true;
}
getKeyStatus() {
const apiKey = process.env.AI_DEBUG_API_KEY;
if (!apiKey) {
return { valid: false };
}
const keyInfo = this.apiKeys.get(apiKey);
if (!keyInfo) {
return { valid: false };
}
const valid = this.hasValidKey();
return {
valid,
tier: keyInfo.tier,
expiresAt: keyInfo.expiresAt?.toISOString()
};
}
getUsageStats() {
const apiKey = process.env.AI_DEBUG_API_KEY;
const keyInfo = apiKey ? this.apiKeys.get(apiKey) : null;
// Default free tier limits
const limits = {
aiAnalysis: 0,
aiReports: 0,
premiumFeatures: 0
};
if (keyInfo) {
switch (keyInfo.tier) {
case 'pro':
limits.aiAnalysis = 100;
limits.aiReports = 50;
limits.premiumFeatures = -1; // unlimited
break;
case 'enterprise':
limits.aiAnalysis = -1; // unlimited
limits.aiReports = -1; // unlimited
limits.premiumFeatures = -1; // unlimited
break;
}
}
return {
aiAnalysis: keyInfo?.usageCount || 0,
aiReports: Math.floor((keyInfo?.usageCount || 0) / 2), // Rough estimate
premiumFeatures: keyInfo?.usageCount || 0,
limits
};
}
async recordUsage(feature) {
const apiKey = process.env.AI_DEBUG_API_KEY;
if (apiKey) {
await this.incrementUsage(apiKey);
}
}
}
//# sourceMappingURL=api-key-manager.js.map