rapace_cell/
lifecycle.rs

1//! Cell lifecycle protocol
2//!
3//! Standard protocol for cells to signal readiness to the host.
4//! This is automatically handled by `run_with_session` when `--peer-id` is present.
5
6use facet::Facet;
7
8/// Message sent by cell to indicate it's ready to handle RPC requests
9#[derive(Debug, Clone, Facet)]
10pub struct ReadyMsg {
11    /// Authoritative peer ID assigned by host
12    pub peer_id: u16,
13    /// Cell name (e.g. "ddc-cell-markdown", "ddc-cell-http")
14    pub cell_name: String,
15    /// Process ID (optional, for diagnostics)
16    pub pid: Option<u32>,
17    /// Version (optional, e.g. git SHA or crate version)
18    pub version: Option<String>,
19    /// Feature flags (optional; can be empty)
20    pub features: Vec<String>,
21}
22
23/// Acknowledgment sent by host
24#[derive(Debug, Clone, Facet)]
25pub struct ReadyAck {
26    /// Always true unless host rejects
27    pub ok: bool,
28    /// Host time in unix milliseconds (optional; helps debug clock/timing)
29    pub host_time_unix_ms: Option<u64>,
30}
31
32/// Cell lifecycle service implemented by the **host**.
33///
34/// Cells call these methods to signal readiness states.
35#[allow(async_fn_in_trait)]
36#[rapace::service]
37pub trait CellLifecycle {
38    /// Cell calls this after starting its demux loop to signal it's ready for RPC requests
39    ///
40    /// This proves the cell can receive and respond to RPC calls, establishing RPC-readiness.
41    async fn ready(&self, msg: ReadyMsg) -> ReadyAck;
42}