Skip to navigation

Generated from cargo doc --no-deps -p nemo-relay-builtins -p nemo-relay-diagnostics -p nemo-relay-logging -p nemo-relay-plugin-host -p nemo-relay-codecs -p nemo-relay -p nemo-relay-runtime -p nemo-relay-model-pricing -p nemo-relay-resource-metrics -p nemo-relay-observability -p nemo-relay-adaptive -p nemo-relay-pii-redaction -p nemo-relay-ffi -p nemo-relay-types -p nemo-relay-plugin -p nemo-relay-worker-proto -p nemo-relay-worker.

pub struct OpenAIResponsesStreamingCodec { /* private fields */ }

Streaming counterpart to OpenAIResponsesCodec.

Replays the OpenAI Responses SSE event sequence into the same JSON shape the API returns for a non-streaming request ({id, model, status, output, usage, incomplete_details, ...}). Once finalized, the assembled JSON can be fed back through OpenAIResponsesCodec::decode_response to produce the canonical AnnotatedLlmResponse.

Strategy

The Responses API is a relatively forgiving streaming target because every event carries either the full response snapshot (response.created, response.in_progress, response.completed, response.failed, response.incomplete) or the final-state output item (response.output_item.done). We:

  1. Track the latest response snapshot until the first final response event (completed, failed, or incomplete). Keep that snapshot for the rest of the stream.
  2. Track output items by output_index - output_item.done events deliver the final per-item state, used as a fallback when the terminal response.output is missing or empty.
  3. Retain text, refusal, and function-argument deltas provisionally for supplied output items. Completed content parts and output items replace provisional data, so interrupted streams retain observed content without duplicating it when a completed snapshot arrives.

Use StreamingCodec::validate_stream with this instance’s collector and finalizer to report provider failures and streams that end before a final event.

Internal state lives behind Arc<Mutex<...>> so the &self-produced collector and finalizer closures share access. Each instance is single-use because LlmFinalizerFn consumes the finalize step.

Implementations

impl OpenAIResponsesStreamingCodec

impl OpenAIResponsesStreamingCodec

new

pub fn new() -> Self

Creates a fresh streaming codec with empty accumulator state.

Trait Implementations

impl Default for OpenAIResponsesStreamingCodec

impl Default for OpenAIResponsesStreamingCodec

default

fn default() -> Self

impl StreamingCodec for OpenAIResponsesStreamingCodec

impl StreamingCodec for OpenAIResponsesStreamingCodec

validate_stream

fn validate_stream(&self, stream: LlmJsonStream) -> LlmJsonStream

Forwards a failed response or error event before reporting its error on the next poll. Reports an error at EOF unless a final response event was seen.

The check passes when this stream forwarded a final response event or when this codec’s collector recorded one. Middleware between this stream and the collector can drain the source first, so a clean EOF does not mean the collector has finished: the finalizer reflects only the events that reached the collector.

collector

fn collector(&self) -> LlmCollectorFn

Collects response snapshots and output items into this codec’s shared state.

finalizer

fn finalizer(&self) -> LlmFinalizerFn

Takes the collected state and returns the final provider response.

borrowed_collector

fn borrowed_collector(&self) -> Option<LlmBorrowedCollectorFn>