use std::collections::HashMap;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SuggestedNextCall {
#[serde(default)]
pub tool: String,
#[serde(default)]
pub args: HashMap<String, serde_json::Value>,
#[serde(default)]
pub reason: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolMeta {
#[serde(default)]
pub schema_version: String,
#[serde(default)]
pub request_id: Option<String>,
#[serde(default)]
pub latency_ms: Option<i64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryRecord {
#[serde(rename = "memory_id")]
pub id: String,
pub content: String,
pub category: String,
#[serde(default)]
pub title: Option<String>,
#[serde(default)]
pub anchors: Vec<String>,
#[serde(default)]
pub importance: f64,
#[serde(default)]
pub created_at: Option<String>,
#[serde(default)]
pub updated_at: Option<String>,
#[serde(default, rename = "final_score")]
pub score: Option<f64>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SaveResult {
pub memory_id: String,
#[serde(default)]
pub anchors: Vec<String>,
#[serde(default)]
pub status: String,
#[serde(default)]
pub hints: Vec<String>,
#[serde(default)]
pub auto_fired: Vec<String>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SearchResult {
pub memories: Vec<MemoryRecord>,
#[serde(default)]
pub total_found: usize,
#[serde(default)]
pub familiarity: f64,
#[serde(default)]
pub hints: Vec<String>,
#[serde(default)]
pub auto_fired: Vec<String>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
}
pub struct SaveBuilder<'a> {
pub(crate) client: &'a crate::client::Memory,
pub(crate) content: String,
pub(crate) category: String,
pub(crate) title: Option<String>,
pub(crate) anchors: Option<Vec<String>>,
pub(crate) importance: Option<f64>,
pub(crate) memory_type: Option<String>,
}
impl<'a> SaveBuilder<'a> {
pub fn title(mut self, title: &str) -> Self {
self.title = Some(title.to_string());
self
}
pub fn anchors(mut self, anchors: Vec<&str>) -> Self {
self.anchors = Some(anchors.into_iter().map(String::from).collect());
self
}
pub fn importance(mut self, importance: f64) -> Self {
self.importance = Some(importance);
self
}
pub fn memory_type(mut self, memory_type: &str) -> Self {
self.memory_type = Some(memory_type.to_string());
self
}
pub async fn send(self) -> Result<SaveResult, crate::Error> {
self.client.execute_save(self).await
}
}
pub struct SearchBuilder<'a> {
pub(crate) client: &'a crate::client::Memory,
pub(crate) query: String,
pub(crate) limit: Option<u32>,
pub(crate) hint_anchors: Option<Vec<String>>,
pub(crate) time_range: Option<String>,
pub(crate) types: Option<Vec<String>>,
}
impl<'a> SearchBuilder<'a> {
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
pub fn hint_anchors(mut self, anchors: Vec<&str>) -> Self {
self.hint_anchors = Some(anchors.into_iter().map(String::from).collect());
self
}
pub fn time_range(mut self, range: &str) -> Self {
self.time_range = Some(range.to_string());
self
}
pub async fn send(self) -> Result<SearchResult, crate::Error> {
self.client.execute_search(self).await
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WrapUpResult {
#[serde(default)]
pub handoff_id: String,
#[serde(default)]
pub session_id: String,
#[serde(default)]
pub anchors: Vec<String>,
#[serde(default)]
pub summary: String,
#[serde(default)]
pub saves_persisted: i64,
#[serde(default)]
pub reflections_persisted: i64,
#[serde(default)]
pub next_action_hint: String,
#[serde(default)]
pub narrative: String,
#[serde(default)]
pub suggested_next_call: Option<SuggestedNextCall>,
#[serde(default)]
pub meta: Option<ToolMeta>,
#[serde(default)]
pub hints: Vec<String>,
#[serde(default)]
pub auto_fired: Vec<String>,
#[serde(flatten)]
pub extra: HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WrapUpMemory {
pub category: String,
pub content: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub anchors: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub importance: Option<f64>,
}
pub struct WrapUpBuilder<'a> {
pub(crate) client: &'a crate::client::Memory,
pub(crate) what_we_built: String,
pub(crate) whats_next: String,
pub(crate) diary: Option<String>,
pub(crate) anchors: Option<Vec<String>>,
pub(crate) energy: Option<String>,
pub(crate) memories: Option<Vec<WrapUpMemory>>,
}
impl<'a> WrapUpBuilder<'a> {
pub fn diary(mut self, diary: &str) -> Self {
self.diary = Some(diary.to_string());
self
}
pub fn anchors(mut self, anchors: Vec<&str>) -> Self {
self.anchors = Some(anchors.into_iter().map(String::from).collect());
self
}
pub fn energy(mut self, energy: &str) -> Self {
self.energy = Some(energy.to_string());
self
}
pub fn memories(mut self, memories: Vec<WrapUpMemory>) -> Self {
self.memories = Some(memories);
self
}
pub async fn send(self) -> Result<WrapUpResult, crate::Error> {
self.client.execute_wrap_up(self).await
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IdentityCore {
#[serde(default)]
pub name: String,
#[serde(default)]
pub instance_id: String,
#[serde(default)]
pub origin_statement: String,
#[serde(default)]
pub persona_summary: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FoundationMemoryItem {
pub id: String,
#[serde(default)]
pub title: Option<String>,
#[serde(default)]
pub snippet: String,
#[serde(default)]
pub anchors: Vec<String>,
#[serde(default)]
pub captured_at: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RestoreIdentityResult {
#[serde(default = "default_identity_core")]
pub identity: IdentityCore,
#[serde(default)]
pub ethos: Vec<String>,
#[serde(default)]
pub foundation_memories: Vec<FoundationMemoryItem>,
#[serde(default)]
pub topology: HashMap<String, serde_json::Value>,
#[serde(default)]
pub continuity: HashMap<String, serde_json::Value>,
#[serde(default)]
pub needs_onboarding: bool,
#[serde(default)]
pub memory_guide: Option<String>,
#[serde(default)]
pub narrative: String,
#[serde(default)]
pub suggested_next_call: Option<SuggestedNextCall>,
#[serde(default)]
pub meta: Option<ToolMeta>,
#[serde(default)]
pub hints: Vec<String>,
#[serde(default)]
pub auto_fired: Vec<String>,
#[serde(flatten)]
pub extra: HashMap<String, serde_json::Value>,
}
fn default_identity_core() -> IdentityCore {
IdentityCore {
name: String::new(),
instance_id: String::new(),
origin_statement: String::new(),
persona_summary: None,
}
}
pub struct RestoreIdentityBuilder<'a> {
pub(crate) client: &'a crate::client::Memory,
pub(crate) detail_level: Option<String>,
pub(crate) include_guide: Option<bool>,
pub(crate) limit: Option<u32>,
}
impl<'a> RestoreIdentityBuilder<'a> {
pub fn detail_level(mut self, level: &str) -> Self {
self.detail_level = Some(level.to_string());
self
}
pub fn include_guide(mut self, include: bool) -> Self {
self.include_guide = Some(include);
self
}
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
pub async fn send(self) -> Result<RestoreIdentityResult, crate::Error> {
self.client.execute_restore_identity(self).await
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HandoffSummary {
pub id: String,
#[serde(default)]
pub summary: String,
#[serde(default)]
pub anchors: Vec<String>,
#[serde(default)]
pub captured_at: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RelatedMemoryItem {
pub id: String,
#[serde(default)]
pub title: Option<String>,
#[serde(default)]
pub snippet: String,
#[serde(default)]
pub anchors: Vec<String>,
#[serde(default)]
pub relevance_tier: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LoadContextResult {
#[serde(default)]
pub session_id: String,
#[serde(default)]
pub anchors: Vec<String>,
#[serde(default)]
pub handoff: Option<HandoffSummary>,
#[serde(default)]
pub related_memories: Vec<RelatedMemoryItem>,
#[serde(default)]
pub skills: Vec<String>,
#[serde(default)]
pub topology: HashMap<String, serde_json::Value>,
#[serde(default)]
pub narrative: String,
#[serde(default)]
pub suggested_next_call: Option<SuggestedNextCall>,
#[serde(default)]
pub meta: Option<ToolMeta>,
#[serde(default)]
pub hints: Vec<String>,
#[serde(default)]
pub auto_fired: Vec<String>,
#[serde(flatten)]
pub extra: HashMap<String, serde_json::Value>,
}
pub struct LoadContextBuilder<'a> {
pub(crate) client: &'a crate::client::Memory,
pub(crate) anchors: Option<Vec<String>>,
pub(crate) mode: Option<String>,
pub(crate) specialization_name: Option<String>,
pub(crate) detail_level: Option<String>,
pub(crate) load_priority: Option<String>,
}
impl<'a> LoadContextBuilder<'a> {
pub fn anchors(mut self, anchors: Vec<&str>) -> Self {
self.anchors = Some(anchors.into_iter().map(String::from).collect());
self
}
pub fn detail_level(mut self, level: &str) -> Self {
self.detail_level = Some(level.to_string());
self
}
pub fn load_priority(mut self, priority: &str) -> Self {
self.load_priority = Some(priority.to_string());
self
}
pub async fn send(self) -> Result<LoadContextResult, crate::Error> {
self.client.execute_load_context(self).await
}
}