102102# connection_config.add_connection(process_id=process_id, connection=websocket)
103103
104104@app .websocket ("/socket/{process_id}" )
105- async def process_outputs (websocket : WebSocket , process_id : str ):
105+ async def start_comms (websocket : WebSocket , process_id : str ):
106106 """ Web-Socket endpoint for real-time process status updates. """
107107
108108 # Always accept the WebSocket connection first
109109 await websocket .accept ()
110110
111- # user_id = None
112- # try:
113- # # WebSocket headers are different, try to get user info
114- # headers = dict(websocket.headers)
115- # authenticated_user = get_authenticated_user_details(request_headers=headers)
116- # user_id = authenticated_user.get("user_principal_id")
117- # if not user_id:
118- # user_id = f"anonymous_{process_id}"
119- # except Exception as e:
120- # logging.warning(f"Could not extract user from WebSocket headers: {e}")
121- # user_id = f"anonymous_{user_id}"
111+ user_id = None
112+ try :
113+ # WebSocket headers are different, try to get user info
114+ headers = dict (websocket .headers )
115+ authenticated_user = get_authenticated_user_details (request_headers = headers )
116+ user_id = authenticated_user .get ("user_principal_id" )
117+ if not user_id :
118+ user_id = f"anonymous_{ process_id } "
119+ except Exception as e :
120+ logging .warning (f"Could not extract user from WebSocket headers: { e } " )
121+ user_id = f"anonymous_{ user_id } "
122122
123123 # Add to the connection manager for backend updates
124124
125- connection_config .add_connection (process_id , websocket )
125+ connection_config .add_connection (user_id , websocket )
126126 track_event_if_configured ("WebSocketConnectionAccepted" , {"process_id" : "user_id" })
127127
128128 # Keep the connection open - FastAPI will close the connection if this returns
@@ -135,8 +135,8 @@ async def process_outputs(websocket: WebSocket, process_id: str):
135135 pass
136136
137137 except WebSocketDisconnect :
138- track_event_if_configured ("WebSocketDisconnect" , {"process_id" : user_id })
139- logging .info (f"Client disconnected from batch { user_id } " )
138+ track_event_if_configured ("WebSocketDisconnect" , {"process_id" : process_id })
139+ logging .info (f"Client disconnected from batch { process_id } " )
140140 await connection_config .close_connection (user_id )
141141 except Exception as e :
142142 logging .error ("Error in WebSocket connection" , error = str (e ))
@@ -726,10 +726,7 @@ async def get_plans(
726726
727727 await connection_config .send_status_update_async ("Test message from get_plans" , user_id )
728728
729- # Initialize agent team for this user session
730- #await OrchestrationManager.get_current_orchestration(user_id=user_id)
731-
732- # Replace the following with code to get plan run history from the database
729+ #### <To do: Francia> Replace the following with code to get plan run history from the database
733730
734731 # # Initialize memory context
735732 # memory_store = await DatabaseFactory.get_database(user_id=user_id)
@@ -786,7 +783,21 @@ async def get_plans(
786783
787784 return []
788785
789-
786+ @app .get ("/api/init_team" )
787+ async def init_team (
788+ request : Request ,
789+ ):
790+ """ Initialize the team of agents """
791+ authenticated_user = get_authenticated_user_details (request_headers = request .headers )
792+ user_id = authenticated_user ["user_principal_id" ]
793+ if not user_id :
794+ track_event_if_configured (
795+ "UserIdNotFound" , {"status_code" : 400 , "detail" : "no user" }
796+ )
797+ raise HTTPException (status_code = 400 , detail = "no user" )
798+ # Initialize agent team for this user session
799+ await OrchestrationManager .get_current_orchestration (user_id = user_id )
800+
790801@app .get ("/api/steps/{plan_id}" , response_model = List [Step ])
791802async def get_steps_by_plan (plan_id : str , request : Request ) -> List [Step ]:
792803 """
0 commit comments