export declare function getProviderStreamIdleTimeoutFallbackMs(provider: string): number | undefined; export declare function isGrokModelId(modelId: string | undefined): boolean; export declare function getProviderFirstEventTimeoutFallbackMs(provider: string): number | undefined; /** * Returns the idle timeout used for provider streaming transports. * * `GJC_OPENAI_STREAM_IDLE_TIMEOUT_MS` is honored first; `PI_OPENAI_STREAM_IDLE_TIMEOUT_MS` is a backward-compatible alias. * Set `PI_STREAM_IDLE_TIMEOUT_MS=0` to disable the watchdog. * * Providers that legitimately stream much slower than the global default can pass * `fallbackMs` to widen the floor used when neither env var nor caller option is set. * Caller options still take precedence; env overrides still trump the fallback. */ export declare function getStreamIdleTimeoutMs(fallbackMs?: number): number | undefined; /** * Returns the idle timeout used for OpenAI-family streaming transports. * * Honors `GJC_OPENAI_STREAM_IDLE_TIMEOUT_MS` first (`PI_OPENAI_STREAM_IDLE_TIMEOUT_MS` is the legacy alias). Set `=0` to disable. * When `provider` is given, long-reasoning hosts (xAI Grok and Grok Build) use that floor instead of the 120s default. * Grok models reached through other OpenAI-compatible hosts (`openrouter/x-ai/grok-*`, kilo, litellm, …) get the * same floor keyed on the model id, because long-reasoning silence is a property of the model (#4797). */ export declare function getOpenAIStreamIdleTimeoutMs(provider?: string, modelId?: string): number | undefined; /** * Returns the timeout used while waiting for the first stream event. * The first token can legitimately take longer than later inter-event gaps, * so the default never undershoots the steady-state idle timeout. * * Set `PI_STREAM_FIRST_EVENT_TIMEOUT_MS=0` to disable the watchdog. * * Providers whose first response can legitimately take longer (heavy reasoning, * slow cold-start proxies) can pass `fallbackMs` to widen the floor used when * neither env var nor caller option is set. Caller options still take precedence; * env overrides still trump the fallback. */ export declare function getStreamFirstEventTimeoutMs(idleTimeoutMs?: number, fallbackMs?: number): number | undefined; /** * Resolves the OpenAI SDK client `timeout` so stalled-before-headers requests are * bounded by the same first-event window the transport watchdog uses after * `create()` returns. Without this, providers that only arm * `iterateWithIdleTimeout` post-setup can wait the full SDK default (10 minutes * per attempt) before any provider-owned watchdog exists. * * - Explicit `0` disables the request timeout (the SDK treats `timeout: 0` as an * immediate failure, so callers that disable the first-event watchdog must not * pass a timeout). * - Providers with a first-event fallback (Alibaba, Kimi) honor an explicit * nonzero override as-is, even when shorter than the fallback. * - Other providers floor an explicit override at the env/default first-event * window so a short post-connect first-event budget cannot kill legitimate * slow setup. */ export declare function resolveOpenAISdkRequestTimeoutMs(provider: string, streamFirstEventTimeoutOverride?: number, modelId?: string): number | undefined; /** * Resolves the Anthropic SDK client `timeout` so stalled-before-headers requests * are bounded. The Anthropic first-event watchdog deliberately arms only once * response headers have arrived (setup latency must not consume the first-event * budget), which left the connect/headers phase governed solely by the SDK * default of 10 minutes per attempt — multiplied by SDK-internal retries, a * connection that silently died right after a completed tool call could spin * with no user-visible error for the better part of an hour. * * - Explicit `0` disables the request timeout, matching a disabled first-event * watchdog. * - An explicit nonzero override is floored at the env/default first-event * window (which itself never undershoots the provider idle window) so a short * post-connect first-event budget cannot kill legitimate slow setup. */ export declare function resolveAnthropicSdkRequestTimeoutMs(provider: string, streamFirstEventTimeoutOverride?: number, streamIdleTimeoutOverride?: number): number | undefined; export type Watchdog = NodeJS.Timeout | undefined; export interface FirstEventTimeoutFacts { requestBytes?: number; firstEventElapsedMs?: number; firstEventTimeoutMs?: number; endpointClass?: "canonical" | "custom"; retryMaxAttempts?: number; } export declare class FirstEventTimeoutError extends Error { readonly providerCode = "stream_first_event_timeout"; readonly requestBytes?: number; readonly firstEventElapsedMs?: number; readonly firstEventTimeoutMs?: number; readonly endpointClass?: "canonical" | "custom"; readonly retryMaxAttempts?: number; constructor(message: string, facts?: FirstEventTimeoutFacts); } /** * Starts a watchdog that aborts a request if no first stream event arrives in time. * Call `markFirstEventReceived()` as soon as the first event is observed. */ export declare function createWatchdog(timeoutMs: number | undefined, onTimeout: () => void): Watchdog; export interface IdleTimeoutIteratorOptions { watchdog?: Watchdog; idleTimeoutMs?: number; firstItemTimeoutMs?: number; errorMessage: string; firstItemErrorMessage?: string; onIdle?: () => void; onFirstItemTimeout?: () => void; /** * Optional semantic-progress predicate. Non-progress items are still yielded, * but they do not reset the idle deadline. This prevents provider * keepalive/no-op events from keeping a stalled tool call alive forever. */ isProgressItem?: (item: unknown) => boolean; /** * Cancel iteration as soon as this signal aborts. Required for caller-driven * cancellation (ESC) when the underlying transport does not surface signal * aborts to the iterator (HTTP/2 proxies, native sockets, mocked fetch). * Without this, the consumer sleeps on iterator.next() until the idle/first * -event watchdog fires — observable as the issue #912 "Working… forever" * symptom on the github-copilot provider. */ abortSignal?: AbortSignal; } /** * Yields items from an async iterable while enforcing a maximum idle gap between items. * * The first item may use a shorter timeout so stuck requests can be aborted and retried * before any user-visible content has streamed. */ export declare function iterateWithIdleTimeout(iterable: AsyncIterable, options: IdleTimeoutIteratorOptions): AsyncGenerator;