llm_orchestrator_state/lib.rs
1// Copyright (c) 2025 LLM DevOps
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! State persistence and recovery for LLM workflow orchestrator.
5//!
6//! This crate provides database-backed state management for workflows with support for:
7//! - Workflow state persistence (PostgreSQL and SQLite)
8//! - Automatic checkpointing for recovery
9//! - Connection pooling and transactions
10//! - Workflow resumption after crashes
11//!
12//! # Examples
13//!
14//! ## PostgreSQL
15//!
16//! ```no_run
17//! # use llm_orchestrator_state::{PostgresStateStore, StateStore, WorkflowState};
18//! # use serde_json::json;
19//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
20//! // Create PostgreSQL state store
21//! let store = PostgresStateStore::new(
22//! "postgresql://user:pass@localhost/workflows",
23//! Some(5), // min connections
24//! Some(20), // max connections
25//! ).await?;
26//!
27//! // Create workflow state
28//! let state = WorkflowState::new(
29//! "my-workflow",
30//! "My Workflow",
31//! Some("user-123".to_string()),
32//! json!({"inputs": {"key": "value"}}),
33//! );
34//!
35//! // Save state
36//! store.save_workflow_state(&state).await?;
37//!
38//! // Load state
39//! let loaded = store.load_workflow_state(&state.id).await?;
40//! # Ok(())
41//! # }
42//! ```
43//!
44//! ## SQLite
45//!
46//! ```no_run
47//! # use llm_orchestrator_state::{SqliteStateStore, StateStore};
48//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
49//! // Create SQLite state store
50//! let store = SqliteStateStore::new("./workflows.db").await?;
51//!
52//! // Use same API as PostgreSQL
53//! store.health_check().await?;
54//! # Ok(())
55//! # }
56//! ```
57
58pub mod models;
59pub mod postgres;
60pub mod sqlite;
61pub mod traits;
62
63#[cfg(test)]
64mod tests;
65
66// Re-export commonly used types
67pub use models::{Checkpoint, StepState, StepStatus, WorkflowState, WorkflowStatus};
68pub use postgres::PostgresStateStore;
69pub use sqlite::SqliteStateStore;
70pub use traits::{StateStore, StateStoreError, StateStoreResult};
71
72/// Library version.
73pub const VERSION: &str = env!("CARGO_PKG_VERSION");