diff --git a/.changes/next-release/bugfix-b204e9b7-e11e-46c7-bfb2-4704db861dd8.json b/.changes/next-release/bugfix-b204e9b7-e11e-46c7-bfb2-4704db861dd8.json new file mode 100644 index 0000000000..e262fcb3a5 --- /dev/null +++ b/.changes/next-release/bugfix-b204e9b7-e11e-46c7-bfb2-4704db861dd8.json @@ -0,0 +1,4 @@ +{ + "type" : "bugfix", + "description" : "Amazon Q /doc: fix for user prompt to change folder in chat" +} \ No newline at end of file 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 2d3729532a..2879c0adf6 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 @@ -55,6 +55,7 @@ import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendCodeResu import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendError import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendFolderConfirmationMessage import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendMonthlyLimitError +import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendRetryChangeFolderMessage 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 @@ -337,6 +338,31 @@ class DocController( } } + private suspend fun promptForRetryFolderSelection(tabId: String, message: String) { + messenger.sendRetryChangeFolderMessage( + tabId = tabId, + message = message, + followUps = listOf( + FollowUp( + icon = FollowUpIcons.Refresh, + pillText = message("amazonqDoc.prompt.folder.change"), + prompt = message("amazonqDoc.prompt.folder.change"), + status = FollowUpStatusType.Info, + type = FollowUpTypes.MODIFY_DEFAULT_SOURCE_FOLDER + ), + FollowUp( + icon = FollowUpIcons.Cancel, + pillText = message("general.cancel"), + prompt = message("general.cancel"), + status = FollowUpStatusType.Error, + type = FollowUpTypes.CANCEL_FOLDER_SELECTION + ), + ) + ) + + messenger.sendChatInputEnabledMessage(tabId, false) + } + override suspend fun processLinkClick(message: IncomingDocMessage.ClickedLink) { BrowserUtil.browse(message.link) } @@ -914,11 +940,22 @@ class DocController( val projectRoot = session.context.projectRoot withContext(EDT) { + messenger.sendAnswer( + tabId = tabId, + messageType = DocMessageType.Answer, + message = message("amazonqDoc.prompt.choose_folder_to_continue") + ) + val selectedFolder = selectFolder(context.project, currentSourceFolder) // No folder was selected if (selectedFolder == null) { logger.info { "Cancelled dialog and not selected any folder" } + promptForRetryFolderSelection( + tabId, + message("amazonqDoc.prompt.canceled_source_folder_selection") + ) + return@withContext } diff --git a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/messages/DocMessage.kt b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/messages/DocMessage.kt index 61c8bc0109..047501bead 100644 --- a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/messages/DocMessage.kt +++ b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/messages/DocMessage.kt @@ -179,6 +179,15 @@ data class FolderConfirmationMessage( type = "folderConfirmationMessage" ) +data class RetryChangeFolderMessage( + @JsonProperty("tabID") override val tabId: String, + val message: String, + val followUps: List?, +) : UiMessage( + tabId = tabId, + type = "retryChangeFolderMessage" +) + // this should come from mynah? data class ChatItemButton( val id: String, diff --git a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/messages/DocMessagePublisherExtensions.kt b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/messages/DocMessagePublisherExtensions.kt index 963b6d95be..0920b8564d 100644 --- a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/messages/DocMessagePublisherExtensions.kt +++ b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/messages/DocMessagePublisherExtensions.kt @@ -208,6 +208,16 @@ suspend fun MessagePublisher.sendFolderConfirmationMessage( ) } +suspend fun MessagePublisher.sendRetryChangeFolderMessage( + tabId: String, + message: String, + followUps: List, +) { + this.publish( + RetryChangeFolderMessage(tabId = tabId, message = message, followUps = followUps) + ) +} + suspend fun MessagePublisher.sendUpdatePromptProgress(tabId: String, progressField: ProgressField?) { this.publish( PromptProgressMessage(tabId, progressField) 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 e92421213d..a1547b5b83 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 @@ -170,6 +170,21 @@ export class Connector { } } + private processRetryChangeFolderMessage = async (messageData: any): Promise => { + if (this.onChatAnswerReceived !== undefined) { + const answer: ChatItem = { + type: ChatItemType.ANSWER, + body: messageData.message ?? undefined, + messageId: messageData.messageID ?? messageData.triggerID ?? '', + followUp: { + text: '', + options: messageData.followUps, + }, + } + this.onChatAnswerReceived(messageData.tabID, answer) + } + } + private processChatMessage = async (messageData: any): Promise => { if (this.onChatAnswerReceived !== undefined) { const answer: ChatItem = { @@ -263,6 +278,11 @@ export class Connector { return } + if (messageData.type === 'retryChangeFolderMessage') { + await this.processRetryChangeFolderMessage(messageData) + return + } + if (messageData.type === 'chatMessage') { await this.processChatMessage(messageData) return 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 38038b9b38..feeddf8f5f 100644 --- a/plugins/core/resources/resources/software/aws/toolkits/resources/MessagesBundle.properties +++ b/plugins/core/resources/resources/software/aws/toolkits/resources/MessagesBundle.properties @@ -59,6 +59,8 @@ amazonqDoc.progress_message.generating=Generating documentation amazonqDoc.progress_message.scanning=Scanning source files amazonqDoc.progress_message.summarizing=Summarizing source files amazonqDoc.progress_message.updating=Okay, I'm updating the README. +amazonqDoc.prompt.canceled_source_folder_selection=It looks like you didn't choose a folder. Choose a folder to continue. +amazonqDoc.prompt.choose_folder_to_continue=Choose a folder to continue amazonqDoc.prompt.create=Create a README amazonqDoc.prompt.create.confirmation=Create a README for this project? amazonqDoc.prompt.folder.change=Change folder