@@ -41,8 +41,8 @@ import { extractAuthFollowUp } from '../../../../amazonq/util/authUtils'
41
41
import { helpMessage } from '../../../../amazonq/webview/ui/texts/constants'
42
42
import { ChatItemButton , ChatItemFormItem , MynahUIDataModel } from '@aws/mynah-ui'
43
43
import { ChatHistoryManager } from '../../../storages/chatHistory'
44
- import { ExecuteBashParams } from '../../../tools/executeBash '
45
- import { FsWriteParams } from '../../../tools/fsWrite '
44
+ import { ToolUtils } from '../../../tools/toolUtils '
45
+ import { ChatStream } from '../../../tools/chatStream '
46
46
47
47
export type StaticTextResponseType = 'quick-action-help' | 'onboarding-help' | 'transform' | 'help'
48
48
@@ -213,39 +213,19 @@ export class Messenger {
213
213
toolUse . name = cwChatEvent . toolUseEvent . name ?? ''
214
214
session . setToolUse ( toolUse )
215
215
216
- const message = this . getToolUseMessage ( toolUse )
217
- // const isConfirmationRequired = this.getIsConfirmationRequired(toolUse)
216
+ const tool = ToolUtils . tryFromToolUse ( toolUse )
217
+ if ( 'type' in tool ) {
218
+ const chatStream = new ChatStream ( this , tabID , triggerID , toolUse . toolUseId )
219
+ ToolUtils . queueDescription ( tool , chatStream )
218
220
219
- // TODO: If toolUse is fs_write then session.setShowDiffOnFileWrite(true)
220
-
221
- this . dispatcher . sendChatMessage (
222
- new ChatMessage (
223
- {
224
- message,
225
- messageType : 'answer' ,
226
- followUps : undefined ,
227
- followUpsHeader : undefined ,
228
- relatedSuggestions : undefined ,
229
- codeReference,
230
- triggerID,
231
- messageID : toolUse . toolUseId ,
232
- userIntent : triggerPayload . userIntent ,
233
- codeBlockLanguage : codeBlockLanguage ,
234
- contextList : undefined ,
235
- // TODO: confirmation buttons
236
- } ,
237
- tabID
221
+ this . dispatcher . sendCustomFormActionMessage (
222
+ new CustomFormActionMessage ( tabID , {
223
+ id : 'confirm-tool-use' ,
224
+ } )
238
225
)
239
- )
240
-
241
- this . dispatcher . sendCustomFormActionMessage (
242
- new CustomFormActionMessage ( tabID , {
243
- id : 'confirm-tool-use' ,
244
- } )
245
- )
246
- // TODO: setup permission action
247
- // if (!isConfirmationRequired) {
248
- // }
226
+ } else {
227
+ // TODO: Handle the error
228
+ }
249
229
}
250
230
251
231
if (
@@ -438,7 +418,7 @@ export class Messenger {
438
418
)
439
419
}
440
420
441
- public sendPartialBashToolLog ( message : string , tabID : string , triggerID : string , toolUseId : string | undefined ) {
421
+ public sendPartialToolLog ( message : string , tabID : string , triggerID : string , toolUseId : string | undefined ) {
442
422
this . dispatcher . sendChatMessage (
443
423
new ChatMessage (
444
424
{
@@ -450,7 +430,7 @@ export class Messenger {
450
430
triggerID,
451
431
messageID : toolUseId ?? `tool-output` ,
452
432
userIntent : undefined ,
453
- codeBlockLanguage : 'plaintext' ,
433
+ codeBlockLanguage : undefined ,
454
434
contextList : undefined ,
455
435
canBeVoted : false ,
456
436
} ,
@@ -617,67 +597,4 @@ export class Messenger {
617
597
new ShowCustomFormMessage ( tabID , formItems , buttons , title , description )
618
598
)
619
599
}
620
-
621
- // TODO: Make this cleaner
622
- // private getIsConfirmationRequired(toolUse: ToolUse) {
623
- // if (toolUse.name === 'execute_bash') {
624
- // const executeBash = new ExecuteBash(toolUse.input as unknown as ExecuteBashParams)
625
- // return executeBash.requiresAcceptance()
626
- // }
627
- // return toolUse.name === 'fs_write'
628
- // }
629
- private getToolUseMessage ( toolUse : ToolUse ) {
630
- if ( toolUse . name === 'fsRead' ) {
631
- return `Reading the file at \`${ ( toolUse . input as any ) ?. path } \` using the \`fsRead\` tool.`
632
- }
633
- if ( toolUse . name === 'executeBash' ) {
634
- const input = toolUse . input as unknown as ExecuteBashParams
635
- return `Executing the bash command
636
- \`\`\`bash
637
- ${ input . command }
638
- \`\`\`
639
- using the \`executeBash\` tool.`
640
- }
641
- if ( toolUse . name === 'fsWrite' ) {
642
- const input = toolUse . input as unknown as FsWriteParams
643
- switch ( input . command ) {
644
- case 'create' : {
645
- return `Writing
646
- \`\`\`
647
- ${ input . fileText }
648
- \`\`\`
649
- into the file at \`${ input . path } \` using the \`fsWrite\` tool.`
650
- }
651
- case 'strReplace' : {
652
- return `Replacing
653
- \`\`\`
654
- ${ input . oldStr }
655
- \`\`\`
656
- with
657
- \`\`\`
658
- ${ input . newStr }
659
- \`\`\`
660
- at \`${ input . path } \` using the \`fsWrite\` tool.`
661
- }
662
- case 'insert' : {
663
- return `Inserting
664
- \`\`\`
665
- ${ input . newStr }
666
- \`\`\`
667
- at line
668
- \`\`\`
669
- ${ input . insertLine }
670
- \`\`\`
671
- at \`${ input . path } \` using the \`fsWrite\` tool.`
672
- }
673
- case 'append' : {
674
- return `Appending
675
- \`\`\`
676
- ${ input . newStr }
677
- \`\`\`
678
- at \`${ input . path } \` using the \`fsWrite\` tool.`
679
- }
680
- }
681
- }
682
- }
683
600
}
0 commit comments