systemprompt_agent/repository/task/constructor/
mod.rs1mod batch;
9mod batch_builders;
10pub(in crate::repository) mod batch_queries;
11mod converters;
12mod single;
13
14use crate::models::a2a::Task;
15use crate::repository::content::ArtifactRepository;
16use sqlx::PgPool;
17use std::sync::Arc;
18use systemprompt_database::DbPool;
19use systemprompt_identifiers::TaskId;
20use systemprompt_traits::RepositoryError;
21
22#[derive(Debug, Clone)]
23pub struct TaskConstructor {
24 pool: Arc<PgPool>,
25 db_pool: DbPool,
26 artifact_repo: ArtifactRepository,
27}
28
29impl TaskConstructor {
30 pub fn new(db: &DbPool) -> Result<Self, crate::error::AgentError> {
31 let pool = db
32 .pool_arc()
33 .map_err(|e| crate::error::AgentError::Init(e.to_string()))?;
34 let artifact_repo = ArtifactRepository::new(db)?;
35 Ok(Self {
36 pool,
37 db_pool: Arc::clone(db),
38 artifact_repo,
39 })
40 }
41
42 pub(crate) const fn pool(&self) -> &Arc<PgPool> {
43 &self.pool
44 }
45
46 pub(crate) const fn artifact_repo(&self) -> &ArtifactRepository {
47 &self.artifact_repo
48 }
49
50 pub(crate) const fn db_pool(&self) -> &DbPool {
51 &self.db_pool
52 }
53
54 pub async fn construct_task_from_task_id(
55 &self,
56 task_id: &TaskId,
57 ) -> Result<Task, RepositoryError> {
58 single::construct_task_from_task_id(self, task_id).await
59 }
60
61 pub async fn construct_tasks_batch(
62 &self,
63 task_ids: &[TaskId],
64 ) -> Result<Vec<Task>, RepositoryError> {
65 batch::construct_tasks_batch(self, task_ids).await
66 }
67}