import type { AsyncIterableStream, TextStreamPart } from "ai";
import type { Tool } from "../../agent/tools2/types.js";
import type { IdleMonitor } from "./idle-monitor.js";
import type { StreamSession } from "./session.js";
/**
 * Creates a managed stream that wraps the source stream with lifecycle management.
 *
 * The managed stream:
 * - Emits "chunk" events for each chunk
 * - Throws errors from error chunks
 * - Races against idle monitor to detect stalled streams
 * - Finalizes the session on complete or cancel (but NOT on error - see below)
 *
 * IMPORTANT: This stream intentionally does NOT finalize the session on errors.
 * If you call session.finalize("error") here, the session becomes non-pending,
 * which means new managed streams created during retry will immediately close
 * (see the `!session.isPending()` check in pull).
 *
 * The retry logic in wrapWithRetry is responsible for finalizing the session
 * when all retries are exhausted. Don't be a hero and add finalization here.
 *
 * @param source - The source async iterable stream
 * @param session - The session to update with events
 * @param idleMonitor - Idle monitor to detect stalled streams
 * @returns A managed stream with lifecycle hooks
 */
export declare function createManagedStream<T extends TextStreamPart<Record<string, Tool>>>(source: AsyncIterableStream<T>, session: StreamSession, idleMonitor: IdleMonitor): AsyncIterableStream<T>;
//# sourceMappingURL=managed-stream.d.ts.map