Convert a core Message to a UI ChatMessage
(msg: &CoreMessage)
| 138 | impl ChatMessage { |
| 139 | /// Convert a core Message to a UI ChatMessage |
| 140 | pub fn from_core_message(msg: &CoreMessage) -> Self { |
| 141 | let role = MessageRole::from(&msg.role); |
| 142 | let mut flow_items = Vec::new(); |
| 143 | |
| 144 | match &msg.content { |
| 145 | MessageContent::Text(text) => { |
| 146 | if !text.is_empty() { |
| 147 | flow_items.push(FlowItem::Text { |
| 148 | content: display_text_for_role(&role, text), |
| 149 | is_streaming: false, |
| 150 | }); |
| 151 | } |
| 152 | } |
| 153 | MessageContent::Mixed { |
| 154 | reasoning_content, |
| 155 | text, |
| 156 | tool_calls, |
| 157 | } => { |
| 158 | // Add reasoning/thinking block if present |
| 159 | if let Some(reasoning) = reasoning_content { |
| 160 | if !reasoning.is_empty() { |
| 161 | flow_items.push(FlowItem::Thinking { |
| 162 | content: reasoning.clone(), |
| 163 | }); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | // Add text block if present |
| 168 | if !text.is_empty() { |
| 169 | flow_items.push(FlowItem::Text { |
| 170 | content: display_text_for_role(&role, text), |
| 171 | is_streaming: false, |
| 172 | }); |
| 173 | } |
| 174 | |
| 175 | // Add tool call blocks |
| 176 | for tc in tool_calls { |
| 177 | flow_items.push(FlowItem::Tool { |
| 178 | tool_state: ToolDisplayState { |
| 179 | tool_id: tc.tool_id.clone(), |
| 180 | tool_name: tc.tool_name.clone(), |
| 181 | parameters: tc.arguments.clone(), |
| 182 | status: ToolDisplayStatus::Success, // Historical messages are completed |
| 183 | result: None, |
| 184 | progress_message: None, |
| 185 | duration_ms: None, |
| 186 | metadata: None, |
| 187 | subagent_progress: None, |
| 188 | }, |
| 189 | }); |
| 190 | } |
| 191 | } |
| 192 | MessageContent::Multimodal { text, .. } => { |
| 193 | if !text.is_empty() { |
| 194 | flow_items.push(FlowItem::Text { |
| 195 | content: display_text_for_role(&role, text), |
| 196 | is_streaming: false, |
| 197 | }); |
nothing calls this directly
no test coverage detected