|
28 | 28 | from kernel_agents.agent_factory import AgentFactory |
29 | 29 | # Local imports |
30 | 30 | from middleware.health_check import HealthCheckMiddleware |
| 31 | +from common.utils.utils_date import format_dates_in_messages |
31 | 32 | from v3.api.router import app_v3 |
32 | 33 |
|
33 | 34 | # Semantic Kernel imports |
@@ -671,57 +672,57 @@ async def get_plans( |
671 | 672 | #### <To do: Francia> Replace the following with code to get plan run history from the database |
672 | 673 |
|
673 | 674 | # # Initialize memory context |
674 | | - # memory_store = await DatabaseFactory.get_database(user_id=user_id) |
675 | | - # if session_id: |
676 | | - # plan = await memory_store.get_plan_by_session(session_id=session_id) |
677 | | - # if not plan: |
678 | | - # track_event_if_configured( |
679 | | - # "GetPlanBySessionNotFound", |
680 | | - # {"status_code": 400, "detail": "Plan not found"}, |
681 | | - # ) |
682 | | - # raise HTTPException(status_code=404, detail="Plan not found") |
683 | | - |
684 | | - # # Use get_steps_by_plan to match the original implementation |
685 | | - # steps = await memory_store.get_steps_by_plan(plan_id=plan.id) |
686 | | - # plan_with_steps = PlanWithSteps(**plan.model_dump(), steps=steps) |
687 | | - # plan_with_steps.update_step_counts() |
688 | | - # return [plan_with_steps] |
689 | | - # if plan_id: |
690 | | - # plan = await memory_store.get_plan_by_plan_id(plan_id=plan_id) |
691 | | - # if not plan: |
692 | | - # track_event_if_configured( |
693 | | - # "GetPlanBySessionNotFound", |
694 | | - # {"status_code": 400, "detail": "Plan not found"}, |
695 | | - # ) |
696 | | - # raise HTTPException(status_code=404, detail="Plan not found") |
697 | | - |
698 | | - # # Use get_steps_by_plan to match the original implementation |
699 | | - # steps = await memory_store.get_steps_by_plan(plan_id=plan.id) |
700 | | - # messages = await memory_store.get_data_by_type_and_session_id( |
701 | | - # "agent_message", session_id=plan.session_id |
702 | | - # ) |
703 | | - |
704 | | - # plan_with_steps = PlanWithSteps(**plan.model_dump(), steps=steps) |
705 | | - # plan_with_steps.update_step_counts() |
706 | | - |
707 | | - # # Format dates in messages according to locale |
708 | | - # formatted_messages = format_dates_in_messages( |
709 | | - # messages, config.get_user_local_browser_language() |
710 | | - # ) |
711 | | - |
712 | | - # return [plan_with_steps, formatted_messages] |
713 | | - |
714 | | - # all_plans = await memory_store.get_all_plans() |
715 | | - # # Fetch steps for all plans concurrently |
716 | | - # steps_for_all_plans = await asyncio.gather( |
717 | | - # *[memory_store.get_steps_by_plan(plan_id=plan.id) for plan in all_plans] |
718 | | - # ) |
719 | | - # # Create list of PlanWithSteps and update step counts |
720 | | - # list_of_plans_with_steps = [] |
721 | | - # for plan, steps in zip(all_plans, steps_for_all_plans): |
722 | | - # plan_with_steps = PlanWithSteps(**plan.model_dump(), steps=steps) |
723 | | - # plan_with_steps.update_step_counts() |
724 | | - # list_of_plans_with_steps.append(plan_with_steps) |
| 675 | + memory_store = await DatabaseFactory.get_database(user_id=user_id) |
| 676 | + if session_id: |
| 677 | + plan = await memory_store.get_plan_by_session(session_id=session_id) |
| 678 | + if not plan: |
| 679 | + track_event_if_configured( |
| 680 | + "GetPlanBySessionNotFound", |
| 681 | + {"status_code": 400, "detail": "Plan not found"}, |
| 682 | + ) |
| 683 | + raise HTTPException(status_code=404, detail="Plan not found") |
| 684 | + |
| 685 | + # Use get_steps_by_plan to match the original implementation |
| 686 | + steps = await memory_store.get_steps_by_plan(plan_id=plan.id) |
| 687 | + plan_with_steps = PlanWithSteps(**plan.model_dump(), steps=steps) |
| 688 | + plan_with_steps.update_step_counts() |
| 689 | + return [plan_with_steps] |
| 690 | + if plan_id: |
| 691 | + plan = await memory_store.get_plan_by_plan_id(plan_id=plan_id) |
| 692 | + if not plan: |
| 693 | + track_event_if_configured( |
| 694 | + "GetPlanBySessionNotFound", |
| 695 | + {"status_code": 400, "detail": "Plan not found"}, |
| 696 | + ) |
| 697 | + raise HTTPException(status_code=404, detail="Plan not found") |
| 698 | + |
| 699 | + # Use get_steps_by_plan to match the original implementation |
| 700 | + steps = await memory_store.get_steps_by_plan(plan_id=plan.id) |
| 701 | + messages = await memory_store.get_data_by_type_and_session_id( |
| 702 | + "agent_message", session_id=plan.session_id |
| 703 | + ) |
| 704 | + |
| 705 | + plan_with_steps = PlanWithSteps(**plan.model_dump(), steps=steps) |
| 706 | + plan_with_steps.update_step_counts() |
| 707 | + |
| 708 | + # Format dates in messages according to locale |
| 709 | + formatted_messages = format_dates_in_messages( |
| 710 | + messages, config.get_user_local_browser_language() |
| 711 | + ) |
| 712 | + |
| 713 | + return [plan_with_steps, formatted_messages] |
| 714 | + |
| 715 | + all_plans = await memory_store.get_all_plans() |
| 716 | + # Fetch steps for all plans concurrently |
| 717 | + steps_for_all_plans = await asyncio.gather( |
| 718 | + *[memory_store.get_steps_by_plan(plan_id=plan.id) for plan in all_plans] |
| 719 | + ) |
| 720 | + # Create list of PlanWithSteps and update step counts |
| 721 | + list_of_plans_with_steps = [] |
| 722 | + for plan, steps in zip(all_plans, steps_for_all_plans): |
| 723 | + plan_with_steps = PlanWithSteps(**plan.model_dump(), steps=steps) |
| 724 | + plan_with_steps.update_step_counts() |
| 725 | + list_of_plans_with_steps.append(plan_with_steps) |
725 | 726 |
|
726 | 727 | return [] |
727 | 728 |
|
|
0 commit comments