| 1562 | } |
| 1563 | |
| 1564 | fn part_to_content_part(part: &Part) -> Option<opencode_provider::ContentPart> { |
| 1565 | match part { |
| 1566 | Part::Text { text, .. } => Some(opencode_provider::ContentPart { |
| 1567 | content_type: "text".to_string(), |
| 1568 | text: Some(text.clone()), |
| 1569 | image_url: None, |
| 1570 | tool_use: None, |
| 1571 | tool_result: None, |
| 1572 | cache_control: None, |
| 1573 | filename: None, |
| 1574 | media_type: None, |
| 1575 | provider_options: None, |
| 1576 | }), |
| 1577 | Part::File(file_part) => Some(opencode_provider::ContentPart { |
| 1578 | content_type: "file".to_string(), |
| 1579 | text: None, |
| 1580 | image_url: Some(ImageUrl { |
| 1581 | url: file_part.url.clone(), |
| 1582 | }), |
| 1583 | tool_use: None, |
| 1584 | tool_result: None, |
| 1585 | cache_control: None, |
| 1586 | filename: file_part.filename.clone(), |
| 1587 | media_type: Some(file_part.mime.clone()), |
| 1588 | provider_options: None, |
| 1589 | }), |
| 1590 | Part::Tool(tool_part) => { |
| 1591 | if let crate::ToolState::Completed { output, .. } = &tool_part.state { |
| 1592 | Some(opencode_provider::ContentPart { |
| 1593 | content_type: "tool_result".to_string(), |
| 1594 | text: Some(output.clone()), |
| 1595 | image_url: None, |
| 1596 | tool_use: None, |
| 1597 | tool_result: Some(opencode_provider::ToolResult { |
| 1598 | tool_use_id: tool_part.call_id.clone(), |
| 1599 | content: output.clone(), |
| 1600 | is_error: Some(false), |
| 1601 | }), |
| 1602 | cache_control: None, |
| 1603 | filename: None, |
| 1604 | media_type: None, |
| 1605 | provider_options: None, |
| 1606 | }) |
| 1607 | } else { |
| 1608 | None |
| 1609 | } |
| 1610 | } |
| 1611 | _ => None, |
| 1612 | } |
| 1613 | } |
| 1614 | |
| 1615 | #[cfg(test)] |
| 1616 | mod tests { |