Skip to main content Module streaming Copy item path Source FallbackTriggeredError Error thrown after MAX_529_RETRIES consecutive 529 errors when a fallback
model is available. Matches TypeScript’s FallbackTriggeredError. SharedExecutorFn A clonable, thread-safe tool executor function wrapper.
Uses an async channel to dispatch tool execution. StallStats Tracks streaming stall statistics. StreamWatchdog Manages the stream idle timeout watchdog.
Matches TypeScript’s streamIdleTimer/streamIdleWarningTimer logic. StreamingResult Streaming result containing accumulated content, tool calls, and metadata.
Matches TypeScript’s partialMessage + newMessages + usage + cost accumulation. StreamingToolExecutor Executes tools as they stream in with concurrency control.
Rust port of TypeScript’s StreamingToolExecutor class. TrackedTool A tool being tracked by the streaming executor. ToolStatus Status of a tracked tool in the streaming executor. DEFAULT_STREAM_IDLE_TIMEOUT_MS Default streaming idle timeout in milliseconds (90 seconds) DEFAULT_STREAM_IDLE_WARNING_MS Default streaming idle warning threshold (half of timeout, 45 seconds) FLOOR_OUTPUT_TOKENS MAX_529_RETRIES Maximum consecutive 529 retries before triggering model fallback. STALL_THRESHOLD_MS Stall detection threshold in milliseconds (30 seconds) calculate_streaming_cost Calculate cost based on token usage and model.
Matches TypeScript’s cost tracking in message_delta. cleanup_stream Manages cleanup of stream resources to prevent memory leaks.
Matches TypeScript’s releaseStreamResources() + cleanupStream(). extract_fallback_error Extract fallback info from an AgentError, if it’s a FallbackTriggeredError. get_nonstreaming_fallback_timeout_ms Get the timeout for non-streaming fallback in milliseconds.
Matches TypeScript’s getNonstreamingFallbackTimeoutMs(). is_404_stream_creation_error Check if an error is a 404 during stream creation that should trigger
non-streaming fallback.
Matches TypeScript’s is404StreamCreationError check. is_429_only_error Check if an error is a 429 rate limit error specifically (NOT 529).
529 is server overload, 429 is client rate limit. They have different
retry semantics. This separates pure 429 from 529 which was being
caught by a broad “429” or “529” check.
Matches TypeScript’s is429OnlyError. is_529_error Check if an error is a 529 (server overload) error.
Matches TypeScript’s is529Error. is_api_timeout_error Check if an error is an API connection timeout. is_auth_error Check if an error is an authentication failure (401) that should trigger
client recreation / token refresh. is_fallback_triggered_error Check if an AgentError wraps a FallbackTriggeredError. is_nonstreaming_fallback_disabled Determines whether non-streaming fallback should be disabled.
Matches TypeScript’s disableFallback logic: is_stale_connection_error Check if an error is a stale connection (ECONNRESET/EPIPE) that should
trigger HTTP client recreation. Matches TypeScript’s isStaleConnectionError. is_user_abort_error Check if an error is a user-initiated abort.
Matches TypeScript’s APIUserAbortError handling. parse_max_tokens_context_overflow Parse a max-tokens-context-overflow API error (400).
Matches TypeScript’s parseMaxTokensContextOverflowError.
Example: “input length and max_tokens exceed context limit: 188059 + 20000 > 200000” release_stream_resources validate_stream_completion Validates that a stream completed properly.
Matches TypeScript’s check:
if (!partialMessage || (newMessages.length === 0 && !stopReason))
throw new Error(‘Stream ended without receiving any events’)