wist-contracts 0.1.4

Versioned contract and schema objects shared by the wist edge and center components
Documentation
//! Agent runtime state contract types.

use serde::{Deserialize, Serialize};

use crate::SCHEMA_VERSION_V1;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct AgentRuntimeState {
    pub schema_version: String,
    pub agent_id: String,
    pub instance_id: String,
    pub version: String,
    #[serde(default)]
    pub credential_id: Option<String>,
    #[serde(default)]
    pub bearer_token: Option<String>,
    #[serde(default)]
    pub credential_expires_at: Option<String>,
    pub mode: RuntimeMode,
    pub updated_at: String,
}

impl AgentRuntimeState {
    pub fn new(
        agent_id: String,
        instance_id: String,
        version: String,
        mode: RuntimeMode,
        updated_at: String,
    ) -> Self {
        Self {
            schema_version: SCHEMA_VERSION_V1.to_string(),
            agent_id,
            instance_id,
            version,
            credential_id: None,
            bearer_token: None,
            credential_expires_at: None,
            mode,
            updated_at,
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum RuntimeMode {
    #[serde(rename = "normal")]
    Normal,
    #[serde(rename = "degraded")]
    Degraded,
    #[serde(rename = "protect")]
    Protect,
    #[serde(rename = "upgrade_in_progress")]
    UpgradeInProgress,
}