Skip to main content

rs_genai/
lib.rs

1#![warn(missing_docs)]
2//! # rs-genai
3//!
4//! Full Rust equivalent of Google's `@google/genai` SDK.
5//! Wire protocol, transport, types, auth, plus REST API modules (feature-gated).
6//!
7//! ## Layers
8//!
9//! - **Protocol**: Wire-format types mapping 1:1 to the API (`protocol/`)
10//! - **Transport**: WebSocket connection with reconnection and flow control (`transport/`)
11//! - **Session**: Session handle with command/event channels and phase FSM (`session/`)
12//! - **Buffer**: Lock-free SPSC ring buffer and adaptive jitter buffer (`buffer/`)
13//! - **VAD**: Voice activity detection with adaptive noise floor (`vad/`)
14//! - **Flow**: Barge-in detection and turn detection (`flow/`)
15//! - **Telemetry**: OTel spans, structured logging, Prometheus metrics (`telemetry/`)
16
17#[cfg(feature = "batches")]
18pub mod batches;
19pub mod buffer;
20#[cfg(feature = "caches")]
21pub mod caches;
22#[cfg(feature = "chats")]
23pub mod chats;
24pub mod client;
25#[cfg(feature = "embed")]
26pub mod embed;
27#[cfg(feature = "files")]
28pub mod files;
29pub mod flow;
30#[cfg(feature = "generate")]
31pub mod generate;
32#[cfg(feature = "models")]
33pub mod models;
34pub mod protocol;
35pub mod quick;
36pub mod session;
37pub mod telemetry;
38#[cfg(feature = "tokens")]
39pub mod tokens;
40pub mod transport;
41#[cfg(feature = "tunings")]
42pub mod tunings;
43#[cfg(feature = "vad")]
44pub mod vad;
45
46// Top-level re-exports for convenience.
47pub use client::Client;
48pub use quick::{quick_connect, quick_connect_vertex};
49
50/// Convenient re-exports for wire-level usage.
51pub mod prelude {
52    // Protocol types
53    pub use crate::protocol::messages::*;
54    pub use crate::protocol::types::*;
55    pub use crate::protocol::Platform;
56
57    // Transport
58    pub use crate::transport::auth::{
59        AuthProvider, GoogleAIAuth, GoogleAITokenAuth, ServiceEndpoint, VertexAIAuth,
60    };
61    pub use crate::transport::ws::{MockTransport, Transport, TungsteniteTransport};
62    pub use crate::transport::{
63        connect, connect_with, Codec, CodecError, ConnectBuilder, JsonCodec, TransportConfig,
64    };
65
66    // Session
67    pub use crate::session::{
68        recv_event, AuthError, ResumeInfo, SessionCommand, SessionError, SessionEvent,
69        SessionHandle, SessionPhase, SessionReader, SessionWriter, SetupError, WebSocketError,
70    };
71
72    // Buffers
73    pub use crate::buffer::{bytes_to_i16, i16_to_bytes, into_shared};
74    pub use crate::buffer::{AudioJitterBuffer, JitterConfig, SpscRing};
75
76    // VAD
77    #[cfg(feature = "vad")]
78    pub use crate::vad::{VadConfig, VadEvent, VoiceActivityDetector};
79
80    // Flow
81    pub use crate::flow::{
82        BargeInAction, BargeInConfig, BargeInDetector, TurnDetectionConfig, TurnDetectionEvent,
83        TurnDetector,
84    };
85
86    // Telemetry
87    pub use crate::telemetry::TelemetryConfig;
88
89    // Safety types (shared across all APIs)
90    pub use crate::protocol::types::{
91        CitationMetadata, CitationSource, FileData, FinishReason, HarmBlockThreshold, HarmCategory,
92        HarmProbability, SafetyRating, SafetySetting,
93    };
94
95    // Client
96    #[cfg(feature = "http")]
97    pub use crate::client::http::{HttpClient, HttpConfig, HttpError};
98    pub use crate::client::Client;
99
100    // Generate API
101    #[cfg(feature = "generate")]
102    pub use crate::generate::{
103        Candidate, GenerateContentConfig, GenerateContentResponse, GenerateError,
104    };
105
106    // Tokens API
107    #[cfg(feature = "tokens")]
108    pub use crate::tokens::{CountTokensResponse, TokensError};
109
110    // Models API
111    #[cfg(feature = "models")]
112    pub use crate::models::{ListModelsResponse, ModelInfo, ModelsError};
113
114    // Embed API
115    #[cfg(feature = "embed")]
116    pub use crate::embed::{
117        ContentEmbedding, EmbedContentConfig, EmbedContentResponse, EmbedError, TaskType,
118    };
119
120    // Files API
121    #[cfg(feature = "files")]
122    pub use crate::files::{
123        File, FileSource, FileState, FilesError, ListFilesResponse, UploadFileConfig,
124    };
125
126    // Caches API
127    #[cfg(feature = "caches")]
128    pub use crate::caches::{
129        CachedContent, CachedContentUsageMetadata, CachesError, CreateCachedContentConfig,
130        ListCachedContentsResponse, UpdateCachedContentRequest,
131    };
132
133    // Tunings API
134    #[cfg(feature = "tunings")]
135    pub use crate::tunings::{
136        CreateTuningJobConfig, ListTuningJobsResponse, SupervisedTuningSpec, TuningHyperParameters,
137        TuningJob, TuningJobState, TuningsError,
138    };
139
140    // Batches API
141    #[cfg(feature = "batches")]
142    pub use crate::batches::{
143        BatchJob, BatchJobDestination, BatchJobSource, BatchJobState, BatchesError,
144        CreateBatchJobConfig, ListBatchJobsResponse,
145    };
146
147    // Chat API
148    #[cfg(feature = "chats")]
149    pub use crate::chats::ChatSession;
150
151    // Quick-start
152    pub use crate::quick::{quick_connect, quick_connect_vertex};
153}