Skip to content

Commit 1f102c0

Browse files
author
Viktor Shesternyak
committed
fix(amazonq): /doc fix prompt to change folder in chat
1 parent effbebd commit 1f102c0

File tree

6 files changed

+78
-4
lines changed

6 files changed

+78
-4
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Amazon Q /doc: fix for user prompt to change folder in chat"
4+
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocController.kt

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendCodeResu
5252
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendError
5353
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendFolderConfirmationMessage
5454
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendMonthlyLimitError
55+
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendRetryChangeFolderMessage
5556
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendSystemPrompt
5657
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendUpdatePlaceholder
5758
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendUpdatePromptProgress
@@ -330,6 +331,31 @@ class DocController(
330331
}
331332
}
332333

334+
private suspend fun promptForRetryFolderSelection(tabId: String, message: String) {
335+
messenger.sendRetryChangeFolderMessage(
336+
tabId = tabId,
337+
message = message,
338+
followUps = listOf(
339+
FollowUp(
340+
icon = FollowUpIcons.Refresh,
341+
pillText = message("amazonqDoc.prompt.folder.change"),
342+
prompt = message("amazonqDoc.prompt.folder.change"),
343+
status = FollowUpStatusType.Info,
344+
type = FollowUpTypes.MODIFY_DEFAULT_SOURCE_FOLDER
345+
),
346+
FollowUp(
347+
icon = FollowUpIcons.Cancel,
348+
pillText = message("general.cancel"),
349+
prompt = message("general.cancel"),
350+
status = FollowUpStatusType.Error,
351+
type = FollowUpTypes.CANCEL_FOLDER_SELECTION
352+
),
353+
)
354+
)
355+
356+
messenger.sendChatInputEnabledMessage(tabId, false)
357+
}
358+
333359
override suspend fun processLinkClick(message: IncomingDocMessage.ClickedLink) {
334360
BrowserUtil.browse(message.link)
335361
}
@@ -898,17 +924,21 @@ class DocController(
898924
// No folder was selected
899925
if (selectedFolder == null) {
900926
logger.info { "Cancelled dialog and not selected any folder" }
927+
promptForRetryFolderSelection(
928+
tabId,
929+
message("amazonqFeatureDev.follow_up.cancel_source_folder_selection")
930+
)
931+
901932
return@withContext
902933
}
903934

904935
// The folder is not in the workspace
905936
if (!selectedFolder.path.startsWith(projectRoot.path)) {
906937
logger.info { "Selected folder not in workspace: ${selectedFolder.path}" }
907938

908-
messenger.sendAnswer(
909-
tabId = tabId,
910-
messageType = DocMessageType.Answer,
911-
message = message("amazonqFeatureDev.follow_up.incorrect_source_folder"),
939+
promptForRetryFolderSelection(
940+
tabId,
941+
message("amazonqFeatureDev.follow_up.incorrect_source_folder")
912942
)
913943
return@withContext
914944
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/messages/DocMessage.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ data class FolderConfirmationMessage(
179179
type = "folderConfirmationMessage"
180180
)
181181

182+
data class RetryChangeFolderMessage(
183+
@JsonProperty("tabID") override val tabId: String,
184+
val message: String,
185+
val followUps: List<FollowUp>?,
186+
) : UiMessage(
187+
tabId = tabId,
188+
type = "retryChangeFolderMessage"
189+
)
190+
182191
// this should come from mynah?
183192
data class ChatItemButton(
184193
val id: String,

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/messages/DocMessagePublisherExtensions.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,16 @@ suspend fun MessagePublisher.sendFolderConfirmationMessage(
208208
)
209209
}
210210

211+
suspend fun MessagePublisher.sendRetryChangeFolderMessage(
212+
tabId: String,
213+
message: String,
214+
followUps: List<FollowUp>,
215+
) {
216+
this.publish(
217+
RetryChangeFolderMessage(tabId = tabId, message = message, followUps = followUps)
218+
)
219+
}
220+
211221
suspend fun MessagePublisher.sendUpdatePromptProgress(tabId: String, progressField: ProgressField?) {
212222
this.publish(
213223
PromptProgressMessage(tabId, progressField)

plugins/amazonq/mynah-ui/src/mynah-ui/ui/apps/docChatConnector.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,21 @@ export class Connector {
170170
}
171171
}
172172

173+
private processRetryChangeFolderMessage = async (messageData: any): Promise<void> => {
174+
if (this.onChatAnswerReceived !== undefined) {
175+
const answer: ChatItem = {
176+
type: ChatItemType.ANSWER,
177+
body: messageData.message ?? undefined,
178+
messageId: messageData.messageID ?? messageData.triggerID ?? '',
179+
followUp: {
180+
text: '',
181+
options: messageData.followUps,
182+
},
183+
}
184+
this.onChatAnswerReceived(messageData.tabID, answer)
185+
}
186+
}
187+
173188
private processChatMessage = async (messageData: any): Promise<void> => {
174189
if (this.onChatAnswerReceived !== undefined) {
175190
const answer: ChatItem = {
@@ -263,6 +278,11 @@ export class Connector {
263278
return
264279
}
265280

281+
if (messageData.type === 'retryChangeFolderMessage') {
282+
await this.processRetryChangeFolderMessage(messageData)
283+
return
284+
}
285+
266286
if (messageData.type === 'chatMessage') {
267287
await this.processChatMessage(messageData)
268288
return

plugins/core/resources/resources/software/aws/toolkits/resources/MessagesBundle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ amazonqFeatureDev.exception.throttling=I'm sorry, I'm experiencing high demand a
113113
amazonqFeatureDev.exception.upload_code=I'm sorry, I couldn't upload your workspace artifacts to Amazon S3 to help you with this task. You might need to allow access to the S3 bucket. For more information, see the [Amazon Q documentation](https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/security_iam_manage-access-with-policies.html#data-perimeters) or contact your network or organization administrator.
114114
amazonqFeatureDev.exception.upload_url_expiry=I'm sorry, I wasn't able to generate code. A connection timed out or became unavailable. Please try again or check the following:\n\n- Exclude non-essential files in your workspace's `.gitignore`.\n\n- Check that your network connection is stable.
115115
amazonqFeatureDev.follow_instructions_for_authentication=Follow instructions to re-authenticate ...
116+
amazonqFeatureDev.follow_up.cancel_source_folder_selection=It looks like you didn't choose a folder. Choose a folder to continue.
116117
amazonqFeatureDev.follow_up.close_session=No, thanks
117118
amazonqFeatureDev.follow_up.continue=Continue
118119
amazonqFeatureDev.follow_up.incorrect_source_folder=The folder you chose isn't in your open workspace folder. You can add this folder to your workspace, or choose a folder in your open workspace.

0 commit comments

Comments
 (0)