(self, os: &mut Os, session: &mut ChatSession)
| 138 | |
| 139 | impl AgentSubcommand { |
| 140 | pub async fn execute(self, os: &mut Os, session: &mut ChatSession) -> Result<ChatState, ChatError> { |
| 141 | let agents = &session.conversation.agents; |
| 142 | |
| 143 | macro_rules! _print_err { |
| 144 | ($err:expr) => { |
| 145 | execute!( |
| 146 | session.stderr, |
| 147 | StyledText::error_fg(), |
| 148 | style::Print(format!("\nError: {}\n\n", $err)), |
| 149 | StyledText::reset(), |
| 150 | )? |
| 151 | }; |
| 152 | } |
| 153 | |
| 154 | match self { |
| 155 | Self::List => { |
| 156 | let profiles = agents.agents.values().collect::<Vec<_>>(); |
| 157 | let active_profile = agents.get_active(); |
| 158 | |
| 159 | for (i, profile) in profiles.iter().enumerate() { |
| 160 | if active_profile.is_some_and(|p| p == *profile) { |
| 161 | queue!( |
| 162 | session.stderr, |
| 163 | StyledText::success_fg(), |
| 164 | style::Print("* "), |
| 165 | style::Print(&profile.name), |
| 166 | StyledText::reset(), |
| 167 | )?; |
| 168 | } else { |
| 169 | queue!(session.stderr, style::Print(" "), style::Print(&profile.name),)?; |
| 170 | } |
| 171 | |
| 172 | if i < profiles.len().saturating_sub(1) { |
| 173 | queue!(session.stderr, style::Print("\n"))?; |
| 174 | } |
| 175 | } |
| 176 | execute!(session.stderr, style::Print("\n"))?; |
| 177 | }, |
| 178 | Self::Schema => { |
| 179 | use schemars::schema_for; |
| 180 | |
| 181 | let schema = schema_for!(Agent); |
| 182 | let pretty = serde_json::to_string_pretty(&schema) |
| 183 | .map_err(|e| ChatError::Custom(format!("Failed to convert agent schema to string: {e}").into()))?; |
| 184 | highlight_json(&mut session.stderr, pretty.as_str()) |
| 185 | .map_err(|e| ChatError::Custom(format!("Error printing agent schema: {e}").into()))?; |
| 186 | }, |
| 187 | Self::Create { name, directory, from } => { |
| 188 | let mut agents = Agents::load(os, None, true, &mut session.stderr, session.conversation.mcp_enabled) |
| 189 | .await |
| 190 | .0; |
| 191 | let path_with_file_name = create_agent(os, &mut agents, name.clone(), directory, from) |
| 192 | .await |
| 193 | .map_err(|e| ChatError::Custom(Cow::Owned(e.to_string())))?; |
| 194 | |
| 195 | crate::util::editor::launch_editor(&path_with_file_name) |
| 196 | .map_err(|e| ChatError::Custom(Cow::Owned(e.to_string())))?; |
| 197 |
nothing calls this directly
no test coverage detected