systemprompt_models/audit/
actor.rs1use std::fmt;
2
3use systemprompt_identifiers::UserId;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct Actor {
7 pub user_id: UserId,
8 pub kind: ActorKind,
9}
10
11impl Actor {
12 #[must_use]
13 pub const fn user(user_id: UserId) -> Self {
14 Self {
15 user_id,
16 kind: ActorKind::User,
17 }
18 }
19
20 #[must_use]
21 pub fn job(user_id: UserId, job_name: impl Into<String>) -> Self {
22 Self {
23 user_id,
24 kind: ActorKind::Job {
25 job_name: job_name.into(),
26 },
27 }
28 }
29
30 #[must_use]
31 pub fn mcp(user_id: UserId, server_name: impl Into<String>) -> Self {
32 Self {
33 user_id,
34 kind: ActorKind::Mcp {
35 server_name: server_name.into(),
36 },
37 }
38 }
39}
40
41#[derive(Debug, Clone, PartialEq, Eq)]
42pub enum ActorKind {
43 User,
44 Job { job_name: String },
45 Mcp { server_name: String },
46}
47
48impl ActorKind {
49 #[must_use]
50 pub const fn as_str(&self) -> &'static str {
51 match self {
52 Self::User => "user",
53 Self::Job { .. } => "job",
54 Self::Mcp { .. } => "mcp",
55 }
56 }
57
58 #[must_use]
59 pub fn actor_id<'a>(&'a self, user_id: &'a UserId) -> &'a str {
60 match self {
61 Self::User => user_id.as_str(),
62 Self::Job { job_name } => job_name.as_str(),
63 Self::Mcp { server_name } => server_name.as_str(),
64 }
65 }
66}
67
68impl fmt::Display for ActorKind {
69 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
70 f.write_str(self.as_str())
71 }
72}