OpenAgentID documentation
Source referencesRust module referencearsenal-core

arsenal-core · session

Declared module signatures, types, configuration, and source documentation.

Source: arsenal/crates/arsenal-core/src/session.rs. SHA-256: f774575cf6008b05bafb52312b9d92083e0dd30d55e00b467702c72c613f17eb.

This source reference follows declared modules and preserves feature attributes. It includes public declarations and implementation methods in those modules. Private-module exports and trait resolution still require the compiler; not every declaration is a crate-root import. Function bodies and constant values are omitted. Source comments describe their implementation context and are not a production deployment claim.

session::SessionId

Session identifier

#[derive(Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(transparent)]
pub struct SessionId(Uuid);

Source line: 20.

session::SessionId::generate

Generate a new session ID

#[must_use]
pub fn generate() -> Self;

Source line: 25.

session::SessionId::from_uuid

Create from an existing UUID

#[must_use]
pub const fn from_uuid(uuid: Uuid) -> Self;

Source line: 31.

session::SessionId::as_uuid

Get the inner UUID

#[must_use]
pub const fn as_uuid(&self) -> &Uuid;

Source line: 37.

session::SessionState

Session state machine states

Represents the lifecycle of an agent session:

  1. AgentBootstrapped - Agent has proven identity
  2. SessionStarted - Session is active
  3. CapabilitiesGranted - Agent has received capabilities
  4. ToolUse - Agent is actively using tools
  5. Renewal - Session/tokens being renewed
  6. Escalation - Privilege escalation requested
  7. SessionEnded - Session terminated
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SessionState {
    /// Agent has completed identity verification
    AgentBootstrapped,
    /// Session has been established
    SessionStarted,
    /// Capabilities have been granted to the agent
    CapabilitiesGranted,
    /// Agent is actively using tools
    ToolUse,
    /// Session or tokens are being renewed
    Renewal,
    /// Privilege escalation is in progress
    Escalation,
    /// Session has ended
    SessionEnded,
}

Source line: 66.

session::SessionState::can_use_tools

Check if this state allows tool usage

#[must_use]
pub const fn can_use_tools(&self) -> bool;

Source line: 86.

session::SessionState::can_request_capabilities

Check if this state allows capability requests

#[must_use]
pub const fn can_request_capabilities(&self) -> bool;

Source line: 92.

session::SessionState::is_terminal

Check if this is a terminal state

#[must_use]
pub const fn is_terminal(&self) -> bool;

Source line: 101.

session::SessionState::is_active

Check if the session is active

#[must_use]
pub const fn is_active(&self) -> bool;

Source line: 107.

session::SessionState::valid_transitions

Get valid transitions from this state

#[must_use]
pub fn valid_transitions(&self) -> &'static [SessionState];

Source line: 113.

session::SessionState::can_transition_to

Check if a transition to the target state is valid

#[must_use]
pub fn can_transition_to(&self, target: SessionState) -> bool;

Source line: 137.

session::SessionEndReason

Reason for session termination

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SessionEndReason {
    /// Normal completion
    Completed,
    /// Explicit logout
    Logout,
    /// Session timeout
    Timeout,
    /// Token expired
    TokenExpired,
    /// Revoked by administrator
    Revoked,
    /// Security violation detected
    SecurityViolation,
    /// Policy violation
    PolicyViolation,
    /// System shutdown
    SystemShutdown,
    /// Error during session
    Error(String),
}

Source line: 160.

session::AgentSession

Agent session - represents an authenticated agent's session

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AgentSession {
/// Unique session identifier

pub id: SessionId,
/// Tenant this session belongs to

pub tenant_id: TenantId,
/// Agent identity

pub agent_id: AgentId,
/// Principal (user/service) that initiated the session

#[serde(skip_serializing_if = "Option::is_none")]
pub principal_id: Option<PrincipalId>,
/// Current state

pub state: SessionState,
/// When the session was created

pub created_at: chrono::DateTime<chrono::Utc>,
/// When the session was last active

pub last_activity_at: chrono::DateTime<chrono::Utc>,
/// When the session expires

pub expires_at: chrono::DateTime<chrono::Utc>,
/// Session metadata

#[serde(default)]
pub metadata: std::collections::HashMap<String, String>,
/// Reason for session end (if ended)

#[serde(skip_serializing_if = "Option::is_none")]
pub end_reason: Option<SessionEndReason>
}

Source line: 199.

session::AgentSession::new

Create a new session

#[must_use]
pub fn new(tenant_id: TenantId, agent_id: AgentId, ttl_seconds: u64) -> Self;

Source line: 248.

session::AgentSession::with_principal

Set the principal ID

#[must_use]
pub fn with_principal(mut self, principal_id: PrincipalId) -> Self;

Source line: 272.

session::AgentSession::transition_to

Transition to a new state

Errors

Returns an error if the transition is invalid

pub fn transition_to(
        &mut self,
        new_state: SessionState,
        reason: Option<String>,
    ) -> ArsenalResult<()>;

Source line: 281.

session::AgentSession::start

Start the session

Errors

Returns an error if the session cannot be started

pub fn start(&mut self) -> ArsenalResult<()>;

Source line: 311.

session::AgentSession::grant_capabilities

Grant capabilities

Errors

Returns an error if capabilities cannot be granted

pub fn grant_capabilities(&mut self, scopes: &ScopeSet) -> ArsenalResult<()>;

Source line: 322.

session::AgentSession::begin_tool_use

Begin tool use

Errors

Returns an error if tool use cannot begin

pub fn begin_tool_use(&mut self) -> ArsenalResult<()>;

Source line: 335.

session::AgentSession::begin_renewal

Begin renewal

Errors

Returns an error if renewal cannot begin

pub fn begin_renewal(&mut self) -> ArsenalResult<()>;

Source line: 343.

session::AgentSession::complete_renewal

Complete renewal

Errors

Returns an error if renewal cannot be completed

pub fn complete_renewal(
        &mut self,
        new_expires_at: chrono::DateTime<chrono::Utc>,
    ) -> ArsenalResult<()>;

Source line: 351.

session::AgentSession::begin_escalation

Begin escalation

Errors

Returns an error if escalation cannot begin

pub fn begin_escalation(&mut self) -> ArsenalResult<()>;

Source line: 367.

session::AgentSession::end

End the session

Errors

Returns an error if the session cannot be ended

pub fn end(&mut self, reason: SessionEndReason) -> ArsenalResult<()>;

Source line: 378.

session::AgentSession::add_token

Add an active token

pub fn add_token(&mut self, token_id: TokenId);

Source line: 388.

session::AgentSession::remove_token

Remove an active token

pub fn remove_token(&mut self, token_id: &TokenId);

Source line: 394.

session::AgentSession::active_tokens

Get active token IDs

#[must_use]
pub fn active_tokens(&self) -> &HashSet<TokenId>;

Source line: 401.

session::AgentSession::granted_scopes

Get granted scopes

#[must_use]
pub fn granted_scopes(&self) -> &ScopeSet;

Source line: 407.

session::AgentSession::is_expired

Check if the session is expired

#[must_use]
pub fn is_expired(&self) -> bool;

Source line: 413.

session::AgentSession::is_active

Check if the session is active

#[must_use]
pub fn is_active(&self) -> bool;

Source line: 419.

session::AgentSession::touch

Update last activity timestamp

pub fn touch(&mut self);

Source line: 424.

session::AgentSession::state_history_len

Get state history

#[must_use]
pub fn state_history_len(&self) -> usize;

Source line: 430.

session::AgentSession::extend

Extend session expiration

pub fn extend(&mut self, additional_seconds: u64);

Source line: 435.

session::AgentSession::set_metadata

Set metadata

pub fn set_metadata(&mut self, key: impl Into<String>, value: impl Into<String>);

Source line: 442.

session::AgentSession::get_metadata

Get metadata

#[must_use]
pub fn get_metadata(&self, key: &str) -> Option<&String>;

Source line: 448.

session::SessionConfig

Session configuration

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SessionConfig {
/// Default session TTL in seconds

pub default_ttl_seconds: u64,
/// Maximum session TTL in seconds

pub max_ttl_seconds: u64,
/// Idle timeout in seconds

pub idle_timeout_seconds: u64,
/// Maximum concurrent sessions per agent

pub max_concurrent_sessions: u32,
/// Allow session extension

pub allow_extension: bool,
/// Maximum extensions allowed

pub max_extensions: u32
}

Source line: 455.

On this page