@@ -146,7 +146,7 @@ impl OpenAIClient {
146146 "parameters" : input_schema
147147 }
148148 } ) ) ,
149- _ => None , // Web search isn't supported via OpenAI tools
149+ _ => None , // TODO: Add OpenAI web search
150150 } )
151151 . collect ( ) ;
152152
@@ -243,7 +243,7 @@ impl OpenAIClient {
243243 if !tools. is_empty ( ) {
244244 body[ "tools" ] = json ! ( tools) ;
245245 body[ "tool_choice" ] = json ! ( "auto" ) ;
246-
246+
247247 if std:: env:: var ( "SOFOS_DEBUG" ) . is_ok ( ) {
248248 eprintln ! ( "\n === OpenAI /responses Request ===" ) ;
249249 eprintln ! ( "Sending {} tools to OpenAI" , tools. len( ) ) ;
@@ -260,23 +260,27 @@ impl OpenAIClient {
260260 }
261261
262262 let url = format ! ( "{}/responses" , OPENAI_API_BASE ) ;
263-
263+
264264 if std:: env:: var ( "SOFOS_DEBUG" ) . is_ok ( ) {
265265 eprintln ! ( "\n === OpenAI /responses Request Body ===" ) ;
266- eprintln ! ( "{}" , serde_json:: to_string_pretty( & body) . unwrap_or_else( |_| "Failed to serialize" . to_string( ) ) ) ;
266+ eprintln ! (
267+ "{}" ,
268+ serde_json:: to_string_pretty( & body)
269+ . unwrap_or_else( |_| "Failed to serialize" . to_string( ) )
270+ ) ;
267271 eprintln ! ( "======================================\n " ) ;
268272 }
269-
273+
270274 let response = self . client . post ( & url) . json ( & body) . send ( ) . await ?;
271275 let response = super :: utils:: check_response_status ( response) . await ?;
272-
276+
273277 let response_text = response. text ( ) . await ?;
274278 if std:: env:: var ( "SOFOS_DEBUG" ) . is_ok ( ) {
275279 eprintln ! ( "\n === OpenAI Raw Response ===" ) ;
276280 eprintln ! ( "{}" , response_text) ;
277281 eprintln ! ( "===========================\n " ) ;
278282 }
279-
283+
280284 let parsed: OpenAIResponse = serde_json:: from_str ( & response_text)
281285 . map_err ( |e| SofosError :: Api ( format ! ( "Failed to parse OpenAI response: {}" , e) ) ) ?;
282286
@@ -285,24 +289,27 @@ impl OpenAIClient {
285289 eprintln ! ( "Model: {}" , parsed. model) ;
286290 eprintln ! ( "Output items count: {}" , parsed. output. len( ) ) ;
287291 for ( i, item) in parsed. output . iter ( ) . enumerate ( ) {
288- eprintln ! ( " Item {}: type={}, content_count={}, tool_calls={:?}" ,
289- i,
290- item. item_type,
292+ eprintln ! (
293+ " Item {}: type={}, content_count={}, tool_calls={:?}" ,
294+ i,
295+ item. item_type,
291296 item. content. len( ) ,
292297 item. tool_calls. as_ref( ) . map( |tc| tc. len( ) )
293298 ) ;
294299 for ( j, content) in item. content . iter ( ) . enumerate ( ) {
295- eprintln ! ( " Content {}: type={}, text_len={}" ,
296- j,
297- content. content_type,
300+ eprintln ! (
301+ " Content {}: type={}, text_len={}" ,
302+ j,
303+ content. content_type,
298304 content. text. len( )
299305 ) ;
300306 }
301307 if let Some ( ref tool_calls) = item. tool_calls {
302308 for ( j, call) in tool_calls. iter ( ) . enumerate ( ) {
303- eprintln ! ( " Tool call {}: name={}, args_len={}" ,
304- j,
305- call. name,
309+ eprintln ! (
310+ " Tool call {}: name={}, args_len={}" ,
311+ j,
312+ call. name,
306313 call. arguments. len( )
307314 ) ;
308315 }
@@ -316,7 +323,8 @@ impl OpenAIClient {
316323 match item. item_type . as_str ( ) {
317324 "message" => {
318325 for content in item. content {
319- if content. content_type == "output_text" && !content. text . trim ( ) . is_empty ( ) {
326+ if content. content_type == "output_text" && !content. text . trim ( ) . is_empty ( )
327+ {
320328 content_blocks. push ( ContentBlock :: Text { text : content. text } ) ;
321329 }
322330 }
@@ -334,8 +342,9 @@ impl OpenAIClient {
334342 }
335343 }
336344 "function_call" => {
337- if let ( Some ( name) , Some ( arguments) , Some ( call_id) ) =
338- ( item. name , item. arguments , item. call_id ) {
345+ if let ( Some ( name) , Some ( arguments) , Some ( call_id) ) =
346+ ( item. name , item. arguments , item. call_id )
347+ {
339348 let input = serde_json:: from_str :: < serde_json:: Value > ( & arguments)
340349 . unwrap_or_else ( |_| json ! ( { "raw_arguments" : arguments} ) ) ;
341350 content_blocks. push ( ContentBlock :: ToolUse {
@@ -359,7 +368,10 @@ impl OpenAIClient {
359368 }
360369
361370 if std:: env:: var ( "SOFOS_DEBUG" ) . is_ok ( ) {
362- eprintln ! ( "=== Converted to {} content blocks ===\n " , content_blocks. len( ) ) ;
371+ eprintln ! (
372+ "=== Converted to {} content blocks ===\n " ,
373+ content_blocks. len( )
374+ ) ;
363375 }
364376
365377 let usage = parsed. usage . unwrap_or_default ( ) ;
@@ -400,7 +412,11 @@ fn build_response_input(request: &CreateMessageRequest) -> Vec<serde_json::Value
400412 MessageContentBlock :: Text { text } => {
401413 input. push ( json ! ( { "role" : msg. role, "content" : text} ) ) ;
402414 }
403- MessageContentBlock :: ToolUse { id, name, input : tool_input } => {
415+ MessageContentBlock :: ToolUse {
416+ id,
417+ name,
418+ input : tool_input,
419+ } => {
404420 // Responses API requires function_call items to match with function_call_output
405421 input. push ( json ! ( {
406422 "type" : "function_call" ,
0 commit comments