use async_trait::async_trait;
use serde_json::Value as JsonValue;
use langgraph_checkpoint::config::RunnableConfig;
use crate::types::GraphInterrupt;
#[async_trait]
pub trait Runnable: Send + Sync {
fn invoke(&self, input: &JsonValue, config: &RunnableConfig) -> Result<JsonValue, RunnableError>;
async fn ainvoke(&self, input: &JsonValue, config: &RunnableConfig) -> Result<JsonValue, RunnableError>;
fn name(&self) -> &str {
std::any::type_name::<Self>()
}
}
#[derive(Debug, thiserror::Error)]
pub enum RunnableError {
#[error("node error: {0}")]
Node(String),
#[error("config error: {0}")]
Config(String),
#[error("channel error: {0}")]
Channel(#[from] langgraph_checkpoint::error::ChannelError),
#[error(transparent)]
Other(#[from] Box<dyn std::error::Error + Send + Sync>),
#[error("runner error: {0}")]
Runner(String),
#[error("graph interrupt")]
Interrupt(GraphInterrupt),
}