@nuwa-ai/ui-kit gives you a React hook (useNuwa) and a context provider (NuwaProvider) to talk to the Nuwa Client from your Cap UI. With it you can send prompts, persist UI state per chat thread, stream AI output, add selections, and manage iframe height/theme.
Connect To The Client
Wrap your UI withNuwaProvider, then call useNuwa() inside to access the nuwa client instance and connection state.
For all props and return types, see: NuwaProvider and useNuwa
NuwaProvider
NuwaProvider sets up the client connection and exposes it via context.
- automatically connects to the Nuwa Client
- provides a
nuwaclient instance for calling Nuwa Client functions - optional
autoHeightresizes the parent iframe to fit your content - syncs light/dark
themefrom the Nuwa Client to your UI wrapper
Send Prompt
Send a message to the current chat thread withnuwa.sendPrompt(message)
See full method signature
UI State
Persist and retrieve UI state per chat thread withnuwa.saveState() and nuwa.getState(). You can save UI state at any time, as any object types. When the user returns to the same chat thread, your latest saved state is delivered back to the UI.
See full method signature
You can save any object types as UI state but you need to make sure your UI can handle the state object. For example, if you save a state object with a property
title, you need to make sure your UI can handle the title property.AI Stream
Stream AI output and update the UI incrementally.nuwa.createAIStream({ prompt, capId? }) -> StreamHandleawait handle.execute({ onChunk?, onError? }) -> { result, error }handle.abort()to cancel; inspecthandle.status | error | result
This function only supports streaming text-based LLM output at the moment.
Add Selection
Add a selection (label + message) to parent UI. The selection message is provided to the AI as part of the system prompt. You can set it with the prompt variable{{artifact_selections}} in the Cap’s prompt field.
nuwa.addSelection(label: string, message: string | object): Promise<void>
Height And Theme
NuwaProvider with autoHeight keeps your iframe fully visible. You can also set height manually when needed.
- Auto height:
<NuwaProvider autoHeight>(enabled by default) - Manual:
nuwa.setHeight(pxOrCss): Promise<void>
See Also
MCP UI
Return UI resource from MCP tools
Artifact UI
Dedicated panel with your Cap UI
UI Kit
UI Kit specifications

