@@ -290,13 +290,12 @@ async fn process_chat_sse<S>(
290
290
. get ( "delta" )
291
291
. and_then ( |d| d. get ( "content" ) )
292
292
. and_then ( |c| c. as_str ( ) )
293
+ && !content. is_empty ( )
293
294
{
294
- if !content. is_empty ( ) {
295
- assistant_text. push_str ( content) ;
296
- let _ = tx_event
297
- . send ( Ok ( ResponseEvent :: OutputTextDelta ( content. to_string ( ) ) ) )
298
- . await ;
299
- }
295
+ assistant_text. push_str ( content) ;
296
+ let _ = tx_event
297
+ . send ( Ok ( ResponseEvent :: OutputTextDelta ( content. to_string ( ) ) ) )
298
+ . await ;
300
299
}
301
300
302
301
// Forward any reasoning/thinking deltas if present.
@@ -333,27 +332,25 @@ async fn process_chat_sse<S>(
333
332
. get ( "delta" )
334
333
. and_then ( |d| d. get ( "tool_calls" ) )
335
334
. and_then ( |tc| tc. as_array ( ) )
335
+ && let Some ( tool_call) = tool_calls. first ( )
336
336
{
337
- if let Some ( tool_call) = tool_calls. first ( ) {
338
- // Mark that we have an active function call in progress.
339
- fn_call_state. active = true ;
337
+ // Mark that we have an active function call in progress.
338
+ fn_call_state. active = true ;
340
339
341
- // Extract call_id if present.
342
- if let Some ( id) = tool_call. get ( "id" ) . and_then ( |v| v. as_str ( ) ) {
343
- fn_call_state. call_id . get_or_insert_with ( || id. to_string ( ) ) ;
344
- }
340
+ // Extract call_id if present.
341
+ if let Some ( id) = tool_call. get ( "id" ) . and_then ( |v| v. as_str ( ) ) {
342
+ fn_call_state. call_id . get_or_insert_with ( || id. to_string ( ) ) ;
343
+ }
345
344
346
- // Extract function details if present.
347
- if let Some ( function) = tool_call. get ( "function" ) {
348
- if let Some ( name) = function. get ( "name" ) . and_then ( |n| n. as_str ( ) ) {
349
- fn_call_state. name . get_or_insert_with ( || name. to_string ( ) ) ;
350
- }
345
+ // Extract function details if present.
346
+ if let Some ( function) = tool_call. get ( "function" ) {
347
+ if let Some ( name) = function. get ( "name" ) . and_then ( |n| n. as_str ( ) ) {
348
+ fn_call_state. name . get_or_insert_with ( || name. to_string ( ) ) ;
349
+ }
351
350
352
- if let Some ( args_fragment) =
353
- function. get ( "arguments" ) . and_then ( |a| a. as_str ( ) )
354
- {
355
- fn_call_state. arguments . push_str ( args_fragment) ;
356
- }
351
+ if let Some ( args_fragment) = function. get ( "arguments" ) . and_then ( |a| a. as_str ( ) )
352
+ {
353
+ fn_call_state. arguments . push_str ( args_fragment) ;
357
354
}
358
355
}
359
356
}
@@ -491,15 +488,14 @@ where
491
488
// Only use the final assistant message if we have not
492
489
// seen any deltas; otherwise, deltas already built the
493
490
// cumulative text and this would duplicate it.
494
- if this. cumulative . is_empty ( ) {
495
- if let crate :: models:: ResponseItem :: Message { content, .. } = & item {
496
- if let Some ( text) = content. iter ( ) . find_map ( |c| match c {
497
- crate :: models:: ContentItem :: OutputText { text } => Some ( text) ,
498
- _ => None ,
499
- } ) {
500
- this. cumulative . push_str ( text) ;
501
- }
502
- }
491
+ if this. cumulative . is_empty ( )
492
+ && let crate :: models:: ResponseItem :: Message { content, .. } = & item
493
+ && let Some ( text) = content. iter ( ) . find_map ( |c| match c {
494
+ crate :: models:: ContentItem :: OutputText { text } => Some ( text) ,
495
+ _ => None ,
496
+ } )
497
+ {
498
+ this. cumulative . push_str ( text) ;
503
499
}
504
500
505
501
// Swallow assistant message here; emit on Completed.
0 commit comments