capsule-ai-cli
Version:
The AI Model Orchestrator - Intelligent multi-model workflows with device-locked licensing
73 lines • 3 kB
JavaScript
import chalk from 'chalk';
import inquirer from 'inquirer';
import { authService } from '../services/auth.js';
import ora from 'ora';
export async function promptForAuth() {
console.log(chalk.yellow('\n⚡ Welcome to Capsule CLI'));
console.log(chalk.gray('The AI Model Orchestrator\n'));
console.log(chalk.cyan('To use Capsule CLI, you need to authenticate with your purchase.'));
console.log(chalk.gray('Don\'t have Capsule yet? Get it at https://capsule.dev\n'));
if (process.stdin.isTTY) {
process.stdin.setRawMode(false);
}
const { shouldAuth } = await inquirer.prompt([
{
type: 'confirm',
name: 'shouldAuth',
message: 'Would you like to authenticate now?',
default: true
}
]);
if (!shouldAuth) {
console.log(chalk.gray('\nYou can authenticate later with: capsule auth <email>'));
if (process.stdin.isTTY) {
process.stdin.setRawMode(true);
}
return false;
}
const { email } = await inquirer.prompt([
{
type: 'input',
name: 'email',
message: 'Enter your email address:',
validate: (input) => {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(input)) {
return 'Please enter a valid email address';
}
return true;
}
}
]);
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()}`);
}
console.log(chalk.gray('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'));
console.log(chalk.green('\n🚀 You\'re all set! Capsule CLI is ready to use.\n'));
if (process.stdin.isTTY) {
process.stdin.setRawMode(true);
}
return true;
}
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'));
}
if (process.stdin.isTTY) {
process.stdin.setRawMode(true);
}
return false;
}
}
//# sourceMappingURL=auth-prompt.js.map