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

@bytemaster2704/streaming-chat-sdk

v1.0.7

Published

A simple SDK to interact with a streaming chat API

Readme

📦 Streaming Chat SDK

npm version
A lightweight, TypeScript-friendly SDK for connecting to streaming chat APIs using Server-Sent Events (SSE).
Perfect for building real-time AI assistants, chatbots, or any application requiring live streamed responses.


🚀 Features

  • Streaming support via SSE (real-time tokens as they arrive)
  • 🛠️ TypeScript types included for zero-guesswork development
  • 🔌 Works in browser and Node.js (with an SSE polyfill in Node)
  • 🔍 Easy to configure and extend

📥 Installation

npm install @bytemaster2704/streaming-chat-sdk

If you’re using Node.js (not the browser), install an SSE polyfill:

npm install eventsource

🛠️ Quick Start

import { ChatSDK } from "@bytemaster2704/streaming-chat-sdk";

const sdk = new ChatSDK({
  baseUrl: "https://your-chat-api.com", // defaults to http://localhost:3000
});

sdk.stream("Hello, world!", {
  onToken: (token) => {
    process.stdout.write(token); // stream tokens in real-time
  },
  onEnd: () => {
    console.log("\n✅ Stream ended by server.");
  },
  onError: (err) => {
    console.error("❌ Error:", err.message);
  },
});

📖 API Reference

Class: ChatSDK

Constructor

new ChatSDK(options?: { baseUrl?: string })
  • baseUrl (string) – The root URL of your chat API.
    Defaults to http://localhost:3000.

Method: stream

sdk.stream(query: string, options: StreamingChatOptions): EventSource

Starts a streaming chat session with the server.

  • Parameters

    • query (string) – The prompt or question to send.
    • options (StreamingChatOptions) – Callbacks for handling stream events.
  • Returns

    • EventSource – The underlying SSE connection.

Interface: StreamingChatOptions

interface StreamingChatOptions {
  onToken: (token: string) => void; // required
  onEnd?: () => void; // optional
  onError?: (error: Error) => void; // optional
}
  • onToken – Fired whenever the server streams a new token.
  • onEnd – Fired when the stream is completed.
  • onError – Fired if a network or server error occurs.

💡 Common Use Cases

✅ Building an AI Chatbot

Display tokens as they arrive for a natural typing effect.

✅ Real-time Status Updates

Use the status event type to stream progress updates from the server.

✅ Long-running Tasks

Stream results chunk by chunk instead of waiting for the full response.


🐛 Troubleshooting

1. EventSource is not defined (Node.js only)

Node.js doesn’t ship with EventSource. Install a polyfill:

npm install eventsource

Then, at the top of your app:

import EventSource from "eventsource";
(global as any).EventSource = EventSource;

2. Failed to parse server message

Make sure your server sends JSON-encoded messages in this format:

{ "type": "token", "content": "Hello" }
{ "type": "end" }
{ "type": "error", "content": "Something went wrong" }

3. Stream never ends

Your server must send an "end" message. Otherwise, the connection stays open indefinitely.


🧪 Development

Clone and build locally:

git clone https://github.com/bytemaster2704/streaming-chat-sdk.git
cd streaming-chat-sdk
npm install
npm run build

📜 License

ISC © Hanumant Kakde