aicrawlers 0.0.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/LICENSE +21 -0
- package/README.md +162 -2
- package/dist/cli.js +207 -0
- package/dist/index.cjs +162 -0
- package/dist/index.d.cts +74 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.js +126 -0
- package/package.json +68 -6
- package/index.js +0 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
- First release.
|
|
6
|
+
- 39 AI crawlers with operator and purpose (training, AI search, user fetch, other), plus official IP-range lists or reverse-DNS hostnames where the operator publishes them.
|
|
7
|
+
- `isAiCrawler()` (also `isAiBot()`) and `getAiCrawler()`, with a `purpose` filter.
|
|
8
|
+
- `aiCrawlerPattern` for web server, CDN and WAF rules.
|
|
9
|
+
- `robotsTxt()` and `nginxMap()` rule generators, including robots.txt-only tokens such as Google-Extended and Applebot-Extended.
|
|
10
|
+
- CLI: `npx aicrawlers check | list | robots | nginx`.
|
|
11
|
+
- Zero dependencies; ESM and CommonJS with types.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CK Giri
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,5 +1,165 @@
|
|
|
1
1
|
# aicrawlers
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Know when a request comes from an AI crawler, and block the ones you don't want.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
A list of 39 AI crawlers (GPTBot, ClaudeBot, PerplexityBot, Bytespider, CCBot…) with who runs each one and what it's for: training AI models, AI search, or fetching a page for a user. Plus `isAiCrawler(userAgent)`, and ready-made robots.txt and nginx rules.
|
|
6
|
+
|
|
7
|
+
Zero dependencies. Works in Node, Bun, Deno, edge runtimes and browsers.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install aicrawlers
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import { isAiCrawler, getAiCrawler } from "aicrawlers";
|
|
15
|
+
|
|
16
|
+
isAiCrawler(req.headers["user-agent"]); // true for GPTBot, ClaudeBot, PerplexityBot…
|
|
17
|
+
|
|
18
|
+
getAiCrawler("Mozilla/5.0 (compatible; GPTBot/1.2; +https://openai.com/gptbot)");
|
|
19
|
+
// { name: "GPTBot", operator: "OpenAI", purpose: "training", ipRanges: "https://openai.com/gptbot.json" }
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Why the purpose matters
|
|
23
|
+
|
|
24
|
+
Not every AI crawler is the same. Blocking all of them can also remove you from ChatGPT search and Perplexity answers, which send visitors back.
|
|
25
|
+
|
|
26
|
+
| Purpose | What it does | Examples |
|
|
27
|
+
|---|---|---|
|
|
28
|
+
| `training` | Collects pages to train AI models | GPTBot, ClaudeBot, CCBot, Bytespider, Google-Extended |
|
|
29
|
+
| `search` | Powers an AI search or answer product, which can link back to you | OAI-SearchBot, Claude-SearchBot, PerplexityBot, Applebot |
|
|
30
|
+
| `user` | Fetches a page because a person asked an assistant about it | ChatGPT-User, Claude-User, Perplexity-User |
|
|
31
|
+
| `other` | Anything else, or not documented | GoogleOther, cohere-ai, FirecrawlAgent |
|
|
32
|
+
|
|
33
|
+
A common choice is **block training, allow search and user fetches**:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
isAiCrawler(userAgent, { purpose: "training" }); // true only for training crawlers
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Common tasks
|
|
40
|
+
|
|
41
|
+
| I want to… | Use |
|
|
42
|
+
|---|---|
|
|
43
|
+
| Check a request in my server | `isAiCrawler(userAgent)` |
|
|
44
|
+
| Know which crawler it is | `getAiCrawler(userAgent)` |
|
|
45
|
+
| Block training crawlers only | `isAiCrawler(userAgent, { purpose: "training" })` |
|
|
46
|
+
| Write robots.txt rules | `npx aicrawlers robots --block training >> robots.txt` |
|
|
47
|
+
| Block on nginx | `npx aicrawlers nginx --block training` |
|
|
48
|
+
| Use a regex in a CDN or WAF rule | `aiCrawlerPattern` |
|
|
49
|
+
| See the whole list | `npx aicrawlers list` or `aiCrawlers` |
|
|
50
|
+
| Check one user agent from the terminal | `npx aicrawlers check "<user agent>"` |
|
|
51
|
+
|
|
52
|
+
## Examples
|
|
53
|
+
|
|
54
|
+
### Express
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
import { isAiCrawler } from "aicrawlers";
|
|
58
|
+
|
|
59
|
+
app.use((req, res, next) => {
|
|
60
|
+
if (isAiCrawler(req.get("user-agent"), { purpose: "training" })) return res.status(403).end();
|
|
61
|
+
next();
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Next.js middleware
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
import { NextResponse } from "next/server";
|
|
69
|
+
import { isAiCrawler } from "aicrawlers";
|
|
70
|
+
|
|
71
|
+
export function middleware(request) {
|
|
72
|
+
if (isAiCrawler(request.headers.get("user-agent"), { purpose: "training" })) {
|
|
73
|
+
return new NextResponse(null, { status: 403 });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### robots.txt
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
npx aicrawlers robots --block training
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
# AI crawler rules, generated by aicrawlers 1.0.0
|
|
86
|
+
# Blocked: training
|
|
87
|
+
User-agent: GPTBot
|
|
88
|
+
User-agent: ClaudeBot
|
|
89
|
+
User-agent: anthropic-ai
|
|
90
|
+
User-agent: Google-Extended
|
|
91
|
+
...
|
|
92
|
+
Disallow: /
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The rules include robots.txt-only tokens such as **Google-Extended** and **Applebot-Extended**. They stop Gemini and Apple Intelligence training without removing you from Google Search or Siri.
|
|
96
|
+
|
|
97
|
+
Block everything except the AI search bots that send you visitors:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npx aicrawlers robots --block all --allow OAI-SearchBot,PerplexityBot,Claude-SearchBot
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Or from code: `robotsTxt({ block: ["training"], allow: [] })`.
|
|
104
|
+
|
|
105
|
+
### nginx
|
|
106
|
+
|
|
107
|
+
robots.txt is a request; well-behaved crawlers follow it, others don't. To enforce it, block on the server:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
npx aicrawlers nginx --block training > /etc/nginx/conf.d/ai-crawlers.conf
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
That defines `$ai_crawler` in the `http` block. Then, in a `server` or `location`:
|
|
114
|
+
|
|
115
|
+
```nginx
|
|
116
|
+
if ($ai_crawler) { return 403; }
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## API
|
|
120
|
+
|
|
121
|
+
| Export | Returns |
|
|
122
|
+
|---|---|
|
|
123
|
+
| `isAiCrawler(userAgent, options?)` | `true` when the User-Agent belongs to a known AI crawler. `isAiBot` is the same function. |
|
|
124
|
+
| `getAiCrawler(userAgent, options?)` | The crawler (`name`, `operator`, `purpose`, and `ipRanges` or `rdns` when known), or `undefined`. |
|
|
125
|
+
| `aiCrawlers` | Every known crawler, frozen. |
|
|
126
|
+
| `aiCrawlerPattern` | A case-insensitive `RegExp` matching any crawler's token. |
|
|
127
|
+
| `robotsTxt(options?)` | robots.txt rules as a string. |
|
|
128
|
+
| `nginxMap(options?)` | An nginx `map` that sets `$ai_crawler`. |
|
|
129
|
+
| `blockedCrawlers(options?)` | The crawlers a set of rule options blocks. |
|
|
130
|
+
| `purposes` | `["training", "search", "user", "other"]` |
|
|
131
|
+
|
|
132
|
+
Options:
|
|
133
|
+
- `isAiCrawler` and `getAiCrawler` take `{ purpose }`: one purpose or a list.
|
|
134
|
+
- `robotsTxt`, `nginxMap` and `blockedCrawlers` take `{ block, allow }`:
|
|
135
|
+
- `block` is a list of purposes or `"all"`, and defaults to `["training"]`;
|
|
136
|
+
- `allow` lists crawler names to leave out.
|
|
137
|
+
|
|
138
|
+
Matching is case-insensitive and on whole tokens: `GPTBot/1.2` matches, `NotGPTBotAtAll` doesn't. It never matches Googlebot, Bingbot, `facebookexternalhit` or browsers, so search engines and link previews keep working.
|
|
139
|
+
|
|
140
|
+
## FAQ
|
|
141
|
+
|
|
142
|
+
**Can a scraper fake the User-Agent?** Yes. A User-Agent is only a claim. For crawlers that publish their IP addresses, `ipRanges` (an official JSON list) or `rdns` (reverse-DNS hostnames) tell you how to confirm it. [botlens](https://github.com/ckgiri/botlens) checks this for you against your server logs.
|
|
143
|
+
|
|
144
|
+
**How is this different from `isbot`?** `isbot` detects all bots and crawlers. aicrawlers detects only AI crawlers, and tells you which one and what it's for, so you can block AI training while keeping search engines, link previews and AI search.
|
|
145
|
+
|
|
146
|
+
**A crawler is missing.** Open an issue or a pull request with a link to the operator's documentation of its User-Agent. The list only includes crawlers whose operator documents them.
|
|
147
|
+
|
|
148
|
+
## Sponsors
|
|
149
|
+
|
|
150
|
+
**Free and open source, MIT-licensed.** If this project saves you or your team time, sponsoring is the best way to give back. It funds maintenance, security fixes and new features across all my open-source packages, so they stay reliable, independent and free for everyone.
|
|
151
|
+
|
|
152
|
+
<p>
|
|
153
|
+
<a href="https://github.com/sponsors/ckgiri"><img src="https://img.shields.io/badge/Sponsor-ckgiri-ea4aaa?logo=githubsponsors&logoColor=white" alt="Sponsor ckgiri on GitHub"></a>
|
|
154
|
+
</p>
|
|
155
|
+
|
|
156
|
+
| Sponsor as | You get |
|
|
157
|
+
|---|---|
|
|
158
|
+
| **A company** | Your logo here, with a link to your site, and early answers on issues that affect you |
|
|
159
|
+
| **An individual** | Your name here, and my thanks |
|
|
160
|
+
|
|
161
|
+
Thank you to everyone who supports this work. Your logo or name could be the first one here: [become a sponsor](https://github.com/sponsors/ckgiri).
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
MIT
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/crawlers.ts
|
|
4
|
+
var GOOGLE_RDNS = ["googlebot.com", "google.com", "googleusercontent.com"];
|
|
5
|
+
var LIST = [
|
|
6
|
+
// OpenAI
|
|
7
|
+
{ name: "GPTBot", operator: "OpenAI", purpose: "training", ipRanges: "https://openai.com/gptbot.json" },
|
|
8
|
+
{ name: "OAI-SearchBot", operator: "OpenAI", purpose: "search", ipRanges: "https://openai.com/searchbot.json" },
|
|
9
|
+
{ name: "ChatGPT-User", operator: "OpenAI", purpose: "user", ipRanges: "https://openai.com/chatgpt-user.json" },
|
|
10
|
+
// Anthropic
|
|
11
|
+
{ name: "ClaudeBot", operator: "Anthropic", purpose: "training" },
|
|
12
|
+
{ name: "Claude-SearchBot", operator: "Anthropic", purpose: "search" },
|
|
13
|
+
{ name: "Claude-User", operator: "Anthropic", purpose: "user" },
|
|
14
|
+
{ name: "Claude-Web", operator: "Anthropic", purpose: "other" },
|
|
15
|
+
{ name: "anthropic-ai", operator: "Anthropic", purpose: "training" },
|
|
16
|
+
// Perplexity
|
|
17
|
+
{ name: "PerplexityBot", operator: "Perplexity", purpose: "search", ipRanges: "https://www.perplexity.com/perplexitybot.json" },
|
|
18
|
+
{ name: "Perplexity-User", operator: "Perplexity", purpose: "user", ipRanges: "https://www.perplexity.com/perplexity-user.json" },
|
|
19
|
+
// Google
|
|
20
|
+
{ name: "Google-Extended", operator: "Google", purpose: "training", robotsOnly: true },
|
|
21
|
+
{ name: "Google-CloudVertexBot", operator: "Google", purpose: "other", rdns: GOOGLE_RDNS },
|
|
22
|
+
{ name: "GoogleOther", operator: "Google", purpose: "other", rdns: GOOGLE_RDNS },
|
|
23
|
+
// Apple
|
|
24
|
+
{ name: "Applebot", operator: "Apple", purpose: "search", rdns: ["applebot.apple.com"] },
|
|
25
|
+
{ name: "Applebot-Extended", operator: "Apple", purpose: "training", robotsOnly: true },
|
|
26
|
+
// Meta
|
|
27
|
+
{ name: "Meta-ExternalAgent", operator: "Meta", purpose: "training" },
|
|
28
|
+
{ name: "Meta-ExternalFetcher", operator: "Meta", purpose: "user" },
|
|
29
|
+
{ name: "FacebookBot", operator: "Meta", purpose: "training" },
|
|
30
|
+
// Others
|
|
31
|
+
{ name: "Amazonbot", operator: "Amazon", purpose: "search" },
|
|
32
|
+
{ name: "Bytespider", operator: "ByteDance", purpose: "training" },
|
|
33
|
+
{ name: "CCBot", operator: "Common Crawl", purpose: "training" },
|
|
34
|
+
{ name: "DuckAssistBot", operator: "DuckDuckGo", purpose: "search" },
|
|
35
|
+
{ name: "MistralAI-User", operator: "Mistral", purpose: "user" },
|
|
36
|
+
{ name: "cohere-training-data-crawler", operator: "Cohere", purpose: "training" },
|
|
37
|
+
{ name: "cohere-ai", operator: "Cohere", purpose: "other" },
|
|
38
|
+
{ name: "AI2Bot", operator: "Allen Institute for AI", purpose: "training" },
|
|
39
|
+
{ name: "Ai2Bot-Dolma", operator: "Allen Institute for AI", purpose: "training" },
|
|
40
|
+
{ name: "PanguBot", operator: "Huawei", purpose: "training" },
|
|
41
|
+
{ name: "Diffbot", operator: "Diffbot", purpose: "training" },
|
|
42
|
+
{ name: "YouBot", operator: "You.com", purpose: "search" },
|
|
43
|
+
{ name: "PhindBot", operator: "Phind", purpose: "search" },
|
|
44
|
+
{ name: "iaskspider", operator: "iAsk.ai", purpose: "search" },
|
|
45
|
+
{ name: "Timpibot", operator: "Timpi", purpose: "training" },
|
|
46
|
+
{ name: "ImagesiftBot", operator: "Hive", purpose: "training" },
|
|
47
|
+
{ name: "Kangaroo Bot", operator: "Kangaroo LLM", purpose: "training" },
|
|
48
|
+
{ name: "img2dataset", operator: "img2dataset", purpose: "training" },
|
|
49
|
+
{ name: "FirecrawlAgent", operator: "Firecrawl", purpose: "other" },
|
|
50
|
+
{ name: "omgili", operator: "Webz.io", purpose: "training", match: ["omgilibot"] },
|
|
51
|
+
{ name: "Webzio-Extended", operator: "Webz.io", purpose: "training", robotsOnly: true }
|
|
52
|
+
];
|
|
53
|
+
var aiCrawlers = Object.freeze(LIST.map((c) => Object.freeze(c)));
|
|
54
|
+
var PURPOSES = ["training", "search", "user", "other"];
|
|
55
|
+
function isPurpose(value) {
|
|
56
|
+
return PURPOSES.includes(value);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/index.ts
|
|
60
|
+
var version = true ? "1.0.0" : "0.0.0-dev";
|
|
61
|
+
var escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
62
|
+
var tokensOf = (c) => [c.name.toLowerCase(), ...c.match ?? []];
|
|
63
|
+
var BY_TOKEN = /* @__PURE__ */ new Map();
|
|
64
|
+
for (const c of aiCrawlers) if (!c.robotsOnly) for (const t of tokensOf(c)) BY_TOKEN.set(t, c);
|
|
65
|
+
var ALTERNATION = [...BY_TOKEN.keys()].sort((a, b) => b.length - a.length).map(escape).join("|");
|
|
66
|
+
var aiCrawlerPattern = new RegExp(`(?<![a-z0-9])(?:${ALTERNATION})(?![a-z0-9])`, "i");
|
|
67
|
+
function purposeFilter(purpose) {
|
|
68
|
+
if (purpose === void 0) return () => true;
|
|
69
|
+
const list2 = typeof purpose === "string" ? [purpose] : purpose;
|
|
70
|
+
for (const p of list2) if (!isPurpose(p)) throw new TypeError(`Unknown purpose "${p}". Use: ${PURPOSES.join(", ")}.`);
|
|
71
|
+
return (c) => list2.includes(c.purpose);
|
|
72
|
+
}
|
|
73
|
+
function getAiCrawler(userAgent, options = {}) {
|
|
74
|
+
if (!userAgent) return void 0;
|
|
75
|
+
const found = aiCrawlerPattern.exec(userAgent);
|
|
76
|
+
const crawler = found ? BY_TOKEN.get(found[0].toLowerCase()) : void 0;
|
|
77
|
+
return crawler && purposeFilter(options.purpose)(crawler) ? crawler : void 0;
|
|
78
|
+
}
|
|
79
|
+
function blockedCrawlers(options = {}) {
|
|
80
|
+
const block = options.block ?? ["training"];
|
|
81
|
+
const inPurpose = block === "all" ? () => true : purposeFilter(block);
|
|
82
|
+
const allow = new Set((options.allow ?? []).map((n) => n.toLowerCase()));
|
|
83
|
+
return aiCrawlers.filter((c) => inPurpose(c) && !allow.has(c.name.toLowerCase()));
|
|
84
|
+
}
|
|
85
|
+
function describe(options) {
|
|
86
|
+
const block = options.block ?? ["training"];
|
|
87
|
+
const what = block === "all" ? "all AI crawlers" : block.length ? block.join(", ") : "nothing";
|
|
88
|
+
const allowed = options.allow?.length ? ` \xB7 Allowed anyway: ${options.allow.join(", ")}` : "";
|
|
89
|
+
return `Blocked: ${what}${allowed}`;
|
|
90
|
+
}
|
|
91
|
+
function robotsTxt(options = {}) {
|
|
92
|
+
const crawlers = blockedCrawlers(options);
|
|
93
|
+
const head = `# AI crawler rules, generated by aicrawlers ${version}
|
|
94
|
+
# ${describe(options)}
|
|
95
|
+
`;
|
|
96
|
+
if (!crawlers.length) return head;
|
|
97
|
+
return `${head}${crawlers.map((c) => `User-agent: ${c.name}`).join("\n")}
|
|
98
|
+
Disallow: /
|
|
99
|
+
`;
|
|
100
|
+
}
|
|
101
|
+
function nginxMap(options = {}) {
|
|
102
|
+
const tokens = blockedCrawlers(options).filter((c) => !c.robotsOnly).flatMap(tokensOf).sort((a, b) => b.length - a.length).map((t) => escape(t).replace(/ /g, "\\s"));
|
|
103
|
+
const head = `# AI crawler rules, generated by aicrawlers ${version}
|
|
104
|
+
# ${describe(options)}
|
|
105
|
+
`;
|
|
106
|
+
const rule = tokens.length ? ` "~*(?<![a-z0-9])(?:${tokens.join("|")})(?![a-z0-9])" 1;
|
|
107
|
+
` : "";
|
|
108
|
+
return `${head}map $http_user_agent $ai_crawler {
|
|
109
|
+
default 0;
|
|
110
|
+
${rule}}
|
|
111
|
+
`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/cli.ts
|
|
115
|
+
var HELP = `aicrawlers ${version}: known AI crawlers, and rules to block them
|
|
116
|
+
|
|
117
|
+
Usage
|
|
118
|
+
aicrawlers check "<user agent>" Is it an AI crawler? (exit code 0 yes, 1 no)
|
|
119
|
+
aicrawlers list [--json] Every known AI crawler
|
|
120
|
+
aicrawlers robots [rule options] robots.txt rules
|
|
121
|
+
aicrawlers nginx [rule options] nginx map for blocking on the server
|
|
122
|
+
|
|
123
|
+
Rule options
|
|
124
|
+
--block <purposes> training, search, user, other, or all (default: training)
|
|
125
|
+
--allow <names> Crawlers to leave out, e.g. OAI-SearchBot,PerplexityBot
|
|
126
|
+
|
|
127
|
+
Options
|
|
128
|
+
--purpose <purposes> list/check: only these purposes
|
|
129
|
+
--json Output JSON
|
|
130
|
+
-h, --help Show this help
|
|
131
|
+
-v, --version Show the version
|
|
132
|
+
|
|
133
|
+
Examples
|
|
134
|
+
npx aicrawlers robots --block training >> robots.txt
|
|
135
|
+
npx aicrawlers check "Mozilla/5.0 (compatible; GPTBot/1.2; +https://openai.com/gptbot)"
|
|
136
|
+
`;
|
|
137
|
+
function fail(message) {
|
|
138
|
+
process.stderr.write(`aicrawlers: ${message}
|
|
139
|
+
Run "aicrawlers --help" for usage.
|
|
140
|
+
`);
|
|
141
|
+
process.exit(2);
|
|
142
|
+
}
|
|
143
|
+
function parseArgs(argv) {
|
|
144
|
+
const positional2 = [];
|
|
145
|
+
const flags2 = {};
|
|
146
|
+
for (let i = 0; i < argv.length; i++) {
|
|
147
|
+
const arg = argv[i];
|
|
148
|
+
if (arg === "-h") flags2.help = true;
|
|
149
|
+
else if (arg === "-v") flags2.version = true;
|
|
150
|
+
else if (arg.startsWith("--")) {
|
|
151
|
+
const [key, inline] = arg.slice(2).split("=", 2);
|
|
152
|
+
if (key === "json" || key === "help" || key === "version") flags2[key] = true;
|
|
153
|
+
else if (inline !== void 0) flags2[key] = inline;
|
|
154
|
+
else if (i + 1 < argv.length) flags2[key] = argv[++i];
|
|
155
|
+
else fail(`--${key} needs a value`);
|
|
156
|
+
} else positional2.push(arg);
|
|
157
|
+
}
|
|
158
|
+
return { positional: positional2, flags: flags2 };
|
|
159
|
+
}
|
|
160
|
+
var list = (value) => typeof value === "string" ? value.split(",").map((s) => s.trim()).filter(Boolean) : void 0;
|
|
161
|
+
function purposeList(value) {
|
|
162
|
+
const items = list(value);
|
|
163
|
+
if (!items) return void 0;
|
|
164
|
+
for (const p of items) if (!PURPOSES.includes(p)) fail(`unknown purpose "${p}". Use: ${PURPOSES.join(", ")}`);
|
|
165
|
+
return items;
|
|
166
|
+
}
|
|
167
|
+
function ruleOptions(flags2) {
|
|
168
|
+
const block = flags2.block === "all" ? "all" : purposeList(flags2.block);
|
|
169
|
+
return { block, allow: list(flags2.allow) };
|
|
170
|
+
}
|
|
171
|
+
var { positional, flags } = parseArgs(process.argv.slice(2));
|
|
172
|
+
var [command, ...rest] = positional;
|
|
173
|
+
if (flags.version) {
|
|
174
|
+
process.stdout.write(`${version}
|
|
175
|
+
`);
|
|
176
|
+
} else if (flags.help || !command) {
|
|
177
|
+
process.stdout.write(HELP);
|
|
178
|
+
} else if (command === "check") {
|
|
179
|
+
const ua = rest.join(" ");
|
|
180
|
+
if (!ua) fail("check needs a user agent");
|
|
181
|
+
const crawler = getAiCrawler(ua, { purpose: purposeList(flags.purpose) });
|
|
182
|
+
if (flags.json) process.stdout.write(`${JSON.stringify(crawler ?? null, null, 2)}
|
|
183
|
+
`);
|
|
184
|
+
else process.stdout.write(crawler ? `AI crawler: ${crawler.name} (${crawler.operator}, ${crawler.purpose})
|
|
185
|
+
` : "Not a known AI crawler\n");
|
|
186
|
+
process.exitCode = crawler ? 0 : 1;
|
|
187
|
+
} else if (command === "list") {
|
|
188
|
+
const only = purposeList(flags.purpose);
|
|
189
|
+
const rows = aiCrawlers.filter((c) => !only || only.includes(c.purpose));
|
|
190
|
+
if (flags.json) process.stdout.write(`${JSON.stringify(rows, null, 2)}
|
|
191
|
+
`);
|
|
192
|
+
else {
|
|
193
|
+
const w = Math.max(...rows.map((c) => c.name.length));
|
|
194
|
+
const o = Math.max(...rows.map((c) => c.operator.length));
|
|
195
|
+
for (const c of rows) {
|
|
196
|
+
const note = c.robotsOnly ? " (robots.txt only)" : "";
|
|
197
|
+
process.stdout.write(`${c.name.padEnd(w)} ${c.operator.padEnd(o)} ${c.purpose}${note}
|
|
198
|
+
`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
} else if (command === "robots") {
|
|
202
|
+
process.stdout.write(robotsTxt(ruleOptions(flags)));
|
|
203
|
+
} else if (command === "nginx") {
|
|
204
|
+
process.stdout.write(nginxMap(ruleOptions(flags)));
|
|
205
|
+
} else {
|
|
206
|
+
fail(`unknown command "${command}"`);
|
|
207
|
+
}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
aiCrawlerPattern: () => aiCrawlerPattern,
|
|
24
|
+
aiCrawlers: () => aiCrawlers,
|
|
25
|
+
blockedCrawlers: () => blockedCrawlers,
|
|
26
|
+
getAiCrawler: () => getAiCrawler,
|
|
27
|
+
isAiBot: () => isAiBot,
|
|
28
|
+
isAiCrawler: () => isAiCrawler,
|
|
29
|
+
nginxMap: () => nginxMap,
|
|
30
|
+
purposes: () => PURPOSES,
|
|
31
|
+
robotsTxt: () => robotsTxt,
|
|
32
|
+
version: () => version
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(src_exports);
|
|
35
|
+
|
|
36
|
+
// src/crawlers.ts
|
|
37
|
+
var GOOGLE_RDNS = ["googlebot.com", "google.com", "googleusercontent.com"];
|
|
38
|
+
var LIST = [
|
|
39
|
+
// OpenAI
|
|
40
|
+
{ name: "GPTBot", operator: "OpenAI", purpose: "training", ipRanges: "https://openai.com/gptbot.json" },
|
|
41
|
+
{ name: "OAI-SearchBot", operator: "OpenAI", purpose: "search", ipRanges: "https://openai.com/searchbot.json" },
|
|
42
|
+
{ name: "ChatGPT-User", operator: "OpenAI", purpose: "user", ipRanges: "https://openai.com/chatgpt-user.json" },
|
|
43
|
+
// Anthropic
|
|
44
|
+
{ name: "ClaudeBot", operator: "Anthropic", purpose: "training" },
|
|
45
|
+
{ name: "Claude-SearchBot", operator: "Anthropic", purpose: "search" },
|
|
46
|
+
{ name: "Claude-User", operator: "Anthropic", purpose: "user" },
|
|
47
|
+
{ name: "Claude-Web", operator: "Anthropic", purpose: "other" },
|
|
48
|
+
{ name: "anthropic-ai", operator: "Anthropic", purpose: "training" },
|
|
49
|
+
// Perplexity
|
|
50
|
+
{ name: "PerplexityBot", operator: "Perplexity", purpose: "search", ipRanges: "https://www.perplexity.com/perplexitybot.json" },
|
|
51
|
+
{ name: "Perplexity-User", operator: "Perplexity", purpose: "user", ipRanges: "https://www.perplexity.com/perplexity-user.json" },
|
|
52
|
+
// Google
|
|
53
|
+
{ name: "Google-Extended", operator: "Google", purpose: "training", robotsOnly: true },
|
|
54
|
+
{ name: "Google-CloudVertexBot", operator: "Google", purpose: "other", rdns: GOOGLE_RDNS },
|
|
55
|
+
{ name: "GoogleOther", operator: "Google", purpose: "other", rdns: GOOGLE_RDNS },
|
|
56
|
+
// Apple
|
|
57
|
+
{ name: "Applebot", operator: "Apple", purpose: "search", rdns: ["applebot.apple.com"] },
|
|
58
|
+
{ name: "Applebot-Extended", operator: "Apple", purpose: "training", robotsOnly: true },
|
|
59
|
+
// Meta
|
|
60
|
+
{ name: "Meta-ExternalAgent", operator: "Meta", purpose: "training" },
|
|
61
|
+
{ name: "Meta-ExternalFetcher", operator: "Meta", purpose: "user" },
|
|
62
|
+
{ name: "FacebookBot", operator: "Meta", purpose: "training" },
|
|
63
|
+
// Others
|
|
64
|
+
{ name: "Amazonbot", operator: "Amazon", purpose: "search" },
|
|
65
|
+
{ name: "Bytespider", operator: "ByteDance", purpose: "training" },
|
|
66
|
+
{ name: "CCBot", operator: "Common Crawl", purpose: "training" },
|
|
67
|
+
{ name: "DuckAssistBot", operator: "DuckDuckGo", purpose: "search" },
|
|
68
|
+
{ name: "MistralAI-User", operator: "Mistral", purpose: "user" },
|
|
69
|
+
{ name: "cohere-training-data-crawler", operator: "Cohere", purpose: "training" },
|
|
70
|
+
{ name: "cohere-ai", operator: "Cohere", purpose: "other" },
|
|
71
|
+
{ name: "AI2Bot", operator: "Allen Institute for AI", purpose: "training" },
|
|
72
|
+
{ name: "Ai2Bot-Dolma", operator: "Allen Institute for AI", purpose: "training" },
|
|
73
|
+
{ name: "PanguBot", operator: "Huawei", purpose: "training" },
|
|
74
|
+
{ name: "Diffbot", operator: "Diffbot", purpose: "training" },
|
|
75
|
+
{ name: "YouBot", operator: "You.com", purpose: "search" },
|
|
76
|
+
{ name: "PhindBot", operator: "Phind", purpose: "search" },
|
|
77
|
+
{ name: "iaskspider", operator: "iAsk.ai", purpose: "search" },
|
|
78
|
+
{ name: "Timpibot", operator: "Timpi", purpose: "training" },
|
|
79
|
+
{ name: "ImagesiftBot", operator: "Hive", purpose: "training" },
|
|
80
|
+
{ name: "Kangaroo Bot", operator: "Kangaroo LLM", purpose: "training" },
|
|
81
|
+
{ name: "img2dataset", operator: "img2dataset", purpose: "training" },
|
|
82
|
+
{ name: "FirecrawlAgent", operator: "Firecrawl", purpose: "other" },
|
|
83
|
+
{ name: "omgili", operator: "Webz.io", purpose: "training", match: ["omgilibot"] },
|
|
84
|
+
{ name: "Webzio-Extended", operator: "Webz.io", purpose: "training", robotsOnly: true }
|
|
85
|
+
];
|
|
86
|
+
var aiCrawlers = Object.freeze(LIST.map((c) => Object.freeze(c)));
|
|
87
|
+
var PURPOSES = ["training", "search", "user", "other"];
|
|
88
|
+
function isPurpose(value) {
|
|
89
|
+
return PURPOSES.includes(value);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/index.ts
|
|
93
|
+
var version = true ? "1.0.0" : "0.0.0-dev";
|
|
94
|
+
var escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
95
|
+
var tokensOf = (c) => [c.name.toLowerCase(), ...c.match ?? []];
|
|
96
|
+
var BY_TOKEN = /* @__PURE__ */ new Map();
|
|
97
|
+
for (const c of aiCrawlers) if (!c.robotsOnly) for (const t of tokensOf(c)) BY_TOKEN.set(t, c);
|
|
98
|
+
var ALTERNATION = [...BY_TOKEN.keys()].sort((a, b) => b.length - a.length).map(escape).join("|");
|
|
99
|
+
var aiCrawlerPattern = new RegExp(`(?<![a-z0-9])(?:${ALTERNATION})(?![a-z0-9])`, "i");
|
|
100
|
+
function purposeFilter(purpose) {
|
|
101
|
+
if (purpose === void 0) return () => true;
|
|
102
|
+
const list = typeof purpose === "string" ? [purpose] : purpose;
|
|
103
|
+
for (const p of list) if (!isPurpose(p)) throw new TypeError(`Unknown purpose "${p}". Use: ${PURPOSES.join(", ")}.`);
|
|
104
|
+
return (c) => list.includes(c.purpose);
|
|
105
|
+
}
|
|
106
|
+
function getAiCrawler(userAgent, options = {}) {
|
|
107
|
+
if (!userAgent) return void 0;
|
|
108
|
+
const found = aiCrawlerPattern.exec(userAgent);
|
|
109
|
+
const crawler = found ? BY_TOKEN.get(found[0].toLowerCase()) : void 0;
|
|
110
|
+
return crawler && purposeFilter(options.purpose)(crawler) ? crawler : void 0;
|
|
111
|
+
}
|
|
112
|
+
function isAiCrawler(userAgent, options = {}) {
|
|
113
|
+
return getAiCrawler(userAgent, options) !== void 0;
|
|
114
|
+
}
|
|
115
|
+
var isAiBot = isAiCrawler;
|
|
116
|
+
function blockedCrawlers(options = {}) {
|
|
117
|
+
const block = options.block ?? ["training"];
|
|
118
|
+
const inPurpose = block === "all" ? () => true : purposeFilter(block);
|
|
119
|
+
const allow = new Set((options.allow ?? []).map((n) => n.toLowerCase()));
|
|
120
|
+
return aiCrawlers.filter((c) => inPurpose(c) && !allow.has(c.name.toLowerCase()));
|
|
121
|
+
}
|
|
122
|
+
function describe(options) {
|
|
123
|
+
const block = options.block ?? ["training"];
|
|
124
|
+
const what = block === "all" ? "all AI crawlers" : block.length ? block.join(", ") : "nothing";
|
|
125
|
+
const allowed = options.allow?.length ? ` \xB7 Allowed anyway: ${options.allow.join(", ")}` : "";
|
|
126
|
+
return `Blocked: ${what}${allowed}`;
|
|
127
|
+
}
|
|
128
|
+
function robotsTxt(options = {}) {
|
|
129
|
+
const crawlers = blockedCrawlers(options);
|
|
130
|
+
const head = `# AI crawler rules, generated by aicrawlers ${version}
|
|
131
|
+
# ${describe(options)}
|
|
132
|
+
`;
|
|
133
|
+
if (!crawlers.length) return head;
|
|
134
|
+
return `${head}${crawlers.map((c) => `User-agent: ${c.name}`).join("\n")}
|
|
135
|
+
Disallow: /
|
|
136
|
+
`;
|
|
137
|
+
}
|
|
138
|
+
function nginxMap(options = {}) {
|
|
139
|
+
const tokens = blockedCrawlers(options).filter((c) => !c.robotsOnly).flatMap(tokensOf).sort((a, b) => b.length - a.length).map((t) => escape(t).replace(/ /g, "\\s"));
|
|
140
|
+
const head = `# AI crawler rules, generated by aicrawlers ${version}
|
|
141
|
+
# ${describe(options)}
|
|
142
|
+
`;
|
|
143
|
+
const rule = tokens.length ? ` "~*(?<![a-z0-9])(?:${tokens.join("|")})(?![a-z0-9])" 1;
|
|
144
|
+
` : "";
|
|
145
|
+
return `${head}map $http_user_agent $ai_crawler {
|
|
146
|
+
default 0;
|
|
147
|
+
${rule}}
|
|
148
|
+
`;
|
|
149
|
+
}
|
|
150
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
151
|
+
0 && (module.exports = {
|
|
152
|
+
aiCrawlerPattern,
|
|
153
|
+
aiCrawlers,
|
|
154
|
+
blockedCrawlers,
|
|
155
|
+
getAiCrawler,
|
|
156
|
+
isAiBot,
|
|
157
|
+
isAiCrawler,
|
|
158
|
+
nginxMap,
|
|
159
|
+
purposes,
|
|
160
|
+
robotsTxt,
|
|
161
|
+
version
|
|
162
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
type Purpose = "training" | "search" | "user" | "other";
|
|
2
|
+
interface AiCrawler {
|
|
3
|
+
/** Product token: what the crawler sends in its User-Agent and obeys in robots.txt. */
|
|
4
|
+
name: string;
|
|
5
|
+
/** Company or project that runs it. */
|
|
6
|
+
operator: string;
|
|
7
|
+
/**
|
|
8
|
+
* What it collects pages for, from the operator's documentation:
|
|
9
|
+
* - "training": data to train AI models
|
|
10
|
+
* - "search": an AI search or answer product
|
|
11
|
+
* - "user": fetches a page because a person asked an assistant about it
|
|
12
|
+
* - "other": anything else, or not documented
|
|
13
|
+
*/
|
|
14
|
+
purpose: Purpose;
|
|
15
|
+
/** Extra lowercase strings matched in the User-Agent. The name always matches. */
|
|
16
|
+
match?: string[];
|
|
17
|
+
/** Only used in robots.txt: it never appears in a User-Agent. */
|
|
18
|
+
robotsOnly?: boolean;
|
|
19
|
+
/** URL of the operator's official JSON list of IP ranges, to tell real requests from fakes. */
|
|
20
|
+
ipRanges?: string;
|
|
21
|
+
/** Reverse-DNS hostname suffixes of real requests, confirmed with a forward lookup. */
|
|
22
|
+
rdns?: string[];
|
|
23
|
+
}
|
|
24
|
+
/** Known AI crawlers and fetchers. Frozen: copy it before changing anything. */
|
|
25
|
+
declare const aiCrawlers: readonly Readonly<AiCrawler>[];
|
|
26
|
+
declare const PURPOSES: readonly Purpose[];
|
|
27
|
+
|
|
28
|
+
/** Version of this package. */
|
|
29
|
+
declare const version: string;
|
|
30
|
+
/**
|
|
31
|
+
* Matches the User-Agent of any known AI crawler, case-insensitively, as a whole token:
|
|
32
|
+
* "GPTBot/1.2" matches, "NotGPTBotX" does not. Use it where a regular expression is all you can
|
|
33
|
+
* pass, such as a web server or CDN rule.
|
|
34
|
+
*/
|
|
35
|
+
declare const aiCrawlerPattern: RegExp;
|
|
36
|
+
interface MatchOptions {
|
|
37
|
+
/** Only count crawlers with these purposes, e.g. `["training"]`. */
|
|
38
|
+
purpose?: Purpose | readonly Purpose[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The AI crawler a User-Agent belongs to, or `undefined` when it isn't one.
|
|
42
|
+
*
|
|
43
|
+
* This reads the User-Agent only, which anyone can fake. To be sure a request really comes from
|
|
44
|
+
* the crawler, check its IP against `ipRanges` or `rdns` where the crawler has them.
|
|
45
|
+
*/
|
|
46
|
+
declare function getAiCrawler(userAgent: string | null | undefined, options?: MatchOptions): Readonly<AiCrawler> | undefined;
|
|
47
|
+
/** Whether a User-Agent belongs to a known AI crawler. */
|
|
48
|
+
declare function isAiCrawler(userAgent: string | null | undefined, options?: MatchOptions): boolean;
|
|
49
|
+
/** Same as `isAiCrawler`. */
|
|
50
|
+
declare const isAiBot: typeof isAiCrawler;
|
|
51
|
+
interface RuleOptions {
|
|
52
|
+
/** Purposes to block. `"all"` blocks every AI crawler. Default: `["training"]`. */
|
|
53
|
+
block?: readonly Purpose[] | "all";
|
|
54
|
+
/** Crawler names to leave out even when their purpose is blocked, e.g. `["OAI-SearchBot"]`. */
|
|
55
|
+
allow?: readonly string[];
|
|
56
|
+
}
|
|
57
|
+
/** The crawlers a set of rule options blocks. */
|
|
58
|
+
declare function blockedCrawlers(options?: RuleOptions): Readonly<AiCrawler>[];
|
|
59
|
+
/**
|
|
60
|
+
* robots.txt rules that block AI crawlers. Paste them into robots.txt, or append them to your
|
|
61
|
+
* own rules. Polite crawlers obey robots.txt; to stop the rest, block them on the server too.
|
|
62
|
+
*
|
|
63
|
+
* ```js
|
|
64
|
+
* robotsTxt({ block: ["training"] }) // keep AI search, block training
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
declare function robotsTxt(options?: RuleOptions): string;
|
|
68
|
+
/**
|
|
69
|
+
* An nginx `map` that sets `$ai_crawler` to 1 for blocked crawlers. Put it in the `http` block,
|
|
70
|
+
* then add `if ($ai_crawler) { return 403; }` to a `server` or `location`.
|
|
71
|
+
*/
|
|
72
|
+
declare function nginxMap(options?: RuleOptions): string;
|
|
73
|
+
|
|
74
|
+
export { type AiCrawler, type MatchOptions, type Purpose, type RuleOptions, aiCrawlerPattern, aiCrawlers, blockedCrawlers, getAiCrawler, isAiBot, isAiCrawler, nginxMap, PURPOSES as purposes, robotsTxt, version };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
type Purpose = "training" | "search" | "user" | "other";
|
|
2
|
+
interface AiCrawler {
|
|
3
|
+
/** Product token: what the crawler sends in its User-Agent and obeys in robots.txt. */
|
|
4
|
+
name: string;
|
|
5
|
+
/** Company or project that runs it. */
|
|
6
|
+
operator: string;
|
|
7
|
+
/**
|
|
8
|
+
* What it collects pages for, from the operator's documentation:
|
|
9
|
+
* - "training": data to train AI models
|
|
10
|
+
* - "search": an AI search or answer product
|
|
11
|
+
* - "user": fetches a page because a person asked an assistant about it
|
|
12
|
+
* - "other": anything else, or not documented
|
|
13
|
+
*/
|
|
14
|
+
purpose: Purpose;
|
|
15
|
+
/** Extra lowercase strings matched in the User-Agent. The name always matches. */
|
|
16
|
+
match?: string[];
|
|
17
|
+
/** Only used in robots.txt: it never appears in a User-Agent. */
|
|
18
|
+
robotsOnly?: boolean;
|
|
19
|
+
/** URL of the operator's official JSON list of IP ranges, to tell real requests from fakes. */
|
|
20
|
+
ipRanges?: string;
|
|
21
|
+
/** Reverse-DNS hostname suffixes of real requests, confirmed with a forward lookup. */
|
|
22
|
+
rdns?: string[];
|
|
23
|
+
}
|
|
24
|
+
/** Known AI crawlers and fetchers. Frozen: copy it before changing anything. */
|
|
25
|
+
declare const aiCrawlers: readonly Readonly<AiCrawler>[];
|
|
26
|
+
declare const PURPOSES: readonly Purpose[];
|
|
27
|
+
|
|
28
|
+
/** Version of this package. */
|
|
29
|
+
declare const version: string;
|
|
30
|
+
/**
|
|
31
|
+
* Matches the User-Agent of any known AI crawler, case-insensitively, as a whole token:
|
|
32
|
+
* "GPTBot/1.2" matches, "NotGPTBotX" does not. Use it where a regular expression is all you can
|
|
33
|
+
* pass, such as a web server or CDN rule.
|
|
34
|
+
*/
|
|
35
|
+
declare const aiCrawlerPattern: RegExp;
|
|
36
|
+
interface MatchOptions {
|
|
37
|
+
/** Only count crawlers with these purposes, e.g. `["training"]`. */
|
|
38
|
+
purpose?: Purpose | readonly Purpose[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The AI crawler a User-Agent belongs to, or `undefined` when it isn't one.
|
|
42
|
+
*
|
|
43
|
+
* This reads the User-Agent only, which anyone can fake. To be sure a request really comes from
|
|
44
|
+
* the crawler, check its IP against `ipRanges` or `rdns` where the crawler has them.
|
|
45
|
+
*/
|
|
46
|
+
declare function getAiCrawler(userAgent: string | null | undefined, options?: MatchOptions): Readonly<AiCrawler> | undefined;
|
|
47
|
+
/** Whether a User-Agent belongs to a known AI crawler. */
|
|
48
|
+
declare function isAiCrawler(userAgent: string | null | undefined, options?: MatchOptions): boolean;
|
|
49
|
+
/** Same as `isAiCrawler`. */
|
|
50
|
+
declare const isAiBot: typeof isAiCrawler;
|
|
51
|
+
interface RuleOptions {
|
|
52
|
+
/** Purposes to block. `"all"` blocks every AI crawler. Default: `["training"]`. */
|
|
53
|
+
block?: readonly Purpose[] | "all";
|
|
54
|
+
/** Crawler names to leave out even when their purpose is blocked, e.g. `["OAI-SearchBot"]`. */
|
|
55
|
+
allow?: readonly string[];
|
|
56
|
+
}
|
|
57
|
+
/** The crawlers a set of rule options blocks. */
|
|
58
|
+
declare function blockedCrawlers(options?: RuleOptions): Readonly<AiCrawler>[];
|
|
59
|
+
/**
|
|
60
|
+
* robots.txt rules that block AI crawlers. Paste them into robots.txt, or append them to your
|
|
61
|
+
* own rules. Polite crawlers obey robots.txt; to stop the rest, block them on the server too.
|
|
62
|
+
*
|
|
63
|
+
* ```js
|
|
64
|
+
* robotsTxt({ block: ["training"] }) // keep AI search, block training
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
declare function robotsTxt(options?: RuleOptions): string;
|
|
68
|
+
/**
|
|
69
|
+
* An nginx `map` that sets `$ai_crawler` to 1 for blocked crawlers. Put it in the `http` block,
|
|
70
|
+
* then add `if ($ai_crawler) { return 403; }` to a `server` or `location`.
|
|
71
|
+
*/
|
|
72
|
+
declare function nginxMap(options?: RuleOptions): string;
|
|
73
|
+
|
|
74
|
+
export { type AiCrawler, type MatchOptions, type Purpose, type RuleOptions, aiCrawlerPattern, aiCrawlers, blockedCrawlers, getAiCrawler, isAiBot, isAiCrawler, nginxMap, PURPOSES as purposes, robotsTxt, version };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// src/crawlers.ts
|
|
2
|
+
var GOOGLE_RDNS = ["googlebot.com", "google.com", "googleusercontent.com"];
|
|
3
|
+
var LIST = [
|
|
4
|
+
// OpenAI
|
|
5
|
+
{ name: "GPTBot", operator: "OpenAI", purpose: "training", ipRanges: "https://openai.com/gptbot.json" },
|
|
6
|
+
{ name: "OAI-SearchBot", operator: "OpenAI", purpose: "search", ipRanges: "https://openai.com/searchbot.json" },
|
|
7
|
+
{ name: "ChatGPT-User", operator: "OpenAI", purpose: "user", ipRanges: "https://openai.com/chatgpt-user.json" },
|
|
8
|
+
// Anthropic
|
|
9
|
+
{ name: "ClaudeBot", operator: "Anthropic", purpose: "training" },
|
|
10
|
+
{ name: "Claude-SearchBot", operator: "Anthropic", purpose: "search" },
|
|
11
|
+
{ name: "Claude-User", operator: "Anthropic", purpose: "user" },
|
|
12
|
+
{ name: "Claude-Web", operator: "Anthropic", purpose: "other" },
|
|
13
|
+
{ name: "anthropic-ai", operator: "Anthropic", purpose: "training" },
|
|
14
|
+
// Perplexity
|
|
15
|
+
{ name: "PerplexityBot", operator: "Perplexity", purpose: "search", ipRanges: "https://www.perplexity.com/perplexitybot.json" },
|
|
16
|
+
{ name: "Perplexity-User", operator: "Perplexity", purpose: "user", ipRanges: "https://www.perplexity.com/perplexity-user.json" },
|
|
17
|
+
// Google
|
|
18
|
+
{ name: "Google-Extended", operator: "Google", purpose: "training", robotsOnly: true },
|
|
19
|
+
{ name: "Google-CloudVertexBot", operator: "Google", purpose: "other", rdns: GOOGLE_RDNS },
|
|
20
|
+
{ name: "GoogleOther", operator: "Google", purpose: "other", rdns: GOOGLE_RDNS },
|
|
21
|
+
// Apple
|
|
22
|
+
{ name: "Applebot", operator: "Apple", purpose: "search", rdns: ["applebot.apple.com"] },
|
|
23
|
+
{ name: "Applebot-Extended", operator: "Apple", purpose: "training", robotsOnly: true },
|
|
24
|
+
// Meta
|
|
25
|
+
{ name: "Meta-ExternalAgent", operator: "Meta", purpose: "training" },
|
|
26
|
+
{ name: "Meta-ExternalFetcher", operator: "Meta", purpose: "user" },
|
|
27
|
+
{ name: "FacebookBot", operator: "Meta", purpose: "training" },
|
|
28
|
+
// Others
|
|
29
|
+
{ name: "Amazonbot", operator: "Amazon", purpose: "search" },
|
|
30
|
+
{ name: "Bytespider", operator: "ByteDance", purpose: "training" },
|
|
31
|
+
{ name: "CCBot", operator: "Common Crawl", purpose: "training" },
|
|
32
|
+
{ name: "DuckAssistBot", operator: "DuckDuckGo", purpose: "search" },
|
|
33
|
+
{ name: "MistralAI-User", operator: "Mistral", purpose: "user" },
|
|
34
|
+
{ name: "cohere-training-data-crawler", operator: "Cohere", purpose: "training" },
|
|
35
|
+
{ name: "cohere-ai", operator: "Cohere", purpose: "other" },
|
|
36
|
+
{ name: "AI2Bot", operator: "Allen Institute for AI", purpose: "training" },
|
|
37
|
+
{ name: "Ai2Bot-Dolma", operator: "Allen Institute for AI", purpose: "training" },
|
|
38
|
+
{ name: "PanguBot", operator: "Huawei", purpose: "training" },
|
|
39
|
+
{ name: "Diffbot", operator: "Diffbot", purpose: "training" },
|
|
40
|
+
{ name: "YouBot", operator: "You.com", purpose: "search" },
|
|
41
|
+
{ name: "PhindBot", operator: "Phind", purpose: "search" },
|
|
42
|
+
{ name: "iaskspider", operator: "iAsk.ai", purpose: "search" },
|
|
43
|
+
{ name: "Timpibot", operator: "Timpi", purpose: "training" },
|
|
44
|
+
{ name: "ImagesiftBot", operator: "Hive", purpose: "training" },
|
|
45
|
+
{ name: "Kangaroo Bot", operator: "Kangaroo LLM", purpose: "training" },
|
|
46
|
+
{ name: "img2dataset", operator: "img2dataset", purpose: "training" },
|
|
47
|
+
{ name: "FirecrawlAgent", operator: "Firecrawl", purpose: "other" },
|
|
48
|
+
{ name: "omgili", operator: "Webz.io", purpose: "training", match: ["omgilibot"] },
|
|
49
|
+
{ name: "Webzio-Extended", operator: "Webz.io", purpose: "training", robotsOnly: true }
|
|
50
|
+
];
|
|
51
|
+
var aiCrawlers = Object.freeze(LIST.map((c) => Object.freeze(c)));
|
|
52
|
+
var PURPOSES = ["training", "search", "user", "other"];
|
|
53
|
+
function isPurpose(value) {
|
|
54
|
+
return PURPOSES.includes(value);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/index.ts
|
|
58
|
+
var version = true ? "1.0.0" : "0.0.0-dev";
|
|
59
|
+
var escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
60
|
+
var tokensOf = (c) => [c.name.toLowerCase(), ...c.match ?? []];
|
|
61
|
+
var BY_TOKEN = /* @__PURE__ */ new Map();
|
|
62
|
+
for (const c of aiCrawlers) if (!c.robotsOnly) for (const t of tokensOf(c)) BY_TOKEN.set(t, c);
|
|
63
|
+
var ALTERNATION = [...BY_TOKEN.keys()].sort((a, b) => b.length - a.length).map(escape).join("|");
|
|
64
|
+
var aiCrawlerPattern = new RegExp(`(?<![a-z0-9])(?:${ALTERNATION})(?![a-z0-9])`, "i");
|
|
65
|
+
function purposeFilter(purpose) {
|
|
66
|
+
if (purpose === void 0) return () => true;
|
|
67
|
+
const list = typeof purpose === "string" ? [purpose] : purpose;
|
|
68
|
+
for (const p of list) if (!isPurpose(p)) throw new TypeError(`Unknown purpose "${p}". Use: ${PURPOSES.join(", ")}.`);
|
|
69
|
+
return (c) => list.includes(c.purpose);
|
|
70
|
+
}
|
|
71
|
+
function getAiCrawler(userAgent, options = {}) {
|
|
72
|
+
if (!userAgent) return void 0;
|
|
73
|
+
const found = aiCrawlerPattern.exec(userAgent);
|
|
74
|
+
const crawler = found ? BY_TOKEN.get(found[0].toLowerCase()) : void 0;
|
|
75
|
+
return crawler && purposeFilter(options.purpose)(crawler) ? crawler : void 0;
|
|
76
|
+
}
|
|
77
|
+
function isAiCrawler(userAgent, options = {}) {
|
|
78
|
+
return getAiCrawler(userAgent, options) !== void 0;
|
|
79
|
+
}
|
|
80
|
+
var isAiBot = isAiCrawler;
|
|
81
|
+
function blockedCrawlers(options = {}) {
|
|
82
|
+
const block = options.block ?? ["training"];
|
|
83
|
+
const inPurpose = block === "all" ? () => true : purposeFilter(block);
|
|
84
|
+
const allow = new Set((options.allow ?? []).map((n) => n.toLowerCase()));
|
|
85
|
+
return aiCrawlers.filter((c) => inPurpose(c) && !allow.has(c.name.toLowerCase()));
|
|
86
|
+
}
|
|
87
|
+
function describe(options) {
|
|
88
|
+
const block = options.block ?? ["training"];
|
|
89
|
+
const what = block === "all" ? "all AI crawlers" : block.length ? block.join(", ") : "nothing";
|
|
90
|
+
const allowed = options.allow?.length ? ` \xB7 Allowed anyway: ${options.allow.join(", ")}` : "";
|
|
91
|
+
return `Blocked: ${what}${allowed}`;
|
|
92
|
+
}
|
|
93
|
+
function robotsTxt(options = {}) {
|
|
94
|
+
const crawlers = blockedCrawlers(options);
|
|
95
|
+
const head = `# AI crawler rules, generated by aicrawlers ${version}
|
|
96
|
+
# ${describe(options)}
|
|
97
|
+
`;
|
|
98
|
+
if (!crawlers.length) return head;
|
|
99
|
+
return `${head}${crawlers.map((c) => `User-agent: ${c.name}`).join("\n")}
|
|
100
|
+
Disallow: /
|
|
101
|
+
`;
|
|
102
|
+
}
|
|
103
|
+
function nginxMap(options = {}) {
|
|
104
|
+
const tokens = blockedCrawlers(options).filter((c) => !c.robotsOnly).flatMap(tokensOf).sort((a, b) => b.length - a.length).map((t) => escape(t).replace(/ /g, "\\s"));
|
|
105
|
+
const head = `# AI crawler rules, generated by aicrawlers ${version}
|
|
106
|
+
# ${describe(options)}
|
|
107
|
+
`;
|
|
108
|
+
const rule = tokens.length ? ` "~*(?<![a-z0-9])(?:${tokens.join("|")})(?![a-z0-9])" 1;
|
|
109
|
+
` : "";
|
|
110
|
+
return `${head}map $http_user_agent $ai_crawler {
|
|
111
|
+
default 0;
|
|
112
|
+
${rule}}
|
|
113
|
+
`;
|
|
114
|
+
}
|
|
115
|
+
export {
|
|
116
|
+
aiCrawlerPattern,
|
|
117
|
+
aiCrawlers,
|
|
118
|
+
blockedCrawlers,
|
|
119
|
+
getAiCrawler,
|
|
120
|
+
isAiBot,
|
|
121
|
+
isAiCrawler,
|
|
122
|
+
nginxMap,
|
|
123
|
+
PURPOSES as purposes,
|
|
124
|
+
robotsTxt,
|
|
125
|
+
version
|
|
126
|
+
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,72 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aicrawlers",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"keywords": [
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Known AI crawlers (GPTBot, ClaudeBot, PerplexityBot and 36 more) with what each one is for, isAiCrawler(userAgent), and robots.txt and nginx rules to block them. Zero dependencies.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ai-crawlers",
|
|
7
|
+
"ai-bots",
|
|
8
|
+
"isbot",
|
|
9
|
+
"bot-detection",
|
|
10
|
+
"user-agent",
|
|
11
|
+
"crawler",
|
|
12
|
+
"gptbot",
|
|
13
|
+
"claudebot",
|
|
14
|
+
"perplexitybot",
|
|
15
|
+
"robots.txt",
|
|
16
|
+
"nginx",
|
|
17
|
+
"middleware",
|
|
18
|
+
"llm",
|
|
19
|
+
"ai-training"
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
8
22
|
"author": "CK Giri <ckgdev@gmail.com>",
|
|
9
|
-
"
|
|
23
|
+
"homepage": "https://github.com/ckgiri/aicrawlers#readme",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/ckgiri/aicrawlers.git"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/ckgiri/aicrawlers/issues"
|
|
30
|
+
},
|
|
31
|
+
"funding": "https://github.com/sponsors/ckgiri",
|
|
32
|
+
"type": "module",
|
|
33
|
+
"sideEffects": false,
|
|
34
|
+
"main": "./dist/index.cjs",
|
|
35
|
+
"module": "./dist/index.js",
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"bin": {
|
|
38
|
+
"aicrawlers": "./dist/cli.js"
|
|
39
|
+
},
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"import": {
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"default": "./dist/index.js"
|
|
45
|
+
},
|
|
46
|
+
"require": {
|
|
47
|
+
"types": "./dist/index.d.cts",
|
|
48
|
+
"default": "./dist/index.cjs"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"./package.json": "./package.json"
|
|
52
|
+
},
|
|
53
|
+
"files": [
|
|
54
|
+
"dist",
|
|
55
|
+
"CHANGELOG.md"
|
|
56
|
+
],
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=18"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "tsup",
|
|
62
|
+
"test": "tsup --silent && vitest run",
|
|
63
|
+
"typecheck": "tsc -p .",
|
|
64
|
+
"prepublishOnly": "npm run typecheck && npm test"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@types/node": "^20.14.0",
|
|
68
|
+
"tsup": "^8.3.0",
|
|
69
|
+
"typescript": "^5.6.0",
|
|
70
|
+
"vitest": "^2.1.0"
|
|
71
|
+
}
|
|
10
72
|
}
|
package/index.js
DELETED