use crate::channel::{
ChannelDescriptor, ChannelInboundEnvelope, ChannelOutboundIntent, ChannelSendError,
MessageReceipt,
};
use crate::controllers::ChannelAccountSnapshot;
use async_trait::async_trait;
use serde_json::Value;
#[derive(
Debug,
Clone,
Copy,
Default,
PartialEq,
Eq,
serde::Serialize,
serde::Deserialize,
schemars::JsonSchema,
)]
#[serde(rename_all = "snake_case")]
pub enum ChannelReceiveAckPolicy {
#[default]
AfterReceiveRecord,
AfterAgentDispatch,
AfterDurableSend,
Manual,
}
#[async_trait]
pub trait ChannelInboundSink: Send + Sync {
async fn push(&self, envelope: ChannelInboundEnvelope) -> Result<(), ChannelSendError>;
}
#[async_trait]
pub trait ChannelAdapter: Send + Sync {
fn descriptor(&self) -> ChannelDescriptor;
fn receive_ack_policy(&self) -> ChannelReceiveAckPolicy {
ChannelReceiveAckPolicy::AfterReceiveRecord
}
async fn start(
&self,
sink: &(dyn ChannelInboundSink + Send + Sync),
) -> Result<(), ChannelSendError>;
async fn stop(&self) -> Result<(), ChannelSendError>;
async fn send(&self, intent: ChannelOutboundIntent)
-> Result<MessageReceipt, ChannelSendError>;
async fn status(&self) -> Result<ChannelAccountSnapshot, ChannelSendError>;
}
#[async_trait]
pub trait ChannelSetup: Send + Sync {
async fn validate_setup(&self, input: Value) -> Result<Value, ChannelSendError>;
}
#[async_trait]
pub trait ChannelDirectory: Send + Sync {
async fn list_conversations(&self, query: Option<&str>)
-> Result<Vec<Value>, ChannelSendError>;
}
#[async_trait]
pub trait ChannelResolver: Send + Sync {
async fn resolve_target(&self, target: &str) -> Result<Value, ChannelSendError>;
}
#[async_trait]
pub trait ChannelTyping: Send + Sync {
async fn start_typing(&self, conversation_id: &str) -> Result<(), ChannelSendError>;
async fn stop_typing(&self, conversation_id: &str) -> Result<(), ChannelSendError>;
}
#[async_trait]
pub trait ChannelReaction: Send + Sync {
async fn send_reaction(
&self,
conversation_id: &str,
message_id: &str,
reaction: &str,
) -> Result<(), ChannelSendError>;
}
#[async_trait]
pub trait ChannelEdit: Send + Sync {
async fn edit(
&self,
receipt: &MessageReceipt,
intent: ChannelOutboundIntent,
) -> Result<MessageReceipt, ChannelSendError>;
}
#[async_trait]
pub trait ChannelDelete: Send + Sync {
async fn delete(&self, receipt: &MessageReceipt) -> Result<(), ChannelSendError>;
}
#[async_trait]
pub trait ChannelStreamingDraft: Send + Sync {
async fn upsert_draft(
&self,
previous: Option<&MessageReceipt>,
intent: ChannelOutboundIntent,
) -> Result<MessageReceipt, ChannelSendError>;
}