agentctl-auth 0.1.0

Unified auth pool and LLM API client for Claude Max Plan, OpenAI, and more
Documentation
//! Core credential types.

use serde::{Deserialize, Serialize};

/// A credential in the auth pool.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Credential {
    pub provider: String,
    #[serde(rename = "type")]
    pub cred_type: String,
    #[serde(default)]
    pub token: Option<String>,
    #[serde(default)]
    pub keychain_service: Option<String>,
}

impl Credential {
    /// Get the resolved token value.
    ///
    /// Returns `None` if the credential uses keychain storage (caller must resolve).
    pub fn resolved_token(&self) -> Option<&str> {
        self.token.as_deref()
    }

    /// Whether this credential is an OAuth credential.
    pub fn is_oauth(&self) -> bool {
        self.cred_type == "oauth"
    }
}

/// Usage statistics for a credential.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct UsageStats {
    #[serde(default)]
    pub last_used: Option<u64>,
    #[serde(default)]
    pub error_count: Option<u32>,
    #[serde(default)]
    pub cooldown_until: Option<u64>,
}

/// Result of testing a credential against an API.
#[derive(Debug, Clone, Serialize)]
pub struct TestResult {
    pub credential_name: String,
    pub provider: String,
    pub success: bool,
    pub status_code: Option<u16>,
    pub error: Option<String>,
    pub latency_ms: u64,
}