| 3396 | } |
| 3397 | |
| 3398 | fn map_api_message_part(part: &crate::api::MessagePart) -> Option<ContextMessagePart> { |
| 3399 | if let Some(text) = &part.text { |
| 3400 | if part.ignored == Some(true) { |
| 3401 | return None; |
| 3402 | } |
| 3403 | if part.part_type == "reasoning" { |
| 3404 | return Some(ContextMessagePart::Reasoning { text: text.clone() }); |
| 3405 | } |
| 3406 | // Skip synthetic text parts (auto-continue prompts, etc.) |
| 3407 | if part.synthetic == Some(true) { |
| 3408 | return None; |
| 3409 | } |
| 3410 | return Some(ContextMessagePart::Text { text: text.clone() }); |
| 3411 | } |
| 3412 | |
| 3413 | if let Some(file) = &part.file { |
| 3414 | return Some(ContextMessagePart::File { |
| 3415 | path: file.filename.clone(), |
| 3416 | mime: file.mime.clone(), |
| 3417 | }); |
| 3418 | } |
| 3419 | |
| 3420 | if let Some(tool_call) = &part.tool_call { |
| 3421 | let arguments = if let Some(value) = tool_call.input.as_str() { |
| 3422 | value.to_string() |
| 3423 | } else { |
| 3424 | tool_call.input.to_string() |
| 3425 | }; |
| 3426 | return Some(ContextMessagePart::ToolCall { |
| 3427 | id: tool_call.id.clone(), |
| 3428 | name: tool_call.name.clone(), |
| 3429 | arguments, |
| 3430 | }); |
| 3431 | } |
| 3432 | |
| 3433 | if let Some(tool_result) = &part.tool_result { |
| 3434 | return Some(ContextMessagePart::ToolResult { |
| 3435 | id: tool_result.tool_call_id.clone(), |
| 3436 | result: tool_result.content.clone(), |
| 3437 | is_error: tool_result.is_error, |
| 3438 | }); |
| 3439 | } |
| 3440 | |
| 3441 | None |
| 3442 | } |
| 3443 | |
| 3444 | fn message_part_text(part: &ContextMessagePart) -> String { |
| 3445 | match part { |