Skip to main content

whycodes_storage/
models.rs

1use serde::{Deserialize, Serialize};
2use whycodes_core::types::Usage;
3
4/// A row from the sessions table.
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct SessionRow {
7    pub id: String,
8    pub title: String,
9    pub created_at: String,
10    pub updated_at: String,
11    pub project_path: String,
12    /// Provider-reported token totals for this session.
13    #[serde(default)]
14    pub usage: Usage,
15}
16
17/// A session whose messages contain every search term.
18#[derive(Debug, Clone)]
19pub struct SessionTextHit {
20    pub session: SessionRow,
21    /// Messages in the session that matched.
22    pub hits: usize,
23    /// Raw stored content (message JSON) of one matching message.
24    pub sample: String,
25}
26
27/// Aggregated usage across all sessions (for `whycodes stats`).
28#[derive(Debug, Clone, Default, Serialize, Deserialize)]
29pub struct UsageTotals {
30    pub session_count: usize,
31    pub message_count: usize,
32    pub usage: Usage,
33}
34
35/// A row from the messages table.
36#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct MessageRow {
38    pub id: String,
39    pub session_id: String,
40    pub role: String,
41    pub content: String,
42    pub tool_call_id: Option<String>,
43    pub name: Option<String>,
44    pub created_at: String,
45}
46
47/// A stored conversation branch: its optional name and every message (the
48/// stored message JSON) from the root to its leaf, in order.
49#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
50pub struct BranchRow {
51    pub name: Option<String>,
52    pub messages: Vec<String>,
53}
54
55/// A row from the state key-value table.
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct StateRow {
58    pub key: String,
59    pub value: String,
60}
61
62/// A row from the memories table (cross-session semantic / auto memory).
63#[derive(Debug, Clone, Serialize, Deserialize)]
64pub struct MemoryRow {
65    pub id: String,
66    /// Bank key: project key, optionally `project::agent`.
67    pub project_key: String,
68    pub text: String,
69    /// Little-endian f32 embedding blob.
70    pub embedding: Vec<u8>,
71    pub source_session: Option<String>,
72    pub created_at: String,
73    pub last_recalled_at: Option<String>,
74    pub recall_count: i64,
75}
76
77/// Indexed source chunk for lightweight code RAG.
78#[derive(Debug, Clone, Serialize, Deserialize)]
79pub struct CodeChunkRow {
80    pub id: String,
81    pub project_key: String,
82    pub path: String,
83    pub start_line: i64,
84    pub end_line: i64,
85    pub text: String,
86    pub embedding: Vec<u8>,
87    pub updated_at: String,
88}
89
90/// Embedded turn excerpt for session RAG.
91#[derive(Debug, Clone, Serialize, Deserialize)]
92pub struct SessionChunkRow {
93    pub id: String,
94    pub project_key: String,
95    pub session_id: String,
96    pub turn_index: i64,
97    pub text: String,
98    pub embedding: Vec<u8>,
99    pub created_at: String,
100}