interplane.Get Omega
Read in your language

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

branch main Branches Tags History

aegis-runtime-mv / src / defense / approval.rs

67 lines · 1731 bytes Raw Blame History
1use crate::sessions::id::{ActionId, ApprovalId, RunId, SessionId};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5#[serde(rename_all = "snake_case")]
6pub enum ApprovalStatus {
7 Pending,
8 Approved,
9 Rejected,
10 Expired,
11}
12
13impl ApprovalStatus {
14 pub fn as_str(&self) -> &'static str {
15 match self {
16 Self::Pending => "pending",
17 Self::Approved => "approved",
18 Self::Rejected => "rejected",
19 Self::Expired => "expired",
20 }
21 }
22
23 #[allow(clippy::should_implement_trait)]
24 pub fn from_str(s: &str) -> Option<Self> {
25 match s {
26 "pending" => Some(Self::Pending),
27 "approved" => Some(Self::Approved),
28 "rejected" => Some(Self::Rejected),
29 "expired" => Some(Self::Expired),
30 _ => None,
31 }
32 }
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
36pub struct Approval {
37 pub id: ApprovalId,
38 pub action_id: ActionId,
39 pub run_id: RunId,
40 pub session_id: SessionId,
41 pub prompt: String,
42 pub status: ApprovalStatus,
43 pub requested_at: i64,
44 pub decided_at: Option<i64>,
45 pub decided_by: Option<String>,
46}
47
48impl Approval {
49 pub fn new(
50 action_id: ActionId,
51 run_id: RunId,
52 session_id: SessionId,
53 prompt: impl Into<String>,
54 ) -> Self {
55 Self {
56 id: ApprovalId::new(),
57 action_id,
58 run_id,
59 session_id,
60 prompt: prompt.into(),
61 status: ApprovalStatus::Pending,
62 requested_at: chrono::Utc::now().timestamp(),
63 decided_at: None,
64 decided_by: None,
65 }
66 }
67}