rtb_chat/lib.rs
1//! Unified AI chat 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//! Formerly `rtb-ai` in the
13//! [rust-tool-base](https://gitlab.com/phpboyscout/rust-tool-base)
14//! monorepo; renamed to `rtb-chat` at extraction. The authoritative
15//! contract remains the monorepo spec
16//! `docs/development/specs/2026-05-01-rtb-ai-v0.1.md`.
17//!
18//! # Lint exception
19//!
20//! Crate-level `deny(unsafe_code)` (not `forbid`) so the genai-key
21//! shim in [`client`] can locally `allow(unsafe_code)` the
22//! `std::env::set_var` it needs to hand the API key to genai. No
23//! hand-rolled `unsafe` blocks anywhere else.
24
25#![deny(unsafe_code)]
26// Token counts cross the u64 (provider response) ↔ u32 (Usage)
27// boundary frequently; the saturating defaults are intentional.
28#![allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
29// The Anthropic helpers are `pub(crate)` for the `test_hooks` re-
30// export pattern; clippy's `redundant_pub_crate` is overzealous here.
31#![allow(clippy::redundant_pub_crate)]
32
33pub mod client;
34pub mod config;
35pub mod error;
36pub mod message;
37pub mod thinking;
38
39pub(crate) mod anthropic;
40
41pub use client::{AiClient, ChatRequest, ChatResponse, ChatStream, ChatStreamEvent};
42pub use config::{validate_base_url, Config, Provider};
43pub use error::AiError;
44pub use message::{Citation, ContentBlock, Message, Role, Usage};
45pub use thinking::ThinkingMode;
46
47/// Internal hooks exposed for unit-test reach-throughs. Not part of
48/// the stable public API and may change between minor releases.
49#[doc(hidden)]
50pub mod test_hooks {
51 pub use crate::anthropic::{build_request_body, parse_chat_response};
52}