aegis-runtime-mv
Native Rust agent runtime: Axum WebSocket/SSE/REST gateway, heartbeat scheduler, dependency-aware task workflow, SQLite storage. Attachment of AienOS. Pre-alpha.
Brought by drakestapleton
aegis-runtime-mv / src / orchestration / run.rs
| 1 | use super::budget::RunBudget; |
| 2 | use super::termination::TerminationReason; |
| 3 | use super::trigger::Trigger; |
| 4 | use crate::sessions::id::{RunId, SessionId}; |
| 5 | use chrono::Utc; |
| 6 | use serde::{Deserialize, Serialize}; |
| 7 | |
| 8 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] |
| 9 | #[serde(rename_all = "snake_case")] |
| 10 | pub enum RunState { |
| 11 | Running, |
| 12 | WaitingForApproval, |
| 13 | WaitingForTool, |
| 14 | Completed, |
| 15 | Failed, |
| 16 | Cancelled, |
| 17 | } |
| 18 | |
| 19 | impl RunState { |
| 20 | pub fn as_str(&self) -> &'static str { |
| 21 | match self { |
| 22 | Self::Running => "running", |
| 23 | Self::WaitingForApproval => "waiting_for_approval", |
| 24 | Self::WaitingForTool => "waiting_for_tool", |
| 25 | Self::Completed => "completed", |
| 26 | Self::Failed => "failed", |
| 27 | Self::Cancelled => "cancelled", |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | #[allow(clippy::should_implement_trait)] |
| 32 | pub fn from_str(s: &str) -> Option<Self> { |
| 33 | match s { |
| 34 | "running" => Some(Self::Running), |
| 35 | "waiting_for_approval" => Some(Self::WaitingForApproval), |
| 36 | "waiting_for_tool" => Some(Self::WaitingForTool), |
| 37 | "completed" => Some(Self::Completed), |
| 38 | "failed" => Some(Self::Failed), |
| 39 | "cancelled" => Some(Self::Cancelled), |
| 40 | _ => None, |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 46 | pub struct Run { |
| 47 | pub id: RunId, |
| 48 | pub session_id: SessionId, |
| 49 | pub state: RunState, |
| 50 | pub trigger: Trigger, |
| 51 | pub steps_used: u32, |
| 52 | pub inference_calls_used: u32, |
| 53 | pub actions_used: u32, |
| 54 | pub budget: RunBudget, |
| 55 | pub started_at: i64, |
| 56 | pub completed_at: Option<i64>, |
| 57 | pub termination: Option<TerminationReason>, |
| 58 | } |
| 59 | |
| 60 | impl Run { |
| 61 | pub fn new(session_id: SessionId, trigger: Trigger, budget: RunBudget) -> Self { |
| 62 | Self { |
| 63 | id: RunId::new(), |
| 64 | session_id, |
| 65 | state: RunState::Running, |
| 66 | trigger, |
| 67 | steps_used: 0, |
| 68 | inference_calls_used: 0, |
| 69 | actions_used: 0, |
| 70 | budget, |
| 71 | started_at: Utc::now().timestamp(), |
| 72 | completed_at: None, |
| 73 | termination: None, |
| 74 | } |
| 75 | } |
| 76 | } |