velixar 0.1.0

Governed, auditable memory for AI agents. Official Rust client for the Velixar API.
Documentation
//! Runs the README flow against the REAL API. Mocks only prove the crate agrees
//! with my assumptions; this proves it agrees with production.
//!
//!   VELIXAR_API_KEY=vlx_... cargo run --example live
use velixar::{SearchOpts, StoreOpts, Velixar};

#[tokio::main]
async fn main() -> velixar::Result<()> {
    let key = std::env::var("VELIXAR_API_KEY").expect("set VELIXAR_API_KEY");
    let c = Velixar::new(key)?;

    let h = c.health().await?;
    println!("  health          -> {}", h.get("status").and_then(|v| v.as_str()).unwrap_or("?"));

    let id = c
        .store(
            "Rust crate live check — Priya is lactose intolerant.",
            StoreOpts::new().user("priya-rs").tags(["diet", "rust-live"]),
        )
        .await?;
    println!("  store           -> {id}");

    tokio::time::sleep(std::time::Duration::from_secs(2)).await;

    let mine = c.search("what can priya eat?", SearchOpts::new().user("priya-rs").limit(5)).await?;
    println!("  search (priya)  -> {} hit(s)", mine.count);
    for m in &mine.memories {
        println!("      {:?} | {}", m.user_id.as_deref().unwrap_or("-"), &m.content[..m.content.len().min(44)]);
    }

    // THE PROPERTY: a scoped search must contain no other user's memories.
    let foreign: Vec<_> = mine.memories.iter().filter(|m| m.user_id.as_deref() != Some("priya-rs")).collect();
    assert!(foreign.is_empty(), "CROSS-USER LEAK: {foreign:?}");
    println!("  isolation       -> ✓ no foreign user_id in priya's results");

    // A read+write key must get Scope, not a silent success or a confusing 404.
    match c.delete(&id).await {
        Err(velixar::Error::Scope(e)) => println!("  delete (no scope) -> ✓ Error::Scope [{}]", e.code),
        Ok(v) => println!("  delete          -> deleted={v} (key HAS memory:delete)"),
        Err(e) => println!("  delete          -> {e}"),
    }
    Ok(())
}