/** * useStream Hook * * React hook for generic text streaming with state management. * * @module */ /** * Stream hook options. */ export interface UseStreamOptions { /** Called for each chunk */ onChunk?: (chunk: string) => void; /** Called when stream completes */ onComplete?: (fullText: string) => void; /** Called on error */ onError?: (error: Error) => void; /** Initial text value */ initialText?: string; } /** * Stream hook return value. */ export interface UseStreamReturn { /** Current streamed text */ text: string; /** Whether streaming is active */ isStreaming: boolean; /** Error if any */ error: Error | undefined; /** Start streaming from a response */ startStream: (response: Response) => Promise; /** Start streaming from a ReadableStream */ startReadableStream: (stream: ReadableStream) => Promise; /** Start streaming from an async iterable */ startAsyncIterable: (iterable: AsyncIterable) => Promise; /** Stop streaming */ stop: () => void; /** Reset state */ reset: () => void; /** Manually set text */ setText: (text: string) => void; } /** * useStream - React hook for generic text streaming. * * Provides state management for streaming text from various sources * including fetch responses, ReadableStreams, and async iterables. * * @example * ```tsx * import { useStream } from 'ai.matey.react.hooks'; * * function StreamingComponent() { * const { text, isStreaming, startStream, stop } = useStream({ * onComplete: (fullText) => console.log('Completed:', fullText), * }); * * const handleClick = async () => { * const response = await fetch('/api/stream'); * await startStream(response); * }; * * return ( *
* * *
{text}
*
* ); * } * ``` */ export declare function useStream(options?: UseStreamOptions): UseStreamReturn; //# sourceMappingURL=use-stream.d.ts.map