Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions packages/core/src/codewhispererChat/controllers/chat/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
36 changes: 23 additions & 13 deletions packages/core/src/codewhispererChat/tools/chatStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
}
}
6 changes: 3 additions & 3 deletions packages/core/src/codewhispererChat/tools/fsRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/utilities/messageUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down