Skip to content

Commit e5d2f6a

Browse files
authored
feat: fsWrite undo button (#1053)
1 parent 74abb12 commit e5d2f6a

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export class AgenticChatController implements ChatHandlers {
150150
}
151151

152152
async onButtonClick(params: ButtonClickParams): Promise<ButtonClickResult> {
153+
this.#log(`onButtonClick event with params: ${JSON.stringify(params)}`)
153154
if (params.buttonId === 'run-shell-command' || params.buttonId === 'reject-shell-command') {
154155
const session = this.#chatSessionManagementService.getSession(params.tabId)
155156
if (!session.data) {
@@ -166,15 +167,36 @@ export class AgenticChatController implements ChatHandlers {
166167
return {
167168
success: true,
168169
}
170+
} else if (params.buttonId === 'undo-changes') {
171+
const toolUseId = params.messageId
172+
try {
173+
await this.#undoFileChange(toolUseId)
174+
} catch (err: any) {
175+
return { success: false, failureReason: err.message }
176+
}
177+
return {
178+
success: true,
179+
}
169180
} else {
170-
this.#log(`onButtonClick event with params: ${JSON.stringify(params)}`)
171181
return {
172182
success: false,
173183
failureReason: 'not implemented',
174184
}
175185
}
176186
}
177187

188+
async #undoFileChange(toolUseId: string): Promise<void> {
189+
this.#log(`Reverting file change for tooluseId: ${toolUseId}`)
190+
const toolUse = this.#triggerContext.getToolUseLookup().get(toolUseId)
191+
192+
const input = toolUse?.input as unknown as FsWriteParams
193+
if (toolUse?.oldContent) {
194+
await this.#features.workspace.fs.writeFile(input.path, toolUse.oldContent)
195+
} else {
196+
await this.#features.workspace.fs.rm(input.path)
197+
}
198+
}
199+
178200
async onCreatePrompt(params: CreatePromptParams): Promise<void> {
179201
const newFilePath = getNewPromptFilePath(params.promptName)
180202
const newFileContent = ''

0 commit comments

Comments
 (0)