Skip to main content

systemprompt_agent/repository/task/constructor/
mod.rs

1mod batch;
2mod batch_builders;
3mod batch_queries;
4mod converters;
5mod single;
6
7use crate::models::a2a::Task;
8use crate::repository::content::ArtifactRepository;
9use sqlx::PgPool;
10use std::sync::Arc;
11use systemprompt_database::DbPool;
12use systemprompt_identifiers::TaskId;
13use systemprompt_traits::RepositoryError;
14
15#[derive(Debug, Clone)]
16pub struct TaskConstructor {
17    pool: Arc<PgPool>,
18    db_pool: DbPool,
19    artifact_repo: ArtifactRepository,
20}
21
22impl TaskConstructor {
23    pub fn new(db: &DbPool) -> anyhow::Result<Self> {
24        let pool = db.pool_arc()?;
25        let artifact_repo = ArtifactRepository::new(db)?;
26        Ok(Self {
27            pool,
28            db_pool: db.clone(),
29            artifact_repo,
30        })
31    }
32
33    pub(crate) fn pool(&self) -> &Arc<PgPool> {
34        &self.pool
35    }
36
37    pub(crate) const fn artifact_repo(&self) -> &ArtifactRepository {
38        &self.artifact_repo
39    }
40
41    pub(crate) const fn db_pool(&self) -> &DbPool {
42        &self.db_pool
43    }
44
45    pub async fn construct_task_from_task_id(
46        &self,
47        task_id: &TaskId,
48    ) -> Result<Task, RepositoryError> {
49        single::construct_task_from_task_id(self, task_id).await
50    }
51
52    pub async fn construct_tasks_batch(
53        &self,
54        task_ids: &[TaskId],
55    ) -> Result<Vec<Task>, RepositoryError> {
56        batch::construct_tasks_batch(self, task_ids).await
57    }
58}