alpine-protocol-sdk 0.2.4

High-level SDK on top of the ALPINE protocol layer.
Documentation
use std::time::Duration;

use crate::session::{ControlOptions, ControlRetryPolicy, ProbeOptions};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ClientMode {
    Ui,
    Automation,
    Test,
}

impl ClientMode {
    pub fn control_options(self) -> ControlOptions {
        match self {
            ClientMode::Ui => ControlOptions {
                timeout: Some(Duration::from_millis(750)),
                retry: Some(ControlRetryPolicy {
                    max_attempts: 1,
                    backoff_base_ms: 150,
                    backoff_max_ms: 500,
                }),
                allow_dangerous: false,
            },
            ClientMode::Automation => ControlOptions {
                timeout: Some(Duration::from_secs(2)),
                retry: Some(ControlRetryPolicy::default()),
                allow_dangerous: false,
            },
            ClientMode::Test => ControlOptions {
                timeout: Some(Duration::from_secs(1)),
                retry: Some(ControlRetryPolicy {
                    max_attempts: 2,
                    backoff_base_ms: 50,
                    backoff_max_ms: 250,
                }),
                allow_dangerous: true,
            },
        }
    }

    pub fn probe_options(self) -> ProbeOptions {
        ProbeOptions {
            include_health: true,
            control: self.control_options(),
        }
    }

    pub fn log_level_hint(self) -> &'static str {
        match self {
            ClientMode::Ui => "warn",
            ClientMode::Automation => "info",
            ClientMode::Test => "debug",
        }
    }
}