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

@trugen/js-sdk

v1.0.1

Published

JavaScript/TypeScript SDK for the TruGen.ai Platform

Readme

TruGen.AI JavaScript SDK

Official JavaScript/TypeScript client library for integrating TruGen.ai low-latency, real-time conversational video avatars into web applications.


Installation

npm install @trugen/js-sdk

Local Development

The quickest way to start testing the SDK is to use your API key directly with our SDK. To use the SDK, initialize a session using the createClientWithDevApiKey method:

import { createClientWithDevApiKey, TruGenEvent } from '@trugen/js-sdk';

const session = await createClientWithDevApiKey('your-api-key', {
  agentId: 'your-agent-id'
});

// Wire up track events to attach to a DOM video element
session.on(TruGenEvent.VIDEO_STREAM_STARTED, (track) => {
  const videoElement = document.getElementById('video-element-id');
  track.attach(videoElement);
});

await session.connect();

[!WARNING] The method createClientWithDevApiKey is unsafe for production use cases because it exposes your secret API key to the client. For production deployments, follow the instructions in the Usage in Production section below.

To stop a session, use the disconnect method:

await session.disconnect();

Features & Core Capabilities

The TruGenSession class exposes detailed primitives for advanced media control, real-time computer vision, and custom audio input.

Quick Example Snippets

Here are focused, copy-pasteable snippets for common SDK integrations.

1. Getting Started

Initialize and connect to the avatar using a backend-generated session JWT token:

import { createClient } from '@trugen/js-sdk';

const session = await createClient({
  token: 'YOUR_JWT_TOKEN'
});

await session.connect();

2. Media Track Access

Access WebRTC remote media tracks directly, or listen to when they go active:

// Get current active tracks
const videoTrack = session.getVideoTrack(); // RemoteVideoTrack | null
const audioTrack = session.getAudioTrack(); // RemoteAudioTrack | null

// Register callbacks for track activation
session.onVideoTrack((track) => {
  track.attach(document.getElementById('video-element-id'));
});

session.onAudioTrack((track) => {
  // Attach to audio element or WebAudio context
});

3. Video Frame Processing

Process remote decoded video frames in real-time. The SDK automatically handles WebCodecs (VideoFrame) and Canvas fallbacks (ImageData):

session.onVideoFrame((frame) => {
  if (frame instanceof ImageData) {
    // Canvas Fallback - raw pixel data
    const data = frame.data;
  } else {
    // WebCodecs VideoFrame - hardware decoded
    const width = frame.displayWidth;
    // Remember to close the frame to release GPU/memory!
    frame.close();
  }
});

4. Microphone Controls

Manage local hardware microphone publishing states:

// Toggle microphone manually
await session.stopMic();  // Deactivates & unpublishes mic
await session.startMic(); // Re-enables & publishes mic

// Get current state
const { isMuted, permissionState } = session.getInputAudioState();

5. Audio File & Stream Upload

Decodes a local file or raw audio stream on the client side and feeds it into the avatar conversation:

// Stream a pre-recorded audio file (e.g. WAV/MP3)
await session.uploadAudio(audioFile);

// Stream raw audio blob
await session.sendAudio(audioBlob);

Usage in Production

When deploying to production, exchange your API key for a short-lived session token (JWT) on your backend server.

1. Retrieve a Session Token (Server-side)

Your backend should handle authentication and return a single JWT token containing the required connection fields (rtcServerUrl, accessToken, agentId).

const response = await fetch('https://api.trugen.ai/v1/auth/conversation', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': apiKey,
  },
  body: JSON.stringify({
    agentId: 'your-agent-id'
  }),
});
const data = await response.json();
const sessionToken = data.token; // Single short-lived JWT token

2. Initialize the Session (Client-side)

import { createClient, TruGenEvent } from '@trugen/js-sdk';

// Under the hood, createClient decodes the JWT and returns a ready session instance
const session = await createClient({
  token: sessionToken
});

session.on(TruGenEvent.VIDEO_STREAM_STARTED, (track) => {
  const videoElement = document.getElementById('video-element-id');
  track.attach(videoElement);
});

await session.connect();