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

@idlen/chat-sdk

v1.0.5

Published

Idlen Chat SDK for AI chatbot publishers - monetize conversations with contextual ads

Readme

@idlen/chat-sdk

Monetize your AI chatbot with contextual, non-intrusive ads. The Idlen Chat SDK analyzes conversation context and serves relevant sponsored content in multiple formats.

Installation

npm install @idlen/chat-sdk

Quick Start

Server-side (Node.js)

import { IdlenChatAds } from '@idlen/chat-sdk/server';

const ads = new IdlenChatAds({ apiKey: 'idl_pk_...' });

// Auto-extract context from conversation text
const ad = await ads.getAd({
  sessionId: conversationId,
  rawText: userMessage,
});

if (ad) {
  response += ad.renderMarkdown();
}

Vercel AI SDK Middleware

import { wrapLanguageModel } from 'ai';
import { idlenAdsMiddleware } from '@idlen/chat-sdk/ai-sdk';

const model = wrapLanguageModel({
  model: openai('gpt-4o'),
  middleware: idlenAdsMiddleware({
    apiKey: 'idl_pk_...',
    frequency: 3,       // inject ad every 3 messages
    position: 'append', // 'append' or 'prepend'
  }),
});

const result = await streamText({ model, prompt: '...' });

React

import { useIdlenAd } from '@idlen/chat-sdk/react';

function ChatMessage({ message }: { message: string }) {
  const { ad, loading, fetchAd, trackClick } = useIdlenAd({
    apiKey: 'idl_pk_...',
  });

  useEffect(() => {
    fetchAd({ rawText: message, sessionId: 'abc' });
  }, [message]);

  return (
    <div>
      <p>{message}</p>
      {ad && (
        <a href={ad.ctaUrl} onClick={trackClick}>
          {ad.title}
        </a>
      )}
    </div>
  );
}

Vue

<script setup>
import { useIdlenAd } from '@idlen/chat-sdk/vue';
import { watch } from 'vue';

const props = defineProps(['message']);
const { ad, loading, fetchAd, trackClick } = useIdlenAd({
  apiKey: 'idl_pk_...',
});

watch(() => props.message, (msg) => {
  fetchAd({ rawText: msg, sessionId: 'abc' });
});
</script>

<template>
  <div>
    <p>{{ message }}</p>
    <a v-if="ad" :href="ad.ctaUrl" @click="trackClick">
      {{ ad.title }}
    </a>
  </div>
</template>

Browser (Script Tag)

<script src="https://chat-sdk.idlen.io/v1/chat-sdk.js"></script>
<script>
  idlenChat('init', 'idl_pk_...');

  const ad = await idlenChat('getAd', {
    sessionId: 'session-123',
    context: {
      topics: ['react', 'deployment'],
      intent: 'informational',
      category: 'devtools',
    },
  });

  if (ad) {
    document.getElementById('ad-slot').innerHTML = ad.renderHTML();
  }
</script>

Ad Formats

| Format | Description | |--------|-------------| | chat_sponsored_recommendation | Suggested tool/product (default) | | chat_cta_card | Call-to-action card with image | | chat_contextual_link | Inline contextual link | | chat_sponsored_answer | Sponsored answer block |

Context Extraction

The SDK includes a built-in dictionary of 120+ tech topics. Pass rawText and context is extracted automatically — no API call needed.

const ads = new IdlenChatAds({ apiKey: 'idl_pk_...' });

// Manual extraction
const context = ads.extractContext('How do I deploy a Next.js app on Vercel?');
// → { topics: ['nextjs', 'vercel'], intent: 'informational', category: 'devtools' }

// Or let getAd() do it automatically
const ad = await ads.getAd({
  sessionId: 'abc',
  rawText: 'How do I deploy a Next.js app on Vercel?',
});

You can also provide context manually:

const ad = await ads.getAd({
  sessionId: 'abc',
  context: {
    topics: ['react', 'deployment'],
    intent: 'transactional',
    category: 'cloud',
  },
});

Rendering

Each ad has three render methods:

ad.renderMarkdown();  // For LLM/chat responses
ad.renderHTML();       // For web UIs
ad.renderPlainText();  // For terminals/logs

Tracking

Impressions are tracked automatically when getAd() returns an ad. Clicks must be tracked manually:

// Server
await ads.trackClick(ad.adId, ad.publisherId, ad.requestId);

// React
const { trackClick } = useIdlenAd({ apiKey: '...' });
<button onClick={trackClick}>Learn more</button>

// Browser (uses sendBeacon)
idlenChat('click', adId, publisherId, requestId);

API Reference

IdlenChatAds (Server)

| Method | Description | |--------|-------------| | getAd(request) | Fetch a contextual ad. Returns ChatAd \| null | | extractContext(text) | Extract topics/intent/category from text | | trackImpression(token, adId, publisherId) | Record an impression (auto-called by getAd) | | trackClick(adId, publisherId, requestId) | Record a click |

idlenAdsMiddleware(options) (AI SDK)

| Option | Type | Default | Description | |--------|------|---------|-------------| | apiKey | string | required | Publisher API key | | format | ChatAdFormat | 'chat_sponsored_recommendation' | Ad format | | frequency | number | 3 | Inject ad every N messages | | position | 'append' \| 'prepend' | 'append' | Where to inject the ad |

useIdlenAd(options) (React / Vue)

Returns { ad, loading, error, fetchAd, trackClick }.

License

MIT