@@ -519,31 +519,40 @@ Hi, I'm <g>Amazon Q</g>. Ask me anything.
519519 tool. queue_description ( & self . ctx , self . output ) ?;
520520 queue ! ( self . output, style:: Print ( "\n " ) ) ?;
521521 }
522-
523- execute ! (
524- self . output,
525- style:: SetForegroundColor ( Color :: DarkGrey ) ,
526- style:: Print ( "▁" . repeat( terminal_width) ) ,
527- style:: ResetColor ,
528- style:: Print ( "\n \n Enter " ) ,
529- style:: SetForegroundColor ( Color :: Green ) ,
530- style:: Print ( "y" ) ,
531- style:: ResetColor ,
532- style:: Print ( format!(
533- " to run {}, or otherwise continue your conversation.\n \n " ,
534- match queued_tools. len( ) == 1 {
535- true => "this tool" ,
536- false => "these tools" ,
537- }
538- ) ) ,
539- ) ?;
540522 }
541523
542524 let user_input = match self . initial_input . take ( ) {
543525 Some ( input) => input,
544- None => match self . input_source . read_line ( Some ( "> " ) ) ? {
545- Some ( line) => line,
546- None => return Ok ( None ) ,
526+ None => match ( self . ctx . env ( ) . get ( "Q_CHAT_SKIP_TOOL_CONSENT" ) , !queued_tools. is_empty ( ) ) {
527+ // Skip prompting the user if they auto consent to the tool use.
528+ ( Ok ( _) , true ) => "y" . to_string ( ) ,
529+ // Otherwise, read input.
530+ _ => {
531+ if !queued_tools. is_empty ( ) {
532+ let terminal_width = self . terminal_width ( ) ;
533+ execute ! (
534+ self . output,
535+ style:: SetForegroundColor ( Color :: DarkGrey ) ,
536+ style:: Print ( "▁" . repeat( terminal_width) ) ,
537+ style:: ResetColor ,
538+ style:: Print ( "\n \n Enter " ) ,
539+ style:: SetForegroundColor ( Color :: Green ) ,
540+ style:: Print ( "y" ) ,
541+ style:: ResetColor ,
542+ style:: Print ( format!(
543+ " to run {}, or otherwise continue your conversation.\n \n " ,
544+ match queued_tools. len( ) == 1 {
545+ true => "this tool" ,
546+ false => "these tools" ,
547+ }
548+ ) ) ,
549+ ) ?;
550+ }
551+ match self . input_source . read_line ( Some ( "> " ) ) ? {
552+ Some ( line) => line,
553+ None => return Ok ( None ) ,
554+ }
555+ } ,
547556 } ,
548557 } ;
549558
@@ -574,13 +583,14 @@ Hi, I'm <g>Amazon Q</g>. Ask me anything.
574583 style:: SetForegroundColor ( Color :: Reset ) ,
575584 ) ?;
576585 let invoke_result = tool. 1 . invoke ( & self . ctx , self . output ) . await ;
586+ execute ! ( self . output, style:: Print ( "\n " ) ) ?;
577587 let tool_time = std:: time:: Instant :: now ( ) . duration_since ( tool_start) ;
578588 let tool_time = format ! ( "{}.{}" , tool_time. as_secs( ) , tool_time. subsec_millis( ) ) ;
579589
580590 match invoke_result {
581591 Ok ( result) => {
582592 debug ! ( "tool result output: {:#?}" , result) ;
583- queue ! (
593+ execute ! (
584594 self . output,
585595 style:: SetForegroundColor ( Color :: Green ) ,
586596 style:: Print ( format!( "🟢 Completed in {}s" , tool_time) ) ,
@@ -599,27 +609,27 @@ Hi, I'm <g>Amazon Q</g>. Ask me anything.
599609 } ,
600610 Err ( err) => {
601611 error ! ( ?err, "An error occurred processing the tool" ) ;
602- tool_results. push ( ToolResult {
603- tool_use_id : tool. 0 ,
604- content : vec ! [ ToolResultContentBlock :: Text ( format!(
605- "An error occurred processing the tool: \n {}" ,
606- err
607- ) ) ] ,
608- status : ToolResultStatus :: Error ,
609- } ) ;
610-
611612 execute ! (
612613 self . output,
613614 style:: SetAttribute ( Attribute :: Bold ) ,
614615 style:: SetForegroundColor ( Color :: Red ) ,
615616 style:: Print ( format!( "🔴 Execution failed after {}s:\n " , tool_time) ) ,
616617 style:: SetAttribute ( Attribute :: Reset ) ,
617618 style:: SetForegroundColor ( Color :: Red ) ,
618- style:: Print ( err) ,
619+ style:: Print ( & err) ,
619620 style:: SetAttribute ( Attribute :: Reset ) ,
620621 style:: Print ( "\n \n " ) ,
621622 ) ?;
622623
624+ tool_results. push ( ToolResult {
625+ tool_use_id : tool. 0 ,
626+ content : vec ! [ ToolResultContentBlock :: Text ( format!(
627+ "An error occurred processing the tool: \n {}" ,
628+ & err
629+ ) ) ] ,
630+ status : ToolResultStatus :: Error ,
631+ } ) ;
632+
623633 if let Some ( builder) = corresponding_builder {
624634 builder. is_success = Some ( false ) ;
625635 }
0 commit comments