export { useGenerator }; export type { UseGeneratorState, UseGeneratorOptions, GeneratorError }; type GeneratorError = { message: string; name?: string; stack?: string; cause?: unknown; }; type UseGeneratorOptions = { /** Called for each yielded value */ onValue?: (value: T) => void; /** Called when streaming starts */ onStart?: () => void; /** Called when streaming ends (whether completed, aborted, or errored) */ onEnd?: () => void; /** Called when an error occurs */ onError?: (error: GeneratorError) => void; }; type UseGeneratorState = { /** Values yielded by the current invocation (resets on each `invoke`) */ values: T[]; /** The most recently yielded value, or undefined if nothing yielded yet */ lastValue: T | undefined; /** Whether the generator is currently yielding values */ isStreaming: boolean; /** Error thrown during iteration, or null if no error */ error: GeneratorError | null; /** Abort the current generator early */ abort: () => void; /** Call the telefunction and start streaming */ invoke: (...args: Args) => void; }; /** * @experimental — DO NOT USE unless you reached out to a Telefunc maintainer — this component hook will break upon minor version releases. * * React hook for consuming a telefunction that returns an AsyncGenerator. * Call `invoke(args)` to start streaming, `abort()` to stop. * Cleans up automatically on unmount or when `invoke` is called again. * * @param fn - A telefunction that returns an `AsyncGenerator` * * @example * ```tsx * const { invoke, values, isStreaming } = useGenerator(onChat) * * * {values.map((msg, i) =>

{msg}

)} * ``` */ declare function useGenerator(fn: (...args: Args) => Promise>, options?: UseGeneratorOptions): UseGeneratorState;