mirror of
https://github.com/vercel/chat.git
synced 2026-09-14 18:32:29 +08:00
e0a3c0a399
When AI agents (Claude, ChatGPT, Cursor, etc.) request docs pages, the proxy now detects them and transparently rewrites to the markdown route — matching the geistdocs template default. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
import { siteId } from "@/geistdocs";
|
|
|
|
const PLATFORM_URL = "https://geistdocs.com/md-tracking";
|
|
|
|
interface TrackMdRequestParams {
|
|
/** Detection method used to identify the agent (only for agent-rewrite requests) */
|
|
detectionMethod?: "ua-match" | "signature-agent" | "heuristic" | null;
|
|
acceptHeader: string | null;
|
|
path: string;
|
|
referer: string | null;
|
|
/** How the markdown was requested: 'md-url' for direct .md URLs, 'header-negotiated' for Accept header */
|
|
requestType?: "md-url" | "header-negotiated" | "agent-rewrite";
|
|
userAgent: string | null;
|
|
}
|
|
|
|
/**
|
|
* Track a markdown page request via the geistdocs platform.
|
|
* Fire-and-forget: errors are logged but don't affect the response.
|
|
*/
|
|
export async function trackMdRequest({
|
|
path,
|
|
userAgent,
|
|
referer,
|
|
acceptHeader,
|
|
requestType,
|
|
detectionMethod,
|
|
}: TrackMdRequestParams): Promise<void> {
|
|
try {
|
|
const response = await fetch(PLATFORM_URL, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({
|
|
path,
|
|
siteId: siteId ?? "geistdocs-unknown",
|
|
userAgent,
|
|
referer,
|
|
acceptHeader,
|
|
requestType,
|
|
detectionMethod,
|
|
}),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
console.error(
|
|
"MD tracking failed:",
|
|
response.status,
|
|
await response.text()
|
|
);
|
|
}
|
|
} catch (error) {
|
|
console.error("MD tracking error:", error);
|
|
}
|
|
}
|