use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AgentId(pub [u8; 32]);
impl AgentId {
pub fn from_hex(s: &str) -> anyhow::Result<Self> {
let bytes = hex::decode(s)?;
let arr: [u8; 32] = bytes
.try_into()
.map_err(|_| anyhow::anyhow!("AgentId must be 32 bytes"))?;
Ok(Self(arr))
}
pub fn to_hex(&self) -> String {
hex::encode(self.0)
}
}
impl std::fmt::Display for AgentId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.to_hex())
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ConversationId(pub [u8; 16]);
impl ConversationId {
pub fn new_random() -> Self {
Self(*uuid::Uuid::new_v4().as_bytes())
}
pub fn from_hex(s: &str) -> anyhow::Result<Self> {
let bytes = hex::decode(s)?;
let arr: [u8; 16] = bytes
.try_into()
.map_err(|_| anyhow::anyhow!("ConversationId must be 16 bytes"))?;
Ok(Self(arr))
}
pub fn to_hex(&self) -> String {
hex::encode(self.0)
}
}
impl std::fmt::Display for ConversationId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.to_hex())
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct InboundEnvelope {
pub msg_type: String,
pub sender: String,
#[serde(default)]
pub recipient: Option<String>,
pub conversation_id: String,
pub slot: u64,
pub nonce: u64,
pub payload_b64: String,
#[serde(default)]
pub feedback: Option<serde_json::Value>,
}
#[derive(Debug, Serialize)]
pub struct SendEnvelopeRequest {
pub msg_type: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub recipient: Option<String>,
pub conversation_id: String,
pub payload_b64: String,
}
#[derive(Debug, Deserialize)]
pub struct SendEnvelopeResponse {
pub nonce: u64,
pub payload_hash: String,
}
#[derive(Debug, Serialize)]
pub struct HostedSendRequest {
pub msg_type: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub recipient: Option<String>,
pub conversation_id: String,
pub payload_hex: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct ActivityEvent {
pub id: i64,
pub ts: i64,
pub event_type: String,
pub agent_id: String,
#[serde(default)]
pub target_id: Option<String>,
#[serde(default)]
pub score: Option<i64>,
#[serde(default)]
pub name: Option<String>,
#[serde(default)]
pub conversation_id: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct IdentityResponse {
pub agent_id: String,
}