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

@idevconn/ai-chat-be

v0.3.0

Published

Drop-in NestJS module for AI chat with multi-provider LLM, RAG, and SSE streaming

Downloads

626

Readme

💬 iDEVconn AI Chat - Backend Module

NPM Version NestJS License: MIT

@idevconn/ai-chat-be is a drop-in, highly-optimized NestJS module that provides an instant, docs-aware AI customer support backend.

No vector database to host, no complex prompt engineering required. Simply point the module at a folder containing your Markdown documentation, and it handles the rest.


🌟 Core Superpowers

⚡ Zero-DB RAG (Retrieval-Augmented Generation)

We completely eliminated the need for external Vector Databases. On application boot, the module reads your local markdown files, generates vector embeddings, and stores them in a lightning-fast, secure in-memory indexing layer.

🛡️ Enterprise-Grade Security Pipeline

Every user input and LLM output goes through a strict, multi-stage security pipeline:

  • Prompt Injection Guard: Advanced pattern matching and Unicode deconfusion blocks exploits.
  • PII Protection: Automatically scans for and redacts sensitive information (Emails, SSNs, Credit Cards, IPs).
  • Cosine Intent Routing: Compares user input embeddings to your document index to identify off-topic questions, automatically redirecting them before they even hit the LLM.

🔌 Multi-Provider Support

Instantly swap between industry-leading LLMs by just changing an environment variable. We natively support:

  • Google Gemini (gemini-2.5-flash)
  • OpenAI (gpt-4o)
  • xAI Grok (grok-3-mini)

🚀 Quick Start Guide

1. Installation

Install the backend module and the required NestJS throttler:

npm install @idevconn/ai-chat-be @nestjs/throttler

2. Register the Module

Import AiChatModule into your root AppModule:

import { Module } from '@nestjs/common';
import { AiChatModule } from '@idevconn/ai-chat-be';

@Module({
  imports: [
    AiChatModule.forRoot({
      // ─── LLM Provider (required) ───────────────────────────
      provider: process.env.AI_CHAT_PROVIDER || 'gemini',
      apiKey: process.env.AI_CHAT_PROVIDER_API_KEY,

      // ─── RAG Settings (optional) ───────────────────────────
      rag: {
        docsPath: './chatdocs', // Folder containing your markdown files
      },

      // ─── Widget Authenticity ───────────────────────────────
      auth: {
        strategy: 'api-key',
        key: process.env.AI_CHAT_WIDGET_API_KEY, // Shared secret with frontend
      },
    }),
  ],
})
export class AppModule {}

3. Add your Markdown Documents

Create a chatdocs/ directory at your project root and drop your markdown guides, help pages, or FAQs in it. The RAG pipeline will index them automatically:

your-nest-app/
├── chatdocs/
│   ├── getting-started.md
│   ├── advanced-features.md
│   └── pricing-faq.md
├── src/
│   └── app.module.ts
└── .env

4. Setup Environment Variables

# Set to 'gemini', 'openai', or 'grok'
AI_CHAT_PROVIDER=gemini
AI_CHAT_PROVIDER_API_KEY=your_api_key_here

# Used to authenticate requests from your frontend widget
AI_CHAT_WIDGET_API_KEY=your_secure_shared_secret

⚙️ Configuration Reference

Provider Options

| Configuration Option | Environmental Variable | Purpose | Default | | :------------------- | :--------------------------------- | :------------------------------ | :----------------------- | | provider | AI_CHAT_PROVIDER | Swaps LLM strategy | 'gemini' | | apiKey | AI_CHAT_PROVIDER_API_KEY | API Key for the chosen provider | (Required) | | model | AI_CHAT_PROVIDER_MODEL | Specific LLM model selection | 'gemini-2.5-flash' | | embeddingModel | AI_CHAT_PROVIDER_EMBEDDING_MODEL | Embedding model override | 'gemini-embedding-001' |

RAG Options

| Configuration Option | Environmental Variable | Purpose | Default | | :------------------- | :---------------------- | :--------------------------- | :--------- | | rag.docsPath | AI_CHAT_DOCS_PATH | Path to your markdown folder | './docs' | | rag.chunkSize | AI_CHAT_CHUNK_SIZE | Words per vector chunk | 250 | | rag.overlapSize | AI_CHAT_CHUNK_OVERLAP | Overlap to maintain context | 50 |

Security & Limits

| Configuration Option | Environmental Variable | Purpose | Default | | :---------------------------- | :--------------------- | :------------------------- | :------ | | limits.maxRequestsPerMinute | AI_CHAT_MAX_RPM | Rate limit per IP address | 10 | | limits.maxInputTokens | AI_CHAT_MAX_INPUT | Hard limit on prompt size | 2000 | | limits.maxOutputTokens | AI_CHAT_MAX_OUTPUT | Maximum length of AI reply | 1000 |


🔗 Pair with the Frontend Widget

This backend is designed to pair perfectly with our universal, framework-agnostic frontend widget. Check out @idevconn/ai-chat-client to complete the integration!