@@ -1255,7 +1255,7 @@ async def get_plans(request: Request):
12551255
12561256# Get plans is called in the initial side rendering of the frontend 
12571257@app_v3 .get ("/plan" ) 
1258- async  def  get_plan_by_id (request : Request , plan_id : str ):
1258+ async  def  get_plan_by_id (request : Request ,   plan_id : Optional [ str ]  =   Query ( None ), ):
12591259    """ 
12601260    Retrieve plans for the current user. 
12611261
@@ -1326,29 +1326,32 @@ async def get_plan_by_id(request: Request, plan_id: str):
13261326
13271327    # # Initialize memory context 
13281328    memory_store  =  await  DatabaseFactory .get_database (user_id = user_id )
1329+     try :
1330+         if  plan_id :
1331+             plan  =  await  memory_store .get_plan_by_plan_id (plan_id = plan_id )
1332+             if  not  plan :
1333+                 track_event_if_configured (
1334+                     "GetPlanBySessionNotFound" ,
1335+                     {"status_code" : 400 , "detail" : "Plan not found" },
1336+                 )
1337+                 raise  HTTPException (status_code = 404 , detail = "Plan not found" )
1338+ 
1339+             # Use get_steps_by_plan to match the original implementation 
13291340
1330-     if  plan_id :
1331-         plan  =  await  memory_store .get_plan_by_plan_id (plan_id = plan_id )
1332-         if  not  plan :
1341+             team  =  await  memory_store .get_team_by_id (team_id = plan .team_id )
1342+             agent_messages  =  await  memory_store .get_agent_messages (plan_id = plan .plan_id )
1343+             m_plan  =  await  memory_store .get_mplan (plan_id = plan .plan_id )
1344+             return  {
1345+                 "plan" : plan ,
1346+                 "team" : team  if  team  else  None ,
1347+                 "messages" : agent_messages ,
1348+                 "m_plan" : m_plan  if  m_plan  else  None ,
1349+             }
1350+         else :
13331351            track_event_if_configured (
1334-                 "GetPlanBySessionNotFound" ,
1335-                 {"status_code" : 400 , "detail" : "Plan not found" },
1352+                 "GetPlanId" , {"status_code" : 400 , "detail" : "no plan id" }
13361353            )
1337-             raise  HTTPException (status_code = 404 , detail = "Plan not found" )
1338- 
1339-         # Use get_steps_by_plan to match the original implementation 
1340- 
1341-         team  =  await  memory_store .get_team_by_id (team_id = plan .team_id )
1342-         agent_messages  =  await  memory_store .get_agent_messages (plan_id = plan .plan_id )
1343-         m_plan  =  await  memory_store .get_mplan (plan_id = plan .plan_id )
1344-         return  {
1345-             "plan" : plan ,
1346-             "team" : team  if  team  else  None ,
1347-             "messages" : agent_messages ,
1348-             "m_plan" : m_plan  if  m_plan  else  None ,
1349-         }
1350-     else :
1351-         track_event_if_configured (
1352-             "GetPlanId" , {"status_code" : 400 , "detail" : "no plan id" }
1353-         )
1354-         raise  HTTPException (status_code = 400 , detail = "no plan id" )
1354+             raise  HTTPException (status_code = 400 , detail = "no plan id" )
1355+     except  Exception  as  e :
1356+         logging .error (f"Error retrieving plan: { str (e )}  " )
1357+         raise  HTTPException (status_code = 500 , detail = "Internal server error occurred" )
0 commit comments