@@ -98,6 +98,12 @@ def main():
9898 default = "Default Team" ,
9999 help = "Team name (default: Default Team)" ,
100100 )
101+ init .add_argument (
102+ "--org-name" ,
103+ type = str ,
104+ default = None ,
105+ help = "Organization name (auto-generated if not provided)" ,
106+ )
101107 init .set_defaults (func = init_command )
102108
103109 # run command (with subcommands)
@@ -173,32 +179,38 @@ def init_command(args):
173179 else f"{ user_name .lower ().replace (' ' , '.' )} @inftyai.com"
174180 )
175181 team_name = args .team_name
182+ org_name = args .org_name if args .org_name else fake .company ()
176183
177184 try :
178185 metadb = runtime .storage_runtime ().metadb
179186
180187 console .print ()
188+ # Create organization
189+ console .print (Text (f"🏢 Creating organization: { org_name } " , style = "bold cyan" ))
190+ org_id = metadb .create_organization (name = org_name )
181191 # Create user
182192 console .print (
183193 Text (f"👤 Creating user: { user_name } ({ email } )" , style = "bold cyan" )
184194 )
185- user_id = metadb .create_user (username = user_name , email = email )
195+ user_id = metadb .create_user (name = user_name , email = email , org_id = org_id )
186196
187197 # Create team
188198 console .print (Text (f"🏢 Creating team: { team_name } " , style = "bold cyan" ))
189199 team_id = metadb .create_team (
190- name = team_name , description = f"Team for { user_name } "
200+ name = team_name , description = f"Team for { user_name } " , org_id = org_id
191201 )
192202 # Add user to team
193203 metadb .add_user_to_team (user_id = user_id , team_id = team_id )
194204
195205 console .print ()
196206 console .print (Text ("✅ Initialization successful!" , style = "bold green" ))
197207 console .print ()
198- console .print (Text ("📋 Your user ID:" , style = "bold yellow" ))
199- console .print (Text (f" { user_id } " , style = "bold cyan" ))
208+ console .print (Text ("📋 Your organization ID:" , style = "bold yellow" ))
209+ console .print (Text (f" { org_id } " , style = "bold cyan" ))
200210 console .print (Text (" Your team ID:" , style = "bold yellow" ))
201211 console .print (Text (f" { team_id } " , style = "bold cyan" ))
212+ console .print (Text (" Your user ID:" , style = "bold yellow" ))
213+ console .print (Text (f" { user_id } " , style = "bold cyan" ))
202214 console .print ()
203215 console .print (
204216 Text (
@@ -296,6 +308,7 @@ def run_agent_command(args):
296308 agent_id = metadb .create_agent (
297309 name = agent_name ,
298310 type = agent_type ,
311+ org_id = metadb .get_user (uuid .UUID (user_id )).org_id ,
299312 team_id = uuid .UUID (team_id ),
300313 user_id = uuid .UUID (user_id ),
301314 )
@@ -529,12 +542,34 @@ def start_dashboard(args):
529542 # Create HTTP client for proxying requests to backend
530543 http_client = httpx .AsyncClient (base_url = args .backend_url , timeout = 30.0 )
531544
532- # Endpoint to get current user ID (for frontend)
545+ # Endpoint to get current user ID and org ID (for frontend)
533546 @app .get ("/api/config" )
534547 async def get_config ():
548+ import contextlib
549+ import uuid
550+
551+ from alphatrion .storage import runtime as storage_runtime
552+
553+ # Initialize storage if not already done
554+ with contextlib .suppress (Exception ):
555+ storage_runtime .init ()
556+
535557 config = {"userId" : app .state .user_id }
558+
559+ # Look up user's org_id
560+ try :
561+ metadb = storage_runtime .storage_runtime ().metadb
562+ user = metadb .get_user (user_id = uuid .UUID (app .state .user_id ))
563+ if user :
564+ config ["orgId" ] = str (user .org_id )
565+ except Exception as e :
566+ console .print (
567+ Text (f"Warning: Could not fetch user org_id: { e } " , style = "yellow" )
568+ )
569+
536570 if hasattr (app .state , "team_id" ):
537571 config ["teamId" ] = app .state .team_id
572+
538573 return config
539574
540575 # Proxy /graphql requests to backend (MUST be before catch-all route)
0 commit comments