@@ -21,6 +21,7 @@ import {
21
21
SelectTabMessage ,
22
22
ChatItemHeader ,
23
23
ToolMessage ,
24
+ ChatMessageType ,
24
25
} from '../../../view/connector/connector'
25
26
import { EditorContextCommandType } from '../../../commands/registerCommands'
26
27
import { ChatResponseStream as qdevChatResponseStream } from '@amzn/amazon-q-developer-streaming-client'
@@ -53,6 +54,7 @@ import {
53
54
MynahIconsType ,
54
55
DetailedList ,
55
56
MynahUIDataModel ,
57
+ CodeBlockActions ,
56
58
} from '@aws/mynah-ui'
57
59
import { Database } from '../../../../shared/db/chatDb/chatDb'
58
60
import { TabType } from '../../../../amazonq/webview/ui/storages/tabsStorage'
@@ -71,6 +73,7 @@ import { ConversationTracker } from '../../../storages/conversationTracker'
71
73
import { waitTimeout , Timeout } from '../../../../shared/utilities/timeoutUtils'
72
74
import { FsReadParams } from '../../../tools/fsRead'
73
75
import { ListDirectoryParams } from '../../../tools/listDirectory'
76
+ import { fs } from '../../../../shared/fs/fs'
74
77
75
78
export type StaticTextResponseType = 'quick-action-help' | 'onboarding-help' | 'transform' | 'help'
76
79
@@ -193,12 +196,16 @@ export class Messenger {
193
196
return codeBlocks . length
194
197
}
195
198
196
- public handleFileReadOrListOperation = ( session : ChatSession , toolUse : ToolUse , tool : Tool ) => {
199
+ public handleFileReadOrListOperation = async ( session : ChatSession , toolUse : ToolUse , tool : Tool ) => {
197
200
const messageIdToUpdate =
198
201
tool . type === ToolType . FsRead ? session . messageIdToUpdate : session . messageIdToUpdateListDirectory
199
202
const messageId = messageIdToUpdate ?? toolUse ?. toolUseId ?? ''
200
203
const operationType = tool . type === ToolType . FsRead ? 'read' : 'listDir'
201
204
const input = toolUse . input as unknown as FsReadParams | ListDirectoryParams
205
+ const fileExists = await fs . exists ( input . path )
206
+ if ( ! fileExists ) {
207
+ return messageIdToUpdate
208
+ }
202
209
const existingPaths = session . getFilePathsByMessageId ( messageId )
203
210
204
211
// Check if path already exists in the list
@@ -359,7 +366,7 @@ export class Messenger {
359
366
changeList = await tool . tool . getDiffChanges ( )
360
367
}
361
368
if ( isReadOrList ) {
362
- messageIdToUpdate = this . handleFileReadOrListOperation ( session , toolUse , tool )
369
+ messageIdToUpdate = await this . handleFileReadOrListOperation ( session , toolUse , tool )
363
370
}
364
371
const validation = ToolUtils . requiresAcceptance ( tool )
365
372
const chatStream = new ChatStream (
@@ -471,7 +478,11 @@ export class Messenger {
471
478
if ( this . isTriggerCancelled ( triggerID ) ) {
472
479
return
473
480
}
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
+ }
475
486
this . dispatcher . sendChatMessage (
476
487
new ChatMessage (
477
488
{
@@ -486,6 +497,7 @@ export class Messenger {
486
497
userIntent : triggerPayload . userIntent ,
487
498
codeBlockLanguage : codeBlockLanguage ,
488
499
contextList : undefined ,
500
+ codeBlockActions,
489
501
} ,
490
502
tabID
491
503
)
@@ -768,8 +780,10 @@ export class Messenger {
768
780
const buttons : ChatItemButton [ ] = [ ]
769
781
let header : ChatItemHeader | undefined = undefined
770
782
let messageID : string = toolUse ?. toolUseId ?? ''
783
+ let messageType : ChatMessageType = 'answer-part'
771
784
if ( toolUse ?. name === ToolType . ExecuteBash && message . startsWith ( '```shell' ) ) {
772
785
if ( validation . requiresAcceptance ) {
786
+ messageType = 'answer'
773
787
const buttons : ChatItemButton [ ] = [
774
788
{
775
789
id : 'reject-shell-command' ,
@@ -796,6 +810,7 @@ export class Messenger {
796
810
if ( this . isTriggerCancelled ( triggerID ) ) {
797
811
return
798
812
}
813
+ messageType = 'answer'
799
814
const input = toolUse . input as unknown as FsWriteParams
800
815
const fileName = path . basename ( input . path )
801
816
const changes = getDiffLinesFromChanges ( changeList )
@@ -829,6 +844,7 @@ export class Messenger {
829
844
* requiredAcceptance = false, we use messageID = toolID and we keep on updating this messageID
830
845
* requiredAcceptance = true, IDE sends messageID != toolID, some default value, as this overlaps with previous message. */
831
846
messageID = 'toolUse'
847
+ messageType = 'answer'
832
848
const buttons : ChatItemButton [ ] = [
833
849
{
834
850
id : 'confirm-tool-use' ,
@@ -858,8 +874,8 @@ export class Messenger {
858
874
this . dispatcher . sendChatMessage (
859
875
new ChatMessage (
860
876
{
861
- message : message ,
862
- messageType : toolUse ?. name === ToolType . FsWrite ? 'answer' : 'answer-part' ,
877
+ message,
878
+ messageType,
863
879
followUps : undefined ,
864
880
followUpsHeader : undefined ,
865
881
relatedSuggestions : undefined ,
0 commit comments