embedia
Version:
Zero-configuration AI chatbot integration CLI - direct file copy with embedded API keys
58 lines (47 loc) ⢠2.25 kB
JavaScript
const chalk = require('chalk');
const { detectSimpleEnvironment } = require('../services/simpleDetection');
const { SimpleServerClient } = require('../services/simpleServerClient');
const { integrateEmbediaChat } = require('./simpleIntegration');
/**
* Simplified Init Command
* Replaces intelligentInitV2 with clean, simple approach
*/
async function simpleInit(options) {
console.log(chalk.cyan('\nš Embedia CLI v4.1 - Direct File Copy Integration\n'));
try {
// 1. Validate token
if (!options.token) {
console.error(chalk.red('ā Token is required. Use --token=ac_your_token'));
process.exit(1);
}
if (!options.token.startsWith('ac_')) {
console.error(chalk.red('ā Invalid token format. Token must start with "ac_"'));
process.exit(1);
}
// 2. Simple environment detection
console.log('š Detecting project environment...');
const environment = detectSimpleEnvironment();
if (!environment.isNextJS) {
console.warn(chalk.yellow('ā ļø This tool is optimized for Next.js projects'));
console.warn(chalk.yellow(' For other frameworks, manually copy files and integrate'));
}
console.log(chalk.gray(` Framework: ${environment.framework}`));
console.log(chalk.gray(` TypeScript: ${environment.isTypeScript ? 'Yes' : 'No'}`));
console.log(chalk.gray(` App Router: ${environment.isAppRouter ? 'Yes' : 'No'}`));
// 3. Fetch files from server
const serverClient = new SimpleServerClient();
const serverResponse = await serverClient.fetchEmbediaFiles(options.token);
// 4. Integrate with direct file copy approach
await integrateEmbediaChat(serverResponse, environment);
console.log(chalk.green('\nš Integration complete!'));
console.log(chalk.cyan('š Next steps:'));
console.log(' 1. Check README.md for setup instructions');
console.log(' 2. Start your development server');
console.log(' 3. The chat widget is ready with embedded configuration');
} catch (error) {
console.error(chalk.red('\nā Integration failed:'), error.message);
console.log(chalk.yellow('\nš” Try running: npx embedia doctor'));
process.exit(1);
}
}
module.exports = { simpleInit };