Skip to main content

Store

Struct Store 

Source
pub struct Store { /* private fields */ }
Expand description

SQLite-backed session store.

Wraps rusqlite::Connection in a Mutex so the store is Send + Sync and can be shared across threads without the caller needing to add their own interior mutability.

The connection is opened in WAL mode with synchronous=NORMAL for significantly better throughput on the agent hot path. Prepared statements are cached across calls.

Implementations§

Source§

impl Store

Source

pub fn open(path: &str) -> Result<Store, String>

Source

pub fn journal_mode(&self) -> Result<String, String>

Returns the current journal_mode PRAGMA value (e.g. “wal”). Primarily used by tests to confirm WAL is active.

Source

pub fn log_tool( &self, session: &str, name: &str, args: &str, result: &str, duration_us: u64, ) -> Result<(), String>

Source

pub fn load(&self, session: &str) -> Result<Vec<Message>, String>

Source

pub fn append(&self, session: &str, msg: &Message) -> Result<(), String>

Append a single message. Uses a single INSERT…SELECT to compute the next idx in one roundtrip instead of a separate SELECT + INSERT.

Source

pub fn append_many( &self, session: &str, messages: &[Message], ) -> Result<(), String>

Append many messages in a single transaction. Reduces fsync cost from 2+N per turn down to 1.

Source

pub fn with_transaction<F, T>(&self, f: F) -> Result<T, String>
where F: FnOnce(&Transaction<'_>) -> Result<T, String>,

Run an arbitrary closure inside a single BEGIN/COMMIT transaction. The closure receives a borrowed rusqlite::Transaction and can issue multiple writes that will all commit together (or roll back on error).

Source

pub fn clear(&self, session: &str) -> Result<(), String>

Source

pub fn stats( &self, session: &str, ) -> Result<Vec<(String, i64, i64, i64)>, String>

Per-tool latency stats for a session: (name, count, avg_us, max_us).

Source

pub fn log_usage( &self, session: &str, message_idx: i64, prompt: u32, completion: u32, ) -> Result<(), String>

Record token usage for a single message in a session.

Source

pub fn usage_total(&self, session: &str) -> Result<(i64, i64, i64), String>

Sum token usage across a session: (prompt_sum, completion_sum, total_sum).

Trait Implementations§

Source§

impl MessageStore for Store

Source§

fn load(&self, session: &str) -> Result<Vec<Message>, StoreError>

Load all messages for a session in insertion order.
Source§

fn append(&self, session: &str, message: &Message) -> Result<(), StoreError>

Append one message to the session log.
Source§

fn log_tool(&self, session: &str, log: &ToolLog<'_>) -> Result<(), StoreError>

Record a tool execution with its args, result, and duration.
Source§

fn clear(&self, session: &str) -> Result<(), StoreError>

Wipe all messages and tool logs for a session.

Auto Trait Implementations§

§

impl !Freeze for Store

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

§

impl UnwindSafe for Store

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more