UNPKG

bear-tracker

Version:

Lightweight bot detection middleware for tracking AI crawler visits (OpenAI, ChatGPT, etc.) with API support and analytics

80 lines 2.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BOT_PATTERNS = void 0; exports.detectBot = detectBot; exports.BOT_PATTERNS = [ // OpenAI Bots { name: 'OAI-SearchBot', type: 'ai_search', patterns: [/OAI-SearchBot/i], description: 'OpenAI SearchBot for linking and surfacing websites in ChatGPT search results' }, { name: 'ChatGPT-User', type: 'ai_user', patterns: [/ChatGPT-User/i], description: 'ChatGPT user actions and Custom GPTs web interactions' }, { name: 'GPTBot', type: 'ai_training', patterns: [/GPTBot/i], description: 'OpenAI GPTBot for training generative AI foundation models' }, // Google Search Engine { name: 'Googlebot', type: 'search_engine', patterns: [/Googlebot/i, /Google-InspectionTool/i, /Google-Site-Verification/i], description: 'Google web crawler for search indexing' }, // Additional AI/LLM related bots that might be encountered { name: 'Claude-Web', type: 'ai_user', patterns: [/Claude-Web/i, /Claude/i], description: 'Anthropic Claude web interactions' }, { name: 'Bard', type: 'ai_user', patterns: [/Bard/i, /Google-Extended/i], description: 'Google Bard AI interactions' }, // Generic AI/Bot patterns (fallback) { name: 'AI Bot', type: 'unknown', patterns: [ /\bai\b/i, /\bgpt\b/i, /\bllm\b/i, /\bchat\b/i, /\bassistant\b/i, /\bbot\b/i, /\bcrawler\b/i, /\bspider\b/i ], description: 'Generic AI or bot-like user agent' } ]; function detectBot(userAgent) { if (!userAgent) { return { isBot: false, name: 'Unknown', type: 'unknown' }; } for (const botPattern of exports.BOT_PATTERNS) { for (const pattern of botPattern.patterns) { if (pattern.test(userAgent)) { return { isBot: true, name: botPattern.name, type: botPattern.type, description: botPattern.description }; } } } return { isBot: false, name: 'Human', type: 'unknown' }; } //# sourceMappingURL=bot-patterns.js.map