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

openclaw-webchat

v0.2.0

Published

Core WebSocket client for OpenClaw Gateway

Readme

openclaw-webchat

Core WebSocket client for OpenClaw Gateway. Framework-agnostic, works with any JavaScript environment.

Installation

npm install openclaw-webchat
# or
pnpm add openclaw-webchat
# or
yarn add openclaw-webchat

Quick Start

import { OpenClawClient } from 'openclaw-webchat';

const client = new OpenClawClient({
  gateway: 'wss://your-gateway.example.com/ws',
  token: 'your-auth-token',
});

// Listen for messages
client.on('message', (msg) => {
  console.log(`${msg.role}: ${msg.content}`);
});

// Listen for streaming responses
client.on('streamChunk', (messageId, chunk) => {
  process.stdout.write(chunk);
});

// Connect and send message
await client.connect();
await client.send('Hello, AI!');

API Reference

Constructor Options

interface OpenClawClientOptions {
  /** Gateway WebSocket URL (required) */
  gateway: string;

  /** Authentication token */
  token?: string;

  /** Authentication password (alternative to token) */
  password?: string;

  /** Device token for persistent sessions */
  deviceToken?: string;

  /** Session key (auto-detected if not provided) */
  sessionKey?: string;

  /** Client name for identification */
  clientName?: string;

  /** Client version */
  clientVersion?: string;

  /** Auto-reconnect on disconnect (default: true) */
  reconnect?: boolean;

  /** Reconnect interval in ms (default: 3000) */
  reconnectInterval?: number;

  /** Max reconnect attempts (default: 10, -1 for infinite) */
  maxReconnectAttempts?: number;

  /** Connection timeout in ms (default: 10000) */
  connectionTimeout?: number;

  /** Enable debug logging (default: false) */
  debug?: boolean;
}

Methods

// Connection
await client.connect();        // Connect to gateway
client.disconnect();           // Disconnect from gateway
client.isConnected;            // boolean - connection status
client.connectionState;        // 'disconnected' | 'connecting' | 'authenticating' | 'connected' | 'reconnecting' | 'error'

// Chat
await client.send(content);                    // Send message to AI
await client.send(content, metadata);          // Send with metadata
const history = await client.getHistory(50);   // Get chat history
await client.inject(content, 'system');        // Inject system message

Events

client.on('connected', () => {
  console.log('Connected to gateway');
});

client.on('disconnected', (reason) => {
  console.log('Disconnected:', reason);
});

client.on('reconnecting', (attempt) => {
  console.log(`Reconnecting... attempt ${attempt}`);
});

client.on('error', (error) => {
  console.error('Error:', error.message);
});

client.on('message', (message) => {
  // Complete message received
  console.log(message.role, message.content);
});

client.on('streamStart', (messageId) => {
  // AI started streaming response
});

client.on('streamChunk', (messageId, chunk) => {
  // Streaming chunk received
  process.stdout.write(chunk);
});

client.on('streamEnd', (messageId) => {
  // Streaming complete
});

client.on('stateChange', (state) => {
  // Connection state changed
  console.log('State:', state.connectionState);
});

Message Type

interface Message {
  id: string;
  role: 'user' | 'assistant' | 'system';
  content: string;
  timestamp: number;
  metadata?: Record<string, unknown>;
}

Advanced Usage

Manual Session Key

const client = new OpenClawClient({
  gateway: 'wss://your-gateway.example.com/ws',
  token: 'your-token',
  sessionKey: 'custom-session-key',  // Use specific session
});

Disable Auto-Reconnect

const client = new OpenClawClient({
  gateway: 'wss://your-gateway.example.com/ws',
  token: 'your-token',
  reconnect: false,
});

Custom Reconnect Strategy

const client = new OpenClawClient({
  gateway: 'wss://your-gateway.example.com/ws',
  token: 'your-token',
  reconnect: true,
  reconnectInterval: 5000,      // 5 seconds between attempts
  maxReconnectAttempts: -1,     // Infinite retries
});

License

MIT