UNPKG

snes-disassembler

Version:

A Super Nintendo (SNES) ROM disassembler for 65816 assembly

322 lines 11.6 kB
"use strict"; /** * AI Configuration Management * * Centralized configuration for all GenAI features in the SNES disassembler. * All AI features are optional and can be disabled for users who prefer * traditional analysis methods. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.AIConfigManager = exports.DEFAULT_AI_CONFIG = void 0; /** * Default AI configuration - all features disabled by default * Users must explicitly enable AI features they want to use */ exports.DEFAULT_AI_CONFIG = { enabled: false, // AI features are opt-in graphicsClassification: { modelPath: 'Xenova/vit-base-patch16-224', enabled: false, revision: 'main', parameters: { task: 'image-classification', quantized: true // Use smaller quantized models by default } }, textClassification: { modelPath: 'Xenova/distilbert-base-uncased-finetuned-sst-2-english', enabled: false, revision: 'main', parameters: { task: 'text-classification', quantized: true } }, audioClassification: { modelPath: 'Xenova/wav2vec2-base', enabled: false, revision: 'main', parameters: { task: 'audio-classification', quantized: true } }, namingSuggestions: { enabled: false, useContextualNames: true, useSNESConventions: true, customPatterns: [ 'sprite_{{type}}_{{index}}', 'bg_{{layer}}_{{index}}', 'sfx_{{type}}_{{index}}', '{{game}}_{{asset_type}}_{{index}}' ] }, documentationGeneration: { enabled: false, generateComments: true, generateDocs: true, style: 'technical', includeConfidence: false }, performance: { maxMemoryMB: 512, enableCaching: true, maxConcurrentJobs: 2, timeoutSeconds: 30 }, fallback: { useHeuristics: true, showWarnings: true, cacheResults: true } }; /** * AI Configuration Manager * Handles loading, saving, and validating AI configuration */ class AIConfigManager { constructor(configPath = './ai-config.json') { this.configPath = configPath; this.config = { ...exports.DEFAULT_AI_CONFIG }; } /** * Load configuration from file or use defaults */ async loadConfig() { try { const fs = await Promise.resolve().then(() => __importStar(require('fs/promises'))); const configData = await fs.readFile(this.configPath, 'utf-8'); const userConfig = JSON.parse(configData); // Merge with defaults, allowing partial configuration this.config = this.mergeWithDefaults(userConfig); console.log('✅ AI configuration loaded successfully'); if (!this.config.enabled) { console.log('ℹ️ AI features are disabled. Enable them in ai-config.json'); } return this.config; } catch (error) { console.log('ℹ️ No AI configuration found, using defaults (AI disabled)'); return this.config; } } /** * Save current configuration to file */ async saveConfig() { try { const fs = await Promise.resolve().then(() => __importStar(require('fs/promises'))); await fs.writeFile(this.configPath, JSON.stringify(this.config, null, 2), 'utf-8'); console.log('✅ AI configuration saved'); } catch (error) { console.error('❌ Failed to save AI configuration:', error); } } /** * Get current configuration */ getConfig() { return { ...this.config }; } /** * Update configuration */ updateConfig(updates) { this.config = { ...this.config, ...updates }; } /** * Check if AI features are enabled globally */ isAIEnabled() { return this.config.enabled; } /** * Check if a specific AI feature is enabled */ isFeatureEnabled(feature) { if (!this.config.enabled) return false; const featureConfig = this.config[feature]; if (typeof featureConfig === 'object' && 'enabled' in featureConfig) { return featureConfig.enabled; } return false; } /** * Get model configuration for a specific feature */ getModelConfig(feature) { if (!this.isFeatureEnabled(feature)) return null; return this.config[feature]; } /** * Create a sample configuration file with all options documented */ async createSampleConfig() { const sampleConfig = { ...exports.DEFAULT_AI_CONFIG, enabled: true, // Enable AI in sample // Enable some features for demonstration graphicsClassification: { ...exports.DEFAULT_AI_CONFIG.graphicsClassification, enabled: true }, namingSuggestions: { ...exports.DEFAULT_AI_CONFIG.namingSuggestions, enabled: true } }; const configWithComments = { '_comment': 'SNES Disassembler AI Configuration', '_description': 'Enable AI-powered analysis features. All features are optional.', '_warning': 'AI features require internet connection and additional resources', ...sampleConfig }; try { const fs = await Promise.resolve().then(() => __importStar(require('fs/promises'))); await fs.writeFile('./ai-config.sample.json', JSON.stringify(configWithComments, null, 2), 'utf-8'); console.log('✅ Sample AI configuration created: ai-config.sample.json'); } catch (error) { console.error('❌ Failed to create sample configuration:', error); } } mergeWithDefaults(userConfig) { // Deep merge user config with defaults const merged = { ...exports.DEFAULT_AI_CONFIG }; // Safely merge each section if (userConfig.enabled !== undefined) { merged.enabled = userConfig.enabled; } // Merge model configurations const modelKeys = ['graphicsClassification', 'textClassification', 'audioClassification']; modelKeys.forEach(key => { if (userConfig[key]) { const defaultValue = merged[key]; merged[key] = { ...defaultValue, ...userConfig[key] }; } }); // Merge feature configurations const featureKeys = ['namingSuggestions', 'documentationGeneration', 'performance', 'fallback']; featureKeys.forEach(key => { if (userConfig[key]) { const defaultValue = merged[key]; merged[key] = { ...defaultValue, ...userConfig[key] }; } }); return merged; } } exports.AIConfigManager = AIConfigManager; /** * Environment detection for AI features */ class AIEnvironmentChecker { static async checkCompatibility() { const issues = []; const recommendations = []; // Check Node.js version const nodeVersion = process.version; const majorVersion = parseInt(nodeVersion.slice(1).split('.')[0]); if (majorVersion < 16) { issues.push(`Node.js ${nodeVersion} detected. AI features require Node.js 16+`); recommendations.push('Upgrade to Node.js 16 or higher'); } // Check available memory const totalMemory = process.memoryUsage().heapTotal / 1024 / 1024; if (totalMemory < 256) { issues.push('Low memory detected. AI models may require more RAM'); recommendations.push('Ensure at least 512MB RAM available for AI features'); } // Check internet connectivity (for model downloads) try { const https = await Promise.resolve().then(() => __importStar(require('https'))); await new Promise((resolve, reject) => { const req = https.request('https://huggingface.co', { method: 'HEAD', timeout: 5000 }, resolve); req.on('error', reject); req.on('timeout', () => reject(new Error('Timeout'))); req.end(); }); } catch (error) { issues.push('Cannot reach HuggingFace servers. AI models may not download'); recommendations.push('Check internet connection or use offline models'); } // Check for required packages try { require.resolve('@huggingface/transformers'); } catch (error) { issues.push('HuggingFace Transformers not installed'); recommendations.push('Run: npm install @huggingface/transformers'); } const compatible = issues.length === 0; return { compatible, issues, recommendations }; } static async printCompatibilityReport() { console.log('🔍 Checking AI feature compatibility...\n'); const report = await this.checkCompatibility(); if (report.compatible) { console.log('✅ System is compatible with AI features'); } else { console.log('⚠️ Compatibility issues found:'); report.issues.forEach(issue => console.log(` • ${issue}`)); if (report.recommendations.length > 0) { console.log('\n💡 Recommendations:'); report.recommendations.forEach(rec => console.log(` • ${rec}`)); } } console.log('\n📝 To enable AI features:'); console.log(' 1. Copy ai-config.sample.json to ai-config.json'); console.log(' 2. Set "enabled": true in the configuration'); console.log(' 3. Enable specific features you want to use'); } } //# sourceMappingURL=ai-config.js.map