Skip to content

Commit 3748934

Browse files
committed
feat: send chat update on undo
1 parent f396bd6 commit 3748934

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

chat-client/src/client/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ export function toMynahButtons(buttons: Button[] | undefined): ChatItemButton[]
1111
}
1212

1313
export function toMynahHeader(header: ChatMessage['header']): ChatItemContent['header'] {
14-
return { ...header, icon: toMynahIcon(header?.icon), buttons: toMynahButtons(header?.buttons) }
14+
return {
15+
...header,
16+
icon: toMynahIcon(header?.icon),
17+
buttons: toMynahButtons(header?.buttons),
18+
status: { ...header?.status, icon: toMynahIcon(header?.status?.icon) },
19+
}
1520
}
1621

1722
export function toDetailsWithoutIcon(

server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,26 @@ export class AgenticChatController implements ChatHandlers {
171171
const toolUseId = params.messageId
172172
try {
173173
await this.#undoFileChange(toolUseId)
174+
const cachedToolUse = this.#triggerContext.getToolUseLookup().get(toolUseId)
175+
if (cachedToolUse) {
176+
this.#features.chat.sendChatUpdate({
177+
tabId: params.tabId,
178+
data: {
179+
messages: [
180+
{
181+
...cachedToolUse.chatResult,
182+
header: {
183+
...cachedToolUse.chatResult?.header,
184+
buttons: cachedToolUse.chatResult?.header?.buttons?.filter(
185+
button => button.id !== 'undo-changes'
186+
),
187+
status: { status: 'error', icon: 'cancel', text: 'Change discarded' },
188+
},
189+
},
190+
],
191+
},
192+
})
193+
}
174194
} catch (err: any) {
175195
return { success: false, failureReason: err.message }
176196
}
@@ -554,6 +574,11 @@ export class AgenticChatController implements ChatHandlers {
554574
break
555575
case 'fsWrite':
556576
const chatResult = await this.#getFsWriteChatResult(toolUse)
577+
const toolUseLookup = this.#triggerContext.getToolUseLookup()
578+
const cachedToolUse = toolUseLookup.get(toolUse.toolUseId)
579+
if (cachedToolUse) {
580+
toolUseLookup.set(toolUse.toolUseId, { ...cachedToolUse, chatResult })
581+
}
557582
await chatResultStream.writeResultBlock(chatResult)
558583
break
559584
case 'executeBash':

server/aws-lsp-codewhisperer/src/language-server/agenticChat/context/agenticChatTriggerContext.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
FileList,
2121
TextDocument,
2222
OPEN_WORKSPACE_INDEX_SETTINGS_BUTTON_ID,
23+
ChatResult,
2324
} from '@aws/language-server-runtimes/server-interface'
2425
import { Features } from '../../types'
2526
import { DocumentContext, DocumentContextExtractor } from '../../chat/contexts/documentContext'
@@ -58,7 +59,7 @@ export class AgenticChatTriggerContext {
5859
#lsp: Features['lsp']
5960
#logging: Features['logging']
6061
#documentContextExtractor: DocumentContextExtractor
61-
#toolUseLookup: Map<string, ToolUse & { oldContent?: string }>
62+
#toolUseLookup: Map<string, ToolUse & { oldContent?: string; chatResult?: ChatResult }>
6263

6364
constructor({ workspace, lsp, logging }: Pick<Features, 'workspace' | 'lsp' | 'logging'> & Partial<Features>) {
6465
this.#workspace = workspace

0 commit comments

Comments
 (0)