@@ -216,32 +216,62 @@ async def process_request(background_tasks: BackgroundTasks, input_task: InputTa
216216 )
217217 raise HTTPException (status_code = 400 , detail = "no user" )
218218
219- if not input_task .team_id :
220- track_event_if_configured (
221- "TeamIDNofound" , {"status_code" : 400 , "detail" : "no team id" }
222- )
223- raise HTTPException (status_code = 400 , detail = "no team id" )
219+ # if not input_task.team_id:
220+ # track_event_if_configured(
221+ # "TeamIDNofound", {"status_code": 400, "detail": "no team id"}
222+ # )
223+ # raise HTTPException(status_code=400, detail="no team id")
224224
225225 if not input_task .session_id :
226226 input_task .session_id = str (uuid .uuid4 ())
227-
228- plan_id = str (uuid .uuid4 ())
229-
230227 try :
231- current_user_id .set (user_id ) # Set context
232- current_context = contextvars .copy_context () # Capture context
233- # background_tasks.add_task(
234- # lambda: current_context.run(lambda:OrchestrationManager().run_orchestration, user_id, input_task)
235- # )
228+ plan_id = str (uuid .uuid4 ())
229+ # Initialize memory store and service
236230 memory_store = await DatabaseFactory .get_database (user_id = user_id )
237231 plan = Plan (
238232 id = plan_id ,
233+ plan_id = plan_id ,
239234 user_id = user_id ,
240- team_id = "" , #TODO add current_team_id
235+ session_id = input_task .session_id ,
236+ team_id = None , #TODO add current_team_id
241237 initial_goal = input_task .description ,
242238 overall_status = PlanStatus .in_progress ,
243239 )
244240 await memory_store .add_plan (plan )
241+
242+
243+ track_event_if_configured (
244+ "PlanCreated" ,
245+ {
246+ "status" : "success" ,
247+ "plan_id" : plan .plan_id ,
248+ "session_id" : input_task .session_id ,
249+ "user_id" : user_id ,
250+ "team_id" : "" , #TODO add current_team_id
251+ "description" : input_task .description ,
252+ },
253+ )
254+ except Exception as e :
255+ print (f"Error creating plan: { e } " )
256+ track_event_if_configured (
257+ "PlanCreationFailed" ,
258+ {
259+ "status" : "error" ,
260+ "description" : input_task .description ,
261+ "session_id" : input_task .session_id ,
262+ "user_id" : user_id ,
263+ "error" : str (e ),
264+ },
265+ )
266+ raise HTTPException (status_code = 500 , detail = "Failed to create plan" )
267+
268+ try :
269+ current_user_id .set (user_id ) # Set context
270+ current_context = contextvars .copy_context () # Capture context
271+ # background_tasks.add_task(
272+ # lambda: current_context.run(lambda:OrchestrationManager().run_orchestration, user_id, input_task)
273+ # )
274+
245275 async def run_with_context ():
246276 return await current_context .run (OrchestrationManager ().run_orchestration , user_id , input_task )
247277
0 commit comments