Skip to main content

Store

Struct Store 

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

Persistent memory store backed by SQLite.

Implementations§

Source§

impl Store

Source

pub async fn build_context( &self, channel: &str, incoming: &Request, base_system_prompt: &str, needs: &ContextNeeds, active_project: Option<&str>, ) -> Result<Context, KernexError>

Build a conversation context from memory for the provider.

The channel parameter identifies the communication channel since Request is channel-agnostic.

Source§

impl Store

Source

pub async fn find_idle_conversations( &self, ) -> Result<Vec<(String, String, String, String)>, KernexError>

Find active conversations that have been idle beyond the timeout.

Source

pub async fn find_all_active_conversations( &self, ) -> Result<Vec<(String, String, String, String)>, KernexError>

Find all active conversations (for shutdown).

Source

pub async fn get_conversation_messages( &self, conversation_id: &str, ) -> Result<Vec<(String, String)>, KernexError>

Get all messages for a conversation (for summarization).

Source

pub async fn close_conversation( &self, conversation_id: &str, summary: &str, ) -> Result<(), KernexError>

Close a conversation with a summary.

Source

pub async fn close_current_conversation( &self, channel: &str, sender_id: &str, project: &str, ) -> Result<bool, KernexError>

Close the current active conversation for a sender + project.

Source

pub async fn get_recent_summaries( &self, channel: &str, sender_id: &str, limit: i64, ) -> Result<Vec<(String, String)>, KernexError>

Get recent closed conversation summaries for a sender.

Source

pub async fn get_all_recent_summaries( &self, limit: i64, ) -> Result<Vec<(String, String)>, KernexError>

Get recent conversation summaries across all users.

Source

pub async fn get_history( &self, channel: &str, sender_id: &str, limit: i64, ) -> Result<Vec<(String, String)>, KernexError>

Get conversation history (summaries with timestamps) for a sender.

Source

pub async fn get_memory_stats( &self, sender_id: &str, ) -> Result<(i64, i64, i64), KernexError>

Get memory statistics for a sender.

Source§

impl Store

Source

pub async fn store_fact( &self, sender_id: &str, key: &str, value: &str, ) -> Result<(), KernexError>

Store a fact (upsert by sender_id + key).

Source

pub async fn get_fact( &self, sender_id: &str, key: &str, ) -> Result<Option<String>, KernexError>

Get a single fact by sender and key.

Source

pub async fn delete_fact( &self, sender_id: &str, key: &str, ) -> Result<bool, KernexError>

Delete a single fact by sender and key. Returns true if a row was deleted.

Source

pub async fn get_facts( &self, sender_id: &str, ) -> Result<Vec<(String, String)>, KernexError>

Get all facts for a sender.

Source

pub async fn delete_facts( &self, sender_id: &str, key: Option<&str>, ) -> Result<u64, KernexError>

Delete facts for a sender — all facts if key is None, specific fact if key is Some.

Source

pub async fn get_all_facts(&self) -> Result<Vec<(String, String)>, KernexError>

Get all facts across all users.

Source

pub async fn get_all_facts_by_key( &self, key: &str, ) -> Result<Vec<(String, String)>, KernexError>

Get all (sender_id, value) pairs for a given fact key across all users.

Source

pub async fn is_new_user(&self, sender_id: &str) -> Result<bool, KernexError>

Check if a sender has never been welcomed (no welcomed fact).

Source

pub async fn resolve_sender_id( &self, sender_id: &str, ) -> Result<String, KernexError>

Resolve a sender_id to its canonical form via the user_aliases table.

Source

pub async fn create_alias( &self, alias_id: &str, canonical_id: &str, ) -> Result<(), KernexError>

Create an alias mapping: alias_id → canonical_id.

Source

pub async fn find_canonical_user( &self, exclude_sender_id: &str, ) -> Result<Option<String>, KernexError>

Find an existing welcomed user different from sender_id.

Source

pub async fn store_limitation( &self, title: &str, description: &str, proposed_plan: &str, ) -> Result<bool, KernexError>

Store a limitation (deduplicates by title, case-insensitive).

Source

pub async fn get_open_limitations( &self, ) -> Result<Vec<(String, String, String)>, KernexError>

Get all open limitations: (title, description, proposed_plan).

Source§

impl Store

Source

pub async fn store_exchange( &self, channel: &str, incoming: &Request, response: &Response, project: &str, ) -> Result<(), KernexError>

Store a user message and assistant response.

The channel parameter identifies the communication channel (e.g. “api”, “slack”) since Request is channel-agnostic.

Source

pub async fn search_messages( &self, query: &str, exclude_conversation_id: &str, sender_id: &str, limit: i64, ) -> Result<Vec<(String, String, String)>, KernexError>

Search past messages across all conversations using FTS5 full-text search.

Source§

impl Store

Source

pub async fn store_outcome( &self, sender_id: &str, domain: &str, score: i32, lesson: &str, source: &str, project: &str, ) -> Result<(), KernexError>

Store a raw outcome from a REWARD marker.

Source

pub async fn get_recent_outcomes( &self, sender_id: &str, limit: i64, project: Option<&str>, ) -> Result<Vec<(i32, String, String, String)>, KernexError>

Get recent outcomes for a sender.

When project is Some, returns only outcomes for that project. When project is None, returns all outcomes.

Source

pub async fn get_all_recent_outcomes( &self, hours: i64, limit: i64, project: Option<&str>, ) -> Result<Vec<(i32, String, String, String)>, KernexError>

Get recent outcomes across all users.

Source

pub async fn store_lesson( &self, sender_id: &str, domain: &str, rule: &str, project: &str, ) -> Result<(), KernexError>

Store a distilled lesson with content-based deduplication.

Multiple lessons can exist per (sender_id, domain, project). If the exact same rule text already exists, its occurrences counter is bumped instead of creating a duplicate. After insertion, a cap of 10 lessons per (sender_id, domain, project) is enforced — oldest are pruned.

Source

pub async fn get_lessons( &self, sender_id: &str, project: Option<&str>, ) -> Result<Vec<(String, String, String)>, KernexError>

Get lessons for a sender.

When project is Some, returns project-specific lessons first, then general. When project is None, returns general lessons only (project = ‘’).

Source

pub async fn get_all_lessons( &self, project: Option<&str>, ) -> Result<Vec<(String, String, String)>, KernexError>

Get all lessons across all users.

Source§

impl Store

Source

pub async fn store_session( &self, channel: &str, sender_id: &str, project: &str, session_id: &str, ) -> Result<(), KernexError>

Upsert a CLI session for a (channel, sender_id, project) tuple.

Source

pub async fn get_session( &self, channel: &str, sender_id: &str, project: &str, ) -> Result<Option<String>, KernexError>

Look up the CLI session_id for a (channel, sender_id, project) tuple.

Source

pub async fn clear_session( &self, channel: &str, sender_id: &str, project: &str, ) -> Result<(), KernexError>

Delete the CLI session for a specific (channel, sender_id, project).

Source

pub async fn clear_all_sessions_for_sender( &self, sender_id: &str, ) -> Result<(), KernexError>

Delete all CLI sessions for a sender.

Source§

impl Store

Source

pub async fn create_task( &self, channel: &str, sender_id: &str, reply_target: &str, description: &str, due_at: &str, repeat: Option<&str>, task_type: &str, project: &str, ) -> Result<String, KernexError>

Create a scheduled task. Deduplicates on two levels:

  1. Exact match: same sender + description + normalized due_at.
  2. Fuzzy match: same sender + similar description + due_at within 30 min.
Source

pub async fn get_due_tasks(&self) -> Result<Vec<DueTask>, KernexError>

Get tasks that are due for delivery.

Source

pub async fn complete_task( &self, id: &str, repeat: Option<&str>, ) -> Result<(), KernexError>

Complete a task: one-shot tasks become ‘delivered’, recurring tasks advance due_at.

Source

pub async fn fail_task( &self, id: &str, error: &str, max_retries: u32, ) -> Result<bool, KernexError>

Fail an action task: increment retry count and either reschedule or permanently fail.

Returns true if the task will be retried, false if permanently failed.

Source

pub async fn get_tasks_for_sender( &self, sender_id: &str, ) -> Result<Vec<(String, String, String, Option<String>, String, String)>, KernexError>

Get pending tasks for a sender.

Source

pub async fn cancel_task( &self, id_prefix: &str, sender_id: &str, ) -> Result<bool, KernexError>

Cancel a task by ID prefix (must match sender).

Source

pub async fn update_task( &self, id_prefix: &str, sender_id: &str, description: Option<&str>, due_at: Option<&str>, repeat: Option<&str>, ) -> Result<bool, KernexError>

Update fields of a pending task by ID prefix (must match sender).

Source

pub async fn defer_task( &self, id: &str, new_due_at: &str, ) -> Result<(), KernexError>

Defer a pending task to a new due_at time (by exact ID).

Source§

impl Store

Source

pub async fn new(config: &MemoryConfig) -> Result<Self, KernexError>

Create a new store, running migrations on first use.

Source

pub fn pool(&self) -> &SqlitePool

Get a reference to the underlying connection pool.

Source

pub async fn db_size(&self) -> Result<u64, KernexError>

Get the database file size in bytes.

Trait Implementations§

Source§

impl Clone for Store

Source§

fn clone(&self) -> Store

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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