@@ -53,10 +53,7 @@ export class ExtensionChannel extends BaseChannel<
5353		this . setupListeners ( ) 
5454	} 
5555
56- 	/** 
57- 	 * Handle extension-specific commands from the web app 
58- 	 */ 
59- 	public  handleCommand ( command : ExtensionBridgeCommand ) : void { 
56+ 	public  async  handleCommand ( command : ExtensionBridgeCommand ) : Promise < void >  { 
6057		if  ( command . instanceId  !==  this . instanceId )  { 
6158			console . log ( `[ExtensionChannel] command -> instance id mismatch | ${ this . instanceId }  ,  { 
6259				messageInstanceId : command . instanceId , 
@@ -69,13 +66,22 @@ export class ExtensionChannel extends BaseChannel<
6966				console . log ( `[ExtensionChannel] command -> createTask() | ${ command . instanceId }  ,  { 
7067					text : command . payload . text ?. substring ( 0 ,  100 )  +  "..." , 
7168					hasImages : ! ! command . payload . images , 
69+ 					mode : command . payload . mode , 
70+ 					providerProfile : command . payload . providerProfile , 
7271				} ) 
7372
74- 				this . provider . createTask ( command . payload . text ,  command . payload . images ) 
73+ 				this . provider . createTask ( 
74+ 					command . payload . text , 
75+ 					command . payload . images , 
76+ 					undefined ,  // parentTask 
77+ 					undefined ,  // options 
78+ 					{  mode : command . payload . mode ,  currentApiConfigName : command . payload . providerProfile  } , 
79+ 				) 
80+ 
7581				break 
7682			} 
7783			case  ExtensionBridgeCommandName . StopTask : { 
78- 				const  instance  =  this . updateInstance ( ) 
84+ 				const  instance  =  await   this . updateInstance ( ) 
7985
8086				if  ( instance . task . taskStatus  ===  TaskStatus . Running )  { 
8187					console . log ( `[ExtensionChannel] command -> cancelTask() | ${ command . instanceId }  ) 
@@ -86,14 +92,14 @@ export class ExtensionChannel extends BaseChannel<
8692					this . provider . clearTask ( ) 
8793					this . provider . postStateToWebview ( ) 
8894				} 
95+ 
8996				break 
9097			} 
9198			case  ExtensionBridgeCommandName . ResumeTask : { 
9299				console . log ( `[ExtensionChannel] command -> resumeTask() | ${ command . instanceId }  ,  { 
93100					taskId : command . payload . taskId , 
94101				} ) 
95102
96- 				// Resume the task from history by taskId 
97103				this . provider . resumeTask ( command . payload . taskId ) 
98104				this . provider . postStateToWebview ( ) 
99105				break 
@@ -122,20 +128,20 @@ export class ExtensionChannel extends BaseChannel<
122128	} 
123129
124130	private  async  registerInstance ( _socket : Socket ) : Promise < void >  { 
125- 		const  instance  =  this . updateInstance ( ) 
131+ 		const  instance  =  await   this . updateInstance ( ) 
126132		await  this . publish ( ExtensionSocketEvents . REGISTER ,  instance ) 
127133	} 
128134
129135	private  async  unregisterInstance ( _socket : Socket ) : Promise < void >  { 
130- 		const  instance  =  this . updateInstance ( ) 
136+ 		const  instance  =  await   this . updateInstance ( ) 
131137		await  this . publish ( ExtensionSocketEvents . UNREGISTER ,  instance ) 
132138	} 
133139
134140	private  startHeartbeat ( socket : Socket ) : void { 
135141		this . stopHeartbeat ( ) 
136142
137143		this . heartbeatInterval  =  setInterval ( async  ( )  =>  { 
138- 			const  instance  =  this . updateInstance ( ) 
144+ 			const  instance  =  await   this . updateInstance ( ) 
139145
140146			try  { 
141147				socket . emit ( ExtensionSocketEvents . HEARTBEAT ,  instance ) 
@@ -172,11 +178,11 @@ export class ExtensionChannel extends BaseChannel<
172178		]  as  const 
173179
174180		eventMapping . forEach ( ( {  from,  to } )  =>  { 
175- 			// Create and store the listener function for cleanup/  
176- 			const  listener  =  ( ..._args : unknown [ ] )  =>  { 
181+ 			// Create and store the listener function for cleanup.  
182+ 			const  listener  =  async   ( ..._args : unknown [ ] )  =>  { 
177183				this . publish ( ExtensionSocketEvents . EVENT ,  { 
178184					type : to , 
179- 					instance : this . updateInstance ( ) , 
185+ 					instance : await   this . updateInstance ( ) , 
180186					timestamp : Date . now ( ) , 
181187				} ) 
182188			} 
@@ -195,10 +201,16 @@ export class ExtensionChannel extends BaseChannel<
195201		this . eventListeners . clear ( ) 
196202	} 
197203
198- 	private  updateInstance ( ) : ExtensionInstance  { 
204+ 	private  async   updateInstance ( ) : Promise < ExtensionInstance >  { 
199205		const  task  =  this . provider ?. getCurrentTask ( ) 
200206		const  taskHistory  =  this . provider ?. getRecentTasks ( )  ??  [ ] 
201207
208+ 		const  mode  =  await  this . provider ?. getMode ( ) 
209+ 		const  modes  =  ( await  this . provider ?. getModes ( ) )  ??  [ ] 
210+ 
211+ 		const  providerProfile  =  await  this . provider ?. getProviderProfile ( ) 
212+ 		const  providerProfiles  =  ( await  this . provider ?. getProviderProfiles ( ) )  ??  [ ] 
213+ 
202214		this . extensionInstance  =  { 
203215			...this . extensionInstance , 
204216			appProperties : this . extensionInstance . appProperties  ??  this . provider . appProperties , 
@@ -213,6 +225,10 @@ export class ExtensionChannel extends BaseChannel<
213225				: {  taskId : "" ,  taskStatus : TaskStatus . None  } , 
214226			taskAsk : task ?. taskAsk , 
215227			taskHistory, 
228+ 			mode, 
229+ 			providerProfile, 
230+ 			modes, 
231+ 			providerProfiles, 
216232		} 
217233
218234		return  this . extensionInstance 
0 commit comments