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

botversion

v0.2.0

Published

Serve AI-optimized versions of your Next.js pages. Detect AI browsers automatically or build AI-native sites.

Readme

botversion

Serve AI-optimized versions of your Next.js pages. Detect AI browsers automatically, or build AI-native sites where humans opt-in to the rich experience.

Install

npm install botversion

Quick Start

1. Add the middleware

// middleware.ts
import { withBotVersion } from 'botversion/middleware';

export default withBotVersion();

2. Add the provider to your layout

// app/layout.tsx
import { isAIBot } from 'botversion/server';
import { BotVersionProvider } from 'botversion/react';

export default async function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html>
      <body>
        <BotVersionProvider isAIBot={await isAIBot()}>
          {children}
        </BotVersionProvider>
      </body>
    </html>
  );
}

3. Use in your pages

// app/page.tsx
import { ForAI, ForHumans } from 'botversion/react';

export default function Page() {
  return (
    <main>
      <h1>My Product</h1>

      <ForHumans>
        <InteractiveCarousel />
        <AnimatedPricing />
        <VideoReviews />
      </ForHumans>

      <ForAI>
        <p>Price: $49.99</p>
        <p>A detailed, structured description of the product...</p>
        <ul>
          <li>Feature 1</li>
          <li>Feature 2</li>
        </ul>
      </ForAI>
    </main>
  );
}

Two Modes

Auto-Detect (default)

Detects AI crawlers (GPTBot, ClaudeBot, PerplexityBot, and 30+ others) via user-agent. Human visitors get the normal site. AI bots get your optimized version.

export default withBotVersion(); // default: auto-detect

AI-Native

Your site is AI-first by default. Human visitors opt-in to the rich version via a query parameter (e.g. ?human=true). The preference is persisted in a cookie.

export default withBotVersion({
  mode: 'ai-native',
  humanParam: 'human', // default — customize if you want ?view=rich, etc.
});

Client-Side Mode Switching

In Next.js App Router, layouts persist across client-side navigations. Use switchToHuman and switchToAI for instant mode switching without a full page reload:

'use client';
import { switchToHuman, switchToAI } from 'botversion/react';

export function ModeToggle() {
  return (
    <>
      <button onClick={() => switchToHuman()}>Humans Click Here</button>
      <button onClick={() => switchToAI()}>Switch to AI View</button>
    </>
  );
}

These functions update the cookie and the BotVersionProvider context in one step. The ?human=true query param still works for direct links and initial page loads.

API Reference

botversion/middleware

withBotVersion(config?) — Creates a Next.js middleware function.

withBotVersion({
  mode: 'auto-detect' | 'ai-native',  // default: 'auto-detect'
  humanParam: string,                   // query param for ai-native mode, default: 'human'
  humanCookie: string,                  // cookie name for persistence, default: 'botversion-human'
  additionalBots: BotInfo[],            // extend the built-in bot list
  headerName: string,                   // custom header name, default: 'x-botversion'
})

detectAndAnnotate(request, config?) — Lower-level function for composing with existing middleware.

import { detectAndAnnotate } from 'botversion/middleware';

export function middleware(request: NextRequest) {
  const { headers, detection, isHuman } = detectAndAnnotate(request);

  // Your own logic...
  if (!isHuman) {
    console.log(`AI bot: ${detection.bot?.name}`);
  }

  return NextResponse.next({ request: { headers } });
}

botversion/server

For use in Server Components and Route Handlers.

import { isAIBot, getAIBotInfo } from 'botversion/server';

// Simple boolean
const bot = await isAIBot();

// Full detection info
const info = await getAIBotInfo();
// { isAIBot: true, bot: { name: 'GPTBot', operator: 'OpenAI', ... }, matchedPattern: 'GPTBot' }

botversion/react

Client-side components and hooks. Requires BotVersionProvider in your layout.

import { ForAI, ForHumans, useIsAIBot, BotVersionProvider, switchToHuman, switchToAI } from 'botversion/react';

// Conditional rendering
<ForAI>Only visible to AI bots</ForAI>
<ForHumans>Only visible to humans</ForHumans>

// With fallbacks
<ForAI fallback={<p>Human version</p>}>AI version</ForAI>

// Hook
const isBot = useIsAIBot();

// Client-side mode switching (ai-native)
switchToHuman()   // set human cookie + update context
switchToAI()      // clear human cookie + update context

botversion/detect

Pure detection engine. Zero dependencies, works anywhere (Edge, Node, browser, Deno).

import { detectAIBot, isAIBot, createDetector, AI_BOTS } from 'botversion/detect';

// Simple check
isAIBot('Mozilla/5.0 (compatible; GPTBot/1.0)'); // true

// Detailed info
detectAIBot('Mozilla/5.0 (compatible; ClaudeBot/1.0)');
// { isAIBot: true, bot: { name: 'ClaudeBot', operator: 'Anthropic', category: 'ai-crawler' }, matchedPattern: 'ClaudeBot' }

// Custom detector with extra bots
const detect = createDetector([
  { name: 'MyInternalBot', operator: 'MyCompany', category: 'ai-crawler' }
]);

Detected Bots

30+ AI bots detected out of the box including:

| Bot | Operator | |-----|----------| | GPTBot, ChatGPT-User, OAI-SearchBot | OpenAI | | ClaudeBot, Claude-SearchBot | Anthropic | | PerplexityBot | Perplexity | | Google-Extended, Gemini-Deep-Research | Google | | Bytespider | ByteDance | | CCBot | Common Crawl | | DeepSeekBot | DeepSeek | | Meta-ExternalAgent | Meta | | Amazonbot, NovaAct | Amazon | | And many more... | |

License

MIT