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

@telygent/ai-sdk

v0.1.17

Published

Telygent Conversational AI SDK

Downloads

1,310

Readme

Telygent AI SDK

Client-side SDK to connect your app to Telygent AI. The SDK stores conversation history in your Redis, executes database tools locally, and sends tool results to Telygent for AI reasoning.

Install

npm install @telygent/ai-sdk

Required dependencies

npm install ioredis mongodb

Usage

import { createAiClient, createRedisHistoryStore, createMongoAdapter, type ModelRegistry } from "@telygent/ai-sdk";
import { MongoClient } from "mongodb";

const historyStore = createRedisHistoryStore({
  url: process.env.REDIS_URL as string,
  ttlSeconds: 3600,
});

const mongoClient = new MongoClient(process.env.MONGO_URI as string);
await mongoClient.connect();
const mongoDb = mongoClient.db(process.env.MONGO_DB_NAME as string);

const registry = {
  Statute: {
    collectionName: "canadian_statutes",
    allowedFields: ["title", "shortTitle", "year", "jurisdiction", "topics", "createdAt"],
    links: {
      list: "/laws/statutes",
      detail: "/laws/statutes/{_id}",
      allowedQueryParams: ["year", "jurisdiction", "topics", "createdAt"],
      queryParamMap: {
        year: "year",
        jurisdiction: "jurisdiction",
        topics: "topic",
        createdAt: { gte: "fromDate", lte: "toDate" },
      },
      allowedQueryValues: {
        jurisdiction: ["federal", "provincial"],
      },
    },
    fieldTypes: {
      _id: "objectId",
      createdAt: "date",
    },
    requiredFilters: [
      { field: "jurisdiction", contextKey: "jurisdiction", type: "string" }
    ],
    instructions:
      "Use jurisdiction filters (federal or provincial) and default to the most recent 5 years when dates are missing.",
  },
  CaseLaw: {
    collectionName: "canadian_cases",
    allowedFields: ["title", "citation", "court", "decisionDate", "topics", "summary"],
    links: {
      list: "/laws/cases",
      detail: "/laws/cases/{_id}",
      allowedQueryParams: ["court", "decisionDate", "topics"],
      queryParamMap: {
        court: "court",
        decisionDate: { gte: "fromDate", lte: "toDate" },
        topics: "topic",
      },
    },
    fieldTypes: {
      _id: "objectId",
      decisionDate: "date",
    },
    customServices: [
      {
        name: "case_search",
        description: "Search Canadian case law by title, citation, or topic.",
        inputSchema: {
          properties: {
            query: { type: "string", optional: false, description: "Title, citation, or keyword." },
            court: { type: "string", optional: true, description: "e.g., SCC, FCA, ONSC." },
            year: { type: "number", optional: true, description: "Decision year filter." },
            limit: { type: "number", optional: true, description: "Maximum results to return." }
          }
        }
      },
      {
        name: "case_summary",
        description: "Fetch a short summary for a single case by citation.",
        inputSchema: {
          properties: {
            citation: { type: "string", optional: false, description: "Case citation, e.g. 2018 SCC 10." }
          }
        }
      }
    ]
  },
} satisfies ModelRegistry;

// If you don't have Redis yet, omit `historyStore` and the SDK will use empty history.

const dbAdapter = createMongoAdapter({
  db: mongoDb,
  registry,
});

const client = createAiClient({
  apiKey: process.env.TELYGENT_API_KEY as string,
  aiName: "Atlas",
  registry,
  historyStore,
  dbAdapter,
  customServices: {
    CaseLaw: {
      case_search: async (input) => caseService.search(input),
      case_summary: async (input) => caseService.summary(input),
    },
  },
  log: false,
});

const response = await client.query({
  question: "Show me federal statutes on privacy passed after 2018",
  conversationId: "conv_123",
  userContext: {
    userId: "user_1",
    jurisdiction: "federal",
  },
});

console.log(response.content);

const messages = await client.getConversationMessages("conv_123");
console.log(messages);

Reload conversation history

import { createAiClient, createRedisHistoryStore, type ModelRegistry } from "@telygent/ai-sdk";

const historyStore = createRedisHistoryStore({
  url: process.env.REDIS_URL as string,
});

// Requires Redis. If you don't pass a history store, this returns an empty list.

const client = createAiClient({
  apiKey: process.env.TELYGENT_API_KEY as string,
  aiName: "Atlas",
  historyStore,
});

const messages = await client.getConversationMessages("conv_123");
console.log(messages);

Notes

  • Conversation history lives in your Redis and is sent to Telygent each request.
  • Database queries are executed locally through the adapter you provide.
  • Registry is static and versioned by hash after initial sync.
  • Use requiredFilters to inject fixed constraints into queries.
  • Custom services are optional and let the AI call your own per-model lookup handlers.
  • Use getConversationMessages to reload message history from Redis.
  • For Redis, create a single shared client (or use createRedisHistoryStore) to avoid exhausting the max client limit.

Express middleware

import express from "express";
import { attachAiClient, RedisHistoryStore, createMongoAdapter } from "@telygent/ai-sdk";

const app = express();
app.use(express.json());

app.use(
  attachAiClient({
    apiKey: process.env.TELYGENT_API_KEY as string,
    registry,
    historyStore: new RedisHistoryStore({ client: redisClient }),
    dbAdapter: createMongoAdapter({ db: mongoDb, registry }),
  })
);

app.post("/ask", async (req, res) => {
  const { question, conversationId, userContext } = req.body;
  const response = await req.aiClient!.query({ question, conversationId, userContext });
  res.json(response);
});