rmux-proto 0.6.1

RMUX detached IPC protocol DTOs, framing, and wire-safe error types.
Documentation
use serde::{Deserialize, Serialize};

use super::CommandOutput;
use crate::WebShareScope;

/// Response payload for the `web-share` command family.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum WebShareResponse {
    /// A share was created and access URLs are available to the caller.
    Created(WebShareCreatedResponse),
    /// Active shares were listed.
    List(WebShareListResponse),
    /// One share was stopped.
    Stopped(WebShareStoppedResponse),
    /// Every active share was stopped.
    StoppedAll(WebShareStoppedAllResponse),
    /// One active share was looked up without exposing access keys.
    Lookup(WebShareLookupResponse),
    /// Listener configuration was returned.
    Config(WebShareConfigResponse),
}

impl WebShareResponse {
    /// Returns command stdout for CLI-facing web-share responses.
    #[must_use]
    pub fn command_output(&self) -> Option<&CommandOutput> {
        match self {
            Self::Created(response) => Some(&response.output),
            Self::List(response) => Some(&response.output),
            Self::Stopped(response) => Some(&response.output),
            Self::StoppedAll(response) => Some(&response.output),
            Self::Lookup(response) => Some(&response.output),
            Self::Config(response) => Some(&response.output),
        }
    }
}

/// Success payload for creating a browser-visible web share.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct WebShareCreatedResponse {
    /// Opaque share identifier.
    pub share_id: String,
    /// Shared browser scope.
    pub scope: WebShareScope,
    /// Browser URL for spectator access, when requested.
    #[serde(default)]
    pub spectator_url: Option<String>,
    /// Browser URL for operator access, when requested.
    #[serde(default)]
    pub operator_url: Option<String>,
    /// Named tunnel provider used by the daemon, when a tunnel preset was spawned.
    #[serde(default)]
    pub tunnel_provider: Option<String>,
    /// Public tunnel origin used by generated URLs, when available.
    #[serde(default)]
    pub tunnel_public_url: Option<String>,
    /// Expiration timestamp as UNIX seconds, when a TTL was requested.
    #[serde(default)]
    pub expires_at_unix: Option<u64>,
    /// Out-of-band pairing code required by operator clients, when requested.
    #[serde(default)]
    pub operator_pairing_code: Option<String>,
    /// Out-of-band pairing code required by spectator clients, when requested.
    #[serde(default)]
    pub spectator_pairing_code: Option<String>,
    /// Effective cap for concurrent spectator clients, when capped.
    #[serde(default)]
    pub max_spectators: Option<u16>,
    /// Effective cap for concurrent operator clients, when capped.
    #[serde(default)]
    pub max_operators: Option<u16>,
    /// Whether an operator URL was minted.
    pub operator: bool,
    /// Whether a spectator URL was minted.
    pub spectator: bool,
    /// Whether this operator share can execute rmux controls.
    pub controls: bool,
    /// Whether the target session is killed when this share expires.
    pub kill_session_on_expire: bool,
    /// CLI stdout rendering.
    pub output: CommandOutput,
}

/// Success payload for listing active browser-visible web shares.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct WebShareListResponse {
    /// Redacted active share rows.
    pub shares: Vec<WebShareSummary>,
    /// CLI stdout rendering.
    pub output: CommandOutput,
}

/// Success payload for stopping one active web share.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct WebShareStoppedResponse {
    /// Requested share identifier.
    pub share_id: String,
    /// Whether the share existed and was removed.
    pub stopped: bool,
    /// CLI stdout rendering.
    pub output: CommandOutput,
}

/// Success payload for stopping every active pane share.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct WebShareStoppedAllResponse {
    /// Number of removed shares.
    pub stopped: u32,
    /// CLI stdout rendering.
    pub output: CommandOutput,
}

/// Success payload for looking up one active share without exposing keys.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct WebShareLookupResponse {
    /// Redacted share metadata, if the share exists.
    #[serde(default)]
    pub share: Option<WebShareSummary>,
    /// CLI stdout rendering.
    pub output: CommandOutput,
}

/// Success payload for daemon web-share listener configuration.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct WebShareConfigResponse {
    /// Current listener binding.
    pub listener: WebShareListener,
    /// CLI stdout rendering.
    pub output: CommandOutput,
}

/// Redacted metadata for an active browser-visible web share.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct WebShareSummary {
    /// Opaque share identifier.
    pub share_id: String,
    /// Shared browser scope.
    pub scope: WebShareScope,
    /// Redacted spectator URL, when available for display.
    #[serde(default)]
    pub spectator_url: Option<String>,
    /// Whether an operator URL exists for this share.
    pub operator: bool,
    /// Whether a spectator URL exists for this share.
    pub spectator: bool,
    /// Whether this share can execute rmux controls.
    pub controls: bool,
    /// Active spectator clients.
    pub active_spectators: u16,
    /// Active operator clients.
    pub active_operators: u16,
    /// Effective cap for concurrent spectator clients, when capped.
    #[serde(default)]
    pub max_spectators: Option<u16>,
    /// Effective cap for concurrent operator clients, when capped.
    #[serde(default)]
    pub max_operators: Option<u16>,
    /// Expiration timestamp as UNIX seconds, when a TTL was requested.
    #[serde(default)]
    pub expires_at_unix: Option<u64>,
    /// Whether the target session is killed when this share expires.
    #[serde(default)]
    pub kill_session_on_expire: bool,
}

/// Listener metadata for browser-visible pane shares.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct WebShareListener {
    /// Listener host or IP address.
    pub host: String,
    /// Listener TCP port.
    pub port: u16,
    /// Frontend origin used when generating URLs.
    pub frontend_origin: String,
}