@nuwa-ai/ui-kit provides a NuwaClient class and a set of React hooks to help you build interactive UI for your Cap.
Example
Install
NuwaClient
NuwaClient is the main class that you can use to interact with the Nuwa Client. It provides a set of methods that you can use to interact with the Nuwa Client.
You can initialize a NuwaClient instance directly, or use the useNuwa hook to get a NuwaClient instance.
constructor
Create a NuwaClient for parent iframe communication.Configured client instance
sendPrompt
Send a message to the parent client chat. InputsText message to send
Resolves when sent
setHeight
Set the UI iframe height in the Nuwa Client. InputsCSS size or number
Resolves when applied
addSelection
Add a selection (label + message) to parent UI. InputsSelection title. This will be displayed as a badge in the user’s input.
Payload message. This will be provided to the AI as part of the system prompt.
Resolves when added
saveState
Save state to the Nuwa Client. InputsState to save
Resolves when applied
getState
Retrieve the state from the Nuwa Client. InputsRetrieve the state
Resolves when applied
createAIStream
Start a LLM stream controlled by nuwa client. Inputs Streaming requestControl/observe the stream
StreamHandle.execute / abort
Run the stream and observe live chunks/errors. Inputs Optional callbacksFinal stream result and error (object with
result and error)Cancel the stream
React Helpers
NuwaProvider
Wrap your app and auto-manage connection and resizing. Inputs Provider propertiesRendered provider element
useNuwa
Access the client, theme, and connection status. InputsHook takes no parameters
Client instance
Current theme
Connection state
MCP Transport
PostMessageMCPTransport (constructor)
A Transport for official MCP SDK over postMessage. Inputs Constructor optionsConfigured transport
start / send / connect / disconnect
Transport lifecycle and messaging. InputsSee individual methods
Begin listening
Send JSON-RPC message
Connect to window
Tear down transport
Current status flags
UI Helpers
Return UI resources from MCP tools. InputsPath relative to artifact origin
Optional metadata
Result for createUIResource
Result for createUIToolResult

