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

@prexo/ai-chat-sdk

v1.1.0

Published

AI Chat SDK for building AI chat applications with Context and History

Readme

AI Chat SDK

A comprehensive AI chat SDK that provides persistent history, vector context for building intelligent chat applications.

Features

  • Persistent Message History: Store chat history in memory or Redis
  • Vector Context: Add and retrieve contextual information using vector databases
  • Telemetry: Built-in analytics and usage tracking
  • Flexible Configuration: Support for both external and internal vector databases
  • TypeScript Support: Full TypeScript support with comprehensive type definitions
  • Modular Architecture: Import only what you need
  • Zero Dependencies: Lightweight and tree-shakeable

Installation

npm install @prexo/ai-chat-sdk@latest
# or
yarn add @prexo/ai-chat-sdk@latest
# or
bun add @prexo/ai-chat-sdk@latest

Quick Start

Professional Usage (Recommended)

import { AIChatSDK } from "@prexo/ai-chat-sdk";

// Create SDK instance using constructor - professional approach
const sdk = new AIChatSDK({
  telemetry: { enabled: true },
  context: {
    vector: {
      url: "https://your-vector-db.upstash.io",
      token: "your-token",
      namespace: "your-namespace",
    },
  },
  history: {
    redis: {
      url: "https://your-redis.upstash.io",
      token: "your-token",
    },
  },
});

// Use the configured clients
const contextClient = sdk.getContextClient();
const historyClient = sdk.getHistoryClient();

// Check configuration status
const status = sdk.getConfigurationStatus();
console.log("SDK Status:", status);

Alternative Usage (Convenience Function)

import { createAIChatSDK } from "@prexo/ai-chat-sdk";

// Alternative approach using convenience function
const sdk = createAIChatSDK({
  telemetry: { enabled: true },
});

Basic Usage

import { AIChatSDK } from "@prexo/ai-chat-sdk";

// Create a basic SDK instance
const sdk = new AIChatSDK();

// Check if configured
console.log(sdk.isConfigured()); // false (no context or history configured)

With Vector Context

import { createAIChatSDK } from "@prexo/ai-chat-sdk";

// Configure with external vector database
const sdk = createAIChatSDK({
  context: {
    vector: {
      url: "https://your-vector-db.upstash.io",
      token: "your-token",
      namespace: "your-namespace",
    },
  },
});

// Get the context client
const contextClient = sdk.getContextClient();
if (contextClient) {
  // Add context
  await contextClient.addContext({
    type: "text",
    data: "Your contextual information here",
    options: {
      metadata: { source: "documentation" },
    },
  });

  // Retrieve context
  const results = await contextClient.getContext({
    question: "What is the main feature?",
    topK: 5,
  });
}

With Redis History

import { createAIChatSDK } from "@prexo/ai-chat-sdk";

const sdk = createAIChatSDK({
  history: {
    redis: {
      url: "https://your-redis.upstash.io",
      token: "your-token",
    },
  },
});

const historyClient = sdk.getHistoryClient();

// Add a message
await historyClient.addMessage({
  message: { id: "1", content: "Hello!", role: "user" },
  sessionId: "session-123",
});

// Retrieve messages
const messages = await historyClient.getMessages({
  sessionId: "session-123",
  amount: 10,
});

With Telemetry

import { createAIChatSDK } from "@prexo/ai-chat-sdk";

const sdk = createAIChatSDK({
  telemetry: {
    enabled: true,
    endpoint: "https://api.prexoai.xyz/v1/telementry",
    // Note: sdkVersion is automatically detected - no need to provide it!
  },
});

// Track custom events
await sdk.trackEvent("chat_started", {
  userId: "user-123",
  sessionId: "session-456",
});

Auto-Versioning

The SDK automatically detects and reports its version without requiring manual configuration:

import { createAIChatSDK, SDK_VERSION, SDK_NAME } from "@prexo/ai-chat-sdk";

// Access version information directly
console.log(`Using ${SDK_NAME} version ${SDK_VERSION}`);

// Or get it from the SDK instance
const sdk = createAIChatSDK();
const versionInfo = sdk.getVersionInfo();
console.log(`SDK Version: ${versionInfo.version}`);
console.log(`SDK Name: ${versionInfo.name}`);

How it works:

  • Version is automatically read from package.json during build
  • No need to manually specify sdkVersion in telemetry configuration
  • Version is always up-to-date with your package version
  • Works across all environments (Node.js, browser, bundlers)

Advanced Configuration

Full Configuration Example

import { AIChatSDK } from "@prexo/ai-chat-sdk";

const sdk = new AIChatSDK({
  // Telemetry configuration
  telemetry: {
    enabled: true,
    // sdkVersion is automatically detected
  },

  // Vector context configuration
  context: {
    vector: {
      url: "https://your-vector-db.upstash.io",
      token: "your-token",
      namespace: "your-namespace",
    },
    // Or use internal vector with API key
    // apiKey: 'your-api-key'
  },

  // History configuration
  history: {
    redis: {
      url: "https://your-redis.upstash.io",
      token: "your-token",
    },
  },
});

Using Internal Vector Database

import { AIChatSDK } from "@prexo/ai-chat-sdk";

const sdk = new AIChatSDK({
  context: {
    apiKey: "your-prexo-api-key",
  },
});

const contextClient = sdk.getContextClient();
if (contextClient) {
  // Add context using internal vector database
  await contextClient.addContext({
    type: "text",
    data: "Your contextual information",
    options: {
      namespace: "your-namespace",
      metadata: { source: "documentation" },
    },
  });
}

Modular Imports

You can also import specific modules directly:

// Import only telemetry
import { Telementry } from "@prexo/ai-chat-sdk/telemetry";

// Import only context utilities
import { getContextClient, ExtVector } from "@prexo/ai-chat-sdk/context";

// Import only history utilities
import { getHistoryClient, InMemoryHistory } from "@prexo/ai-chat-sdk/history";

// Import only types
import type { SDKConfig, TelementryOptions } from "@prexo/ai-chat-sdk/types";

API Reference

AIChatSDK Class

Constructor

constructor(config?: SDKConfig)

Methods

  • getTelemetry(): Returns the configured telemetry instance
  • getContextClient(): Returns the configured context client
  • getHistoryClient(): Returns the configured history client
  • getApiKey(): Returns the configured API key
  • trackEvent(event, properties): Sends a telemetry event
  • isConfigured(): Checks if the SDK is properly configured
  • getConfigurationStatus(): Returns detailed configuration status
  • reset(): Resets all configured clients
  • updateConfig(config): Updates the SDK configuration

Context Clients

ExtVector (External Vector Database)

import { ExtVector } from "@prexo/ai-chat-sdk/context";

const extVector = new ExtVector(
  {
    url: "https://your-vector-db.upstash.io",
    token: "your-token",
  },
  "namespace",
);

await extVector.addContext({
  type: "text",
  data: "Your text data",
});

const results = await extVector.getContext({
  question: "Your question",
  topK: 5,
});

IntVector (Internal Vector Database)

import { IntVector } from "@prexo/ai-chat-sdk/context";

const intVector = new IntVector("namespace", "your-api-key");

await intVector.addContext({
  type: "text",
  data: "Your text data",
});

const results = await intVector.getContext({
  question: "Your question",
  topK: 5,
});

History Clients

InMemoryHistory

import { InMemoryHistory } from "@prexo/ai-chat-sdk/history";

const history = new InMemoryHistory();

await history.addMessage({
  message: { id: "1", content: "Hello", role: "user" },
  sessionId: "session-123",
});

const messages = await history.getMessages({
  sessionId: "session-123",
  amount: 10,
});

InRedisHistory

import { InRedisHistory } from "@prexo/ai-chat-sdk/history";

const history = new InRedisHistory({
  config: {
    url: "https://your-redis.upstash.io",
    token: "your-token",
  },
});

await history.addMessage({
  message: { id: "1", content: "Hello", role: "user" },
  sessionId: "session-123",
});

const messages = await history.getMessages({
  sessionId: "session-123",
  amount: 10,
});

Configuration Management

Dynamic Configuration Updates

const sdk = new AIChatSDK({
  telemetry: { enabled: true },
});

// Later, update the configuration
sdk.updateConfig({
  telemetry: { enabled: true },
  context: {
    vector: {
      url: "https://new-vector-db.upstash.io",
      token: "new-token",
      namespace: "new-namespace",
    },
  },
});

// Check configuration status
const status = sdk.getConfigurationStatus();
console.log(status); // { telemetry: true, context: true, history: false }

Environment Variables

  • DISABLE_TELEMETRY=1: Disables telemetry globally
  • PREXO_API_KEY: API key for internal vector database operations

Types

The SDK exports comprehensive TypeScript types:

import type {
  SDKConfig, // Main SDK configuration
  SDKStatus, // SDK configuration status
  TelementryOptions, // Telemetry configuration
  GetContextClientParams, // Context client parameters
  GetHistoryClientParams, // History client parameters
  ExtVectorConfig, // External vector configuration
  RedisHistoryConfig, // Redis history configuration
  EventName, // Event name type
  EventProperties, // Event properties type
} from "@prexo/ai-chat-sdk/types";

Building and Development

# Install dependencies
bun install

# Build the SDK
bun run d:build

# Type checking
bun run type-check

Contributing

This project is licensed under the GNU Affero General Public License v3.0. See the LICENSE file for details.

Support

For support and questions, please visit our documentation or open an issue on GitHub.