mod send;
pub mod stream;
pub(crate) mod tasks;
use crate::a2a::types::*;
use crate::brain::agent::service::AgentService;
use crate::services::ServiceContext;
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::RwLock;
use tokio_util::sync::CancellationToken;
pub type TaskStore = Arc<RwLock<HashMap<String, Task>>>;
pub type CancelStore = Arc<RwLock<HashMap<String, CancellationToken>>>;
pub fn new_task_store() -> TaskStore {
Arc::new(RwLock::new(HashMap::new()))
}
pub fn new_cancel_store() -> CancelStore {
Arc::new(RwLock::new(HashMap::new()))
}
pub async fn dispatch(
req: JsonRpcRequest,
store: TaskStore,
cancel_store: CancelStore,
agent_service: Arc<AgentService>,
service_context: ServiceContext,
) -> JsonRpcResponse {
match req.method.as_str() {
"message/send" => {
send::handle_send_message(
req.id,
req.params,
store,
cancel_store,
agent_service,
service_context,
)
.await
}
"tasks/get" => tasks::handle_get_task(req.id, req.params, store).await,
"tasks/cancel" => {
tasks::handle_cancel_task(
req.id,
req.params,
store,
cancel_store,
&service_context.pool(),
)
.await
}
_ => JsonRpcResponse::error(
req.id,
error_codes::METHOD_NOT_FOUND,
format!("Method not found: {}", req.method),
),
}
}