tools: delete old dispatch functions
All dispatch now goes through the Tool registry. Removed: - memory::dispatch() (20-line match) - channels::dispatch() and dispatch_blocking() - channel_list_blocking(), channel_notifications_blocking() Channel tool functions made pub so registry calls them directly. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
03cf13e9eb
commit
112abb2000
3 changed files with 8 additions and 71 deletions
|
|
@ -53,49 +53,13 @@ pub fn definitions() -> Vec<ToolDef> {
|
||||||
|
|
||||||
// ── Dispatch ───────────────────────────────────────────────────
|
// ── Dispatch ───────────────────────────────────────────────────
|
||||||
|
|
||||||
pub async fn dispatch(name: &str, args: &serde_json::Value) -> Result<String> {
|
|
||||||
match name {
|
|
||||||
"channel_list" => channel_list().await,
|
|
||||||
"channel_recv" => channel_recv(args).await,
|
|
||||||
"channel_send" => channel_send(args).await,
|
|
||||||
"channel_notifications" => channel_notifications().await,
|
|
||||||
_ => anyhow::bail!("unknown channel tool: {}", name),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Blocking dispatch for synchronous contexts (MCP server).
|
|
||||||
pub fn dispatch_blocking(name: &str, args: &serde_json::Value) -> Result<String> {
|
|
||||||
match name {
|
|
||||||
"channel_list" => Ok(channel_list_blocking()),
|
|
||||||
"channel_notifications" => Ok(channel_notifications_blocking()),
|
|
||||||
"channel_recv" | "channel_send" => {
|
|
||||||
let rt = tokio::runtime::Builder::new_current_thread()
|
|
||||||
.enable_all()
|
|
||||||
.build()?;
|
|
||||||
let local = tokio::task::LocalSet::new();
|
|
||||||
local.block_on(&rt, async {
|
|
||||||
match name {
|
|
||||||
"channel_recv" => channel_recv(args).await,
|
|
||||||
"channel_send" => channel_send(args).await,
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
_ => anyhow::bail!("unknown channel tool: {}", name),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Tool implementations ───────────────────────────────────────
|
// ── Tool implementations ───────────────────────────────────────
|
||||||
|
|
||||||
async fn channel_list() -> Result<String> {
|
pub async fn channel_list() -> Result<String> {
|
||||||
let result = fetch_all_channels().await;
|
let result = fetch_all_channels().await;
|
||||||
Ok(format_channel_list(&result))
|
Ok(format_channel_list(&result))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn channel_list_blocking() -> String {
|
|
||||||
let result = fetch_all_channels_blocking();
|
|
||||||
format_channel_list(&result)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn format_channel_list(channels: &[(String, bool, u32)]) -> String {
|
fn format_channel_list(channels: &[(String, bool, u32)]) -> String {
|
||||||
if channels.is_empty() {
|
if channels.is_empty() {
|
||||||
|
|
@ -119,7 +83,7 @@ struct RecvArgs {
|
||||||
fn default_true() -> bool { true }
|
fn default_true() -> bool { true }
|
||||||
fn default_min_count() -> u32 { 20 }
|
fn default_min_count() -> u32 { 20 }
|
||||||
|
|
||||||
async fn channel_recv(args: &serde_json::Value) -> Result<String> {
|
pub async fn channel_recv(args: &serde_json::Value) -> Result<String> {
|
||||||
let a: RecvArgs = serde_json::from_value(args.clone())
|
let a: RecvArgs = serde_json::from_value(args.clone())
|
||||||
.context("invalid channel_recv arguments")?;
|
.context("invalid channel_recv arguments")?;
|
||||||
let sock = daemon_sock(&a.channel)?;
|
let sock = daemon_sock(&a.channel)?;
|
||||||
|
|
@ -140,7 +104,7 @@ struct SendArgs {
|
||||||
message: String,
|
message: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn channel_send(args: &serde_json::Value) -> Result<String> {
|
pub async fn channel_send(args: &serde_json::Value) -> Result<String> {
|
||||||
let a: SendArgs = serde_json::from_value(args.clone())
|
let a: SendArgs = serde_json::from_value(args.clone())
|
||||||
.context("invalid channel_send arguments")?;
|
.context("invalid channel_send arguments")?;
|
||||||
let sock = daemon_sock(&a.channel)?;
|
let sock = daemon_sock(&a.channel)?;
|
||||||
|
|
@ -154,15 +118,11 @@ async fn channel_send(args: &serde_json::Value) -> Result<String> {
|
||||||
.map_err(|e| anyhow::anyhow!("{}", e))
|
.map_err(|e| anyhow::anyhow!("{}", e))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn channel_notifications() -> Result<String> {
|
pub async fn channel_notifications() -> Result<String> {
|
||||||
let result = fetch_all_channels().await;
|
let result = fetch_all_channels().await;
|
||||||
Ok(format_notifications(&result))
|
Ok(format_notifications(&result))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn channel_notifications_blocking() -> String {
|
|
||||||
let result = fetch_all_channels_blocking();
|
|
||||||
format_notifications(&result)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn format_notifications(channels: &[(String, bool, u32)]) -> String {
|
fn format_notifications(channels: &[(String, bool, u32)]) -> String {
|
||||||
let unread: Vec<_> = channels.iter().filter(|(_, _, u)| *u > 0).collect();
|
let unread: Vec<_> = channels.iter().filter(|(_, _, u)| *u > 0).collect();
|
||||||
|
|
|
||||||
|
|
@ -41,29 +41,6 @@ pub fn journal_definitions() -> Vec<ToolDef> {
|
||||||
vec![journal_tail_def(), journal_new_def(), journal_update_def()]
|
vec![journal_tail_def(), journal_new_def(), journal_update_def()]
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Dispatch (legacy — to be replaced by Tool registry) ───────
|
|
||||||
|
|
||||||
pub fn dispatch(name: &str, args: &serde_json::Value, provenance: Option<&str>) -> Result<String> {
|
|
||||||
match name {
|
|
||||||
"memory_render" => render(args),
|
|
||||||
"memory_write" => write(args),
|
|
||||||
"memory_search" => search(args),
|
|
||||||
"memory_links" => links(args),
|
|
||||||
"memory_link_set" => link_set(args),
|
|
||||||
"memory_link_add" => link_add(args),
|
|
||||||
"memory_used" => used(args),
|
|
||||||
"memory_weight_set" => weight_set(args),
|
|
||||||
"memory_rename" => rename(args),
|
|
||||||
"memory_supersede" => supersede(args),
|
|
||||||
"memory_query" => query(args),
|
|
||||||
"output" => output(args),
|
|
||||||
"journal_tail" => journal_tail(args),
|
|
||||||
"journal_new" => journal_new(args),
|
|
||||||
"journal_update" => journal_update(args),
|
|
||||||
_ => anyhow::bail!("Unknown memory tool: {}", name),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Memory tools ───────────────────────────────────────────────
|
// ── Memory tools ───────────────────────────────────────────────
|
||||||
|
|
||||||
pub fn render_def() -> ToolDef {
|
pub fn render_def() -> ToolDef {
|
||||||
|
|
|
||||||
|
|
@ -233,10 +233,10 @@ pub fn tools() -> Vec<Tool> {
|
||||||
Tool { def: memory::output_def(), handler: |_a, v| Box::pin(async move { memory::output(&v) }) },
|
Tool { def: memory::output_def(), handler: |_a, v| Box::pin(async move { memory::output(&v) }) },
|
||||||
|
|
||||||
// Channel tools
|
// Channel tools
|
||||||
Tool { def: channels::definitions()[0].clone(), handler: |_a, v| Box::pin(async move { channels::dispatch("channel_list", &v).await }) },
|
Tool { def: channels::definitions()[0].clone(), handler: |_a, v| Box::pin(async move { channels::channel_list().await }) },
|
||||||
Tool { def: channels::definitions()[1].clone(), handler: |_a, v| Box::pin(async move { channels::dispatch("channel_recv", &v).await }) },
|
Tool { def: channels::definitions()[1].clone(), handler: |_a, v| Box::pin(async move { channels::channel_recv(&v).await }) },
|
||||||
Tool { def: channels::definitions()[2].clone(), handler: |_a, v| Box::pin(async move { channels::dispatch("channel_send", &v).await }) },
|
Tool { def: channels::definitions()[2].clone(), handler: |_a, v| Box::pin(async move { channels::channel_send(&v).await }) },
|
||||||
Tool { def: channels::definitions()[3].clone(), handler: |_a, v| Box::pin(async move { channels::dispatch("channel_notifications", &v).await }) },
|
Tool { def: channels::definitions()[3].clone(), handler: |_a, v| Box::pin(async move { channels::channel_notifications().await }) },
|
||||||
|
|
||||||
// Control tools
|
// Control tools
|
||||||
Tool { def: control::definitions()[0].clone(),
|
Tool { def: control::definitions()[0].clone(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue