Skip to content

Commit 3927cb5

Browse files
committed
getting the plan messages
1 parent 8f5697c commit 3927cb5

File tree

5 files changed

+39
-17
lines changed

5 files changed

+39
-17
lines changed

src/backend/app_kernel.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,12 +519,12 @@ async def approve_step_endpoint(
519519
return {"status": "All steps approved"}
520520

521521

522-
@app.get("/api/plans", response_model=List[PlanWithSteps])
522+
@app.get("/api/plans")
523523
async def get_plans(
524524
request: Request,
525525
session_id: Optional[str] = Query(None),
526526
plan_id: Optional[str] = Query(None),
527-
) -> List[PlanWithSteps]:
527+
):
528528
"""
529529
Retrieve plans for the current user.
530530
@@ -620,9 +620,12 @@ async def get_plans(
620620

621621
# Use get_steps_by_plan to match the original implementation
622622
steps = await memory_store.get_steps_by_plan(plan_id=plan.id)
623+
messages = await memory_store.get_data_by_type_and_plan_id(
624+
"agent_message", plan_id=plan.id
625+
)
623626
plan_with_steps = PlanWithSteps(**plan.model_dump(), steps=steps)
624627
plan_with_steps.update_step_counts()
625-
return [plan_with_steps]
628+
return [plan_with_steps, messages]
626629

627630
all_plans = await memory_store.get_all_plans()
628631
# Fetch steps for all plans concurrently

src/frontend_react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "frontend_react",
2+
"name": "Multi Agent frontend",
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {

src/frontend_react/src/api/apiService.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
Plan,
99
Step,
1010
StepStatus,
11-
AgentType
11+
AgentType,
12+
PlanMessage
1213
} from '../models';
1314

1415
// Constants for endpoints
@@ -137,27 +138,28 @@ export class APIService {
137138
* @param useCache Whether to use cached data or force fresh fetch
138139
* @returns Promise with the plan and its steps
139140
*/
140-
async getPlanById(planId: string, useCache = true): Promise<PlanWithSteps> {
141+
async getPlanById(planId: string, useCache = true): Promise<{ plan_with_steps: PlanWithSteps; messages: PlanMessage[] }> {
141142
const cacheKey = `plan_by_id_${planId}`;
142143
const params = { plan_id: planId };
143144

144145
const fetcher = async () => {
145146
const data = await apiClient.get(API_ENDPOINTS.PLANS, { params });
146147

147148
// The API returns an array, but with plan_id filter it should have only one item
148-
if (!data || data.length === 0) {
149+
if (!data) {
149150
throw new Error(`Plan with ID ${planId} not found`);
150151
}
151152

152-
const plan = data[0];
153+
const plan = data[0] as PlanWithSteps;
154+
const messages = data[1] || [];
153155
if (useCache) {
154-
this._cache.set(cacheKey, plan, 30000); // Cache for 30 seconds
156+
this._cache.set(cacheKey, { plan_with_steps: plan, messages }, 30000); // Cache for 30 seconds
155157
}
156-
return plan;
158+
return { plan_with_steps: plan, messages };
157159
};
158160

159161
if (useCache) {
160-
const cachedPlan = this._cache.get<PlanWithSteps>(cacheKey);
162+
const cachedPlan = this._cache.get<{ plan_with_steps: PlanWithSteps; messages: PlanMessage[] }>(cacheKey);
161163
if (cachedPlan) return cachedPlan;
162164

163165
return this._requestTracker.trackRequest(cacheKey, fetcher);

src/frontend_react/src/models/plan.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,22 @@ export interface Step extends BaseModel {
6161
/** Optional updated action */
6262
updated_action?: string;
6363
}
64-
64+
export interface PlanMessage extends BaseModel {
65+
/** The type of data model */
66+
data_type: "agent_message";
67+
/** Session identifier */
68+
session_id: string;
69+
/** User identifier */
70+
user_id: string;
71+
/** Plan identifier */
72+
plan_id: string;
73+
/** Message content */
74+
content: string;
75+
/** Source of the message */
76+
source: string;
77+
/** Step identifier */
78+
step_id: string;
79+
}
6580
/**
6681
* Represents a plan that includes its associated steps.
6782
*/
@@ -95,6 +110,7 @@ export interface ProcessedPlanData {
95110
agents: AgentType[];
96111
steps: Step[];
97112
hasHumanClarificationRequest: boolean;
113+
messages: PlanMessage[];
98114
}
99115

100116
export interface PlanChatProps {

src/frontend_react/src/services/PlanDataService.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PlanWithSteps, Step, AgentType, ProcessedPlanData } from '@/models';
1+
import { PlanWithSteps, Step, AgentType, ProcessedPlanData, PlanMessage } from '@/models';
22
import { apiService } from '@/api';
33

44

@@ -13,8 +13,8 @@ export class PlanDataService { /**
1313
static async fetchPlanData(planId: string): Promise<ProcessedPlanData> {
1414
try {
1515
// Use optimized getPlanById method for better performance
16-
const plan = await apiService.getPlanById(planId);
17-
return this.processPlanData(plan);
16+
const planBody = await apiService.getPlanById(planId);
17+
return this.processPlanData(planBody.plan_with_steps, planBody.messages || []);
1818
} catch (error) {
1919
console.error('Failed to fetch plan data:', error);
2020
throw error;
@@ -26,7 +26,7 @@ export class PlanDataService { /**
2626
* @param plan PlanWithSteps object to process
2727
* @returns Processed plan data
2828
*/
29-
static processPlanData(plan: PlanWithSteps): ProcessedPlanData {
29+
static processPlanData(plan: PlanWithSteps, messages: PlanMessage[]): ProcessedPlanData {
3030
// Extract unique agents from steps
3131
const uniqueAgents = new Set<AgentType>();
3232
plan.steps.forEach(step => {
@@ -49,7 +49,8 @@ export class PlanDataService { /**
4949
plan,
5050
agents,
5151
steps,
52-
hasHumanClarificationRequest
52+
hasHumanClarificationRequest,
53+
messages
5354
};
5455
}
5556

0 commit comments

Comments
 (0)