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

@collieai/sdk

v1.0.0

Published

Node/TypeScript SDK for CollieAi — safe customer-owned LLM streaming and input moderation.

Downloads

310

Readme

@collieai/sdk

Node/TypeScript SDK for CollieAi — safe customer-owned LLM streaming and pre-generation input moderation. You run your own model; the SDK checks the prompt before you call it and lets you stream back only CollieAi-released text — never raw model output. Mirrors the Python SDK.

Status: 0.1.0. Input moderation, streaming preflight, protectStream / protectBuffered, the low-level session, SSE delivery (session.streamEvents

  • browser stream tokens), and provider adapters (@collieai/sdk/adapters/*). Zero runtime dependencies (uses the global fetch).

Install

npm install @collieai/sdk

Quick start

import { CollieClient } from "@collieai/sdk";

const collie = new CollieClient({
  apiKey: "clai_...",
  baseUrl: "https://app.collieai.io",
  projectId: "project_123",
});

Check an input before calling your LLM

const result = await collie.moderate.input({ prompt: userPrompt });
if (result.blocked) return result.blockMessage ?? "Input blocked by policy.";

A policy block is a normal result (result.blocked === true), not an error.

Stream safely (Express)

protectStream checks the input, calls your LLM only if it passes, batches the output, and yields only safe events. Pass a factory — a zero-arg function returning your stream — not an already-started stream.

import { openaiFactory } from "@collieai/sdk/adapters/openai"; // optional helper

const factory = openaiFactory(openai, {
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: prompt }],
});

for await (const event of collie.streaming.protectStream({ input: prompt, rawStreamFactory: factory })) {
  if (event.type === "delta") res.write(event.text);            // forward ONLY safe text
  else if (event.type === "blocked" || event.type === "input_blocked") {
    res.write(event.blockMessage ?? "Blocked by policy.");
    break;
  }
}

See examples/express.ts and examples/next-route.ts.

Choose the UX up front (preflight)

const cap = await collie.streaming.preflight();           // cached until cap.validUntil
if (cap.recommendedClientBehavior === "stream") { /* protectStream */ }
else if (cap.recommendedClientBehavior === "buffer_then_show") {
  const r = await collie.streaming.protectBuffered({ input: prompt, rawStreamFactory: factory });
} else throw new Error(cap.reasonDetail ?? cap.reason ?? "unavailable");

Or pass requireStreaming: true to protectStream — it preflights and throws BufferedFallbackRequired / a PreflightError before calling your LLM.

Relay to a browser (SSE)

import { toSse } from "@collieai/sdk";

for await (const event of session.streamEvents()) {       // auto-resumes from Last-Event-ID
  if (event.type === "interrupted") continue;             // reconnecting; nothing to forward
  res.write(toSse(event));                                // SSE bytes for text/event-stream
  if (event.type === "blocked" || event.type === "finished") break;
}

For direct browser subscription, mint a short-lived, job-scoped token (const st = await session.mintStreamToken()) and open new EventSource(st.url).

Errors

Catch typed errors (all extend CollieError): ChunkRetryExhausted, ChunkPolicyChanged, ChunkQuotaExceeded, ChunkSessionUnrecoverable, ChunkStreamingUnsupported, BufferedFallbackRequired, ProjectNotFound / PlanNotEntitled / … (PreflightError), ProviderStreamFactoryRequired, ConcurrentSessionUseError, ModerationError, CollieConnectionError, CollieApiError.

Develop

npm install
npm run typecheck   # tsc --noEmit
npm test            # vitest
npm run build       # tsc -> dist/