Skip to content

Commit 83a69b2

Browse files
author
Viktor Shesternyak
committed
fix(amazonq): /doc enable text input in edit mode for retries and use it instead of retry button
1 parent dac6c74 commit 83a69b2

File tree

6 files changed

+49
-39
lines changed

6 files changed

+49
-39
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"type" : "bugfix",
3-
"description" : "AmazonQ doc agent: Enable text input in edit mode for retries and use it instead of retry button"
3+
"description" : "Amazon Q /doc: Ask for user prompt if error occurs while updating documentation"
44
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
package software.aws.toolkits.jetbrains.services.amazonqDoc
55

6+
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.FollowUp
7+
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.FollowUpStatusType
8+
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.FollowUpTypes
9+
import software.aws.toolkits.resources.message
10+
611
const val FEATURE_EVALUATION_PRODUCT_NAME = "DocGeneration"
712

813
const val FEATURE_NAME = "Amazon Q Documentation Generation"
@@ -25,3 +30,16 @@ enum class ModifySourceFolderErrorReason(
2530

2631
override fun toString(): String = reasonText
2732
}
33+
34+
val NEW_SESSION_FOLLOWUPS: List<FollowUp> = listOf(
35+
FollowUp(
36+
pillText = message("amazonqDoc.prompt.reject.new_task"),
37+
type = FollowUpTypes.NEW_TASK,
38+
status = FollowUpStatusType.Info
39+
),
40+
FollowUp(
41+
pillText = message("amazonqDoc.prompt.reject.close_session"),
42+
type = FollowUpTypes.CLOSE_SESSION,
43+
status = FollowUpStatusType.Info
44+
)
45+
)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import software.aws.toolkits.resources.message
88
open class DocException(
99
override val message: String?,
1010
override val cause: Throwable? = null,
11-
val remainingIterations: Int? = null) : RuntimeException()
11+
val remainingIterations: Int? = null,
12+
) : RuntimeException()
1213

1314
class ZipFileError(override val message: String, override val cause: Throwable?) : RuntimeException()
1415

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendAuthenti
5353
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendChatInputEnabledMessage
5454
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendCodeResult
5555
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendError
56+
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendErrorToUser
5657
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendFolderConfirmationMessage
5758
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendMonthlyLimitError
5859
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendSystemPrompt
5960
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendUpdatePlaceholder
6061
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendUpdatePromptProgress
61-
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendErrorToUser
6262
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.updateFileComponent
6363
import software.aws.toolkits.jetbrains.services.amazonqDoc.session.DocSession
6464
import software.aws.toolkits.jetbrains.services.amazonqDoc.session.PrepareDocGenerationState
@@ -380,7 +380,7 @@ class DocController(
380380
tabId = message.tabId,
381381
errMessage = message("amazonqFeatureDev.exception.open_diff_failed"),
382382
retries = 0,
383-
conversationId = session.conversationIdUnsafe,
383+
conversationId = session.conversationIdUnsafe
384384
)
385385
}
386386
}
@@ -428,10 +428,9 @@ class DocController(
428428
messenger.sendUpdatePlaceholder(tabId, message("amazonqDoc.prompt.placeholder"))
429429
} catch (err: Exception) {
430430
val message = createUserFacingErrorMessage(err.message)
431-
messenger.sendError(
431+
messenger.sendErrorToUser(
432432
tabId = tabId,
433433
errMessage = message ?: message("amazonqFeatureDev.exception.request_failed"),
434-
retries = retriesRemaining(session),
435434
conversationId = session?.conversationIdUnsafe,
436435
)
437436
}
@@ -725,7 +724,7 @@ class DocController(
725724
}
726725
} catch (err: Exception) {
727726
// For non edit mode lock the chat input until they explicitly click one of the follow-ups
728-
var isEnableChatInput = false;
727+
var isEnableChatInput = false
729728
if (err is DocException && Mode.EDIT == mode) {
730729
isEnableChatInput = err.remainingIterations != null && err.remainingIterations > 0
731730
}
@@ -887,7 +886,7 @@ class DocController(
887886
tabId = tabId,
888887
errMessage = message ?: message("amazonqFeatureDev.exception.retry_request_failed"),
889888
retries = retriesRemaining(session),
890-
conversationId = session?.conversationIdUnsafe
889+
conversationId = session?.conversationIdUnsafe,
891890
)
892891
} finally {
893892
// Finish processing the event

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

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import software.aws.toolkits.jetbrains.services.amazonq.auth.AuthNeededState
77
import software.aws.toolkits.jetbrains.services.amazonq.messages.MessagePublisher
88
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.messages.ProgressField
99
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.messages.PromptProgressMessage
10+
import software.aws.toolkits.jetbrains.services.amazonqDoc.NEW_SESSION_FOLLOWUPS
1011
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.CodeReferenceGenerated
1112
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.DeletedFileInfo
1213
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.NewFileZipInfo
@@ -114,7 +115,6 @@ suspend fun MessagePublisher.sendChatInputEnabledMessage(tabId: String, enabled:
114115
this.publish(chatInputEnabledMessage)
115116
}
116117

117-
118118
suspend fun MessagePublisher.sendError(tabId: String, errMessage: String?, retries: Int, conversationId: String? = null, showDefaultMessage: Boolean? = false) {
119119
val conversationIdText = if (conversationId == null) "" else "\n\nConversation ID: **$conversationId**"
120120

@@ -151,45 +151,37 @@ suspend fun MessagePublisher.sendError(tabId: String, errMessage: String?, retri
151151
)
152152
}
153153

154-
155154
suspend fun MessagePublisher.sendErrorToUser(
156155
tabId: String,
157156
errMessage: String?,
158157
conversationId: String? = null,
159-
isEnableChatInput: Boolean = false
158+
isEnableChatInput: Boolean = false,
160159
) {
161160
val conversationIdText = if (conversationId == null) "" else "\n\nConversation ID: **$conversationId**"
162161

163-
var followUps = listOf(
164-
FollowUp(
165-
pillText = message("amazonqDoc.prompt.reject.new_task"),
166-
type = FollowUpTypes.NEW_TASK,
167-
status = FollowUpStatusType.Info
168-
),
169-
FollowUp(
170-
pillText = message("amazonqDoc.prompt.reject.close_session"),
171-
type = FollowUpTypes.CLOSE_SESSION,
172-
status = FollowUpStatusType.Info
173-
)
174-
);
175-
176-
this.sendChatInputEnabledMessage(tabId, enabled = isEnableChatInput)
177-
if (isEnableChatInput) {
178-
this.sendUpdatePlaceholder(tabId, message("amazonqDoc.edit.placeholder"))
179-
followUps = Collections.emptyList()
180-
}
181-
182162
this.sendAnswer(
183163
tabId = tabId,
184164
messageType = DocMessageType.Answer,
185165
message = errMessage + conversationIdText,
186166
)
187167

188-
this.sendAnswer(
189-
tabId = tabId,
190-
messageType = DocMessageType.SystemPrompt,
191-
followUp = followUps
192-
)
168+
if (isEnableChatInput) {
169+
this.sendAnswer(
170+
tabId = tabId,
171+
messageType = DocMessageType.SystemPrompt,
172+
followUp = Collections.emptyList()
173+
)
174+
this.sendUpdatePlaceholder(tabId, message("amazonqDoc.edit.placeholder"))
175+
} else {
176+
this.sendAnswer(
177+
tabId = tabId,
178+
messageType = DocMessageType.SystemPrompt,
179+
followUp = NEW_SESSION_FOLLOWUPS
180+
)
181+
this.sendUpdatePlaceholder(tabId, message("amazonqDoc.prompt.placeholder"))
182+
}
183+
184+
this.sendChatInputEnabledMessage(tabId, enabled = isEnableChatInput)
193185
}
194186

195187
suspend fun MessagePublisher.sendMonthlyLimitError(tabId: String) {

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/session/DocGenerationState.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ private suspend fun DocGenerationState.generateCode(codeGenerationId: String, mo
178178
codeGenerationResultState.codeGenerationStatusDetail()?.contains(
179179
"README_TOO_LARGE"
180180
),
181-
-> docServiceError(message("amazonqDoc.exception.readme_too_large"), remainingIterations=remainingIterations)
181+
-> docServiceError(message("amazonqDoc.exception.readme_too_large"), remainingIterations = remainingIterations)
182182

183183
codeGenerationResultState.codeGenerationStatusDetail()?.contains(
184184
"README_UPDATE_TOO_LARGE"
185185
),
186-
-> docServiceError(message("amazonqDoc.exception.readme_update_too_large"), remainingIterations=remainingIterations)
186+
-> docServiceError(message("amazonqDoc.exception.readme_update_too_large"), remainingIterations = remainingIterations)
187187

188188
codeGenerationResultState.codeGenerationStatusDetail()?.contains(
189189
"WORKSPACE_TOO_LARGE"
@@ -203,12 +203,12 @@ private suspend fun DocGenerationState.generateCode(codeGenerationId: String, mo
203203
codeGenerationResultState.codeGenerationStatusDetail()?.contains(
204204
"PROMPT_TOO_VAGUE"
205205
),
206-
-> docServiceError(message("amazonqDoc.exception.prompt_too_vague"), remainingIterations=remainingIterations)
206+
-> docServiceError(message("amazonqDoc.exception.prompt_too_vague"), remainingIterations = remainingIterations)
207207

208208
codeGenerationResultState.codeGenerationStatusDetail()?.contains(
209209
"PromptRefusal"
210210
),
211-
-> docServiceError(message("amazonqFeatureDev.exception.prompt_refusal"), remainingIterations=remainingIterations)
211+
-> docServiceError(message("amazonqFeatureDev.exception.prompt_refusal"), remainingIterations = remainingIterations)
212212

213213
codeGenerationResultState.codeGenerationStatusDetail()?.contains(
214214
"Guardrails"

0 commit comments

Comments
 (0)