use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use thiserror::Error;
#[derive(Error, Debug)]
pub enum PluginError {
#[error("Plugin not found: {0}")]
NotFound(String),
#[error("Load failed: {0}")]
LoadFailed(String),
#[error("Hook failed: {0}")]
HookFailed(String),
#[error("Execution error: {0}")]
ExecutionError(String),
#[error("IPC error: {0}")]
Ipc(String),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum PluginHook {
BeforeMessage,
AfterMessage,
BeforeToolCall,
AfterToolCall,
SessionStart,
SessionEnd,
AgentResponse,
Error,
}
#[async_trait]
pub trait Plugin: Send + Sync {
fn id(&self) -> &str;
fn name(&self) -> &str;
fn version(&self) -> &str;
fn hooks(&self) -> &[PluginHook];
async fn execute_hook(
&self,
hook: PluginHook,
data: serde_json::Value,
) -> Result<serde_json::Value, PluginError>;
async fn activate(&self) -> Result<(), PluginError>;
async fn deactivate(&self) -> Result<(), PluginError>;
}
pub struct PluginApi {
}
impl PluginApi {
#[must_use]
pub const fn new() -> Self {
Self {}
}
}
impl Default for PluginApi {
fn default() -> Self {
Self::new()
}
}