AI Stream Adapter
The StreamAdapter contract behind AI actions.
ai has no default adapter — it stays unregistered until you pass one:
Prop
Type
interface AiRequest {
action: string;
prompt: string;
context: string;
scope: "cursor" | "selection" | "block";
}
interface StreamContext {
signal: AbortSignal;
}useSlashEditor({
blockKit: {
ai: { adapter: yourStreamAdapter },
},
});Actions and contexts
defaultAiActions contains slash, selection, and block actions. Custom actions declare their
available surfaces through contexts: ["slash", "selection", "block"]. The adapter is stored on
the editor, so slash, bubble-toolbar, and block-handle actions use the same backend.
Selection and block actions insert a transient result below their source. The node view offers
Replace (mapped source range) and Insert below; if the source was deleted meanwhile, Replace
falls back to Insert below.
Lifecycle
runAiAction inserts a transient node and starts streaming; retryAiAction(id) replays the last
request from scratch; acceptAiAction(id, { mode }) turns the result into regular paragraphs;
discardAiAction(id) removes the node and aborts an in-flight stream. PendingAiRegistry keeps
successful entries around for Try again and drops them after accept/discard.