Archived
add axon-events: typed event schema for the full neuron-technologies stack
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::axon::{AxonMessage, AxonResponse};
|
||||
use crate::axon::{AxonMessage, AxonMethod, AxonResponse};
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
@@ -30,8 +30,8 @@ impl AxonHandler {
|
||||
|
||||
/// Dispatch an AxonMessage to the appropriate handler.
|
||||
pub fn dispatch(&self, msg: AxonMessage) -> AxonResponse {
|
||||
match msg.method.as_str() {
|
||||
"tool_call" => {
|
||||
match msg.method {
|
||||
AxonMethod::ToolCall => {
|
||||
let tool_name = msg
|
||||
.params
|
||||
.get("tool")
|
||||
@@ -50,8 +50,12 @@ impl AxonHandler {
|
||||
AxonResponse::err(msg.id, format!("unknown tool: {}", tool_name))
|
||||
}
|
||||
}
|
||||
"ping" => AxonResponse::ok(msg.id, serde_json::json!({ "pong": true })),
|
||||
other => AxonResponse::err(msg.id, format!("unknown method: {}", other)),
|
||||
AxonMethod::Ping => {
|
||||
AxonResponse::ok(msg.id, serde_json::json!({ "pong": true }))
|
||||
}
|
||||
other => {
|
||||
AxonResponse::err(msg.id, format!("unknown method: {}", other.as_str()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +82,7 @@ mod tests {
|
||||
let handler = AxonHandler::new();
|
||||
let msg = AxonMessage {
|
||||
id: "1".into(),
|
||||
method: "ping".into(),
|
||||
method: AxonMethod::Ping,
|
||||
params: serde_json::json!({}),
|
||||
};
|
||||
let resp = handler.dispatch(msg);
|
||||
@@ -95,7 +99,7 @@ mod tests {
|
||||
|
||||
let msg = AxonMessage {
|
||||
id: "2".into(),
|
||||
method: "tool_call".into(),
|
||||
method: AxonMethod::ToolCall,
|
||||
params: serde_json::json!({ "tool": "remember", "params": { "content": "hello" } }),
|
||||
};
|
||||
let resp = handler.dispatch(msg);
|
||||
@@ -108,7 +112,7 @@ mod tests {
|
||||
let handler = AxonHandler::new();
|
||||
let msg = AxonMessage {
|
||||
id: "3".into(),
|
||||
method: "tool_call".into(),
|
||||
method: AxonMethod::ToolCall,
|
||||
params: serde_json::json!({ "tool": "nonexistent", "params": {} }),
|
||||
};
|
||||
let resp = handler.dispatch(msg);
|
||||
@@ -116,11 +120,11 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dispatch_unknown_method() {
|
||||
fn dispatch_unhandled_method() {
|
||||
let handler = AxonHandler::new();
|
||||
let msg = AxonMessage {
|
||||
id: "4".into(),
|
||||
method: "mystery".into(),
|
||||
method: AxonMethod::Subscribe,
|
||||
params: serde_json::json!({}),
|
||||
};
|
||||
let resp = handler.dispatch(msg);
|
||||
|
||||
Reference in New Issue
Block a user