pub struct Store { /* private fields */ }Expand description
Persistent memory store backed by SQLite.
Implementations§
Source§impl Store
impl Store
Sourcepub async fn build_context(
&self,
channel: &str,
incoming: &Request,
base_system_prompt: &str,
needs: &ContextNeeds,
active_project: Option<&str>,
) -> Result<Context, KernexError>
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
impl Store
Sourcepub async fn find_idle_conversations(
&self,
) -> Result<Vec<(String, String, String, String)>, KernexError>
pub async fn find_idle_conversations( &self, ) -> Result<Vec<(String, String, String, String)>, KernexError>
Find active conversations that have been idle beyond the timeout.
Sourcepub async fn find_all_active_conversations(
&self,
) -> Result<Vec<(String, String, String, String)>, KernexError>
pub async fn find_all_active_conversations( &self, ) -> Result<Vec<(String, String, String, String)>, KernexError>
Find all active conversations (for shutdown).
Sourcepub async fn get_conversation_messages(
&self,
conversation_id: &str,
) -> Result<Vec<(String, String)>, KernexError>
pub async fn get_conversation_messages( &self, conversation_id: &str, ) -> Result<Vec<(String, String)>, KernexError>
Get all messages for a conversation (for summarization).
Sourcepub async fn close_conversation(
&self,
conversation_id: &str,
summary: &str,
) -> Result<(), KernexError>
pub async fn close_conversation( &self, conversation_id: &str, summary: &str, ) -> Result<(), KernexError>
Close a conversation with a summary.
Sourcepub async fn close_current_conversation(
&self,
channel: &str,
sender_id: &str,
project: &str,
) -> Result<bool, KernexError>
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.
Sourcepub async fn get_recent_summaries(
&self,
channel: &str,
sender_id: &str,
limit: i64,
) -> Result<Vec<(String, String)>, KernexError>
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.
Sourcepub async fn get_all_recent_summaries(
&self,
limit: i64,
) -> Result<Vec<(String, String)>, KernexError>
pub async fn get_all_recent_summaries( &self, limit: i64, ) -> Result<Vec<(String, String)>, KernexError>
Get recent conversation summaries across all users.
Sourcepub async fn get_history(
&self,
channel: &str,
sender_id: &str,
limit: i64,
) -> Result<Vec<(String, String)>, KernexError>
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.
Sourcepub async fn get_memory_stats(
&self,
sender_id: &str,
) -> Result<(i64, i64, i64), KernexError>
pub async fn get_memory_stats( &self, sender_id: &str, ) -> Result<(i64, i64, i64), KernexError>
Get memory statistics for a sender.
Source§impl Store
impl Store
Sourcepub async fn store_fact(
&self,
sender_id: &str,
key: &str,
value: &str,
) -> Result<(), KernexError>
pub async fn store_fact( &self, sender_id: &str, key: &str, value: &str, ) -> Result<(), KernexError>
Store a fact (upsert by sender_id + key).
Sourcepub async fn get_fact(
&self,
sender_id: &str,
key: &str,
) -> Result<Option<String>, KernexError>
pub async fn get_fact( &self, sender_id: &str, key: &str, ) -> Result<Option<String>, KernexError>
Get a single fact by sender and key.
Sourcepub async fn delete_fact(
&self,
sender_id: &str,
key: &str,
) -> Result<bool, KernexError>
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.
Sourcepub async fn get_facts(
&self,
sender_id: &str,
) -> Result<Vec<(String, String)>, KernexError>
pub async fn get_facts( &self, sender_id: &str, ) -> Result<Vec<(String, String)>, KernexError>
Get all facts for a sender.
Sourcepub async fn delete_facts(
&self,
sender_id: &str,
key: Option<&str>,
) -> Result<u64, KernexError>
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.
Sourcepub async fn get_all_facts(&self) -> Result<Vec<(String, String)>, KernexError>
pub async fn get_all_facts(&self) -> Result<Vec<(String, String)>, KernexError>
Get all facts across all users.
Sourcepub async fn get_all_facts_by_key(
&self,
key: &str,
) -> Result<Vec<(String, String)>, KernexError>
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.
Sourcepub async fn is_new_user(&self, sender_id: &str) -> Result<bool, KernexError>
pub async fn is_new_user(&self, sender_id: &str) -> Result<bool, KernexError>
Check if a sender has never been welcomed (no welcomed fact).
Sourcepub async fn resolve_sender_id(
&self,
sender_id: &str,
) -> Result<String, KernexError>
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.
Sourcepub async fn create_alias(
&self,
alias_id: &str,
canonical_id: &str,
) -> Result<(), KernexError>
pub async fn create_alias( &self, alias_id: &str, canonical_id: &str, ) -> Result<(), KernexError>
Create an alias mapping: alias_id → canonical_id.
Sourcepub async fn find_canonical_user(
&self,
exclude_sender_id: &str,
) -> Result<Option<String>, KernexError>
pub async fn find_canonical_user( &self, exclude_sender_id: &str, ) -> Result<Option<String>, KernexError>
Find an existing welcomed user different from sender_id.
Sourcepub async fn store_limitation(
&self,
title: &str,
description: &str,
proposed_plan: &str,
) -> Result<bool, KernexError>
pub async fn store_limitation( &self, title: &str, description: &str, proposed_plan: &str, ) -> Result<bool, KernexError>
Store a limitation (deduplicates by title, case-insensitive).
Sourcepub async fn get_open_limitations(
&self,
) -> Result<Vec<(String, String, String)>, KernexError>
pub async fn get_open_limitations( &self, ) -> Result<Vec<(String, String, String)>, KernexError>
Get all open limitations: (title, description, proposed_plan).
Source§impl Store
impl Store
Sourcepub async fn store_exchange(
&self,
channel: &str,
incoming: &Request,
response: &Response,
project: &str,
) -> Result<(), KernexError>
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§impl Store
impl Store
Sourcepub async fn store_outcome(
&self,
sender_id: &str,
domain: &str,
score: i32,
lesson: &str,
source: &str,
project: &str,
) -> Result<(), KernexError>
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.
Sourcepub async fn get_recent_outcomes(
&self,
sender_id: &str,
limit: i64,
project: Option<&str>,
) -> Result<Vec<(i32, String, String, String)>, KernexError>
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.
Sourcepub async fn get_all_recent_outcomes(
&self,
hours: i64,
limit: i64,
project: Option<&str>,
) -> Result<Vec<(i32, String, String, String)>, KernexError>
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.
Sourcepub async fn store_lesson(
&self,
sender_id: &str,
domain: &str,
rule: &str,
project: &str,
) -> Result<(), KernexError>
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.
Sourcepub async fn get_lessons(
&self,
sender_id: &str,
project: Option<&str>,
) -> Result<Vec<(String, String, String)>, KernexError>
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 = ‘’).
Sourcepub async fn get_all_lessons(
&self,
project: Option<&str>,
) -> Result<Vec<(String, String, String)>, KernexError>
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
impl Store
Sourcepub async fn store_session(
&self,
channel: &str,
sender_id: &str,
project: &str,
session_id: &str,
) -> Result<(), KernexError>
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.
Sourcepub async fn get_session(
&self,
channel: &str,
sender_id: &str,
project: &str,
) -> Result<Option<String>, KernexError>
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.
Sourcepub async fn clear_session(
&self,
channel: &str,
sender_id: &str,
project: &str,
) -> Result<(), KernexError>
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).
Sourcepub async fn clear_all_sessions_for_sender(
&self,
sender_id: &str,
) -> Result<(), KernexError>
pub async fn clear_all_sessions_for_sender( &self, sender_id: &str, ) -> Result<(), KernexError>
Delete all CLI sessions for a sender.
Source§impl Store
impl Store
Sourcepub 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>
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:
- Exact match: same sender + description + normalized due_at.
- Fuzzy match: same sender + similar description + due_at within 30 min.
Sourcepub async fn get_due_tasks(&self) -> Result<Vec<DueTask>, KernexError>
pub async fn get_due_tasks(&self) -> Result<Vec<DueTask>, KernexError>
Get tasks that are due for delivery.
Sourcepub async fn complete_task(
&self,
id: &str,
repeat: Option<&str>,
) -> Result<(), KernexError>
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.
Sourcepub async fn fail_task(
&self,
id: &str,
error: &str,
max_retries: u32,
) -> Result<bool, KernexError>
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.
Sourcepub async fn get_tasks_for_sender(
&self,
sender_id: &str,
) -> Result<Vec<(String, String, String, Option<String>, String, String)>, KernexError>
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.
Sourcepub async fn cancel_task(
&self,
id_prefix: &str,
sender_id: &str,
) -> Result<bool, KernexError>
pub async fn cancel_task( &self, id_prefix: &str, sender_id: &str, ) -> Result<bool, KernexError>
Cancel a task by ID prefix (must match sender).
Sourcepub async fn update_task(
&self,
id_prefix: &str,
sender_id: &str,
description: Option<&str>,
due_at: Option<&str>,
repeat: Option<&str>,
) -> Result<bool, KernexError>
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).
Sourcepub async fn defer_task(
&self,
id: &str,
new_due_at: &str,
) -> Result<(), KernexError>
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
impl Store
Sourcepub async fn new(config: &MemoryConfig) -> Result<Self, KernexError>
pub async fn new(config: &MemoryConfig) -> Result<Self, KernexError>
Create a new store, running migrations on first use.
Sourcepub fn pool(&self) -> &SqlitePool
pub fn pool(&self) -> &SqlitePool
Get a reference to the underlying connection pool.
Sourcepub async fn db_size(&self) -> Result<u64, KernexError>
pub async fn db_size(&self) -> Result<u64, KernexError>
Get the database file size in bytes.
Trait Implementations§
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> 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