Rulvar API reference / @rulvar/openai / mapResponsesStream
Function: mapResponsesStream()
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
| Parameter | Type |
|---|---|
stream | AsyncIterable<ResponsesStreamEvent> |
ids | OpenAiIdMap |
options? | { effortDownmapped?: boolean; signal?: AbortSignal; } |
options.effortDownmapped? | boolean |
options.signal? | AbortSignal |
Returns
AsyncGenerator<ChatEvent, void>