1+ use std:: collections:: HashSet ;
12use std:: sync:: Arc ;
23use std:: time:: Duration ;
34
@@ -610,6 +611,7 @@ pub async fn query(
610611 let mut assistant_text = String :: new ( ) ;
611612 let mut reasoning_text = String :: new ( ) ;
612613 let mut tool_uses: Vec < ( String , String , serde_json:: Value , String , bool ) > = Vec :: new ( ) ;
614+ let mut emitted_tool_use_starts: HashSet < String > = HashSet :: new ( ) ;
613615 let mut final_response = None ;
614616 let mut stop_reason = None ;
615617
@@ -631,6 +633,13 @@ pub async fn query(
631633 Ok ( StreamEvent :: ToolCallStart {
632634 id, name, input, ..
633635 } ) => {
636+ if emitted_tool_use_starts. insert ( id. clone ( ) ) {
637+ emit ( QueryEvent :: ToolUseStart {
638+ id : id. clone ( ) ,
639+ name : name. clone ( ) ,
640+ input : input. clone ( ) ,
641+ } ) ;
642+ }
634643 tool_uses. push ( ( id, name, input, String :: new ( ) , false ) ) ;
635644 }
636645 Ok ( StreamEvent :: ToolCallInputDelta { partial_json, .. } ) => {
@@ -784,11 +793,13 @@ pub async fn query(
784793 } else {
785794 initial_input
786795 } ;
787- emit ( QueryEvent :: ToolUseStart {
788- id : id. clone ( ) ,
789- name : name. clone ( ) ,
790- input : input. clone ( ) ,
791- } ) ;
796+ if emitted_tool_use_starts. insert ( id. clone ( ) ) {
797+ emit ( QueryEvent :: ToolUseStart {
798+ id : id. clone ( ) ,
799+ name : name. clone ( ) ,
800+ input : input. clone ( ) ,
801+ } ) ;
802+ }
792803 assistant_content. push ( ContentBlock :: ToolUse {
793804 id : id. clone ( ) ,
794805 name : name. clone ( ) ,
@@ -977,6 +988,7 @@ mod tests {
977988 use devo_protocol:: Usage ;
978989 use devo_provider:: ModelProviderSDK ;
979990 use devo_safety:: PermissionMode ;
991+ use devo_tools:: ToolPreparationFeedback ;
980992 use devo_tools:: ToolRegistry ;
981993 use devo_tools:: ToolRuntime ;
982994 use devo_tools:: errors:: ToolExecutionError ;
@@ -1462,6 +1474,7 @@ mod tests {
14621474 execution_mode : ToolExecutionMode :: Mutating ,
14631475 capability_tags : vec ! [ ] ,
14641476 supports_parallel : false ,
1477+ preparation_feedback : ToolPreparationFeedback :: None ,
14651478 } ) ;
14661479 let registry = Arc :: new ( builder. build ( ) ) ;
14671480 let deny_checker = PermissionChecker :: new ( |request| {
@@ -1957,6 +1970,7 @@ mod tests {
19571970 execution_mode : ToolExecutionMode :: Mutating ,
19581971 capability_tags : vec ! [ ] ,
19591972 supports_parallel : false ,
1973+ preparation_feedback : ToolPreparationFeedback :: None ,
19601974 } ) ;
19611975 let registry = Arc :: new ( builder. build ( ) ) ;
19621976 let runtime = ToolRuntime :: new_without_permissions ( Arc :: clone ( & registry) ) ;
@@ -2010,6 +2024,7 @@ mod tests {
20102024 execution_mode : ToolExecutionMode :: ReadOnly ,
20112025 capability_tags : vec ! [ ] ,
20122026 supports_parallel : false ,
2027+ preparation_feedback : ToolPreparationFeedback :: None ,
20132028 } ) ;
20142029 let registry = Arc :: new ( builder. build ( ) ) ;
20152030 let runtime = ToolRuntime :: new_without_permissions ( Arc :: clone ( & registry) ) ;
@@ -2067,6 +2082,7 @@ mod tests {
20672082 execution_mode : ToolExecutionMode :: Mutating ,
20682083 capability_tags : vec ! [ ] ,
20692084 supports_parallel : false ,
2085+ preparation_feedback : ToolPreparationFeedback :: None ,
20702086 } ) ;
20712087 let registry = Arc :: new ( builder. build ( ) ) ;
20722088 let runtime = ToolRuntime :: new_without_permissions ( Arc :: clone ( & registry) ) ;
@@ -2144,6 +2160,7 @@ mod tests {
21442160 execution_mode : ToolExecutionMode :: ReadOnly ,
21452161 capability_tags : vec ! [ ] ,
21462162 supports_parallel : true ,
2163+ preparation_feedback : ToolPreparationFeedback :: None ,
21472164 } ) ;
21482165 let registry = Arc :: new ( builder. build ( ) ) ;
21492166 let runtime = ToolRuntime :: new_without_permissions ( Arc :: clone ( & registry) ) ;
0 commit comments