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

@cristianglezm/live-commentary-widget

v1.2.0

Published

A React component that provides a Twitch-chat-like widget for live AI commentary on screen / canvas content.

Downloads

42

Readme

@cristianglezm/live-commentary-widget

npm License

A React component library that adds a "Twitch-style" live chat overlay to your application. It uses AI Vision models to "watch" the screen (or a specific canvas) and generate humor, context-aware commentary, or useful insights in real-time.

✨ Features

  • Plug & Play: Drop <LiveCommentary /> into any React app.
  • Visual Context: Users can toggle "Show Context" on comments to verify exactly what the AI saw at that moment.
  • Headless Hooks: Use useLiveCommentary and useScreenCapture to build your own custom UI.
  • AI Middleware: Intercept raw AI responses to handle your own parsing, username assignment, or state management.
  • AI Powered: Compatible with OpenAI's Vision API (gpt-4o) and local alternatives (e.g., llama.cpp server).
  • Screen & Canvas Support: Capture the entire screen via the browser API or hook directly into a <canvas> for games.
  • Sticky Scroll: Chat widget automatically scrolls to new messages but pauses when you scroll up.

📦 Installation

npm install @cristianglezm/live-commentary-widget

💻 Usage

1. Basic Usage (The "Easy" Way)

The LiveCommentary component wraps the logic and the UI into one standard widget.

import { LiveCommentary } from '@cristianglezm/live-commentary-widget';
import '@cristianglezm/live-commentary-widget/style.css';

function App() {
  return (
    <div>
      <LiveCommentary 
        config={{
          model: 'gpt-4o',
          apiKey: 'not_required', 
        }} 
      />
    </div>
  );
}

2. Middleware (Controlled Mode)

Want to control exactly who says what? Use responseTransform to intercept the raw text from the LLM and return your own message objects.

Pro Tip: You also receive the capturedImage snapshot, so you can attach it to your custom messages to enable the "Show Context" feature.

import { LiveCommentary, createChatMessage } from '@cristianglezm/live-commentary-widget';

<LiveCommentary 
  responseTransform={(rawText, capturedImage) => {
    // rawText: The raw string response from the AI
    // capturedImage: The base64 image used for this analysis
    
    // You can parse JSON, XML, or just return a hardcoded user
    return [
      // createChatMessage(text, username, color, customUsernamesList, attachment)
      createChatMessage(rawText, "MyCustomBot", "#ff0000", undefined, capturedImage)
    ];
  }}
/>

3. Headless Mode (Custom UI)

Build your own UI entirely using the hooks.

import { useLiveCommentary, useScreenCapture, ChatWidget } from '@cristianglezm/live-commentary-widget';

function MyCustomPage() {
  const { isCapturing, startCapture, captureFrame } = useScreenCapture({ mode: 'screen-capture' });
  
  const { messages, triggerEvaluation } = useLiveCommentary({
     isCapturing,
     captureFrame,
     config: { apiKey: '...' }
  });

  return (
    <div>
      <button onClick={startCapture}>Start Recording</button>
      <button onClick={() => triggerEvaluation()}>Force Comment</button>
      
      {/* You can use our widget or render your own list */}
      <div className="my-custom-chat-container">
        {messages.map(msg => (
            <div key={msg.id}>
                <b>{msg.username}:</b> {msg.text}
                {/* Access the visual context image via msg.attachment */}
                {msg.attachment && <img src={`data:image/jpeg;base64,${msg.attachment}`} />}
            </div>
        ))}
      </div>
    </div>
  );
}

📸 Visual Context

The widget automatically attaches a snapshot of the screen to every AI-generated comment. This allows users to understand why the AI said something.

  1. Hover/Look at a message in the chat.
  2. Click the "Show Context" button (small eye icon).
  3. The image frame analyzed by the AI will appear below the text.

This is particularly useful for:

  • Debugging prompts: See if the model is hallucinating or just saw something you missed.
  • Verification: Proving the commentary is "live" and reacting to the actual video feed.

⚙️ Configuration Props (LiveCommentary)

| Prop | Type | Default | Description | |------|------|---------|-------------| | config | Partial<VlmSettings> | | Override API settings (url, key, model, temp). | | mode | 'screen-capture' \| 'external' | 'screen-capture' | Use 'external' for direct canvas/video hook. | | responseTransform | (raw: string, img?: string) => ChatMessage[] | | New: Middleware to handle raw AI text yourself. | | captureSource | () => string \| null | | Required if mode is external. Returns base64 image string. | | prompts | CommentaryPrompts | | Customize the system instructions and triggers. | | contextData | object | | Arbitrary JSON data sent to the AI for context. | | usernames | string[] | undefined | Custom list of usernames for random assignment. | | showBadges | boolean | true | Show Twitch-style badges (Broadcaster, Prime, etc). | | title | string | "Live Commentary" | Header title of the widget. | | overlay | boolean | true | If true, fixed positioning. If false, fills parent. |

🎨 Customization

The widget uses CSS variables for theming. Import the CSS and override variables in your :root.

import '@cristianglezm/live-commentary-widget/style.css';

:root {
  --color-lc-bg: #18181b;
  --color-lc-accent: #9147ff;
}

📄 License

MIT © Cristian Gonzalez