UNPKG

capsule-ai-cli

Version:

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

135 lines β€’ 6.53 kB
import chalk from 'chalk'; export var Mode; (function (Mode) { Mode["CHAT"] = "chat"; Mode["AGENT"] = "agent"; Mode["PLAN"] = "plan"; Mode["FUSION"] = "fusion"; })(Mode || (Mode = {})); const modeColors = { [Mode.CHAT]: chalk.cyan, [Mode.AGENT]: chalk.yellow, [Mode.PLAN]: chalk.blue, [Mode.FUSION]: chalk.magenta }; const modeIcons = { [Mode.CHAT]: 'πŸ’¬', [Mode.AGENT]: 'πŸ€–', [Mode.PLAN]: 'πŸ“‹', [Mode.FUSION]: '⚑' }; export async function startInteractiveMode(options) { let currentMode = Mode.CHAT; let inputBuffer = ''; console.log(chalk.yellow('\n⚑ Welcome to Capsule CLI')); console.log(chalk.dim(`Model: ${chalk.yellow(options.model || 'gpt-3.5-turbo')} | Provider: ${chalk.yellow(options.provider || 'openai')}`)); console.log(); if (process.stdin.isTTY) { process.stdin.setRawMode(true); } process.stdin.resume(); process.stdin.setEncoding('utf8'); showPrompt(); process.stdin.on('data', async (key) => { if (key === '\u0003') { console.log(chalk.yellow('\n\nπŸ‘‹ Thanks for using Capsule CLI!')); process.exit(); } if (key === '\t') { const modes = Object.values(Mode); const currentIndex = modes.indexOf(currentMode); currentMode = modes[(currentIndex + 1) % modes.length]; process.stdout.write('\r\x1b[K'); showStatusBar(); showPrompt(); process.stdout.write(inputBuffer); return; } if (key === '\r' || key === '\n') { if (inputBuffer.trim()) { console.log(); await processInput(inputBuffer.trim(), currentMode, options); inputBuffer = ''; } showPrompt(); return; } if (key === '\x7f' || key === '\b') { if (inputBuffer.length > 0) { inputBuffer = inputBuffer.slice(0, -1); process.stdout.write('\b \b'); } return; } if (key >= ' ' && key <= '~') { inputBuffer += key; process.stdout.write(key); } }); function showStatusBar() { console.log(chalk.dim(`\nβ–Άβ–Ά ${currentMode} mode on `) + chalk.gray('(tab to cycle)')); } function showPrompt() { process.stdout.write(modeColors[currentMode](`${modeIcons[currentMode]} ${currentMode}: `)); } async function processInput(input, mode, options) { if (input.startsWith('/')) { const command = input.substring(1).toLowerCase(); if (command === 'exit') { console.log(chalk.yellow('\nπŸ‘‹ Thanks for using Capsule CLI!')); process.exit(); } if (command === 'help') { console.log(chalk.cyan('\nπŸ“š Commands:')); console.log(chalk.dim(' /help - Show this help')); console.log(chalk.dim(' /exit - Exit Capsule CLI')); console.log(chalk.dim(' /clear - Clear screen')); console.log(); console.log(chalk.cyan('Keyboard:')); console.log(chalk.dim(' Tab - Switch modes')); console.log(chalk.dim(' Ctrl+C - Exit')); console.log(); return; } if (command === 'clear') { console.clear(); console.log(chalk.yellow('\n⚑ Capsule CLI')); showStatusBar(); return; } } console.log(chalk.gray('\nβ”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”')); console.log(chalk.gray('β”‚') + ' ' + modeColors[mode](`${modeIcons[mode]} USER (${mode.toUpperCase()})`) + chalk.gray(' '.padEnd(55 - mode.length - 7)) + chalk.gray('β”‚')); console.log(chalk.gray('β”‚') + ' ' + chalk.white(input.length > 55 ? input.substring(0, 52) + '...' : input.padEnd(55)) + ' ' + chalk.gray('β”‚')); console.log(chalk.gray('β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜')); console.log(chalk.dim('\n⚑ Processing...')); await new Promise(resolve => setTimeout(resolve, 1000)); console.log(chalk.gray('\nβ”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”')); console.log(chalk.gray('β”‚') + ' ' + chalk.green('πŸ€– CAPSULE AI') + chalk.gray(' '.padEnd(43)) + chalk.gray('β”‚')); console.log(chalk.gray('β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€')); const response = getResponseForMode(input, mode); const lines = response.split('\n'); for (const line of lines) { const paddedLine = line.padEnd(55); console.log(chalk.gray('β”‚') + ' ' + chalk.white(paddedLine) + ' ' + chalk.gray('β”‚')); } console.log(chalk.gray('β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜')); console.log(chalk.dim(`\nπŸ’° Cost: $0.0001 | ⏱️ Latency: 234ms | πŸ“ Tokens: 28`)); showStatusBar(); } function getResponseForMode(input, mode) { switch (mode) { case Mode.AGENT: return `Task: "${input.substring(0, 40)}..."\n1. Analyzing requirements\n2. Breaking into subtasks\n3. Ready for execution`; case Mode.PLAN: return `Strategic plan for: "${input.substring(0, 30)}..."\nβ€’ Architecture: Microservices\nβ€’ Timeline: 2-3 weeks\nβ€’ Team: 3 developers`; case Mode.FUSION: return `Model Fusion for: "${input.substring(0, 35)}..."\nβ†’ GPT-4: Analysis\nβ†’ Claude: Implementation\nβ†’ Gemini: Optimization`; default: return `I'll help with: "${input.substring(0, 35)}..."\n[Demo - real AI coming soon]`; } } showStatusBar(); showPrompt(); } //# sourceMappingURL=clean-interactive.js.map