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

Method to_message_with_parts

crates/opencode-session/src/prompt.rs:2207–2434  ·  view source on GitHub ↗
(
        messages: &[SessionMessage],
        provider_id: &str,
        model_id: &str,
    )

Source from the content-addressed store, hash-verified

2205 }
2206
2207 fn to_message_with_parts(
2208 messages: &[SessionMessage],
2209 provider_id: &str,
2210 model_id: &str,
2211 ) -> Vec<MessageWithParts> {
2212 let mut out = Vec::with_capacity(messages.len());
2213 let mut last_user_id = String::new();
2214
2215 for msg in messages {
2216 let created = msg.created_at.timestamp_millis();
2217 let mut parts: Vec<V2Part> = msg
2218 .parts
2219 .iter()
2220 .filter_map(|part| match &part.part_type {
2221 PartType::Text { text, .. } => Some(V2Part::Text {
2222 id: part.id.clone(),
2223 session_id: msg.session_id.clone(),
2224 message_id: msg.id.clone(),
2225 text: text.clone(),
2226 synthetic: None,
2227 ignored: None,
2228 time: None,
2229 metadata: None,
2230 }),
2231 PartType::File {
2232 url,
2233 filename,
2234 mime,
2235 } => Some(V2Part::File(crate::message_v2::FilePart {
2236 id: part.id.clone(),
2237 session_id: msg.session_id.clone(),
2238 message_id: msg.id.clone(),
2239 mime: mime.clone(),
2240 url: url.clone(),
2241 filename: Some(filename.clone()),
2242 source: None,
2243 })),
2244 PartType::Compaction { .. } => Some(V2Part::Compaction(V2CompactionPart {
2245 id: part.id.clone(),
2246 session_id: msg.session_id.clone(),
2247 message_id: msg.id.clone(),
2248 auto: true,
2249 })),
2250 _ => None,
2251 })
2252 .collect();
2253
2254 if let Some(snapshot) = msg
2255 .metadata
2256 .get("step_start_snapshot")
2257 .or_else(|| msg.metadata.get("snapshot"))
2258 .and_then(|v| v.as_str())
2259 {
2260 parts.push(V2Part::StepStart(StepStartPart {
2261 id: format!("prt_{}", uuid::Uuid::new_v4()),
2262 session_id: msg.session_id.clone(),
2263 message_id: msg.id.clone(),
2264 snapshot: Some(snapshot.to_string()),

Callers

nothing calls this directly

Calls 5

newFunction · 0.85
is_emptyMethod · 0.80
cloneMethod · 0.45
getMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected