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

@ai-chans/sdk-js

v0.3.2

Published

JavaScript client for chans.ai voice AI

Downloads

20

Readme

@ai-chans/sdk-js

Core JavaScript/TypeScript client for chans.ai voice AI.

Installation

npm install @ai-chans/sdk-js

Quick Start

import { ChansClient } from "@ai-chans/sdk-js"

const client = new ChansClient({
  agentToken: "agt_your_token"  // From chans.ai dashboard
})

// Listen for events
client.on("transcript", (text) => console.log("User:", text))
client.on("response", (text) => console.log("Agent:", text))
client.on("error", (err) => console.error("Error:", err))

// Connect (requests microphone permission in browsers)
await client.connect({ userId: "user-123" })

// Disconnect when done
await client.disconnect()

API Reference

Constructor

new ChansClient(options: ChansClientOptions)

| Option | Type | Default | Description | |--------|------|---------|-------------| | agentToken | string | required | Agent token from dashboard | | apiUrl | string | https://api.chans.ai | API endpoint | | manualAudioHandling | boolean | false | Handle audio manually (for Node.js) |

Methods

connect(options?)

Connect to the voice agent. In browsers, this requests microphone permission.

await client.connect({ userId: "user-123" })

disconnect()

End the voice session.

await client.disconnect()

getState()

Get current connection state.

const state = client.getState()
// "idle" | "connecting" | "connected" | "listening" | "speaking" | "error"

isConnected()

Check if currently connected.

if (client.isConnected()) {
  // Handle connected state
}

on(event, callback)

Subscribe to events. Returns an unsubscribe function.

const unsubscribe = client.on("transcript", (text) => {
  console.log("User said:", text)
})

// Later: stop listening
unsubscribe()

off(event, callback)

Unsubscribe from events.

client.off("transcript", myHandler)

Events

| Event | Callback | Description | |-------|----------|-------------| | stateChange | (state: ChansState) => void | Connection state changed | | transcript | (text: string) => void | User speech transcribed | | response | (text: string) => void | Agent response text | | error | (error: Error) => void | Error occurred | | connected | () => void | Successfully connected | | disconnected | () => void | Disconnected | | audioTrack | (track: RemoteTrack) => void | Agent audio available | | audioTrackEnded | () => void | Agent audio ended |

States

| State | Description | |-------|-------------| | idle | Not connected | | connecting | Connection in progress | | connected | Connected, initializing | | listening | Listening for user speech | | speaking | Agent is speaking | | error | Error occurred |

Node.js Usage

In Node.js, there's no DOM for audio playback. Enable manual audio handling:

import { ChansClient } from "@ai-chans/sdk-js"

const client = new ChansClient({
  agentToken: "agt_xxx",
  manualAudioHandling: true
})

client.on("audioTrack", (track) => {
  // Handle audio track (LiveKit RemoteTrack)
})

client.on("audioTrackEnded", () => {
  // Agent stopped speaking
})

await client.connect()

Testing

The SDK provides utilities for mocking in tests.

Basic Test Setup

import { ChansClient } from "@ai-chans/sdk-js"
import { createMockClientOptions } from "@ai-chans/sdk-js/testing"

test("client connects", async () => {
  const { getRoom, ...options } = createMockClientOptions()
  const client = new ChansClient(options)

  await client.connect()

  expect(client.getState()).toBe("listening")
})

Simulating Agent Responses

test("receives agent response", async () => {
  const { getRoom, ...options } = createMockClientOptions()
  const client = new ChansClient(options)
  const responses: string[] = []

  client.on("response", (text) => responses.push(text))
  await client.connect()

  // Simulate agent speaking
  getRoom()?.simulateAgentResponse("Hello!")

  expect(responses).toContain("Hello!")
})

Testing Errors

test("handles auth error", async () => {
  const { getRoom, ...options } = createMockClientOptions({
    fetchError: { status: 401, detail: "Invalid token" }
  })
  const client = new ChansClient(options)

  await expect(client.connect()).rejects.toThrow("Invalid token")
  expect(client.getState()).toBe("error")
})

Self-Hosted

Point to your own chans.ai instance:

const client = new ChansClient({
  agentToken: "agt_xxx",
  apiUrl: "https://your-instance.com"
})

Your instance must implement the POST /v1/session endpoint.

License

Apache 2.0