ai-agent 0.13.4

Idiomatic agent sdk inspired by the claude code source leak
Documentation
// Source: /data/home/swei/claudecode/openclaudecode/src/utils/memoize.ts
//! Memoization utilities with TTL support.

use std::collections::HashMap;
use std::time::{Duration, Instant};

/// Simple memoization with TTL (stub implementation)
pub fn memoize_with_ttl<Args, Result, F>(_f: F, _cache_lifetime_ms: u64) -> impl Fn(Args) -> Result
where
    Args: Clone + std::fmt::Debug + 'static,
    Result: Clone + 'static,
    F: Fn(Args) -> Result + 'static,
{
    // Simple wrapper that just calls the function directly
    // In a full implementation, this would cache results
    move |arg: Args| {
        let key = format!("{:?}", arg);
        let _ = key; // Suppress unused warning
                     // TODO: Implement actual caching
        unimplemented!("memoize_with_ttl not fully implemented")
    }
}

/// Async memoization with TTL (stub)
pub fn memoize_with_ttl_async<Args, Result, F, Fut>(
    _f: F,
    _cache_lifetime_ms: u64,
) -> impl Fn(Args) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result> + Send>>
where
    Args: Clone + std::fmt::Debug + Send + 'static,
    Result: Clone + Send + 'static,
    F: Fn(Args) -> Fut + 'static,
    Fut: std::future::Future<Output = Result> + Send,
{
    move |_arg: Args| {
        Box::pin(async { unimplemented!("memoize_with_ttl_async not fully implemented") })
    }
}

/// LRU memoization (stub)
pub fn memoize_with_lru<Args, Result, K, F>(
    f: F,
    _cache_fn: impl Fn(&Args) -> K,
    _max_cache_size: usize,
) -> impl Fn(Args) -> Result
where
    Args: std::fmt::Debug,
    Result: Clone,
    K: std::hash::Hash + Eq,
    F: Fn(Args) -> Result,
{
    move |arg: Args| f(arg)
}