import type { StreamSession } from "./session.js";
import type { Tool } from "../../agent/tools2/types.js";
import type { AsyncIterableStream, TextStreamPart } from "ai";
/**
 * 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
 * - 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
 * @returns A managed stream with lifecycle hooks
 */
export declare function createManagedStream<T extends TextStreamPart<Record<string, Tool>>>(source: AsyncIterableStream<T>, session: StreamSession): AsyncIterableStream<T>;
//# sourceMappingURL=managed-stream.d.ts.map