rtb_ai/lib.rs
1//! Unified AI client.
2//!
3//! Wraps [`genai`] for the multi-provider mainstream (`OpenAI` /
4//! Gemini / Ollama / OpenAI-compatible) and drops down to a direct
5//! `reqwest`-on-Anthropic-Messages path for features `genai` does not
6//! yet surface — prompt caching, extended thinking, citations.
7//!
8//! Structured output uses `schemars::JsonSchema` on caller-supplied
9//! types: the schema is sent with the request, and the response is
10//! validated with `jsonschema` before deserialising.
11//!
12//! See `docs/development/specs/2026-05-01-rtb-ai-v0.1.md` for the
13//! authoritative contract.
14//!
15//! # Lint exception
16//!
17//! Crate-level `deny(unsafe_code)` (not `forbid`) so the genai-key
18//! shim in [`client`] can locally `allow(unsafe_code)` the
19//! `std::env::set_var` it needs to hand the API key to genai. No
20//! hand-rolled `unsafe` blocks anywhere else.
21
22#![deny(unsafe_code)]
23// Token counts cross the u64 (provider response) ↔ u32 (Usage)
24// boundary frequently; the saturating defaults are intentional.
25#![allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
26// The Anthropic helpers are `pub(crate)` for the `test_hooks` re-
27// export pattern; clippy's `redundant_pub_crate` is overzealous here.
28#![allow(clippy::redundant_pub_crate)]
29
30pub mod client;
31pub mod config;
32pub mod error;
33pub mod message;
34pub mod thinking;
35
36pub(crate) mod anthropic;
37
38pub use client::{AiClient, ChatRequest, ChatResponse, ChatStream, ChatStreamEvent};
39pub use config::{validate_base_url, Config, Provider};
40pub use error::AiError;
41pub use message::{Citation, ContentBlock, Message, Role, Usage};
42pub use thinking::ThinkingMode;
43
44/// Internal hooks exposed for unit-test reach-throughs. Not part of
45/// the stable public API and may change between minor releases.
46#[doc(hidden)]
47pub mod test_hooks {
48 pub use crate::anthropic::{build_request_body, parse_chat_response};
49}