Skip to content

Commit 2232d2d

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

File tree

6 files changed

+130
-4
lines changed

6 files changed

+130
-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: 86 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,83 @@ class DocController(
330331
}
331332
}
332333

334+
private suspend fun promptForRetryFolderSelection(tabId: String, message: String) {
335+
try {
336+
messenger.sendRetryChangeFolderMessage(
337+
tabId = tabId,
338+
message = message,
339+
followUps = listOf(
340+
FollowUp(
341+
icon = FollowUpIcons.Refresh,
342+
pillText = message("amazonqDoc.prompt.folder.change"),
343+
prompt = message("amazonqDoc.prompt.folder.change"),
344+
status = FollowUpStatusType.Info,
345+
type = FollowUpTypes.MODIFY_DEFAULT_SOURCE_FOLDER
346+
),
347+
FollowUp(
348+
icon = FollowUpIcons.Cancel,
349+
pillText = message("general.cancel"),
350+
prompt = message("general.cancel"),
351+
status = FollowUpStatusType.Error,
352+
type = FollowUpTypes.CANCEL_FOLDER_SELECTION
353+
),
354+
)
355+
)
356+
357+
messenger.sendChatInputEnabledMessage(tabId, false)
358+
} catch (e: Exception) {
359+
logger.error(e) { "Error sending RetryChangeFolder message: ${e.message}" }
360+
// Consider logging the error or handling it appropriately
361+
}
362+
}
363+
364+
override suspend fun processChatItemVotedMessage(message: IncomingDocMessage.ChatItemVotedMessage) {
365+
logger.debug { "$FEATURE_NAME: Processing ChatItemVotedMessage: $message" }
366+
367+
val session = chatSessionStorage.getSession(message.tabId, context.project)
368+
when (message.vote) {
369+
"upvote" -> {
370+
AmazonqTelemetry.codeGenerationThumbsUp(
371+
amazonqConversationId = session.conversationId,
372+
credentialStartUrl = getStartUrl(project = context.project)
373+
)
374+
}
375+
376+
"downvote" -> {
377+
AmazonqTelemetry.codeGenerationThumbsDown(
378+
amazonqConversationId = session.conversationId,
379+
credentialStartUrl = getStartUrl(project = context.project)
380+
)
381+
}
382+
}
383+
}
384+
385+
override suspend fun processChatItemFeedbackMessage(message: IncomingDocMessage.ChatItemFeedbackMessage) {
386+
logger.debug { "$FEATURE_NAME: Processing ChatItemFeedbackMessage: ${message.comment}" }
387+
388+
val session = getSessionInfo(message.tabId)
389+
390+
val comment = FeedbackComment(
391+
conversationId = session.conversationId,
392+
userComment = message.comment.orEmpty(),
393+
reason = message.selectedOption,
394+
messageId = message.messageId,
395+
type = "doc-chat-answer-feedback"
396+
)
397+
398+
try {
399+
TelemetryService.getInstance().sendFeedback(
400+
sentiment = Sentiment.NEGATIVE,
401+
comment = objectMapper.writeValueAsString(comment),
402+
)
403+
logger.info { "$FEATURE_NAME answer feedback sent: \"Negative\"" }
404+
} catch (e: Throwable) {
405+
e.notifyError(message("feedback.submit_failed", e))
406+
logger.warn(e) { "Failed to submit feedback" }
407+
return
408+
}
409+
}
410+
333411
override suspend fun processLinkClick(message: IncomingDocMessage.ClickedLink) {
334412
BrowserUtil.browse(message.link)
335413
}
@@ -898,17 +976,21 @@ class DocController(
898976
// No folder was selected
899977
if (selectedFolder == null) {
900978
logger.info { "Cancelled dialog and not selected any folder" }
979+
promptForRetryFolderSelection(
980+
tabId,
981+
message("amazonqFeatureDev.follow_up.cancel_source_folder_selection")
982+
)
983+
901984
return@withContext
902985
}
903986

904987
// The folder is not in the workspace
905988
if (!selectedFolder.path.startsWith(projectRoot.path)) {
906989
logger.info { "Selected folder not in workspace: ${selectedFolder.path}" }
907990

908-
messenger.sendAnswer(
909-
tabId = tabId,
910-
messageType = DocMessageType.Answer,
911-
message = message("amazonqFeatureDev.follow_up.incorrect_source_folder"),
991+
promptForRetryFolderSelection(
992+
tabId,
993+
message("amazonqFeatureDev.follow_up.incorrect_source_folder")
912994
)
913995
return@withContext
914996
}

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)