Skip to content

Commit fd0dccc

Browse files
committed
Refactor plan data handling and WebSocket params
Updated backend to return raw plan, team, messages, and m_plan objects instead of model_dump results. Adjusted frontend API service and PlanPage to handle new response structure and improved variable naming for clarity. Refactored WebSocketService to use planId instead of sessionId for connection and URL building.
1 parent c4120fd commit fd0dccc

File tree

13 files changed

+331
-289
lines changed

13 files changed

+331
-289
lines changed

src/backend/v3/api/router.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,15 +1250,7 @@ async def get_plans(request: Request):
12501250
team_id=current_team.team_id, status=PlanStatus.completed
12511251
)
12521252

1253-
# Create list of PlanWithSteps and update step counts
1254-
list_of_plans_with_steps = []
1255-
for plan in all_plans:
1256-
plan_with_steps = PlanWithSteps(**plan.model_dump(), steps=[])
1257-
plan_with_steps.overall_status
1258-
plan_with_steps.update_step_counts()
1259-
list_of_plans_with_steps.append(plan_with_steps)
1260-
1261-
return list_of_plans_with_steps
1253+
return all_plans
12621254

12631255

12641256
# Get plans is called in the initial side rendering of the frontend
@@ -1347,13 +1339,13 @@ async def get_plan_by_id(request: Request, plan_id: str):
13471339
# Use get_steps_by_plan to match the original implementation
13481340

13491341
team = await memory_store.get_team_by_id(team_id=plan.team_id)
1350-
messages = await memory_store.get_agent_messages(plan_id=plan.plan_id)
1351-
m_plan = await memory_store.get_m_plan_by_plan_id(plan_id=plan.plan_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)
13521344
return {
1353-
"plan": plan.model_dump(),
1354-
"team": team.model_dump() if team else None,
1355-
"messages": [msg.model_dump() for msg in messages],
1356-
"m_plan": m_plan.model_dump() if m_plan else None,
1345+
"plan": plan,
1346+
"team": team if team else None,
1347+
"messages": agent_messages,
1348+
"m_plan": m_plan if m_plan else None,
13571349
}
13581350
else:
13591351
track_event_if_configured(

src/frontend/src/api/apiService.tsx

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ import {
44
HumanClarification,
55
InputTask,
66
InputTaskResponse,
7-
PlanWithSteps,
87
Plan,
9-
Step,
108
StepStatus,
119
AgentType,
12-
PlanMessage,
1310
PlanApprovalRequest,
1411
PlanApprovalResponse,
15-
AgentMessageData
12+
AgentMessageData,
13+
MPlanData,
14+
AgentMessageBE,
15+
MPlanBE,
16+
TeamConfigurationBE,
17+
PlanFromAPI
1618
} from '../models';
1719

1820
// Constants for endpoints
@@ -122,7 +124,7 @@ export class APIService {
122124
* @param useCache Whether to use cached data or force fresh fetch
123125
* @returns Promise with array of plans with their steps
124126
*/
125-
async getPlans(sessionId?: string, useCache = true): Promise<PlanWithSteps[]> {
127+
async getPlans(sessionId?: string, useCache = true): Promise<Plan[]> {
126128
const cacheKey = `plans_${sessionId || 'all'}`;
127129
const params = sessionId ? { session_id: sessionId } : {};
128130
// TODO replace session for team_id
@@ -147,7 +149,7 @@ export class APIService {
147149
* @param useCache Whether to use cached data or force fresh fetch
148150
* @returns Promise with the plan and its steps
149151
*/
150-
async getPlanById(planId: string, useCache = true): Promise<{ plan_with_steps: PlanWithSteps; messages: PlanMessage[] }> {
152+
async getPlanById(planId: string, useCache = true): Promise<PlanFromAPI> {
151153
const cacheKey = `plan_by_id_${planId}`;
152154
const params = { plan_id: planId };
153155

@@ -158,17 +160,21 @@ export class APIService {
158160
if (!data) {
159161
throw new Error(`Plan with ID ${planId} not found`);
160162
}
161-
162-
const plan = data[0] as PlanWithSteps;
163-
const messages = data[1] || [];
163+
console.log('Fetched plan by ID:', data);
164+
const results = {
165+
plan: data.plan as Plan,
166+
messages: data.messages as AgentMessageBE[],
167+
m_plan: data.m_plan as MPlanBE | null,
168+
team: data.team as TeamConfigurationBE | null
169+
} as PlanFromAPI;
164170
if (useCache) {
165-
this._cache.set(cacheKey, { plan_with_steps: plan, messages }, 30000); // Cache for 30 seconds
171+
this._cache.set(cacheKey, results, 30000); // Cache for 30 seconds
166172
}
167-
return { plan_with_steps: plan, messages };
173+
return results;
168174
};
169175

170176
if (useCache) {
171-
const cachedPlan = this._cache.get<{ plan_with_steps: PlanWithSteps; messages: PlanMessage[] }>(cacheKey);
177+
const cachedPlan = this._cache.get<PlanFromAPI>(cacheKey);
172178
if (cachedPlan) return cachedPlan;
173179

174180
return this._requestTracker.trackRequest(cacheKey, fetcher);
@@ -184,11 +190,11 @@ export class APIService {
184190
* @param useCache Whether to use cached data or force fresh fetch
185191
* @returns Promise with the plan and its steps
186192
*/
187-
async getPlanWithSteps(sessionId: string, planId: string, useCache = true): Promise<PlanWithSteps> {
193+
async getPlanWithSteps(sessionId: string, planId: string, useCache = true): Promise<Plan> {
188194
const cacheKey = `plan_${sessionId}_${planId}`;
189195

190196
if (useCache) {
191-
const cachedPlan = this._cache.get<PlanWithSteps>(cacheKey);
197+
const cachedPlan = this._cache.get<Plan>(cacheKey);
192198
if (cachedPlan) return cachedPlan;
193199
}
194200

@@ -239,49 +245,6 @@ export class APIService {
239245
});
240246
}
241247

242-
/**
243-
* Get final plan execution results after approval
244-
* @param planId
245-
* @param useCache
246-
* @returns Promise with final plan execution data
247-
*/
248-
async getFinalPlanResults(planId: string, useCache = true): Promise<{ plan_with_steps: PlanWithSteps; messages: PlanMessage[] }> {
249-
const cacheKey = `final_plan_results_${planId}`;
250-
251-
const fetcher = async () => {
252-
console.log('📤 Fetching final plan results for plan_id:', planId);
253-
254-
// ✅ Call /api/plans?plan_id={plan_id} to get executed plan
255-
const data = await apiClient.get(API_ENDPOINTS.PLANS, {
256-
params: { plan_id: planId }
257-
});
258-
259-
if (!data || !Array.isArray(data) || data.length === 0) {
260-
throw new Error(`No plan results found for plan_id: ${planId}`);
261-
}
262-
263-
const plan = data[0] as PlanWithSteps;
264-
const messages = data[1] || [];
265-
266-
if (useCache) {
267-
this._cache.set(cacheKey, { plan_with_steps: plan, messages }, 30000);
268-
}
269-
270-
console.log('✅ Final plan results received:', { plan, messages });
271-
return { plan_with_steps: plan, messages };
272-
};
273-
274-
if (useCache) {
275-
const cachedData = this._cache.get<{ plan_with_steps: PlanWithSteps; messages: PlanMessage[] }>(cacheKey);
276-
if (cachedData) return cachedData;
277-
278-
return this._requestTracker.trackRequest(cacheKey, fetcher);
279-
}
280-
281-
return fetcher();
282-
}
283-
284-
285248

286249
/**
287250
* Submit clarification for a plan

src/frontend/src/components/content/PlanPanelLeft.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
import TaskList from "./TaskList";
2020
import { useCallback, useEffect, useState } from "react";
2121
import { useNavigate, useParams } from "react-router-dom";
22-
import { PlanPanelLefProps, PlanWithSteps, Task, UserInfo } from "@/models";
22+
import { Plan, PlanPanelLefProps, Task, UserInfo } from "@/models";
2323
import { apiService } from "@/api";
2424
import { TaskService } from "@/services";
2525
import MsftColor from "@/coral/imports/MsftColor";
@@ -47,7 +47,7 @@ const PlanPanelLeft: React.FC<PlanPanelLefProps> = ({
4747

4848
const [inProgressTasks, setInProgressTasks] = useState<Task[]>([]);
4949
const [completedTasks, setCompletedTasks] = useState<Task[]>([]);
50-
const [plans, setPlans] = useState<PlanWithSteps[] | null>(null);
50+
const [plans, setPlans] = useState<Plan[] | null>(null);
5151
const [plansLoading, setPlansLoading] = useState<boolean>(false);
5252
const [plansError, setPlansError] = useState<Error | null>(null);
5353
const [userInfo, setUserInfo] = useState<UserInfo | null>(
@@ -119,7 +119,7 @@ const PlanPanelLeft: React.FC<PlanPanelLefProps> = ({
119119
const handleTaskSelect = useCallback(
120120
(taskId: string) => {
121121
const selectedPlan = plans?.find(
122-
(plan: PlanWithSteps) => plan.session_id === taskId
122+
(plan: Plan) => plan.session_id === taskId
123123
);
124124
if (selectedPlan) {
125125
navigate(`/plan/${selectedPlan.id}`);

src/frontend/src/models/agentMessage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface AgentMessageData {
2525
agent_type: AgentMessageType;
2626
timestamp: number;
2727
steps: any[];
28-
next_steps: [];
28+
next_steps: any[];
2929
content: string;
3030
raw_data: string;
3131
}

src/frontend/src/models/enums.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,12 @@ export enum StepStatus {
222222
* Enumeration of possible statuses for a plan.
223223
*/
224224
export enum PlanStatus {
225+
CREATED = "created",
225226
IN_PROGRESS = "in_progress",
226227
COMPLETED = "completed",
227-
FAILED = "failed"
228+
FAILED = "failed",
229+
CANCELED = "canceled",
230+
APPROVED = "approved"
228231
}
229232

230233
/**

src/frontend/src/models/messages.tsx

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,7 @@
11
import { AgentType, StepStatus, PlanStatus, WebsocketMessageType } from './enums';
22
import { MPlanData } from './plan';
33

4-
/**
5-
* Message roles compatible with Semantic Kernel
6-
* Currently unused but kept for potential future use
7-
*/
8-
// export enum MessageRole {
9-
// SYSTEM = "system",
10-
// USER = "user",
11-
// ASSISTANT = "assistant",
12-
// FUNCTION = "function"
13-
// }
144

15-
/**
16-
* Base class for generic chat messages with roles
17-
* Currently unused but kept for potential future use with Semantic Kernel integration
18-
*/
19-
// export interface GenericChatMessage {
20-
// /** Role of the message sender */
21-
// role: MessageRole;
22-
// /** Content of the message */
23-
// content: string;
24-
// /** Additional metadata */
25-
// metadata: Record<string, any>;
26-
// }
275

286
/**
297
* Message sent to request approval for a step

0 commit comments

Comments
 (0)