Skip to main content

agent_sdk_store_sqlite/
bundle.rs

1use std::path::{Path, PathBuf};
2
3use crate::{
4    SqliteAgentPoolStore, SqliteCheckpointStore, SqliteContentStore, SqliteEventArchive,
5    SqliteProviderArgumentStore, SqliteRunJournal, SqliteToolExecutionStore,
6};
7
8#[derive(Clone, Debug)]
9/// SQLite-backed store bundle sharing one database path.
10pub struct SqliteStoreBundle {
11    path: PathBuf,
12}
13
14impl SqliteStoreBundle {
15    /// Opens a SQLite store bundle rooted at one database file.
16    pub fn open(path: impl Into<PathBuf>) -> Result<Self, agent_sdk_core::AgentError> {
17        let path = path.into();
18        let bundle = Self { path };
19        let _ = bundle.journal()?;
20        let _ = bundle.checkpoints()?;
21        let _ = bundle.content()?;
22        let _ = bundle.event_archive()?;
23        let _ = bundle.provider_arguments()?;
24        let _ = bundle.tool_execution()?;
25        let _ = bundle.agent_pool()?;
26        Ok(bundle)
27    }
28
29    /// Returns the backing database path.
30    pub fn path(&self) -> &Path {
31        &self.path
32    }
33
34    /// Returns a run journal adapter.
35    pub fn journal(&self) -> Result<SqliteRunJournal, agent_sdk_core::AgentError> {
36        SqliteRunJournal::open(&self.path)
37    }
38
39    /// Returns a checkpoint store adapter.
40    pub fn checkpoints(&self) -> Result<SqliteCheckpointStore, agent_sdk_core::AgentError> {
41        SqliteCheckpointStore::open(&self.path)
42    }
43
44    /// Returns a content store adapter.
45    pub fn content(&self) -> Result<SqliteContentStore, agent_sdk_core::AgentError> {
46        SqliteContentStore::open(&self.path)
47    }
48
49    /// Returns an event archive adapter.
50    pub fn event_archive(&self) -> Result<SqliteEventArchive, agent_sdk_core::AgentError> {
51        SqliteEventArchive::open(&self.path)
52    }
53
54    /// Returns a provider argument store adapter.
55    pub fn provider_arguments(
56        &self,
57    ) -> Result<SqliteProviderArgumentStore, agent_sdk_core::AgentError> {
58        SqliteProviderArgumentStore::open(&self.path)
59    }
60
61    /// Returns an agent-pool store adapter.
62    pub fn agent_pool(&self) -> Result<SqliteAgentPoolStore, agent_sdk_core::AgentError> {
63        SqliteAgentPoolStore::open(&self.path)
64    }
65
66    /// Returns a rebuildable tool-execution projection store adapter.
67    pub fn tool_execution(&self) -> Result<SqliteToolExecutionStore, agent_sdk_core::AgentError> {
68        SqliteToolExecutionStore::open(&self.path)
69    }
70}