Skip to main content

cccc_sdk/
protocol.rs

1use serde::{Deserialize, Serialize};
2use serde_json::{Map, Value};
3
4use crate::DaemonError;
5
6/// Group-wide current awaiting Mail, evaluated at one observation time.
7#[derive(Clone, Debug, Deserialize)]
8pub struct InboxSummaryResult {
9    pub group_id: String,
10    pub observed_at: String,
11    pub cutoff: String,
12    pub actors: Vec<InboxSummaryActor>,
13}
14
15#[derive(Clone, Debug, Deserialize)]
16pub struct InboxSummaryActor {
17    pub actor_id: String,
18    pub awaiting_count: u64,
19    pub overdue_count: u64,
20    pub oldest_awaiting_at: Option<String>,
21    pub oldest_age_seconds: Option<u64>,
22}
23
24/// Daemon IPC v1 request envelope.
25#[derive(Clone, Debug, Serialize)]
26pub struct DaemonRequest<'a> {
27    pub v: u32,
28    pub op: &'a str,
29    pub args: &'a Map<String, Value>,
30}
31
32/// Daemon IPC v1 response envelope.
33#[derive(Clone, Debug, Deserialize)]
34pub struct DaemonResponse {
35    pub v: u32,
36    pub ok: bool,
37    #[serde(default)]
38    pub result: Map<String, Value>,
39    #[serde(default)]
40    pub error: Option<DaemonError>,
41}
42
43/// Stable fields returned by `ping`; unknown fields remain available through
44/// [`CCCCClient::call`](crate::CCCCClient::call).
45#[derive(Clone, Debug, Deserialize)]
46pub struct PingResult {
47    #[serde(default)]
48    pub version: String,
49    #[serde(default)]
50    pub pid: u64,
51    #[serde(default)]
52    pub ts: String,
53    #[serde(default)]
54    pub ipc_v: u32,
55    #[serde(default)]
56    pub capabilities: Map<String, Value>,
57    pub implementation: String,
58    #[serde(default)]
59    pub compatibility: Option<String>,
60}
61
62/// Delivery policy for a newly stored chat message.
63#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
64#[serde(rename_all = "snake_case")]
65pub enum MessageMode {
66    Send,
67    RequestReply,
68    Mail,
69}
70
71/// Delivery policy for a reply. Replies cannot create another reply obligation.
72#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
73#[serde(rename_all = "snake_case")]
74pub enum ReplyMessageMode {
75    Send,
76    Mail,
77}
78
79impl ReplyMessageMode {
80    pub const fn as_str(self) -> &'static str {
81        match self {
82            Self::Send => "send",
83            Self::Mail => "mail",
84        }
85    }
86}
87
88/// Projection requested from `context_get`.
89#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
90#[serde(rename_all = "snake_case")]
91pub enum ContextDetail {
92    Overview,
93    Summary,
94    Full,
95}
96
97impl ContextDetail {
98    pub const fn as_str(self) -> &'static str {
99        match self {
100            Self::Overview => "overview",
101            Self::Summary => "summary",
102            Self::Full => "full",
103        }
104    }
105}
106
107/// Optional mode filter for non-consuming message history reads.
108#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
109#[serde(rename_all = "snake_case")]
110pub enum MessageHistoryMode {
111    All,
112    Send,
113    RequestReply,
114    Mail,
115}
116
117impl MessageHistoryMode {
118    pub const fn as_str(self) -> &'static str {
119        match self {
120            Self::All => "all",
121            Self::Send => "send",
122            Self::RequestReply => "request_reply",
123            Self::Mail => "mail",
124        }
125    }
126}
127
128impl MessageMode {
129    pub const fn as_str(self) -> &'static str {
130        match self {
131            Self::Send => "send",
132            Self::RequestReply => "request_reply",
133            Self::Mail => "mail",
134        }
135    }
136}
137
138/// Optional arguments for `terminal_history`.
139#[derive(Clone, Debug, Default)]
140pub struct TerminalHistoryOptions {
141    pub render_before: Option<u64>,
142    pub before: Option<u64>,
143    pub limit_bytes: Option<u64>,
144    pub strip_ansi: Option<bool>,
145    pub compact: Option<bool>,
146    pub by: Option<String>,
147}
148
149/// Optional arguments for `terminal_since`.
150#[derive(Clone, Debug, Default)]
151pub struct TerminalSinceOptions {
152    pub limit_bytes: Option<u64>,
153    pub by: Option<String>,
154}
155
156/// Optional arguments for `terminal_snapshot`.
157#[derive(Clone, Debug, Default)]
158pub struct TerminalSnapshotOptions {
159    pub limit_bytes: Option<u64>,
160    pub by: Option<String>,
161}
162
163#[derive(Clone, Debug, Deserialize)]
164pub struct TerminalSnapshotResult {
165    pub data: String,
166    pub start_cursor: u64,
167    pub end_cursor: u64,
168}
169
170#[derive(Clone, Debug, Deserialize)]
171pub struct TerminalHistoryResult {
172    pub group_id: String,
173    pub actor_id: String,
174    pub warning: String,
175    pub hint: String,
176    pub text: String,
177    pub start_cursor: u64,
178    pub end_cursor: u64,
179    pub has_more: bool,
180    pub cursor_expired: bool,
181}
182
183#[derive(Clone, Debug, Deserialize)]
184pub struct TerminalSinceHistory {
185    pub data: String,
186    pub start_cursor: u64,
187    pub end_cursor: u64,
188    pub has_more: bool,
189    pub cursor_expired: bool,
190}
191
192#[derive(Clone, Debug, Deserialize)]
193pub struct TerminalSinceResult {
194    pub history: TerminalSinceHistory,
195}
196
197#[derive(Clone, Debug, Deserialize)]
198pub struct TerminalResizeResult {
199    pub group_id: String,
200    pub actor_id: String,
201    pub cols: u32,
202    pub rows: u32,
203}
204
205#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
206#[serde(rename_all = "snake_case")]
207pub enum WebModelDeliveryMode {
208    Standard,
209    ImageCompat,
210}
211
212#[derive(Clone, Debug, Deserialize)]
213pub struct WebModelDeliveryPreference {
214    pub mode: WebModelDeliveryMode,
215    pub updated_at: String,
216    pub updated_by: String,
217}
218
219#[derive(Clone, Debug, Deserialize)]
220pub struct WebModelDeliveryPreferencesResult {
221    pub group_id: String,
222    pub actor_id: String,
223    pub preference: WebModelDeliveryPreference,
224}
225
226#[derive(Clone, Debug, Deserialize)]
227pub struct WebModelRecoveredTurnDelivery {
228    pub mode: String,
229    pub cursor_committed: bool,
230    pub web_model_mode: WebModelDeliveryMode,
231}
232
233#[derive(Clone, Debug, Deserialize)]
234pub struct WebModelRecoveredTurn {
235    pub turn_id: String,
236    pub group_id: String,
237    pub actor_id: String,
238    pub event_ids: Vec<String>,
239    pub latest_event_id: String,
240    pub latest_ts: String,
241    pub messages: Vec<Value>,
242    pub coalesced_text: String,
243    pub system_prompt: String,
244    pub delivery: WebModelRecoveredTurnDelivery,
245}
246
247#[derive(Clone, Debug, Deserialize)]
248pub struct WebModelRuntimeRecoverTurnResult {
249    pub status: String,
250    pub turn: WebModelRecoveredTurn,
251}