const p=new Set(["https://chatgpt.com","https://anthropic.com","https://gemini.google.com","https://perplexity.ai"]),l=["GPTBot","ChatGPT-User","OAI-SearchBot","ClaudeBot","Claude-User","Claude-SearchBot","anthropic-ai","Google-Extended","Gemini-Deep-Research","Google-CloudVertexBot","PerplexityBot","Perplexity-User","Meta-ExternalAgent","Meta-ExternalFetcher","meta-webindexer","CrawlBot","CCBot","Bytespider","DuckAssistBot","Cursor"];function m(t,e,r){return Math.min(r,Math.max(e,t))}function u(t){if(!t?.trim())return[];const e=[],r=t.split(",").map(o=>o.trim());for(const o of r){if(!o)continue;const[n,...a]=o.split(";").map(s=>s.trim().toLowerCase());if(!n.includes("/"))continue;let i=1;for(const s of a)if(s.startsWith("q=")){const c=parseFloat(s.slice(2));i=Number.isFinite(c)?m(c,0,1):1;break}e.push({type:n,q:i})}return e}function f(t){const e=u(t),r=Math.max(0,...e.filter(n=>n.type==="text/html").map(n=>n.q)),o=Math.max(0,...e.filter(n=>n.type==="text/markdown").map(n=>n.q));return o>=r&&o>0}function x(t){return u(t??"").some(r=>r.type==="text/html"&&r.q>0)}function h(t){if(!t||!t.trim().length)return!1;const e=t.trim().toLowerCase().replace(/\/$/,"");return p.has(e)}function d(t){if(!t)return!1;const e=t.toLowerCase();return l.some(r=>e.includes(r.toLowerCase()))}function g(t){const{accept:e,signatureAgent:r,signature:o,signatureInput:n,userAgent:a}=t;return!!(f(e??"")||h(r)&&(o!==void 0||n!==void 0)||d(a))}export{x as acceptsHtml,g as isAiAgentRequest};
