1pub mod bm25;
31pub mod chat_definitions;
32pub mod chat_ops;
33pub mod definitions;
34pub mod dream_ops;
35pub mod embed_audit;
37pub mod embed_audit_definitions;
38pub mod helpers;
39pub mod kg_ops;
40pub mod memory_ops;
41pub mod palace_ops;
42pub mod room_definitions;
43pub mod room_ops;
44pub mod task_definitions;
45pub mod task_ops;
46pub mod wing_definitions;
49pub mod wing_ops;
50
51pub use bm25::{spawn_bm25_index_worker, Bm25IndexRequest, BM25_INDEX_QUEUE_CAPACITY};
55pub use definitions::{tool_definitions, tool_definitions_with, MemoryMcpServer};
56pub(crate) use helpers::{auto_extract_and_assert, room_label};
57
58#[cfg(test)]
60pub(crate) use bm25::{bm25_hits_to_recall_results, bm25_index_enqueue};
61#[cfg(test)]
62pub(crate) use helpers::{blocklist_gate, content_gate, dedup_gate, open_palace_handle};
63
64use crate::AppState;
65use anyhow::Result;
66use serde_json::Value;
67
68use chat_ops::{
69 handle_chat_session_add_turn, handle_chat_session_create, handle_chat_session_delete,
70 handle_chat_session_get, handle_chat_session_list, handle_chat_session_recall,
71 handle_chat_turn_append,
72};
73use dream_ops::{handle_dream_consolidate_room, handle_palace_dream};
74use kg_ops::{
75 handle_add_alias, handle_discover_aliases, handle_get_prompt_context, handle_kg_assert,
76 handle_kg_bootstrap, handle_kg_gaps, handle_kg_list_subjects, handle_kg_query,
77 handle_kg_retract_triple, handle_list_prompt_facts, handle_remove_prompt_fact,
78 handle_upgrade_tool,
79};
80use memory_ops::{
81 handle_memory_forget, handle_memory_list, handle_memory_note, handle_memory_recall,
82 handle_memory_recall_all, handle_memory_recall_deep, handle_memory_remember,
83 handle_memory_send_message,
84};
85use palace_ops::{
86 handle_palace_compact, handle_palace_create, handle_palace_delete, handle_palace_info,
87 handle_palace_list, handle_palace_reembed, handle_palace_unalias, handle_palace_update,
88};
89use room_ops::{handle_room_create, handle_room_list, handle_room_rename};
90use task_ops::{handle_task_add, handle_task_complete, handle_task_list};
91use wing_ops::{handle_wing_create, handle_wing_list, handle_wing_rename};
92
93pub async fn dispatch_tool(state: &AppState, name: &str, args: Value) -> Result<Value> {
105 match name {
106 "memory_remember" => handle_memory_remember(state, args).await,
107 "memory_note" => handle_memory_note(state, args).await,
108 "memory_recall" => handle_memory_recall(state, args).await,
109 "memory_recall_deep" => handle_memory_recall_deep(state, args).await,
110 "palace_create" => handle_palace_create(state, args).await,
111 "palace_list" => handle_palace_list(state, args).await,
112 "palace_delete" => handle_palace_delete(state, args).await,
113 "palace_update" => handle_palace_update(state, args).await,
114 "kg_assert" => handle_kg_assert(state, args).await,
115 "kg_retract_triple" => handle_kg_retract_triple(state, args).await,
118 "add_alias" => handle_add_alias(state, args).await,
119 "list_prompt_facts" => handle_list_prompt_facts(state, args).await,
120 "remove_prompt_fact" => handle_remove_prompt_fact(state, args).await,
121 "kg_query" => handle_kg_query(state, args).await,
122 "kg_list_subjects" => handle_kg_list_subjects(state, args).await,
125 "memory_list" => handle_memory_list(state, args).await,
126 "memory_forget" => handle_memory_forget(state, args).await,
127 "palace_info" => handle_palace_info(state, args).await,
128 "palace_compact" => handle_palace_compact(state, args).await,
129 "palace_reembed" => handle_palace_reembed(state, args).await,
131 "palace_unalias" => handle_palace_unalias(state, args).await,
133 "palace_verify_embedded" => embed_audit::handle_palace_verify_embedded(state, args).await,
135 "palace_embed_sweep" => embed_audit::handle_palace_embed_sweep(state, args).await,
138 "kg_gaps" => handle_kg_gaps(state, args).await,
139 "memory_recall_all" => handle_memory_recall_all(state, args).await,
140 "get_prompt_context" => handle_get_prompt_context(state, args).await,
141 "discover_aliases" => handle_discover_aliases(state, args).await,
142 "kg_bootstrap" => handle_kg_bootstrap(state, args).await,
143 "memory_send_message" => handle_memory_send_message(state, args).await,
144 "upgrade" => handle_upgrade_tool(state, args).await,
145 "console_metrics" => crate::console_metrics::handle_console_metrics(state, args).await,
146 "chat_session_create" => handle_chat_session_create(state, args).await,
147 "chat_session_add_turn" => handle_chat_session_add_turn(state, args).await,
148 "chat_session_get" => handle_chat_session_get(state, args).await,
149 "chat_session_recall" => handle_chat_session_recall(state, args).await,
150 "chat_session_list" => handle_chat_session_list(state, args).await,
151 "chat_session_delete" => handle_chat_session_delete(state, args).await,
152 "chat_turn_append" => handle_chat_turn_append(state, args).await,
153 "dream_consolidate_room" => handle_dream_consolidate_room(state, args).await,
154 "palace_dream" => handle_palace_dream(state, args).await,
155 "task_add" => handle_task_add(state, args).await,
156 "task_list" => handle_task_list(state, args).await,
157 "task_complete" => handle_task_complete(state, args).await,
158 "room_list" => handle_room_list(state, args).await,
161 "room_create" => handle_room_create(state, args).await,
162 "room_rename" => handle_room_rename(state, args).await,
163 "wing_list" => handle_wing_list(state, args).await,
165 "wing_create" => handle_wing_create(state, args).await,
166 "wing_rename" => handle_wing_rename(state, args).await,
167 other => anyhow::bail!("unknown tool: {other}"),
168 }
169}
170
171#[cfg(test)]
172mod tests;