Skip to content

Commit 4381e66

Browse files
committed
fix(dev): disable past messages
1 parent a18baf7 commit 4381e66

File tree

10 files changed

+78
-41
lines changed

10 files changed

+78
-41
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package software.aws.toolkits.jetbrains.services.amazonqFeatureDev
66
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.messages.IncomingFeatureDevMessage
77

88
interface InboundAppMessagesHandler {
9+
910
suspend fun processPromptChatMessage(message: IncomingFeatureDevMessage.ChatPrompt)
1011
suspend fun processNewTabCreatedMessage(message: IncomingFeatureDevMessage.NewTabCreated)
1112
suspend fun processTabRemovedMessage(message: IncomingFeatureDevMessage.TabRemoved)

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ class FeatureDevController(
273273
}
274274

275275
messenger.updateFileComponent(message.tabId, filePaths, deletedFiles, messageId)
276+
277+
//TODO: session.acceptCodeMessageId
276278
}
277279

278280
private suspend fun newTabOpened(tabId: String) {
@@ -353,6 +355,9 @@ class FeatureDevController(
353355
messenger
354356
)
355357

358+
//TODO: if (session.acceptCodeMessageId) {
359+
360+
356361
messenger.sendAnswer(
357362
tabId = tabId,
358363
message = message("amazonqFeatureDev.code_generation.updated_code"),
@@ -392,10 +397,11 @@ class FeatureDevController(
392397
}
393398

394399
private suspend fun newTask(tabId: String, isException: Boolean? = false) {
400+
this.disablePreviousFileList(tabId)
401+
395402
val session = getSessionInfo(tabId)
396403
val sessionLatency = System.currentTimeMillis() - session.sessionStartTime
397404

398-
this.disablePreviousFileList(tabId)
399405
AmazonqTelemetry.endChat(
400406
amazonqConversationId = session.conversationId,
401407
amazonqEndOfTheConversationLatency = sessionLatency.toDouble(),
@@ -584,6 +590,8 @@ class FeatureDevController(
584590
message: String,
585591
) {
586592
var session: Session? = null
593+
594+
this.disablePreviousFileList(tabId)
587595
try {
588596
logger.debug { "$FEATURE_NAME: Processing message: $message" }
589597
session = getSessionInfo(tabId)

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.messages.sendC
1616
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.messages.sendCodeResult
1717
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.messages.sendSystemPrompt
1818
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.messages.sendUpdatePlaceholder
19+
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.messages.updateChatAnswer
20+
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.messages.updateFileComponent
1921
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.CodeReferenceGenerated
2022
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.DeletedFileInfo
2123
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.NewFileZipInfo
@@ -132,7 +134,11 @@ suspend fun FeatureDevController.onCodeGeneration(
132134
)
133135
}
134136

135-
messenger.sendSystemPrompt(tabId = tabId, followUp = getFollowUpOptions(session.sessionState.phase))
137+
if (filePaths.any { it.rejected or it.changeApplied } or deletedFiles.any { it.rejected or it.changeApplied }) {
138+
messenger.sendSystemPrompt(tabId = tabId, followUp = getFollowUpOptions(session.sessionState.phase, "Accept remaining changes"))
139+
} else {
140+
messenger.sendSystemPrompt(tabId = tabId, followUp = getFollowUpOptions(session.sessionState.phase, null))
141+
}
136142

137143
messenger.sendUpdatePlaceholder(tabId = tabId, newPlaceholder = message("amazonqFeatureDev.placeholder.after_code_generation"))
138144
} finally {

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/messages/FeatureDevMessage.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ data class FileComponent(
154154
val filePaths: List<NewFileZipInfo>,
155155
val deletedFiles: List<DeletedFileInfo>,
156156
val messageId: String,
157-
val disableFileActions: Boolean,
157+
val disableFileActions: Boolean = false,
158158
) : UiMessage(
159159
tabId = tabId,
160160
type = "updateFileComponent"

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/messages/FeatureDevMessagePublisherExtensions.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ suspend fun MessagePublisher.sendSystemPrompt(
5959
)
6060
}
6161

62+
suspend fun MessagePublisher.updateChatAnswer(tabId: String, messageId: String, message: String?, followUps: List<FollowUp>) {
63+
this.updateChatAnswer(
64+
tabId,
65+
messageId,
66+
message,
67+
followUps,
68+
)
69+
}
70+
6271
suspend fun MessagePublisher.updateFileComponent(
6372
tabId: String,
6473
filePaths: List<NewFileZipInfo>,

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/session/Session.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Session(
3636
private var task: String = ""
3737
private val proxyClient: FeatureDevClient
3838
private val featureDevService: FeatureDevService
39-
private var _codeResultMessageId: String? = null
39+
var _codeResultMessageId: String? = null
4040

4141
// retry session state vars
4242
private var codegenRetries: Int

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/util/FeatureDevControllerUtil.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.messages.Follo
1010
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.SessionStatePhase
1111
import software.aws.toolkits.resources.message
1212

13-
fun getFollowUpOptions(phase: SessionStatePhase?): List<FollowUp> {
13+
fun getFollowUpOptions(phase: SessionStatePhase?, insertCodePillText: String?): List<FollowUp> {
1414
when (phase) {
1515
SessionStatePhase.CODEGEN -> {
16+
val messageText = insertCodePillText ?: message("amazonqFeatureDev.follow_up.insert_code")
1617
return listOf(
1718
FollowUp(
18-
pillText = message("amazonqFeatureDev.follow_up.insert_code"),
19+
pillText = messageText,
1920
type = FollowUpTypes.INSERT_CODE,
2021
icon = FollowUpIcons.Ok,
2122
status = FollowUpStatusType.Success

plugins/amazonq/chat/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/controller/FeatureDevControllerTest.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ class FeatureDevControllerTest : FeatureDevTestBase() {
8181

8282
private val newFileContents =
8383
listOf(
84-
NewFileZipInfo("test.ts", "This is a comment", false),
85-
NewFileZipInfo("test2.ts", "This is a rejected file", true),
84+
NewFileZipInfo("test.ts", "This is a comment", false, false),
85+
NewFileZipInfo("test2.ts", "This is a rejected file", true, false),
8686
)
8787
private val deletedFiles =
8888
listOf(
89-
DeletedFileInfo("delete.ts", false),
90-
DeletedFileInfo("delete2.ts", true),
89+
DeletedFileInfo("delete.ts", false, false),
90+
DeletedFileInfo("delete2.ts", true, false),
9191
)
9292

9393
@Before
@@ -238,15 +238,15 @@ class FeatureDevControllerTest : FeatureDevTestBase() {
238238
),
239239
)
240240

241-
doNothing().`when`(spySession).insertChanges(any(), any(), any())
241+
doNothing().`when`(spySession).insertChanges(any(), any(), any(), any())
242242

243243
spySession.preloader(userMessage, messenger)
244244
controller.processFollowupClickedMessage(message)
245245

246246
mockitoVerify(
247247
spySession,
248248
times(1),
249-
).insertChanges(listOf(newFileContents[0]), listOf(deletedFiles[0]), testReferences) // insert changes for only non rejected files
249+
).insertChanges(listOf(newFileContents[0]), listOf(deletedFiles[0]), testReferences, messenger) // insert changes for only non rejected files
250250
coVerifyOrder {
251251
AmazonqTelemetry.isAcceptedCodeChanges(
252252
amazonqNumberOfFilesAccepted = 2.0, // it should be 2 files per test setup
@@ -304,7 +304,7 @@ class FeatureDevControllerTest : FeatureDevTestBase() {
304304
messenger.sendAnswer(testTabId, message("amazonqFeatureDev.chat_message.requesting_changes"), FeatureDevMessageType.AnswerStream)
305305
messenger.sendUpdatePlaceholder(testTabId, message("amazonqFeatureDev.placeholder.generating_code"))
306306
messenger.sendCodeResult(testTabId, testUploadId, newFileContents, deletedFiles, testReferences)
307-
messenger.sendSystemPrompt(testTabId, getFollowUpOptions(SessionStatePhase.CODEGEN))
307+
messenger.sendSystemPrompt(testTabId, getFollowUpOptions(SessionStatePhase.CODEGEN, null))
308308
messenger.sendUpdatePlaceholder(testTabId, message("amazonqFeatureDev.placeholder.after_code_generation"))
309309
messenger.sendAsyncEventProgress(testTabId, false)
310310
messenger.sendChatInputEnabledMessage(testTabId, false)

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

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface ConnectorProps {
2020
onMessageReceived?: (tabID: string, messageData: any, needToShowAPIDocsTab: boolean) => void
2121
onAsyncEventProgress: (tabID: string, inProgress: boolean, message: string) => void
2222
onChatAnswerReceived?: (tabID: string, message: ChatItem) => void
23+
onChatAnswerUpdated?: (tabID: string, message: ChatItem) => void
2324
sendFeedback?: (tabId: string, feedbackPayload: FeedbackPayload) => void | undefined
2425
onError: (tabID: string, message: string, title: string) => void
2526
onWarning: (tabID: string, message: string, title: string) => void
@@ -36,6 +37,7 @@ export class Connector {
3637
private readonly onError
3738
private readonly onWarning
3839
private readonly onChatAnswerReceived
40+
private readonly onChatAnswerUpdated
3941
private readonly onAsyncEventProgress
4042
private readonly updatePlaceholder
4143
private readonly chatInputEnabled
@@ -47,6 +49,7 @@ export class Connector {
4749
constructor(props: ConnectorProps) {
4850
this.sendMessageToExtension = props.sendMessageToExtension
4951
this.onChatAnswerReceived = props.onChatAnswerReceived
52+
this.onChatAnswerUpdated = props.onChatAnswerUpdated
5053
this.onWarning = props.onWarning
5154
this.onError = props.onError
5255
this.onAsyncEventProgress = props.onAsyncEventProgress
@@ -130,24 +133,7 @@ export class Connector {
130133

131134
private processChatMessage = async (messageData: any): Promise<void> => {
132135
if (this.onChatAnswerReceived !== undefined) {
133-
const answer: ChatItem = {
134-
type: messageData.messageType,
135-
body: messageData.message ?? undefined,
136-
messageId: messageData.messageID ?? messageData.triggerID ?? '',
137-
relatedContent: undefined,
138-
canBeVoted: messageData.canBeVoted,
139-
snapToTop: messageData.snapToTop,
140-
followUp:
141-
messageData.followUps !== undefined && messageData.followUps.length > 0
142-
? {
143-
text:
144-
messageData.messageType === ChatItemType.SYSTEM_PROMPT
145-
? ''
146-
: 'Please follow up with one of these',
147-
options: messageData.followUps,
148-
}
149-
: undefined,
150-
}
136+
const answer: ChatItem = this.createAnswer(messageData)
151137
this.onChatAnswerReceived(messageData.tabID, answer)
152138
}
153139
}
@@ -202,11 +188,38 @@ export class Connector {
202188
return
203189
}
204190

191+
private createAnswer = (messageData: any): ChatItem => {
192+
return {
193+
type: messageData.messageType,
194+
body: messageData.message ?? undefined,
195+
messageId: messageData.messageId ?? messageData.messageID ?? messageData.triggerID ?? '',
196+
relatedContent: undefined,
197+
canBeVoted: messageData.canBeVoted ?? undefined,
198+
snapToTop: messageData.snapToTop ?? undefined,
199+
followUp:
200+
messageData.followUps !== undefined && Array.isArray(messageData.followUps)
201+
? {
202+
text:
203+
messageData.messageType === ChatItemType.SYSTEM_PROMPT ||
204+
messageData.followUps.length === 0
205+
? ''
206+
: 'Please follow up with one of these',
207+
options: messageData.followUps,
208+
}
209+
: undefined,
210+
}
211+
}
212+
205213
handleMessageReceive = async (messageData: any): Promise<void> => {
206214
if (messageData.type === 'updateFileComponent') {
207215
this.onFileComponentUpdate(messageData.tabID, messageData.filePaths, messageData.deletedFiles, messageData.messageId, messageData.disableFileActions)
208216
return
209217
}
218+
if (messageData.type === 'updateChatAnswer') {
219+
const answer = this.createAnswer(messageData)
220+
this.onChatAnswerUpdated?.(messageData.tabID, answer)
221+
return
222+
}
210223
if (messageData.type === 'errorMessage') {
211224
this.onError(messageData.tabID, messageData.message, messageData.title)
212225
return

plugins/amazonq/mynah-ui/src/mynah-ui/ui/diffTree/actions.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ export function getDetails(filePaths: DiffTreeFileInfo[]): Record<string, TreeNo
1010
if (filePath.changeApplied) {
1111
details[filePath.zipFilePath] = {
1212
status: 'success',
13-
label: 'File accepted',
13+
label: 'Change accepted',
1414
icon: MynahIcons.OK,
1515
}
1616
} else if (filePath.rejected) {
1717
details[filePath.zipFilePath] = {
1818
status: 'error',
19-
label: 'File rejected',
19+
label: 'Change rejected',
2020
icon: MynahIcons.CANCEL_CIRCLE,
2121
}
2222
}
@@ -30,14 +30,7 @@ export function getActions(filePaths: DiffTreeFileInfo[]): Record<string, FileNo
3030
return actions
3131
}
3232

33-
actions[filePath.zipFilePath] = [
34-
{
35-
icon: MynahIcons.OK,
36-
status: 'success',
37-
name: 'accept-change',
38-
description: 'Accept file change',
39-
}
40-
]
33+
actions[filePath.zipFilePath] = []
4134

4235
switch (filePath.rejected) {
4336
case true:
@@ -48,6 +41,12 @@ export function getActions(filePaths: DiffTreeFileInfo[]): Record<string, FileNo
4841
})
4942
break
5043
case false:
44+
actions[filePath.zipFilePath].push({
45+
icon: MynahIcons.OK,
46+
status: 'success',
47+
name: 'accept-change',
48+
description: 'Accept change',
49+
})
5150
actions[filePath.zipFilePath].push({
5251
icon: MynahIcons.CANCEL_CIRCLE,
5352
status: 'error',

0 commit comments

Comments
 (0)