use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum OpStatus {
Pending,
Running,
Completed,
Failed,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum VectorMutationOp {
Upserted,
Deleted,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum DakeraEvent {
NamespaceCreated { namespace: String, dimension: usize },
NamespaceDeleted { namespace: String },
OperationProgress {
operation_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
namespace: Option<String>,
op_type: String,
progress: u8,
status: OpStatus,
#[serde(skip_serializing_if = "Option::is_none")]
message: Option<String>,
updated_at: u64,
},
JobProgress {
job_id: String,
job_type: String,
#[serde(skip_serializing_if = "Option::is_none")]
namespace: Option<String>,
progress: u8,
status: String,
},
VectorsMutated {
namespace: String,
op: VectorMutationOp,
count: usize,
},
StreamLagged { dropped: u64, hint: String },
Connected {
timestamp: u64,
},
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryEvent {
#[serde(alias = "type", default)]
pub event_type: String,
#[serde(default)]
pub agent_id: String,
pub timestamp: u64,
#[serde(skip_serializing_if = "Option::is_none")]
pub memory_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub content: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub importance: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub session_id: Option<String>,
}
impl DakeraEvent {
pub fn event_type(&self) -> &'static str {
match self {
DakeraEvent::NamespaceCreated { .. } => "namespace_created",
DakeraEvent::NamespaceDeleted { .. } => "namespace_deleted",
DakeraEvent::OperationProgress { .. } => "operation_progress",
DakeraEvent::JobProgress { .. } => "job_progress",
DakeraEvent::VectorsMutated { .. } => "vectors_mutated",
DakeraEvent::StreamLagged { .. } => "stream_lagged",
DakeraEvent::Connected { .. } => "connected",
}
}
}