Package Exports
- @dualmark/cloudflare
Readme
@dualmark/cloudflare
Cloudflare Workers edge adapter for the Dualmark AEO framework. Wraps any upstream Worker and transparently serves markdown to AI bots — no changes to your existing site.
Install
bun add @dualmark/cloudflare @dualmark/coreUsage
import astroWorker from "./dist/_worker.js/index.js";
import { createAEOWorker } from "@dualmark/cloudflare";
export default createAEOWorker({
upstream: astroWorker,
redirects: {
internal: { "/old-path": "/new-path" },
external: { "/login": "https://app.example.com" },
},
analytics: { binding: "AI_AGENT_ANALYTICS" },
trailingSlash: "never",
hooks: {
onAIRequest: (info) => console.log(`${info.botName} hit ${info.pathname}`),
onMiss: (info) => console.warn(`miss: ${info.pathname}`),
},
});Wrangler config
{
"name": "my-site",
"main": "./worker.ts",
"compatibility_date": "2026-05-04",
"assets": {
"directory": "./dist",
"binding": "ASSETS"
},
"analytics_engine_datasets": [
{ "binding": "AI_AGENT_ANALYTICS", "dataset": "ai_agent_events" }
]
}What it does
- Trailing-slash enforcement (configurable:
never,always,preserve) - AI bot detection via UA
- Content negotiation via Accept header
- Serves pre-built
.mdfromenv.ASSETSwith full AEO headers - Internal redirects: routes to target's
.md - External redirects: returns markdown notice
- 406 when neither HTML nor markdown is acceptable
- Link header injection (
<…>; rel="alternate"; type="text/markdown") on HTML responses - Analytics Engine tracking (hit/miss, bot, country, tokens)
- Falls through to upstream Worker for everything else
License
Apache 2.0