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

@simulacra-ai/stream-client

v0.0.13

Published

Client-side decoder and RemoteConversation facade for consuming Simulacra Conversation event streams

Readme

@simulacra-ai/stream-client

Client-side counterpart to @simulacra-ai/stream-server. Decodes a wire-format byte stream into typed WireEvents and offers RemoteConversation — a facade that mirrors the local Conversation event-bus surface so UI code can be written once and swapped between local and remote conversations.

Transport-agnostic: RemoteConversation and collect_conversation_result consume any AsyncIterable<WireEvent>. Use decode_ndjson for HTTP NDJSON responses; for SSE or WebSocket sources, write a small generator that yields WireEvents.

Install

npm install @simulacra-ai/stream-client @simulacra-ai/core

@simulacra-ai/core is declared as a peer dependency. The client package uses it only for type imports — no runtime dependency — but the install line above is still required (npm doesn't resolve types from peer-only declarations).

RemoteConversation (NDJSON over HTTP)

The headline API. Treats a remote conversation's stream like a local one's event bus.

import { RemoteConversation, decode_ndjson } from "@simulacra-ai/stream-client";

const res = await fetch("/api/chat", { method: "POST", body });
if (!res.body) throw new Error("missing body");

const conv = new RemoteConversation(decode_ndjson(res.body));

conv.on("content_update", ({ content }) => {
  if (content?.type === "text" && content.text) {
    // `content.text` is the cumulative text so far — to render only the
    // newly-arrived chunk, slice off the previous length.
    ui.appendText(content.text);
  }
});

const { text, tool_calls } = await conv.consume();

Single-use: each RemoteConversation wraps one event source. After consume() resolves or rejects, the instance is exhausted.

WebSocket

Adapt the socket as an async iterable of WireEvents and pass it in:

import type { WireEvent } from "@simulacra-ai/core";
import { RemoteConversation } from "@simulacra-ai/stream-client";

async function* events_from_ws(ws: WebSocket): AsyncGenerator<WireEvent> {
  for await (const msg of /* your ws message iterator */) {
    yield JSON.parse(msg.data) as WireEvent;
  }
}

const conv = new RemoteConversation(events_from_ws(ws));

Lower-level helpers

For consumers that don't want the facade:

import { decode_ndjson, collect_conversation_result } from "@simulacra-ai/stream-client";

// per-event streaming
for await (const event of decode_ndjson(res.body)) {
  // ...
}

// one-shot aggregate
const { text, tool_calls } = await collect_conversation_result(decode_ndjson(res.body));

API

RemoteConversation

  • new RemoteConversation(source: AsyncIterable<WireEvent>)
  • .on(type, listener), .off(type, listener), .once(type, listener) — typed per WireEventType. Listener receives the event's data payload.
  • .consume(options?)Promise<ConversationResult>. Drains, dispatches, aggregates, throws on request_error / lifecycle_error.

decode_ndjson(source, options?) → AsyncGenerator<WireEvent>

Parse an NDJSON byte stream. Handles partial-line buffering, CRLF, and UTF-8 boundaries.

Options:

  • on_parse_error"throw" (default), "skip", or a callback returning a replacement event.
  • abort_signal — cancel the underlying reader and exit cleanly.

collect_conversation_result(events) → Promise<{ text, tool_calls }>

Drain an AsyncIterable<WireEvent> and return the aggregated text + tool calls extracted from message_complete. Throws on request_error / lifecycle_error.

collect_ndjson(source, options?)

Test/utility helper. Drains an NDJSON byte stream into WireEvent[]. Don't use on long-lived streams.