@@ -675,69 +675,6 @@ export class ChatController {
675675 telemetry . ui_click . emit ( { elementId : 'amazonq_createSavedPrompt' } )
676676 }
677677
678- private async processUnavailableToolUseMessage ( message : CustomFormActionMessage ) {
679- const tabID = message . tabID
680- if ( ! tabID ) {
681- return
682- }
683- this . editorContextExtractor
684- . extractContextForTrigger ( 'ChatMessage' )
685- . then ( async ( context ) => {
686- const triggerID = randomUUID ( )
687- this . triggerEventsStorage . addTriggerEvent ( {
688- id : triggerID ,
689- tabID : message . tabID ,
690- message : undefined ,
691- type : 'chat_message' ,
692- context,
693- } )
694- const session = this . sessionStorage . getSession ( tabID )
695- const toolUse = session . toolUse
696- if ( ! toolUse || ! toolUse . input ) {
697- return
698- }
699- session . setToolUse ( undefined )
700-
701- const toolResults : ToolResult [ ] = [ ]
702-
703- toolResults . push ( {
704- content : [ { text : 'This tool is not an available tool in this mode' } ] ,
705- toolUseId : toolUse . toolUseId ,
706- status : ToolResultStatus . ERROR ,
707- } )
708-
709- await this . generateResponse (
710- {
711- message : '' ,
712- trigger : ChatTriggerType . ChatMessage ,
713- query : undefined ,
714- codeSelection : context ?. focusAreaContext ?. selectionInsideExtendedCodeBlock ,
715- fileText : context ?. focusAreaContext ?. extendedCodeBlock ?? '' ,
716- fileLanguage : context ?. activeFileContext ?. fileLanguage ,
717- filePath : context ?. activeFileContext ?. filePath ,
718- matchPolicy : context ?. activeFileContext ?. matchPolicy ,
719- codeQuery : context ?. focusAreaContext ?. names ,
720- userIntent : undefined ,
721- customization : getSelectedCustomization ( ) ,
722- toolResults : toolResults ,
723- origin : Origin . IDE ,
724- context : session . context ?? [ ] ,
725- relevantTextDocuments : [ ] ,
726- additionalContents : [ ] ,
727- documentReferences : [ ] ,
728- useRelevantDocuments : false ,
729- contextLengths : {
730- ...defaultContextLengths ,
731- } ,
732- } ,
733- triggerID
734- )
735- } )
736- . catch ( ( e ) => {
737- this . processException ( e , tabID )
738- } )
739- }
740-
741678 private async processToolUseMessage ( message : CustomFormActionMessage ) {
742679 const tabID = message . tabID
743680 if ( ! tabID ) {
@@ -756,59 +693,69 @@ export class ChatController {
756693 } )
757694 this . messenger . sendAsyncEventProgress ( tabID , true , '' )
758695 const session = this . sessionStorage . getSession ( tabID )
759- const toolUse = session . toolUse
760- if ( ! toolUse || ! toolUse . input ) {
696+ const toolUseWithError = session . toolUseWithError
697+ if ( ! toolUseWithError || ! toolUseWithError . toolUse || ! toolUseWithError . toolUse . input ) {
761698 // Turn off AgentLoop flag if there's no tool use
762699 this . sessionStorage . setAgentLoopInProgress ( tabID , false )
763700 return
764701 }
765- session . setToolUse ( undefined )
702+ session . setToolUseWithError ( undefined )
766703
704+ const toolUse = toolUseWithError . toolUse
705+ const toolUseError = toolUseWithError . error
767706 const toolResults : ToolResult [ ] = [ ]
768707
769- const result = ToolUtils . tryFromToolUse ( toolUse )
770- if ( 'type' in result ) {
771- const tool : Tool = result
772-
773- try {
774- await ToolUtils . validate ( tool )
775-
776- const chatStream = new ChatStream ( this . messenger , tabID , triggerID , toolUse , {
777- requiresAcceptance : false ,
778- } )
779- const output = await ToolUtils . invoke ( tool , chatStream )
780- if ( output . output . content . length > maxToolOutputCharacterLength ) {
781- throw Error (
782- `Tool output exceeds maximum character limit of ${ maxToolOutputCharacterLength } `
783- )
708+ if ( toolUseError ) {
709+ toolResults . push ( {
710+ content : [ { text : toolUseError . message } ] ,
711+ toolUseId : toolUse . toolUseId ,
712+ status : ToolResultStatus . ERROR ,
713+ } )
714+ } else {
715+ const result = ToolUtils . tryFromToolUse ( toolUse )
716+ if ( 'type' in result ) {
717+ const tool : Tool = result
718+
719+ try {
720+ await ToolUtils . validate ( tool )
721+
722+ const chatStream = new ChatStream ( this . messenger , tabID , triggerID , toolUse , {
723+ requiresAcceptance : false ,
724+ } )
725+ const output = await ToolUtils . invoke ( tool , chatStream )
726+ if ( output . output . content . length > maxToolOutputCharacterLength ) {
727+ throw Error (
728+ `Tool output exceeds maximum character limit of ${ maxToolOutputCharacterLength } `
729+ )
730+ }
731+
732+ toolResults . push ( {
733+ content : [
734+ output . output . kind === OutputKind . Text
735+ ? { text : output . output . content }
736+ : { json : output . output . content } ,
737+ ] ,
738+ toolUseId : toolUse . toolUseId ,
739+ status : ToolResultStatus . SUCCESS ,
740+ } )
741+ } catch ( e : any ) {
742+ toolResults . push ( {
743+ content : [ { text : e . message } ] ,
744+ toolUseId : toolUse . toolUseId ,
745+ status : ToolResultStatus . ERROR ,
746+ } )
784747 }
785-
786- toolResults . push ( {
787- content : [
788- output . output . kind === OutputKind . Text
789- ? { text : output . output . content }
790- : { json : output . output . content } ,
791- ] ,
792- toolUseId : toolUse . toolUseId ,
793- status : ToolResultStatus . SUCCESS ,
794- } )
795- } catch ( e : any ) {
796- toolResults . push ( {
797- content : [ { text : e . message } ] ,
798- toolUseId : toolUse . toolUseId ,
799- status : ToolResultStatus . ERROR ,
800- } )
748+ } else {
749+ const toolResult : ToolResult = result
750+ toolResults . push ( toolResult )
801751 }
802- } else {
803- const toolResult : ToolResult = result
804- toolResults . push ( toolResult )
805- }
806752
807- if ( toolUse . name === ToolType . FsWrite ) {
808- await vscode . commands . executeCommand (
809- 'vscode.open' ,
810- vscode . Uri . file ( ( toolUse . input as unknown as FsWriteParams ) . path )
811- )
753+ if ( toolUse . name === ToolType . FsWrite ) {
754+ await vscode . commands . executeCommand (
755+ 'vscode.open' ,
756+ vscode . Uri . file ( ( toolUse . input as unknown as FsWriteParams ) . path )
757+ )
758+ }
812759 }
813760
814761 await this . generateResponse (
@@ -879,9 +826,6 @@ export class ChatController {
879826 case 'reject-shell-command' :
880827 await this . rejectShellCommand ( message )
881828 break
882- case 'tool-unavailable' :
883- await this . processUnavailableToolUseMessage ( message )
884- break
885829 default :
886830 getLogger ( ) . warn ( `Unhandled action: ${ message . action . id } ` )
887831 }
@@ -920,19 +864,19 @@ export class ChatController {
920864 await fs . mkdir ( resultArtifactsDir )
921865 const tempFilePath = path . join (
922866 resultArtifactsDir ,
923- `temp-${ path . basename ( ( session . toolUse ? .input as unknown as FsWriteParams ) . path ) } `
867+ `temp-${ path . basename ( ( session . toolUseWithError ?. toolUse . input as unknown as FsWriteParams ) . path ) } `
924868 )
925869
926870 // If we have existing filePath copy file content from existing file to temporary file.
927- const filePath = ( session . toolUse ? .input as any ) . path ?? message . filePath
871+ const filePath = ( session . toolUseWithError ?. toolUse . input as any ) . path ?? message . filePath
928872 const fileExists = await fs . existsFile ( filePath )
929873 if ( fileExists ) {
930874 const fileContent = await fs . readFileText ( filePath )
931875 await fs . writeFile ( tempFilePath , fileContent )
932876 }
933877
934878 // Create a deep clone of the toolUse object and pass this toolUse to FsWrite tool execution to get the modified temporary file.
935- const clonedToolUse = structuredClone ( session . toolUse )
879+ const clonedToolUse = structuredClone ( session . toolUseWithError ?. toolUse )
936880 if ( ! clonedToolUse ) {
937881 return
938882 }
0 commit comments