@@ -38,12 +38,11 @@ export class AIAssistantController extends Controller {
3838
3939 private getCustomizedResponseTitle (
4040 status : MessageStatus . Success | MessageStatus . Failure ,
41- commandNames : GridCommand [ 'name' ] [ ] ,
41+ commandNames : string [ ] ,
4242 ) : string {
4343 // TODO: remove type description, it should be got from d.ts
4444 const customizeResponseTitle = this . option ( 'aiAssistant.customizeResponseTitle' ) as CustomizeResponseTitle | undefined ;
4545
46- // There shouldn't be an empty array here, but we need to handle it anyway.
4746 if ( ! commandNames . length ) {
4847 return messageLocalization . format ( 'dxDataGrid-aiAssistantErrorMessage' ) ;
4948 }
@@ -63,7 +62,7 @@ export class AIAssistantController extends Controller {
6362 ] . join ( ' and ' ) ;
6463 }
6564
66- private getCommandNames ( actions : ExecuteGridAssistantAction [ ] ) : GridCommand [ 'name' ] [ ] {
65+ private getCommandNames ( actions : ExecuteGridAssistantAction [ ] ) : string [ ] {
6766 const commandNames = actions . map ( ( { name } ) => name ) ;
6867 const uniqueCommandNameSet = new Set ( commandNames ) ;
6968
@@ -131,7 +130,7 @@ export class AIAssistantController extends Controller {
131130 private completeAIMessage (
132131 messageId : string ,
133132 commands : CommandResult [ ] ,
134- commandNames : GridCommand [ 'name' ] [ ] ,
133+ commandNames : string [ ] ,
135134 ) : void {
136135 const messageStatus = hasCommandErrors ( commands )
137136 ? MessageStatus . Failure
@@ -174,10 +173,16 @@ export class AIAssistantController extends Controller {
174173 } ) ;
175174 }
176175
177- private sendRequestToAICore ( aiMessage : AIMessage ) : Promise < void > {
176+ private withProcessing ( promise : Promise < void > ) : Promise < void > {
178177 this . setProcessing ( true ) ;
179178
180- return new Promise ( ( resolve , reject ) => {
179+ return promise . finally ( ( ) => {
180+ this . setProcessing ( false ) ;
181+ } ) ;
182+ }
183+
184+ private sendRequestToAICore ( aiMessage : AIMessage ) : Promise < void > {
185+ return this . withProcessing ( new Promise < void > ( ( resolve , reject ) => {
181186 const responseSchema = this . gridCommands ?. buildResponseSchema ( ) ;
182187 const extraContext = this . getGridExtraContext ( ) ;
183188
@@ -186,7 +191,6 @@ export class AIAssistantController extends Controller {
186191 const error = new Error ( 'Grid commands not initialized' ) ;
187192
188193 this . failAIMessage ( aiMessage . id , error ) ;
189- this . setProcessing ( false ) ;
190194 reject ( error ) ;
191195 return ;
192196 }
@@ -202,36 +206,32 @@ export class AIAssistantController extends Controller {
202206 const commandNames = this . getCommandNames ( response . actions ) ;
203207
204208 this . completeAIMessage ( aiMessage . id , commands , commandNames ) ;
205- this . setProcessing ( false ) ;
206209 resolve ( ) ;
207210 } )
208211 . fail ( ( errorMessage ) => {
209- // TODO: Change error message
212+ // TODO: Change error message
210213 const error = errorMessage instanceof Error
211214 ? errorMessage
212215 : new Error ( String ( errorMessage ) ) ;
213216
214217 this . failAIMessage ( aiMessage . id , error ) ;
215- this . setProcessing ( false ) ;
216218 reject ( error ) ;
217219 } ) ;
218220 } ,
219221 onError : ( error : Error ) : void => {
220- // TODO: Change error message
222+ // TODO: Change error message
221223 this . failAIMessage ( aiMessage . id , error ) ;
222- this . setProcessing ( false ) ;
223224 reject ( error ) ;
224225 } ,
225226 onAbort : ( ) : void => {
226227 const error = new Error ( messageLocalization . format ( 'dxDataGrid-aiAssistantAbortMessage' ) ) ;
227228
228229 this . failAIMessage ( aiMessage . id , error ) ;
229- this . setProcessing ( false ) ;
230230 reject ( error ) ;
231231 } ,
232232 } ,
233233 ) ;
234- } ) ;
234+ } ) ) ;
235235 }
236236
237237 protected getGridCommandList ( ) : GridCommand [ ] {
@@ -243,7 +243,6 @@ export class AIAssistantController extends Controller {
243243 }
244244
245245 public init ( ) : void {
246- // TODO: initialize default commands list when they are ready
247246 this . gridCommands = new GridCommands ( this . component , this . getGridCommandList ( ) ) ;
248247 this . messageStore = new ArrayStore < Message , string > ( {
249248 key : 'id' ,
0 commit comments