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

@tashiscool/stream

v0.1.0

Published

Streaming utilities for real-time LLM responses

Readme

@llm-utils/stream

Streaming utilities for real-time LLM responses. Handle HTTP streaming, chunk aggregation, and JSONL parsing with ease.

Installation

pnpm add @llm-utils/stream
# or
npm install @llm-utils/stream

Features

  • HTTP Response Interception - Transform streaming responses without breaking semantics
  • Chunk Aggregation - Aggregate chunks from multiple sources with lifecycle handlers
  • JSONL Streaming - Parse and serialize JSONL streams (server and client)
  • Type-Safe - Full TypeScript support with generics

Usage

Intercept and Transform Streaming Responses

import { interceptResponseWrites } from '@llm-utils/stream';

app.post('/chat', async (req, res) => {
  const llmStream = await callLLM(req.body);

  interceptResponseWrites(res, {
    transform: async (chunk) => {
      // Transform each chunk before sending to client
      const data = JSON.parse(chunk);
      const enriched = { ...data, timestamp: Date.now() };
      return JSON.stringify(enriched) + '\n';
    },
    onFinish: async () => {
      // Cleanup after stream ends
      await saveConversation();
    }
  });

  llmStream.pipe(res);
});

Aggregate Chunks from Multiple Sources

import { createChunkAggregator } from '@llm-utils/stream';

const aggregator = createChunkAggregator({
  onBegin: async (message) => {
    console.log(`Starting message from node: ${message.nodeId}`);
  },
  onItem: async (message, delta) => {
    // Stream delta to client
    sendToClient(delta);
  },
  onEnd: async (message) => {
    // Save complete message
    await saveMessage(message);
  },
  onError: async (message, error) => {
    console.error(`Error in ${message.nodeId}:`, error);
  }
});

// Ingest structured chunks
for await (const chunk of structuredStream) {
  await aggregator.ingest(chunk);
}

// Finalize any incomplete messages
await aggregator.finalizeAll();

JSONL Streaming

import { streamJsonLines, parseJsonLines } from '@llm-utils/stream';

// Server: Stream objects as JSONL
app.get('/events', (req, res) => {
  streamJsonLines(res, async function* () {
    for (const event of events) {
      yield event;
    }
  });
});

// Client: Parse JSONL stream
const response = await fetch('/events');
for await (const event of parseJsonLines(response)) {
  handleEvent(event);
}

API Reference

interceptResponseWrites(res, options)

Intercepts Express response writes for transformation.

interface InterceptOptions {
  transform: (text: string) => Promise<string | undefined>;
  onFinish?: () => Promise<void>;
  onError?: (error: Error) => void;
}

createChunkAggregator(handlers)

Creates a stateful chunk aggregator for multi-source streaming.

interface StructuredChunk {
  nodeId: string;
  runIndex: number;
  itemIndex: number;
  type: 'begin' | 'item' | 'end' | 'error';
  data?: string;
  error?: string;
}

interface ChunkHandlers {
  onBegin?: (message: AggregatedMessage) => Promise<void>;
  onItem?: (message: AggregatedMessage, delta: string) => Promise<void>;
  onEnd?: (message: AggregatedMessage) => Promise<void>;
  onError?: (message: AggregatedMessage, error?: string) => Promise<void>;
}

streamJsonLines(res, generator)

Streams objects as JSONL to an HTTP response.

parseJsonLines(response)

Parses a JSONL stream from a fetch Response.

License

MIT