export type JSONValue = string | number | boolean | JSONObject | JSONArray; interface JSONObject { [x: string]: JSONValue | undefined; } interface JSONArray extends Array {} export type AIAction = (...args: T[]) => Promise; export type AIActions = Record>; export type ServerWrappedAction = ( aiState: T, ...args: unknown[] ) => Promise<[Promise, unknown]>; export type ServerWrappedActions = Record< string, ServerWrappedAction >; export type InternalAIProviderProps = { children: React.ReactNode; initialUIState: UIState; initialAIState: AIState; initialAIStatePatch: undefined | Promise; wrappedActions: ServerWrappedActions; wrappedSyncUIState?: ServerWrappedAction; }; export type AIProviderProps = { children: React.ReactNode; initialAIState?: AIState; initialUIState?: UIState; /** $ActionTypes is only added for type inference and is never used at runtime **/ $ActionTypes?: Actions; }; export type AIProvider = ( props: AIProviderProps, ) => Promise; export type InferAIState = T extends AIProvider ? AIState : Fallback; export type InferUIState = T extends AIProvider ? UIState : Fallback; export type InferActions = T extends AIProvider ? Actions : Fallback; export type InternalAIStateStorageOptions = { onSetAIState?: OnSetAIState; }; export type OnSetAIState = ({ key, state, done, }: { key: string | number | symbol | undefined; state: S; done: boolean; }) => void | Promise; export type OnGetUIState = AIAction; export type ValueOrUpdater = T | ((current: T) => T); export type MutableAIState = { get: () => AIState; update: (newState: ValueOrUpdater) => void; done: ((newState: AIState) => void) | (() => void); };