MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / parts_to_content

Method parts_to_content

crates/opencode-session/src/prompt.rs:1771–1841  ·  view source on GitHub ↗
(parts: &[crate::MessagePart])

Source from the content-addressed store, hash-verified

1769 }
1770
1771 fn parts_to_content(parts: &[crate::MessagePart]) -> Content {
1772 let has_parts = parts
1773 .iter()
1774 .any(|p| !matches!(p.part_type, PartType::Text { .. }));
1775
1776 if !has_parts {
1777 let text = parts
1778 .iter()
1779 .filter_map(|p| match &p.part_type {
1780 PartType::Text { text, .. } => Some(text.clone()),
1781 _ => None,
1782 })
1783 .collect::<Vec<_>>()
1784 .join("\n");
1785 return Content::Text(text);
1786 }
1787
1788 let content_parts: Vec<ContentPart> = parts
1789 .iter()
1790 .filter_map(|p| match &p.part_type {
1791 PartType::Text { text, .. } => Some(ContentPart {
1792 content_type: "text".to_string(),
1793 text: Some(text.clone()),
1794 image_url: None,
1795 tool_use: None,
1796 tool_result: None,
1797 cache_control: None,
1798 filename: None,
1799 media_type: None,
1800 provider_options: None,
1801 }),
1802 PartType::ToolCall { id, name, input } => Some(ContentPart {
1803 content_type: "tool_use".to_string(),
1804 text: None,
1805 image_url: None,
1806 tool_use: Some(opencode_provider::ToolUse {
1807 id: id.clone(),
1808 name: name.clone(),
1809 input: input.clone(),
1810 }),
1811 tool_result: None,
1812 cache_control: None,
1813 filename: None,
1814 media_type: None,
1815 provider_options: None,
1816 }),
1817 PartType::ToolResult {
1818 tool_call_id,
1819 content,
1820 is_error,
1821 } => Some(ContentPart {
1822 content_type: "tool_result".to_string(),
1823 text: None,
1824 image_url: None,
1825 tool_use: None,
1826 tool_result: Some(opencode_provider::ToolResult {
1827 tool_use_id: tool_call_id.clone(),
1828 content: content.clone(),

Callers

nothing calls this directly

Calls 1

cloneMethod · 0.45

Tested by

no test coverage detected