feat: add get_all_runner_status to WASM client and use it to show real runner status in dropdown

This commit is contained in:
Timur Gordon
2025-11-11 15:09:19 +01:00
parent 2ca593510c
commit 285199edac
7 changed files with 49 additions and 529 deletions

View File

@@ -1,31 +1,3 @@
//! OpenRPC client for Hero Supervisor
//!
//! This crate provides a client library for interacting with the Hero Supervisor
//! OpenRPC server. It offers a simple, async interface for managing actors and jobs.
//!
//! ## Features
//!
//! - **Native client**: Full-featured client for native Rust applications
//! - **WASM client**: Browser-compatible client using fetch APIs
//!
//! ## Usage
//!
//! ### Native Client
//! ```rust
//! use hero_supervisor_openrpc_client::SupervisorClient;
//!
//! let client = SupervisorClient::new("http://localhost:3030")?;
//! let runners = client.list_runners().await?;
//! ```
//!
//! ### WASM Client
//! ```rust
//! use hero_supervisor_openrpc_client::wasm::WasmSupervisorClient;
//!
//! let client = WasmSupervisorClient::new("http://localhost:3030".to_string());
//! let runners = client.list_runners().await?;
//! ```
use serde::{Deserialize, Serialize};
use thiserror::Error;
use serde_json;

View File

@@ -326,10 +326,22 @@ impl WasmSupervisorClient {
if let Ok(runners) = serde_json::from_value::<Vec<String>>(result) {
Ok(runners)
} else {
Err(JsValue::from_str("Invalid response format for list_runners"))
Err(JsValue::from_str("Failed to parse runners list"))
}
},
Err(e) => Err(JsValue::from_str(&e.to_string())),
Err(e) => Err(JsValue::from_str(&format!("Failed to list runners: {}", e)))
}
}
/// Get status of all runners
pub async fn get_all_runner_status(&self) -> Result<JsValue, JsValue> {
match self.call_method("get_all_runner_status", serde_json::Value::Null).await {
Ok(result) => {
// Convert serde_json::Value to JsValue
Ok(serde_wasm_bindgen::to_value(&result)
.map_err(|e| JsValue::from_str(&format!("Failed to convert result: {}", e)))?)
},
Err(e) => Err(JsValue::from_str(&format!("Failed to get runner statuses: {}", e)))
}
}