(req: AddPartRequest, msg_id: &str)
| 1139 | } |
| 1140 | |
| 1141 | fn build_message_part(req: AddPartRequest, msg_id: &str) -> Result<opencode_session::MessagePart> { |
| 1142 | let part_type = match req.part_type.as_str() { |
| 1143 | "text" => opencode_session::PartType::Text { |
| 1144 | text: req.text.ok_or_else(|| { |
| 1145 | ApiError::BadRequest("Field `text` is required for text parts".to_string()) |
| 1146 | })?, |
| 1147 | synthetic: None, |
| 1148 | ignored: None, |
| 1149 | }, |
| 1150 | "reasoning" => opencode_session::PartType::Reasoning { |
| 1151 | text: req.text.ok_or_else(|| { |
| 1152 | ApiError::BadRequest("Field `text` is required for reasoning parts".to_string()) |
| 1153 | })?, |
| 1154 | }, |
| 1155 | "tool_call" => opencode_session::PartType::ToolCall { |
| 1156 | id: req.tool_call_id.ok_or_else(|| { |
| 1157 | ApiError::BadRequest( |
| 1158 | "Field `tool_call_id` is required for tool_call parts".to_string(), |
| 1159 | ) |
| 1160 | })?, |
| 1161 | name: req.tool_name.ok_or_else(|| { |
| 1162 | ApiError::BadRequest( |
| 1163 | "Field `tool_name` is required for tool_call parts".to_string(), |
| 1164 | ) |
| 1165 | })?, |
| 1166 | input: req.tool_input.unwrap_or_else(|| serde_json::json!({})), |
| 1167 | }, |
| 1168 | "tool_result" => opencode_session::PartType::ToolResult { |
| 1169 | tool_call_id: req.tool_call_id.ok_or_else(|| { |
| 1170 | ApiError::BadRequest( |
| 1171 | "Field `tool_call_id` is required for tool_result parts".to_string(), |
| 1172 | ) |
| 1173 | })?, |
| 1174 | content: req.content.ok_or_else(|| { |
| 1175 | ApiError::BadRequest( |
| 1176 | "Field `content` is required for tool_result parts".to_string(), |
| 1177 | ) |
| 1178 | })?, |
| 1179 | is_error: req.is_error.unwrap_or(false), |
| 1180 | }, |
| 1181 | unsupported => { |
| 1182 | return Err(ApiError::BadRequest(format!( |
| 1183 | "Unsupported part type: {}", |
| 1184 | unsupported |
| 1185 | ))); |
| 1186 | } |
| 1187 | }; |
| 1188 | |
| 1189 | Ok(opencode_session::MessagePart { |
| 1190 | id: format!("prt_{}", uuid::Uuid::new_v4().simple()), |
| 1191 | part_type, |
| 1192 | created_at: chrono::Utc::now(), |
| 1193 | message_id: Some(msg_id.to_string()), |
| 1194 | }) |
| 1195 | } |
| 1196 | |
| 1197 | async fn add_message_part( |
| 1198 | State(state): State<Arc<ServerState>>, |
no test coverage detected