systemprompt_agent/repository/task/constructor/
mod.rs1mod 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 db_pool: DbPool,
18 artifact_repo: ArtifactRepository,
19}
20
21impl TaskConstructor {
22 pub fn new(db_pool: DbPool) -> Self {
23 Self {
24 artifact_repo: ArtifactRepository::new(db_pool.clone()),
25 db_pool,
26 }
27 }
28
29 pub(crate) fn get_pg_pool(&self) -> Result<Arc<PgPool>, RepositoryError> {
30 self.db_pool.as_ref().get_postgres_pool().ok_or_else(|| {
31 RepositoryError::InvalidData("PostgreSQL pool not available".to_string())
32 })
33 }
34
35 pub(crate) const fn artifact_repo(&self) -> &ArtifactRepository {
36 &self.artifact_repo
37 }
38
39 pub(crate) const fn db_pool(&self) -> &DbPool {
40 &self.db_pool
41 }
42
43 pub async fn construct_task_from_task_id(
44 &self,
45 task_id: &TaskId,
46 ) -> Result<Task, RepositoryError> {
47 single::construct_task_from_task_id(self, task_id).await
48 }
49
50 pub async fn construct_tasks_batch(
51 &self,
52 task_ids: &[TaskId],
53 ) -> Result<Vec<Task>, RepositoryError> {
54 batch::construct_tasks_batch(self, task_ids).await
55 }
56}