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

ai-chat-toolkit-widget

v1.0.0

Published

Embeddable AI chat web component

Readme

ai-chat-toolkit-widget

Embeddable AI chat widget for any website or app. Drop it in with a <script> tag or import it as an npm package — no framework required.

Built with vanilla Web Components and Shadow DOM, so it works in React, Vue, plain HTML, or anything else without conflicts.


Install

CDN (easiest)

<script src="https://cdn.jsdelivr.net/npm/ai-chat-toolkit-widget/dist/widget.global.js"></script>

<ai-chat
  title="AI Assistant"
  subtitle="How can I help?"
  backend-url="https://api.example.com"
  path="/ai-chat/custom"
></ai-chat>

The script auto-registers the <ai-chat> custom element when it loads.

npm

npm install ai-chat-toolkit-widget
import "ai-chat-toolkit-widget";
<ai-chat title="Support" backend-url="https://api.example.com"></ai-chat>

Attributes

| Attribute | Default | Description | |-----------|---------|-------------| | title | AI Assistant | Header title | | subtitle | How can I help you today? | Header subtitle | | logo | (none) | Image URL for the FAB button and header. Falls back to the default chat icon if the URL fails to load. | | primary-color | #2563eb | Accent color for the header, FAB button, and send button | | backend-url | window.location.origin | Base URL of your API server (no trailing slash) | | path | /ai-chat/custom | Endpoint path appended to backend-url | | placeholder | Type a message… | Textarea placeholder text | | position | bottom-right | Corner position: bottom-right, bottom-left, top-right, top-left |


Backend API

The widget sends a POST request to ${backend-url}${path} on every message.

Request body:

{
  "message": "user message text",
  "history": [
    { "role": "user", "content": "previous message" },
    { "role": "assistant", "content": "previous reply" }
  ]
}

Expected response — either field is accepted:

{ "message": "assistant reply" }
{ "response": "assistant reply" }

Error handling:

  • Non-2xx responses display the error text inline in the chat (no popup).
  • Network failures and CORS errors also display inline with a descriptive message.
  • If the logo URL fails to load, the widget silently falls back to the default chat icon.

If your API is on a different domain, enable CORS on the server. See ai-chat-toolkit-server for a ready-made backend.


Programmatic API

const el = document.querySelector("ai-chat") as AiChatElement;

el.open();         // Open the chat panel
el.close();        // Close the chat panel
el.toggle();       // Toggle open/closed
el.clearHistory(); // Clear all messages

React usage

Import once in main.tsx:

import "ai-chat-toolkit-widget";

Add TypeScript types in src/types/web-components.d.ts:

declare module "react" {
  namespace JSX {
    interface IntrinsicElements {
      "ai-chat": React.DetailedHTMLProps<
        React.HTMLAttributes<HTMLElement> & {
          title?: string;
          subtitle?: string;
          logo?: string;
          "primary-color"?: string;
          "backend-url"?: string;
          path?: string;
          placeholder?: string;
          position?: "bottom-right" | "bottom-left" | "top-right" | "top-left";
        },
        HTMLElement
      >;
    }
  }
}

Use in JSX:

<ai-chat
  title="Support"
  primary-color="#2563eb"
  path="/ai-chat/custom"
/>

Build outputs

| File | Use case | |------|----------| | dist/widget.global.js | CDN / <script> tag | | dist/index.js | ESM import | | dist/index.d.ts | TypeScript types |


Development

From the monorepo root:

pnpm install
pnpm --filter ai-chat-toolkit-widget dev

License

MIT