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

chat-nest-sdk

v1.1.2

Published

Frontend React SDK for consuming streaming AI APIs with cancellation and retry safety.

Readme

chat-nest-sdk

Frontend SDK for Chat Nest providing a simple React hook to consume streaming AI APIs safely using Server-Side Events (SSE).

This package handles:

  • Server-Side Events (SSE) streaming response handling
  • Real-time token streaming via SSE protocol
  • Cancellation propagation
  • Intelligent retry behavior
  • Error normalization
  • Message state management

Designed for production usage in React applications. Uses SSE for efficient, bidirectional communication with the backend.


✨ Features

  • Server-Side Events (SSE) streaming protocol
  • Real-time token streaming via SSE events
  • Abort-safe cancellation
  • Retry only on network / server failures
  • No retries on client or policy errors
  • Message state management
  • Lightweight and framework-friendly
  • Efficient SSE event parsing (token, done, error, ping, start events)

📦 Installation

npm install chat-nest-sdk

🚀 Usage

Example

import { useAiChat } from "chat-nest-sdk";

function App() {
  const chat = useAiChat({
    endpoint: "http://localhost:3001/api/chat",
    initialProfile: "balanced",
    dailyTokenLimit: 50_000,    // optional: cap daily tokens
    maxTokensPerRequest: 4096,  // optional: cap per request
  });

  return (
    <>
      <div>
        {chat.messages.map((m) => (
          <div key={m.id}>
            <strong>{m.role}</strong>: {m.content}
          </div>
        ))}
      </div>

      <button onClick={() => chat.sendMessage("Hello!")}>
        Send
      </button>

      <button onClick={chat.cancel}>
        Cancel
      </button>
      <select value={chat.profile} onChange={(e) => chat.setProfile(e.target.value)}>
        <option value="constrained">Constrained</option>
        <option value="balanced">Balanced</option>
        <option value="expanded">Expanded</option>
      </select>
    </>
  );
}

🧠 API

useAiChat(options)

| Field | Type | Description | | ------------------- | ------ | --------------------------------------------------------------------------- | | endpoint | string | Backend API endpoint | | initialMessages | Message[] | Optional. Initial messages | | maxMessages | number | Optional. Max messages to keep in context (default 10) | | initialProfile | AiUsageProfile | Optional. Profile: constrained, balanced, expanded | | dailyTokenLimit | number | Optional. Cap daily tokens; server applies min(profile limit, this) | | maxTokensPerRequest | number | Optional. Cap tokens per request (input + output); server applies min |

Return value

| Field | Description | | ----------------- | ----------------------------- | | messages | Chat message list | | sendMessage(text) | Sends user message | | cancel() | Cancels active request | | isStreaming | Whether stream is active | | error | Last error | | profile | Current profile | | setProfile(p) | Set profile; persisted to localStorage | | reset() | Reset messages and error |


⚠️ Important Notes

Only one active request is allowed at a time.

Cancel immediately stops streaming and billing.

4xx errors are never retried.

Network failures retry automatically.

Server-Side Events (SSE): The SDK communicates with the backend using the SSE protocol. The backend must send events in SSE format (event: <type>\ndata: <data>\n\n). Supported event types: start, token, done, error, ping.


📄 License

ISC