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

@deltakit/react

v0.2.0

Published

React hooks for streaming AI conversations with real-time updates

Readme

@deltakit/react

React hook for building streaming chat UIs over Server-Sent Events (SSE). Manages the entire lifecycle -- state, network requests, SSE parsing, cancellation, and event handling -- in a single useStreamChat hook.

Installation

npm install @deltakit/react

Requires React 18+ and a backend endpoint that streams SSE.

Quick Start

import { useStreamChat } from "@deltakit/react";

function Chat() {
  const { messages, isLoading, sendMessage } = useStreamChat({
    api: "/api/chat",
  });

  return (
    <div>
      {messages.map((msg) => (
        <div key={msg.id}>
          <strong>{msg.role}:</strong>{" "}
          {msg.parts
            .filter((p) => p.type === "text")
            .map((p) => p.text)
            .join("")}
        </div>
      ))}

      {isLoading && <span>Thinking...</span>}

      <form
        onSubmit={(e) => {
          e.preventDefault();
          const input = e.currentTarget.elements.namedItem("message") as HTMLInputElement;
          sendMessage(input.value);
          input.value = "";
        }}
      >
        <input name="message" placeholder="Type a message..." />
        <button type="submit" disabled={isLoading}>Send</button>
      </form>
    </div>
  );
}

API

useStreamChat(options)

const {
  messages,    // Message[]           -- live-updating conversation
  isLoading,   // boolean             -- true while streaming
  error,       // Error | null        -- latest error
  sendMessage, // (text: string) => void -- send and start streaming
  stop,        // () => void          -- abort current stream
  setMessages, // React setState      -- direct state control
} = useStreamChat({
  api: "/api/chat",           // Required. SSE endpoint URL
  initialMessages: [],        // Pre-populate conversation (e.g. from DB)
  headers: {},                // Extra fetch headers (e.g. Authorization)
  body: {},                   // Extra POST body fields
  onEvent: (event, helpers) => {},  // Custom event handler (replaces default)
  onFinish: (messages) => {},       // Stream ended
  onMessage: (message) => {},       // New message added
  onError: (error) => {},           // Fetch/stream error
});

Event Helpers

When using onEvent, you receive helpers for mutating message state during streaming:

onEvent: (event, { appendText, appendPart, setMessages }) => {
  switch (event.type) {
    case "text_delta":
      appendText(event.delta);
      break;
    case "tool_call":
      appendPart({
        type: "tool_call",
        tool_name: event.tool_name,
        argument: event.argument,
        callId: event.call_id,
      });
      break;
    case "tool_result":
      // Use setMessages for complex mutations
      setMessages((prev) =>
        prev.map((msg) => ({
          ...msg,
          parts: msg.parts.map((p) =>
            p.type === "tool_call" && p.callId === event.call_id
              ? { ...p, result: event.output }
              : p
          ),
        }))
      );
      break;
  }
}

Custom Content Parts

Extend with custom types using generics:

type ImagePart = { type: "image"; url: string };
type MyPart = ContentPart | ImagePart;

const { messages } = useStreamChat<MyPart>({
  api: "/api/chat",
  onEvent: (event, { appendPart }) => {
    if (event.type === "image") {
      appendPart({ type: "image", url: event.url });
    }
  },
});

Re-exports from @deltakit/core

This package re-exports everything from @deltakit/core, so you only need one import:

  • parseSSEStream -- SSE stream parser
  • fromOpenAiAgents -- OpenAI Agents SDK history converter
  • All types: Message, ContentPart, TextPart, ToolCallPart, ReasoningPart, SSEEvent, TextDeltaEvent, ToolCallEvent, ToolResultEvent

Documentation

Full documentation, guides, and examples at deltakit.dev.

License

MIT