Documentation/Streaming
v2.0.0-beta.1Snapshot bebdcd1Markdown ↗

Streaming

Streaming

Real-time streaming of agent responses

StreamHelpers class

📍 src/capabilities/agents/StreamHelpers.ts:19

Helper class for consuming and processing streams

Static Methods

static collectResponse()

Collect complete response from stream Accumulates all events and reconstructs final LLMResponse

typescript
static async collectResponse(
    stream: AsyncIterableIterator<StreamEvent>
  ): Promise<LLMResponse>

Parameters:

  • stream: AsyncIterableIterator<StreamEvent>

Returns: Promise<LLMResponse>

static textOnly()

Get only text deltas from stream (for simple text streaming) Filters out all other event types

typescript
static async *textOnly(
    stream: AsyncIterableIterator<StreamEvent>
  ): AsyncIterableIterator<string>

Parameters:

  • stream: AsyncIterableIterator<StreamEvent>

Returns: AsyncIterableIterator<string>

static filterByType()

Filter stream events by type

typescript
static async *filterByType<T extends StreamEvent>(
    stream: AsyncIterableIterator<StreamEvent>,
    eventType: StreamEventType
  ): AsyncIterableIterator<T>

Parameters:

  • stream: AsyncIterableIterator<StreamEvent>
  • eventType: StreamEventType

Returns: AsyncIterableIterator<T>

static accumulateText()

Accumulate text from stream into a single string

typescript
static async accumulateText(
    stream: AsyncIterableIterator<StreamEvent>
  ): Promise<string>

Parameters:

  • stream: AsyncIterableIterator<StreamEvent>

Returns: Promise<string>

static thinkingOnly()

Get only reasoning/thinking deltas from stream Filters out all other event types

typescript
static async *thinkingOnly(
    stream: AsyncIterableIterator<StreamEvent>
  ): AsyncIterableIterator<string>

Parameters:

  • stream: AsyncIterableIterator<StreamEvent>

Returns: AsyncIterableIterator<string>

static textAndThinking()

Get both text and thinking deltas from stream Yields tagged objects so consumers can distinguish them

typescript
static async *textAndThinking(
    stream: AsyncIterableIterator<StreamEvent>
  ): AsyncIterableIterator<{ type: 'text' | 'thinking'; delta: string }>

Parameters:

  • stream: AsyncIterableIterator<StreamEvent>

Returns: AsyncIterableIterator<{ type: "thinking" | "text"; delta: string; }>

static accumulateThinking()

Accumulate all thinking/reasoning content from stream into a single string

typescript
static async accumulateThinking(
    stream: AsyncIterableIterator<StreamEvent>
  ): Promise<string>

Parameters:

  • stream: AsyncIterableIterator<StreamEvent>

Returns: Promise<string>

static bufferEvents()

Buffer stream events into batches

typescript
static async *bufferEvents(
    stream: AsyncIterableIterator<StreamEvent>,
    batchSize: number
  ): AsyncIterableIterator<StreamEvent[]>

Parameters:

  • stream: AsyncIterableIterator<StreamEvent>
  • batchSize: number

Returns: AsyncIterableIterator<StreamEvent[]>

static tap()

Tap into stream without consuming it Useful for logging or side effects

typescript
static async *tap(
    stream: AsyncIterableIterator<StreamEvent>,
    callback: (event: StreamEvent) => void | Promise<void>
  ): AsyncIterableIterator<StreamEvent>

Parameters:

  • stream: AsyncIterableIterator<StreamEvent>
  • callback: (event: StreamEvent) => void | Promise<void>

Returns: AsyncIterableIterator<StreamEvent>

static take()

Take first N events from stream

typescript
static async *take(
    stream: AsyncIterableIterator<StreamEvent>,
    count: number
  ): AsyncIterableIterator<StreamEvent>

Parameters:

  • stream: AsyncIterableIterator<StreamEvent>
  • count: number

Returns: AsyncIterableIterator<StreamEvent>

static skip()

Skip first N events from stream

typescript
static async *skip(
    stream: AsyncIterableIterator<StreamEvent>,
    count: number
  ): AsyncIterableIterator<StreamEvent>

Parameters:

  • stream: AsyncIterableIterator<StreamEvent>
  • count: number

Returns: AsyncIterableIterator<StreamEvent>


StreamState class

📍 src/domain/entities/StreamState.ts:78

StreamState tracks all accumulated data during streaming

Constructor

constructor

typescript
constructor(responseId: string, model: string, createdAt?: number)

Parameters:

  • responseId: string
  • model: string
  • createdAt: number | undefined (optional)
Methods

accumulateTextDelta()

Accumulate text delta for a specific item

typescript
accumulateTextDelta(itemId: string, delta: string, position: StreamOutputPosition = {}): void

Parameters:

  • itemId: string
  • delta: string
  • position: StreamOutputPosition (optional) (default: {})

Returns: void

getCompleteText()

Get complete accumulated text for an item

typescript
getCompleteText(itemId: string): string

Parameters:

  • itemId: string

Returns: string

getAllText()

Get all accumulated text (all items concatenated)

typescript
getAllText(): string

Returns: string

accumulateReasoningDelta()

Accumulate reasoning delta for a specific item

typescript
accumulateReasoningDelta(
    itemId: string,
    delta: string,
    position: StreamOutputPosition = {},
  ): void

Parameters:

  • itemId: string
  • delta: string
  • position: StreamOutputPosition (optional) (default: {})

Returns: void

getCompleteReasoning()

Get complete accumulated reasoning for an item

typescript
getCompleteReasoning(itemId: string): string

Parameters:

  • itemId: string

Returns: string

getAllReasoning()

Get all accumulated reasoning (all items concatenated)

typescript
getAllReasoning(): string

Returns: string

completeReasoning()

Reasoning blocks with provider item IDs, used by stateless replay APIs.

typescript
completeReasoning(
    itemId: string,
    metadata: { signature?: string; encryptedContent?: string; effort?: import('../interfaces/ITextProvider.js').ReasoningEffort },
    position: StreamOutputPosition = {},
  ): void

Parameters:

  • itemId: string
  • metadata: { signature?: string | undefined; encryptedContent?: string | undefined; effort?: ReasoningEffort | undefined; }
  • position: StreamOutputPosition (optional) (default: {})

Returns: void

getReasoningEntries()

typescript
getReasoningEntries(): Array<{
    itemId: string;
    thinking: string;
    signature?: string;
    encryptedContent?: string;
    effort?: import('../interfaces/ITextProvider.js').ReasoningEffort;
  }>

Returns: { itemId: string; thinking: string; signature?: string | undefined; encryptedContent?: string | undefined; effort?: ReasoningEffort | undefined; }[]

hasReasoning()

Check if stream has any accumulated reasoning

typescript
hasReasoning(): boolean

Returns: boolean

accumulateCompaction()

typescript
accumulateCompaction(item: CompactionItem, position: StreamOutputPosition = {}): void

Parameters:

  • item: CompactionItem
  • position: StreamOutputPosition (optional) (default: {})

Returns: void

getCompactions()

typescript
getCompactions(): CompactionItem[]

Returns: CompactionItem[]

hasCompactions()

typescript
hasCompactions(): boolean

Returns: boolean

accumulateProviderState()

typescript
accumulateProviderState(
    itemId: string,
    state: ProviderStateContent,
    position: StreamOutputPosition = {},
  ): void

Parameters:

  • itemId: string
  • state: ProviderStateContent
  • position: StreamOutputPosition (optional) (default: {})

Returns: void

getProviderStates()

typescript
getProviderStates(): ProviderStateContent[]

Returns: ProviderStateContent[]

hasProviderStates()

typescript
hasProviderStates(): boolean

Returns: boolean

startToolCall()

Start accumulating tool call arguments

typescript
startToolCall(
    toolCallId: string,
    toolName: string,
    itemId = toolCallId,
    position: StreamOutputPosition = {},
    metadata: { toolType?: 'function' | 'custom'; async?: boolean } = {},
  ): void

Parameters:

  • toolCallId: string
  • toolName: string
  • itemId: string (optional) (default: toolCallId)
  • position: StreamOutputPosition (optional) (default: {})
  • metadata: { toolType?: "function" | "custom" | undefined; async?: boolean | undefined; } (optional) (default: {})

Returns: void

getOrderedOutputEntries()

Reconstruct every streamed provider output item in its original order.

typescript
getOrderedOutputEntries(): OrderedStreamOutputEntry[]

Returns: OrderedStreamOutputEntry[]

accumulateToolArguments()

Accumulate tool argument delta

typescript
accumulateToolArguments(toolCallId: string, delta: string): void

Parameters:

  • toolCallId: string
  • delta: string

Returns: void

completeToolCall()

Mark tool call arguments as complete

typescript
completeToolCall(toolCallId: string): void

Parameters:

  • toolCallId: string

Returns: void

getCompleteToolArguments()

Get complete tool arguments (joined chunks)

typescript
getCompleteToolArguments(toolCallId: string): string

Parameters:

  • toolCallId: string

Returns: string

isToolCallComplete()

Check if tool call is complete

typescript
isToolCallComplete(toolCallId: string): boolean

Parameters:

  • toolCallId: string

Returns: boolean

getToolName()

Get tool name for a tool call

typescript
getToolName(toolCallId: string): string | undefined

Parameters:

  • toolCallId: string

Returns: string | undefined

addCompletedToolCall()

Add completed tool call

typescript
addCompletedToolCall(toolCall: ToolCall): void

Parameters:

  • toolCall: ToolCall

Returns: void

getCompletedToolCalls()

Get all completed tool calls

typescript
getCompletedToolCalls(): ToolCall[]

Returns: ToolCall[]

setToolResult()

Store tool execution result

typescript
setToolResult(toolCallId: string, result: any): void

Parameters:

  • toolCallId: string
  • result: any

Returns: void

getToolResult()

Get tool execution result

typescript
getToolResult(toolCallId: string): any

Parameters:

  • toolCallId: string

Returns: any

updateUsage()

Update token usage (replaces values, doesn't accumulate)

typescript
updateUsage(usage: Partial<TokenUsage>): void

Parameters:

  • usage: Partial<TokenUsage>

Returns: void

accumulateFrom()

Accumulate text, reasoning, and statistics from another StreamState. Used to merge per-iteration state into the global execution state, so that the final response built from the global state has full text.

typescript
accumulateFrom(other: StreamState): void

Parameters:

  • other: StreamState

Returns: void

accumulateUsage()

Accumulate token usage (adds to existing values)

typescript
accumulateUsage(usage: Partial<TokenUsage>): void

Parameters:

  • usage: Partial<TokenUsage>

Returns: void

markComplete()

Mark stream as complete

typescript
markComplete(status: 'completed' | 'incomplete' | 'failed' = 'completed'): void

Parameters:

  • status: "completed" | "failed" | "incomplete" (optional) (default: 'completed')

Returns: void

getDuration()

Get duration in milliseconds

typescript
getDuration(): number

Returns: number

incrementIteration()

Increment iteration counter

typescript
incrementIteration(): void

Returns: void

getStatistics()

Get summary statistics

typescript
getStatistics()

Returns: { responseId: string; model: string; status: "completed" | "failed" | "in_progress" | "incomplete"; iterations: number; totalChunks: number; totalTextDeltas: number; totalToolCalls: number; textItemsCount: number; toolCallBuffersCount: number; completedToolCallsCount: number; durationMs: number; usage: { input_tokens: number; output_tokens: number; total_tokens: number; output_tokens_details?: { reasoning_tokens: number; } | undefined; cached_input_tokens?: number | undefined; cache_creation_input_tokens?: number | undefined; cache_creation_details?: { short_ttl_input_tokens?: number | undefined; extended_ttl_input_tokens?: number | undefined; } | undefined; native_tool_calls?: Record<string, number | undefined> | undefined; processing_mode?: ProcessingMode | undefined; service_tier?: string | undefined; speed?: string | undefined; cost_usd_ticks?: number | undefined; }; providerStatus: "completed" | "failed" | "incomplete"; stopReason: string | undefined; stopDetails: ProviderStopDetails | undefined; }

hasText()

Check if stream has any accumulated text

typescript
hasText(): boolean

Returns: boolean

hasToolCalls()

Check if stream has any tool calls

typescript
hasToolCalls(): boolean

Returns: boolean

clear()

Clear all buffers (for memory management)

typescript
clear(): void

Returns: void

createSnapshot()

Create a snapshot for checkpointing (error recovery)

typescript
createSnapshot()

Returns: { responseId: string; model: string; createdAt: number; textBuffers: Map<string, string[]>; reasoningBuffers: Map<string, string[]>; reasoningMetadata: Map<string, { signature?: string | undefined; encryptedContent?: string | undefined; effort?: ReasoningEffort | undefined; }>; compactions: Map<string, CompactionItem>; providerStates: Map<string, ProviderStateContent>; orderedOutputs: Map<string, OrderedOutputRef>; nextOutputOrdinal: number; toolCallBuffers: Map<string, ToolCallBuffer>; completedToolCalls: ToolCall[]; toolResults: Map<string, any>; currentIteration: number; usage: { input_tokens: number; output_tokens: number; total_tokens: number; output_tokens_details?: { reasoning_tokens: number; } | undefined; cached_input_tokens?: number | undefined; cache_creation_input_tokens?: number | undefined; cache_creation_details?: { short_ttl_input_tokens?: number | undefined; extended_ttl_input_tokens?: number | undefined; } | undefined; native_tool_calls?: Record<string, number | undefined> | undefined; processing_mode?: ProcessingMode | undefined; service_tier?: string | undefined; speed?: string | undefined; cost_usd_ticks?: number | undefined; }; status: "completed" | "failed" | "in_progress" | "incomplete"; providerStatus: "completed" | "failed" | "incomplete"; stopReason: string | undefined; stopDetails: ProviderStopDetails | undefined; continuationToken: string | undefined; startTime: Date; endTime: Date | undefined; }

Properties
Property Type Description
responseId responseId: string -
model model: string -
createdAt createdAt: number -
currentIteration currentIteration: number -
usage usage: TokenUsage -
status `status: "completed" "failed"
providerStatus `providerStatus: "completed" "failed"
stopReason? `stopReason: string undefined`
continuationToken? `continuationToken: string undefined`
stopDetails? `stopDetails: ProviderStopDetails undefined`
startTime startTime: Date -
endTime? `endTime: Date undefined`
totalChunks totalChunks: number -
totalTextDeltas totalTextDeltas: number -
totalToolCalls totalToolCalls: number -

VoiceStream class

📍 src/capabilities/speech/VoiceStream.ts:55

Static Methods

static create()

Create a new VoiceStream instance

typescript
static create(config: VoiceStreamConfig): VoiceStream

Parameters:

  • config: VoiceStreamConfig

Returns: VoiceStream

Methods

wrap()

Transform an agent text stream into an augmented stream with audio events. Original text events pass through unchanged; audio events are interleaved.

The generator yields events in this order:

  1. All original StreamEvents (pass-through)
  2. AudioChunkReady/AudioChunkError events as TTS completes
  3. AudioStreamComplete as the final audio event
typescript
async *wrap(
    textStream: AsyncIterableIterator<StreamEvent>
  ): AsyncIterableIterator<StreamEvent>

Parameters:

  • textStream: AsyncIterableIterator<StreamEvent>

Returns: AsyncIterableIterator<StreamEvent>

interrupt()

Interrupt audio generation. Cancels pending TTS and flushes queue. Call this when the user sends a new message mid-speech. Active HTTP requests cannot be cancelled but their results will be discarded.

typescript
interrupt(): void

Returns: void

reset()

Reset state for a new stream. Called automatically by wrap().

typescript
reset(): void

Returns: void

destroy()

typescript
destroy(): void

Returns: void


AudioChunkErrorEvent interface

📍 src/domain/entities/StreamEvent.ts:302

Audio chunk error - TTS synthesis failed for a text chunk

Properties
Property Type Description
type type: StreamEventType.AUDIO_CHUNK_ERROR; -
chunk_index chunk_index: number; -
text text: string; -
error error: string; -

AudioChunkReadyEvent interface

📍 src/domain/entities/StreamEvent.ts:281

Audio chunk ready - TTS synthesis complete for a text chunk

Properties
Property Type Description
type type: StreamEventType.AUDIO_CHUNK_READY; -
chunk_index chunk_index: number; Sequential index for ordered playback
sub_index? sub_index?: number; Sub-chunk index within a chunk (for streaming TTS mode)
text text: string; Source text that was synthesized
audio_base64 audio_base64: string; Audio data as base64 string (survives JSON/IPC serialization)
format format: string; Audio format
duration_seconds? duration_seconds?: number; Duration in seconds (if available from TTS provider)
characters_used? characters_used?: number; Characters used for this chunk

AudioStreamCompleteEvent interface

📍 src/domain/entities/StreamEvent.ts:312

Audio stream complete - all TTS chunks have been processed

Properties
Property Type Description
type type: StreamEventType.AUDIO_STREAM_COMPLETE; -
total_chunks total_chunks: number; -
total_characters total_characters: number; -
total_duration_seconds? total_duration_seconds?: number; -

CompactionEvent interface

📍 src/domain/entities/StreamEvent.ts:237

Encrypted compaction state emitted by the provider. Preserve this item for stateless continuation replay; the content is intentionally opaque.

Properties
Property Type Description
type type: StreamEventType.COMPACTION; -
item_id item_id: string; -
output_index output_index: number; -
encrypted_content encrypted_content: string; -
content? `content?: string null;`
signature? `signature?: string null;`
provider_metadata? provider_metadata?: Record<string, unknown>; Opaque provider fields that must be replayed verbatim.
sequence_number sequence_number: number; -

ErrorEvent interface

📍 src/domain/entities/StreamEvent.ts:264

Error event

Properties
Property Type Description
type type: StreamEventType.ERROR; -
error `error: {
type: string;
message: string;
code?: string;

};| - | |recoverable|recoverable: boolean;` | - |


IStreamingSpeechToTextProvider interface

📍 src/domain/interfaces/IAudioProvider.ts:240

Opt-in extension implemented by providers with a live STT WebSocket API.

Methods

supportsStreaming()

typescript
supportsStreaming(): boolean;

Returns: boolean

transcribeStream()

typescript
transcribeStream(options: STTStreamOptions): AsyncIterableIterator<STTStreamEvent>;

Parameters:

  • options: STTStreamOptions

Returns: AsyncIterableIterator<STTStreamEvent>


IStreamingTextToSpeechProvider interface

📍 src/domain/interfaces/IAudioProvider.ts:91

Streaming Text-to-Speech provider interface (opt-in extension) Providers that support chunked transfer implement this alongside ITextToSpeechProvider.

Methods

supportsStreaming()

Check if streaming is supported for the given format

typescript
supportsStreaming(format?: AudioFormat): boolean;

Parameters:

  • format: AudioFormat | undefined (optional)

Returns: boolean

synthesizeStream()

Stream TTS audio chunks as they arrive from the API

typescript
synthesizeStream(options: TTSOptions): AsyncIterableIterator<TTSStreamChunk>;

Parameters:

  • options: TTSOptions

Returns: AsyncIterableIterator<TTSStreamChunk>


IterationCompleteEvent interface

📍 src/domain/entities/StreamEvent.ts:155

Iteration complete - end of agentic loop iteration

Properties
Property Type Description
loop? loop?: import('./AgentLoop.js').AgentLoopDiagnostics; Optional managed-loop progress, without changing event discriminants.
type type: StreamEventType.ITERATION_COMPLETE; -
iteration iteration: number; -
tool_calls_count tool_calls_count: number; -
has_more_iterations has_more_iterations: boolean; -

OutputTextDeltaEvent interface

📍 src/domain/entities/StreamEvent.ts:65

Text delta - incremental text output

Properties
Property Type Description
type type: StreamEventType.OUTPUT_TEXT_DELTA; -
item_id item_id: string; -
output_index output_index: number; -
content_index content_index: number; -
delta delta: string; -
sequence_number sequence_number: number; -

OutputTextDoneEvent interface

📍 src/domain/entities/StreamEvent.ts:77

Text output complete for this item

Properties
Property Type Description
type type: StreamEventType.OUTPUT_TEXT_DONE; -
item_id item_id: string; -
output_index output_index: number; -
text text: string; -

ProviderStateEvent interface

📍 src/domain/entities/StreamEvent.ts:252

Opaque provider-owned block that must be replayed on the next request.

Properties
Property Type Description
type type: StreamEventType.PROVIDER_STATE; -
item_id item_id: string; -
output_index output_index: number; -
provider provider: string; -
data data: Record<string, unknown>; -
sequence_number sequence_number: number; -

ReasoningDeltaEvent interface

📍 src/domain/entities/StreamEvent.ts:205

Reasoning/thinking delta - incremental reasoning output

Properties
Property Type Description
type type: StreamEventType.REASONING_DELTA; -
item_id item_id: string; -
output_index? output_index?: number; Provider output position for ordered replay.
content_index? content_index?: number; -
delta delta: string; -
sequence_number sequence_number: number; -

ReasoningDoneEvent interface

📍 src/domain/entities/StreamEvent.ts:218

Reasoning/thinking complete for this item

Properties
Property Type Description
type type: StreamEventType.REASONING_DONE; -
item_id item_id: string; -
output_index? output_index?: number; Provider output position for ordered replay.
sequence_number? sequence_number?: number; -
thinking thinking: string; -
signature? signature?: string; Provider signature required when replaying Anthropic thinking blocks.
encrypted_content? encrypted_content?: string; Opaque OpenAI/xAI reasoning state required for stateless continuation.
effort? effort?: import('../interfaces/ITextProvider.js').ReasoningEffort; Provider-reported reasoning effort, when present.

ResponseCompleteEvent interface

📍 src/domain/entities/StreamEvent.ts:167

Response complete - final event

Properties
Property Type Description
routing? routing?: import('../../core/model-execution/types.js').ModelRoutingDiagnostics; Optional managed routing decision, without a new stream event kind.
loop? loop?: import('./AgentLoop.js').AgentLoopDiagnostics; Optional managed-loop verdict; provider status keeps its existing meaning.
type type: StreamEventType.RESPONSE_COMPLETE; -
status `status: 'completed' 'incomplete'
usage usage: TokenUsage; -
iterations iterations: number; -
duration_ms? duration_ms?: number; -
stop_reason? stop_reason?: string; Raw provider stop reason for diagnostics (e.g., 'end_turn', 'max_tokens', 'SAFETY')
continuation_token? continuation_token?: string; Opaque provider token used to resume an incomplete long decode.
stop_details? stop_details?: ProviderStopDetails; Structured detail accompanying a terminal stop reason, when the provider
supplies one. Anthropic populates this only for stop_reason: 'refusal'
({ type: 'refusal', category, explanation }) — the category names which
safety classifier fired (e.g. 'cyber', 'bio'). Surfaced in logs so a refusal
is diagnosable rather than an opaque empty response.

ResponseCreatedEvent interface

📍 src/domain/entities/StreamEvent.ts:49

Response created - first event in stream

Properties
Property Type Description
type type: StreamEventType.RESPONSE_CREATED; -
model model: string; -
created_at created_at: number; -

ResponseInProgressEvent interface

📍 src/domain/entities/StreamEvent.ts:58

Response in progress

Properties
Property Type Description
type type: StreamEventType.RESPONSE_IN_PROGRESS; -

StreamOutputPosition interface

📍 src/domain/entities/StreamState.ts:23

Properties
Property Type Description
outputIndex? outputIndex?: number; -
contentIndex? contentIndex?: number; -
sequenceNumber? sequenceNumber?: number; -

VoiceStreamConfig interface

📍 src/capabilities/speech/types.ts:63

Configuration for VoiceStream

Properties
Property Type Description
ttsConnector `ttsConnector: string Connector;`
ttsModel? ttsModel?: string; TTS model (e.g., 'tts-1-hd', 'gpt-4o-mini-tts')
voice? voice?: string; Voice ID (e.g., 'nova', 'alloy')
format? format?: AudioFormat; Audio output format. Default: 'mp3'
speed? speed?: number; Speech speed (0.25 to 4.0). Default: 1.0
chunkingStrategy? chunkingStrategy?: IChunkingStrategy; Custom chunking strategy. Default: SentenceChunkingStrategy
chunkingOptions? chunkingOptions?: ChunkingOptions; Options for default chunking strategy (ignored if chunkingStrategy provided)
maxConcurrentTTS? maxConcurrentTTS?: number; Maximum concurrent TTS synthesis requests. Default: 2
maxQueuedChunks? maxQueuedChunks?: number; Maximum queued chunks waiting for TTS.
When full, wrap() awaits a free slot (lossless backpressure).
Default: 5
vendorOptions? vendorOptions?: Record<string, unknown>; Vendor-specific TTS options passthrough
streaming? streaming?: boolean; Enable streaming TTS. When true, audio chunks are yielded as they arrive
from the API instead of buffering the entire response. Best with format 'pcm'.
Default: false

VoiceStreamEvents interface

📍 src/capabilities/speech/types.ts:113

Events emitted by VoiceStream via EventEmitter

Properties
Property Type Description
'audio:ready' 'audio:ready': (data: { chunkIndex: number; text: string; durationSeconds?: number }) => void; -
'audio:error' 'audio:error': (data: { chunkIndex: number; text: string; error: Error }) => void; -
'audio:complete' 'audio:complete': (data: { totalChunks: number; totalDurationSeconds?: number }) => void; -
'audio:interrupted' 'audio:interrupted': (data: { pendingChunks: number }) => void; -

StreamEventType enum

📍 src/domain/entities/StreamEvent.ts:13

Stream event type enum

Properties
Property Type Description
RESPONSE_CREATED response.created -
RESPONSE_IN_PROGRESS response.in_progress -
OUTPUT_TEXT_DELTA response.output_text.delta -
OUTPUT_TEXT_DONE response.output_text.done -
TOOL_CALL_START response.tool_call.start -
TOOL_CALL_ARGUMENTS_DELTA response.tool_call_arguments.delta -
TOOL_CALL_ARGUMENTS_DONE response.tool_call_arguments.done -
TOOL_EXECUTION_START response.tool_execution.start -
TOOL_EXECUTION_DONE response.tool_execution.done -
ITERATION_COMPLETE response.iteration.complete -
REASONING_DELTA response.reasoning.delta -
REASONING_DONE response.reasoning.done -
COMPACTION response.compaction -
PROVIDER_STATE response.provider_state -
RESPONSE_COMPLETE response.complete -
RETRY response.retry -
ERROR response.error -
AUDIO_CHUNK_READY response.audio_chunk.ready -
AUDIO_CHUNK_ERROR response.audio_chunk.error -
AUDIO_STREAM_COMPLETE response.audio_stream.complete -

OrderedStreamOutputEntry type

📍 src/domain/entities/StreamState.ts:29

typescript
type OrderedStreamOutputEntry = | {
      kind: 'text';
      itemId: string;
      outputIndex?: number;
      contentIndex?: number;
      text: string;
    }
  | {
      kind: 'reasoning';
      itemId: string;
      outputIndex?: number;
      thinking: string;
      signature?: string;
      encryptedContent?: string;
      effort?: import('../interfaces/ITextProvider.js').ReasoningEffort;
    }
  | { kind: 'compaction'; itemId: string; outputIndex?: number; item: CompactionItem }
  | {
      kind: 'provider_state';
      itemId: string;
      outputIndex?: number;
      state: ProviderStateContent;
    }
  | {
      kind: 'tool_call';
      itemId: string;
      outputIndex?: number;
      toolCallId: string;
      toolName: string;
      arguments: string;
      toolType?: 'function' | 'custom';
      async?: boolean;
    }

StreamEvent type

📍 src/domain/entities/StreamEvent.ts:323

Union type of all stream events Discriminated by 'type' field for type narrowing

typescript
type StreamEvent = | ResponseCreatedEvent
  | ResponseInProgressEvent
  | OutputTextDeltaEvent
  | OutputTextDoneEvent
  | ReasoningDeltaEvent
  | ReasoningDoneEvent
  | CompactionEvent
  | ProviderStateEvent
  | ToolCallStartEvent
  | ToolCallArgumentsDeltaEvent
  | ToolCallArgumentsDoneEvent
  | ToolExecutionStartEvent
  | ToolExecutionDoneEvent
  | IterationCompleteEvent
  | ResponseCompleteEvent
  | RetryEvent
  | ErrorEvent
  | AudioChunkReadyEvent
  | AudioChunkErrorEvent
  | AudioStreamCompleteEvent

isAudioChunkError function

📍 src/domain/entities/StreamEvent.ts:402

typescript
export function isAudioChunkError(event: StreamEvent): event is AudioChunkErrorEvent

isAudioChunkReady function

📍 src/domain/entities/StreamEvent.ts:398

typescript
export function isAudioChunkReady(event: StreamEvent): event is AudioChunkReadyEvent

isAudioStreamComplete function

📍 src/domain/entities/StreamEvent.ts:406

typescript
export function isAudioStreamComplete(event: StreamEvent): event is AudioStreamCompleteEvent

isCompaction function

📍 src/domain/entities/StreamEvent.ts:386

typescript
export function isCompaction(event: StreamEvent): event is CompactionEvent

isErrorEvent function

📍 src/domain/entities/StreamEvent.ts:394

typescript
export function isErrorEvent(event: StreamEvent): event is ErrorEvent

isOutputTextDelta function

📍 src/domain/entities/StreamEvent.ts:358

Type guards for specific events

typescript
export function isOutputTextDelta(event: StreamEvent): event is OutputTextDeltaEvent

isReasoningDelta function

📍 src/domain/entities/StreamEvent.ts:378

typescript
export function isReasoningDelta(event: StreamEvent): event is ReasoningDeltaEvent

isReasoningDone function

📍 src/domain/entities/StreamEvent.ts:382

typescript
export function isReasoningDone(event: StreamEvent): event is ReasoningDoneEvent

isResponseComplete function

📍 src/domain/entities/StreamEvent.ts:390

typescript
export function isResponseComplete(event: StreamEvent): event is ResponseCompleteEvent

isStreamEvent function

📍 src/domain/entities/StreamEvent.ts:348

Type guard to check if event is a specific type

typescript
export function isStreamEvent<T extends StreamEvent>(
  event: StreamEvent,
  type: StreamEventType
): event is T

Documentation snapshot · 2026-11-02Suggest a correction ↗

Search documentation

Type to search the v2 documentation.