From 29b1a6cbcf45618f62e379344b6414e29af2c3b4 Mon Sep 17 00:00:00 2001 From: Andy Gagen <66085068+aggagen@users.noreply.github.com> Date: Thu, 12 Dec 2024 17:44:29 -0500 Subject: [PATCH] fix(amazonq): align /doc messages with vscode (#5191) * Aligns a few /doc chat messages with strings from the vscode extension * Fixes a bug where the checklist progress view wasn't showing up * As part of this, I added support for disabling the "Stop" button at the bottom of the chat window when an async event is in progress. Similar to this vscode commit: https://github.com/aws/aws-toolkit-vscode/commit/9c89c53a5a337d6b8b19c2e4252e080ae282d11a#diff-8eb911f0ec050013422c6b3bd03c793a30f8c6ecf0eb63297cf4f10611b0274dR3 --- .../amazonqDoc/controller/DocController.kt | 26 ++-------------- .../controller/DocControllerExtensions.kt | 31 +++++++++++++------ .../amazonqDoc/util/DocControllerUtil.kt | 24 +++++++++----- .../src/mynah-ui/ui/apps/docChatConnector.ts | 2 +- .../ui/apps/featureDevChatConnector.ts | 4 +-- .../mynah-ui/src/mynah-ui/ui/connector.ts | 2 +- .../amazonq/mynah-ui/src/mynah-ui/ui/main.ts | 4 +-- .../resources/MessagesBundle.properties | 7 +++-- 8 files changed, 51 insertions(+), 49 deletions(-) diff --git a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocController.kt b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocController.kt index 28c02cfe02..8352d621d8 100644 --- a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocController.kt +++ b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocController.kt @@ -66,6 +66,7 @@ import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.updateFileCo import software.aws.toolkits.jetbrains.services.amazonqDoc.session.DocSession import software.aws.toolkits.jetbrains.services.amazonqDoc.session.PrepareDocGenerationState import software.aws.toolkits.jetbrains.services.amazonqDoc.storage.ChatSessionStorage +import software.aws.toolkits.jetbrains.services.amazonqDoc.util.getFollowUpOptions import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.CodeIterationLimitException import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.MonthlyConversationLimitError import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.CodeReferenceGenerated @@ -813,7 +814,6 @@ class DocController( when (session.sessionState.phase) { SessionStatePhase.CODEGEN -> { - messenger.sendUpdatePromptProgress(tabId, inProgress(progress = 10)) onCodeGeneration(session, message, tabId, mode) } else -> null @@ -904,29 +904,7 @@ class DocController( messenger.sendAnswer( messageType = DocMessageType.SystemPrompt, tabId = followUpMessage.tabId, - followUp = listOf( - FollowUp( - pillText = message("amazonqDoc.prompt.review.accept"), - prompt = message("amazonqDoc.prompt.review.accept"), - status = FollowUpStatusType.Success, - type = FollowUpTypes.ACCEPT_CHANGES, - icon = FollowUpIcons.Ok, - ), - FollowUp( - pillText = message("amazonqDoc.prompt.review.changes"), - prompt = message("amazonqDoc.prompt.review.changes"), - status = FollowUpStatusType.Info, - type = FollowUpTypes.MAKE_CHANGES, - icon = FollowUpIcons.Info, - ), - FollowUp( - pillText = message("general.reject"), - prompt = message("general.reject"), - status = FollowUpStatusType.Error, - type = FollowUpTypes.REJECT_CHANGES, - icon = FollowUpIcons.Cancel, - ) - ) + followUp = getFollowUpOptions(session.sessionState.phase) ) processOpenDiff( diff --git a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocControllerExtensions.kt b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocControllerExtensions.kt index ff4374eae1..d6441008ee 100644 --- a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocControllerExtensions.kt +++ b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocControllerExtensions.kt @@ -4,6 +4,7 @@ package software.aws.toolkits.jetbrains.services.amazonqDoc.controller import com.intellij.notification.NotificationAction +import software.aws.toolkits.jetbrains.services.amazonqDoc.inProgress import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.DocMessageType import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.FollowUp import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.FollowUpStatusType @@ -14,19 +15,27 @@ import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendChatInpu import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendCodeResult import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendSystemPrompt import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendUpdatePlaceholder +import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendUpdatePromptProgress import software.aws.toolkits.jetbrains.services.amazonqDoc.session.DocSession import software.aws.toolkits.jetbrains.services.amazonqDoc.session.PrepareDocGenerationState +import software.aws.toolkits.jetbrains.services.amazonqDoc.util.getFollowUpOptions import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.messages.sendSystemPrompt import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.CodeReferenceGenerated import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.DeletedFileInfo import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.NewFileZipInfo -import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.util.InsertAction -import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.util.getFollowUpOptions import software.aws.toolkits.jetbrains.utils.notifyInfo import software.aws.toolkits.resources.message suspend fun DocController.onCodeGeneration(session: DocSession, message: String, tabId: String, mode: Mode) { try { + messenger.sendAsyncEventProgress(tabId, inProgress = true) + messenger.sendUpdatePromptProgress(tabId, inProgress(progress = 10, message("amazonqDoc.progress_message.scanning"))) + messenger.sendAnswer( + message = docGenerationProgressMessage(DocGenerationStep.UPLOAD_TO_S3, this.mode), + messageType = DocMessageType.AnswerPart, + tabId = tabId, + ) + val sessionMessage = if (mode == Mode.CREATE) { message( "amazonqDoc.session.create" @@ -80,25 +89,27 @@ suspend fun DocController.onCodeGeneration(session: DocSession, message: String, return } + messenger.sendAnswer( + message = docGenerationProgressMessage(DocGenerationStep.COMPLETE, mode), + messageType = DocMessageType.AnswerPart, + tabId = tabId, + ) + messenger.sendCodeResult(tabId = tabId, uploadId = uploadId, filePaths = filePaths, deletedFiles = deletedFiles, references = references) if (remainingIterations != null && totalIterations != null) { messenger.sendAnswer( tabId = tabId, messageType = DocMessageType.Answer, - message = if (remainingIterations == 0) { - message("amazonqFeatureDev.code_generation.iteration_zero") + message = if (this.mode === Mode.CREATE) { + message("amazonqDoc.answer.readmeCreated") } else { - message( - "amazonqFeatureDev.code_generation.iteration_counts", - remainingIterations, - totalIterations - ) + "${message("amazonqDoc.answer.readmeUpdated")} ${message("amazonqDoc.answer.codeResult")}" } ) } - messenger.sendSystemPrompt(tabId = tabId, followUp = getFollowUpOptions(session.sessionState.phase, InsertAction.ALL)) + messenger.sendSystemPrompt(tabId = tabId, followUp = getFollowUpOptions(session.sessionState.phase)) messenger.sendUpdatePlaceholder(tabId = tabId, newPlaceholder = message("amazonqFeatureDev.placeholder.after_code_generation")) } finally { diff --git a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/util/DocControllerUtil.kt b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/util/DocControllerUtil.kt index 95a7e8235e..89c351cf37 100644 --- a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/util/DocControllerUtil.kt +++ b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/util/DocControllerUtil.kt @@ -15,19 +15,29 @@ fun getFollowUpOptions(phase: SessionStatePhase?): List { SessionStatePhase.CODEGEN -> { return listOf( FollowUp( - pillText = message("amazonqDoc.follow_up.insert_code"), - type = FollowUpTypes.INSERT_CODE, + pillText = message("amazonqDoc.prompt.review.accept"), + prompt = message("amazonqDoc.prompt.review.accept"), + status = FollowUpStatusType.Success, + type = FollowUpTypes.ACCEPT_CHANGES, icon = FollowUpIcons.Ok, - status = FollowUpStatusType.Success ), FollowUp( - pillText = message("amazonqDoc.follow_up.provide_feedback_and_regenerate"), - type = FollowUpTypes.PROVIDE_FEEDBACK_AND_REGENERATE_CODE, - icon = FollowUpIcons.Refresh, - status = FollowUpStatusType.Info + pillText = message("amazonqDoc.prompt.review.changes"), + prompt = message("amazonqDoc.prompt.review.changes"), + status = FollowUpStatusType.Info, + type = FollowUpTypes.MAKE_CHANGES, + icon = FollowUpIcons.Info, + ), + FollowUp( + pillText = message("general.reject"), + prompt = message("general.reject"), + status = FollowUpStatusType.Error, + type = FollowUpTypes.REJECT_CHANGES, + icon = FollowUpIcons.Cancel, ) ) } + else -> return emptyList() } } diff --git a/plugins/amazonq/mynah-ui/src/mynah-ui/ui/apps/docChatConnector.ts b/plugins/amazonq/mynah-ui/src/mynah-ui/ui/apps/docChatConnector.ts index 07fa03b9f1..f0ec312fe5 100644 --- a/plugins/amazonq/mynah-ui/src/mynah-ui/ui/apps/docChatConnector.ts +++ b/plugins/amazonq/mynah-ui/src/mynah-ui/ui/apps/docChatConnector.ts @@ -19,7 +19,7 @@ export interface ConnectorProps { sendMessageToExtension: (message: ExtensionMessage) => void onMessageReceived?: (tabID: string, messageData: any, needToShowAPIDocsTab: boolean) => void onUpdatePromptProgress: (tabID: string, progressField: ProgressField) => void - onAsyncEventProgress: (tabID: string, inProgress: boolean, message: string) => void + onAsyncEventProgress: (tabID: string, inProgress: boolean, message: string, cancelButtonWhenLoading?: boolean) => void onChatAnswerReceived?: (tabID: string, message: ChatItem) => void sendFeedback?: (tabId: string, feedbackPayload: FeedbackPayload) => void | undefined onError: (tabID: string, message: string, title: string) => void diff --git a/plugins/amazonq/mynah-ui/src/mynah-ui/ui/apps/featureDevChatConnector.ts b/plugins/amazonq/mynah-ui/src/mynah-ui/ui/apps/featureDevChatConnector.ts index 14b46ce310..3b1e44c5bf 100644 --- a/plugins/amazonq/mynah-ui/src/mynah-ui/ui/apps/featureDevChatConnector.ts +++ b/plugins/amazonq/mynah-ui/src/mynah-ui/ui/apps/featureDevChatConnector.ts @@ -18,7 +18,7 @@ interface ChatPayload { export interface ConnectorProps { sendMessageToExtension: (message: ExtensionMessage) => void onMessageReceived?: (tabID: string, messageData: any, needToShowAPIDocsTab: boolean) => void - onAsyncEventProgress: (tabID: string, inProgress: boolean, message: string) => void + onAsyncEventProgress: (tabID: string, inProgress: boolean, message: string, cancelButtonWhenLoading?: boolean) => void onChatAnswerReceived?: (tabID: string, message: ChatItem) => void onChatAnswerUpdated?: (tabID: string, message: ChatItem) => void sendFeedback?: (tabId: string, feedbackPayload: FeedbackPayload) => void | undefined @@ -249,7 +249,7 @@ export class Connector { } if (messageData.type === 'asyncEventProgressMessage') { - this.onAsyncEventProgress(messageData.tabID, messageData.inProgress, messageData.message ?? undefined) + this.onAsyncEventProgress(messageData.tabID, messageData.inProgress, messageData.message ?? undefined, true) return } diff --git a/plugins/amazonq/mynah-ui/src/mynah-ui/ui/connector.ts b/plugins/amazonq/mynah-ui/src/mynah-ui/ui/connector.ts index 510c9a891c..37a68037e1 100644 --- a/plugins/amazonq/mynah-ui/src/mynah-ui/ui/connector.ts +++ b/plugins/amazonq/mynah-ui/src/mynah-ui/ui/connector.ts @@ -61,7 +61,7 @@ export interface ConnectorProps { onCodeTransformMessageUpdate: (tabID: string, messageId: string, chatItem: Partial) => void onRunTestMessageReceived?: (tabID: string, showRunTestMessage: boolean) => void onWelcomeFollowUpClicked: (tabID: string, welcomeFollowUpType: WelcomeFollowupType) => void - onAsyncEventProgress: (tabID: string, inProgress: boolean, message: string | undefined) => void + onAsyncEventProgress: (tabID: string, inProgress: boolean, message: string | undefined, cancelButtonWhenLoading?: boolean) => void onCWCContextCommandMessage: (message: ChatItem, command?: string) => string | undefined onCWCOnboardingPageInteractionMessage: (message: ChatItem) => string | undefined onOpenSettingsMessage: (tabID: string) => void diff --git a/plugins/amazonq/mynah-ui/src/mynah-ui/ui/main.ts b/plugins/amazonq/mynah-ui/src/mynah-ui/ui/main.ts index ffbd69f339..1a9fd5ac77 100644 --- a/plugins/amazonq/mynah-ui/src/mynah-ui/ui/main.ts +++ b/plugins/amazonq/mynah-ui/src/mynah-ui/ui/main.ts @@ -184,12 +184,12 @@ export const createMynahUI = ( promptInputDisabledState: tabsStorage.isTabDead(tabID) || !enabled, }) }, - onAsyncEventProgress: (tabID: string, inProgress: boolean, message: string | undefined) => { + onAsyncEventProgress: (tabID: string, inProgress: boolean, message: string | undefined, cancelButtonWhenLoading: boolean = false) => { if (inProgress) { mynahUI.updateStore(tabID, { loadingChat: true, promptInputDisabledState: true, - cancelButtonWhenLoading: true, + cancelButtonWhenLoading, }) if (message) { mynahUI.updateLastChatAnswer(tabID, { diff --git a/plugins/core/resources/resources/software/aws/toolkits/resources/MessagesBundle.properties b/plugins/core/resources/resources/software/aws/toolkits/resources/MessagesBundle.properties index 9d683cac64..599eb2ce8d 100644 --- a/plugins/core/resources/resources/software/aws/toolkits/resources/MessagesBundle.properties +++ b/plugins/core/resources/resources/software/aws/toolkits/resources/MessagesBundle.properties @@ -38,8 +38,11 @@ action.aws.toolkit.toolwindow.newConnection.text=Add Another Connection... action.dynamic.open.text=Open Resource... action.q.openchat.text=Open Chat Panel amazonqChat.project_context.index_in_progress=By the way, I'm still indexing this project for full context from your workspace. I may have a better response in a few minutes when it's complete if you'd like to try again then. -amazonqDoc.edit.message=Please describe the changes you would like to make to your documentation. For example, you can ask me to add a section, remove a section, make a correction, expand upon something, etc. -amazonqDoc.edit.placeholder=Describe your documentation request +amazonqDoc.answer.codeResult=You can accept the changes to your files, or describe any additional changes you'd like me to make. +amazonqDoc.answer.readmeCreated=I've created a README for your code. +amazonqDoc.answer.readmeUpdated=I've updated your README. +amazonqDoc.edit.message=Okay, let's work on your README. Describe the changes you would like to make. For example, you can ask me to:\n- Correct something\n- Expand on something\n- Add a section\n- Remove a section +amazonqDoc.edit.placeholder=Describe documentation changes amazonqDoc.error.generating=Unable to generate changes. amazonqDoc.error_text=I'm sorry, I ran into an issue while trying to generate your documentation. Please try again. amazonqDoc.exception.content_length_error=Your workspace is too large for me to review. Your workspace must be within the quota, even if you choose a smaller folder. For more information on quotas, see the Amazon Q Developer documentation.