ai-agent 0.88.0

Idiomatic agent sdk inspired by the claude code source leak
Documentation
// Source: ~/claudecode/openclaudecode/src/utils/crypto.ts
//! Indirection point for the package.json "browser" field. When bun builds
//! browser-sdk.js with --target browser, this file is swapped for
//! crypto.browser.ts — avoiding a ~500KB crypto-browserify polyfill that Bun
//! would otherwise inline for `import ... from 'crypto'`. Node/bun builds use
//! this file unchanged.
//!
//! NOTE: `export { randomUUID } from 'crypto'` (re-export syntax) breaks under
//! bun-internal's bytecode compilation — the generated bytecode shows the
//! import but the binding doesn't link (`ReferenceError: randomUUID is not
//! defined`). The explicit import-then-export below produces a correct live
//! binding.

#![allow(dead_code)]

pub use uuid::Uuid;

/// Generate a random UUID (v4).
pub fn random_uuid() -> String {
    Uuid::new_v4().to_string()
}

/// Generate a random UUID and return it as a hyphenated string.
pub fn random_uuid_hyphenated() -> String {
    Uuid::new_v4().hyphenated().to_string()
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_random_uuid_format() {
        let uuid = random_uuid();
        // UUID v4 format: 8-4-4-4-12 hex chars
        let parts: Vec<&str> = uuid.split('-').collect();
        assert_eq!(parts.len(), 5);
        assert_eq!(parts[0].len(), 8);
        assert_eq!(parts[1].len(), 4);
        assert_eq!(parts[2].len(), 4);
        assert_eq!(parts[3].len(), 4);
        assert_eq!(parts[4].len(), 12);
    }

    #[test]
    fn test_random_uuid_unique() {
        let uuid1 = random_uuid();
        let uuid2 = random_uuid();
        assert_ne!(uuid1, uuid2);
    }
}