import type { AssistantMessage, StopReason } from "../types.js";
import type { AssistantMessageEventStream } from "./event-stream.js";
/** Shared state a stream handler operates on: the output message being built, the event stream it writes to, and an optional cancellation signal. */
export interface StreamHandlerContext {
    output: AssistantMessage;
    stream: AssistantMessageEventStream;
    signal?: AbortSignal;
}
/**
 * Base template for provider-specific stream handlers. A subclass supplies
 * {@link processStream} to map a provider's raw wire events onto the shared
 * assistant-message stream, then signals completion through {@link done} or
 * {@link fail}.
 */
export declare abstract class BaseStreamHandler<TContext extends StreamHandlerContext = StreamHandlerContext> {
    protected readonly context?: TContext | undefined;
    constructor(context?: TContext | undefined);
    /** Subclass-provided routine that reads the provider stream and emits events. */
    protected abstract processStream(): Promise<void>;
    /** Begin draining the backing provider stream. */
    run(): Promise<void>;
    /** Close the stream cleanly: record the stop reason, then emit the final `done` event. */
    protected done(reason: Extract<StopReason, "stop" | "length" | "toolUse">): void;
    /**
     * Close the stream after something went wrong. An aborted signal maps the
     * stop reason to `aborted`; anything else maps it to `error`. The error
     * text is recorded on the output before the terminal `error` event fires.
     */
    protected fail(error: unknown): void;
}
