Gemini.Streaming.ManagerV2 (GeminiEx v0.0.2)
View SourceImproved GenServer for managing streaming connections and state.
Features:
- Proper HTTP streaming with persistent connections
- Resource management and cleanup
- Subscriber pattern with backpressure
- Error handling and automatic retries
- Stream lifecycle management
Summary
Functions
Returns a specification to start this module under a supervisor.
Get manager statistics.
Get information about a stream.
List all active streams.
Start the streaming manager.
Start a new streaming session.
Stop a streaming session.
Subscribe to events from an existing stream.
Unsubscribe from a stream.
Types
@type manager_state() :: %{ streams: %{required(stream_id()) => stream_state()}, stream_counter: non_neg_integer(), max_streams: pos_integer(), default_timeout: pos_integer() }
@type stream_id() :: String.t()
@type stream_state() :: %{ stream_id: stream_id(), stream_pid: pid() | nil, model: String.t(), request_body: map(), status: :starting | :active | :completed | :error | :stopped, error: term() | nil, started_at: DateTime.t(), subscribers: [subscriber_ref()], events_count: non_neg_integer(), last_event_at: DateTime.t() | nil, config: keyword() }
Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec get_stats() :: map()
Get manager statistics.
Get information about a stream.
@spec list_streams() :: [stream_id()]
List all active streams.
@spec start_link(keyword()) :: GenServer.on_start()
Start the streaming manager.
Start a new streaming session.
Parameters
contents
- Content to stream (string or list of Content structs)opts
- Generation options (model, generation_config, etc.)subscriber_pid
- Process to receive stream events (default: calling process)
Returns
{:ok, stream_id}
- Stream started successfully{:error, reason}
- Failed to start stream
Events sent to subscriber:
{:stream_event, stream_id, event_data}
- New event received{:stream_complete, stream_id}
- Stream completed successfully{:stream_error, stream_id, error}
- Stream failed with error
Stop a streaming session.
Subscribe to events from an existing stream.
Unsubscribe from a stream.