capsule-ai-cli
Version:
The AI Model Orchestrator - Intelligent multi-model workflows with device-locked licensing
66 lines • 3.17 kB
JavaScript
import chalk from 'chalk';
import ora from 'ora';
import { authService } from '../services/auth.js';
export async function authCommand(email) {
try {
if (!email) {
const status = await authService.getStatus();
console.log(authService.formatStatus(status));
return;
}
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
console.error(chalk.red('Invalid email format'));
process.exit(1);
}
const spinner = ora('Authenticating...').start();
try {
const auth = await authService.authenticate(email);
spinner.stop();
console.log(chalk.green('\n✓ Authentication successful!'));
console.log(chalk.gray('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'));
const tierColor = auth.tier === 'super' ? chalk.cyan : chalk.green;
console.log(`${chalk.gray('Tier:')} ${tierColor(auth.tier.toUpperCase())}`);
console.log(`${chalk.gray('Email:')} ${auth.email}`);
if (auth.tier === 'super' && auth.remainingRUs) {
console.log(`${chalk.gray('RUs:')} ${auth.remainingRUs.toLocaleString()}`);
}
const validUntil = new Date(auth.validUntil);
const daysLeft = Math.ceil((validUntil.getTime() - Date.now()) / (1000 * 60 * 60 * 24));
console.log(`${chalk.gray('Valid for:')} ${daysLeft} days`);
console.log(chalk.gray('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'));
if (auth.tier === 'base') {
console.log(chalk.yellow('\n⚡ Base Tier Features:'));
console.log(' • Full CLI functionality');
console.log(' • All AI providers supported');
console.log(' • Use your own API keys');
console.log(' • Dashboard analytics');
}
else {
console.log(chalk.cyan('\n🚀 Super Tier Features:'));
console.log(' • Everything in Base tier');
console.log(` • ${auth.remainingRUs?.toLocaleString()} Request Units included`);
console.log(' • No need for API keys (until RUs run out)');
console.log(' • Priority support');
}
console.log(chalk.gray('\nYou can now use Capsule CLI!'));
}
catch (error) {
spinner.stop();
console.error(chalk.red('\n✗ Authentication failed:'), error.message);
if (error.message.includes('No purchase found')) {
console.log(chalk.yellow('\nGet Capsule CLI at: https://capsule.dev'));
}
process.exit(1);
}
}
catch (error) {
console.error(chalk.red('Error:'), error.message);
process.exit(1);
}
}
export async function logoutCommand() {
await authService.logout();
console.log(chalk.green('✓ Logged out successfully'));
}
//# sourceMappingURL=auth.js.map