Skip to main content

systemprompt_agent/services/agents/
agent_entity.rs

1use crate::models::Agent;
2use crate::repository::content::AgentRepository;
3use anyhow::Result;
4use std::sync::Arc;
5use systemprompt_database::DbPool;
6use systemprompt_identifiers::AgentId;
7
8#[derive(Debug)]
9pub struct AgentEntityService {
10    agent_repo: Arc<AgentRepository>,
11}
12
13impl AgentEntityService {
14    pub fn new(db: &DbPool) -> Result<Self> {
15        Ok(Self {
16            agent_repo: Arc::new(AgentRepository::new(db)?),
17        })
18    }
19
20    pub async fn get_agent(&self, agent_id: &AgentId) -> Result<Option<Agent>> {
21        self.agent_repo.get_by_agent_id(agent_id).await
22    }
23
24    pub async fn get_agent_by_name(&self, name: &str) -> Result<Option<Agent>> {
25        self.agent_repo.get_by_name(name).await
26    }
27
28    pub async fn list_agents(&self) -> Result<Vec<Agent>> {
29        self.agent_repo.list_all().await
30    }
31
32    pub async fn list_enabled_agents(&self) -> Result<Vec<Agent>> {
33        self.agent_repo.list_enabled().await
34    }
35
36    pub async fn create_agent(&self, agent: &Agent) -> Result<()> {
37        self.agent_repo.create(agent).await
38    }
39
40    pub async fn update_agent(&self, agent_id: &AgentId, agent: &Agent) -> Result<()> {
41        self.agent_repo.update(agent_id, agent).await
42    }
43
44    pub async fn delete_agent(&self, agent_id: &AgentId) -> Result<()> {
45        self.agent_repo.delete(agent_id).await
46    }
47}