refactor: deduplicate simple list tool handlers via handle_list_with_namespace macro
This commit is contained in:
1 parent
d237f5c5ad
commit
9f24e66d88
1 file changed
+14
-18
+14
-18
@@ -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 serde::de::DeserializeOwned;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -1258,15 +1270,7 @@ impl MemoryHandler {
|
|||||||
});
|
});
|
||||||
Ok("Handoff memo left".to_string())
|
Ok("Handoff memo left".to_string())
|
||||||
}
|
}
|
||||||
"read_handoff_memos" => {
|
"read_handoff_memos" => handle_list_with_namespace!(self, handoff_memos, ReadHandoffMemosTool, args, id),
|
||||||
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())
|
|
||||||
}
|
|
||||||
"clear_handoff_memos" => {
|
"clear_handoff_memos" => {
|
||||||
let req = parse_tool!(args, id, ClearHandoffMemosTool);
|
let req = parse_tool!(args, id, ClearHandoffMemosTool);
|
||||||
let ids: HashSet<_> = req.ids.into_iter().collect();
|
let ids: HashSet<_> = req.ids.into_iter().collect();
|
||||||
@@ -1349,15 +1353,7 @@ impl MemoryHandler {
|
|||||||
Ok("Milestone not found".to_string())
|
Ok("Milestone not found".to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"list_milestones" => {
|
"list_milestones" => handle_list_with_namespace!(self, milestones, ListMilestonesTool, args, id),
|
||||||
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())
|
|
||||||
}
|
|
||||||
"generate_standup_report" => {
|
"generate_standup_report" => {
|
||||||
let req = parse_tool!(args, id, GenerateStandupReportTool);
|
let req = parse_tool!(args, id, GenerateStandupReportTool);
|
||||||
let cutoff = SystemTime::now()
|
let cutoff = SystemTime::now()
|
||||||
|
|||||||
Reference in new issue
Block a user