Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export class Connector extends BaseConnector {
body: messageData.message,
canBeVoted: false,
informationCard: messageData.informationCard,
buttons: messageData.buttons ?? [],
}
this.onChatAnswerReceived(messageData.tabID, answer, messageData)
}
Expand Down
59 changes: 54 additions & 5 deletions packages/core/src/amazonqTest/chat/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import MessengerUtils, { ButtonActions } from './messenger/messengerUtils'
import { getTelemetryReasonDesc, isAwsError } from '../../../shared/errors'
import { ChatItemType } from '../../../amazonq/commons/model'
import { ProgressField } from '@aws/mynah-ui'
import { ChatItemButton, MynahIcons, ProgressField } from '@aws/mynah-ui'
import { FollowUpTypes } from '../../../amazonq/commons/types'
import {
cancelBuild,
Expand Down Expand Up @@ -63,6 +63,9 @@ import {
} from '../../../codewhisperer/models/constants'
import { UserWrittenCodeTracker } from '../../../codewhisperer/tracker/userWrittenCodeTracker'
import { ReferenceLogViewProvider } from '../../../codewhisperer/service/referenceLogViewProvider'
import { submitFeedback } from '../../../feedback/vue/submitFeedback'
import { placeholder } from '../../../shared/vscode/commands2'
import { Auth } from '../../../auth/auth'

export interface TestChatControllerEventEmitters {
readonly tabOpened: vscode.EventEmitter<any>
Expand Down Expand Up @@ -299,10 +302,22 @@ export class TestController {
)
if (session.stopIteration) {
// Error from Science
this.messenger.sendMessage(data.error.uiMessage.replaceAll('```', ''), data.tabID, 'answer')
this.messenger.sendMessage(
data.error.uiMessage.replaceAll('```', ''),
data.tabID,
'answer',
'testGenErrorMessage',
this.getFeedbackButtons()
)
} else {
isCancel
? this.messenger.sendMessage(data.error.uiMessage, data.tabID, 'answer')
? this.messenger.sendMessage(
data.error.uiMessage,
data.tabID,
'answer',
'testGenErrorMessage',
this.getFeedbackButtons()
)
: this.sendErrorMessage(data)
}
await this.sessionCleanUp()
Expand All @@ -322,7 +337,9 @@ export class TestController {
return this.messenger.sendMessage(
i18n('AWS.amazonq.featureDev.error.monthlyLimitReached'),
tabID,
'answer'
'answer',
'testGenErrorMessage',
this.getFeedbackButtons()
)
}
if (error.message.includes('Too many requests')) {
Expand Down Expand Up @@ -354,6 +371,7 @@ export class TestController {
// This function handles actions if user clicked on any Button one of these cases will be executed
private async handleFormActionClicked(data: any) {
const typedAction = MessengerUtils.stringToEnumValue(ButtonActions, data.action as any)
let getFeedbackCommentData = ''
switch (typedAction) {
case ButtonActions.STOP_TEST_GEN:
testGenState.setToCancelling()
Expand All @@ -366,6 +384,16 @@ export class TestController {
this.messenger.sendChatInputEnabled(data.tabID, true)
await this.sessionCleanUp()
break
case ButtonActions.PROVIDE_FEEDBACK:
getFeedbackCommentData = `Q Test Generation: RequestId: ${this.sessionStorage.getSession().startTestGenerationRequestId}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can we add Job Id if available?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jobId may or may not be available in most of the cases. Taking these things into consideration, I opted out mentioning this as part of ticket process.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah agreed...but thought it would be useful to add in case of availability.

void submitFeedback(placeholder, 'Amazon Q', getFeedbackCommentData)
telemetry.ui_click.emit({ elementId: 'unitTestGeneration_provideFeedback' })
this.messenger.sendMessage(
'Unit test generation completed. Thanks for providing feedback.',
data.tabID,
'answer'
)
break
}
}
// This function handles actions if user gives any input from the chatInput box
Expand Down Expand Up @@ -395,6 +423,21 @@ export class TestController {
}
}

private getFeedbackButtons(): ChatItemButton[] {
const buttons: ChatItemButton[] = []
if (Auth.instance.isInternalAmazonUser()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with external user/Builder Id?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, both @ankit-sharma90 and I tested this scenario.

buttons.push({
keepCardAfterClick: false,
text: 'How can we make /test better?',
id: ButtonActions.PROVIDE_FEEDBACK,
disabled: false, // allow button to be re-clicked
position: 'outside',
icon: 'comment' as MynahIcons,
})
}
return buttons
}

/**
* Start Test Generation and show the code results
*/
Expand Down Expand Up @@ -897,7 +940,13 @@ export class TestController {

// TODO: Check if there are more cases to endSession if yes create a enum or type for step
private async endSession(data: any, step: FollowUpTypes) {
this.messenger.sendMessage('Unit test generation completed.', data.tabID, 'answer')
this.messenger.sendMessage(
'Unit test generation completed.',
data.tabID,
'answer',
'testGenEndSessionMessage',
this.getFeedbackButtons()
)

const session = this.sessionStorage.getSession()
if (step === FollowUpTypes.RejectCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
UpdatePromptProgressMessage,
} from '../../views/connector/connector'
import { ChatItemType } from '../../../../amazonq/commons/model'
import { ChatItemAction, ProgressField } from '@aws/mynah-ui'
import { ChatItemAction, ChatItemButton, ProgressField } from '@aws/mynah-ui'
import * as CodeWhispererConstants from '../../../../codewhisperer/models/constants'
import { TriggerPayload } from '../../../../codewhispererChat/controllers/chat/model'
import {
Expand Down Expand Up @@ -76,8 +76,16 @@ export class Messenger {
this.dispatcher.sendChatMessage(new CapabilityCardMessage(params.tabID))
}

public sendMessage(message: string, tabID: string, messageType: ChatItemType) {
this.dispatcher.sendChatMessage(new ChatMessage({ message, messageType }, tabID))
public sendMessage(
message: string,
tabID: string,
messageType: ChatItemType,
messageId?: string,
buttons?: ChatItemButton[]
) {
this.dispatcher.sendChatMessage(
new ChatMessage({ message, messageType, messageId: messageId, buttons: buttons }, tabID)
)
}

public sendShortSummary(params: {
Expand Down Expand Up @@ -159,16 +167,7 @@ export class Messenger {
message = CodeWhispererConstants.invalidFileTypeChatMessage
break
}

this.dispatcher.sendChatMessage(
new ChatMessage(
{
message,
messageType: 'answer-stream',
},
tabID
)
)
this.sendMessage(message, tabID, 'answer-stream')
}

public sendErrorMessage(errorMessage: string, tabID: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum ButtonActions {
VIEW_DIFF = 'View-Diff',
STOP_TEST_GEN = 'Stop-Test-Generation',
STOP_BUILD = 'Stop-Build-Process',
PROVIDE_FEEDBACK = 'Provide-Feedback',
}

// TODO: Refactor the common functionality between Transform, FeatureDev, CWSPRChat, Scan and UTG to a new Folder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class ChatMessage extends UiMessage {
readonly messageId?: string | undefined
readonly messageType: ChatItemType
readonly canBeVoted?: boolean
readonly buttons?: ChatItemButton[]
readonly informationCard: ChatItemContent['informationCard']
override type: TestMessageType = 'chatMessage'

Expand All @@ -90,6 +91,7 @@ export class ChatMessage extends UiMessage {
this.messageId = props.messageId || undefined
this.canBeVoted = props.canBeVoted || undefined
this.informationCard = props.informationCard || undefined
this.buttons = props.buttons || undefined
}
}

Expand Down
Loading