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

@revelations88/chatbot-ui

v1.0.1

Published

A modular React chatbot component with code editing preview and undo support

Readme

ChatBot UI

A modular, drop-in React chatbot component with code editing preview and undo functionality. Built with TypeScript, Tailwind CSS, and Lucide React icons.

Features

  • 🎨 Glassmorphic UI - Modern, floating chatbot with backdrop blur
  • 📝 Code Edit Previews - View proposed changes with diff highlighting before applying
  • ↩️ Undo Support - Built-in /undo command to rollback changes
  • 🔌 Configurable API - Point to any backend API endpoint
  • 🧩 Modular Architecture - Separated hooks, components, and types
  • 📦 Drop-in Ready - Import and use in any React project

Installation

npm install @revelations88/chatbot-ui

Peer Dependencies

This package requires the following peer dependencies:

npm install react react-dom lucide-react

Prerequisites

Backend API

The chatbot expects a backend API with the following endpoints:

POST /api/propose-edits

// Request
{
  "request": "Add a function to calculate factorial"
}

// Response
{
  "session_id": "abc123",
  "status": "success",
  "request": "Add a function to calculate factorial",
  "preview": [
    {
      "file": "src/math.ts",
      "changes": [
        {
          "line": 10,
          "old_code": "",
          "new_code": "function factorial(n: number): number { ... }"
        }
      ]
    }
  ],
  "summary": {
    "total_edits": 1,
    "files_affected": 1
  }
}

POST /api/apply-edits

// Request
{
  "session_id": "abc123"
}

// Response
{
  "status": "success",
  "message": "Changes applied successfully"
}

POST /api/undo

// Response
{
  "status": "success",
  "message": "Reverted to previous commit",
  "commit": "abc123"
}

Usage

Option 1: Auto-Mount (No React Required)

For non-React projects or simple integrations, use initChatbotUI() to automatically mount the chatbot:

<!DOCTYPE html>
<html>
<head>
  <title>My App</title>
</head>
<body>
  <h1>My Application</h1>

  <script type="module">
    import { initChatbotUI } from '@revelations88/chatbot-ui';

    // Automatically mounts chatbot to the page
    initChatbotUI({
      apiBaseUrl: 'https://api.myapp.com/v1'
    });
  </script>
</body>
</html>

With cleanup:

import { initChatbotUI } from '@revelations88/chatbot-ui';

const chatbot = initChatbotUI({
  apiBaseUrl: 'https://api.myapp.com/v1'
});

// Later, to remove the chatbot:
chatbot.unmount();

Option 2: React Component

For React projects, use as a standard component:

import { ChatBot } from '@revelations88/chatbot-ui';

function App() {
  return (
    <div>
      <h1>My Application</h1>
      <ChatBot />
    </div>
  );
}

Custom API URL

import { ChatBot } from '@revelations88/chatbot-ui';

function App() {
  return (
    <ChatBot apiBaseUrl="https://api.myapp.com/v1" />
  );
}

TypeScript Types

import { ChatBot, Message, FilePreview } from '@revelations88/chatbot-ui';

// Use exported types in your own code
const messages: Message[] = [];

Commands

  • Regular messages: Type naturally to propose code edits
  • /undo: Rollback the last applied changes

Advanced Usage

Using Hooks Directly

For custom implementations, you can use the underlying hooks:

import { useApi, useChat } from '@yourscope/chatbot-ui';

function CustomChatBot() {
  const api = useApi('https://api.myapp.com');
  const { messages, addUserMessage, addBotMessage } = useChat();

  const handleSubmit = async (input: string) => {
    addUserMessage(input);
    const result = await api.proposeEdits(input);
    // Custom handling...
  };

  // Custom UI...
}

API Reference

initChatbotUI(options?)

Initialize and mount the chatbot to the DOM automatically.

Parameters

| Param | Type | Default | Description | |------|------|---------|-------------| | options | ChatBotProps | {} | Optional configuration object | | options.apiBaseUrl | string | 'http://localhost:8000/api' | Base URL for API endpoints |

Returns

| Property | Type | Description | |----------|------|-------------| | unmount | () => void | Function to unmount and remove the chatbot from DOM |

<ChatBot>

React component for manual integration.

Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | apiBaseUrl | string | 'http://localhost:8000/api' | Base URL for API endpoints |

Exported Types

// Main message types
type Message =
  | { type: "text"; role: "user" | "bot"; content: string }
  | { type: "preview"; role: "bot"; sessionId: string; preview: FilePreview[]; summary: {...}; request: string };

// API response types
interface FilePreview {
  file: string;
  changes: PreviewChange[];
}

interface PreviewChange {
  line: number;
  old_code: string;
  new_code: string;
}

Development

Building the Library

# Build for production
npm run build:lib

# Development mode (demo app)
npm run dev

Project Structure

src/
├── components/
│   ├── ChatBot.tsx          # Main component
│   └── chat/
│       ├── MessageList.tsx
│       ├── MessageBubble.tsx
│       └── PreviewCard.tsx
├── hooks/
│   ├── useApi.ts            # API calls
│   └── useChat.ts           # Message state
└── index.ts                 # Public exports

Changelog

v1.0.1 (Latest)

  • Initial stable release
  • Code editing preview with diff highlighting
  • Undo support
  • Glassmorphic UI design
  • Auto-mount functionality with proper JSX rendering
  • Type-safe API with full TypeScript support

Note: Versions 1.1.0 and 1.1.1 were deprecated. Use 1.0.1 or later.

Publishing

  1. Update version in package.json

  2. Build the library:

npm run build:lib
  1. Publish to npm:
npm publish --access public

License

MIT

Contributing

Contributions welcome! Please open an issue or PR.