kitsune2_api/
local_agent_store.rs

1use crate::agent::DynLocalAgent;
2use crate::{builder, config, id, BoxFut, K2Result};
3use std::sync::Arc;
4
5/// A store for local agents.
6///
7/// These are the agents that are running on the current Kitsune2 instance.
8pub trait LocalAgentStore: 'static + Send + Sync + std::fmt::Debug {
9    /// Add a local agent to the store.
10    fn add(&self, local_agent: DynLocalAgent) -> BoxFut<'_, K2Result<()>>;
11
12    /// Remove a local agent from the store.
13    fn remove(
14        &self,
15        local_agent: id::AgentId,
16    ) -> BoxFut<'_, Option<DynLocalAgent>>;
17
18    /// Get a list of all local agents currently in the store.
19    fn get_all(&self) -> BoxFut<'_, K2Result<Vec<DynLocalAgent>>>;
20}
21
22/// Trait-object version of kitsune2 [LocalAgentStore].
23pub type DynLocalAgentStore = Arc<dyn LocalAgentStore>;
24
25/// A factory for constructing [LocalAgentStore] instances.
26pub trait LocalAgentStoreFactory:
27    'static + Send + Sync + std::fmt::Debug
28{
29    /// Help the builder construct a default config from the chosen
30    /// module factories.
31    fn default_config(&self, config: &mut config::Config) -> K2Result<()>;
32
33    /// Validate configuration.
34    fn validate_config(&self, config: &config::Config) -> K2Result<()>;
35
36    /// Construct a local agent store instance.
37    fn create(
38        &self,
39        builder: Arc<builder::Builder>,
40    ) -> BoxFut<'static, K2Result<DynLocalAgentStore>>;
41}
42
43/// Trait-object [LocalAgentStoreFactory].
44pub type DynLocalAgentStoreFactory = Arc<dyn LocalAgentStoreFactory>;