whycodes-storage 0.6.29

SQLite storage for WhyCodes sessions, messages and memories
Documentation
use serde::{Deserialize, Serialize};
use whycodes_core::types::Usage;

/// A row from the sessions table.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SessionRow {
    pub id: String,
    pub title: String,
    pub created_at: String,
    pub updated_at: String,
    pub project_path: String,
    /// Provider-reported token totals for this session.
    #[serde(default)]
    pub usage: Usage,
}

/// A session whose messages contain every search term.
#[derive(Debug, Clone)]
pub struct SessionTextHit {
    pub session: SessionRow,
    /// Messages in the session that matched.
    pub hits: usize,
    /// Raw stored content (message JSON) of one matching message.
    pub sample: String,
}

/// Aggregated usage across all sessions (for `whycodes stats`).
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct UsageTotals {
    pub session_count: usize,
    pub message_count: usize,
    pub usage: Usage,
}

/// A row from the messages table.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MessageRow {
    pub id: String,
    pub session_id: String,
    pub role: String,
    pub content: String,
    pub tool_call_id: Option<String>,
    pub name: Option<String>,
    pub created_at: String,
}

/// A stored conversation branch: its optional name and every message (the
/// stored message JSON) from the root to its leaf, in order.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct BranchRow {
    pub name: Option<String>,
    pub messages: Vec<String>,
}

/// A row from the state key-value table.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StateRow {
    pub key: String,
    pub value: String,
}

/// A row from the memories table (cross-session semantic / auto memory).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryRow {
    pub id: String,
    /// Bank key: project key, optionally `project::agent`.
    pub project_key: String,
    pub text: String,
    /// Little-endian f32 embedding blob.
    pub embedding: Vec<u8>,
    pub source_session: Option<String>,
    pub created_at: String,
    pub last_recalled_at: Option<String>,
    pub recall_count: i64,
}

/// Indexed source chunk for lightweight code RAG.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CodeChunkRow {
    pub id: String,
    pub project_key: String,
    pub path: String,
    pub start_line: i64,
    pub end_line: i64,
    pub text: String,
    pub embedding: Vec<u8>,
    pub updated_at: String,
}

/// Embedded turn excerpt for session RAG.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SessionChunkRow {
    pub id: String,
    pub project_key: String,
    pub session_id: String,
    pub turn_index: i64,
    pub text: String,
    pub embedding: Vec<u8>,
    pub created_at: String,
}