@@ -21,6 +21,7 @@ import {
2121 SelectTabMessage ,
2222 ChatItemHeader ,
2323 ToolMessage ,
24+ ChatMessageType ,
2425} from '../../../view/connector/connector'
2526import { EditorContextCommandType } from '../../../commands/registerCommands'
2627import { ChatResponseStream as qdevChatResponseStream } from '@amzn/amazon-q-developer-streaming-client'
@@ -53,6 +54,7 @@ import {
5354 MynahIconsType ,
5455 DetailedList ,
5556 MynahUIDataModel ,
57+ CodeBlockActions ,
5658} from '@aws/mynah-ui'
5759import { Database } from '../../../../shared/db/chatDb/chatDb'
5860import { TabType } from '../../../../amazonq/webview/ui/storages/tabsStorage'
@@ -71,6 +73,7 @@ import { ConversationTracker } from '../../../storages/conversationTracker'
7173import { waitTimeout , Timeout } from '../../../../shared/utilities/timeoutUtils'
7274import { FsReadParams } from '../../../tools/fsRead'
7375import { ListDirectoryParams } from '../../../tools/listDirectory'
76+ import { fs } from '../../../../shared/fs/fs'
7477
7578export type StaticTextResponseType = 'quick-action-help' | 'onboarding-help' | 'transform' | 'help'
7679
@@ -193,12 +196,16 @@ export class Messenger {
193196 return codeBlocks . length
194197 }
195198
196- public handleFileReadOrListOperation = ( session : ChatSession , toolUse : ToolUse , tool : Tool ) => {
199+ public handleFileReadOrListOperation = async ( session : ChatSession , toolUse : ToolUse , tool : Tool ) => {
197200 const messageIdToUpdate =
198201 tool . type === ToolType . FsRead ? session . messageIdToUpdate : session . messageIdToUpdateListDirectory
199202 const messageId = messageIdToUpdate ?? toolUse ?. toolUseId ?? ''
200203 const operationType = tool . type === ToolType . FsRead ? 'read' : 'listDir'
201204 const input = toolUse . input as unknown as FsReadParams | ListDirectoryParams
205+ const fileExists = await fs . exists ( input . path )
206+ if ( ! fileExists ) {
207+ return messageIdToUpdate
208+ }
202209 const existingPaths = session . getFilePathsByMessageId ( messageId )
203210
204211 // Check if path already exists in the list
@@ -359,7 +366,7 @@ export class Messenger {
359366 changeList = await tool . tool . getDiffChanges ( )
360367 }
361368 if ( isReadOrList ) {
362- messageIdToUpdate = this . handleFileReadOrListOperation ( session , toolUse , tool )
369+ messageIdToUpdate = await this . handleFileReadOrListOperation ( session , toolUse , tool )
363370 }
364371 const validation = ToolUtils . requiresAcceptance ( tool )
365372 const chatStream = new ChatStream (
@@ -471,7 +478,11 @@ export class Messenger {
471478 if ( this . isTriggerCancelled ( triggerID ) ) {
472479 return
473480 }
474-
481+ let codeBlockActions : CodeBlockActions | null = { }
482+ if ( session . pairProgrammingModeOn ) {
483+ // eslint-disable-next-line unicorn/no-null
484+ codeBlockActions = { 'insert-to-cursor' : null }
485+ }
475486 this . dispatcher . sendChatMessage (
476487 new ChatMessage (
477488 {
@@ -486,6 +497,7 @@ export class Messenger {
486497 userIntent : triggerPayload . userIntent ,
487498 codeBlockLanguage : codeBlockLanguage ,
488499 contextList : undefined ,
500+ codeBlockActions,
489501 } ,
490502 tabID
491503 )
@@ -768,8 +780,10 @@ export class Messenger {
768780 const buttons : ChatItemButton [ ] = [ ]
769781 let header : ChatItemHeader | undefined = undefined
770782 let messageID : string = toolUse ?. toolUseId ?? ''
783+ let messageType : ChatMessageType = 'answer-part'
771784 if ( toolUse ?. name === ToolType . ExecuteBash && message . startsWith ( '```shell' ) ) {
772785 if ( validation . requiresAcceptance ) {
786+ messageType = 'answer'
773787 const buttons : ChatItemButton [ ] = [
774788 {
775789 id : 'reject-shell-command' ,
@@ -796,6 +810,7 @@ export class Messenger {
796810 if ( this . isTriggerCancelled ( triggerID ) ) {
797811 return
798812 }
813+ messageType = 'answer'
799814 const input = toolUse . input as unknown as FsWriteParams
800815 const fileName = path . basename ( input . path )
801816 const changes = getDiffLinesFromChanges ( changeList )
@@ -829,6 +844,7 @@ export class Messenger {
829844 * requiredAcceptance = false, we use messageID = toolID and we keep on updating this messageID
830845 * requiredAcceptance = true, IDE sends messageID != toolID, some default value, as this overlaps with previous message. */
831846 messageID = 'toolUse'
847+ messageType = 'answer'
832848 const buttons : ChatItemButton [ ] = [
833849 {
834850 id : 'confirm-tool-use' ,
@@ -858,8 +874,8 @@ export class Messenger {
858874 this . dispatcher . sendChatMessage (
859875 new ChatMessage (
860876 {
861- message : message ,
862- messageType : toolUse ?. name === ToolType . FsWrite ? 'answer' : 'answer-part' ,
877+ message,
878+ messageType,
863879 followUps : undefined ,
864880 followUpsHeader : undefined ,
865881 relatedSuggestions : undefined ,
0 commit comments