ragrig_gpui/model/
component.rs1use gpui_kit::assets::IconName;
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
7pub enum ComponentKind {
8 Chat,
10 Embedder,
12 Store,
14 Parser,
16 Chunker,
18 Retriever,
20 Vision,
22 References,
24 Other,
26}
27
28impl ComponentKind {
29 pub fn label(self) -> &'static str {
31 match self {
32 Self::Chat => "Chat model",
33 Self::Embedder => "Embedder",
34 Self::Store => "Store",
35 Self::Parser => "Parser",
36 Self::Chunker => "Chunker",
37 Self::Retriever => "Retriever",
38 Self::Vision => "Vision",
39 Self::References => "References",
40 Self::Other => "Component",
41 }
42 }
43
44 pub fn icon(self) -> IconName {
46 match self {
47 Self::Chat => IconName::Bot,
48 Self::Embedder => IconName::Cpu,
49 Self::Store => IconName::Database,
50 Self::Parser => IconName::FileText,
51 Self::Chunker => IconName::Scissors,
52 Self::Retriever => IconName::Search,
53 Self::Vision => IconName::Eye,
54 Self::References => IconName::BookOpen,
55 Self::Other => IconName::Settings,
56 }
57 }
58}
59
60#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
62pub enum ComponentStatus {
63 #[default]
65 Inactive,
66 Ready,
68 Busy,
70 Error,
72}
73
74impl ComponentStatus {
75 pub fn label(self) -> &'static str {
77 match self {
78 Self::Inactive => "inactive",
79 Self::Ready => "ready",
80 Self::Busy => "busy",
81 Self::Error => "error",
82 }
83 }
84
85 pub fn is_busy(self) -> bool {
87 matches!(self, Self::Busy)
88 }
89}
90
91#[derive(Clone, Debug, PartialEq)]
93pub struct AgentComponent {
94 pub id: String,
96 pub kind: ComponentKind,
98 pub label: String,
100 pub status: ComponentStatus,
102 pub detail: Option<String>,
104}
105
106impl AgentComponent {
107 pub fn new(id: impl Into<String>, kind: ComponentKind, label: impl Into<String>) -> Self {
109 Self {
110 id: id.into(),
111 kind,
112 label: label.into(),
113 status: ComponentStatus::default(),
114 detail: None,
115 }
116 }
117
118 pub fn status(mut self, status: ComponentStatus) -> Self {
120 self.status = status;
121 self
122 }
123
124 pub fn detail(mut self, detail: impl Into<String>) -> Self {
126 self.detail = Some(detail.into());
127 self
128 }
129}
130
131#[cfg(test)]
132mod tests {
133 use super::*;
134
135 #[test]
136 fn kinds_have_labels_and_icons() {
137 assert_eq!(ComponentKind::Chat.label(), "Chat model");
138 assert_eq!(ComponentKind::Store.icon(), IconName::Database);
139 assert_eq!(ComponentKind::References.label(), "References");
140 assert_eq!(ComponentKind::References.icon(), IconName::BookOpen);
141 }
142
143 #[test]
144 fn components_default_to_inactive() {
145 let component = AgentComponent::new("chat", ComponentKind::Chat, "DeepSeek");
146 assert_eq!(component.status, ComponentStatus::Inactive);
147 assert!(!component.status.is_busy());
148 }
149}