AI SDK RSCcreateAI

createAI

Creates a client-server context provider that can be used to wrap parts of your application tree to easily manage both UI and AI states of your application.

Import

import { createAI } from "ai/rsc"

Object Parameter

actions:

Record<string, Action>
Server side actions that can be called from the client.

initialAIState:

any
Initial AI state to be used in the client.

initialUIState:

any
Initial UI state to be used in the client.

onGetUIState:

() => UIState
is called during SSR to compare and update UI state.

onSetAIState:

(Event) => void
is triggered whenever an update() or done() is called by the mutable AI state in your action, so you can safely store your AI state in the database.
Event

state:

AIState
The resulting AI state after the update.

done:

boolean
Whether the AI state updates have been finalized or not.

Returns

It returns an <AI> context provider.

Examples