From a2e1476c95d2cbff20d20b69970ec9c9dc5cfa7e Mon Sep 17 00:00:00 2001 From: laileni Date: Thu, 17 Apr 2025 16:13:44 -0700 Subject: [PATCH 1/2] Fixing bugs --- packages/core/src/amazonq/webview/ui/main.ts | 14 ++++++++++++++ .../controllers/chat/messenger/messenger.ts | 18 ++++++++++++++---- .../core/src/codewhispererChat/tools/fsRead.ts | 13 ++++++------- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/packages/core/src/amazonq/webview/ui/main.ts b/packages/core/src/amazonq/webview/ui/main.ts index 6fb2ce273d8..6303d4c02db 100644 --- a/packages/core/src/amazonq/webview/ui/main.ts +++ b/packages/core/src/amazonq/webview/ui/main.ts @@ -178,6 +178,9 @@ export const createMynahUI = ( let messageController: MessageController function getCodeBlockActions(messageData: any) { + if (!messageData.codeBlockActions) { + return {} + } // Show ViewDiff and AcceptDiff for allowedCommands in CWC const isEnabled = featureConfigs.get('ViewDiffInChat')?.variation === 'TREATMENT' const tab = tabsStorage.getTab(messageData?.tabID || '') @@ -204,6 +207,17 @@ export const createMynahUI = ( }, } } + if ( + tab?.type === 'cwc' && + messageData.codeBlockActions['insert-to-cursor'] === null && + messageData.codeBlockActions['copy'] === null + ) { + return { + 'insert-to-cursor': undefined, + // eslint-disable-next-line prettier/prettier + copy: undefined, + } + } // Show only "Copy" option for codeblocks in Q Test Tab if (tab?.type === 'testgen') { return { diff --git a/packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts b/packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts index d58fa3c15e1..9b0022c9fde 100644 --- a/packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts +++ b/packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts @@ -21,6 +21,7 @@ import { SelectTabMessage, ChatItemHeader, ToolMessage, + ChatMessageType, } from '../../../view/connector/connector' import { EditorContextCommandType } from '../../../commands/registerCommands' import { ChatResponseStream as qdevChatResponseStream } from '@amzn/amazon-q-developer-streaming-client' @@ -71,6 +72,7 @@ import { ConversationTracker } from '../../../storages/conversationTracker' import { waitTimeout, Timeout } from '../../../../shared/utilities/timeoutUtils' import { FsReadParams } from '../../../tools/fsRead' import { ListDirectoryParams } from '../../../tools/listDirectory' +import { fs } from '../../../../shared/fs/fs' export type StaticTextResponseType = 'quick-action-help' | 'onboarding-help' | 'transform' | 'help' @@ -193,12 +195,16 @@ export class Messenger { return codeBlocks.length } - public handleFileReadOrListOperation = (session: ChatSession, toolUse: ToolUse, tool: Tool) => { + public handleFileReadOrListOperation = async (session: ChatSession, toolUse: ToolUse, tool: Tool) => { const messageIdToUpdate = tool.type === ToolType.FsRead ? session.messageIdToUpdate : session.messageIdToUpdateListDirectory const messageId = messageIdToUpdate ?? toolUse?.toolUseId ?? '' const operationType = tool.type === ToolType.FsRead ? 'read' : 'listDir' const input = toolUse.input as unknown as FsReadParams | ListDirectoryParams + const fileExists = await fs.exists(input.path) + if (!fileExists) { + return messageIdToUpdate + } const existingPaths = session.getFilePathsByMessageId(messageId) // Check if path already exists in the list @@ -359,7 +365,7 @@ export class Messenger { changeList = await tool.tool.getDiffChanges() } if (isReadOrList) { - messageIdToUpdate = this.handleFileReadOrListOperation(session, toolUse, tool) + messageIdToUpdate = await this.handleFileReadOrListOperation(session, toolUse, tool) } const validation = ToolUtils.requiresAcceptance(tool) const chatStream = new ChatStream( @@ -768,8 +774,10 @@ export class Messenger { const buttons: ChatItemButton[] = [] let header: ChatItemHeader | undefined = undefined let messageID: string = toolUse?.toolUseId ?? '' + let messageType: ChatMessageType = 'answer-part' if (toolUse?.name === ToolType.ExecuteBash && message.startsWith('```shell')) { if (validation.requiresAcceptance) { + messageType = 'answer' const buttons: ChatItemButton[] = [ { id: 'reject-shell-command', @@ -796,6 +804,7 @@ export class Messenger { if (this.isTriggerCancelled(triggerID)) { return } + messageType = 'answer' const input = toolUse.input as unknown as FsWriteParams const fileName = path.basename(input.path) const changes = getDiffLinesFromChanges(changeList) @@ -829,6 +838,7 @@ export class Messenger { * requiredAcceptance = false, we use messageID = toolID and we keep on updating this messageID * requiredAcceptance = true, IDE sends messageID != toolID, some default value, as this overlaps with previous message. */ messageID = 'toolUse' + messageType = 'answer' const buttons: ChatItemButton[] = [ { id: 'confirm-tool-use', @@ -858,8 +868,8 @@ export class Messenger { this.dispatcher.sendChatMessage( new ChatMessage( { - message: message, - messageType: toolUse?.name === ToolType.FsWrite ? 'answer' : 'answer-part', + message, + messageType, followUps: undefined, followUpsHeader: undefined, relatedSuggestions: undefined, diff --git a/packages/core/src/codewhispererChat/tools/fsRead.ts b/packages/core/src/codewhispererChat/tools/fsRead.ts index dd698463cf2..7559ba71a02 100644 --- a/packages/core/src/codewhispererChat/tools/fsRead.ts +++ b/packages/core/src/codewhispererChat/tools/fsRead.ts @@ -52,21 +52,20 @@ export class FsRead { if (requiresAcceptance) { const fileName = path.basename(this.fsPath) const fileUri = vscode.Uri.file(this.fsPath) - updates.write(`Reading file: [${fileName}](${fileUri}), `) - const [start, end] = this.readRange ?? [] - + let readMessage = '' if (start && end) { - updates.write(`from line ${start} to ${end}`) + readMessage += `from line ${start} to ${end}` } else if (start) { if (start > 0) { - updates.write(`from line ${start} to end of file`) + readMessage += `from line ${start} to end of file` } else { - updates.write(`${start} line from the end of file to end of file`) + readMessage += `${start} line from the end of file to end of file` } } else { - updates.write('all lines') + readMessage += 'all lines' } + updates.write(`Reading file: [${fileName}](${fileUri}), ${readMessage}`) } else { updates.write('') } From 4e79bd5971383433b78d387a845ff8984569686f Mon Sep 17 00:00:00 2001 From: Tai Lai Date: Thu, 17 Apr 2025 14:13:08 -0700 Subject: [PATCH 2/2] Removing insert at cursor from Pair programming mode --- packages/core/src/amazonq/webview/ui/main.ts | 14 ++++++-------- .../controllers/chat/messenger/messenger.ts | 8 +++++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/core/src/amazonq/webview/ui/main.ts b/packages/core/src/amazonq/webview/ui/main.ts index 6303d4c02db..9d0507b846e 100644 --- a/packages/core/src/amazonq/webview/ui/main.ts +++ b/packages/core/src/amazonq/webview/ui/main.ts @@ -207,16 +207,14 @@ export const createMynahUI = ( }, } } - if ( - tab?.type === 'cwc' && - messageData.codeBlockActions['insert-to-cursor'] === null && - messageData.codeBlockActions['copy'] === null - ) { - return { + if (tab?.type === 'cwc' && messageData.codeBlockActions['insert-to-cursor'] === null) { + const actions: Record = { 'insert-to-cursor': undefined, - // eslint-disable-next-line prettier/prettier - copy: undefined, } + if (messageData.codeBlockActions['copy'] === null) { + actions.copy = undefined + } + return actions } // Show only "Copy" option for codeblocks in Q Test Tab if (tab?.type === 'testgen') { diff --git a/packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts b/packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts index 9b0022c9fde..97fe686920f 100644 --- a/packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts +++ b/packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts @@ -54,6 +54,7 @@ import { MynahIconsType, DetailedList, MynahUIDataModel, + CodeBlockActions, } from '@aws/mynah-ui' import { Database } from '../../../../shared/db/chatDb/chatDb' import { TabType } from '../../../../amazonq/webview/ui/storages/tabsStorage' @@ -477,7 +478,11 @@ export class Messenger { if (this.isTriggerCancelled(triggerID)) { return } - + let codeBlockActions: CodeBlockActions | null = {} + if (session.pairProgrammingModeOn) { + // eslint-disable-next-line unicorn/no-null + codeBlockActions = { 'insert-to-cursor': null } + } this.dispatcher.sendChatMessage( new ChatMessage( { @@ -492,6 +497,7 @@ export class Messenger { userIntent: triggerPayload.userIntent, codeBlockLanguage: codeBlockLanguage, contextList: undefined, + codeBlockActions, }, tabID )