Skip to main content
@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 with NuwaProvider, 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 nuwa client instance for calling Nuwa Client functions
  • optional autoHeight resizes the parent iframe to fit your content
  • syncs light/dark theme from the Nuwa Client to your UI wrapper
Example with options:
See full provider API and option types

Send Prompt

Send a message to the current chat thread with nuwa.sendPrompt(message) See full method signature

UI State

Persist and retrieve UI state per chat thread with nuwa.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? }) -> StreamHandle
  • await handle.execute({ onChunk?, onError? }) -> { result, error }
  • handle.abort() to cancel; inspect handle.status | error | result
See full streaming API
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>
More details and types

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