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

@johnhenry/aimatey-react-stream

v0.1.6

Published

React streaming utilities for Aimatey - StreamProvider, StreamContext

Readme

@johnhenry/aimatey-react-stream

npm version license

Note: Previously published as [email protected].

React components and utilities for streaming AI responses.

Part of the aimatey monorepo.

Installation

npm install @johnhenry/aimatey-react-stream

Quick Start

import { StreamProvider, useStreamContext, StreamText } from '@johnhenry/aimatey-react-stream';

// Wrap your app with StreamProvider
function App() {
  return (
    <StreamProvider maxStreams={10}>
      <ChatComponent />
    </StreamProvider>
  );
}

// Use streaming in components
function ChatComponent() {
  const { startStream, appendToStream, completeStream, getStream } = useStreamContext();
  const [streamId, setStreamId] = useState<string | null>(null);

  const handleSend = async () => {
    const id = `msg-${Date.now()}`;
    setStreamId(id);
    startStream(id);

    const response = await fetch('/api/chat', { method: 'POST' });
    const reader = response.body?.getReader();
    const decoder = new TextDecoder();

    while (reader) {
      const { done, value } = await reader.read();
      if (done) break;
      appendToStream(id, decoder.decode(value));
    }

    completeStream(id);
  };

  const stream = streamId ? getStream(streamId) : null;

  return (
    <div>
      {stream && (
        <StreamText
          text={stream.text}
          isStreaming={stream.isStreaming}
          showCursor={true}
        />
      )}
      <button onClick={handleSend}>Send</button>
    </div>
  );
}

Exports

Components

  • StreamProvider - Context provider for stream state management
  • StreamText - Display streaming text with cursor
  • TypeWriter - Typewriter effect for static text

Hooks

  • useStreamContext - Access stream management functions
  • useStreamState - Get state for a specific stream

Utilities

  • createTextStream - Create controlled text stream from fetch response
  • parseSSEStream - Parse Server-Sent Events
  • transformStream - Transform stream data
  • mergeStreams - Merge multiple streams
  • fromAsyncIterable - Convert async iterable to stream
  • toAsyncIterable - Convert stream to async iterable

Types

  • StreamState, StreamContextValue, StreamProviderProps
  • StreamTextProps, TypeWriterProps
  • CreateTextStreamOptions, SSEEvent

API Reference

StreamProvider

Context provider for managing multiple concurrent streams.

<StreamProvider maxStreams={100}>
  {children}
</StreamProvider>

Props:

  • maxStreams - Maximum streams to keep (default: 100, oldest completed removed when exceeded)

useStreamContext

Access stream management functions.

const {
  streams,          // Map<string, StreamState> - All streams
  getStream,        // (id: string) => StreamState | undefined
  startStream,      // (id: string, metadata?: object) => void
  updateStream,     // (id: string, text: string) => void - Replace text
  appendToStream,   // (id: string, chunk: string) => void - Append text
  completeStream,   // (id: string) => void - Mark complete
  setStreamError,   // (id: string, error: Error) => void
  removeStream,     // (id: string) => void
  clearAllStreams,  // () => void
} = useStreamContext();

useStreamState

Get state for a specific stream by ID.

const stream = useStreamState('message-1');
// stream: { id, text, isStreaming, error, metadata } | undefined

StreamText

Display streaming text with optional blinking cursor.

<StreamText
  text="Hello world"
  isStreaming={true}
  showCursor={true}           // Show cursor while streaming
  cursor="▋"                  // Cursor character
  cursorBlinkInterval={500}   // Blink speed in ms
  className="my-class"
  renderText={(text) => <Markdown>{text}</Markdown>}
/>

TypeWriter

Simulate typing effect for non-streaming text.

<TypeWriter
  text="Welcome to Aimatey!"
  speed={30}                  // ms per character
  delay={500}                 // ms before starting
  showCursor={true}
  cursor="▋"
  onComplete={() => console.log('Done!')}
/>

Stream Utilities

import {
  createTextStream,
  parseSSEStream,
  fromAsyncIterable,
} from '@johnhenry/aimatey-react-stream';

// Create text stream from fetch response
const text = await createTextStream(response, {
  onChunk: (chunk) => console.log(chunk),
  onComplete: (fullText) => console.log('Done:', fullText),
  signal: abortController.signal,
});

// Parse SSE events
for await (const event of parseSSEStream(response)) {
  console.log(event.data); // { type: 'data' | 'event', data: string }
}

License

MIT - see LICENSE for details.