Skip to main content

brainwires_cognition/knowledge/
types.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4// ── capture_thought ──────────────────────────────────────────────────────
5
6/// Request to capture a new thought.
7#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
8pub struct CaptureThoughtRequest {
9    /// The thought text to capture
10    pub content: String,
11    /// Category: decision, person, insight, meeting_note, idea, action_item, reference, general.
12    /// Auto-detected if omitted.
13    #[serde(default)]
14    pub category: Option<String>,
15    /// User-provided tags
16    #[serde(default)]
17    pub tags: Option<Vec<String>>,
18    /// Importance score 0.0–1.0 (default: 0.5)
19    #[serde(default)]
20    pub importance: Option<f32>,
21    /// Source identifier (default: "manual")
22    #[serde(default)]
23    pub source: Option<String>,
24}
25
26/// Response after capturing a thought.
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct CaptureThoughtResponse {
29    /// UUID of the captured thought.
30    pub id: String,
31    /// Detected or specified category.
32    pub category: String,
33    /// Auto-extracted and user-provided tags.
34    pub tags: Vec<String>,
35    /// Importance score.
36    pub importance: f32,
37    /// Number of facts extracted from the thought.
38    pub facts_extracted: usize,
39}
40
41// ── search_memory ────────────────────────────────────────────────────────
42
43/// Request to search memory.
44#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
45pub struct SearchMemoryRequest {
46    /// Natural language search query
47    pub query: String,
48    /// Max results (default: 10)
49    #[serde(default = "default_limit")]
50    pub limit: usize,
51    /// Minimum similarity score (default: 0.6)
52    #[serde(default = "default_min_score")]
53    pub min_score: f32,
54    /// Filter by ThoughtCategory
55    #[serde(default)]
56    pub category: Option<String>,
57    /// Which stores to search: "thoughts", "facts". Default: all.
58    #[serde(default)]
59    pub sources: Option<Vec<String>>,
60}
61
62/// Response from a memory search.
63#[derive(Debug, Clone, Serialize, Deserialize)]
64pub struct SearchMemoryResponse {
65    /// Matching results.
66    pub results: Vec<MemorySearchResult>,
67    /// Total number of results.
68    pub total: usize,
69}
70
71/// A single memory search result.
72#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct MemorySearchResult {
74    /// The matched content text.
75    pub content: String,
76    /// Similarity score.
77    pub score: f32,
78    /// Source store (e.g. "thoughts", "facts").
79    pub source: String,
80    /// Thought UUID if from thoughts store.
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub thought_id: Option<String>,
83    /// Category of the matched item.
84    #[serde(skip_serializing_if = "Option::is_none")]
85    pub category: Option<String>,
86    /// Tags of the matched item.
87    #[serde(skip_serializing_if = "Option::is_none")]
88    pub tags: Option<Vec<String>>,
89    /// Unix timestamp of creation.
90    #[serde(skip_serializing_if = "Option::is_none")]
91    pub created_at: Option<i64>,
92}
93
94// ── list_recent ──────────────────────────────────────────────────────────
95
96/// Request to list recent thoughts.
97#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
98pub struct ListRecentRequest {
99    /// Max results (default: 20)
100    #[serde(default = "default_list_limit")]
101    pub limit: usize,
102    /// Filter by category
103    #[serde(default)]
104    pub category: Option<String>,
105    /// ISO 8601 timestamp (default: 7 days ago)
106    #[serde(default)]
107    pub since: Option<String>,
108}
109
110/// Response from listing recent thoughts.
111#[derive(Debug, Clone, Serialize, Deserialize)]
112pub struct ListRecentResponse {
113    /// Recent thought summaries.
114    pub thoughts: Vec<ThoughtSummary>,
115    /// Total count.
116    pub total: usize,
117}
118
119/// Summary of a thought for listing.
120#[derive(Debug, Clone, Serialize, Deserialize)]
121pub struct ThoughtSummary {
122    /// Thought UUID.
123    pub id: String,
124    /// Content text.
125    pub content: String,
126    /// Category name.
127    pub category: String,
128    /// Tags.
129    pub tags: Vec<String>,
130    /// Importance score.
131    pub importance: f32,
132    /// Unix timestamp of creation.
133    pub created_at: i64,
134}
135
136// ── get_thought ──────────────────────────────────────────────────────────
137
138/// Request to get a single thought by ID.
139#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
140pub struct GetThoughtRequest {
141    /// Thought UUID
142    pub id: String,
143}
144
145/// Response containing a full thought.
146#[derive(Debug, Clone, Serialize, Deserialize)]
147pub struct GetThoughtResponse {
148    /// Thought UUID.
149    pub id: String,
150    /// Content text.
151    pub content: String,
152    /// Category name.
153    pub category: String,
154    /// Tags.
155    pub tags: Vec<String>,
156    /// Source identifier.
157    pub source: String,
158    /// Importance score.
159    pub importance: f32,
160    /// Unix timestamp of creation.
161    pub created_at: i64,
162    /// Unix timestamp of last update.
163    pub updated_at: i64,
164}
165
166// ── search_knowledge ─────────────────────────────────────────────────────
167
168/// Request to search the knowledge store (PKS/BKS).
169#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
170pub struct SearchKnowledgeRequest {
171    /// Context to match against
172    pub query: String,
173    /// "personal" (PKS), "behavioral" (BKS), or "all" (default)
174    #[serde(default)]
175    pub source: Option<String>,
176    /// PKS/BKS category filter
177    #[serde(default)]
178    pub category: Option<String>,
179    /// Minimum confidence (default: 0.5)
180    #[serde(default = "default_min_confidence")]
181    pub min_confidence: f32,
182    /// Max results (default: 10)
183    #[serde(default = "default_limit")]
184    pub limit: usize,
185}
186
187/// Response from a knowledge search.
188#[derive(Debug, Clone, Serialize, Deserialize)]
189pub struct SearchKnowledgeResponse {
190    /// Matching knowledge results.
191    pub results: Vec<KnowledgeResult>,
192    /// Total count.
193    pub total: usize,
194}
195
196/// A single knowledge search result.
197#[derive(Debug, Clone, Serialize, Deserialize)]
198pub struct KnowledgeResult {
199    /// Knowledge source ("personal" or "behavioral").
200    pub source: String,
201    /// Knowledge category.
202    pub category: String,
203    /// Fact/truth key or pattern.
204    pub key: String,
205    /// Fact/truth value or rule.
206    pub value: String,
207    /// Confidence score.
208    pub confidence: f32,
209    /// Optional additional context.
210    #[serde(skip_serializing_if = "Option::is_none")]
211    pub context: Option<String>,
212}
213
214// ── memory_stats ─────────────────────────────────────────────────────────
215
216// No request params needed — but we still define an empty struct for the macro.
217/// Request for memory statistics (no parameters).
218#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
219pub struct MemoryStatsRequest {}
220
221/// Response with memory statistics.
222#[derive(Debug, Clone, Serialize, Deserialize)]
223pub struct MemoryStatsResponse {
224    /// Thought store statistics.
225    pub thoughts: ThoughtStats,
226    /// Personal Knowledge Store statistics.
227    pub pks: PksStats,
228    /// Behavioral Knowledge Store statistics.
229    pub bks: BksStats,
230}
231
232/// Statistics about stored thoughts.
233#[derive(Debug, Clone, Serialize, Deserialize)]
234pub struct ThoughtStats {
235    /// Total number of thoughts.
236    pub total: usize,
237    /// Counts by category.
238    pub by_category: std::collections::HashMap<String, usize>,
239    /// Thoughts created in the last 24 hours.
240    pub recent_24h: usize,
241    /// Thoughts created in the last 7 days.
242    pub recent_7d: usize,
243    /// Thoughts created in the last 30 days.
244    pub recent_30d: usize,
245    /// Most-used tags with counts.
246    pub top_tags: Vec<(String, usize)>,
247}
248
249/// Personal Knowledge Store statistics.
250#[derive(Debug, Clone, Serialize, Deserialize)]
251pub struct PksStats {
252    /// Total number of personal facts.
253    pub total_facts: u32,
254    /// Counts by category.
255    pub by_category: std::collections::HashMap<String, u32>,
256    /// Average confidence score.
257    pub avg_confidence: f32,
258}
259
260/// Behavioral Knowledge Store statistics.
261#[derive(Debug, Clone, Serialize, Deserialize)]
262pub struct BksStats {
263    /// Total number of behavioral truths.
264    pub total_truths: u32,
265    /// Counts by category.
266    pub by_category: std::collections::HashMap<String, u32>,
267}
268
269// ── delete_thought ───────────────────────────────────────────────────────
270
271/// Request to delete a thought.
272#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
273pub struct DeleteThoughtRequest {
274    /// Thought UUID to delete
275    pub id: String,
276}
277
278/// Response after deleting a thought.
279#[derive(Debug, Clone, Serialize, Deserialize)]
280pub struct DeleteThoughtResponse {
281    /// Whether the thought was successfully deleted.
282    pub deleted: bool,
283    /// UUID of the deleted thought.
284    pub id: String,
285}
286
287// ── defaults ─────────────────────────────────────────────────────────────
288
289fn default_limit() -> usize {
290    10
291}
292
293fn default_list_limit() -> usize {
294    20
295}
296
297fn default_min_score() -> f32 {
298    0.6
299}
300
301fn default_min_confidence() -> f32 {
302    0.5
303}