diff --git a/alphatrion/envs.py b/alphatrion/envs.py index 4062fe3..cb404f3 100644 --- a/alphatrion/envs.py +++ b/alphatrion/envs.py @@ -6,3 +6,6 @@ ENABLE_TRACING = "ALPHATRION_ENABLE_TRACING" ROOT_PATH = "ALPHATRION_ROOT_PATH" AUTO_CLEANUP = "ALPHATRION_AUTO_CLEANUP" + +# Dashboard only related envs +DASHBOARD_USER_ID = "ALPHATRION_DASHBOARD_USER_ID" diff --git a/alphatrion/server/cmd/main.py b/alphatrion/server/cmd/main.py index ffdebd7..60cbfe1 100644 --- a/alphatrion/server/cmd/main.py +++ b/alphatrion/server/cmd/main.py @@ -1,6 +1,7 @@ # ruff: noqa: E501 import argparse +import os import threading import time import webbrowser @@ -17,6 +18,7 @@ from rich.console import Console from rich.text import Text +from alphatrion import envs from alphatrion.storage import runtime load_dotenv() @@ -59,7 +61,7 @@ def main(): dashboard.add_argument( "--userid", type=str, - required=True, + default=os.getenv(envs.DASHBOARD_USER_ID), help="User ID to scope the dashboard (required)", ) dashboard.set_defaults(func=start_dashboard) @@ -140,7 +142,13 @@ def init_command(args): console.print(Text(" Your team ID:", style="bold yellow")) console.print(Text(f" {team_id}", style="bold cyan")) console.print() - console.print(Text("💡 Use this user ID to launch the dashboard:", style="dim")) + console.print( + Text( + "💡 Use this user ID to launch the dashboard, " + "or set the ALPHATRION_DASHBOARD_USER_ID environment variable", + style="dim", + ) + ) console.print( Text(f" alphatrion dashboard --userid {user_id}", style="magenta") ) @@ -154,7 +162,7 @@ def init_command(args): console.print(Text(" import alphatrion as alpha", style="white")) console.print( Text( - f" alpha.init(user_id='{user_id}', team_id='{team_id}')", + f" alpha.init(user_id='{user_id}')", style="white", ) ) @@ -264,6 +272,26 @@ def start_dashboard(args): app = FastAPI() + if not args.userid: + console.print( + Text( + "❌ Error: User ID is required to launch the dashboard!", + style="bold red", + ) + ) + console.print( + Text( + "Please provide a user ID using the --userid argument or set the ALPHATRION_DASHBOARD_USER_ID environment variable.", + style="yellow", + ) + ) + console.print( + Text( + "You can create a user and get their ID by running: alphatrion init", + style="cyan", + ) + ) + return # Store user ID in app state app.state.user_id = args.userid diff --git a/file:testdb b/file:testdb new file mode 100644 index 0000000..fd99bce Binary files /dev/null and b/file:testdb differ