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

assistant-stream

v0.3.59

Published

Streaming utilities for AI assistants

Readme

assistant-stream

npm version npm downloads bundle size GitHub stars

Framework-agnostic streaming primitives for AI assistant backends. Defines a chunked stream of typed events (text, tool calls, tool results, data parts, message metadata), encoders/decoders for several wire formats, and a server-side tool execution pipeline. Runs in any standard JavaScript runtime; no React or DOM dependencies.

Most apps reach assistant-stream indirectly through @assistant-ui/ai-sdk or @assistant-ui/react-data-stream, which handle the wire format for you. Install it directly when you are building a custom backend or a new integration package.

Installation

npm install assistant-stream

Usage

import { createAssistantStreamResponse } from "assistant-stream";

export async function POST(request: Request) {
  return createAssistantStreamResponse(async (controller) => {
    controller.appendText("Hello, ");
    controller.appendText("world!");
  });
}

createAssistantStreamResponse returns a standard Web Response, so it works out of the box with any Fetch-style route (Next.js App Router, Hono, Bun.serve, Deno, Cloudflare Workers). Frameworks that use their own response objects (Express, Fastify) need a small adapter: copy status and headers, then pipe response.body into the framework's writable stream. Avoid sending the Response body into a res object whose lifecycle is already controlled by the framework (that is the ERR_INVALID_STATE: Controller is already closed failure mode).

createAssistantStreamResponse emits the data stream wire format and sets the x-vercel-ai-data-stream: v1 response header. On the frontend, useDataStreamRuntime({ api }) detects that marker automatically; pass protocol: "data-stream" only if a custom proxy strips or hides the header.

For tool execution, pipe through ToolExecutionStream; for resumable streams (clients can reconnect and replay), import from the assistant-stream/resumable sub-path with a redis or ioredis adapter.

JSON parser backends

registerJsonParserBackend lets integration packages provide an optional backend for shared tool-argument parsing. The JavaScript parser remains the default; assistant-stream has no dependency on a particular backend.

import { registerJsonParserBackend } from "assistant-stream";

const unregister = registerJsonParserBackend(({ text, fallback, createSnapshot }) => {
  return createCustomParser({ text, fallback, createSnapshot });
});

Keep unregister for application cleanup when the backend is no longer needed.

createCustomParser is supplied by the integration. Its returned backend exposes currentArgs and append(delta), which returns the next backend or undefined. The host retains accepted text and its length for native replay. Each backend must preserve its arguments for historical reads and independent branches. createSnapshot(value, state, partialPath) detaches mutable containers and attaches assistant-stream's partial-field metadata; build every currentArgs snapshot with it. Preserve the caller's fallback object until parsing starts. Backends must match the native parser's values, metadata, and security filtering; return undefined for unsupported input. Creation and append failures fall back to native parsing using the accepted text and latest arguments.

Registration is shared across copies of assistant-stream in the same JavaScript realm through a versioned global symbol. The latest registration is used for new parsers. Its unregister function removes only that registration and can be called repeatedly. Removing the latest registration restores the previous active one; removing an older registration leaves the latest one active. Existing parsers retain their backend. Register at application startup, not per request in a shared server process. Complete inputs retain the native fast path.

This affects the shared parser used by message accumulators, active tool readers, and runtimes built on it. Provider SDK parsers remain separate. The AI SDK UI-message decoder currently buffers tool input until it is available, so that path does not gain incremental parsing from a backend.

Using Streamfold

Install streamfold@^0.1.19 in your application, then initialize its integration once at startup before creating streams:

import { initializeAssistantStream } from "streamfold/assistant-ui";

const enabled = await initializeAssistantStream();

enabled is true when the backend is registered. It is false if the installed assistant-stream does not expose registerJsonParserBackend, or if WASM or finalization support is unavailable. Native parsing remains available in those cases. Importing the integration alone does not enable it, and assistant-stream does not install Streamfold for you. Measure your workload before enabling it; small deltas can be slower than native parsing.

Sub-paths

., ./utils, ./ai-sdk, ./internal, ./resumable, ./resumable/redis, ./resumable/ioredis. ./ai-sdk exports frontendTools, which converts the tool schemas an assistant-ui client uploads into AI SDK tools; it works with ai@6 or ai@7, install it alongside (declared as an optional peer). ./internal is an internal-use entry: it is published like every other export, but it only carries the helpers @assistant-ui/ai-sdk shares with ./ai-sdk and is not a supported surface. The two Redis adapters are optional peer dependencies; install whichever client your stack already uses.

Full reference for encoders, tool execution, message conversion, and resumable streams at assistant-ui.com/docs/architecture.