Skip to main content

systemprompt_agent/repository/context/
mod.rs

1//! Repository for conversational contexts (multi-turn dialogue state).
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6pub mod message;
7mod mutations;
8pub mod notifications;
9mod queries;
10
11pub use notifications::ContextNotificationRepository;
12
13use sqlx::PgPool;
14use std::sync::Arc;
15use systemprompt_database::DbPool;
16
17use crate::error::AgentError;
18
19#[derive(Debug, Clone)]
20pub struct ContextRepository {
21    pool: Arc<PgPool>,
22    write_pool: Arc<PgPool>,
23    db_pool: DbPool,
24}
25
26impl ContextRepository {
27    pub fn new(db: &DbPool) -> Result<Self, AgentError> {
28        let pool = db.pool_arc().map_err(|e| AgentError::Init(e.to_string()))?;
29        let write_pool = db
30            .write_pool_arc()
31            .map_err(|e| AgentError::Init(e.to_string()))?;
32        Ok(Self {
33            pool,
34            write_pool,
35            db_pool: Arc::clone(db),
36        })
37    }
38}