@agentictrust/ui) for React apps, and works with Next.js App Router out of the box. It renders a chat interface on your site, connects to your project’s API, and streams AI responses in real time.
Install
- Script tag
- React
- Next.js
Include the widget script and initialize it — no build step required.1. Add the script2. Initialize
initAsync fetches the widget configuration from the server before rendering, so the widget reflects your dashboard settings (colors, position, branding). init uses defaults and renders immediately.3. VerifyReload your page. A chat bubble appears in the bottom-right corner (default position). Click it to open the chat panel.Configuration options
Pass these properties toinit, initAsync, or Widget:
| Property | Type | Required | Description |
|---|---|---|---|
apiUrl | string | Yes | API base URL (e.g. https://platform.agentictrust.com/api/v1) |
apiKey | string | Yes | Public API key (lum_pk_...) |
user | UserIdentity | No | End-user identity for HMAC verification (see Identity) |
userTokens | Record<string, string> | No | Auth headers forwarded to action endpoints |
pageContext | PageContext | No | Page metadata sent with messages |
getPageContext | () => PageContext | No | Dynamic page context fetcher called before each message |
captureDom | boolean | No | Auto-capture headings, links, buttons, and form fields from the page |
readOnly | boolean | No | Hide the chat input so no new messages can be sent |
navigate | (path: string) => void | Promise<void> | No | SPA-friendly navigation function (e.g. router.push). See SPA navigation |
embedded | boolean | No | Render inline instead of as a floating bubble (auto-set by Widget) |
SPA navigation
When the agent decides to navigate the user to a different page, it calls thenavigate function you provide. This keeps your SPA’s router in control instead of triggering a full page reload.
() => void) and async (() => Promise<void>) functions are accepted.
If you don’t pass
navigate, the widget falls back to window.location.href which triggers a full page reload. The conversation state is preserved in localStorage and the agent continues automatically after the page loads.Full example
The widget script is cached for 1 hour with a stale-while-revalidate window of 1 day. Users always get a fast load with automatic background updates.