Skip to content

Commit 34c42b9

Browse files
committed
fix(dev): use currentIteration since the counts isnt provided when stop code gen
1 parent 290ed7d commit 34c42b9

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/controller/FeatureDevControllerExtensions.kt

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ suspend fun FeatureDevController.onCodeGeneration(
5757
var totalIterations: Int? = state.codeGenerationTotalIterationCount
5858

5959
if (state.token?.token()?.isCancellationRequested == true) {
60-
this.disposeToken(state, messenger, tabId, remainingIterations, totalIterations)
60+
this.disposeToken(state, messenger, tabId, state.currentIteration?.let { CODE_GENERATION_RETRY_LIMIT.minus(it) }, CODE_GENERATION_RETRY_LIMIT)
6161
return
6262
}
6363

@@ -82,7 +82,7 @@ suspend fun FeatureDevController.onCodeGeneration(
8282
}
8383

8484
if (state.token?.token()?.isCancellationRequested == true) {
85-
disposeToken(state, messenger, tabId, remainingIterations, totalIterations)
85+
disposeToken(state, messenger, tabId, state.currentIteration?.let { CODE_GENERATION_RETRY_LIMIT.minus(it) }, CODE_GENERATION_RETRY_LIMIT)
8686
return
8787
}
8888

@@ -162,25 +162,50 @@ private suspend fun FeatureDevController.disposeToken(
162162
remainingIterations: Number?,
163163
totalIterations: Number?,
164164
) {
165-
if (state.codeGenerationRemainingIterationCount !== null) {
165+
166+
if (remainingIterations !== null && remainingIterations.toInt() <= 0) {
166167
messenger.sendAnswer(
167168
tabId = tabId,
168169
messageType = FeatureDevMessageType.Answer,
169170
message =
170171
message(
171-
"amazonqFeatureDev.code_generation.stopped_code_generation",
172-
remainingIterations ?: state.currentIteration as Any,
173-
totalIterations ?: CODE_GENERATION_RETRY_LIMIT,
172+
"amazonqFeatureDev.code_generation.stopped_code_generation_no_iterations"
174173
),
175174
)
176-
} else {
177-
messenger.sendAnswer(
175+
//I stopped generating your code. You don't have more iterations left, however, you can start a new session
176+
messenger.sendSystemPrompt(
178177
tabId = tabId,
179-
messageType = FeatureDevMessageType.Answer,
180-
message = message("amazonqFeatureDev.code_generation.stopped_code_generation_without_total", state.currentIteration as Any),
178+
followUp = listOf(
179+
FollowUp(
180+
pillText = message("amazonqFeatureDev.follow_up.new_task"),
181+
type = FollowUpTypes.NEW_TASK,
182+
status = FollowUpStatusType.Info
183+
),
184+
FollowUp(
185+
pillText = message("amazonqFeatureDev.follow_up.close_session"),
186+
type = FollowUpTypes.CLOSE_SESSION,
187+
status = FollowUpStatusType.Info
188+
)
189+
)
181190
)
191+
messenger.sendChatInputEnabledMessage(tabId = tabId, enabled = false)
192+
messenger.sendUpdatePlaceholder(tabId = tabId, newPlaceholder = message("amazonqFeatureDev.placeholder.after_code_generation"))
193+
194+
return
182195
}
183196

197+
198+
messenger.sendAnswer(
199+
tabId = tabId,
200+
messageType = FeatureDevMessageType.Answer,
201+
message =
202+
message(
203+
"amazonqFeatureDev.code_generation.stopped_code_generation",
204+
remainingIterations ?: state.currentIteration?.let { CODE_GENERATION_RETRY_LIMIT.minus(it) } as Any,
205+
totalIterations ?: CODE_GENERATION_RETRY_LIMIT,
206+
),
207+
)
208+
184209
messenger.sendChatInputEnabledMessage(tabId = tabId, enabled = true)
185210

186211
messenger.sendUpdatePlaceholder(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ amazonqFeatureDev.code_generation.notification_open_link=Open chat
5858
amazonqFeatureDev.code_generation.notification_title=Amazon Q Developer Agent for software development
5959
amazonqFeatureDev.code_generation.provide_code_feedback=How can I improve the code for your use case?
6060
amazonqFeatureDev.code_generation.stopped_code_generation=I stopped generating your code. If you want to continue working on this task, provide another description. You have {0} out of {1} code generations left.
61-
amazonqFeatureDev.code_generation.stopped_code_generation_without_total=I stopped generating your code. If you want to continue working on this task, provide another description. You have started {0} code generations.
6261
amazonqFeatureDev.code_generation.stopping_code_generation=Stopping code generation...
62+
amazonqFeatureDev.code_generation.stopped_code_generation_no_iterations=I stopped generating your code. You don't have more iterations left, however, you can start a new session.
6363
amazonqFeatureDev.code_generation.updated_code=Okay, I updated your code files. Would you like to work on another task?
6464
amazonqFeatureDev.content_length.error_text=The folder you selected is too large for me to use as context. Please choose a smaller folder to work on. For more information on quotas, see the [Amazon Q Developer documentation](https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/software-dev.html#quotas).
6565
amazonqFeatureDev.error_text=Sorry, we encountered a problem when processing your request.

0 commit comments

Comments
 (0)