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, AutomaticActivityDetection, Blob,
51        CodeExecutionResult, Content, ContextWindowCompressionConfig, EndpointEnvError,
52        ExecutableCode, FunctionCall, FunctionCallingBehavior, FunctionCallingConfig,
53        FunctionCallingMode, FunctionDeclaration, FunctionResponse, FunctionResponseScheduling,
54        GenerationConfig, GoogleSearch, GoogleSearchRetrieval, GroundingMetadata,
55        InputAudioTranscription, LIVE_INPUT_SAMPLE_RATE, MediaResolution, Modality,
56        ModalityTokenCount, ModelId, OutputAudioTranscription, Part, PrebuiltVoiceConfig,
57        ProactivityConfig, RealtimeInputConfig, Role, Sensitivity, SessionConfig,
58        SessionResumptionConfig, SlidingWindow, SpeechConfig, ThinkingConfig, Tool,
59        ToolCodeExecution, ToolConfig, ToolProvider, TurnCoverage, UrlContext, UrlContextMetadata,
60        UsageMetadata, VertexConfig, Voice, VoiceConfig,
61    };
62    // The decoded server message is the one envelope applications do match on.
63    pub use crate::protocol::messages::ServerMessage;
64
65    // Transport
66    pub use crate::transport::auth::{
67        AuthProvider, GoogleAIAuth, GoogleAITokenAuth, ServiceEndpoint, VertexAIAuth,
68    };
69    // Wire recording and replay are debugging/test tooling; they live at
70    // `transport::recording` and `transport::replay` rather than in the prelude.
71    pub use crate::transport::ws::{
72        MockTransport, Transport, TungsteniteError, TungsteniteTransport,
73    };
74    pub use crate::transport::{
75        Codec, CodecError, ConnectBuilder, JsonCodec, TransportConfig, connect,
76    };
77
78    // Session
79    pub use crate::session::{
80        AuthError, ResumeInfo, SessionCommand, SessionError, SessionEvent, SessionHandle,
81        SessionPhase, SessionReader, SessionWriter, SetupError, WebSocketError, recv_event,
82    };
83
84    // Buffers
85    pub use crate::buffer::{
86        AudioJitterBuffer, BufferState, JitterConfig, SpscConsumer, SpscProducer, SpscRing,
87    };
88    pub use crate::buffer::{bytes_to_i16, i16_to_bytes, into_shared};
89
90    // VAD
91    #[cfg(feature = "vad")]
92    pub use crate::vad::{VadConfig, VadEvent, VoiceActivityDetector};
93
94    // Flow
95    pub use crate::turn::{
96        BargeInAction, BargeInConfig, BargeInDetector, TurnDetectionConfig, TurnDetectionEvent,
97        TurnDetector,
98    };
99
100    // `telemetry::TelemetryConfig` installs a process-global subscriber; that
101    // is an application's once-per-binary decision, not prelude material.
102
103    // Safety types (shared across all APIs)
104    pub use crate::protocol::types::{
105        CitationMetadata, CitationSource, FileData, FinishReason, HarmBlockThreshold, HarmCategory,
106        HarmProbability, SafetyRating, SafetySetting,
107    };
108
109    // `Client` (the REST client) is at the crate root; a name that generic does
110    // not belong in a glob.
111    #[cfg(feature = "http")]
112    pub use crate::client::http::{HttpClient, HttpConfig, HttpError};
113
114    // Generate API
115    #[cfg(feature = "generate")]
116    pub use crate::generate::{GenerateContentConfig, GenerateContentResponse, GenerateError};
117
118    // Tokens API
119    #[cfg(feature = "tokens")]
120    pub use crate::tokens::{CountTokensResponse, TokensError};
121
122    // Models API
123    #[cfg(feature = "models")]
124    pub use crate::models::{ListModelsResponse, ModelsError};
125
126    // Embed API
127    #[cfg(feature = "embed")]
128    pub use crate::embed::{
129        ContentEmbedding, EmbedContentConfig, EmbedContentResponse, EmbedError,
130    };
131
132    // The Files API is at `crate::files`; `File` next to `std::fs::File` in a
133    // glob import is an ambiguity error waiting to happen.
134
135    // Caches API
136    #[cfg(feature = "caches")]
137    pub use crate::caches::{
138        CachedContent, CachedContentUsageMetadata, CachesError, CreateCachedContentConfig,
139        ListCachedContentsResponse, UpdateCachedContentRequest,
140    };
141
142    // Tunings API
143    #[cfg(feature = "tunings")]
144    pub use crate::tunings::{
145        CreateTuningJobConfig, ListTuningJobsResponse, SupervisedTuningSpec, TuningHyperParameters,
146        TuningJob, TuningJobState, TuningsError,
147    };
148
149    // Batches API
150    #[cfg(feature = "batches")]
151    pub use crate::batches::{
152        BatchJob, BatchJobDestination, BatchJobSource, BatchJobState, BatchesError,
153        CreateBatchJobConfig, ListBatchJobsResponse,
154    };
155
156    // Chat API
157    #[cfg(feature = "chats")]
158    pub use crate::chats::ChatSession;
159}