diff --git a/server/src/handlers.rs b/server/src/handlers.rs index d9a6541..7d5de00 100644 --- a/server/src/handlers.rs +++ b/server/src/handlers.rs @@ -23,6 +23,18 @@ macro_rules! parse_tool { }; } +macro_rules! handle_list_with_namespace { + ($self:expr, $store:ident, $tool_type:ty, $args:expr, $id:expr) => {{ + let req = parse_tool!($args, $id, $tool_type); + let mut items = $self.state.$store.read(); + if let Some(ns) = req.namespace { + items.retain(|i| i.namespace == ns); + } + let data = serde_json::to_string(&items).unwrap_or_default(); + Ok(data.to_string()) + }}; +} + use serde::de::DeserializeOwned; use std::collections::HashSet; use std::sync::Arc; @@ -1258,15 +1270,7 @@ impl MemoryHandler { }); Ok("Handoff memo left".to_string()) } - "read_handoff_memos" => { - let req = parse_tool!(args, id, ReadHandoffMemosTool); - let mut memos = self.state.handoff_memos.read(); - if let Some(ns) = req.namespace { - memos.retain(|m| m.namespace == ns); - } - let data = serde_json::to_string(&memos).unwrap_or_default(); - Ok(data.to_string()) - } + "read_handoff_memos" => handle_list_with_namespace!(self, handoff_memos, ReadHandoffMemosTool, args, id), "clear_handoff_memos" => { let req = parse_tool!(args, id, ClearHandoffMemosTool); let ids: HashSet<_> = req.ids.into_iter().collect(); @@ -1349,15 +1353,7 @@ impl MemoryHandler { Ok("Milestone not found".to_string()) } } - "list_milestones" => { - let req = parse_tool!(args, id, ListMilestonesTool); - let mut ms = self.state.milestones.read(); - if let Some(ns) = req.namespace { - ms.retain(|m| m.namespace == ns); - } - let data = serde_json::to_string(&ms).unwrap_or_default(); - Ok(data.to_string()) - } + "list_milestones" => handle_list_with_namespace!(self, milestones, ListMilestonesTool, args, id), "generate_standup_report" => { let req = parse_tool!(args, id, GenerateStandupReportTool); let cutoff = SystemTime::now()