import { StreamConfig, StreamError, StreamState, UseStreamResult } from '../types';
/**
* Options for the useStream hook.
*/
export interface UseStreamOptions {
/**
* Boundary ID to monitor/control.
* If not provided, creates an unregistered stream interface.
*/
boundaryId?: string;
/**
* Stream configuration for auto-registration.
* If provided with boundaryId, the boundary will be automatically registered.
*/
config?: StreamConfig;
/**
* Auto-start streaming when the hook mounts.
* @default false
*/
autoStart?: boolean;
/**
* Callback when stream state changes.
*/
onStateChange?: (state: StreamState) => void;
/**
* Callback when stream completes.
*/
onComplete?: () => void;
/**
* Callback when stream errors.
*/
onError?: (error: StreamError) => void;
}
/**
* Core hook for stream control and monitoring.
*
* @description
* Provides a complete interface for interacting with a stream boundary,
* including state observation, lifecycle control, and progress tracking.
*
* Features:
* - Real-time state monitoring
* - Lifecycle control (start, pause, resume, abort)
* - Progress tracking (when determinable)
* - Error handling
* - Automatic cleanup on unmount
*
* @param boundaryIdOrOptions - Boundary ID string or options object
* @returns Stream control interface
*
* @example
* ```tsx
* // Simple usage with just boundary ID
* const stream = useStream('my-boundary');
*
* // Usage with options
* const stream = useStream({
* boundaryId: 'my-boundary',
* config: { priority: StreamPriority.High },
* autoStart: true,
* onComplete: () => console.log('Done!'),
* });
*
* // Control stream lifecycle
* stream.start();
* stream.pause();
* stream.resume();
* stream.abort('User cancelled');
* stream.reset();
* ```
*/
export declare function useStream(boundaryIdOrOptions?: string | UseStreamOptions): UseStreamResult;
/**
* Hook for monitoring multiple streams.
*
* @description
* Provides aggregated state for multiple stream boundaries,
* useful for tracking overall page streaming progress.
*
* @param boundaryIds - Array of boundary IDs to monitor
* @returns Aggregated stream information
*
* @example
* ```tsx
* function PageLoader() {
* const { allComplete, progress, states } = useMultipleStreams([
* 'header',
* 'main',
* 'sidebar',
* 'footer',
* ]);
*
* if (!allComplete) {
* return ;
* }
*
* return ;
* }
* ```
*/
export interface UseMultipleStreamsResult {
/** States for each boundary */
states: Map;
/** Whether all streams are complete */
allComplete: boolean;
/** Whether any stream has an error */
hasErrors: boolean;
/** Aggregate progress (0-1) */
progress: number;
/** Number of active streams */
activeCount: number;
/** Number of completed streams */
completedCount: number;
/** Start all streams */
startAll: () => void;
/** Abort all streams */
abortAll: (reason?: string) => void;
}
export declare function useMultipleStreams(boundaryIds: string[]): UseMultipleStreamsResult;
/**
* Hook for awaiting stream completion.
*
* @description
* Returns a promise that resolves when the stream completes
* or rejects when the stream errors.
*
* @param boundaryId - Boundary ID to await
* @returns Promise that resolves/rejects with stream result
*
* @example
* ```tsx
* function DataProcessor() {
* const awaitStream = useAwaitStream('data-stream');
*
* const handleProcess = async () => {
* try {
* await awaitStream();
* console.log('Stream completed, processing data...');
* } catch (error) {
* console.error('Stream failed:', error);
* }
* };
*
* return ;
* }
* ```
*/
export declare function useAwaitStream(boundaryId: string): () => Promise;