File size: 5,297 Bytes
4e3c158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python3
"""
Interactive Setup Wizard for ATOM Application
Guides users through environment configuration step-by-step.
"""

import base64
import os
from pathlib import Path
import secrets


def generate_secret_key() -> str:
    """Generate a secure random key for encryption."""
    return base64.b64encode(secrets.token_bytes(32)).decode('utf-8')


def get_input(prompt: str, default: str = "", required: bool = False) -> str:
    """Get user input with optional default value."""
    if default:
        full_prompt = f"{prompt} [{default}]: "
    else:
        full_prompt = f"{prompt}: "
    
    while True:
        value = input(full_prompt).strip()
        if not value and default:
            return default
        if not value and required:
            print("❌ This field is required. Please provide a value.")
            continue
        return value


def main():
    """Main setup wizard."""
    print("=" * 80)
    print("🚀 ATOM APPLICATION - INTERACTIVE SETUP WIZARD")
    print("=" * 80)
    print()
    print("This wizard will help you create a .env file with your credentials.")
    print("Press Enter to skip optional fields.")
    print()
    
    # Check if .env already exists
    env_path = Path(__file__).parent.parent.parent / ".env"
    if env_path.exists():
        response = input("⚠️  .env file already exists. Overwrite? (y/N): ").strip().lower()
        if response != 'y':
            print("Setup cancelled.")
            return
    
    config = {}
    
    # Required: Security keys
    print("\n🔒 SECURITY CONFIGURATION (Required)")
    print("-" * 80)
    print("Generating secure encryption keys...")
    config["NEXTAUTH_SECRET"] = generate_secret_key()
    config["ATOM_ENCRYPTION_KEY"] = generate_secret_key()
    config["BYOK_ENCRYPTION_KEY"] = generate_secret_key()
    print("✅ Generated NEXTAUTH_SECRET")
    print("✅ Generated ATOM_ENCRYPTION_KEY")
    print("✅ Generated BYOK_ENCRYPTION_KEY")
    
    config["NEXTAUTH_URL"] = get_input(
        "NextAuth URL", 
        default="http://localhost:3000",
        required=True
    )
    
    # Core configuration
    print("\n⚙️  CORE CONFIGURATION")
    print("-" * 80)
    config["NODE_ENV"] = get_input("Environment", default="development")
    config["NEXT_PUBLIC_API_BASE_URL"] = get_input(
        "Backend API URL",
        default="http://localhost:8000"
    )
    config["LOG_LEVEL"] = get_input("Log Level", default="info")
    
    # Database
    print("\n💾 DATABASE CONFIGURATION")
    print("-" * 80)
    config["LANCEDB_PATH"] = get_input("LanceDB Path", default="./data/lancedb")
    config["SQLITE_PATH"] = get_input("SQLite Path", default="./data/atom.db")
    
    use_postgres = input("Use PostgreSQL? (y/N): ").strip().lower() == 'y'
    if use_postgres:
        config["DATABASE_URL"] = get_input("PostgreSQL URL", required=True)
    
    # AI Services
    print("\n🤖 AI SERVICES (Optional - Add as needed)")
    print("-" * 80)
    print("Tip: You can skip these and add them later in .env")
    
    if input("Configure OpenAI? (y/N): ").strip().lower() == 'y':
        config["OPENAI_API_KEY"] = get_input("OpenAI API Key", required=True)
    
    if input("Configure Anthropic (Claude)? (y/N): ").strip().lower() == 'y':
        config["ANTHROPIC_API_KEY"] = get_input("Anthropic API Key", required=True)
    
    # Integrations (optional)
    print("\n🔌 INTEGRATIONS (Optional)")
    print("-" * 80)
    print("You can configure integrations now or add them later.")
    print("See docs/missing_credentials_guide.md for full list.")
    
    if input("Configure Slack? (y/N): ").strip().lower() == 'y':
        config["SLACK_CLIENT_ID"] = get_input("Slack Client ID", required=True)
        config["SLACK_CLIENT_SECRET"] = get_input("Slack Client Secret", required=True)
    
    if input("Configure Google Services? (y/N): ").strip(). lower() == 'y':
        config["GOOGLE_CLIENT_ID"] = get_input("Google Client ID", required=True)
        config["GOOGLE_CLIENT_SECRET"] = get_input("Google Client Secret", required=True)
    
    # Write .env file
    print("\n📝 Writing .env file...")
    with open(env_path, 'w') as f:
        f.write("# ATOM Application Environment Variables\n")
        f.write(f"# Generated by setup wizard\n\n")
        
        for key, value in config.items():
            f.write(f"{key}={value}\n")
        
        f.write("\n# Add more credentials as needed")
        f.write("\n# See .env.example for full template\n")
    
    print("✅ .env file created successfully!")
    print()
    print("=" * 80)
    print("NEXT STEPS")
    print("=" * 80)
    print("1. Review and edit .env to add more integrations")
    print("2. Run: python backend/scripts/validate_credentials.py")
    print("3. Start backend: cd backend && python main_api_app.py")
    print("4. Start frontend: cd frontend-nextjs && npm run dev")
    print()
    print("📖 For more integrations: See .env.example and docs/missing_credentials_guide.md")
    print("=" * 80)


if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        print("\n\nSetup cancelled by user.")
    except Exception as e:
        print(f"\n❌ Error: {e}")
        print("Please check your inputs and try again.")