use zerolaunch_plugin_protocol::{codes, JsonRpcError};
pub trait PluginEventSink: Send + Sync {
fn notify(&self, method: &str, params: serde_json::Value);
}
#[async_trait::async_trait]
pub trait HostCallHandler: Send + Sync {
async fn handle_host_call(
&self,
method: &str,
params: serde_json::Value,
) -> Result<serde_json::Value, JsonRpcError>;
fn attach_event_sink(&self, _sink: std::sync::Arc<dyn PluginEventSink>) {}
fn detach_event_sink(&self) {}
}
impl std::fmt::Debug for dyn HostCallHandler {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "HostCallHandler")
}
}
pub fn method_not_found(method: &str) -> JsonRpcError {
JsonRpcError::new(
codes::METHOD_NOT_FOUND,
format!("host method not found: {}", method),
)
}
pub fn invalid_params(msg: impl Into<String>) -> JsonRpcError {
JsonRpcError::new(codes::INVALID_PARAMS, msg)
}