1use std::fmt;
4
5use crate::consts::{AGENT0_NAME, AGENTINFINITY_NAME, CLONE_PREFIX};
6
7#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
12pub enum AgentId {
13 Agent0,
15 Clone(u32),
17 Agentinfinity,
19}
20
21impl AgentId {
22 pub fn from_number(n: u32) -> Self {
24 if n == 0 { Self::Agent0 } else { Self::Clone(n) }
25 }
26
27 pub fn name(&self) -> String {
29 match self {
30 Self::Agent0 => AGENT0_NAME.to_string(),
31 Self::Clone(n) => format!("{CLONE_PREFIX}{n}"),
32 Self::Agentinfinity => AGENTINFINITY_NAME.to_string(),
33 }
34 }
35
36 pub fn env_n(&self) -> String {
39 match self {
40 Self::Agent0 => "0".to_string(),
41 Self::Clone(n) => n.to_string(),
42 Self::Agentinfinity => "infinity".to_string(),
43 }
44 }
45
46 pub fn is_agent0(&self) -> bool {
48 matches!(self, Self::Agent0)
49 }
50
51 pub fn is_agentinfinity(&self) -> bool {
53 matches!(self, Self::Agentinfinity)
54 }
55}
56
57impl fmt::Display for AgentId {
58 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
59 f.write_str(&self.name())
60 }
61}
62
63impl netsky_prompts::prompt::PromptAgent for AgentId {
64 fn prompt_agent_kind(self) -> netsky_prompts::prompt::PromptAgentKind {
65 match self {
66 Self::Agent0 => netsky_prompts::prompt::PromptAgentKind::Agent0,
67 Self::Clone(_) => netsky_prompts::prompt::PromptAgentKind::Clone,
68 Self::Agentinfinity => netsky_prompts::prompt::PromptAgentKind::Agentinfinity,
69 }
70 }
71
72 fn prompt_agent_name(self) -> String {
73 self.name()
74 }
75
76 fn prompt_agent_env_n(self) -> String {
77 self.env_n()
78 }
79}
80
81#[cfg(test)]
82mod tests {
83 use super::*;
84
85 #[test]
86 fn name_roundtrip() {
87 assert_eq!(AgentId::Agent0.name(), "agent0");
88 assert_eq!(AgentId::Clone(5).name(), "agent5");
89 assert_eq!(AgentId::Agentinfinity.name(), "agentinfinity");
90 }
91
92 #[test]
93 fn from_number_zero_is_agent0() {
94 assert_eq!(AgentId::from_number(0), AgentId::Agent0);
95 assert_eq!(AgentId::from_number(3), AgentId::Clone(3));
96 }
97
98 #[test]
99 fn env_n_strings() {
100 assert_eq!(AgentId::Agent0.env_n(), "0");
101 assert_eq!(AgentId::Clone(7).env_n(), "7");
102 assert_eq!(AgentId::Agentinfinity.env_n(), "infinity");
103 }
104}