zerolaunch_plugin_host/
host_dispatch.rs1use zerolaunch_plugin_protocol::{codes, JsonRpcError};
6
7pub trait PluginEventSink: Send + Sync {
10 fn notify(&self, method: &str, params: serde_json::Value);
13}
14
15#[async_trait::async_trait]
19pub trait HostCallHandler: Send + Sync {
20 async fn handle_host_call(
22 &self,
23 method: &str,
24 params: serde_json::Value,
25 ) -> Result<serde_json::Value, JsonRpcError>;
26
27 fn attach_event_sink(&self, _sink: std::sync::Arc<dyn PluginEventSink>) {}
30
31 fn detach_event_sink(&self) {}
34}
35
36impl std::fmt::Debug for dyn HostCallHandler {
37 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38 write!(f, "HostCallHandler")
39 }
40}
41
42pub fn method_not_found(method: &str) -> JsonRpcError {
44 JsonRpcError::new(
45 codes::METHOD_NOT_FOUND,
46 format!("host method not found: {}", method),
47 )
48}
49
50pub fn invalid_params(msg: impl Into<String>) -> JsonRpcError {
52 JsonRpcError::new(codes::INVALID_PARAMS, msg)
53}