UNPKG

maia-cli

Version:

Command-line interface for MAIA (Modern AI Assistant)

146 lines (131 loc) • 4.98 kB
/** * MAIA Init Command - Initialize MAIA in current directory */ import { Command } from 'commander'; import inquirer from 'inquirer'; import chalk from 'chalk'; import ora from 'ora'; import { ConfigManager, getBuiltinTools } from 'maia-core'; import { v4 as uuidv4 } from 'uuid'; import { existsSync } from 'fs'; export const initCommand = new Command('init') .description('Initialize MAIA in current directory') .option('-f, --force', 'overwrite existing configuration') .option('--ai-provider <provider>', 'AI provider (claude, openai)', 'claude') .action(async (options) => { console.log(chalk.cyan('šŸš€ Initializing MAIA...\n')); try { const configManager = new ConfigManager(); // Check if config already exists if (configManager.exists() && !options.force) { console.log(chalk.yellow('āš ļø MAIA is already initialized in this directory.')); console.log(chalk.gray('Use --force to overwrite existing configuration.')); return; } // Gather configuration through interactive prompts const answers = await inquirer.prompt([ { type: 'input', name: 'userName', message: 'What should I call you?', default: 'User', }, { type: 'list', name: 'aiProvider', message: 'Which AI provider would you like to use?', choices: [ { name: 'Claude (Anthropic) - Recommended', value: 'claude' }, { name: 'OpenAI GPT', value: 'openai' }, ], default: options.aiProvider || 'claude', }, { type: 'password', name: 'apiKey', message: (answers) => `Enter your ${answers.aiProvider === 'claude' ? 'Claude' : 'OpenAI'} API key:`, validate: (input) => { if (!input || input.trim().length === 0) { return 'API key is required'; } return true; }, }, { type: 'confirm', name: 'enableVoice', message: 'Enable voice features? (requires additional API keys)', default: false, }, { type: 'checkbox', name: 'enabledTools', message: 'Select built-in tools to enable:', choices: [ { name: 'Calculator - Basic math operations', value: 'calculator', checked: true }, { name: 'File System - File operations', value: 'filesystem', checked: true }, { name: 'Web Search - Search the internet', value: 'web-search', checked: true }, ], }, ]); // Create configuration const spinner = ora('Creating configuration...').start(); const config = { ai: { provider: answers.aiProvider, [answers.aiProvider]: { apiKey: answers.apiKey, model: answers.aiProvider === 'claude' ? 'claude-3-5-sonnet-20241022' : 'gpt-4', maxTokens: 4096, }, }, voice: { enabled: answers.enableVoice, }, tools: { enabled: answers.enabledTools, config: {}, }, user: { id: uuidv4(), name: answers.userName, preferences: {}, }, }; // Save configuration configManager.save(config); spinner.succeed('Configuration created'); // Validate configuration const validation = configManager.validate(); if (!validation.valid) { console.log(chalk.red('āŒ Configuration validation failed:')); validation.errors.forEach(error => { console.log(chalk.red(` • ${error}`)); }); return; } console.log(chalk.green('\nāœ… MAIA initialized successfully!')); console.log(chalk.gray(`Configuration saved to: ${configManager.getConfigPath()}`)); // Show next steps console.log(chalk.yellow('\nšŸ“‹ Next steps:')); console.log(' maia chat Start chatting with your assistant'); console.log(' maia tools list View available tools'); console.log(' maia config show View your configuration'); console.log(' maia status Check system status'); // Show enabled tools if (answers.enabledTools.length > 0) { console.log(chalk.cyan(`\nšŸ”§ Enabled tools: ${answers.enabledTools.join(', ')}`)); } // Voice setup reminder if (answers.enableVoice) { console.log(chalk.yellow('\nšŸŽ¤ Voice features enabled but not configured.')); console.log(chalk.gray('Run "maia config set voice.tts.apiKey YOUR_KEY" to set up text-to-speech')); console.log(chalk.gray('Run "maia config set voice.stt.apiKey YOUR_KEY" to set up speech-to-text')); } } catch (error) { console.error(chalk.red('āŒ Initialization failed:'), error.message); process.exit(1); } });