@@ -450,8 +450,13 @@ export class FeatureDevController {
450450 // Finish processing the event
451451
452452 if ( session ?. state ?. tokenSource ?. token . isCancellationRequested ) {
453+ this . workOnNewTask (
454+ session ,
455+ session . state . codeGenerationRemainingIterationCount || session . state ?. currentIteration ,
456+ session . state . codeGenerationTotalIterationCount ,
457+ session ?. state ?. tokenSource ?. token . isCancellationRequested
458+ )
453459 this . disposeToken ( session )
454- this . workOnNewTask ( session )
455460 } else {
456461 this . messenger . sendAsyncEventProgress ( tabID , false , undefined )
457462
@@ -472,28 +477,41 @@ export class FeatureDevController {
472477 }
473478 }
474479 }
475- private workOnNewTask ( message : any ) {
476- this . messenger . sendAnswer ( {
477- message : i18n ( 'AWS.amazonq.featureDev.pillText.stoppedCodeGeneration' ) ,
478- type : 'answer-part' ,
479- tabID : message . tabID ,
480- } )
481- this . messenger . sendAnswer ( {
482- type : 'system-prompt' ,
483- tabID : message . tabID ,
484- followUps : [
485- {
486- pillText : i18n ( 'AWS.amazonq.featureDev.pillText.newTask' ) ,
487- type : FollowUpTypes . NewTask ,
488- status : 'info' ,
489- } ,
490- {
491- pillText : i18n ( 'AWS.amazonq.featureDev.pillText.closeSession' ) ,
492- type : FollowUpTypes . CloseSession ,
493- status : 'info' ,
494- } ,
495- ] ,
496- } )
480+ private workOnNewTask (
481+ message : any ,
482+ remainingIterations ?: number ,
483+ totalIterations ?: number ,
484+ isStoppedGeneration : boolean = false
485+ ) {
486+ if ( isStoppedGeneration ) {
487+ this . messenger . sendAnswer ( {
488+ message :
489+ remainingIterations === 0
490+ ? "I stopped generating your code. You don't have more iterations left, however, you can start a new session."
491+ : `I stopped generating your code. If you want to continue working on this task, provide another description. ${ ! totalIterations ? `You have started ${ remainingIterations } code generations.` : `You have ${ remainingIterations } out of ${ totalIterations } code generations left.` } ` ,
492+ type : 'answer-part' ,
493+ tabID : message . tabID ,
494+ } )
495+ }
496+
497+ if ( ( remainingIterations === 0 && isStoppedGeneration ) || ! isStoppedGeneration ) {
498+ this . messenger . sendAnswer ( {
499+ type : 'system-prompt' ,
500+ tabID : message . tabID ,
501+ followUps : [
502+ {
503+ pillText : i18n ( 'AWS.amazonq.featureDev.pillText.newTask' ) ,
504+ type : FollowUpTypes . NewTask ,
505+ status : 'info' ,
506+ } ,
507+ {
508+ pillText : i18n ( 'AWS.amazonq.featureDev.pillText.closeSession' ) ,
509+ type : FollowUpTypes . CloseSession ,
510+ status : 'info' ,
511+ } ,
512+ ] ,
513+ } )
514+ }
497515
498516 // Ensure that chat input is enabled so that they can provide additional iterations if they choose
499517 this . messenger . sendChatInputEnabled ( message . tabID , true )
@@ -528,7 +546,11 @@ export class FeatureDevController {
528546 canBeVoted : true ,
529547 } )
530548
531- this . workOnNewTask ( message )
549+ this . workOnNewTask (
550+ message ,
551+ session . state . codeGenerationRemainingIterationCount ,
552+ session . state . codeGenerationTotalIterationCount
553+ )
532554 } catch ( err : any ) {
533555 this . messenger . sendErrorMessage (
534556 createUserFacingErrorMessage ( `Failed to insert code changes: ${ err . message } ` ) ,
0 commit comments