attuned_http/
lib.rs

1//! # attuned-http
2//!
3//! HTTP reference server for Attuned.
4//!
5//! This crate provides a ready-to-use HTTP server exposing the Attuned API.
6//! It includes health checks, metrics, and OpenAPI documentation.
7//!
8//! ## Endpoints
9//!
10//! - `POST /v1/state` - Upsert state (patch semantics, optionally with inference)
11//! - `GET /v1/state/{user_id}` - Get latest state
12//! - `GET /v1/context/{user_id}` - Get PromptContext
13//! - `DELETE /v1/state/{user_id}` - Delete state
14//! - `POST /v1/infer` - Infer axes from message text (requires "inference" feature)
15//! - `GET /health` - Health check
16//! - `GET /metrics` - Prometheus metrics
17//!
18//! ## Features
19//!
20//! - `inference` - Enable automatic inference from message text. Adds the `/v1/infer`
21//!   endpoint and allows the `/v1/state` endpoint to accept a `message` field for
22//!   automatic axis inference.
23//!
24//! ## Example
25//!
26//! ```rust,ignore
27//! use attuned_http::{Server, ServerConfig};
28//! use attuned_store::MemoryStore;
29//!
30//! #[tokio::main]
31//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
32//!     let store = MemoryStore::default();
33//!     let config = ServerConfig::default();
34//!
35//!     let server = Server::new(store, config);
36//!     server.run().await?;
37//!     Ok(())
38//! }
39//! ```
40//!
41//! ## With Inference
42//!
43//! ```rust,ignore
44//! use attuned_http::{Server, ServerConfig};
45//! use attuned_store::MemoryStore;
46//!
47//! #[tokio::main]
48//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
49//!     let store = MemoryStore::default();
50//!     let config = ServerConfig::default().with_inference();
51//!
52//!     let server = Server::new(store, config);
53//!     server.run().await?;
54//!     Ok(())
55//! }
56//! ```
57
58#![deny(missing_docs)]
59
60mod config;
61mod error;
62pub mod handlers;
63pub mod middleware;
64mod server;
65
66pub use config::ServerConfig;
67pub use error::HttpError;
68pub use handlers::AppState;
69pub use middleware::{AuthConfig, RateLimitConfig, RateLimitKey};
70pub use server::Server;
71
72// Re-export inference types when feature is enabled
73#[cfg(feature = "inference")]
74pub use handlers::{InferEstimate, InferRequest, InferResponse, InferSourceResponse};