mirror of
https://github.com/vercel/flags.git
synced 2026-09-19 03:49:23 +08:00
73c38b6669
- Change DetectionMethod import from deleted local file to @vercel/agent-readability - Add Vary: Accept header on agent-rewrite responses - Add discovery options (sitemapUrl, indexUrl) to generateNotFoundMarkdown Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import { siteId } from "@/geistdocs";
|
|
import type { DetectionMethod } from "@vercel/agent-readability";
|
|
|
|
const PLATFORM_URL = "https://geistdocs.com/md-tracking";
|
|
|
|
type TrackMdRequestParams = {
|
|
path: string;
|
|
userAgent: string | null;
|
|
referer: string | null;
|
|
acceptHeader: 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";
|
|
/** Which detection method identified the AI agent */
|
|
detectionMethod?: DetectionMethod | 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);
|
|
}
|
|
}
|