Skip to main content

clawdb_client/
models.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5#[serde(rename_all = "snake_case")]
6pub enum MemoryType {
7    Context,
8    Task,
9    ToolOutput,
10    Session,
11    ReasoningTrace,
12    Message,
13    Summary,
14}
15
16impl Default for MemoryType {
17    fn default() -> Self {
18        Self::Context
19    }
20}
21
22impl std::fmt::Display for MemoryType {
23    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24        let s = match self {
25            Self::Context => "context",
26            Self::Task => "task",
27            Self::ToolOutput => "tool_output",
28            Self::Session => "session",
29            Self::ReasoningTrace => "reasoning_trace",
30            Self::Message => "message",
31            Self::Summary => "summary",
32        };
33        f.write_str(s)
34    }
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct MemoryRecord {
39    pub id: String,
40    pub content: String,
41    pub memory_type: String,
42    #[serde(default)]
43    pub tags: Vec<String>,
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
47pub struct SearchHit {
48    pub id: String,
49    pub content: String,
50    pub score: f64,
51    pub memory_type: String,
52    #[serde(default)]
53    pub tags: Vec<String>,
54    pub metadata: Option<serde_json::Value>,
55    pub created_at: Option<DateTime<Utc>>,
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
59pub struct BranchInfo {
60    pub branch_id: String,
61    pub name: String,
62    pub branch_json: Option<String>,
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct MergeResult {
67    pub success: bool,
68    pub applied: u32,
69    pub skipped: u32,
70    pub conflicts: u32,
71    pub duration_ms: u64,
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct DiffResult {
76    pub added: u32,
77    pub removed: u32,
78    pub modified: u32,
79    pub unchanged: u32,
80    pub divergence_score: f64,
81    pub diff_json: Option<String>,
82}
83
84#[derive(Debug, Clone, Serialize, Deserialize)]
85pub struct SyncResult {
86    pub pushed: u32,
87    pub pulled: u32,
88    pub conflicts: u32,
89    pub duration_ms: u64,
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
93pub struct SyncActionResult {
94    pub summary_json: Option<String>,
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize)]
98pub struct SyncStatusResult {
99    pub status_json: Option<String>,
100}
101
102#[derive(Debug, Clone, Serialize, Deserialize)]
103pub struct ReflectJob {
104    pub job_id: String,
105    pub status: String,
106    pub message: Option<String>,
107    pub skipped: bool,
108}
109
110#[derive(Debug, Clone, Serialize, Deserialize)]
111pub struct TxInfo {
112    pub tx_id: String,
113}
114
115#[derive(Debug, Clone, Serialize, Deserialize)]
116pub struct SessionInfo {
117    pub session_id: String,
118    pub role: String,
119    pub scopes: Vec<String>,
120    pub expires_at: Option<DateTime<Utc>>,
121}
122
123#[derive(Debug, Clone, Serialize, Deserialize)]
124pub struct HealthResponse {
125    pub status: String,
126    pub version: Option<String>,
127}
128
129#[derive(Debug, Clone, Default)]
130pub struct RememberOptions {
131    pub memory_type: Option<String>,
132    pub tags: Option<Vec<String>>,
133    pub ttl_days: Option<u32>,
134}
135
136#[derive(Debug, Clone, Default)]
137pub struct SearchOptions {
138    pub top_k: Option<u32>,
139    pub semantic: Option<bool>,
140    pub alpha: Option<f64>,
141    pub filter: Option<serde_json::Value>,
142}