Skip to main content

systemprompt_agent/
state.rs

1//! Shared `AgentState` handle for the A2A server.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use std::sync::Arc;
7use systemprompt_database::DbPool;
8use systemprompt_models::Config;
9use systemprompt_traits::DynJwtValidationProvider;
10
11use crate::repository::A2ARepositories;
12
13#[derive(Clone)]
14pub struct AgentState {
15    db_pool: DbPool,
16    config: Arc<Config>,
17    jwt_provider: DynJwtValidationProvider,
18    repositories: Arc<A2ARepositories>,
19}
20
21impl AgentState {
22    #[must_use]
23    pub fn new(
24        db_pool: DbPool,
25        config: Arc<Config>,
26        jwt_provider: DynJwtValidationProvider,
27        repositories: Arc<A2ARepositories>,
28    ) -> Self {
29        Self {
30            db_pool,
31            config,
32            jwt_provider,
33            repositories,
34        }
35    }
36
37    #[must_use]
38    pub const fn db_pool(&self) -> &DbPool {
39        &self.db_pool
40    }
41
42    #[must_use]
43    pub fn config(&self) -> &Config {
44        &self.config
45    }
46
47    #[must_use]
48    pub fn jwt_provider(&self) -> &DynJwtValidationProvider {
49        &self.jwt_provider
50    }
51
52    #[must_use]
53    pub const fn repositories(&self) -> &Arc<A2ARepositories> {
54        &self.repositories
55    }
56}
57
58impl std::fmt::Debug for AgentState {
59    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
60        f.debug_struct("AgentState")
61            .field("db_pool", &"<DbPool>")
62            .field("config", &"<Arc<Config>>")
63            .field("jwt_provider", &"<DynJwtValidationProvider>")
64            .field("repositories", &"<A2ARepositories>")
65            .finish()
66    }
67}