/** * Tiered timeouts (1.38.1, design/17 §5B). The task-level `timeoutSec` only bounds the *whole* run; * it can't tell apart a gateway that never accepts the connection from one that accepts it, opens the * SSE stream, then hangs forever without emitting a token (the most common gateway-stall symptom). * Two finer levels close that gap, each retryable as a transient `network` failure: * * - **connect**: `fetch` hasn't returned response headers in time. * - **first-token**: the SSE stream is open but no content delta has arrived (see brain read loops). * * Both default to `undefined` (disabled) so existing behavior is unchanged. */ export interface BrainTimeoutConfig { /** Abort the request if `fetch` doesn't return response headers within this many ms. Retryable. */ connectTimeoutMs?: number; /** * After the stream opens, cancel it if no content delta (text / thinking / tool input) arrives * within this many ms → `BrainError("network", "first-token timeout")`. For reasoning models the * **first thinking delta also counts** as the first token, so a long-thinking model isn't killed * for being slow to its first *visible* word (design/17 O5). */ firstTokenTimeoutMs?: number; /** * **Idle / mid-stream stall watchdog** (1.40.1, design/24 — gap found in the Claude Code source study). * After the first delta, re-armed on every delta; if the stream then goes silent for this many ms * (a gateway that hung mid-output) → `reader.cancel()` + `BrainError("network", "stream idle timeout")`. * Complements `firstTokenTimeoutMs`: that one tolerates a long *first* token (reasoning), this one * catches a stall *after* output has started, where a healthy stream emits steadily. Default off. */ idleTimeoutMs?: number; } /** * A per-fetch-attempt abort controller that fires on a connect timeout while still forwarding an * outer (task) abort. The returned `signal` governs the **whole** request including the streamed body * — so once headers arrive, call `clearTimer()` (NOT `dispose()`) to stop the connect timer while * keeping the outer-abort link alive for the body read; call `dispose()` only when the request is * fully done or being discarded. */ export declare function makeConnectController(connectTimeoutMs: number | undefined, outerSignal: AbortSignal | undefined): { signal: AbortSignal; timedOut: () => boolean; clearTimer: () => void; dispose: () => void; }; //# sourceMappingURL=timeout.d.ts.map