Skip to main content

systemprompt_agent/repository/task/
task_messages.rs

1//! Task message-history persistence.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use super::TaskRepository;
7use crate::models::a2a::{Message, Part};
8use crate::repository::context::message::{
9    PersistMessageWithTxParams, get_message_parts, get_messages_by_context, get_messages_by_task,
10    get_next_sequence_number_in_tx, message_exists, persist_message_with_tx,
11};
12use systemprompt_traits::RepositoryError;
13
14impl TaskRepository {
15    pub async fn message_exists(
16        &self,
17        message_id: &systemprompt_identifiers::MessageId,
18    ) -> Result<bool, RepositoryError> {
19        message_exists(&self.pool, message_id).await
20    }
21
22    pub async fn get_messages_by_task(
23        &self,
24        task_id: &systemprompt_identifiers::TaskId,
25    ) -> Result<Vec<Message>, RepositoryError> {
26        get_messages_by_task(&self.pool, task_id).await
27    }
28
29    pub async fn get_message_parts(
30        &self,
31        message_id: &systemprompt_identifiers::MessageId,
32    ) -> Result<Vec<Part>, RepositoryError> {
33        get_message_parts(&self.pool, message_id).await
34    }
35
36    pub async fn get_messages_by_context(
37        &self,
38        context_id: &systemprompt_identifiers::ContextId,
39    ) -> Result<Vec<Message>, RepositoryError> {
40        get_messages_by_context(&self.pool, context_id).await
41    }
42
43    pub async fn get_next_sequence_number_in_tx(
44        &self,
45        tx: &mut dyn systemprompt_database::DatabaseTransaction,
46        task_id: &systemprompt_identifiers::TaskId,
47    ) -> Result<i32, RepositoryError> {
48        get_next_sequence_number_in_tx(tx, task_id).await
49    }
50
51    pub async fn persist_message_with_tx(
52        &self,
53        params: PersistMessageWithTxParams<'_>,
54    ) -> Result<(), RepositoryError> {
55        persist_message_with_tx(params).await
56    }
57}