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

@mistscale/web-sdk

v0.0.1-beta

Published

MistScale Web SDK — browser client for NPC chat, voice, and spatial context over the MistScale REST and WebSocket APIs.

Readme

@mistscale/web-sdk

TypeScript-first browser SDK for MistScale: list a project's NPCs and hold realtime chat/voice/spatial-context conversations with them over WebSocket.

Targets browser games, interactive fiction, chat-based games, and chatbot-style demos — anything that can run JavaScript in a browser (or any WebSocket/fetch-capable JS runtime; nothing here is browser-DOM-specific beyond WebSocket, fetch, and crypto.randomUUID).

Install

npm install @mistscale/web-sdk

Quick start

import { MistScale } from '@mistscale/web-sdk';

const mistscale = new MistScale({ apiKey: 'ms_...' }); // Project Settings → API Keys

const npcs = await mistscale.npcs.list();
const connection = mistscale.connect(npcs[0].id);

connection.on('chatChunk', (e) => process.stdout.write(e.delta));   // streamed tokens
connection.on('chatMessage', (e) => console.log('\n[final]', e.text)); // settled turn

connection.on('open', () => connection.sendChat('Hello there!'));

Public API

new MistScale(config)

interface MistScaleConfig {
  apiKey: string;              // required, must start with "ms_"
  controlPlaneUrl?: string;    // default: https://api.mistscale.com
  npcServiceUrl?: string;      // default: https://npc.mistscale.com (auto-upgraded to wss://)
  playerId?: string;           // default sender/player id for every connection; auto-generated if omitted
  requestTimeoutMs?: number;   // default: 15000, REST calls only
}

Throws MistScaleConfigError synchronously if apiKey is missing or malformed — no network call happens at construction time.

mistscale.npcs

  • list(): Promise<NPCSummary[]> — GET /v1/npcs, every NPC in the key's project.
  • verifyKey(): Promise<boolean> — POST /v1/auth/verify-key.

mistscale.connect(npcId, options?): NPCConnection

Opens one WebSocket to one NPC.

interface ConnectOptions {
  playerId?: string;            // overrides MistScaleConfig.playerId for this connection
  instanceId?: string;          // auto-generated UUID if omitted
  autoReconnect?: boolean;      // default true
  maxReconnectDelayMs?: number; // default 30000
}

NPCConnection

Methods:

  • sendChat(message: string, senderId?: string): void
  • sendVoiceChunk(data: ArrayBuffer | Uint8Array, end?: boolean, senderId?: string): void
  • setSpatialContext(location: string, opts?: { timeOfDay?: string; weather?: string }): void
  • getEvolutionStatus(): void / getQuotaStatus(): void
  • close(): void
  • .state: 'connecting' | 'open' | 'closing' | 'closed'

Events (connection.on(event, handler) => unsubscribe):

| Event | Payload | When | |---|---|---| | open | — | socket connected | | close | {code, reason, expected} | socket closed (expected is true for client-initiated closes) | | error | Error | transport-level error | | chatChunk | {chatId, delta} | one streamed token — append | | chatRevision | {chatId, text} | grounding rewrote the reply — replace | | chatMessage | {chatId, text, finalizedByMetadata, metadata?} | turn settled | | transcript | {text} | voice message transcribed | | chatBlocked | {chatType, reason, limit, used} | quota exceeded, no reply generated | | quotaStatus | {text, voice} | reply to getQuotaStatus() | | evolutionStatus | metadata object | reply to getEvolutionStatus() | | audio | ArrayBuffer | synthesized speech (voice replies only) | | reconnecting | {attempt, delayMs} | auto-reconnect about to fire |

Streaming contract: append chatChunk.delta to build the visible text; if chatRevision arrives, replace the accumulated text outright; chatMessage is the settled final state for the turn. See docs/websocket-api.md for the full server-side rationale (this mirrors the buffering the production Unity SDK and dashboard client already do).

Errors

MistScaleError (base) → MistScaleConfigError, MistScaleAPIError → MistScaleAuthError / MistScaleRateLimitError, MistScaleTimeoutError, MistScaleConnectionError. See src/errors.ts.

What this SDK does not do

NPC authoring (create/update/delete), knowledge/RAG upload, behaviour rules, NPC-to-NPC relationships, and the Playground session API are studio/dashboard operations gated behind a dashboard session, not a project API key — they are out of scope for a game client and therefore out of scope for this SDK. See docs/rest-api.md, "Endpoints out of scope for the SDK".

Raw API docs

If you'd rather not install the SDK: docs/rest-api.md and docs/websocket-api.md document the exact same contract this package implements.

Development

npm install
npm run build       # tsup -> dist/ (ESM + CJS + .d.ts)
npm run typecheck
npm test

See examples/vanilla-chat for a working browser example.