File size: 10,457 Bytes
b0e3b5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#!/usr/bin/env python3
"""

Universal App Launcher for AgenticAI Projects



Usage:

    python run.py <app_name> [--port PORT] [--help]



Examples:

    python run.py remedy

    python run.py athena --port 8502

    python run.py midas

    python run.py --list

"""

import sys
import os
import subprocess
import argparse
import time
from pathlib import Path
from typing import Dict, Optional
# from agents import Runner, SQLiteSession
# from agents import set_trace_processors
# from langsmith.wrappers import OpenAIAgentsTracingProcessor

# Load environment variables explicitly
from dotenv import load_dotenv
load_dotenv(override=True)

# App registry - maps app names to their paths and entry points
APP_REGISTRY: Dict[str, Dict[str, str]] = {
    "nexus": {
        "path": "src/nexus",
        "entry": "app.py",
        "description": "Nexus - AI Research Assistant - Multi-specialist orchestrator for finance, news, and web research"
    },
    "athena": {
        "path": "src/athena",
        "entry": "app.py",
        "description": "Athena - Deep Research Reporter - Plans, searches, and synthesises comprehensive research reports"
    },
    "remedy": {
        "path": "src/remedy",
        "entry": "app.py",
        "description": "Remedy - Healthcare RAG Advisor - Medical information retrieval using RAG and web search"
    },
    "midas": {
        "path": "src/midas",
        "entry": "app.py",
        "description": "Midas - Stock Investment Analyst - Multi-agent investment team for technical and sentiment analysis"
    },
    "odyssey": {
        "path": "src/odyssey",
        "entry": "app.py",
        "description": "Odyssey - Travel Planner - AI-powered trip planning with flight, hotel, and itinerary recommendations"
    },
    "waypoint": {
        "path": "src/waypoint",
        "entry": "main.py",
        "type": "fastapi",
        "description": "Waypoint - Trip Planner API - Phidata-powered trip itinerary planning REST API"
    },
    "agora": {
        "path": "src/agora",
        "entry": "backend/main.py",
        "type": "fastapi",
        "description": "Agora - AI Market Analyst - Real-time multi-agent market analysis with streaming (Vue.js + FastAPI)"
    },
    "fifa": {
        "path": "src/fifa",
        "entry": "backend/main.py",
        "type": "fastapi",
        "description": "FIFA - World Cup 2026 Dashboard - Live scores, schedule & news powered by LangGraph + Gemini (Vue.js PWA + FastAPI)"
    },
    "news": {
        "path": "src/news",
        "entry": "backend/main.py",
        "type": "fastapi",
        "description": "News - Daily News Digest - Top 5 stories across 10 categories powered by LangGraph + Claude (OpenRouter) (Vue.js PWA + FastAPI)"
    },
    "options": {
        "path": "src/options",
        "entry": "main.py",
        "type": "script",
        "description": "Options - Options Paper Trader - Automated options-selling paper trading dashboard with self-tuning strategy (Flask + SocketIO)"
    },
    "test": {
        "path": ".",
        "entry": "tests",
        "type": "test",
        "description": "Run Project Tests - Executes pytest suite"
    },
}


def print_banner():
    """Print a nice banner."""
    print("=" * 70)
    print("πŸš€ AgenticAI Projects Launcher".center(70))
    print("=" * 70)
    print()


def list_apps():
    """List all available apps."""
    print_banner()
    print("Available Applications:\n")
    
    max_name_len = max(len(name) for name in APP_REGISTRY.keys())
    
    for name, config in sorted(APP_REGISTRY.items()):
        print(f"  {name.ljust(max_name_len + 2)} - {config['description']}")
    
    print("\n" + "=" * 70)
    print("\nUsage: python run.py <app_name> [--port PORT]")
    print("Example: python run.py remedy --port 8501\n")


def validate_app(app_name: str) -> Optional[Dict[str, str]]:
    """

    Validate that the app exists and its files are present.

    

    Args:

        app_name: Name of the app to validate

        

    Returns:

        App configuration dict if valid, None otherwise

    """
    if app_name not in APP_REGISTRY:
        print(f"❌ Error: Unknown app '{app_name}'")
        print(f"\nAvailable apps: {', '.join(sorted(APP_REGISTRY.keys()))}")
        print("\nRun 'python run.py --list' to see all available apps.")
        return None
    
    config = APP_REGISTRY[app_name]
    project_root = Path(__file__).parent
    app_path = project_root / config["path"] / config["entry"]
    
    if not app_path.exists():
        print(f"❌ Error: App file not found at {app_path}")
        return None
    
    return config


def launch_app(app_name: str, port: Optional[int] = None):
    """

    Launch a Streamlit app.

    

    Args:

        app_name: Name of the app to launch

        port: Optional port number (default: 8501)

    """
    config = validate_app(app_name)
    if not config:
        sys.exit(1)
    
    project_root = Path(__file__).parent
    app_dir = project_root / config["path"]
    app_file = config["entry"]
    
    print_banner()
    print(f"πŸ“± Launching: {config['description']}")
    print(f"πŸ“‚ Location: {config['path']}")
    print(f"🌐 Entry Point: {app_file}")
    
    app_type = config.get("type", "streamlit")
    
    python_exe = sys.executable
    is_windows = sys.platform == "win32"
    
    # Prepare environment with project root in PYTHONPATH to fix imports
    env = os.environ.copy()
    env["PYTHONPATH"] = str(project_root) + os.pathsep + env.get("PYTHONPATH", "")
    
    # Decoupled App Logic: Build frontend if needed
    if app_name in ("agora", "fifa", "news"):
        frontend_dir = project_root / f"src/{app_name}/frontend"
        dist_dir = frontend_dir / "dist"
        if not dist_dir.exists():
            print(f"\nπŸ› οΈ  Frontend build missing for {app_name}. Building now...")
            subprocess.run(["npm", "install"], cwd=frontend_dir, shell=is_windows)
            subprocess.run(["npm", "run", "build"], cwd=frontend_dir, shell=is_windows)
            print("βœ… Frontend built.\n")
    
    # App Type specific logic
    if app_type == "fastapi":
        # Extract module name from entry point (e.g. backend/main.py -> backend.main)
        module_path = app_file.replace(".py", "").replace("/", ".").replace("\\", ".")
        cmd = [python_exe, "-m", "uvicorn", f"{module_path}:app", "--host", "0.0.0.0"]
        default_port = 8000
    elif app_type == "script":
        cmd = [python_exe, app_file]
        default_port = None
    elif app_type == "test":
        cmd = [python_exe, "-m", "pytest", app_file, "-v"]
        default_port = None
    elif app_type == "npm":
        cmd = ["npm", "run", "dev"]
        default_port = 5173
    else:
        cmd = [python_exe, "-m", "streamlit", "run", app_file]
        default_port = 8501
    
    # Add port if specified
    actual_port = port if port else default_port
    
    if app_type in ["streamlit", "fastapi", "npm"]:
        if port:
            if app_type == "fastapi":
                cmd.extend(["--port", str(port)])
            elif app_type == "npm":
                cmd.extend(["--", "--port", str(port)])
            else:
                cmd.extend(["--server.port", str(port)])
            print(f"πŸ”Œ Port: {port}")
        else:
            print(f"πŸ”Œ Port: {default_port} (default)")
            
        # Kill any process using the target port (Port is only relevant for web apps)
        try:
            import platform
            if platform.system() != "Windows":
                # Use fuser on Linux/Mac to kill processes on the port
                kill_cmd = ["fuser", "-k", f"{actual_port}/tcp"]
                subprocess.run(kill_cmd, stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
                print(f"🧹 Cleaned up port {actual_port}")
        except Exception:
            pass  # Silently continue if cleanup fails
    
    print("\n" + "=" * 70)
    print("\n🎯 Starting application...\n")
    
    print(f"\n\nPYTHONPATH: {env['PYTHONPATH']}")

    try:
        # Change to app directory and run
        os.chdir(app_dir)
        


        subprocess.run(cmd, env=env, shell=is_windows)
    except KeyboardInterrupt:
        print("\n\nπŸ‘‹ Application stopped by user")
    except FileNotFoundError:
        binary = "command"
        if app_type == "fastapi": binary = "uvicorn"
        elif app_type == "streamlit": binary = "streamlit"
        elif app_type == "test": binary = "pytest"
        
        print(f"\n❌ Error: {binary} not found in the current environment.")
        print(f"   Please install it: pip install {binary}")
        sys.exit(1)
    except Exception as e:
        print(f"\n❌ Error launching app: {e}")
        sys.exit(1)

def main():
    """Main entry point."""
    parser = argparse.ArgumentParser(
        description="Universal launcher for AgenticAI project applications",
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog="""

Examples:

  python run.py remedy                  # Launch Remedy healthcare chatbot

  python run.py athena --port 8502      # Launch on custom port

  python run.py --list                  # List all available apps



Available Apps:

  """ + "\n  ".join(f"{name}: {config['description']}" 
                     for name, config in sorted(APP_REGISTRY.items()))
    )
    
    parser.add_argument(
        "app_name",
        nargs="?",
        help="Name of the app to launch"
    )
    
    parser.add_argument(
        "--port",
        type=int,
        help="Port number for Streamlit server (default: 8501)"
    )
    
    parser.add_argument(
        "--list",
        action="store_true",
        help="List all available apps"
    )
    
    args = parser.parse_args()
    
    # Handle --list flag
    if args.list:
        list_apps()
        return
    
    # Require app name if not listing
    if not args.app_name:
        parser.print_help()
        print("\n")
        list_apps()
        return
    
    # Launch the app
    launch_app(args.app_name, args.port)


if __name__ == "__main__":
    # set_trace_processors([OpenAIAgentsTracingProcessor()])
    main()