Skip to main content

openbutler_protocol/session/
attach.rs

1//! The `attach` answer: what a client adopts when it joins a session.
2
3use serde::{Deserialize, Serialize};
4
5use crate::runtime::{LocalClientKind, RuntimeViewData};
6use crate::session::{SessionSnapshotData, SessionSummary};
7use crate::util::{de_trio_option, trio_absent};
8
9/// Result of the `attach` request (TS `AttachResult`).
10///
11/// Capability fields double as version negotiation: a newer client reads a
12/// missing `sessionAttachments` or an unexpected `clientKind` echo as "this
13/// host is older" and reports a restart instruction instead of silently
14/// degrading (the TS capability-order rule).
15#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
16#[serde(rename_all = "camelCase")]
17pub struct AttachResult {
18    /// The host's entry script — source tree or built bundle — for the
19    /// vintage check against the client's own entry.
20    #[serde(default, skip_serializing_if = "Option::is_none")]
21    pub host_entry: Option<String>,
22    /// Immutable compiled host identity: `null` for a source run, absent on
23    /// an older host (the distinction is preserved).
24    #[serde(
25        default,
26        deserialize_with = "de_trio_option",
27        skip_serializing_if = "trio_absent"
28    )]
29    pub host_build_id: Option<Option<String>>,
30    /// The host can attach this conversation without replacing another
31    /// controller; `true` whenever present.
32    #[serde(default, skip_serializing_if = "Option::is_none")]
33    pub session_attachments: Option<bool>,
34    /// Host-issued binding key; every later session-bound request echoes it.
35    #[serde(
36        default,
37        skip_serializing_if = "Option::is_none",
38        rename = "bindingKey"
39    )]
40    pub binding_key: Option<String>,
41    /// The client identity the host accepted for this socket.
42    #[serde(
43        default,
44        skip_serializing_if = "Option::is_none",
45        rename = "clientKind"
46    )]
47    pub client_kind: Option<LocalClientKind>,
48    pub snapshot: SessionSnapshotData,
49    pub runtime: RuntimeViewData,
50    pub saved_sessions: Vec<SessionSummary>,
51}