npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@uraiai/chat-widget-react

v0.1.4

Published

React component for the Urai chat widget

Readme

@uraiai/chat-widget-react

React component for the Urai chat widget (React 18 / 19).

npm install @uraiai/chat-widget-react
import { useRef } from "react";
import { UraiChatWidget, type WidgetController } from "@uraiai/chat-widget-react";

function App() {
  const widget = useRef<WidgetController>(null);

  return (
    <>
      <button onClick={() => widget.current?.open()}>Chat with us</button>
      <UraiChatWidget
        ref={widget}
        widgetToken="<widget token>"
        userId="<stable visitor id>"
        theme={{ primaryColor: "#0ea5e9" }}
        onAssistantReply={(content) => console.log(content)}
      />
    </>
  );
}

Allow your origin. The server validates the Origin header of every widget request (including the SSE stream) against the widget's allowed origins. Add your app's origin in the Urai dashboard or all requests 403.

Props

Required: widgetToken, userId. Optional: baseUrl (defaults to https://chat.app.urai.dev; set it for self-hosted deployments), vars, theme, layout, behavior, mode ("floating" default | "inline"), className/style (inline container div only), and event callbacks onReady, onOpened, onClosed, onUserMessage, onAssistantReply, onCommand, onError.

onCommand fires when a uraiJS tool calls meta.urai.sendCommand(meta.vars.thread_id, payload) during the turn — use it to react to tool-driven UI signals (e.g. navigation). The payload is the tool author's JSON, verbatim: treat it as untrusted and validate its shape before acting. Delivered only while the turn's stream is open; each open widget instance receives its own copy.

In inline mode the component renders a div and the chat panel fills it — give it a height via style/className.

Prop changes: live vs. remount

| Prop | Effect | |---|---| | theme, layout, behavior | Applied live via configure() (deep-compared, so inline object literals are fine). Structural changes (mode/position/header/welcome/suggested) rebuild the panel and clear the visible conversation. | | userId | setUser() — resets the conversation for the new visitor. | | vars | setVars() — updates the current/next thread's context. | | widgetToken, baseUrl, mode | Destroys and recreates the widget. |

The ref exposes the full WidgetController (open, close, sendMessage, startConversation, on, …). Mount/unmount is idempotent and StrictMode-safe.

Passing context (vars)

Vars are a JSON object stored on the thread and made available to your assistant (plan, locale, current route, …). The idiomatic way is the vars prop — changing it calls setVars() on the active thread (deep-compared, so inline literals are fine):

function App() {
  const location = useLocation();
  const widget = useRef<WidgetController>(null);

  return (
    <UraiChatWidget
      ref={widget}
      widgetToken="<widget token>"
      userId="user_42"
      vars={{ plan: "pro", page: location.pathname }}
    />
  );
}

Or imperatively through the controller:

widget.current?.setVars({ plan: "pro" });          // update active thread
widget.current?.setVars(null);                     // clear
widget.current?.startConversation({ topic: "billing" }); // seed a fresh thread