Skip to main content

agent_first_http/shared/
profile_snapshot.rs

1//! Canonical profile-state snapshot shared by the SDK and the wire layer.
2
3use std::path::PathBuf;
4
5use serde::{Deserialize, Serialize};
6
7/// Snapshot of the host's active profile, shared by `GET /profile` (full),
8/// `GET /health` (summary without path), and the SDK's `Client::profile_info`.
9///
10/// Fields that are not meaningful for a given endpoint are omitted during
11/// serialization — `path` in the health response, `locked` when false.
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct ProfileSnapshot {
14    pub kind: String,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub name: Option<String>,
17    /// Absolute profile directory on the host filesystem. Present in
18    /// `GET /profile`; absent in `GET /health`.
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub path: Option<PathBuf>,
21    /// Whether the profile lock is held. `false` for ephemeral hosts.
22    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
23    pub locked: bool,
24}
25
26impl ProfileSnapshot {
27    /// `true` when the host is running with `--profile <name>`.
28    #[must_use]
29    pub fn is_persistent(&self) -> bool {
30        self.kind == "persistent"
31    }
32
33    /// Default cookie-jar path for this profile. `None` when `path` is
34    /// absent (e.g. a health-response snapshot with no profile path).
35    #[must_use]
36    pub fn canonical_cookie_jar(&self) -> Option<PathBuf> {
37        self.path.as_ref().map(|p| p.join("cookies.jar.json"))
38    }
39}