pub struct SqliteStore { /* private fields */ }Expand description
SQLite-backed RunStore. Cheap to clone (wraps a pool).
Implementations§
Source§impl SqliteStore
impl SqliteStore
Sourcepub async fn open(path: impl AsRef<Path>) -> Result<Self, Error>
pub async fn open(path: impl AsRef<Path>) -> Result<Self, Error>
Open (creating if needed) a database file. Uses WAL,
synchronous=NORMAL, foreign keys and a busy timeout, then migrates
and refreshes planner statistics (maintenance::optimize).
Sourcepub async fn open_in_memory() -> Result<Self, Error>
pub async fn open_in_memory() -> Result<Self, Error>
A private in-memory database (one connection, lives as long as the store). Handy for tests.
Sourcepub async fn from_pool(pool: SqlitePool) -> Result<Self, Error>
pub async fn from_pool(pool: SqlitePool) -> Result<Self, Error>
Use an existing pool (its connection options are kept as given) and apply migrations.
pub fn pool(&self) -> &SqlitePool
Sourcepub async fn schema_version(&self) -> Result<i64, Error>
pub async fn schema_version(&self) -> Result<i64, Error>
The schema version recorded in the database.
Sourcepub async fn append(&self, run_id: RunId, event: &Event) -> Result<i64, Error>
pub async fn append(&self, run_id: RunId, event: &Event) -> Result<i64, Error>
Append one event and return its sequence number. The number is computed inside the insert statement, which SQLite runs under the write lock, so concurrent appends to one run never collide or skip.
Sourcepub async fn run_ended(&self, run_id: RunId) -> Result<bool, Error>
pub async fn run_ended(&self, run_id: RunId) -> Result<bool, Error>
Whether the last thing the run journaled was its end. A run that was
resumed and then cut short journals something after its pause. A run
paused for an answer journals finished with an Interrupted status:
that is a pause, not an end, so it is still waiting.
Sourcepub async fn events(&self, run_id: RunId) -> Result<Vec<Event>, Error>
pub async fn events(&self, run_id: RunId) -> Result<Vec<Event>, Error>
The run’s journal in order, decoded.
Sourcepub async fn raw_events(&self, run_id: RunId) -> Result<Vec<StoredEvent>, Error>
pub async fn raw_events(&self, run_id: RunId) -> Result<Vec<StoredEvent>, Error>
The run’s journal in order, as stored.
Sourcepub async fn upsert_state(&self, state: &RunState) -> Result<(), Error>
pub async fn upsert_state(&self, state: &RunState) -> Result<(), Error>
Insert or replace the snapshot for state.run_id.
Sourcepub async fn state(&self, run_id: RunId) -> Result<Option<RunState>, Error>
pub async fn state(&self, run_id: RunId) -> Result<Option<RunState>, Error>
The latest snapshot of one run.
Sourcepub async fn runs_for_session(
&self,
session_id: &str,
) -> Result<Vec<RunState>, Error>
pub async fn runs_for_session( &self, session_id: &str, ) -> Result<Vec<RunState>, Error>
Every run of a session, least recently updated first.
Sourcepub async fn latest_state_for_session(
&self,
session_id: &str,
) -> Result<Option<RunState>, Error>
pub async fn latest_state_for_session( &self, session_id: &str, ) -> Result<Option<RunState>, Error>
The most recently updated run of a session.
Sourcepub async fn interrupted_runs(&self) -> Result<Vec<RunState>, Error>
pub async fn interrupted_runs(&self) -> Result<Vec<RunState>, Error>
Runs paused on an interruption (pending set). Settle each with
Agent::resume. A child run is not listed: it was started by its
parent’s tool call, and an answer reaches it through the parent, whose
state holds it. Resuming its own row would run it behind the parent’s
back and again when the parent resumes.
Sourcepub async fn in_flight_runs(&self) -> Result<Vec<RunState>, Error>
pub async fn in_flight_runs(&self) -> Result<Vec<RunState>, Error>
Runs whose last checkpoint was taken mid tool batch (in_flight
set): the process stopped while tools ran. Continue each with
Agent::run_from, which re-runs idempotent calls and marks the rest
indeterminate.
Sourcepub async fn clock(&self) -> Result<String, Error>
pub async fn clock(&self) -> Result<String, Error>
The store’s clock, in the format its checkpoints are stamped with:
a mark to compare later checkpoints against
(SqliteStore::unfinished_runs_since).
Sourcepub async fn unfinished_runs_since(
&self,
since: &str,
) -> Result<Vec<RunState>, Error>
pub async fn unfinished_runs_since( &self, since: &str, ) -> Result<Vec<RunState>, Error>
Top-level runs that never ended and were last checkpointed at or
after since (a SqliteStore::clock mark), each still the latest
run of its session: the turns a process stop cut off. A run paused
for an answer is listed too; a child run is not (its parent holds it).
Trait Implementations§
Source§impl Clone for SqliteStore
impl Clone for SqliteStore
Source§impl Debug for SqliteStore
impl Debug for SqliteStore
Source§impl RunStore for SqliteStore
impl RunStore for SqliteStore
fn append_event<'life0, 'life1, 'async_trait>(
&'life0 self,
run_id: RunId,
event: &'life1 Event,
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn save_state<'life0, 'life1, 'async_trait>(
&'life0 self,
state: &'life1 RunState,
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn load_state<'life0, 'async_trait>(
&'life0 self,
run_id: RunId,
) -> Pin<Box<dyn Future<Output = Result<Option<RunState>, StoreError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Auto Trait Implementations§
impl !RefUnwindSafe for SqliteStore
impl !UnwindSafe for SqliteStore
impl Forget for SqliteStore
impl Freeze for SqliteStore
impl Move for SqliteStore
impl Send for SqliteStore
impl Sync for SqliteStore
impl Unpin for SqliteStore
impl UnsafeUnpin for SqliteStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more