Skip to content

Commit aba1566

Browse files
author
David Hasani
committed
feat(amazonq): ask user for permission to rerun job
1 parent 3f45c37 commit aba1566

File tree

5 files changed

+111
-22
lines changed

5 files changed

+111
-22
lines changed

packages/core/src/amazonqGumby/chat/controller/controller.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
validateCanCompileProject,
2929
getValidSQLConversionCandidateProjects,
3030
openHilPomFile,
31+
getFeedbackCommentData,
3132
} from '../../../codewhisperer/commands/startTransformByQ'
3233
import { JDKVersion, TransformationCandidateProject, transformByQState } from '../../../codewhisperer/models/model'
3334
import {
@@ -61,6 +62,7 @@ import {
6162
validateSQLMetadataFile,
6263
} from '../../../codewhisperer/service/transformByQ/transformFileHandler'
6364
import { getAuthType } from '../../../auth/utils'
65+
import globals from '../../../shared/extensionGlobals'
6466

6567
// These events can be interactions within the chat,
6668
// or elsewhere in the IDE
@@ -370,15 +372,12 @@ export class GumbyController {
370372
case ButtonActions.CONFIRM_SKIP_TESTS_FORM:
371373
await this.handleSkipTestsSelection(message)
372374
break
373-
case ButtonActions.CANCEL_SKIP_TESTS_FORM:
374-
this.messenger.sendJobFinishedMessage(message.tabID, CodeWhispererConstants.jobCancelledChatMessage)
375+
case ButtonActions.CONFIRM_FEEDBACK_FORM:
376+
await this.handleFeedback(message)
375377
break
376378
case ButtonActions.CONFIRM_SELECTIVE_TRANSFORMATION_FORM:
377379
await this.handleOneOrMultipleDiffs(message)
378380
break
379-
case ButtonActions.CANCEL_SELECTIVE_TRANSFORMATION_FORM:
380-
this.messenger.sendJobFinishedMessage(message.tabID, CodeWhispererConstants.jobCancelledChatMessage)
381-
break
382381
case ButtonActions.CONFIRM_SQL_CONVERSION_TRANSFORMATION_FORM:
383382
await this.handleUserSQLConversionProjectSelection(message)
384383
break
@@ -640,6 +639,17 @@ export class GumbyController {
640639
}
641640
}
642641

642+
private async handleFeedback(message: any) {
643+
const canRerunJob = message.formSelectedValues['TransformFeedbackRerunJob']
644+
const canViewLogs = message.formSelectedValues['TransformFeedbackViewLogs']
645+
const comment = `Permission to re-run job: ${canRerunJob}\nPermission to view logs: ${canViewLogs}\n${getFeedbackCommentData()}`
646+
this.messenger.sendFeedbackReceivedMessage(canRerunJob, canViewLogs, message.tabID)
647+
if (comment.toLowerCase().includes('yes')) {
648+
// post feedback if user says yes to at least one of the questions
649+
await globals.telemetry.postFeedback({ comment: comment, sentiment: 'Positive' })
650+
}
651+
}
652+
643653
private resetTransformationChatFlow() {
644654
this.sessionStorage.getSession().conversationState = ConversationState.IDLE
645655
}

packages/core/src/amazonqGumby/chat/controller/messenger/messenger.ts

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ export class Messenger {
124124
title: CodeWhispererConstants.skipUnitTestsFormTitle,
125125
mandatory: true,
126126
options: [
127-
{
128-
value: CodeWhispererConstants.runUnitTestsMessage,
129-
label: CodeWhispererConstants.runUnitTestsMessage,
130-
},
131127
{
132128
value: CodeWhispererConstants.skipUnitTestsMessage,
133129
label: CodeWhispererConstants.skipUnitTestsMessage,
134130
},
131+
{
132+
value: CodeWhispererConstants.runUnitTestsMessage,
133+
label: CodeWhispererConstants.runUnitTestsMessage,
134+
},
135135
],
136136
})
137137

@@ -552,6 +552,12 @@ export class Messenger {
552552
tabID
553553
)
554554
)
555+
556+
// TO-DO: make this `isPartiallySucceeded`
557+
if (transformByQState.isSucceeded() && message == CodeWhispererConstants.viewProposedChangesChatMessage) {
558+
// get permission to re-run job and view logs after partially successful job is downloaded
559+
this.sendFeedbackFormMessage(tabID)
560+
}
555561
}
556562

557563
public sendTransformationIntroduction(tabID: string) {
@@ -799,4 +805,64 @@ ${codeSnippet}
799805
)
800806
)
801807
}
808+
809+
public sendFeedbackFormMessage(tabID: string) {
810+
const formItems: ChatItemFormItem[] = []
811+
formItems.push({
812+
id: 'TransformFeedbackRerunJob',
813+
type: 'radiogroup',
814+
title: 'To improve our service, do we have permission to re-run your job? (you will *not* be charged)',
815+
mandatory: true,
816+
options: [
817+
{
818+
value: 'Yes',
819+
label: 'Yes',
820+
},
821+
{
822+
value: 'No',
823+
label: 'No',
824+
},
825+
],
826+
})
827+
828+
formItems.push({
829+
id: 'TransformFeedbackViewLogs',
830+
type: 'radiogroup',
831+
title: 'Do we also have permission to view the logs associated with your job?',
832+
mandatory: true,
833+
options: [
834+
{
835+
value: 'Yes',
836+
label: 'Yes',
837+
},
838+
{
839+
value: 'No',
840+
label: 'No',
841+
},
842+
],
843+
})
844+
845+
this.dispatcher.sendChatPrompt(
846+
new ChatPrompt(
847+
{
848+
message: 'Amazon Q Feedback Form',
849+
formItems: formItems,
850+
},
851+
'FeedbackForm',
852+
tabID,
853+
true
854+
)
855+
)
856+
}
857+
858+
public sendFeedbackReceivedMessage(canRerunJob: string, canViewLogs: string, tabID: string) {
859+
const message = `### Feedback received
860+
-------------
861+
| | |
862+
| :------------------- | -------: |
863+
| **Permission to re-run job** | ${canRerunJob} |
864+
| **Permission to view logs** | ${canViewLogs} |
865+
`
866+
this.dispatcher.sendChatMessage(new ChatMessage({ message, messageType: 'prompt' }, tabID))
867+
}
802868
}

packages/core/src/amazonqGumby/chat/controller/messenger/messengerUtils.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ export enum ButtonActions {
1818
CONFIRM_SQL_CONVERSION_TRANSFORMATION_FORM = 'gumbySQLConversionTransformFormConfirm',
1919
CANCEL_TRANSFORMATION_FORM = 'gumbyTransformFormCancel', // shared between Language Upgrade & SQL Conversion
2020
CONFIRM_SKIP_TESTS_FORM = 'gumbyTransformSkipTestsFormConfirm',
21-
CANCEL_SKIP_TESTS_FORM = 'gumbyTransformSkipTestsFormCancel',
21+
CONFIRM_FEEDBACK_FORM = 'gumbyFeedbackFormConfirm',
2222
CONFIRM_SELECTIVE_TRANSFORMATION_FORM = 'gumbyTransformOneOrMultipleDiffsFormConfirm',
23-
CANCEL_SELECTIVE_TRANSFORMATION_FORM = 'gumbyTransformOneOrMultipleDiffsFormCancel',
2423
SELECT_SQL_CONVERSION_METADATA_FILE = 'gumbySQLConversionMetadataTransformFormConfirm',
2524
CONFIRM_DEPENDENCY_FORM = 'gumbyTransformDependencyFormConfirm',
2625
CANCEL_DEPENDENCY_FORM = 'gumbyTransformDependencyFormCancel',
2726
CONFIRM_JAVA_HOME_FORM = 'gumbyJavaHomeFormConfirm',
28-
CANCEL_JAVA_HOME_FORM = 'gumbyJavaHomeFormCancel',
2927
CONFIRM_START_TRANSFORMATION_FLOW = 'gumbyStartTransformation',
3028
OPEN_FILE = 'gumbyOpenFile',
3129
OPEN_BUILD_LOG = 'gumbyOpenBuildLog',

packages/core/src/codewhisperer/commands/startTransformByQ.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ import { convertDateToTimestamp } from '../../shared/datetime'
8181
import { findStringInDirectory } from '../../shared/utilities/workspaceUtils'
8282
import { makeTemporaryToolkitFolder } from '../../shared/filesystemUtilities'
8383

84-
function getFeedbackCommentData() {
84+
export function getFeedbackCommentData() {
8585
const jobId = transformByQState.getJobId()
8686
const s = `Q CodeTransform jobId: ${jobId ? jobId : 'none'}`
8787
return s
@@ -510,14 +510,19 @@ export async function startTransformationJob(uploadId: string, transformStartTim
510510
})
511511
} catch (error) {
512512
getLogger().error(`CodeTransformation: ${CodeWhispererConstants.failedToStartJobNotification}`, error)
513-
const errorMessage = (error as Error).message
513+
const errorMessage = (error as Error).message.toLowerCase()
514514
if (errorMessage.includes('too many active running jobs')) {
515515
transformByQState.setJobFailureErrorNotification(
516-
CodeWhispererConstants.failedToStartJobTooManyJobsNotification
516+
CodeWhispererConstants.tooManyJobsNotification
517+
// TO-DO: change this text (and the ones below) to link to the docs around limits
518+
// https://issues.amazon.com/issues/V1679684569
517519
)
518-
transformByQState.setJobFailureErrorChatMessage(
519-
CodeWhispererConstants.failedToStartJobTooManyJobsChatMessage
520+
transformByQState.setJobFailureErrorChatMessage(CodeWhispererConstants.tooManyJobsChatMessage)
521+
} else if (errorMessage.includes('lines of code limit breached')) {
522+
transformByQState.setJobFailureErrorNotification(
523+
CodeWhispererConstants.linesOfCodeLimitBreachedNotification
520524
)
525+
transformByQState.setJobFailureErrorChatMessage(CodeWhispererConstants.linesOfCodeLimitBreachedChatMessage)
521526
} else {
522527
transformByQState.setJobFailureErrorNotification(
523528
`${CodeWhispererConstants.failedToStartJobNotification} ${errorMessage}`
@@ -584,8 +589,12 @@ export async function pollTransformationStatusUntilPlanReady(jobId: string) {
584589
} catch (error) {
585590
// means API call failed
586591
getLogger().error(`CodeTransformation: ${CodeWhispererConstants.failedToCompleteJobNotification}`, error)
587-
transformByQState.setJobFailureErrorNotification(CodeWhispererConstants.failedToGetPlanNotification)
588-
transformByQState.setJobFailureErrorChatMessage(CodeWhispererConstants.failedToGetPlanChatMessage)
592+
transformByQState.setJobFailureErrorNotification(
593+
`${CodeWhispererConstants.failedToGetPlanNotification} ${(error as Error).message}`
594+
)
595+
transformByQState.setJobFailureErrorChatMessage(
596+
`${CodeWhispererConstants.failedToGetPlanChatMessage} ${(error as Error).message}`
597+
)
589598
throw new Error('Get plan failed')
590599
}
591600

packages/core/src/codewhisperer/models/constants.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,12 +611,18 @@ export const failedToStartJobChatMessage =
611611
export const failedToStartJobNotification =
612612
'Amazon Q could not begin the transformation. Please try starting the transformation again.'
613613

614-
export const failedToStartJobTooManyJobsChatMessage =
614+
export const tooManyJobsChatMessage =
615615
"Sorry, I couldn't begin the transformation. You have too many active transformations running. Please try again after your other transformations have completed."
616616

617-
export const failedToStartJobTooManyJobsNotification =
617+
export const tooManyJobsNotification =
618618
'Amazon Q could not begin the transformation. You have too many active transformations running. Please try again after your other transformations have completed.'
619619

620+
export const linesOfCodeLimitBreachedChatMessage =
621+
"Sorry, I couldn't begin the transformation. You have exceeded the lines of code limit for your plan."
622+
623+
export const linesOfCodeLimitBreachedNotification =
624+
'Amazon Q could not begin the transformation. You have exceeded the lines of code limit for your plan.'
625+
620626
export const failedToUploadProjectChatMessage =
621627
"Sorry, I couldn't upload your project. Please try starting the transformation again."
622628

@@ -643,7 +649,7 @@ export const genericErrorMessage =
643649
'Sorry, I am experiencing technical issues at the moment. Please try again in a few minutes.'
644650

645651
export const jobCancelledChatMessage =
646-
'I cancelled your transformation. If you want to start another transformation, choose **Start a new transformation**.'
652+
'If you want to start another transformation, choose **Start a new transformation**.'
647653

648654
export const jobCancelledNotification = 'You cancelled the transformation.'
649655

0 commit comments

Comments
 (0)