refactor(desktop): split kernel_commands/pipeline_commands into modules, add SaaS client libs and gateway modules
Split monolithic kernel_commands.rs (2185 lines) and pipeline_commands.rs (1391 lines) into focused sub-modules under kernel_commands/ and pipeline_commands/ directories. Add gateway module (commands, config, io, runtime), health_check, and 15 new TypeScript client libraries for SaaS relay, auth, admin, telemetry, and kernel sub-systems (a2a, agent, chat, hands, skills, triggers). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
114
desktop/src-tauri/src/kernel_commands/a2a.rs
Normal file
114
desktop/src-tauri/src/kernel_commands/a2a.rs
Normal file
@@ -0,0 +1,114 @@
|
||||
//! A2A (Agent-to-Agent) commands — gated behind `multi-agent` feature
|
||||
|
||||
use serde_json;
|
||||
use tauri::State;
|
||||
use zclaw_types::AgentId;
|
||||
|
||||
use super::KernelState;
|
||||
|
||||
// ============================================================
|
||||
// A2A (Agent-to-Agent) Commands — gated behind multi-agent feature
|
||||
// ============================================================
|
||||
|
||||
#[cfg(feature = "multi-agent")]
|
||||
/// Send a direct A2A message from one agent to another
|
||||
#[tauri::command]
|
||||
pub async fn agent_a2a_send(
|
||||
state: State<'_, KernelState>,
|
||||
from: String,
|
||||
to: String,
|
||||
payload: serde_json::Value,
|
||||
message_type: Option<String>,
|
||||
) -> Result<(), String> {
|
||||
let kernel_lock = state.lock().await;
|
||||
let kernel = kernel_lock.as_ref()
|
||||
.ok_or_else(|| "Kernel not initialized. Call kernel_init first.".to_string())?;
|
||||
|
||||
let from_id: AgentId = from.parse()
|
||||
.map_err(|_| format!("Invalid from agent ID: {}", from))?;
|
||||
let to_id: AgentId = to.parse()
|
||||
.map_err(|_| format!("Invalid to agent ID: {}", to))?;
|
||||
|
||||
let msg_type = message_type.map(|mt| match mt.as_str() {
|
||||
"request" => zclaw_kernel::A2aMessageType::Request,
|
||||
"notification" => zclaw_kernel::A2aMessageType::Notification,
|
||||
"task" => zclaw_kernel::A2aMessageType::Task,
|
||||
_ => zclaw_kernel::A2aMessageType::Notification,
|
||||
});
|
||||
|
||||
kernel.a2a_send(&from_id, &to_id, payload, msg_type).await
|
||||
.map_err(|e| format!("A2A send failed: {}", e))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Broadcast a message from one agent to all other agents
|
||||
#[cfg(feature = "multi-agent")]
|
||||
#[tauri::command]
|
||||
pub async fn agent_a2a_broadcast(
|
||||
state: State<'_, KernelState>,
|
||||
from: String,
|
||||
payload: serde_json::Value,
|
||||
) -> Result<(), String> {
|
||||
let kernel_lock = state.lock().await;
|
||||
let kernel = kernel_lock.as_ref()
|
||||
.ok_or_else(|| "Kernel not initialized. Call kernel_init first.".to_string())?;
|
||||
|
||||
let from_id: AgentId = from.parse()
|
||||
.map_err(|_| format!("Invalid from agent ID: {}", from))?;
|
||||
|
||||
kernel.a2a_broadcast(&from_id, payload).await
|
||||
.map_err(|e| format!("A2A broadcast failed: {}", e))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Discover agents with a specific capability
|
||||
#[cfg(feature = "multi-agent")]
|
||||
#[tauri::command]
|
||||
pub async fn agent_a2a_discover(
|
||||
state: State<'_, KernelState>,
|
||||
capability: String,
|
||||
) -> Result<Vec<serde_json::Value>, String> {
|
||||
let kernel_lock = state.lock().await;
|
||||
let kernel = kernel_lock.as_ref()
|
||||
.ok_or_else(|| "Kernel not initialized. Call kernel_init first.".to_string())?;
|
||||
|
||||
let profiles = kernel.a2a_discover(&capability).await
|
||||
.map_err(|e| format!("A2A discover failed: {}", e))?;
|
||||
|
||||
let result: Vec<serde_json::Value> = profiles.iter()
|
||||
.filter_map(|p| serde_json::to_value(p).ok())
|
||||
.collect();
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Delegate a task to another agent and wait for response
|
||||
#[cfg(feature = "multi-agent")]
|
||||
#[tauri::command]
|
||||
pub async fn agent_a2a_delegate_task(
|
||||
state: State<'_, KernelState>,
|
||||
from: String,
|
||||
to: String,
|
||||
task: String,
|
||||
timeout_ms: Option<u64>,
|
||||
) -> Result<serde_json::Value, String> {
|
||||
let kernel_lock = state.lock().await;
|
||||
let kernel = kernel_lock.as_ref()
|
||||
.ok_or_else(|| "Kernel not initialized. Call kernel_init first.".to_string())?;
|
||||
|
||||
let from_id: AgentId = from.parse()
|
||||
.map_err(|_| format!("Invalid from agent ID: {}", from))?;
|
||||
let to_id: AgentId = to.parse()
|
||||
.map_err(|_| format!("Invalid to agent ID: {}", to))?;
|
||||
|
||||
let timeout = timeout_ms.unwrap_or(30_000);
|
||||
|
||||
// 30 seconds default
|
||||
|
||||
let response = kernel.a2a_delegate_task(&from_id, &to_id, task, timeout).await
|
||||
.map_err(|e| format!("A2A task delegation failed: {}", e))?;
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
Reference in New Issue
Block a user