1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, PartialEq, Eq, Hash)]
9pub struct AgentId(pub [u8; 32]);
10
11impl AgentId {
12 pub fn from_hex(s: &str) -> anyhow::Result<Self> {
14 let bytes = hex::decode(s)?;
15 let arr: [u8; 32] = bytes
16 .try_into()
17 .map_err(|_| anyhow::anyhow!("AgentId must be 32 bytes"))?;
18 Ok(Self(arr))
19 }
20
21 pub fn to_hex(&self) -> String {
23 hex::encode(self.0)
24 }
25}
26
27impl std::fmt::Display for AgentId {
28 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29 write!(f, "{}", self.to_hex())
30 }
31}
32
33#[derive(Debug, Clone, PartialEq, Eq, Hash)]
35pub struct ConversationId(pub [u8; 16]);
36
37impl ConversationId {
38 pub fn new_random() -> Self {
40 Self(*uuid::Uuid::new_v4().as_bytes())
41 }
42
43 pub fn from_hex(s: &str) -> anyhow::Result<Self> {
45 let bytes = hex::decode(s)?;
46 let arr: [u8; 16] = bytes
47 .try_into()
48 .map_err(|_| anyhow::anyhow!("ConversationId must be 16 bytes"))?;
49 Ok(Self(arr))
50 }
51
52 pub fn to_hex(&self) -> String {
54 hex::encode(self.0)
55 }
56}
57
58impl std::fmt::Display for ConversationId {
59 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
60 write!(f, "{}", self.to_hex())
61 }
62}
63
64#[derive(Debug, Clone, Deserialize)]
71pub struct InboundEnvelope {
72 pub msg_type: String,
74 pub sender: String,
76 #[serde(default)]
78 pub recipient: Option<String>,
79 pub conversation_id: String,
81 pub slot: u64,
83 pub nonce: u64,
85 pub payload_b64: String,
87 #[serde(default)]
89 pub feedback: Option<serde_json::Value>,
90}
91
92#[derive(Debug, Serialize)]
94pub struct SendEnvelopeRequest {
95 pub msg_type: String,
96 #[serde(skip_serializing_if = "Option::is_none")]
97 pub recipient: Option<String>,
98 pub conversation_id: String,
99 pub payload_b64: String,
100}
101
102#[derive(Debug, Deserialize)]
104pub struct SendEnvelopeResponse {
105 pub nonce: u64,
106 pub payload_hash: String,
107}
108
109#[derive(Debug, Serialize)]
111pub struct HostedSendRequest {
112 pub msg_type: String,
113 #[serde(skip_serializing_if = "Option::is_none")]
114 pub recipient: Option<String>,
115 pub conversation_id: String,
116 pub payload_hex: String,
118}
119
120#[derive(Debug, Clone, Deserialize)]
124pub struct ActivityEvent {
125 pub id: i64,
126 pub ts: i64,
127 pub event_type: String,
129 pub agent_id: String,
131 #[serde(default)]
133 pub target_id: Option<String>,
134 #[serde(default)]
135 pub score: Option<i64>,
136 #[serde(default)]
137 pub name: Option<String>,
138 #[serde(default)]
139 pub conversation_id: Option<String>,
140}
141
142#[derive(Debug, Deserialize)]
144pub struct IdentityResponse {
145 pub agent_id: String,
146}