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

@brainbase-labs/chat-widget

v0.1.11

Published

A React chat widget for embedding Brainbase Labs AI agents in your applications

Readme

@brainbase-labs/chat-widget

A React chat widget for embedding Brainbase Labs AI agents in your applications.

npm version License: MIT

Features

  • 🚀 Drop-in React component - Add AI chat to your app in minutes
  • 🎨 Fully customizable - Theme with CSS variables or override styles
  • 📱 Responsive - Works on desktop and mobile
  • 🔄 Session persistence - Conversations survive page refreshes
  • 🛠️ Tool call support - Display function calls and results
  • 🧪 Mock mode - Develop UI without a backend connection

Installation

npm install @brainbase-labs/chat-widget
# or
yarn add @brainbase-labs/chat-widget
# or
pnpm add @brainbase-labs/chat-widget

Quick Start

import { ChatWidget } from '@brainbase-labs/chat-widget';
import '@brainbase-labs/chat-widget/styles.css';

function App() {
  return (
    <ChatWidget
      embedId="your-embed-id-here"
      onSessionEnd={(session) => console.log('Session ended:', session)}
    />
  );
}

Mock Mode for Development

Test the UI without a backend connection:

import { ChatWidget } from '@brainbase-labs/chat-widget';
import '@brainbase-labs/chat-widget/styles.css';

function App() {
  return (
    <ChatWidget
      embedId="demo"
      mockMode={true}
      defaultOpen={true}
      agentName="Dev Assistant"
    />
  );
}

Custom Mock Responses

<ChatWidget
  embedId="demo"
  mockMode={true}
  mockResponses={[
    {
      trigger: /order|status/i,
      response: "Let me look up your order...",
      toolCalls: [
        {
          name: 'lookup_order',
          arguments: { orderId: '12345' },
          result: { status: 'shipped' }
        }
      ]
    },
    {
      trigger: /.*/,
      response: "I'm here to help! Ask me anything.",
      delay: 500
    }
  ]}
/>

Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | embedId | string | Required | The embed ID from your Brainbase Labs deployment | | apiBaseUrl | string | Production URL | API base URL for the Brainbase Labs API | | mockMode | boolean | false | Enable mock mode for UI development | | mockResponses | MockResponse[] | Default responses | Custom mock responses | | position | 'bottom-right' \| 'bottom-left' \| 'inline' | 'bottom-right' | Widget position | | defaultOpen | boolean | false | Whether widget starts open | | primaryColor | string | '#1a1a2e' | Primary theme color (hex) | | agentName | string | From deployment | Agent display name | | className | string | - | Custom CSS class | | onSessionStart | (sessionId: string) => void | - | Session start callback | | onSessionEnd | (session: Session) => void | - | Session end callback | | onMessage | (message: Message) => void | - | Message callback | | onError | (error: Error) => void | - | Error callback |

Theming

The widget uses CSS custom properties for theming. Override them in your CSS:

:root {
  /* Primary brand color */
  --bb-primary-color: #1a1a2e;
  
  /* Accent color for highlights */
  --bb-accent-color: #6366f1;
  
  /* Background colors */
  --bb-surface-bg: #ffffff;
  --bb-surface-secondary: #f8f9fb;
  
  /* Text colors */
  --bb-text-primary: #1a1a2e;
  --bb-text-secondary: #6b7280;
  
  /* Message bubbles */
  --bb-user-message-bg: var(--bb-primary-color);
  --bb-user-message-text: #ffffff;
  --bb-assistant-message-bg: var(--bb-surface-secondary);
  --bb-assistant-message-text: var(--bb-text-primary);
  
  /* Widget dimensions */
  --bb-widget-width: 400px;
  --bb-widget-height: 600px;
}

Advanced Usage

Using the Chat Hook

For custom UI implementations:

import { useChat, createMockAPIClient } from '@brainbase-labs/chat-widget';

function CustomChat() {
  const mockClient = createMockAPIClient();
  
  const chat = useChat({
    config: {
      embedId: 'demo',
      deploymentId: 'mock',
      workerId: 'mock',
      flowId: 'mock',
    },
    apiClient: mockClient,
    mockMode: true,
  });

  return (
    <div>
      {chat.messages.map(msg => (
        <div key={msg.id}>{msg.content}</div>
      ))}
      <input
        onKeyDown={(e) => {
          if (e.key === 'Enter') {
            chat.sendMessage(e.currentTarget.value);
            e.currentTarget.value = '';
          }
        }}
      />
    </div>
  );
}

Inline Mode

Embed the chat directly in your page layout instead of as a floating widget:

<ChatWidget
  embedId="your-embed-id"
  position="inline"
  defaultOpen={true}
/>

TypeScript

Full TypeScript support with exported types:

import type {
  ChatWidgetProps,
  Message,
  Session,
  ToolCall,
  DeploymentConfig,
} from '@brainbase-labs/chat-widget';

Development

# Install dependencies
npm install

# Run Storybook for development
npm run storybook

# Build the library
npm run build

# Type check
npm run typecheck

# Lint
npm run lint

Contributing

Contributions are welcome! Please read our contributing guidelines before submitting a PR.

License

MIT © Brainbase Labs