Skip to main content
Two React components ship from @waniwani/chat. Pick based on who runs the chat backend: WaniwaniChat is the embed script as a React component. It renders the components the script mounts, takes every option WaniWani.chat.init() takes in overrides, and its ref has the same controls (open, sendMessage, track, …). By default it mounts the full chat inline, wherever you place it. With overrides.mode set to "composer" it renders only an input in your page, and the first message opens the chat panel over the page, as a centered modal or a sidebar on the right. "floating" renders the docked bar at the bottom of the window. See Composer, floating bar and sidebar. ChatEmbed always mounts inline.
Platform feature. Requires a Waniwani project token (wwp_...). Get one at app.waniwani.ai or read more about the Platform.

Install

Add the stylesheet to your app once (e.g. in _app.tsx or your root layout):
It styles the widget only. Its base reset applies inside the chat, so your page keeps its own headings, margins and line height.

WaniwaniChat

The hosted chat. Pass your project token and channel ID and it talks to app.waniwani.ai directly — no API route, no proxy, no backend work on your side.
The system prompt, welcome message, placeholder, suggestions, thread history and tool-call display are configured per channel in the dashboard, so business users can change them without a deploy. Theming has no dashboard equivalent — set it in code via overrides.appearance.

Sizing and placement

WaniwaniChat fills its parent. Put it wherever you want it and size the container:
To use it as a full-width page hero, give the wrapper the height you want and let the chat fill it. className is applied to the chat root if you’d rather style it directly. overrides.height ("600", "80vh", a bare number is pixels) sets the height instead, as data-height does. The chat sits in a wrapper that plays the part of the script’s [data-waniwani-embed] container. With an appearance.theme, it is a card with 16px corners (appearance.variables.borderRadius changes them), and appearance.variables.borderWidth, borderColor and boxShadow draw on it, as on the script.

Composer, floating bar and sidebar

overrides.mode picks the surface. The values and their behavior match the script’s data-mode. panelLayout sets the shape of the panel that composer and floating open: "modal" (default) is a centered card, "sidebar" is a full-height column on the right edge, --ww-sidebar-width wide. Phones show a full-screen sheet for both. An outline composer in a hero, opening a sidebar, with the visitor tied to your Amplitude device id:
The same page on the script tag is data-mode="composer" data-panel-layout="sidebar" data-composer-variant="outline" data-send-icon="right" data-theme="light". The composer and the panel are the same components in both, so the embed’s composer docs apply as written. Where your CSS goes:
  • The in-page composer renders inside your tree. --ww-composer-* and the other --ww-* properties reach it from any ancestor: a wrapper with a class, as above, or :root.
  • The panel renders at the end of <body>, outside your tree, so it sees only what you set on :root (or body). Put the --ww-* colors and font the panel should share there. overrides.appearance.variables reach the composer and the panel both.
  • className goes on the wrapper of the in-page composer. In floating mode nothing renders in place, so it is unused.
In composer and floating mode, open() on the ref opens the panel, and sendMessage opens it and sends, the same as the visitor sending from the composer. focus() lands on the in-page input while the panel is closed, and on the panel’s input once it is open. A press anywhere on the page outside the panel closes it, in both layouts. mode: "off" renders nothing, as on the script: WebMCP still publishes the site’s tools and the ref’s track / identify still work. welcome, headerActions, classNames and allowAttachments are React-only and apply to the inline chat. Changing mode on a mounted component remounts the chat.

Per-page overrides

overrides takes every option of WaniWani.chat.init(), with the same names, types and defaults. Its type is built from the script’s own config, so an option the script gains is a React option in the same release. The dashboard stays the source of truth for the channel; use overrides for a local tweak that doesn’t justify a separate channel:

Control the chat from your page

Pass a ref to drive the chat from anywhere else on the page: a call to action in your hero, a link in your navigation, a pricing row that asks about itself. The ref holds a ChatHandle.
Calls made before the chat has loaded its channel config are dropped, so wire the handle to a visitor’s click rather than calling it during the first render. On a page that the dashboard’s per-URL rules hide, the component renders nothing and the chat methods do nothing.

In a sidebar or drawer

Use panelLayout: "sidebar" with mode: "composer" or "floating", and open it from your own buttons through the ref:
open, close and toggle are optional on ChatHandle because ChatEmbed has no panel, hence the ?.().

Tracking from the host page

The same ChatHandle carries track and identify. identify takes two positional arguments, the user id first and optional traits second:
Both are present on WaniwaniChat only — the bare ChatEmbed primitive has no Waniwani credential to send events with. See Identify.

The page the visitor is on

From 0.24.1, WaniwaniChat sends the address of the current page with each message, and your agent is told which page the visitor is on. There is nothing to set up. The page the visitor is on shows what the agent gets and how to tell it what your pages are.

ChatEmbed

A bare-bones primitive for when you run the chat backend yourself. api is required and there is no default; pass any endpoint implementing the Vercel AI SDK chat protocol and the component handles the rest.
Reach for ChatEmbed only when self-hosting. If you’re using the Waniwani Platform, WaniwaniChat gives you the same UI plus dashboard configuration, visitor correlation, and tracking.
ChatEmbed also takes the look-and-feel props the script embed exposes as data-* attributes. WaniwaniChat takes menu, restartConfirm, suggestionsPosition, sendIcon and showTableToolbar through overrides. welcome.icon also accepts an image URL, rendered as the avatar’s welcome slot. A string counts as a URL when it starts with http:, https:, data: or blob:, or contains a / (so /bot.svg and ./bot.svg work). Any other string, such as "👋", renders as text, and an empty string renders no icon. For the part classes and tokens that style all of this, see Theming & customization. Both components accept a visitorId prop to override the anonymous id the widget generates with one you already track (a PostHog / Amplitude / Segment distinct id, your own cookie). Waniwani correlates its sessions and events to the same visitor your analytics sees, and your server-side MCP tools and flows read it back as context.waniwani.visitorId. Leave it unset to keep the auto-generated, localStorage-persisted id. visitorId accepts a string, or a resolver that returns one. The resolver may be sync or async, which is handy when your analytics SDK only exposes its id after it bootstraps:
A blank or failed result is ignored, so a not-ready id never wipes a good one. The value is read live on every request, so updating it applies to the next message. See Sessions for how the three correlation ids fit together.
For an expensive async resolver, pass a stable reference (useCallback) so it isn’t re-invoked on every render.

Attachments

ChatEmbed takes the documents module’s state as a prop, since it fetches no remote config of its own:
The composer offers a paperclip, a drop target and paste only while enabled is true, and the upload endpoint enforces the same flag. WaniwaniChat and the script embed read all of this from the dashboard, so they need none of it. See Documents for what an agent does with the files.

Authentication

headers goes out with every chat request, and document uploads reuse it, so one bearer usually covers both.
Set uploadHeaders when your upload endpoint takes a different credential than your chat endpoint. It is merged over headers on the document upload and discard calls, and leaves the chat request alone.
Uploads there go out with the upload token and still carry X-Tenant-Id. Only the names you repeat are replaced, and the match ignores case, so authorization overrides Authorization. Both land in the browser, so put only public credentials in them.

Theming

Both components take an appearance preset (light, dark, or auto) with optional per-property overrides layered on top:
auto follows the host’s prefers-color-scheme. variables accepts every ChatTheme token — colors, message-bubble radius/padding/max-width, base font size and line height. The full token and CSS-variable list lives on Theming & customization.

Deep customization

Two escape hatches when tokens aren’t enough:
  • appearance.assistantBubble — opt-in filled bubble for assistant replies (plain text by default), styled by assistantBubbleColor / assistantBubbleTextColor.
  • classNames — per-slot classes added next to the widget’s own (nothing is removed, see Deep customization): root, header, message, userBubble, assistantBubble, input. Pass it directly on ChatEmbed, or as overrides.classNames on WaniwaniChat.
Recipes and the list of what remains non-themeable: Theming & customization.

Mirroring events into your analytics

The hosted WaniwaniChat component accepts an onEvent prop that fires on chat lifecycle events (messages, session start, errors, link clicks) so you can mirror widget activity into your own analytics — Segment, Amplitude, gtag — with the page’s identity attached automatically. ChatEmbed, the bring-your-own-backend primitive, does not expose it. See Widget events (onEvent).