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