1use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use sqlx::FromRow;
6
7#[derive(Debug, Clone, FromRow, Serialize, Deserialize)]
9pub struct MemoryRow {
10 pub id: i64,
11 pub namespace_id: i64,
12 pub content: String,
13 pub category: String,
14 pub memory_lane_type: Option<String>,
15 pub labels: String, pub metadata: String, pub similarity_score: Option<f32>,
18 pub relevance_score: Option<f32>,
19 pub content_embedding: Option<String>, pub embedding_model: Option<String>,
21 pub created_at: DateTime<Utc>,
22 pub updated_at: Option<DateTime<Utc>>,
23 pub last_accessed: Option<DateTime<Utc>>,
24 pub is_active: bool,
25 pub is_archived: bool,
26 pub access_count: i64,
27}
28
29#[derive(Debug, Clone, FromRow, Serialize, Deserialize)]
31pub struct AgentNamespaceRow {
32 pub id: i64,
33 pub name: String,
34 pub description: Option<String>,
35 pub agent_type: String,
36 pub created_at: DateTime<Utc>,
37 pub updated_at: Option<DateTime<Utc>>,
38}
39
40#[derive(Debug, Clone, FromRow, Serialize, Deserialize)]
42pub struct TaskSpecificationRow {
43 pub id: i64,
44 pub namespace_id: i64,
45 pub spec_id: String,
46 pub task_description: String,
47 pub spec_content: String, pub complexity_score: f32,
49 pub usage_count: i64,
50 pub success_rate: f32,
51 pub created_at: DateTime<Utc>,
52 pub updated_at: Option<DateTime<Utc>>,
53}
54
55#[derive(Debug, Clone, FromRow, Serialize, Deserialize)]
57pub struct MemoryRelationRow {
58 pub id: i64,
59 pub source_memory_id: i64,
60 pub target_memory_id: i64,
61 pub relation_type: String,
62 pub strength: f32,
63 pub metadata: Option<String>, pub created_at: DateTime<Utc>,
65}
66
67#[derive(Debug, Clone, FromRow, Serialize, Deserialize)]
69pub struct SystemMetricRow {
70 pub id: i64,
71 pub metric_name: String,
72 pub metric_value: f64,
73 pub labels: String, pub recorded_at: DateTime<Utc>,
75}
76
77#[derive(Debug, Clone, sqlx::FromRow)]
79pub struct ProcessedFileRow {
80 pub id: i64,
81 pub namespace_id: i64,
82 pub path: String,
83 pub content_hash: Option<String>,
84 pub status: String,
85 pub memory_id: Option<i64>,
86 pub last_error: Option<String>,
87 pub processed_at: Option<chrono::DateTime<chrono::Utc>>,
88 pub created_at: chrono::DateTime<chrono::Utc>,
89 pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
90}
91
92pub mod processed_file_status {
94 pub const PENDING: &str = "pending";
95 pub const PROCESSING: &str = "processing";
96 pub const COMPLETED: &str = "completed";
97 pub const FAILED: &str = "failed";
98}
99
100#[derive(Debug, Clone, sqlx::FromRow)]
106pub struct MemoryJobRow {
107 pub id: i64,
108 pub namespace_id: i64,
109 pub job_type: String,
110 pub status: String,
111 pub priority: i64,
112 pub perspective_json: Option<String>,
113 pub payload_json: String,
114 pub lease_owner: Option<String>,
115 pub claim_token: Option<String>,
116 pub lease_expires_at: Option<String>,
117 pub attempts: i64,
118 pub last_error: Option<String>,
119 pub created_at: String,
120 pub updated_at: String,
121}
122
123#[derive(Debug, Clone, sqlx::FromRow)]
125pub struct SessionDigestRow {
126 pub id: i64,
127 pub namespace_id: i64,
128 pub session_key: String,
129 pub digest_kind: String,
130 pub memory_id: i64,
131 pub start_memory_id: Option<i64>,
132 pub end_memory_id: Option<i64>,
133 pub token_count: i64,
134 pub created_at: String,
135}
136
137#[derive(Debug, Clone, sqlx::FromRow)]
139pub struct MemoryEvidenceRow {
140 pub id: i64,
141 pub derived_memory_id: i64,
142 pub source_memory_id: i64,
143 pub evidence_role: String,
144 pub created_at: String,
145}
146
147pub mod memory_job_status {
149 pub const PENDING: &str = "pending";
150 pub const RUNNING: &str = "running";
151 pub const COMPLETED: &str = "completed";
152 pub const FAILED: &str = "failed";
153}
154
155pub mod evidence_role {
157 pub const SOURCE: &str = "source";
158 pub const DERIVED_FROM: &str = "derived_from";
159 pub const CONTRADICTS: &str = "contradicts";
160 pub const SUPPORTS: &str = "supports";
161}
162
163#[derive(Debug, Clone)]
165pub struct ClaimedMemoryJob {
166 pub row: MemoryJobRow,
167 pub perspective: Option<nexus_core::PerspectiveKey>,
168 pub payload: serde_json::Value,
169}
170
171pub struct EnqueueJobParams<'a> {
173 pub namespace_id: i64,
174 pub job_type: &'a str,
175 pub priority: i64,
176 pub perspective: Option<&'a serde_json::Value>,
177 pub payload: &'a serde_json::Value,
178}
179
180#[derive(Debug, Clone)]
182pub struct MemoryLineageEntry {
183 pub derived_memory_id: i64,
184 pub source_memory_id: i64,
185 pub evidence_role: String,
186}