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

Function delete_part

crates/opencode-server/src/routes.rs:1225–1252  ·  view source on GitHub ↗
(
    State(state): State<Arc<ServerState>>,
    Path((session_id, msg_id, part_id)): Path<(String, String, String)>,
)

Source from the content-addressed store, hash-verified

1223}
1224
1225async fn delete_part(
1226 State(state): State<Arc<ServerState>>,
1227 Path((session_id, msg_id, part_id)): Path<(String, String, String)>,
1228) -> Result<Json<serde_json::Value>> {
1229 let mut sessions = state.sessions.lock().await;
1230 let session = sessions
1231 .get_mut(&session_id)
1232 .ok_or_else(|| ApiError::SessionNotFound(session_id.clone()))?;
1233 let message = session
1234 .get_message_mut(&msg_id)
1235 .ok_or_else(|| ApiError::NotFound(format!("Message not found: {}", msg_id)))?;
1236
1237 let before = message.parts.len();
1238 message.parts.retain(|part| part.id != part_id);
1239 if message.parts.len() == before {
1240 return Err(ApiError::NotFound(format!("Part not found: {}", part_id)));
1241 }
1242 session.touch();
1243 drop(sessions);
1244 persist_sessions_if_enabled(&state).await;
1245
1246 Ok(Json(serde_json::json!({
1247 "deleted": true,
1248 "session_id": session_id,
1249 "message_id": msg_id,
1250 "part_id": part_id,
1251 })))
1252}
1253
1254#[derive(Debug, Serialize, Clone)]
1255pub struct StreamEvent {

Callers

nothing calls this directly

Calls 5

get_message_mutMethod · 0.80
get_mutMethod · 0.45
cloneMethod · 0.45
touchMethod · 0.45

Tested by

no test coverage detected