1use std::future::Future;23use bifrostlink::declarative::endpoints;4use bifrostlink::Config;5use serde::{Deserialize, Serialize};67#[derive(Serialize, Deserialize, Debug, thiserror::Error)]8pub enum Error {9 #[error("plugin name must be a bare file name")]10 BadName,11 #[error("spawning plugin failed: {0}")]12 Spawn(String),13 #[error("agent is shutting down")]14 Gone,15}1617pub trait PluginHost: Send + Sync {18 fn load_plugin(&self, id: u16, name: String) -> impl Future<Output = Result<(), Error>> + Send;1920 fn load_plugin_path(21 &self,22 id: u16,23 path: String,24 ) -> impl Future<Output = Result<(), Error>> + Send;25}2627pub struct PluginEndpoints<H>(pub H);2829#[endpoints(ns = 9)]30impl<H: PluginHost + 'static> PluginEndpoints<H> {31 #[endpoints(id = 1)]32 async fn load_plugin(&self, id: u16, name: String) -> Result<(), Error> {33 self.0.load_plugin(id, name).await34 }35 #[endpoints(id = 2)]36 async fn load_plugin_path(&self, id: u16, path: String) -> Result<(), Error> {37 self.0.load_plugin_path(id, path).await38 }39}