Skip to main content
@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.
Inputs Construct-time options
object?
Returns
NuwaClient
Configured client instance

sendPrompt

Send a message to the parent client chat. Inputs
string
required
Text message to send
Returns
Promise<void>
Resolves when sent

setHeight

Set the UI iframe height in the Nuwa Client. Inputs
string | number
required
CSS size or number
Returns
Promise<void>
Resolves when applied

addSelection

Add a selection (label + message) to parent UI. Inputs
string
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.
Returns
Promise<void>
Resolves when added

saveState

Save state to the Nuwa Client. Inputs
any
State to save
Returns
Promise<void>
Resolves when applied

getState

Retrieve the state from the Nuwa Client. Inputs
any?
Retrieve the state
Returns
Promise<any>
Resolves when applied

createAIStream

Start a LLM stream controlled by nuwa client. Inputs Streaming request
object
required
Returns
StreamHandle
Control/observe the stream

StreamHandle.execute / abort

Run the stream and observe live chunks/errors. Inputs Optional callbacks
object?
Returns
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 properties
object
Returns
ReactElement
Rendered provider element

useNuwa

Access the client, theme, and connection status. Inputs
void
Hook takes no parameters
Returns
NuwaClient
Client instance
"light"|"dark"
Current theme
boolean
Connection state

MCP Transport

PostMessageMCPTransport (constructor)

A Transport for official MCP SDK over postMessage. Inputs Constructor options
object?
Returns
PostMessageMCPTransport
Configured transport

start / send / connect / disconnect

Transport lifecycle and messaging. Inputs
-
See individual methods
Returns
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. Inputs
string
required
Path relative to artifact origin
string?
Optional metadata
Returns
UIResource
Result for createUIResource
UIToolResult
Result for createUIToolResult