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

yoda-widget

v0.1.2

Published

Yoda Assistant widget - React + TypeScript chat widget with Shadow DOM.

Readme

yoda-widget

A lightweight React + TypeScript chat widget that embeds a Yoda assistant on any page. It renders inside a Shadow DOM, supports theming, and talks to a FastAPI backend.

Install

npm install yoda-widget
# peer deps
npm install react react-dom

Quick start

import { useEffect } from 'react';
import { initYoda, setYodaEnabled, setYodaBackendUrl } from 'yoda-widget';

export default function App() {
  useEffect(() => {
    // Point to your backend once (default is http://localhost:8000)
    setYodaBackendUrl('http://localhost:8000');

    initYoda({
      authToken: 'YOUR_CLIENT_TOKEN',
      model: 'gemini',
      position: 'top-right',
      theme: {
        background: '#1a0909',
        headerBg: '#2a0d0d',
        text: '#ffe6e6',
        accent: '#7a1f1f',
        userBubble: '#5b1b1b',
        assistantBubble: '#3a1414',
        border: '#4a0e0e'
      }
    });
  }, []);
  return <div>Your app</div>;
}

API

initYoda(options)

Initializes the widget (idempotent).

initYoda({
  authToken: string;              // required client token
  model: 'gemini';                // required; reserved for future models
  position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
  theme?: {
    background?: string;
    headerBg?: string;
    text?: string;
    accent?: string;
    userBubble?: string;
    assistantBubble?: string;
    border?: string;
  };
});
  • The widget mounts to the page using a Shadow DOM host at a fixed corner.
  • A default assistant greeting is shown on open.

setYodaEnabled(enabled)

Toggle the widget at runtime, useful for per-route control.

import { setYodaEnabled } from 'yoda-widget';

// Disable on a specific route
setYodaEnabled(false);

Example with React Router:

import { useLocation } from 'react-router-dom';
import { setYodaEnabled } from 'yoda-widget';

function RouterWatcher() {
  const location = useLocation();
  useEffect(() => {
    setYodaEnabled(location.pathname !== '/page');
  }, [location.pathname]);
  return null;
}

setYodaBackendUrl(url)

Set the backend base URL. Defaults to http://localhost:8000 if not set.

import { setYodaBackendUrl } from 'yoda-widget';
setYodaBackendUrl('https://api.example.com');

Backend expectations

The widget calls these endpoints on the configured backend (or same-origin):

  • POST /v1/start_session -> { session_id }
  • POST /v1/send_message -> { reply } (body includes session_id, message)
  • POST /v1/end_session -> { success: true }
  • Fallback single-turn: POST /v1/chat -> { reply }

Auth: All requests include Authorization: Bearer <authToken>.

CORS: If serving backend on a different origin, allow the frontend origin.

Theming

The widget uses CSS variables inside its Shadow DOM:

  • --yoda-bg, --yoda-header-bg, --yoda-text, --yoda-accent,
  • --yoda-user, --yoda-assistant, --yoda-border

You normally pass these via theme in initYoda. Advanced users can also override from the host with CSS variables if needed.

Notes

  • React and ReactDOM are peer dependencies; the widget externalizes them.
  • All styles are scoped to the Shadow DOM; no global CSS leak.
  • The chat input auto-resizes; Shift+Enter inserts a newline, Enter sends.

License

MIT