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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@a.izzuddin/ai-chat

v0.2.8

Published

A framework-agnostic AI chat web component. Works with React, Vue, Svelte, Angular, and vanilla JavaScript.

Downloads

1,083

Readme

@a.izzuddin/ai-chat

A beautiful, configurable AI chat component for React applications. Built with Radix UI, Tailwind CSS, and TypeScript.

Features

  • 🎨 Beautiful UI - Modern chat interface with dark mode support
  • Lightweight - Minimal dependencies, optimized bundle size
  • 🔧 Configurable - Customize API endpoint, session management, styling
  • 📱 Responsive - Works great on mobile and desktop
  • 🎯 TypeScript - Full type safety out of the box
  • Accessible - Built on Radix UI primitives

Installation

npm install @a.izzuddin/ai-chat
# or
yarn add @a.izzuddin/ai-chat
# or
pnpm add @a.izzuddin/ai-chat

Peer Dependencies

This package requires React 18+ or React 19+:

npm install react react-dom

Quick Start

import { AIChat } from "@a.izzuddin/ai-chat";
import "@a.izzuddin/ai-chat/styles";

function App() {
  return (
    <AIChat
      apiUrl="https://your-api-endpoint.com"
      sessionId="user-123"
      title="My AI Assistant"
    />
  );
}

Tailwind CSS Setup

This component uses Tailwind CSS. Add the component path to your tailwind.config.js:

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./app/**/*.{js,ts,jsx,tsx}",
    "./components/**/*.{js,ts,jsx,tsx}",
    // Add this line:
    "./node_modules/@a.izzuddin/ai-chat/**/*.{js,ts,jsx,tsx}",
  ],
  // ... rest of your config
};

Or if using Tailwind v4, add to your CSS:

@import "tailwindcss";
@import "@a.izzuddin/ai-chat/styles";

API Requirements

Your API endpoint should accept POST requests to /ask with this format:

Request:

{
  "session_id": "string",
  "question": "string"
}

Response:

{
  "response": "string"
}

Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | apiUrl | string | required | Your API endpoint URL | | sessionId | string | "default-session" | Session identifier for conversation context | | title | string | "My AI Agent" | Chat header title | | initialMessages | Message[] | [] | Pre-populate chat with messages | | className | string | undefined | Custom CSS class for container | | onMessageSent | (message: Message) => void | undefined | Callback when user sends a message | | onResponseReceived | (message: Message) => void | undefined | Callback when AI responds | | onError | (error: Error) => void | undefined | Callback when an error occurs |

Advanced Usage

With Custom Styling

<AIChat
  apiUrl="https://api.example.com"
  className="max-w-4xl mx-auto shadow-lg"
  title="Customer Support Bot"
/>

With Event Handlers

<AIChat
  apiUrl="https://api.example.com"
  onMessageSent={(message) => {
    // Track analytics
    analytics.track("message_sent", { content: message.content });
  }}
  onResponseReceived={(message) => {
    // Log responses
    console.log("AI responded:", message.content);
  }}
  onError={(error) => {
    // Handle errors
    toast.error(error.message);
  }}
/>

With Initial Messages

const welcomeMessages = [
  {
    id: "1",
    role: "assistant" as const,
    content: "Hello! How can I help you today?",
  },
];

<AIChat
  apiUrl="https://api.example.com"
  initialMessages={welcomeMessages}
/>

With Dynamic Session Management

import { useUser } from "@/hooks/useUser";

function ChatPage() {
  const user = useUser();

  return (
    <AIChat
      apiUrl={process.env.NEXT_PUBLIC_API_URL!}
      sessionId={user.id}
      title={`Chat with ${user.name}'s Assistant`}
    />
  );
}

TypeScript

Full TypeScript support is included. Import types as needed:

import type { Message, AIChatProps } from "@a.izzuddin/ai-chat";

const customMessage: Message = {
  id: "123",
  role: "user",
  content: "Hello!",
};

Styling

The component uses Tailwind CSS with custom theme variables. You can customize the appearance by:

  1. Using Tailwind's dark mode: The component automatically supports dark mode
  2. Custom CSS variables: Override theme colors in your global CSS
  3. className prop: Add custom Tailwind classes to the container

Custom Theme Colors

@layer base {
  :root {
    --primary: oklch(0.205 0 0);
    --primary-foreground: oklch(0.985 0 0);
    /* ... other variables */
  }

  .dark {
    --primary: oklch(0.922 0 0);
    --primary-foreground: oklch(0.205 0 0);
    /* ... other variables */
  }
}

Framework Support

Next.js (App Router)

"use client";

import { AIChat } from "@a.izzuddin/ai-chat";
import "@a.izzuddin/ai-chat/styles";

export default function ChatPage() {
  return <AIChat apiUrl={process.env.NEXT_PUBLIC_API_URL!} />;
}

Next.js (Pages Router)

import { AIChat } from "@a.izzuddin/ai-chat";
import "@a.izzuddin/ai-chat/styles";

export default function ChatPage() {
  return <AIChat apiUrl={process.env.NEXT_PUBLIC_API_URL!} />;
}

Vite + React

import { AIChat } from "@a.izzuddin/ai-chat";
import "@a.izzuddin/ai-chat/styles";

function App() {
  return <AIChat apiUrl={import.meta.env.VITE_API_URL} />;
}

Create React App

import { AIChat } from "@a.izzuddin/ai-chat";
import "@a.izzuddin/ai-chat/styles";

function App() {
  return <AIChat apiUrl={process.env.REACT_APP_API_URL} />;
}

Examples

Check out the examples directory for complete working examples with:

  • Next.js App Router
  • Vite + React
  • Custom styling
  • Advanced features

Browser Support

  • Chrome/Edge (latest)
  • Firefox (latest)
  • Safari 14+
  • Mobile browsers (iOS Safari, Chrome Android)

Contributing

Contributions are welcome! Please read our contributing guidelines first.

License

MIT © [Your Name]

Related

Support