/**
 * Real-time Streaming Support
 *
 * Provides dedicated streaming capabilities including Server-Sent Events (SSE),
 * WebSocket connections, and async iterators for real-time data streaming.
 *
 * @module @neurolink/client/streaming
 */
import type { ClientStreamEvent as StreamEvent, StreamCallbacks, ClientStreamResult as StreamResult, ApiError, WebSocketOptions, WebSocketState, WebSocketMessageHandler } from "../types/clientTypes.js";
import type { JsonObject, UnknownRecord } from "../types/common.js";
import type { ToolCall, ToolResult } from "../types/streamTypes.js";
/**
 * SSE connection options
 */
export type SSEConnectionOptions = {
    /** Request headers */
    headers?: Record<string, string>;
    /** Request credentials */
    credentials?: RequestCredentials;
    /** Reconnect on disconnect */
    autoReconnect?: boolean;
    /** Reconnect delay in milliseconds */
    reconnectDelay?: number;
    /** Maximum reconnect attempts */
    maxReconnectAttempts?: number;
    /** Signal for request cancellation */
    signal?: AbortSignal;
};
/**
 * SSE connection state
 */
export type SSEConnectionState = "connecting" | "connected" | "disconnected" | "reconnecting" | "error";
/**
 * Streaming request options
 */
export type StreamingRequestOptions = {
    /** Input text or data */
    input: {
        text: string;
    } & UnknownRecord;
    /** Provider to use */
    provider?: string;
    /** Model to use */
    model?: string;
    /** Temperature */
    temperature?: number;
    /** Maximum tokens */
    maxTokens?: number;
    /** System prompt */
    systemPrompt?: string;
    /** Enable tools */
    enableTools?: boolean;
    /** Context data */
    context?: UnknownRecord;
};
/**
 * Streaming event emitter interface
 */
export type StreamingEventEmitter = {
    on(event: "text", callback: (text: string) => void): void;
    on(event: "tool-call", callback: (toolCall: ToolCall) => void): void;
    on(event: "tool-result", callback: (toolResult: ToolResult) => void): void;
    on(event: "error", callback: (error: ApiError) => void): void;
    on(event: "done", callback: (result: StreamResult) => void): void;
    on(event: "metadata", callback: (metadata: JsonObject) => void): void;
    off(event: string, callback: (...args: unknown[]) => void): void;
    emit(event: string, ...args: unknown[]): void;
};
/**
 * Server-Sent Events (SSE) Client
 *
 * Provides a robust SSE connection with automatic reconnection,
 * event parsing, and async iterator support.
 *
 * @example Basic usage
 * ```typescript
 * const sse = new SSEClient('https://api.example.com/stream');
 *
 * sse.on('message', (data) => console.log(data));
 * sse.on('error', (error) => console.error(error));
 *
 * await sse.connect({ body: { prompt: 'Hello' } });
 * ```
 *
 * @example Async iterator usage
 * ```typescript
 * const sse = new SSEClient('https://api.example.com/stream');
 *
 * for await (const event of sse.events({ body: { prompt: 'Hello' } })) {
 *   if (event.type === 'text') {
 *     console.log(event.content);
 *   }
 * }
 * ```
 */
export declare class SSEClient {
    private url;
    private options;
    private state;
    private abortController;
    private reconnectAttempts;
    private eventHandlers;
    constructor(url: string, options?: SSEConnectionOptions);
    /**
     * Connect to SSE endpoint
     */
    connect(requestOptions?: {
        body?: unknown;
        headers?: Record<string, string>;
    }): Promise<void>;
    /**
     * Disconnect from SSE endpoint
     */
    disconnect(): void;
    /**
     * Process the SSE stream
     */
    private processStream;
    /**
     * Handle a stream event
     */
    private handleEvent;
    /**
     * Check if should attempt reconnection
     */
    private shouldReconnect;
    /**
     * Attempt reconnection
     */
    private reconnect;
    /**
     * Register event handler
     */
    on(event: string, callback: (...args: unknown[]) => void): void;
    /**
     * Remove event handler
     */
    off(event: string, callback: (...args: unknown[]) => void): void;
    /**
     * Emit event
     */
    private emit;
    /**
     * Get current connection state
     */
    getState(): SSEConnectionState;
    /**
     * Create async iterator for events
     *
     * @example
     * ```typescript
     * for await (const event of sse.events({ body: { prompt: 'Hello' } })) {
     *   console.log(event);
     * }
     * ```
     */
    events(requestOptions?: {
        body?: unknown;
        headers?: Record<string, string>;
    }): AsyncGenerator<StreamEvent, void, unknown>;
}
/**
 * WebSocket Streaming Client
 *
 * Provides WebSocket-based streaming with automatic reconnection,
 * heartbeat, and message handling.
 *
 * @example
 * ```typescript
 * const ws = new WebSocketStreamingClient({
 *   url: 'wss://api.example.com/ws',
 *   autoReconnect: true,
 * });
 *
 * ws.on('message', (data) => console.log(data));
 *
 * await ws.connect();
 * ws.send({ type: 'chat', content: 'Hello' });
 * ```
 */
export declare class WebSocketStreamingClient {
    private options;
    private ws;
    private state;
    private reconnectAttempts;
    private heartbeatInterval;
    private eventHandlers;
    constructor(options: WebSocketOptions);
    /**
     * Connect to WebSocket server
     */
    connect(): Promise<void>;
    /**
     * Disconnect from WebSocket server
     */
    disconnect(): void;
    /**
     * Send message to server
     */
    send(data: unknown): void;
    /**
     * Send message and wait for response
     */
    request<T>(data: unknown, timeout?: number): Promise<T>;
    /**
     * Handle incoming message
     */
    private handleMessage;
    /**
     * Start heartbeat
     */
    private startHeartbeat;
    /**
     * Stop heartbeat
     */
    private stopHeartbeat;
    /**
     * Attempt reconnection
     */
    private attemptReconnect;
    /**
     * Register event handler
     */
    on(event: string, callback: WebSocketMessageHandler): void;
    /**
     * Remove event handler
     */
    off(event: string, callback: WebSocketMessageHandler): void;
    /**
     * Emit event
     */
    private emit;
    /**
     * Get current connection state
     */
    getState(): WebSocketState;
    /**
     * Create async iterator for messages
     */
    messages(): AsyncGenerator<unknown, void, unknown>;
}
/**
 * Streaming client configuration
 */
export type StreamingClientConfig = {
    /** Base URL for the API */
    baseUrl: string;
    /** API key */
    apiKey?: string;
    /** Bearer token */
    token?: string;
    /** Default headers */
    headers?: Record<string, string>;
    /** Preferred transport: 'sse' or 'websocket' */
    transport?: "sse" | "websocket";
};
/**
 * Streaming Client Factory
 *
 * Creates streaming clients for real-time communication with NeuroLink API.
 *
 * @example SSE streaming
 * ```typescript
 * const client = createStreamingClient({
 *   baseUrl: 'https://api.example.com',
 *   apiKey: 'your-key',
 *   transport: 'sse',
 * });
 *
 * const result = await client.stream({
 *   input: { text: 'Hello' },
 *   callbacks: {
 *     onText: (text) => console.log(text),
 *   },
 * });
 * ```
 *
 * @example WebSocket streaming
 * ```typescript
 * const client = createStreamingClient({
 *   baseUrl: 'https://api.example.com',
 *   apiKey: 'your-key',
 *   transport: 'websocket',
 * });
 *
 * await client.connect();
 * const result = await client.stream({
 *   input: { text: 'Hello' },
 * });
 * ```
 */
export declare function createStreamingClient(config: StreamingClientConfig): {
    connect: () => Promise<void>;
    disconnect: () => void;
    stream: (options: StreamingRequestOptions & {
        callbacks?: StreamCallbacks;
    }) => Promise<StreamResult>;
    send: (data: unknown) => void;
    on: (event: string, callback: WebSocketMessageHandler) => void;
    off: (event: string, callback: WebSocketMessageHandler) => void;
    getState: () => WebSocketState;
};
/**
 * Create an async iterable from streaming response
 *
 * @example
 * ```typescript
 * const stream = createAsyncStream(fetch('/api/stream', { method: 'POST' }));
 *
 * for await (const event of stream) {
 *   console.log(event);
 * }
 * ```
 */
export declare function createAsyncStream(responsePromise: Promise<Response>): AsyncGenerator<StreamEvent, void, unknown>;
/**
 * Collect streaming events into a single result
 *
 * @example
 * ```typescript
 * const result = await collectStream(
 *   createAsyncStream(fetch('/api/stream', { method: 'POST' }))
 * );
 * console.log(result.content);
 * ```
 */
export declare function collectStream(stream: AsyncIterable<StreamEvent>): Promise<StreamResult>;
