179 lines
5.1 KiB
JavaScript
Executable File
179 lines
5.1 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
// Environment setup script for Reason Flow
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const readline = require('readline');
|
|
|
|
const rl = readline.createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout
|
|
});
|
|
|
|
const question = (query) => {
|
|
return new Promise((resolve) => {
|
|
rl.question(query, resolve);
|
|
});
|
|
};
|
|
|
|
const main = async () => {
|
|
console.log('🚀 Reason Flow Environment Setup');
|
|
console.log('================================\n');
|
|
|
|
try {
|
|
// Check if .env already exists
|
|
const envPath = path.join(__dirname, '.env');
|
|
if (fs.existsSync(envPath)) {
|
|
const overwrite = await question('⚠️ .env file already exists. Overwrite? (y/N): ');
|
|
if (overwrite.toLowerCase() !== 'y' && overwrite.toLowerCase() !== 'yes') {
|
|
console.log('Setup cancelled.');
|
|
process.exit(0);
|
|
}
|
|
}
|
|
|
|
console.log('Please provide the following configuration values:\n');
|
|
|
|
// Collect configuration
|
|
const config = {};
|
|
|
|
// Server Configuration
|
|
console.log('📡 Server Configuration:');
|
|
config.PORT = await question('Port (default: 8000): ') || '8000';
|
|
config.NODE_ENV = await question('Environment (development/production/test, default: development): ') || 'development';
|
|
|
|
// Database Configuration
|
|
console.log('\n🗄️ Database Configuration:');
|
|
config.DB_HOST = await question('Database Host (default: localhost): ') || 'localhost';
|
|
config.DB_PORT = await question('Database Port (default: 5432): ') || '5432';
|
|
config.DB_NAME = await question('Database Name (default: reason_flow): ') || 'reason_flow';
|
|
config.DB_USER = await question('Database User (default: postgres): ') || 'postgres';
|
|
config.DB_PASSWORD = await question('Database Password: ');
|
|
|
|
// API Keys
|
|
console.log('\n🔑 API Keys:');
|
|
config.GROQ_API_KEY = await question('Groq API Key (required): ');
|
|
config.OPENAI_API_KEY = await question('OpenAI API Key (optional): ');
|
|
config.SERP_API_KEY = await question('SERP API Key (optional): ');
|
|
|
|
// JWT Configuration
|
|
console.log('\n🔐 Security Configuration:');
|
|
config.JWT_SECRET = await question('JWT Secret (or press Enter for auto-generated): ');
|
|
if (!config.JWT_SECRET) {
|
|
config.JWT_SECRET = require('crypto').randomBytes(64).toString('hex');
|
|
console.log(`Auto-generated JWT Secret: ${config.JWT_SECRET}`);
|
|
}
|
|
|
|
// Admin User
|
|
console.log('\n👤 Admin User Configuration:');
|
|
config.ADMIN_EMAIL = await question('Admin Email (default: admin@reasonflow.com): ') || 'admin@reasonflow.com';
|
|
config.ADMIN_PASSWORD = await question('Admin Password (default: admin123): ') || 'admin123';
|
|
|
|
// Generate .env file
|
|
const envContent = generateEnvContent(config);
|
|
fs.writeFileSync(envPath, envContent);
|
|
|
|
console.log('\n✅ Environment configuration created successfully!');
|
|
console.log(`📁 Configuration saved to: ${envPath}`);
|
|
|
|
console.log('\nNext steps:');
|
|
console.log('1. Review your configuration: node server/utils/validateConfig.js show');
|
|
console.log('2. Validate configuration: node server/utils/validateConfig.js validate');
|
|
console.log('3. Setup database: npm run db:setup');
|
|
console.log('4. Start the server: npm run dev');
|
|
|
|
} catch (error) {
|
|
console.error('\n❌ Setup failed:', error.message);
|
|
process.exit(1);
|
|
} finally {
|
|
rl.close();
|
|
}
|
|
};
|
|
|
|
const generateEnvContent = (config) => {
|
|
return `# Reason Flow Environment Configuration
|
|
# Generated on ${new Date().toISOString()}
|
|
|
|
# Server Configuration
|
|
PORT=${config.PORT}
|
|
NODE_ENV=${config.NODE_ENV}
|
|
HOST=localhost
|
|
|
|
# Database Configuration
|
|
DB_HOST=${config.DB_HOST}
|
|
DB_PORT=${config.DB_PORT}
|
|
DB_NAME=${config.DB_NAME}
|
|
DB_USER=${config.DB_USER}
|
|
DB_PASSWORD=${config.DB_PASSWORD}
|
|
DB_SSL=false
|
|
|
|
# Groq API Configuration
|
|
GROQ_API_KEY=${config.GROQ_API_KEY}
|
|
GROQ_MODEL=moonshotai/kimi-k2-instruct-0905
|
|
GROQ_BASE_URL=https://api.groq.com
|
|
|
|
# OpenAI API Configuration
|
|
OPENAI_API_KEY=${config.OPENAI_API_KEY}
|
|
OPENAI_BASE_URL=https://api.openai.com/v1
|
|
|
|
# JWT Configuration
|
|
JWT_SECRET=${config.JWT_SECRET}
|
|
JWT_EXPIRES_IN=7d
|
|
|
|
# Admin User Configuration
|
|
ADMIN_EMAIL=${config.ADMIN_EMAIL}
|
|
ADMIN_PASSWORD=${config.ADMIN_PASSWORD}
|
|
ADMIN_FIRST_NAME=Admin
|
|
ADMIN_LAST_NAME=User
|
|
|
|
# File Upload Configuration
|
|
MAX_FILE_SIZE=50MB
|
|
UPLOAD_PATH=./uploads
|
|
ALLOWED_FILE_TYPES=pdf,txt,doc,docx
|
|
|
|
# Rate Limiting
|
|
RATE_LIMIT_WINDOW_MS=900000
|
|
RATE_LIMIT_MAX_REQUESTS=100
|
|
|
|
# Logging Configuration
|
|
LOG_LEVEL=info
|
|
LOG_FILE=./logs/app.log
|
|
LOG_MAX_SIZE=10MB
|
|
LOG_MAX_FILES=5
|
|
|
|
# CORS Configuration
|
|
CORS_ORIGIN=http://localhost:3000
|
|
|
|
# Security Configuration
|
|
HELMET_ENABLED=true
|
|
RATE_LIMIT_ENABLED=true
|
|
|
|
# Development Configuration
|
|
DEBUG_MODE=true
|
|
VERBOSE_LOGGING=true
|
|
HOT_RELOAD=true
|
|
|
|
# Monitoring Configuration
|
|
HEALTH_CHECK_ENABLED=true
|
|
METRICS_ENABLED=true
|
|
PERFORMANCE_MONITORING=true
|
|
|
|
# Model Configuration
|
|
MODEL1_TEMPERATURE=0.3
|
|
MODEL1_MAX_TOKENS=3000
|
|
QUERYMODEL_TEMPERATURE=0.5
|
|
QUERYMODEL_MAX_TOKENS=4000
|
|
|
|
# Fine-tuning Configuration
|
|
FINE_TUNING_ENABLED=true
|
|
FINE_TUNING_SCHEDULE=weekly
|
|
FINE_TUNING_BATCH_SIZE=10
|
|
|
|
# Feedback Configuration
|
|
FEEDBACK_PROCESSING_ENABLED=true
|
|
FEEDBACK_BATCH_SIZE=50
|
|
FEEDBACK_PROCESSING_SCHEDULE=daily
|
|
`;
|
|
};
|
|
|
|
main();
|