import * as react_jsx_runtime from 'react/jsx-runtime'; declare const __internal_curr: unique symbol; declare const __internal_error: unique symbol; /** * StreamableValue is a value that can be streamed over the network via AI Actions. * To read the streamed values, use the `readStreamableValue` or `useStreamableValue` APIs. */ type StreamableValue = { [__internal_curr]?: T; [__internal_error]?: E; }; /** * `readStreamableValue` takes a streamable value created via the `createStreamableValue().value` API, * and returns an async iterator. * * ```js * // Inside your AI action: * * async function action() { * 'use server' * const streamable = createStreamableValue(); * * streamable.update(1); * streamable.update(2); * streamable.done(3); * // ... * return streamable.value; * } * ``` * * And to read the value: * * ```js * const streamableValue = await action() * for await (const v of readStreamableValue(streamableValue)) { * console.log(v) * } * ``` * * This logs out 1, 2, 3 on console. */ declare function readStreamableValue(streamableValue: StreamableValue): AsyncIterable; /** * `useStreamableValue` is a React hook that takes a streamable value created via the `createStreamableValue().value` API, * and returns the current value, error, and pending state. * * This is useful for consuming streamable values received from a component's props. For example: * * ```js * function MyComponent({ streamableValue }) { * const [data, error, pending] = useStreamableValue(streamableValue); * * if (pending) return
Loading...
; * if (error) return
Error: {error.message}
; * * return
Data: {data}
; * } * ``` */ declare function useStreamableValue(streamableValue?: StreamableValue): [data: T | undefined, error: Error | undefined, pending: boolean]; type ServerWrappedAction = (aiState: T, ...args: unknown[]) => Promise<[Promise, unknown]>; type ServerWrappedActions = Record>; type InternalAIProviderProps = { children: React.ReactNode; initialUIState: UIState; initialAIState: AIState; initialAIStatePatch: undefined | Promise; wrappedActions: ServerWrappedActions; wrappedSyncUIState?: ServerWrappedAction; }; type AIProviderProps = { children: React.ReactNode; initialAIState?: AIState; initialUIState?: UIState; /** $ActionTypes is only added for type inference and is never used at runtime **/ $ActionTypes?: Actions; }; type AIProvider = (props: AIProviderProps) => Promise; type InferAIState = T extends AIProvider ? AIState : Fallback; type InferUIState = T extends AIProvider ? UIState : Fallback; type InferActions = T extends AIProvider ? Actions : Fallback; type ValueOrUpdater = T | ((current: T) => T); declare function InternalAIProvider({ children, initialUIState, initialAIState, initialAIStatePatch, wrappedActions, wrappedSyncUIState, }: InternalAIProviderProps): react_jsx_runtime.JSX.Element; declare function useUIState(): [InferUIState, (v: InferUIState | ((v_: InferUIState) => InferUIState)) => void]; declare function useAIState(): [ InferAIState, (newState: ValueOrUpdater>) => void ]; declare function useAIState(key: keyof InferAIState): [ InferAIState[typeof key], (newState: ValueOrUpdater[typeof key]>) => void ]; declare function useActions(): InferActions; declare function useSyncUIState(): () => Promise; export { InternalAIProvider, readStreamableValue, useAIState, useActions, useStreamableValue, useSyncUIState, useUIState };