@@ -118,7 +118,9 @@ impl ToolCallFull {
118118 current_call_id = Some ( new_call_id. clone ( ) ) ;
119119 }
120120
121- if let Some ( name) = & part. name {
121+ if let Some ( name) = & part. name
122+ && !name. as_str ( ) . is_empty ( )
123+ {
122124 current_tool_name = Some ( name. clone ( ) ) ;
123125 }
124126
@@ -289,4 +291,36 @@ mod tests {
289291 let actual = tool_call. first ( ) . unwrap ( ) . call_id . as_ref ( ) . unwrap ( ) ;
290292 assert ! ( actual. as_str( ) . starts_with( "forge_call_id_" ) ) ;
291293 }
294+ #[ test]
295+ fn test_try_from_parts_handles_empty_tool_names ( ) {
296+ // Fixture: Tool call parts where empty names in subsequent parts should not
297+ // override valid names
298+ let input = [
299+ ToolCallPart {
300+ call_id : Some ( ToolCallId ( "0" . to_string ( ) ) ) ,
301+ name : Some ( ToolName :: new ( "forge_tool_fs_read" ) ) ,
302+ arguments_part : "" . to_string ( ) ,
303+ } ,
304+ ToolCallPart {
305+ call_id : Some ( ToolCallId ( "0" . to_string ( ) ) ) ,
306+ name : Some ( ToolName :: new ( "" ) ) , // Empty name should not override valid name
307+ arguments_part : "{\" path\" " . to_string ( ) ,
308+ } ,
309+ ToolCallPart {
310+ call_id : Some ( ToolCallId ( "0" . to_string ( ) ) ) ,
311+ name : Some ( ToolName :: new ( "" ) ) , // Empty name should not override valid name
312+ arguments_part : ": \" /test/file.md\" }" . to_string ( ) ,
313+ } ,
314+ ] ;
315+
316+ let actual = ToolCallFull :: try_from_parts ( & input) . unwrap ( ) ;
317+
318+ let expected = vec ! [ ToolCallFull {
319+ name: ToolName :: new( "forge_tool_fs_read" ) ,
320+ call_id: Some ( ToolCallId ( "0" . to_string( ) ) ) ,
321+ arguments: serde_json:: json!( { "path" : "/test/file.md" } ) ,
322+ } ] ;
323+
324+ assert_eq ! ( actual, expected) ;
325+ }
292326}
0 commit comments