@knownagents/sdk 1.11.0 → 2.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/README.md +82 -43
- package/dist/KnownAgents.d.ts +74 -0
- package/dist/KnownAgents.d.ts.map +1 -0
- package/dist/KnownAgents.js +247 -0
- package/dist/commerce.d.ts +28 -0
- package/dist/commerce.d.ts.map +1 -0
- package/dist/commerce.js +51 -0
- package/dist/headers.d.ts +6 -0
- package/dist/headers.d.ts.map +1 -0
- package/dist/headers.js +54 -0
- package/dist/index.d.ts +2 -156
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -253
- package/dist/paths.d.ts +2 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +72 -0
- package/dist/types.d.ts +133 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +25 -0
- package/package.json +14 -1
- package/src/KnownAgents.ts +324 -0
- package/src/commerce.ts +68 -0
- package/src/headers.ts +56 -0
- package/src/index.ts +10 -353
- package/src/paths.ts +72 -0
- package/src/types.ts +139 -0
- package/tsconfig.json +0 -16
package/dist/headers.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFilteredHeaders = getFilteredHeaders;
|
|
4
|
+
exports.getIsMCPCall = getIsMCPCall;
|
|
5
|
+
exports.getIsUCPCall = getIsUCPCall;
|
|
6
|
+
exports.getIsProbablyACPCall = getIsProbablyACPCall;
|
|
7
|
+
const filteredHeaderNames = [
|
|
8
|
+
"authorization",
|
|
9
|
+
"proxy-authorization",
|
|
10
|
+
"cookie",
|
|
11
|
+
"set-cookie",
|
|
12
|
+
"x-api-key",
|
|
13
|
+
"api-key",
|
|
14
|
+
"apikey",
|
|
15
|
+
"x-auth-token",
|
|
16
|
+
"x-access-token",
|
|
17
|
+
"x-id-token",
|
|
18
|
+
"x-refresh-token",
|
|
19
|
+
"x-session-token",
|
|
20
|
+
"session-token",
|
|
21
|
+
"csrf-token",
|
|
22
|
+
"x-csrf-token",
|
|
23
|
+
"xsrf-token",
|
|
24
|
+
"x-xsrf-token",
|
|
25
|
+
"x-amz-security-token",
|
|
26
|
+
"x-goog-api-key",
|
|
27
|
+
"x-client-secret",
|
|
28
|
+
"client-secret",
|
|
29
|
+
"private-token"
|
|
30
|
+
];
|
|
31
|
+
function getFilteredHeaders(headers) {
|
|
32
|
+
const filteredHeaders = { ...headers };
|
|
33
|
+
Object.keys(filteredHeaders).forEach((key) => {
|
|
34
|
+
if (filteredHeaderNames.includes(key.toLowerCase())) {
|
|
35
|
+
delete filteredHeaders[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return filteredHeaders;
|
|
39
|
+
}
|
|
40
|
+
function getIsMCPCall(headers) {
|
|
41
|
+
return Object.keys(headers).some((key) => {
|
|
42
|
+
return key.toLowerCase() === "mcp-protocol-version";
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function getIsUCPCall(headers) {
|
|
46
|
+
return Object.keys(headers).some((key) => {
|
|
47
|
+
return key.toLowerCase() === "ucp-agent";
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function getIsProbablyACPCall(headers) {
|
|
51
|
+
return Object.keys(headers).some((key) => {
|
|
52
|
+
return key.toLowerCase() === "api-version";
|
|
53
|
+
});
|
|
54
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,157 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* A framework-agnostic HTTP request interface.
|
|
4
|
-
* Used as a convenience type for single-request methods.
|
|
5
|
-
*/
|
|
6
|
-
export interface Request {
|
|
7
|
-
/** The URL path and query string (e.g. "/about?foo=bar") */
|
|
8
|
-
path: string;
|
|
9
|
-
/** The HTTP method (e.g. "GET", "POST") */
|
|
10
|
-
method: string;
|
|
11
|
-
/** The HTTP request headers */
|
|
12
|
-
headers: Record<string, string | string[] | undefined>;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* A minimal HTTP response interface.
|
|
16
|
-
* Used as a convenience type for single-request methods.
|
|
17
|
-
*/
|
|
18
|
-
export interface Response {
|
|
19
|
-
/** The HTTP response status code (e.g. 200, 404) */
|
|
20
|
-
statusCode: number;
|
|
21
|
-
/** The HTTP response headers */
|
|
22
|
-
headers?: Record<string, string | string[] | undefined>;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* A visit tracking request for the Known Agents API.
|
|
26
|
-
* Used for batch visit tracking with `trackVisits()`.
|
|
27
|
-
*/
|
|
28
|
-
export interface VisitRequest {
|
|
29
|
-
/** The URL path of the request (e.g. "/about?foo=bar") */
|
|
30
|
-
request_path: string;
|
|
31
|
-
/** The HTTP method (e.g. "GET", "POST") */
|
|
32
|
-
request_method: string;
|
|
33
|
-
/** The HTTP request headers */
|
|
34
|
-
request_headers: Record<string, string | string[] | undefined>;
|
|
35
|
-
/** The HTTP response status code (e.g. 200, 404) */
|
|
36
|
-
response_status_code?: number;
|
|
37
|
-
/** The HTTP response headers */
|
|
38
|
-
response_headers?: Record<string, string | string[] | undefined>;
|
|
39
|
-
/** The response duration in milliseconds */
|
|
40
|
-
response_duration_in_milliseconds?: number;
|
|
41
|
-
/** The timestamp when the visit occurred (ISO 8601 format) */
|
|
42
|
-
created?: string;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* An agent identification request for the Known Agents API.
|
|
46
|
-
* Used for batch agent identification with `identifyAgents()`.
|
|
47
|
-
*/
|
|
48
|
-
export interface IdentificationRequest {
|
|
49
|
-
/** An identifier that will be echoed back in the response to match requests with results */
|
|
50
|
-
id?: string;
|
|
51
|
-
/** The HTTP request headers */
|
|
52
|
-
request_headers: Record<string, string | string[] | undefined>;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* The result of an agent identification request.
|
|
56
|
-
*/
|
|
57
|
-
export interface IdentificationResult {
|
|
58
|
-
/** The identifier from the request (if provided) */
|
|
59
|
-
id?: string;
|
|
60
|
-
/**
|
|
61
|
-
* The identification result:
|
|
62
|
-
* - "verified": The agent was identified and verified
|
|
63
|
-
* - "verification_failed": The agent was identified but failed verification (spoofed)
|
|
64
|
-
* - "unknown_agent": The request is from an unrecognized agent or human
|
|
65
|
-
* - "not_verifiable": The agent was identified but cannot be verified
|
|
66
|
-
*/
|
|
67
|
-
result: "verified" | "verification_failed" | "unknown_agent" | "not_verifiable";
|
|
68
|
-
/** The unique ID of the identified agent */
|
|
69
|
-
agent_id?: string;
|
|
70
|
-
/** The name of the identified agent (e.g. "Googlebot") */
|
|
71
|
-
agent_token?: string;
|
|
72
|
-
/** The documentation URL for the identified agent */
|
|
73
|
-
agent_url?: string;
|
|
74
|
-
/** The type of the identified agent (e.g. "AI Agent", "Search Engine Crawler") */
|
|
75
|
-
agent_type_name?: string;
|
|
76
|
-
/** The company behind the identified agent (e.g. "Google") */
|
|
77
|
-
operator_name?: string;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Agent types that can be controlled with robots.txt rules.
|
|
81
|
-
*/
|
|
82
|
-
export declare enum AgentType {
|
|
83
|
-
AIAgent = "AI Agent",
|
|
84
|
-
AIAssistant = "AI Assistant",
|
|
85
|
-
AICodingAgent = "AI Coding Agent",
|
|
86
|
-
AIDataProvider = "AI Data Provider",
|
|
87
|
-
AIDataScraper = "AI Data Scraper",
|
|
88
|
-
AISearchCrawler = "AI Search Crawler",
|
|
89
|
-
Archiver = "Archiver",
|
|
90
|
-
DeveloperHelper = "Developer Helper",
|
|
91
|
-
Fetcher = "Fetcher",
|
|
92
|
-
HeadlessAgent = "Headless Agent",
|
|
93
|
-
IntelligenceGatherer = "Intelligence Gatherer",
|
|
94
|
-
Scraper = "Scraper",
|
|
95
|
-
SEOCrawler = "SEO Crawler",
|
|
96
|
-
SearchEngineCrawler = "Search Engine Crawler",
|
|
97
|
-
SecurityScanner = "Security Scanner",
|
|
98
|
-
UndocumentedAIAgent = "Undocumented AI Agent"
|
|
99
|
-
}
|
|
100
|
-
export declare class KnownAgents {
|
|
101
|
-
private readonly accessToken;
|
|
102
|
-
/**
|
|
103
|
-
* Creates a new instance of the Known Agents client.
|
|
104
|
-
*
|
|
105
|
-
* @param accessToken - Your project's access token.
|
|
106
|
-
*/
|
|
107
|
-
constructor(accessToken: string);
|
|
108
|
-
/**
|
|
109
|
-
* Tracks a single agent visit for analytics.
|
|
110
|
-
* This method is non-blocking and handles errors internally.
|
|
111
|
-
*
|
|
112
|
-
* @param request - The incoming HTTP request (Request or Node.js IncomingMessage).
|
|
113
|
-
* @param response - The outgoing HTTP response (optional).
|
|
114
|
-
* @param responseDurationInMilliseconds - The time taken to process the request in milliseconds (optional).
|
|
115
|
-
*/
|
|
116
|
-
trackVisit(request: Request | IncomingMessage, response?: Response | ServerResponse, responseDurationInMilliseconds?: number): void;
|
|
117
|
-
/**
|
|
118
|
-
* Tracks multiple agent visits in a batch for analytics.
|
|
119
|
-
* This method is non-blocking and handles errors internally.
|
|
120
|
-
* Recommended for high-traffic websites - batch visits and send periodically (e.g. every 30 seconds).
|
|
121
|
-
*
|
|
122
|
-
* @param visits - An array of visit tracking requests.
|
|
123
|
-
*/
|
|
124
|
-
trackVisits(visits: VisitRequest[]): void;
|
|
125
|
-
/**
|
|
126
|
-
* Generates a robots.txt file that disallows the specified agent types.
|
|
127
|
-
* The generated file stays up-to-date with all current and future agents in the specified categories.
|
|
128
|
-
* Cache and serve the result at your website's `/robots.txt` endpoint.
|
|
129
|
-
*
|
|
130
|
-
* @param agentTypes - An array of agent types to disallow.
|
|
131
|
-
* @param disallow - The path to disallow (default: "/" for all paths).
|
|
132
|
-
* @returns A promise that resolves to the generated robots.txt content as a string.
|
|
133
|
-
* @throws {Error} If the API call fails or returns a non-200 status.
|
|
134
|
-
*/
|
|
135
|
-
generateRobotsTXT(agentTypes: AgentType[], disallow?: string): Promise<string>;
|
|
136
|
-
/**
|
|
137
|
-
* Identifies and verifies a single agent from an HTTP request.
|
|
138
|
-
* Uses Web Bot Auth (HTTP message signatures), IP matching, or other available methods.
|
|
139
|
-
*
|
|
140
|
-
* @param request - The incoming HTTP request (Request or Node.js IncomingMessage).
|
|
141
|
-
* @returns A promise that resolves to the identification result.
|
|
142
|
-
* @throws {Error} If the API call fails or returns a non-200 status.
|
|
143
|
-
*/
|
|
144
|
-
identifyAgent(request: Request | IncomingMessage): Promise<IdentificationResult>;
|
|
145
|
-
/**
|
|
146
|
-
* Identifies and verifies multiple agents from HTTP requests in a batch.
|
|
147
|
-
* Uses Web Bot Auth (HTTP message signatures), IP matching, or other available methods.
|
|
148
|
-
*
|
|
149
|
-
* @param requests - An array of identification requests.
|
|
150
|
-
* @returns A promise that resolves to an array of identification results.
|
|
151
|
-
* @throws {Error} If the API call fails or returns a non-200 status.
|
|
152
|
-
*/
|
|
153
|
-
identifyAgents(requests: IdentificationRequest[]): Promise<IdentificationResult[]>;
|
|
154
|
-
private isPathExcluded;
|
|
155
|
-
private filterHeaders;
|
|
156
|
-
}
|
|
1
|
+
export { KnownAgents } from "./KnownAgents";
|
|
2
|
+
export { AgentType, type IdentificationRequest, type IdentificationResult, type RESTACPResponseBody, type RESTUCPResponseBody, type TrackPageviewOrRESTCallOptions, type VisitRequest } from "./types";
|
|
157
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EACH,SAAS,EACT,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,8BAA8B,EACnC,KAAK,YAAY,EACpB,MAAM,SAAS,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,255 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var AgentType;
|
|
9
|
-
(function (AgentType) {
|
|
10
|
-
AgentType["AIAgent"] = "AI Agent";
|
|
11
|
-
AgentType["AIAssistant"] = "AI Assistant";
|
|
12
|
-
AgentType["AICodingAgent"] = "AI Coding Agent";
|
|
13
|
-
AgentType["AIDataProvider"] = "AI Data Provider";
|
|
14
|
-
AgentType["AIDataScraper"] = "AI Data Scraper";
|
|
15
|
-
AgentType["AISearchCrawler"] = "AI Search Crawler";
|
|
16
|
-
AgentType["Archiver"] = "Archiver";
|
|
17
|
-
AgentType["DeveloperHelper"] = "Developer Helper";
|
|
18
|
-
AgentType["Fetcher"] = "Fetcher";
|
|
19
|
-
AgentType["HeadlessAgent"] = "Headless Agent";
|
|
20
|
-
AgentType["IntelligenceGatherer"] = "Intelligence Gatherer";
|
|
21
|
-
AgentType["Scraper"] = "Scraper";
|
|
22
|
-
AgentType["SEOCrawler"] = "SEO Crawler";
|
|
23
|
-
AgentType["SearchEngineCrawler"] = "Search Engine Crawler";
|
|
24
|
-
AgentType["SecurityScanner"] = "Security Scanner";
|
|
25
|
-
AgentType["UndocumentedAIAgent"] = "Undocumented AI Agent";
|
|
26
|
-
})(AgentType || (exports.AgentType = AgentType = {}));
|
|
27
|
-
class KnownAgents {
|
|
28
|
-
/**
|
|
29
|
-
* Creates a new instance of the Known Agents client.
|
|
30
|
-
*
|
|
31
|
-
* @param accessToken - Your project's access token.
|
|
32
|
-
*/
|
|
33
|
-
constructor(accessToken) {
|
|
34
|
-
this.accessToken = accessToken;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Tracks a single agent visit for analytics.
|
|
38
|
-
* This method is non-blocking and handles errors internally.
|
|
39
|
-
*
|
|
40
|
-
* @param request - The incoming HTTP request (Request or Node.js IncomingMessage).
|
|
41
|
-
* @param response - The outgoing HTTP response (optional).
|
|
42
|
-
* @param responseDurationInMilliseconds - The time taken to process the request in milliseconds (optional).
|
|
43
|
-
*/
|
|
44
|
-
trackVisit(request, response, responseDurationInMilliseconds) {
|
|
45
|
-
const path = "path" in request ? request.path : request.url;
|
|
46
|
-
const responseHeaders = response instanceof http_1.ServerResponse ? response.getHeaders() : response?.headers;
|
|
47
|
-
if (!path || this.isPathExcluded(path)) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
fetch("https://api.knownagents.com/visits", {
|
|
51
|
-
method: "POST",
|
|
52
|
-
headers: {
|
|
53
|
-
"Authorization": `Bearer ${this.accessToken}`,
|
|
54
|
-
"Content-Type": "application/json"
|
|
55
|
-
},
|
|
56
|
-
body: JSON.stringify({
|
|
57
|
-
request_path: path,
|
|
58
|
-
request_method: request.method,
|
|
59
|
-
request_headers: this.filterHeaders(request.headers),
|
|
60
|
-
response_status_code: response?.statusCode,
|
|
61
|
-
response_headers: responseHeaders ? this.filterHeaders(responseHeaders) : undefined,
|
|
62
|
-
response_duration_in_milliseconds: responseDurationInMilliseconds,
|
|
63
|
-
created: new Date().toISOString()
|
|
64
|
-
})
|
|
65
|
-
}).catch(error => {
|
|
66
|
-
console.error(`Known Agents failed to track visit: ${error.message}`);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Tracks multiple agent visits in a batch for analytics.
|
|
71
|
-
* This method is non-blocking and handles errors internally.
|
|
72
|
-
* Recommended for high-traffic websites - batch visits and send periodically (e.g. every 30 seconds).
|
|
73
|
-
*
|
|
74
|
-
* @param visits - An array of visit tracking requests.
|
|
75
|
-
*/
|
|
76
|
-
trackVisits(visits) {
|
|
77
|
-
const filteredVisits = visits
|
|
78
|
-
.filter((visit) => {
|
|
79
|
-
return !this.isPathExcluded(visit.request_path);
|
|
80
|
-
})
|
|
81
|
-
.map((visit) => {
|
|
82
|
-
return {
|
|
83
|
-
...visit,
|
|
84
|
-
request_headers: this.filterHeaders(visit.request_headers),
|
|
85
|
-
response_headers: visit.response_headers ? this.filterHeaders(visit.response_headers) : undefined,
|
|
86
|
-
};
|
|
87
|
-
});
|
|
88
|
-
if (filteredVisits.length === 0) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
fetch("https://api.knownagents.com/visits", {
|
|
92
|
-
method: "POST",
|
|
93
|
-
headers: {
|
|
94
|
-
"Authorization": `Bearer ${this.accessToken}`,
|
|
95
|
-
"Content-Type": "application/json"
|
|
96
|
-
},
|
|
97
|
-
body: JSON.stringify(filteredVisits)
|
|
98
|
-
}).catch(error => {
|
|
99
|
-
console.error(`Known Agents failed to track visits: ${error.message}`);
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Generates a robots.txt file that disallows the specified agent types.
|
|
104
|
-
* The generated file stays up-to-date with all current and future agents in the specified categories.
|
|
105
|
-
* Cache and serve the result at your website's `/robots.txt` endpoint.
|
|
106
|
-
*
|
|
107
|
-
* @param agentTypes - An array of agent types to disallow.
|
|
108
|
-
* @param disallow - The path to disallow (default: "/" for all paths).
|
|
109
|
-
* @returns A promise that resolves to the generated robots.txt content as a string.
|
|
110
|
-
* @throws {Error} If the API call fails or returns a non-200 status.
|
|
111
|
-
*/
|
|
112
|
-
async generateRobotsTXT(agentTypes, disallow = "/") {
|
|
113
|
-
const response = await fetch("https://api.knownagents.com/robots-txts", {
|
|
114
|
-
method: "POST",
|
|
115
|
-
headers: {
|
|
116
|
-
"Authorization": `Bearer ${this.accessToken}`,
|
|
117
|
-
"Content-Type": "application/json"
|
|
118
|
-
},
|
|
119
|
-
body: JSON.stringify({
|
|
120
|
-
agent_types: agentTypes,
|
|
121
|
-
disallow: disallow
|
|
122
|
-
})
|
|
123
|
-
});
|
|
124
|
-
if (response.ok) {
|
|
125
|
-
return await response.text();
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
throw new Error(`Known Agents failed to generate robots.txt: ${response.status} ${response.statusText}`);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Identifies and verifies a single agent from an HTTP request.
|
|
133
|
-
* Uses Web Bot Auth (HTTP message signatures), IP matching, or other available methods.
|
|
134
|
-
*
|
|
135
|
-
* @param request - The incoming HTTP request (Request or Node.js IncomingMessage).
|
|
136
|
-
* @returns A promise that resolves to the identification result.
|
|
137
|
-
* @throws {Error} If the API call fails or returns a non-200 status.
|
|
138
|
-
*/
|
|
139
|
-
async identifyAgent(request) {
|
|
140
|
-
const response = await fetch("https://api.knownagents.com/agent-identifications", {
|
|
141
|
-
method: "POST",
|
|
142
|
-
headers: {
|
|
143
|
-
"Authorization": `Bearer ${this.accessToken}`,
|
|
144
|
-
"Content-Type": "application/json"
|
|
145
|
-
},
|
|
146
|
-
body: JSON.stringify({
|
|
147
|
-
request_headers: this.filterHeaders(request.headers)
|
|
148
|
-
})
|
|
149
|
-
});
|
|
150
|
-
if (response.ok) {
|
|
151
|
-
return await response.json();
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
throw new Error(`Known Agents failed to identify agent: ${response.status} ${response.statusText}`);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Identifies and verifies multiple agents from HTTP requests in a batch.
|
|
159
|
-
* Uses Web Bot Auth (HTTP message signatures), IP matching, or other available methods.
|
|
160
|
-
*
|
|
161
|
-
* @param requests - An array of identification requests.
|
|
162
|
-
* @returns A promise that resolves to an array of identification results.
|
|
163
|
-
* @throws {Error} If the API call fails or returns a non-200 status.
|
|
164
|
-
*/
|
|
165
|
-
async identifyAgents(requests) {
|
|
166
|
-
const response = await fetch("https://api.knownagents.com/agent-identifications", {
|
|
167
|
-
method: "POST",
|
|
168
|
-
headers: {
|
|
169
|
-
"Authorization": `Bearer ${this.accessToken}`,
|
|
170
|
-
"Content-Type": "application/json"
|
|
171
|
-
},
|
|
172
|
-
body: JSON.stringify(requests.map(request => {
|
|
173
|
-
return {
|
|
174
|
-
...request,
|
|
175
|
-
request_headers: this.filterHeaders(request.request_headers),
|
|
176
|
-
};
|
|
177
|
-
}))
|
|
178
|
-
});
|
|
179
|
-
if (response.ok) {
|
|
180
|
-
return await response.json();
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
throw new Error(`Known Agents failed to identify agents: ${response.status} ${response.statusText}`);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
// Helpers
|
|
187
|
-
isPathExcluded(path) {
|
|
188
|
-
const excludedPrefixes = [
|
|
189
|
-
"/_next/",
|
|
190
|
-
"/_nuxt/",
|
|
191
|
-
"/_astro/",
|
|
192
|
-
"/_app/",
|
|
193
|
-
"/@vite/",
|
|
194
|
-
"/@fs/",
|
|
195
|
-
"/@id/",
|
|
196
|
-
"/node_modules/",
|
|
197
|
-
"/_vercel/",
|
|
198
|
-
];
|
|
199
|
-
const excludedSuffixes = [
|
|
200
|
-
".ico",
|
|
201
|
-
".png",
|
|
202
|
-
".jpg",
|
|
203
|
-
".jpeg",
|
|
204
|
-
".gif",
|
|
205
|
-
".webp",
|
|
206
|
-
".svg",
|
|
207
|
-
".bmp",
|
|
208
|
-
".tiff",
|
|
209
|
-
".avif",
|
|
210
|
-
".css",
|
|
211
|
-
".js",
|
|
212
|
-
".mjs",
|
|
213
|
-
".ts",
|
|
214
|
-
".jsx",
|
|
215
|
-
".tsx",
|
|
216
|
-
".map",
|
|
217
|
-
".woff",
|
|
218
|
-
".woff2",
|
|
219
|
-
".ttf",
|
|
220
|
-
".otf",
|
|
221
|
-
".eot",
|
|
222
|
-
".mp3",
|
|
223
|
-
".mp4",
|
|
224
|
-
".webm",
|
|
225
|
-
".wav",
|
|
226
|
-
".ogg",
|
|
227
|
-
".mov",
|
|
228
|
-
".avi",
|
|
229
|
-
".flv",
|
|
230
|
-
".m4v",
|
|
231
|
-
".rss",
|
|
232
|
-
".json",
|
|
233
|
-
".xml",
|
|
234
|
-
".pdf",
|
|
235
|
-
".zip",
|
|
236
|
-
];
|
|
237
|
-
return excludedPrefixes.some((excludedPrefix) => {
|
|
238
|
-
return path.toLowerCase().startsWith(excludedPrefix.toLowerCase());
|
|
239
|
-
}) || excludedSuffixes.some((excludedSuffix) => {
|
|
240
|
-
return path.toLowerCase().endsWith(excludedSuffix.toLowerCase());
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
filterHeaders(headers) {
|
|
244
|
-
const excludedHeaders = new Set([
|
|
245
|
-
"authorization",
|
|
246
|
-
"proxy-authorization",
|
|
247
|
-
"cookie",
|
|
248
|
-
"set-cookie"
|
|
249
|
-
]);
|
|
250
|
-
return Object.fromEntries(Object.entries(headers).filter(([key]) => {
|
|
251
|
-
return !excludedHeaders.has(key.toLowerCase());
|
|
252
|
-
}));
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
exports.KnownAgents = KnownAgents;
|
|
3
|
+
exports.AgentType = exports.KnownAgents = void 0;
|
|
4
|
+
var KnownAgents_1 = require("./KnownAgents");
|
|
5
|
+
Object.defineProperty(exports, "KnownAgents", { enumerable: true, get: function () { return KnownAgents_1.KnownAgents; } });
|
|
6
|
+
var types_1 = require("./types");
|
|
7
|
+
Object.defineProperty(exports, "AgentType", { enumerable: true, get: function () { return types_1.AgentType; } });
|
package/dist/paths.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAuEvD"}
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getIsPathExcluded = getIsPathExcluded;
|
|
4
|
+
function getIsPathExcluded(path) {
|
|
5
|
+
const pathWithoutQueryString = path.split(/[?#]/)[0];
|
|
6
|
+
const lowercasedPath = pathWithoutQueryString.toLowerCase();
|
|
7
|
+
const excludedPrefixes = [
|
|
8
|
+
"/_next/",
|
|
9
|
+
"/_nuxt/",
|
|
10
|
+
"/_astro/",
|
|
11
|
+
"/_app/",
|
|
12
|
+
"/__nextjs",
|
|
13
|
+
"/__vite_ping",
|
|
14
|
+
"/__webpack_hmr",
|
|
15
|
+
"/@vite/",
|
|
16
|
+
"/@fs/",
|
|
17
|
+
"/@id/",
|
|
18
|
+
"/@react-refresh",
|
|
19
|
+
"/node_modules/",
|
|
20
|
+
"/_vercel/",
|
|
21
|
+
"/sockjs-node/",
|
|
22
|
+
"/webpack-dev-server/",
|
|
23
|
+
];
|
|
24
|
+
const excludedSuffixes = [
|
|
25
|
+
".ico",
|
|
26
|
+
".png",
|
|
27
|
+
".jpg",
|
|
28
|
+
".jpeg",
|
|
29
|
+
".gif",
|
|
30
|
+
".webp",
|
|
31
|
+
".svg",
|
|
32
|
+
".bmp",
|
|
33
|
+
".tiff",
|
|
34
|
+
".avif",
|
|
35
|
+
".heic",
|
|
36
|
+
".heif",
|
|
37
|
+
".css",
|
|
38
|
+
".js",
|
|
39
|
+
".mjs",
|
|
40
|
+
".ts",
|
|
41
|
+
".jsx",
|
|
42
|
+
".tsx",
|
|
43
|
+
".map",
|
|
44
|
+
".wasm",
|
|
45
|
+
".woff",
|
|
46
|
+
".woff2",
|
|
47
|
+
".ttf",
|
|
48
|
+
".otf",
|
|
49
|
+
".eot",
|
|
50
|
+
".mp3",
|
|
51
|
+
".mp4",
|
|
52
|
+
".webm",
|
|
53
|
+
".wav",
|
|
54
|
+
".ogg",
|
|
55
|
+
".aac",
|
|
56
|
+
".m4a",
|
|
57
|
+
".flac",
|
|
58
|
+
".mov",
|
|
59
|
+
".avi",
|
|
60
|
+
".flv",
|
|
61
|
+
".m4v",
|
|
62
|
+
".webmanifest",
|
|
63
|
+
".pdf",
|
|
64
|
+
".zip",
|
|
65
|
+
".gz",
|
|
66
|
+
];
|
|
67
|
+
return excludedPrefixes.some((excludedPrefix) => {
|
|
68
|
+
return lowercasedPath.startsWith(excludedPrefix.toLowerCase());
|
|
69
|
+
}) || excludedSuffixes.some((excludedSuffix) => {
|
|
70
|
+
return lowercasedPath.endsWith(excludedSuffix.toLowerCase());
|
|
71
|
+
});
|
|
72
|
+
}
|