gemini_genai_rs/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![cfg_attr(not(test), forbid(unsafe_code))]
3#![cfg_attr(test, deny(unsafe_code))]
4#![warn(unreachable_pub)]
5#![warn(missing_docs)]
6// The README is the crate doc, so its code blocks are doctests: the
7// quickstart cannot drift from the API without failing `cargo test`.
8#![doc = include_str!("../README.md")]
9
10#[cfg(feature = "batches")]
11pub mod batches;
12pub mod buffer;
13#[cfg(feature = "caches")]
14pub mod caches;
15#[cfg(feature = "chats")]
16pub mod chats;
17pub mod client;
18#[cfg(feature = "embed")]
19pub mod embed;
20#[cfg(feature = "files")]
21pub mod files;
22#[cfg(feature = "generate")]
23pub mod generate;
24#[cfg(feature = "models")]
25pub mod models;
26pub mod primitives;
27pub mod protocol;
28pub mod session;
29pub mod telemetry;
30#[cfg(feature = "tokens")]
31pub mod tokens;
32pub mod transport;
33#[cfg(feature = "tunings")]
34pub mod tunings;
35pub mod turn;
36#[cfg(feature = "vad")]
37pub mod vad;
38
39// Top-level re-exports for convenience.
40pub use client::Client;
41pub use transport::{ConnectBuilder, connect};
42
43/// Convenient re-exports for wire-level usage.
44pub mod prelude {
45    // Protocol types — the API vocabulary an application names. The wire
46    // envelopes (`SetupMessage`, `RealtimeInputPayload`, `ServerMessageWrapper`,
47    // …) stay public at `protocol::messages` for anyone writing a codec, but
48    // they are not something a glob import should hand every caller.
49    pub use crate::protocol::types::{
50        AccessToken, ActivityHandling, ApiEndpoint, AudioFormat, AudioTranscriptionConfig,
51        AutomaticActivityDetection, AvatarConfig, Blob, CodeExecutionResult, Content,
52        ContextWindowCompressionConfig, EndpointEnvError, ExecutableCode, FunctionCall,
53        FunctionCallingBehavior, FunctionCallingConfig, FunctionCallingMode, FunctionDeclaration,
54        FunctionResponse, FunctionResponseScheduling, GenerationConfig, GoogleSearch,
55        GoogleSearchRetrieval, GroundingMetadata, HistoryConfig, InputAudioTranscription,
56        LIVE_INPUT_SAMPLE_RATE, LiveModelProfile, MediaResolution, Modality, ModalityTokenCount,
57        ModelId, OutputAudioTranscription, Part, PrebuiltVoiceConfig, ProactivityConfig,
58        RealtimeInputConfig, ReplicatedVoiceConfig, Role, Sensitivity, SessionConfig,
59        SessionResumptionConfig, SlidingWindow, SpeechConfig, ThinkingConfig, ThinkingLevel, Tool,
60        ToolCodeExecution, ToolConfig, ToolProvider, TurnCoverage, UrlContext, UrlContextMetadata,
61        UsageMetadata, VertexConfig, Voice, VoiceConfig,
62    };
63    // The decoded server message is the one envelope applications do match on.
64    pub use crate::protocol::messages::ServerMessage;
65
66    // Transport
67    pub use crate::transport::auth::{
68        AuthProvider, GoogleAIAuth, GoogleAITokenAuth, ServiceEndpoint, VertexAIAuth,
69    };
70    // Wire recording and replay are debugging/test tooling; they live at
71    // `transport::recording` and `transport::replay` rather than in the prelude.
72    pub use crate::transport::ws::{
73        MockTransport, Transport, TungsteniteError, TungsteniteTransport,
74    };
75    pub use crate::transport::{
76        Codec, CodecError, ConnectBuilder, JsonCodec, TransportConfig, connect,
77    };
78
79    // Session
80    pub use crate::session::{
81        AuthError, InlineMedia, ResumeInfo, SessionCommand, SessionError, SessionEvent,
82        SessionHandle, SessionPhase, SessionReader, SessionWriter, SetupError, WebSocketError,
83        recv_event,
84    };
85
86    // Buffers
87    pub use crate::buffer::{
88        AudioJitterBuffer, BufferState, JitterConfig, SpscConsumer, SpscProducer, SpscRing,
89    };
90    pub use crate::buffer::{bytes_to_i16, i16_to_bytes, into_shared};
91
92    // VAD
93    #[cfg(feature = "vad")]
94    pub use crate::vad::{VadConfig, VadEvent, VoiceActivityDetector};
95
96    // Flow
97    pub use crate::turn::{
98        BargeInAction, BargeInConfig, BargeInDetector, TurnDetectionConfig, TurnDetectionEvent,
99        TurnDetector,
100    };
101
102    // `telemetry::TelemetryConfig` installs a process-global subscriber; that
103    // is an application's once-per-binary decision, not prelude material.
104
105    // Safety types (shared across all APIs)
106    pub use crate::protocol::types::{
107        CitationMetadata, CitationSource, FileData, FinishReason, HarmBlockThreshold, HarmCategory,
108        HarmProbability, SafetyRating, SafetySetting,
109    };
110
111    // `Client` (the REST client) is at the crate root; a name that generic does
112    // not belong in a glob.
113    #[cfg(feature = "http")]
114    pub use crate::client::http::{HttpClient, HttpConfig, HttpError};
115
116    // Generate API
117    #[cfg(feature = "generate")]
118    pub use crate::generate::{GenerateContentConfig, GenerateContentResponse, GenerateError};
119
120    // Tokens API
121    #[cfg(feature = "tokens")]
122    pub use crate::tokens::{CountTokensResponse, TokensError};
123
124    // Models API
125    #[cfg(feature = "models")]
126    pub use crate::models::{ListModelsResponse, ModelsError};
127
128    // Embed API
129    #[cfg(feature = "embed")]
130    pub use crate::embed::{
131        ContentEmbedding, EmbedContentConfig, EmbedContentResponse, EmbedError,
132    };
133
134    // The Files API is at `crate::files`; `File` next to `std::fs::File` in a
135    // glob import is an ambiguity error waiting to happen.
136
137    // Caches API
138    #[cfg(feature = "caches")]
139    pub use crate::caches::{
140        CachedContent, CachedContentUsageMetadata, CachesError, CreateCachedContentConfig,
141        ListCachedContentsResponse, UpdateCachedContentRequest,
142    };
143
144    // Tunings API
145    #[cfg(feature = "tunings")]
146    pub use crate::tunings::{
147        CreateTuningJobConfig, ListTuningJobsResponse, SupervisedTuningSpec, TuningHyperParameters,
148        TuningJob, TuningJobState, TuningsError,
149    };
150
151    // Batches API
152    #[cfg(feature = "batches")]
153    pub use crate::batches::{
154        BatchJob, BatchJobDestination, BatchJobSource, BatchJobState, BatchesError,
155        CreateBatchJobConfig, ListBatchJobsResponse,
156    };
157
158    // Chat API
159    #[cfg(feature = "chats")]
160    pub use crate::chats::ChatSession;
161}