aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / crates / cortex-rs / src / models.rs
| 1 | #![allow(dead_code)] |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | // Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | |
| 17 | use serde::{Deserialize, Serialize}; |
| 18 | use serde_json::Value; |
| 19 | |
| 20 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 21 | #[serde(rename_all = "camelCase")] |
| 22 | pub struct CortexEntity { |
| 23 | pub id: String, |
| 24 | pub space_id: String, |
| 25 | pub space_slug: String, |
| 26 | pub entity_type: String, |
| 27 | pub canonical_name: String, |
| 28 | pub content: String, |
| 29 | pub aliases: Vec<String>, |
| 30 | pub metadata: Value, |
| 31 | pub confidence: f64, |
| 32 | pub revision: i64, |
| 33 | pub retracted: bool, |
| 34 | pub valid_from: Option<String>, |
| 35 | pub valid_to: Option<String>, |
| 36 | pub created_at: String, |
| 37 | } |
| 38 | |
| 39 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 40 | #[serde(rename_all = "camelCase")] |
| 41 | pub struct CortexClaim { |
| 42 | pub id: String, |
| 43 | pub space_id: String, |
| 44 | pub space_slug: String, |
| 45 | pub subject_entity_id: String, |
| 46 | pub predicate: String, |
| 47 | pub object_entity_id: Option<String>, |
| 48 | pub literal_value: Option<Value>, |
| 49 | pub confidence: f64, |
| 50 | pub metadata: Value, |
| 51 | pub retracted: bool, |
| 52 | pub created_at: String, |
| 53 | pub verification_tier: VerificationTier, |
| 54 | pub status: ClaimStatus, |
| 55 | pub evidence_count: usize, |
| 56 | } |
| 57 | |
| 58 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 59 | #[serde(rename_all = "camelCase")] |
| 60 | pub struct ReceiptDetails { |
| 61 | pub id: String, |
| 62 | pub operation: String, |
| 63 | pub target_type: String, |
| 64 | pub target_id: String, |
| 65 | pub committed_at: String, |
| 66 | } |
| 67 | |
| 68 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 69 | pub struct CortexReceipt { |
| 70 | pub recorded: bool, |
| 71 | pub receipt: ReceiptDetails, |
| 72 | } |
| 73 | |
| 74 | #[derive(Debug, Clone, Deserialize)] |
| 75 | #[serde(rename_all = "camelCase")] |
| 76 | pub struct EntityWriteInput { |
| 77 | pub id: Option<String>, |
| 78 | #[serde(default = "default_space")] |
| 79 | pub space: String, |
| 80 | #[serde(default = "default_entity_type")] |
| 81 | pub entity_type: String, |
| 82 | pub canonical_name: String, |
| 83 | #[serde(default)] |
| 84 | pub content: String, |
| 85 | #[serde(default)] |
| 86 | pub aliases: Vec<String>, |
| 87 | #[serde(default = "default_json_object")] |
| 88 | pub metadata: Value, |
| 89 | #[serde(default = "default_confidence")] |
| 90 | pub confidence: f64, |
| 91 | pub valid_from: Option<String>, |
| 92 | pub valid_to: Option<String>, |
| 93 | pub external_id: Option<String>, |
| 94 | } |
| 95 | |
| 96 | fn default_space() -> String { |
| 97 | "atlas-memory".to_string() |
| 98 | } |
| 99 | fn default_entity_type() -> String { |
| 100 | "discovery".to_string() |
| 101 | } |
| 102 | fn default_json_object() -> Value { |
| 103 | serde_json::json!({}) |
| 104 | } |
| 105 | fn default_confidence() -> f64 { |
| 106 | 1.0 |
| 107 | } |
| 108 | |
| 109 | #[derive(Debug, Clone, Deserialize)] |
| 110 | #[serde(rename_all = "camelCase")] |
| 111 | pub struct ClaimWriteInput { |
| 112 | pub id: Option<String>, |
| 113 | #[serde(default = "default_space")] |
| 114 | pub space: String, |
| 115 | pub subject_entity_id: String, |
| 116 | pub predicate: String, |
| 117 | pub object_entity_id: Option<String>, |
| 118 | pub literal_value: Option<Value>, |
| 119 | #[serde(default = "default_confidence")] |
| 120 | pub confidence: f64, |
| 121 | #[serde(default = "default_json_object")] |
| 122 | pub metadata: Value, |
| 123 | } |
| 124 | |
| 125 | #[derive(Debug, Clone, Deserialize)] |
| 126 | #[serde(rename_all = "camelCase")] |
| 127 | pub struct RetractInput { |
| 128 | pub target_type: String, |
| 129 | pub target_id: String, |
| 130 | pub reason: Option<String>, |
| 131 | } |
| 132 | |
| 133 | #[derive(Debug, Clone, Deserialize)] |
| 134 | #[serde(tag = "kind")] |
| 135 | pub enum WritePayload { |
| 136 | #[serde(rename = "entity")] |
| 137 | Entity { value: EntityWriteInput }, |
| 138 | #[serde(rename = "claim")] |
| 139 | Claim { value: ClaimWriteInput }, |
| 140 | #[serde(rename = "retract")] |
| 141 | Retract { value: RetractInput }, |
| 142 | } |
| 143 | |
| 144 | #[derive(Debug, Clone, Deserialize)] |
| 145 | pub struct SearchParams { |
| 146 | #[serde(default)] |
| 147 | pub q: Option<String>, |
| 148 | #[serde(default)] |
| 149 | pub query: Option<String>, |
| 150 | pub space: Option<String>, |
| 151 | #[serde(default = "default_search_limit")] |
| 152 | pub limit: Option<usize>, |
| 153 | #[serde(default)] |
| 154 | pub include_retracted: Option<bool>, |
| 155 | } |
| 156 | |
| 157 | fn default_search_limit() -> Option<usize> { |
| 158 | Some(12) |
| 159 | } |
| 160 | |
| 161 | #[derive(Debug, Clone, Serialize)] |
| 162 | #[serde(rename_all = "camelCase")] |
| 163 | pub struct SearchResult { |
| 164 | #[serde(flatten)] |
| 165 | pub entity: CortexEntity, |
| 166 | pub lexical_score: f64, |
| 167 | pub graph_score: f64, |
| 168 | pub semantic_score: f64, |
| 169 | pub score: f64, |
| 170 | } |
| 171 | |
| 172 | #[derive(Debug, Clone, Serialize)] |
| 173 | pub struct SearchResponse { |
| 174 | pub results: Vec<SearchResult>, |
| 175 | pub degraded: Vec<String>, |
| 176 | #[serde(rename = "elapsedMs")] |
| 177 | pub elapsed_ms: f64, |
| 178 | } |
| 179 | |
| 180 | #[derive(Debug, Clone, Deserialize)] |
| 181 | #[serde(rename_all = "camelCase")] |
| 182 | pub struct RecallPayload { |
| 183 | pub query: String, |
| 184 | pub space: Option<String>, |
| 185 | #[serde(default = "default_recall_limit")] |
| 186 | pub limit: usize, |
| 187 | #[serde(default = "default_token_budget")] |
| 188 | pub token_budget: usize, |
| 189 | } |
| 190 | |
| 191 | fn default_recall_limit() -> usize { |
| 192 | 5 |
| 193 | } |
| 194 | fn default_token_budget() -> usize { |
| 195 | 1200 |
| 196 | } |
| 197 | |
| 198 | #[derive(Debug, Clone, Serialize)] |
| 199 | #[serde(rename_all = "camelCase")] |
| 200 | pub struct RecallComponentScores { |
| 201 | pub lexical: f64, |
| 202 | pub semantic: f64, |
| 203 | pub confidence_recency: f64, |
| 204 | pub graph: f64, |
| 205 | } |
| 206 | |
| 207 | #[derive(Debug, Clone, Serialize)] |
| 208 | #[serde(rename_all = "camelCase")] |
| 209 | pub struct RecallItem { |
| 210 | pub entity: CortexEntity, |
| 211 | pub final_score: f64, |
| 212 | pub component_scores: RecallComponentScores, |
| 213 | } |
| 214 | |
| 215 | #[derive(Debug, Clone, Serialize)] |
| 216 | pub struct RecallResponse { |
| 217 | pub results: Vec<RecallItem>, |
| 218 | pub degraded: Vec<String>, |
| 219 | #[serde(rename = "elapsedMs")] |
| 220 | pub elapsed_ms: f64, |
| 221 | } |
| 222 | |
| 223 | #[derive(Debug, Clone, Deserialize)] |
| 224 | #[serde(rename_all = "camelCase")] |
| 225 | pub struct TraversePayload { |
| 226 | pub subject_id: String, |
| 227 | pub space: Option<String>, |
| 228 | } |
| 229 | |
| 230 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 231 | #[serde(rename_all = "camelCase")] |
| 232 | pub struct CortexSession { |
| 233 | pub id: String, |
| 234 | pub space_slug: String, |
| 235 | pub agent_id: Option<String>, |
| 236 | pub world_id: Option<String>, |
| 237 | pub parent_session_id: Option<String>, |
| 238 | pub fork_event_id: Option<String>, |
| 239 | pub created_at: String, |
| 240 | pub closed_at: Option<String>, |
| 241 | pub status: String, |
| 242 | pub retention_class: String, |
| 243 | pub metadata: Value, |
| 244 | } |
| 245 | |
| 246 | #[derive(Debug, Clone, Deserialize)] |
| 247 | #[serde(rename_all = "camelCase")] |
| 248 | pub struct CreateSessionInput { |
| 249 | pub id: Option<String>, |
| 250 | #[serde(default = "default_space")] |
| 251 | pub space: String, |
| 252 | pub agent_id: Option<String>, |
| 253 | pub world_id: Option<String>, |
| 254 | pub parent_session_id: Option<String>, |
| 255 | pub fork_event_id: Option<String>, |
| 256 | #[serde(default = "default_retention_class")] |
| 257 | pub retention_class: String, |
| 258 | #[serde(default = "default_json_object")] |
| 259 | pub metadata: Value, |
| 260 | } |
| 261 | |
| 262 | fn default_retention_class() -> String { |
| 263 | "standard".to_string() |
| 264 | } |
| 265 | |
| 266 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 267 | #[serde(rename_all = "camelCase")] |
| 268 | pub struct CortexSessionEvent { |
| 269 | pub id: String, |
| 270 | pub session_id: String, |
| 271 | pub sequence: i64, |
| 272 | pub branch_id: String, |
| 273 | pub parent_event_id: Option<String>, |
| 274 | pub event_type: String, |
| 275 | pub role: Option<String>, |
| 276 | pub content: Option<String>, |
| 277 | pub payload: Value, |
| 278 | pub created_at: String, |
| 279 | pub content_hash: String, |
| 280 | pub sensitivity: Option<String>, |
| 281 | pub redacted: bool, |
| 282 | pub segment_id: Option<String>, |
| 283 | } |
| 284 | |
| 285 | #[derive(Debug, Clone, Deserialize)] |
| 286 | #[serde(rename_all = "camelCase")] |
| 287 | pub struct SessionEventInput { |
| 288 | pub id: Option<String>, |
| 289 | pub branch_id: Option<String>, |
| 290 | pub parent_event_id: Option<String>, |
| 291 | pub event_type: String, |
| 292 | pub role: Option<String>, |
| 293 | pub content: Option<String>, |
| 294 | #[serde(default = "default_json_object")] |
| 295 | pub payload: Value, |
| 296 | pub sensitivity: Option<String>, |
| 297 | } |
| 298 | |
| 299 | #[derive(Debug, Clone, Deserialize)] |
| 300 | #[serde(rename_all = "camelCase")] |
| 301 | pub struct BatchAppendEventsInput { |
| 302 | #[serde(default = "default_branch_id")] |
| 303 | pub branch_id: String, |
| 304 | pub events: Vec<SessionEventInput>, |
| 305 | } |
| 306 | |
| 307 | fn default_branch_id() -> String { |
| 308 | "main".to_string() |
| 309 | } |
| 310 | |
| 311 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 312 | #[serde(rename_all = "camelCase")] |
| 313 | pub struct ProcessingWatermark { |
| 314 | pub session_id: String, |
| 315 | pub processor_kind: String, |
| 316 | pub processor_version: String, |
| 317 | pub watermark_seq: i64, |
| 318 | pub updated_at: String, |
| 319 | } |
| 320 | |
| 321 | #[derive(Debug, Clone, Deserialize)] |
| 322 | #[serde(rename_all = "camelCase")] |
| 323 | pub struct SetWatermarkInput { |
| 324 | pub processor_kind: String, |
| 325 | pub processor_version: String, |
| 326 | pub watermark_seq: i64, |
| 327 | } |
| 328 | |
| 329 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 330 | #[serde(rename_all = "camelCase")] |
| 331 | pub struct EventSegment { |
| 332 | pub id: String, |
| 333 | pub session_id: String, |
| 334 | pub branch_id: String, |
| 335 | pub start_seq: i64, |
| 336 | pub end_seq: i64, |
| 337 | pub merkle_root: String, |
| 338 | pub prev_segment_root: Option<String>, |
| 339 | pub sealed_at: String, |
| 340 | pub state: String, |
| 341 | } |
| 342 | |
| 343 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 344 | #[serde(rename_all = "camelCase")] |
| 345 | pub struct SessionSummary { |
| 346 | pub id: String, |
| 347 | pub session_id: String, |
| 348 | pub branch_id: String, |
| 349 | pub level: i64, |
| 350 | pub start_seq: i64, |
| 351 | pub end_seq: i64, |
| 352 | pub summary_text: String, |
| 353 | pub source_hash: String, |
| 354 | pub processor_version: String, |
| 355 | pub created_at: String, |
| 356 | } |
| 357 | |
| 358 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] |
| 359 | pub enum VerificationTier { |
| 360 | T0Direct, |
| 361 | T1Corroborated, |
| 362 | T2Verified, |
| 363 | T3Controlled, |
| 364 | } |
| 365 | |
| 366 | impl VerificationTier { |
| 367 | pub fn as_str(&self) -> &'static str { |
| 368 | match self { |
| 369 | Self::T0Direct => "T0Direct", |
| 370 | Self::T1Corroborated => "T1Corroborated", |
| 371 | Self::T2Verified => "T2Verified", |
| 372 | Self::T3Controlled => "T3Controlled", |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | pub fn from_str_opt(s: &str) -> Self { |
| 377 | match s { |
| 378 | "T1Corroborated" => Self::T1Corroborated, |
| 379 | "T2Verified" => Self::T2Verified, |
| 380 | "T3Controlled" => Self::T3Controlled, |
| 381 | _ => Self::T0Direct, |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] |
| 387 | #[serde(rename_all = "snake_case")] |
| 388 | pub enum ClaimStatus { |
| 389 | Active, |
| 390 | Superseded, |
| 391 | Disputed, |
| 392 | Retracted, |
| 393 | Invalidated, |
| 394 | } |
| 395 | |
| 396 | impl ClaimStatus { |
| 397 | pub fn as_str(&self) -> &'static str { |
| 398 | match self { |
| 399 | Self::Active => "active", |
| 400 | Self::Superseded => "superseded", |
| 401 | Self::Disputed => "disputed", |
| 402 | Self::Retracted => "retracted", |
| 403 | Self::Invalidated => "invalidated", |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 409 | #[serde(rename_all = "camelCase")] |
| 410 | pub struct MemoryCandidate { |
| 411 | pub id: String, |
| 412 | pub space_slug: String, |
| 413 | pub session_id: String, |
| 414 | pub branch_id: String, |
| 415 | pub memory_type: String, |
| 416 | pub subject: String, |
| 417 | pub predicate: String, |
| 418 | pub object_value: Value, |
| 419 | pub scope: String, |
| 420 | pub confidence: f64, |
| 421 | pub verification_tier: VerificationTier, |
| 422 | pub state: String, |
| 423 | pub extractor_version: String, |
| 424 | pub created_at: String, |
| 425 | pub evidence_ids: Vec<String>, |
| 426 | } |
| 427 | |
| 428 | #[derive(Debug, Clone, Deserialize)] |
| 429 | #[serde(rename_all = "camelCase")] |
| 430 | pub struct CandidateWriteInput { |
| 431 | pub id: Option<String>, |
| 432 | #[serde(default = "default_space")] |
| 433 | pub space: String, |
| 434 | pub session_id: String, |
| 435 | #[serde(default = "default_branch_id")] |
| 436 | pub branch_id: String, |
| 437 | pub memory_type: String, |
| 438 | pub subject: String, |
| 439 | pub predicate: String, |
| 440 | pub object_value: Value, |
| 441 | #[serde(default = "default_scope")] |
| 442 | pub scope: String, |
| 443 | pub confidence: f64, |
| 444 | pub verification_tier: Option<VerificationTier>, |
| 445 | pub extractor_version: String, |
| 446 | #[serde(default)] |
| 447 | pub evidence_ids: Vec<String>, |
| 448 | } |
| 449 | |
| 450 | fn default_scope() -> String { |
| 451 | "global".to_string() |
| 452 | } |
| 453 | |
| 454 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 455 | #[serde(rename_all = "camelCase")] |
| 456 | pub struct PromotionReceipt { |
| 457 | pub id: String, |
| 458 | pub candidate_id: String, |
| 459 | pub claim_id: String, |
| 460 | pub policy_id: String, |
| 461 | pub policy_version: String, |
| 462 | pub achieved_tier: String, |
| 463 | pub verifier_receipt: Option<String>, |
| 464 | pub promoted_at: String, |
| 465 | } |
| 466 | |
| 467 | #[derive(Debug, Clone, Deserialize)] |
| 468 | #[serde(rename_all = "camelCase")] |
| 469 | pub struct PromoteCandidateInput { |
| 470 | pub candidate_id: String, |
| 471 | pub policy_id: Option<String>, |
| 472 | pub verifier_receipt: Option<String>, |
| 473 | } |