use crate::models::field_names;
use axum::{
Json,
extract::State,
http::{HeaderMap, StatusCode},
response::IntoResponse,
};
use serde::Deserialize;
use serde_json::{Value, json};
use super::AppState;
#[derive(Debug, Deserialize)]
pub struct ShareBody {
pub source_memory_id: String,
pub target_agent_id: String,
}
pub async fn share_memory(
State(app): State<AppState>,
_headers: HeaderMap,
Json(body): Json<ShareBody>,
) -> impl IntoResponse {
let params: Value = json!({
(field_names::SOURCE_MEMORY_ID): body.source_memory_id,
(field_names::TARGET_AGENT_ID): body.target_agent_id,
});
let lock = app.db.lock().await;
let result = crate::mcp::share::handle_share(&lock.0, ¶ms);
drop(lock);
match result {
Ok(v) => (StatusCode::OK, Json(v)).into_response(),
Err(e) => {
tracing::warn!("share_memory failed: {e}");
(
StatusCode::BAD_REQUEST,
Json(json!({"error": e.to_string()})),
)
.into_response()
}
}
}