Skip to content

Commit c979253

Browse files
committed
Implement plan retrieval and WebSocket improvements
Uncommented and enabled plan retrieval logic in the backend, including session and plan ID resolution and message date formatting. Updated frontend PlanPage and WebSocketService to pass planId when connecting, improved plan data processing, and fixed minor formatting and callback issues for better reliability and maintainability.
1 parent f134cbf commit c979253

File tree

5 files changed

+192
-187
lines changed

5 files changed

+192
-187
lines changed

src/backend/app_kernel.py

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from kernel_agents.agent_factory import AgentFactory
2929
# Local imports
3030
from middleware.health_check import HealthCheckMiddleware
31+
from common.utils.utils_date import format_dates_in_messages
3132
from v3.api.router import app_v3
3233

3334
# Semantic Kernel imports
@@ -671,57 +672,57 @@ async def get_plans(
671672
#### <To do: Francia> Replace the following with code to get plan run history from the database
672673

673674
# # 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)
725726

726727
return []
727728

src/frontend/src/api/config.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function getUserInfoGlobal() {
9797
}
9898

9999
if (!USER_INFO) {
100-
console.info('User info not yet configured');
100+
// console.info('User info not yet configured');
101101
return null;
102102
}
103103

@@ -149,7 +149,7 @@ export function headerBuilder(headers?: Record<string, string>): Record<string,
149149
// });
150150

151151
// console.log('initializeTeam: Starting team initialization...');
152-
152+
153153
// try {
154154
// const response = await fetch(`${apiUrl}/init_team`, {
155155
// method: 'GET',
@@ -163,12 +163,12 @@ export function headerBuilder(headers?: Record<string, string>): Record<string,
163163

164164
// const data = await response.json();
165165
// console.log('initializeTeam: Team initialization completed:', data);
166-
166+
167167
// // Validate the expected response format
168168
// if (data.status !== 'Request started successfully' || !data.team_id) {
169169
// throw new Error('Invalid response format from init_team endpoint');
170170
// }
171-
171+
172172
// return data;
173173
// } catch (error) {
174174
// console.error('initializeTeam: Error initializing team:', error);

0 commit comments

Comments
 (0)