diff --git a/packages/core/src/codewhispererChat/controllers/chat/controller.ts b/packages/core/src/codewhispererChat/controllers/chat/controller.ts index c06bfc1db98..ce37b6f019c 100644 --- a/packages/core/src/codewhispererChat/controllers/chat/controller.ts +++ b/packages/core/src/codewhispererChat/controllers/chat/controller.ts @@ -830,6 +830,20 @@ export class ChatController { } private async processCustomFormAction(message: CustomFormActionMessage) { + if (message.action.id.startsWith('reject-code-diff')) { + // revert the file changes + const toolUseId = message.action.id.split('/')[1] + const backups = this.sessionStorage.getSession(message.tabID!).fsWriteBackups + const { filePath, content, isNew } = backups.get(toolUseId) ?? {} + if (filePath && isNew) { + await fs.delete(filePath) + } else if (filePath && content !== undefined) { + await fs.writeFile(filePath, content) + } + await this.closeDiffView() + return + } + switch (message.action.id) { case 'submit-create-prompt': await this.handleCreatePrompt(message) @@ -847,19 +861,6 @@ export class ChatController { default: getLogger().warn(`Unhandled action: ${message.action.id}`) } - - if (message.action.id.startsWith('reject-code-diff')) { - // revert the changes - const toolUseId = message.action.id.split('/')[1] - const backups = this.sessionStorage.getSession(message.tabID!).fsWriteBackups - const { filePath, content, isNew } = backups.get(toolUseId) ?? {} - if (filePath && isNew) { - await fs.delete(filePath) - } else if (filePath && content !== undefined) { - await fs.writeFile(filePath, content) - } - await this.closeDiffView() - } } private async processContextSelected(message: ContextSelectedMessage) { diff --git a/packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts b/packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts index 9fe06263a28..fcd1fcc27c2 100644 --- a/packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts +++ b/packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts @@ -250,9 +250,11 @@ export class Messenger { const actionId = tool.type === ToolType.ExecuteBash ? 'run-shell-command' : 'generic-tool-execution' - this.dispatcher.sendCustomFormActionMessage( - new CustomFormActionMessage(tabID, { id: actionId }) - ) + if (!validation.requiresAcceptance) { + this.dispatcher.sendCustomFormActionMessage( + new CustomFormActionMessage(tabID, { id: actionId }) + ) + } } else { // TODO: Handle the error } diff --git a/packages/core/src/codewhispererChat/tools/chatStream.ts b/packages/core/src/codewhispererChat/tools/chatStream.ts index 40177813593..18e84bccf3f 100644 --- a/packages/core/src/codewhispererChat/tools/chatStream.ts +++ b/packages/core/src/codewhispererChat/tools/chatStream.ts @@ -32,21 +32,31 @@ export class ChatStream extends Writable { } override _write(chunk: Buffer, encoding: BufferEncoding, callback: (error?: Error | null) => void): void { - const text = chunk.toString() - this.accumulatedLogs += text - this.logger.debug(`ChatStream received chunk: ${text}`) - this.messenger.sendPartialToolLog( - this.accumulatedLogs, - this.tabID, - this.triggerID, - this.toolUse, - this.validation, - this.changeList - ) - callback() + try { + const text = chunk.toString() + this.accumulatedLogs += text + this.logger.debug(`ChatStream received chunk: ${text}`) + this.messenger.sendPartialToolLog( + this.accumulatedLogs, + this.tabID, + this.triggerID, + this.toolUse, + this.validation, + this.changeList + ) + callback() + } catch (error) { + this.logger.error(`Error in ChatStream.write: ${error}`) + callback(error instanceof Error ? error : new Error(String(error))) + } } override _final(callback: (error?: Error | null) => void): void { - callback() + try { + callback() + } catch (error) { + this.logger.error(`Error in ChatStream.final: ${error}`) + callback(error instanceof Error ? error : new Error(String(error))) + } } } diff --git a/packages/core/src/codewhispererChat/tools/fsRead.ts b/packages/core/src/codewhispererChat/tools/fsRead.ts index 07fd64d5293..905056597af 100644 --- a/packages/core/src/codewhispererChat/tools/fsRead.ts +++ b/packages/core/src/codewhispererChat/tools/fsRead.ts @@ -50,15 +50,15 @@ export class FsRead { public queueDescription(updates: Writable): void { const fileName = path.basename(this.fsPath) const fileUri = vscode.Uri.file(this.fsPath) - updates.write(`Reading file: [${fileName}](${fileUri}), `) + updates.write(`Reading file: [${fileName}](${fileUri}) `) const [start, end] = this.readRange ?? [] if (start && end) { - updates.write(`from line ${start} to ${end}`) + updates.write(`L${start} to L${end}`) } else if (start) { if (start > 0) { - updates.write(`from line ${start} to end of file`) + updates.write(`from L${start} to end of file`) } else { updates.write(`${start} line from the end of file to end of file`) } diff --git a/packages/core/src/shared/utilities/messageUtil.ts b/packages/core/src/shared/utilities/messageUtil.ts index f2cefe824de..f1aa690ff26 100644 --- a/packages/core/src/shared/utilities/messageUtil.ts +++ b/packages/core/src/shared/utilities/messageUtil.ts @@ -13,7 +13,7 @@ export interface MessageErrorInfo { } export function extractErrorInfo(error: any): MessageErrorInfo { - let errorMessage = 'Error reading chat stream.' + let errorMessage = 'Error reading chat stream: ' + error.message let statusCode = undefined let requestId = undefined