@@ -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
0 commit comments