@@ -638,6 +638,70 @@ export class ChatController {
638638 telemetry . ui_click . emit ( { elementId : 'amazonq_createSavedPrompt' } )
639639 }
640640
641+ private async processUnavailableToolUseMessage ( message : CustomFormActionMessage ) {
642+ const tabID = message . tabID
643+ if ( ! tabID ) {
644+ return
645+ }
646+ this . editorContextExtractor
647+ . extractContextForTrigger ( 'ChatMessage' )
648+ . then ( async ( context ) => {
649+ const triggerID = randomUUID ( )
650+ this . triggerEventsStorage . addTriggerEvent ( {
651+ id : triggerID ,
652+ tabID : message . tabID ,
653+ message : undefined ,
654+ type : 'chat_message' ,
655+ context,
656+ } )
657+ const session = this . sessionStorage . getSession ( tabID )
658+ const toolUse = session . toolUse
659+ if ( ! toolUse || ! toolUse . input ) {
660+ return
661+ }
662+ session . setToolUse ( undefined )
663+
664+ const toolResults : ToolResult [ ] = [ ]
665+
666+ toolResults . push ( {
667+ content : [ { text : 'This tool is not an available tool in this mode' } ] ,
668+ toolUseId : toolUse . toolUseId ,
669+ status : ToolResultStatus . ERROR ,
670+ } )
671+
672+ await this . generateResponse (
673+ {
674+ message : '' ,
675+ trigger : ChatTriggerType . ChatMessage ,
676+ query : undefined ,
677+ codeSelection : context ?. focusAreaContext ?. selectionInsideExtendedCodeBlock ,
678+ fileText : context ?. focusAreaContext ?. extendedCodeBlock ?? '' ,
679+ fileLanguage : context ?. activeFileContext ?. fileLanguage ,
680+ filePath : context ?. activeFileContext ?. filePath ,
681+ matchPolicy : context ?. activeFileContext ?. matchPolicy ,
682+ codeQuery : context ?. focusAreaContext ?. names ,
683+ userIntent : undefined ,
684+ customization : getSelectedCustomization ( ) ,
685+ toolResults : toolResults ,
686+ origin : Origin . IDE ,
687+ chatHistory : this . chatHistoryStorage . getTabHistory ( tabID ) . getHistory ( ) ,
688+ context : session . context ?? [ ] ,
689+ relevantTextDocuments : [ ] ,
690+ additionalContents : [ ] ,
691+ documentReferences : [ ] ,
692+ useRelevantDocuments : false ,
693+ contextLengths : {
694+ ...defaultContextLengths ,
695+ } ,
696+ } ,
697+ triggerID
698+ )
699+ } )
700+ . catch ( ( e ) => {
701+ this . processException ( e , tabID )
702+ } )
703+ }
704+
641705 private async processToolUseMessage ( message : CustomFormActionMessage ) {
642706 const tabID = message . tabID
643707 if ( ! tabID ) {
@@ -769,6 +833,9 @@ export class ChatController {
769833 case 'reject-code-diff' :
770834 await this . closeDiffView ( )
771835 break
836+ case 'tool-unavailable' :
837+ await this . processUnavailableToolUseMessage ( message )
838+ break
772839 default :
773840 getLogger ( ) . warn ( `Unhandled action: ${ message . action . id } ` )
774841 }
0 commit comments