@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.object?
NuwaClient
Configured client instance
sendPrompt
Send a message to the parent client chat. Inputsstring
required
Text message to send
Promise<void>
Resolves when sent
setHeight
Set the UI iframe height in the Nuwa Client. Inputsstring | number
required
CSS size or number
Promise<void>
Resolves when applied
addSelection
Add a selection (label + message) to parent UI. Inputsstring
required
Selection title. This will be displayed as a badge in the user’s input.
string | object
required
Payload message. This will be provided to the AI as part of the system prompt.
Promise<void>
Resolves when added
saveState
Save state to the Nuwa Client. Inputsany
State to save
Promise<void>
Resolves when applied
getState
Retrieve the state from the Nuwa Client. Inputsany?
Retrieve the state
Promise<any>
Resolves when applied
createAIStream
Start a LLM stream controlled by nuwa client. Inputs Streaming requestobject
required
StreamHandle
Control/observe the stream
StreamHandle.execute / abort
Run the stream and observe live chunks/errors. Inputs Optional callbacksobject?
Promise
Final stream result and error (object with
result and error)void
Cancel the stream
React Helpers
NuwaProvider
Wrap your app and auto-manage connection and resizing. Inputs Provider propertiesobject
ReactElement
Rendered provider element
useNuwa
Access the client, theme, and connection status. Inputsvoid
Hook takes no parameters
NuwaClient
Client instance
"light"|"dark"
Current theme
boolean
Connection state
MCP Transport
PostMessageMCPTransport (constructor)
A Transport for official MCP SDK over postMessage. Inputs Constructor optionsobject?
PostMessageMCPTransport
Configured transport
start / send / connect / disconnect
Transport lifecycle and messaging. Inputs-
See individual methods
Promise<void>
Begin listening
Promise<void>
Send JSON-RPC message
Promise<void>
Connect to window
void
Tear down transport
boolean
Current status flags
UI Helpers
Return UI resources from MCP tools. Inputsstring
required
Path relative to artifact origin
string?
Optional metadata
UIResource
Result for createUIResource
UIToolResult
Result for createUIToolResult

