/**
 * Data Stream Protocol Implementation
 * Implements a protocol for streaming structured data between server and client
 * Compatible with AI SDK's data stream format
 */
import type { CloseHandler, DataStreamResponseConfig, DataStreamWriter, DataStreamWriterConfig, SSEEventOptions } from "../../types/index.js";
/**
 * Creates a data stream writer
 */
export declare function createDataStreamWriter(config: DataStreamWriterConfig): DataStreamWriter;
/**
 * Configuration for DataStreamResponse
 */
/**
 * Data stream response class
 * Creates a streaming response with writer interface
 */
export declare class DataStreamResponse {
    private writer;
    private controller;
    private keepAliveTimer;
    private closed;
    private encoder;
    /** The readable stream */
    readonly stream: ReadableStream<Uint8Array>;
    /** Response headers */
    readonly headers: Record<string, string>;
    constructor(config?: DataStreamResponseConfig);
    /**
     * Get the data stream writer
     */
    getWriter(): DataStreamWriter;
    /**
     * Write text start event
     */
    writeTextStart(id: string): Promise<void>;
    /**
     * Write text delta event
     */
    writeTextDelta(id: string, delta: string): Promise<void>;
    /**
     * Write text end event
     */
    writeTextEnd(id: string): Promise<void>;
    /**
     * Write tool call event
     */
    writeToolCall(toolCall: {
        id: string;
        name: string;
        arguments: Record<string, unknown>;
    }): Promise<void>;
    /**
     * Write tool result event
     */
    writeToolResult(toolResult: {
        id: string;
        name: string;
        result: unknown;
    }): Promise<void>;
    /**
     * Write arbitrary data event
     */
    writeData(data: unknown): Promise<void>;
    /**
     * Write error event
     */
    writeError(error: {
        message: string;
        code?: string;
    }): Promise<void>;
    /**
     * Write finish event and close the stream
     */
    finish(options?: {
        reason?: string;
        usage?: {
            input: number;
            output: number;
            total: number;
        };
    }): Promise<void>;
    /**
     * Close the stream
     */
    close(): void;
    /**
     * Check if stream is closed
     */
    isClosed(): boolean;
    private closeStream;
}
/**
 * Create a data stream response
 */
export declare function createDataStreamResponse(config?: DataStreamResponseConfig): DataStreamResponse;
/**
 * Pipe an async iterable to a data stream response
 */
export declare function pipeAsyncIterableToDataStream(iterable: AsyncIterable<unknown>, response: DataStreamResponse, options?: {
    textId?: string;
    onChunk?: (chunk: unknown) => void;
    onError?: (error: Error) => void;
}): Promise<void>;
/**
 * Create SSE headers for streaming responses
 */
export declare function createSSEHeaders(additionalHeaders?: Record<string, string>): Record<string, string>;
/**
 * Create NDJSON headers for streaming responses
 */
export declare function createNDJSONHeaders(additionalHeaders?: Record<string, string>): Record<string, string>;
/**
 * SSE Event options for formatSSEEvent
 */
/**
 * Format a Server-Sent Events (SSE) message
 *
 * @param options SSE event options
 * @returns Formatted SSE string
 *
 * @example
 * ```typescript
 * formatSSEEvent({ data: "Hello world" });
 * // => "data: Hello world\n\n"
 *
 * formatSSEEvent({ event: "message", data: "Test" });
 * // => "event: message\ndata: Test\n\n"
 *
 * formatSSEEvent({ data: "Line 1\nLine 2" });
 * // => "data: Line 1\ndata: Line 2\n\n"
 * ```
 */
export declare function formatSSEEvent(options: SSEEventOptions): string;
/**
 * Base class for data stream writers
 * Provides common functionality for streaming data
 */
export declare abstract class BaseDataStreamWriter {
    protected closed: boolean;
    protected closeHandlers: CloseHandler[];
    /**
     * Check if the stream is closed
     */
    isClosed(): boolean;
    /**
     * Register a close handler
     */
    onClose(handler: CloseHandler): void;
    /**
     * Close the stream
     */
    close(): void;
    /**
     * Subclass-specific close implementation
     */
    protected abstract doClose(): void;
}
/**
 * WebStreamWriter - Writes SSE events to a Web Streams API ReadableStream
 *
 * Provides a simple interface for creating streaming responses that can be
 * consumed by browsers and other HTTP clients.
 *
 * @example
 * ```typescript
 * const writer = new WebStreamWriter();
 *
 * // Write data events
 * writer.writeData({ message: "Hello" });
 *
 * // Write error events
 * writer.writeError("Something went wrong");
 *
 * // Write done event and close
 * writer.writeDone();
 * writer.close();
 *
 * // Use the stream
 * return new Response(writer.stream, {
 *   headers: { "Content-Type": "text/event-stream" }
 * });
 * ```
 */
export declare class WebStreamWriter extends BaseDataStreamWriter {
    private controller;
    private encoder;
    /** The readable stream */
    readonly stream: ReadableStream<Uint8Array>;
    constructor();
    /**
     * Write raw text to the stream
     */
    private write;
    /**
     * Write a data event
     */
    writeData(data: unknown): void;
    /**
     * Write an error event
     */
    writeError(message: string): void;
    /**
     * Write a done event
     */
    writeDone(): void;
    /**
     * Write a custom event
     */
    writeEvent(eventType: string, data: unknown): void;
    protected doClose(): void;
}
