Skip to content

Rulvar API reference


Rulvar API reference / @rulvar/openai / mapResponsesStream

Function: mapResponsesStream()

ts
function mapResponsesStream(
   stream, 
   ids, 
options?): AsyncGenerator<ChatEvent, void>;

Defined in: packages/openai/src/wire.ts:333

Maps the typed Responses SSE stream to ChatEvents, yielding each canonical event AS the corresponding provider event is consumed: the consumer's pull drives the provider read (natural backpressure, no buffering, no detached work). Canonical parts come from the typed output array, never the output_text aggregate. Raw output items ride finish.providerMetadata.openai.outputItems so the runtime can retain reasoning items as provider-raw parts.

A stream that drains without any response terminal event (response.completed, response.incomplete, response.failed, or error) is a truncated wire read: the mapper fails closed with one retryable transport error instead of ending silently, unless options.signal shows the caller requested the abort (the documented exception that ends a stream without a terminal event).

Parameters

ParameterType
streamAsyncIterable&lt;ResponsesStreamEvent&gt;
idsOpenAiIdMap
options?{ effortDownmapped?: boolean; signal?: AbortSignal; }
options.effortDownmapped?boolean
options.signal?AbortSignal

Returns

AsyncGenerator&lt;ChatEvent, void&gt;