Skip to content

Commit dac6c74

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 5bceb99 commit dac6c74

File tree

5 files changed

+76
-29
lines changed

5 files changed

+76
-29
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" : "AmazonQ doc agent: Enable text input in edit mode for retries and use it instead of retry button"
4+
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ package software.aws.toolkits.jetbrains.services.amazonqDoc
55

66
import software.aws.toolkits.resources.message
77

8-
open class DocException(override val message: String?, override val cause: Throwable? = null) : RuntimeException()
8+
open class DocException(
9+
override val message: String?,
10+
override val cause: Throwable? = null,
11+
val remainingIterations: Int? = null) : RuntimeException()
912

1013
class ZipFileError(override val message: String, override val cause: Throwable?) : RuntimeException()
1114

1215
class CodeIterationLimitError(override val message: String, override val cause: Throwable?) : RuntimeException()
1316

14-
internal fun docServiceError(message: String?): Nothing =
15-
throw DocException(message)
16-
17-
internal fun codeGenerationFailedError(): Nothing =
18-
throw DocException(message("amazonqFeatureDev.code_generation.failed_generation"))
17+
internal fun docServiceError(message: String?, cause: Throwable? = null, remainingIterations: Int? = null): Nothing =
18+
throw DocException(message, cause, remainingIterations)
1919

2020
internal fun conversationIdNotFound(): Nothing =
2121
throw DocException(message("amazonqFeatureDev.exception.conversation_not_found"))

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendMonthlyL
5858
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendSystemPrompt
5959
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendUpdatePlaceholder
6060
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendUpdatePromptProgress
61+
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.sendErrorToUser
6162
import software.aws.toolkits.jetbrains.services.amazonqDoc.messages.updateFileComponent
6263
import software.aws.toolkits.jetbrains.services.amazonqDoc.session.DocSession
6364
import software.aws.toolkits.jetbrains.services.amazonqDoc.session.PrepareDocGenerationState
@@ -379,7 +380,7 @@ class DocController(
379380
tabId = message.tabId,
380381
errMessage = message("amazonqFeatureDev.exception.open_diff_failed"),
381382
retries = 0,
382-
conversationId = session.conversationIdUnsafe
383+
conversationId = session.conversationIdUnsafe,
383384
)
384385
}
385386
}
@@ -431,7 +432,7 @@ class DocController(
431432
tabId = tabId,
432433
errMessage = message ?: message("amazonqFeatureDev.exception.request_failed"),
433434
retries = retriesRemaining(session),
434-
conversationId = session?.conversationIdUnsafe
435+
conversationId = session?.conversationIdUnsafe,
435436
)
436437
}
437438
}
@@ -553,7 +554,7 @@ class DocController(
553554
messenger.sendUpdatePlaceholder(tabId, message("amazonqFeatureDev.placeholder.provide_code_feedback"))
554555
}
555556

556-
private suspend fun processErrorChatMessage(err: Exception, session: DocSession?, tabId: String) {
557+
private suspend fun processErrorChatMessage(err: Exception, session: DocSession?, tabId: String, isEnableChatInput: Boolean) {
557558
logger.warn(err) { "Encountered ${err.message} for tabId: $tabId" }
558559
messenger.sendUpdatePromptProgress(tabId, null)
559560

@@ -593,23 +594,21 @@ class DocController(
593594
}
594595

595596
is DocException -> {
596-
messenger.sendError(
597+
messenger.sendErrorToUser(
597598
tabId = tabId,
598599
errMessage = err.message,
599-
retries = retriesRemaining(session),
600-
conversationId = session?.conversationIdUnsafe
600+
conversationId = session?.conversationIdUnsafe,
601+
isEnableChatInput
601602
)
602603
}
603604

604605
is CodeIterationLimitException -> {
605606
messenger.sendUpdatePlaceholder(tabId, newPlaceholder = message("amazonqFeatureDev.placeholder.after_monthly_limit"))
606607
messenger.sendChatInputEnabledMessage(tabId, enabled = true)
607-
messenger.sendError(
608+
messenger.sendErrorToUser(
608609
tabId = tabId,
609610
errMessage = err.message,
610-
retries = retriesRemaining(session),
611-
conversationId = session?.conversationIdUnsafe,
612-
showDefaultMessage = true,
611+
conversationId = session?.conversationIdUnsafe
613612
)
614613

615614
val filePaths: List<NewFileZipInfo> = when (val state = session?.sessionState) {
@@ -725,10 +724,13 @@ class DocController(
725724
)
726725
}
727726
} catch (err: Exception) {
728-
processErrorChatMessage(err, session, tabId)
727+
// For non edit mode lock the chat input until they explicitly click one of the follow-ups
728+
var isEnableChatInput = false;
729+
if (err is DocException && Mode.EDIT == mode) {
730+
isEnableChatInput = err.remainingIterations != null && err.remainingIterations > 0
731+
}
729732

730-
// Lock the chat input until they explicitly click one of the follow-ups
731-
messenger.sendChatInputEnabledMessage(tabId, enabled = false)
733+
processErrorChatMessage(err, session, tabId, isEnableChatInput)
732734
}
733735
}
734736

@@ -808,10 +810,7 @@ class DocController(
808810
message = IncomingDocMessage.OpenDiff(tabId = followUpMessage.tabId, filePath = filePaths[0].zipFilePath, deleted = false)
809811
)
810812
} catch (err: Exception) {
811-
processErrorChatMessage(err, session, tabId = followUpMessage.tabId)
812-
813-
// Lock the chat input until they explicitly click one of the follow-ups
814-
messenger.sendChatInputEnabledMessage(tabId = followUpMessage.tabId, enabled = false)
813+
processErrorChatMessage(err, session, tabId = followUpMessage.tabId, false)
815814
} finally {
816815
messenger.sendUpdatePlaceholder(
817816
tabId = followUpMessage.tabId,
@@ -888,7 +887,7 @@ class DocController(
888887
tabId = tabId,
889888
errMessage = message ?: message("amazonqFeatureDev.exception.retry_request_failed"),
890889
retries = retriesRemaining(session),
891-
conversationId = session?.conversationIdUnsafe,
890+
conversationId = session?.conversationIdUnsafe
892891
)
893892
} finally {
894893
// Finish processing the event

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.NewFil
1313
import software.aws.toolkits.jetbrains.services.cwc.messages.CodeReference
1414
import software.aws.toolkits.jetbrains.services.cwc.messages.RecommendationContentSpan
1515
import software.aws.toolkits.resources.message
16+
import java.util.Collections
1617
import java.util.UUID
1718

1819
suspend fun MessagePublisher.sendAnswer(
@@ -113,6 +114,7 @@ suspend fun MessagePublisher.sendChatInputEnabledMessage(tabId: String, enabled:
113114
this.publish(chatInputEnabledMessage)
114115
}
115116

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

@@ -149,6 +151,47 @@ suspend fun MessagePublisher.sendError(tabId: String, errMessage: String?, retri
149151
)
150152
}
151153

154+
155+
suspend fun MessagePublisher.sendErrorToUser(
156+
tabId: String,
157+
errMessage: String?,
158+
conversationId: String? = null,
159+
isEnableChatInput: Boolean = false
160+
) {
161+
val conversationIdText = if (conversationId == null) "" else "\n\nConversation ID: **$conversationId**"
162+
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+
182+
this.sendAnswer(
183+
tabId = tabId,
184+
messageType = DocMessageType.Answer,
185+
message = errMessage + conversationIdText,
186+
)
187+
188+
this.sendAnswer(
189+
tabId = tabId,
190+
messageType = DocMessageType.SystemPrompt,
191+
followUp = followUps
192+
)
193+
}
194+
152195
suspend fun MessagePublisher.sendMonthlyLimitError(tabId: String) {
153196
this.sendAnswer(
154197
tabId = tabId,

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,18 @@ private suspend fun DocGenerationState.generateCode(codeGenerationId: String, mo
172172

173173
CodeGenerationWorkflowStatus.FAILED -> {
174174
messenger.sendUpdatePromptProgress(tabId = tabID, progressField = null)
175+
val remainingIterations = codeGenerationResultState.codeGenerationRemainingIterationCount()
175176

176177
when (true) {
177178
codeGenerationResultState.codeGenerationStatusDetail()?.contains(
178179
"README_TOO_LARGE"
179180
),
180-
-> docServiceError(message("amazonqDoc.exception.readme_too_large"))
181+
-> docServiceError(message("amazonqDoc.exception.readme_too_large"), remainingIterations=remainingIterations)
181182

182183
codeGenerationResultState.codeGenerationStatusDetail()?.contains(
183184
"README_UPDATE_TOO_LARGE"
184185
),
185-
-> docServiceError(message("amazonqDoc.exception.readme_update_too_large"))
186+
-> docServiceError(message("amazonqDoc.exception.readme_update_too_large"), remainingIterations=remainingIterations)
186187

187188
codeGenerationResultState.codeGenerationStatusDetail()?.contains(
188189
"WORKSPACE_TOO_LARGE"
@@ -197,17 +198,17 @@ private suspend fun DocGenerationState.generateCode(codeGenerationId: String, mo
197198
codeGenerationResultState.codeGenerationStatusDetail()?.contains(
198199
"PROMPT_UNRELATED"
199200
),
200-
-> docServiceError(message("amazonqDoc.exception.prompt_unrelated"))
201+
-> docServiceError(message("amazonqDoc.exception.prompt_unrelated"), remainingIterations = remainingIterations)
201202

202203
codeGenerationResultState.codeGenerationStatusDetail()?.contains(
203204
"PROMPT_TOO_VAGUE"
204205
),
205-
-> docServiceError(message("amazonqDoc.exception.prompt_too_vague"))
206+
-> docServiceError(message("amazonqDoc.exception.prompt_too_vague"), remainingIterations=remainingIterations)
206207

207208
codeGenerationResultState.codeGenerationStatusDetail()?.contains(
208209
"PromptRefusal"
209210
),
210-
-> docServiceError(message("amazonqFeatureDev.exception.prompt_refusal"))
211+
-> docServiceError(message("amazonqFeatureDev.exception.prompt_refusal"), remainingIterations=remainingIterations)
211212

212213
codeGenerationResultState.codeGenerationStatusDetail()?.contains(
213214
"Guardrails"

0 commit comments

Comments
 (0)