@ontosdk/next 1.5.5 → 1.5.6

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.
@@ -1,4 +1,4 @@
1
- "use strict";var m=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var _=(t,e)=>{for(var n in e)m(t,n,{get:e[n],enumerable:!0})},$=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of T(e))!G.call(t,a)&&a!==n&&m(t,a,{get:()=>e[a],enumerable:!(o=C(e,a))||o.enumerable});return t};var P=t=>$(m({},"__esModule",{value:!0}),t);var k={};_(k,{AI_BOT_USER_AGENTS:()=>y,matchBot:()=>p,ontoMiddleware:()=>I});module.exports=P(k);var s=require("next/server");var u=[{name:"GPTBot",company:"OpenAI",addedAt:"2025-01-01"},{name:"ChatGPT-User",company:"OpenAI",addedAt:"2025-01-01"},{name:"OAI-SearchBot",company:"OpenAI",addedAt:"2025-01-01"},{name:"ChatGPT",company:"OpenAI",addedAt:"2025-03-25"},{name:"OpenAI",company:"OpenAI",addedAt:"2025-03-25"},{name:"GPT",company:"OpenAI",addedAt:"2025-03-25"},{name:"Google-CloudVertexBot",company:"Google",addedAt:"2025-01-01"},{name:"Google-Extended",company:"Google",addedAt:"2025-01-01"},{name:"GoogleOther",company:"Google",addedAt:"2025-01-01"},{name:"ClaudeBot",company:"Anthropic",addedAt:"2025-01-01"},{name:"Claude-User",company:"Anthropic",addedAt:"2025-01-01"},{name:"claude-fetch",company:"Anthropic",addedAt:"2025-03-25"},{name:"AnthropicFetch",company:"Anthropic",addedAt:"2025-03-25"},{name:"Claude-Fetch",company:"Anthropic",addedAt:"2025-03-25"},{name:"anthropic-ai",company:"Anthropic",addedAt:"2025-01-01"},{name:"Claude",company:"Anthropic",addedAt:"2025-03-25"},{name:"Anthropic",company:"Anthropic",addedAt:"2025-03-25"},{name:"PerplexityBot",company:"Perplexity",addedAt:"2025-01-01"},{name:"Perplexity-User",company:"Perplexity",addedAt:"2025-01-01"},{name:"Perplexity",company:"Perplexity",addedAt:"2025-03-25"},{name:"Meta-ExternalAgent",company:"Meta",addedAt:"2025-01-01"},{name:"Meta-ExternalFetcher",company:"Meta",addedAt:"2025-01-01"},{name:"facebookexternalhit",company:"Meta",addedAt:"2025-03-25"},{name:"FacebookBot",company:"Meta",addedAt:"2025-01-01"},{name:"MistralBot",company:"Mistral",addedAt:"2025-03-25"},{name:"Mistral",company:"Mistral",addedAt:"2025-03-25"},{name:"Amazonbot",company:"Amazon",addedAt:"2025-03-25"},{name:"AI2Bot",company:"Allen Institute",addedAt:"2025-03-25"},{name:"DuckAssistBot",company:"DuckDuckGo",addedAt:"2025-03-25"},{name:"Diffbot",company:"Diffbot",addedAt:"2025-03-25"},{name:"CCBot",company:"Common Crawl",addedAt:"2025-01-01"},{name:"Bytespider",company:"ByteDance",addedAt:"2025-01-01"},{name:"Applebot-Extended",company:"Apple",addedAt:"2025-01-01"},{name:"YouBot",company:"You.com",addedAt:"2025-01-01"},{name:"python-requests",company:"Generic Bot",addedAt:"2025-03-25"},{name:"python-httpx",company:"Generic Bot",addedAt:"2025-03-25"},{name:"httpx",company:"Generic Bot",addedAt:"2025-03-25"},{name:"axios",company:"Generic Bot",addedAt:"2025-03-25"},{name:"node-fetch",company:"Generic Bot",addedAt:"2025-03-25"},{name:"Go-http-client",company:"Generic Bot",addedAt:"2025-03-25"},{name:"Wget",company:"Generic Bot",addedAt:"2025-03-25"},{name:"Curl",company:"Generic Bot",addedAt:"2025-03-25"}],y=b();function b(){return u.map(t=>t.name)}function p(t){if(!t)return;let e=t.toLowerCase(),n=u.filter(o=>e.includes(o.name.toLowerCase()));if(n.length!==0)return n.length===1?n[0]:n.reduce((o,a)=>a.name.length>o.name.length?a:o)}function x(t){let e=[];if(e.push(`# ${t.name}`),e.push(""),e.push(`> ${t.summary}`),e.push(""),t.routes&&t.routes.length>0){e.push("## Key Routes"),e.push("");for(let n of t.routes){let o=`${t.baseUrl}${n.path}`;e.push(`- [${n.path}](${o}): ${n.description}`)}e.push("")}if(t.externalLinks&&t.externalLinks.length>0){e.push("## Resources"),e.push("");for(let n of t.externalLinks)n.description?e.push(`- [${n.title}](${n.url}): ${n.description}`):e.push(`- [${n.title}](${n.url})`);e.push("")}if(t.sections&&t.sections.length>0)for(let n of t.sections)e.push(`## ${n.heading}`),e.push(""),e.push(n.content),e.push("");return e.join(`
1
+ "use strict";var h=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var _=(t,e)=>{for(var n in e)h(t,n,{get:e[n],enumerable:!0})},$=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of T(e))!G.call(t,a)&&a!==n&&h(t,a,{get:()=>e[a],enumerable:!(o=C(e,a))||o.enumerable});return t};var P=t=>$(h({},"__esModule",{value:!0}),t);var U={};_(U,{AI_BOT_USER_AGENTS:()=>y,matchBot:()=>p,ontoMiddleware:()=>I});module.exports=P(U);var s=require("next/server");var u=[{name:"GPTBot",company:"OpenAI",addedAt:"2025-01-01"},{name:"ChatGPT-User",company:"OpenAI",addedAt:"2025-01-01"},{name:"OAI-SearchBot",company:"OpenAI",addedAt:"2025-01-01"},{name:"ChatGPT",company:"OpenAI",addedAt:"2025-03-25"},{name:"OpenAI",company:"OpenAI",addedAt:"2025-03-25"},{name:"GPT",company:"OpenAI",addedAt:"2025-03-25"},{name:"Google-CloudVertexBot",company:"Google",addedAt:"2025-01-01"},{name:"Google-Extended",company:"Google",addedAt:"2025-01-01"},{name:"GoogleOther",company:"Google",addedAt:"2025-01-01"},{name:"ClaudeBot",company:"Anthropic",addedAt:"2025-01-01"},{name:"Claude-User",company:"Anthropic",addedAt:"2025-01-01"},{name:"claude-fetch",company:"Anthropic",addedAt:"2025-03-25"},{name:"AnthropicFetch",company:"Anthropic",addedAt:"2025-03-25"},{name:"Claude-Fetch",company:"Anthropic",addedAt:"2025-03-25"},{name:"anthropic-ai",company:"Anthropic",addedAt:"2025-01-01"},{name:"Claude",company:"Anthropic",addedAt:"2025-03-25"},{name:"Anthropic",company:"Anthropic",addedAt:"2025-03-25"},{name:"PerplexityBot",company:"Perplexity",addedAt:"2025-01-01"},{name:"Perplexity-User",company:"Perplexity",addedAt:"2025-01-01"},{name:"Perplexity",company:"Perplexity",addedAt:"2025-03-25"},{name:"Meta-ExternalAgent",company:"Meta",addedAt:"2025-01-01"},{name:"Meta-ExternalFetcher",company:"Meta",addedAt:"2025-01-01"},{name:"facebookexternalhit",company:"Meta",addedAt:"2025-03-25"},{name:"FacebookBot",company:"Meta",addedAt:"2025-01-01"},{name:"MistralBot",company:"Mistral",addedAt:"2025-03-25"},{name:"Mistral",company:"Mistral",addedAt:"2025-03-25"},{name:"Amazonbot",company:"Amazon",addedAt:"2025-03-25"},{name:"AI2Bot",company:"Allen Institute",addedAt:"2025-03-25"},{name:"DuckAssistBot",company:"DuckDuckGo",addedAt:"2025-03-25"},{name:"Diffbot",company:"Diffbot",addedAt:"2025-03-25"},{name:"CCBot",company:"Common Crawl",addedAt:"2025-01-01"},{name:"Bytespider",company:"ByteDance",addedAt:"2025-01-01"},{name:"Applebot-Extended",company:"Apple",addedAt:"2025-01-01"},{name:"YouBot",company:"You.com",addedAt:"2025-01-01"},{name:"python-requests",company:"Generic Bot",addedAt:"2025-03-25"},{name:"python-httpx",company:"Generic Bot",addedAt:"2025-03-25"},{name:"httpx",company:"Generic Bot",addedAt:"2025-03-25"},{name:"axios",company:"Generic Bot",addedAt:"2025-03-25"},{name:"node-fetch",company:"Generic Bot",addedAt:"2025-03-25"},{name:"Go-http-client",company:"Generic Bot",addedAt:"2025-03-25"},{name:"Wget",company:"Generic Bot",addedAt:"2025-03-25"},{name:"Curl",company:"Generic Bot",addedAt:"2025-03-25"}],y=b();function b(){return u.map(t=>t.name)}function p(t){if(!t)return;let e=t.toLowerCase(),n=u.filter(o=>e.includes(o.name.toLowerCase()));if(n.length!==0)return n.length===1?n[0]:n.reduce((o,a)=>a.name.length>o.name.length?a:o)}function g(t){let e=[];if(e.push(`# ${t.name}`),e.push(""),e.push(`> ${t.summary}`),e.push(""),t.routes&&t.routes.length>0){e.push("## Key Routes"),e.push("");for(let n of t.routes){let o=`${t.baseUrl}${n.path}`;e.push(`- [${n.path}](${o}): ${n.description}`)}e.push("")}if(t.externalLinks&&t.externalLinks.length>0){e.push("## Resources"),e.push("");for(let n of t.externalLinks)n.description?e.push(`- [${n.title}](${n.url}): ${n.description}`):e.push(`- [${n.title}](${n.url})`);e.push("")}if(t.sections&&t.sections.length>0)for(let n of t.sections)e.push(`## ${n.heading}`),e.push(""),e.push(n.content),e.push("");return e.join(`
2
2
  `).trim()+`
3
- `}async function I(t,e){let n=t.headers.get("user-agent"),o=t.nextUrl.clone(),a=p(n),g=t.headers.get("accept")||"",l=t.nextUrl.searchParams.has("onto"),f=!!a,B=g.includes("text/markdown")||l;if(f||B){if(o.pathname.startsWith("/_next"))return s.NextResponse.next();if(o.pathname==="/llms.txt")try{if(e){let c=x(e),i=new s.NextResponse(c,{headers:{"Content-Type":"text/plain; charset=utf-8","Cache-Control":"public, max-age=3600, s-maxage=3600, stale-while-revalidate=86400"}});return a&&i.headers.set("X-Onto-Bot",`${a.name} (${a.company})`),i.headers.set("X-Onto-Trace",n||"no-ua"),i}}catch(c){console.error("[Onto] Failed to generate llms.txt:",c)}if(o.pathname.includes("."))return s.NextResponse.next();let r=o.pathname;(r==="/"||r==="")&&(r="/index"),r.endsWith("/")&&r!=="/"&&(r=r.slice(0,-1));let A=process.env.ONTO_API_KEY,O=process.env.ONTO_DASHBOARD_URL||"https://app.buildonto.dev";A&&fetch(`${O}/api/track`,{method:"POST",headers:{"x-onto-key":A,"Content-Type":"application/json"},body:JSON.stringify({route:o.pathname,userAgent:n,bot:a?.name,company:a?.company})}).catch(()=>{}),o.pathname=`/.onto${r}.md`;let d=s.NextResponse.rewrite(o);return d.headers.set("Content-Type","text/markdown; charset=utf-8"),d.headers.set("Cache-Control","public, max-age=3600, s-maxage=3600, stale-while-revalidate=86400"),d.headers.set("X-Onto-Trace",n||"no-ua"),a&&d.headers.set("X-Onto-Bot",`${a.name} (${a.company})`),l&&d.headers.set("X-Onto-Debug","true"),d}let h=s.NextResponse.next();return h.headers.set("X-Onto-Trace",n||"no-ua"),h}0&&(module.exports={AI_BOT_USER_AGENTS,matchBot,ontoMiddleware});
3
+ `}async function I(t,e){let n=t.headers.get("user-agent"),o=t.nextUrl.clone(),a=p(n),x=t.headers.get("accept")||"",l=t.nextUrl.searchParams.has("onto"),f=!!a,B=x.includes("text/markdown")||l;if(f||B){if(o.pathname.startsWith("/_next"))return s.NextResponse.next();if(o.pathname==="/llms.txt")try{if(e){let i=g(e),m=new s.NextResponse(i,{headers:{"Content-Type":"text/plain; charset=utf-8","Cache-Control":"public, max-age=3600, s-maxage=3600, stale-while-revalidate=86400"}});return a&&m.headers.set("X-Onto-Bot",`${a.name} (${a.company})`),m.headers.set("X-Onto-Trace",n||"no-ua"),m}}catch(i){console.error("[Onto] Failed to generate llms.txt:",i)}if(o.pathname.includes("."))return s.NextResponse.next();let r=o.pathname;(r==="/"||r==="")&&(r="/index"),r.endsWith("/")&&r!=="/"&&(r=r.slice(0,-1));let A=process.env.ONTO_API_KEY,O=process.env.ONTO_DASHBOARD_URL||"https://app.buildonto.dev";A&&fetch(`${O}/api/track`,{method:"POST",headers:{"x-onto-key":A,"Content-Type":"application/json"},body:JSON.stringify({route:o.pathname,userAgent:n,bot:a?.name,company:a?.company})}).catch(()=>{}),o.pathname=`/.onto${r}.md`;let d=s.NextResponse.rewrite(o);return d.headers.set("Content-Type","text/markdown; charset=utf-8"),d.headers.set("Cache-Control","public, max-age=3600, s-maxage=3600, stale-while-revalidate=86400"),d.headers.set("Vary","User-Agent, Accept"),d.headers.set("X-Onto-Trace",n||"no-ua"),a&&(d.headers.set("X-Onto-Bot",`${a.name} (${a.company})`),d.headers.set("X-Onto-Matched","true")),l&&d.headers.set("X-Onto-Debug","true"),d}let c=s.NextResponse.next();return c.headers.set("Vary","User-Agent, Accept"),c.headers.set("X-Onto-Trace",n||"no-ua"),c}0&&(module.exports={AI_BOT_USER_AGENTS,matchBot,ontoMiddleware});
4
4
  //# sourceMappingURL=middleware.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/middleware.ts","../src/bots.ts","../src/config.ts"],"sourcesContent":["import { NextRequest, NextResponse } from 'next/server';\r\nimport { matchBot } from './bots';\r\nimport { generateLlmsTxt, OntoConfig } from './config';\r\n\r\nexport async function ontoMiddleware(request: any, config?: OntoConfig) {\r\n const userAgent = request.headers.get('user-agent');\r\n const url = request.nextUrl.clone();\r\n const matched = matchBot(userAgent);\r\n\r\n const accept = request.headers.get('accept') || '';\r\n const hasDebugParam = request.nextUrl.searchParams.has('onto');\r\n\r\n const isAiBot = !!matched;\r\n const isMarkdownRequested = accept.includes('text/markdown') || hasDebugParam;\r\n\r\n // Common logic for bot/markdown negotiation\r\n if (isAiBot || isMarkdownRequested) {\r\n // Ignore internal next.js requests\r\n if (url.pathname.startsWith('/_next')) {\r\n return NextResponse.next();\r\n }\r\n\r\n // --- llms.txt Auto-Discovery ---\r\n if (url.pathname === '/llms.txt') {\r\n try {\r\n if (config) {\r\n const llmsTxtContent = generateLlmsTxt(config);\r\n const response = new NextResponse(llmsTxtContent, {\r\n headers: {\r\n 'Content-Type': 'text/plain; charset=utf-8',\r\n 'Cache-Control': 'public, max-age=3600, s-maxage=3600, stale-while-revalidate=86400',\r\n }\r\n });\r\n if (matched) response.headers.set('X-Onto-Bot', `${matched.name} (${matched.company})`);\r\n response.headers.set('X-Onto-Trace', userAgent || 'no-ua');\r\n return response;\r\n }\r\n } catch (error) {\r\n console.error('[Onto] Failed to generate llms.txt:', error);\r\n }\r\n }\r\n\r\n // Skip other static assets with dots\r\n if (url.pathname.includes('.')) {\r\n return NextResponse.next();\r\n }\r\n\r\n // Determine the corresponding payload path\r\n let payloadPath = url.pathname;\r\n if (payloadPath === '/' || payloadPath === '') payloadPath = '/index';\r\n if (payloadPath.endsWith('/') && payloadPath !== '/') payloadPath = payloadPath.slice(0, -1);\r\n\r\n // --- Onto Control Plane Integration (Premium) ---\r\n const ONTO_API_KEY = process.env.ONTO_API_KEY;\r\n const DASHBOARD_URL = process.env.ONTO_DASHBOARD_URL || 'https://app.buildonto.dev';\r\n\r\n if (ONTO_API_KEY) {\r\n // Logic for tracking and injection ... (fire-and-forget tracking)\r\n fetch(`${DASHBOARD_URL}/api/track`, {\r\n method: 'POST',\r\n headers: { 'x-onto-key': ONTO_API_KEY, 'Content-Type': 'application/json' },\r\n body: JSON.stringify({ route: url.pathname, userAgent, bot: matched?.name, company: matched?.company })\r\n }).catch(() => {});\r\n }\r\n\r\n // Rewrite to semantic payload\r\n url.pathname = `/.onto${payloadPath}.md`;\r\n const response = NextResponse.rewrite(url);\r\n \r\n // Apply headers\r\n response.headers.set('Content-Type', 'text/markdown; charset=utf-8');\r\n response.headers.set('Cache-Control', 'public, max-age=3600, s-maxage=3600, stale-while-revalidate=86400');\r\n response.headers.set('X-Onto-Trace', userAgent || 'no-ua');\r\n if (matched) response.headers.set('X-Onto-Bot', `${matched.name} (${matched.company})`);\r\n if (hasDebugParam) response.headers.set('X-Onto-Debug', 'true');\r\n\r\n return response;\r\n }\r\n\r\n // Default response for non-bots\r\n const response = NextResponse.next();\r\n response.headers.set('X-Onto-Trace', userAgent || 'no-ua');\r\n return response;\r\n}\r\n\r\n// Re-export the bot registry for consumers who want to extend or inspect it\r\nexport { AI_BOT_USER_AGENTS, matchBot } from './bots';\r\nexport type { AiBot } from './bots';\r\n\r\n\r\n","/**\n * Comprehensive registry of AI bot user-agent strings.\n * The middleware uses this list to detect AI crawlers and serve optimized markdown.\n */\n\nexport interface AiBot {\n /** The user-agent substring to match against */\n name: string;\n /** The company operating this bot */\n company: string;\n /** ISO date when this bot was added or last verified */\n addedAt?: string;\n}\n\n/**\n * Structured registry of all known AI bots, grouped by company.\n * Useful for analytics and the Control Plane dashboard.\n */\nexport const AI_BOTS: AiBot[] = [\n // OpenAI\n { name: 'GPTBot', company: 'OpenAI', addedAt: '2025-01-01' },\n { name: 'ChatGPT-User', company: 'OpenAI', addedAt: '2025-01-01' },\n { name: 'OAI-SearchBot', company: 'OpenAI', addedAt: '2025-01-01' },\n { name: 'ChatGPT', company: 'OpenAI', addedAt: '2025-03-25' },\n { name: 'OpenAI', company: 'OpenAI', addedAt: '2025-03-25' },\n { name: 'GPT', company: 'OpenAI', addedAt: '2025-03-25' },\n\n // Google (SEO Safety: Googlebot proper is EXCLUDED)\n { name: 'Google-CloudVertexBot', company: 'Google', addedAt: '2025-01-01' },\n { name: 'Google-Extended', company: 'Google', addedAt: '2025-01-01' },\n { name: 'GoogleOther', company: 'Google', addedAt: '2025-01-01' },\n\n // Anthropic\n { name: 'ClaudeBot', company: 'Anthropic', addedAt: '2025-01-01' },\n { name: 'Claude-User', company: 'Anthropic', addedAt: '2025-01-01' },\n { name: 'claude-fetch', company: 'Anthropic', addedAt: '2025-03-25' },\n { name: 'AnthropicFetch', company: 'Anthropic', addedAt: '2025-03-25' },\n { name: 'Claude-Fetch', company: 'Anthropic', addedAt: '2025-03-25' },\n { name: 'anthropic-ai', company: 'Anthropic', addedAt: '2025-01-01' },\n { name: 'Claude', company: 'Anthropic', addedAt: '2025-03-25' },\n { name: 'Anthropic', company: 'Anthropic', addedAt: '2025-03-25' },\n\n // Perplexity\n { name: 'PerplexityBot', company: 'Perplexity', addedAt: '2025-01-01' },\n { name: 'Perplexity-User', company: 'Perplexity', addedAt: '2025-01-01' },\n { name: 'Perplexity', company: 'Perplexity', addedAt: '2025-03-25' },\n\n // Meta\n { name: 'Meta-ExternalAgent', company: 'Meta', addedAt: '2025-01-01' },\n { name: 'Meta-ExternalFetcher', company: 'Meta', addedAt: '2025-01-01' },\n { name: 'facebookexternalhit', company: 'Meta', addedAt: '2025-03-25' },\n { name: 'FacebookBot', company: 'Meta', addedAt: '2025-01-01' },\n\n // Mistral\n { name: 'MistralBot', company: 'Mistral', addedAt: '2025-03-25' },\n { name: 'Mistral', company: 'Mistral', addedAt: '2025-03-25' },\n\n // Amazon\n { name: 'Amazonbot', company: 'Amazon', addedAt: '2025-03-25' },\n\n // Others\n { name: 'AI2Bot', company: 'Allen Institute', addedAt: '2025-03-25' },\n { name: 'DuckAssistBot', company: 'DuckDuckGo', addedAt: '2025-03-25' },\n { name: 'Diffbot', company: 'Diffbot', addedAt: '2025-03-25' },\n { name: 'CCBot', company: 'Common Crawl', addedAt: '2025-01-01' },\n { name: 'Bytespider', company: 'ByteDance', addedAt: '2025-01-01' },\n { name: 'Applebot-Extended', company: 'Apple', addedAt: '2025-01-01' },\n { name: 'YouBot', company: 'You.com', addedAt: '2025-01-01' },\n\n // Generic AI / Scraping Libraries (Last Resort)\n { name: 'python-requests', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'python-httpx', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'httpx', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'axios', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'node-fetch', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'Go-http-client', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'Wget', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'Curl', company: 'Generic Bot', addedAt: '2025-03-25' },\n];\n\n/**\n * Flat list of user-agent substrings for fast matching in the middleware.\n */\nexport const AI_BOT_USER_AGENTS: string[] = AI_BOT_USER_AGENTS_CACHE();\n\nfunction AI_BOT_USER_AGENTS_CACHE() {\n return AI_BOTS.map(bot => bot.name);\n}\n\n/**\n * Given a raw user-agent string, returns the matched AiBot entry or undefined.\n * Uses a \"Longest Match\" strategy to ensure maximum specificity.\n * Comparison is case-insensitive.\n */\nexport function matchBot(userAgent: string | null): AiBot | undefined {\n if (!userAgent) return undefined;\n const lowerUA = userAgent.toLowerCase();\n \n // Find all matches\n const matches = AI_BOTS.filter(bot => \n lowerUA.includes(bot.name.toLowerCase())\n );\n\n if (matches.length === 0) return undefined;\n if (matches.length === 1) return matches[0];\n\n // Pick the longest match for maximum specificity (e.g. 'ChatGPT-User' vs 'GPT')\n return matches.reduce((longest, current) => \n current.name.length > longest.name.length ? current : longest\n );\n}\n","/**\r\n * Configuration schema for onto.config.ts\r\n * Used to dynamically generate llms.txt and other AI discovery files\r\n */\r\n\r\nexport type PageType = 'scoring' | 'about' | 'default';\r\n\r\nexport interface OntoRoute {\r\n /**\r\n * The URL path (e.g., '/docs', '/api/reference')\r\n */\r\n path: string;\r\n /**\r\n * Description of what this route contains\r\n */\r\n description: string;\r\n /**\r\n * Optional: Page type for automatic JSON-LD schema injection\r\n * - 'scoring': Injects Methodology schema with AIO scoring weights (40/35/25)\r\n * - 'about': Injects Organization/AboutPage schema\r\n * - 'default': No automatic schema injection\r\n */\r\n pageType?: PageType;\r\n}\r\n\r\nexport interface OntoConfig {\r\n /**\r\n * The name of your project or site (required)\r\n * Used as the H1 heading in llms.txt\r\n */\r\n name: string;\r\n\r\n /**\r\n * A short summary of your project (required)\r\n * Displayed as a blockquote in llms.txt\r\n * Should contain key information necessary for understanding the rest of the file\r\n */\r\n summary: string;\r\n\r\n /**\r\n * The base URL of your site (e.g., 'https://example.com')\r\n */\r\n baseUrl: string;\r\n\r\n /**\r\n * Optional: Additional sections to include in llms.txt\r\n * Each section can contain any markdown content\r\n */\r\n sections?: {\r\n heading: string;\r\n content: string;\r\n }[];\r\n\r\n /**\r\n * Key routes that AI agents should know about\r\n * These will be formatted as a markdown list in llms.txt\r\n */\r\n routes?: OntoRoute[];\r\n\r\n /**\r\n * Optional: Links to external resources (documentation, API references, etc.)\r\n */\r\n externalLinks?: {\r\n title: string;\r\n url: string;\r\n description?: string;\r\n }[];\r\n\r\n /**\r\n * Optional: Organization information for JSON-LD schemas\r\n */\r\n organization?: {\r\n name: string;\r\n description?: string;\r\n url?: string;\r\n logo?: string;\r\n foundingDate?: string;\r\n };\r\n}\r\n\r\n/**\r\n * Generate llms.txt content from OntoConfig\r\n * Follows the llms.txt specification:\r\n * - H1 with project name\r\n * - Blockquote with summary\r\n * - Additional markdown sections\r\n */\r\nexport function generateLlmsTxt(config: OntoConfig): string {\r\n const lines: string[] = [];\r\n\r\n // H1: Project name (required)\r\n lines.push(`# ${config.name}`);\r\n lines.push('');\r\n\r\n // Blockquote: Summary (required)\r\n lines.push(`> ${config.summary}`);\r\n lines.push('');\r\n\r\n // Key Routes section (if provided)\r\n if (config.routes && config.routes.length > 0) {\r\n lines.push('## Key Routes');\r\n lines.push('');\r\n for (const route of config.routes) {\r\n const fullUrl = `${config.baseUrl}${route.path}`;\r\n lines.push(`- [${route.path}](${fullUrl}): ${route.description}`);\r\n }\r\n lines.push('');\r\n }\r\n\r\n // External Links section (if provided)\r\n if (config.externalLinks && config.externalLinks.length > 0) {\r\n lines.push('## Resources');\r\n lines.push('');\r\n for (const link of config.externalLinks) {\r\n if (link.description) {\r\n lines.push(`- [${link.title}](${link.url}): ${link.description}`);\r\n } else {\r\n lines.push(`- [${link.title}](${link.url})`);\r\n }\r\n }\r\n lines.push('');\r\n }\r\n\r\n // Custom sections (if provided)\r\n if (config.sections && config.sections.length > 0) {\r\n for (const section of config.sections) {\r\n lines.push(`## ${section.heading}`);\r\n lines.push('');\r\n lines.push(section.content);\r\n lines.push('');\r\n }\r\n }\r\n\r\n return lines.join('\\n').trim() + '\\n';\r\n}\r\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,EAAA,aAAAC,EAAA,mBAAAC,IAAA,eAAAC,EAAAL,GAAA,IAAAM,EAA0C,uBCkBnC,IAAMC,EAAmB,CAE5B,CAAE,KAAM,SAAqB,QAAS,SAAY,QAAS,YAAa,EACxE,CAAE,KAAM,eAAoB,QAAS,SAAY,QAAS,YAAa,EACvE,CAAE,KAAM,gBAAoB,QAAS,SAAY,QAAS,YAAa,EACvE,CAAE,K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IAAI,eAAgB,8BAA8B,EACnEA,EAAS,QAAQ,IAAI,gBAAiB,mEAAmE,EACzGA,EAAS,QAAQ,IAAI,eAAgBV,GAAa,OAAO,EACrDE,GAASQ,EAAS,QAAQ,IAAI,aAAc,GAAGR,EAAQ,IAAI,KAAKA,EAAQ,OAAO,GAAG,EAClFG,GAAeK,EAAS,QAAQ,IAAI,eAAgB,MAAM,EAEvDA,CACX,CAGA,IAAMA,EAAW,eAAa,KAAK,EACnC,OAAAA,EAAS,QAAQ,IAAI,eAAgBV,GAAa,OAAO,EAClDU,CACX","names":["middleware_exports","__export","AI_BOT_USER_AGENTS","matchBot","ontoMiddleware","__toCommonJS","import_server","AI_BOTS","AI_BOT_USER_AGENTS","AI_BOT_USER_AGENTS_CACHE","bot","matchBot","userAgent","lowerUA","matches","longest","current","generateLlmsTxt","config","lines","route","fullUrl","link","section","ontoMiddleware","request","config","userAgent","url","matched","matchBot","accept","hasDebugParam","isAiBot","isMarkdownRequested","llmsTxtContent","generateLlmsTxt","response","error","payloadPath","ONTO_API_KEY","DASHBOARD_URL"]}
1
+ {"version":3,"sources":["../src/middleware.ts","../src/bots.ts","../src/config.ts"],"sourcesContent":["import { NextRequest, NextResponse } from 'next/server';\r\nimport { matchBot } from './bots';\r\nimport { generateLlmsTxt, OntoConfig } from './config';\r\n\r\nexport async function ontoMiddleware(request: any, config?: OntoConfig) {\r\n const userAgent = request.headers.get('user-agent');\r\n const url = request.nextUrl.clone();\r\n const matched = matchBot(userAgent);\r\n\r\n const accept = request.headers.get('accept') || '';\r\n const hasDebugParam = request.nextUrl.searchParams.has('onto');\r\n\r\n const isAiBot = !!matched;\r\n const isMarkdownRequested = accept.includes('text/markdown') || hasDebugParam;\r\n\r\n // Common logic for bot/markdown negotiation\r\n if (isAiBot || isMarkdownRequested) {\r\n // Ignore internal next.js requests\r\n if (url.pathname.startsWith('/_next')) {\r\n return NextResponse.next();\r\n }\r\n\r\n // --- llms.txt Auto-Discovery ---\r\n if (url.pathname === '/llms.txt') {\r\n try {\r\n if (config) {\r\n const llmsTxtContent = generateLlmsTxt(config);\r\n const response = new NextResponse(llmsTxtContent, {\r\n headers: {\r\n 'Content-Type': 'text/plain; charset=utf-8',\r\n 'Cache-Control': 'public, max-age=3600, s-maxage=3600, stale-while-revalidate=86400',\r\n }\r\n });\r\n if (matched) response.headers.set('X-Onto-Bot', `${matched.name} (${matched.company})`);\r\n response.headers.set('X-Onto-Trace', userAgent || 'no-ua');\r\n return response;\r\n }\r\n } catch (error) {\r\n console.error('[Onto] Failed to generate llms.txt:', error);\r\n }\r\n }\r\n\r\n // Skip other static assets with dots\r\n if (url.pathname.includes('.')) {\r\n return NextResponse.next();\r\n }\r\n\r\n // Determine the corresponding payload path\r\n let payloadPath = url.pathname;\r\n if (payloadPath === '/' || payloadPath === '') payloadPath = '/index';\r\n if (payloadPath.endsWith('/') && payloadPath !== '/') payloadPath = payloadPath.slice(0, -1);\r\n\r\n // --- Onto Control Plane Integration (Premium) ---\r\n const ONTO_API_KEY = process.env.ONTO_API_KEY;\r\n const DASHBOARD_URL = process.env.ONTO_DASHBOARD_URL || 'https://app.buildonto.dev';\r\n\r\n if (ONTO_API_KEY) {\r\n // Logic for tracking and injection ... (fire-and-forget tracking)\r\n fetch(`${DASHBOARD_URL}/api/track`, {\r\n method: 'POST',\r\n headers: { 'x-onto-key': ONTO_API_KEY, 'Content-Type': 'application/json' },\r\n body: JSON.stringify({ route: url.pathname, userAgent, bot: matched?.name, company: matched?.company })\r\n }).catch(() => {});\r\n }\r\n\r\n // Rewrite to semantic payload\r\n url.pathname = `/.onto${payloadPath}.md`;\r\n const response = NextResponse.rewrite(url);\r\n \r\n // Apply headers\r\n response.headers.set('Content-Type', 'text/markdown; charset=utf-8');\r\n response.headers.set('Cache-Control', 'public, max-age=3600, s-maxage=3600, stale-while-revalidate=86400');\r\n response.headers.set('Vary', 'User-Agent, Accept');\r\n response.headers.set('X-Onto-Trace', userAgent || 'no-ua');\r\n \r\n if (matched) {\r\n response.headers.set('X-Onto-Bot', `${matched.name} (${matched.company})`);\r\n response.headers.set('X-Onto-Matched', 'true');\r\n }\r\n \r\n if (hasDebugParam) response.headers.set('X-Onto-Debug', 'true');\r\n\r\n return response;\r\n }\r\n\r\n // Default response for non-bots\r\n const response = NextResponse.next();\r\n \r\n // Crucial: Tell Vercel/Edge to vary the cache by User-Agent \r\n // This ensures bots get the rewrite and humans get the HTML\r\n response.headers.set('Vary', 'User-Agent, Accept');\r\n response.headers.set('X-Onto-Trace', userAgent || 'no-ua');\r\n \r\n return response;\r\n}\r\n\r\n// Re-export the bot registry for consumers who want to extend or inspect it\r\nexport { AI_BOT_USER_AGENTS, matchBot } from './bots';\r\nexport type { AiBot } from './bots';\r\n\r\n\r\n","/**\n * Comprehensive registry of AI bot user-agent strings.\n * The middleware uses this list to detect AI crawlers and serve optimized markdown.\n */\n\nexport interface AiBot {\n /** The user-agent substring to match against */\n name: string;\n /** The company operating this bot */\n company: string;\n /** ISO date when this bot was added or last verified */\n addedAt?: string;\n}\n\n/**\n * Structured registry of all known AI bots, grouped by company.\n * Useful for analytics and the Control Plane dashboard.\n */\nexport const AI_BOTS: AiBot[] = [\n // OpenAI\n { name: 'GPTBot', company: 'OpenAI', addedAt: '2025-01-01' },\n { name: 'ChatGPT-User', company: 'OpenAI', addedAt: '2025-01-01' },\n { name: 'OAI-SearchBot', company: 'OpenAI', addedAt: '2025-01-01' },\n { name: 'ChatGPT', company: 'OpenAI', addedAt: '2025-03-25' },\n { name: 'OpenAI', company: 'OpenAI', addedAt: '2025-03-25' },\n { name: 'GPT', company: 'OpenAI', addedAt: '2025-03-25' },\n\n // Google (SEO Safety: Googlebot proper is EXCLUDED)\n { name: 'Google-CloudVertexBot', company: 'Google', addedAt: '2025-01-01' },\n { name: 'Google-Extended', company: 'Google', addedAt: '2025-01-01' },\n { name: 'GoogleOther', company: 'Google', addedAt: '2025-01-01' },\n\n // Anthropic\n { name: 'ClaudeBot', company: 'Anthropic', addedAt: '2025-01-01' },\n { name: 'Claude-User', company: 'Anthropic', addedAt: '2025-01-01' },\n { name: 'claude-fetch', company: 'Anthropic', addedAt: '2025-03-25' },\n { name: 'AnthropicFetch', company: 'Anthropic', addedAt: '2025-03-25' },\n { name: 'Claude-Fetch', company: 'Anthropic', addedAt: '2025-03-25' },\n { name: 'anthropic-ai', company: 'Anthropic', addedAt: '2025-01-01' },\n { name: 'Claude', company: 'Anthropic', addedAt: '2025-03-25' },\n { name: 'Anthropic', company: 'Anthropic', addedAt: '2025-03-25' },\n\n // Perplexity\n { name: 'PerplexityBot', company: 'Perplexity', addedAt: '2025-01-01' },\n { name: 'Perplexity-User', company: 'Perplexity', addedAt: '2025-01-01' },\n { name: 'Perplexity', company: 'Perplexity', addedAt: '2025-03-25' },\n\n // Meta\n { name: 'Meta-ExternalAgent', company: 'Meta', addedAt: '2025-01-01' },\n { name: 'Meta-ExternalFetcher', company: 'Meta', addedAt: '2025-01-01' },\n { name: 'facebookexternalhit', company: 'Meta', addedAt: '2025-03-25' },\n { name: 'FacebookBot', company: 'Meta', addedAt: '2025-01-01' },\n\n // Mistral\n { name: 'MistralBot', company: 'Mistral', addedAt: '2025-03-25' },\n { name: 'Mistral', company: 'Mistral', addedAt: '2025-03-25' },\n\n // Amazon\n { name: 'Amazonbot', company: 'Amazon', addedAt: '2025-03-25' },\n\n // Others\n { name: 'AI2Bot', company: 'Allen Institute', addedAt: '2025-03-25' },\n { name: 'DuckAssistBot', company: 'DuckDuckGo', addedAt: '2025-03-25' },\n { name: 'Diffbot', company: 'Diffbot', addedAt: '2025-03-25' },\n { name: 'CCBot', company: 'Common Crawl', addedAt: '2025-01-01' },\n { name: 'Bytespider', company: 'ByteDance', addedAt: '2025-01-01' },\n { name: 'Applebot-Extended', company: 'Apple', addedAt: '2025-01-01' },\n { name: 'YouBot', company: 'You.com', addedAt: '2025-01-01' },\n\n // Generic AI / Scraping Libraries (Last Resort)\n { name: 'python-requests', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'python-httpx', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'httpx', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'axios', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'node-fetch', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'Go-http-client', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'Wget', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'Curl', company: 'Generic Bot', addedAt: '2025-03-25' },\n];\n\n/**\n * Flat list of user-agent substrings for fast matching in the middleware.\n */\nexport const AI_BOT_USER_AGENTS: string[] = AI_BOT_USER_AGENTS_CACHE();\n\nfunction AI_BOT_USER_AGENTS_CACHE() {\n return AI_BOTS.map(bot => bot.name);\n}\n\n/**\n * Given a raw user-agent string, returns the matched AiBot entry or undefined.\n * Uses a \"Longest Match\" strategy to ensure maximum specificity.\n * Comparison is case-insensitive.\n */\nexport function matchBot(userAgent: string | null): AiBot | undefined {\n if (!userAgent) return undefined;\n const lowerUA = userAgent.toLowerCase();\n \n // Find all matches\n const matches = AI_BOTS.filter(bot => \n lowerUA.includes(bot.name.toLowerCase())\n );\n\n if (matches.length === 0) return undefined;\n if (matches.length === 1) return matches[0];\n\n // Pick the longest match for maximum specificity (e.g. 'ChatGPT-User' vs 'GPT')\n return matches.reduce((longest, current) => \n current.name.length > longest.name.length ? current : longest\n );\n}\n","/**\r\n * Configuration schema for onto.config.ts\r\n * Used to dynamically generate llms.txt and other AI discovery files\r\n */\r\n\r\nexport type PageType = 'scoring' | 'about' | 'default';\r\n\r\nexport interface OntoRoute {\r\n /**\r\n * The URL path (e.g., '/docs', '/api/reference')\r\n */\r\n path: string;\r\n /**\r\n * Description of what this route contains\r\n */\r\n description: string;\r\n /**\r\n * Optional: Page type for automatic JSON-LD schema injection\r\n * - 'scoring': Injects Methodology schema with AIO scoring weights (40/35/25)\r\n * - 'about': Injects Organization/AboutPage schema\r\n * - 'default': No automatic schema injection\r\n */\r\n pageType?: PageType;\r\n}\r\n\r\nexport interface OntoConfig {\r\n /**\r\n * The name of your project or site (required)\r\n * Used as the H1 heading in llms.txt\r\n */\r\n name: string;\r\n\r\n /**\r\n * A short summary of your project (required)\r\n * Displayed as a blockquote in llms.txt\r\n * Should contain key information necessary for understanding the rest of the file\r\n */\r\n summary: string;\r\n\r\n /**\r\n * The base URL of your site (e.g., 'https://example.com')\r\n */\r\n baseUrl: string;\r\n\r\n /**\r\n * Optional: Additional sections to include in llms.txt\r\n * Each section can contain any markdown content\r\n */\r\n sections?: {\r\n heading: string;\r\n content: string;\r\n }[];\r\n\r\n /**\r\n * Key routes that AI agents should know about\r\n * These will be formatted as a markdown list in llms.txt\r\n */\r\n routes?: OntoRoute[];\r\n\r\n /**\r\n * Optional: Links to external resources (documentation, API references, etc.)\r\n */\r\n externalLinks?: {\r\n title: string;\r\n url: string;\r\n description?: string;\r\n }[];\r\n\r\n /**\r\n * Optional: Organization information for JSON-LD schemas\r\n */\r\n organization?: {\r\n name: string;\r\n description?: string;\r\n url?: string;\r\n logo?: string;\r\n foundingDate?: string;\r\n };\r\n}\r\n\r\n/**\r\n * Generate llms.txt content from OntoConfig\r\n * Follows the llms.txt specification:\r\n * - H1 with project name\r\n * - Blockquote with summary\r\n * - Additional markdown sections\r\n */\r\nexport function generateLlmsTxt(config: OntoConfig): string {\r\n const lines: string[] = [];\r\n\r\n // H1: Project name (required)\r\n lines.push(`# ${config.name}`);\r\n lines.push('');\r\n\r\n // Blockquote: Summary (required)\r\n lines.push(`> ${config.summary}`);\r\n lines.push('');\r\n\r\n // Key Routes section (if provided)\r\n if (config.routes && config.routes.length > 0) {\r\n lines.push('## Key Routes');\r\n lines.push('');\r\n for (const route of config.routes) {\r\n const fullUrl = `${config.baseUrl}${route.path}`;\r\n lines.push(`- [${route.path}](${fullUrl}): ${route.description}`);\r\n }\r\n lines.push('');\r\n }\r\n\r\n // External Links section (if provided)\r\n if (config.externalLinks && config.externalLinks.length > 0) {\r\n lines.push('## Resources');\r\n lines.push('');\r\n for (const link of config.externalLinks) {\r\n if (link.description) {\r\n lines.push(`- [${link.title}](${link.url}): ${link.description}`);\r\n } else {\r\n lines.push(`- [${link.title}](${link.url})`);\r\n }\r\n }\r\n lines.push('');\r\n }\r\n\r\n // Custom sections (if provided)\r\n if (config.sections && config.sections.length > 0) {\r\n for (const section of config.sections) {\r\n lines.push(`## ${section.heading}`);\r\n lines.push('');\r\n lines.push(section.content);\r\n lines.push('');\r\n }\r\n }\r\n\r\n return lines.join('\\n').trim() + '\\n';\r\n}\r\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,EAAA,aAAAC,EAAA,mBAAAC,IAAA,eAAAC,EAAAL,GAAA,IAAAM,EAA0C,uBCkBnC,IAAMC,EAAmB,CAE5B,CAAE,KAAM,SAAqB,QAAS,SAAY,QAAS,YAAa,EACxE,CAAE,KAAM,eAAoB,QAAS,SAAY,QAAS,YAAa,EACvE,CAAE,KAAM,gBAAoB,QAAS,SAAY,QAAS,YAAa,EACvE,CAAE,KAAM,UAAoB,QAAS,SAAY,QAAS,YAAa,EACvE,CAAE,KAAM,SAAoB,QAAS,SAAY,QAAS,YAAa,EACvE,CAAE,KAAM,MAAoB,QAAS,SAAY,QAAS,YAAa,EAGvE,CAAE,KAAM,wBAA2B,QAAS,SAAU,QAAS,YAAa,EAC5E,CAAE,KAAM,kBAA2B,QAAS,SAAU,QAAS,YAAa,EAC5E,CAAE,KAAM,cAA2B,QAAS,SAAU,QAAS,YAAa,EAG5E,CAAE,KAAM,YAAmB,QAAS,YAAa,QAAS,YAAa,EACvE,CAAE,KAAM,cAAkB,QAAS,YAAa,QAAS,YAAa,EACtE,CAAE,KAAM,eAAkB,QAAS,YAAa,QAAS,YAAa,EACtE,CAAE,KAAM,iBAAkB,QAAS,YAAa,QAAS,YAAa,EACtE,CAAE,KAAM,eAAkB,QAAS,YAAa,QAAS,YAAa,EACtE,CAAE,KAAM,eAAkB,QAAS,YAA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ENTS","AI_BOT_USER_AGENTS_CACHE","bot","matchBot","userAgent","lowerUA","matches","longest","current","generateLlmsTxt","config","lines","route","fullUrl","link","section","ontoMiddleware","request","config","userAgent","url","matched","matchBot","accept","hasDebugParam","isAiBot","isMarkdownRequested","llmsTxtContent","generateLlmsTxt","response","error","payloadPath","ONTO_API_KEY","DASHBOARD_URL"]}
@@ -1,4 +1,4 @@
1
- import{NextResponse as s}from"next/server";var A=[{name:"GPTBot",company:"OpenAI",addedAt:"2025-01-01"},{name:"ChatGPT-User",company:"OpenAI",addedAt:"2025-01-01"},{name:"OAI-SearchBot",company:"OpenAI",addedAt:"2025-01-01"},{name:"ChatGPT",company:"OpenAI",addedAt:"2025-03-25"},{name:"OpenAI",company:"OpenAI",addedAt:"2025-03-25"},{name:"GPT",company:"OpenAI",addedAt:"2025-03-25"},{name:"Google-CloudVertexBot",company:"Google",addedAt:"2025-01-01"},{name:"Google-Extended",company:"Google",addedAt:"2025-01-01"},{name:"GoogleOther",company:"Google",addedAt:"2025-01-01"},{name:"ClaudeBot",company:"Anthropic",addedAt:"2025-01-01"},{name:"Claude-User",company:"Anthropic",addedAt:"2025-01-01"},{name:"claude-fetch",company:"Anthropic",addedAt:"2025-03-25"},{name:"AnthropicFetch",company:"Anthropic",addedAt:"2025-03-25"},{name:"Claude-Fetch",company:"Anthropic",addedAt:"2025-03-25"},{name:"anthropic-ai",company:"Anthropic",addedAt:"2025-01-01"},{name:"Claude",company:"Anthropic",addedAt:"2025-03-25"},{name:"Anthropic",company:"Anthropic",addedAt:"2025-03-25"},{name:"PerplexityBot",company:"Perplexity",addedAt:"2025-01-01"},{name:"Perplexity-User",company:"Perplexity",addedAt:"2025-01-01"},{name:"Perplexity",company:"Perplexity",addedAt:"2025-03-25"},{name:"Meta-ExternalAgent",company:"Meta",addedAt:"2025-01-01"},{name:"Meta-ExternalFetcher",company:"Meta",addedAt:"2025-01-01"},{name:"facebookexternalhit",company:"Meta",addedAt:"2025-03-25"},{name:"FacebookBot",company:"Meta",addedAt:"2025-01-01"},{name:"MistralBot",company:"Mistral",addedAt:"2025-03-25"},{name:"Mistral",company:"Mistral",addedAt:"2025-03-25"},{name:"Amazonbot",company:"Amazon",addedAt:"2025-03-25"},{name:"AI2Bot",company:"Allen Institute",addedAt:"2025-03-25"},{name:"DuckAssistBot",company:"DuckDuckGo",addedAt:"2025-03-25"},{name:"Diffbot",company:"Diffbot",addedAt:"2025-03-25"},{name:"CCBot",company:"Common Crawl",addedAt:"2025-01-01"},{name:"Bytespider",company:"ByteDance",addedAt:"2025-01-01"},{name:"Applebot-Extended",company:"Apple",addedAt:"2025-01-01"},{name:"YouBot",company:"You.com",addedAt:"2025-01-01"},{name:"python-requests",company:"Generic Bot",addedAt:"2025-03-25"},{name:"python-httpx",company:"Generic Bot",addedAt:"2025-03-25"},{name:"httpx",company:"Generic Bot",addedAt:"2025-03-25"},{name:"axios",company:"Generic Bot",addedAt:"2025-03-25"},{name:"node-fetch",company:"Generic Bot",addedAt:"2025-03-25"},{name:"Go-http-client",company:"Generic Bot",addedAt:"2025-03-25"},{name:"Wget",company:"Generic Bot",addedAt:"2025-03-25"},{name:"Curl",company:"Generic Bot",addedAt:"2025-03-25"}],B=O();function O(){return A.map(n=>n.name)}function i(n){if(!n)return;let t=n.toLowerCase(),e=A.filter(a=>t.includes(a.name.toLowerCase()));if(e.length!==0)return e.length===1?e[0]:e.reduce((a,o)=>o.name.length>a.name.length?o:a)}function u(n){let t=[];if(t.push(`# ${n.name}`),t.push(""),t.push(`> ${n.summary}`),t.push(""),n.routes&&n.routes.length>0){t.push("## Key Routes"),t.push("");for(let e of n.routes){let a=`${n.baseUrl}${e.path}`;t.push(`- [${e.path}](${a}): ${e.description}`)}t.push("")}if(n.externalLinks&&n.externalLinks.length>0){t.push("## Resources"),t.push("");for(let e of n.externalLinks)e.description?t.push(`- [${e.title}](${e.url}): ${e.description}`):t.push(`- [${e.title}](${e.url})`);t.push("")}if(n.sections&&n.sections.length>0)for(let e of n.sections)t.push(`## ${e.heading}`),t.push(""),t.push(e.content),t.push("");return t.join(`
1
+ import{NextResponse as s}from"next/server";var A=[{name:"GPTBot",company:"OpenAI",addedAt:"2025-01-01"},{name:"ChatGPT-User",company:"OpenAI",addedAt:"2025-01-01"},{name:"OAI-SearchBot",company:"OpenAI",addedAt:"2025-01-01"},{name:"ChatGPT",company:"OpenAI",addedAt:"2025-03-25"},{name:"OpenAI",company:"OpenAI",addedAt:"2025-03-25"},{name:"GPT",company:"OpenAI",addedAt:"2025-03-25"},{name:"Google-CloudVertexBot",company:"Google",addedAt:"2025-01-01"},{name:"Google-Extended",company:"Google",addedAt:"2025-01-01"},{name:"GoogleOther",company:"Google",addedAt:"2025-01-01"},{name:"ClaudeBot",company:"Anthropic",addedAt:"2025-01-01"},{name:"Claude-User",company:"Anthropic",addedAt:"2025-01-01"},{name:"claude-fetch",company:"Anthropic",addedAt:"2025-03-25"},{name:"AnthropicFetch",company:"Anthropic",addedAt:"2025-03-25"},{name:"Claude-Fetch",company:"Anthropic",addedAt:"2025-03-25"},{name:"anthropic-ai",company:"Anthropic",addedAt:"2025-01-01"},{name:"Claude",company:"Anthropic",addedAt:"2025-03-25"},{name:"Anthropic",company:"Anthropic",addedAt:"2025-03-25"},{name:"PerplexityBot",company:"Perplexity",addedAt:"2025-01-01"},{name:"Perplexity-User",company:"Perplexity",addedAt:"2025-01-01"},{name:"Perplexity",company:"Perplexity",addedAt:"2025-03-25"},{name:"Meta-ExternalAgent",company:"Meta",addedAt:"2025-01-01"},{name:"Meta-ExternalFetcher",company:"Meta",addedAt:"2025-01-01"},{name:"facebookexternalhit",company:"Meta",addedAt:"2025-03-25"},{name:"FacebookBot",company:"Meta",addedAt:"2025-01-01"},{name:"MistralBot",company:"Mistral",addedAt:"2025-03-25"},{name:"Mistral",company:"Mistral",addedAt:"2025-03-25"},{name:"Amazonbot",company:"Amazon",addedAt:"2025-03-25"},{name:"AI2Bot",company:"Allen Institute",addedAt:"2025-03-25"},{name:"DuckAssistBot",company:"DuckDuckGo",addedAt:"2025-03-25"},{name:"Diffbot",company:"Diffbot",addedAt:"2025-03-25"},{name:"CCBot",company:"Common Crawl",addedAt:"2025-01-01"},{name:"Bytespider",company:"ByteDance",addedAt:"2025-01-01"},{name:"Applebot-Extended",company:"Apple",addedAt:"2025-01-01"},{name:"YouBot",company:"You.com",addedAt:"2025-01-01"},{name:"python-requests",company:"Generic Bot",addedAt:"2025-03-25"},{name:"python-httpx",company:"Generic Bot",addedAt:"2025-03-25"},{name:"httpx",company:"Generic Bot",addedAt:"2025-03-25"},{name:"axios",company:"Generic Bot",addedAt:"2025-03-25"},{name:"node-fetch",company:"Generic Bot",addedAt:"2025-03-25"},{name:"Go-http-client",company:"Generic Bot",addedAt:"2025-03-25"},{name:"Wget",company:"Generic Bot",addedAt:"2025-03-25"},{name:"Curl",company:"Generic Bot",addedAt:"2025-03-25"}],B=O();function O(){return A.map(n=>n.name)}function m(n){if(!n)return;let t=n.toLowerCase(),e=A.filter(a=>t.includes(a.name.toLowerCase()));if(e.length!==0)return e.length===1?e[0]:e.reduce((a,o)=>o.name.length>a.name.length?o:a)}function u(n){let t=[];if(t.push(`# ${n.name}`),t.push(""),t.push(`> ${n.summary}`),t.push(""),n.routes&&n.routes.length>0){t.push("## Key Routes"),t.push("");for(let e of n.routes){let a=`${n.baseUrl}${e.path}`;t.push(`- [${e.path}](${a}): ${e.description}`)}t.push("")}if(n.externalLinks&&n.externalLinks.length>0){t.push("## Resources"),t.push("");for(let e of n.externalLinks)e.description?t.push(`- [${e.title}](${e.url}): ${e.description}`):t.push(`- [${e.title}](${e.url})`);t.push("")}if(n.sections&&n.sections.length>0)for(let e of n.sections)t.push(`## ${e.heading}`),t.push(""),t.push(e.content),t.push("");return t.join(`
2
2
  `).trim()+`
3
- `}async function I(n,t){let e=n.headers.get("user-agent"),a=n.nextUrl.clone(),o=i(e),y=n.headers.get("accept")||"",m=n.nextUrl.searchParams.has("onto"),x=!!o,g=y.includes("text/markdown")||m;if(x||g){if(a.pathname.startsWith("/_next"))return s.next();if(a.pathname==="/llms.txt")try{if(t){let p=u(t),c=new s(p,{headers:{"Content-Type":"text/plain; charset=utf-8","Cache-Control":"public, max-age=3600, s-maxage=3600, stale-while-revalidate=86400"}});return o&&c.headers.set("X-Onto-Bot",`${o.name} (${o.company})`),c.headers.set("X-Onto-Trace",e||"no-ua"),c}}catch(p){console.error("[Onto] Failed to generate llms.txt:",p)}if(a.pathname.includes("."))return s.next();let r=a.pathname;(r==="/"||r==="")&&(r="/index"),r.endsWith("/")&&r!=="/"&&(r=r.slice(0,-1));let h=process.env.ONTO_API_KEY,f=process.env.ONTO_DASHBOARD_URL||"https://app.buildonto.dev";h&&fetch(`${f}/api/track`,{method:"POST",headers:{"x-onto-key":h,"Content-Type":"application/json"},body:JSON.stringify({route:a.pathname,userAgent:e,bot:o?.name,company:o?.company})}).catch(()=>{}),a.pathname=`/.onto${r}.md`;let d=s.rewrite(a);return d.headers.set("Content-Type","text/markdown; charset=utf-8"),d.headers.set("Cache-Control","public, max-age=3600, s-maxage=3600, stale-while-revalidate=86400"),d.headers.set("X-Onto-Trace",e||"no-ua"),o&&d.headers.set("X-Onto-Bot",`${o.name} (${o.company})`),m&&d.headers.set("X-Onto-Debug","true"),d}let l=s.next();return l.headers.set("X-Onto-Trace",e||"no-ua"),l}export{B as AI_BOT_USER_AGENTS,i as matchBot,I as ontoMiddleware};
3
+ `}async function I(n,t){let e=n.headers.get("user-agent"),a=n.nextUrl.clone(),o=m(e),y=n.headers.get("accept")||"",h=n.nextUrl.searchParams.has("onto"),g=!!o,x=y.includes("text/markdown")||h;if(g||x){if(a.pathname.startsWith("/_next"))return s.next();if(a.pathname==="/llms.txt")try{if(t){let c=u(t),i=new s(c,{headers:{"Content-Type":"text/plain; charset=utf-8","Cache-Control":"public, max-age=3600, s-maxage=3600, stale-while-revalidate=86400"}});return o&&i.headers.set("X-Onto-Bot",`${o.name} (${o.company})`),i.headers.set("X-Onto-Trace",e||"no-ua"),i}}catch(c){console.error("[Onto] Failed to generate llms.txt:",c)}if(a.pathname.includes("."))return s.next();let r=a.pathname;(r==="/"||r==="")&&(r="/index"),r.endsWith("/")&&r!=="/"&&(r=r.slice(0,-1));let l=process.env.ONTO_API_KEY,f=process.env.ONTO_DASHBOARD_URL||"https://app.buildonto.dev";l&&fetch(`${f}/api/track`,{method:"POST",headers:{"x-onto-key":l,"Content-Type":"application/json"},body:JSON.stringify({route:a.pathname,userAgent:e,bot:o?.name,company:o?.company})}).catch(()=>{}),a.pathname=`/.onto${r}.md`;let d=s.rewrite(a);return d.headers.set("Content-Type","text/markdown; charset=utf-8"),d.headers.set("Cache-Control","public, max-age=3600, s-maxage=3600, stale-while-revalidate=86400"),d.headers.set("Vary","User-Agent, Accept"),d.headers.set("X-Onto-Trace",e||"no-ua"),o&&(d.headers.set("X-Onto-Bot",`${o.name} (${o.company})`),d.headers.set("X-Onto-Matched","true")),h&&d.headers.set("X-Onto-Debug","true"),d}let p=s.next();return p.headers.set("Vary","User-Agent, Accept"),p.headers.set("X-Onto-Trace",e||"no-ua"),p}export{B as AI_BOT_USER_AGENTS,m as matchBot,I as ontoMiddleware};
4
4
  //# sourceMappingURL=middleware.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/middleware.ts","../src/bots.ts","../src/config.ts"],"sourcesContent":["import { NextRequest, NextResponse } from 'next/server';\r\nimport { matchBot } from './bots';\r\nimport { generateLlmsTxt, OntoConfig } from './config';\r\n\r\nexport async function ontoMiddleware(request: any, config?: OntoConfig) {\r\n const userAgent = request.headers.get('user-agent');\r\n const url = request.nextUrl.clone();\r\n const matched = matchBot(userAgent);\r\n\r\n const accept = request.headers.get('accept') || '';\r\n const hasDebugParam = request.nextUrl.searchParams.has('onto');\r\n\r\n const isAiBot = !!matched;\r\n const isMarkdownRequested = accept.includes('text/markdown') || hasDebugParam;\r\n\r\n // Common logic for bot/markdown negotiation\r\n if (isAiBot || isMarkdownRequested) {\r\n // Ignore internal next.js requests\r\n if (url.pathname.startsWith('/_next')) {\r\n return NextResponse.next();\r\n }\r\n\r\n // --- llms.txt Auto-Discovery ---\r\n if (url.pathname === '/llms.txt') {\r\n try {\r\n if (config) {\r\n const llmsTxtContent = generateLlmsTxt(config);\r\n const response = new NextResponse(llmsTxtContent, {\r\n headers: {\r\n 'Content-Type': 'text/plain; charset=utf-8',\r\n 'Cache-Control': 'public, max-age=3600, s-maxage=3600, stale-while-revalidate=86400',\r\n }\r\n });\r\n if (matched) response.headers.set('X-Onto-Bot', `${matched.name} (${matched.company})`);\r\n response.headers.set('X-Onto-Trace', userAgent || 'no-ua');\r\n return response;\r\n }\r\n } catch (error) {\r\n console.error('[Onto] Failed to generate llms.txt:', error);\r\n }\r\n }\r\n\r\n // Skip other static assets with dots\r\n if (url.pathname.includes('.')) {\r\n return NextResponse.next();\r\n }\r\n\r\n // Determine the corresponding payload path\r\n let payloadPath = url.pathname;\r\n if (payloadPath === '/' || payloadPath === '') payloadPath = '/index';\r\n if (payloadPath.endsWith('/') && payloadPath !== '/') payloadPath = payloadPath.slice(0, -1);\r\n\r\n // --- Onto Control Plane Integration (Premium) ---\r\n const ONTO_API_KEY = process.env.ONTO_API_KEY;\r\n const DASHBOARD_URL = process.env.ONTO_DASHBOARD_URL || 'https://app.buildonto.dev';\r\n\r\n if (ONTO_API_KEY) {\r\n // Logic for tracking and injection ... (fire-and-forget tracking)\r\n fetch(`${DASHBOARD_URL}/api/track`, {\r\n method: 'POST',\r\n headers: { 'x-onto-key': ONTO_API_KEY, 'Content-Type': 'application/json' },\r\n body: JSON.stringify({ route: url.pathname, userAgent, bot: matched?.name, company: matched?.company })\r\n }).catch(() => {});\r\n }\r\n\r\n // Rewrite to semantic payload\r\n url.pathname = `/.onto${payloadPath}.md`;\r\n const response = NextResponse.rewrite(url);\r\n \r\n // Apply headers\r\n response.headers.set('Content-Type', 'text/markdown; charset=utf-8');\r\n response.headers.set('Cache-Control', 'public, max-age=3600, s-maxage=3600, stale-while-revalidate=86400');\r\n response.headers.set('X-Onto-Trace', userAgent || 'no-ua');\r\n if (matched) response.headers.set('X-Onto-Bot', `${matched.name} (${matched.company})`);\r\n if (hasDebugParam) response.headers.set('X-Onto-Debug', 'true');\r\n\r\n return response;\r\n }\r\n\r\n // Default response for non-bots\r\n const response = NextResponse.next();\r\n response.headers.set('X-Onto-Trace', userAgent || 'no-ua');\r\n return response;\r\n}\r\n\r\n// Re-export the bot registry for consumers who want to extend or inspect it\r\nexport { AI_BOT_USER_AGENTS, matchBot } from './bots';\r\nexport type { AiBot } from './bots';\r\n\r\n\r\n","/**\n * Comprehensive registry of AI bot user-agent strings.\n * The middleware uses this list to detect AI crawlers and serve optimized markdown.\n */\n\nexport interface AiBot {\n /** The user-agent substring to match against */\n name: string;\n /** The company operating this bot */\n company: string;\n /** ISO date when this bot was added or last verified */\n addedAt?: string;\n}\n\n/**\n * Structured registry of all known AI bots, grouped by company.\n * Useful for analytics and the Control Plane dashboard.\n */\nexport const AI_BOTS: AiBot[] = [\n // OpenAI\n { name: 'GPTBot', company: 'OpenAI', addedAt: '2025-01-01' },\n { name: 'ChatGPT-User', company: 'OpenAI', addedAt: '2025-01-01' },\n { name: 'OAI-SearchBot', company: 'OpenAI', addedAt: '2025-01-01' },\n { name: 'ChatGPT', company: 'OpenAI', addedAt: '2025-03-25' },\n { name: 'OpenAI', company: 'OpenAI', addedAt: '2025-03-25' },\n { name: 'GPT', company: 'OpenAI', addedAt: '2025-03-25' },\n\n // Google (SEO Safety: Googlebot proper is EXCLUDED)\n { name: 'Google-CloudVertexBot', company: 'Google', addedAt: '2025-01-01' },\n { name: 'Google-Extended', company: 'Google', addedAt: '2025-01-01' },\n { name: 'GoogleOther', company: 'Google', addedAt: '2025-01-01' },\n\n // Anthropic\n { name: 'ClaudeBot', company: 'Anthropic', addedAt: '2025-01-01' },\n { name: 'Claude-User', company: 'Anthropic', addedAt: '2025-01-01' },\n { name: 'claude-fetch', company: 'Anthropic', addedAt: '2025-03-25' },\n { name: 'AnthropicFetch', company: 'Anthropic', addedAt: '2025-03-25' },\n { name: 'Claude-Fetch', company: 'Anthropic', addedAt: '2025-03-25' },\n { name: 'anthropic-ai', company: 'Anthropic', addedAt: '2025-01-01' },\n { name: 'Claude', company: 'Anthropic', addedAt: '2025-03-25' },\n { name: 'Anthropic', company: 'Anthropic', addedAt: '2025-03-25' },\n\n // Perplexity\n { name: 'PerplexityBot', company: 'Perplexity', addedAt: '2025-01-01' },\n { name: 'Perplexity-User', company: 'Perplexity', addedAt: '2025-01-01' },\n { name: 'Perplexity', company: 'Perplexity', addedAt: '2025-03-25' },\n\n // Meta\n { name: 'Meta-ExternalAgent', company: 'Meta', addedAt: '2025-01-01' },\n { name: 'Meta-ExternalFetcher', company: 'Meta', addedAt: '2025-01-01' },\n { name: 'facebookexternalhit', company: 'Meta', addedAt: '2025-03-25' },\n { name: 'FacebookBot', company: 'Meta', addedAt: '2025-01-01' },\n\n // Mistral\n { name: 'MistralBot', company: 'Mistral', addedAt: '2025-03-25' },\n { name: 'Mistral', company: 'Mistral', addedAt: '2025-03-25' },\n\n // Amazon\n { name: 'Amazonbot', company: 'Amazon', addedAt: '2025-03-25' },\n\n // Others\n { name: 'AI2Bot', company: 'Allen Institute', addedAt: '2025-03-25' },\n { name: 'DuckAssistBot', company: 'DuckDuckGo', addedAt: '2025-03-25' },\n { name: 'Diffbot', company: 'Diffbot', addedAt: '2025-03-25' },\n { name: 'CCBot', company: 'Common Crawl', addedAt: '2025-01-01' },\n { name: 'Bytespider', company: 'ByteDance', addedAt: '2025-01-01' },\n { name: 'Applebot-Extended', company: 'Apple', addedAt: '2025-01-01' },\n { name: 'YouBot', company: 'You.com', addedAt: '2025-01-01' },\n\n // Generic AI / Scraping Libraries (Last Resort)\n { name: 'python-requests', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'python-httpx', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'httpx', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'axios', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'node-fetch', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'Go-http-client', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'Wget', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'Curl', company: 'Generic Bot', addedAt: '2025-03-25' },\n];\n\n/**\n * Flat list of user-agent substrings for fast matching in the middleware.\n */\nexport const AI_BOT_USER_AGENTS: string[] = AI_BOT_USER_AGENTS_CACHE();\n\nfunction AI_BOT_USER_AGENTS_CACHE() {\n return AI_BOTS.map(bot => bot.name);\n}\n\n/**\n * Given a raw user-agent string, returns the matched AiBot entry or undefined.\n * Uses a \"Longest Match\" strategy to ensure maximum specificity.\n * Comparison is case-insensitive.\n */\nexport function matchBot(userAgent: string | null): AiBot | undefined {\n if (!userAgent) return undefined;\n const lowerUA = userAgent.toLowerCase();\n \n // Find all matches\n const matches = AI_BOTS.filter(bot => \n lowerUA.includes(bot.name.toLowerCase())\n );\n\n if (matches.length === 0) return undefined;\n if (matches.length === 1) return matches[0];\n\n // Pick the longest match for maximum specificity (e.g. 'ChatGPT-User' vs 'GPT')\n return matches.reduce((longest, current) => \n current.name.length > longest.name.length ? current : longest\n );\n}\n","/**\r\n * Configuration schema for onto.config.ts\r\n * Used to dynamically generate llms.txt and other AI discovery files\r\n */\r\n\r\nexport type PageType = 'scoring' | 'about' | 'default';\r\n\r\nexport interface OntoRoute {\r\n /**\r\n * The URL path (e.g., '/docs', '/api/reference')\r\n */\r\n path: string;\r\n /**\r\n * Description of what this route contains\r\n */\r\n description: string;\r\n /**\r\n * Optional: Page type for automatic JSON-LD schema injection\r\n * - 'scoring': Injects Methodology schema with AIO scoring weights (40/35/25)\r\n * - 'about': Injects Organization/AboutPage schema\r\n * - 'default': No automatic schema injection\r\n */\r\n pageType?: PageType;\r\n}\r\n\r\nexport interface OntoConfig {\r\n /**\r\n * The name of your project or site (required)\r\n * Used as the H1 heading in llms.txt\r\n */\r\n name: string;\r\n\r\n /**\r\n * A short summary of your project (required)\r\n * Displayed as a blockquote in llms.txt\r\n * Should contain key information necessary for understanding the rest of the file\r\n */\r\n summary: string;\r\n\r\n /**\r\n * The base URL of your site (e.g., 'https://example.com')\r\n */\r\n baseUrl: string;\r\n\r\n /**\r\n * Optional: Additional sections to include in llms.txt\r\n * Each section can contain any markdown content\r\n */\r\n sections?: {\r\n heading: string;\r\n content: string;\r\n }[];\r\n\r\n /**\r\n * Key routes that AI agents should know about\r\n * These will be formatted as a markdown list in llms.txt\r\n */\r\n routes?: OntoRoute[];\r\n\r\n /**\r\n * Optional: Links to external resources (documentation, API references, etc.)\r\n */\r\n externalLinks?: {\r\n title: string;\r\n url: string;\r\n description?: string;\r\n }[];\r\n\r\n /**\r\n * Optional: Organization information for JSON-LD schemas\r\n */\r\n organization?: {\r\n name: string;\r\n description?: string;\r\n url?: string;\r\n logo?: string;\r\n foundingDate?: string;\r\n };\r\n}\r\n\r\n/**\r\n * Generate llms.txt content from OntoConfig\r\n * Follows the llms.txt specification:\r\n * - H1 with project name\r\n * - Blockquote with summary\r\n * - Additional markdown sections\r\n */\r\nexport function generateLlmsTxt(config: OntoConfig): string {\r\n const lines: string[] = [];\r\n\r\n // H1: Project name (required)\r\n lines.push(`# ${config.name}`);\r\n lines.push('');\r\n\r\n // Blockquote: Summary (required)\r\n lines.push(`> ${config.summary}`);\r\n lines.push('');\r\n\r\n // Key Routes section (if provided)\r\n if (config.routes && config.routes.length > 0) {\r\n lines.push('## Key Routes');\r\n lines.push('');\r\n for (const route of config.routes) {\r\n const fullUrl = `${config.baseUrl}${route.path}`;\r\n lines.push(`- [${route.path}](${fullUrl}): ${route.description}`);\r\n }\r\n lines.push('');\r\n }\r\n\r\n // External Links section (if provided)\r\n if (config.externalLinks && config.externalLinks.length > 0) {\r\n lines.push('## Resources');\r\n lines.push('');\r\n for (const link of config.externalLinks) {\r\n if (link.description) {\r\n lines.push(`- [${link.title}](${link.url}): ${link.description}`);\r\n } else {\r\n lines.push(`- [${link.title}](${link.url})`);\r\n }\r\n }\r\n lines.push('');\r\n }\r\n\r\n // Custom sections (if provided)\r\n if (config.sections && config.sections.length > 0) {\r\n for (const section of config.sections) {\r\n lines.push(`## ${section.heading}`);\r\n lines.push('');\r\n lines.push(section.content);\r\n lines.push('');\r\n }\r\n }\r\n\r\n return lines.join('\\n').trim() + '\\n';\r\n}\r\n"],"mappings":"AAAA,OAAsB,gBAAAA,MAAoB,cCkBnC,IAAMC,EAAmB,CAE5B,CAAE,KAAM,SAAqB,QAAS,SAAY,QAAS,YAAa,EACxE,CAAE,KAAM,eAAoB,QAAS,SAAY,QAAS,YAAa,EACvE,CAAE,KAAM,gBAAoB,QAAS,SAAY,QAAS,YAAa,EACvE,CAAE,KAAM,UAAoB,QAAS,SAAY,QAAS,YAAa,EACvE,CAAE,KAAM,SAAoB,QAAS,SAAY,QAAS,YAAa,EACvE,CAAE,KAAM,MAAoB,QAAS,SAAY,QAAS,YAAa,EAGvE,CAAE,KAAM,wBAA2B,QAAS,SAAU,QAAS,YAAa,EAC5E,CAAE,KAAM,kBAA2B,QAAS,SAAU,QAAS,YAAa,EAC5E,CAAE,KAAM,cAA2B,QAAS,SAAU,QAAS,YAAa,EAG5E,CAAE,KAAM,YAAmB,QAAS,YAAa,QAAS,YAAa,EACvE,CAAE,KAAM,cAAkB,QAAS,YAAa,QAAS,YAAa,EACtE,CAAE,KAAM,eAAkB,QAAS,YAAa,QAAS,YAAa,EACtE,CAAE,KAAM,iBAAkB,QAAS,YAAa,QAAS,YAAa,EACtE,CAAE,KAAM,eAAkB,QAAS,YAAa,QAAS,YAAa,EACtE,CAAE,KAAM,eAAkB,QAAS,YAAa,QAAS,YAAa,EACtE,CAAE,KAAM,SAAkB,QAAS,YAAa,QAAS,YAAa,EACtE,CAAE,KAAM,YAAkB,QAAS,YAAa,QAAS,YAAa,EAGtE,CAAE,KAAM,gBAAmB,QAAS,aAAc,QAAS,YAAa,EACxE,CAAE,KAAM,kBAAmB,QA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IAAgB,MAAKA,EAAcA,EAAY,MAAM,EAAG,EAAE,GAG3F,IAAMC,EAAe,QAAQ,IAAI,aAC3BC,EAAgB,QAAQ,IAAI,oBAAsB,4BAEpDD,GAEA,MAAM,GAAGC,CAAa,aAAc,CAChC,OAAQ,OACR,QAAS,CAAE,aAAcD,EAAc,eAAgB,kBAAmB,EAC1E,KAAM,KAAK,UAAU,CAAE,MAAOb,EAAI,SAAU,UAAAD,EAAW,IAAKE,GAAS,KAAM,QAASA,GAAS,OAAQ,CAAC,CAC1G,CAAC,EAAE,MAAM,IAAM,CAAC,CAAC,EAIrBD,EAAI,SAAW,SAASY,CAAW,MACnC,IAAMF,EAAWH,EAAa,QAAQP,CAAG,EAGzC,OAAAU,EAAS,QAAQ,IAAI,eAAgB,8BAA8B,EACnEA,EAAS,QAAQ,IAAI,gBAAiB,mEAAmE,EACzGA,EAAS,QAAQ,IAAI,eAAgBX,GAAa,OAAO,EACrDE,GAASS,EAAS,QAAQ,IAAI,aAAc,GAAGT,EAAQ,IAAI,KAAKA,EAAQ,OAAO,GAAG,EAClFG,GAAeM,EAAS,QAAQ,IAAI,eAAgB,MAAM,EAEvDA,CACX,CAGA,IAAMA,EAAWH,EAAa,KAAK,EACnC,OAAAG,EAAS,QAAQ,IAAI,eAAgBX,GAAa,OAAO,EAClDW,CACX","names":["NextResponse","AI_BOTS","AI_BOT_USER_AGENTS","AI_BOT_USER_AGENTS_CACHE","bot","matchBot","userAgent","lowerUA","matches","longest","current","generateLlmsTxt","config","lines","route","fullUrl","link","section","ontoMiddleware","request","config","userAgent","url","matched","matchBot","accept","hasDebugParam","isAiBot","isMarkdownRequested","NextResponse","llmsTxtContent","generateLlmsTxt","response","error","payloadPath","ONTO_API_KEY","DASHBOARD_URL"]}
1
+ {"version":3,"sources":["../src/middleware.ts","../src/bots.ts","../src/config.ts"],"sourcesContent":["import { NextRequest, NextResponse } from 'next/server';\r\nimport { matchBot } from './bots';\r\nimport { generateLlmsTxt, OntoConfig } from './config';\r\n\r\nexport async function ontoMiddleware(request: any, config?: OntoConfig) {\r\n const userAgent = request.headers.get('user-agent');\r\n const url = request.nextUrl.clone();\r\n const matched = matchBot(userAgent);\r\n\r\n const accept = request.headers.get('accept') || '';\r\n const hasDebugParam = request.nextUrl.searchParams.has('onto');\r\n\r\n const isAiBot = !!matched;\r\n const isMarkdownRequested = accept.includes('text/markdown') || hasDebugParam;\r\n\r\n // Common logic for bot/markdown negotiation\r\n if (isAiBot || isMarkdownRequested) {\r\n // Ignore internal next.js requests\r\n if (url.pathname.startsWith('/_next')) {\r\n return NextResponse.next();\r\n }\r\n\r\n // --- llms.txt Auto-Discovery ---\r\n if (url.pathname === '/llms.txt') {\r\n try {\r\n if (config) {\r\n const llmsTxtContent = generateLlmsTxt(config);\r\n const response = new NextResponse(llmsTxtContent, {\r\n headers: {\r\n 'Content-Type': 'text/plain; charset=utf-8',\r\n 'Cache-Control': 'public, max-age=3600, s-maxage=3600, stale-while-revalidate=86400',\r\n }\r\n });\r\n if (matched) response.headers.set('X-Onto-Bot', `${matched.name} (${matched.company})`);\r\n response.headers.set('X-Onto-Trace', userAgent || 'no-ua');\r\n return response;\r\n }\r\n } catch (error) {\r\n console.error('[Onto] Failed to generate llms.txt:', error);\r\n }\r\n }\r\n\r\n // Skip other static assets with dots\r\n if (url.pathname.includes('.')) {\r\n return NextResponse.next();\r\n }\r\n\r\n // Determine the corresponding payload path\r\n let payloadPath = url.pathname;\r\n if (payloadPath === '/' || payloadPath === '') payloadPath = '/index';\r\n if (payloadPath.endsWith('/') && payloadPath !== '/') payloadPath = payloadPath.slice(0, -1);\r\n\r\n // --- Onto Control Plane Integration (Premium) ---\r\n const ONTO_API_KEY = process.env.ONTO_API_KEY;\r\n const DASHBOARD_URL = process.env.ONTO_DASHBOARD_URL || 'https://app.buildonto.dev';\r\n\r\n if (ONTO_API_KEY) {\r\n // Logic for tracking and injection ... (fire-and-forget tracking)\r\n fetch(`${DASHBOARD_URL}/api/track`, {\r\n method: 'POST',\r\n headers: { 'x-onto-key': ONTO_API_KEY, 'Content-Type': 'application/json' },\r\n body: JSON.stringify({ route: url.pathname, userAgent, bot: matched?.name, company: matched?.company })\r\n }).catch(() => {});\r\n }\r\n\r\n // Rewrite to semantic payload\r\n url.pathname = `/.onto${payloadPath}.md`;\r\n const response = NextResponse.rewrite(url);\r\n \r\n // Apply headers\r\n response.headers.set('Content-Type', 'text/markdown; charset=utf-8');\r\n response.headers.set('Cache-Control', 'public, max-age=3600, s-maxage=3600, stale-while-revalidate=86400');\r\n response.headers.set('Vary', 'User-Agent, Accept');\r\n response.headers.set('X-Onto-Trace', userAgent || 'no-ua');\r\n \r\n if (matched) {\r\n response.headers.set('X-Onto-Bot', `${matched.name} (${matched.company})`);\r\n response.headers.set('X-Onto-Matched', 'true');\r\n }\r\n \r\n if (hasDebugParam) response.headers.set('X-Onto-Debug', 'true');\r\n\r\n return response;\r\n }\r\n\r\n // Default response for non-bots\r\n const response = NextResponse.next();\r\n \r\n // Crucial: Tell Vercel/Edge to vary the cache by User-Agent \r\n // This ensures bots get the rewrite and humans get the HTML\r\n response.headers.set('Vary', 'User-Agent, Accept');\r\n response.headers.set('X-Onto-Trace', userAgent || 'no-ua');\r\n \r\n return response;\r\n}\r\n\r\n// Re-export the bot registry for consumers who want to extend or inspect it\r\nexport { AI_BOT_USER_AGENTS, matchBot } from './bots';\r\nexport type { AiBot } from './bots';\r\n\r\n\r\n","/**\n * Comprehensive registry of AI bot user-agent strings.\n * The middleware uses this list to detect AI crawlers and serve optimized markdown.\n */\n\nexport interface AiBot {\n /** The user-agent substring to match against */\n name: string;\n /** The company operating this bot */\n company: string;\n /** ISO date when this bot was added or last verified */\n addedAt?: string;\n}\n\n/**\n * Structured registry of all known AI bots, grouped by company.\n * Useful for analytics and the Control Plane dashboard.\n */\nexport const AI_BOTS: AiBot[] = [\n // OpenAI\n { name: 'GPTBot', company: 'OpenAI', addedAt: '2025-01-01' },\n { name: 'ChatGPT-User', company: 'OpenAI', addedAt: '2025-01-01' },\n { name: 'OAI-SearchBot', company: 'OpenAI', addedAt: '2025-01-01' },\n { name: 'ChatGPT', company: 'OpenAI', addedAt: '2025-03-25' },\n { name: 'OpenAI', company: 'OpenAI', addedAt: '2025-03-25' },\n { name: 'GPT', company: 'OpenAI', addedAt: '2025-03-25' },\n\n // Google (SEO Safety: Googlebot proper is EXCLUDED)\n { name: 'Google-CloudVertexBot', company: 'Google', addedAt: '2025-01-01' },\n { name: 'Google-Extended', company: 'Google', addedAt: '2025-01-01' },\n { name: 'GoogleOther', company: 'Google', addedAt: '2025-01-01' },\n\n // Anthropic\n { name: 'ClaudeBot', company: 'Anthropic', addedAt: '2025-01-01' },\n { name: 'Claude-User', company: 'Anthropic', addedAt: '2025-01-01' },\n { name: 'claude-fetch', company: 'Anthropic', addedAt: '2025-03-25' },\n { name: 'AnthropicFetch', company: 'Anthropic', addedAt: '2025-03-25' },\n { name: 'Claude-Fetch', company: 'Anthropic', addedAt: '2025-03-25' },\n { name: 'anthropic-ai', company: 'Anthropic', addedAt: '2025-01-01' },\n { name: 'Claude', company: 'Anthropic', addedAt: '2025-03-25' },\n { name: 'Anthropic', company: 'Anthropic', addedAt: '2025-03-25' },\n\n // Perplexity\n { name: 'PerplexityBot', company: 'Perplexity', addedAt: '2025-01-01' },\n { name: 'Perplexity-User', company: 'Perplexity', addedAt: '2025-01-01' },\n { name: 'Perplexity', company: 'Perplexity', addedAt: '2025-03-25' },\n\n // Meta\n { name: 'Meta-ExternalAgent', company: 'Meta', addedAt: '2025-01-01' },\n { name: 'Meta-ExternalFetcher', company: 'Meta', addedAt: '2025-01-01' },\n { name: 'facebookexternalhit', company: 'Meta', addedAt: '2025-03-25' },\n { name: 'FacebookBot', company: 'Meta', addedAt: '2025-01-01' },\n\n // Mistral\n { name: 'MistralBot', company: 'Mistral', addedAt: '2025-03-25' },\n { name: 'Mistral', company: 'Mistral', addedAt: '2025-03-25' },\n\n // Amazon\n { name: 'Amazonbot', company: 'Amazon', addedAt: '2025-03-25' },\n\n // Others\n { name: 'AI2Bot', company: 'Allen Institute', addedAt: '2025-03-25' },\n { name: 'DuckAssistBot', company: 'DuckDuckGo', addedAt: '2025-03-25' },\n { name: 'Diffbot', company: 'Diffbot', addedAt: '2025-03-25' },\n { name: 'CCBot', company: 'Common Crawl', addedAt: '2025-01-01' },\n { name: 'Bytespider', company: 'ByteDance', addedAt: '2025-01-01' },\n { name: 'Applebot-Extended', company: 'Apple', addedAt: '2025-01-01' },\n { name: 'YouBot', company: 'You.com', addedAt: '2025-01-01' },\n\n // Generic AI / Scraping Libraries (Last Resort)\n { name: 'python-requests', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'python-httpx', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'httpx', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'axios', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'node-fetch', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'Go-http-client', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'Wget', company: 'Generic Bot', addedAt: '2025-03-25' },\n { name: 'Curl', company: 'Generic Bot', addedAt: '2025-03-25' },\n];\n\n/**\n * Flat list of user-agent substrings for fast matching in the middleware.\n */\nexport const AI_BOT_USER_AGENTS: string[] = AI_BOT_USER_AGENTS_CACHE();\n\nfunction AI_BOT_USER_AGENTS_CACHE() {\n return AI_BOTS.map(bot => bot.name);\n}\n\n/**\n * Given a raw user-agent string, returns the matched AiBot entry or undefined.\n * Uses a \"Longest Match\" strategy to ensure maximum specificity.\n * Comparison is case-insensitive.\n */\nexport function matchBot(userAgent: string | null): AiBot | undefined {\n if (!userAgent) return undefined;\n const lowerUA = userAgent.toLowerCase();\n \n // Find all matches\n const matches = AI_BOTS.filter(bot => \n lowerUA.includes(bot.name.toLowerCase())\n );\n\n if (matches.length === 0) return undefined;\n if (matches.length === 1) return matches[0];\n\n // Pick the longest match for maximum specificity (e.g. 'ChatGPT-User' vs 'GPT')\n return matches.reduce((longest, current) => \n current.name.length > longest.name.length ? current : longest\n );\n}\n","/**\r\n * Configuration schema for onto.config.ts\r\n * Used to dynamically generate llms.txt and other AI discovery files\r\n */\r\n\r\nexport type PageType = 'scoring' | 'about' | 'default';\r\n\r\nexport interface OntoRoute {\r\n /**\r\n * The URL path (e.g., '/docs', '/api/reference')\r\n */\r\n path: string;\r\n /**\r\n * Description of what this route contains\r\n */\r\n description: string;\r\n /**\r\n * Optional: Page type for automatic JSON-LD schema injection\r\n * - 'scoring': Injects Methodology schema with AIO scoring weights (40/35/25)\r\n * - 'about': Injects Organization/AboutPage schema\r\n * - 'default': No automatic schema injection\r\n */\r\n pageType?: PageType;\r\n}\r\n\r\nexport interface OntoConfig {\r\n /**\r\n * The name of your project or site (required)\r\n * Used as the H1 heading in llms.txt\r\n */\r\n name: string;\r\n\r\n /**\r\n * A short summary of your project (required)\r\n * Displayed as a blockquote in llms.txt\r\n * Should contain key information necessary for understanding the rest of the file\r\n */\r\n summary: string;\r\n\r\n /**\r\n * The base URL of your site (e.g., 'https://example.com')\r\n */\r\n baseUrl: string;\r\n\r\n /**\r\n * Optional: Additional sections to include in llms.txt\r\n * Each section can contain any markdown content\r\n */\r\n sections?: {\r\n heading: string;\r\n content: string;\r\n }[];\r\n\r\n /**\r\n * Key routes that AI agents should know about\r\n * These will be formatted as a markdown list in llms.txt\r\n */\r\n routes?: OntoRoute[];\r\n\r\n /**\r\n * Optional: Links to external resources (documentation, API references, etc.)\r\n */\r\n externalLinks?: {\r\n title: string;\r\n url: string;\r\n description?: string;\r\n }[];\r\n\r\n /**\r\n * Optional: Organization information for JSON-LD schemas\r\n */\r\n organization?: {\r\n name: string;\r\n description?: string;\r\n url?: string;\r\n logo?: string;\r\n foundingDate?: string;\r\n };\r\n}\r\n\r\n/**\r\n * Generate llms.txt content from OntoConfig\r\n * Follows the llms.txt specification:\r\n * - H1 with project name\r\n * - Blockquote with summary\r\n * - Additional markdown sections\r\n */\r\nexport function generateLlmsTxt(config: OntoConfig): string {\r\n const lines: string[] = [];\r\n\r\n // H1: Project name (required)\r\n lines.push(`# ${config.name}`);\r\n lines.push('');\r\n\r\n // Blockquote: Summary (required)\r\n lines.push(`> ${config.summary}`);\r\n lines.push('');\r\n\r\n // Key Routes section (if provided)\r\n if (config.routes && config.routes.length > 0) {\r\n lines.push('## Key Routes');\r\n lines.push('');\r\n for (const route of config.routes) {\r\n const fullUrl = `${config.baseUrl}${route.path}`;\r\n lines.push(`- [${route.path}](${fullUrl}): ${route.description}`);\r\n }\r\n lines.push('');\r\n }\r\n\r\n // External Links section (if provided)\r\n if (config.externalLinks && config.externalLinks.length > 0) {\r\n lines.push('## Resources');\r\n lines.push('');\r\n for (const link of config.externalLinks) {\r\n if (link.description) {\r\n lines.push(`- [${link.title}](${link.url}): ${link.description}`);\r\n } else {\r\n lines.push(`- [${link.title}](${link.url})`);\r\n }\r\n }\r\n lines.push('');\r\n }\r\n\r\n // Custom sections (if provided)\r\n if (config.sections && config.sections.length > 0) {\r\n for (const section of config.sections) {\r\n lines.push(`## ${section.heading}`);\r\n lines.push('');\r\n lines.push(section.content);\r\n lines.push('');\r\n }\r\n }\r\n\r\n return lines.join('\\n').trim() + '\\n';\r\n}\r\n"],"mappings":"AAAA,OAAsB,gBAAAA,MAAoB,cCkBnC,IAAMC,EAAmB,CAE5B,CAAE,KAAM,SAAqB,QAAS,SAAY,QAAS,YAAa,EACxE,CAAE,KAAM,eAAoB,QAAS,SAAY,QAAS,YAAa,EACvE,CAAE,KAAM,gBAAoB,QAAS,SAAY,QAAS,YAAa,EACvE,CAAE,KAAM,UAAoB,QAAS,SAAY,QAAS,YAAa,EACvE,CAAE,KAAM,SAAoB,QAAS,SAAY,QAAS,YAAa,EACvE,CAAE,KAAM,MAAoB,QAAS,SAAY,QAAS,YAAa,EAGvE,CAAE,KAAM,wBAA2B,QAAS,SAAU,QAAS,YAAa,EAC5E,CAAE,KAAM,kBAA2B,QAAS,SAAU,QAAS,YAAa,EAC5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ACzES,EAAS,QAAQ,IAAI,iBAAkB,MAAM,GAG7CN,GAAeM,EAAS,QAAQ,IAAI,eAAgB,MAAM,EAEvDA,CACX,CAGA,IAAMA,EAAWH,EAAa,KAAK,EAInC,OAAAG,EAAS,QAAQ,IAAI,OAAQ,oBAAoB,EACjDA,EAAS,QAAQ,IAAI,eAAgBX,GAAa,OAAO,EAElDW,CACX","names":["NextResponse","AI_BOTS","AI_BOT_USER_AGENTS","AI_BOT_USER_AGENTS_CACHE","bot","matchBot","userAgent","lowerUA","matches","longest","current","generateLlmsTxt","config","lines","route","fullUrl","link","section","ontoMiddleware","request","config","userAgent","url","matched","matchBot","accept","hasDebugParam","isAiBot","isMarkdownRequested","NextResponse","llmsTxtContent","generateLlmsTxt","response","error","payloadPath","ONTO_API_KEY","DASHBOARD_URL"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ontosdk/next",
3
- "version": "1.5.5",
3
+ "version": "1.5.6",
4
4
  "description": "Extracts semantic Markdown from React/Next.js pages for AI Agents",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/middleware.ts CHANGED
@@ -70,8 +70,14 @@ export async function ontoMiddleware(request: any, config?: OntoConfig) {
70
70
  // Apply headers
71
71
  response.headers.set('Content-Type', 'text/markdown; charset=utf-8');
72
72
  response.headers.set('Cache-Control', 'public, max-age=3600, s-maxage=3600, stale-while-revalidate=86400');
73
+ response.headers.set('Vary', 'User-Agent, Accept');
73
74
  response.headers.set('X-Onto-Trace', userAgent || 'no-ua');
74
- if (matched) response.headers.set('X-Onto-Bot', `${matched.name} (${matched.company})`);
75
+
76
+ if (matched) {
77
+ response.headers.set('X-Onto-Bot', `${matched.name} (${matched.company})`);
78
+ response.headers.set('X-Onto-Matched', 'true');
79
+ }
80
+
75
81
  if (hasDebugParam) response.headers.set('X-Onto-Debug', 'true');
76
82
 
77
83
  return response;
@@ -79,7 +85,12 @@ export async function ontoMiddleware(request: any, config?: OntoConfig) {
79
85
 
80
86
  // Default response for non-bots
81
87
  const response = NextResponse.next();
88
+
89
+ // Crucial: Tell Vercel/Edge to vary the cache by User-Agent
90
+ // This ensures bots get the rewrite and humans get the HTML
91
+ response.headers.set('Vary', 'User-Agent, Accept');
82
92
  response.headers.set('X-Onto-Trace', userAgent || 'no-ua');
93
+
83
94
  return response;
84
95
  }
85
96