import type { ModelMessage } from "ai";
import type { Tool } from "../../agent/tools2/types.js";
import type { StepResult, FinalResult, StreamChunk } from "../interaction/provider.js";
import type { StreamSession } from "./session.js";
import type { ProviderInfo } from "./types.js";
export interface RequestPayload {
    system?: string;
    messages: ModelMessage[];
    tools?: Record<string, Tool>;
}
export interface StepStartPayload {
    stepNumber: number;
    activeTools?: string[];
}
export type StreamEvents = {
    chunk: [chunk: StreamChunk, session: StreamSession];
    retry: [
        error: unknown,
        attempt: number,
        delayMs: number,
        session: StreamSession
    ];
    fallback: [
        from: ProviderInfo,
        to: ProviderInfo,
        reason: "error" | "no_output",
        session: StreamSession
    ];
    "step:start": [step: StepStartPayload, session: StreamSession];
    "step:finish": [
        step: StepResult<Record<string, Tool>>,
        session: StreamSession
    ];
    "stream:finish": [
        result: FinalResult<Record<string, Tool>>,
        session: StreamSession
    ];
    "session:start": [session: StreamSession, request?: RequestPayload];
    "session:complete": [session: StreamSession];
    "session:error": [error: unknown, session: StreamSession];
    "session:abort": [session: StreamSession];
};
export type StreamEventName = keyof StreamEvents;
export type StreamEventHandler<K extends StreamEventName> = (...args: StreamEvents[K]) => void | Promise<void>;
/**
 * Type-safe event bus for stream lifecycle events.
 *
 * Observers subscribe to specific events and receive typed arguments.
 * Handlers are called in parallel, and errors in one handler don't affect others.
 *
 * @example
 * ```typescript
 * const events = new StreamEventBus();
 *
 * // Subscribe to events
 * const unsubscribe = events.on("chunk", (chunk, session) => {
 *   console.log(`Received chunk: ${chunk.type}`);
 * });
 *
 * // Emit events
 * await events.emit("chunk", myChunk, mySession);
 *
 * // Unsubscribe when done
 * unsubscribe();
 * ```
 */
export declare class StreamEventBus {
    private readonly listeners;
    on<K extends StreamEventName>(event: K, handler: StreamEventHandler<K>): () => void;
    emit<K extends StreamEventName>(event: K, ...args: StreamEvents[K]): Promise<void>;
    clear(): void;
}
//# sourceMappingURL=event-bus.d.ts.map